Fix assorted bugs

This commit is contained in:
AlexTheCoder 2016-08-01 14:48:44 -04:00
parent cd237b8d3b
commit 4fdbb1fc9d
8 changed files with 190 additions and 95 deletions

View File

@ -1192,6 +1192,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_worldEvent.onDisable();
_goldManager.onDisable();
_playTracker.onDisable();
_bannerManager.onDisable();
_amplifierManager.onDisable();
_netherManager.onDisable();
}
@EventHandler(priority = EventPriority.HIGHEST)

View File

@ -2,21 +2,6 @@ package mineplex.game.clans.clans.banners;
import java.util.HashMap;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.command.BannerCommand;
import mineplex.game.clans.core.repository.ClanTerritory;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Banner;
@ -25,18 +10,36 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.banners.command.BannerCommand;
import mineplex.game.clans.core.repository.ClanTerritory;
import net.minecraft.server.v1_8_R3.MinecraftServer;
/**
* Manager class for cosmetic clans banners
*/
public class BannerManager extends MiniPlugin
{
private static final long BANNER_PLACE_DURATION = UtilTime.convert(30, TimeUnit.MINUTES, TimeUnit.MILLISECONDS);
public final HashMap<String, ClanBanner> LoadedBanners = new HashMap<>();
private final HashMap<Block, Long> _placedBanners = new HashMap<>();
private final BlockFace[] _radial = { BlockFace.SOUTH, BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST, BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST };
private BannerRepository _repo;
public BannerManager(JavaPlugin plugin)
@ -48,18 +51,6 @@ public class BannerManager extends MiniPlugin
addCommand(new BannerCommand(this));
}
/**
* Resets all placed banners to air
*/
@Override
public void disable()
{
for (Block changed : _placedBanners.keySet())
{
changed.setType(Material.AIR);
}
}
/**
* Checks what type of banner unlock a player has
* @param player The player to check
@ -149,8 +140,17 @@ public class BannerManager extends MiniPlugin
Banner state = (Banner) block.getState();
state.setBaseColor(banner.getBaseColor());
state.setPatterns(((BannerMeta)banner.getBanner().getItemMeta()).getPatterns());
org.bukkit.material.Banner data = (org.bukkit.material.Banner) state.getData();
try
{
data.setFacingDirection(_radial[Math.round(placing.getLocation().getYaw() / 45f) & 0x7]);
}
catch (Exception e)
{
e.printStackTrace();
}
state.setData(data);
state.update();
_placedBanners.put(block, System.currentTimeMillis());
}
else
{
@ -163,26 +163,79 @@ public class BannerManager extends MiniPlugin
@EventHandler
public void onBreak(BlockBreakEvent event)
{
if (_placedBanners.containsKey(event.getBlock()))
if (event.getBlock().getType() == Material.STANDING_BANNER || event.getBlock().getType() == Material.WALL_BANNER)
{
_placedBanners.remove(event.getBlock());
event.setCancelled(true);
event.getBlock().setType(Material.AIR);
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
public void onDropBanner(BlockPhysicsEvent event)
{
if (event.getType() == UpdateType.FAST)
if (event.getBlock().getType() == Material.STANDING_BANNER || event.getBlock().getType() == Material.WALL_BANNER)
{
for (Block reset : _placedBanners.keySet())
event.setCancelled(true);
}
}
@EventHandler
public void onCraftBanner(PrepareItemCraftEvent event)
{
if (event.getInventory().getResult() == null || event.getInventory().getResult().getType() != Material.BANNER)
{
return;
}
event.getInventory().setResult(null);
}
@EventHandler
public void onCraftBanner(CraftItemEvent event)
{
if (event.getInventory().getResult() == null || event.getInventory().getResult().getType() != Material.BANNER)
{
return;
}
event.setCancelled(true);
}
@EventHandler
public void onJoinWithBanner(PlayerJoinEvent event)
{
if (MinecraftServer.getServer().recentTps[0] < 19)
{
return;
}
runSyncLater(() ->
{
for (ItemStack item : event.getPlayer().getInventory().getContents())
{
if (UtilTime.elapsed(_placedBanners.get(reset), BANNER_PLACE_DURATION))
if (item != null && item.getType() == Material.BANNER)
{
reset.setType(Material.AIR);
event.getPlayer().getInventory().remove(item);
}
}
}, 20);
}
@EventHandler
public void onPickupBanner(PlayerPickupItemEvent event)
{
if (event.getItem().getItemStack().getType() == Material.BANNER)
{
event.setCancelled(true);
event.getItem().remove();
}
}
@EventHandler
public void onPickupBanner(PlayerDropItemEvent event)
{
if (event.getItemDrop().getItemStack().getType() == Material.BANNER)
{
event.getItemDrop().remove();
}
}
}

View File

@ -110,17 +110,20 @@ public class InvseeInventory implements Listener
else
{
// This should always work
_targetPlayer = Bukkit.getOfflinePlayer(_uuid);
updateInventory();
if (_uuid.equals(event.getPlayer().getUniqueId()))
{
_targetPlayer = Bukkit.getOfflinePlayer(_uuid);
updateInventory();
}
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void on(InventoryOpenEvent event)
{
if (event.getPlayer().getUniqueId().equals(_targetPlayer.getUniqueId()) && !_canOpenInventory)
if (event.getPlayer().getUniqueId().equals(_uuid) && !_canOpenInventory)
{
event.setCancelled(true);
Bukkit.getScheduler().runTaskLater(UtilServer.getPlugin(), () -> {event.getPlayer().closeInventory();}, 20);
}
}
@ -295,7 +298,7 @@ public class InvseeInventory implements Listener
}
}
/*
/**
* Update the player inventory and invsee inventory.
*
* @param targetClick If true, then it means the player being invseen has modified their inventory. Otherwise, it's the admin who has modified something

View File

@ -102,16 +102,6 @@ public class BossNetherPortal implements Listener
{
_portalFacing = (byte)0;
}
_closeWarnings.add(UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(UtilTime.convert(1, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(30000L);
_closeWarnings.add(10000L);
_closeWarnings.add(5000L);
_closeWarnings.add(4000L);
_closeWarnings.add(3000L);
_closeWarnings.add(2000L);
_closeWarnings.add(1000L);
}
private boolean isInPortal(Block block)
@ -177,6 +167,15 @@ public class BossNetherPortal implements Listener
block.setType(Material.PORTAL);
block.setData(_portalFacing);
}
_closeWarnings.add(UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(UtilTime.convert(1, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(30000L);
_closeWarnings.add(10000L);
_closeWarnings.add(5000L);
_closeWarnings.add(4000L);
_closeWarnings.add(3000L);
_closeWarnings.add(2000L);
_closeWarnings.add(1000L);
}
}
@ -196,6 +195,7 @@ public class BossNetherPortal implements Listener
block.setType(Material.AIR);
}
HandlerList.unregisterAll(this);
_closeWarnings.clear();
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -245,11 +245,14 @@ public class BossNetherPortal implements Listener
ClansManager.getInstance().getNetherManager().OverworldOrigins.remove((Player)event.getEntity());
((Player)event.getEntity()).removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(event.getEntity(), F.main(ClansManager.getInstance().getNetherManager().getName(), "You have escaped " + F.clansNether("The Nether") + "!"));
ClansManager.getInstance().runSyncLater(() ->
{
ClansManager.getInstance().getCombatManager().Get((Player)event.getEntity()).SetLastCombatEngaged(System.currentTimeMillis());
}, 20);
}
else
{
ClansManager.getInstance().getNetherManager().InNether.put((Player)event.getEntity(), Expire);
Location from = event.getEntity().getLocation();
event.getEntity().teleport(ClansManager.getInstance().getNetherManager().getNetherWorld().getSpawnLocation());
ClansManager.getInstance().ClanTips.displayTip(TipType.ENTER_NETHER, (Player)event.getEntity());
}

View File

@ -4,6 +4,32 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin;
import mineplex.core.common.Rank;
import mineplex.core.common.generator.VoidGenerator;
@ -31,32 +57,6 @@ import mineplex.minecraft.game.core.boss.broodmother.SpiderCreature;
import mineplex.minecraft.game.core.boss.ironwizard.GolemCreature;
import mineplex.minecraft.game.core.boss.skeletonking.SkeletonCreature;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import org.bukkit.WorldCreator;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import com.google.common.collect.Lists;
/**
* Manager for all nether features
*/
@ -155,7 +155,12 @@ public class NetherManager extends MiniPlugin
*/
public Location getReturnLocation(Player player)
{
return OverworldOrigins.getOrDefault(player, Spawn.getWestTown());
Location defaultLoc = Spawn.getWestTown();
if (UtilMath.random.nextDouble() <= .5)
{
defaultLoc = Spawn.getEastTown();
}
return OverworldOrigins.getOrDefault(player, defaultLoc);
}
/**

View File

@ -104,16 +104,6 @@ public class NetherPortal implements Listener
{
_portalFacing = (byte)0;
}
_closeWarnings.add(UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(UtilTime.convert(1, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(30000L);
_closeWarnings.add(10000L);
_closeWarnings.add(5000L);
_closeWarnings.add(4000L);
_closeWarnings.add(3000L);
_closeWarnings.add(2000L);
_closeWarnings.add(1000L);
}
private boolean isInPortal(Block block)
@ -188,6 +178,15 @@ public class NetherPortal implements Listener
block.setType(Material.PORTAL);
block.setData(_portalFacing);
}
_closeWarnings.add(UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(UtilTime.convert(1, TimeUnit.MINUTES, TimeUnit.MILLISECONDS));
_closeWarnings.add(30000L);
_closeWarnings.add(10000L);
_closeWarnings.add(5000L);
_closeWarnings.add(4000L);
_closeWarnings.add(3000L);
_closeWarnings.add(2000L);
_closeWarnings.add(1000L);
}
}
@ -207,6 +206,7 @@ public class NetherPortal implements Listener
block.setType(Material.AIR);
}
HandlerList.unregisterAll(this);
_closeWarnings.clear();
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -256,11 +256,14 @@ public class NetherPortal implements Listener
ClansManager.getInstance().getNetherManager().OverworldOrigins.remove((Player)event.getEntity());
((Player)event.getEntity()).removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(event.getEntity(), F.main(ClansManager.getInstance().getNetherManager().getName(), "You have escaped " + F.clansNether("The Nether") + "!"));
ClansManager.getInstance().runSyncLater(() ->
{
ClansManager.getInstance().getCombatManager().Get((Player)event.getEntity()).SetLastCombatEngaged(System.currentTimeMillis());
}, 20);
}
else
{
ClansManager.getInstance().getNetherManager().InNether.put((Player)event.getEntity(), Expire);
Location from = event.getEntity().getLocation();
event.getEntity().teleport(ClansManager.getInstance().getNetherManager().getNetherWorld().getSpawnLocation());
ClansManager.getInstance().ClanTips.displayTip(TipType.ENTER_NETHER, (Player)event.getEntity());
}
@ -291,7 +294,7 @@ public class NetherPortal implements Listener
Long warning = -1L;
for (Long test : _closeWarnings)
{
if ((Expire - System.currentTimeMillis()) < warning)
if ((Expire - System.currentTimeMillis()) < test)
{
warning = test;
break;

View File

@ -43,6 +43,10 @@ public class ForceTeleportCommand extends CommandBase<NetherManager>
Plugin.OverworldOrigins.remove(caller);
caller.removePotionEffect(PotionEffectType.NIGHT_VISION);
UtilPlayer.message(caller, F.main(ClansManager.getInstance().getNetherManager().getName(), "You have escaped " + F.clansNether("The Nether") + "!"));
ClansManager.getInstance().runSyncLater(() ->
{
ClansManager.getInstance().getCombatManager().Get(caller).SetLastCombatEngaged(System.currentTimeMillis());
}, 20);
}
else
{

View File

@ -398,20 +398,41 @@ public class GoldManager extends MiniDbClientPlugin<GoldData>
@Override
public String getQuery(int accountId, String uuid, String name) {
public String getQuery(int accountId, String uuid, String name)
{
return "SELECT gold FROM clansGold WHERE id = '" + accountId + "' AND serverId=" + _serverId + ";";
}
@Override
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException {
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
if (resultSet.next())
{
Get(playerName).setBalance(resultSet.getInt(1));
if (resultSet.getInt(1) < 0)
{
setGold(new Callback<Boolean>()
{
public void run(Boolean success)
{
if (success)
{
System.out.println("Fixed negative gold balance for " + playerName + "!");
}
else
{
System.out.println("Failed to fix negative gold balance for " + playerName + "!");
}
}
}, "", playerName, accountId, 0, true);
}
}
}
@Override
protected GoldData addPlayer(String player) {
protected GoldData addPlayer(String player)
{
return new GoldData();
}
}