diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautArrayList.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautArrayList.java index 9f00dace4..a61b1d411 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautArrayList.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautArrayList.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.function.Consumer; +import java.util.stream.Stream; public class NautArrayList { @@ -135,4 +136,14 @@ public class NautArrayList { _wrappedArrayList.forEach(consumer); } + + public Stream stream() + { + return _wrappedArrayList.stream(); + } + + public List getWrapped() + { + return _wrappedArrayList; + } } 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 5a300322c..fcafaa0ae 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 @@ -1125,4 +1125,56 @@ public class UtilItem i.setItemMeta(im); return i; } + + public static double getAttackDamage(Material type) + { + return ItemDamage.get(type); + } + + enum ItemDamage + { + IRON_SHOVEL(Material.IRON_SPADE, 3), + IRON_PICKAXE(Material.IRON_PICKAXE, 4), + IRON_AXE(Material.IRON_AXE, 5), + WOODEN_SHOVEL(Material.WOOD_SPADE, 1), + WOODEN_PICKAXE(Material.WOOD_PICKAXE, 2), + WOODEN_AXE(Material.WOOD_AXE, 3), + STONE_SHOVEL(Material.STONE_SPADE, 2), + STONE_PICKAXE(Material.STONE_PICKAXE, 3), + STONE_AXE(Material.STONE_AXE, 4), + DIAMOND_SHOVEL(Material.DIAMOND_SPADE, 4), + DIAMOND_PICKAXE(Material.DIAMOND_PICKAXE, 5), + DIAMOND_AXE(Material.DIAMOND_AXE, 6), + GOLD_SHOVEL(Material.GOLD_SPADE, 1), + GOLD_PICKAXE(Material.GOLD_PICKAXE, 2), + GOLD_AXE(Material.GOLD_AXE, 3), + IRON_SWORD(Material.IRON_SWORD, 6), + WOODEN_SWORD(Material.WOOD_SWORD, 4), + STONE_SWORD(Material.STONE_SWORD, 5), + DIAMOND_SWORD(Material.DIAMOND_SWORD, 7), + GOLDEN_SWORD(Material.GOLD_SWORD, 4); + + private double _damage; + private Material _type; + + ItemDamage(Material type, double damage) + { + _type = type; + _damage = damage; + } + + public static double get(Material type) + { + for (ItemDamage item : values()) + { + if (item._type.equals(type)) + { + return item._damage; + } + } + + return 1; + } + + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilServer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilServer.java index 79f248c3d..229166e39 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilServer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilServer.java @@ -6,12 +6,12 @@ import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; import java.util.List; -import java.util.stream.Stream; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.plugin.PluginManager; public class UtilServer { @@ -86,4 +86,9 @@ public class UtilServer { return (double)getPlayers().length / (double)UtilServer.getServer().getMaxPlayers(); } + + public static PluginManager getPluginManager() + { + return getServer().getPluginManager(); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanTips.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanTips.java index eb76dfd1b..cc941f8fa 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanTips.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanTips.java @@ -221,13 +221,8 @@ public class ClanTips extends MiniPlugin }), MOUNT_CANNON( new String[] { - C.cDAqua + "Cannons", - C.cAqua + "A Cannon is a Siege weapon used to infiltrate your enemies bases. NEEDS MORE INFO HERE, I'M NOT GOOD AT THINKING UP STUFF THIS LATE!!!!" - }), - MOUNT_CATAPULT( - new String[] { - C.cDAqua + "Meowapult", - C.cAqua + "Congratulations on your new purchase! You are now in possesion, of the one, and only, Meowapult 3000.24! " + C.Italics + "we are not responsible for any injuries caused by the meowapult, or any related products. please stay safe." + C.cDAqua + "Meownon", + C.cAqua + "Congratulations on your new purchase! You are now in possesion, of the one, and only, Meownon 3000.24! " + C.Italics + "we are not responsible for any injuries caused by the meownon, or any related products. stay safe kids." }), ; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/BarrierCollisionBox.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/BarrierCollisionBox.java new file mode 100644 index 000000000..d412a8537 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/BarrierCollisionBox.java @@ -0,0 +1,251 @@ +package mineplex.game.clans.clans.siege; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.function.BiConsumer; + +import org.bukkit.Location; +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.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDamageEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class BarrierCollisionBox implements Listener +{ + private List _collisionBlocks; + + private List> _leftClickListeners; + private List> _rightClickListeners; + + BarrierCollisionBox() + { + _collisionBlocks = new ArrayList<>(); + + _leftClickListeners = new ArrayList<>(); + _rightClickListeners = new ArrayList<>(); + } + + BarrierCollisionBox(List locations) + { + this(); + + _collisionBlocks.addAll(locations); + } + + BarrierCollisionBox(Location start, Location end) + { + this(); + + UtilBlock.getInBoundingBox(start, end, false).forEach(block -> _collisionBlocks.add(block.getLocation())); + } + + public void Construct() + { + setBlocks(); + + UtilServer.getPluginManager().registerEvents(this, UtilServer.getServer().getPluginManager().getPlugins()[0]); + } + + public void Destruct() + { + System.out.println("Destructing..."); + HandlerList.unregisterAll(this); + + resetBlocks(); + + _leftClickListeners.clear(); + _rightClickListeners.clear(); + _collisionBlocks.clear(); + } + + public void Update() + { + setBlocks(); + } + + public void registerLeft(BiConsumer listener) + { + _leftClickListeners.add(listener); + } + + public void registerRight(BiConsumer listener) + { + _rightClickListeners.add(listener); + } + + public void unregisterLeft(BiConsumer listener) + { + _leftClickListeners.remove(listener); + } + + public void unregisterRight(BiConsumer listener) + { + _rightClickListeners.remove(listener); + } + + private void onLeftClick(Location location, Player player) + { + _leftClickListeners.forEach(listener -> listener.accept(location, player)); + } + + private void onRightClick(Location location, Player player) + { + _rightClickListeners.forEach(listener -> listener.accept(location, player)); + } + + private void resetBlocks() + { + _collisionBlocks + .stream() + .filter(location -> location.getBlock().getType().equals(Material.BARRIER)) + .forEach(location -> location.getBlock().setType(Material.AIR)); + } + + private void setBlocks() + { + for (Location location : _collisionBlocks) + { + location.getBlock().setType(Material.BARRIER); + } + } + + public boolean isInBox(Location location) + { + for (Location boxLocation : _collisionBlocks) + { + if (boxLocation.equals(location)) + { + return true; + } + } + + return false; + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() == UpdateType.FAST) + { + Update(); + } + } + + // Events for interaction with the collision box; + @EventHandler + public void blockDamage(BlockDamageEvent event) + { + if (isInBox(event.getBlock().getLocation())) + { + onLeftClick(event.getBlock().getLocation(), event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void blockBreak(BlockBreakEvent event) + { + if (isInBox(event.getBlock().getLocation())) + { + onLeftClick(event.getBlock().getLocation(), event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void interact(PlayerInteractEvent event) + { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + { + return; + } + + if (isInBox(event.getClickedBlock().getLocation())) + { + onRightClick(event.getClickedBlock().getLocation(), event.getPlayer()); + event.setCancelled(true); + } + } + + public BarrierCollisionBox add(Location... location) + { + _collisionBlocks.addAll(Arrays.asList(location)); + + Update(); + + return this; + } + + public BarrierCollisionBox add(List location) + { + _collisionBlocks.addAll(location); + + Update(); + + return this; + } + + public BarrierCollisionBox remove(Location... location) + { + _collisionBlocks.removeAll(Arrays.asList(location)); + + Update(); + + return this; + } + + public BarrierCollisionBox add(BarrierCollisionBox box, boolean destructOld, boolean cloneListeners) + { + _collisionBlocks.addAll(box._collisionBlocks); + + if (cloneListeners) + { + _leftClickListeners.addAll(box._leftClickListeners); + _rightClickListeners.addAll(box._rightClickListeners); + } + + if (destructOld) + { + box.Destruct(); + } + + Update(); + + return this; + } + + public BarrierCollisionBox add(BarrierCollisionBox box) + { + return add(box, false, false); + } + + public BarrierCollisionBox addAll(Location start, Location end) + { + UtilBlock.getInBoundingBox(start, end).forEach(block -> _collisionBlocks.add(block.getLocation())); + + Update(); + + return this; + } + + public static BarrierCollisionBox all(Location start, Location end) + { + return new BarrierCollisionBox(start, end); + } + + public static BarrierCollisionBox single(Location location) + { + return new BarrierCollisionBox(new ArrayList<>(Arrays.asList(location))); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java index c49609792..6fc3e5416 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java @@ -55,6 +55,7 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanTips.TipType; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.siege.BarrierCollisionBox; public class Cannon implements Listener { @@ -94,6 +95,8 @@ public class Cannon implements Listener private ClanInfo _clan; + private BarrierCollisionBox _collisionBox; + public Cannon(Location location, ClanInfo clan) { _location = location; @@ -103,6 +106,11 @@ public class Cannon implements Listener _entities = new ArrayList<>(); + _collisionBox = BarrierCollisionBox.single(_location.clone()); + _collisionBox.Construct(); + _collisionBox.registerRight((block, player) -> handleRightClick(player)); + _collisionBox.registerLeft((block, player) -> handleLeftClick(player, -1)); + _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Cannon"); _healthHologram = new Hologram(ClansManager.getInstance().getHologramManager(), location.clone().add(.5, 3, .5), "Cannon Health", getDisplayHealth()); @@ -117,6 +125,7 @@ public class Cannon implements Listener _entities.clear(); + _collisionBox.Destruct(); _healthHologram.stop(); _healthHologram = null; @@ -154,8 +163,8 @@ public class Cannon implements Listener UtilEnt.setFakeHead(armorStand, true); armorStand.teleport(getArmorStandLocation()); armorStand.setVisible(false); - armorStand.setGravity(false); armorStand.setHelmet(_state.toItemStack()); + armorStand.setGravity(false); armorStand.setPassenger(UtilMath.getFirst(_entities)); @@ -418,17 +427,10 @@ public class Cannon implements Listener return; } - if (!_clan.isMember((Player) event.getDamager())) + if (!(event.getDamager() instanceof Player)) { - removeHealth(event.getFinalDamage()); + handleLeftClick((Player) event.getDamager(), event.getFinalDamage()); } - - if (!event.getDamager().equals(_rider)) - { - return; - } - - attemptFire(); } @EventHandler @@ -436,26 +438,7 @@ public class Cannon implements Listener { if (_entities.contains(event.getRightClicked())) { - if (!_clan.isMember(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "This Cannon does not belong to your Clan.")); - return; - } - - Entity passenger = UtilMath.getLast(_entities); - if (passenger == null) - { - UtilMath.getLast(_entities).setPassenger(event.getPlayer()); - - _rider = event.getPlayer(); - - ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); - } - else - { - handleOpenInv(event.getPlayer()); - } - + handleRightClick(event.getPlayer()); event.setCancelled(true); } } @@ -465,26 +448,7 @@ public class Cannon implements Listener { if (_entities.contains(event.getRightClicked())) { - if (!_clan.isMember(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "This Cannon does not belong to your Clan.")); - return; - } - - Entity passenger = UtilMath.getLast(_entities).getPassenger(); - if (passenger == null) - { - UtilMath.getLast(_entities).setPassenger(event.getPlayer()); - - _rider = event.getPlayer(); - - ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); - } - else - { - handleOpenInv(event.getPlayer()); - } - + handleRightClick(event.getPlayer()); event.setCancelled(true); } } @@ -494,30 +458,78 @@ public class Cannon implements Listener { if (_entities.contains(event.getRightClicked())) { - if (!_clan.isMember(event.getPlayer())) - { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "This Cannon does not belong to your Clan.")); - return; - } - - Entity passenger = UtilMath.getLast(_entities).getPassenger(); - if (passenger == null) - { - UtilMath.getLast(_entities).setPassenger(event.getPlayer()); - - _rider = event.getPlayer(); - - ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); - } - else - { - handleOpenInv(event.getPlayer()); - } - + handleRightClick(event.getPlayer()); event.setCancelled(true); } } + public void handleLeftClick(Player player, double damage) + { + if (!_clan.isMember(player)) + { + removeHealth(damage == -1 ? calcDmg(player) : damage); + } + + if (!player.equals(_rider)) + { + return; + } + + attemptFire(); + } + + private double calcDmg(Player player) + { + ItemStack item = player.getItemInHand(); + + if (item == null) + { + return 1; + } + + double dmg = UtilItem.getAttackDamage(item.getType()); + + switch(item.getType()) + { + case RECORD_4: + dmg += 7; + case GREEN_RECORD: + dmg += 6; + case GOLD_RECORD: + dmg += 9; + case RECORD_3: + dmg += 1; + case RECORD_5: + dmg += 7; + default: + } + + return dmg; + } + + public void handleRightClick(Player player) + { + if (!_clan.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This Cannon does not belong to your Clan.")); + return; + } + + Entity passenger = UtilMath.getLast(_entities).getPassenger(); + if (passenger == null) + { + UtilMath.getLast(_entities).setPassenger(player); + + _rider = player; + + ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); + } + else + { + handleOpenInv(player); + } + } + @EventHandler public void update(UpdateEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java index a8345bb82..ecd61ee69 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java @@ -34,6 +34,7 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; 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.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; @@ -49,6 +50,8 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.ClanTips.TipType; +import mineplex.game.clans.clans.siege.BarrierCollisionBox; public class Catapult implements Listener { @@ -91,7 +94,7 @@ public class Catapult implements Listener private Hologram _healthHologram; - private List _barriers; + private BarrierCollisionBox _collisionBox; public Catapult(Location location, ClanInfo clan) { @@ -101,12 +104,10 @@ public class Catapult implements Listener _rotationPoints = new ArrayList<>(); _entities = new ArrayList<>(); - _barriers = new ArrayList<>(); - - _barriers.add(_location.getBlock()); - _barriers.add(_location.getBlock().getRelative(BlockFace.UP)); - - _barriers.forEach(block -> block.setType(Material.BARRIER)); + _collisionBox = BarrierCollisionBox.all(_location.clone().subtract(1, 0, 1), _location.clone().add(1.5, 2, 1.5)); + _collisionBox.Construct(); + _collisionBox.registerRight((block, player) -> handleOpenInv(player)); + _collisionBox.registerLeft((block, player) -> handleLeftClick(player, -1)); for (int i = 0; i < 20; i++) { @@ -132,7 +133,7 @@ public class Catapult implements Listener _healthHologram.stop(); _healthHologram = null; - _barriers.forEach(block -> block.setType(Material.AIR)); + _collisionBox.Destruct(); HandlerList.unregisterAll(this); } @@ -411,6 +412,47 @@ public class Catapult implements Listener } } + public void handleLeftClick(Player player, double damage) + { + if (!_clan.isMember(player)) + { + removeHealth(damage == -1 ? calcDmg(player) : damage); + } + else + { + attemptFire(player); + } + } + + private double calcDmg(Player player) + { + ItemStack item = player.getItemInHand(); + + if (item == null) + { + return 1; + } + + double dmg = UtilItem.getAttackDamage(item.getType()); + + switch(item.getType()) + { + case RECORD_4: + dmg += 7; + case GREEN_RECORD: + dmg += 6; + case GOLD_RECORD: + dmg += 9; + case RECORD_3: + dmg += 1; + case RECORD_5: + dmg += 7; + default: + } + + return dmg; + } + @EventHandler public void update(UpdateEvent event) {