Fix misc bugs

Change UtilServer to return proper plugin instance
Remove /energyshop debug command
Add warning for opening chests while in vanish
Fix item maps being broken
Fix tutorials possibly wiping inventory
Make the project compile
This commit is contained in:
samczsun 2016-06-16 15:46:12 -04:00
parent 5ac6249684
commit 01409af5bd
No known key found for this signature in database
GPG Key ID: B0AFDBD87206805D
9 changed files with 210 additions and 105 deletions

View File

@ -11,6 +11,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.lang.reflect.Field;
@ -112,7 +113,7 @@ public class UtilServer
public static Plugin getPlugin()
{
return getPluginManager().getPlugins()[0];
return JavaPlugin.getProvidingPlugin(UtilServer.class);
}
public static PluginManager getPluginManager()

View File

@ -85,15 +85,6 @@ public class ClanEnergyManager extends MiniPlugin implements Runnable
return _clansManager;
}
@EventHandler
public void command(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().startsWith("/energyshop"))
{
openShop(event.getPlayer());
}
}
public int convertEnergyToGold(int energy)
{
return (energy / 8) + (energy % 8 == 0 ? 0 : 1);

View File

@ -71,6 +71,7 @@ import mineplex.game.clans.core.repository.tokens.ClanToken;
import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.fields.Field;
import mineplex.game.clans.gameplay.Gameplay;
import mineplex.game.clans.gameplay.HiddenChestManager;
import mineplex.game.clans.gameplay.safelog.SafeLog;
import mineplex.game.clans.gameplay.safelog.npc.NPCManager;
import mineplex.game.clans.items.GearManager;
@ -290,6 +291,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
new Weapon(plugin, energy);
new Gameplay(plugin, this, blockRestore, _damageManager);
new HiddenChestManager(this, packetHandler);
_projectileManager = new ProjectileManager(plugin);
Fire fire = new Fire(plugin, _condition, _damageManager);
@ -619,7 +621,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
continue;
}
other.sendMessage(F.sys("Quit ", event.getPlayer().getName()));
other.sendMessage(F.sys("Quit", event.getPlayer().getName()));
}
}

View File

@ -482,7 +482,15 @@ public class ItemMapManager extends MiniPlugin
}*/
byte color = (byte) (origColor + b0);
map[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] = color;
if((color <= -113 || color >= 0) && color <= 127)
{
map[(x + HALF_WORLD_SIZE) / zoom][(z + HALF_WORLD_SIZE) / zoom] = color;
}
else
{
System.out.println(String.format("Tried to set color to %s in colorWorldHeight scale: %s, sx: %s, sz: %s, x: %z, z: %s, zoom: %s",
color, scale, startingX, startingZ, x, z, zoom));
}
}
}
}

View File

@ -184,74 +184,83 @@ public class ItemMapRenderer extends MapRenderer
if (clanColor != null)
{
int chunkBX = blockX & 0xF;
int chunkBZ = blockZ & 0xF;
int chunkX1 = (int) Math.floor(blockX / 16D);
int chunkZ1 = (int) Math.floor(blockZ / 16D);
//Border
if (colorAll ||
((chunkBX == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 - 1) + "," + chunkZ1))
|| ((chunkBZ == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 - 1)))
|| ((chunkBX + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 + 1) + "," + chunkZ1))
|| ((chunkBZ + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 + 1))))
if(! ((color <= -113 || color >= 0) && color <= 127))
{
Color cColor = MapPalette.getColor(color);
double clans = colorAll ? 1 : 0.8;// 0.65;
//Use clanColor2 no matter what for admins
Color drawColor = clanColor;
if (owningClan.isAdmin() && clanColor2 != null)
{
drawColor = clanColor2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
color = (byte) 0;
System.out.println(String.format("Tried to draw invalid color %s, player: %s, mapX: %s, mapZ: %s",
color, player.getName(), mapX, mapZ));
}
//Inside
else
{
Color cColor = MapPalette.getColor(color);
int chunkBX = blockX & 0xF;
int chunkBZ = blockZ & 0xF;
int chunkX1 = (int) Math.floor(blockX / 16D);
int chunkZ1 = (int) Math.floor(blockZ / 16D);
double clans = 0.065;
//Border
if (colorAll ||
//Stripes
boolean checker = (mapX + (mapZ % 4)) % 4 == 0;
Color drawColor = clanColor;
if (checker && owningClan.isAdmin() && clanColor2 != null)
((chunkBX == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 - 1) + "," + chunkZ1))
|| ((chunkBZ == 0 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 - 1)))
|| ((chunkBX + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + (chunkX1 + 1) + "," + chunkZ1))
|| ((chunkBZ + zoom > 15 || zoom == 13) &&
owningClan != _manager.getClansUtility().getOwner("world," + chunkX1 + "," + (chunkZ1 + 1))))
{
drawColor = clanColor2;
clans = 1;
Color cColor = MapPalette.getColor(color);
double clans = colorAll ? 1 : 0.8;// 0.65;
//Use clanColor2 no matter what for admins
Color drawColor = clanColor;
if (owningClan.isAdmin() && clanColor2 != null)
{
drawColor = clanColor2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
//Inside
else
{
Color cColor = MapPalette.getColor(color);
color = MapPalette.matchColor(r, g, b);
double clans = 0.065;
//Stripes
boolean checker = (mapX + (mapZ % 4)) % 4 == 0;
Color drawColor = clanColor;
if (checker && owningClan.isAdmin() && clanColor2 != null)
{
drawColor = clanColor2;
clans = 1;
}
double base = 1 - clans;
int r = (int) ((cColor.getRed() * base) + (drawColor.getRed() * clans));
int b = (int) ((cColor.getBlue() * base) + (drawColor.getBlue() * clans));
int g = (int) ((cColor.getGreen() * base) + (drawColor.getGreen() * clans));
color = MapPalette.matchColor(r, g, b);
}
}
}
}

