diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEvent.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEvent.java index bd5346696..c4bb681a8 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEvent.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEvent.java @@ -1,5 +1,6 @@ package mineplex.core.common.util; +import org.bukkit.entity.Arrow; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Projectile; import org.bukkit.event.block.Action; @@ -46,6 +47,15 @@ public class UtilEvent return false; } + public static boolean isBowDamage(EntityDamageEvent event) + { + if (!(event instanceof EntityDamageByEntityEvent)) + return false; + + EntityDamageByEntityEvent e = (EntityDamageByEntityEvent)event; + return e.getDamager() instanceof Arrow; + } + public static LivingEntity GetDamagerEntity(EntityDamageEvent event, boolean ranged) { if (!(event instanceof EntityDamageByEntityEvent)) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java index dc970e4eb..11c709372 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java @@ -306,10 +306,10 @@ public class UtilItem _materials.put(Material.DIAMOND_CHESTPLATE, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_CHESTPLATE, ItemCategory.ARMOR)); _materials.put(Material.DIAMOND_LEGGINGS, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_LEGGINGS, ItemCategory.ARMOR)); _materials.put(Material.DIAMOND_BOOTS, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_BOOTS, ItemCategory.ARMOR)); - _materials.put(Material.GOLD_HELMET, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_HELMET, ItemCategory.ARMOR)); - _materials.put(Material.GOLD_CHESTPLATE, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_CHESTPLATE, ItemCategory.ARMOR)); - _materials.put(Material.GOLD_LEGGINGS, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_LEGGINGS, ItemCategory.ARMOR)); - _materials.put(Material.GOLD_BOOTS, EnumSet.of(ItemCategory.ITEM, ItemCategory.DIAMOND, ItemCategory.ARMOR_BOOTS, ItemCategory.ARMOR)); + _materials.put(Material.GOLD_HELMET, EnumSet.of(ItemCategory.ITEM, ItemCategory.GOLD, ItemCategory.ARMOR_HELMET, ItemCategory.ARMOR)); + _materials.put(Material.GOLD_CHESTPLATE, EnumSet.of(ItemCategory.ITEM, ItemCategory.GOLD, ItemCategory.ARMOR_CHESTPLATE, ItemCategory.ARMOR)); + _materials.put(Material.GOLD_LEGGINGS, EnumSet.of(ItemCategory.ITEM, ItemCategory.GOLD, ItemCategory.ARMOR_LEGGINGS, ItemCategory.ARMOR)); + _materials.put(Material.GOLD_BOOTS, EnumSet.of(ItemCategory.ITEM, ItemCategory.GOLD, ItemCategory.ARMOR_BOOTS, ItemCategory.ARMOR)); _materials.put(Material.FLINT, EnumSet.of(ItemCategory.ITEM)); _materials.put(Material.PORK, EnumSet.of(ItemCategory.ITEM, ItemCategory.EDIBLE, ItemCategory.RAW_FOOD)); _materials.put(Material.GRILLED_PORK, EnumSet.of(ItemCategory.ITEM, ItemCategory.EDIBLE)); @@ -550,7 +550,7 @@ public class UtilItem public static boolean isSword(ItemStack stack) { - return isEdible(stack == null ? null : stack.getType()); + return isSword(stack == null ? null : stack.getType()); } public static boolean isSword(Material material) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java index ad8b468ac..a0fedc46e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/Achievement.java @@ -164,6 +164,43 @@ public enum Achievement new int[]{10}, AchievementCategory.UHC), + //MC League + MC_LEAGUE_STRIKE("First Strike", 600, + new String[] {"MC League.FirstStrike"}, + new String[] {"Earn 30 First Bloods"}, + new int[] {30}, + AchievementCategory.MC_LEAGUE), + + MC_LEAGUE_HEAD("Head Hunter", 600, + new String[] {"MC League.HeadHunter"}, + new String[] {"Grab 25 Wither Skulls"}, + new int[] {25}, + AchievementCategory.MC_LEAGUE), + + MC_LEAGUE_ALTAR("Altar Builder", 600, + new String[] {"MC League.AltarBuilder"}, + new String[] {"Place 50 Wither Skulls", "on your Altar"}, + new int[] {50}, + AchievementCategory.MC_LEAGUE), + + MC_LEAGUE_WINS("Mineplex Champion", 900, + new String[] {"MC League.Wins"}, + new String[] {"Win 25 Games"}, + new int[] {25}, + AchievementCategory.MC_LEAGUE), + + MC_LEAGUE_TOWER("Tower Defender", 800, + new String[] {"MC League.TowerDefender"}, + new String[] {"Get a double kill", "inside your Active Tower"}, + new int[] {1}, + AchievementCategory.MC_LEAGUE), + + MC_LEAGUE_SAVING("Saving Up", 900, + new String[] {"MC League.SavingUp"}, + new String[] {"Craft a Diamond Chestplate"}, + new int[] {1}, + AchievementCategory.MC_LEAGUE), + //UHC WIZARDS_WINS("Supreme Wizard", 600, new String[]{"Wizards.Wins"}, @@ -834,7 +871,7 @@ public enum Achievement new int[]{15}, AchievementCategory.GLADIATORS), - TYPE_WARS_SPEED_DEMON("Speed Demon", 1000, + /*TYPE_WARS_SPEED_DEMON("Speed Demon", 1000, new String[]{"Type Wars.Demon"}, new String[]{"Kill 5 Mobs in 8 seconds", "by typing"}, new int[]{1}, @@ -868,7 +905,7 @@ public enum Achievement new String[]{"Type Wars.Wins"}, new String[]{"Win 30 Games"}, new int[]{30}, - AchievementCategory.TYPE_WARS), + AchievementCategory.TYPE_WARS),*/ SPEED_BUILDERS_SPEED_MASTER("Speed Master", 800, new String[]{"Speed Builders.Wins"}, diff --git a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java index ca55d520f..e6f445aa4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/achievement/AchievementCategory.java @@ -6,6 +6,7 @@ import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilTime; +import mineplex.core.game.GameCategory; import mineplex.core.game.GameDisplay; import mineplex.core.stats.PlayerStats; import mineplex.core.stats.StatsManager; @@ -48,6 +49,10 @@ public enum AchievementCategory UHC("Ultra Hardcore", null, new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, Material.GOLDEN_APPLE, 0, GameCategory.SURVIVAL, "None"), + + MC_LEAGUE("MC League", null, + new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, + Material.IRON_CHESTPLATE, 0, GameCategory.SURVIVAL, "None"), WIZARDS("Wizards", null, new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, @@ -155,9 +160,9 @@ public enum AchievementCategory new StatDisplay[] { StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.KILLS, StatDisplay.DEATHS, StatDisplay.GEMS_EARNED }, Material.IRON_SWORD, 0, GameCategory.ARCADE, null), - TYPE_WARS("Type Wars", null, + /*TYPE_WARS("Type Wars", null, new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, new StatDisplay("Minions killed", "MinionKills"), new StatDisplay("Words Per Minute", false, true, "MinionKills", "TimeInGame"), StatDisplay.GEMS_EARNED}, - Material.NAME_TAG, 0, GameCategory.CLASSICS, null), + Material.NAME_TAG, 0, GameCategory.CLASSICS, null),*/ SPEED_BUILDERS("Speed Builders", null, new StatDisplay[] {StatDisplay.WINS, StatDisplay.GAMES_PLAYED, StatDisplay.GEMS_EARNED, null, new StatDisplay("Perfect Builds", "PerfectBuild")}, diff --git a/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java b/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java index 31c8f24d7..b950fb05e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/explosion/Explosion.java @@ -9,14 +9,13 @@ import java.util.Map.Entry; import java.util.UUID; import mineplex.core.MiniPlugin; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.updater.UpdateType; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import org.bukkit.Effect; import org.bukkit.Location; @@ -32,7 +31,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; -import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -234,7 +232,7 @@ public class Explosion extends MiniPlugin fallingIterator.remove(); //Expire - if (cur.getTicksLived() > 400 || !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4)) + if (cur.getTicksLived() > 100 || !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4)) { cur.remove(); return; @@ -362,4 +360,16 @@ public class Explosion extends MiniPlugin } }, 1); } + + public void setEnabled(boolean var) + { + if (var) + { + registerSelf(); + } + else + { + deregisterSelf(); + } + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java index d14d5c35b..30589266e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/GameDisplay.java @@ -69,14 +69,17 @@ public enum GameDisplay Lobbers("Bomb Lobbers", Material.FIREBALL, (byte) 0, GameCategory.ARCADE, 54), + Minecraft_League("MC League", Material.DIAMOND_SWORD, (byte)0, GameCategory.SURVIVAL, 62), + ChampionsCTF("Champions CTF", "Champions", Material.BANNER, DyeColor.RED.getDyeData(), GameCategory.CHAMPIONS, 56), + BouncyBalls("Bouncy Balls", Material.SLIME_BALL, (byte)0, GameCategory.ARCADE, 57), Gladiators("Gladiators", Material.IRON_SWORD, (byte)0, GameCategory.ARCADE, 58), TypeWars("Type Wars", Material.NAME_TAG, (byte) 0, GameCategory.CLASSICS, 59), SpeedBuilders("Speed Builders", Material.QUARTZ_BLOCK, (byte) 0, GameCategory.CLASSICS, 60), - Valentines("Valentines Vendetta", Material.LEATHER, (byte)0, GameCategory.EXTRA, 60), + Valentines("Valentines Vendetta", Material.LEATHER, (byte)0, GameCategory.EXTRA, 61), Event("Mineplex Event", Material.CAKE, (byte)0, GameCategory.EVENT, 999); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/map/TeamMap.java b/Plugins/Mineplex.Core/src/mineplex/core/map/TeamMap.java new file mode 100644 index 000000000..d7336ae21 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/map/TeamMap.java @@ -0,0 +1,106 @@ +package mineplex.core.map; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilPlayer; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.map.MapView; +import org.bukkit.map.MapView.Scale; + +public class TeamMap +{ + List _players; + final ItemStack _map; + + public TeamMap(List display, Location loc, Scale scale) + { + _players = display; + MapView view = Bukkit.createMap(loc.getWorld()); + view.setCenterX(loc.getBlockX()); + view.setCenterZ(loc.getBlockZ()); + view.setScale(scale); + + _map = new ItemStack(Material.MAP); + _map.setDurability(view.getId()); + } + + public void update(Player... forceRemove) + { + if (forceRemove != null) + { + for (Player remove : forceRemove) + { + _players.remove(remove); + } + } + + List confirmed = new ArrayList(); + + for (Player check : _players) + { + if (!UtilPlayer.isOnline(check.getName())) + continue; + + if (UtilPlayer.isSpectator(check)) + continue; + + confirmed.add(check); + } + + _players.clear(); + for (Player add : confirmed) + _players.add(add); + } + + public void giveMaps() + { + update(null); + + for (Player player : _players) + { + UtilInv.insert(player, _map); + UtilInv.Update(player); + } + } + + public void giveMap(Player player) + { + giveMap(player, true, ""); + } + + public void giveMap(Player player, boolean add, String displayName, String... lore) + { + if (!_players.contains(player)) + { + if (add) + { + _players.add(player); + } + } + + ItemStack map = _map.clone(); + ItemMeta im = map.getItemMeta(); + if (!displayName.equalsIgnoreCase("")) + im.setDisplayName(displayName); + + List lores = new ArrayList(); + for (String s : lore) + lores.add(s); + + if (!lores.isEmpty()) + im.setLore(lores); + + map.setItemMeta(im); + + UtilInv.insert(player, map); + UtilInv.Update(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java index 33e1b397a..8385f00a7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java @@ -226,7 +226,7 @@ public class MessageManager extends MiniClientPlugin Get(from).LastToTime = System.currentTimeMillis(); // Chiss or defek7 - if (to.getName().equals("Chiss") || to.getName().equals("defek7") || to.getName().equals("Phinary") || to.getName().equals("fooify") || to.getName().equals("sampepere")) + if (to.getName().equals("Chiss") || to.getName().equals("defek7") || to.getName().equals("Phinary") || to.getName().equals("AlexTheCoder")) { UtilPlayer.message(from, C.cPurple + to.getName() + " is often AFK or minimized, due to plugin development."); UtilPlayer.message(from, C.cPurple + "Please be patient if he does not reply instantly."); diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/combat/CombatManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/combat/CombatManager.java index b42ae087d..e8cd54e15 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/combat/CombatManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/combat/CombatManager.java @@ -3,6 +3,7 @@ package mineplex.minecraft.game.core.combat; import java.util.HashSet; import java.util.Iterator; +import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.entity.Arrow; import org.bukkit.entity.Fireball; @@ -89,11 +90,53 @@ public class CombatManager extends MiniPlugin { if (damagerEnt instanceof Player) Get((Player)damagerEnt).SetLastCombat(System.currentTimeMillis()); + + String cause = ""; + switch(event.getCause()) + { + case ENTITY_ATTACK: + cause = "Attack"; + break; + case ENTITY_EXPLOSION: + cause = "Explosion"; + break; + case MAGIC: + cause = "Thrown Potion"; + break; + case PROJECTILE: + cause = "Ranged Weapon"; + break; + case THORNS: + cause = "Thorns Enchantment"; + break; + default: + cause = event.getCause() + ""; + break; + } + + if (UtilEvent.isBowDamage(event)) + { + cause = "Bow"; + } + + if (damagerEnt instanceof Player) + { + if (event.getCause() == DamageCause.ENTITY_ATTACK) + { + Player player = (Player) damagerEnt; + if (player.getItemInHand() == null) + cause = "Fists"; + else if (player.getItemInHand().getType() == Material.AIR) + cause = "Fists"; + else + cause = ItemStackFactory.Instance.GetName(player.getItemInHand(), false); + } + } Get(damagee).Attacked( UtilEnt.getName(damagerEnt), event.getDamage(), damagerEnt, - event.getCause() + "", null); + cause, null); } // Damager is WORLD else diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java index 67b2ba1f3..de559f25b 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/damage/DamageManager.java @@ -692,6 +692,11 @@ public class DamageManager extends MiniPlugin return null; } + + public boolean IsEnabled() + { + return _enabled; + } public void SetEnabled(boolean var) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index 08553888b..f2c27d4b8 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -58,6 +58,7 @@ import mineplex.core.velocity.VelocityFix; import mineplex.core.visibility.VisibilityManager; import mineplex.minecraft.game.core.combat.CombatManager; import mineplex.minecraft.game.core.damage.DamageManager; +import nautilus.game.arcade.broadcast.BroadcastManager; import nautilus.game.arcade.game.GameServerConfig; import net.minecraft.server.v1_8_R3.BiomeBase; import net.minecraft.server.v1_8_R3.MinecraftServer; @@ -161,6 +162,8 @@ public class Arcade extends JavaPlugin PollManager pollManager = new PollManager(this, _clientManager, _donationManager); _gameManager = new ArcadeManager(this, serverStatusManager, ReadServerConfig(), _clientManager, _donationManager, _damageManager, statsManager, incognito, achievementManager, disguiseManager, creature, teleport, new Blood(this), chat, portal, preferenceManager, inventoryManager, packetHandler, cosmeticManager, projectileManager, petManager, hologramManager, webServerAddress, pollManager, npcmanager, customDataManager, punish); + //new BroadcastManager(this, _gameManager); + new MemoryFix(this); new CustomTagFix(this, packetHandler); new PacketsInteractionFix(this, packetHandler); @@ -253,6 +256,11 @@ public class Arcade extends JavaPlugin return config; } + + public ArcadeManager getArcadeManager() + { + return _gameManager; + } private void DeleteFolders() { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index 6dd245b99..c642dee43 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -199,6 +199,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation // Observers private HashSet _specList = new HashSet(); + private HashSet _fakeObserve = new HashSet(); // Server Games private GameServerConfig _serverConfig; @@ -1139,14 +1140,22 @@ public class ArcadeManager extends MiniPlugin implements IRelation { _specList.remove(event.getPlayer()); } + + public void toggleFakeObserver(Player player) + { + if (!_fakeObserve.remove(player)) + _fakeObserve.add(player); + } public boolean IsObserver(Player player) { + if (_fakeObserve.contains(player)) + return true; + if (_incognitoManager.Get(player).Status) { _specList.add(player); } - return _specList.contains(player); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java index 41dcec1e4..1b70d41d0 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameType.java @@ -38,6 +38,7 @@ import nautilus.game.arcade.game.games.horsecharge.Horse; import nautilus.game.arcade.game.games.lobbers.BombLobbers; import nautilus.game.arcade.game.games.micro.Micro; import nautilus.game.arcade.game.games.milkcow.MilkCow; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; import nautilus.game.arcade.game.games.minestrike.MineStrike; import nautilus.game.arcade.game.games.mineware.MineWare; import nautilus.game.arcade.game.games.monsterleague.MonsterLeague; @@ -120,6 +121,7 @@ public enum GameType Pair.create(MinecraftVersion.Version1_9, "http://chivebox.com/mineplex/ResMinestrike19.zip") }, true), MineWare(MineWare.class, GameDisplay.MineWare), + MinecraftLeague(MinecraftLeague.class, GameDisplay.Minecraft_League), OldMineWare(OldMineWare.class, GameDisplay.OldMineWare), Paintball(Paintball.class, GameDisplay.Paintball), Quiver(Quiver.class, GameDisplay.Quiver), @@ -203,6 +205,7 @@ public enum GameType GameType(Class gameClass, GameDisplay display, Pair[] resourcePackUrls, boolean enforceResourcePack, GameType[] mapSource, boolean ownMaps) { _display = display; + _gameId = display.getGameId(); _gameClass = gameClass; _resourcePacks = resourcePackUrls; _enforceResourcePack = enforceResourcePack; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java new file mode 100644 index 000000000..fe4b389da --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastData.java @@ -0,0 +1,97 @@ +package nautilus.game.arcade.broadcast; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.F; +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 net.minecraft.server.v1_8_R3.PacketPlayOutCamera; + +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; +import org.bukkit.entity.Player; + +public class BroadcastData +{ + private Player _player; + private BroadcastManager _plugin; + + private boolean _rotate; + + private List _gamePlayers; + private List _recentlyViewed; + private Player _currentlyViewing; + + public BroadcastData(Player player, BroadcastManager plugin) + { + _player = player; + _plugin = plugin; + + _recentlyViewed = new ArrayList(); + + setRotating(false); + } + + private void setRotating(boolean rotate) + { + _rotate = rotate; + UtilPlayer.message(_player, F.main(_plugin.getName(), "Player Rotation: " + rotate)); + } + + public boolean isRotating() + { + return _rotate; + } + + public Player currentView() + { + return _currentlyViewing; + } + + public Player nextPlayer() + { + if (_gamePlayers.size() == _recentlyViewed.size()) + _recentlyViewed.clear(); + + for (Player player : _gamePlayers) + { + if (!player.isOnline() || !player.isValid() || player.isDead()) + continue; + + if (!_recentlyViewed.contains(player)) + return player; + } + + return null; + } + + public void toggleRotating(List gamePlayers) + { + if (!isRotating()) + { + if (gamePlayers == null) + return; + + if (gamePlayers.size() == 0) + return; + + _gamePlayers = gamePlayers; + } + if (isRotating()) + { + PacketPlayOutCamera restore = new PacketPlayOutCamera((net.minecraft.server.v1_8_R3.Entity)_player); + ((CraftPlayer)_player).getHandle().playerConnection.sendPacket(restore); + } + setRotating(!isRotating()); + } + + public void goToNext(Player player) + { + Recharge.Instance.useForce(_player, "Broadcaster Rotation", UtilTime.convert(10, TimeUnit.SECONDS, TimeUnit.MILLISECONDS), false); + _currentlyViewing = player; + PacketPlayOutCamera view = new PacketPlayOutCamera((net.minecraft.server.v1_8_R3.Entity)player); + ((CraftPlayer)_player).getHandle().playerConnection.sendPacket(view); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java new file mode 100644 index 000000000..d3693e598 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/BroadcastManager.java @@ -0,0 +1,120 @@ +package nautilus.game.arcade.broadcast; + +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.MiniPlugin; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.Game.GameState; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.plugin.java.JavaPlugin; + +public class BroadcastManager extends MiniPlugin +{ + ArcadeManager ArcadeManager; + private ConcurrentHashMap _broadcasters; + + public BroadcastManager(JavaPlugin plugin, ArcadeManager manager) + { + super("Broadcasting Manager", plugin); + ArcadeManager = manager; + _broadcasters = new ConcurrentHashMap(); + } + + public boolean isBroadcaster(Player player) + { + return _broadcasters.containsKey(player); + } + + public void addBroadcaster(Player player) + { + _broadcasters.put(player, new BroadcastData(player, this)); + if (ArcadeManager.GetGame() != null) + { + ArcadeManager.GetGame().RemoveTeamPreference(player); + ArcadeManager.GetGame().GetPlayerKits().remove(player); + ArcadeManager.GetGame().GetPlayerGems().remove(player); + try + { + ArcadeManager.GetGame().GetTeam(player).RemovePlayer(player); + } + catch (Exception e) {} + ArcadeManager.Clear(player); + ArcadeManager.toggleFakeObserver(player); + } + player.getInventory().clear(); + player.setGameMode(GameMode.SPECTATOR); + } + + public void removeBroadcaster(Player player) + { + _broadcasters.remove(player); + ArcadeManager.toggleFakeObserver(player); + if (ArcadeManager.GetGame().InProgress()) + ArcadeManager.addSpectator(player, true); + player.setGameMode(GameMode.SURVIVAL); + } + + @EventHandler + public void handleBroadcasting(GameStateChangeEvent event) + { + if (event.GetState() == GameState.Dead) + { + for (BroadcastData data : _broadcasters.values()) + { + if (data.isRotating()) + data.toggleRotating(null); + } + _broadcasters.clear(); + } + } + + @EventHandler + public void handleRotation(UpdateEvent event) + { + if (event.getType() == UpdateType.FASTEST) + { + Game game = ArcadeManager.GetGame(); + if (game == null) + return; + if (!game.InProgress()) + return; + + for (Player player : _broadcasters.keySet()) + { + if (!Recharge.Instance.usable(player, "Broadcaster Rotation", false)) + continue; + } + } + } + + @EventHandler + public void handleRotation(PlayerQuitEvent event) + { + Game game = ArcadeManager.GetGame(); + if (game == null) + return; + if (!game.InProgress()) + return; + + if (_broadcasters.containsKey(event.getPlayer())) + _broadcasters.remove(event.getPlayer()); + + for (BroadcastData data : _broadcasters.values()) + { + if (data.currentView() == null) + continue; + + if (data.currentView() == event.getPlayer()); + data.goToNext(data.nextPlayer()); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java new file mode 100644 index 000000000..49d4858d2 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/BroadcastCommand.java @@ -0,0 +1,33 @@ +package nautilus.game.arcade.broadcast.command; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.broadcast.BroadcastManager; +import nautilus.game.arcade.broadcast.command.manage.AddCommand; +import nautilus.game.arcade.broadcast.command.manage.RemoveCommand; + +import org.bukkit.entity.Player; + +public class BroadcastCommand extends MultiCommandBase +{ + public BroadcastCommand(BroadcastManager plugin) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.TWITCH, Rank.YOUTUBE, Rank.YOUTUBE_SMALL, Rank.JNR_DEV}, "broadcaster"); + AddCommand(new AddCommand(plugin)); + AddCommand(new RemoveCommand(plugin)); + AddCommand(new RotateCommand(plugin)); + } + + @Override + protected void Help(Player caller, String[] args) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "Commands List:")); + UtilPlayer.message(caller, F.help("/broadcaster add ", "Puts a player in Broadcast mode for this game", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/broadcaster remove ", "Takes a player out of Broadcast mode", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/broadcaster rotate", "Toggles rotating view between game players", Rank.TWITCH)); + UtilPlayer.message(caller, F.main("Tip", "Rotation is great for a background to commentary!")); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java new file mode 100644 index 000000000..b455ce4af --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/RotateCommand.java @@ -0,0 +1,21 @@ +package nautilus.game.arcade.broadcast.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.broadcast.BroadcastManager; + +public class RotateCommand extends CommandBase +{ + public RotateCommand(BroadcastManager plugin) { + super(plugin, Rank.TWITCH, "rotate"); + } + + @Override + public void Execute(Player caller, String[] args) + { + + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java new file mode 100644 index 000000000..ee67c8609 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/AddCommand.java @@ -0,0 +1,22 @@ +package nautilus.game.arcade.broadcast.command.manage; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.broadcast.BroadcastManager; + +public class AddCommand extends CommandBase +{ + public AddCommand(BroadcastManager plugin) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "add"); + } + + @Override + public void Execute(Player caller, String[] args) + { + + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java new file mode 100644 index 000000000..021202498 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/broadcast/command/manage/RemoveCommand.java @@ -0,0 +1,22 @@ +package nautilus.game.arcade.broadcast.command.manage; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.broadcast.BroadcastManager; + +public class RemoveCommand extends CommandBase +{ + public RemoveCommand(BroadcastManager plugin) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "remove"); + } + + @Override + public void Execute(Player caller, String[] args) + { + + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index 4d55ecf34..30f0bd51f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -893,7 +893,7 @@ public abstract class Game implements Listener public void RespawnPlayer(final Player player) { player.eject(); - player.teleport(GetTeam(player).GetSpawn()); + RespawnPlayerTeleport(player); Manager.Clear(player); @@ -910,6 +910,11 @@ public abstract class Game implements Listener } }, 0); } + + public void RespawnPlayerTeleport(Player player) + { + player.teleport(GetTeam(player).GetSpawn()); + } public boolean IsPlaying(Player player) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/DataLoc.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/DataLoc.java new file mode 100644 index 000000000..8ca22140e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/DataLoc.java @@ -0,0 +1,42 @@ +package nautilus.game.arcade.game.games.minecraftleague; + +public enum DataLoc +{ + //Base + RED_CRYSTAL(" RED CRYSTAL"), + RED_TOWER(" RED TOWER"), + BLUE_CRYSTAL(" BLUE CRYSTAL"), + BLUE_TOWER(" BLUE TOWER"), + VARIANT_BASE("GAMEMODE "), + //RED_BEACON("PINK"), + /*BLUE_*/BEACON("CYAN"), + SKELETON_SPAWNER("BROWN"), + //MAP_DIAMOND("LIGHT_BLUE"), + //MAP_IRON("SILVER"), + RED_ORE("15"), + BLUE_ORE("14"), + DIAMOND_ORE("56"), + COAL_ORE("16"), + MOSH_IRON("129"), + GRIND_AREA(" GRIND"), + + //Wither + WITHER_WAYPOINT("PURPLE"), + TOWER_WAYPOINT(" $team$ WITHER $number$"), + WITHER_SKELETON("BLACK"), + BLUE_ALTAR("LIME"), + RED_ALTAR("YELLOW") + ; + + private String _key; + + private DataLoc(String key) + { + _key = key; + } + + public String getKey() + { + return _key; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/MinecraftLeague.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/MinecraftLeague.java new file mode 100644 index 000000000..9c2f29fd0 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/MinecraftLeague.java @@ -0,0 +1,1984 @@ +package nautilus.game.arcade.game.games.minecraftleague; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.Rank; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.message.PrivateMessageEvent; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.combat.DeathMessageType; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.events.PlayerDeathOutEvent; +import nautilus.game.arcade.events.PlayerGameRespawnEvent; +import nautilus.game.arcade.events.PlayerPrepareTeleportEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.minecraftleague.commands.MinecraftLeagueCommand; +import nautilus.game.arcade.game.games.minecraftleague.commands.freeze.FreezeManager; +import nautilus.game.arcade.game.games.minecraftleague.data.BlockProtection; +import nautilus.game.arcade.game.games.minecraftleague.data.MapZone; +import nautilus.game.arcade.game.games.minecraftleague.data.Spawner; +import nautilus.game.arcade.game.games.minecraftleague.data.TeamBeacon; +import nautilus.game.arcade.game.games.minecraftleague.data.TeamCrystal; +import nautilus.game.arcade.game.games.minecraftleague.data.TeamTowerBase; +import nautilus.game.arcade.game.games.minecraftleague.data.TowerAlert; +import nautilus.game.arcade.game.games.minecraftleague.data.TowerManager; +import nautilus.game.arcade.game.games.minecraftleague.data.map.ItemMapManager; +import nautilus.game.arcade.game.games.minecraftleague.kit.KitPlayer; +import nautilus.game.arcade.game.games.minecraftleague.tracker.AltarBuilderTracker; +import nautilus.game.arcade.game.games.minecraftleague.tracker.FirstStrikeTracker; +import nautilus.game.arcade.game.games.minecraftleague.tracker.HeadHunterTracker; +import nautilus.game.arcade.game.games.minecraftleague.tracker.SavingUpTracker; +import nautilus.game.arcade.game.games.minecraftleague.tracker.TowerDefenderTracker; +import nautilus.game.arcade.game.games.minecraftleague.variation.ExtraScoreboardData; +import nautilus.game.arcade.game.games.minecraftleague.variation.GameVariation; +import nautilus.game.arcade.game.games.minecraftleague.variation.VariationManager; +import nautilus.game.arcade.kit.Kit; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Furnace; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Enderman; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.ItemFrame; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.FurnaceBurnEvent; +import org.bukkit.event.inventory.FurnaceSmeltEvent; +import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.inventory.PrepareItemCraftEvent; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.material.Dispenser; +import org.bukkit.material.MaterialData; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.google.common.base.Objects; + +public class MinecraftLeague extends TeamGame +{ + //private ConcurrentHashMap _customRespawns = new ConcurrentHashMap(); + //private ConcurrentHashMap _maps = new ConcurrentHashMap(); + private ConcurrentHashMap> _gear = new ConcurrentHashMap>(); + public ConcurrentHashMap Beacons = new ConcurrentHashMap(); + //public ConcurrentHashMap TeamPoison = new ConcurrentHashMap(); + private ConcurrentHashMap _blockLock = new ConcurrentHashMap(); + //private ConcurrentHashMap _spawnAllow = new ConcurrentHashMap(); + private List _spawners = new ArrayList(); + private List _noFall = new ArrayList(); + + private static final String[] PERM_OP = new String[] {"SamitoD", "Relyh", "AlexTheCoder"}; + + public ConcurrentHashMap ExtraSb = new ConcurrentHashMap(); + + private long _liveTime = 0; + private MinecraftLeagueCommand _cmd; + private long _lastIncrease; + private long _lastOreReset; + private long _lastGrindReset; + private boolean _yellow = false; + + public List MapZones = new ArrayList(); + public ItemMapManager MapManager; + public boolean OverTime = false; + + private VariationManager _vman; + //public ObjectiveManager Objective; + private FreezeManager _freeze; + private TowerManager _tower; + public TowerAlert Alert; + public boolean ScoreboardAutoWrite = true; + + //private final EntityType[] _passive = new EntityType[] {EntityType.CHICKEN, EntityType.COW, EntityType.PIG, EntityType.RABBIT, EntityType.SHEEP}; + + public MinecraftLeague(ArcadeManager manager) + { + super(manager, GameType.MinecraftLeague, + + new Kit[] + { + new KitPlayer(manager) + }, + + new String[] + { + C.cWhite + "Gather resources for battle.", + C.cWhite + "Destroy all of the enemy's Towers to", + C.cWhite + "Defeat them and win the game!", + " ", + C.cWhite + "Last team with Towers alive wins", + }); + + this.EloRanking = true; + this.DeathOut = true; + this.DamageSelf = false; + this.DeathSpectateSecs = 10; + this.WorldBoundaryKill = true; + this.DeathDropItems = true; + this.CreatureAllow = false; + this.HungerSet = 20; + + this.BlockBreak = true; + this.BlockPlace = true; + this.ItemPickup = true; + this.ItemDrop = true; + + this.InventoryClick = true; + this.InventoryOpenBlock = true; + this.InventoryOpenChest = true; + + this.WorldWeatherEnabled = true; + this.WorldBlockBurn = true; + this.WorldBlockGrow = true; + this.WorldBoneMeal = true; + this.WorldFireSpread = true; + this.WorldLeavesDecay = true; + this.WorldSoilTrample = true; + + this.StrictAntiHack = true; + this.AllowParticles = false; + this.SoupEnabled = false; + this.GameTimeout = -1; + + _help = new String[] + { + "Towers have 150 health per person in-game!", + "The better the sword you have, the more damage you deal to Towers!", + //"Right-click a bed in order to change your personal spawn location!", + "Your map will display the locations of your enemies in OverTime!" + }; + + + registerStatTrackers( + new AltarBuilderTracker(this), + new FirstStrikeTracker(this), + new HeadHunterTracker(this), + new TowerDefenderTracker(this, 2, 8000, "TowerDefender"), + new SavingUpTracker(this) + ); + + _vman = new VariationManager(this); + //Objective = new ObjectiveManager(this); + _freeze = new FreezeManager(); + _tower = new TowerManager(this); + Alert = new TowerAlert(); + Bukkit.getPluginManager().registerEvents(_freeze, manager.getPlugin()); + } + + private enum DamageAmount + { + NONE(1), + WOOD(4), + STONE(5), + GOLD(4), + IRON(6), + DIAMOND(7); + + private double _amount; + + private DamageAmount(int amount) + { + _amount = amount; + } + + public double getDamage(int sharpnessLevel, DamageType type) + { + if (type.getDamageReduction() == null) + return 1; + + return _amount + (sharpnessLevel / 2) - type.getDamageReduction(); + } + + public static DamageAmount getDamageAmount(Material material) + { + for (DamageAmount da : DamageAmount.values()) + { + if (da == DamageAmount.NONE) + continue; + + if (material.toString().contains(da.toString() + "_")) + return da; + } + + return DamageAmount.NONE; + } + } + + private enum DamageType + { + NONE(null), + PICKAXE(2), + AXE(1), + SWORD(0), + SPADE(3); + + private Integer _reduction; + + private DamageType(Integer reduction) + { + _reduction = reduction; + } + + public Integer getDamageReduction() + { + return _reduction; + } + + public static DamageType getDamageType(Material material) + { + for (DamageType dt : DamageType.values()) + { + if (dt == DamageType.NONE) + continue; + + if (material.toString().contains("_" + dt.toString())) + return dt; + } + + return DamageType.NONE; + } + } + + private ItemStack getNewItemStack(ItemStack item) + { + ItemStack ret = item.clone(); + /*String type = ret.getType().toString(); + boolean damage = false; + boolean itemD = false; + if (type.contains("HELMET") || type.contains("CHESTPLATE") || type.contains("LEGGINGS") || type.contains("BOOTS")) + damage = true; + if (DamageType.getDamageType(ret.getType()) != DamageType.NONE) + itemD = true; + + if (damage) + { + ret.setDurability((short) (ret.getDurability() + (ret.getDurability() * .25))); + } + if (itemD) + { + ret.setDurability((short) (ret.getDurability() + 25)); + } + + if (ret.getDurability() > ret.getType().getMaxDurability()) + ret = new ItemStack(Material.AIR);*/ + + if (ret.getType() == Material.MAP) + ret = new ItemStack(Material.AIR); + if (UtilItem.isTool(ret)) + ret = new ItemStack(ret.getType()); + + return ret; + } + + private int getSwordLevel(ItemStack sword) + { + if (UtilItem.isSword(sword)) + { + //if (UtilItem.isDiamondProduct(sword)) + //return 5; + if (UtilItem.isIronProduct(sword)) + return 4; + if (UtilItem.isGoldProduct(sword)) + return 3; + if (UtilItem.isStoneProduct(sword)) + return 2; + if (UtilItem.isWoodProduct(sword)) + return 1; + } + + return 0; + } + + private int getPickLevel(ItemStack sword) + { + if (UtilItem.isPickaxe(sword)) + { + //if (UtilItem.isDiamondProduct(sword)) + //return 5; + if (UtilItem.isIronProduct(sword)) + return 4; + if (UtilItem.isGoldProduct(sword)) + return 3; + if (UtilItem.isStoneProduct(sword)) + return 2; + if (UtilItem.isWoodProduct(sword)) + return 1; + } + + return 0; + } + + private ItemStack getBestSword(Player player) + { + ItemStack ret = new ItemStack(Material.AIR); + int level = 0; + + for (ItemStack item : UtilInv.getItems(player, false, true, false)) + { + if (UtilItem.isSword(item)) + { + if (getSwordLevel(item) > level) + { + ret = item; + level = getSwordLevel(item); + } + } + } + + return ret; + } + + private ItemStack getBestPick(Player player) + { + ItemStack ret = new ItemStack(Material.AIR); + int level = 0; + + for (ItemStack item : UtilInv.getItems(player, false, true, false)) + { + if (UtilItem.isPickaxe(item)) + { + if (getPickLevel(item) > level) + { + ret = item; + level = getPickLevel(item); + } + } + } + + return ret; + } + + public List getMapVariantIDS() + { + List ids = new ArrayList(); + for (String s : WorldData.GetAllCustomLocs().keySet()) + { + if (s.contains(DataLoc.VARIANT_BASE.getKey())) + ids.add(s); + } + return ids; + } + + public TeamTowerBase getActiveTower(GameTeam team) + { + return _tower.getVulnerable(team); + } + + public TowerManager getTowerManager() + { + return _tower; + } + + public FreezeManager getFreezeManager() + { + return _freeze; + } + + /*public TeamMap getMap(GameTeam team) + { + return _maps.get(team); + }*/ + + @Override + public void ParseData() + { + _tower.parseTowers(WorldData); + + //_beacons.put(GetTeam(ChatColor.RED), new TeamBeacon(GetTeam(ChatColor.RED), WorldData.GetDataLocs(DataLoc.RED_BEACON.getKey()).get(0).getBlock(), redLoc)); + //_beacons.put(GetTeam(ChatColor.AQUA), new TeamBeacon(GetTeam(ChatColor.AQUA), WorldData.GetDataLocs(DataLoc.BLUE_BEACON.getKey()).get(0).getBlock(), blueLoc)); + + for (Location loc : WorldData.GetDataLocs(DataLoc.SKELETON_SPAWNER.getKey())) + { + _spawners.add(new Spawner(this, loc, EntityType.SKELETON)); + } + + /*for (Location loc : WorldData.GetDataLocs(DataLoc.MAP_DIAMOND.getKey())) + { + Ore.add(new OreDeposit(loc, Material.DIAMOND_ORE, new int[] {0, 255, 255})); + } + for (Location loc : WorldData.GetDataLocs(DataLoc.MAP_IRON.getKey())) + { + Ore.add(new OreDeposit(loc, Material.IRON_ORE, new int[] {190, 190, 190})); + }*/ + + for (Location diamond : WorldData.GetCustomLocs(DataLoc.DIAMOND_ORE.getKey())) + { + diamond.getBlock().setType(Material.DIAMOND_ORE); + } + for (Location coal : WorldData.GetCustomLocs(DataLoc.COAL_ORE.getKey())) + { + coal.getBlock().setType(Material.COAL_ORE); + } + + MapManager = new ItemMapManager(this, WorldData.World, WorldData.MinX, WorldData.MinZ, WorldData.MaxX, WorldData.MaxZ); + + _vman.selectVariation(); + } + + @Override + @EventHandler + public void ScoreboardUpdate(UpdateEvent event) + { + if (!ScoreboardAutoWrite) + return; + + if (event.getType() == UpdateType.FAST || event.getType() == UpdateType.SEC) + scoreboardWrite(event.getType() == UpdateType.SEC); + } + + public void writeEndSb(String winner) + { + Scoreboard.Reset(); + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cDRedB + GetName()); + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cGoldB + "Winner:"); + Scoreboard.Write(winner); + + Scoreboard.Draw(); + } + + private void scoreboardWrite(boolean sec) + { + if (!InProgress()) + return; + + if (!IsLive()) + { + if (!sec) + return; + Scoreboard.Reset(); + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cDRedB + GetName()); + Scoreboard.WriteBlank(); + + if (_yellow) + { + Scoreboard.Write(C.cYellow + "Loading..."); + _yellow = false; + } + else + { + Scoreboard.Write("Loading..."); + _yellow = true; + } + + Scoreboard.Draw(); + return; + } + + if (sec) + return; + + GameTeam red = GetTeam(ChatColor.RED); + GameTeam blue = GetTeam(ChatColor.AQUA); + String reds = ""; + String blues = ""; + for (TeamTowerBase tb : _tower.getTeamTowers(red)) + { + if (!reds.equalsIgnoreCase("")) + reds = reds + " "; + + String symbol = "♛"; + if (tb instanceof TeamCrystal) + symbol = "♚"; + + reds = reds + tb.getHealthColor() + symbol; + } + for (TeamTowerBase tb : _tower.getTeamTowers(blue)) + { + if (!blues.equalsIgnoreCase("")) + blues = blues + " "; + + String symbol = "♛"; + if (tb instanceof TeamCrystal) + symbol = "♚"; + + blues = blues + tb.getHealthColor() + symbol; + } + + _liveTime = Math.max(System.currentTimeMillis() - GetStateTime(), 0); + + Scoreboard.Reset(); + + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cRedB + "Red Team"); + Scoreboard.Write("Towers: " + reds); + for (String s : _vman.getSelected().getTeamScoreboardAdditions(red)) + { + Scoreboard.Write(s); + } + + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cAquaB + "Blue Team"); + Scoreboard.Write("Towers: " + blues); + for (String s : _vman.getSelected().getTeamScoreboardAdditions(blue)) + { + Scoreboard.Write(s); + } + + int i = 1; + for (ExtraScoreboardData sbD : ExtraSb.keySet()) + { + Scoreboard.WriteBlank(); + sbD.write(); + if (i < ExtraSb.size()) + Scoreboard.WriteBlank(); + i++; + } + + Scoreboard.WriteBlank(); + Scoreboard.Write(C.cYellowB + "Time Elapsed"); + Scoreboard.Write(UtilTime.MakeStr(_liveTime)); + if (OverTime) + Scoreboard.Write(C.cDRedB + "Overtime"); + + Scoreboard.Draw(); + } + + /*@Override + public void RespawnPlayerTeleport(Player player) + { + if (_customRespawns.containsKey(player)) + { + PlayerRespawnPoint point = _customRespawns.get(player); + if (point.respawnPlayer()) + return; + + _customRespawns.remove(player); + } + + player.teleport(GetTeam(player).GetSpawn()); + }*/ + + public boolean handleCommand(Player caller) + { + for (GameTeam team : GetTeamList()) + { + TeamTowerBase tower = _tower.getTeamTowers(team).getLast(); + UtilPlayer.message(caller, team.GetColor() + team.GetName()); + UtilPlayer.message(caller, C.cGray + "Health: " + tower.getHealth()); + UtilPlayer.message(caller, C.cGray + "Alive: " + tower.Alive); + } + + return true; + } + + public void restoreGear(Player player) + { + if (!_gear.containsKey(player)) + return; + List items = _gear.get(player); + for (int i = 0; i < 4; i++) + { + ItemStack item; + if (items.get(i) != null) + item = items.get(i); + else + item = new ItemStack(Material.AIR); + + switch(i + 1) + { + case 1: + player.getInventory().setHelmet(getNewItemStack(item)); + break; + case 2: + player.getInventory().setChestplate(getNewItemStack(item)); + break; + case 3: + player.getInventory().setLeggings(getNewItemStack(item)); + break; + case 4: + player.getInventory().setBoots(getNewItemStack(item)); + break; + } + } + for (int i = 4; i < items.size(); i++) + { + if (items.get(i) == null) + UtilInv.insert(player, new ItemStack(Material.AIR)); + else + UtilInv.insert(player, getNewItemStack(items.get(i))); + } + _gear.remove(player); + } + + @EventHandler + public void onEditSettings(GameStateChangeEvent event) + { + if (event.GetGame() != this) + return; + + if (event.GetState() == GameState.Live) + { + _lastIncrease = System.currentTimeMillis(); + _lastOreReset = System.currentTimeMillis(); + _lastGrindReset = System.currentTimeMillis() - UtilTime.convert(30, TimeUnit.SECONDS, TimeUnit.MILLISECONDS); + Manager.GetExplosion().setEnabled(false); + Manager.GetExplosion().SetTemporaryDebris(false); + Manager.GetExplosion().SetDebris(true); + Manager.GetDamage().SetEnabled(false); + Manager.GetCreature().SetForce(false); + Manager.GetCreature().SetDisableCustomDrops(true); + _cmd = new MinecraftLeagueCommand(Manager, this); + Manager.addCommand(_cmd); + Manager.getGameChatManager().TeamSpy = false; + //Objective.setMainObjective(new GearObjective()); + } + + if (event.GetState() == GameState.End) + { + Manager.GetExplosion().setEnabled(true); + Manager.GetExplosion().SetDebris(false); + Manager.GetExplosion().SetTemporaryDebris(true); + Manager.GetDamage().SetEnabled(true); + Manager.GetCreature().SetForce(false); + Manager.GetCreature().SetDisableCustomDrops(false); + Manager.removeCommand(_cmd); + Manager.getGameChatManager().TeamSpy = true; + HandlerList.unregisterAll(MapManager); + HandlerList.unregisterAll(_freeze); + } + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!IsLive()) + return; + + if (event.getType() == UpdateType.SEC) + { + /*for (MapZone od : Ore) + { + od.update(); + }*/ + + for (Player player : GetTeam(ChatColor.RED).GetPlayers(true)) + { + for (ItemStack armor : player.getInventory().getArmorContents()) + { + if (UtilItem.isLeatherProduct(armor)) + { + LeatherArmorMeta im = (LeatherArmorMeta)armor.getItemMeta(); + im.setColor(Color.RED); + armor.setItemMeta(im); + } + } + } + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(true)) + { + for (ItemStack armor : player.getInventory().getArmorContents()) + { + if (UtilItem.isLeatherProduct(armor)) + { + LeatherArmorMeta im = (LeatherArmorMeta)armor.getItemMeta(); + im.setColor(Color.BLUE); + armor.setItemMeta(im); + } + } + } + } + + /*if (event.getType() == UpdateType.FASTER) + { + for (GameTeam team : _teamList) + { + for (Location loc : team.GetSpawns()) + { + for (LivingEntity near : UtilEnt.getInRadius(loc, 2).keySet()) + { + if (!(near instanceof Player)) + continue; + Player player = (Player)near; + if (team.HasPlayer(player)) + { + if (_spawnAllow.containsKey(player)) + continue; + } + if (UtilPlayer.isSpectator(player)) + continue; + + Vector vec = UtilAlg.getTrajectory(loc, player.getLocation()); + + Location tpLoc = loc.add(vec.clone().multiply(8)); + tpLoc.setDirection(player.getLocation().getDirection()); + + //First tp out this combats hacked clients with anti-KB + player.teleport(tpLoc); + + //Then apply velocity as normal + UtilAction.velocity(player, vec, 1.8, false, 0, 0.4, vec.length(), false); + + player.playSound(player.getEyeLocation(), Sound.NOTE_PLING, 10F, 0.5F); + } + } + } + }*/ + + if (event.getType() == UpdateType.FASTEST) + { + _tower.update(); + + /*for (TeamMap map : _maps.values()) + { + map.update(null); + }*/ + + for (Spawner spawner : _spawners) + { + spawner.update(); + } + + for (TeamBeacon beacon : Beacons.values()) + { + beacon.update(); + } + + //Alert.update(); + + /*for (GameTeam dmg : TeamPoison.keySet()) + { + if (UtilTime.elapsed(TeamPoison.get(dmg), UtilTime.convert(1, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + TeamPoison.put(dmg, System.currentTimeMillis()); + for (Player player : dmg.GetPlayers(true)) + { + this.storeGear(player); + player.damage(1); + } + } + }*/ + + if (UtilTime.elapsed(_lastOreReset, UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS))) + { + _lastOreReset = System.currentTimeMillis(); + for (Location loc : WorldData.GetCustomLocs(DataLoc.COAL_ORE.getKey())) + { + loc.getBlock().setType(Material.COAL_ORE); + } + } + + if (!OverTime) + { + if (UtilTime.elapsed(GetStateTime(), UtilTime.convert(15, TimeUnit.MINUTES, TimeUnit.MILLISECONDS))) + { + OverTime = true; + UtilTextMiddle.display(C.cGold + "Overtime", C.cGold + "Dying will now cause your crystal to lose 50 health!"); + } + } + + if (UtilTime.elapsed(_lastIncrease, UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS))) + { + _lastIncrease = System.currentTimeMillis(); + this.DeathSpectateSecs = Math.min(20, this.DeathSpectateSecs + 2.5); + } + + if (UtilTime.elapsed(_lastGrindReset, UtilTime.convert(30, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + _lastGrindReset = System.currentTimeMillis(); + for (Location grind : WorldData.GetCustomLocs(DataLoc.GRIND_AREA.getKey())) + { + int spider = 0; + int chicken = 0; + for (LivingEntity le : UtilEnt.getInRadius(grind, 15).keySet()) + { + if (le.getType() == EntityType.SPIDER) + spider++; + if (le.getType() == EntityType.CHICKEN) + chicken++; + } + while (spider < 5) + { + spider = 5; + CreatureAllowOverride = true; + Manager.GetCreature().SpawnEntity(grind, EntityType.SPIDER); + CreatureAllowOverride = false; + } + while (chicken < 10) + { + chicken = 10; + CreatureAllowOverride = true; + Manager.GetCreature().SpawnEntity(grind, EntityType.CHICKEN); + CreatureAllowOverride = false; + } + } + } + + /*for (Player player : _spawnAllow.keySet()) + { + if (UtilTime.elapsed(_spawnAllow.get(player), UtilTime.convert(30, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + _spawnAllow.remove(player); + } + }*/ + + for (Player player : _blockLock.keySet()) + { + if (!player.isOnline()) + _blockLock.remove(player); + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + if (UtilPlayer.isSpectator(player)) + { + player.setFireTicks(-1); + player.setFoodLevel(20); + } + if (UtilInv.contains(player, Material.LAVA_BUCKET, (byte) 0, 1)) + { + UtilInv.insert(player, new ItemStack(Material.BUCKET, UtilInv.removeAll(player, Material.LAVA_BUCKET, (byte) 0))); + } + if (player.getOpenInventory().getType() == InventoryType.BEACON) + player.closeInventory(); + if (player.getFireTicks() > 20 * 4) + player.setFireTicks(20 * 4); + } + } + } + + @EventHandler + public void towerDmg(EntityDamageEvent event) + { + if (!InProgress()) + return; + + if (event.getEntity().getType() != EntityType.ENDER_CRYSTAL) + return; + + for (GameTeam team : GetTeamList()) + for (TeamTowerBase tower : _tower.getTeamTowers(team)) + { + if (tower.isEntity(event.getEntity())) + event.setCancelled(true); + } + } + + @EventHandler + public void towerDmg(EntityDamageByEntityEvent event) + { + if (!IsLive()) + return; + + if (event.getEntity().getType() != EntityType.ENDER_CRYSTAL) + return; + + TeamTowerBase tower = null; + for (GameTeam team : GetTeamList()) + for (TeamTowerBase tow : _tower.getTeamTowers(team)) + { + if (tow == null) + continue; + if (tow.isEntity(event.getEntity())) + tower = tow; + } + + if (tower == null) + return; + + event.setCancelled(true); + + Player player; + + if (event.getDamager() instanceof Projectile) + { + if (((Projectile)event.getDamager()).getShooter() instanceof Player) + { + if (event.getDamager() instanceof Arrow) + { + player = (Player) ((Projectile)event.getDamager()).getShooter(); + + if (!tower.canDamage(player)) + return; + + if (!tower.Vulnerable) + { + UtilPlayer.message(player, F.main("Game", "That Tower is protected by the power of another!")); + return; + } + + if (!tower.damage(event.getDamage() / 2, player)) + { + player.playSound(tower.getLocation(), Sound.ORB_PICKUP, 100, 0); + Alert.alert(tower.getTeam(), tower); + } + } + } + } + + if (event.getDamager() instanceof Player) + { + player = (Player)event.getDamager(); + if (!tower.canDamage(player)) + return; + + if (!tower.Vulnerable) + { + UtilPlayer.message(player, F.main("Game", "That Tower is protected by the power of another!")); + return; + } + + if (player.getItemInHand() == null || player.getItemInHand().getType() == Material.AIR) + { + if (!tower.damage(1, player)) + { + player.getWorld().playSound(tower.getLocation(), Sound.ZOMBIE_METAL, 1, 1.5f); + Alert.alert(tower.getTeam(), tower); + } + return; + } + + Material type = player.getItemInHand().getType(); + int level = player.getItemInHand().getEnchantmentLevel(Enchantment.DAMAGE_ALL); + double damage = DamageAmount.getDamageAmount(type).getDamage(level, DamageType.getDamageType(type)); + + if (!tower.damage(damage, player)) + { + player.getWorld().playSound(tower.getLocation(), Sound.ZOMBIE_METAL, 1, 1.5f); + Alert.alert(tower.getTeam(), tower); + } + + if (DamageAmount.getDamageAmount(type) != DamageAmount.NONE) + { + player.getItemInHand().setDurability((short) (player.getItemInHand().getDurability() + 1)); + if (player.getItemInHand().getDurability() > player.getItemInHand().getType().getMaxDurability()) + { + player.getInventory().remove(player.getItemInHand()); + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0); + } + UtilInv.Update(player); + } + } + } + + /*@EventHandler + public void placeBed(PlayerInteractEvent event) + { + if (!IsLive()) + return; + + if (event.getClickedBlock() == null) + return; + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + if (event.getClickedBlock().getType() != Material.BED_BLOCK) + return; + + event.setCancelled(true); + + Player player = event.getPlayer(); + if (_customRespawns.containsKey(player)) + _customRespawns.get(player).overWrite(event.getClickedBlock().getLocation()); + else + _customRespawns.put(player, new PlayerRespawnPoint(player, event.getClickedBlock().getLocation())); + }*/ + + private boolean isLocked(Block block) + { + for (BlockProtection prot : _blockLock.values()) + { + if (prot.hasBlock(block)) + return true; + } + return false; + } + + private Player getOwner(Block block) + { + for (Player player : _blockLock.keySet()) + { + if (_blockLock.get(player).hasBlock(block)) + return player; + } + + return null; + } + + private boolean isLockedTo(Block block, Player to, boolean ignoreTeam) + { + for (BlockProtection prot : _blockLock.values()) + { + if (prot.hasBlock(block)) + return prot.isLockedTo(to, block, ignoreTeam); + } + return false; + } + + private boolean isOwner(Block block, Player owner) + { + for (BlockProtection prot : _blockLock.values()) + { + if (prot.hasBlock(block)) + return prot.getOwner().getName().equalsIgnoreCase(owner.getName()); + } + return false; + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void lockBlock(BlockPlaceEvent event) + { + if (!IsLive()) + return; + + Block block = event.getBlock(); + if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST || block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE) + _blockLock.get(event.getPlayer()).lockBlock(block); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void unlockBlock(BlockBreakEvent event) + { + if (!IsLive()) + return; + + if (!isLocked(event.getBlock())) + return; + + if (!isLockedTo(event.getBlock(), event.getPlayer(), false)) + _blockLock.get(getOwner(event.getBlock())).unlockBlock(event.getBlock()); + else + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "That container is locked by " + getOwner(event.getBlock()).getName() + "!")); + event.setCancelled(true); + } + } + + @EventHandler + public void tryOpen(PlayerInteractEvent event) + { + if (!IsLive()) + return; + + if (event.getClickedBlock() == null) + return; + + if (UtilPlayer.isSpectator(event.getPlayer())) + { + event.setCancelled(true); + return; + } + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + Block block = event.getClickedBlock(); + + if (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST || block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE) + { + if (!isLocked(block)) + { + if (event.getPlayer().isSneaking()) + { + _blockLock.get(event.getPlayer()).lockBlock(block); + return; + } + } + + if (isLockedTo(event.getClickedBlock(), event.getPlayer(), false)) + { + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main("Game", "That container is locked by " + getOwner(event.getClickedBlock()).getName() + "!")); + return; + } + if (isOwner(event.getClickedBlock(), event.getPlayer())) + { + if (event.getPlayer().isSneaking()) + { + _blockLock.get(event.getPlayer()).unlockBlock(event.getClickedBlock()); + return; + } + } + } + } + + /*@EventHandler + public void breakBed(BlockBreakEvent event) + { + if (!IsLive()) + return; + + if (event.getBlock().getType() != Material.BED_BLOCK) + return; + + for (Player player : _customRespawns.keySet()) + { + PlayerRespawnPoint point = _customRespawns.get(player); + + if (point.breakBed(event.getBlock())) + _customRespawns.remove(player); + } + }*/ + + @EventHandler + public void onRespawn(PlayerGameRespawnEvent event) + { + if (event.GetGame() != this) + return; + + Player player = event.GetPlayer(); + + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5 * 20, 3)); + _noFall.add(player); + //_spawnAllow.put(player, System.currentTimeMillis()); + + /*if (!_crystals.get(GetTeam(player)).Alive) + { + SetPlayerState(player, PlayerState.OUT); + + Manager.GetCondition().Factory().Blind("PermDead", player, player, 1.5, 0, false, false, false); + Manager.GetCondition().Factory().Cloak("PermDead", player, player, 9999, false, false); + + player.setAllowFlight(true); + player.setFlying(true); + ((CraftPlayer)player).getHandle().spectating = true; + ((CraftPlayer)player).getHandle().k = false; + + UtilAction.velocity(player, new Vector(0,1.2,0)); + + getMap(GetTeam(player)).update(player); + player.getInventory().clear(); + player.getInventory().setArmorContents(new ItemStack[] + { + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + new ItemStack(Material.AIR), + new ItemStack(Material.AIR) + }); + return; + } + + if (_overTime) + _crystals.get(GetTeam(player)).damage(20, null);*/ + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) + { + if (!IsLive()) + return; + + ItemStack item = event.getItemDrop().getItemStack(); + + if (item.getType() != Material.MAP) + return; + + event.setCancelled(true); + UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot drop your team map!")); + } + + @EventHandler + public void preventMapMoveInventories(InventoryClickEvent event) + { + if (!IsLive()) + return; + + if (event.getWhoClicked() instanceof Player) + { + Player p = (Player)event.getWhoClicked(); + if (p.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) + return; + + if (p.getOpenInventory().getTopInventory().getType() == InventoryType.CREATIVE) + return; + } + + if (event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD || event.getAction() == InventoryAction.HOTBAR_SWAP) + { + ItemStack i = event.getWhoClicked().getInventory().getItem(event.getHotbarButton()); + if (i == null || i.getType() != Material.MAP) + return; + + event.setCancelled(true); + UtilPlayer.message(event.getWhoClicked(), F.main("Game", "You cannot store team maps inside containers!")); + return; + } + + Inventory inv = event.getClickedInventory(); + + if (inv == null) + return; + + for (ItemStack item : new ItemStack[] + { + event.getCurrentItem(), event.getCursor() + }) + { + if (item == null || item.getType() != Material.MAP) + continue; + + if (inv.getHolder() instanceof Player ? !event.isShiftClick() : Objects.equal(event.getCurrentItem(), item)) + continue; + + event.setCancelled(true); + + UtilPlayer.message(event.getWhoClicked(), F.main("Game", "You cannot store team maps inside containers!")); + return; + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDie(PlayerDeathEvent event) + { + if (!IsLive()) + return; + + event.getEntity().setHealth(event.getEntity().getMaxHealth()); + List newDrops = new ArrayList(); + Integer arrows = 0; + + for (ItemStack item : event.getDrops()) + { + if (item.getType() == Material.MAP) + continue; + + if (_gear.get(event.getEntity()) != null) + { + if (item.getType() == Material.ARROW) + { + arrows += item.getAmount(); + continue; + } + if (_gear.get(event.getEntity()).contains(item)) + continue; + } + + newDrops.add(item); + } + arrows = arrows / 2; + + while (arrows >= 1) + { + int subtract = Math.min(64, arrows); + newDrops.add(new ItemStack(Material.ARROW, subtract)); + arrows -= subtract; + } + + event.getDrops().clear(); + for (ItemStack item : newDrops) + event.getDrops().add(item); + } + + @EventHandler + public void preventMapInItemFrame(PlayerInteractEntityEvent event) + { + if (!IsLive()) + return; + + if (!(event.getRightClicked() instanceof ItemFrame)) + return; + + ItemStack item = event.getPlayer().getItemInHand(); + + if (item == null || item.getType() != Material.MAP) + return; + + event.setCancelled(true); + } + + @EventHandler + public void craftItem(PrepareItemCraftEvent event) + { + if (!IsLive()) + return; + + if (event.getInventory().getResult().getType() == Material.EMPTY_MAP || event.getInventory().getResult().getType() == Material.MAP) + event.getInventory().setResult(new ItemStack(Material.AIR)); + + if (UtilItem.isArmor(event.getInventory().getResult())) + { + event.getInventory().setResult(UtilItem.makeUnbreakable(event.getInventory().getResult())); + } + if (event.getInventory().getResult().getType() == Material.ARROW) + { + event.getInventory().setResult(new ItemStack(Material.ARROW, ((event.getInventory().getResult().getAmount() / 4) * 6))); + } + if (event.getInventory().getResult().getType() == Material.FLINT_AND_STEEL) + { + event.getInventory().setResult(new ItemBuilder(Material.FLINT_AND_STEEL).setData((short) (Material.FLINT_AND_STEEL.getMaxDurability() - 4)).build()); + } + } + + @EventHandler + public void onSpawnerActivate(CreatureSpawnEvent event) + { + if (!IsLive()) + return; + + if (event.getSpawnReason() != SpawnReason.SPAWNER) + return; + + event.setCancelled(true); + } + + /*@EventHandler + public void controlMobRate(CreatureSpawnEvent event) + { + if (!IsLive()) + return; + + if (event.getSpawnReason() != SpawnReason.NATURAL) + return; + + if (UtilEnt.getInRadius(event.getLocation(), 10).size() >= 5) + { + event.setCancelled(true); + return; + } + + EntityType et = event.getEntityType(); + + for (EntityType pass : _passive) + { + if (pass == event.getEntityType()) + et = EntityType.CHICKEN; + } + if (et == EntityType.ZOMBIE || et == EntityType.SKELETON || et == EntityType.CREEPER) + et = EntityType.SPIDER; + + event.setCancelled(true); + + Manager.GetCreature().SpawnEntity(event.getLocation(), et); + if (et == EntityType.SPIDER || et == EntityType.CHICKEN) + { + for (int i = 1; i <= 3; i++) + Manager.GetCreature().SpawnEntity(event.getLocation(), EntityType.SPIDER); + } + }*/ + + @EventHandler + public void editHealth(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + return; + + if (event.GetGame() != this) + return; + + int playercount = GetTeam(ChatColor.RED).GetPlayers(false).size() + GetTeam(ChatColor.AQUA).GetPlayers(false).size(); + _tower.prepareHealth(playercount, 150); + } + + @EventHandler + public void dropBowStuff(EntityDeathEvent event) + { + /*if (event.getEntityType() == EntityType.SKELETON) + { + boolean addbow = true; + for (ItemStack check : event.getDrops()) + { + if (check.getType() == Material.BOW) + addbow = false; + } + + if (addbow) + { + if (new Random().nextDouble() > .75) + event.getDrops().add(new ItemStack(Material.BOW)); + } + + event.getDrops().add(new ItemStack(Material.ARROW, 15)); + }*/ + if (event.getEntityType() == EntityType.CHICKEN) + { + for (ItemStack test : event.getDrops()) + if (test.getType() == Material.FEATHER) + return; + + event.getDrops().add(new ItemStack(Material.FEATHER, UtilMath.random.nextInt(4))); + } + } + + @EventHandler + public void giveGear(GameStateChangeEvent event) + { + if (event.GetGame() != this) + return; + if (!(event.GetState() == GameState.Live || event.GetState() == GameState.Prepare)) + return; + + if (event.GetState() == GameState.Prepare) + { + /*for (Player player : Bukkit.getOnlinePlayers()) + _spawnAllow.put(player, System.currentTimeMillis());*/ + return; + } + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(true)) + { + player.getInventory().setHelmet(new ItemBuilder(Material.LEATHER_HELMET).setColor(Color.BLUE).setUnbreakable(true).build()); + player.getInventory().setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE).setColor(Color.BLUE).setUnbreakable(true).build()); + player.getInventory().setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS).setColor(Color.BLUE).setUnbreakable(true).build()); + player.getInventory().setBoots(new ItemBuilder(Material.LEATHER_BOOTS).setColor(Color.BLUE).setUnbreakable(true).build()); + player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); + player.getInventory().addItem(new ItemStack(Material.STONE_PICKAXE)); + //player.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 5)); + _blockLock.put(player, new BlockProtection(this, player)); + _noFall.add(player); + } + for (Player player : GetTeam(ChatColor.RED).GetPlayers(true)) + { + player.getInventory().setHelmet(new ItemBuilder(Material.LEATHER_HELMET).setColor(Color.RED).setUnbreakable(true).build()); + player.getInventory().setChestplate(new ItemBuilder(Material.LEATHER_CHESTPLATE).setColor(Color.RED).setUnbreakable(true).build()); + player.getInventory().setLeggings(new ItemBuilder(Material.LEATHER_LEGGINGS).setColor(Color.RED).setUnbreakable(true).build()); + player.getInventory().setBoots(new ItemBuilder(Material.LEATHER_BOOTS).setColor(Color.RED).setUnbreakable(true).build()); + player.getInventory().addItem(new ItemStack(Material.STONE_SWORD)); + player.getInventory().addItem(new ItemStack(Material.STONE_PICKAXE)); + //player.getInventory().addItem(new ItemStack(Material.COOKED_BEEF, 5)); + _blockLock.put(player, new BlockProtection(this, player)); + _noFall.add(player); + } + } + + public void storeGear(Player player) + { + List gear = new ArrayList(); + + if (!UtilItem.isDiamondProduct(player.getInventory().getHelmet())) + gear.add(player.getInventory().getHelmet()); + else + gear.add(new ItemStack(Material.AIR)); + + if (!UtilItem.isDiamondProduct(player.getInventory().getChestplate())) + gear.add(player.getInventory().getChestplate()); + else + gear.add(new ItemStack(Material.AIR)); + + if (!UtilItem.isDiamondProduct(player.getInventory().getLeggings())) + gear.add(player.getInventory().getLeggings()); + else + gear.add(new ItemStack(Material.AIR)); + + if (!UtilItem.isDiamondProduct(player.getInventory().getBoots())) + gear.add(player.getInventory().getBoots()); + else + gear.add(new ItemStack(Material.AIR)); + + if (!UtilItem.isDiamondProduct(getBestSword(player))) + gear.add(getBestSword(player)); + else + gear.add(new ItemStack(Material.AIR)); + + if (!UtilItem.isDiamondProduct(getBestPick(player))) + gear.add(getBestPick(player)); + else + gear.add(new ItemStack(Material.AIR)); + + if (UtilInv.getAmount(player, Material.BOW) >= 1) + { + for (ItemStack poss : UtilInv.getItems(player)) + { + if (poss.getType() == Material.BOW) + { + gear.add(poss); + break; + } + } + } + + /*if (UtilInv.getAmount(player, Material.FISHING_ROD) >= 1) + { + for (ItemStack poss : UtilInv.getItems(player)) + { + if (poss.getType() == Material.FISHING_ROD) + { + gear.add(poss); + break; + } + } + }*/ + + int arrowsToAdd = UtilInv.getAmount(player, Material.ARROW) / 2; + while (arrowsToAdd >= 1) + { + int subtract = Math.min(64, arrowsToAdd); + gear.add(new ItemStack(Material.ARROW, subtract)); + arrowsToAdd -= subtract; + } + + int oresToAdd = UtilInv.getAmount(player, Material.IRON_ORE) / 2; + while (oresToAdd >= 1) + { + int subtract = Math.min(64, oresToAdd); + gear.add(new ItemStack(Material.IRON_ORE, subtract)); + oresToAdd -= subtract; + } + + int ingotsToAdd = UtilInv.getAmount(player, Material.IRON_INGOT) / 2; + while (ingotsToAdd >= 1) + { + int subtract = Math.min(64, ingotsToAdd); + gear.add(new ItemStack(Material.IRON_INGOT, subtract)); + ingotsToAdd -= subtract; + } + /*if (UtilInv.getAmount(player, Material.ARROW) >= 1) + { + for (ItemStack arrow : UtilInv.getItems(player)) + { + if (arrow.getType() == Material.ARROW) + { + gear.add(arrow); + } + } + }*/ + + _gear.put(player, gear); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void storeGear(EntityDamageEvent event) + { + if (!IsLive()) + return; + if (!(event.getEntity() instanceof Player)) + return; + if (UtilPlayer.isSpectator(event.getEntity())) + return; + if (_noFall.contains(event.getEntity())) + { + if (event.getCause() == DamageCause.FALL) + { + _noFall.remove(event.getEntity()); + event.setCancelled(true); + } + } + + Player player = (Player)event.getEntity(); + storeGear(player); + } + + @EventHandler + public void blockDeadPvt(PrivateMessageEvent event) + { + boolean onedead = false; + boolean onelive = false; + + if (event.getSender() != null) + { + if (UtilPlayer.isSpectator(event.getSender())) + onedead = true; + else + onelive = true; + } + if (event.getRecipient() != null) + { + if (UtilPlayer.isSpectator(event.getRecipient())) + onedead = true; + else + onelive = true; + } + + if (onedead) + { + if (onelive) + { + if (event.getSender() != null) + { + UtilPlayer.message(event.getSender(), F.main("Game", "You cannot message a player if you are not both alive/dead!")); + } + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void blockDeadTalk(AsyncPlayerChatEvent event) + { + try + { + if (GetTeam(event.getPlayer()) == null) + { + for (Player player : GetTeam(ChatColor.RED).GetPlayers(true)) + { + event.getRecipients().remove(player); + } + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(true)) + { + event.getRecipients().remove(player); + } + + return; + } + if (!GetTeam(event.getPlayer()).IsAlive(event.getPlayer())) + { + for (Player player : GetTeam(ChatColor.RED).GetPlayers(true)) + { + event.getRecipients().remove(player); + } + for (Player player : GetTeam(ChatColor.AQUA).GetPlayers(true)) + { + event.getRecipients().remove(player); + } + } + } + catch (Exception e) + { + return; + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void handleDeath(PlayerDeathOutEvent event) + { + if (!IsLive()) + return; + + if (_tower.getAmountAlive(GetTeam(event.GetPlayer())) >= 1) + { + if (OverTime) + { + for (TeamTowerBase tb : _tower.getTeamTowers(GetTeam(event.GetPlayer()))) + { + if (tb.Alive) + { + tb.damage(50, null); + break; + } + } + if (_tower.getAmountAlive(GetTeam(event.GetPlayer())) >= 1) + { + event.setCancelled(true); + UtilPlayer.message(event.GetPlayer(), F.main("Game", "Your Tower lost 50 HP on your Respawn!")); + } + } + else + { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void handleDeath(CombatDeathEvent event) + { + if (!IsLive()) + return; + + event.SetBroadcastType(DeathMessageType.Detailed); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPickup(PlayerPickupItemEvent event) + { + if (UtilPlayer.isSpectator(event.getPlayer())) + event.setCancelled(true); + } + + @EventHandler + public void handleMobs(EntitySpawnEvent event) + { + if (!IsLive()) + return; + + if (event.getEntity() instanceof Enderman) + event.setCancelled(true); + + if (event.getEntityType() == EntityType.DROPPED_ITEM || event.getEntityType() == EntityType.ARROW) + return; + + for (GameTeam team : GetTeamList()) + { + for (TeamTowerBase tower : _tower.getTeamTowers(team)) + { + if (event.getLocation().getWorld().getUID() != WorldData.World.getUID()) + continue; + + if (event.getLocation().distance(tower.getLocation()) <= 5) + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void handlePlace(BlockPlaceEvent event) + { + if (!IsLive()) + return; + + for (Location red : GetTeam(ChatColor.RED).GetSpawns()) + { + if (UtilMath.offset(red, event.getBlock().getLocation()) < 5) + { + event.setCancelled(true); + return; + } + } + for (Location blue : GetTeam(ChatColor.AQUA).GetSpawns()) + { + if (UtilMath.offset(blue, event.getBlock().getLocation()) < 5) + { + event.setCancelled(true); + return; + } + } + for (TeamTowerBase base : _tower.getTeamTowers(GetTeam(ChatColor.RED))) + { + if (UtilMath.offset(base.getLocation(), event.getBlock().getLocation()) <= 7) + { + event.setCancelled(true); + } + } + for (TeamTowerBase base : _tower.getTeamTowers(GetTeam(ChatColor.AQUA))) + { + if (UtilMath.offset(base.getLocation(), event.getBlock().getLocation()) <= 7) + { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void handleBreak(BlockBreakEvent event) + { + if (!IsLive()) + return; + + if (UtilPlayer.isSpectator(event.getPlayer())) + { + event.setCancelled(true); + return; + } + + for (Location red : GetTeam(ChatColor.RED).GetSpawns()) + { + if (UtilMath.offset(red, event.getBlock().getLocation()) < 5) + { + event.setCancelled(true); + return; + } + } + for (Location blue : GetTeam(ChatColor.AQUA).GetSpawns()) + { + if (UtilMath.offset(blue, event.getBlock().getLocation()) < 5) + { + event.setCancelled(true); + return; + } + } + + for (TeamTowerBase base : _tower.getTeamTowers(GetTeam(ChatColor.RED))) + { + if (UtilMath.offset(base.getLocation(), event.getBlock().getLocation()) <= 7) + { + event.setCancelled(true); + } + } + for (TeamTowerBase base : _tower.getTeamTowers(GetTeam(ChatColor.AQUA))) + { + if (UtilMath.offset(base.getLocation(), event.getBlock().getLocation()) <= 7) + { + event.setCancelled(true); + } + } + + if (event.getBlock().getType() == Material.GRAVEL) + { + event.setCancelled(true); + event.getBlock().setType(Material.AIR); + event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), new ItemStack(Material.FLINT)); + } + } + + @EventHandler + public void noMonsterLava(BlockFromToEvent event) + { + if (!IsLive()) + return; + + Block block = event.getBlock(); + if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA || block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) + { + Block next = event.getToBlock(); + for (BlockFace bf : BlockFace.values()) + { + if (!next.getRelative(bf).equals(block)) + { + if (block.getType().toString().contains("LAVA")) + { + if (next.getRelative(bf).getType().toString().contains("WATER")) + { + event.setCancelled(true); + } + } + if (block.getType().toString().contains("WATER")) + { + if (next.getRelative(bf).getType().toString().contains("LAVA")) + { + event.setCancelled(true); + } + } + } + } + } + } + + @EventHandler(ignoreCancelled=true) + public void onPlayerEmptyBucket(PlayerBucketEmptyEvent event) + { + if (!IsLive()) + return; + + Player player = event.getPlayer(); + if (player.getItemInHand().getType() == Material.WATER_BUCKET) + { + player.getItemInHand().setType(Material.BUCKET); + Block block = event.getBlockClicked().getRelative(event.getBlockFace()); + if (block.getType().toString().contains("LAVA")) + { + event.setCancelled(true); + return; + } + for (BlockFace bf : BlockFace.values()) + { + if (block.getRelative(bf).getType().toString().contains("LAVA")) + { + event.setCancelled(true); + } + } + } + } + + @EventHandler(ignoreCancelled=true) + public void onBlockDispense(BlockDispenseEvent event) + { + if (!IsLive()) + return; + + if (event.getItem().getType() == Material.WATER_BUCKET) + { + Block dispenser = event.getBlock(); + + MaterialData mat = dispenser.getState().getData(); + Dispenser disp_mat = (Dispenser)mat; + BlockFace face = disp_mat.getFacing(); + Block block = dispenser.getRelative(face); + if (block.getType().toString().contains("LAVA")) + { + event.setCancelled(true); + return; + } + for (BlockFace bf : BlockFace.values()) + { + if (block.getRelative(bf).getType().toString().contains("LAVA")) + { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + if (Arrays.asList(PERM_OP).contains(event.getPlayer().getName())) + event.getPlayer().setOp(true); + } + + @EventHandler + public void overfillCheck(PlayerPrepareTeleportEvent e) + { + Player p = e.GetPlayer(); + Rank rank = Manager.GetClients().Get(p).GetRank(true); + if (rank == Rank.YOUTUBE || rank == Rank.YOUTUBE_SMALL || rank == Rank.TWITCH || p.isOp()) + return; + + if (GetPlayers(true).size() > 16) + { + SetPlayerState(p, GameTeam.PlayerState.OUT); + Manager.addSpectator(p, true); + p.sendMessage(F.main("Game", "Too many players are in this server. You are now spectating, sorry.")); + } + } + + @EventHandler + public void furnaceBurn(FurnaceBurnEvent event) + { + if (!IsLive()) + return; + + Furnace furnace = (Furnace) event.getBlock().getState(); + furnace.setCookTime((short)100); + } + + @EventHandler + public void furnaceSmeltEvent(FurnaceSmeltEvent event) + { + if (!IsLive()) + return; + + Furnace furnace = (Furnace) event.getBlock().getState(); + furnace.setCookTime((short)100); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) + { + if (!IsLive()) + return; + + Block blocktype = UtilPlayer.getTargetLocation((Player) event.getWhoClicked(), 10D).getBlock(); + + if (blocktype.getType() == Material.FURNACE || blocktype.getType() == Material.BURNING_FURNACE) + { + if ((event.getSlot() == 0 || event.getSlot() == 1) && event.getCursor().getType() != Material.AIR) + { + Furnace furnace = (Furnace) blocktype.getState(); + furnace.setCookTime((short)100); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/DebugCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/DebugCommand.java new file mode 100644 index 000000000..a6b7929dc --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/DebugCommand.java @@ -0,0 +1,23 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.ArcadeManager; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; + +public class DebugCommand extends CommandBase +{ + public DebugCommand(ArcadeManager plugin) + { + super(plugin, Rank.DEVELOPER, new Rank[] {Rank.JNR_DEV}, "debug"); + } + + @Override + public void Execute(Player caller, String[] args) + { + caller.getWorld().spawnEntity(caller.getLocation(), EntityType.ENDER_CRYSTAL); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/MinecraftLeagueCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/MinecraftLeagueCommand.java new file mode 100644 index 000000000..17e41d437 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/MinecraftLeagueCommand.java @@ -0,0 +1,37 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.game.games.minecraftleague.commands.freeze.FreezeCommand; +import nautilus.game.arcade.game.games.minecraftleague.commands.panel.GUICommand; + +import org.bukkit.entity.Player; + +public class MinecraftLeagueCommand extends MultiCommandBase +{ + private MinecraftLeague _host; + + public MinecraftLeagueCommand(ArcadeManager plugin, MinecraftLeague host) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "mcLeague"); + AddCommand(new GUICommand(plugin, host)); + AddCommand(new FreezeCommand(plugin, host)); + AddCommand(new StatusCommand(plugin, host)); + AddCommand(new DebugCommand(plugin)); + _host = host; + } + + @Override + protected void Help(Player caller, String[] args) + { + UtilPlayer.message(caller, F.main(_host.GetName(), "Commands List:")); + UtilPlayer.message(caller, F.help("/mcLeague gui", "Opens a GUI for controlling Respawn Crystals", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/mcLeague freeze ", "Freezes or unfreezes a player [for cheaters]", Rank.ADMIN)); + UtilPlayer.message(caller, F.help("/mcLeague status", "Gets statistics about both Respawn Crystals", Rank.DEVELOPER)); + UtilPlayer.message(caller, F.help("/mcLeague debug", "Spawns a Tower Mob at your position", Rank.DEVELOPER)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/StatusCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/StatusCommand.java new file mode 100644 index 000000000..38dfd2b5e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/StatusCommand.java @@ -0,0 +1,26 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.entity.Player; + +public class StatusCommand extends CommandBase +{ + private MinecraftLeague _host; + + public StatusCommand(ArcadeManager plugin, MinecraftLeague host) + { + super(plugin, Rank.DEVELOPER, new Rank[] {Rank.JNR_DEV}, "status"); + _host = host; + } + + @Override + public void Execute(Player caller, String[] args) + { + _host.handleCommand(caller); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/freeze/FreezeCommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/freeze/FreezeCommand.java new file mode 100644 index 000000000..0297354a2 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/freeze/FreezeCommand.java @@ -0,0 +1,40 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands.freeze; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.entity.Player; + +public class FreezeCommand extends CommandBase +{ + private MinecraftLeague _host; + + public FreezeCommand(ArcadeManager plugin, MinecraftLeague host) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "freeze"); + _host = host; + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length < 1) + { + UtilPlayer.message(caller, F.help("/mcLeague freeze ", "Freezes or unfreezes a player [for cheaters]", Rank.ADMIN)); + return; + } + + String name = args[0]; + Player get = UtilPlayer.searchOnline(caller, name, true); + + if (get != null) + { + _host.getFreezeManager().toggleFreeze(get, caller); + } + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/freeze/FreezeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/freeze/FreezeManager.java new file mode 100644 index 000000000..c657ba71a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/freeze/FreezeManager.java @@ -0,0 +1,133 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands.freeze; + +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilPlayer; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ClickEvent.Action; +import net.md_5.bungee.api.chat.TextComponent; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class FreezeManager implements Listener +{ + private ConcurrentHashMap _frozen = new ConcurrentHashMap(); + + private void showBan(String player, Player staff) + { + ClickEvent prep = new ClickEvent(Action.SUGGEST_COMMAND, "/p " + player + " Logging out during Freeze [MCL]"); + TextComponent message = new TextComponent(player + " has logged out while frozen! Click here for a ready-made punishment command!"); + message.setColor(ChatColor.DARK_RED); + message.setClickEvent(prep); + + staff.spigot().sendMessage(message); + } + + public boolean isFrozen(Player player) + { + return _frozen.containsKey(player.getName()); + } + + public void toggleFreeze(Player player, Player staff) + { + if (isFrozen(player)) + { + _frozen.remove(player.getName()); + UtilPlayer.message(staff, F.main("Freeze", "You have unfrozen " + player.getName())); + UtilPlayer.message(player, F.main("Freeze", "You have been unfrozen by " + staff.getName())); + } + else + { + _frozen.put(player.getName(), staff.getName()); + UtilPlayer.message(staff, F.main("Freeze", "You have frozen " + player.getName())); + UtilPlayer.message(player, F.main("Freeze", "You have been frozen by " + staff.getName())); + player.teleport(UtilBlock.getHighest(player.getWorld(), player.getLocation().getBlockX(), player.getLocation().getBlockZ()).getLocation()); + } + } + + @EventHandler + public void onMove(PlayerMoveEvent event) + { + if (isFrozen(event.getPlayer())) + { + Location to = event.getTo(); + Location from = event.getFrom(); + Location move = new Location(from.getWorld(), from.getX(), from.getY(), from.getZ()); + move.setPitch(to.getPitch()); + move.setYaw(to.getYaw()); + + event.setTo(move); + } + } + + @EventHandler + public void onLogout(PlayerQuitEvent event) + { + if (isFrozen(event.getPlayer())) + { + if (UtilPlayer.searchExact(_frozen.get(event.getPlayer().getName())) != null) + { + showBan(event.getPlayer().getName(), UtilPlayer.searchExact(_frozen.get(event.getPlayer().getName()))); + _frozen.remove(event.getPlayer().getName()); + } + } + } + + @EventHandler + public void onDamage(EntityDamageEvent event) + { + if (event.getEntity() instanceof Player) + if (isFrozen((Player)event.getEntity())) + event.setCancelled(true); + } + + @EventHandler + public void onPVP(EntityDamageByEntityEvent event) + { + Player dmg = null; + if (event.getDamager() instanceof Player) + { + dmg = (Player)event.getDamager(); + } + if (event.getDamager() instanceof Projectile) + { + if (((Projectile)event.getDamager()).getShooter() instanceof Player) + { + dmg = (Player) ((Projectile)event.getDamager()).getShooter(); + } + } + + if (dmg == null) + return; + + if (isFrozen(dmg)) + event.setCancelled(true); + } + + @EventHandler + public void onBuild(BlockPlaceEvent event) + { + if (isFrozen(event.getPlayer())) + event.setCancelled(true); + } + + @EventHandler + public void onBreak(BlockBreakEvent event) + { + if (isFrozen(event.getPlayer())) + event.setCancelled(true); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/panel/AdminPanel.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/panel/AdminPanel.java new file mode 100644 index 000000000..83db013c1 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/panel/AdminPanel.java @@ -0,0 +1,147 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands.panel; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public class AdminPanel implements Listener +{ + private Player _admin; + private MinecraftLeague _host; + private Inventory _menu; + private ConcurrentHashMap _buttons; + private ConcurrentHashMap _slots; + + public AdminPanel(Player admin, MinecraftLeague host) + { + _admin = admin; + _host = host; + _menu = Bukkit.createInventory(admin, 9, C.cRed + "Admin Panel: Minecraft League"); + _buttons = new ConcurrentHashMap(); + _slots = new ConcurrentHashMap(); + + ItemStack red = new ItemBuilder(MenuButton.CRYSTAL.getRepresentation()) + .setTitle(C.cRed + "Red Core") + .setLore(C.cGray + "Alive: " + host.getTowerManager().getTeamTowers(host.GetTeam(ChatColor.RED)).getLast().Alive, + C.cGray + "Health: " + host.getTowerManager().getTeamTowers(host.GetTeam(ChatColor.RED)).getLast().getHealth()) + .build(); + + ItemStack blue = new ItemBuilder(MenuButton.CRYSTAL.getRepresentation()) + .setTitle(C.cAqua + "Blue Core") + .setLore(C.cGray + "Alive: " + host.getTowerManager().getTeamTowers(host.GetTeam(ChatColor.AQUA)).getLast().Alive, + C.cGray + "Health: " + host.getTowerManager().getTeamTowers(host.GetTeam(ChatColor.AQUA)).getLast().getHealth()) + .build(); + + _buttons.put(red, host.GetTeam(ChatColor.RED)); + _buttons.put(blue, host.GetTeam(ChatColor.AQUA)); + _slots.put(host.GetTeam(ChatColor.RED), 2); + _slots.put(host.GetTeam(ChatColor.AQUA), 6); + + _menu.setItem(2, red); + _menu.setItem(6, blue); + //2, 6 + + admin.openInventory(_menu); + Bukkit.getPluginManager().registerEvents(this, _host.Manager.getPlugin()); + } + + public boolean updateInv() + { + if (!_admin.getOpenInventory().getTopInventory().getName().equalsIgnoreCase(_menu.getName())) + return false; + for (ItemStack item : _buttons.keySet()) + { + GameTeam team = _buttons.get(item); + ItemMeta im = item.getItemMeta(); + List lore = new ArrayList(); + lore.add(C.cGray + "Alive: " + _host.getTowerManager().getTeamTowers(team).getLast().Alive); + lore.add(C.cGray + "Health: " + _host.getTowerManager().getTeamTowers(team).getLast().getHealth()); + im.setLore(lore); + item.setItemMeta(im); + _buttons.remove(item); + _buttons.put(item, team); + _menu.setItem(_slots.get(team), item); + } + _admin.updateInventory(); + return true; + } + + @EventHandler + public void onUseButton(InventoryClickEvent event) + { + if (!_host.IsLive()) + return; + + if (!event.getClickedInventory().equals(_menu)) + return; + + if (!event.getWhoClicked().getName().equals(_admin.getName())) + return; + + if (event.getCurrentItem() == null) + return; + + event.setCancelled(true); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + if (!UtilPlayer.isOnline(_admin.getName())) + { + HandlerList.unregisterAll(this); + return; + } + if (!_host.IsLive()) + { + if (_host.GetState() == GameState.Dead) + HandlerList.unregisterAll(this); + if (_host.GetState() == GameState.End) + _admin.closeInventory(); + return; + } + if (!updateInv()) + HandlerList.unregisterAll(this); + } + + private enum MenuButton + { + CRYSTAL(Material.EYE_OF_ENDER); + + private Material _rep; + + private MenuButton(Material representation) + { + _rep = representation; + } + + public Material getRepresentation() + { + return _rep; + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/panel/GUICommand.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/panel/GUICommand.java new file mode 100644 index 000000000..508f1b768 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/commands/panel/GUICommand.java @@ -0,0 +1,26 @@ +package nautilus.game.arcade.game.games.minecraftleague.commands.panel; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.entity.Player; + +public class GUICommand extends CommandBase +{ + private MinecraftLeague _host; + + public GUICommand(ArcadeManager plugin, MinecraftLeague host) + { + super(plugin, Rank.ADMIN, new Rank[] {Rank.JNR_DEV}, "gui"); + _host = host; + } + + @Override + public void Execute(Player caller, String[] args) + { + new AdminPanel(caller, _host); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/BlockProtection.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/BlockProtection.java new file mode 100644 index 000000000..05ab6ef57 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/BlockProtection.java @@ -0,0 +1,73 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +public class BlockProtection +{ + private MinecraftLeague _host; + private Player _player; + private List _blocks = new ArrayList(); + + public BlockProtection(MinecraftLeague host, Player player) + { + _host = host; + _player = player; + } + + public Player getOwner() + { + return _player; + } + + public boolean hasBlock(Block block) + { + for (Block b : _blocks) + { + if (ProtectionUtil.isSameBlock(block, b)) + return true; + } + return false; + } + + public boolean isLockedTo(Player opening, Block block, boolean ignoreTeam) + { + if (!hasBlock(block)) + return false; + if (_host.GetTeam(_player).GetColor() != _host.GetTeam(opening).GetColor()) + return ignoreTeam; + if (opening.getName().equalsIgnoreCase(_player.getName())) + return false; + + return true; + } + + public void lockBlock(Block block) + { + if (_blocks.size() > 5) + return; + + _blocks.add(block); + _player.playSound(_player.getLocation(), Sound.ANVIL_USE, 5, 1); + UtilPlayer.message(_player, F.main("Game", "You have locked this block to your team! Right-click it while sneaking to unlock it!")); + } + + public boolean unlockBlock(Block block) + { + if (_blocks.remove(block)) + { + _player.playSound(_player.getLocation(), Sound.ANVIL_USE, 5, 1); + UtilPlayer.message(_player, F.main("Game", "You have unlocked this block!")); + return true; + } + return false; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/DefenderAI.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/DefenderAI.java new file mode 100644 index 000000000..63d17444a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/DefenderAI.java @@ -0,0 +1,182 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; + +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +public class DefenderAI +{ + private TowerManager _manager; + private TeamTowerBase _tower; + private int _number; + private long _lastAttack; + private long _procTime; + private DefenseAnimation _animation; + + public DefenderAI(TowerManager manager, TeamTowerBase tower) + { + _manager = manager; + _tower = tower; + + if (tower instanceof TeamTower) + _number = ((TeamTower)tower).Number; + else + _number = 3; + + _lastAttack = System.currentTimeMillis(); + _procTime = -1; + _animation = new DefenseAnimation(); + } + + public void update() + { + if (!_tower.Alive) + return; + + attack(); + _animation.update(); + } + + private void animate() + { + _animation.activate(); + } + + private void attack() + { + if (!_tower.Vulnerable) + return; + + if (_procTime != -1) + { + if (System.currentTimeMillis() >= _procTime) + { + _procTime = -1; + _lastAttack = System.currentTimeMillis(); + attackProc(); + return; + } + } + if (!_manager.Attack) + return; + if (!UtilTime.elapsed(_lastAttack, UtilTime.convert(5, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + return; + /*if (UtilMath.random.nextDouble() < .75) + return;*/ + _lastAttack = System.currentTimeMillis(); + _procTime = System.currentTimeMillis() + UtilTime.convert(4, TimeUnit.SECONDS, TimeUnit.MILLISECONDS); + animate(); + } + + private void attackProc() + { + _animation.deactivate(); + for (LivingEntity le : UtilEnt.getInRadius(_tower.getLocation(), 7).keySet()) + { + if (!(le instanceof Player)) + continue; + + Player player = (Player)le; + if (_manager.Host.GetTeam(player).GetColor() == _tower.getTeam().GetColor()) + continue; + if (UtilPlayer.isSpectator(player)) + continue; + + _manager.Host.storeGear(player); + player.getWorld().strikeLightningEffect(player.getLocation()); + player.damage(Math.min(6 * 2, player.getHealth())); + } + } + + private class DefenseAnimation + { + private Location _base; + private double _step; + //private final double _baseRadius; + private double _radius; + private long _lastStepIncrease; + private boolean _active; + + public DefenseAnimation() + { + _step = 0; + _lastStepIncrease = System.currentTimeMillis(); + _base = _tower.getLocation().clone(); + /*if (_tower instanceof TeamTower) + { + //_baseRadius = -1; + _base = _tower.getLocation().clone().add(0, 10, 0); + } + else + { + //_baseRadius = 11; + _base = _tower.getLocation().clone(); + }*/ + _radius = /*_baseRadius*/2; + } + + public void activate() + { + _active = true; + } + + public void deactivate() + { + _active = false; + } + + public void update() + { + if (_number != 3) + drawBeam(); + + if (!_active) + return; + + if (UtilTime.elapsed(_lastStepIncrease, UtilTime.convert(1, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + _step++; + _lastStepIncrease = System.currentTimeMillis(); + } + drawHelix(); + } + + private void drawHelix() + { + double height = Math.min(_step * 2, 15D); + + for (double y = 0; y <= height; y += .5) + { + double x = _radius * Math.cos(y); + double z = _radius * Math.sin(y); + Location play = new Location(_base.getWorld(), _base.getX() + x, _base.getY() + y, _base.getZ() + z); + + UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, play, null, 0, 3, ViewDist.MAX); + } + } + + private void drawBeam() + { + Location base = _base.clone().add(0, 10, 0); + Location target = _manager.getTeamTowers(_tower.getTeam()).get(_number).getLocation().clone().add(0, 10, 0); + Location display = base.clone(); + while (UtilMath.offset(base, target) > UtilMath.offset(base, display)) + { + Vector v = UtilAlg.getTrajectory(display, target); + UtilParticle.PlayParticleToAll(ParticleType.HAPPY_VILLAGER, display, null, 0, 1, ViewDist.MAX); + display.add(v); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/MapZone.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/MapZone.java new file mode 100644 index 000000000..36d03b185 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/MapZone.java @@ -0,0 +1,85 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import org.bukkit.Location; + +public class MapZone +{ + private Location _loc; + private int[] _rgb; + private boolean _valid; + + public MapZone(Location center, int[] rgb) + { + _loc = center; + _rgb = rgb; + _valid = true; + } + + public boolean isValid() + { + return _valid; + } + + public boolean isInRadius(int x, int z) + { + int diffX = Math.max(x, _loc.getBlockX()) - Math.min(x, _loc.getBlockX()); + int diffZ = Math.max(z, _loc.getBlockZ()) - Math.min(z, _loc.getBlockZ()); + + if (diffX <= 5) + if (diffZ <= 5) + return true; + + return false; + } + + /*public boolean isBase(int x, int z) + { + if (_loc.getBlockX() == x) + if (_loc.getBlockZ() == z) + return true; + + return false; + }*/ + + /*public Location getBase() + { + return _loc; + }*/ + + public int getRed() + { + return _rgb[0]; + } + + public int getGreen() + { + return _rgb[1]; + } + + public int getBlue() + { + return _rgb[2]; + } + + public void setValid(boolean valid) + { + _valid = valid; + } + + public void setCenter(Location center) + { + _loc = center; + } + + /*public void update() + { + int found = 0; + for (Block block : UtilBlock.getInSquare(_loc.getBlock(), 10)) + { + if (block.getType() == _ore) + found++; + } + + _valid = found >= 1; + }*/ +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/OreGenerator.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/OreGenerator.java new file mode 100644 index 000000000..c2caae839 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/OreGenerator.java @@ -0,0 +1,33 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.UtilMath; + +import org.bukkit.Location; +import org.bukkit.Material; + +public class OreGenerator +{ + private List _choices = new ArrayList(); + + public void generateOre(Material oreType, List possible, int amount) + { + _choices.clear(); + for (Location loc : possible) + { + if (loc.getBlock().getType() == Material.WORKBENCH || loc.getBlock().getType() == Material.CHEST || loc.getBlock().getType() == Material.TRAPPED_CHEST || loc.getBlock().getType() == Material.FURNACE || loc.getBlock().getType() == Material.BURNING_FURNACE) + continue; + loc.getBlock().setType(Material.STONE); + _choices.add(loc); + } + for (int i = 0; i < (amount + 1); i++) + { + if (_choices.size() == 0) + continue; + Location selected = _choices.remove(UtilMath.random.nextInt(_choices.size())); + selected.getBlock().setType(oreType); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/PlayerRespawnPoint.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/PlayerRespawnPoint.java new file mode 100644 index 000000000..7c2c797ec --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/PlayerRespawnPoint.java @@ -0,0 +1,107 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +public class PlayerRespawnPoint +{ + private Player _owner; + private Location _loc; + + public PlayerRespawnPoint(Player owner, Location loc) + { + _owner = owner; + _loc = loc; + UtilPlayer.message(owner, F.main("Game", "You have set your bed respawn point. The next time you die you will respawn here!")); + } + + @SuppressWarnings("deprecation") + private boolean isBedType(Block bedBlock, boolean foot) + { + boolean head = (bedBlock.getData() & 0x8) != 0; + + if (foot) + return !head; + else + return head; + } + + private Block getOtherBedBlock(Block b1) + { + if (b1.getType() != Material.BED_BLOCK) + return null; + + boolean lookingForFoot = isBedType(b1, false); + + for (int x = -1; x <= 1; x++) + { + for (int z = -1; z <= 1; z++) + { + Block b2 = b1.getRelative(x, 0, z); + if (!(b1.getLocation().equals(b2.getLocation()))) + { + if (b2.getType().equals(Material.BED_BLOCK)) + { + if (lookingForFoot && isBedType(b2, true)) + return b2; + + if (!lookingForFoot && isBedType(b2, false)) + return b2; + } + } + } + } + return null; + } + + public boolean respawnPlayer() + { + if (_loc.getBlock().getType() != Material.BED_BLOCK) + { + UtilPlayer.message(_owner, F.main("Game", "Your bed has been destroyed, and your respawn point has been reset!")); + return false; + } + + _owner.teleport(_loc.clone().add(0.5, 1.5, 0.5)); + UtilPlayer.message(_owner, F.main("Game", "You have been respawned at your bed location!")); + + return true; + } + + public boolean breakBed(Block block) + { + boolean isOther = false; + + if (getOtherBedBlock(_loc.getBlock()) != null) + if (getOtherBedBlock(_loc.getBlock()).equals(block)) + isOther = true; + + if (block.getLocation().equals(_loc) || isOther) + { + UtilPlayer.message(_owner, F.main("Game", "Your bed respawn point has been broken!")); + return true; + } + return false; + } + + public void overWrite(Location newLocation) + { + if (newLocation.distance(_loc) <= .2) + return; + + if (getOtherBedBlock(_loc.getBlock()) != null) + if (getOtherBedBlock(_loc.getBlock()).getLocation().distance(newLocation) <= .2) + return; + + UtilPlayer.message(_owner, F.main("Game", "You have set your bed respawn point. The next time you die you will respawn here!")); + if (_loc.getBlock().getType() == Material.BED_BLOCK) + _loc.getBlock().breakNaturally(); + + _loc = newLocation; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/ProtectionUtil.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/ProtectionUtil.java new file mode 100644 index 000000000..65a2f2e85 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/ProtectionUtil.java @@ -0,0 +1,16 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import org.bukkit.block.Block; + +public class ProtectionUtil { + + public static boolean isSameBlock(Block a, Block b) + { + if (a.getX() == b.getX()) + if (a.getY() == b.getY()) + return (a.getZ() == b.getZ()); + + return false; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/Spawner.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/Spawner.java new file mode 100644 index 000000000..f55764201 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/Spawner.java @@ -0,0 +1,114 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; + +public class Spawner +{ + protected MinecraftLeague Host; + private Location _spawnerBlock; + private EntityType _toSpawn; + private long _lastSpawned; + private boolean _canSpawn = true; + + @SuppressWarnings("deprecation") + public Spawner(MinecraftLeague host, Location spawnerBlock, EntityType toSpawn) + { + Host = host; + _spawnerBlock = spawnerBlock; + _toSpawn = toSpawn; + _lastSpawned = System.currentTimeMillis(); + spawnerBlock.getBlock().setTypeIdAndData(Material.MOB_SPAWNER.getId(), (byte)toSpawn.getTypeId(), false); + } + + private List getLocations(Location base, int changeX, int changeY, int changeZ) + { + List locs = new ArrayList(); + for(int x = (base.getBlockX() - changeX); x <= (base.getBlockX() + changeX); x++) + { + for(int y = (base.getBlockY() - changeY); y <= (base.getBlockY() + changeY); y++) + { + for(int z = (base.getBlockZ() - changeZ); z <= (base.getBlockZ() + changeZ); z++) + { + Location loc = new Location(base.getWorld(), x, y, z); + locs.add(loc); + } + } + } + + return locs; + } + + private boolean canSpawnMob(Location l) + { + Block b = l.getBlock(); + if ((b.getType() != Material.AIR) && !b.getType().toString().contains("WATER") && !UtilBlock.airFoliage(b)) + return false; + + Block b2 = b.getRelative(BlockFace.UP); + if ((b2.getType() != Material.AIR) && !b2.getType().toString().contains("WATER") && !UtilBlock.airFoliage(b2)) + return false; + + return true; + } + + private void spawn() + { + if (!_canSpawn) + return; + + List possible = getLocations(_spawnerBlock, 2, 1, 2); + boolean spawned = false; + int i = UtilMath.r(possible.size()); + while (!spawned) + { + Location l = possible.get(i); + if (canSpawnMob(l)) + { + Entity e = Host.getArcadeManager().GetCreature().SpawnEntity(l, _toSpawn); + UtilEnt.Vegetate(e); + spawned = true; + _lastSpawned = System.currentTimeMillis(); + continue; + } + + int newi = 0; + if (i == (possible.size() - 1)) + i = newi; + else + i++; + } + } + + public void update() + { + if (_spawnerBlock.getBlock().getType() != Material.MOB_SPAWNER) + _canSpawn = false; + else + _canSpawn = true; + + if (_canSpawn) + { + if (!UtilTime.elapsed(_lastSpawned, UtilTime.convert(10, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + _canSpawn = false; + else + _canSpawn = true; + } + + spawn(); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamBeacon.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamBeacon.java new file mode 100644 index 000000000..a67db3d51 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamBeacon.java @@ -0,0 +1,74 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.util.HashSet; + +import nautilus.game.arcade.game.GameTeam; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class TeamBeacon +{ + private GameTeam _team; + private Block _block; + //private Location _core; + + public TeamBeacon(GameTeam team, Block block/*, Location core*/) + { + _team = team; + _block = block; + //_core = core; + + _block.setType(Material.BEACON); + } + + /*public boolean isBlock(Block match) + { + if (match.getX() == _block.getX()) + if (match.getZ() == _block.getZ()) + if (match.getY() == _block.getY()) + return true; + + return false; + }*/ + + /*public Block getBlock() + { + return _block; + }*/ + + public void setBlock(Block block) + { + _block = block; + block.setType(Material.BEACON); + } + + public void update() + { + if (_block.getType() != Material.BEACON) + return; + + HashSet ignore = new HashSet(); + ignore.add(Material.GLASS); + ignore.add(Material.THIN_GLASS); + ignore.add(Material.STAINED_GLASS); + ignore.add(Material.STAINED_GLASS_PANE); + //Bukkit.broadcastMessage(UtilBlock.getHighest(_block.getWorld(), _block.getX(), _block.getZ(), ignore) + ""); + //if (!isBlock(UtilBlock.getHighest(_block.getWorld(), _block.getX(), _block.getZ(), ignore).getRelative(BlockFace.DOWN))) + //return; + + for (Player player : _team.GetPlayers(true)) + { + if (player.getLocation().distance(_block.getLocation()) < 15) + { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 5 * 20, 0)); + //player.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 5 * 20, 0)); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 5 * 20, 0)); + //player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 5 * 20, 0)); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamCrystal.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamCrystal.java new file mode 100644 index 000000000..afea34d7e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamCrystal.java @@ -0,0 +1,14 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Location; + +public class TeamCrystal extends TeamTowerBase +{ + public TeamCrystal(MinecraftLeague host, TowerManager manager, GameTeam team, Location spawn) + { + super(host, manager, team, spawn); + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamTower.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamTower.java new file mode 100644 index 000000000..3fab4b528 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamTower.java @@ -0,0 +1,17 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Location; + +public class TeamTower extends TeamTowerBase +{ + public Integer Number; + + public TeamTower(MinecraftLeague host, TowerManager manager, GameTeam team, Location spawn, Integer number) + { + super(host, manager, team, spawn); + Number = number; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamTowerBase.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamTowerBase.java new file mode 100644 index 000000000..5eff66a55 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TeamTowerBase.java @@ -0,0 +1,312 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.util.ArrayList; +import java.util.List; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.hologram.Hologram; +import mineplex.core.recharge.Recharge; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.DataLoc; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.EnderCrystal; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Wither; +import org.bukkit.util.Vector; + +public abstract class TeamTowerBase +{ + private MinecraftLeague _host; + private TowerManager _manager; + private Location _spawn; + private GameTeam _team; + private Double _health, _maxHealth; + private EnderCrystal _entity; + private Hologram _name, _healthTag; + private String _type; + public boolean Alive; + public boolean Vulnerable; + + public TeamTowerBase(MinecraftLeague host, TowerManager manager, GameTeam team, Location spawn) + { + _host = host; + _manager = manager; + _spawn = spawn.clone().add(0, 3.2, 0); + _team = team; + _maxHealth = 11111D; + _health = 11111D; + _type = "Tower"; + if (this instanceof TeamCrystal) + _type = "Core"; + _name = new Hologram(_host.getArcadeManager().getHologramManager(), _spawn.clone().add(1, 3, 0), team.GetColor() + team.getDisplayName() + "'s " + _type); + _healthTag = new Hologram(_host.getArcadeManager().getHologramManager(), _spawn.clone().add(1, 2, 0), formatHealth(_health)); + + spawn(); + } + + private void spawn() + { + _name.start(); + _healthTag.start(); + _entity = (EnderCrystal) _host.getArcadeManager().GetCreature().SpawnEntity(_spawn, EntityType.ENDER_CRYSTAL); + _health = _maxHealth; + Alive = true; + } + + private void kill(Player player) + { + String message = ""; + if (player != null) + message = _host.GetTeam(player).GetColor() + player.getName() + _team.GetColor() + " has destroyed " + _team.getDisplayName() + "'s " + _type + "!"; + else + message = _team.GetColor() + _team.getDisplayName() + "'s " + _type + " has been destroyed!"; + + //Bukkit.broadcastMessage(message); + UtilTextMiddle.display("", message); + + if (!_type.equalsIgnoreCase("Tower")) + { + for (Player inform : _team.GetPlayers(true)) + UtilTextMiddle.display(C.cGold + "Team Crystal Destroyed", C.cGold + "You will no longer respawn and will be poisoned in 5 minutes!", inform); + } + + Alive = false; + _entity.remove(); + _healthTag.stop(); + _name.stop(); + Bukkit.getScheduler().runTaskLater(_host.Manager.getPlugin(), new Runnable() + { + public void run() + { + playDeathAnimation(_spawn); + } + }, 20 * 5); + detonate(); + _manager.handleTowerDeath(this); + } + + private void playDeathAnimation(Location loc) + { + _spawn.getWorld().playSound(loc, Sound.EXPLODE, 10, 0); + //GFX subject to change + Location loc1 = loc.clone().add(-2, 3, -2); + Location loc2 = loc.clone().add(2, 0, 2); + Location loc3 = loc.clone().add(2, 3, 2); + Location loc4 = loc.clone().add(-2, 0, -2); + Location particle1 = loc2.clone(); + Location particle2 = loc4.clone(); + while (UtilMath.offset(loc1, loc) >= UtilMath.offset(particle1, loc)) + { + Vector v = UtilAlg.getTrajectory(particle1, loc1); + //UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, particle, v, 0, 1, ViewDist.NORMAL, UtilServer.getPlayers()); + UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, particle1, v, 0, 5, ViewDist.MAX, UtilServer.getPlayers()); + particle1.add(v); + } + while (UtilMath.offset(loc3, loc) >= UtilMath.offset(particle2, loc)) + { + Vector v = UtilAlg.getTrajectory(particle2, loc3); + UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, particle2, v, 0, 5, ViewDist.MAX, UtilServer.getPlayers()); + particle2.add(v); + } + } + + private void detonate() + { + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, _spawn, null, 0, 2, ViewDist.NORMAL); + _spawn.getWorld().playSound(_spawn, Sound.EXPLODE, 10, 0); + List blocks = new ArrayList(); + Location bottom = _spawn.clone().subtract(0, -3.2, 0); + for (int i = 0; i < 23; i++) + { + blocks.addAll(UtilBlock.getInSquare(bottom.clone().add(0, i, 0).getBlock(), 4)); + } + for (int i = 0; i < 3; i++) + { + getBeacon().clone().add(0, i, 0).getBlock().setType(Material.BEDROCK); + } + _host.Manager.GetExplosion().BlockExplosion(blocks, _spawn, false, true); + for (Entity e : _host.WorldData.World.getEntities()) + { + if (e instanceof Wither) + { + LivingEntity le = (LivingEntity) e; + le.setHealth(le.getHealth() / 2); + } + } + for (LivingEntity le : UtilEnt.getInRadius(_spawn, 5).keySet()) + { + if (UtilMath.offset(le.getLocation(), _spawn) <= 5) + { + if (UtilPlayer.isSpectator(le)) + continue; + if (le instanceof Player) + { + _host.storeGear((Player)le); + } + le.damage(6); + } + } + } + + public Location getBeacon() + { + Location ret = null; + for (Location loc : _host.WorldData.GetDataLocs(DataLoc.BEACON.getKey())) + { + if (ret == null || UtilMath.offset(ret, _spawn) > UtilMath.offset(loc, _spawn)) + ret = loc; + } + + return ret; + } + + public Entity getEntity() + { + return _entity; + } + + public boolean isEntity(Entity e) + { + return e.getEntityId() == _entity.getEntityId(); + } + + public boolean canDamage(Player player) + { + if (UtilPlayer.isSpectator(player)) + return false; + + if (_host.GetTeam(player) == _team) + return false; + + if (!_host.IsPlaying(player)) + return false; + + if (!Recharge.Instance.usable(player, "Damage TeamTower")) + return false; + + return true; + } + + public Double getHealth() + { + if (!Alive) + return 0D; + + return _health; + } + + public String formatHealth(Double healthNumber) + { + String tag = healthNumber.toString(); + + if (healthNumber > (.9 * _maxHealth)) + tag = C.cGreen + tag; + else if (healthNumber < (.45 * _maxHealth)) + tag = C.cRed + tag; + else + tag = C.cYellow + tag; + + return tag; + } + + public ChatColor getHealthColor() + { + if (!Alive) + return ChatColor.GRAY; + + ChatColor color = ChatColor.YELLOW; + + if (_health > (.9 * _maxHealth)) + color = ChatColor.GREEN; + else if (_health < (.45 * _maxHealth)) + color = ChatColor.RED; + + return color; + } + + public boolean damage(double damage, Player player) + { + if (!Vulnerable) + return false; + + Double newHealth = Math.max(_health - damage, 0); + + if (newHealth == 0) + { + kill(player); + return true; + } + + _health = newHealth; + if (player != null) + Recharge.Instance.use(player, "Damage TeamTower", 400, false, false); + return false; + } + + public Location getLocation() + { + return _spawn; + } + + public GameTeam getTeam() + { + return _team; + } + + public void update() + { + _healthTag.setText(formatHealth(_health)); + + if (Alive) + { + if (_entity.isDead() || !_entity.isValid()) + { + _entity = (EnderCrystal) _host.getArcadeManager().GetCreature().SpawnEntity(_spawn, EntityType.ENDER_CRYSTAL); + } + + if (_health > _maxHealth) + { + _health = _maxHealth; + } + } + } + + public void setMaxHealth(Double health) + { + _maxHealth = Math.abs(health); + } + + public void setVulnerable(boolean vulnerable) + { + if (vulnerable) + { + getBeacon().getBlock().setType(Material.BEACON); + Vulnerable = vulnerable; + } + else + { + getBeacon().getBlock().setType(Material.BEDROCK); + Vulnerable = vulnerable; + } + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TowerAlert.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TowerAlert.java new file mode 100644 index 000000000..eafdc46df --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TowerAlert.java @@ -0,0 +1,70 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import nautilus.game.arcade.game.GameTeam; + +import org.bukkit.Instrument; +import org.bukkit.Note; +import org.bukkit.Note.Tone; +import org.bukkit.entity.Player; + +public class TowerAlert +{ + private ConcurrentHashMap _alerts = new ConcurrentHashMap(); + //private ConcurrentHashMap _alertType = new ConcurrentHashMap(); + + public void alert(GameTeam team, TeamTowerBase tower) + { + if (!UtilTime.elapsed(_alerts.getOrDefault(team, (long) 1), UtilTime.convert(7, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + for (Player player : team.GetPlayers(true)) + playSound(player); + + return; + } + + _alerts.put(team, System.currentTimeMillis()); + + String type = ""; + if (tower instanceof TeamTower) + { + int number = ((TeamTower)tower).Number; + if (number == 1) + /*_alertType.put(team, */type = "First Tower";//); + else + /*_alertType.put(team, */type = "Second Tower";//); + } + else + /*_alertType.put(team, */type = "Crystal";//); + + showAlert(team, type); + } + + private void showAlert(GameTeam team, String type) + { + /*for (GameTeam team : _alerts.keySet()) + {*/ + for (Player player : team.GetPlayers(true)) + { + UtilTextMiddle.display("", C.cGold + "Your " + /*_alertType.get(team)*/type + " is under attack!", 0, 20 * 5, 0, player); + playSound(player); + } + + /*if (UtilTime.elapsed(_alerts.get(team), UtilTime.convert(5, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + _alerts.remove(team); + _alertType.remove(team); + }*/ + //} + } + + private void playSound(Player player) + { + player.playNote(player.getLocation(), Instrument.PIANO, Note.sharp(1, Tone.A)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TowerManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TowerManager.java new file mode 100644 index 000000000..4ab0a41fa --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/TowerManager.java @@ -0,0 +1,307 @@ +package nautilus.game.arcade.game.games.minecraftleague.data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.DataLoc; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.world.WorldData; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +public class TowerManager implements Listener +{ + public MinecraftLeague Host; + private ConcurrentHashMap _towers = new ConcurrentHashMap(); + private ConcurrentHashMap _vulnerableTower = new ConcurrentHashMap(); + private ConcurrentHashMap _def = new ConcurrentHashMap(); + //private ConcurrentHashMap _mapZone = new ConcurrentHashMap(); + private ConcurrentHashMap _beacons = new ConcurrentHashMap(); + private OreGenerator _ore; + public boolean Attack = false; + + public TowerManager(MinecraftLeague host) + { + Host = host; + _ore = new OreGenerator(); + } + + private void makeVulnerable(TeamTowerBase base) + { + if (base instanceof TeamTower) + _vulnerableTower.put(base.getTeam(), ((TeamTower)base).Number); + else + _vulnerableTower.put(base.getTeam(), 3); + + base.Vulnerable = true; + _beacons.get(base.getTeam()).setBlock(base.getBeacon().getBlock()); + } + + public void ironOreGen(GameTeam team, boolean start) + { + int amount = 20; + if (start) + amount = 50; + + for (Location loc : Host.WorldData.GetCustomLocs(DataLoc.DIAMOND_ORE.getKey())) + { + loc.getBlock().setType(Material.DIAMOND_ORE); + } + + if (start) + { + if (team.GetColor() == ChatColor.RED) + _ore.generateOre(Material.IRON_ORE, Host.WorldData.GetCustomLocs(DataLoc.RED_ORE.getKey()), amount); + else + _ore.generateOre(Material.IRON_ORE, Host.WorldData.GetCustomLocs(DataLoc.BLUE_ORE.getKey()), amount); + + for (Location loc : Host.WorldData.GetCustomLocs(DataLoc.MOSH_IRON.getKey())) + { + loc.getBlock().setType(Material.STONE); + } + } + else + { + _ore.generateOre(Material.IRON_ORE, Host.WorldData.GetCustomLocs(DataLoc.MOSH_IRON.getKey()), amount); + UtilTextMiddle.display("", "Valuable Ores have respawned in the middle!"); + } + } + + private List getAllTeamTowers(GameTeam team) + { + List ret = new ArrayList(); + + for (TeamTowerBase tower : _towers.keySet()) + { + if (_towers.get(tower).GetColor() == team.GetColor()) + { + ret.add(tower); + } + } + + return ret; + } + + public LinkedList getTeamTowers(GameTeam team) + { + LinkedList ret = new LinkedList(); + TeamTower one = null; + TeamTower two = null; + TeamCrystal three = null; + + for (TeamTowerBase tower : getAllTeamTowers(team)) + { + if (tower instanceof TeamCrystal) + { + three = (TeamCrystal) tower; + continue; + } + if (one == null) + { + one = (TeamTower) tower; + continue; + } + if (one.Number > ((TeamTower)tower).Number) + { + two = one; + one = (TeamTower) tower; + continue; + } + two = (TeamTower) tower; + } + + ret.add(one); + ret.add(two); + ret.add(three); + + return ret; + } + + public Integer getAmountAlive(GameTeam team) + { + int i = 0; + + for (TeamTowerBase tower : getAllTeamTowers(team)) + { + if (tower.Alive) + i++; + } + + return i; + } + + public TeamTowerBase getVulnerable(GameTeam team) + { + return getTeamTowers(team).get(_vulnerableTower.get(team) - 1); + } + + public void parseTowers(WorldData data) + { + GameTeam red = Host.GetTeam(ChatColor.RED); + GameTeam blue = Host.GetTeam(ChatColor.AQUA); + //int[] redRGB = new int[] {255, 0, 0}; + //int[] blueRGB = new int[] {0, 0, 255}; + + _towers.put(new TeamTower(Host, this, red, data.GetCustomLocs(DataLoc.RED_TOWER.getKey() + " 1").get(0), 1), red); + _towers.put(new TeamTower(Host, this, red, data.GetCustomLocs(DataLoc.RED_TOWER.getKey() + " 2").get(0), 2), red); + _towers.put(new TeamCrystal(Host, this, red, data.GetCustomLocs(DataLoc.RED_CRYSTAL.getKey()).get(0)), red); + + _towers.put(new TeamTower(Host, this, blue, data.GetCustomLocs(DataLoc.BLUE_TOWER.getKey() + " 1").get(0), 1), blue); + _towers.put(new TeamTower(Host, this, blue, data.GetCustomLocs(DataLoc.BLUE_TOWER.getKey() + " 2").get(0), 2), blue); + _towers.put(new TeamCrystal(Host, this, blue, data.GetCustomLocs(DataLoc.BLUE_CRYSTAL.getKey()).get(0)), blue); + + for (TeamTowerBase tower : _towers.keySet()) + { + _def.put(tower, new DefenderAI(this, tower)); + /*int[] rgb; + if (tower.getTeam().GetColor() == red.GetColor()) + rgb = redRGB; + else + rgb = blueRGB; + + MapZone zone = new MapZone(tower.getLocation(), rgb); + Host.MapZones.add(zone); + _mapZone.put(tower, zone);*/ + } + + TeamBeacon redb = new TeamBeacon(red, getTeamTowers(red).getFirst().getBeacon().getBlock()); + _beacons.put(red, redb); + Host.Beacons.put(red, redb); + TeamBeacon blueb = new TeamBeacon(blue, getTeamTowers(blue).getFirst().getBeacon().getBlock()); + _beacons.put(blue, blueb); + Host.Beacons.put(blue, blueb); + makeVulnerable(getTeamTowers(red).getFirst()); + makeVulnerable(getTeamTowers(blue).getFirst()); + ironOreGen(red, true); + ironOreGen(blue, true); + } + + public void prepareHealth(int players, double multiplier) + { + for (TeamTowerBase tower : _towers.keySet()) + { + if (tower instanceof TeamCrystal) + tower.setMaxHealth(players * multiplier); + else + { + int divisor = 3 - ((TeamTower)tower).Number; + double rawHealth = (.67 * multiplier) * players; + Double health = new BigDecimal(rawHealth / divisor).intValue() * 1D; + tower.setMaxHealth(health); + } + } + } + + public void handleTowerDeath(TeamTowerBase towerBase) + { + towerBase.setVulnerable(false); + //ironOreGen(towerBase.getTeam()); + /*for (Player player : towerBase.getTeam().GetPlayers(true)) + { + player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 20 * 60, 1)); + }*/ + /*Bukkit.getScheduler().runTaskLater(Host.Manager.getPlugin(), new Runnable() + { + public void run() + { + UtilTextMiddle.display("", towerBase.getTeam().GetColor() + towerBase.getTeam().GetName() + " Team ores have been replenished!", UtilServer.getPlayers()); + } + }, 20 * 5);*/ + //_mapZone.get(towerBase).setValid(false); + if (towerBase instanceof TeamCrystal) + { + GameTeam enemy = null; + if (towerBase.getTeam() == Host.GetTeam(ChatColor.RED)) + enemy = Host.GetTeam(ChatColor.AQUA); + else + enemy = Host.GetTeam(ChatColor.RED); + + Host.ScoreboardAutoWrite = false; + Host.writeEndSb(enemy.GetColor() + enemy.getDisplayName()); + Host.AnnounceEnd(enemy); + + for (GameTeam team : Host.GetTeamList()) + { + if (enemy != null && team.equals(enemy)) + { + for (Player player : team.GetPlayers(false)) + Host.AddGems(player, 10, "Winning Team", false, false); + } + + for (Player player : team.GetPlayers(false)) + if (player.isOnline()) + Host.AddGems(player, 10, "Participation", false, false); + } + Host.SetState(GameState.End); + + //Host.Objective.setTeamObjective(enemy, new KillObjective()); + + //Host.TeamPoison.put(towerBase.getTeam(), System.currentTimeMillis() + (UtilTime.convert(5, TimeUnit.MINUTES, TimeUnit.MILLISECONDS) - UtilTime.convert(1, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))); + + return; + } + for (Player player : towerBase.getTeam().GetPlayers(true)) + { + if (!UtilPlayer.isSpectator(player)) + { + boolean replaced = false; + if (UtilItem.isLeatherProduct(player.getInventory().getHelmet())) + { + if (replaced) + continue; + replaced = true; + player.getInventory().setHelmet(new ItemBuilder(Material.GOLD_HELMET).setUnbreakable(true).build()); + } + if (UtilItem.isLeatherProduct(player.getInventory().getLeggings())) + { + if (replaced) + continue; + replaced = true; + player.getInventory().setLeggings(new ItemBuilder(Material.GOLD_LEGGINGS).setUnbreakable(true).build()); + } + if (UtilItem.isLeatherProduct(player.getInventory().getChestplate())) + { + if (replaced) + continue; + replaced = true; + player.getInventory().setChestplate(new ItemBuilder(Material.GOLD_CHESTPLATE).setUnbreakable(true).build()); + } + if (UtilItem.isLeatherProduct(player.getInventory().getBoots())) + { + if (replaced) + continue; + replaced = true; + player.getInventory().setBoots(new ItemBuilder(Material.GOLD_BOOTS).setUnbreakable(true).build()); + } + } + } + makeVulnerable(getTeamTowers(towerBase.getTeam()).get(_vulnerableTower.get(towerBase.getTeam()))); + } + + public void toggleAttack() + { + //Attack = !Attack; + } + + public void update() + { + for (TeamTowerBase tower : _towers.keySet()) + { + tower.update(); + _def.get(tower).update(); + } + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/map/ItemMapManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/map/ItemMapManager.java new file mode 100644 index 000000000..0a077c627 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/map/ItemMapManager.java @@ -0,0 +1,673 @@ +package nautilus.game.arcade.game.games.minecraftleague.data.map; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map.Entry; + +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import net.minecraft.server.v1_8_R3.Block; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.IBlockData; +import net.minecraft.server.v1_8_R3.MaterialMapColor; +import net.minecraft.server.v1_8_R3.PersistentCollection; + +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.map.MapRenderer; +import org.bukkit.map.MapView; + +import com.google.common.collect.HashMultiset; +import com.google.common.collect.Iterables; +import com.google.common.collect.Multisets; + +public class ItemMapManager /*extends MiniPlugin*/ implements Listener +{ + private MinecraftLeague _host; + + private int _blocksScan = 16; + private Comparator> _comparator; + private int _halfMapSize; + private int[][] _heightMap; + private boolean _loadWorld = true; + private HashMap _map = new HashMap(); + private short _mapId = (short) UtilMath.r(Short.MAX_VALUE); + private ArrayList> _scanList = new ArrayList>(); + private World _world; + private int _centerX; + private int _centerZ; + private int _scale; + + public ItemMapManager(MinecraftLeague host, World world, int minX, int minZ, int maxX, int maxZ) + { + //super("ItemMapManager", host.getArcadeManager().getPlugin()); + Bukkit.getPluginManager().registerEvents(this, host.getArcadeManager().getPlugin()); + + _host = host; + + _centerX = minX + ((maxX - minX) / 2); + _centerZ = minZ + ((maxZ - minZ) / 2); + _centerX = (int) (Math.round(_centerX / 16D) * 16); + _centerZ = (int) (Math.round(_centerZ / 16D) * 16); + + _halfMapSize = (int) (Math.ceil(Math.max((maxX - minX) / 2D, (maxZ - minZ) / 2D) / 16D) * 16); + + ArrayList> list = new ArrayList>(); + + for (int scale = 1; scale <= 16; scale++) + { + int s = _halfMapSize; + + if ((s / scale) > 127) + continue; + + while (s < 10000 && (s % 16 != 0 || s % scale != 0)) + { + s += 16; + } + + if (s < 10000) + { + list.add(new HashMap.SimpleEntry(scale, s)); + } + } + + if (list.isEmpty()) + { + _scale = 16; + _halfMapSize = 127 * 8; + } + else + { + Collections.sort(list, new Comparator>() + { + + @Override + public int compare(Entry o1, Entry o2) + { + return Integer.compare(o1.getValue(), o2.getValue()); + } + }); + + _scale = list.get(0).getKey(); + _halfMapSize = list.get(0).getValue(); + + System.out.print( + "Using scale " + _scale + ", Size: " + _halfMapSize + ", CenterX: " + _centerX + ", CenterZ: " + _centerZ); + } + + _heightMap = new int[(_halfMapSize * 2) + 16][]; + + _comparator = new Comparator>() + { + + @Override + public int compare(Entry o1, Entry o2) + { + // Render the places outside the map first to speed up visual errors fixing + int outsideMap = Boolean.compare(o1.getValue() < -_halfMapSize, o2.getValue() < -_halfMapSize); + + if (outsideMap != 0) + { + return -outsideMap; + } + + double dist1 = 0; + double dist2 = 0; + + for (Player player : UtilServer.getPlayers()) + { + dist1 += getDistance(o1, player.getLocation().getX(), player.getLocation().getZ()); + dist2 += getDistance(o2, player.getLocation().getX(), player.getLocation().getZ()); + } + + if (dist1 != dist2) + { + return Double.compare(dist1, dist2); + } + + dist1 = getDistance(o1, 0, 0); + dist2 = getDistance(o2, 0, 0); + + return Double.compare(dist1, dist2); + + } + }; + + for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan) + { + for (int z = -_halfMapSize - 16; z < _halfMapSize; z += (z < -_halfMapSize ? 16 : _blocksScan)) + { + _scanList.add(new HashMap.SimpleEntry(x, z)); + } + } + + for (int s = 1; s <= 2; s++) + { + if (s == 2) + { + s = getScale(); + + if (s == 1) + break; + } + + int size = (_halfMapSize * 2) / s; + Byte[][] bytes = new Byte[size][]; + + for (int i = 0; i < size; i++) + { + bytes[i] = new Byte[size]; + } + + _map.put(s, bytes); + } + + for (int i = 0; i < _heightMap.length; i++) + { + _heightMap[i] = new int[_heightMap.length]; + } + + _world = world; + + try + { + File foundFile = null; + + for (File f : new File("world/data").listFiles()) + { + if (f.getName().startsWith("map_")) + { + foundFile = f; + break; + } + } + + if (foundFile == null) + { + PersistentCollection collection = ((CraftWorld) _world).getHandle().worldMaps; + Field f = collection.getClass().getDeclaredField("d"); + f.setAccessible(true); + ((HashMap) f.get(collection)).put("map", (short) 0); + } + + MapView view = Bukkit.createMap(_world); + _mapId = view.getId(); + setupRenderer(view); + + for (int i = 0; i < 100; i++) + { + setupRenderer(Bukkit.createMap(_world));// Ensures the following 100 maps are unused + } + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + rebuildScan(); + } + + private void setupRenderer(MapView view) + { + for (MapRenderer renderer : view.getRenderers()) + { + view.removeRenderer(renderer); + } + + view.addRenderer(new ItemMapRenderer(this, _host)); + } + + public int getScale() + { + return _scale; + } + + public int getX() + { + return _centerX; + } + + public int getZ() + { + return _centerZ; + } + + /** + * Get the center of the map. + */ + public int calcMapCenter(int zoom, int cord) + { + int mapSize = _halfMapSize / zoom; // This is how large the map is in pixels + + int mapCord = cord / zoom; // This is pixels from true center of map, not held map + + int fDiff = mapSize - -mapCord; + int sDiff = mapSize - mapCord; + + double chunkBlock = cord & 0xF; + cord -= chunkBlock; + chunkBlock /= zoom; + + /*if ((fDiff < 64 || sDiff < 64) && (Math.abs(fDiff - sDiff) > 1)) + { + cord += (fDiff > sDiff ? Math.floor(chunkBlock) : Math.ceil(chunkBlock)); + } + else*/ + { + cord += (int) Math.floor(chunkBlock) * zoom; + } + + while ((fDiff < 64 || sDiff < 64) && (Math.abs(fDiff - sDiff) > 1)) + { + int change = (fDiff > sDiff ? -zoom : zoom); + cord += change; + + mapCord = cord / zoom; + + fDiff = mapSize - -mapCord; + sDiff = mapSize - mapCord; + } + + return cord; + } + + private void colorWorldHeight(int zoom, int startingX, int startingZ) + { + if (zoom == 0) + zoom = 1; + + Byte[][] map = _map.get(zoom); + + for (int x = startingX; x < startingX + _blocksScan; x += zoom) + { + double d0 = 0; + + // Prevents ugly lines for the first line of Z + + for (int addX = 0; addX < zoom; addX++) + { + for (int addZ = 0; addZ < zoom; addZ++) + { + int hX = x + addX + _halfMapSize; + int hZ = (startingZ - zoom) + addZ + _halfMapSize; + + if (hX >= _halfMapSize * 2 || hZ >= _halfMapSize * 2) + { + continue; + } + + d0 += _heightMap[hX + 16][hZ + 16] / (zoom * zoom); + } + } + + for (int z = startingZ; z < startingZ + _blocksScan; z += zoom) + { + // Water depth colors not included + double d1 = 0; + + for (int addX = 0; addX < zoom; addX++) + { + for (int addZ = 0; addZ < zoom; addZ++) + { + int hX = x + addX + _halfMapSize; + int hZ = z + addZ + _halfMapSize; + + if (hX >= _halfMapSize * 2 || hZ >= _halfMapSize * 2) + { + continue; + } + + d1 += _heightMap[hX + 16][hZ + 16] / (zoom * zoom); + } + } + + double d2 = (d1 - d0) * 4.0D / (zoom + 4) + ((x + z & 0x1) - 0.5D) * 0.4D; + byte b0 = 1; + + d0 = d1; + + if (d2 > 0.6D) + { + b0 = 2; + } + else if (d2 > 1.2D) + { + b0 = 3; + } + else if (d2 < -0.6D) + { + b0 = 0; + } + + int origColor = map[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] - 1; + + /*if (color < 4) + { + d2 = waterDepth * 0.1D + (k1 + j2 & 0x1) * 0.2D; + b0 = 1; + if (d2 < 0.5D) + { + b0 = 2; + } + + if (d2 > 0.9D) + { + b0 = 0; + } + }*/ + + byte color = (byte) (origColor + b0); + map[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color; + } + } + } + + private void drawWorldScale(int zoom, int startingX, int startingZ) + { + Byte[][] first = _map.get(1); + Byte[][] second = _map.get(zoom); + + for (int x = startingX; x < startingX + _blocksScan; x += zoom) + { + for (int z = startingZ; z < startingZ + _blocksScan; z += zoom) + { + HashMultiset hashmultiset = HashMultiset.create(); + + for (int addX = 0; addX < zoom; addX++) + { + for (int addZ = 0; addZ < zoom; addZ++) + { + int pX = x + addX + _halfMapSize; + int pZ = z + addZ + _halfMapSize; + + if (pX >= first.length || pZ >= first.length) + { + continue; + } + + Byte b = first[pX][pZ]; + + if (b == null) + continue; + + hashmultiset.add(b); + } + } + + Byte color = Iterables.getFirst(Multisets.copyHighestCountFirst(hashmultiset), (byte) 0); + + second[(x + _halfMapSize) / zoom][(z + _halfMapSize) / zoom] = color; + } + } + } + + private double getDistance(double x1, double z1, double x2, double z2) + { + x1 = (x1 - x2); + z1 = (z1 - z2); + + return (x1 * x1) + (z1 * z1); + } + + private double getDistance(Entry entry, double x1, double z1) + { + return getDistance(x1 + _centerX, z1 + _centerZ, entry.getKey() + (_blocksScan / 2), + entry.getValue() + (_blocksScan / 2)); + } + + public Byte[][] getMap(int scale) + { + return _map.get(scale); + } + + public int getMapSize() + { + return _halfMapSize; + } + + /*@EventHandler + public void onServerTransfer(ServerTransferEvent event) + { + Player p = event.getPlayer(); + + p.sendMessage(C.cDRed + C.Bold + "WARNING!"); + p.sendMessage(C.cYellow + "There's a bug where switching servers may freeze the Team Map!"); + p.sendMessage(C.cYellow + "If you want to play Minecraft League again and this error occurs, rejoin the Mineplex server!"); + }*/ + + private void rebuildScan() + { + for (int x = -_halfMapSize; x < _halfMapSize; x += _blocksScan) + { + for (int z = -_halfMapSize - 16; z < _halfMapSize; z += (z < -_halfMapSize ? 16 : _blocksScan)) + { + _scanList.add(new HashMap.SimpleEntry(x, z)); + } + } + + if (!_loadWorld) + { + Iterator> itel = _scanList.iterator(); + + while (itel.hasNext()) + { + Entry entry = itel.next(); + boolean removeEntry = true; + + for (Player player : UtilServer.getPlayers()) + { + if (Math.sqrt(getDistance(entry, player.getLocation().getX(), player.getLocation().getZ())) < 200) + { + removeEntry = false; + break; + } + } + + if (removeEntry) + { + itel.remove(); + } + } + } + + Collections.sort(_scanList, _comparator); + } + + @EventHandler + public void renderMap(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + return; + + if (_scanList.isEmpty()) + { + if (_loadWorld) + { + _loadWorld = false; + System.out.print("Finished first map scan and render"); + } + + if (UtilServer.getPlayers().length == 0) + return; + + rebuildScan(); + } + else if (_scanList.size() % 20 == 0) + { + Collections.sort(_scanList, _comparator); + } + + Entry entry = _scanList.remove(0); + + int startingX = entry.getKey(); + int startingZ = entry.getValue(); + + boolean outsideMap = startingZ < -_halfMapSize; + + scanWorldMap(startingX, startingZ, !outsideMap); + + if (outsideMap) + { + return; + } + + for (int s = 1; s <= 2; s++) + { + if (s == 2) + { + s = getScale(); + + if (s == 1) + break; + } + + if (s == 13 && _loadWorld) + continue; + + if (!outsideMap) + { + drawWorldScale(s, startingX, startingZ); + } + + colorWorldHeight(s, startingX, startingZ); + } + + colorWorldHeight(0, startingX, startingZ); + } + + public void scanWorldMap(int startingX, int startingZ, boolean setColors) + { + Byte[][] map = _map.get(1); + + for (int beginX = startingX; beginX < startingX + _blocksScan; beginX += 16) + { + for (int beginZ = startingZ - (startingZ > -_halfMapSize ? 16 : 0); beginZ < startingZ + + (setColors ? _blocksScan : 16); beginZ += 16) + { + Chunk chunk = _world.getChunkAt((beginX + _centerX) / 16, (beginZ + _centerZ) / 16); + boolean loaded = false; + + if (!chunk.isLoaded()) + { + if (_loadWorld) + { + loaded = chunk.load(); + } + else + { + continue; + } + } + + net.minecraft.server.v1_8_R3.Chunk nmsChunk = ((CraftChunk) chunk).getHandle(); + + for (int x = beginX; x < beginX + 16; x++) + { + for (int z = beginZ; z < beginZ + 16; z++) + { + int color = 0; + + if (!nmsChunk.isEmpty()) + { + int k3 = x & 0xF; + int l3 = z & 0xF; + + int l4 = nmsChunk.b(k3, l3) + 1; + IBlockData iblockdata = Blocks.AIR.getBlockData(); + + if (l4 > 1) + { + do + { + l4--; + iblockdata = nmsChunk.getBlockData(new BlockPosition(k3, l4, l3)); + } + while (iblockdata.getBlock().g(iblockdata) == MaterialMapColor.b && (l4 > 0)); + + if ((l4 > 0) && (iblockdata.getBlock().getMaterial().isLiquid())) + { + int j5 = l4 - 1; + Block block1; + do + { + block1 = nmsChunk.getType(new BlockPosition(k3, j5--, l3)); + } + while ((j5 > 0) && (block1.getMaterial().isLiquid())); + } + } + + _heightMap[x + _halfMapSize + 16][z + _halfMapSize + 16] = l4; + + if (setColors) + { + // color = block.f(i5).M; + IBlockData data = nmsChunk.getBlockData(new BlockPosition(k3, l4, l3)); + color = data.getBlock().g(data).M; + + color = (byte) ((color * 4) + 1); + } + } + + if (setColors && beginZ >= startingZ) + { + map[x + _halfMapSize][z + _halfMapSize] = (byte) color; + } + } + + if (loaded) + { + chunk.unload(); + } + } + } + } + } + + public void setMap(Player player) + { + for (ItemStack item : UtilInv.getItems(player)) + { + if (item.getType() == Material.MAP && item.getDurability() == _mapId) + { + return; + } + } + + ItemStack item = new ItemBuilder(Material.MAP, 1, _mapId).setTitle("Team Map").build(); + + int slot = player.getInventory().firstEmpty(); + + if (slot >= 0) + { + ItemStack mapSlot = player.getInventory().getItem(8); + + if (mapSlot == null || mapSlot.getType() == Material.AIR) + { + slot = 8; + } + + player.getInventory().setItem(slot, item); + } + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/map/ItemMapRenderer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/map/ItemMapRenderer.java new file mode 100644 index 000000000..e161d0583 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/map/ItemMapRenderer.java @@ -0,0 +1,161 @@ +package nautilus.game.arcade.game.games.minecraftleague.data.map; + +import mineplex.core.recharge.Recharge; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.game.games.minecraftleague.data.MapZone; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.map.MapCanvas; +import org.bukkit.map.MapCursor; +import org.bukkit.map.MapCursorCollection; +import org.bukkit.map.MapPalette; +import org.bukkit.map.MapRenderer; +import org.bukkit.map.MapView; + +public class ItemMapRenderer extends MapRenderer +{ + private ItemMapManager _manager; + private MinecraftLeague _host; + + public ItemMapRenderer(ItemMapManager itemMapManager, MinecraftLeague host) + { + super(true); + + _manager = itemMapManager; + _host = host; + } + + @Override + public void render(MapView mapView, MapCanvas canvas, Player player) + { + int zoom = _manager.getScale(); + + Byte[][] map = _manager.getMap(zoom); + + int centerX = 0; + int centerZ = 0; + + // We have this cooldown to squeeze out every single bit of performance from the server. + if (Recharge.Instance.use(player, "Draw Map", 4000, false, false)) + { + for (int mapX = 0; mapX < 128; mapX++) + { + for (int mapZ = 0; mapZ < 128; mapZ++) + { + int blockX = centerX + (mapX - 64); + int blockZ = centerZ + (mapZ - 64); + + int pixelX = blockX + (map.length / 2); + int pixelZ = blockZ + (map.length / 2); + + Byte color; + + if (!(pixelX < 0 || pixelZ < 0 || pixelX >= map.length || pixelZ >= map.length) + && map[pixelX][pixelZ] != null) + { + color = map[pixelX][pixelZ]; + + blockX *= zoom; + blockZ *= zoom; + } + else + { + color = (byte) 0; + } + + for (MapZone od : _host.MapZones) + { + if (od.isInRadius(blockX, blockZ)) // TODO Some math to figure out if this pixel is going to be colored in for the circle or not. + { + if (od.isValid()) + color = MapPalette.matchColor(od.getRed(), od.getGreen(), od.getBlue()); + } + + /*if (od.isBase(blockX - 20, blockZ + 15)) + { + color = MapPalette.matchColor(Color.PINK); + Bukkit.broadcastMessage("X:" + blockX + " Z:" + blockZ + "/" + od.getBase()); + }*/ + } + + canvas.setPixel(mapX, mapZ, color); + } + } + + player.sendMap(mapView); + } + + MapCursorCollection cursors = canvas.getCursors(); + + while (cursors.size() > 0) + + { + cursors.removeCursor(cursors.getCursor(0)); + } + + // TODO If you want players to see each other as cursors. Otherwise delete this bit. + for ( + + Player other : Bukkit.getOnlinePlayers()) + + { + if (player.canSee(other) && other.isValid()) + { + Location l = other.getLocation(); + + double mapX = (l.getX() - _manager.getX()) / zoom; + double mapZ = (l.getZ() - _manager.getZ()) / zoom; + + if (mapX > -64 && mapX < 64 && mapZ > -64 && mapZ < 64) + { + MapCursor.Type cursorDisplay; + MapCursor.Type friend; + MapCursor.Type foe; + + if (_host.GetTeam(player).GetColor() == ChatColor.RED) + { + friend = MapCursor.Type.RED_POINTER; + foe = MapCursor.Type.BLUE_POINTER; + } + else + { + friend = MapCursor.Type.BLUE_POINTER; + foe = MapCursor.Type.RED_POINTER; + } + + if (player == other) + { + cursorDisplay = MapCursor.Type.WHITE_POINTER; + } + else if (_host.GetTeam(player) == _host.GetTeam(other)) + { + cursorDisplay = friend; + } + else if (_host.GetTeam(player) != _host.GetTeam(other)) + { + if (_host.OverTime) + cursorDisplay = foe; + else + continue; + } + else + { + continue; + } + + byte b0 = (byte) (int) Math.min(127, (double) (mapX * 2.0F) + 0.5D); + byte b1 = (byte) (int) Math.max(-127, (double) (mapZ * 2.0F) + 0.5D); + + byte rotation = (byte) (int) ((l.getYaw() * 16D) / 360D); + + MapCursor cursor = new MapCursor(b0, b1, (byte) (rotation & 0xF), cursorDisplay.getValue(), true); + + cursors.addCursor(cursor); + } + } + } + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/objectives/GearObjective.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/objectives/GearObjective.java new file mode 100644 index 000000000..1c7c72621 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/objectives/GearObjective.java @@ -0,0 +1,11 @@ +package nautilus.game.arcade.game.games.minecraftleague.data.objectives; + +import nautilus.game.arcade.game.games.minecraftleague.objective.GameObjective; + +public class GearObjective extends GameObjective +{ + public GearObjective() + { + super("GEAR", "Gear Up"); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/objectives/KillObjective.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/objectives/KillObjective.java new file mode 100644 index 000000000..938d09e7d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/data/objectives/KillObjective.java @@ -0,0 +1,12 @@ +package nautilus.game.arcade.game.games.minecraftleague.data.objectives; + +import nautilus.game.arcade.game.games.minecraftleague.objective.GameObjective; + +public class KillObjective extends GameObjective +{ + public KillObjective() + { + super("KILL_ENEMY", "Kill Enemy"); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/kit/KitPlayer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/kit/KitPlayer.java new file mode 100644 index 000000000..90043f0c0 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/kit/KitPlayer.java @@ -0,0 +1,63 @@ +package nautilus.game.arcade.game.games.minecraftleague.kit; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class KitPlayer extends Kit +{ + public KitPlayer(ArcadeManager manager) + { + super(manager, "Player", KitAvailability.Free, + + new String[] + { + "", + "Entirely vanilla combat!", + "" + }, + + new Perk[] + { + + }, EntityType.PLAYER, new ItemStack(Material.DIAMOND_SWORD)); + } + + @Override + public void GiveItems(Player player) + { + MinecraftLeague game = (MinecraftLeague)Manager.GetGame(); + /*player.getInventory().setHelmet(new ItemStack(Material.LEATHER_HELMET)); + player.getInventory().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE)); + player.getInventory().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS)); + player.getInventory().setBoots(new ItemStack(Material.LEATHER_BOOTS)); + player.getInventory().addItem(new ItemStack(Material.WOOD_SWORD));*/ + + if (game != null) + { + game.restoreGear(player); + game.MapManager.setMap(player); + } + + /*TeamMap tmap = game.getMap(game.GetTeam(player)); + + if (tmap == null) + return; + + tmap.giveMap(player, true, C.cGold + "Team Map", C.cGray + "This map contains", C.cGray + "the locations of", C.cGray + "your teammates.");*/ + } + + @Override + public void SpawnCustom(LivingEntity ent) + { + + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/objective/GameObjective.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/objective/GameObjective.java new file mode 100644 index 000000000..54c633da3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/objective/GameObjective.java @@ -0,0 +1,23 @@ +package nautilus.game.arcade.game.games.minecraftleague.objective; + + +public abstract class GameObjective +{ + private String _displayText, _id; + + public GameObjective(String id, String displayText) + { + _id = id; + _displayText = displayText; + } + + public String getID() + { + return _id; + } + + public String getDisplayText() + { + return _displayText; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/objective/ObjectiveManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/objective/ObjectiveManager.java new file mode 100644 index 000000000..5281fecfe --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/objective/ObjectiveManager.java @@ -0,0 +1,125 @@ +package nautilus.game.arcade.game.games.minecraftleague.objective; + +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilTextBottom; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; + +public class ObjectiveManager implements Listener +{ + private MinecraftLeague _host; + private GameObjective _main; + private ConcurrentHashMap _specificObjectives = new ConcurrentHashMap(); + private ConcurrentHashMap _teamObjectives = new ConcurrentHashMap(); + + public ObjectiveManager(MinecraftLeague host) + { + _host = host; + Bukkit.getPluginManager().registerEvents(this, _host.getArcadeManager().getPlugin()); + } + + private void displayObjective(Player player) + { + GameObjective obj = _main; + if (_teamObjectives.containsKey(_host.GetTeam(player))) + obj = _teamObjectives.get(_host.GetTeam(player)); + if (_specificObjectives.containsKey(player)) + obj = _specificObjectives.get(player); + + UtilTextBottom.display(C.cGold + "Objective: " + obj.getDisplayText(), player); + } + + public String getMainObjective() + { + return _main.getID(); + } + + public String getTeamObjective(GameTeam team) + { + if (_teamObjectives.containsKey(team)) + return _teamObjectives.get(team).getID(); + + return getMainObjective(); + } + + public String getPlayerObjective(Player player) + { + if (_specificObjectives.containsKey(player)) + return _specificObjectives.get(player).getID(); + + return getTeamObjective(_host.GetTeam(player)); + } + + public void setMainObjective(GameObjective objective) + { + _main = objective; + } + + public void setPlayerObjective(Player player, GameObjective objective) + { + resetPlayerToMainObjective(player); + _specificObjectives.put(player, objective); + } + + public void resetPlayerToMainObjective(Player player) + { + if (!_specificObjectives.containsKey(player)) + return; + _specificObjectives.remove(player); + } + + public void setTeamObjective(GameTeam team, GameObjective objective) + { + if (getTeamObjective(team).equalsIgnoreCase("KILL_ENEMY")) + return; + + resetTeamToMainObjective(team); + _teamObjectives.put(team, objective); + } + + public void resetTeamToMainObjective(GameTeam team) + { + if (!_teamObjectives.containsKey(team)) + return; + _teamObjectives.remove(team); + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!_host.IsLive()) + return; + if (event.getType() != UpdateType.FASTEST) + return; + + for (Player player : _host.GetPlayers(true)) + { + if (_main != null || _specificObjectives.containsKey(player) || _teamObjectives.containsKey(_host.GetTeam(player))) + displayObjective(player); + } + } + + @EventHandler + public void handleDeregister(GameStateChangeEvent event) + { + if (event.GetGame() != _host) + return; + + if (event.GetState() != GameState.Dead) + return; + + HandlerList.unregisterAll(this); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/AltarBuilderTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/AltarBuilderTracker.java new file mode 100644 index 000000000..d4eb61c0e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/AltarBuilderTracker.java @@ -0,0 +1,21 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.stats.StatTracker; + +import org.bukkit.event.EventHandler; + +public class AltarBuilderTracker extends StatTracker +{ + public AltarBuilderTracker(MinecraftLeague game) + { + super(game); + } + + @EventHandler + public void build(PlaceSkullEvent e) + { + addStat(e.getPlayer(), "AltarBuilder", 1, false, false); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/FirstStrikeTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/FirstStrikeTracker.java new file mode 100644 index 000000000..07d08ba0a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/FirstStrikeTracker.java @@ -0,0 +1,22 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import nautilus.game.arcade.events.FirstBloodEvent; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.stats.StatTracker; + +import org.bukkit.event.EventHandler; + +public class FirstStrikeTracker extends StatTracker +{ + public FirstStrikeTracker(MinecraftLeague game) + { + super(game); + } + + @EventHandler + public void blood(FirstBloodEvent e) + { + addStat(e.getPlayer(), "FirstStrike", 1, false, false); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/GrabSkullEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/GrabSkullEvent.java new file mode 100644 index 000000000..7da1c076e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/GrabSkullEvent.java @@ -0,0 +1,31 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class GrabSkullEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + private Player _player; + + public GrabSkullEvent(Player player) + { + _player = player; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Player getPlayer() + { + return _player; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/HeadHunterTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/HeadHunterTracker.java new file mode 100644 index 000000000..72100ecfe --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/HeadHunterTracker.java @@ -0,0 +1,21 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.stats.StatTracker; + +import org.bukkit.event.EventHandler; + +public class HeadHunterTracker extends StatTracker +{ + public HeadHunterTracker(MinecraftLeague game) + { + super(game); + } + + @EventHandler + public void build(GrabSkullEvent e) + { + addStat(e.getPlayer(), "HeadHunter", 1, false, false); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/PlaceSkullEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/PlaceSkullEvent.java new file mode 100644 index 000000000..a9193a640 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/PlaceSkullEvent.java @@ -0,0 +1,31 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PlaceSkullEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + private Player _player; + + public PlaceSkullEvent(Player player) + { + _player = player; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Player getPlayer() + { + return _player; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/SavingUpTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/SavingUpTracker.java new file mode 100644 index 000000000..9ab8f4756 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/SavingUpTracker.java @@ -0,0 +1,25 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.stats.StatTracker; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.CraftItemEvent; + +public class SavingUpTracker extends StatTracker +{ + public SavingUpTracker(MinecraftLeague game) + { + super(game); + } + + @EventHandler + public void build(CraftItemEvent e) + { + if (e.getRecipe().getResult().getType() == Material.DIAMOND_CHESTPLATE) + addStat((Player)e.getWhoClicked(), "SavingUp", 1, false, false); + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/TowerDefenderTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/TowerDefenderTracker.java new file mode 100644 index 000000000..a9fa6936f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/tracker/TowerDefenderTracker.java @@ -0,0 +1,85 @@ +package nautilus.game.arcade.game.games.minecraftleague.tracker; + +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.stats.StatTracker; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +public class TowerDefenderTracker extends StatTracker +{ + private final int _killCount; + private final String _stat; + private final int _timeLimit; + + private final ConcurrentHashMap _kills = new ConcurrentHashMap(); + private final ConcurrentHashMap _lastKill = new ConcurrentHashMap(); + + public TowerDefenderTracker(MinecraftLeague game, int killCount, int timeLimit, String stat) + { + super(game); + + _killCount = killCount; + _stat = stat; + _timeLimit = timeLimit * 1000; + } + + public int getKillCount() + { + return _killCount; + } + + public int getTimeLimit() + { + return _timeLimit; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onCombatDeath(CombatDeathEvent event) + { + if (getGame().GetState() != Game.GameState.Live) + return; + + if (event.GetLog().GetKiller() == null) + return; + + if (!event.GetLog().GetKiller().IsPlayer()) + return; + + Player player = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); + if (player == null) + return; + + Integer killCount = _kills.get(player.getUniqueId()); + Long lastKill = _lastKill.get(player.getUniqueId()); + + killCount = (killCount == null ? 0 : killCount) + 1; + lastKill = (lastKill == null ? System.currentTimeMillis() : lastKill); + + _kills.put(player.getUniqueId(), killCount); + _lastKill.put(player.getUniqueId(), System.currentTimeMillis()); + + if (killCount == getKillCount() && System.currentTimeMillis() - lastKill < getTimeLimit()) + { + if (UtilMath.offset2d(player.getLocation(), getGame().getActiveTower(getGame().GetTeam(player)).getLocation()) <= 7) + { + addStat(player, getStat(), 1, true, false); + _lastKill.remove(player.getUniqueId()); + _kills.remove(player.getUniqueId()); + } + } + } + + public String getStat() + { + return _stat; + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/ExtraScoreboardData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/ExtraScoreboardData.java new file mode 100644 index 000000000..c13960834 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/ExtraScoreboardData.java @@ -0,0 +1,15 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation; + +import nautilus.game.arcade.scoreboard.GameScoreboard; + +public abstract class ExtraScoreboardData +{ + public GameScoreboard Scoreboard; + + public ExtraScoreboardData(GameScoreboard sb) + { + Scoreboard = sb; + } + + public abstract void write(); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/GameVariation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/GameVariation.java new file mode 100644 index 000000000..3b713809f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/GameVariation.java @@ -0,0 +1,40 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation; + +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.world.WorldData; + +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; + +public abstract class GameVariation implements Listener +{ + public MinecraftLeague Host; + public ArcadeManager Manager; + public WorldData WorldData; + + public GameVariation(MinecraftLeague host) + { + Host = host; + Manager = host.getArcadeManager(); + WorldData = host.WorldData; + } + + public void ParseData() + { + + } + + public String[] getTeamScoreboardAdditions(GameTeam team) + { + return new String[]{}; + } + + public void deregister() + { + HandlerList.unregisterAll(this); + } + + public abstract void customDeregister(); +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/StandardGameplay.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/StandardGameplay.java new file mode 100644 index 000000000..2c06dffc4 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/StandardGameplay.java @@ -0,0 +1,14 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation; + +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +public class StandardGameplay extends GameVariation +{ + public StandardGameplay(MinecraftLeague host) + { + super(host); + } + + public void customDeregister() {} + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/VariationManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/VariationManager.java new file mode 100644 index 000000000..fc392060e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/VariationManager.java @@ -0,0 +1,99 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation; + +import java.lang.reflect.InvocationTargetException; + +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.games.minecraftleague.DataLoc; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class VariationManager implements Listener +{ + private MinecraftLeague _host; + + private GameVariation _variation; + //private VariationType _selected; + + public VariationManager(MinecraftLeague host) + { + _host = host; + Bukkit.getPluginManager().registerEvents(this, _host.getArcadeManager().getPlugin()); + } + + public GameVariation getSelected() + { + return _variation; + } + + public void selectVariation() + { + VariationType type = null; + if (_host.getMapVariantIDS().size() != 1) + type = VariationType.STANDARD; + else + { + type = VariationType.getFromID(_host.getMapVariantIDS().get(0).replace(DataLoc.VARIANT_BASE.getKey(), "")); + } + + try + { + _variation = type.getVariation().getConstructor(MinecraftLeague.class).newInstance(_host); + //_selected = type; + } + catch (NoSuchMethodException ex) + { + System.err.println("Is the constructor for " + type.toString() + " using only one argument?"); + ex.printStackTrace(); + return; + } + catch (InvocationTargetException ex) + { + ex.getCause().printStackTrace(); + return; + } + catch (Exception ex) + { + ex.printStackTrace(); + return; + } + + //Bukkit.broadcastMessage(type.getDisplayMessage()); + Bukkit.getPluginManager().registerEvents(_variation, _host.getArcadeManager().getPlugin()); + _variation.ParseData(); + } + + public void deregister() + { + if (_variation != null) + _variation.deregister(); + + HandlerList.unregisterAll(this); + } + + @EventHandler + public void handleDeregister(GameStateChangeEvent event) + { + if (event.GetGame() != _host) + return; + + if (event.GetState() != GameState.Dead) + return; + + deregister(); + } + + @EventHandler + public void onInform(PlayerJoinEvent event) + { + if (_variation != null) + { + //event.getPlayer().sendMessage(_selected.getDisplayMessage()); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/VariationType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/VariationType.java new file mode 100644 index 000000000..de1124d99 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/VariationType.java @@ -0,0 +1,47 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation; + +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.WitherVariation; + +import org.bukkit.ChatColor; + +public enum VariationType +{ + STANDARD("STANDARD", StandardGameplay.class, "Standard Gameplay", ChatColor.GREEN), + WITHER("WITHER", WitherVariation.class, "Wither Variation", ChatColor.RED), + //GUARDIAN(3, GuardianVariation.class, "Guardian Variation", ChatColor.DARK_AQUA) + ; + + private String _id; + private String _name; + private ChatColor _color; + private Class _variation; + + private VariationType(String id, Class variationClass, String displayName, ChatColor displayColor) + { + _id = id; + _name = displayName; + _color = displayColor; + _variation = variationClass; + } + + public Class getVariation() + { + return _variation; + } + + public String getDisplayMessage() + { + return ChatColor.DARK_AQUA + "Game Type Selected: " + _color + _name; + } + + public static VariationType getFromID(String id) + { + for (VariationType type : VariationType.values()) + { + if (type._id.equalsIgnoreCase(id)) + return type; + } + + return VariationType.STANDARD; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/WitherVariation.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/WitherVariation.java new file mode 100644 index 000000000..b9643c6af --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/WitherVariation.java @@ -0,0 +1,465 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.events.PlayerGameRespawnEvent; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.DataLoc; +import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague; +import nautilus.game.arcade.game.games.minecraftleague.data.TeamTowerBase; +import nautilus.game.arcade.game.games.minecraftleague.variation.GameVariation; +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.data.TeamAltar; +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.data.WitherMinionManager; +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.data.WitherPathfinder; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.entity.Wither; +import org.bukkit.entity.WitherSkull; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class WitherVariation extends GameVariation +{ + private ConcurrentHashMap _altars = new ConcurrentHashMap(); + + private Wither _wither; + private WitherPathfinder _pathfinder; + + private WitherMinionManager _skellyMan; + + public boolean WitherSpawned; + + private GameTeam _wowner = null; + + public WitherVariation(MinecraftLeague host) + { + super(host); + WitherSpawned = false; + _skellyMan = new WitherMinionManager(this, WorldData.GetDataLocs(DataLoc.WITHER_SKELETON.getKey())); + } + + @Override + public void customDeregister() + { + HandlerList.unregisterAll(_skellyMan); + } + + @Override + public void ParseData() + { + _altars.put(Host.GetTeam(ChatColor.AQUA), new TeamAltar(this, Host.GetTeam(ChatColor.AQUA), WorldData.GetDataLocs(DataLoc.BLUE_ALTAR.getKey()).get(0))); + _altars.put(Host.GetTeam(ChatColor.RED), new TeamAltar(this, Host.GetTeam(ChatColor.RED), WorldData.GetDataLocs(DataLoc.RED_ALTAR.getKey()).get(0))); + } + + @Override + public String[] getTeamScoreboardAdditions(GameTeam team) + { + String skulls = ""; + for (int i = 1; i < 4; i++) + { + if (!skulls.equalsIgnoreCase("")) + skulls = skulls + " "; + + if (_altars.get(team).getPlacedSkulls() >= i) + skulls = skulls + ChatColor.GREEN + "☠"; + else + skulls = skulls + ChatColor.GRAY + "☠"; + } + + return new String[] {"Skulls: " + skulls}; + } + + private Location getNearest(Location to, ConcurrentHashMap options) + { + Location ret = null; + double dist = Double.MAX_VALUE; + + for (Location check : options.keySet()) + { + if (options.get(check) < dist) + { + ret = check; + dist = options.get(check); + } + } + + return ret; + } + + private LinkedList getWaypoints(Location altar) + { + LinkedList waypoints = new LinkedList(); + ConcurrentHashMap distances = new ConcurrentHashMap(); + + for (Location loc : WorldData.GetDataLocs(DataLoc.WITHER_WAYPOINT.getKey())) + { + distances.put(loc, altar.distance(loc)); + } + + while (distances.size() >= 1) + { + Location act = getNearest(altar, distances); + waypoints.add(act); + distances.remove(act); + } + + return waypoints; + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!Host.IsLive()) + return; + + if (event.getType() != UpdateType.TICK) + { + for (Player player : Bukkit.getOnlinePlayers()) + { + if (player.hasPotionEffect(PotionEffectType.WITHER)) + { + player.removePotionEffect(PotionEffectType.WITHER); + player.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 20 * 6, 0)); + } + if (!Host.IsAlive(player)) + continue; + /*GameTeam enemy = null; + if (Host.GetTeam(player).GetColor() == ChatColor.RED) + { + enemy = Host.GetTeam(ChatColor.AQUA); + } + else + { + enemy = Host.GetTeam(ChatColor.RED); + } + if (UtilMath.offset(player, Host.getActiveTower(enemy).getEntity()) <= 7) + { + for (Location loc : UtilShapes.getCircle(player.getEyeLocation(), true, 3)) + { + if (new Random().nextInt(5) <= 3) + { + UtilParticle.PlayParticle(ParticleType.DRIP_LAVA, loc, null, 0, 2, ViewDist.SHORT, player); + } + } + }*/ + } + if (_pathfinder != null) + if (_pathfinder.update()) + { + GameTeam team = _pathfinder.getTeam(); + _pathfinder = null; + WitherSpawned = false; + _wowner = null; + _skellyMan.onWitherDeath(); + UtilTextMiddle.display("", team.GetColor() + team.getDisplayName() + "'s Wither has been Defeated!"); + //Host.Objective.resetTeamToMainObjective(Host.GetTeam(ChatColor.RED)); + //Host.Objective.resetTeamToMainObjective(Host.GetTeam(ChatColor.AQUA)); + } + } + } + + @EventHandler + public void onWitherSpawn(EntitySpawnEvent event) + { + if (!Host.IsLive()) + return; + + if (event.getEntity() instanceof Wither) + { + if (WitherSpawned) + { + event.setCancelled(true); + return; + } + + for (GameTeam team : _altars.keySet()) + { + GameTeam enemy = null; + if (team.GetColor() == ChatColor.AQUA) + { + enemy = Host.GetTeam(ChatColor.RED); + } + else if (team.GetColor() == ChatColor.RED) + { + enemy = Host.GetTeam(ChatColor.AQUA); + } + if (_altars.get(team).ownsWither(event)) + { + if (Host.getTowerManager().getAmountAlive(enemy) < 1) + { + event.setCancelled(true); + return; + } + WitherSpawned = true; + _wowner = team; + _wither = (Wither)event.getEntity(); + _wither.setCustomName(team.GetColor() + team.getDisplayName() + "'s Wither"); + _wither.setCustomNameVisible(true); + UtilTextMiddle.display("", C.cWhite + team.getDisplayName() + " Team has spawned a Wither Boss!", UtilServer.getPlayers()); + _pathfinder = new WitherPathfinder(this, _wither, getWaypoints(_altars.get(team).getLocation()), team, enemy, Host.getTowerManager()); + _skellyMan.onWitherSpawn(); + //Host.Objective.setMainObjective(new GearObjective()); + //Host.Objective.setTeamObjective(team, new WitherObjective("Attack Enemy Towers")); + //Host.Objective.setTeamObjective(enemy, new WitherObjective("Kill Wither")); + /*for (Player player : Host.GetPlayers(true)) + { + Host.Objective.resetPlayerToMainObjective(player); + }*/ + Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable() + { + public void run() + { + Host.CreatureAllowOverride = false; + } + }, 20 * 3); + Bukkit.getScheduler().runTaskLater(Manager.getPlugin(), new Runnable() + { + public void run() + { + _altars.get(team).spawnSoulsand(); + } + }, 20 * 35); + } + } + + if (_wither == null) + { + event.setCancelled(true); + } + } + } + + @EventHandler + public void handleWitherDrops(EntityDeathEvent event) + { + if (!Host.IsLive()) + return; + + if (event.getEntity() instanceof Wither) + { + event.setDroppedExp(0); + event.getDrops().clear(); + } + } + + //@SuppressWarnings("deprecation") + @EventHandler + public void onExplode(EntityExplodeEvent event) + { + if (!Host.IsLive()) + return; + + if (event.getEntity() instanceof Wither) + { + event.blockList().clear(); + return; + } + if (event.getEntity() instanceof WitherSkull) + { + event.setCancelled(true); + + if (!((WitherSkull)event.getEntity()).isCharged()) + return; + + LinkedList red = Host.getTowerManager().getTeamTowers(Host.GetTeam(ChatColor.RED)); + LinkedList blue = Host.getTowerManager().getTeamTowers(Host.GetTeam(ChatColor.AQUA)); + HashMap inside = UtilBlock.getInRadius(event.getLocation().getBlock(), 4, false); + + double dmg = 10 * (Host.GetTeam(ChatColor.RED).GetPlayers(true).size() + Host.GetTeam(ChatColor.RED).GetPlayers(true).size()); + for (TeamTowerBase tb : red) + { + if (inside.containsKey(tb.getLocation().getBlock())) + { + tb.damage(dmg, null); + Host.Alert.alert(tb.getTeam(), tb); + } + } + for (TeamTowerBase tb : blue) + { + if (inside.containsKey(tb.getLocation().getBlock())) + { + tb.damage(dmg, null); + Host.Alert.alert(tb.getTeam(), tb); + } + } + for (Block b : inside.keySet()) + { + if (inside.get(b) > 2) + continue; + + for (TeamAltar altar : _altars.values()) + { + if (altar.isInsideAltar(b.getLocation())) + continue; + } + for (GameTeam owner : Host.GetTeamList()) + { + for (TeamTowerBase tb : Host.getTowerManager().getTeamTowers(owner)) + { + if (!tb.Vulnerable) + continue; + + if (tb.getLocation().distance(b.getLocation()) < 7) + { + if (b.getType() == Material.BEDROCK) + continue; + if (b.getType() == Material.OBSIDIAN) + { + if (new Random().nextDouble() > (.75 / 2)) + continue; + } + if (b.getType() == Material.AIR) + continue; + if (b.getType() == Material.STATIONARY_WATER || b.getType() == Material.WATER) + continue; + if (b.getType() == Material.STATIONARY_LAVA || b.getType() == Material.LAVA) + continue; + //WorldData.World.dropItem(b.getLocation(), new ItemBuilder(b.getType()).setData(b.getData()).build()); + b.setType(Material.AIR); + } + } + } + } + } + else if (event.getEntity() instanceof TNTPrimed) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) + { + if (!Host.IsLive()) + return; + + for (TeamAltar altar : _altars.values()) + { + if (!altar.canPlace(event.getPlayer(), event.getBlock().getType(), event.getBlock().getLocation(), true)) + event.setCancelled(true); + } + } + + @EventHandler + public void onBreak(BlockBreakEvent event) + { + if (!Host.IsLive()) + return; + + for (TeamAltar altar : _altars.values()) + { + if (!altar.canBreak(event.getPlayer(), event.getBlock(), true)) + event.setCancelled(true); + } + } + + @EventHandler + public void onShoot(ProjectileLaunchEvent event) + { + if (!Host.IsLive()) + return; + + if (event.getEntity()instanceof WitherSkull) + { + final WitherSkull entity = (WitherSkull)event.getEntity(); + if (entity.isCharged()) + { + event.setCancelled(true); + } + else + { + if (!((Wither)entity.getShooter()).hasMetadata("Shooting")) + event.setCancelled(true); + } + } + } + + @EventHandler + public void preserveAltars(EntityChangeBlockEvent event) + { + if (!Host.IsLive()) + return; + + for (TeamAltar altar : _altars.values()) + { + if (altar.isInsideAltar(event.getBlock().getLocation())) + { + event.setCancelled(true); + } + } + } + + @EventHandler + public void protectWither(EntityDamageByEntityEvent event) + { + if (!Host.IsLive()) + return; + if (!WitherSpawned) + return; + + if (event.getEntity() instanceof Wither) + { + if (event.getDamager() instanceof Player) + { + Player dmg = (Player)event.getDamager(); + if (_wowner.HasPlayer(dmg)) + { + event.setCancelled(true); + return; + } + } + if (event.getDamager() instanceof Projectile) + { + if (((Projectile)event.getDamager()).getShooter() instanceof Player) + { + Player dmg = (Player) ((Projectile)event.getDamager()).getShooter(); + if (_wowner.HasPlayer(dmg)) + { + event.setCancelled(true); + return; + } + } + } + event.setDamage(event.getDamage() * .8); + } + } + + @EventHandler + public void onRespawn(PlayerGameRespawnEvent event) + { + if (!Host.IsLive()) + return; + + Manager.GetCondition().Clean(event.GetPlayer()); + /*if (Host.Objective.getPlayerObjective(event.GetPlayer()).equals("RETURN_SKULL")) + { + Host.Objective.resetPlayerToMainObjective(event.GetPlayer()); + }*/ + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/PathfinderData.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/PathfinderData.java new file mode 100644 index 000000000..97d6ec69a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/PathfinderData.java @@ -0,0 +1,81 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; + +import org.bukkit.Location; +import org.bukkit.entity.Wither; +import org.bukkit.util.Vector; + +public class PathfinderData +{ + public Wither Wither; + + public Location Target = null; + public Location Location = null; + + public float Pitch = 0; + public Vector Velocity = new Vector(0,0,0); + + //private long _lastReview; + + public PathfinderData(Wither wither, Location target) + { + Wither = wither; + UtilEnt.ghost(wither, true, false); + UtilEnt.Vegetate(wither, false); + + Location temp = wither.getLocation(); + temp.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(wither.getLocation(), target))); + wither.teleport(temp); + + Velocity = wither.getLocation().getDirection().setY(0).normalize(); + Pitch = UtilAlg.GetPitch(wither.getLocation().getDirection()); + + Location = wither.getLocation(); + //_lastReview = System.currentTimeMillis(); + } + + public void move() + { + turn(); + + //Speed + double speed = 0.325 / 2; + + Location.add(Velocity.clone().multiply(speed)); + Location.add(0, -Pitch, 0); + + Location.setPitch(-1 * Pitch); + Location.setYaw(/*180 +*/ UtilAlg.GetYaw(Velocity)); + + // + if (!UtilBlock.airFoliage(Location.getBlock())) + { + Location.setY(UtilBlock.getHighest(Location.getWorld(), Location.getBlockX(), Location.getBlockZ()).getY()); + } + + Wither.teleport(Location); + } + + private void turn() + { + //Pitch + float desiredPitch = UtilAlg.GetPitch(UtilAlg.getTrajectory(Location, Target)); + if (desiredPitch < Pitch) Pitch = (float)(Pitch - 0.05); + if (desiredPitch > Pitch) Pitch = (float)(Pitch + 0.05); + if (Pitch > 0.5) Pitch = 0.5f; + if (Pitch < -0.5) Pitch = -0.5f; + + //Flat + Vector desired = UtilAlg.getTrajectory2d(Location, Target); + desired.subtract(UtilAlg.Normalize(new Vector(Velocity.getX(), 0, Velocity.getZ()))); + desired.multiply(0.2); + + Velocity.add(desired); + + //Speed + UtilAlg.Normalize(Velocity); + } +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/TeamAltar.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/TeamAltar.java new file mode 100644 index 000000000..da234474b --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/TeamAltar.java @@ -0,0 +1,202 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data; + +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.hologram.Hologram; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.tracker.PlaceSkullEvent; +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.WitherVariation; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.entity.Wither; +import org.bukkit.event.entity.EntitySpawnEvent; + +public class TeamAltar +{ + private WitherVariation _host; + private GameTeam _team; + private Location _center; + + //private List _protected; + + private Location[] _skullSpots; + + private int _placed; + + public TeamAltar(WitherVariation host, GameTeam team, Location center) + { + _host = host; + _team = team; + _center = center; + + spawnSoulsand(); + + //_protected = UtilShapes.getSphereBlocks(center, 7, 7, false); + + Location labelLoc = center.clone().add(0/*.5*/, 5, 0.5); + String labelStr = team.GetColor() + team.getDisplayName() + "'s Altar"; + Hologram label = new Hologram(host.Host.getArcadeManager().getHologramManager(), labelLoc, labelStr); + label.start(); + } + + public boolean isInsideAltar(Location location) + { + return UtilMath.offset(_center, location) <= 7; + //return _protected.contains(location); + } + + public void spawnSoulsand() + { + _placed = 0; + Location s1 = null; + Location s2 = null; + Location s3 = null; + + for (int i = -1; i <= 1; i++) + { + _center.getBlock().getRelative(i, 1, 0).setType(Material.SOUL_SAND); + if (i == -1) + s1 = _center.getBlock().getRelative(i, 2, 0).getLocation(); + if (i == 0) + s2 = _center.getBlock().getRelative(i, 2, 0).getLocation(); + if (i == 1) + s3 = _center.getBlock().getRelative(i, 2, 0).getLocation(); + } + _center.getBlock().setType(Material.SOUL_SAND); + + _skullSpots = new Location[] {s1, s2, s3}; + } + + public boolean canBreak(Player player, Block block, boolean notify) + { + if (isInsideAltar(block.getLocation())) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "You cannot break blocks inside an Altar!")); + return false; + /*if (!_team.HasPlayer(player)) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "This is not your Altar!")); + return false; + } + if (block.getType() != Material.SKULL) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "You cannot break that block inside an Altar!")); + return false; + }*/ + } + return true; + } + + public boolean canPlace(Player player, Material blockType, Location location, boolean notify) + { + if (isInsideAltar(location)) + { + if (!_team.HasPlayer(player)) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "This is not your Altar!")); + return false; + } + + if (_host.WitherSpawned) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "A Wither is already spawned!")); + return false; + } + + if (blockType != Material.SKULL) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "You cannot place that inside an Altar!")); + return false; + } + + boolean passes = false; + for (Location l : _skullSpots) + { + if (l.equals(location)) + passes = true; + } + + if (!passes) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "That doesn't go there!")); + return false; + } + + if (_team.GetColor() == ChatColor.RED) + { + if (_host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.AQUA)) < 1) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "You do not need a Wither!")); + return false; + } + } + if (_team.GetColor() == ChatColor.AQUA) + { + if (_host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.RED)) < 1) + { + if (notify) + UtilPlayer.message(player, F.main("Game", "You do not need a Wither!")); + return false; + } + } + + if (_team.HasPlayer(player) && blockType == Material.SKULL) + { + //_host.Host.Objective.resetPlayerToMainObjective(player); + Bukkit.getPluginManager().callEvent(new PlaceSkullEvent(player)); + if (_placed < 2) + { + UtilTextMiddle.display("", _team.GetColor() + _team.getDisplayName() + " has placed a Skull on their Altar!"); + for (Player scare : UtilServer.getPlayers()) + { + scare.playSound(scare.getLocation(), Sound.WITHER_SPAWN, 10, 0); + } + } + else + { + _host.Host.CreatureAllowOverride = true; + } + _placed++; + } + } + return true; + } + + public boolean ownsWither(EntitySpawnEvent event) + { + if (event.getEntity() instanceof Wither) + { + Location base = event.getLocation(); + return (isInsideAltar(base.getBlock().getLocation())); + } + + return false; + } + + public Location getLocation() + { + return _center.clone(); + } + + public int getPlacedSkulls() + { + return _placed; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherMinionManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherMinionManager.java new file mode 100644 index 000000000..a42b8523d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherMinionManager.java @@ -0,0 +1,488 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data; + +import java.util.List; +import java.util.Random; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilFirework; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.games.minecraftleague.data.MapZone; +import nautilus.game.arcade.game.games.minecraftleague.tracker.GrabSkullEvent; +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.WitherVariation; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.FireworkEffect.Type; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftSkeleton; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Skeleton.SkeletonType; +import org.bukkit.entity.Wither; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; + +public class WitherMinionManager implements Listener +{ + private WitherVariation _host; + private List _spawns; + private long _lastDied; + private int _lastUsed; + private int _selected; + + private Skeleton _entity; + + private ItemStack _witherItem; + + private WitherSkeletonTimer _sbTimer; + //private MapZone _skellyZone; + + private Block _cb; + private Material _changed = Material.AIR; + + private boolean _witherBlocked = false; + + private boolean _spawned = false; + + public WitherMinionManager(WitherVariation host, List spawns) + { + _host = host; + _spawns = spawns; + _lastDied = System.currentTimeMillis(); + _lastUsed = -1; + _witherItem = new ItemBuilder(Material.SKULL_ITEM).setTitle(C.cDRedB + "Wither Skeleton Head").setData((short) 1).setLore(C.cGray + "Bring this back", C.cGray + "to your team's Altar", C.cGray + "To summon a Wither!").build(); + _sbTimer = new WitherSkeletonTimer(host.Host.GetScoreboard()); + host.Host.ExtraSb.put(_sbTimer, host); + //_skellyZone = new MapZone(spawns.get(0), new int[] {0, 0, 0}); + //_skellyZone.setValid(false); + //host.Host.MapZones.add(_skellyZone); + + Bukkit.getPluginManager().registerEvents(this, host.Manager.getPlugin()); + } + + private void preSpawn() + { + Location chosen = null; + while (chosen == null) + { + int check = new Random().nextInt(_spawns.size()); + if (check != _lastUsed) + { + chosen = _spawns.get(check); + _lastUsed = check; + _selected = check; + } + } + + _cb = chosen.clone().add(0, -2, 0).getBlock(); + _changed = _cb.getType(); + chosen.clone().add(0, -2, 0).getBlock().setType(Material.BEACON); + } + + private void spawn(boolean respawn) + { + Location chosen = null; + if (!respawn) + chosen = _spawns.get(_selected); + else + chosen = _spawns.get(_lastUsed); + _host.Host.CreatureAllowOverride = true; + Entity e = _host.Manager.GetCreature().SpawnEntity(chosen, EntityType.SKELETON); + _host.Host.CreatureAllowOverride = false; + ((Skeleton)e).setSkeletonType(SkeletonType.WITHER); + _entity = (Skeleton)e; + UtilEnt.ghost(e, true, false); + UtilEnt.Vegetate(e); + e.setCustomName(C.cRed + "Wither Skeleton"); + ((Skeleton)e).setMaxHealth(/*100*/65); + ((Skeleton)e).setHealth(/*100*/65); + ((CraftSkeleton)e).getEquipment().setChestplate(new ItemStack(Material.IRON_CHESTPLATE)); + ((CraftSkeleton)e).getEquipment().setLeggings(new ItemStack(Material.IRON_LEGGINGS)); + //((Skeleton)e).addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 9999999, 7)); + + if (!respawn) + { + UtilTextMiddle.display("", C.cGray + "A Wither Skeleton has spawned!"); + //_skellyZone.setCenter(chosen); + //_skellyZone.setValid(true); + //_host.Host.Objective.setMainObjective(new GrabSkullObjective()); + } + _selected = -1; + _spawned = true; + } + + public void onWitherDeath() + { + _lastDied = System.currentTimeMillis(); + _witherBlocked = false; + _host.Host.getTowerManager().toggleAttack(); + _sbTimer.freezeTime(-1); + } + + public void onWitherSpawn() + { + _host.Host.getTowerManager().toggleAttack(); + _witherBlocked = true; + if (_entity != null) + { + _spawned = false; + _entity.remove(); + _lastDied = System.currentTimeMillis(); + //_skellyZone.setValid(false); + _entity = null; + } + if (_cb != null) + { + _cb.setType(_changed); + _cb = null; + _changed = Material.AIR; + } + } + + @EventHandler + public void onLive(GameStateChangeEvent event) + { + if (event.GetGame() != _host.Host) + return; + if (event.GetState() != GameState.Live) + return; + + _lastDied = System.currentTimeMillis() + UtilTime.convert(60, TimeUnit.SECONDS, TimeUnit.MILLISECONDS); + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (event.getType() != UpdateType.FASTEST) + return; + + if (_entity == null || !_entity.isValid()) + { + if (_spawned) + spawn(true); + } + + if (_entity != null) + { + _entity.teleport(_spawns.get(_lastUsed)); + } + + try { + if (UtilTime.elapsed(_lastDied, UtilTime.convert(45, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + boolean noUse = _host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.RED)) < 1; + if (_host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.AQUA)) >= 1) + noUse = false; + if (!_witherBlocked && !noUse) + { + if (_entity == null) + { + if (_selected != _lastUsed) + { + preSpawn(); + } + long end = _lastDied + UtilTime.convert(1, TimeUnit.MINUTES, TimeUnit.MILLISECONDS); + end =- System.currentTimeMillis(); + long secLeft = UtilTime.convert(end, TimeUnit.MILLISECONDS, TimeUnit.SECONDS); + if (secLeft <= 3) + { + if (secLeft > 0) + { + UtilTextMiddle.display(secLeft + " Seconds", "Until Wither Skeleton Spawn"); + } + } + } + } + } + + if (UtilTime.elapsed(_lastDied, UtilTime.convert(90, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + boolean noUse = _host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.RED)) < 1; + if (_host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.AQUA)) >= 1) + noUse = false; + if (!_witherBlocked && !noUse) + { + if (_entity == null) + spawn(false); + } + } + + for (Player player : Bukkit.getOnlinePlayers()) + { + if (UtilInv.contains(player, Material.SKULL_ITEM, (byte) 1, 1)) + { + UtilParticle.PlayParticle(ParticleType.WITCH_MAGIC, player.getLocation(), new Random().nextFloat(), new Random().nextFloat(), new Random().nextFloat(), 0, 1, ViewDist.MAX); + if (Recharge.Instance.usable(player, "FIREWORK_ALERT", false)) + { + Recharge.Instance.use(player, "FIREWORK_ALERT", UtilTime.convert(2, TimeUnit.SECONDS, TimeUnit.MILLISECONDS), false, false); + UtilFirework.playFirework(player.getEyeLocation().add(0, 3, 0), Type.BURST, _host.Host.GetTeam(player).GetColorBase(), false, true); + } + } + else + { + /*if (_host.Host.Objective.getPlayerObjective(player) != null) + { + if (_host.Host.Objective.getPlayerObjective(player).equalsIgnoreCase("GRAB_SKULL")) + { + _host.Host.Objective.resetPlayerToMainObjective(player); + } + }*/ + } + + if (player.getInventory().getHelmet() != null) + { + if (UtilInv.IsItem(player.getInventory().getHelmet(), Material.SKULL_ITEM, (byte) 1)) + { + player.getInventory().setHelmet(new ItemStack(Material.AIR)); + UtilInv.insert(player, _witherItem.clone()); + } + } + } + } catch (Exception e) + { + + } + } + + @EventHandler + public void handleTimer(UpdateEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (event.getType() != UpdateType.FASTEST) + return; + + boolean noUse = _host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.RED)) < 1; + if (_host.Host.getTowerManager().getAmountAlive(_host.Host.GetTeam(ChatColor.AQUA)) >= 1) + noUse = false; + + if (_entity != null || noUse) + { + _sbTimer.freezeTime(0); + return; + } + + if (_host.WitherSpawned || _witherBlocked) + { + _sbTimer.freezeTime(-2); + return; + } + + if (_entity == null) + _sbTimer.freezeTime(-1); + + _sbTimer.setEnd((_lastDied + UtilTime.convert(90, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onSkellyDie(EntityDeathEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (event.getEntity() instanceof Skeleton) + { + Skeleton skelly = (Skeleton)event.getEntity(); + if (skelly.getSkeletonType() == SkeletonType.WITHER) + { + if (_entity != null) + { + if (skelly.getEntityId() == _entity.getEntityId()) + { + _spawned = false; + _lastDied = System.currentTimeMillis(); + _entity = null; + event.getDrops().clear(); + event.getDrops().add(_witherItem.clone()); + event.setDroppedExp(10); + //_skellyZone.setValid(false); + + _cb.setType(_changed); + _cb = null; + _changed = Material.AIR; + + Bukkit.getScheduler().runTaskLater(_host.Manager.getPlugin(), new Runnable() { + public void run() + { + _host.Host.getTowerManager().ironOreGen(null, false); + } + }, 20 * 10); + + //_host.Host.Objective.setMainObjective(new GearObjective()); + } + } + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPickup(PlayerPickupItemEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (!event.isCancelled()) + { + String com = UtilItem.itemToStr(event.getItem().getItemStack()); + String com1 = UtilItem.itemToStr(_witherItem.clone()); + String[] compare = com.split(":"); + String[] compare1 = com1.split(":"); + String fin = compare[0] + ":" + compare[2] + ":" + compare[3]; + String fin1 = compare1[0] + ":" + compare1[2] + ":" + compare1[3]; + if (fin.equalsIgnoreCase(fin1)) + { + UtilPlayer.message(event.getPlayer(), F.main("Game", "You have the Wither Skull! Return the skull to your base and place it on your Altar to summon the Wither!")); + UtilTextMiddle.display("", C.cGray + "You have picked up the Wither Skull!", event.getPlayer()); + Bukkit.getScheduler().runTaskLater(_host.Manager.getPlugin(), new Runnable() + { + public void run() + { + UtilTextMiddle.display("", "Place the skull on top of", event.getPlayer()); + } + }, 20 * 5); + Bukkit.getScheduler().runTaskLater(_host.Manager.getPlugin(), new Runnable() + { + public void run() + { + UtilTextMiddle.display("", "Your Altar's Soul Sand!", event.getPlayer()); + } + }, 20 * 8); + //_host.Host.Objective.setPlayerObjective(event.getPlayer(), new ReturnSkullObjective()); + if (!event.getItem().hasMetadata("Dropped")) + { + Bukkit.getPluginManager().callEvent(new GrabSkullEvent(event.getPlayer())); + UtilTextMiddle.display("", _host.Host.GetTeam(event.getPlayer()).GetColor() + _host.Host.GetTeam(event.getPlayer()).getDisplayName() + " has picked up a Wither Skull!", 20, 20 * 5, 20); + } + } + } + } + + @EventHandler + public void onDrop(PlayerDropItemEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (!event.isCancelled()) + { + String com = UtilItem.itemToStr(event.getItemDrop().getItemStack()); + String com1 = UtilItem.itemToStr(_witherItem.clone()); + String[] compare = com.split(":"); + String[] compare1 = com1.split(":"); + String fin = compare[0] + ":" + compare[2] + ":" + compare[3]; + String fin1 = compare1[0] + ":" + compare1[2] + ":" + compare1[3]; + if (fin.equalsIgnoreCase(fin1)) + { + event.getItemDrop().setMetadata("Dropped", new FixedMetadataValue(_host.Manager.getPlugin(), true)); + //_host.Host.Objective.resetPlayerToMainObjective(event.getPlayer()); + } + } + } + + @EventHandler + public void onPlace(BlockPlaceEvent event) + { + if (!_host.Host.IsLive()) + return; + + for (Location loc : _spawns) + { + //if (UtilShapes.getSphereBlocks(loc, 6, 6, false).contains(event.getBlock().getLocation())) + if (UtilMath.offset(loc, event.getBlock().getLocation()) <= 6) + event.setCancelled(true); + } + } + + @EventHandler + public void onBreak(BlockBreakEvent event) + { + if (!_host.Host.IsLive()) + return; + + for (Location loc : _spawns) + { + //if (UtilShapes.getSphereBlocks(loc, 6, 6, false).contains(event.getBlock().getLocation())) + if (UtilMath.offset(loc, event.getBlock().getLocation()) <= 6) + event.setCancelled(true); + } + } + + @EventHandler + public void onExp(EntityExplodeEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (event.getEntity() instanceof Wither) + { + event.blockList().clear(); + return; + } + event.setCancelled(true); + } + + @EventHandler + public void onEntity(EntityChangeBlockEvent event) + { + if (!_host.Host.IsLive()) + return; + + for (Location loc : _spawns) + { + //if (UtilShapes.getSphereBlocks(loc, 5, 5, false).contains(event.getBlock().getLocation())) + if (UtilMath.offset(loc, event.getBlock().getLocation()) <= 6) + event.setCancelled(true); + } + } + + @EventHandler + public void fixDamage(EntityDamageEvent event) + { + if (!_host.Host.IsLive()) + return; + + if (_entity == null) + return; + if (event.getEntity().getEntityId() != _entity.getEntityId()) + return; + + UtilAction.zeroVelocity(event.getEntity()); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherPathfinder.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherPathfinder.java new file mode 100644 index 000000000..57f98615e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherPathfinder.java @@ -0,0 +1,226 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data; + +import java.util.HashMap; +import java.util.LinkedList; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.minecraftleague.DataLoc; +import nautilus.game.arcade.game.games.minecraftleague.data.TeamTower; +import nautilus.game.arcade.game.games.minecraftleague.data.TeamTowerBase; +import nautilus.game.arcade.game.games.minecraftleague.data.TowerManager; +import nautilus.game.arcade.game.games.minecraftleague.variation.wither.WitherVariation; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Wither; +import org.bukkit.entity.WitherSkull; +import org.bukkit.metadata.FixedMetadataValue; + +public class WitherPathfinder +{ + private PathfinderData _pathData; + private WitherVariation _host; + private Wither _ent; + private LinkedList _waypoints; + private GameTeam _team; + private GameTeam _enemy; + private TowerManager _towerManager; + private long _lastAttack; + private long _lastTowerAttack; + + private boolean _startedJourney = false; + + private double _health; + + public WitherPathfinder(WitherVariation host, Wither ent, LinkedList waypoints, GameTeam team, GameTeam enemy, TowerManager towerManager) + { + _host = host; + _ent = ent; + _waypoints = waypoints; + _team = team; + _enemy = enemy; + _towerManager = towerManager; + _lastAttack = -1; + _lastTowerAttack = -1; + _pathData = new PathfinderData(ent, waypoints.getFirst()); + _health = ent.getHealth(); + } + + private int getWaypointIndex(Location loc) + { + int best = -1; + double bestDist = 0; + + for (int i=0 ; i<_waypoints.size() ; i++) + { + Location waypoint = _waypoints.get(i); + + double dist = UtilMath.offset(waypoint, loc); + + if (best == -1 || dist < bestDist) + { + best = i; + bestDist = dist; + } + } + + return best; + } + + private void advance() + { + _pathData.Target = _waypoints.get(Math.min(_waypoints.size()-1, (getWaypointIndex(_pathData.Location) + 1))); + _pathData.move(); + } + + private void retarget() + { + _ent.setTarget(null); + + LivingEntity target = null; + HashMap inside = UtilEnt.getInRadius(_ent.getLocation(), 30); + for (LivingEntity ent : inside.keySet()) + { + if (UtilPlayer.isSpectator(ent)) + continue; + + if (ent instanceof Player) + { + if (_team.HasPlayer((Player)ent)) + continue; + } + else + continue; + + if (target == null) + target = ent; + + if (inside.get(target) > inside.get(ent)) + target = ent; + } + + if (target != null) + { + if (UtilTime.elapsed(_lastAttack, UtilTime.convert(2, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + _lastAttack = System.currentTimeMillis(); + shootAt(target.getLocation(), false); + } + } + } + + private void shootAt(Location loc, boolean charged) + { + Location old = _ent.getLocation(); + Location temp = _ent.getLocation(); + temp.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(_ent.getEyeLocation(), loc))); + temp.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(_ent.getEyeLocation(), loc))); + _ent.teleport(temp); + _ent.setMetadata("Shooting", new FixedMetadataValue(_host.Manager.getPlugin(), "1")); + WitherSkull skull = _ent.launchProjectile(WitherSkull.class); + skull.setCharged(charged); + _ent.removeMetadata("Shooting", _host.Manager.getPlugin()); + _ent.teleport(old); + //skull.setDirection(UtilAlg.getTrajectory(_ent.getLocation(), loc).normalize()); + } + + private TeamTowerBase getProperTarget() + { + for (TeamTowerBase t : _towerManager.getTeamTowers(_enemy)) + { + if (t.Alive) + return t; + } + return null; + } + + public GameTeam getTeam() + { + return _team; + } + + /** + * Returns true if the entity is dead or invalid + */ + public boolean update() + { + if ((_ent == null) || _ent.isDead() || !_ent.isValid()) + return true; + + Entity eTower = getProperTarget().getEntity(); + if (eTower == null || !eTower.isValid() || eTower.isDead()) + { + _ent.remove(); + return true; + } + + if (_ent.getHealth() < _ent.getMaxHealth()) + { + if (!_startedJourney) + { + _health = _ent.getMaxHealth(); + return false; + } + } + _startedJourney = true; + + _health = Math.min(_health, _ent.getHealth()); + _ent.setHealth(_health); + + for (Entity e : UtilEnt.getAllInRadius(_ent.getLocation(), 3).keySet()) + { + if (e instanceof Arrow) + { + Arrow arrow = (Arrow)e; + if (arrow.getShooter() instanceof Player) + { + if (!_team.HasPlayer((Player)arrow.getShooter())) + { + arrow.remove(); + _ent.damage(5, (Player)arrow.getShooter()); + } + } + } + } + + if (_ent.getLocation().distance(eTower.getLocation()) <= 10) + { + _ent.setTarget(null); + String tName = ""; + if (_team.GetColor() == ChatColor.RED) + tName = "RED"; + if (_team.GetColor() == ChatColor.AQUA) + tName = "BLUE"; + Integer cNumber = -1; + if (getProperTarget() instanceof TeamTower) + cNumber = ((TeamTower)getProperTarget()).Number; + else + cNumber = 3; + Location finalize = _host.Host.WorldData.GetCustomLocs(DataLoc.TOWER_WAYPOINT.getKey().replace("$team$", tName).replace("$number$", cNumber + "")).get(0); + finalize.setPitch(UtilAlg.GetPitch(UtilAlg.getTrajectory(_ent, eTower))); + finalize.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory(_ent, eTower))); + _ent.teleport(finalize); + if (UtilTime.elapsed(_lastTowerAttack, UtilTime.convert(5, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))) + { + _lastTowerAttack = System.currentTimeMillis(); + shootAt(eTower.getLocation(), true); + } + return false; + } + + advance(); + retarget(); + + return false; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherSkeletonTimer.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherSkeletonTimer.java new file mode 100644 index 000000000..0b655ae09 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/WitherSkeletonTimer.java @@ -0,0 +1,50 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; +import nautilus.game.arcade.game.games.minecraftleague.variation.ExtraScoreboardData; +import nautilus.game.arcade.scoreboard.GameScoreboard; + +public class WitherSkeletonTimer extends ExtraScoreboardData +{ + private long _end; + private int _frozen; + + public WitherSkeletonTimer(GameScoreboard sb) + { + super(sb); + _end = 0; + _frozen = -1; + } + + public void setEnd(long end) + { + _end = end; + } + + public void freezeTime(int seconds) + { + _frozen = seconds; + } + + public void write() + { + Scoreboard.Write(C.cYellowB + "Wither Skeleton Spawn"); + if (_frozen != -1) + { + if (_frozen == -2) + Scoreboard.Write("WITHER ALIVE"); + else + Scoreboard.Write(_frozen + " Seconds"); + } + else + { + long seconds = 0; + if (_end - System.currentTimeMillis() > 0) + seconds = UtilTime.convert(_end - System.currentTimeMillis(), TimeUnit.MILLISECONDS, TimeUnit.SECONDS); + + Scoreboard.Write(UtilTime.MakeStr(UtilTime.convert(seconds, TimeUnit.SECONDS, TimeUnit.MILLISECONDS))); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/GrabSkullObjective.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/GrabSkullObjective.java new file mode 100644 index 000000000..1b66bee30 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/GrabSkullObjective.java @@ -0,0 +1,11 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data.objectives; + +import nautilus.game.arcade.game.games.minecraftleague.objective.GameObjective; + +public class GrabSkullObjective extends GameObjective +{ + public GrabSkullObjective() + { + super("GRAB_SKULL", "Collect Wither Skull"); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/ReturnSkullObjective.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/ReturnSkullObjective.java new file mode 100644 index 000000000..5b5958601 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/ReturnSkullObjective.java @@ -0,0 +1,12 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data.objectives; + +import nautilus.game.arcade.game.games.minecraftleague.objective.GameObjective; + +public class ReturnSkullObjective extends GameObjective +{ + public ReturnSkullObjective() + { + super("RETURN_SKULL", "Return the Skull to your Altar!"); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/WitherObjective.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/WitherObjective.java new file mode 100644 index 000000000..d7dc13823 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/minecraftleague/variation/wither/data/objectives/WitherObjective.java @@ -0,0 +1,11 @@ +package nautilus.game.arcade.game.games.minecraftleague.variation.wither.data.objectives; + +import nautilus.game.arcade.game.games.minecraftleague.objective.GameObjective; + +public class WitherObjective extends GameObjective +{ + public WitherObjective(String instruction) + { + super("WITHER_OBJ", instruction); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java index 9ddacd156..4300dfd09 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameFlagManager.java @@ -1,6 +1,6 @@ package nautilus.game.arcade.managers; -import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; import mineplex.core.antihack.AntiHack; import mineplex.core.common.MinecraftVersion; @@ -14,8 +14,10 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.recharge.Recharge; import mineplex.core.teleport.event.MineplexTeleportEvent; @@ -33,6 +35,8 @@ import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.kit.perks.event.PerkDestructorBlockEvent; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.Sound; @@ -46,6 +50,7 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBurnEvent; @@ -54,6 +59,7 @@ import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.LeavesDecayEvent; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; @@ -73,6 +79,9 @@ import org.bukkit.util.Vector; public class GameFlagManager implements Listener { ArcadeManager Manager; + SecondaryDamageManager Secondary; + private ConcurrentHashMap _respawnTimers = new ConcurrentHashMap(); + private ConcurrentHashMap _respawnRunnables = new ConcurrentHashMap(); public GameFlagManager(ArcadeManager manager) { @@ -80,6 +89,33 @@ public class GameFlagManager implements Listener Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); } + + @EventHandler + public void triggerSecondary(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + return; + + if (Secondary == null) + { + if (!Manager.GetDamage().IsEnabled()) + { + Secondary = new SecondaryDamageManager(Manager); + Bukkit.getPluginManager().registerEvents(Secondary, Manager.getPlugin()); + } + } + else + { + if (Manager.GetDamage().IsEnabled()) + { + if (Secondary != null) + { + HandlerList.unregisterAll(Secondary); + Secondary = null; + } + } + } + } @EventHandler(priority = EventPriority.LOW) public void DamageEvent(CustomDamageEvent event) @@ -738,6 +774,8 @@ public class GameFlagManager implements Listener if (game.GetTeam(player).GetRespawnTime() > time) time = game.GetTeam(player).GetRespawnTime(); + final double timeF = time; + UtilInv.Clear(player); Manager.GetCondition().Factory().Cloak("Ghost", player, player, time, false, false); player.setAllowFlight(true); @@ -762,8 +800,15 @@ public class GameFlagManager implements Listener UtilPlayer.message(player, C.cWhite + C.Bold + "You will respawn in " + time + " seconds..."); UtilTextMiddle.display(null, "Respawning in " + time + " seconds...", 5, 40, 5, player); } - Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() + { + public void run() + { + Long t = Double.valueOf(timeF).longValue(); + _respawnTimers.put(player, System.currentTimeMillis() + UtilTime.convert(t, TimeUnit.SECONDS, TimeUnit.MILLISECONDS)); + } + }, 6); + int run = Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() { public void run() { @@ -779,8 +824,11 @@ public class GameFlagManager implements Listener player.setFireTicks(0); UtilAction.zeroVelocity(player); + + _respawnRunnables.remove(player); } }, (int)(time * 20d)); + _respawnRunnables.put(player, run); } } @@ -913,12 +961,22 @@ public class GameFlagManager implements Listener Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 4, false, false, false, "Border", "Border Damage"); + + if (!Manager.GetDamage().IsEnabled()) + { + Bukkit.getPluginManager().callEvent(new EntityDamageEvent(player, DamageCause.VOID, 4)); + } player.getWorld().playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 1f); player.getWorld().playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 1f); } else { + if (!Manager.GetDamage().IsEnabled()) + { + Bukkit.getPluginManager().callEvent(new EntityDamageEvent(player, DamageCause.VOID, 9001)); + } + Manager.GetDamage().NewDamageEvent(player, null, null, DamageCause.VOID, 9001, false, false, false, "Border", "Border Damage"); @@ -1210,4 +1268,52 @@ public class GameFlagManager implements Listener UtilTextMiddle.display(C.cGold + C.Bold + Manager.GetGame().GetType().GetName(), "Make sure you accept the Resource Pack", 20, 120, 20, event.getPlayer()); } + + @EventHandler + public void displayRespawnTimer(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + return; + + if (Manager.GetGame() == null) + { + _respawnTimers.clear(); + for (Integer r : _respawnRunnables.values()) + { + Bukkit.getScheduler().cancelTask(r); + } + _respawnRunnables.clear(); + return; + } + if (!Manager.GetGame().IsLive()) + { + _respawnTimers.clear(); + for (Integer r : _respawnRunnables.values()) + { + Bukkit.getScheduler().cancelTask(r); + } + _respawnRunnables.clear(); + return; + } + for (Player player : _respawnTimers.keySet()) + { + if (!player.isOnline()) + { + _respawnTimers.remove(player); + continue; + } + if (System.currentTimeMillis() >= _respawnTimers.get(player)) + { + _respawnTimers.remove(player); + continue; + } + long sec = UtilTime.convert(_respawnTimers.get(player) - System.currentTimeMillis(), TimeUnit.MILLISECONDS, TimeUnit.SECONDS); + ChatColor color = ChatColor.RED; + if (sec < 8) + color = ChatColor.YELLOW; + if (sec < 4) + color = ChatColor.GREEN; + UtilTextBottom.display(color + "Respawning In: " + sec + " Seconds", player); + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java index 7f1126a81..1e5eb71c5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameHostManager.java @@ -208,7 +208,7 @@ public class GameHostManager implements Listener } @EventHandler - public void whitelistJoin(PlayerLoginEvent event) + public void handleLogin(PlayerLoginEvent event) { Player p = event.getPlayer(); if (Manager.GetServerConfig().PlayerServerWhitelist){ @@ -220,6 +220,8 @@ public class GameHostManager implements Listener event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "This MPS is whitelisted."); } } + if (_blacklist.contains(p.getName())) + event.disallow(PlayerLoginEvent.Result.KICK_BANNED, "You were removed from this Mineplex Private Server."); } @EventHandler @@ -791,12 +793,6 @@ public class GameHostManager implements Listener { if (!isPrivateServer()) return; - - if (_blacklist.contains(event.getPlayer().getName())) - { - Manager.GetPortal().sendToHub(event.getPlayer(), "You were kicked from this Mineplex Private Server."); - return; - } String serverName = Manager.getPlugin().getConfig().getString("serverstatus.name"); UtilPlayer.message(event.getPlayer(), ChatColor.BOLD + "Welcome to Mineplex Private Servers!"); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/SecondaryDamageManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/SecondaryDamageManager.java new file mode 100644 index 000000000..adcb4c103 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/SecondaryDamageManager.java @@ -0,0 +1,187 @@ +package nautilus.game.arcade.managers; + +import mineplex.minecraft.game.core.condition.Condition.ConditionType; +import mineplex.minecraft.game.core.condition.events.ConditionApplyEvent; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.Game; +import nautilus.game.arcade.game.Game.GameState; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; + +public class SecondaryDamageManager implements Listener +{ + ArcadeManager Manager; + public SecondaryDamageManager(ArcadeManager manager) + { + Manager = manager; + } + + @EventHandler(priority = EventPriority.LOW) + public void EntDamage(EntityDamageEvent event) + { + Game game = Manager.GetGame(); + if (game == null) + { + event.setCancelled(true); + return; + } + if (!(event.getEntity() instanceof LivingEntity)) + return; + + LivingEntity ent = (LivingEntity) event.getEntity(); + if (ent.getWorld().getName().equals("world")) + { + event.setCancelled(true); + + if (event.getCause() == DamageCause.VOID) + ent.teleport(Manager.GetLobby().GetSpawn()); + + return; + } + + if (Manager.isSpectator(ent)) + { + event.setCancelled(true); + if (ent.getFireTicks() > 0) + { + ent.setFireTicks(-1); + } + + return; + } + + if (game.GetState() != GameState.Live) + { + event.setCancelled(true); + return; + } + + if (!game.Damage) + { + event.setCancelled(true); + return; + } + + if (ent instanceof Player) + { + if (!game.IsAlive((Player)ent)) + { + event.setCancelled(true); + return; + } + } + + if (event.getCause() == DamageCause.FALL) + { + if (!game.DamageFall) + { + event.setCancelled(true); + return; + } + } + } + + @EventHandler(priority = EventPriority.LOW) + public void DamageEvent(EntityDamageByEntityEvent event) + { + Game game = Manager.GetGame(); + if (game == null) + return; + + if (!(event.getEntity() instanceof LivingEntity)) + return; + + LivingEntity damagee = (LivingEntity)event.getEntity(); + + if (event.getDamager() instanceof LivingEntity || event.getDamager() instanceof Projectile) + { + LivingEntity damager = null; + if (event.getDamager() instanceof LivingEntity) + { + damager = (LivingEntity)event.getDamager(); + } + else + { + if (((Projectile)event.getDamager()).getShooter() instanceof LivingEntity) + { + damager = (LivingEntity)((Projectile)event.getDamager()).getShooter(); + } + } + //Damager Spec + if (damager != null && Manager.isSpectator(damager)) + { + event.setCancelled(true); + return; + } + + if (damager != null && damager instanceof Player && !game.IsAlive((Player)damager)) + { + event.setCancelled(true); + return; + } + + //Entity vs Entity + if (damagee != null && damager != null) + { + //PvP + if (damagee instanceof Player && damager instanceof Player) + { + if (!Manager.canHurt((Player)damagee, (Player)damager)) + { + event.setCancelled(true); + return; + } + } + //PvE + else if (damager instanceof Player) + { + if (!game.DamagePvE) + { + event.setCancelled(true); + return; + } + } + //EvP + else if (damagee instanceof Player) + { + if (!game.DamageEvP) + { + event.setCancelled(true); + return; + } + } + } + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void DamageExplosion(ConditionApplyEvent event) + { + if (event.isCancelled()) + return; + + if (event.GetCondition().GetType() != ConditionType.EXPLOSION) + return; + + LivingEntity damagee = event.GetCondition().GetEnt(); + if (damagee == null) return; + if (!(damagee instanceof Player)) return; + + LivingEntity damager = event.GetCondition().GetSource(); + if (damager == null) return; + if (!(damager instanceof Player)) return; + + if (Manager.canHurt((Player)damagee, (Player)damager)) + return; + + event.setCancelled(true); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java index 9a195ef1c..0d9dea0fa 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/chat/GameChatManager.java @@ -33,6 +33,8 @@ public class GameChatManager implements Listener private ArcadeManager _manager; private LinkedList _chatStats; + + public boolean TeamSpy; public GameChatManager(ArcadeManager manager) { @@ -41,6 +43,8 @@ public class GameChatManager implements Listener _manager.getPluginManager().registerEvents(this, _manager.getPlugin()); _chatStats = new LinkedList(); + + TeamSpy = true; } @EventHandler @@ -157,7 +161,10 @@ public class GameChatManager implements Listener format = event.getFormat().split(rankStr)[0]; name = _manager.GetColor(sender) + sender.getName() + C.Reset; - message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + _manager.GetChat().getFilteredMessage(sender, event.getMessage()); + if (event.getMessage().charAt(0) == '@') + message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + _manager.GetChat().getFilteredMessage(sender, event.getMessage().substring(1, event.getMessage().length())); + else + message = event.getFormat().split(sender.getName())[1].replace("%2$s", "") + _manager.GetChat().getFilteredMessage(sender, event.getMessage()); if (_manager.GetGame() == null || _manager.GetGame().GetState() != GameState.Live) { @@ -230,7 +237,10 @@ public class GameChatManager implements Listener Player receiver = recipientIterator.next(); if (!_manager.GetServerConfig().Tournament && _manager.GetClients().Get(receiver).GetRank().has(Rank.MODERATOR)) - continue; + { + if (TeamSpy) + continue; + } GameTeam recTeam = _manager.GetGame().GetTeam(receiver); GameTeam sendTeam = _manager.GetGame().GetTeam(sender);