From a430f7e94d7ce0697edc8819e130e990f3f13339 Mon Sep 17 00:00:00 2001 From: xXVevzZXx Date: Wed, 6 Jul 2016 13:45:31 +0200 Subject: [PATCH] Add chat messages for Peace Phase, remove arrows from chests, disable crafting, fix dropped pumpkins and disable weapon enchantments --- .../skywars/modes/OverpoweredSkywars.java | 6 + .../survivalgames/modes/StrikeGames.java | 131 +++++++++++++++++- 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java index 561acb4c4..7f971dc34 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skywars/modes/OverpoweredSkywars.java @@ -7,8 +7,14 @@ import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilMath; import mineplex.core.loot.ChestLoot; import mineplex.core.loot.RandomItem; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java index f90f9c141..5a2bc96ef 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/survivalgames/modes/StrikeGames.java @@ -1,6 +1,7 @@ package nautilus.game.arcade.game.games.survivalgames.modes; import java.util.Arrays; +import java.util.Iterator; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -11,23 +12,35 @@ import org.bukkit.block.Chest; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.enchantment.EnchantItemEvent; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.gadgets.gamemodifiers.GameModifierType; import mineplex.core.gadget.gadgets.gamemodifiers.minestrike.GameModifierMineStrikeSkin; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.loot.RandomItem; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; +import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.PlayerKitGiveEvent; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.games.minestrike.GunModule; @@ -54,17 +67,85 @@ public class StrikeGames extends SoloSurvivalGames { private GunModule _gunModule; + + private long _peacePhase; public StrikeGames(ArcadeManager manager) { super(manager, new Kit[] - { new KitPlayer(manager) }, GameType.Brawl); + { + new KitPlayer(manager) + }, GameType.Brawl); + DamagePvP = false; + + _peacePhase = 20000; + _gunModule = new GunModule(this); _gunModule.setEnablePickup(false); _gunModule.setEnableDrop(false); _gunModule.setEnableCleaning(false); } + + @EventHandler + public void enableDamage(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) + return; + + if (!IsLive()) + return; + + if (!UtilTime.elapsed(GetStateTime(), _peacePhase)) + return; + + if (DamagePvP) + return; + + Announce(F.main("Game", "The Peace Phase has ended! You can now fight each other!")); + DamagePvP = true; + } + + @EventHandler + public void informPeace(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Live) + return; + + Announce(F.main("Game", "A Peace Phase of " + F.time((_peacePhase/1000) + "") + "seconds has started!")); + } + + @EventHandler(priority=EventPriority.HIGHEST) + public void pumpkinDrop(PlayerDeathEvent event) + { + Iterator itemIterator = event.getDrops().iterator(); + while (itemIterator.hasNext()) + { + ItemStack item = itemIterator.next(); + if (item.getType() == Material.PUMPKIN + || item.getType() == Material.PUMPKIN_STEM) + { + itemIterator.remove(); + } + } + } + + @EventHandler + public void disableCrafting(PlayerInteractEvent event) + { + if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) + return; + + if (event.getClickedBlock().getType() == Material.WORKBENCH) + event.setCancelled(true); + } + + @EventHandler + public void weaponEnchantment(EnchantItemEvent event) + { + if (!UtilItem.isArmor(event.getItem())) + event.setCancelled(true); + } public void setupLoot() { @@ -105,8 +186,6 @@ public class StrikeGames extends SoloSurvivalGames // Throwable getBaseLoot().addLoot(new RandomItem(Material.FISHING_ROD, 30)); - getBaseLoot().addLoot(new RandomItem(Material.BOW, 20)); - getBaseLoot().addLoot(new RandomItem(Material.ARROW, 20, 1, 3)); getBaseLoot().addLoot(new RandomItem(Material.EGG, 30, 1, 2)); // Misc @@ -434,6 +513,52 @@ public class StrikeGames extends SoloSurvivalGames ItemStack knife = ItemStackFactory.Instance.CreateStack(mat, data, 1, name); event.getPlayer().getInventory().setItem(0, knife); } + + @EventHandler + @Override + public void ItemSpawn(ItemSpawnEvent event) + { + if (event.getEntity().getItemStack().hasItemMeta()) + return; + + Material mat = event.getEntity().getItemStack().getType(); + + switch (mat) + { + case SEEDS: + case SAPLING: + case VINE: + case LEAVES: + case LONG_GRASS: + case RED_ROSE: + case YELLOW_FLOWER: + case DEAD_BUSH: + case WATER_LILY: + event.setCancelled(true); + return; + case CARROT_ITEM: + event.setCancelled(true); + return; + case POTATO_ITEM: + event.setCancelled(true); + return; + case WHEAT: + event.setCancelled(true); + return; + case WOOD: + event.setCancelled(true); + return; + + default: + break; + } + + for (Player player : GetPlayers(true)) + if (UtilMath.offset(player, event.getEntity()) < 6) + return; + + event.setCancelled(true); + } @Override public String GetMode()