View File

@ -332,35 +332,6 @@ public class Gameplay extends MiniPlugin
}
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (!_clansManager.getIncognitoManager().Get(event.getPlayer()).Status)
{
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (event.getClickedBlock() == null)
{
return;
}
Material type = event.getClickedBlock().getType();
if (type != Material.CHEST && type != Material.TRAPPED_CHEST)
{
return;
}
Chest chest = (Chest) event.getClickedBlock().getState();
event.getPlayer().openInventory(chest.getInventory());
event.setCancelled(true);
}
/**
* Disable all Piston related events in Clans
*

View File

@ -0,0 +1,111 @@
package mineplex.game.clans.gameplay;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
import mineplex.game.clans.clans.ClansManager;
import net.minecraft.server.v1_8_R3.BaseBlockPosition;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.PacketPlayOutBlockAction;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedSoundEffect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class HiddenChestManager implements Listener
{
private final Set<BaseBlockPosition> _locationsToCancel = Collections.synchronizedSet(new HashSet<>());
private final Set<String> _fine = new HashSet<>();
private final ClansManager _clansManager;
public HiddenChestManager(ClansManager clansManager, PacketHandler packetHandler)
{
this._clansManager = clansManager;
UtilServer.RegisterEvents(this);
// packetHandler.addPacketHandler(this, PacketPlayOutBlockAction.class, PacketPlayOutNamedSoundEffect.class);
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event)
{
if (!_clansManager.getIncognitoManager().Get(event.getPlayer()).Status)
{
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK)
{
return;
}
if (event.getClickedBlock() == null)
{
return;
}
Material type = event.getClickedBlock().getType();
if (type != Material.CHEST && type != Material.TRAPPED_CHEST)
{
return;
}
Location location = event.getClickedBlock().getLocation();
if (!_fine.contains(event.getPlayer().getName()))
{
event.setCancelled(true);
UtilPlayer.message(event.getPlayer(), F.main("Clans", "Opening chests while vanished will still make the chest open noise"));
UtilPlayer.message(event.getPlayer(), F.main("Clans", "If you are sure, run /IUnderstandOpeningChestsWillMakeNoise"));
}
// _locationsToCancel.add(new BaseBlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()));
}
@EventHandler
public void areYouReallySureYouWantTo(PlayerCommandPreprocessEvent event)
{
if (event.getMessage().equalsIgnoreCase("/IUnderstandOpeningChestsWillMakeNoise"))
{
_fine.add(event.getPlayer().getName());
event.setCancelled(true);
}
}
// @Override
// public void handle(PacketInfo packetInfo)
// {
// if (packetInfo.getPacket() instanceof PacketPlayOutBlockAction)
// {
// PacketPlayOutBlockAction blockAction = (PacketPlayOutBlockAction) packetInfo.getPacket();
// if (_locationsToCancel.contains(blockAction.a))
// {
// System.out.println(blockAction.b + " " + blockAction.c);
// packetInfo.setCancelled(true);
// if (blockAction.c == 0)
// {
// _locationsToCancel.remove(blockAction.a);
// }
// }
// }
// else if (packetInfo.getPacket() instanceof PacketPlayOutNamedSoundEffect)
// {
// PacketPlayOutNamedSoundEffect soundEffect = (PacketPlayOutNamedSoundEffect) packetInfo.getPacket();
//
// System.out.println(soundEffect.a);
// }
// }
}

View File

@ -74,6 +74,11 @@ public abstract class Tutorial implements Listener, ObjectiveListener
public void start(Player player)
{
if (!canStart(player))
{
return;
}
System.out.println(String.format("Tutorial> [%s] started tutorial [%s]", player.getName(), getName()));
TutorialSession session = new TutorialSession();
@ -223,6 +228,8 @@ public abstract class Tutorial implements Listener, ObjectiveListener
*/
protected abstract void onQuit(Player player);
protected abstract boolean canStart(Player player);
public void unregisterAll()
{
HandlerList.unregisterAll(this);

View File

@ -171,6 +171,18 @@ public class ClansMainTutorial extends Tutorial
*/
}
@Override
protected boolean canStart(Player player)
{
ClanInfo clan = ClansManager.getInstance().getClan(player);
if (clan != null)
{
UtilPlayer.message(player, F.main("Clans", "You are part of a clan - please leave or disband the clan before doing the tutorial"));
return false;
}
return true;
}
@Override
protected void onStart(Player player)
{
@ -205,13 +217,6 @@ public class ClansMainTutorial extends Tutorial
addHologram(player,
getPoint(region, ClansMainTutorial.Point.SPAWN).add(0, 1.5, -23),
"Jump Off!");
ClanInfo clan = ClansManager.getInstance().getClan(player);
if (clan != null)
{
UtilPlayer.message(player, F.main("Clans", "You are part of a clan - please leave or disband the clan before doing the tutorial"));
ClansManager.getInstance().getTutorial().finishTutorial(player); //nopenopenopenopenope
}
}
@Override