From 6c2b40d63aea26c6b8de6436a65829b736eda733 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sun, 13 Dec 2015 15:40:32 -0500 Subject: [PATCH 001/122] Cannon work --- Plugins/.idea/compiler.xml | 2 +- .../game/clans/clans/ClansManager.java | 2 + .../game/clans/clans/siege/SiegeManager.java | 25 ++++++ .../game/clans/clans/siege/cannon/Cannon.java | 90 +++++++++++++++++++ .../clans/clans/siege/cannon/CannonState.java | 28 ++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java diff --git a/Plugins/.idea/compiler.xml b/Plugins/.idea/compiler.xml index df8666836..ec08cea77 100644 --- a/Plugins/.idea/compiler.xml +++ b/Plugins/.idea/compiler.xml @@ -23,7 +23,7 @@ - + diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index d97ad7c78..2f16b18e5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -86,6 +86,7 @@ import mineplex.game.clans.clans.redis.ClanDeleteCommandHandler; import mineplex.game.clans.clans.redis.ClanLoadCommandHandler; import mineplex.game.clans.clans.regions.ClansRegions; import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager; +import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.stuck.StuckManager; import mineplex.game.clans.clans.supplyDrop.SupplyDropManager; import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager; @@ -246,6 +247,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati _itemMapManager = new ItemMapManager(this, _worldEvent); new TntGeneratorManager(plugin, this); new SupplyDropManager(plugin, this); + new SiegeManager(plugin); _explosion = new Explosion(plugin, blockRestore); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java new file mode 100644 index 000000000..81b7df231 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.clans.siege; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.game.clans.clans.siege.cannon.Cannon; + +public class SiegeManager extends MiniPlugin +{ + public SiegeManager(JavaPlugin plugin) + { + super("Siege", plugin); + } + + @EventHandler + public void debug(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().contains("cannon")) + { + Cannon.spawnCannon(getPlugin(), event.getPlayer().getLocation()); + } + } +} 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 new file mode 100644 index 000000000..809297362 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java @@ -0,0 +1,90 @@ +package mineplex.game.clans.clans.siege.cannon; + +import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +public class Cannon implements Listener +{ + private Location _location; + private CannonState _state; + + // Entity Information + private ArmorStand _armorStand; + + private Cannon(Location location) + { + _location = location; + _state = CannonState.EMPTY; + + updateEntities(); + } + + private void updateEntities() + { + if (_armorStand == null) + { + _armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); + } + + _armorStand.teleport(getArmorStandLocation()); + _armorStand.setVisible(false); + _armorStand.setGravity(false); + _armorStand.setHelmet(new ItemStack(_state.getMaterial(), 1, (short) 0, _state.getData())); + } + + private Location getArmorStandLocation() + { + return _location.clone().add(0, -0.5, 0); + } + + private void setState(CannonState state) + { + _state = state; + updateEntities(); + } + + /* + * Events + */ + + @EventHandler + public void onInteract(PlayerArmorStandManipulateEvent event) + { + if (_armorStand != null && _armorStand.equals(event.getRightClicked())) + { + Entity passenger = _armorStand.getPassenger(); + if (passenger == null) + { + _armorStand.setPassenger(event.getPlayer()); + } + + event.setCancelled(true); + } + } + + @EventHandler + public void onDamage(EntityDamageEvent event) + { + if (_armorStand != null && _armorStand.equals(event.getEntity())) + { + event.setCancelled(true); + } + } + + public static Cannon spawnCannon(JavaPlugin plugin, Location location) + { + System.out.println("Spawning Cannon at location " + location); + + Cannon cannon = new Cannon(location); + plugin.getServer().getPluginManager().registerEvents(cannon, plugin); + return cannon; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java new file mode 100644 index 000000000..5f0ffd27e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java @@ -0,0 +1,28 @@ +package mineplex.game.clans.clans.siege.cannon; + +import org.bukkit.Material; + +public enum CannonState +{ + EMPTY(Material.SPONGE, (byte) 0), + LOADED(Material.SPONGE, (byte) 1); + + private Material _material; + private byte _data; + + CannonState(Material material, byte data) + { + _material = material; + _data = data; + } + + public byte getData() + { + return _data; + } + + public Material getMaterial() + { + return _material; + } +} From a6be919e4a5c9adeabc28a06b8307ace51e55ae8 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 07:10:22 +0000 Subject: [PATCH 002/122] agh lost some code ;-; --- .../clans/clans/outpost/OutpostBuilder.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java new file mode 100644 index 000000000..e516047c9 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java @@ -0,0 +1,18 @@ +package mineplex.game.clans.clans.outpost; + +import java.util.List; + +import org.bukkit.Location; + +public class OutpostBuilder +{ + public OutpostBuilder(Location pos, String string, List wallLocations, Outpost outpost) + { + } + + public void tick() + { + + } + +} From 5b4b5fb2b5ab82703a460b4e6635e743f7cc53a3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 07:44:20 +0000 Subject: [PATCH 003/122] fixed outpost forcefield knocking you away even if the building is complete, also made the particles show the actual boundaries --- .../mineplex/game/clans/clans/outpost/Outpost.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java index 94f61dfe4..95ae92a19 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -277,13 +277,13 @@ public class Outpost implements Listener // Forcefield RGBData color = UtilColor.RgbLightBlue; - for (int x = -_type._size; x <= _type._size; x++) + for (int x = _forceFieldStart.getBlockX(); x <= _forceFieldEnd.getBlockX(); x++) { - for (int z = -_type._size; z <= _type._size; z++) + for (int z = _forceFieldStart.getBlockZ(); z <= _forceFieldStart.getBlockZ(); z++) { - if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size) + if (x == _forceFieldStart.getBlockX() || x == _forceFieldEnd.getBlockX() || z == _forceFieldStart.getBlockZ() || z == _forceFieldEnd.getBlockZ()) { - UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _origin.clone().add(x + .5, .1, z + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, new Location(_core.getWorld(), x + .5, UtilBlock.getHighest(_core.getWorld(), x, z).getY() + .15, z + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL); } } } @@ -299,7 +299,7 @@ public class Outpost implements Listener double circleX = nextCircleStage.getX(); double circleZ = nextCircleStage.getZ(); - UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 5.f, 0, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1.f, 0, ViewDist.NORMAL); } { @@ -310,7 +310,7 @@ public class Outpost implements Listener double circleX = nextCircleStage.getX(); double circleZ = nextCircleStage.getZ(); - UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 5.f, 0, ViewDist.NORMAL); + UtilParticle.PlayParticleToAll(ParticleType.MOB_SPELL, _core.clone().add(circleX + .5, 1.1d, circleZ + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1.f, 0, ViewDist.NORMAL); } } @@ -330,7 +330,7 @@ public class Outpost implements Listener } } - if (event.getType() != UpdateType.FAST && getState() == OutpostState.CONSTRUCTING) + if (event.getType() != UpdateType.FAST || getState() != OutpostState.CONSTRUCTING) { return; } From 62f16ada8120e035b9ba21de29254150ec0d85d1 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 07:57:35 +0000 Subject: [PATCH 004/122] that's not the correct bounds! --- .../src/mineplex/game/clans/clans/outpost/Outpost.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java index 95ae92a19..a23908327 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -279,7 +279,7 @@ public class Outpost implements Listener for (int x = _forceFieldStart.getBlockX(); x <= _forceFieldEnd.getBlockX(); x++) { - for (int z = _forceFieldStart.getBlockZ(); z <= _forceFieldStart.getBlockZ(); z++) + for (int z = _forceFieldStart.getBlockZ(); z <= _forceFieldEnd.getBlockZ(); z++) { if (x == _forceFieldStart.getBlockX() || x == _forceFieldEnd.getBlockX() || z == _forceFieldStart.getBlockZ() || z == _forceFieldEnd.getBlockZ()) { From 025f82e5ed2e6f351aac7aa85450af3db045477c Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 16:31:21 +0000 Subject: [PATCH 005/122] made the forcefield bump much weaker --- .../src/mineplex/game/clans/clans/outpost/Outpost.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java index a23908327..1730826b5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -339,7 +339,7 @@ public class Outpost implements Listener .filter(player -> !_clan.isMember(player)) .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) .forEach(player -> { - UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), 1, true, 0.8, 0, 1.1, true); + UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .4, true, 0.8, 0, 1.1, true); UtilPlayer.message(player, F.main("Clans", "This Outpost is still under construction!")); player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); }); From 6cde84ec5f565bd96e2321573ffe893945528cbe Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 18:57:25 +0000 Subject: [PATCH 006/122] fixed outpost block placing/breaking boundary checking --- .../game/clans/clans/outpost/Outpost.java | 10 +-- .../game/clans/clans/outpost/OutpostType.java | 67 ++++++++++++++++++- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java index 1730826b5..2f6d5e3ea 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -96,7 +96,7 @@ public class Outpost implements Listener _clan = clan; - _startCorner = location.clone().subtract(type._size, 1, type._size); + _startCorner = location.clone().subtract(type._size, 1.1, type._size); _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); _builders = new ArrayList<>(); @@ -209,17 +209,17 @@ public class Outpost implements Listener return; } - System.out.println(_blocks); - _blocks.values().stream().filter(event.getBlock().getLocation()::equals).forEach(block -> { + if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) + { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks in Outposts.")); event.setCancelled(true); - }); + }; } @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner, _endCorner)) + if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks in Outposts.")); event.setCancelled(true); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java index d7e04055b..f243bedcf 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; @@ -236,7 +237,6 @@ public enum OutpostType LinkedHashMap build = new LinkedHashMap<>(); File file = new File("schematic" + File.separator + "outpost_mk_II.schematic"); - System.out.println(file.getAbsolutePath()); Schematic schematic = UtilSchematic.loadSchematic(file); for (int y = 0; y < schematic.getHeight(); y++) @@ -284,6 +284,71 @@ public enum OutpostType return list; } + public Location getCoreLocation(Location location) + { + return location.clone().subtract(0, 1, 0); + } + }, + MK3(5, 25) { + public LinkedHashMap createBuildQueue(Location location, ClansManager clans) + { + try + { + LinkedHashMap build = new LinkedHashMap<>(); + + File file = new File("schematic" + File.separator + "outpost_mk_III.schematic"); + Schematic schematic = UtilSchematic.loadSchematic(file); + + for (int y = 0; y < schematic.getHeight(); y++) + { + for (int x = 0; x < schematic.getWidth(); x++) + { + for (int z = 0; z < schematic.getLength(); z++) + { + int relativeX = -(schematic.getWidth() / 2) + x; + int relativeZ = -(schematic.getLength() / 2) + z; + + Location loc = location.clone().add(relativeX, y - 1, relativeZ); + + if (schematic.getBlock(x, y, z) == 0 && loc.getBlock().getType() == Material.AIR) + { + continue; + } + + if (Material.getMaterial(schematic.getBlock(x, y, z)).name().contains("BANNER")) + { + build.put(UtilWorld.locToStr(loc), new OutpostBlockBanner(build, loc, schematic.getBlock(x, y, z), schematic.getData(x, y, z), DyeColor.RED)); + } + else + build.put(UtilWorld.locToStr(loc), new OutpostBlock(build, loc, schematic.getBlock(x, y, z), schematic.getData(x, y, z))); + } + } + } + + //Core + build.put(UtilWorld.locToStr(getCoreLocation(location)), new OutpostBlock(build, getCoreLocation(location), Material.DIAMOND_BLOCK.getId(), (byte)0)); + + return build; + } + catch(Exception e) + { + e.printStackTrace(); + return null; + } + } + + public List getWallLocations(Location middle) + { + List list = new ArrayList<>(); + + list.add(middle.clone().add(_size / 2, 0, 0).add(1, 0, 0)); + list.add(middle.clone().add(_size / 2, 0, -(_size / 2)).add(1, 0, -1)); + list.add(middle.clone().add(-(_size / 2), 0, -(_size / 2)).add(-1, 0, -1)); + list.add(middle.clone().add(-(_size / 2), 0, 0).add(-1, 0, 0)); + + return list; + } + public Location getCoreLocation(Location location) { return location.clone().subtract(0, 1, 0); From f3003e795ee29b92239f453282efcd2483b7784e Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 18:59:01 +0000 Subject: [PATCH 007/122] Implemented Outpost MK III --- .../message/commands/AnnounceCommand.java | 9 ++--- .../clans/outpost/OutpostBlockBanner.java | 36 +++++++++++++++++++ .../clans/clans/outpost/OutpostManager.java | 3 +- 3 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AnnounceCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AnnounceCommand.java index cbdddc228..d233056d0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AnnounceCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/commands/AnnounceCommand.java @@ -1,18 +1,15 @@ package mineplex.core.message.commands; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; -import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.message.MessageManager; import mineplex.serverdata.commands.AnnouncementCommand; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - public class AnnounceCommand extends CommandBase { public AnnounceCommand(MessageManager plugin) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java new file mode 100644 index 000000000..83bd55d1a --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java @@ -0,0 +1,36 @@ +package mineplex.game.clans.clans.outpost; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.bukkit.DyeColor; +import org.bukkit.Location; +import org.bukkit.block.Banner; +import org.bukkit.block.banner.Pattern; + +public class OutpostBlockBanner extends OutpostBlock +{ + private DyeColor _baseColor; + private List _patterns; + + public OutpostBlockBanner(Map blocks, Location loc, int id, byte data, DyeColor color, Pattern... patterns) + { + super(blocks, loc, id, data); + _baseColor = color; + _patterns = new ArrayList<>(Arrays.asList(patterns)); + } + + @Override + public void set() + { + super.set(); + + Banner banner = (Banner) _loc.getBlock().getState(); + banner.setBaseColor(_baseColor); + banner.setPatterns(_patterns); + + banner.update(true, false); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java index 355baa093..2e31b3d7c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java @@ -21,7 +21,6 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; @@ -50,7 +49,7 @@ public class OutpostManager extends MiniPlugin { if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) { - if (Spawn(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK2)) + if (Spawn(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3)) { event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); } From fb53e443e73805c597d3b0e69c1cb39440551cc3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 12 Jan 2016 20:27:24 +0000 Subject: [PATCH 008/122] cleanup and cannons stuff --- .../mineplex/game/clans/clans/ClansManager.java | 3 +-- .../clans/clans/{commands => outpost}/Meow.java | 6 +++--- .../clans/clans/outpost/OutpostManager.java | 2 ++ .../clans/scoreboard/ClansPlayerScoreboard.java | 2 -- .../game/clans/clans/siege/SiegeManager.java | 17 +++++++++++++++++ 5 files changed, 23 insertions(+), 7 deletions(-) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{commands => outpost}/Meow.java (70%) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index ebf4c0068..b58f8735b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -77,7 +77,6 @@ import mineplex.game.clans.clans.commands.ClansCommand; import mineplex.game.clans.clans.commands.ClansLoginManager; import mineplex.game.clans.clans.commands.KillCommand; import mineplex.game.clans.clans.commands.MapCommand; -import mineplex.game.clans.clans.commands.Meow; import mineplex.game.clans.clans.commands.RegionsCommand; import mineplex.game.clans.clans.data.PlayerClan; import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; @@ -215,7 +214,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati if (serverName.equals("GarboClans-1")) { - addCommand(new Meow(new OutpostManager(this))); + new OutpostManager(this); } _instance = this; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/Meow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Meow.java similarity index 70% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/Meow.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Meow.java index b6bc54b64..fff8b7821 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/Meow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Meow.java @@ -1,11 +1,10 @@ -package mineplex.game.clans.clans.commands; +package mineplex.game.clans.clans.outpost; import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; -import mineplex.game.clans.clans.outpost.Outpost; -import mineplex.game.clans.clans.outpost.OutpostManager; +import mineplex.game.clans.clans.siege.SiegeManager; public class Meow extends CommandBase { @@ -18,5 +17,6 @@ public class Meow extends CommandBase public void Execute(Player caller, String[] args) { caller.getInventory().addItem(Outpost.OUTPOST_ITEM); + caller.getInventory().addItem(SiegeManager.CANNON_ITEM); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java index 2e31b3d7c..b8f938b9c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java @@ -42,6 +42,8 @@ public class OutpostManager extends MiniPlugin _clansManager = clansManager; _removalQueue = new ArrayList<>(); + + addCommand(new Meow(this)); } @EventHandler(priority = EventPriority.LOWEST) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansPlayerScoreboard.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansPlayerScoreboard.java index 4fc9e80ab..c3e213da9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansPlayerScoreboard.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansPlayerScoreboard.java @@ -9,8 +9,6 @@ import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; -import net.minecraft.server.v1_8_R3.ScoreboardTeam; - import mineplex.core.common.util.C; import mineplex.core.common.util.UtilText; import mineplex.core.scoreboard.PlayerScoreboard; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 81b7df231..a10161ca1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,19 +1,36 @@ package mineplex.game.clans.clans.siege; +import org.bukkit.Material; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.siege.cannon.Cannon; public class SiegeManager extends MiniPlugin { + public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + public SiegeManager(JavaPlugin plugin) { super("Siege", plugin); } + @EventHandler(priority = EventPriority.LOWEST) + public void onPlaceBlock(BlockPlaceEvent event) + { + if (event.getItemInHand().isSimilar(CANNON_ITEM)) + { + Cannon.spawnCannon(getPlugin(), event.getPlayer().getLocation()); + } + } + @EventHandler public void debug(PlayerCommandPreprocessEvent event) { From 595ab0d76341103c7b96f0df7a7175108eade9c1 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 14 Jan 2016 09:46:12 +0000 Subject: [PATCH 009/122] siege work --- .../src/mineplex/game/clans/Recipes.java | 29 +++++++------- .../mineplex/game/clans/clans/ClansGame.java | 7 +--- .../game/clans/clans/ClansManager.java | 28 +------------ .../game/clans/clans/outpost/Outpost.java | 12 ++++++ .../clans/clans/outpost/OutpostManager.java | 10 +++++ .../game/clans/clans/siege/SiegeManager.java | 39 +++++++++++++++---- .../game/clans/clans/siege/cannon/Cannon.java | 14 +------ 7 files changed, 75 insertions(+), 64 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Recipes.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Recipes.java index 26c41fd33..05dc0d497 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Recipes.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Recipes.java @@ -1,27 +1,23 @@ package mineplex.game.clans; -import java.util.ArrayList; -import java.util.List; - -import mineplex.core.MiniPlugin; -import mineplex.core.common.util.UtilGear; -import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilServer; - import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; +import org.bukkit.material.SmoothBrick; import org.bukkit.plugin.java.JavaPlugin; +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilServer; +import mineplex.core.itemstack.ItemStackFactory; + public class Recipes extends MiniPlugin { public Recipes(JavaPlugin plugin) @@ -41,7 +37,14 @@ public class Recipes extends MiniPlugin diamondAxe.setIngredient('M', Material.DIAMOND_BLOCK); diamondAxe.setIngredient('S', Material.STICK); UtilServer.getServer().addRecipe(diamondAxe); - + + + ShapedRecipe bricks = new ShapedRecipe(new ItemStack(Material.SMOOTH_BRICK, 1)); + bricks.shape("XX", "XX"); + bricks.setIngredient('X', new SmoothBrick(Material.COBBLESTONE)); + UtilServer.getServer().addRecipe(bricks); + + ItemStack boosterSword = ItemStackFactory.Instance.CreateStack(Material.GOLD_SWORD, (byte) 0, 1, "Booster Sword", false); ShapedRecipe goldSword = new ShapedRecipe(boosterSword); goldSword.shape("M","M","S"); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java index 9db1f9d2e..88c12e4b0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java @@ -1,6 +1,8 @@ package mineplex.game.clans.clans; import java.sql.Timestamp; +import java.util.Arrays; +import java.util.Iterator; import org.bukkit.Bukkit; import org.bukkit.Effect; @@ -18,14 +20,11 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockIgniteEvent; import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -51,9 +50,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.core.repository.ClanTerritory; -import mineplex.game.clans.spawn.Spawn; import mineplex.minecraft.game.core.damage.CustomDamageEvent; -import net.minecraft.server.v1_8_R3.EnumDirection; public class ClansGame extends MiniPlugin { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index b58f8735b..ca972bc27 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -4,6 +4,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TimeZone; @@ -84,7 +85,6 @@ import mineplex.game.clans.clans.gui.ClanShop; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; import mineplex.game.clans.clans.observer.ObserverManager; -import mineplex.game.clans.clans.outpost.OutpostManager; import mineplex.game.clans.clans.playtime.Playtime; import mineplex.game.clans.clans.potato.PotatoManager; import mineplex.game.clans.clans.pvptimer.PvpTimer; @@ -212,11 +212,6 @@ public class ClansManager extends MiniClientPluginimplements IRelati { super("Clans Manager", plugin); - if (serverName.equals("GarboClans-1")) - { - new OutpostManager(this); - } - _instance = this; _punish = punish; @@ -258,7 +253,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati _itemMapManager = new ItemMapManager(this, _worldEvent); new TntGeneratorManager(plugin, this); new SupplyDropManager(plugin, this); - new SiegeManager(plugin); + new SiegeManager(plugin, this); _explosion = new Explosion(plugin, blockRestore); @@ -383,25 +378,6 @@ public class ClansManager extends MiniClientPluginimplements IRelati hologram.start(); } -// Iterator it = _plugin.getServer().recipeIterator(); -// Recipe recipe; -// while (it.hasNext()) -// { -// recipe = it.next(); -// if (recipe != null) -// { -// if (recipe.getResult().getType() == Material.SMOOTH_BRICK) -// { -// it.remove(); -// } -// } -// } -// -// final ShapedRecipe brrecipe = new ShapedRecipe(new ItemStack(Material.SMOOTH_BRICK, 1)); -// brrecipe.shape("XX", "XX", ""); -// brrecipe.setIngredient('X', Material.STONE); -// UtilServer.getServer().addRecipe(brrecipe); -// Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java index 2f6d5e3ea..c73749026 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java @@ -65,6 +65,9 @@ public class Outpost implements Listener private Location _origin; private Location _endCorner; + private Location _siegeAreaStart; + private Location _siegeAreaEnd; + private Location _forceFieldStart; private Location _forceFieldEnd; @@ -105,6 +108,9 @@ public class Outpost implements Listener _forceFieldStart = _startCorner.clone().subtract(3, 0, 3); _forceFieldEnd = _endCorner.clone().add(3, 0, 3); + _siegeAreaStart = _startCorner.clone().subtract(7, 0, 7); + _siegeAreaEnd = _endCorner.clone().add(7, 0, 7); + _origin = location.clone(); _type = type; @@ -480,4 +486,10 @@ public class Outpost implements Listener { _removalQueue.add(builder); } + + // AREA IN WHICH CANNONS AND OTHER SIEGE WEAPONS CAN BE PLACED + public boolean isInSiegeArea(Location location) + { + return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java index b8f938b9c..10427a819 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java @@ -210,4 +210,14 @@ public class OutpostManager extends MiniPlugin { _removalQueue.add(name); } + + public boolean isInOutpostSiegeArea(Location location, ClanInfo clan) + { + if (!_outposts.containsKey(clan.getName().toLowerCase())) + { + return false; + } + + return _outposts.get(clan.getName().toLowerCase()).isInSiegeArea(location); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index a10161ca1..b3bc6c958 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,25 +1,39 @@ package mineplex.game.clans.clans.siege; +import org.apache.commons.lang.Validate; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemBuilder; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.outpost.OutpostManager; import mineplex.game.clans.clans.siege.cannon.Cannon; public class SiegeManager extends MiniPlugin { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); - public SiegeManager(JavaPlugin plugin) + private ClansManager _clans; + + private OutpostManager _outpostManager; + + public SiegeManager(JavaPlugin plugin, ClansManager clans) { super("Siege", plugin); + + _clans = clans; + + _outpostManager = new OutpostManager(clans); } @EventHandler(priority = EventPriority.LOWEST) @@ -27,16 +41,27 @@ public class SiegeManager extends MiniPlugin { if (event.getItemInHand().isSimilar(CANNON_ITEM)) { - Cannon.spawnCannon(getPlugin(), event.getPlayer().getLocation()); + if (!spawnCannon(event.getPlayer(), event.getBlock().getLocation())) + { + event.setCancelled(true); + } } } - @EventHandler - public void debug(PlayerCommandPreprocessEvent event) + public boolean spawnCannon(Player player, Location location) { - if (event.getMessage().contains("cannon")) + if (!_clans.isInClan(player)) { - Cannon.spawnCannon(getPlugin(), event.getPlayer().getLocation()); + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon.")); + return false; } + + if (!_outpostManager.isInOutpostSiegeArea(location, _clans.getClan(player))) + { + UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); + return false; + } + + return true; } } 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 809297362..6d24bb30f 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 @@ -3,6 +3,7 @@ package mineplex.game.clans.clans.siege.cannon; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; @@ -51,10 +52,6 @@ public class Cannon implements Listener updateEntities(); } - /* - * Events - */ - @EventHandler public void onInteract(PlayerArmorStandManipulateEvent event) { @@ -78,13 +75,4 @@ public class Cannon implements Listener event.setCancelled(true); } } - - public static Cannon spawnCannon(JavaPlugin plugin, Location location) - { - System.out.println("Spawning Cannon at location " + location); - - Cannon cannon = new Cannon(location); - plugin.getServer().getPluginManager().registerEvents(cannon, plugin); - return cannon; - } } From 70444ff5081ff2eb32567def874258237c6ad2a2 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 14 Jan 2016 19:53:29 +0000 Subject: [PATCH 010/122] cannon + siege work with outposts, also moved outposts to the clans.siege package --- .../mineplex/core/common/util/UtilInv.java | 17 +++++++ .../game/clans/clans/siege/SiegeManager.java | 42 +---------------- .../game/clans/clans/siege/cannon/Cannon.java | 38 +++++++++++---- .../clans/clans/siege/cannon/CannonState.java | 6 +++ .../clans/clans/{ => siege}/outpost/Meow.java | 2 +- .../clans/{ => siege}/outpost/Outpost.java | 35 +++++++++++++- .../{ => siege}/outpost/OutpostBlock.java | 2 +- .../outpost/OutpostBlockBanner.java | 2 +- .../{ => siege}/outpost/OutpostBuilder.java | 2 +- .../{ => siege}/outpost/OutpostManager.java | 47 ++++++++++++++++--- .../{ => siege}/outpost/OutpostState.java | 2 +- .../{ => siege}/outpost/OutpostType.java | 2 +- 12 files changed, 133 insertions(+), 64 deletions(-) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/Meow.java (90%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/Outpost.java (93%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/OutpostBlock.java (95%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/OutpostBlockBanner.java (94%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/OutpostBuilder.java (81%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/OutpostManager.java (80%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/OutpostState.java (63%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/{ => siege}/outpost/OutpostType.java (99%) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java index 1b1b5b775..aa0b8acb8 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilInv.java @@ -396,4 +396,21 @@ public class UtilInv return amount; } + + public static ItemStack decrement(ItemStack item) + { + ItemStack newItem; + + if (item.getAmount() == 1) + { + newItem = null; + } + else + { + newItem = item; + newItem.setAmount(newItem.getAmount() - 1); + } + + return newItem; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index b3bc6c958..08422e6a8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,23 +1,14 @@ package mineplex.game.clans.clans.siege; -import org.apache.commons.lang.Validate; -import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.outpost.OutpostManager; -import mineplex.game.clans.clans.siege.cannon.Cannon; +import mineplex.game.clans.clans.siege.outpost.OutpostManager; public class SiegeManager extends MiniPlugin { @@ -33,35 +24,6 @@ public class SiegeManager extends MiniPlugin _clans = clans; - _outpostManager = new OutpostManager(clans); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlaceBlock(BlockPlaceEvent event) - { - if (event.getItemInHand().isSimilar(CANNON_ITEM)) - { - if (!spawnCannon(event.getPlayer(), event.getBlock().getLocation())) - { - event.setCancelled(true); - } - } - } - - public boolean spawnCannon(Player player, Location location) - { - if (!_clans.isInClan(player)) - { - UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon.")); - return false; - } - - if (!_outpostManager.isInOutpostSiegeArea(location, _clans.getClan(player))) - { - UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); - return false; - } - - return true; + _outpostManager = new OutpostManager(clans, this); } } 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 6d24bb30f..88ccf5b70 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 @@ -3,31 +3,39 @@ package mineplex.game.clans.clans.siege.cannon; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.game.clans.clans.siege.outpost.Outpost; public class Cannon implements Listener { private Location _location; private CannonState _state; - + + private Outpost _outpost; + // Entity Information private ArmorStand _armorStand; - private Cannon(Location location) + public Cannon(Outpost outpost, Location location) { + _outpost = outpost; _location = location; _state = CannonState.EMPTY; - + updateEntities(); } - + + public void cleanup() + { + _armorStand.remove(); + HandlerList.unregisterAll(this); + } + private void updateEntities() { if (_armorStand == null) @@ -38,12 +46,12 @@ public class Cannon implements Listener _armorStand.teleport(getArmorStandLocation()); _armorStand.setVisible(false); _armorStand.setGravity(false); - _armorStand.setHelmet(new ItemStack(_state.getMaterial(), 1, (short) 0, _state.getData())); + _armorStand.setHelmet(_state.toItemStack()); } private Location getArmorStandLocation() { - return _location.clone().add(0, -0.5, 0); + return _location.clone().add(.5, -1.3, .5); } private void setState(CannonState state) @@ -51,6 +59,16 @@ public class Cannon implements Listener _state = state; updateEntities(); } + + public void load() + { + setState(CannonState.LOADED); + } + + public void fire() + { + setState(CannonState.EMPTY); + } @EventHandler public void onInteract(PlayerArmorStandManipulateEvent event) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java index 5f0ffd27e..3b14d5ee2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java @@ -1,6 +1,7 @@ package mineplex.game.clans.clans.siege.cannon; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; public enum CannonState { @@ -25,4 +26,9 @@ public enum CannonState { return _material; } + + public ItemStack toItemStack() + { + return new ItemStack(_material, 1, (short) 0, _data); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Meow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java similarity index 90% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Meow.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java index fff8b7821..03ff02b9d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Meow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import org.bukkit.entity.Player; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java similarity index 93% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index c73749026..c5cd0daec 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import java.util.ArrayList; import java.util.Collections; @@ -11,6 +11,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; @@ -32,6 +33,7 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilColor; import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; @@ -42,12 +44,15 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilUI; import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; +import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.cannon.Cannon; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; @@ -79,6 +84,8 @@ public class Outpost implements Listener protected OutpostType _type; private OutpostState _state; + private List _cannons; + private Hologram _preHologram; private Hologram _preHologram2; @@ -105,6 +112,8 @@ public class Outpost implements Listener _builders = new ArrayList<>(); _removalQueue = new ArrayList<>(); + _cannons = new ArrayList<>(); + _forceFieldStart = _startCorner.clone().subtract(3, 0, 3); _forceFieldEnd = _endCorner.clone().add(3, 0, 3); @@ -119,7 +128,7 @@ public class Outpost implements Listener _core = _type.getCoreLocation(_origin); - _preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block"); + _preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); _preHologram2 = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); _preHologram.start(); @@ -140,6 +149,9 @@ public class Outpost implements Listener _state = OutpostState.DEAD; + _cannons.forEach(Cannon::cleanup); + _cannons.clear(); + _host.queueForRemoval(_clan.getName()); } @@ -225,6 +237,17 @@ public class Outpost implements Listener @EventHandler public void onBlockPlace(BlockPlaceEvent event) { + if (event.getItemInHand().isSimilar(SiegeManager.CANNON_ITEM)) + { + if (_host.spawnCannon(event.getPlayer(), event.getBlock().getLocation())) + { + event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); + return; + } + + event.setCancelled(true); + } + if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks in Outposts.")); @@ -492,4 +515,12 @@ public class Outpost implements Listener { return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd); } + + public void spawnCannon(Player player, Location location) + { + Cannon cannon = new Cannon(this, location); + + _host.getPlugin().getServer().getPluginManager().registerEvents(cannon, _host.getPlugin()); + _cannons.add(cannon); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java similarity index 95% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlock.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java index cf5b4dac9..f9dde3d53 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlock.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import java.util.Map; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlockBanner.java similarity index 94% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlockBanner.java index 83bd55d1a..fe537ed63 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBlockBanner.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlockBanner.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import java.util.ArrayList; import java.util.Arrays; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java similarity index 81% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java index e516047c9..89ac4d68e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import java.util.List; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java similarity index 80% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 10427a819..6793eba79 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import java.util.ArrayList; import java.util.HashMap; @@ -26,6 +26,7 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; +import mineplex.game.clans.clans.siege.SiegeManager; public class OutpostManager extends MiniPlugin { @@ -35,10 +36,14 @@ public class OutpostManager extends MiniPlugin private List _removalQueue; - public OutpostManager(ClansManager clansManager) + private SiegeManager _siegeManager; + + public OutpostManager(ClansManager clansManager, SiegeManager siegeManager) { super("Outpost Manager", clansManager.getPlugin()); + _siegeManager = siegeManager; + _clansManager = clansManager; _removalQueue = new ArrayList<>(); @@ -46,12 +51,37 @@ public class OutpostManager extends MiniPlugin addCommand(new Meow(this)); } + public boolean spawnCannon(Player player, Location location) + { + if (!_clansManager.isInClan(player)) + { + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon.")); + return false; + } + + if (_clansManager.getClanUtility().isClaimed(location)) + { + UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in unclaimed territory.")); + return false; + } + + if (!isInOutpostSiegeArea(location, _clansManager.getClan(player))) + { + UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); + return false; + } + + Get(_clansManager.getClan(player)).spawnCannon(player, location); + + return true; + } + @EventHandler(priority = EventPriority.LOWEST) public void onPlaceBlock(BlockPlaceEvent event) { if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) { - if (Spawn(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3)) + if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3)) { event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); } @@ -62,7 +92,7 @@ public class OutpostManager extends MiniPlugin } } - public boolean Spawn(Player player, Location location, OutpostType type) + public boolean spawnOutpost(Player player, Location location, OutpostType type) { if (!_clansManager.isInClan(player)) { @@ -86,7 +116,7 @@ public class OutpostManager extends MiniPlugin if (Get(clan) != null) { - UtilPlayer.message(player, F.main("Clans", "Your clan already has an outpost")); + UtilPlayer.message(player, F.main("Clans", "Your Clan already has an outpost.")); return false; } @@ -98,7 +128,7 @@ public class OutpostManager extends MiniPlugin for (Outpost outpost : _outposts.values()) { - if (UtilMath.offset(location, outpost.getExactMiddle()) < 14) + if (UtilMath.offset(location, outpost.getExactMiddle()) < type._size + 8) { UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost near other Outposts.")); return false; @@ -220,4 +250,9 @@ public class OutpostManager extends MiniPlugin return _outposts.get(clan.getName().toLowerCase()).isInSiegeArea(location); } + + public SiegeManager getSiegeManager() + { + return _siegeManager; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java similarity index 63% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostState.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java index 310e9bb59..ffa3162ec 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; public enum OutpostState { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java similarity index 99% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java index f243bedcf..73d9c63a5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.outpost; +package mineplex.game.clans.clans.siege.outpost; import java.io.File; import java.io.FileInputStream; From e0b7be0813da25cb3fc7dc4fceec66bab7ae1111 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 15 Jan 2016 06:58:20 +0000 Subject: [PATCH 011/122] made /meow give you 64 cannons and 64 outposts --- .../game/clans/clans/siege/outpost/Meow.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java index 03ff02b9d..43ad0d033 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java @@ -1,10 +1,12 @@ package mineplex.game.clans.clans.siege.outpost; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.cannon.Cannon; public class Meow extends CommandBase { @@ -16,7 +18,13 @@ public class Meow extends CommandBase @Override public void Execute(Player caller, String[] args) { - caller.getInventory().addItem(Outpost.OUTPOST_ITEM); - caller.getInventory().addItem(SiegeManager.CANNON_ITEM); + ItemStack outpost = new ItemStack(Outpost.OUTPOST_ITEM); + ItemStack cannons = new ItemStack(Cannon.CANNON_ITEM); + + outpost.setAmount(64); + cannons.setAmount(64); + + caller.getInventory().addItem(outpost); + caller.getInventory().addItem(cannons); } } From f78c46987524055fe30d3ce45bc5004ee3ee9a13 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 15 Jan 2016 06:59:18 +0000 Subject: [PATCH 012/122] moved cannon item to Cannon.java to be consistent with the outpost item being in Outpost.java --- .../src/mineplex/game/clans/clans/siege/SiegeManager.java | 2 -- .../src/mineplex/game/clans/clans/siege/cannon/Cannon.java | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 08422e6a8..34e4e3fcb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -12,8 +12,6 @@ import mineplex.game.clans.clans.siege.outpost.OutpostManager; public class SiegeManager extends MiniPlugin { - public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); - private ClansManager _clans; private OutpostManager _outpostManager; 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 88ccf5b70..e109650d8 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 @@ -1,6 +1,7 @@ package mineplex.game.clans.clans.siege.cannon; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; @@ -8,11 +9,16 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.inventory.ItemStack; +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.siege.outpost.Outpost; public class Cannon implements Listener { + public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + private Location _location; private CannonState _state; From a554f1b7c6067d8b68340aa831043a068a0c1a7d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 15 Jan 2016 07:00:39 +0000 Subject: [PATCH 013/122] needed to update some code with the cannon item location changing. also removed unused imports. --- .../src/mineplex/game/clans/clans/ClansManager.java | 1 - .../src/mineplex/game/clans/clans/siege/SiegeManager.java | 4 ---- .../src/mineplex/game/clans/clans/siege/outpost/Meow.java | 1 - .../src/mineplex/game/clans/clans/siege/outpost/Outpost.java | 2 +- 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index ca972bc27..6c6b2e261 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -4,7 +4,6 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.TimeZone; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 34e4e3fcb..8e7896fd6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,12 +1,8 @@ package mineplex.game.clans.clans.siege; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; -import mineplex.core.common.util.C; -import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.outpost.OutpostManager; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java index 43ad0d033..cd7a9f314 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java @@ -5,7 +5,6 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; -import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.cannon.Cannon; public class Meow extends CommandBase diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index c5cd0daec..01dc362a0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -237,7 +237,7 @@ public class Outpost implements Listener @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - if (event.getItemInHand().isSimilar(SiegeManager.CANNON_ITEM)) + if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM)) { if (_host.spawnCannon(event.getPlayer(), event.getBlock().getLocation())) { From 1faeb43b731034afe59910bbf7296923d3219652 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 15 Jan 2016 07:17:51 +0000 Subject: [PATCH 014/122] fixed iron block sometimes sticking around after placing cannon --- .../src/mineplex/game/clans/clans/siege/outpost/Outpost.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 01dc362a0..c1fab01bd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -239,13 +239,13 @@ public class Outpost implements Listener { if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM)) { + event.setCancelled(true); + if (_host.spawnCannon(event.getPlayer(), event.getBlock().getLocation())) { event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); return; } - - event.setCancelled(true); } if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) From 1042edb13486b8f89e5d4d93f18cf1a568e1b382 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 15 Jan 2016 20:17:57 +0000 Subject: [PATCH 015/122] CANNONZ! --- .../mineplex/core/common/util/UtilMath.java | 5 + .../clans/clans/playtime/command/cemde.java | 2 +- .../game/clans/clans/siege/cannon/Cannon.java | 118 ++++++++++++++++-- .../clans/clans/siege/cannon/CannonState.java | 4 +- 4 files changed, 117 insertions(+), 12 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 2c950b705..049dd47d0 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -108,6 +108,11 @@ public class UtilMath return num < min ? min : (num > max ? max : num); } + public static float clamp(float num, float min, float max) + { + return num < min ? min : (num > max ? max : num); + } + public static long clamp(long num, long min, long max) { return num < min ? min : (num > max ? max : num); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java index d170200be..8a0f36609 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/playtime/command/cemde.java @@ -14,7 +14,7 @@ public class cemde extends CommandBase PvpTimer _timer; public cemde(StatsManager plugin, PvpTimer timer) { - super(plugin, Rank.ALL, "rstime"); + super(plugin, Rank.SNR_MODERATOR, "rstime"); _timer = timer; } 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 e109650d8..b021831d9 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 @@ -4,15 +4,25 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.EulerAngle; import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilEnt; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.siege.outpost.Outpost; public class Cannon implements Listener @@ -24,8 +34,12 @@ public class Cannon implements Listener private Outpost _outpost; + private Player _rider; + // Entity Information private ArmorStand _armorStand; + private Slime _filler; + private Slime _filler2; public Cannon(Outpost outpost, Location location) { @@ -39,6 +53,8 @@ public class Cannon implements Listener public void cleanup() { _armorStand.remove(); + _filler.remove(); + _filler2.remove(); HandlerList.unregisterAll(this); } @@ -48,7 +64,30 @@ public class Cannon implements Listener { _armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); } - + + if (_filler == null) + { + _filler = _location.getWorld().spawn(getArmorStandLocation(), Slime.class); + } + + if (_filler2 == null) + { + _filler2 = _location.getWorld().spawn(getArmorStandLocation(), Slime.class); + } + + _filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + _filler.setSize(-1); + _armorStand.setPassenger(_filler); + UtilEnt.Vegetate(_filler); + UtilEnt.silence(_filler, true); + + _filler2.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + _filler2.setSize(-1); + _filler.setPassenger(_filler2); + UtilEnt.Vegetate(_filler2); + UtilEnt.silence(_filler2, true); + + UtilEnt.setFakeHead(_armorStand, true); _armorStand.teleport(getArmorStandLocation()); _armorStand.setVisible(false); _armorStand.setGravity(false); @@ -57,7 +96,7 @@ public class Cannon implements Listener private Location getArmorStandLocation() { - return _location.clone().add(.5, -1.3, .5); + return _location.clone().add(.5, .15, .5); } private void setState(CannonState state) @@ -75,26 +114,87 @@ public class Cannon implements Listener { setState(CannonState.EMPTY); } - + @EventHandler - public void onInteract(PlayerArmorStandManipulateEvent event) - { - if (_armorStand != null && _armorStand.equals(event.getRightClicked())) + public void onInteract(PlayerInteractAtEntityEvent event) + { + if (event.getRightClicked().equals(_filler) || event.getRightClicked().equals(_filler2)) { - Entity passenger = _armorStand.getPassenger(); + Entity passenger = _filler2.getPassenger(); if (passenger == null) { - _armorStand.setPassenger(event.getPlayer()); + _filler2.setPassenger(event.getPlayer()); + + _rider = event.getPlayer(); } event.setCancelled(true); } } + + @EventHandler + public void onInteract(PlayerInteractEntityEvent event) + { + if (event.getRightClicked().equals(_filler) || event.getRightClicked().equals(_filler2)) + { + Entity passenger = _filler2.getPassenger(); + if (passenger == null) + { + _filler2.setPassenger(event.getPlayer()); + + _rider = event.getPlayer(); + } + + event.setCancelled(true); + } + } + + @EventHandler + public void onInteract(PlayerArmorStandManipulateEvent event) + { + if (event.getRightClicked().equals(_armorStand)) + { + Entity passenger = _filler2.getPassenger(); + if (passenger == null) + { + _filler2.setPassenger(event.getPlayer()); + + _rider = event.getPlayer(); + } + + event.setCancelled(true); + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + if (_rider != null && !_rider.equals(_filler2.getPassenger())) + { + _rider = null; + } + + if (_rider != null) + { + double standYaw = Math.toDegrees(_armorStand.getHeadPose().getY()) % 360; + double riderYaw = _rider.getLocation().getYaw() % 360; + + double dif = riderYaw - standYaw; + double yaw = standYaw + (dif / 20.f); + + _armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); + } + } @EventHandler public void onDamage(EntityDamageEvent event) { - if (_armorStand != null && _armorStand.equals(event.getEntity())) + if (_armorStand != null && _armorStand.equals(event.getEntity()) || _filler != null && _filler.equals(event.getEntity()) || _filler2 != null && _filler2.equals(event.getEntity())) { event.setCancelled(true); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java index 3b14d5ee2..c3de8460a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java @@ -5,8 +5,8 @@ import org.bukkit.inventory.ItemStack; public enum CannonState { - EMPTY(Material.SPONGE, (byte) 0), - LOADED(Material.SPONGE, (byte) 1); + EMPTY(Material.SPONGE, (byte) 1), + LOADED(Material.SPONGE, (byte) 0); private Material _material; private byte _data; From e71a2d2e48f8fc07eae6450153e1f3fe71f8a9f1 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 16 Jan 2016 08:20:11 +0000 Subject: [PATCH 016/122] quick npe fix --- .../src/mineplex/game/clans/clans/siege/cannon/Cannon.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 b021831d9..d3b34ccca 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 @@ -52,9 +52,9 @@ public class Cannon implements Listener public void cleanup() { - _armorStand.remove(); - _filler.remove(); - _filler2.remove(); + if (_armorStand != null) _armorStand.remove(); + if (_filler != null) _filler.remove(); + if (_filler2 != null) _filler2.remove(); HandlerList.unregisterAll(this); } From 254a2e45e4494cc7e4151a61ba7c496887f56bc1 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 16 Jan 2016 08:22:35 +0000 Subject: [PATCH 017/122] comments + cannons state enum rename --- .../src/mineplex/game/clans/clans/siege/cannon/Cannon.java | 4 ++-- .../mineplex/game/clans/clans/siege/cannon/CannonState.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 d3b34ccca..f5502e2fb 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 @@ -45,7 +45,7 @@ public class Cannon implements Listener { _outpost = outpost; _location = location; - _state = CannonState.EMPTY; + _state = CannonState.UNLOADED; updateEntities(); } @@ -112,7 +112,7 @@ public class Cannon implements Listener public void fire() { - setState(CannonState.EMPTY); + setState(CannonState.UNLOADED); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java index c3de8460a..8d15cd1c0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java @@ -5,8 +5,8 @@ import org.bukkit.inventory.ItemStack; public enum CannonState { - EMPTY(Material.SPONGE, (byte) 1), - LOADED(Material.SPONGE, (byte) 0); + UNLOADED(Material.SPONGE, (byte) 1 /* wet sponge */), + LOADED(Material.SPONGE, (byte) 0 /* regular sponge */); private Material _material; private byte _data; From 40c52ac5571e88609435c24d11ee3f00c961998d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 16 Jan 2016 08:25:30 +0000 Subject: [PATCH 018/122] made it so that cannons don't rely on outposts. this should help with testing them without needing an outpost --- .../src/mineplex/game/clans/clans/siege/cannon/Cannon.java | 4 +--- .../src/mineplex/game/clans/clans/siege/outpost/Outpost.java | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) 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 f5502e2fb..9b6a96abc 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 @@ -32,7 +32,6 @@ public class Cannon implements Listener private Location _location; private CannonState _state; - private Outpost _outpost; private Player _rider; @@ -41,9 +40,8 @@ public class Cannon implements Listener private Slime _filler; private Slime _filler2; - public Cannon(Outpost outpost, Location location) + public Cannon(Location location) { - _outpost = outpost; _location = location; _state = CannonState.UNLOADED; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index c1fab01bd..50c63eee6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -518,7 +518,7 @@ public class Outpost implements Listener public void spawnCannon(Player player, Location location) { - Cannon cannon = new Cannon(this, location); + Cannon cannon = new Cannon(location); _host.getPlugin().getServer().getPluginManager().registerEvents(cannon, _host.getPlugin()); _cannons.add(cannon); From cc48d9820864171736b7ab3e5be48cdada905147 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 22 Jan 2016 11:06:19 +0000 Subject: [PATCH 019/122] pushing to beta to change to alpha --- .../mineplex/core/common/util/UtilMath.java | 10 +++ .../game/clans/clans/siege/SiegeManager.java | 55 ++++++++++++ .../game/clans/clans/siege/cannon/Cannon.java | 83 +++++++++++-------- .../{Meow.java => CommandSiegeSupplies.java} | 10 ++- .../clans/clans/siege/outpost/Outpost.java | 21 +---- .../clans/siege/outpost/OutpostManager.java | 27 +----- 6 files changed, 122 insertions(+), 84 deletions(-) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/{Meow.java => CommandSiegeSupplies.java} (64%) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 049dd47d0..5e2324704 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -142,4 +142,14 @@ public class UtilMath return ((double) rand) / 100.d; } + + public static T getLast(List list) + { + return list.isEmpty() ? null : list.get(list.size() - 1); + } + + public static T getFirst(List list) + { + return list.isEmpty() ? null : list.get(0); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 8e7896fd6..8fbc15a52 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,9 +1,17 @@ package mineplex.game.clans.clans.siege; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.siege.cannon.Cannon; import mineplex.game.clans.clans.siege.outpost.OutpostManager; public class SiegeManager extends MiniPlugin @@ -20,4 +28,51 @@ public class SiegeManager extends MiniPlugin _outpostManager = new OutpostManager(clans, this); } + + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) + { + if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM)) + { + event.setCancelled(true); + + if (trySpawnCannon(event.getPlayer(), event.getBlock().getLocation())) + { + event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); + return; + } + } + } + + public boolean trySpawnCannon(Player player, Location location) + { + if (!_clans.isInClan(player)) + { + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon.")); + return false; + } + + if (_clans.getClanUtility().isClaimed(location)) + { + UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in unclaimed territory.")); + return false; + } + +// if (!isInOutpostSiegeArea(location, _clans.getClan(player))) +// { +// UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); +// return false; +// } + + spawnCannon(player, location); + + return true; + } + + public void spawnCannon(Player player, Location location) + { + Cannon cannon = new Cannon(location); + + _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(cannon, _outpostManager.getPlugin()); + } } 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 9b6a96abc..173986292 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 @@ -1,5 +1,8 @@ package mineplex.game.clans.clans.siege.cannon; +import java.util.LinkedList; +import java.util.List; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.ArmorStand; @@ -20,10 +23,10 @@ import org.bukkit.util.EulerAngle; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilMath; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.siege.outpost.Outpost; public class Cannon implements Listener { @@ -37,22 +40,25 @@ public class Cannon implements Listener // Entity Information private ArmorStand _armorStand; - private Slime _filler; - private Slime _filler2; - + + private List _fillers; + public Cannon(Location location) { _location = location; _state = CannonState.UNLOADED; + _fillers = new LinkedList<>(); + updateEntities(); } public void cleanup() { if (_armorStand != null) _armorStand.remove(); - if (_filler != null) _filler.remove(); - if (_filler2 != null) _filler2.remove(); + + _fillers.forEach(Entity::remove); + HandlerList.unregisterAll(this); } @@ -63,28 +69,33 @@ public class Cannon implements Listener _armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); } - if (_filler == null) + if (_fillers.isEmpty()) { - _filler = _location.getWorld().spawn(getArmorStandLocation(), Slime.class); + Slime slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class); + + UtilEnt.silence(slime, true); + UtilEnt.Vegetate(slime); + + slime.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + _armorStand.setPassenger(slime); + + _fillers.add(slime); + + slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class); + + UtilEnt.silence(slime, true); + UtilEnt.Vegetate(slime); + + slime.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + UtilMath.getLast(_fillers).setPassenger(slime); + + _fillers.add(slime); } - if (_filler2 == null) - { - _filler2 = _location.getWorld().spawn(getArmorStandLocation(), Slime.class); - } - - _filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - _filler.setSize(-1); - _armorStand.setPassenger(_filler); - UtilEnt.Vegetate(_filler); - UtilEnt.silence(_filler, true); - - _filler2.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - _filler2.setSize(-1); - _filler.setPassenger(_filler2); - UtilEnt.Vegetate(_filler2); - UtilEnt.silence(_filler2, true); - UtilEnt.setFakeHead(_armorStand, true); _armorStand.teleport(getArmorStandLocation()); _armorStand.setVisible(false); @@ -116,12 +127,12 @@ public class Cannon implements Listener @EventHandler public void onInteract(PlayerInteractAtEntityEvent event) { - if (event.getRightClicked().equals(_filler) || event.getRightClicked().equals(_filler2)) + if (_fillers.contains(event.getRightClicked())) { - Entity passenger = _filler2.getPassenger(); + Entity passenger = UtilMath.getLast(_fillers); if (passenger == null) { - _filler2.setPassenger(event.getPlayer()); + UtilMath.getLast(_fillers).setPassenger(event.getPlayer()); _rider = event.getPlayer(); } @@ -133,12 +144,12 @@ public class Cannon implements Listener @EventHandler public void onInteract(PlayerInteractEntityEvent event) { - if (event.getRightClicked().equals(_filler) || event.getRightClicked().equals(_filler2)) + if (_fillers.contains(event.getRightClicked())) { - Entity passenger = _filler2.getPassenger(); + Entity passenger = UtilMath.getLast(_fillers).getPassenger(); if (passenger == null) { - _filler2.setPassenger(event.getPlayer()); + UtilMath.getLast(_fillers).setPassenger(event.getPlayer()); _rider = event.getPlayer(); } @@ -150,12 +161,12 @@ public class Cannon implements Listener @EventHandler public void onInteract(PlayerArmorStandManipulateEvent event) { - if (event.getRightClicked().equals(_armorStand)) + if (_fillers.contains(event.getRightClicked())) { - Entity passenger = _filler2.getPassenger(); + Entity passenger = UtilMath.getLast(_fillers).getPassenger(); if (passenger == null) { - _filler2.setPassenger(event.getPlayer()); + UtilMath.getLast(_fillers).setPassenger(event.getPlayer()); _rider = event.getPlayer(); } @@ -172,7 +183,7 @@ public class Cannon implements Listener return; } - if (_rider != null && !_rider.equals(_filler2.getPassenger())) + if (_rider != null && !_rider.equals(UtilMath.getLast(_fillers).getPassenger())) { _rider = null; } @@ -192,7 +203,7 @@ public class Cannon implements Listener @EventHandler public void onDamage(EntityDamageEvent event) { - if (_armorStand != null && _armorStand.equals(event.getEntity()) || _filler != null && _filler.equals(event.getEntity()) || _filler2 != null && _filler2.equals(event.getEntity())) + if (_armorStand != null && _armorStand.equals(event.getEntity()) || _fillers.contains(event.getEntity())) { event.setCancelled(true); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java similarity index 64% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java index cd7a9f314..6a53b151e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Meow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java @@ -5,13 +5,15 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.siege.cannon.Cannon; -public class Meow extends CommandBase +public class CommandSiegeSupplies extends CommandBase { - public Meow(OutpostManager plugin) + public CommandSiegeSupplies(OutpostManager plugin) { - super(plugin, Rank.ALL, "meow"); + super(plugin, Rank.CMOD, "siegesupplies"); } @Override @@ -25,5 +27,7 @@ public class Meow extends CommandBase caller.getInventory().addItem(outpost); caller.getInventory().addItem(cannons); + + UtilPlayer.message(caller, F.main("Clans", "Received supplies for a siege.")); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 50c63eee6..940aa5eec 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -237,16 +237,7 @@ public class Outpost implements Listener @EventHandler public void onBlockPlace(BlockPlaceEvent event) { - if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM)) - { - event.setCancelled(true); - - if (_host.spawnCannon(event.getPlayer(), event.getBlock().getLocation())) - { - event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); - return; - } - } + if (event.isCancelled()) return; if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { @@ -513,14 +504,6 @@ public class Outpost implements Listener // AREA IN WHICH CANNONS AND OTHER SIEGE WEAPONS CAN BE PLACED public boolean isInSiegeArea(Location location) { - return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd); - } - - public void spawnCannon(Player player, Location location) - { - Cannon cannon = new Cannon(location); - - _host.getPlugin().getServer().getPluginManager().registerEvents(cannon, _host.getPlugin()); - _cannons.add(cannon); + return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd.clone().add(.9, 0, .9)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 6793eba79..388a204f2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -48,32 +48,7 @@ public class OutpostManager extends MiniPlugin _removalQueue = new ArrayList<>(); - addCommand(new Meow(this)); - } - - public boolean spawnCannon(Player player, Location location) - { - if (!_clansManager.isInClan(player)) - { - UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon.")); - return false; - } - - if (_clansManager.getClanUtility().isClaimed(location)) - { - UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in unclaimed territory.")); - return false; - } - - if (!isInOutpostSiegeArea(location, _clansManager.getClan(player))) - { - UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); - return false; - } - - Get(_clansManager.getClan(player)).spawnCannon(player, location); - - return true; + addCommand(new CommandSiegeSupplies(this)); } @EventHandler(priority = EventPriority.LOWEST) From f25c7b0277d08acde1a49a1e3fb5286d917d185a Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 22 Jan 2016 15:19:32 +0000 Subject: [PATCH 020/122] don't need that + npe fix --- .../clans/clans/outpost/OutpostBuilder.java | 130 ------------------ .../game/clans/gameplay/safelog/SafeLog.java | 7 +- .../gameplay/safelog/npc/NPCManager.java | 13 +- 3 files changed, 9 insertions(+), 141 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java deleted file mode 100644 index 51b0724ad..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/OutpostBuilder.java +++ /dev/null @@ -1,130 +0,0 @@ -package mineplex.game.clans.clans.outpost; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton; -import org.bukkit.inventory.ItemStack; - -import com.mojang.authlib.GameProfile; - -import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.disguise.disguises.DisguisePlayer; -import mineplex.game.clans.clans.outpost.pathing.AStar; -import mineplex.game.clans.clans.outpost.pathing.AStar.InvalidPathException; -import mineplex.game.clans.clans.outpost.pathing.PathingResult; -import mineplex.game.clans.clans.outpost.pathing.Tile; - -public class OutpostBuilder -{ - private Skeleton _entity; - - private List _path; - private int _pathPos; - private List _moveLocations; - private int _nextLocation; - private long _arrivedTime; - private long _lastMovement; - - private Outpost _host; - - public OutpostBuilder(Location pos, String name, List locations, Outpost host) - { - _host = host; - - Location spawnLoc = pos; - Skeleton skel = pos.getWorld().spawn(spawnLoc, Skeleton.class); - skel.teleport(spawnLoc); - skel.setHealth(20); - UtilEnt.Vegetate(skel); - UtilEnt.silence(skel, true); - - skel.getEquipment().setHelmet(new ItemStack(Material.NETHER_BRICK_ITEM, 1)); - skel.getEquipment().setItemInHand(new ItemStack(Material.IRON_PICKAXE, 1)); - - // Get in range - List inRange = UtilPlayer.getNearby(spawnLoc, 75d); - - // Disguise - DisguisePlayer disguise = new DisguisePlayer(skel, new GameProfile(Bukkit.getOfflinePlayer("Chiss").getUniqueId(), "Chiss")); - host.getClan().Clans.getDisguiseManager().disguise(disguise, inRange.toArray(new Player[inRange.size()])); - - _entity = skel; - - _moveLocations = locations; - } - - public void tick() - { - if (_path == null || _arrivedTime != -1) - { - _nextLocation = UtilMath.random.nextInt(_moveLocations.size()); - _path = calculatePath(); - _pathPos = 0; - return; - } - - if (System.currentTimeMillis() - _lastMovement >= 500) - { - if (_pathPos == _path.size() - 1) - { - _arrivedTime = 1; - } - else - { - _entity.teleport(_path.get(++_pathPos)); - _arrivedTime = -1; - } - - _lastMovement = System.currentTimeMillis(); - } - } - - private List calculatePath() - { - Location start = _entity.getLocation(); - Location end = _moveLocations.get(_nextLocation); - int range = _host._type._size * 2; - - try - { - AStar pathFinder = new AStar(start, end, range); - ArrayList route = pathFinder.iterate(); - PathingResult res = pathFinder.getPathingResult(); - - if (res == PathingResult.NO_PATH) - { - return Arrays.asList(_moveLocations.get(_nextLocation)); - } - - List list = new ArrayList<>(); - - for (Tile tile : route) - { - list.add(tile.getLocation(start)); - } - - return list; - } - catch (InvalidPathException e) - { - cleanup(); - - return null; - } - } - - private void cleanup() - { - _entity.remove(); - _host.queueForRemoval(this); - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java index 167d189b1..bb4acaff3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java @@ -4,6 +4,7 @@ import java.io.File; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -92,7 +93,7 @@ public class SafeLog extends MiniPlugin } } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerQuit(PlayerQuitEvent event) { event.setQuitMessage(F.sys("Quit", event.getPlayer().getName())); @@ -100,9 +101,11 @@ public class SafeLog extends MiniPlugin onPlayerQuit(event.getPlayer()); } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onPlayerKicked(PlayerKickEvent event) { + if (event.isCancelled()) return; + event.setLeaveMessage(F.sys("Quit", event.getPlayer().getName())); onPlayerQuit(event.getPlayer()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java index ed6cc8809..f081d1450 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java @@ -72,15 +72,10 @@ public class NPCManager extends MiniPlugin { if (!hasLogoutNpc(player)) { - runSyncLater(() -> { - if (!player.isOnline()) - { - CombatLogNPC npc = new CombatLogNPC(player, _clansManager.getDisguiseManager(), _hologramManager, player.getGameMode().equals(GameMode.CREATIVE), _clansManager.UserDataDir); - npc.spawn(); - _logoutNpcs.add(npc); - log(String.format("Spawned combat log NPC for %s!", player.getName())); - } - }, 10L); + CombatLogNPC npc = new CombatLogNPC(player, _clansManager.getDisguiseManager(), _hologramManager, player.getGameMode().equals(GameMode.CREATIVE), _clansManager.UserDataDir); + npc.spawn(); + _logoutNpcs.add(npc); + log(String.format("Spawned combat log NPC for %s!", player.getName())); } } From c524247777e0c8f3203134707d85c20ad9c6b0ae Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 22 Jan 2016 15:27:10 +0000 Subject: [PATCH 021/122] supplies command for sieges --- .../src/mineplex/game/clans/clans/siege/SiegeManager.java | 3 +++ .../game/clans/clans/siege/outpost/CommandSiegeSupplies.java | 2 +- .../game/clans/clans/siege/outpost/OutpostManager.java | 2 -- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 8fbc15a52..a30fa5073 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.cannon.Cannon; +import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.outpost.OutpostManager; public class SiegeManager extends MiniPlugin @@ -27,6 +28,8 @@ public class SiegeManager extends MiniPlugin _clans = clans; _outpostManager = new OutpostManager(clans, this); + + addCommand(new CommandSiegeSupplies(_outpostManager)); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java index 6a53b151e..b2bfedefd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java @@ -13,7 +13,7 @@ public class CommandSiegeSupplies extends CommandBase { public CommandSiegeSupplies(OutpostManager plugin) { - super(plugin, Rank.CMOD, "siegesupplies"); + super(plugin, Rank.MODERATOR, "siege"); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 388a204f2..cdcf11c3f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -47,8 +47,6 @@ public class OutpostManager extends MiniPlugin _clansManager = clansManager; _removalQueue = new ArrayList<>(); - - addCommand(new CommandSiegeSupplies(this)); } @EventHandler(priority = EventPriority.LOWEST) From 090b6e496a02f37365ea747d86da1dc3f9df7f91 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 22 Jan 2016 15:27:44 +0000 Subject: [PATCH 022/122] sapling stuff messed up oops --- .../src/mineplex/game/clans/gameplay/Gameplay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index ce8742950..797ec5e35 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -447,7 +447,7 @@ public class Gameplay extends MiniPlugin @EventHandler(priority = EventPriority.LOWEST) public void disableSaplings(BlockPlaceEvent event) { - if (event.getBlockReplacedState().getType().equals(Material.SAPLING)) + if (!event.getBlockReplacedState().getType().equals(Material.SAPLING)) { return; } From 24011c4af4dba93ce1bdc56807f3bfccd376e147 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 23 Jan 2016 12:46:52 +0000 Subject: [PATCH 023/122] cannons work --- .../core/common/util/NautArrayList.java | 6 + .../mineplex/core/common/util/UtilAlg.java | 29 ++ .../mineplex/core/common/util/UtilMath.java | 10 + .../game/clans/clans/siege/cannon/Cannon.java | 350 ++++++++++++++++-- .../clans/clans/siege/outpost/Outpost.java | 2 +- 5 files changed, 355 insertions(+), 42 deletions(-) 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 29235ec86..9f00dace4 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 @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import java.util.function.Consumer; public class NautArrayList { @@ -129,4 +130,9 @@ public class NautArrayList { return _wrappedArrayList.toArray(); } + + public void forEach(Consumer consumer) + { + _wrappedArrayList.forEach(consumer); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index 40f1147c9..d069a9e47 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -515,4 +515,33 @@ public class UtilAlg { return new AxisAlignedBB(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ()); } + + public static Location offset(Location location, double strength, float yaw, boolean reverse) + { + double x = location.getX(); + double z = location.getZ(); + + double rad = Math.toRadians(yaw); + + x = reverse ? (x + strength * Math.sin(rad)) : (x - strength * Math.sin(rad)); + z = reverse ? (z - strength * Math.cos(rad)) : (z + strength * Math.cos(rad)); + + return new Location(location.getWorld(), x, location.getY(), z); + } + + public static Location offset(Location location, double strength, float yaw, float pitch, boolean reverse) + { + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + + double yawAngle = Math.toRadians(yaw); + double pitchAngle = Math.toRadians(pitch); + + x = reverse ? (x + strength * Math.sin(yawAngle)) : (x - strength * Math.sin(yawAngle)); + y = reverse ? (y + strength * Math.sin(pitchAngle)) : (y - strength * Math.sin(pitchAngle)); + z = reverse ? (z - strength * Math.cos(yawAngle)) : (z + strength * Math.cos(yawAngle)); + + return new Location(location.getWorld(), x, y, z); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 5e2324704..79c06da6a 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -152,4 +152,14 @@ public class UtilMath { return list.isEmpty() ? null : list.get(0); } + + public static T getLast(NautArrayList list) + { + return list.isEmpty() ? null : list.get(list.size() - 1); + } + + public static T getFirst(NautArrayList list) + { + return list.isEmpty() ? null : list.get(0); + } } 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 173986292..29b78dc38 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 @@ -1,29 +1,53 @@ package mineplex.game.clans.clans.siege.cannon; -import java.util.LinkedList; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; +import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.BlockIterator; import org.bukkit.util.EulerAngle; +import org.bukkit.util.Vector; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.NautArrayList; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; 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; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -32,44 +56,50 @@ public class Cannon implements Listener { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + public static final int MAX_SULPHUR = 2; + + public static final int TNT_SLOT = 4; + public static final List SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); + public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); + + private long _lastFired = -1; + private Location _location; private CannonState _state; - private Player _rider; // Entity Information - private ArmorStand _armorStand; + private NautArrayList _entities; - private List _fillers; + private TNTPrimed _projectile; + + private Location _backLoc; + + private Inventory _inventory; public Cannon(Location location) { _location = location; _state = CannonState.UNLOADED; - _fillers = new LinkedList<>(); + _entities = new NautArrayList<>(); + + _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Cannon"); updateEntities(); } public void cleanup() { - if (_armorStand != null) _armorStand.remove(); - - _fillers.forEach(Entity::remove); + _entities.forEach(Entity::remove); HandlerList.unregisterAll(this); } private void updateEntities() { - if (_armorStand == null) - { - _armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); - } - - if (_fillers.isEmpty()) + if (_entities.isEmpty()) { Slime slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class); @@ -79,9 +109,7 @@ public class Cannon implements Listener slime.setSize(-1); slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - _armorStand.setPassenger(slime); - - _fillers.add(slime); + _entities.add(slime); slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class); @@ -91,18 +119,33 @@ public class Cannon implements Listener slime.setSize(-1); slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - UtilMath.getLast(_fillers).setPassenger(slime); + UtilMath.getLast(_entities).setPassenger(slime); - _fillers.add(slime); + _entities.add(slime); + + ArmorStand armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); + + UtilEnt.setFakeHead(armorStand, true); + armorStand.teleport(getArmorStandLocation()); + armorStand.setVisible(false); + armorStand.setGravity(false); + armorStand.setHelmet(_state.toItemStack()); + + armorStand.setPassenger(UtilMath.getFirst(_entities)); + + _entities.add(0, armorStand); + } + else + { + getArmorStand().setHelmet(_state.toItemStack()); } - - UtilEnt.setFakeHead(_armorStand, true); - _armorStand.teleport(getArmorStandLocation()); - _armorStand.setVisible(false); - _armorStand.setGravity(false); - _armorStand.setHelmet(_state.toItemStack()); } + private CraftArmorStand getArmorStand() + { + return (CraftArmorStand) UtilMath.getFirst(_entities); + } + private Location getArmorStandLocation() { return _location.clone().add(.5, .15, .5); @@ -114,28 +157,239 @@ public class Cannon implements Listener updateEntities(); } - public void load() + public void updateCannon() { - setState(CannonState.LOADED); + long timeSinceLast = System.currentTimeMillis() - _lastFired; + + if (timeSinceLast < 5000) + { + if (timeSinceLast <= 1500) + { + getArmorStand().teleport(getArmorStand().getLocation().clone().add(UtilAlg.getTrajectory2d(getArmorStandLocation(), _backLoc).multiply(((double) timeSinceLast) / 1500.d))); + } + else + { + getArmorStand().teleport(getArmorStand().getLocation().clone().add(UtilAlg.getTrajectory2d(_backLoc, getArmorStandLocation()).multiply(((double) timeSinceLast) / 3500.d))); + } + } } public void fire() { - setState(CannonState.UNLOADED); + TNTPrimed tnt = _location.getWorld().spawn(_location, TNTPrimed.class); + + _projectile = tnt; + + Vector velocity = UtilAlg.getTrajectory( + getArmorStand().getLocation(), + UtilAlg.offset( + getArmorStand().getLocation(), + 2., + (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false)) + .setY(1 + ((((double) getPower() - 1.d)) / 2.d)) + .multiply(((double) getPower()) / 2.d); + + tnt.setVelocity(velocity); + + _inventory.setItem(TNT_SLOT, UtilInv.decrement(_inventory.getItem(TNT_SLOT))); + SULPHUR_SLOTS.forEach(_inventory::clear); + + Iterator itr = new BlockIterator(new Location(getArmorStand().getLocation().getWorld(), getArmorStand().getLocation().getX(), getArmorStand().getLocation().getY(), getArmorStand().getLocation().getZ(), getArmorStand().getLocation().getYaw() + 180, getArmorStand().getLocation().getPitch()), 0, 1); + while (itr.hasNext()) + { + Block block = itr.next(); + + _backLoc = block.getLocation(); + } + + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, getArmorStandLocation(), new Vector(0, 0, 0), 1.f, 2, ViewDist.MAX); + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.EXPLODE, 1.f, 1.f)); + + _lastFired = System.currentTimeMillis(); + } + + @EventHandler + public void onTntExplode(EntityExplodeEvent event) + { + // stop the tnt from exploding naturally + if (event.getEntity().equals(_projectile)) + { + event.setCancelled(true); + } + } + + public void updateProjectile() + { + if (_projectile != null && _projectile.getTicksLived() >= 40) + { + if (UtilBlock.getInBoundingBox(_projectile.getLocation().subtract(.5, .5, .5), _projectile.getLocation().add(.5, .5, .5)) + .stream() + .filter(block -> !UtilItem.isBoundless(block.getType())) + .iterator().hasNext()) + { + //Do Explosion; + _projectile.remove(); + _projectile = null; + + Bukkit.broadcastMessage("boom"); + + } + } + } + + private void attemptFire() + { + if (canBeFired()) + { + fire(); + } + else + { + UtilPlayer.message(_rider, F.main("Clans", "Cannon is not correctly loaded.")); + _rider.playSound(_rider.getLocation(), Sound.CLICK, 1.f, 1.f); + } + } + + private void handleOpenInv(Player player) + { + if (!player.equals(_rider)) + { + return; + } + + if (_inventory == null) + { + cleanup(); + return; + } + + _rider.openInventory(_inventory); + } + + private int getPower() + { + int power = 0; + + for (int slot : SULPHUR_SLOTS) + { + if (_inventory.getItem(slot) != null) + { + power += _inventory.getItem(slot).getAmount(); + } + } + + return power / 4; + } + + private int getTnt() + { + return _inventory.getItem(TNT_SLOT) != null ? _inventory.getItem(TNT_SLOT).getAmount() : 0; + } + + private boolean canBeFired() + { + return getTnt() > 0 && getPower() > 0; + } + + @EventHandler + public void updateState(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + CannonState newState = _inventory.getItem(TNT_SLOT) != null ? CannonState.LOADED : CannonState.UNLOADED; + + if (_state != newState) + { + setState(newState); + } + + checkInv(); + + updateProjectile(); + + updateCannon(); + } + + public void checkInv() + { + for (int slot = 0; slot < 9; slot++) + { + ItemStack item = _inventory.getItem(slot); + + if (item == null) + { + continue; + } + + if (slot == TNT_SLOT) + { + if (item.getType() != Material.TNT) + { + _rider.getInventory().addItem(item); + _inventory.setItem(slot, null); + } + } + else if (SULPHUR_SLOTS.contains(slot)) + { + if (item.getType() != Material.SULPHUR) + { + _rider.getInventory().addItem(item); + _inventory.setItem(slot, null); + } + else + { + if (item.getAmount() > MAX_SULPHUR) + { + _rider.getInventory().addItem(new ItemStack(Material.SULPHUR, item.getAmount() - MAX_SULPHUR)); + _inventory.setItem(slot, new ItemStack(Material.SULPHUR, MAX_SULPHUR)); + } + } + } + else if (EMPTY_SLOTS.contains(slot)) // also classes as just an 'else{}' + { + _rider.getInventory().addItem(item); + _inventory.setItem(slot, null); + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onDmg(EntityDamageByEntityEvent event) + { + if (!event.getDamager().equals(_rider)) + { + return; + } + + if (!_entities.contains(event.getEntity())) + { + return; + } + + attemptFire(); } @EventHandler public void onInteract(PlayerInteractAtEntityEvent event) { - if (_fillers.contains(event.getRightClicked())) + if (_entities.contains(event.getRightClicked())) { - Entity passenger = UtilMath.getLast(_fillers); + handleOpenInv(event.getPlayer()); + + Entity passenger = UtilMath.getLast(_entities); if (passenger == null) { - UtilMath.getLast(_fillers).setPassenger(event.getPlayer()); + UtilMath.getLast(_entities).setPassenger(event.getPlayer()); _rider = event.getPlayer(); } + else + { + handleOpenInv(event.getPlayer()); + } event.setCancelled(true); } @@ -144,16 +398,20 @@ public class Cannon implements Listener @EventHandler public void onInteract(PlayerInteractEntityEvent event) { - if (_fillers.contains(event.getRightClicked())) + if (_entities.contains(event.getRightClicked())) { - Entity passenger = UtilMath.getLast(_fillers).getPassenger(); + Entity passenger = UtilMath.getLast(_entities).getPassenger(); if (passenger == null) { - UtilMath.getLast(_fillers).setPassenger(event.getPlayer()); + UtilMath.getLast(_entities).setPassenger(event.getPlayer()); _rider = event.getPlayer(); } - + else + { + handleOpenInv(event.getPlayer()); + } + event.setCancelled(true); } } @@ -161,16 +419,20 @@ public class Cannon implements Listener @EventHandler public void onInteract(PlayerArmorStandManipulateEvent event) { - if (_fillers.contains(event.getRightClicked())) + if (_entities.contains(event.getRightClicked())) { - Entity passenger = UtilMath.getLast(_fillers).getPassenger(); + Entity passenger = UtilMath.getLast(_entities).getPassenger(); if (passenger == null) { - UtilMath.getLast(_fillers).setPassenger(event.getPlayer()); + UtilMath.getLast(_entities).setPassenger(event.getPlayer()); _rider = event.getPlayer(); } - + else + { + handleOpenInv(event.getPlayer()); + } + event.setCancelled(true); } } @@ -183,19 +445,25 @@ public class Cannon implements Listener return; } - if (_rider != null && !_rider.equals(UtilMath.getLast(_fillers).getPassenger())) + if (_rider != null && !_rider.equals(UtilMath.getLast(_entities).getPassenger())) { _rider = null; } if (_rider != null) { + ArmorStand _armorStand = (ArmorStand) UtilMath.getFirst(_entities); double standYaw = Math.toDegrees(_armorStand.getHeadPose().getY()) % 360; double riderYaw = _rider.getLocation().getYaw() % 360; double dif = riderYaw - standYaw; double yaw = standYaw + (dif / 20.f); + Location pos = _armorStand.getLocation(); + + pos.setYaw((float) yaw); + + _armorStand.teleport(pos); _armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); } } @@ -203,7 +471,7 @@ public class Cannon implements Listener @EventHandler public void onDamage(EntityDamageEvent event) { - if (_armorStand != null && _armorStand.equals(event.getEntity()) || _fillers.contains(event.getEntity())) + if (_entities.contains(event.getEntity())) { event.setCancelled(true); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 940aa5eec..86b83b6d9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -439,7 +439,7 @@ public class Outpost implements Listener _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).forEach(block -> _host.runSyncLater(() -> { - UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, block._loc, new Vector(0,0,0), 1f, 1, ViewDist.NORMAL); + UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, block._loc, new Vector(0,0,0), 1f, 2, ViewDist.NORMAL); _origin.getWorld().playSound(block._loc, Sound.EXPLODE, 1.0f, 1.0f); }, wait.add(4 + UtilMath.random.nextInt(4)).get()) ); From 0252436990f1afc588dab223029b53b2376b2dad Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 24 Jan 2016 20:56:47 +0000 Subject: [PATCH 024/122] cannons updates --- .../mineplex/core/common/util/UtilAlg.java | 6 +- .../mineplex/core/common/util/UtilBlock.java | 17 +++ .../mineplex/core/itemstack/ItemBuilder.java | 9 +- .../clans/ban/commands/ClansBanCommand.java | 4 +- .../game/clans/clans/siege/cannon/Cannon.java | 101 ++++++-------- .../clans/siege/cannon/CannonCrater.java | 128 ++++++++++++++++++ .../clans/clans/siege/cannon/CraterBlock.java | 30 ++++ 7 files changed, 227 insertions(+), 68 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index d069a9e47..bcb561f8e 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -516,7 +516,7 @@ public class UtilAlg return new AxisAlignedBB(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ()); } - public static Location offset(Location location, double strength, float yaw, boolean reverse) + public static Location moveForward(Location location, double strength, float yaw, boolean reverse) { double x = location.getX(); double z = location.getZ(); @@ -526,10 +526,10 @@ public class UtilAlg x = reverse ? (x + strength * Math.sin(rad)) : (x - strength * Math.sin(rad)); z = reverse ? (z - strength * Math.cos(rad)) : (z + strength * Math.cos(rad)); - return new Location(location.getWorld(), x, location.getY(), z); + return new Location(location.getWorld(), x, location.getY(), z, location.getYaw(), location.getPitch()); } - public static Location offset(Location location, double strength, float yaw, float pitch, boolean reverse) + public static Location moveForward(Location location, double strength, float yaw, float pitch, boolean reverse) { double x = location.getX(); double y = location.getY(); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index c0a7f5f3b..f4ca2b274 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -1409,4 +1409,21 @@ public class UtilBlock return itemStacks; } + + public static Location nearestFloor(Location location) + { + if (!UtilItem.isBoundless(location.getBlock().getType())) + { + return location.clone(); + } + + Location gr = location.clone(); + + while (UtilItem.isBoundless(gr.getBlock().getType()) && gr.getY() > 0) + { + gr.subtract(0, 0.5, 0); + } + + return gr.getBlock().getLocation(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java index 4f555ab3d..49d0af8e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/itemstack/ItemBuilder.java @@ -277,12 +277,9 @@ public class ItemBuilder ItemBuilder newBuilder = new ItemBuilder(_mat); newBuilder.setTitle(_title); - - for (String lore : _lore) - { - newBuilder.addLore(lore); - } - + + _lore.forEach(newBuilder::addLore); + for (Map.Entry entry : _enchants.entrySet()) { newBuilder.addEnchantment(entry.getKey(), entry.getValue()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java index 4f48508ae..1f612f4ae 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java @@ -87,8 +87,8 @@ public class ClansBanCommand extends CommandBase } else { - UtilPlayer.message(caller, C.cGold + "/cp - Bans the specified player for the specified amount of time"); - UtilPlayer.message(caller, C.cGold + "/cp - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)"); + UtilPlayer.message(caller, C.cGold + "/cb - Bans the specified player for the specified amount of time"); + UtilPlayer.message(caller, C.cGold + "/cb - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)"); } } } 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 29b78dc38..0d4b08cb5 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 @@ -1,14 +1,13 @@ package mineplex.game.clans.clans.siege.cannon; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -30,13 +29,11 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.BlockIterator; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.NautArrayList; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; @@ -49,6 +46,7 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -56,13 +54,11 @@ public class Cannon implements Listener { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); - public static final int MAX_SULPHUR = 2; + public static final int MAX_SULPHUR = 3; public static final int TNT_SLOT = 4; public static final List SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); - public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); - - private long _lastFired = -1; + public static final List EMPTY_SLOTS = Arrays.asList(0, 6, 8); private Location _location; private CannonState _state; @@ -70,20 +66,23 @@ public class Cannon implements Listener private Player _rider; // Entity Information - private NautArrayList _entities; + private List _entities; + + private List _craters; private TNTPrimed _projectile; - private Location _backLoc; - private Inventory _inventory; + private long _lastFired = -1; + public Cannon(Location location) { _location = location; _state = CannonState.UNLOADED; - _entities = new NautArrayList<>(); + _entities = new ArrayList<>(); + _craters = new ArrayList<>(); _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Cannon"); @@ -93,6 +92,10 @@ public class Cannon implements Listener public void cleanup() { _entities.forEach(Entity::remove); + _craters.forEach(CannonCrater::cleanup); + + _entities.clear(); + _craters.clear(); HandlerList.unregisterAll(this); } @@ -157,32 +160,15 @@ public class Cannon implements Listener updateEntities(); } - public void updateCannon() - { - long timeSinceLast = System.currentTimeMillis() - _lastFired; - - if (timeSinceLast < 5000) - { - if (timeSinceLast <= 1500) - { - getArmorStand().teleport(getArmorStand().getLocation().clone().add(UtilAlg.getTrajectory2d(getArmorStandLocation(), _backLoc).multiply(((double) timeSinceLast) / 1500.d))); - } - else - { - getArmorStand().teleport(getArmorStand().getLocation().clone().add(UtilAlg.getTrajectory2d(_backLoc, getArmorStandLocation()).multiply(((double) timeSinceLast) / 3500.d))); - } - } - } - public void fire() { - TNTPrimed tnt = _location.getWorld().spawn(_location, TNTPrimed.class); + TNTPrimed tnt = _location.getWorld().spawn(_location.clone().add(.5, .3, .5), TNTPrimed.class); _projectile = tnt; Vector velocity = UtilAlg.getTrajectory( getArmorStand().getLocation(), - UtilAlg.offset( + UtilAlg.moveForward( getArmorStand().getLocation(), 2., (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false)) @@ -194,15 +180,7 @@ public class Cannon implements Listener _inventory.setItem(TNT_SLOT, UtilInv.decrement(_inventory.getItem(TNT_SLOT))); SULPHUR_SLOTS.forEach(_inventory::clear); - Iterator itr = new BlockIterator(new Location(getArmorStand().getLocation().getWorld(), getArmorStand().getLocation().getX(), getArmorStand().getLocation().getY(), getArmorStand().getLocation().getZ(), getArmorStand().getLocation().getYaw() + 180, getArmorStand().getLocation().getPitch()), 0, 1); - while (itr.hasNext()) - { - Block block = itr.next(); - - _backLoc = block.getLocation(); - } - - UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, getArmorStandLocation(), new Vector(0, 0, 0), 1.f, 2, ViewDist.MAX); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, getArmorStandLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.EXPLODE, 1.f, 1.f)); _lastFired = System.currentTimeMillis(); @@ -220,19 +198,22 @@ public class Cannon implements Listener public void updateProjectile() { - if (_projectile != null && _projectile.getTicksLived() >= 40) + if (_projectile != null) { - if (UtilBlock.getInBoundingBox(_projectile.getLocation().subtract(.5, .5, .5), _projectile.getLocation().add(.5, .5, .5)) - .stream() - .filter(block -> !UtilItem.isBoundless(block.getType())) - .iterator().hasNext()) + UtilParticle.PlayParticleToAll(ParticleType.SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); + UtilParticle.PlayParticleToAll(ParticleType.FLAME, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); + + if (Math.abs(_projectile.getVelocity().getX()) < 0.1 || Math.abs(_projectile.getVelocity().getZ()) < 0.1) { //Do Explosion; + + _craters.add(new CannonCrater(this, UtilBlock.nearestFloor(_projectile.getLocation()))); + + UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, _projectile.getLocation(), new Vector(0, 0, 0), .1f, 4, ViewDist.MAX); + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); + _projectile.remove(); _projectile = null; - - Bukkit.broadcastMessage("boom"); - } } } @@ -241,7 +222,10 @@ public class Cannon implements Listener { if (canBeFired()) { - fire(); + if (Recharge.Instance.use(_rider, "Fire Cannon", 10000 /* 10 seconds */, true, false)) + { + fire(); + } } else { @@ -288,7 +272,7 @@ public class Cannon implements Listener private boolean canBeFired() { - return getTnt() > 0 && getPower() > 0; + return getTnt() > 0 && getPower() > 0 && _projectile == null; } @EventHandler @@ -309,8 +293,6 @@ public class Cannon implements Listener checkInv(); updateProjectile(); - - updateCannon(); } public void checkInv() @@ -452,19 +434,24 @@ public class Cannon implements Listener if (_rider != null) { - ArmorStand _armorStand = (ArmorStand) UtilMath.getFirst(_entities); - double standYaw = Math.toDegrees(_armorStand.getHeadPose().getY()) % 360; + if (System.currentTimeMillis() - _lastFired < 5000) + { + return; + } + + ArmorStand armorStand = (ArmorStand) UtilMath.getFirst(_entities); + double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; double riderYaw = _rider.getLocation().getYaw() % 360; double dif = riderYaw - standYaw; double yaw = standYaw + (dif / 20.f); - Location pos = _armorStand.getLocation(); + Location pos = armorStand.getLocation(); pos.setYaw((float) yaw); - _armorStand.teleport(pos); - _armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); + armorStand.teleport(pos); + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java new file mode 100644 index 000000000..5f955076b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -0,0 +1,128 @@ +package mineplex.game.clans.clans.siege.cannon; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityExplodeEvent; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; + +public class CannonCrater implements Listener +{ + private static final long MAX_LIFEETIME = 100000 /* 10 minutes of lifetime for the fire particles */; + private static final double EXPL_RADIUS = 3; + + private Cannon _host; + private Location _origin; + + private long _birthTime; + + private List _blocks; + + public CannonCrater(Cannon cannon, Location origin) + { + _host = cannon; + _origin = origin; + + _birthTime = System.currentTimeMillis(); + _blocks = new ArrayList<>(); + + UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); + + createExplosion(); + + start(); + } + + @EventHandler + public void updateEffects(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + + } + + private void start() + { + + } + + private void createExplosion() + { + _blocks.add(new CraterBlock(_origin, Material.AIR)); + + HashMap blockList = new HashMap(); + int iR = (int) EXPL_RADIUS + 1; + + for (int x = -iR; x <= iR; x++) + { + for (int z = -iR; z <= iR; z++) + { + for (int y = -iR; y <= iR; y++) + { + Block curBlock = _origin.getBlock().getRelative(x, y, z); + + double offset = UtilMath.offset(_origin, curBlock.getLocation()); + + if (offset <= EXPL_RADIUS) + { + blockList.put(curBlock, offset); + } + } + } + } + + for (Entry entry : blockList.entrySet()) + { + Block block = entry.getKey(); + double distance = entry.getValue(); + + boolean air = distance <= 2 || (Math.random() > (distance) / 3.65d); + + if (block.getType() == Material.AIR) continue; + + if (air) + { + _blocks.add(new CraterBlock(block.getLocation(), Material.AIR)); + + Block above = block.getRelative(BlockFace.UP); + + while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) + { + _blocks.add(new CraterBlock(above.getLocation(), Material.AIR)); + } + } + else if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType())) + { + _blocks.add(new CraterBlock(block.getLocation(), Material.COAL_BLOCK)); + } + } + + _blocks.forEach(CraterBlock::set); + } + + protected void cleanup() + { + HandlerList.unregisterAll(this); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java new file mode 100644 index 000000000..39fa0dd7d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java @@ -0,0 +1,30 @@ +package mineplex.game.clans.clans.siege.cannon; + +import org.bukkit.Location; +import org.bukkit.Material; + +public class CraterBlock +{ + public Material Type; + public byte Data; + + public Location Location; + + public CraterBlock(Location location, Material type, byte data) + { + Location = location; + Type = type; + Data = data; + } + + public CraterBlock(Location location, Material type) + { + this(location, type, (byte) 0); + } + + public void set() + { + Location.getBlock().setType(Type); + Location.getBlock().setData(Data); + } +} From c43c09fd3caa6cb4bbc76e31c249a83e1296672c Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 24 Jan 2016 21:45:46 +0000 Subject: [PATCH 025/122] the cannons shouldn't explode instantly! also added fire effects to craters + clan tips when hopping on a cannon --- .../mineplex/game/clans/clans/ClanTips.java | 5 +++ .../game/clans/clans/siege/cannon/Cannon.java | 32 ++++++++++++--- .../clans/siege/cannon/CannonCrater.java | 32 ++++++++++++--- .../clans/siege/cannon/CraterEffect.java | 40 +++++++++++++++++++ 4 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java 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 c4e4f8f87..4cf85117f 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 @@ -219,6 +219,11 @@ public class ClanTips extends MiniPlugin C.cDAqua + "Clan Home", C.cAqua + "Your Clan Home is a bed in your Territory which you can teleport to from the Spawn Islands. However, you are unable to teleport to your Clan Home if the bed is broken, blocks have been placed above the bed, or enemies are in your Territory." }), + 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!!!!" + }), ; // this is only LinkedList because UtilPlayer.message wants it 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 0d4b08cb5..d5c6c6f36 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 @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -21,6 +20,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -38,7 +38,6 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; 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 +48,8 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClanTips.TipType; +import mineplex.game.clans.clans.ClansManager; public class Cannon implements Listener { @@ -186,6 +187,20 @@ public class Cannon implements Listener _lastFired = System.currentTimeMillis(); } + @EventHandler + public void onCloseInv(InventoryCloseEvent event) + { + if (!event.getInventory().equals(_inventory)) + { + return; + } + + if (canBeFired()) + { + + } + } + @EventHandler public void onTntExplode(EntityExplodeEvent event) { @@ -200,10 +215,11 @@ public class Cannon implements Listener { if (_projectile != null) { - UtilParticle.PlayParticleToAll(ParticleType.SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); - UtilParticle.PlayParticleToAll(ParticleType.FLAME, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); - if (Math.abs(_projectile.getVelocity().getX()) < 0.1 || Math.abs(_projectile.getVelocity().getZ()) < 0.1) + _projectile.setFuseTicks(40); + + if ((Math.abs(_projectile.getVelocity().getX()) < 0.1 || Math.abs(_projectile.getVelocity().getZ()) < 0.1) && _projectile.getTicksLived() >= 10) { //Do Explosion; @@ -367,6 +383,8 @@ public class Cannon implements Listener UtilMath.getLast(_entities).setPassenger(event.getPlayer()); _rider = event.getPlayer(); + + ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); } else { @@ -388,6 +406,8 @@ public class Cannon implements Listener UtilMath.getLast(_entities).setPassenger(event.getPlayer()); _rider = event.getPlayer(); + + ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); } else { @@ -409,6 +429,8 @@ public class Cannon implements Listener UtilMath.getLast(_entities).setPassenger(event.getPlayer()); _rider = event.getPlayer(); + + ClansManager.getInstance().ClanTips.displayTip(TipType.MOUNT_CANNON, _rider); } else { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java index 5f955076b..19b3e407d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -2,8 +2,8 @@ package mineplex.game.clans.clans.siege.cannon; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import org.bukkit.Location; @@ -13,11 +13,10 @@ import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityExplodeEvent; -import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -25,7 +24,6 @@ import mineplex.game.clans.clans.ClansManager; public class CannonCrater implements Listener { - private static final long MAX_LIFEETIME = 100000 /* 10 minutes of lifetime for the fire particles */; private static final double EXPL_RADIUS = 3; private Cannon _host; @@ -34,6 +32,7 @@ public class CannonCrater implements Listener private long _birthTime; private List _blocks; + private List _effects; public CannonCrater(Cannon cannon, Location origin) { @@ -42,6 +41,7 @@ public class CannonCrater implements Listener _birthTime = System.currentTimeMillis(); _blocks = new ArrayList<>(); + _effects = new ArrayList<>(); UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); @@ -58,7 +58,19 @@ public class CannonCrater implements Listener return; } + Iterator iterator = _effects.iterator(); + while (iterator.hasNext()) + { + CraterEffect effect = iterator.next(); + + effect.update(); + + if (effect.getLifetime() >= effect.getMaxLifetime()) + { + iterator.remove(); + } + } } private void start() @@ -110,10 +122,20 @@ public class CannonCrater implements Listener { _blocks.add(new CraterBlock(above.getLocation(), Material.AIR)); } + + if (!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && distance >= 1.5 && UtilMath.random.nextBoolean()) + { + _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); + } } - else if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType())) + else if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) { _blocks.add(new CraterBlock(block.getLocation(), Material.COAL_BLOCK)); + + if (UtilMath.random.nextBoolean()) + { + _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); + } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java new file mode 100644 index 000000000..c13dcab8a --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java @@ -0,0 +1,40 @@ +package mineplex.game.clans.clans.siege.cannon; + +import org.bukkit.Location; +import org.bukkit.util.Vector; + +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; + +public class CraterEffect +{ + private ParticleType _particle; + private Location _location; + + private long _birthTime; + private long _maxLifetime = 15000 + (UtilMath.random.nextInt(30000)); + + public CraterEffect(ParticleType particle, Location location) + { + _particle = particle; + _location = location; + } + + public void update() + { + UtilParticle.PlayParticle(_particle, _location, new Vector(0, 0, 0), .1f, 1, ViewDist.MAX); + } + + public long getLifetime() + { + return System.currentTimeMillis() - _birthTime; + } + + public long getMaxLifetime() + { + return _maxLifetime; + } + +} From 54fa1449f63633468077cee48d0ab87c6a3e183b Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 25 Jan 2016 08:40:59 +0000 Subject: [PATCH 026/122] cannon crater changes --- .../clans/siege/cannon/CannonCrater.java | 29 ++++++++++++------- .../clans/clans/siege/cannon/CraterBlock.java | 8 +++-- .../clans/siege/cannon/CraterEffect.java | 1 + 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java index 19b3e407d..ec8ccf71c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -80,7 +80,7 @@ public class CannonCrater implements Listener private void createExplosion() { - _blocks.add(new CraterBlock(_origin, Material.AIR)); + _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); HashMap blockList = new HashMap(); int iR = (int) EXPL_RADIUS + 1; @@ -114,13 +114,13 @@ public class CannonCrater implements Listener if (air) { - _blocks.add(new CraterBlock(block.getLocation(), Material.AIR)); + _blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR)); - Block above = block.getRelative(BlockFace.UP); + Block above = block; while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) { - _blocks.add(new CraterBlock(above.getLocation(), Material.AIR)); + _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); } if (!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && distance >= 1.5 && UtilMath.random.nextBoolean()) @@ -128,14 +128,21 @@ public class CannonCrater implements Listener _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); } } - else if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) + } + + _blocks.forEach(CraterBlock::set); + + for (Entry entry : blockList.entrySet()) + { + Block block = entry.getKey(); + double distance = entry.getValue(); + + if (block.getType() == Material.AIR) continue; + + if (distance > 2 && Math.random() > .65 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) { - _blocks.add(new CraterBlock(block.getLocation(), Material.COAL_BLOCK)); - - if (UtilMath.random.nextBoolean()) - { - _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); - } + _blocks.add(new CraterBlock(block.getLocation(), distance, Material.COAL_BLOCK)); + _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java index 39fa0dd7d..21f5b54b1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java @@ -7,19 +7,21 @@ public class CraterBlock { public Material Type; public byte Data; + public double DistanceToOrigin; public Location Location; - public CraterBlock(Location location, Material type, byte data) + public CraterBlock(Location location, double dist, Material type, byte data) { Location = location; + DistanceToOrigin = dist; Type = type; Data = data; } - public CraterBlock(Location location, Material type) + public CraterBlock(Location location, double dist, Material type) { - this(location, type, (byte) 0); + this(location, dist, type, (byte) 0); } public void set() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java index c13dcab8a..aa2392d77 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java @@ -25,6 +25,7 @@ public class CraterEffect public void update() { UtilParticle.PlayParticle(_particle, _location, new Vector(0, 0, 0), .1f, 1, ViewDist.MAX); + System.out.println(_particle); } public long getLifetime() From 9b88683fdc54906e7dae3cdeb3f0186a34267714 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 25 Jan 2016 17:00:38 +0000 Subject: [PATCH 027/122] fix cannon tnt exploding prematurely, added cooldown rather than using Recharge. --- .../game/clans/clans/siege/cannon/Cannon.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 d5c6c6f36..4be4e8be5 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 @@ -44,8 +44,8 @@ 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.UtilTime; import mineplex.core.itemstack.ItemBuilder; -import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanTips.TipType; @@ -55,7 +55,10 @@ public class Cannon implements Listener { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + public static final int COOLDOWN = 20 * 1000 /* 20 seconds*/; + public static final int MAX_SULPHUR = 3; + public static final int MAX_TNT = 1; public static final int TNT_SLOT = 4; public static final List SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); @@ -201,7 +204,7 @@ public class Cannon implements Listener } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onTntExplode(EntityExplodeEvent event) { // stop the tnt from exploding naturally @@ -238,14 +241,17 @@ public class Cannon implements Listener { if (canBeFired()) { - if (Recharge.Instance.use(_rider, "Fire Cannon", 10000 /* 10 seconds */, true, false)) + if (System.currentTimeMillis() - _lastFired < COOLDOWN) { - fire(); + UtilPlayer.message(_rider, F.main("Clans", "Cannon is cooling down.")); + return; } + + fire(); } else { - UtilPlayer.message(_rider, F.main("Clans", "Cannon is not correctly loaded.")); + UtilPlayer.message(_rider, F.main("Clans", "Cannon is not correctly loaded. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + ")"))); _rider.playSound(_rider.getLocation(), Sound.CLICK, 1.f, 1.f); } } From ce36cf79bf32917c30f6eddf7df9bba5e6a92f99 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 25 Jan 2016 17:01:46 +0000 Subject: [PATCH 028/122] added a tnt limit, set to 1 as it makes gameplay better --- .../mineplex/game/clans/clans/siege/cannon/Cannon.java | 8 ++++++++ 1 file changed, 8 insertions(+) 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 4be4e8be5..ec5ff5323 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 @@ -335,6 +335,14 @@ public class Cannon implements Listener _rider.getInventory().addItem(item); _inventory.setItem(slot, null); } + else + { + if (item.getAmount() > MAX_TNT) + { + _rider.getInventory().addItem(new ItemStack(Material.TNT, item.getAmount() - MAX_TNT)); + _inventory.setItem(slot, new ItemStack(Material.TNT, MAX_TNT)); + } + } } else if (SULPHUR_SLOTS.contains(slot)) { From 208df93739a584925855e635a48487c785ab9a3f Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 25 Jan 2016 17:02:02 +0000 Subject: [PATCH 029/122] fixed fire particles not showing up in craters --- .../mineplex/game/clans/clans/siege/cannon/CraterEffect.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java index aa2392d77..15dbd111c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java @@ -13,8 +13,8 @@ public class CraterEffect private ParticleType _particle; private Location _location; - private long _birthTime; - private long _maxLifetime = 15000 + (UtilMath.random.nextInt(30000)); + private final long _birthTime = System.currentTimeMillis(); + private final long _maxLifetime = 15000 + (UtilMath.random.nextInt(30000)); public CraterEffect(ParticleType particle, Location location) { @@ -25,7 +25,6 @@ public class CraterEffect public void update() { UtilParticle.PlayParticle(_particle, _location, new Vector(0, 0, 0), .1f, 1, ViewDist.MAX); - System.out.println(_particle); } public long getLifetime() From 5a5dc9925e40e161a93e8655b974969c40a5b4e7 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 25 Jan 2016 17:06:15 +0000 Subject: [PATCH 030/122] set spawning rate of charred blocks a 10% lower --- .../mineplex/game/clans/clans/siege/cannon/CannonCrater.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java index ec8ccf71c..dbcaf0b9e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -139,7 +139,7 @@ public class CannonCrater implements Listener if (block.getType() == Material.AIR) continue; - if (distance > 2 && Math.random() > .65 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) + if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) { _blocks.add(new CraterBlock(block.getLocation(), distance, Material.COAL_BLOCK)); _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); From 2b70daf8dfda52f15ae9bb172db7752a166cbaa8 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 25 Jan 2016 17:12:34 +0000 Subject: [PATCH 031/122] allowed clans mods to use /cban --- .../mineplex/game/clans/clans/ban/commands/ClansBanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java index 1f612f4ae..8442d37b2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ban/commands/ClansBanCommand.java @@ -14,7 +14,7 @@ public class ClansBanCommand extends CommandBase { public ClansBanCommand(ClansBanManager plugin) { - super(plugin, Rank.ADMIN, "cbans", "cb"); + super(plugin, Rank.CMOD, "cbans", "cb"); } @Override From 3b18b93286803e9a7202008b107bb4d5d2fbb9f9 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 09:26:51 +0000 Subject: [PATCH 032/122] fixed top right slot in cannon not counting as an empty slot. --- .../src/mineplex/game/clans/clans/siege/cannon/Cannon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ec5ff5323..d147928f5 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 @@ -62,7 +62,7 @@ public class Cannon implements Listener public static final int TNT_SLOT = 4; public static final List SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); - public static final List EMPTY_SLOTS = Arrays.asList(0, 6, 8); + public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); private Location _location; private CannonState _state; From 2445e736231eaa380195c876e01cb9328b408769 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 13:06:47 +0000 Subject: [PATCH 033/122] better cannon crater particles --- .../game/clans/clans/siege/cannon/Cannon.java | 17 +++++--- .../clans/siege/cannon/CannonCrater.java | 42 ++++++++----------- .../clans/siege/cannon/CraterEffect.java | 40 ------------------ 3 files changed, 29 insertions(+), 70 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java 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 d147928f5..65b73de5d 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 @@ -38,6 +38,7 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; 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; @@ -64,6 +65,9 @@ public class Cannon implements Listener public static final List SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); + private static final double[] VERT_POWER = { 0.5, 0.75631, 0.9382 }; + private static final double[] HORIZ_POWER = { 0.8, 1.1241, 1.34231 }; + private Location _location; private CannonState _state; @@ -170,14 +174,17 @@ public class Cannon implements Listener _projectile = tnt; + double vVel = VERT_POWER[getPower() - 1]; + double hMulti = HORIZ_POWER[getPower() - 1]; + Vector velocity = UtilAlg.getTrajectory( getArmorStand().getLocation(), UtilAlg.moveForward( getArmorStand().getLocation(), 2., (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false)) - .setY(1 + ((((double) getPower() - 1.d)) / 2.d)) - .multiply(((double) getPower()) / 2.d); + .multiply(hMulti) + .setY(vVel); tnt.setVelocity(velocity); @@ -222,7 +229,7 @@ public class Cannon implements Listener _projectile.setFuseTicks(40); - if ((Math.abs(_projectile.getVelocity().getX()) < 0.1 || Math.abs(_projectile.getVelocity().getZ()) < 0.1) && _projectile.getTicksLived() >= 10) + if ((Math.abs(_projectile.getVelocity().getX()) < 0.01 || Math.abs(_projectile.getVelocity().getZ()) < 0.01) && UtilBlock.getInRadius(_projectile.getLocation(), 2).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && _projectile.getTicksLived() >= 10) { //Do Explosion; @@ -243,7 +250,7 @@ public class Cannon implements Listener { if (System.currentTimeMillis() - _lastFired < COOLDOWN) { - UtilPlayer.message(_rider, F.main("Clans", "Cannon is cooling down.")); + UtilPlayer.message(_rider, F.main("Clans", "Cannon is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")"))); return; } @@ -251,7 +258,7 @@ public class Cannon implements Listener } else { - UtilPlayer.message(_rider, F.main("Clans", "Cannon is not correctly loaded. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + ")"))); + UtilPlayer.message(_rider, F.main("Clans", "Cannon is not correctly loaded.")); _rider.playSound(_rider.getLocation(), Sound.CLICK, 1.f, 1.f); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java index dbcaf0b9e..6826067a2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -13,10 +13,13 @@ import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.util.Vector; 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.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -32,7 +35,6 @@ public class CannonCrater implements Listener private long _birthTime; private List _blocks; - private List _effects; public CannonCrater(Cannon cannon, Location origin) { @@ -41,13 +43,10 @@ public class CannonCrater implements Listener _birthTime = System.currentTimeMillis(); _blocks = new ArrayList<>(); - _effects = new ArrayList<>(); UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); createExplosion(); - - start(); } @EventHandler @@ -58,24 +57,17 @@ public class CannonCrater implements Listener return; } - Iterator iterator = _effects.iterator(); - - while (iterator.hasNext()) - { - CraterEffect effect = iterator.next(); + _blocks.stream().filter(block -> block.Type == Material.COAL_BLOCK).forEach(block -> { + long lifetime = System.currentTimeMillis() - _birthTime; - effect.update(); + long max = 25000 - (long) ((block.DistanceToOrigin * 1000) * 3.5); - if (effect.getLifetime() >= effect.getMaxLifetime()) + if (lifetime < max) { - iterator.remove(); + UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1.1, .5), new Vector(0, 0, 0), .4f, 1, ViewDist.MAX); + UtilParticle.PlayParticleToAll(ParticleType.SMOKE, block.Location.clone().add(.5, 1.1, .5), new Vector(0, 0, 0), .4f, 1, ViewDist.MAX); } - } - } - - private void start() - { - + }); } private void createExplosion() @@ -122,11 +114,6 @@ public class CannonCrater implements Listener { _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); } - - if (!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && distance >= 1.5 && UtilMath.random.nextBoolean()) - { - _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); - } } } @@ -139,10 +126,15 @@ public class CannonCrater implements Listener if (block.getType() == Material.AIR) continue; - if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) + if ( + distance > 2 && + Math.random() > .75 && + UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && + !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && + !block.getRelative(BlockFace.UP).getType().equals(Material.COAL_BLOCK) && + !block.getRelative(BlockFace.DOWN).getType().equals(Material.COAL_BLOCK)) { _blocks.add(new CraterBlock(block.getLocation(), distance, Material.COAL_BLOCK)); - _effects.add(new CraterEffect(ParticleType.FLAME, block.getLocation().add(0, .5, 0))); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java deleted file mode 100644 index 15dbd111c..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterEffect.java +++ /dev/null @@ -1,40 +0,0 @@ -package mineplex.game.clans.clans.siege.cannon; - -import org.bukkit.Location; -import org.bukkit.util.Vector; - -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; - -public class CraterEffect -{ - private ParticleType _particle; - private Location _location; - - private final long _birthTime = System.currentTimeMillis(); - private final long _maxLifetime = 15000 + (UtilMath.random.nextInt(30000)); - - public CraterEffect(ParticleType particle, Location location) - { - _particle = particle; - _location = location; - } - - public void update() - { - UtilParticle.PlayParticle(_particle, _location, new Vector(0, 0, 0), .1f, 1, ViewDist.MAX); - } - - public long getLifetime() - { - return System.currentTimeMillis() - _birthTime; - } - - public long getMaxLifetime() - { - return _maxLifetime; - } - -} From 7c85fe62ca2814388df4563404053f1969add5ec Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 17:36:12 +0000 Subject: [PATCH 034/122] charred blocks updates --- .../game/clans/clans/siege/cannon/Cannon.java | 38 +++++++++++++++++-- .../clans/siege/cannon/CannonCrater.java | 28 ++++++++++---- 2 files changed, 55 insertions(+), 11 deletions(-) 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 65b73de5d..552047bad 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 @@ -2,6 +2,7 @@ package mineplex.game.clans.clans.siege.cannon; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import org.bukkit.Location; @@ -235,7 +236,6 @@ public class Cannon implements Listener _craters.add(new CannonCrater(this, UtilBlock.nearestFloor(_projectile.getLocation()))); - UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, _projectile.getLocation(), new Vector(0, 0, 0), .1f, 4, ViewDist.MAX); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); _projectile.remove(); @@ -244,6 +244,21 @@ public class Cannon implements Listener } } + private List circleAround(Vector origin, int points, double radius) + { + List list = new LinkedList<>(); + + double slice = 2 * Math.PI / points; + + for (int point = 0; point < points; point++) + { + double angle = slice * point; + list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle))); + } + + return list; + } + private void attemptFire() { if (canBeFired()) @@ -307,6 +322,20 @@ public class Cannon implements Listener @EventHandler public void updateState(UpdateEvent event) { +// if (event.getType() == UpdateType.FASTEST) +// { +// if (_state == CannonState.LOADED) +// { +// double yaw = getArmorStand().getHeadPose().getY() - 7.75d; +// +// Location loc = new Location(_location.getWorld(), getArmorStand().getLocation().getX() + (0.5 * Math.cos(yaw)), _location.getY() + 1.12, getArmorStand().getLocation().getZ() + (0.5 * Math.sin(yaw))); +// +// loc = UtilAlg.moveForward(loc, 0.1, (float) Math.toDegrees(yaw + 7.75), false); +// +// UtilParticle.PlayParticleToAll(ParticleType.FLAME, loc, new Vector(0, 0, 0), 0.f, 1, ViewDist.MAX); +// } +// } + if (event.getType() != UpdateType.TICK) { return; @@ -483,11 +512,12 @@ public class Cannon implements Listener } ArmorStand armorStand = (ArmorStand) UtilMath.getFirst(_entities); - double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; - double riderYaw = _rider.getLocation().getYaw() % 360; + double standYaw = Math.abs(Math.toDegrees(armorStand.getHeadPose().getY()) % 360); + double riderYaw = Math.abs(_rider.getLocation().getYaw() % 360); double dif = riderYaw - standYaw; - double yaw = standYaw + (dif / 20.f); + + double yaw = standYaw + Math.min(dif / 20.f, 5f); Location pos = armorStand.getLocation(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java index 6826067a2..db67311e5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -15,6 +15,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.util.Vector; +import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; @@ -29,6 +30,8 @@ public class CannonCrater implements Listener { private static final double EXPL_RADIUS = 3; + public static final Material CHARRED_TYPE = Material.OBSIDIAN; + private Cannon _host; private Location _origin; @@ -57,15 +60,26 @@ public class CannonCrater implements Listener return; } - _blocks.stream().filter(block -> block.Type == Material.COAL_BLOCK).forEach(block -> { + _blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> { long lifetime = System.currentTimeMillis() - _birthTime; - long max = 25000 - (long) ((block.DistanceToOrigin * 1000) * 3.5); + long max = 80000; + + if (block.Location.getBlock().getType() != CHARRED_TYPE) + { + return; + } + + // Water touching the charred blocks + if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext()) + { + return; + } if (lifetime < max) { - UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1.1, .5), new Vector(0, 0, 0), .4f, 1, ViewDist.MAX); - UtilParticle.PlayParticleToAll(ParticleType.SMOKE, block.Location.clone().add(.5, 1.1, .5), new Vector(0, 0, 0), .4f, 1, ViewDist.MAX); + UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX); + UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX); } }); } @@ -131,10 +145,10 @@ public class CannonCrater implements Listener Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && - !block.getRelative(BlockFace.UP).getType().equals(Material.COAL_BLOCK) && - !block.getRelative(BlockFace.DOWN).getType().equals(Material.COAL_BLOCK)) + !block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) && + !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) { - _blocks.add(new CraterBlock(block.getLocation(), distance, Material.COAL_BLOCK)); + _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); } } From 63f96228763ff3dec14143d1cb68f09075187e5b Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 17:51:29 +0000 Subject: [PATCH 035/122] cannon correctly loadded title + fixed rotation being all wrong --- .../game/clans/clans/siege/cannon/Cannon.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 552047bad..b7788772d 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 @@ -46,6 +46,8 @@ 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.UtilText; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; @@ -206,10 +208,17 @@ public class Cannon implements Listener return; } - if (canBeFired()) - { + ClansManager.getInstance().runSyncLater(() -> { + if (event.getPlayer().getInventory().equals(_inventory)) + { + return; + } - } + if (canBeFired()) + { + UtilTextMiddle.display("Cannon Ready", "Power Level: " + C.cGreen + UtilText.repeat("▌", getPower()) + C.cRed + UtilText.repeat("▌", 3 - getPower()), 20, 100, 20, _rider); + } + }, 3L); } @EventHandler(priority = EventPriority.HIGHEST) @@ -512,8 +521,8 @@ public class Cannon implements Listener } ArmorStand armorStand = (ArmorStand) UtilMath.getFirst(_entities); - double standYaw = Math.abs(Math.toDegrees(armorStand.getHeadPose().getY()) % 360); - double riderYaw = Math.abs(_rider.getLocation().getYaw() % 360); + double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; + double riderYaw = _rider.getLocation().getYaw() % 360; double dif = riderYaw - standYaw; From 9215d0d3ff1d6a8fe50e868cd576bca6deddcff4 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 18:40:55 +0000 Subject: [PATCH 036/122] NegativeArraySizeException fix --- .../src/mineplex/core/common/util/UtilText.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 360a418c2..92b4eb728 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -614,6 +614,11 @@ public class UtilText public static String repeat(String txt, int times) { + if (times <= 0) + { + return new String(); + } + return new String(new byte[times]).replace("\0", txt); } From 155d8bff1bb992b5a305f03129361a86e57e5685 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 26 Jan 2016 13:36:30 -0600 Subject: [PATCH 037/122] Fix cannon angles --- .../mineplex/game/clans/clans/siege/cannon/Cannon.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 b7788772d..865f7c2c4 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 @@ -523,11 +523,15 @@ public class Cannon implements Listener ArmorStand armorStand = (ArmorStand) UtilMath.getFirst(_entities); double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; double riderYaw = _rider.getLocation().getYaw() % 360; - + + // riderYaw = 350 and standYaw = 20 + // dif should be -30 and not 330 double dif = riderYaw - standYaw; - + if (dif > 180) dif -= 360; + if (dif < -180) dif += 360; + double yaw = standYaw + Math.min(dif / 20.f, 5f); - + Location pos = armorStand.getLocation(); pos.setYaw((float) yaw); From 3d7a371d1dae24a18478a9511d0f7969d7956728 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 20:18:53 +0000 Subject: [PATCH 038/122] catapults --- .../mineplex/game/clans/clans/ClanTips.java | 5 + .../game/clans/clans/siege/SiegeManager.java | 44 ++ .../clans/clans/siege/catapult/Catapult.java | 457 ++++++++++++++++++ .../siege/catapult/CatapultProjectile.java | 79 +++ .../clans/siege/catapult/CatapultState.java | 34 ++ .../siege/outpost/CommandSiegeSupplies.java | 6 +- 6 files changed, 624 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java 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 4cf85117f..eb76dfd1b 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 @@ -224,6 +224,11 @@ public class ClanTips extends MiniPlugin 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." + }), ; // this is only LinkedList because UtilPlayer.message wants it diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index a30fa5073..d705844e1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.cannon.Cannon; +import mineplex.game.clans.clans.siege.catapult.Catapult; import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.outpost.OutpostManager; @@ -45,6 +46,17 @@ public class SiegeManager extends MiniPlugin return; } } + + if (event.getItemInHand().isSimilar(Catapult.CATAPULT_ITEM)) + { + event.setCancelled(true); + + if (trySpawnCatapult(event.getPlayer(), event.getBlock().getLocation())) + { + event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); + return; + } + } } public boolean trySpawnCannon(Player player, Location location) @@ -78,4 +90,36 @@ public class SiegeManager extends MiniPlugin _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(cannon, _outpostManager.getPlugin()); } + + public boolean trySpawnCatapult(Player player, Location location) + { + if (!_clans.isInClan(player)) + { + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a catapult.")); + return false; + } + + if (_clans.getClanUtility().isClaimed(location)) + { + UtilPlayer.message(player, F.main("Clans", "A catapult must be placed in unclaimed territory.")); + return false; + } + +// if (!isInOutpostSiegeArea(location, _clans.getClan(player))) +// { +// UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); +// return false; +// } + + spawnCannon(player, location); + + return true; + } + + public void spawnCatapult(Player player, Location location) + { + Catapult catapult = new Catapult(location, _clans.getClan(player)); + + _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(catapult, _outpostManager.getPlugin()); + } } 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 new file mode 100644 index 000000000..0d0822953 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java @@ -0,0 +1,457 @@ +package mineplex.game.clans.clans.siege.catapult; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.EulerAngle; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +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; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; + +public class Catapult implements Listener +{ + public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); + + public static final int COOLDOWN = 10 * 1000 /* 20 seconds*/; + + public static final int MAX_CHARGES = 3; + public static final int MAX_COBBLE = 1; + + public static final int COBBLE_SLOT = 4; + public static final List CHARGE_SLOTS = Arrays.asList(1, 3, 5, 7); + public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); + + private static final double[] VERT_POWER = { 0.9, 1.25631, 1.5382 }; + private static final double[] HORIZ_POWER = { 0.8, 1.1241, 1.34231 }; + + private Location _location; + private CatapultState _state; + + private float _nextYaw; + + // Entity Information + private List _entities; + + private CatapultProjectile _projectile; + + private Inventory _inventory; + + private long _lastFired = -1; + + private ClanInfo _clan; + + public Catapult(Location location, ClanInfo clan) + { + _location = location; + _state = CatapultState.UNLOADED; + + _entities = new ArrayList<>(); + + _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Catapult"); + + _clan = clan; + + updateEntities(); + } + + public void cleanup() + { + _entities.forEach(Entity::remove); + + _entities.clear(); + + HandlerList.unregisterAll(this); + } + + private void updateEntities() + { + if (_entities.isEmpty()) + { + ArmorStand armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); + + UtilEnt.setFakeHead(armorStand, true); + armorStand.teleport(getArmorStandLocation()); + armorStand.setVisible(false); + armorStand.setGravity(false); + armorStand.setHelmet(_state.toItemStack()); + + _entities.add(armorStand); + } + else + { + getArmorStand().setHelmet(_state.toItemStack()); + } + } + + private CraftArmorStand getArmorStand() + { + return (CraftArmorStand) UtilMath.getFirst(_entities); + } + + private Location getArmorStandLocation() + { + return _location.clone().add(.5, -1.1, .5); + } + + private void setState(CatapultState state) + { + _state = state; + updateEntities(); + } + + public void fire() + { + CatapultProjectile projectile = new CatapultProjectile(_location.clone().add(.5, .3, .5), Material.COBBLESTONE); + + _projectile = projectile; + + double vVel = VERT_POWER[getPower() - 1]; + double hMulti = HORIZ_POWER[getPower() - 1]; + + Vector velocity = UtilAlg.getTrajectory( + getArmorStand().getLocation(), + UtilAlg.moveForward( + getArmorStand().getLocation(), + 2., + (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false)) + .multiply(hMulti) + .setY(vVel); + + projectile.setVelocity(velocity); + + _inventory.setItem(COBBLE_SLOT, UtilInv.decrement(_inventory.getItem(COBBLE_SLOT))); + CHARGE_SLOTS.forEach(_inventory::clear); + + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.BAT_TAKEOFF, 1.f, 1.f)); + + _lastFired = System.currentTimeMillis(); + } + + @EventHandler + public void onCloseInv(InventoryCloseEvent event) + { + if (!event.getInventory().equals(_inventory)) + { + return; + } + + ClansManager.getInstance().runSyncLater(() -> { + if (event.getPlayer().getInventory().equals(_inventory)) + { + return; + } + + if (canBeFired()) + { + UtilTextMiddle.display("Catapult Ready", "Power Level: " + C.cGreen + UtilText.repeat("▌", getPower()) + C.cRed + UtilText.repeat("▌", MAX_CHARGES - getPower()), 20, 100, 20, (Player) event.getPlayer()); + } + }, 3L); + } + + public void updateProjectile() + { + if (_projectile != null) + { + UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); + + if ((Math.abs(_projectile.getVelocity().getX()) < 0.01 || Math.abs(_projectile.getVelocity().getZ()) < 0.01) && UtilBlock.getInRadius(_projectile.getLocation(), 2).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && _projectile.getTicksLived() >= 10) + { + //Do Explosion; + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); + + _projectile.remove(); + _projectile = null; + } + } + } + + private void attemptFire(Player human) + { + if (!_clan.isMember(human)) + { + UtilPlayer.message(human, F.main("Clans", "This catapult is not owned by your Clan.")); + return; + } + + if (canBeFired()) + { + if (System.currentTimeMillis() - _lastFired < COOLDOWN) + { + UtilPlayer.message(human, F.main("Clans", "Catapult is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")"))); + return; + } + + fire(); + } + else + { + UtilPlayer.message(human, F.main("Clans", "Catapult is not correctly loaded.")); + human.playSound(human.getLocation(), Sound.CLICK, 1.f, 1.f); + } + } + + private void handleOpenInv(Player player) + { + if (_inventory == null) + { + cleanup(); + return; + } + + if (!_clan.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This catapult is not owned by your Clan.")); + return; + } + + if (!_inventory.getViewers().isEmpty()) + { + UtilPlayer.message(player, F.main("Clans", "Someone is already looking in this catapult.")); + return; + } + + player.openInventory(_inventory); + } + + private int getPower() + { + int power = 0; + + for (int slot : CHARGE_SLOTS) + { + if (_inventory.getItem(slot) != null) + { + power += _inventory.getItem(slot).getAmount(); + } + } + + return power / 4; + } + + private int getCobblestone() + { + return _inventory.getItem(COBBLE_SLOT) != null ? _inventory.getItem(COBBLE_SLOT).getAmount() : 0; + } + + private boolean canBeFired() + { + return getCobblestone() > 0 && getPower() > 0 && _projectile == null; + } + + @EventHandler + public void updateState(UpdateEvent event) + { +// if (event.getType() == UpdateType.FASTEST) +// { +// if (_state == CannonState.LOADED) +// { +// double yaw = getArmorStand().getHeadPose().getY() - 7.75d; +// +// Location loc = new Location(_location.getWorld(), getArmorStand().getLocation().getX() + (0.5 * Math.cos(yaw)), _location.getY() + 1.12, getArmorStand().getLocation().getZ() + (0.5 * Math.sin(yaw))); +// +// loc = UtilAlg.moveForward(loc, 0.1, (float) Math.toDegrees(yaw + 7.75), false); +// +// UtilParticle.PlayParticleToAll(ParticleType.FLAME, loc, new Vector(0, 0, 0), 0.f, 1, ViewDist.MAX); +// } +// } + + if (event.getType() != UpdateType.TICK) + { + return; + } + + CatapultState newState = _inventory.getItem(COBBLE_SLOT) != null ? CatapultState.LOADED : CatapultState.UNLOADED; + + if (_state != newState) + { + setState(newState); + } + + if (!_inventory.getViewers().isEmpty()) + { + checkInv((Player) _inventory.getViewers().get(0)); + } + + updateProjectile(); + } + + public void checkInv(Player human) + { + for (int slot = 0; slot < 9; slot++) + { + ItemStack item = _inventory.getItem(slot); + + if (item == null) + { + continue; + } + + if (slot == COBBLE_SLOT) + { + if (item.getType() != Material.COBBLESTONE) + { + human.getInventory().addItem(item); + _inventory.setItem(slot, null); + } + else + { + if (item.getAmount() > MAX_CHARGES) + { + human.getInventory().addItem(new ItemStack(Material.COBBLESTONE, item.getAmount() - MAX_COBBLE)); + _inventory.setItem(slot, new ItemStack(Material.COBBLESTONE, MAX_COBBLE)); + } + } + } + else if (CHARGE_SLOTS.contains(slot)) + { + if (item.getType() != Material.FIREWORK_CHARGE) + { + human.getInventory().addItem(item); + _inventory.setItem(slot, null); + } + else + { + if (item.getAmount() > MAX_CHARGES) + { + human.getInventory().addItem(new ItemStack(Material.FIREWORK_CHARGE, item.getAmount() - MAX_CHARGES)); + _inventory.setItem(slot, new ItemStack(Material.FIREWORK_CHARGE, MAX_CHARGES)); + } + } + } + else if (EMPTY_SLOTS.contains(slot)) // also classes as just an 'else{}' + { + human.getInventory().addItem(item); + _inventory.setItem(slot, null); + } + } + } + + + @EventHandler + public void onInteract(PlayerInteractAtEntityEvent event) + { + if (_entities.contains(event.getRightClicked())) + { + handleOpenInv(event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void onInteract(PlayerInteractEntityEvent event) + { + if (_entities.contains(event.getRightClicked())) + { + handleOpenInv(event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void onInteract(PlayerArmorStandManipulateEvent event) + { + if (_entities.contains(event.getRightClicked())) + { + handleOpenInv(event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + ArmorStand armorStand = getArmorStand(); + double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; + double riderYaw = _nextYaw; + + // riderYaw = 350 and standYaw = 20 + // dif should be -30 and not 330 + double dif = riderYaw - standYaw; + if (dif > 180) dif -= 360; + if (dif < -180) dif += 360; + + double yaw = standYaw + Math.min(dif / 20.f, 5f); + + Location pos = armorStand.getLocation(); + + pos.setYaw((float) yaw); + + armorStand.teleport(pos); + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); + } + + @EventHandler + public void onDamage(EntityDamageEvent event) + { + if (_entities.contains(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onDmg(EntityDamageByEntityEvent event) + { + if (!(event.getDamager() instanceof Player)) + { + return; + } + + if (!_entities.contains(event.getEntity())) + { + return; + } + + if (canBeFired()) + attemptFire((Player) event.getDamager()); + else + _nextYaw = ((Player) event.getDamager()).getLocation().getYaw(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java new file mode 100644 index 000000000..163cb007a --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java @@ -0,0 +1,79 @@ +package mineplex.game.clans.clans.siege.catapult; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.EulerAngle; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; + +public class CatapultProjectile implements Listener +{ + private ArmorStand _parent; + + public CatapultProjectile(Location location, Material material) + { + _parent = location.getWorld().spawn(location, ArmorStand.class); + + UtilEnt.setFakeHead(_parent, true); + _parent.teleport(location); + _parent.setVisible(false); + _parent.setGravity(false); + _parent.setHelmet(new ItemStack(material)); + + UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + if (_parent == null || _parent.isDead()) + { + return; + } + + _parent.setHeadPose(new EulerAngle(_parent.getHeadPose().getX() + 2.75, _parent.getHeadPose().getY(), _parent.getHeadPose().getZ())); + } + + public void remove() + { + HandlerList.unregisterAll(this); + _parent.remove(); + _parent = null; + } + + public Location getLocation() + { + return _parent.getLocation(); + } + + public Vector getVelocity() + { + return _parent.getVelocity(); + } + + public int getTicksLived() + { + return _parent.getTicksLived(); + } + + public void setVelocity(Vector velocity) + { + _parent.setVelocity(velocity); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java new file mode 100644 index 000000000..50e9c8fdc --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java @@ -0,0 +1,34 @@ +package mineplex.game.clans.clans.siege.catapult; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public enum CatapultState +{ + UNLOADED(Material.PACKED_ICE, (byte) 0 /* packed ice */), + LOADED(Material.LAPIS_BLOCK, (byte) 0 /* lapis block */); + + private Material _material; + private byte _data; + + CatapultState(Material material, byte data) + { + _material = material; + _data = data; + } + + public byte getData() + { + return _data; + } + + public Material getMaterial() + { + return _material; + } + + public ItemStack toItemStack() + { + return new ItemStack(_material, 1, (short) 0, _data); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java index b2bfedefd..86ed92e0d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java @@ -8,6 +8,7 @@ import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.siege.cannon.Cannon; +import mineplex.game.clans.clans.siege.catapult.Catapult; public class CommandSiegeSupplies extends CommandBase { @@ -21,13 +22,16 @@ public class CommandSiegeSupplies extends CommandBase { ItemStack outpost = new ItemStack(Outpost.OUTPOST_ITEM); ItemStack cannons = new ItemStack(Cannon.CANNON_ITEM); + ItemStack catapults = new ItemStack(Catapult.CATAPULT_ITEM); outpost.setAmount(64); cannons.setAmount(64); + catapults.setAmount(64); caller.getInventory().addItem(outpost); caller.getInventory().addItem(cannons); - + caller.getInventory().addItem(catapults); + UtilPlayer.message(caller, F.main("Clans", "Received supplies for a siege.")); } } From 7f7e73a101eefd2a5906f4d8725b2dbfba6d3f3e Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 26 Jan 2016 21:10:58 +0000 Subject: [PATCH 039/122] more catapults! --- .../mineplex/core/common/util/UtilMath.java | 18 ++++++++++++ .../src/mineplex/game/clans/Clans.java | 2 -- .../game/clans/clans/siege/SiegeManager.java | 2 +- .../clans/clans/siege/catapult/Catapult.java | 29 ++++++++++++++----- .../clans/siege/catapult/CatapultState.java | 3 +- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 79c06da6a..c09b376eb 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -162,4 +162,22 @@ public class UtilMath { return list.isEmpty() ? null : list.get(0); } + + public static N closest(List values, N value) + { + int closestIndex = -1; + + int index = 0; + for (N number : values) + { + if (closestIndex == -1 || (Math.abs(value.doubleValue() - number.doubleValue()) < Math.abs(value.doubleValue() - values.get(closestIndex).doubleValue()))) + { + closestIndex = index; + } + + index++; + } + + return values.get(closestIndex); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 69a6891d4..a4639338f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -152,8 +152,6 @@ public class Clans extends JavaPlugin new Updater(this); MinecraftServer.getServer().getPropertyManager().setProperty("debug", true); - - getServer().setWhitelist(false); // TODO: remove } public static String prettifyName(Material material) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index d705844e1..6bfd76e34 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -111,7 +111,7 @@ public class SiegeManager extends MiniPlugin // return false; // } - spawnCannon(player, location); + spawnCatapult(player, location); return true; } 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 0d0822953..c7626cad4 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 @@ -8,6 +8,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftChicken; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -17,7 +18,6 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; @@ -66,6 +66,8 @@ public class Catapult implements Listener private static final double[] VERT_POWER = { 0.9, 1.25631, 1.5382 }; private static final double[] HORIZ_POWER = { 0.8, 1.1241, 1.34231 }; + private List _rotationPoints; + private Location _location; private CatapultState _state; @@ -87,8 +89,14 @@ public class Catapult implements Listener _location = location; _state = CatapultState.UNLOADED; + _rotationPoints = new ArrayList<>(); _entities = new ArrayList<>(); + for (int i = 0; i < 8; i++) + { + _rotationPoints.add((360.f / 8.f) * i); + } + _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Catapult"); _clan = clan; @@ -117,6 +125,8 @@ public class Catapult implements Listener armorStand.setGravity(false); armorStand.setHelmet(_state.toItemStack()); + ((CraftChicken) armorStand).getHandle().setSize(1.87F, 1.87F); + _entities.add(armorStand); } else @@ -132,7 +142,7 @@ public class Catapult implements Listener private Location getArmorStandLocation() { - return _location.clone().add(.5, -1.1, .5); + return _location.clone().add(.5, -.95, .5); } private void setState(CatapultState state) @@ -304,6 +314,11 @@ public class Catapult implements Listener CatapultState newState = _inventory.getItem(COBBLE_SLOT) != null ? CatapultState.LOADED : CatapultState.UNLOADED; + if ((System.currentTimeMillis() - _lastFired) <= 3000) + { + newState = CatapultState.FIRED; + } + if (_state != newState) { setState(newState); @@ -346,7 +361,7 @@ public class Catapult implements Listener } else if (CHARGE_SLOTS.contains(slot)) { - if (item.getType() != Material.FIREWORK_CHARGE) + if (item.getType() != Material.FIREBALL) { human.getInventory().addItem(item); _inventory.setItem(slot, null); @@ -355,8 +370,8 @@ public class Catapult implements Listener { if (item.getAmount() > MAX_CHARGES) { - human.getInventory().addItem(new ItemStack(Material.FIREWORK_CHARGE, item.getAmount() - MAX_CHARGES)); - _inventory.setItem(slot, new ItemStack(Material.FIREWORK_CHARGE, MAX_CHARGES)); + human.getInventory().addItem(new ItemStack(Material.FIREBALL, item.getAmount() - MAX_CHARGES)); + _inventory.setItem(slot, new ItemStack(Material.FIREBALL, MAX_CHARGES)); } } } @@ -409,7 +424,7 @@ public class Catapult implements Listener ArmorStand armorStand = getArmorStand(); double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; - double riderYaw = _nextYaw; + double riderYaw = _nextYaw % 360; // riderYaw = 350 and standYaw = 20 // dif should be -30 and not 330 @@ -421,7 +436,7 @@ public class Catapult implements Listener Location pos = armorStand.getLocation(); - pos.setYaw((float) yaw); + pos.setYaw(UtilMath.closest(_rotationPoints, (float) yaw)); armorStand.teleport(pos); armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java index 50e9c8fdc..1b940995f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java @@ -6,7 +6,8 @@ import org.bukkit.inventory.ItemStack; public enum CatapultState { UNLOADED(Material.PACKED_ICE, (byte) 0 /* packed ice */), - LOADED(Material.LAPIS_BLOCK, (byte) 0 /* lapis block */); + LOADED(Material.ENDER_PORTAL_FRAME, (byte) 0 /* lapis block */), + FIRED(Material.LAPIS_BLOCK, (byte) 0); private Material _material; private byte _data; From 682a243c31c0fd99e5d2203763629a50373a25ed Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 28 Jan 2016 09:18:58 +0000 Subject: [PATCH 040/122] fixed catapult state being mapped to incorrect blocks --- .../mineplex/core/common/util/UtilMath.java | 2 +- .../game/clans/clans/siege/cannon/Cannon.java | 27 +-- .../clans/siege/cannon/CannonCrater.java | 9 +- .../clans/clans/siege/catapult/Catapult.java | 52 ++---- .../clans/siege/catapult/CatapultCrater.java | 164 ++++++++++++++++++ .../siege/catapult/CatapultProjectile.java | 70 +++++--- .../clans/siege/catapult/CatapultState.java | 6 +- .../game/clans/gameplay/Gameplay.java | 5 + 8 files changed, 234 insertions(+), 101 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index c09b376eb..f80b87bc7 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -170,7 +170,7 @@ public class UtilMath int index = 0; for (N number : values) { - if (closestIndex == -1 || (Math.abs(value.doubleValue() - number.doubleValue()) < Math.abs(value.doubleValue() - values.get(closestIndex).doubleValue()))) + if (closestIndex == -1 || (Math.abs(number.doubleValue() - value.doubleValue()) < Math.abs(values.get(closestIndex).doubleValue() - value.doubleValue()))) { closestIndex = index; } 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 865f7c2c4..fef88da4f 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 @@ -79,8 +79,6 @@ public class Cannon implements Listener // Entity Information private List _entities; - private List _craters; - private TNTPrimed _projectile; private Inventory _inventory; @@ -93,7 +91,6 @@ public class Cannon implements Listener _state = CannonState.UNLOADED; _entities = new ArrayList<>(); - _craters = new ArrayList<>(); _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Cannon"); @@ -103,10 +100,8 @@ public class Cannon implements Listener public void cleanup() { _entities.forEach(Entity::remove); - _craters.forEach(CannonCrater::cleanup); _entities.clear(); - _craters.clear(); HandlerList.unregisterAll(this); } @@ -243,7 +238,7 @@ public class Cannon implements Listener { //Do Explosion; - _craters.add(new CannonCrater(this, UtilBlock.nearestFloor(_projectile.getLocation()))); + new CannonCrater(this, UtilBlock.nearestFloor(_projectile.getLocation())); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); @@ -253,21 +248,6 @@ public class Cannon implements Listener } } - private List circleAround(Vector origin, int points, double radius) - { - List list = new LinkedList<>(); - - double slice = 2 * Math.PI / points; - - for (int point = 0; point < points; point++) - { - double angle = slice * point; - list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle))); - } - - return list; - } - private void attemptFire() { if (canBeFired()) @@ -532,11 +512,6 @@ public class Cannon implements Listener double yaw = standYaw + Math.min(dif / 20.f, 5f); - Location pos = armorStand.getLocation(); - - pos.setYaw((float) yaw); - - armorStand.teleport(pos); armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java index db67311e5..6a92fb634 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java @@ -81,6 +81,10 @@ public class CannonCrater implements Listener UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX); UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX); } + else + { + HandlerList.unregisterAll(this); + } }); } @@ -155,9 +159,4 @@ public class CannonCrater implements Listener _blocks.forEach(CraterBlock::set); } - protected void cleanup() - { - HandlerList.unregisterAll(this); - } - } 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 c7626cad4..0e6249aaf 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 @@ -8,7 +8,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftChicken; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -64,13 +63,14 @@ public class Catapult implements Listener public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); private static final double[] VERT_POWER = { 0.9, 1.25631, 1.5382 }; - private static final double[] HORIZ_POWER = { 0.8, 1.1241, 1.34231 }; + private static final double[] HORIZ_POWER = { 1.2, 1.6241, 1.9231 }; private List _rotationPoints; private Location _location; private CatapultState _state; + private float _curYaw; private float _nextYaw; // Entity Information @@ -92,9 +92,9 @@ public class Catapult implements Listener _rotationPoints = new ArrayList<>(); _entities = new ArrayList<>(); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 20; i++) { - _rotationPoints.add((360.f / 8.f) * i); + _rotationPoints.add((360.f / 20.f) * i); } _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Catapult"); @@ -125,8 +125,6 @@ public class Catapult implements Listener armorStand.setGravity(false); armorStand.setHelmet(_state.toItemStack()); - ((CraftChicken) armorStand).getHandle().setSize(1.87F, 1.87F); - _entities.add(armorStand); } else @@ -142,7 +140,7 @@ public class Catapult implements Listener private Location getArmorStandLocation() { - return _location.clone().add(.5, -.95, .5); + return _location.clone().add(.5, -.5, .5); } private void setState(CatapultState state) @@ -153,7 +151,7 @@ public class Catapult implements Listener public void fire() { - CatapultProjectile projectile = new CatapultProjectile(_location.clone().add(.5, .3, .5), Material.COBBLESTONE); + CatapultProjectile projectile = new CatapultProjectile(this, _location.clone().add(.5, .3, .5), Material.COBBLESTONE, (float) Math.toDegrees(getArmorStand().getHeadPose().getY())); _projectile = projectile; @@ -165,7 +163,7 @@ public class Catapult implements Listener UtilAlg.moveForward( getArmorStand().getLocation(), 2., - (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false)) + (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), true)) .multiply(hMulti) .setY(vVel); @@ -204,16 +202,13 @@ public class Catapult implements Listener { if (_projectile != null) { - UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); - - if ((Math.abs(_projectile.getVelocity().getX()) < 0.01 || Math.abs(_projectile.getVelocity().getZ()) < 0.01) && UtilBlock.getInRadius(_projectile.getLocation(), 2).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && _projectile.getTicksLived() >= 10) + if (_projectile.dead()) { - //Do Explosion; - UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); - - _projectile.remove(); _projectile = null; + return; } + + UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } } @@ -293,20 +288,6 @@ public class Catapult implements Listener @EventHandler public void updateState(UpdateEvent event) { -// if (event.getType() == UpdateType.FASTEST) -// { -// if (_state == CannonState.LOADED) -// { -// double yaw = getArmorStand().getHeadPose().getY() - 7.75d; -// -// Location loc = new Location(_location.getWorld(), getArmorStand().getLocation().getX() + (0.5 * Math.cos(yaw)), _location.getY() + 1.12, getArmorStand().getLocation().getZ() + (0.5 * Math.sin(yaw))); -// -// loc = UtilAlg.moveForward(loc, 0.1, (float) Math.toDegrees(yaw + 7.75), false); -// -// UtilParticle.PlayParticleToAll(ParticleType.FLAME, loc, new Vector(0, 0, 0), 0.f, 1, ViewDist.MAX); -// } -// } - if (event.getType() != UpdateType.TICK) { return; @@ -423,7 +404,7 @@ public class Catapult implements Listener } ArmorStand armorStand = getArmorStand(); - double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; + double standYaw = _curYaw % 360; double riderYaw = _nextYaw % 360; // riderYaw = 350 and standYaw = 20 @@ -432,14 +413,9 @@ public class Catapult implements Listener if (dif > 180) dif -= 360; if (dif < -180) dif += 360; - double yaw = standYaw + Math.min(dif / 20.f, 5f); + _curYaw = (float) (standYaw + dif / 10.f); - Location pos = armorStand.getLocation(); - - pos.setYaw(UtilMath.closest(_rotationPoints, (float) yaw)); - - armorStand.teleport(pos); - armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(UtilMath.closest(_rotationPoints, _curYaw)), 0)); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java new file mode 100644 index 000000000..9144764bb --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java @@ -0,0 +1,164 @@ +package mineplex.game.clans.clans.siege.catapult; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilBlock; +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.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.siege.cannon.CraterBlock; + +public class CatapultCrater implements Listener +{ + private static final double EXPL_RADIUS = 2; + + public static final Material CHARRED_TYPE = Material.OBSIDIAN; + + private Catapult _host; + private Location _origin; + + private long _birthTime; + + private List _blocks; + + public CatapultCrater(Catapult cannon, Location origin) + { + _host = cannon; + _origin = origin; + + _birthTime = System.currentTimeMillis(); + _blocks = new ArrayList<>(); + + UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); + + createExplosion(); + } + + @EventHandler + public void updateEffects(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + _blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> { + long lifetime = System.currentTimeMillis() - _birthTime; + + long max = 80000; + + if (block.Location.getBlock().getType() != CHARRED_TYPE) + { + return; + } + + // Water touching the charred blocks + if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext()) + { + return; + } + + if (lifetime < max) + { + UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX); + UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX); + } + else + { + HandlerList.unregisterAll(this); + } + }); + } + + private void createExplosion() + { + _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); + + HashMap blockList = new HashMap(); + int iR = (int) EXPL_RADIUS + 1; + + for (int x = -iR; x <= iR; x++) + { + for (int z = -iR; z <= iR; z++) + { + for (int y = -iR; y <= iR; y++) + { + Block curBlock = _origin.getBlock().getRelative(x, y, z); + + double offset = UtilMath.offset(_origin, curBlock.getLocation()); + + if (offset <= EXPL_RADIUS) + { + blockList.put(curBlock, offset); + } + } + } + } + + for (Entry entry : blockList.entrySet()) + { + Block block = entry.getKey(); + double distance = entry.getValue(); + + boolean air = distance <= 2 || (Math.random() > (distance) / 3.65d); + + if (block.getType() == Material.AIR) continue; + + if (air) + { + _blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR)); + + Block above = block; + + while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) + { + _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); + } + } + } + + _blocks.forEach(CraterBlock::set); + + for (Entry entry : blockList.entrySet()) + { + Block block = entry.getKey(); + double distance = entry.getValue(); + + if (block.getType() == Material.AIR) continue; + + if ( + distance > 2 && + Math.random() > .85 && + UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && + !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && + !block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) && + !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) + { + _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); + _blocks.add(new CraterBlock(block.getLocation().clone().add(0, 1, 0), distance, Material.FIRE)); + } + } + + _blocks.forEach(CraterBlock::set); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java index 163cb007a..3cb22f22b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java @@ -2,33 +2,33 @@ package mineplex.game.clans.clans.siege.catapult; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.entity.ArmorStand; +import org.bukkit.Sound; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.EulerAngle; +import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.util.Vector; -import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; -import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; public class CatapultProjectile implements Listener { - private ArmorStand _parent; + private FallingBlock _sand; - public CatapultProjectile(Location location, Material material) + private Catapult _host; + + public CatapultProjectile(Catapult host, Location location, Material material, float yaw) { - _parent = location.getWorld().spawn(location, ArmorStand.class); - - UtilEnt.setFakeHead(_parent, true); - _parent.teleport(location); - _parent.setVisible(false); - _parent.setGravity(false); - _parent.setHelmet(new ItemStack(material)); + _host = host; + _sand = location.getWorld().spawnFallingBlock(location, material, (byte) 0); + _sand.setFireTicks(20000); + _sand.setDropItem(false); UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); } @@ -36,44 +36,58 @@ public class CatapultProjectile implements Listener @EventHandler public void update(UpdateEvent event) { - if (event.getType() != UpdateType.TICK) + if (Math.abs(_sand.getVelocity().getX()) < 0.05 || Math.abs(_sand.getVelocity().getZ()) < 0.05) { - return; + remove(); } - - if (_parent == null || _parent.isDead()) + } + + @EventHandler + public void onBlockFall(EntityChangeBlockEvent event) + { + if (event.getEntity().equals(_sand)) { - return; + event.setCancelled(true); + + remove(); } - - _parent.setHeadPose(new EulerAngle(_parent.getHeadPose().getX() + 2.75, _parent.getHeadPose().getY(), _parent.getHeadPose().getZ())); } public void remove() { - HandlerList.unregisterAll(this); - _parent.remove(); - _parent = null; + HandlerList.unregisterAll(this); + + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getLocation(), Sound.EXPLODE, 1.f, 1.f)); + + new CatapultCrater(_host, UtilBlock.nearestFloor(_sand.getLocation())); + + _sand.remove(); + _sand = null; } + public boolean dead() + { + return _sand == null; + } + public Location getLocation() { - return _parent.getLocation(); + return _sand.getLocation(); } public Vector getVelocity() { - return _parent.getVelocity(); + return _sand.getVelocity(); } public int getTicksLived() { - return _parent.getTicksLived(); + return _sand.getTicksLived(); } public void setVelocity(Vector velocity) { - _parent.setVelocity(velocity); + _sand.setVelocity(velocity); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java index 1b940995f..3cbc3a7e0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java @@ -5,9 +5,9 @@ import org.bukkit.inventory.ItemStack; public enum CatapultState { - UNLOADED(Material.PACKED_ICE, (byte) 0 /* packed ice */), - LOADED(Material.ENDER_PORTAL_FRAME, (byte) 0 /* lapis block */), - FIRED(Material.LAPIS_BLOCK, (byte) 0); + UNLOADED(Material.PACKED_ICE, (byte) 0), + LOADED(Material.ENDER_PORTAL_FRAME, (byte) 0), + FIRED(Material.LAPIS_BLOCK, (byte) 1); private Material _material; private byte _data; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index c591c1aab..0e7d58c74 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -513,6 +513,11 @@ public class Gameplay extends MiniPlugin { event.setCancelled(true); } + + if (event.getItem().getType() == Material.SAPLING) + { + event.setCancelled(true); + } } // @EventHandler(priority = EventPriority.LOWEST) From 8cb5591218ae437d2163b69c9e686fc6e6f00247 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 28 Jan 2016 13:28:39 +0000 Subject: [PATCH 041/122] merge conflicts --- .../src/mineplex/game/clans/gameplay/Gameplay.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 8597a27c5..03edbc048 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -513,14 +513,16 @@ public class Gameplay extends MiniPlugin { event.setCancelled(true); } - if (event.getItem().getType() == Material.TNT) + + if (event.getItem().getType() == Material.TNT) { event.setCancelled(true); } - if (event.getItem().getType() == Material.SAPLING) + + if (event.getItem().getType() == Material.SAPLING) { event.setCancelled(true); - } } + } } // @EventHandler(priority = EventPriority.LOWEST) From 37fb65627935304827040e675d8c378161bbb0b6 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 28 Jan 2016 13:31:45 +0000 Subject: [PATCH 042/122] dispenser --- .../src/mineplex/game/clans/gameplay/Gameplay.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 9bf124456..a3e92ee3b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -523,11 +523,6 @@ public class Gameplay extends MiniPlugin { event.setCancelled(true); } - - if (event.getItem().getType() == Material.SAPLING) - { - event.setCancelled(true); - } } // @EventHandler(priority = EventPriority.LOWEST) From f86262dc0e19f0780ad476b50c9a16980a1a369f Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 28 Jan 2016 23:32:23 +0000 Subject: [PATCH 043/122] catapult and cannon progress --- .../mineplex/core/common/util/UtilText.java | 6 +- .../game/clans/clans/siege/SiegeManager.java | 2 +- .../game/clans/clans/siege/cannon/Cannon.java | 83 ++++++++++++-- .../clans/clans/siege/catapult/Catapult.java | 102 ++++++++++++++---- .../clans/siege/catapult/CatapultCrater.java | 7 +- .../siege/catapult/CatapultProjectile.java | 12 ++- 6 files changed, 175 insertions(+), 37 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 92b4eb728..a57a89419 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -658,12 +658,16 @@ public class UtilText } public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap) + { + return getProgress(prefix, amount, suffix, progressDirectionSwap, 24); + } + + public static String getProgress(String prefix, double amount, String suffix, boolean progressDirectionSwap, int bars) { if (progressDirectionSwap) amount = 1 - amount; //Generate Bar - int bars = 24; String progressBar = C.cGreen + ""; boolean colorChange = false; for (int i=0 ; i SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); @@ -85,14 +88,25 @@ public class Cannon implements Listener private long _lastFired = -1; - public Cannon(Location location) + private double _health = MAX_HEALTH; + + private Hologram _healthHologram; + + private ClanInfo _clan; + + public Cannon(Location location, ClanInfo clan) { _location = location; _state = CannonState.UNLOADED; + _clan = clan; + _entities = new ArrayList<>(); _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()); + _healthHologram.start(); updateEntities(); } @@ -103,6 +117,9 @@ public class Cannon implements Listener _entities.clear(); + _healthHologram.stop(); + _healthHologram = null; + HandlerList.unregisterAll(this); } @@ -396,12 +413,17 @@ public class Cannon implements Listener @EventHandler(priority = EventPriority.HIGHEST) public void onDmg(EntityDamageByEntityEvent event) { - if (!event.getDamager().equals(_rider)) + if (!_entities.contains(event.getEntity())) { return; } - if (!_entities.contains(event.getEntity())) + if (!_clan.isMember((Player) event.getDamager())) + { + removeHealth(event.getFinalDamage()); + } + + if (!event.getDamager().equals(_rider)) { return; } @@ -414,7 +436,11 @@ public class Cannon implements Listener { if (_entities.contains(event.getRightClicked())) { - handleOpenInv(event.getPlayer()); + 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) @@ -439,6 +465,12 @@ 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) { @@ -462,6 +494,12 @@ 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) { @@ -510,7 +548,7 @@ public class Cannon implements Listener if (dif > 180) dif -= 360; if (dif < -180) dif += 360; - double yaw = standYaw + Math.min(dif / 20.f, 5f); + double yaw = standYaw + Math.min(dif / 20.f, 4f); armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); } @@ -524,4 +562,37 @@ public class Cannon implements Listener event.setCancelled(true); } } + + // Health Managemnet + public double getHealth() + { + return _health; + } + + public String getDisplayHealth() + { + return UtilText.getProgress(null, _health / MAX_HEALTH, null, false, 12); + } + + public void setHealth(double health) + { + _health = UtilMath.clamp(health, 0, MAX_HEALTH); + + _healthHologram.setText("Cannon Health", getDisplayHealth()); + + if (_health == 0) + { + cleanup(); + } + } + + public void removeHealth(double health) + { + setHealth(_health - health); + } + + public void addHealth(double health) + { + setHealth(_health + health); + } } 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 0e6249aaf..a8345bb82 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 @@ -7,6 +7,8 @@ import java.util.List; 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.craftbukkit.v1_8_R3.entity.CraftArmorStand; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; @@ -30,10 +32,8 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilBlock; 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; @@ -43,6 +43,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; +import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -58,6 +59,8 @@ public class Catapult implements Listener public static final int MAX_CHARGES = 3; public static final int MAX_COBBLE = 1; + public static final double MAX_HEALTH = 600; + public static final int COBBLE_SLOT = 4; public static final List CHARGE_SLOTS = Arrays.asList(1, 3, 5, 7); public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); @@ -84,6 +87,12 @@ public class Catapult implements Listener private ClanInfo _clan; + private double _health = MAX_HEALTH; + + private Hologram _healthHologram; + + private List _barriers; + public Catapult(Location location, ClanInfo clan) { _location = location; @@ -92,6 +101,13 @@ 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)); + for (int i = 0; i < 20; i++) { _rotationPoints.add((360.f / 20.f) * i); @@ -101,6 +117,9 @@ public class Catapult implements Listener _clan = clan; + _healthHologram = new Hologram(ClansManager.getInstance().getHologramManager(), location.clone().add(.5, 3.7, .5), "Catapult Health", getDisplayHealth()); + _healthHologram.start(); + updateEntities(); } @@ -110,6 +129,11 @@ public class Catapult implements Listener _entities.clear(); + _healthHologram.stop(); + _healthHologram = null; + + _barriers.forEach(block -> block.setType(Material.AIR)); + HandlerList.unregisterAll(this); } @@ -140,7 +164,7 @@ public class Catapult implements Listener private Location getArmorStandLocation() { - return _location.clone().add(.5, -.5, .5); + return _location.clone().add(.5, -.65, .5); } private void setState(CatapultState state) @@ -151,7 +175,7 @@ public class Catapult implements Listener public void fire() { - CatapultProjectile projectile = new CatapultProjectile(this, _location.clone().add(.5, .3, .5), Material.COBBLESTONE, (float) Math.toDegrees(getArmorStand().getHeadPose().getY())); + CatapultProjectile projectile = new CatapultProjectile(this, _location.clone().add(.5, 3, .5), Material.COBBLESTONE, (float) Math.toDegrees(getArmorStand().getHeadPose().getY())); _projectile = projectile; @@ -220,21 +244,13 @@ public class Catapult implements Listener return; } - if (canBeFired()) + if (System.currentTimeMillis() - _lastFired < COOLDOWN) { - if (System.currentTimeMillis() - _lastFired < COOLDOWN) - { - UtilPlayer.message(human, F.main("Clans", "Catapult is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")"))); - return; - } - - fire(); - } - else - { - UtilPlayer.message(human, F.main("Clans", "Catapult is not correctly loaded.")); - human.playSound(human.getLocation(), Sound.CLICK, 1.f, 1.f); + UtilPlayer.message(human, F.main("Clans", "Catapult is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")"))); + return; } + + fire(); } private void handleOpenInv(Player player) @@ -405,17 +421,17 @@ public class Catapult implements Listener ArmorStand armorStand = getArmorStand(); double standYaw = _curYaw % 360; - double riderYaw = _nextYaw % 360; + double nextYaw = _nextYaw % 360; // riderYaw = 350 and standYaw = 20 // dif should be -30 and not 330 - double dif = riderYaw - standYaw; + double dif = nextYaw - standYaw; if (dif > 180) dif -= 360; if (dif < -180) dif += 360; - _curYaw = (float) (standYaw + dif / 10.f); + _curYaw = (float) (standYaw + Math.min(dif / 10.f, 4f)); - armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(UtilMath.closest(_rotationPoints, _curYaw)), 0)); + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(_curYaw), 0)); } @EventHandler @@ -440,9 +456,53 @@ public class Catapult implements Listener return; } + if (!_clan.isMember((Player) event.getDamager())) + { + removeHealth(event.getFinalDamage()); + } + + if (!_clan.isMember((Player) event.getDamager())) + { + UtilPlayer.message((Player) event.getDamager(), F.main("Clans", "This catapult is not owned by your Clan.")); + return; + } + if (canBeFired()) attemptFire((Player) event.getDamager()); else _nextYaw = ((Player) event.getDamager()).getLocation().getYaw(); } + + // Health Managemnet + public double getHealth() + { + return _health; + } + + public String getDisplayHealth() + { + return UtilText.getProgress(null, _health / MAX_HEALTH, null, false, 12); + } + + public void setHealth(double health) + { + _health = UtilMath.clamp(health, 0, MAX_HEALTH); + + _healthHologram.setText("Catapult Health", getDisplayHealth()); + + if (_health == 0) + { + cleanup(); + } + } + + public void removeHealth(double health) + { + setHealth(_health - health); + } + + public void addHealth(double health) + { + setHealth(_health + health); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java index 9144764bb..221c6ff0c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java @@ -2,7 +2,6 @@ package mineplex.game.clans.clans.siege.catapult; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map.Entry; @@ -29,7 +28,7 @@ import mineplex.game.clans.clans.siege.cannon.CraterBlock; public class CatapultCrater implements Listener { - private static final double EXPL_RADIUS = 2; + private static final double EXPL_RADIUS = 3; public static final Material CHARRED_TYPE = Material.OBSIDIAN; @@ -119,7 +118,7 @@ public class CatapultCrater implements Listener Block block = entry.getKey(); double distance = entry.getValue(); - boolean air = distance <= 2 || (Math.random() > (distance) / 3.65d); + boolean air = distance <= 1.5 || (Math.random() > (distance) / 3.65d); if (block.getType() == Material.AIR) continue; @@ -146,7 +145,7 @@ public class CatapultCrater implements Listener if (block.getType() == Material.AIR) continue; if ( - distance > 2 && + distance > 1 && Math.random() > .85 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java index 3cb22f22b..4f5703cd3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java @@ -12,6 +12,7 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.event.UpdateEvent; @@ -27,7 +28,6 @@ public class CatapultProjectile implements Listener { _host = host; _sand = location.getWorld().spawnFallingBlock(location, material, (byte) 0); - _sand.setFireTicks(20000); _sand.setDropItem(false); UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); @@ -36,7 +36,11 @@ public class CatapultProjectile implements Listener @EventHandler public void update(UpdateEvent event) { - if (Math.abs(_sand.getVelocity().getX()) < 0.05 || Math.abs(_sand.getVelocity().getZ()) < 0.05) + if (_sand.getTicksLived() >= 20 && UtilBlock.getInRadius(_sand.getLocation(), 1.5).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && Math.abs(_sand.getVelocity().getX()) < 0.05 || Math.abs(_sand.getVelocity().getZ()) < 0.05) + { + remove(); + } + else if (_sand.isDead()) { remove(); } @@ -59,7 +63,7 @@ public class CatapultProjectile implements Listener UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getLocation(), Sound.EXPLODE, 1.f, 1.f)); - new CatapultCrater(_host, UtilBlock.nearestFloor(_sand.getLocation())); + new CatapultCrater(_host, _sand.getLocation()); _sand.remove(); _sand = null; @@ -67,7 +71,7 @@ public class CatapultProjectile implements Listener public boolean dead() { - return _sand == null; + return _sand == null || _sand.isDead(); } public Location getLocation() From 76dba421b4c90bab8a619413fa69b28cc9e52017 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 29 Jan 2016 20:54:31 +0000 Subject: [PATCH 044/122] sapling fix [THIS NEEDS TO GET PUT ONTO CLANS/ALPHA] --- .../src/mineplex/game/clans/gameplay/Gameplay.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index a3e92ee3b..ed9bbd104 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -446,10 +446,10 @@ public class Gameplay extends MiniPlugin event.setCancelled(true); } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.HIGHEST) public void disableSaplings(BlockPlaceEvent event) { - if (!event.getBlockReplacedState().getType().equals(Material.SAPLING)) + if (!event.getItemInHand().getType().equals(Material.SAPLING)) { return; } From 7d28bc69c9519a2b847b025722e0e0fa67caf624 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 29 Jan 2016 20:55:56 +0000 Subject: [PATCH 045/122] collision boxes on siege weapons and other stuff --- .../core/common/util/NautArrayList.java | 11 + .../mineplex/core/common/util/UtilItem.java | 52 ++++ .../mineplex/core/common/util/UtilServer.java | 7 +- .../mineplex/game/clans/clans/ClanTips.java | 9 +- .../clans/siege/BarrierCollisionBox.java | 251 ++++++++++++++++++ .../game/clans/clans/siege/cannon/Cannon.java | 152 ++++++----- .../clans/clans/siege/catapult/Catapult.java | 58 +++- 7 files changed, 454 insertions(+), 86 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/BarrierCollisionBox.java 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) { From 45aacd626ed2842055c1a6b5234c5f6df553ad03 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 31 Jan 2016 19:20:15 +0000 Subject: [PATCH 046/122] this isn't used anymore --- .../clans/clans/outpost/pathing/AStar.java | 391 ------------------ .../clans/outpost/pathing/PathingResult.java | 23 -- .../clans/clans/outpost/pathing/Tile.java | 183 -------- 3 files changed, 597 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/AStar.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/PathingResult.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/Tile.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/AStar.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/AStar.java deleted file mode 100644 index b3da829eb..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/AStar.java +++ /dev/null @@ -1,391 +0,0 @@ -/* - * By @Adamki11s - */ - -package mineplex.game.clans.clans.outpost.pathing; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; - -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.material.Gate; - -/** - * Not made by meee (NewGarbo) - * https://bukkit.org/threads/lib-a-pathfinding-algorithm.129786/ - */ -public class AStar -{ - private final int _sx; - private final int _sy; - private final int _sz; - private final int _ex; - private final int _ey; - private final int _ez; - private final World _world; - - private PathingResult _result; - - private HashMap _open = new HashMap(); - private HashMap _closed = new HashMap(); - - private void addToOpenList(Tile t, boolean modify) - { - if (_open.containsKey(t.getUID())) - { - if (modify) - { - _open.put(t.getUID(), t); - } - } - else - { - _open.put(t.getUID(), t); - } - } - - private void addToClosedList(Tile t) - { - if (!_closed.containsKey(t.getUID())) - { - _closed.put(t.getUID(), t); - } - } - - private final int _range; - private final String _endUID; - - public AStar(Location start, Location end, int range) throws InvalidPathException - { - boolean s = true, e = true; - - if (!(s = isLocationWalkable(start)) || !(e = isLocationWalkable(end))) - { - throw new InvalidPathException(s, e); - } - - _world = start.getWorld(); - _sx = start.getBlockX(); - _sy = start.getBlockY(); - _sz = start.getBlockZ(); - _ex = end.getBlockX(); - _ey = end.getBlockY(); - _ez = end.getBlockZ(); - - _range = range; - - short sh = 0; - Tile t = new Tile(sh, sh, sh, null); - t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true); - _open.put(t.getUID(), t); - processAdjacentTiles(t); - - StringBuilder b = new StringBuilder(); - b.append(_ex - _sx).append(_ey - _sy).append(_ez - _sz); - _endUID = b.toString(); - } - - public Location getEndLocation() - { - return new Location(_world, _ex, _ey, _ez); - } - - public PathingResult getPathingResult() - { - return _result; - } - - protected boolean _checkOnce = false; - - private int abs(int i) - { - return (i < 0 ? -i : i); - } - - public ArrayList iterate() - { - if (!_checkOnce) - { - // invert the boolean flag - _checkOnce ^= true; - if ((abs(_sx - _ex) > _range) || (abs(_sy - _ey) > _range) || (abs(_sz - _ez) > _range)) - { - _result = PathingResult.NO_PATH; - return null;// jump out - } - } - // while not at end - Tile current = null; - - while (canContinue()) - { - - // get lowest F cost square on open list - current = getLowestFTile(); - - // process tiles - processAdjacentTiles(current); - } - - if (_result != PathingResult.SUCCESS) - { - return null; - } - else - { - // path found - LinkedList routeTrace = new LinkedList(); - Tile parent; - - routeTrace.add(current); - - while ((parent = current.getParent()) != null) - { - routeTrace.add(parent); - current = parent; - } - - Collections.reverse(routeTrace); - - return new ArrayList(routeTrace); - } - } - - private boolean canContinue() - { - // check if open list is empty, if it is no path has been found - if (_open.size() == 0) - { - _result = PathingResult.NO_PATH; - return false; - } - else - { - if (_closed.containsKey(_endUID)) - { - _result = PathingResult.SUCCESS; - return false; - } - else - { - return true; - } - } - } - - private Tile getLowestFTile() - { - double f = 0; - Tile drop = null; - - // get lowest F cost square - for (Tile t : _open.values()) - { - if (f == 0) - { - t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true); - f = t.getF(); - drop = t; - } - else - { - t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true); - double posF = t.getF(); - if (posF < f) - { - f = posF; - drop = t; - } - } - } - - // drop from open list and add to closed - - _open.remove(drop.getUID()); - addToClosedList(drop); - - return drop; - } - - private boolean isOnClosedList(Tile t) - { - return _closed.containsKey(t.getUID()); - } - - // pass in the current tile as the parent - private void processAdjacentTiles(Tile current) - { - - // set of possible walk to locations adjacent to current tile - HashSet possible = new HashSet(26); - - for (byte x = -1; x <= 1; x++) - { - for (byte y = -1; y <= 1; y++) - { - for (byte z = -1; z <= 1; z++) - { - - if (x == 0 && y == 0 && z == 0) - { - continue;// don't check current square - } - - Tile t = new Tile((short) (current.getX() + x), (short) (current.getY() + y), (short) (current.getZ() + z), current); - - if (!t.isInRange(_range)) - { - // if block is out of bounds continue - continue; - } - - if (x != 0 && z != 0 && (y == 0 || y == 1)) - { - // check to stop jumping through diagonal blocks - Tile xOff = new Tile((short) (current.getX() + x), (short) (current.getY() + y), (short) (current.getZ()), current), zOff = new Tile((short) (current.getX()), (short) (current.getY() + y), (short) (current.getZ() + z), current); - if (!isTileWalkable(xOff) && !isTileWalkable(zOff)) - { - continue; - } - } - - if (isOnClosedList(t)) - { - // ignore tile - continue; - } - - // only process the tile if it can be walked on - if (isTileWalkable(t)) - { - t.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true); - possible.add(t); - } - - } - } - } - - for (Tile t : possible) - { - // get the reference of the object in the array - Tile openRef = null; - if ((openRef = isOnOpenList(t)) == null) - { - // not on open list, so add - addToOpenList(t, false); - } - else - { - // is on open list, check if path to that square is better using - // G cost - if (t.getG() < openRef.getG()) - { - // if current path is better, change parent - openRef.setParent(current); - // force updates of F, G and H values. - openRef.calculateBoth(_sx, _sy, _sz, _ex, _ey, _ez, true); - } - - } - } - - } - - private Tile isOnOpenList(Tile t) - { - return (_open.containsKey(t.getUID()) ? _open.get(t.getUID()) : null); - /* - * for (Tile o : open) { if (o.equals(t)) { return o; } } return null; - */ - } - - private boolean isTileWalkable(Tile t) - { - Location l = new Location(_world, (_sx + t.getX()), (_sy + t.getY()), (_sz + t.getZ())); - Block b = l.getBlock(); - int i = b.getTypeId(); - - // lava, fire, wheat and ladders cannot be walked on, and of course air - // 85, 107 and 113 stops npcs climbing fences and fence gates - if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != 0 && i != 85 && i != 107 && i != 113 && !canBlockBeWalkedThrough(i)) - { - // make sure the blocks above are air - - if (b.getRelative(0, 1, 0).getTypeId() == 107) - { - // fench gate check, if closed continue - Gate g = new Gate(b.getRelative(0, 1, 0).getData()); - return (g.isOpen() ? (b.getRelative(0, 2, 0).getTypeId() == 0) : false); - } - return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getTypeId()) && b.getRelative(0, 2, 0).getTypeId() == 0); - - } - else - { - return false; - } - } - - private boolean isLocationWalkable(Location l) - { - Block b = l.getBlock(); - int i = b.getTypeId(); - - if (i != 10 && i != 11 && i != 51 && i != 59 && i != 65 && i != 0 && !canBlockBeWalkedThrough(i)) - { - // make sure the blocks above are air or can be walked through - return (canBlockBeWalkedThrough(b.getRelative(0, 1, 0).getTypeId()) && b.getRelative(0, 2, 0).getTypeId() == 0); - } - else - { - return false; - } - } - - private boolean canBlockBeWalkedThrough(int id) - { - return (id == 0 || id == 6 || id == 50 || id == 63 || id == 30 || id == 31 || id == 32 || id == 37 || id == 38 || id == 39 || id == 40 || id == 55 || id == 66 || id == 75 || id == 76 || id == 78); - } - - @SuppressWarnings("serial") - public class InvalidPathException extends Exception - { - private final boolean _s, _e; - - public InvalidPathException(boolean s, boolean e) - { - _s = s; - _e = e; - } - - public String getErrorReason() - { - StringBuilder sb = new StringBuilder(); - if (!_s) - { - sb.append("Start Location was air. "); - } - if (!_e) - { - sb.append("End Location was air."); - } - return sb.toString(); - } - - public boolean isStartNotSolid() - { - return (!_s); - } - - public boolean isEndNotSolid() - { - return (!_e); - } - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/PathingResult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/PathingResult.java deleted file mode 100644 index 06e0084dc..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/PathingResult.java +++ /dev/null @@ -1,23 +0,0 @@ -package mineplex.game.clans.clans.outpost.pathing; - -/** - * Not made by meee (NewGarbo) - * https://bukkit.org/threads/lib-a-pathfinding-algorithm.129786/ - */ -public enum PathingResult -{ - SUCCESS(0), - NO_PATH(-1); - - private final int _ec; - - PathingResult(int ec) - { - _ec = ec; - } - - public int getEndCode() - { - return _ec; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/Tile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/Tile.java deleted file mode 100644 index 133d67278..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/outpost/pathing/Tile.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * By @Adamki11s - */ - -package mineplex.game.clans.clans.outpost.pathing; - -import org.bukkit.Location; - -/** - * Not made by meee (NewGarbo) - * https://bukkit.org/threads/lib-a-pathfinding-algorithm.129786/ - */ -public class Tile -{ - // as offset from starting point - private final short _x; - private final short _y; - private final short _z; - - private double _g = -1; - private double _h = -1; - - private Tile _parent = null; - - private final String _uid; - - public Tile(short x, short y, short z, Tile parent) - { - _x = x; - _y = y; - _z = z; - _parent = parent; - - StringBuilder b = new StringBuilder(); - b.append(x); - b.append(y); - b.append(z); - _uid = b.toString(); - - } - - public boolean isInRange(int range) - { - return ((range - abs(_x) >= 0) && (range - abs(_y) >= 0) && (range - abs(_z) >= 0)); - } - - public void setParent(Tile parent) - { - _parent = parent; - } - - public Location getLocation(Location start) - { - return new Location(start.getWorld(), start.getBlockX() + _x, start.getBlockY() + _y, start.getBlockZ() + _z); - } - - public Tile getParent() - { - return _parent; - } - - public short getX() - { - return _x; - } - - public int getX(Location i) - { - return (i.getBlockX() + _x); - } - - public short getY() - { - return _y; - } - - public int getY(Location i) - { - return (i.getBlockY() + _y); - } - - public short getZ() - { - return _z; - } - - public int getZ(Location i) - { - return (i.getBlockZ() + _z); - } - - public String getUID() - { - return _uid; - } - - public boolean equals(Tile t) - { - return (t.getX() == _x && t.getY() == _y && t.getZ() == _z); - } - - public void calculateBoth(int sx, int sy, int sz, int ex, int ey, int ez, boolean update) - { - calculateG(sx, sy, sz, update); - calculateH(sx, sy, sz, ex, ey, ez, update); - } - - public void calculateH(int sx, int sy, int sz, int ex, int ey, int ez, boolean update) - { - // only update if h hasn't been calculated or if forced - if ((!update && _h == -1) || update) - { - int hx = sx + _x, hy = sy + _y, hz = sz + _z; - _h = getEuclideanDistance(hx, hy, hz, ex, ey, ez); - } - } - - // G = the movement cost to move from the starting point A to a given square - // on the grid, following the path generated to get there. - public void calculateG(int sx, int sy, int sz, boolean update) - { - if ((!update && _g == -1) || update) - { - // only update if g hasn't been calculated or if forced - Tile currentParent = getParent(), currentTile = this; - int gCost = 0; - // follow path back to start - while ((currentParent = currentTile.getParent()) != null) - { - int dx = currentTile.getX() - currentParent.getX(), dy = currentTile.getY() - currentParent.getY(), dz = currentTile.getZ() - currentParent.getZ(); - - dx = abs(dx); - dy = abs(dy); - dz = abs(dz); - - if (dx == 1 && dy == 1 && dz == 1) - { - gCost += 1.7; - } else if (((dx == 1 || dz == 1) && dy == 1) || ((dx == 1 || dz == 1) && dy == 0)) - { - gCost += 1.4; - } - else - { - gCost += 1.0; - } - - // move backwards a tile - currentTile = currentParent; - } - _g = gCost; - } - - } - - public double getG() - { - return _g; - } - - public double getH() - { - return _h; - } - - public double getF() - { - // f = h + g - return (_h + _g); - } - - private double getEuclideanDistance(int sx, int sy, int sz, int ex, int ey, int ez) - { - double dx = sx - ex, dy = sy - ey, dz = sz - ez; - return Math.sqrt((dx * dx) + (dy * dy) + (dz * dz)); - } - - private int abs(int i) - { - return (i < 0 ? -i : i); - } - -} From b4ed912f7d07614ed1ffd84bbe7f58f784c298e8 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 1 Feb 2016 19:52:53 +0000 Subject: [PATCH 047/122] siege weapon modular system beginnings --- .../mineplex/core/common/util/UtilMath.java | 10 + .../clans/clans/siege/cannon/AccessRule.java | 25 + .../game/clans/clans/siege/cannon/Cannon.java | 623 ++---------------- .../clans/clans/siege/weapon/AccessType.java | 7 + .../clans/siege/weapon/ProjectileType.java | 7 + .../clans/clans/siege/weapon/SiegeWeapon.java | 283 ++++++++ .../clans/siege/weapon/WeaponStateInfo.java | 25 + 7 files changed, 426 insertions(+), 554 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index f80b87bc7..d089bad59 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -180,4 +180,14 @@ public class UtilMath return values.get(closestIndex); } + + public static boolean isOdd(int size) + { + return !isEven(size); + } + + public static boolean isEven(int size) + { + return size % 2 == 0; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java new file mode 100644 index 000000000..1ffa94e58 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.clans.siege.cannon; + +import java.util.function.Predicate; + +import org.bukkit.entity.Player; + +import mineplex.game.clans.clans.siege.weapon.AccessType; + +public class AccessRule +{ + private Predicate _access; + private AccessType _type; + + public AccessRule(AccessType type, Predicate access) + { + _type = type; + _access = access; + } + + public boolean allow(AccessType type, Player player) + { + return type.equals(_type) && _access.test(player); + } + +} 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 6fc3e5416..0898a9196 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 @@ -1,610 +1,125 @@ package mineplex.game.clans.clans.siege.cannon; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.Vector; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.entity.Slime; -import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerArmorStandManipulateEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.EulerAngle; -import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilBlock; 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; import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilText; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; -import mineplex.core.hologram.Hologram; -import mineplex.core.itemstack.ItemBuilder; -import mineplex.core.updater.UpdateType; -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; +import mineplex.game.clans.clans.siege.weapon.AccessType; +import mineplex.game.clans.clans.siege.weapon.ProjectileType; +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.clans.siege.weapon.WeaponStateInfo; -public class Cannon implements Listener +public class Cannon extends SiegeWeapon { - public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); - - public static final int COOLDOWN = 20 * 1000 /* 20 seconds*/; - - public static final int MAX_SULPHUR = 3; - public static final int MAX_TNT = 1; - - public static final double MAX_HEALTH = 600; - - public static final int TNT_SLOT = 4; - public static final List SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7); - public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); - - private static final double[] VERT_POWER = { 0.5, 0.75631, 0.9382 }; - private static final double[] HORIZ_POWER = { 0.8, 1.1241, 1.34231 }; - - private Location _location; - private CannonState _state; - - private Player _rider; - - // Entity Information - private List _entities; - - private TNTPrimed _projectile; - - private Inventory _inventory; - - private long _lastFired = -1; - - private double _health = MAX_HEALTH; - - private Hologram _healthHologram; - - private ClanInfo _clan; - - private BarrierCollisionBox _collisionBox; - public Cannon(Location location, ClanInfo clan) { - _location = location; - _state = CannonState.UNLOADED; + super(location, 600.d, "Cannon", clan, clan.Clans); - _clan = clan; + setBoundingBox(1); - _entities = new ArrayList<>(); + setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); + setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0)); - _collisionBox = BarrierCollisionBox.single(_location.clone()); - _collisionBox.Construct(); - _collisionBox.registerRight((block, player) -> handleRightClick(player)); - _collisionBox.registerLeft((block, player) -> handleLeftClick(player, -1)); + Slime slime = location.getWorld().spawn(location, Slime.class); + Slime slime2 = location.getWorld().spawn(location, Slime.class); - _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()); - _healthHologram.start(); + slime.setPassenger(slime2); - updateEntities(); - } - - public void cleanup() - { - _entities.forEach(Entity::remove); + UtilEnt.silence(slime, true); + UtilEnt.silence(slime2, true); + UtilEnt.Vegetate(slime); + UtilEnt.Vegetate(slime2); - _entities.clear(); + slime.setSize(-1); + slime2.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + slime2.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - _collisionBox.Destruct(); - _healthHologram.stop(); - _healthHologram = null; + ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class); - HandlerList.unregisterAll(this); - } - - private void updateEntities() - { - if (_entities.isEmpty()) - { - Slime slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class); - - UtilEnt.silence(slime, true); - UtilEnt.Vegetate(slime); - - slime.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - - _entities.add(slime); - - slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class); - - UtilEnt.silence(slime, true); - UtilEnt.Vegetate(slime); - - slime.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - - UtilMath.getLast(_entities).setPassenger(slime); - - _entities.add(slime); - - ArmorStand armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); - - UtilEnt.setFakeHead(armorStand, true); - armorStand.teleport(getArmorStandLocation()); - armorStand.setVisible(false); - armorStand.setHelmet(_state.toItemStack()); - armorStand.setGravity(false); - - armorStand.setPassenger(UtilMath.getFirst(_entities)); - - _entities.add(0, armorStand); - } - else - { - getArmorStand().setHelmet(_state.toItemStack()); - } - } - - private CraftArmorStand getArmorStand() - { - return (CraftArmorStand) UtilMath.getFirst(_entities); - } - - private Location getArmorStandLocation() - { - return _location.clone().add(.5, .15, .5); - } - - private void setState(CannonState state) - { - _state = state; - updateEntities(); - } - - public void fire() - { - TNTPrimed tnt = _location.getWorld().spawn(_location.clone().add(.5, .3, .5), TNTPrimed.class); + UtilEnt.setFakeHead(armorStand, true); + armorStand.teleport(location); + armorStand.setVisible(false); + armorStand.setGravity(false); - _projectile = tnt; + armorStand.setPassenger(slime); - double vVel = VERT_POWER[getPower() - 1]; - double hMulti = HORIZ_POWER[getPower() - 1]; + addEntity(slime, "Slime1"); + addEntity(slime2, "PLAYERMOUNT"); + addEntity(armorStand, "WEAPON"); - Vector velocity = UtilAlg.getTrajectory( - getArmorStand().getLocation(), - UtilAlg.moveForward( - getArmorStand().getLocation(), - 2., - (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false)) - .multiply(hMulti) - .setY(vVel); + setState("Unloaded"); - tnt.setVelocity(velocity); + setFirepowerType(Material.SULPHUR); + setAmmunitionType(Material.TNT); - _inventory.setItem(TNT_SLOT, UtilInv.decrement(_inventory.getItem(TNT_SLOT))); - SULPHUR_SLOTS.forEach(_inventory::clear); + setFirepowerSlots(1, 3, 5, 7); + setMaximumFirepowerPerSlot(3); - UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, getArmorStandLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); - UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.EXPLODE, 1.f, 1.f)); + setAmmunitionSlot(4); + setMaximumAmmunitionPerSlot(1); - _lastFired = System.currentTimeMillis(); - } - - @EventHandler - public void onCloseInv(InventoryCloseEvent event) - { - if (!event.getInventory().equals(_inventory)) - { - return; - } + setFireCooldown(20000); - ClansManager.getInstance().runSyncLater(() -> { - if (event.getPlayer().getInventory().equals(_inventory)) + setProjectileType(ProjectileType.PRIMED_TNT); + setProjectileDoCrater(3, 2.d); + + enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, super::isRiding)); + + setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { + if (!_owner.isMember(player)) { - return; + UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); + return false; } - if (canBeFired()) + if (getRider() != null && !getRider().equals(player)) { - UtilTextMiddle.display("Cannon Ready", "Power Level: " + C.cGreen + UtilText.repeat("▌", getPower()) + C.cRed + UtilText.repeat("▌", 3 - getPower()), 20, 100, 20, _rider); - } - }, 3L); - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onTntExplode(EntityExplodeEvent event) - { - // stop the tnt from exploding naturally - if (event.getEntity().equals(_projectile)) - { - event.setCancelled(true); - } - } - - public void updateProjectile() - { - if (_projectile != null) - { - UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); - - _projectile.setFuseTicks(40); - - if ((Math.abs(_projectile.getVelocity().getX()) < 0.01 || Math.abs(_projectile.getVelocity().getZ()) < 0.01) && UtilBlock.getInRadius(_projectile.getLocation(), 2).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && _projectile.getTicksLived() >= 10) - { - //Do Explosion; - - new CannonCrater(this, UtilBlock.nearestFloor(_projectile.getLocation())); - - UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); - - _projectile.remove(); - _projectile = null; - } - } - } - - private void attemptFire() - { - if (canBeFired()) - { - if (System.currentTimeMillis() - _lastFired < COOLDOWN) - { - UtilPlayer.message(_rider, F.main("Clans", "Cannon is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")"))); - return; + UtilPlayer.message(player, F.main("Clans", "Someone is already riding this cannon.")); + return false; } - fire(); - } - else + return !player.equals(getRider()); + })); + } + + @Override + public void UpdateState(String state) + { + ((ArmorStand) getEntity("WEAPON")).setHelmet(new ItemStack(getStateInfo(state).getType(), getStateInfo(state).getData())); + } + + @Override + protected void tick() + { + if (getProjectile() != null) { - UtilPlayer.message(_rider, F.main("Clans", "Cannon is not correctly loaded.")); - _rider.playSound(_rider.getLocation(), Sound.CLICK, 1.f, 1.f); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } } - private void handleOpenInv(Player player) + @Override + protected double[] getProjectileVelocityMult() { - if (!player.equals(_rider)) - { - return; - } + int firepower = getPowerLevel(); - if (_inventory == null) - { - cleanup(); - return; - } - - _rider.openInventory(_inventory); + return new double[] { firepower, firepower }; } - private int getPower() - { - int power = 0; - - for (int slot : SULPHUR_SLOTS) - { - if (_inventory.getItem(slot) != null) - { - power += _inventory.getItem(slot).getAmount(); - } - } - - return power / 4; - } - - private int getTnt() - { - return _inventory.getItem(TNT_SLOT) != null ? _inventory.getItem(TNT_SLOT).getAmount() : 0; - } - - private boolean canBeFired() - { - return getTnt() > 0 && getPower() > 0 && _projectile == null; - } - - @EventHandler - public void updateState(UpdateEvent event) - { -// if (event.getType() == UpdateType.FASTEST) -// { -// if (_state == CannonState.LOADED) -// { -// double yaw = getArmorStand().getHeadPose().getY() - 7.75d; -// -// Location loc = new Location(_location.getWorld(), getArmorStand().getLocation().getX() + (0.5 * Math.cos(yaw)), _location.getY() + 1.12, getArmorStand().getLocation().getZ() + (0.5 * Math.sin(yaw))); -// -// loc = UtilAlg.moveForward(loc, 0.1, (float) Math.toDegrees(yaw + 7.75), false); -// -// UtilParticle.PlayParticleToAll(ParticleType.FLAME, loc, new Vector(0, 0, 0), 0.f, 1, ViewDist.MAX); -// } -// } - - if (event.getType() != UpdateType.TICK) - { - return; - } - - CannonState newState = _inventory.getItem(TNT_SLOT) != null ? CannonState.LOADED : CannonState.UNLOADED; - - if (_state != newState) - { - setState(newState); - } - - checkInv(); - - updateProjectile(); - } - - public void checkInv() - { - for (int slot = 0; slot < 9; slot++) - { - ItemStack item = _inventory.getItem(slot); - - if (item == null) - { - continue; - } - - if (slot == TNT_SLOT) - { - if (item.getType() != Material.TNT) - { - _rider.getInventory().addItem(item); - _inventory.setItem(slot, null); - } - else - { - if (item.getAmount() > MAX_TNT) - { - _rider.getInventory().addItem(new ItemStack(Material.TNT, item.getAmount() - MAX_TNT)); - _inventory.setItem(slot, new ItemStack(Material.TNT, MAX_TNT)); - } - } - } - else if (SULPHUR_SLOTS.contains(slot)) - { - if (item.getType() != Material.SULPHUR) - { - _rider.getInventory().addItem(item); - _inventory.setItem(slot, null); - } - else - { - if (item.getAmount() > MAX_SULPHUR) - { - _rider.getInventory().addItem(new ItemStack(Material.SULPHUR, item.getAmount() - MAX_SULPHUR)); - _inventory.setItem(slot, new ItemStack(Material.SULPHUR, MAX_SULPHUR)); - } - } - } - else if (EMPTY_SLOTS.contains(slot)) // also classes as just an 'else{}' - { - _rider.getInventory().addItem(item); - _inventory.setItem(slot, null); - } - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onDmg(EntityDamageByEntityEvent event) - { - if (!_entities.contains(event.getEntity())) - { - return; - } - - if (!(event.getDamager() instanceof Player)) - { - handleLeftClick((Player) event.getDamager(), event.getFinalDamage()); - } - } - - @EventHandler - public void onInteract(PlayerInteractAtEntityEvent event) - { - if (_entities.contains(event.getRightClicked())) - { - handleRightClick(event.getPlayer()); - event.setCancelled(true); - } - } - - @EventHandler - public void onInteract(PlayerInteractEntityEvent event) - { - if (_entities.contains(event.getRightClicked())) - { - handleRightClick(event.getPlayer()); - event.setCancelled(true); - } - } - - @EventHandler - public void onInteract(PlayerArmorStandManipulateEvent event) - { - if (_entities.contains(event.getRightClicked())) - { - 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) - { - if (event.getType() != UpdateType.TICK) - { - return; - } - - if (_rider != null && !_rider.equals(UtilMath.getLast(_entities).getPassenger())) - { - _rider = null; - } - - if (_rider != null) - { - if (System.currentTimeMillis() - _lastFired < 5000) - { - return; - } - - ArmorStand armorStand = (ArmorStand) UtilMath.getFirst(_entities); - double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; - double riderYaw = _rider.getLocation().getYaw() % 360; - - // riderYaw = 350 and standYaw = 20 - // dif should be -30 and not 330 - double dif = riderYaw - standYaw; - if (dif > 180) dif -= 360; - if (dif < -180) dif += 360; - - double yaw = standYaw + Math.min(dif / 20.f, 4f); - - armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); - } - } - - @EventHandler - public void onDamage(EntityDamageEvent event) - { - if (_entities.contains(event.getEntity())) - { - event.setCancelled(true); - } - } - - // Health Managemnet - public double getHealth() - { - return _health; - } - - public String getDisplayHealth() - { - return UtilText.getProgress(null, _health / MAX_HEALTH, null, false, 12); - } - - public void setHealth(double health) - { - _health = UtilMath.clamp(health, 0, MAX_HEALTH); - - _healthHologram.setText("Cannon Health", getDisplayHealth()); - - if (_health == 0) - { - cleanup(); - } - } - - public void removeHealth(double health) - { - setHealth(_health - health); - } - - public void addHealth(double health) - { - setHealth(_health + health); - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java new file mode 100644 index 000000000..aafb8c9d4 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java @@ -0,0 +1,7 @@ +package mineplex.game.clans.clans.siege.weapon; + +public enum AccessType +{ + RCLICK_BB, + LCLICK_BB, +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java new file mode 100644 index 000000000..0f364ee89 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java @@ -0,0 +1,7 @@ +package mineplex.game.clans.clans.siege.weapon; + +public enum ProjectileType +{ + PRIMED_TNT, + FALLING_BLOCK; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java new file mode 100644 index 000000000..e2fc34e90 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -0,0 +1,283 @@ +package mineplex.game.clans.clans.siege.weapon; + +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang.Validate; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.inventory.Inventory; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilText; +import mineplex.core.hologram.Hologram; +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.siege.BarrierCollisionBox; +import mineplex.game.clans.clans.siege.cannon.AccessRule; + +public abstract class SiegeWeapon implements Listener +{ + private ClansManager _clans; + + protected ClanInfo _owner; + protected final String _name; + protected final double _maxHealth; + protected double _health; + + protected Inventory _inventory; + protected AccessRule _inventoryAccess; + + private Hologram _infoHologram; + private BarrierCollisionBox _collisionBox; + + private Location _location; + + private final Map _registeredStates; + private String _currentState; + + private final List _comprisedOf; + + // Friendly-name mapping to index in _comprisedOf for easier management of entities. + private final Map _entityMapping; + + private boolean _isRideable; + private AccessRule _mountAccess; + + private Player _rider; + + public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager) + { + _location = location; + _name = name; + _health = _maxHealth = maxHealth; + _owner = owner; + + _comprisedOf = Lists.newArrayList(); + _registeredStates = Maps.newHashMap(); + _entityMapping = Maps.newHashMap(); + + _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); + _infoHologram.start(); + + UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); + + _clans = clansManager; + } + + protected void enableInventory(Inventory inventory, AccessRule accessRule) + { + _inventory = inventory; + _inventoryAccess = accessRule; + } + + protected void setBoundingBox(int size) + { + Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number."); + Validate.isTrue(size > 0, "Size must be a positive number."); + + _collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .5, size - 1, ((size - 1) / 2) + .5)); + _collisionBox.Construct(); + _collisionBox.registerRight((block, player) -> handleRightClick(player)); + _collisionBox.registerLeft((block, player) -> handleLeftClick(player)); + } + + // Riding + + protected Player getRider() + { + return _rider; + } + + protected void setRideable(AccessRule accessRule) + { + _isRideable = true; + _mountAccess = accessRule; + } + + // Internal + + private void kill() + { + Cleanup(); + + _comprisedOf.forEach(Entity::remove); + + _entityMapping.clear(); + _comprisedOf.clear(); + _infoHologram.stop(); + + HandlerList.unregisterAll(this); + } + + private void handleMount(Player player) + { + getEntity("PLAYERMOUNT").setPassenger(player); + OnMount(player); + } + + private void handleInventoryOpen(Player player) + { + player.openInventory(_inventory); + } + + private void handleRightClick(Player player) + { + RightClick(player); + + if (_isRideable && _mountAccess.allow(AccessType.RCLICK_BB, player)) + { + handleMount(player); + } + + if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player)) + { + handleInventoryOpen(player); + } + } + + private void handleLeftClick(Player player) + { + LeftClick(player); + + if (_isRideable && _mountAccess.allow(AccessType.LCLICK_BB, player)) + { + handleMount(player); + } + + if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player)) + { + handleInventoryOpen(player); + } + } + + // Methods for implementation by sub-classes + + protected void Tick() + { + } + + protected void OnMount(Player player) + { + } + + protected void LeftClick(Player player) + { + } + + protected void RightClick(Player player) + { + } + + protected void Cleanup() + { + } + + protected void UpdateState(String state) + { + } + + // Entity Management + + protected final boolean addEntity(Entity entity, String uniqueName) + { + boolean success = _comprisedOf.add(entity); + + if (success) + { + _entityMapping.put(uniqueName, _comprisedOf.size() - 1); + } + + return success; + } + + protected final Entity getEntity(String uniqueName) + { + return _comprisedOf.get(_entityMapping.get(uniqueName)); + } + + // Health Management + + public final double getHealth() + { + return _health; + } + + public final String getDisplayHealth() + { + return UtilText.getProgress(null, _health / _maxHealth, null, false, 12); + } + + public final void setHealth(double health) + { + _health = UtilMath.clamp(health, 0, _maxHealth); + + _infoHologram.setText(_name + " Health", getDisplayHealth()); + + if (_health == 0) + { + kill(); + } + } + + public final void removeHealth(double health) + { + setHealth(_health - health); + } + + public final void addHealth(double health) + { + setHealth(_health + health); + } + + //State Management + + public final void setState(String state) + { + Validate.isTrue(_registeredStates.containsKey(state), "Provided state has not yet been registered."); + + _currentState = state; + + UpdateState(state); + } + + public final void setStateInfo(String state, WeaponStateInfo info) + { + _registeredStates.put(state, info); + } + + public final WeaponStateInfo getStateInfo(String state) + { + if (!_registeredStates.containsKey(state)) + { + _registeredStates.put(state, new WeaponStateInfo(Material.STONE, (byte) 101)); + } + + return _registeredStates.get(state); + } + + // Events + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + Tick(); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java new file mode 100644 index 000000000..917035f38 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.clans.siege.weapon; + +import org.bukkit.Material; + +public class WeaponStateInfo +{ + private Material _material; + private byte _data; + + public WeaponStateInfo(Material material, byte data) + { + _material = material; + _data = data; + } + + public Material getType() + { + return _material; + } + + public byte getData() + { + return _data; + } +} From 9fa5927240cb751d4f3fd59462ee83d6ca7d0b60 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 2 Feb 2016 19:41:25 +0000 Subject: [PATCH 048/122] siege weapon base progress --- .../mineplex/core/common/util/UtilServer.java | 6 + .../mineplex/game/clans/clans/ClanInfo.java | 2 +- .../clans/siege/BarrierCollisionBox.java | 26 +- .../game/clans/clans/siege/SiegeManager.java | 4 +- .../game/clans/clans/siege/cannon/Cannon.java | 65 ++- .../clans/clans/siege/catapult/Catapult.java | 1 - .../clans/clans/siege/outpost/Outpost.java | 7 +- .../game/clans/clans/siege/weapon/Crater.java | 179 ++++++++ .../clans/clans/siege/weapon/CraterBlock.java | 32 ++ .../siege/weapon/ProjectileAttributes.java | 75 ++++ .../clans/clans/siege/weapon/SiegeWeapon.java | 389 +++++++++++++++++- .../clans/siege/weapon/WeaponProjectile.java | 177 ++++++++ .../gameplay/safelog/npc/NPCManager.java | 2 +- 13 files changed, 924 insertions(+), 41 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java 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 229166e39..921344101 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 @@ -11,6 +11,7 @@ import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; public class UtilServer @@ -86,6 +87,11 @@ public class UtilServer { return (double)getPlayers().length / (double)UtilServer.getServer().getMaxPlayers(); } + + public static void registerEvents(Listener listener) + { + getPluginManager().registerEvents(listener, getPluginManager().getPlugins()[0]); + } public static PluginManager getPluginManager() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java index fac283def..47ae28025 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClanInfo.java @@ -249,7 +249,7 @@ public class ClanInfo public boolean isSelf(String other) { - return this.getName().equals(other); + return getName().equals(other); } public boolean isNeutral(String other) 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 index d412a8537..c9c76bb14 100644 --- 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 @@ -54,7 +54,7 @@ public class BarrierCollisionBox implements Listener { setBlocks(); - UtilServer.getPluginManager().registerEvents(this, UtilServer.getServer().getPluginManager().getPlugins()[0]); + UtilServer.registerEvents(this); } public void Destruct() @@ -96,11 +96,13 @@ public class BarrierCollisionBox implements Listener private void onLeftClick(Location location, Player player) { + System.out.println("Collision Box Left"); _leftClickListeners.forEach(listener -> listener.accept(location, player)); } private void onRightClick(Location location, Player player) { + System.out.println("Collision Box Right"); _rightClickListeners.forEach(listener -> listener.accept(location, player)); } @@ -122,15 +124,7 @@ public class BarrierCollisionBox implements Listener public boolean isInBox(Location location) { - for (Location boxLocation : _collisionBlocks) - { - if (boxLocation.equals(location)) - { - return true; - } - } - - return false; + return _collisionBlocks.contains(location); } @EventHandler @@ -151,6 +145,10 @@ public class BarrierCollisionBox implements Listener onLeftClick(event.getBlock().getLocation(), event.getPlayer()); event.setCancelled(true); } + else + { + System.out.println("BlockDamage: NOT IN BOX"); + } } @EventHandler @@ -161,6 +159,10 @@ public class BarrierCollisionBox implements Listener onLeftClick(event.getBlock().getLocation(), event.getPlayer()); event.setCancelled(true); } + else + { + System.out.println("BlockBreak: NOT IN BOX"); + } } @EventHandler @@ -176,6 +178,10 @@ public class BarrierCollisionBox implements Listener onRightClick(event.getClickedBlock().getLocation(), event.getPlayer()); event.setCancelled(true); } + else + { + System.out.println("PlayerInteract: NOT IN BOX"); + } } public BarrierCollisionBox add(Location... location) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 04a5bb76f..b348a32bb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -86,9 +86,7 @@ public class SiegeManager extends MiniPlugin public void spawnCannon(Player player, Location location) { - Cannon cannon = new Cannon(location, _clans.getClan(player)); - - _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(cannon, _outpostManager.getPlugin()); + new Cannon(location, _clans.getClan(player)); } public boolean trySpawnCatapult(Player player, Location location) 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 0898a9196..c8a6e565a 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 @@ -1,15 +1,15 @@ package mineplex.game.clans.clans.siege.cannon; -import java.util.Vector; - import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -19,18 +19,25 @@ 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.UtilTime; +import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.weapon.AccessType; -import mineplex.game.clans.clans.siege.weapon.ProjectileType; +import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.clans.siege.weapon.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.WeaponStateInfo; public class Cannon extends SiegeWeapon { + public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + public Cannon(Location location, ClanInfo clan) { super(location, 600.d, "Cannon", clan, clan.Clans); + location.add(.5, 0, .5); + setBoundingBox(1); setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); @@ -39,8 +46,6 @@ public class Cannon extends SiegeWeapon Slime slime = location.getWorld().spawn(location, Slime.class); Slime slime2 = location.getWorld().spawn(location, Slime.class); - slime.setPassenger(slime2); - UtilEnt.silence(slime, true); UtilEnt.silence(slime2, true); UtilEnt.Vegetate(slime); @@ -59,6 +64,7 @@ public class Cannon extends SiegeWeapon armorStand.setGravity(false); armorStand.setPassenger(slime); + slime.setPassenger(slime2); addEntity(slime, "Slime1"); addEntity(slime2, "PLAYERMOUNT"); @@ -75,12 +81,30 @@ public class Cannon extends SiegeWeapon setAmmunitionSlot(4); setMaximumAmmunitionPerSlot(1); - setFireCooldown(20000); + setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d)); - setProjectileType(ProjectileType.PRIMED_TNT); - setProjectileDoCrater(3, 2.d); + setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { + if (!_owner.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); + return false; + } + + if (System.currentTimeMillis() - _lastFired < 20000) + { + UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")")); + return false; + } + + if (!isRiding(player)) + { + return false; + } + + return true; + })); - enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, super::isRiding)); + enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { if (!_owner.isMember(player)) @@ -97,25 +121,40 @@ public class Cannon extends SiegeWeapon return !player.equals(getRider()); })); + + System.out.println("Cannon initialized."); } @Override - public void UpdateState(String state) + public void Fire(WeaponProjectile projectile) { - ((ArmorStand) getEntity("WEAPON")).setHelmet(new ItemStack(getStateInfo(state).getType(), getStateInfo(state).getData())); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); } @Override - protected void tick() + public String getNextState() + { + if (getAmmunition() > 0) + { + return "Loaded"; + } + + return "Unloaded"; + } + + @Override + protected void Tick() { if (getProjectile() != null) { + System.out.println("ye"); UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } } @Override - protected double[] getProjectileVelocityMult() + protected double[] getProjectileVelocity() { int firepower = getPowerLevel(); 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 ecd61ee69..58e8b2a7f 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 @@ -381,7 +381,6 @@ public class Catapult implements Listener } } - @EventHandler public void onInteract(PlayerInteractAtEntityEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 86b83b6d9..473b54a4c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -11,7 +11,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; @@ -33,7 +32,6 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilColor; import mineplex.core.common.util.UtilEvent; -import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; @@ -44,15 +42,14 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilUI; import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; -import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.cannon.Cannon; +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; @@ -149,7 +146,7 @@ public class Outpost implements Listener _state = OutpostState.DEAD; - _cannons.forEach(Cannon::cleanup); + _cannons.forEach(SiegeWeapon::kill); _cannons.clear(); _host.queueForRemoval(_clan.getName()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java new file mode 100644 index 000000000..acb732940 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java @@ -0,0 +1,179 @@ +package mineplex.game.clans.clans.siege.weapon; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilBlock; +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.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class Crater implements Listener +{ + public static final Material CHARRED_TYPE = Material.OBSIDIAN; + + private final SiegeWeapon _weapon; + private final Location _origin; + + private final long _birthTime; + + private final int _size; + private final double _airChance; + + private final boolean _fire; + + private final List _blocks; + + public Crater(SiegeWeapon weapon, Location origin, int size, double airChance, boolean doFire) + { + _weapon = weapon; + _origin = origin; + + _birthTime = System.currentTimeMillis(); + _blocks = new ArrayList<>(); + + _size = size; + _airChance = airChance; + _fire = doFire; + + UtilServer.getPluginManager().registerEvents(this, _weapon._clans.getPlugin()); + + createExplosion(); + } + + @EventHandler + public void updateEffects(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + _blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> { + long lifetime = System.currentTimeMillis() - _birthTime; + + long max = 80000; + + if (block.Location.getBlock().getType() != CHARRED_TYPE) + { + return; + } + + // Water touching the charred blocks + if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext()) + { + return; + } + + if (lifetime < max) + { + UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX); + UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX); + } + else + { + HandlerList.unregisterAll(this); + } + }); + } + + private void createExplosion() + { + _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); + + HashMap blockList = new HashMap(); + int iR = (int) _size + 1; + + for (int x = -iR; x <= iR; x++) + { + for (int z = -iR; z <= iR; z++) + { + for (int y = -iR; y <= iR; y++) + { + Block curBlock = _origin.getBlock().getRelative(x, y, z); + + double offset = UtilMath.offset(_origin, curBlock.getLocation()); + + if (offset <= _size) + { + blockList.put(curBlock, offset); + } + } + } + } + + for (Entry entry : blockList.entrySet()) + { + Block block = entry.getKey(); + double distance = entry.getValue(); + + boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d); + + if (block.getType() == Material.AIR) continue; + + if (air) + { + _blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR)); + + Block above = block; + + while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) + { + _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); + } + + if (!UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType())) + { + if (_fire && Math.random() >= .5) + { + _blocks.add(new CraterBlock(block.getLocation(), distance, Material.FIRE)); + } + } + } + } + + _blocks.forEach(CraterBlock::set); + + for (Entry entry : blockList.entrySet()) + { + Block block = entry.getKey(); + double distance = entry.getValue(); + + if (block.getType() == Material.AIR) continue; + + if ( + distance > _airChance && + Math.random() > .75 && + UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && + !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && + !block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) && + !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) + { + _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); + if (_fire) + { + _blocks.add(new CraterBlock(block.getRelative(BlockFace.UP).getLocation(), distance, Material.FIRE)); + } + } + } + + _blocks.forEach(CraterBlock::set); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java new file mode 100644 index 000000000..e770cfb58 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java @@ -0,0 +1,32 @@ +package mineplex.game.clans.clans.siege.weapon; + +import org.bukkit.Location; +import org.bukkit.Material; + +public class CraterBlock +{ + public Material Type; + public byte Data; + public double DistanceToOrigin; + + public Location Location; + + public CraterBlock(Location location, double dist, Material type, byte data) + { + Location = location; + DistanceToOrigin = dist; + Type = type; + Data = data; + } + + public CraterBlock(Location location, double dist, Material type) + { + this(location, dist, type, (byte) 0); + } + + public void set() + { + Location.getBlock().setType(Type); + Location.getBlock().setData(Data); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java new file mode 100644 index 000000000..7b5e94013 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java @@ -0,0 +1,75 @@ +package mineplex.game.clans.clans.siege.weapon; + +import org.bukkit.Material; + +public class ProjectileAttributes +{ + protected boolean _isFallingBlock; + protected Material _fallingBlockType; + protected byte _fallingBlockData; + + protected boolean _isPrimedTnt; + + protected boolean _doCrater; + protected int _craterSize; + protected double _craterChanceOfAir; + + protected boolean _craterDoFire; + + public ProjectileAttributes setFallingBlock() + { + _isFallingBlock = true; + + return this; + } + + public ProjectileAttributes setFallingBlockType(Material type) + { + _fallingBlockType = type; + + return this; + } + + public ProjectileAttributes setFallingBlockData(byte data) + { + _fallingBlockData = data; + + return this; + } + + public ProjectileAttributes setPrimedTnt() + { + _isPrimedTnt = true; + + return this; + } + + public ProjectileAttributes setDoCrater() + { + _doCrater = true; + + return this; + } + + public ProjectileAttributes craterSize(int size) + { + _craterSize = size; + + return this; + } + + public ProjectileAttributes craterDoFire(boolean doFire) + { + _craterDoFire = doFire; + + return this; + } + + public ProjectileAttributes craterChanceOfAir(double chance) + { + _craterChanceOfAir = chance; + + return this; + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index e2fc34e90..a4aad9654 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -6,19 +6,29 @@ import java.util.Map; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerArmorStandManipulateEvent; +import org.bukkit.event.player.PlayerInteractAtEntityEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.EulerAngle; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import mineplex.core.common.util.C; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.hologram.Hologram; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -29,7 +39,7 @@ import mineplex.game.clans.clans.siege.cannon.AccessRule; public abstract class SiegeWeapon implements Listener { - private ClansManager _clans; + protected ClansManager _clans; protected ClanInfo _owner; protected final String _name; @@ -55,10 +65,30 @@ public abstract class SiegeWeapon implements Listener private boolean _isRideable; private AccessRule _mountAccess; + private AccessRule _fireAccess; + private Player _rider; + // Firing stuff + + private Material _firepowerType; + private Material _ammunitionType; + + private List _firepowerSlots; + private int _ammunitionSlot; + + private int _maxAmmunition; + private int _maxFirepowerPerSlot; + + private ProjectileAttributes _projectileAttributes; + private WeaponProjectile _projectile; + + protected long _lastFired; + public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager) { + System.out.println("Siege Weapon initializing."); + _location = location; _name = name; _health = _maxHealth = maxHealth; @@ -76,6 +106,15 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; } + protected void damage(Player player) + { + + } + + protected abstract double[] getProjectileVelocity(); + + protected abstract String getNextState(); + protected void enableInventory(Inventory inventory, AccessRule accessRule) { _inventory = inventory; @@ -84,8 +123,8 @@ public abstract class SiegeWeapon implements Listener protected void setBoundingBox(int size) { - Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number."); Validate.isTrue(size > 0, "Size must be a positive number."); + Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number."); _collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .5, size - 1, ((size - 1) / 2) + .5)); _collisionBox.Construct(); @@ -93,8 +132,167 @@ public abstract class SiegeWeapon implements Listener _collisionBox.registerLeft((block, player) -> handleLeftClick(player)); } + private void updateWeapon() + { + if (_inventory != null) + { + checkInv(); + } + + if (!getNextState().equals(_currentState)) + { + setState(getNextState()); + } + + if (_projectile != null) + { + if (_projectile.hasDied()) + { + _projectile = null; + } + } + + if (_rider != null && !_rider.equals(getEntity("PLAYERMOUNT"))) + { + _rider = null; + } + + if (_rider != null) + { + if (!(getEntity("WEAPON") instanceof ArmorStand)) + { + return; + } + + ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); + double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; + double riderYaw = _rider.getLocation().getYaw() % 360; + + // riderYaw = 350 and standYaw = 20 + // dif should be -30 and not 330 + double dif = riderYaw - standYaw; + if (dif > 180) dif -= 360; + if (dif < -180) dif += 360; + + double yaw = standYaw + Math.min(dif / 20.f, 4f); + + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); + } + } + + // Firing + + protected boolean canBeFired() + { + return getPowerLevel() > 0 && _projectile == null; + } + + protected WeaponProjectile getProjectile() + { + return _projectile; + } + + private void fire(Player player) + { + System.out.println("Firing siege weapon..."); + _lastFired = System.currentTimeMillis(); + + double[] vel = getProjectileVelocity(); + + _projectile = new WeaponProjectile(this, _location.clone().add(.5, 0, .5), _projectileAttributes, ((ArmorStand) getEntity("WEAPON")).getHeadPose().getY(), vel[0], vel[1]); + + Fire(_projectile); + } + + protected void setFireRule(AccessRule rule) + { + _fireAccess = rule; + } + + protected void setFirepowerType(Material type) + { + _firepowerType = type; + } + + protected void setAmmunitionType(Material type) + { + _ammunitionType = type; + } + + protected void setFirepowerSlots(Integer... slots) + { + _firepowerSlots = Lists.newArrayList(slots); + } + + protected void setMaximumFirepowerPerSlot(int maxFirepowerPerSlot) + { + _maxFirepowerPerSlot = maxFirepowerPerSlot; + } + + protected void setAmmunitionSlot(int ammunitionSlot) + { + _ammunitionSlot = ammunitionSlot; + } + + protected void setMaximumAmmunitionPerSlot(int maxAmmunition) + { + _maxAmmunition = maxAmmunition; + } + + protected void setProjectileAttributes(ProjectileAttributes projectileAttributes) + { + _projectileAttributes = projectileAttributes; + } + + protected int getAmmunition() + { + ItemStack item = _inventory.getItem(_ammunitionSlot); + + if (item != null && item.getType().equals(_ammunitionType)) + { + return item.getAmount(); + } + + return 0; + } + + protected int getPowerLevel() + { + int power = 0; + + for (int slot : _firepowerSlots) + { + ItemStack item = _inventory.getItem(slot); + + if (item == null || !item.getType().equals(_ammunitionType)) + { + continue; + } + + power += _inventory.getItem(slot).getAmount(); + } + + + if (UtilMath.isOdd(power)) + { + power -= 4; + } + + return power / 4; + } + // Riding + protected boolean isRiding(Player player) + { + if (getRider() == null) + { + return false; + } + + return getRider().equals(player); + } + protected Player getRider() { return _rider; @@ -108,7 +306,7 @@ public abstract class SiegeWeapon implements Listener // Internal - private void kill() + public void kill() { Cleanup(); @@ -123,6 +321,7 @@ public abstract class SiegeWeapon implements Listener private void handleMount(Player player) { + System.out.println("handling mount"); getEntity("PLAYERMOUNT").setPassenger(player); OnMount(player); } @@ -136,15 +335,20 @@ public abstract class SiegeWeapon implements Listener { RightClick(player); + System.out.println("handling right click"); + if (_isRideable && _mountAccess.allow(AccessType.RCLICK_BB, player)) { handleMount(player); } - - if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player)) + else if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player)) { handleInventoryOpen(player); } + else if (_fireAccess.allow(AccessType.RCLICK_BB, player) && canBeFired()) + { + fire(player); + } } private void handleLeftClick(Player player) @@ -155,11 +359,18 @@ public abstract class SiegeWeapon implements Listener { handleMount(player); } - - if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player)) + else if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player)) { handleInventoryOpen(player); } + else if (_fireAccess.allow(AccessType.LCLICK_BB, player) && canBeFired()) + { + fire(player); + } + else if (!_owner.isMember(player)) + { + damage(player); + } } // Methods for implementation by sub-classes @@ -188,6 +399,10 @@ public abstract class SiegeWeapon implements Listener { } + protected void Fire(WeaponProjectile projectile) + { + } + // Entity Management protected final boolean addEntity(Entity entity, String uniqueName) @@ -247,11 +462,18 @@ public abstract class SiegeWeapon implements Listener { Validate.isTrue(_registeredStates.containsKey(state), "Provided state has not yet been registered."); + System.out.println("Updating siege weapon state"); + _currentState = state; UpdateState(state); } + public final String getState() + { + return _currentState; + } + public final void setStateInfo(String state, WeaponStateInfo info) { _registeredStates.put(state, info); @@ -267,8 +489,159 @@ public abstract class SiegeWeapon implements Listener return _registeredStates.get(state); } + public void checkInv() + { + for (int slot = 0; slot < _inventory.getSize(); slot++) + { + ItemStack item = _inventory.getItem(slot); + + if (item == null) + { + continue; + } + + if (slot == _ammunitionSlot) + { + if (item.getType() != _ammunitionType) + { + if (_rider != null) + { + _rider.getInventory().addItem(item); + } + else + { + _location.getWorld().dropItem(_location, item); + } + + _inventory.setItem(slot, null); + } + else + { + if (item.getAmount() > _maxAmmunition) + { + if (_rider != null) + { + _rider.getInventory().addItem(new ItemStack(Material.TNT, item.getAmount() - _maxAmmunition)); + } + else + { + _location.getWorld().dropItem(_location, item); + } + + _inventory.setItem(slot, new ItemStack(Material.TNT, _maxAmmunition)); + } + } + } + else if (_firepowerSlots.contains(slot)) + { + if (item.getType() != _firepowerType) + { + if (_rider != null) + { + _rider.getInventory().addItem(item); + } + else + { + _location.getWorld().dropItem(_location, item); + } + + _inventory.setItem(slot, null); + } + else + { + if (item.getAmount() > _maxFirepowerPerSlot) + { + if (_rider != null) + { + _rider.getInventory().addItem(new ItemStack(_firepowerType, item.getAmount() - _maxFirepowerPerSlot)); + } + else + { + _location.getWorld().dropItem(_location, item); + } + + _inventory.setItem(slot, new ItemStack(_firepowerType, _maxFirepowerPerSlot)); + } + } + } + else + { + if (_rider != null) + { + _rider.getInventory().addItem(item); + } + else + { + _location.getWorld().dropItem(_location, item); + } + + _inventory.setItem(slot, null); + } + } + } + // Events + @EventHandler + public void onDamage(EntityDamageEvent event) + { + if (_comprisedOf.contains(event.getEntity())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onCloseInv(InventoryCloseEvent event) + { + if (!event.getInventory().equals(_inventory)) + { + return; + } + + ClansManager.getInstance().runSyncLater(() -> { + if (event.getPlayer().getInventory().equals(_inventory)) + { + return; + } + + if (canBeFired()) + { + UtilTextMiddle.display(_name + " Ready", "Power Level: " + C.cGreen + UtilText.repeat("▌", getPowerLevel()) + C.cRed + UtilText.repeat("▌", _maxFirepowerPerSlot - getPowerLevel()), 20, 100, 20, (Player) event.getPlayer()); + } + }, 3L); + } + + @EventHandler + public void onInteract(PlayerInteractAtEntityEvent event) + { + if (_comprisedOf.contains(event.getRightClicked())) + { + handleRightClick(event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void onInteract(PlayerInteractEntityEvent event) + { + if (_comprisedOf.contains(event.getRightClicked())) + { + handleRightClick(event.getPlayer()); + event.setCancelled(true); + } + } + + @EventHandler + public void onInteract(PlayerArmorStandManipulateEvent event) + { + if (_comprisedOf.contains(event.getRightClicked())) + { + handleRightClick(event.getPlayer()); + event.setCancelled(true); + } + } + @EventHandler public void update(UpdateEvent event) { @@ -277,6 +650,8 @@ public abstract class SiegeWeapon implements Listener return; } + updateWeapon(); + Tick(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java new file mode 100644 index 000000000..31971c921 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java @@ -0,0 +1,177 @@ +package mineplex.game.clans.clans.siege.weapon; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.TNTPrimed; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.siege.cannon.CannonCrater; + +public class WeaponProjectile implements Listener +{ + private ProjectileAttributes _attributes; + private Location _origin; + private Entity _projectileEntity; + + private SiegeWeapon _weapon; + + private double _yRot; + private double _xMulti; + private double _yVel; + + private boolean _dead; + + public WeaponProjectile(SiegeWeapon weapon, Location origin, ProjectileAttributes attributes, double yRot, double yVel, double xMulti) + { + _weapon = weapon; + _origin = origin; + _attributes = attributes; + _yRot = yRot; + _yVel = yVel; + _xMulti = xMulti; + + UtilServer.getPluginManager().registerEvents(this, weapon._clans.getPlugin()); + + spawn(); + + System.out.println("New Projectile"); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onTntExplode(EntityExplodeEvent event) + { + if (!_attributes._isPrimedTnt) + { + return; + } + + if (event.getEntity().equals(_projectileEntity)) + { + event.setCancelled(true); + } + } + + @EventHandler + public void onBlockFall(EntityChangeBlockEvent event) + { + if (!_dead && event.getEntity().equals(_projectileEntity)) + { + die(); + event.setCancelled(true); + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + if (_dead || _projectileEntity == null) + { + die(); + return; + } + + if ((Math.abs(_projectileEntity.getVelocity().getX()) < 0.01 + || Math.abs(_projectileEntity.getVelocity().getZ()) < 0.01) + && UtilBlock.getInRadius(_projectileEntity.getLocation(), 2) + .keySet() + .stream() + .filter(block -> !UtilItem.isBoundless(block.getType())) + .iterator().hasNext() && _projectileEntity.getTicksLived() >= 10) + { + new Crater(_weapon, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire); + + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectileEntity.getLocation(), Sound.EXPLODE, 1.f, 1.f)); + + die(); + } + } + + public boolean hasDied() + { + return _dead; + } + + public Location getLocation() + { + return _projectileEntity.getLocation(); + } + + public void setLocation(Location location) + { + _projectileEntity.teleport(location); + } + + private void die() + { + HandlerList.unregisterAll(this); + + if (_projectileEntity != null) + { + _projectileEntity.remove(); + _projectileEntity = null; + } + + _dead = true; + } + + private void spawn() + { + if (_attributes._isFallingBlock) + { + FallingBlock fallingBlock = _origin.getWorld().spawnFallingBlock(_origin, _attributes._fallingBlockType, _attributes._fallingBlockData); + + _projectileEntity = fallingBlock; + + Vector velocity = UtilAlg.getTrajectory( + _origin, + UtilAlg.moveForward( + _origin, + 2., + (float) Math.toDegrees(_yRot), false)) + .multiply(_xMulti) + .setY(_yVel); + + fallingBlock.setVelocity(velocity); + } + else if (_attributes._isPrimedTnt) + { + TNTPrimed tnt = _origin.getWorld().spawn(_origin, TNTPrimed.class); + + _projectileEntity = tnt; + + Vector velocity = UtilAlg.getTrajectory( + _origin, + UtilAlg.moveForward( + _origin, + 2., + (float) Math.toDegrees(_yRot), false)) + .multiply(_xMulti) + .setY(_yVel); + + tnt.setVelocity(velocity); + } + else + { + System.out.println("==== SIEGE WEAPON PROJECTILE ATTRIBUTES DOES NOT SPECIFY ENTITY TYPE ===="); + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java index 451149aad..186433d54 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/NPCManager.java @@ -167,7 +167,7 @@ public class NPCManager extends MiniPlugin if (event.GetDamagerPlayer(true) != null) { - ClanInfo clan = this._clansManager.getClan(event.GetDamagerPlayer(true)); + ClanInfo clan = _clansManager.getClan(event.GetDamagerPlayer(true)); if (clan != null && clan.isMember(logoutNpc.getPlayerInfo().getUniqueId())) { From 95741e30293e61c686e39cceb58b7c9ef23a08c6 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 10:53:53 +0000 Subject: [PATCH 049/122] fixed siege weapon base --- .../game/clans/clans/ClansManager.java | 2 +- .../clans/siege/BarrierCollisionBox.java | 16 ++++- .../game/clans/clans/siege/cannon/Cannon.java | 64 +++++++++++-------- .../clans/clans/siege/weapon/SiegeWeapon.java | 34 +++++++--- 4 files changed, 74 insertions(+), 42 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index e088c9185..5a0c6d47c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -528,7 +528,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati // 0 is set aside for active build so we just dupe build to this row // whenever we update it. - activeBuild.CustomBuildNumber = 0; + activeBuild.CustomBuildNumber = Integer.valueOf(0); _classManager.GetRepository().SaveCustomBuild(activeBuild); } } 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 index c9c76bb14..ff17c819e 100644 --- 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 @@ -47,7 +47,7 @@ public class BarrierCollisionBox implements Listener { this(); - UtilBlock.getInBoundingBox(start, end, false).forEach(block -> _collisionBlocks.add(block.getLocation())); + UtilBlock.getInBoundingBox(start.getBlock().getLocation(), end.getBlock().getLocation(), false).forEach(block -> _collisionBlocks.add(block.getLocation())); } public void Construct() @@ -124,7 +124,17 @@ public class BarrierCollisionBox implements Listener public boolean isInBox(Location location) { - return _collisionBlocks.contains(location); + for (Location other : _collisionBlocks) + { + System.out.println(other + " : " + location); + + if (other.equals(location)) + { + return true; + } + } + + return false; } @EventHandler @@ -252,6 +262,6 @@ public class BarrierCollisionBox implements Listener public static BarrierCollisionBox single(Location location) { - return new BarrierCollisionBox(new ArrayList<>(Arrays.asList(location))); + return new BarrierCollisionBox(new ArrayList<>(Arrays.asList(location.getBlock().getLocation()))); } } \ 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 c8a6e565a..99effa1c2 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 @@ -43,34 +43,7 @@ public class Cannon extends SiegeWeapon setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0)); - Slime slime = location.getWorld().spawn(location, Slime.class); - Slime slime2 = location.getWorld().spawn(location, Slime.class); - - UtilEnt.silence(slime, true); - UtilEnt.silence(slime2, true); - UtilEnt.Vegetate(slime); - UtilEnt.Vegetate(slime2); - - slime.setSize(-1); - slime2.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - slime2.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - - ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class); - - UtilEnt.setFakeHead(armorStand, true); - armorStand.teleport(location); - armorStand.setVisible(false); - armorStand.setGravity(false); - - armorStand.setPassenger(slime); - slime.setPassenger(slime2); - - addEntity(slime, "Slime1"); - addEntity(slime2, "PLAYERMOUNT"); - addEntity(armorStand, "WEAPON"); - - setState("Unloaded"); + loadEntities(); setFirepowerType(Material.SULPHUR); setAmmunitionType(Material.TNT); @@ -125,6 +98,41 @@ public class Cannon extends SiegeWeapon System.out.println("Cannon initialized."); } + private void loadEntities() + { + Slime slime = _location.getWorld().spawn(_location, Slime.class); + + UtilEnt.silence(slime, true); + UtilEnt.Vegetate(slime); + + slime.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + addEntity(slime, "Filler"); + + slime = _location.getWorld().spawn(_location, Slime.class); + + UtilEnt.silence(slime, true); + UtilEnt.Vegetate(slime); + + slime.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + getEntity("Filler").setPassenger(slime); + addEntity(slime, "PLAYERMOUNT"); + + ArmorStand armorStand = _location.getWorld().spawn(_location, ArmorStand.class); + + UtilEnt.setFakeHead(armorStand, true); + armorStand.teleport(_location); + armorStand.setVisible(false); + armorStand.setGravity(false); + + armorStand.setPassenger(getEntity("Filler")); + + addEntity(armorStand, "WEAPON"); + } + @Override public void Fire(WeaponProjectile projectile) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index a4aad9654..1bc476b45 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -10,9 +10,12 @@ import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -52,7 +55,7 @@ public abstract class SiegeWeapon implements Listener private Hologram _infoHologram; private BarrierCollisionBox _collisionBox; - private Location _location; + protected final Location _location; private final Map _registeredStates; private String _currentState; @@ -405,16 +408,11 @@ public abstract class SiegeWeapon implements Listener // Entity Management - protected final boolean addEntity(Entity entity, String uniqueName) + protected final void addEntity(Entity entity, String uniqueName) { - boolean success = _comprisedOf.add(entity); + _comprisedOf.add(entity); - if (success) - { - _entityMapping.put(uniqueName, _comprisedOf.size() - 1); - } - - return success; + _entityMapping.put(uniqueName, _comprisedOf.size() - 1); } protected final Entity getEntity(String uniqueName) @@ -464,6 +462,8 @@ public abstract class SiegeWeapon implements Listener System.out.println("Updating siege weapon state"); + ((ArmorStand) getEntity("WEAPON")).setHelmet(new ItemStack(_registeredStates.get(state).getType(), 1, (short) 0, (byte) _registeredStates.get(state).getData())); + _currentState = state; UpdateState(state); @@ -532,7 +532,7 @@ public abstract class SiegeWeapon implements Listener } } } - else if (_firepowerSlots.contains(slot)) + else if (_firepowerSlots.contains(Integer.valueOf(slot))) { if (item.getType() != _firepowerType) { @@ -591,6 +591,20 @@ public abstract class SiegeWeapon implements Listener } } + @EventHandler(priority = EventPriority.HIGHEST) + public void onDmg(EntityDamageByEntityEvent event) + { + if (!_comprisedOf.contains(event.getEntity())) + { + return; + } + + if (event.getDamager() instanceof Player) + { + handleLeftClick((Player) event.getDamager()); + } + } + @EventHandler public void onCloseInv(InventoryCloseEvent event) { From 8004d0dc3c8841f88aece5644ee12b47697a0a3b Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 11:06:58 +0000 Subject: [PATCH 050/122] fixed npes --- .../clans/clans/siege/weapon/SiegeWeapon.java | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 1bc476b45..854bcde0d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -70,8 +70,6 @@ public abstract class SiegeWeapon implements Listener private AccessRule _fireAccess; - private Player _rider; - // Firing stuff private Material _firepowerType; @@ -155,21 +153,16 @@ public abstract class SiegeWeapon implements Listener } } - if (_rider != null && !_rider.equals(getEntity("PLAYERMOUNT"))) + if (getEntity("PLAYERMOUNT").getPassenger() == null) { - _rider = null; + return; } - if (_rider != null) + if (getRider() != null) { - if (!(getEntity("WEAPON") instanceof ArmorStand)) - { - return; - } - ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; - double riderYaw = _rider.getLocation().getYaw() % 360; + double riderYaw = getRider().getLocation().getYaw() % 360; // riderYaw = 350 and standYaw = 20 // dif should be -30 and not 330 @@ -286,6 +279,16 @@ public abstract class SiegeWeapon implements Listener // Riding + protected Player getRider() + { + if (getEntity("PLAYERMOUNT").getPassenger() == null || !(getEntity("PLAYERMOUNT").getPassenger() instanceof Player)) + { + return null; + } + + return (Player) getEntity("PLAYERMOUNT").getPassenger(); + } + protected boolean isRiding(Player player) { if (getRider() == null) @@ -296,11 +299,6 @@ public abstract class SiegeWeapon implements Listener return getRider().equals(player); } - protected Player getRider() - { - return _rider; - } - protected void setRideable(AccessRule accessRule) { _isRideable = true; @@ -344,11 +342,13 @@ public abstract class SiegeWeapon implements Listener { handleMount(player); } - else if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player)) + + if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player)) { handleInventoryOpen(player); } - else if (_fireAccess.allow(AccessType.RCLICK_BB, player) && canBeFired()) + + if (_fireAccess.allow(AccessType.RCLICK_BB, player) && canBeFired()) { fire(player); } @@ -362,15 +362,18 @@ public abstract class SiegeWeapon implements Listener { handleMount(player); } - else if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player)) + + if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player)) { handleInventoryOpen(player); } - else if (_fireAccess.allow(AccessType.LCLICK_BB, player) && canBeFired()) + + if (_fireAccess.allow(AccessType.LCLICK_BB, player) && canBeFired()) { fire(player); } - else if (!_owner.isMember(player)) + + if (!_owner.isMember(player)) { damage(player); } @@ -504,9 +507,9 @@ public abstract class SiegeWeapon implements Listener { if (item.getType() != _ammunitionType) { - if (_rider != null) + if (getRider() != null) { - _rider.getInventory().addItem(item); + getRider().getInventory().addItem(item); } else { @@ -519,9 +522,9 @@ public abstract class SiegeWeapon implements Listener { if (item.getAmount() > _maxAmmunition) { - if (_rider != null) + if (getRider() != null) { - _rider.getInventory().addItem(new ItemStack(Material.TNT, item.getAmount() - _maxAmmunition)); + getRider().getInventory().addItem(new ItemStack(Material.TNT, item.getAmount() - _maxAmmunition)); } else { @@ -536,9 +539,9 @@ public abstract class SiegeWeapon implements Listener { if (item.getType() != _firepowerType) { - if (_rider != null) + if (getRider() != null) { - _rider.getInventory().addItem(item); + getRider().getInventory().addItem(item); } else { @@ -551,9 +554,9 @@ public abstract class SiegeWeapon implements Listener { if (item.getAmount() > _maxFirepowerPerSlot) { - if (_rider != null) + if (getRider() != null) { - _rider.getInventory().addItem(new ItemStack(_firepowerType, item.getAmount() - _maxFirepowerPerSlot)); + getRider().getInventory().addItem(new ItemStack(_firepowerType, item.getAmount() - _maxFirepowerPerSlot)); } else { @@ -566,9 +569,9 @@ public abstract class SiegeWeapon implements Listener } else { - if (_rider != null) + if (getRider() != null) { - _rider.getInventory().addItem(item); + getRider().getInventory().addItem(item); } else { From d4388870c1e57ecbef1e00b8a12795b22552b149 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 11:19:33 +0000 Subject: [PATCH 051/122] fixed inventory opening on mount --- .../mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 854bcde0d..e758ba1ea 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -341,11 +341,13 @@ public abstract class SiegeWeapon implements Listener if (_isRideable && _mountAccess.allow(AccessType.RCLICK_BB, player)) { handleMount(player); + return; } if (_inventory != null && _inventoryAccess.allow(AccessType.RCLICK_BB, player)) { handleInventoryOpen(player); + return; } if (_fireAccess.allow(AccessType.RCLICK_BB, player) && canBeFired()) @@ -361,16 +363,19 @@ public abstract class SiegeWeapon implements Listener if (_isRideable && _mountAccess.allow(AccessType.LCLICK_BB, player)) { handleMount(player); + return; } if (_inventory != null && _inventoryAccess.allow(AccessType.LCLICK_BB, player)) { handleInventoryOpen(player); + return; } if (_fireAccess.allow(AccessType.LCLICK_BB, player) && canBeFired()) { fire(player); + return; } if (!_owner.isMember(player)) From 6bba4863857cf5fbffd50b6c04493fbd004dcb6d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 11:20:11 +0000 Subject: [PATCH 052/122] Added message if cannon is not loaded correctly --- .../src/mineplex/game/clans/clans/siege/cannon/Cannon.java | 6 ++++++ 1 file changed, 6 insertions(+) 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 99effa1c2..91c18093f 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 @@ -63,6 +63,12 @@ public class Cannon extends SiegeWeapon return false; } + if (!canBeFired()) + { + UtilPlayer.message(player, F.main("Clans", "Cannon is not loaded correctly.")); + return false; + } + if (System.currentTimeMillis() - _lastFired < 20000) { UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")")); From 38cae1e3a20019a4a4108609e6c31b03dd4ea614 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 15:28:53 +0000 Subject: [PATCH 053/122] catapult implemented using new siege weapon system, cannons polished up. not tested completely. don't expect this code to work fully haaha --- .../clans/siege/BarrierCollisionBox.java | 15 - .../game/clans/clans/siege/cannon/Cannon.java | 25 +- .../clans/siege/cannon/CannonCrater.java | 162 ----- .../clans/clans/siege/cannon/CannonState.java | 34 - .../clans/clans/siege/cannon/CraterBlock.java | 32 - .../clans/clans/siege/catapult/Catapult.java | 636 ++++-------------- .../clans/siege/catapult/CatapultCrater.java | 163 ----- .../siege/catapult/CatapultProjectile.java | 97 --- .../clans/siege/catapult/CatapultState.java | 35 - .../siege/{cannon => weapon}/AccessRule.java | 4 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 18 +- .../clans/siege/weapon/WeaponProjectile.java | 1 - 12 files changed, 178 insertions(+), 1044 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/{cannon => weapon}/AccessRule.java (78%) 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 index ff17c819e..82343e0f2 100644 --- 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 @@ -59,7 +59,6 @@ public class BarrierCollisionBox implements Listener public void Destruct() { - System.out.println("Destructing..."); HandlerList.unregisterAll(this); resetBlocks(); @@ -96,13 +95,11 @@ public class BarrierCollisionBox implements Listener private void onLeftClick(Location location, Player player) { - System.out.println("Collision Box Left"); _leftClickListeners.forEach(listener -> listener.accept(location, player)); } private void onRightClick(Location location, Player player) { - System.out.println("Collision Box Right"); _rightClickListeners.forEach(listener -> listener.accept(location, player)); } @@ -155,10 +152,6 @@ public class BarrierCollisionBox implements Listener onLeftClick(event.getBlock().getLocation(), event.getPlayer()); event.setCancelled(true); } - else - { - System.out.println("BlockDamage: NOT IN BOX"); - } } @EventHandler @@ -169,10 +162,6 @@ public class BarrierCollisionBox implements Listener onLeftClick(event.getBlock().getLocation(), event.getPlayer()); event.setCancelled(true); } - else - { - System.out.println("BlockBreak: NOT IN BOX"); - } } @EventHandler @@ -188,10 +177,6 @@ public class BarrierCollisionBox implements Listener onRightClick(event.getClickedBlock().getLocation(), event.getPlayer()); event.setCancelled(true); } - else - { - System.out.println("PlayerInteract: NOT IN BOX"); - } } public BarrierCollisionBox add(Location... location) 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 91c18093f..aa05e1f16 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 @@ -22,6 +22,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.siege.weapon.AccessRule; import mineplex.game.clans.clans.siege.weapon.AccessType; import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; @@ -142,6 +143,8 @@ public class Cannon extends SiegeWeapon @Override public void Fire(WeaponProjectile projectile) { + projectile.setLocation(projectile.getLocation().add(.5, .2, .5)); + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); } @@ -162,7 +165,6 @@ public class Cannon extends SiegeWeapon { if (getProjectile() != null) { - System.out.println("ye"); UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } } @@ -172,7 +174,26 @@ public class Cannon extends SiegeWeapon { int firepower = getPowerLevel(); - return new double[] { firepower, firepower }; + double hMult = 0; + double yAdd = 0; + + if (firepower == 1) + { + hMult = 0.6; + yAdd = 0.5; + } + else if (firepower == 2) + { + hMult = 1; + yAdd = 0.55; + } + else if (firepower >= 3) + { + hMult = 1.5; + yAdd = 0.6; + } + + return new double[] { hMult, yAdd }; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java deleted file mode 100644 index 6a92fb634..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonCrater.java +++ /dev/null @@ -1,162 +0,0 @@ -package mineplex.game.clans.clans.siege.cannon; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilBlock; -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.UtilServer; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClansManager; - -public class CannonCrater implements Listener -{ - private static final double EXPL_RADIUS = 3; - - public static final Material CHARRED_TYPE = Material.OBSIDIAN; - - private Cannon _host; - private Location _origin; - - private long _birthTime; - - private List _blocks; - - public CannonCrater(Cannon cannon, Location origin) - { - _host = cannon; - _origin = origin; - - _birthTime = System.currentTimeMillis(); - _blocks = new ArrayList<>(); - - UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); - - createExplosion(); - } - - @EventHandler - public void updateEffects(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - { - return; - } - - _blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> { - long lifetime = System.currentTimeMillis() - _birthTime; - - long max = 80000; - - if (block.Location.getBlock().getType() != CHARRED_TYPE) - { - return; - } - - // Water touching the charred blocks - if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext()) - { - return; - } - - if (lifetime < max) - { - UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX); - UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX); - } - else - { - HandlerList.unregisterAll(this); - } - }); - } - - private void createExplosion() - { - _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); - - HashMap blockList = new HashMap(); - int iR = (int) EXPL_RADIUS + 1; - - for (int x = -iR; x <= iR; x++) - { - for (int z = -iR; z <= iR; z++) - { - for (int y = -iR; y <= iR; y++) - { - Block curBlock = _origin.getBlock().getRelative(x, y, z); - - double offset = UtilMath.offset(_origin, curBlock.getLocation()); - - if (offset <= EXPL_RADIUS) - { - blockList.put(curBlock, offset); - } - } - } - } - - for (Entry entry : blockList.entrySet()) - { - Block block = entry.getKey(); - double distance = entry.getValue(); - - boolean air = distance <= 2 || (Math.random() > (distance) / 3.65d); - - if (block.getType() == Material.AIR) continue; - - if (air) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR)); - - Block above = block; - - while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) - { - _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); - } - } - } - - _blocks.forEach(CraterBlock::set); - - for (Entry entry : blockList.entrySet()) - { - Block block = entry.getKey(); - double distance = entry.getValue(); - - if (block.getType() == Material.AIR) continue; - - if ( - distance > 2 && - Math.random() > .75 && - UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && - !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && - !block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) && - !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); - } - } - - _blocks.forEach(CraterBlock::set); - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java deleted file mode 100644 index 8d15cd1c0..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java +++ /dev/null @@ -1,34 +0,0 @@ -package mineplex.game.clans.clans.siege.cannon; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public enum CannonState -{ - UNLOADED(Material.SPONGE, (byte) 1 /* wet sponge */), - LOADED(Material.SPONGE, (byte) 0 /* regular sponge */); - - private Material _material; - private byte _data; - - CannonState(Material material, byte data) - { - _material = material; - _data = data; - } - - public byte getData() - { - return _data; - } - - public Material getMaterial() - { - return _material; - } - - public ItemStack toItemStack() - { - return new ItemStack(_material, 1, (short) 0, _data); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java deleted file mode 100644 index 21f5b54b1..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CraterBlock.java +++ /dev/null @@ -1,32 +0,0 @@ -package mineplex.game.clans.clans.siege.cannon; - -import org.bukkit.Location; -import org.bukkit.Material; - -public class CraterBlock -{ - public Material Type; - public byte Data; - public double DistanceToOrigin; - - public Location Location; - - public CraterBlock(Location location, double dist, Material type, byte data) - { - Location = location; - DistanceToOrigin = dist; - Type = type; - Data = data; - } - - public CraterBlock(Location location, double dist, Material type) - { - this(location, dist, type, (byte) 0); - } - - public void set() - { - Location.getBlock().setType(Type); - Location.getBlock().setData(Data); - } -} 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 58e8b2a7f..73f2c5b3a 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 @@ -1,549 +1,205 @@ package mineplex.game.clans.clans.siege.catapult; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - 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.craftbukkit.v1_8_R3.entity.CraftArmorStand; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerArmorStandManipulateEvent; -import org.bukkit.event.player.PlayerInteractAtEntityEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.EulerAngle; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import mineplex.core.common.util.C; 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; import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; -import mineplex.core.common.util.UtilText; -import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; -import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; -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; +import mineplex.game.clans.clans.siege.weapon.AccessRule; +import mineplex.game.clans.clans.siege.weapon.AccessType; +import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes; +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.clans.siege.weapon.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.WeaponStateInfo; -public class Catapult implements Listener +public class Catapult extends SiegeWeapon { public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); - public static final int COOLDOWN = 10 * 1000 /* 20 seconds*/; - - public static final int MAX_CHARGES = 3; - public static final int MAX_COBBLE = 1; - - public static final double MAX_HEALTH = 600; - - public static final int COBBLE_SLOT = 4; - public static final List CHARGE_SLOTS = Arrays.asList(1, 3, 5, 7); - public static final List EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8); - - private static final double[] VERT_POWER = { 0.9, 1.25631, 1.5382 }; - private static final double[] HORIZ_POWER = { 1.2, 1.6241, 1.9231 }; - - private List _rotationPoints; - - private Location _location; - private CatapultState _state; - - private float _curYaw; - private float _nextYaw; - - // Entity Information - private List _entities; - - private CatapultProjectile _projectile; - - private Inventory _inventory; - - private long _lastFired = -1; - - private ClanInfo _clan; - - private double _health = MAX_HEALTH; - - private Hologram _healthHologram; - - private BarrierCollisionBox _collisionBox; - public Catapult(Location location, ClanInfo clan) { - _location = location; - _state = CatapultState.UNLOADED; + super(location, 600.d, "Catapult", clan, clan.Clans); - _rotationPoints = new ArrayList<>(); - _entities = new ArrayList<>(); + location.add(.5, 0, .5); - _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)); + setBoundingBox(1); - for (int i = 0; i < 20; i++) - { - _rotationPoints.add((360.f / 20.f) * i); - } + setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0)); + setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0)); + setStateInfo("Fired", new WeaponStateInfo(Material.LAPIS_BLOCK, (byte) 0)); - _inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Catapult"); + loadEntities(); - _clan = clan; + setFirepowerType(Material.FIREBALL); + setAmmunitionType(Material.COBBLESTONE); - _healthHologram = new Hologram(ClansManager.getInstance().getHologramManager(), location.clone().add(.5, 3.7, .5), "Catapult Health", getDisplayHealth()); - _healthHologram.start(); + setFirepowerSlots(1, 3, 5, 7); + setMaximumFirepowerPerSlot(3); - updateEntities(); - } - - public void cleanup() - { - _entities.forEach(Entity::remove); + setAmmunitionSlot(4); + setMaximumAmmunitionPerSlot(1); - _entities.clear(); + setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(1.5d)); - _healthHologram.stop(); - _healthHologram = null; - - _collisionBox.Destruct(); - - HandlerList.unregisterAll(this); - } - - private void updateEntities() - { - if (_entities.isEmpty()) - { - ArmorStand armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); - - UtilEnt.setFakeHead(armorStand, true); - armorStand.teleport(getArmorStandLocation()); - armorStand.setVisible(false); - armorStand.setGravity(false); - armorStand.setHelmet(_state.toItemStack()); - - _entities.add(armorStand); - } - else - { - getArmorStand().setHelmet(_state.toItemStack()); - } - } - - private CraftArmorStand getArmorStand() - { - return (CraftArmorStand) UtilMath.getFirst(_entities); - } - - private Location getArmorStandLocation() - { - return _location.clone().add(.5, -.65, .5); - } - - private void setState(CatapultState state) - { - _state = state; - updateEntities(); - } - - public void fire() - { - CatapultProjectile projectile = new CatapultProjectile(this, _location.clone().add(.5, 3, .5), Material.COBBLESTONE, (float) Math.toDegrees(getArmorStand().getHeadPose().getY())); - - _projectile = projectile; - - double vVel = VERT_POWER[getPower() - 1]; - double hMulti = HORIZ_POWER[getPower() - 1]; - - Vector velocity = UtilAlg.getTrajectory( - getArmorStand().getLocation(), - UtilAlg.moveForward( - getArmorStand().getLocation(), - 2., - (float) Math.toDegrees(getArmorStand().getHeadPose().getY()), true)) - .multiply(hMulti) - .setY(vVel); - - projectile.setVelocity(velocity); - - _inventory.setItem(COBBLE_SLOT, UtilInv.decrement(_inventory.getItem(COBBLE_SLOT))); - CHARGE_SLOTS.forEach(_inventory::clear); - - UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.BAT_TAKEOFF, 1.f, 1.f)); - - _lastFired = System.currentTimeMillis(); - } - - @EventHandler - public void onCloseInv(InventoryCloseEvent event) - { - if (!event.getInventory().equals(_inventory)) - { - return; - } - - ClansManager.getInstance().runSyncLater(() -> { - if (event.getPlayer().getInventory().equals(_inventory)) + setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { + if (!_owner.isMember(player)) { - return; + UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); + return false; } - if (canBeFired()) + if (!canBeFired()) { - UtilTextMiddle.display("Catapult Ready", "Power Level: " + C.cGreen + UtilText.repeat("▌", getPower()) + C.cRed + UtilText.repeat("▌", MAX_CHARGES - getPower()), 20, 100, 20, (Player) event.getPlayer()); - } - }, 3L); - } - - public void updateProjectile() - { - if (_projectile != null) - { - if (_projectile.dead()) - { - _projectile = null; - return; + UtilPlayer.message(player, F.main("Clans", "Catapult is not loaded correctly.")); + return false; } - UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); - } - } - - private void attemptFire(Player human) - { - if (!_clan.isMember(human)) - { - UtilPlayer.message(human, F.main("Clans", "This catapult is not owned by your Clan.")); - return; - } - - if (System.currentTimeMillis() - _lastFired < COOLDOWN) - { - UtilPlayer.message(human, F.main("Clans", "Catapult is cooling down. (" + F.time(UtilTime.MakeStr(COOLDOWN - (System.currentTimeMillis() - _lastFired)) + C.mBody + ")"))); - return; - } - - fire(); - } - - private void handleOpenInv(Player player) - { - if (_inventory == null) - { - cleanup(); - return; - } - - if (!_clan.isMember(player)) - { - UtilPlayer.message(player, F.main("Clans", "This catapult is not owned by your Clan.")); - return; - } - - if (!_inventory.getViewers().isEmpty()) - { - UtilPlayer.message(player, F.main("Clans", "Someone is already looking in this catapult.")); - return; - } - - player.openInventory(_inventory); - } - - private int getPower() - { - int power = 0; - - for (int slot : CHARGE_SLOTS) - { - if (_inventory.getItem(slot) != null) + if (System.currentTimeMillis() - _lastFired < 20000) { - power += _inventory.getItem(slot).getAmount(); - } - } - - return power / 4; - } - - private int getCobblestone() - { - return _inventory.getItem(COBBLE_SLOT) != null ? _inventory.getItem(COBBLE_SLOT).getAmount() : 0; - } - - private boolean canBeFired() - { - return getCobblestone() > 0 && getPower() > 0 && _projectile == null; - } - - @EventHandler - public void updateState(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - { - return; - } - - CatapultState newState = _inventory.getItem(COBBLE_SLOT) != null ? CatapultState.LOADED : CatapultState.UNLOADED; - - if ((System.currentTimeMillis() - _lastFired) <= 3000) - { - newState = CatapultState.FIRED; - } - - if (_state != newState) - { - setState(newState); - } - - if (!_inventory.getViewers().isEmpty()) - { - checkInv((Player) _inventory.getViewers().get(0)); - } - - updateProjectile(); - } - - public void checkInv(Player human) - { - for (int slot = 0; slot < 9; slot++) - { - ItemStack item = _inventory.getItem(slot); - - if (item == null) - { - continue; + UtilPlayer.message(player, F.main("Clans", "Catapult is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")")); + return false; } - if (slot == COBBLE_SLOT) + if (!isRiding(player)) { - if (item.getType() != Material.COBBLESTONE) - { - human.getInventory().addItem(item); - _inventory.setItem(slot, null); - } - else - { - if (item.getAmount() > MAX_CHARGES) - { - human.getInventory().addItem(new ItemStack(Material.COBBLESTONE, item.getAmount() - MAX_COBBLE)); - _inventory.setItem(slot, new ItemStack(Material.COBBLESTONE, MAX_COBBLE)); - } - } + return false; } - else if (CHARGE_SLOTS.contains(slot)) + + return true; + })); + + enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); + + setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { + if (!_owner.isMember(player)) { - if (item.getType() != Material.FIREBALL) - { - human.getInventory().addItem(item); - _inventory.setItem(slot, null); - } - else - { - if (item.getAmount() > MAX_CHARGES) - { - human.getInventory().addItem(new ItemStack(Material.FIREBALL, item.getAmount() - MAX_CHARGES)); - _inventory.setItem(slot, new ItemStack(Material.FIREBALL, MAX_CHARGES)); - } - } + UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); + return false; } - else if (EMPTY_SLOTS.contains(slot)) // also classes as just an 'else{}' + + if (getRider() != null && !getRider().equals(player)) { - human.getInventory().addItem(item); - _inventory.setItem(slot, null); + UtilPlayer.message(player, F.main("Clans", "Someone is already riding this Catapult.")); + return false; } + + return !player.equals(getRider()); + })); + + System.out.println("Cannon initialized."); + } + + private void loadEntities() + { + Slime slime = _location.getWorld().spawn(_location, Slime.class); + + UtilEnt.silence(slime, true); + UtilEnt.Vegetate(slime); + + slime.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + addEntity(slime, "Filler"); + + slime = _location.getWorld().spawn(_location, Slime.class); + + UtilEnt.silence(slime, true); + UtilEnt.Vegetate(slime); + + slime.setSize(-1); + slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + getEntity("Filler").setPassenger(slime); + addEntity(slime, "PLAYERMOUNT"); + + ArmorStand armorStand = _location.getWorld().spawn(_location, ArmorStand.class); + + UtilEnt.setFakeHead(armorStand, true); + armorStand.teleport(_location); + armorStand.setVisible(false); + armorStand.setGravity(false); + + armorStand.setPassenger(getEntity("Filler")); + + addEntity(armorStand, "WEAPON"); + } + + @Override + public void Fire(WeaponProjectile projectile) + { + projectile.setLocation(projectile.getLocation().add(.5, .2, .5)); + + UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); + } + + @Override + public String getNextState() + { + if (System.currentTimeMillis() - _lastFired < 4500) + { + return "Fired"; + } + + if (getAmmunition() > 0) + { + return "Loaded"; + } + + return "Unloaded"; + } + + @Override + protected void Tick() + { + if (getProjectile() != null) + { + UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } } - @EventHandler - public void onInteract(PlayerInteractAtEntityEvent event) - { - if (_entities.contains(event.getRightClicked())) + @Override + protected double[] getProjectileVelocity() + { + int firepower = getPowerLevel(); + + double hMult = 0; + double yAdd = 0; + + if (firepower == 1) { - handleOpenInv(event.getPlayer()); - event.setCancelled(true); + hMult = 0.6; + yAdd = 0.8; } + else if (firepower == 2) + { + hMult = 1; + yAdd = 1.2; + } + else if (firepower >= 3) + { + hMult = 1.5; + yAdd = 1.35; + } + + return new double[] { hMult, yAdd }; } - @EventHandler - public void onInteract(PlayerInteractEntityEvent event) - { - if (_entities.contains(event.getRightClicked())) - { - handleOpenInv(event.getPlayer()); - event.setCancelled(true); - } - } - - @EventHandler - public void onInteract(PlayerArmorStandManipulateEvent event) - { - if (_entities.contains(event.getRightClicked())) - { - handleOpenInv(event.getPlayer()); - event.setCancelled(true); - } - } - - 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) - { - if (event.getType() != UpdateType.TICK) - { - return; - } - - ArmorStand armorStand = getArmorStand(); - double standYaw = _curYaw % 360; - double nextYaw = _nextYaw % 360; - - // riderYaw = 350 and standYaw = 20 - // dif should be -30 and not 330 - double dif = nextYaw - standYaw; - if (dif > 180) dif -= 360; - if (dif < -180) dif += 360; - - _curYaw = (float) (standYaw + Math.min(dif / 10.f, 4f)); - - armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(_curYaw), 0)); - } - - @EventHandler - public void onDamage(EntityDamageEvent event) - { - if (_entities.contains(event.getEntity())) - { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onDmg(EntityDamageByEntityEvent event) - { - if (!(event.getDamager() instanceof Player)) - { - return; - } - - if (!_entities.contains(event.getEntity())) - { - return; - } - - if (!_clan.isMember((Player) event.getDamager())) - { - removeHealth(event.getFinalDamage()); - } - - if (!_clan.isMember((Player) event.getDamager())) - { - UtilPlayer.message((Player) event.getDamager(), F.main("Clans", "This catapult is not owned by your Clan.")); - return; - } - - if (canBeFired()) - attemptFire((Player) event.getDamager()); - else - _nextYaw = ((Player) event.getDamager()).getLocation().getYaw(); - } - - // Health Managemnet - public double getHealth() - { - return _health; - } - - public String getDisplayHealth() - { - return UtilText.getProgress(null, _health / MAX_HEALTH, null, false, 12); - } - - public void setHealth(double health) - { - _health = UtilMath.clamp(health, 0, MAX_HEALTH); - - _healthHologram.setText("Catapult Health", getDisplayHealth()); - - if (_health == 0) - { - cleanup(); - } - } - - public void removeHealth(double health) - { - setHealth(_health - health); - } - - public void addHealth(double health) - { - setHealth(_health + health); - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java deleted file mode 100644 index 221c6ff0c..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultCrater.java +++ /dev/null @@ -1,163 +0,0 @@ -package mineplex.game.clans.clans.siege.catapult; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilBlock; -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.UtilServer; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.siege.cannon.CraterBlock; - -public class CatapultCrater implements Listener -{ - private static final double EXPL_RADIUS = 3; - - public static final Material CHARRED_TYPE = Material.OBSIDIAN; - - private Catapult _host; - private Location _origin; - - private long _birthTime; - - private List _blocks; - - public CatapultCrater(Catapult cannon, Location origin) - { - _host = cannon; - _origin = origin; - - _birthTime = System.currentTimeMillis(); - _blocks = new ArrayList<>(); - - UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); - - createExplosion(); - } - - @EventHandler - public void updateEffects(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - { - return; - } - - _blocks.stream().filter(block -> block.Type == CHARRED_TYPE).forEach(block -> { - long lifetime = System.currentTimeMillis() - _birthTime; - - long max = 80000; - - if (block.Location.getBlock().getType() != CHARRED_TYPE) - { - return; - } - - // Water touching the charred blocks - if (UtilBlock.getInRadius(block.Location, 1.6).keySet().stream().filter(water -> water.getType() == Material.WATER).iterator().hasNext()) - { - return; - } - - if (lifetime < max) - { - UtilParticle.PlayParticleToAll(ParticleType.FLAME, block.Location.clone().add(.5, 1, .5), new Vector(0, 0, 0), .0f, 3, ViewDist.MAX); - UtilParticle.PlayParticleToAll(lifetime >= max / 1.4 ? ParticleType.SMOKE : ParticleType.LARGE_SMOKE, block.Location.clone().add(.5, .8, .5), new Vector(0, 0, 0), .0f, 1, ViewDist.MAX); - } - else - { - HandlerList.unregisterAll(this); - } - }); - } - - private void createExplosion() - { - _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); - - HashMap blockList = new HashMap(); - int iR = (int) EXPL_RADIUS + 1; - - for (int x = -iR; x <= iR; x++) - { - for (int z = -iR; z <= iR; z++) - { - for (int y = -iR; y <= iR; y++) - { - Block curBlock = _origin.getBlock().getRelative(x, y, z); - - double offset = UtilMath.offset(_origin, curBlock.getLocation()); - - if (offset <= EXPL_RADIUS) - { - blockList.put(curBlock, offset); - } - } - } - } - - for (Entry entry : blockList.entrySet()) - { - Block block = entry.getKey(); - double distance = entry.getValue(); - - boolean air = distance <= 1.5 || (Math.random() > (distance) / 3.65d); - - if (block.getType() == Material.AIR) continue; - - if (air) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, Material.AIR)); - - Block above = block; - - while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType())) - { - _blocks.add(new CraterBlock(above.getLocation(), distance, Material.AIR)); - } - } - } - - _blocks.forEach(CraterBlock::set); - - for (Entry entry : blockList.entrySet()) - { - Block block = entry.getKey(); - double distance = entry.getValue(); - - if (block.getType() == Material.AIR) continue; - - if ( - distance > 1 && - Math.random() > .85 && - UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()) && - !UtilItem.isBoundless(block.getRelative(BlockFace.DOWN).getType()) && - !block.getRelative(BlockFace.UP).getType().equals(CHARRED_TYPE) && - !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) - { - _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); - _blocks.add(new CraterBlock(block.getLocation().clone().add(0, 1, 0), distance, Material.FIRE)); - } - } - - _blocks.forEach(CraterBlock::set); - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java deleted file mode 100644 index 4f5703cd3..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultProjectile.java +++ /dev/null @@ -1,97 +0,0 @@ -package mineplex.game.clans.clans.siege.catapult; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.FallingBlock; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.util.Vector; - -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilItem; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilServer; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClansManager; - -public class CatapultProjectile implements Listener -{ - private FallingBlock _sand; - - private Catapult _host; - - public CatapultProjectile(Catapult host, Location location, Material material, float yaw) - { - _host = host; - _sand = location.getWorld().spawnFallingBlock(location, material, (byte) 0); - _sand.setDropItem(false); - - UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); - } - - @EventHandler - public void update(UpdateEvent event) - { - if (_sand.getTicksLived() >= 20 && UtilBlock.getInRadius(_sand.getLocation(), 1.5).keySet().stream().filter(block -> !UtilItem.isBoundless(block.getType())).iterator().hasNext() && Math.abs(_sand.getVelocity().getX()) < 0.05 || Math.abs(_sand.getVelocity().getZ()) < 0.05) - { - remove(); - } - else if (_sand.isDead()) - { - remove(); - } - } - - @EventHandler - public void onBlockFall(EntityChangeBlockEvent event) - { - if (event.getEntity().equals(_sand)) - { - event.setCancelled(true); - - remove(); - } - } - - public void remove() - { - HandlerList.unregisterAll(this); - - UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getLocation(), Sound.EXPLODE, 1.f, 1.f)); - - new CatapultCrater(_host, _sand.getLocation()); - - _sand.remove(); - _sand = null; - } - - public boolean dead() - { - return _sand == null || _sand.isDead(); - } - - public Location getLocation() - { - return _sand.getLocation(); - } - - public Vector getVelocity() - { - return _sand.getVelocity(); - } - - public int getTicksLived() - { - return _sand.getTicksLived(); - } - - public void setVelocity(Vector velocity) - { - _sand.setVelocity(velocity); - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java deleted file mode 100644 index 3cbc3a7e0..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/CatapultState.java +++ /dev/null @@ -1,35 +0,0 @@ -package mineplex.game.clans.clans.siege.catapult; - -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; - -public enum CatapultState -{ - UNLOADED(Material.PACKED_ICE, (byte) 0), - LOADED(Material.ENDER_PORTAL_FRAME, (byte) 0), - FIRED(Material.LAPIS_BLOCK, (byte) 1); - - private Material _material; - private byte _data; - - CatapultState(Material material, byte data) - { - _material = material; - _data = data; - } - - public byte getData() - { - return _data; - } - - public Material getMaterial() - { - return _material; - } - - public ItemStack toItemStack() - { - return new ItemStack(_material, 1, (short) 0, _data); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessRule.java similarity index 78% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessRule.java index 1ffa94e58..f740f6665 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/AccessRule.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessRule.java @@ -1,11 +1,9 @@ -package mineplex.game.clans.clans.siege.cannon; +package mineplex.game.clans.clans.siege.weapon; import java.util.function.Predicate; import org.bukkit.entity.Player; -import mineplex.game.clans.clans.siege.weapon.AccessType; - public class AccessRule { private Predicate _access; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index e758ba1ea..bace470f0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -38,7 +38,6 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.BarrierCollisionBox; -import mineplex.game.clans.clans.siege.cannon.AccessRule; public abstract class SiegeWeapon implements Listener { @@ -180,7 +179,10 @@ public abstract class SiegeWeapon implements Listener protected boolean canBeFired() { - return getPowerLevel() > 0 && _projectile == null; + + System.out.println(getPowerLevel()); + System.out.println(getAmmunition()); + return getPowerLevel() > 0 && getAmmunition() > 0 && _projectile == null; } protected WeaponProjectile getProjectile() @@ -260,7 +262,7 @@ public abstract class SiegeWeapon implements Listener { ItemStack item = _inventory.getItem(slot); - if (item == null || !item.getType().equals(_ammunitionType)) + if (item == null || !item.getType().equals(_firepowerType)) { continue; } @@ -268,11 +270,7 @@ public abstract class SiegeWeapon implements Listener power += _inventory.getItem(slot).getAmount(); } - - if (UtilMath.isOdd(power)) - { - power -= 4; - } + System.out.println("Power: " + power); return power / 4; } @@ -350,7 +348,7 @@ public abstract class SiegeWeapon implements Listener return; } - if (_fireAccess.allow(AccessType.RCLICK_BB, player) && canBeFired()) + if (_fireAccess.allow(AccessType.RCLICK_BB, player)) { fire(player); } @@ -372,7 +370,7 @@ public abstract class SiegeWeapon implements Listener return; } - if (_fireAccess.allow(AccessType.LCLICK_BB, player) && canBeFired()) + if (_fireAccess.allow(AccessType.LCLICK_BB, player)) { fire(player); return; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java index 31971c921..b2d527368 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java @@ -19,7 +19,6 @@ import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.siege.cannon.CannonCrater; public class WeaponProjectile implements Listener { From 0cb557d9221d8433cea8c71e64813f7051d80265 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 17:02:06 +0000 Subject: [PATCH 054/122] moved some stuff around and slight changes --- .../game/clans/clans/siege/SiegeManager.java | 4 +- .../siege/outpost/CommandSiegeSupplies.java | 4 +- .../clans/clans/siege/outpost/Outpost.java | 2 +- .../clans/clans/siege/weapon/AccessType.java | 7 -- .../siege/{cannon => weapon}/Cannon.java | 15 ++--- .../siege/{catapult => weapon}/Catapult.java | 23 ++++--- .../clans/clans/siege/weapon/SiegeWeapon.java | 67 ++++++++++++++----- .../siege/weapon/{ => projectile}/Crater.java | 5 +- .../weapon/{ => projectile}/CraterBlock.java | 2 +- .../ProjectileAttributes.java | 2 +- .../{ => projectile}/ProjectileType.java | 2 +- .../{ => projectile}/WeaponProjectile.java | 11 +-- .../siege/weapon/{ => util}/AccessRule.java | 2 +- .../clans/siege/weapon/util/AccessType.java | 7 ++ .../util}/BarrierCollisionBox.java | 4 +- .../weapon/{ => util}/WeaponStateInfo.java | 2 +- 16 files changed, 93 insertions(+), 66 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/{cannon => weapon}/Cannon.java (91%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/{catapult => weapon}/Catapult.java (89%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => projectile}/Crater.java (95%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => projectile}/CraterBlock.java (90%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => projectile}/ProjectileAttributes.java (95%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => projectile}/ProjectileType.java (50%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => projectile}/WeaponProjectile.java (93%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => util}/AccessRule.java (87%) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessType.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/{ => weapon/util}/BarrierCollisionBox.java (98%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/{ => util}/WeaponStateInfo.java (85%) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index b348a32bb..2f8c8e4e6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -11,10 +11,10 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.siege.cannon.Cannon; -import mineplex.game.clans.clans.siege.catapult.Catapult; import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.outpost.OutpostManager; +import mineplex.game.clans.clans.siege.weapon.Cannon; +import mineplex.game.clans.clans.siege.weapon.Catapult; public class SiegeManager extends MiniPlugin { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java index 86ed92e0d..4de674758 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java @@ -7,8 +7,8 @@ import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.game.clans.clans.siege.cannon.Cannon; -import mineplex.game.clans.clans.siege.catapult.Catapult; +import mineplex.game.clans.clans.siege.weapon.Cannon; +import mineplex.game.clans.clans.siege.weapon.Catapult; public class CommandSiegeSupplies extends CommandBase { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 473b54a4c..1a6be7234 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -48,7 +48,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; -import mineplex.game.clans.clans.siege.cannon.Cannon; +import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java deleted file mode 100644 index aafb8c9d4..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessType.java +++ /dev/null @@ -1,7 +0,0 @@ -package mineplex.game.clans.clans.siege.weapon; - -public enum AccessType -{ - RCLICK_BB, - LCLICK_BB, -} 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/weapon/Cannon.java similarity index 91% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index aa05e1f16..4b55a9df5 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/weapon/Cannon.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.cannon; +package mineplex.game.clans.clans.siege.weapon; import org.bukkit.Location; import org.bukkit.Material; @@ -22,12 +22,11 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; -import mineplex.game.clans.clans.siege.weapon.AccessRule; -import mineplex.game.clans.clans.siege.weapon.AccessType; -import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes; -import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; -import mineplex.game.clans.clans.siege.weapon.WeaponProjectile; -import mineplex.game.clans.clans.siege.weapon.WeaponStateInfo; +import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; +import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.util.AccessRule; +import mineplex.game.clans.clans.siege.weapon.util.AccessType; +import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; public class Cannon extends SiegeWeapon { @@ -101,8 +100,6 @@ public class Cannon extends SiegeWeapon return !player.equals(getRider()); })); - - System.out.println("Cannon initialized."); } private void loadEntities() 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/weapon/Catapult.java similarity index 89% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/catapult/Catapult.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 73f2c5b3a..2212608c5 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/weapon/Catapult.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.catapult; +package mineplex.game.clans.clans.siege.weapon; import org.bukkit.Location; import org.bukkit.Material; @@ -22,12 +22,11 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; -import mineplex.game.clans.clans.siege.weapon.AccessRule; -import mineplex.game.clans.clans.siege.weapon.AccessType; -import mineplex.game.clans.clans.siege.weapon.ProjectileAttributes; -import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; -import mineplex.game.clans.clans.siege.weapon.WeaponProjectile; -import mineplex.game.clans.clans.siege.weapon.WeaponStateInfo; +import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; +import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.util.AccessRule; +import mineplex.game.clans.clans.siege.weapon.util.AccessType; +import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; public class Catapult extends SiegeWeapon { @@ -56,7 +55,7 @@ public class Catapult extends SiegeWeapon setAmmunitionSlot(4); setMaximumAmmunitionPerSlot(1); - setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(1.5d)); + setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d)); setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { if (!_owner.isMember(player)) @@ -102,8 +101,6 @@ public class Catapult extends SiegeWeapon return !player.equals(getRider()); })); - - System.out.println("Cannon initialized."); } private void loadEntities() @@ -141,6 +138,12 @@ public class Catapult extends SiegeWeapon addEntity(armorStand, "WEAPON"); } + @Override + public float Rotate(float nextYaw) + { + return nextYaw + 180; + } + @Override public void Fire(WeaponProjectile projectile) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index bace470f0..ef6e3967b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -37,7 +37,12 @@ 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.siege.BarrierCollisionBox; +import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; +import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.util.AccessRule; +import mineplex.game.clans.clans.siege.weapon.util.AccessType; +import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox; +import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; public abstract class SiegeWeapon implements Listener { @@ -83,12 +88,13 @@ public abstract class SiegeWeapon implements Listener private ProjectileAttributes _projectileAttributes; private WeaponProjectile _projectile; + private long _lastRight = -1; + private long _lastLeft = -1; + protected long _lastFired; public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager) { - System.out.println("Siege Weapon initializing."); - _location = location; _name = name; _health = _maxHealth = maxHealth; @@ -106,6 +112,11 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; } + public ClansManager getClans() + { + return _clans; + } + protected void damage(Player player) { @@ -169,7 +180,7 @@ public abstract class SiegeWeapon implements Listener if (dif > 180) dif -= 360; if (dif < -180) dif += 360; - double yaw = standYaw + Math.min(dif / 20.f, 4f); + double yaw = Rotate((float) ((float)standYaw + Math.min(dif / 20.f, 4f))); armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); } @@ -179,9 +190,6 @@ public abstract class SiegeWeapon implements Listener protected boolean canBeFired() { - - System.out.println(getPowerLevel()); - System.out.println(getAmmunition()); return getPowerLevel() > 0 && getAmmunition() > 0 && _projectile == null; } @@ -192,7 +200,6 @@ public abstract class SiegeWeapon implements Listener private void fire(Player player) { - System.out.println("Firing siege weapon..."); _lastFired = System.currentTimeMillis(); double[] vel = getProjectileVelocity(); @@ -270,8 +277,6 @@ public abstract class SiegeWeapon implements Listener power += _inventory.getItem(slot).getAmount(); } - System.out.println("Power: " + power); - return power / 4; } @@ -320,7 +325,6 @@ public abstract class SiegeWeapon implements Listener private void handleMount(Player player) { - System.out.println("handling mount"); getEntity("PLAYERMOUNT").setPassenger(player); OnMount(player); } @@ -332,9 +336,21 @@ public abstract class SiegeWeapon implements Listener private void handleRightClick(Player player) { - RightClick(player); + if (_lastRight == -1) + { + _lastRight = System.currentTimeMillis(); + } + else + { + if (System.currentTimeMillis() - _lastRight <= 40) + { + return; + } + } - System.out.println("handling right click"); + _lastRight = System.currentTimeMillis(); + + RightClick(player); if (_isRideable && _mountAccess.allow(AccessType.RCLICK_BB, player)) { @@ -356,6 +372,20 @@ public abstract class SiegeWeapon implements Listener private void handleLeftClick(Player player) { + if (_lastLeft == -1) + { + _lastLeft = System.currentTimeMillis(); + } + else + { + if (System.currentTimeMillis() - _lastLeft <= 40) + { + return; + } + } + + _lastLeft = System.currentTimeMillis(); + LeftClick(player); if (_isRideable && _mountAccess.allow(AccessType.LCLICK_BB, player)) @@ -412,6 +442,11 @@ public abstract class SiegeWeapon implements Listener { } + protected float Rotate(float yaw) + { + return yaw; + } + // Entity Management protected final void addEntity(Entity entity, String uniqueName) @@ -466,8 +501,6 @@ public abstract class SiegeWeapon implements Listener { Validate.isTrue(_registeredStates.containsKey(state), "Provided state has not yet been registered."); - System.out.println("Updating siege weapon state"); - ((ArmorStand) getEntity("WEAPON")).setHelmet(new ItemStack(_registeredStates.get(state).getType(), 1, (short) 0, (byte) _registeredStates.get(state).getData())); _currentState = state; @@ -527,14 +560,14 @@ public abstract class SiegeWeapon implements Listener { if (getRider() != null) { - getRider().getInventory().addItem(new ItemStack(Material.TNT, item.getAmount() - _maxAmmunition)); + getRider().getInventory().addItem(new ItemStack(_ammunitionType, item.getAmount() - _maxAmmunition)); } else { _location.getWorld().dropItem(_location, item); } - _inventory.setItem(slot, new ItemStack(Material.TNT, _maxAmmunition)); + _inventory.setItem(slot, new ItemStack(_ammunitionType, _maxAmmunition)); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java similarity index 95% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java index acb732940..d1c2bd242 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Crater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.projectile; import java.util.ArrayList; import java.util.HashMap; @@ -23,6 +23,7 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; public class Crater implements Listener { @@ -52,7 +53,7 @@ public class Crater implements Listener _airChance = airChance; _fire = doFire; - UtilServer.getPluginManager().registerEvents(this, _weapon._clans.getPlugin()); + UtilServer.getPluginManager().registerEvents(this, _weapon.getClans().getPlugin()); createExplosion(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/CraterBlock.java similarity index 90% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/CraterBlock.java index e770cfb58..e8ff4058b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/CraterBlock.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/CraterBlock.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.projectile; import org.bukkit.Location; import org.bukkit.Material; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/ProjectileAttributes.java similarity index 95% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/ProjectileAttributes.java index 7b5e94013..bbb6ffa7c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileAttributes.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/ProjectileAttributes.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.projectile; import org.bukkit.Material; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/ProjectileType.java similarity index 50% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/ProjectileType.java index 0f364ee89..018255e8f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/ProjectileType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/ProjectileType.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.projectile; public enum ProjectileType { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java similarity index 93% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java index b2d527368..70fb2b4f2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.projectile; import org.bukkit.Location; import org.bukkit.Sound; @@ -19,6 +19,7 @@ import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; public class WeaponProjectile implements Listener { @@ -43,11 +44,9 @@ public class WeaponProjectile implements Listener _yVel = yVel; _xMulti = xMulti; - UtilServer.getPluginManager().registerEvents(this, weapon._clans.getPlugin()); + UtilServer.getPluginManager().registerEvents(this, weapon.getClans().getPlugin()); spawn(); - - System.out.println("New Projectile"); } @EventHandler(priority = EventPriority.HIGHEST) @@ -168,9 +167,5 @@ public class WeaponProjectile implements Listener tnt.setVelocity(velocity); } - else - { - System.out.println("==== SIEGE WEAPON PROJECTILE ATTRIBUTES DOES NOT SPECIFY ENTITY TYPE ===="); - } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessRule.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessRule.java similarity index 87% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessRule.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessRule.java index f740f6665..b1eb7b37d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/AccessRule.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessRule.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.util; import java.util.function.Predicate; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessType.java new file mode 100644 index 000000000..6fccb310d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/AccessType.java @@ -0,0 +1,7 @@ +package mineplex.game.clans.clans.siege.weapon.util; + +public enum AccessType +{ + RCLICK_BB, + LCLICK_BB, +} 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/weapon/util/BarrierCollisionBox.java similarity index 98% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/BarrierCollisionBox.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/BarrierCollisionBox.java index 82343e0f2..3d5dcb0cf 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/BarrierCollisionBox.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/BarrierCollisionBox.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege; +package mineplex.game.clans.clans.siege.weapon.util; import java.util.ArrayList; import java.util.Arrays; @@ -123,8 +123,6 @@ public class BarrierCollisionBox implements Listener { for (Location other : _collisionBlocks) { - System.out.println(other + " : " + location); - if (other.equals(location)) { return true; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/WeaponStateInfo.java similarity index 85% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/WeaponStateInfo.java index 917035f38..b0eae35e7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/WeaponStateInfo.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/WeaponStateInfo.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.weapon; +package mineplex.game.clans.clans.siege.weapon.util; import org.bukkit.Material; From 4488b73e93c132bb6582aa396fcb5fe393472f16 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 17:02:31 +0000 Subject: [PATCH 055/122] change catapult bounding box to 3 --- .../src/mineplex/game/clans/clans/siege/weapon/Catapult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 2212608c5..2ec61ea7b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -38,7 +38,7 @@ public class Catapult extends SiegeWeapon location.add(.5, 0, .5); - setBoundingBox(1); + setBoundingBox(3); setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0)); setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0)); From 4e2da061bb8f5a652ea737de120689959fd14309 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 17:07:06 +0000 Subject: [PATCH 056/122] added protection around siege weapon --- .../clans/clans/siege/weapon/SiegeWeapon.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index ef6e3967b..a6a4ae1b9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -13,9 +13,9 @@ 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.BlockBreakEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -28,7 +28,9 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import mineplex.core.common.util.C; +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.UtilText; import mineplex.core.common.util.UtilTextMiddle; @@ -85,6 +87,8 @@ public abstract class SiegeWeapon implements Listener private int _maxAmmunition; private int _maxFirepowerPerSlot; + private int _boundingBoxSize; + private ProjectileAttributes _projectileAttributes; private WeaponProjectile _projectile; @@ -137,6 +141,8 @@ public abstract class SiegeWeapon implements Listener Validate.isTrue(size > 0, "Size must be a positive number."); Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number."); + _boundingBoxSize = size; + _collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .5, size - 1, ((size - 1) / 2) + .5)); _collisionBox.Construct(); _collisionBox.registerRight((block, player) -> handleRightClick(player)); @@ -685,6 +691,16 @@ public abstract class SiegeWeapon implements Listener } } + @EventHandler + public void onBlockBreak(BlockBreakEvent event) + { + if (event.getBlock().getLocation().distance(_location) < _boundingBoxSize + 1.65 && event.getBlock().getLocation().getY() <= _location.getY()) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks under a Siege Weapon")); + event.setCancelled(true); + } + } + @EventHandler public void onInteract(PlayerArmorStandManipulateEvent event) { From c17849b75135db1ec0637a9191d3841979c9af37 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 3 Feb 2016 17:30:07 +0000 Subject: [PATCH 057/122] fixed some autoboxing stuff --- .../src/mineplex/game/clans/clans/siege/weapon/Cannon.java | 2 +- .../mineplex/game/clans/clans/siege/weapon/Catapult.java | 2 +- .../mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 4b55a9df5..28253d311 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -48,7 +48,7 @@ public class Cannon extends SiegeWeapon setFirepowerType(Material.SULPHUR); setAmmunitionType(Material.TNT); - setFirepowerSlots(1, 3, 5, 7); + setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7)); setMaximumFirepowerPerSlot(3); setAmmunitionSlot(4); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 2ec61ea7b..ee0d7d4da 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -49,7 +49,7 @@ public class Catapult extends SiegeWeapon setFirepowerType(Material.FIREBALL); setAmmunitionType(Material.COBBLESTONE); - setFirepowerSlots(1, 3, 5, 7); + setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7)); setMaximumFirepowerPerSlot(3); setAmmunitionSlot(4); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index a6a4ae1b9..558dee7ab 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -69,7 +69,7 @@ public abstract class SiegeWeapon implements Listener private final List _comprisedOf; // Friendly-name mapping to index in _comprisedOf for easier management of entities. - private final Map _entityMapping; + private final Map _entityMapping; private boolean _isRideable; private AccessRule _mountAccess; @@ -459,12 +459,12 @@ public abstract class SiegeWeapon implements Listener { _comprisedOf.add(entity); - _entityMapping.put(uniqueName, _comprisedOf.size() - 1); + _entityMapping.put(uniqueName, entity); } protected final Entity getEntity(String uniqueName) { - return _comprisedOf.get(_entityMapping.get(uniqueName)); + return _entityMapping.get(uniqueName); } // Health Management From b13494f399f5b931e3464461c14b3532b02c40c8 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 16:00:41 +0000 Subject: [PATCH 058/122] more modifications to siege weapons. --- .../mineplex/core/common/util/UtilBlock.java | 7 +- .../game/clans/clans/siege/SiegeManager.java | 33 +++++- .../siege/events/SiegeWeaponExplodeEvent.java | 53 +++++++++ .../clans/clans/siege/outpost/Outpost.java | 50 +++++++++ .../game/clans/clans/siege/weapon/Cannon.java | 17 +-- .../clans/clans/siege/weapon/Catapult.java | 32 +++--- .../clans/clans/siege/weapon/SiegeWeapon.java | 103 ++++++++++++++++-- .../clans/siege/weapon/projectile/Crater.java | 19 +++- .../weapon/projectile/WeaponProjectile.java | 10 +- 9 files changed, 282 insertions(+), 42 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/events/SiegeWeaponExplodeEvent.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index 611170f37..c6db06459 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -466,7 +466,12 @@ public class UtilBlock public static Block getHighest(World world, Location location) { - return getHighest(world, location.getBlockX(), location.getBlockZ(), null); + return getHighest(world, location.getBlockX(), location.getBlockZ()); + } + + public static Block getHighest(World world, Block block) + { + return getHighest(world, block.getLocation()); } public static Block getHighest(World world, int x, int z, HashSet ignore) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 2f8c8e4e6..0a09d01e7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,6 +1,10 @@ package mineplex.game.clans.clans.siege; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPlaceEvent; @@ -15,6 +19,7 @@ import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; public class SiegeManager extends MiniPlugin { @@ -22,6 +27,10 @@ public class SiegeManager extends MiniPlugin private OutpostManager _outpostManager; + public static SiegeManager Instance; + + public List LiveSiegeWeapons = new ArrayList<>(); + public SiegeManager(JavaPlugin plugin, ClansManager clans) { super("Siege", plugin); @@ -31,6 +40,8 @@ public class SiegeManager extends MiniPlugin _outpostManager = new OutpostManager(clans, this); addCommand(new CommandSiegeSupplies(_outpostManager)); + + Instance = this; } @EventHandler @@ -86,7 +97,7 @@ public class SiegeManager extends MiniPlugin public void spawnCannon(Player player, Location location) { - new Cannon(location, _clans.getClan(player)); + new Cannon(location, _clans.getClan(player), this); } public boolean trySpawnCatapult(Player player, Location location) @@ -116,8 +127,26 @@ public class SiegeManager extends MiniPlugin public void spawnCatapult(Player player, Location location) { - Catapult catapult = new Catapult(location, _clans.getClan(player)); + Catapult catapult = new Catapult(location, _clans.getClan(player), this); _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(catapult, _outpostManager.getPlugin()); } + + public void dead(SiegeWeapon weapon) + { + LiveSiegeWeapons.remove(weapon); + } + + public SiegeWeapon close(Block block) + { + for (SiegeWeapon weapon : LiveSiegeWeapons) + { + if (weapon.getLocation().distance(block.getLocation()) <= weapon.getSize() + 3.d) + { + return weapon; + } + } + + return null; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/events/SiegeWeaponExplodeEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/events/SiegeWeaponExplodeEvent.java new file mode 100644 index 000000000..c0bec7a14 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/events/SiegeWeaponExplodeEvent.java @@ -0,0 +1,53 @@ +package mineplex.game.clans.clans.siege.events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; + +public class SiegeWeaponExplodeEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private SiegeWeapon _weapon; + private WeaponProjectile _projectile; + + private boolean _cancelled; + + public SiegeWeaponExplodeEvent(SiegeWeapon weapon, WeaponProjectile projectile) + { + _weapon = weapon; + _projectile = projectile; + } + + public SiegeWeapon getWeapon() + { + return _weapon; + } + + public WeaponProjectile getProjectile() + { + return _projectile; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 1a6be7234..fe70e3e8c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -48,6 +48,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.core.repository.ClanTerritory; @@ -97,6 +98,9 @@ public class Outpost implements Listener private long _spawnTime; + public double _maxHealth = 4500; + public double _health = _maxHealth; + public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) { _host = host; @@ -468,6 +472,20 @@ public class Outpost implements Listener _clan.inform("Your Clan's Outpost has been destroyed.", null); } + @EventHandler + public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) + { + if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _startCorner.clone().subtract(4, 2, 4), _endCorner.clone().add(4, 2, 4))) + { + if (getHealth() > 700) + { + event.setCancelled(true); + } + + removeHealth(800); + } + } + public ClanInfo getClan() { return _clan; @@ -503,4 +521,36 @@ public class Outpost implements Listener { return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd.clone().add(.9, 0, .9)); } + + // Health Management + + public final double getHealth() + { + return _health; + } + + public final String getDisplayHealth() + { + return UtilText.getProgress(null, _health / _maxHealth, null, false, 12); + } + + public final void setHealth(double health) + { + _health = UtilMath.clamp(health, 0, _maxHealth); + + if (_health == 0) + { + kill(); + } + } + + public final void removeHealth(double health) + { + setHealth(_health - health); + } + + public final void addHealth(double health) + { + setHealth(_health + health); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 28253d311..5b20f80b7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -22,6 +22,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -32,9 +33,9 @@ public class Cannon extends SiegeWeapon { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); - public Cannon(Location location, ClanInfo clan) + public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager) { - super(location, 600.d, "Cannon", clan, clan.Clans); + super(location, 1200.d, "Cannon", clan, clan.Clans, siegeManager); location.add(.5, 0, .5); @@ -57,6 +58,11 @@ public class Cannon extends SiegeWeapon setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d)); setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { + if (!isRiding(player)) + { + return false; + } + if (!_owner.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); @@ -75,11 +81,6 @@ public class Cannon extends SiegeWeapon return false; } - if (!isRiding(player)) - { - return false; - } - return true; })); @@ -140,7 +141,7 @@ public class Cannon extends SiegeWeapon @Override public void Fire(WeaponProjectile projectile) { - projectile.setLocation(projectile.getLocation().add(.5, .2, .5)); + projectile.setLocation(projectile.getLocation().add(.0, .2, .0)); UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index ee0d7d4da..b7a4b534c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -22,6 +22,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -32,13 +33,13 @@ public class Catapult extends SiegeWeapon { public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); - public Catapult(Location location, ClanInfo clan) + public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager) { - super(location, 600.d, "Catapult", clan, clan.Clans); + super(location, 1600.d, "Catapult", clan, clan.Clans, siegeManager); location.add(.5, 0, .5); - setBoundingBox(3); + setBoundingBox(1); setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0)); setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0)); @@ -57,7 +58,16 @@ public class Catapult extends SiegeWeapon setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d)); + _invertRotation = true; + + _rotSpeed = 40.0f; + setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { + if (!isRiding(player)) + { + return false; + } + if (!_owner.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); @@ -76,11 +86,6 @@ public class Catapult extends SiegeWeapon return false; } - if (!isRiding(player)) - { - return false; - } - return true; })); @@ -138,19 +143,12 @@ public class Catapult extends SiegeWeapon addEntity(armorStand, "WEAPON"); } - @Override - public float Rotate(float nextYaw) - { - return nextYaw + 180; - } - @Override public void Fire(WeaponProjectile projectile) { - projectile.setLocation(projectile.getLocation().add(.5, .2, .5)); + projectile.setLocation(projectile.getLocation().add(.0, 3, .0)); - UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX); - UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f)); + UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.BAT_TAKEOFF, 2.f, .45f)); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 558dee7ab..1118271ce 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -2,10 +2,13 @@ package mineplex.game.clans.clans.siege.weapon; import java.util.List; import java.util.Map; +import java.util.function.Function; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -23,12 +26,15 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; +import org.spigotmc.event.entity.EntityDismountEvent; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -39,6 +45,7 @@ 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.siege.SiegeManager; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -49,6 +56,7 @@ import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; public abstract class SiegeWeapon implements Listener { protected ClansManager _clans; + protected SiegeManager _siegeManager; protected ClanInfo _owner; protected final String _name; @@ -78,6 +86,8 @@ public abstract class SiegeWeapon implements Listener // Firing stuff + protected boolean _invertRotation; + private Material _firepowerType; private Material _ammunitionType; @@ -92,13 +102,16 @@ public abstract class SiegeWeapon implements Listener private ProjectileAttributes _projectileAttributes; private WeaponProjectile _projectile; + protected float _rotSpeed = 20.f; + private long _lastRight = -1; private long _lastLeft = -1; protected long _lastFired; - public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager) + public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager) { + _siegeManager = siegeManager; _location = location; _name = name; _health = _maxHealth = maxHealth; @@ -143,7 +156,7 @@ public abstract class SiegeWeapon implements Listener _boundingBoxSize = size; - _collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .5, size - 1, ((size - 1) / 2) + .5)); + _collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .2, size - 1, ((size - 1) / 2) + .2)); _collisionBox.Construct(); _collisionBox.registerRight((block, player) -> handleRightClick(player)); _collisionBox.registerLeft((block, player) -> handleLeftClick(player)); @@ -178,7 +191,7 @@ public abstract class SiegeWeapon implements Listener { ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; - double riderYaw = getRider().getLocation().getYaw() % 360; + double riderYaw = (getRider().getLocation().getYaw() + (_invertRotation ? 180 : 0)) % 360; // riderYaw = 350 and standYaw = 20 // dif should be -30 and not 330 @@ -186,7 +199,7 @@ public abstract class SiegeWeapon implements Listener if (dif > 180) dif -= 360; if (dif < -180) dif += 360; - double yaw = Rotate((float) ((float)standYaw + Math.min(dif / 20.f, 4f))); + double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f)); armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); } @@ -326,6 +339,8 @@ public abstract class SiegeWeapon implements Listener _comprisedOf.clear(); _infoHologram.stop(); + _siegeManager.dead(this); + HandlerList.unregisterAll(this); } @@ -376,6 +391,51 @@ public abstract class SiegeWeapon implements Listener } } + private void dismount(Player player) + { + //2 in ecah + + Block origin = player.getLocation().getBlock(); + + BlockFace[] faces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; + + Block suitable = null; + + findAir: for (int yTests = 0; yTests < _boundingBoxSize; yTests++) + { + final int fyt = yTests; + + Function function = block -> { + Block up = block; + + for (int x = 0; x < fyt; x++) + { + up = up.getRelative(BlockFace.UP); + } + + return up; + }; + + for (BlockFace face : faces) + { + Block testFor = origin.getRelative(face).getRelative(face); + + if (UtilItem.isBoundless(function.apply(testFor).getType())) + { + suitable = function.apply(testFor); + break findAir; + } + } + } + + if (suitable == null) + { + suitable = UtilBlock.getHighest(origin.getWorld(), origin).getRelative(BlockFace.UP); + } + + player.teleport(suitable.getRelative(BlockFace.UP).getLocation()); + } + private void handleLeftClick(Player player) { if (_lastLeft == -1) @@ -448,11 +508,6 @@ public abstract class SiegeWeapon implements Listener { } - protected float Rotate(float yaw) - { - return yaw; - } - // Entity Management protected final void addEntity(Entity entity, String uniqueName) @@ -671,6 +726,15 @@ public abstract class SiegeWeapon implements Listener }, 3L); } + @EventHandler + public void onDismount(EntityDismountEvent event) + { + if (event.getDismounted().equals(getEntity("PLAYERMOUNT"))) + { + dismount((Player) event.getEntity()); + } + } + @EventHandler public void onInteract(PlayerInteractAtEntityEvent event) { @@ -701,6 +765,17 @@ public abstract class SiegeWeapon implements Listener } } + + public boolean inProtection(Block block) + { + if (block.getLocation().distance(_location) < _boundingBoxSize + 1.65 && block.getLocation().getY() <= _location.getY() + 2) + { + return true; + } + + return false; + } + @EventHandler public void onInteract(PlayerArmorStandManipulateEvent event) { @@ -723,5 +798,15 @@ public abstract class SiegeWeapon implements Listener Tick(); } + + public Location getLocation() + { + return _location; + } + + public double getSize() + { + return _boundingBoxSize; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java index d1c2bd242..45e07fc2a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java @@ -23,6 +23,8 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; public class Crater implements Listener @@ -41,7 +43,7 @@ public class Crater implements Listener private final List _blocks; - public Crater(SiegeWeapon weapon, Location origin, int size, double airChance, boolean doFire) + public Crater(SiegeWeapon weapon, WeaponProjectile projectile, Location origin, int size, double airChance, boolean doFire) { _weapon = weapon; _origin = origin; @@ -101,6 +103,7 @@ public class Crater implements Listener HashMap blockList = new HashMap(); int iR = (int) _size + 1; + loop: for (int x = -iR; x <= iR; x++) { for (int z = -iR; z <= iR; z++) @@ -113,7 +116,14 @@ public class Crater implements Listener if (offset <= _size) { - blockList.put(curBlock, offset); + SiegeWeapon weapon = SiegeManager.Instance.close(curBlock); + if (weapon != null) + { + weapon.removeHealth(453); + break loop; + } + + blockList.put(curBlock, Double.valueOf(offset)); } } } @@ -122,7 +132,7 @@ public class Crater implements Listener for (Entry entry : blockList.entrySet()) { Block block = entry.getKey(); - double distance = entry.getValue(); + double distance = entry.getValue().doubleValue(); boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d); @@ -154,7 +164,7 @@ public class Crater implements Listener for (Entry entry : blockList.entrySet()) { Block block = entry.getKey(); - double distance = entry.getValue(); + double distance = entry.getValue().doubleValue(); if (block.getType() == Material.AIR) continue; @@ -167,6 +177,7 @@ public class Crater implements Listener !block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE)) { _blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE)); + if (_fire) { _blocks.add(new CraterBlock(block.getRelative(BlockFace.UP).getLocation(), distance, Material.FIRE)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java index 70fb2b4f2..4707bffe1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java @@ -19,6 +19,7 @@ import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; public class WeaponProjectile implements Listener @@ -95,7 +96,14 @@ public class WeaponProjectile implements Listener .filter(block -> !UtilItem.isBoundless(block.getType())) .iterator().hasNext() && _projectileEntity.getTicksLived() >= 10) { - new Crater(_weapon, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire); + SiegeWeaponExplodeEvent newEvent = new SiegeWeaponExplodeEvent(_weapon, this); + + UtilServer.getPluginManager().callEvent(newEvent); + + if (!newEvent.isCancelled()) + { + new Crater(_weapon, this, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire); + } UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectileEntity.getLocation(), Sound.EXPLODE, 1.f, 1.f)); From ecdd21a800e718df254916dc9141a35806ec84a3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 16:09:13 +0000 Subject: [PATCH 059/122] version or plugin command now shows version of clans --- .../game/clans/clans/ClansManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 5a0c6d47c..93c394931 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -69,6 +69,7 @@ import mineplex.core.task.TaskManager; import mineplex.core.teleport.Teleport; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.Clans; import mineplex.game.clans.clans.ClanTips.TipType; import mineplex.game.clans.clans.ClansUtility.ClanRelation; import mineplex.game.clans.clans.commands.ClanManagementCommand; @@ -641,6 +642,23 @@ public class ClansManager extends MiniClientPluginimplements IRelati } } + @EventHandler(priority = EventPriority.HIGHEST) + public void commandPreProcess(PlayerCommandPreprocessEvent event) + { + String[] messages = { "ver", "version", "pl", "plugins"}; + + for (String message : messages) + { + if (!event.getMessage().equalsIgnoreCase("/" + message) && !event.getMessage().startsWith("/" + message + " ")) + { + continue; + } + + UtilPlayer.message(event.getPlayer(), F.main("Clans", "Server is on version: " + F.elem(Clans.version()))); + event.setCancelled(true); + } + } + @EventHandler public void quit(PlayerQuitEvent event) { From 5a8fae4974480bb87e375690cda7a722d5d57738 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 16:09:32 +0000 Subject: [PATCH 060/122] stop catapult projectile from getting stuck on bounding box --- .../src/mineplex/game/clans/clans/siege/weapon/Catapult.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index b7a4b534c..9f380a365 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -146,7 +146,7 @@ public class Catapult extends SiegeWeapon @Override public void Fire(WeaponProjectile projectile) { - projectile.setLocation(projectile.getLocation().add(.0, 3, .0)); + projectile.setLocation(projectile.getLocation().add(.0, 3.2, .0)); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.BAT_TAKEOFF, 2.f, .45f)); } From 50c2da2a95f4d7473e3c0274ad9f13feeda1a295 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 16:10:08 +0000 Subject: [PATCH 061/122] forgot to include this; version getter thingy in Clans --- .../Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index a4639338f..d7b6ef590 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -177,4 +177,9 @@ public class Clans extends JavaPlugin getServer().getPluginManager().callEvent(new ServerShutdownEvent(this)); } + + public static String version() + { + return "Alpha " + VERSION; + } } From fa460dbd459bb2f3e97a328c322261840f675954 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 21:50:47 +0000 Subject: [PATCH 062/122] catapult rotatyyyy --- .../core/common/util/UtilTextMiddle.java | 6 +- .../game/clans/clans/siege/SiegeManager.java | 12 -- .../clans/clans/siege/weapon/Catapult.java | 70 ++++++---- .../clans/clans/siege/weapon/SiegeWeapon.java | 128 +++++++++++------- .../clans/siege/weapon/projectile/Crater.java | 8 -- 5 files changed, 122 insertions(+), 102 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTextMiddle.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTextMiddle.java index 11b15bd21..106bbdc99 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTextMiddle.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTextMiddle.java @@ -1,6 +1,5 @@ package mineplex.core.common.util; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import net.minecraft.server.v1_8_R3.ChatMessage; @@ -28,6 +27,11 @@ public class UtilTextMiddle public static void display(String text, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks, Player... players) { + if (players.length == 1 && players[0] == null) + { + return; + } + setTimings(fadeInTicks, stayTicks, fadeOutTicks, players); display(text, subtitle, players); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 0a09d01e7..f72c6bbbb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -137,16 +137,4 @@ public class SiegeManager extends MiniPlugin LiveSiegeWeapons.remove(weapon); } - public SiegeWeapon close(Block block) - { - for (SiegeWeapon weapon : LiveSiegeWeapons) - { - if (weapon.getLocation().distance(block.getLocation()) <= weapon.getSize() + 3.d) - { - return weapon; - } - } - - return null; - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 9f380a365..36bcedc8b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -4,15 +4,18 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; @@ -37,9 +40,7 @@ public class Catapult extends SiegeWeapon { super(location, 1600.d, "Catapult", clan, clan.Clans, siegeManager); - location.add(.5, 0, .5); - - setBoundingBox(1); + setBoundingBox(3, 0); setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0)); setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0)); @@ -60,7 +61,7 @@ public class Catapult extends SiegeWeapon _invertRotation = true; - _rotSpeed = 40.0f; + _rotSpeed = 60.0f; setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { if (!isRiding(player)) @@ -110,43 +111,38 @@ public class Catapult extends SiegeWeapon private void loadEntities() { - Slime slime = _location.getWorld().spawn(_location, Slime.class); - - UtilEnt.silence(slime, true); - UtilEnt.Vegetate(slime); - - slime.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - - addEntity(slime, "Filler"); - - slime = _location.getWorld().spawn(_location, Slime.class); - - UtilEnt.silence(slime, true); - UtilEnt.Vegetate(slime); - - slime.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - - getEntity("Filler").setPassenger(slime); - addEntity(slime, "PLAYERMOUNT"); - - ArmorStand armorStand = _location.getWorld().spawn(_location, ArmorStand.class); + ArmorStand armorStand = _location.getWorld().spawn(_location.clone().add(.5, .1, .5), ArmorStand.class); UtilEnt.setFakeHead(armorStand, true); - armorStand.teleport(_location); armorStand.setVisible(false); armorStand.setGravity(false); - armorStand.setPassenger(getEntity("Filler")); - addEntity(armorStand, "WEAPON"); + + ArmorStand customRot = _location.getWorld().spawn(_location, ArmorStand.class); + + customRot.setVisible(false); + customRot.setGravity(false); + + addEntity(customRot, "PLAYERMOUNT"); + + for (int i = 0; i < 24; i++) + { + float yaw = (360.f / ((float) 24)) * i; + + ArmorStand point = _location.getWorld().spawn(UtilAlg.moveForward(_location.clone().subtract(0, 1, 0), .5, yaw, false), ArmorStand.class); + + point.setVisible(false); + point.setGravity(false); + + addEntity(point, "Point_" + i); + } } @Override public void Fire(WeaponProjectile projectile) { - projectile.setLocation(projectile.getLocation().add(.0, 3.2, .0)); + projectile.setLocation(projectile.getLocation().add(.0, 2.7, .0)); UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.BAT_TAKEOFF, 2.f, .45f)); } @@ -174,6 +170,20 @@ public class Catapult extends SiegeWeapon { UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } + + if (getRider() == null) + { + return; + } + + ArmorStand stand = (ArmorStand) getEntity("Point_" + (_yaw / (360.d / 24.d))); + + stand.setPassenger(getRider()); + } + + protected double PreRotate(double yaw) + { + return yaw / (360.d / 24.d); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 1118271ce..a244fd94e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -2,13 +2,11 @@ package mineplex.game.clans.clans.siege.weapon; import java.util.List; import java.util.Map; -import java.util.function.Function; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -17,6 +15,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; 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.inventory.InventoryCloseEvent; @@ -33,8 +32,7 @@ import com.google.common.collect.Maps; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -46,6 +44,7 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -107,6 +106,8 @@ public abstract class SiegeWeapon implements Listener private long _lastRight = -1; private long _lastLeft = -1; + protected double _yaw; + protected long _lastFired; public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager) @@ -129,6 +130,11 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; } + private ClanInfo getOwner() + { + return _owner; + } + public ClansManager getClans() { return _clans; @@ -162,6 +168,19 @@ public abstract class SiegeWeapon implements Listener _collisionBox.registerLeft((block, player) -> handleLeftClick(player)); } + protected void setBoundingBox(int size, int y) + { + Validate.isTrue(size > 0, "Size must be a positive number."); + Validate.isTrue(UtilMath.isOdd(size), "Size must be an odd number."); + + _boundingBoxSize = size; + + _collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .2, y, ((size - 1) / 2) + .2)); + _collisionBox.Construct(); + _collisionBox.registerRight((block, player) -> handleRightClick(player)); + _collisionBox.registerLeft((block, player) -> handleLeftClick(player)); + } + private void updateWeapon() { if (_inventory != null) @@ -182,6 +201,9 @@ public abstract class SiegeWeapon implements Listener } } + ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); + double standYaw = _yaw % 360; + if (getEntity("PLAYERMOUNT").getPassenger() == null) { return; @@ -189,8 +211,6 @@ public abstract class SiegeWeapon implements Listener if (getRider() != null) { - ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); - double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360; double riderYaw = (getRider().getLocation().getYaw() + (_invertRotation ? 180 : 0)) % 360; // riderYaw = 350 and standYaw = 20 @@ -200,8 +220,10 @@ public abstract class SiegeWeapon implements Listener if (dif < -180) dif += 360; double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f)); - - armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0)); + + _yaw = yaw; + + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(PreRotate(_yaw)), 0)); } } @@ -393,47 +415,7 @@ public abstract class SiegeWeapon implements Listener private void dismount(Player player) { - //2 in ecah - - Block origin = player.getLocation().getBlock(); - - BlockFace[] faces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; - - Block suitable = null; - - findAir: for (int yTests = 0; yTests < _boundingBoxSize; yTests++) - { - final int fyt = yTests; - - Function function = block -> { - Block up = block; - - for (int x = 0; x < fyt; x++) - { - up = up.getRelative(BlockFace.UP); - } - - return up; - }; - - for (BlockFace face : faces) - { - Block testFor = origin.getRelative(face).getRelative(face); - - if (UtilItem.isBoundless(function.apply(testFor).getType())) - { - suitable = function.apply(testFor); - break findAir; - } - } - } - - if (suitable == null) - { - suitable = UtilBlock.getHighest(origin.getWorld(), origin).getRelative(BlockFace.UP); - } - - player.teleport(suitable.getRelative(BlockFace.UP).getLocation()); + player.teleport(player.getLocation().add(0, 1, 0)); } private void handleLeftClick(Player player) @@ -495,7 +477,12 @@ public abstract class SiegeWeapon implements Listener protected void RightClick(Player player) { } - + + protected double PreRotate(double yaw) + { + return yaw; + } + protected void Cleanup() { } @@ -517,6 +504,11 @@ public abstract class SiegeWeapon implements Listener _entityMapping.put(uniqueName, entity); } + protected final void removeEntity(String uniqueName) + { + _comprisedOf.remove(_entityMapping.remove(getEntity(uniqueName))); + } + protected final Entity getEntity(String uniqueName) { return _entityMapping.get(uniqueName); @@ -682,6 +674,31 @@ public abstract class SiegeWeapon implements Listener // Events + @EventHandler + public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) + { + if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _location.clone().subtract(4, 2, 4), _location.clone().add(4, 2, 4))) + { + if (getHealth() > 750) + { + event.setCancelled(true); + } + + int hprem = 600 + (UtilMath.random.nextInt(250)); + + removeHealth(hprem); + + if (getHealth() > 0) + { + UtilTextMiddle.display("Damage", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")", 10, 60, 10, event.getWeapon().getRider()); + } + else + { + UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider()); + } + } + } + @EventHandler public void onDamage(EntityDamageEvent event) { @@ -760,11 +777,20 @@ public abstract class SiegeWeapon implements Listener { if (event.getBlock().getLocation().distance(_location) < _boundingBoxSize + 1.65 && event.getBlock().getLocation().getY() <= _location.getY()) { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks under a Siege Weapon")); + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks near a Siege Weapon")); event.setCancelled(true); } } + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) + { + if (event.getBlock().getLocation().distance(_location) < _boundingBoxSize + 1.65 && event.getBlock().getLocation().getY() <= _location.getY()) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks near a Siege Weapon")); + event.setCancelled(true); + } + } public boolean inProtection(Block block) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java index 45e07fc2a..acd074e38 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java @@ -103,7 +103,6 @@ public class Crater implements Listener HashMap blockList = new HashMap(); int iR = (int) _size + 1; - loop: for (int x = -iR; x <= iR; x++) { for (int z = -iR; z <= iR; z++) @@ -116,13 +115,6 @@ public class Crater implements Listener if (offset <= _size) { - SiegeWeapon weapon = SiegeManager.Instance.close(curBlock); - if (weapon != null) - { - weapon.removeHealth(453); - break loop; - } - blockList.put(curBlock, Double.valueOf(offset)); } } From bc19cf01f729740b99404db4388ac4243fa4c1aa Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 22:48:11 +0000 Subject: [PATCH 063/122] hopefully that fixes the location offset =/ --- .../clans/clans/siege/weapon/Catapult.java | 33 ++++++++---- .../clans/clans/siege/weapon/SiegeWeapon.java | 51 ++++++++++++------- 2 files changed, 57 insertions(+), 27 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 36bcedc8b..f4952c0e4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -5,6 +5,7 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; @@ -119,18 +120,11 @@ public class Catapult extends SiegeWeapon addEntity(armorStand, "WEAPON"); - ArmorStand customRot = _location.getWorld().spawn(_location, ArmorStand.class); - - customRot.setVisible(false); - customRot.setGravity(false); - - addEntity(customRot, "PLAYERMOUNT"); - for (int i = 0; i < 24; i++) { float yaw = (360.f / ((float) 24)) * i; - ArmorStand point = _location.getWorld().spawn(UtilAlg.moveForward(_location.clone().subtract(0, 1, 0), .5, yaw, false), ArmorStand.class); + ArmorStand point = _location.getWorld().spawn(UtilAlg.moveForward(_location.clone().subtract(-.5, 1, -.5), 1.3, yaw, false), ArmorStand.class); point.setVisible(false); point.setGravity(false); @@ -176,14 +170,33 @@ public class Catapult extends SiegeWeapon return; } - ArmorStand stand = (ArmorStand) getEntity("Point_" + (_yaw / (360.d / 24.d))); + ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(_yaw)); stand.setPassenger(getRider()); } + protected boolean CustomDismountCheck(Player player, Entity dismounted) + { + return _comprisedOf.contains(dismounted); + } + + protected boolean OverrideMount(Player player) + { + ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(_yaw)); + + stand.setPassenger(player); + + return true; + } + protected double PreRotate(double yaw) { - return yaw / (360.d / 24.d); + return (360.d / 24.d) * ((int) (yaw / (360.d / 24.d))); + } + + private int getPoint(double yaw) + { + return ((int) yaw) / 360 / 24; } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index a244fd94e..9b9e2bcc4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -73,7 +73,7 @@ public abstract class SiegeWeapon implements Listener private final Map _registeredStates; private String _currentState; - private final List _comprisedOf; + protected final List _comprisedOf; // Friendly-name mapping to index in _comprisedOf for easier management of entities. private final Map _entityMapping; @@ -108,6 +108,8 @@ public abstract class SiegeWeapon implements Listener protected double _yaw; + protected Player _rider; + protected long _lastFired; public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager) @@ -188,6 +190,11 @@ public abstract class SiegeWeapon implements Listener checkInv(); } + if (getRider() != null && getRider().getVehicle() == null) + { + _rider = null; + } + if (!getNextState().equals(_currentState)) { setState(getNextState()); @@ -204,7 +211,7 @@ public abstract class SiegeWeapon implements Listener ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); double standYaw = _yaw % 360; - if (getEntity("PLAYERMOUNT").getPassenger() == null) + if (getRider() == null) { return; } @@ -325,22 +332,12 @@ public abstract class SiegeWeapon implements Listener protected Player getRider() { - if (getEntity("PLAYERMOUNT").getPassenger() == null || !(getEntity("PLAYERMOUNT").getPassenger() instanceof Player)) - { - return null; - } - - return (Player) getEntity("PLAYERMOUNT").getPassenger(); + return _rider; } protected boolean isRiding(Player player) { - if (getRider() == null) - { - return false; - } - - return getRider().equals(player); + return player.equals(getRider()); } protected void setRideable(AccessRule accessRule) @@ -368,7 +365,13 @@ public abstract class SiegeWeapon implements Listener private void handleMount(Player player) { - getEntity("PLAYERMOUNT").setPassenger(player); + if (!OverrideMount(player)) + { + getEntity("PLAYERMOUNT").setPassenger(player); + } + + _rider = player; + OnMount(player); } @@ -416,6 +419,7 @@ public abstract class SiegeWeapon implements Listener private void dismount(Player player) { player.teleport(player.getLocation().add(0, 1, 0)); + _rider = null; } private void handleLeftClick(Player player) @@ -491,6 +495,16 @@ public abstract class SiegeWeapon implements Listener { } + protected boolean CustomDismountCheck(Player player, Entity entity) + { + return false; + } + + protected boolean OverrideMount(Player player) + { + return false; + } + protected void Fire(WeaponProjectile projectile) { } @@ -746,9 +760,12 @@ public abstract class SiegeWeapon implements Listener @EventHandler public void onDismount(EntityDismountEvent event) { - if (event.getDismounted().equals(getEntity("PLAYERMOUNT"))) + if (event.getEntity() instanceof Player) { - dismount((Player) event.getEntity()); + if (event.getDismounted().equals(getEntity("PLAYERMOUNT")) || CustomDismountCheck((Player) event.getEntity(), event.getDismounted())) + { + dismount((Player) event.getEntity()); + } } } From 03da4485b3b9d9680a04edb4be6813f108633f7d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 22:54:43 +0000 Subject: [PATCH 064/122] pushing to switch to clans/alpha --- .../src/mineplex/game/clans/clans/siege/weapon/Catapult.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index f4952c0e4..e04d4cdae 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -170,6 +170,8 @@ public class Catapult extends SiegeWeapon return; } + System.out.println(getPoint(_yaw)); + ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(_yaw)); stand.setPassenger(getRider()); From 16012285e0334641353b36ef37446c2140a82935 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 23:11:51 +0000 Subject: [PATCH 065/122] rotation fix --- .../mineplex/game/clans/clans/siege/weapon/Catapult.java | 6 ++---- .../mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 5 ----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index e04d4cdae..5975eb405 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -170,9 +170,7 @@ public class Catapult extends SiegeWeapon return; } - System.out.println(getPoint(_yaw)); - - ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(_yaw)); + ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); stand.setPassenger(getRider()); } @@ -184,7 +182,7 @@ public class Catapult extends SiegeWeapon protected boolean OverrideMount(Player player) { - ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(_yaw)); + ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); stand.setPassenger(player); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 9b9e2bcc4..64459b45d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -211,11 +211,6 @@ public abstract class SiegeWeapon implements Listener ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); double standYaw = _yaw % 360; - if (getRider() == null) - { - return; - } - if (getRider() != null) { double riderYaw = (getRider().getLocation().getYaw() + (_invertRotation ? 180 : 0)) % 360; From 8c1ae12d1976bffc9e132f014e3421a588765871 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 23:29:48 +0000 Subject: [PATCH 066/122] beta stuff --- .../Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java | 4 ++-- .../src/mineplex/game/clans/clans/ClansManager.java | 2 +- .../game/clans/clans/scoreboard/ClansScoreboardManager.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index d7b6ef590..ddbb3ac4a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -53,7 +53,7 @@ import net.minecraft.server.v1_8_R3.MinecraftServer; public class Clans extends JavaPlugin { - public static final String VERSION = "0.19"; + public static final String VERSION = "Beta 1.1_02"; private String WEB_CONFIG = "webServer"; // Modules @@ -180,6 +180,6 @@ public class Clans extends JavaPlugin public static String version() { - return "Alpha " + VERSION; + return VERSION; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 93c394931..4c66eac69 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -280,7 +280,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati new ClanEnergyTracker(plugin, this); new StuckManager(this); - new ClansAlphaManager(this, taskManager); +// new ClansAlphaManager(this, taskManager); new PotatoManager(plugin, this); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java index 47457a05b..9f12d8a66 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/ClansScoreboardManager.java @@ -45,7 +45,7 @@ public class ClansScoreboardManager extends ScoreboardManager private void init() { - setTitle("Clans Alpha " + Clans.VERSION); + setTitle("Clans " + Clans.VERSION); ScoreboardData data = getData("default", true); From f5d826a2cb1e9d089ad018862e08c773305489b9 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 23:42:27 +0000 Subject: [PATCH 067/122] two parentheses. all it took to fix it. GRRR --- .../src/mineplex/game/clans/clans/siege/weapon/Catapult.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 5975eb405..b4251d8a1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -170,6 +170,8 @@ public class Catapult extends SiegeWeapon return; } + System.out.println(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()) + ", " + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); + ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); stand.setPassenger(getRider()); @@ -196,7 +198,7 @@ public class Catapult extends SiegeWeapon private int getPoint(double yaw) { - return ((int) yaw) / 360 / 24; + return ((int) yaw) / (360 / 24); } @Override From 62d45d5419846801094952c7b85f40ed1677bd21 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 23:49:02 +0000 Subject: [PATCH 068/122] fix flip starngesness --- .../game/clans/clans/siege/weapon/Catapult.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index b4251d8a1..79b210a0b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -37,6 +37,8 @@ public class Catapult extends SiegeWeapon { public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); + public static final int MAXROTS = 24; + public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager) { super(location, 1600.d, "Catapult", clan, clan.Clans, siegeManager); @@ -60,8 +62,6 @@ public class Catapult extends SiegeWeapon setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d)); - _invertRotation = true; - _rotSpeed = 60.0f; setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { @@ -120,9 +120,9 @@ public class Catapult extends SiegeWeapon addEntity(armorStand, "WEAPON"); - for (int i = 0; i < 24; i++) + for (int i = 0; i < MAXROTS; i++) { - float yaw = (360.f / ((float) 24)) * i; + float yaw = (360.f / ((float) MAXROTS)) * i; ArmorStand point = _location.getWorld().spawn(UtilAlg.moveForward(_location.clone().subtract(-.5, 1, -.5), 1.3, yaw, false), ArmorStand.class); @@ -193,12 +193,12 @@ public class Catapult extends SiegeWeapon protected double PreRotate(double yaw) { - return (360.d / 24.d) * ((int) (yaw / (360.d / 24.d))); + return (360.d / MAXROTS) * ((int) (yaw / (360.d / MAXROTS))); } private int getPoint(double yaw) { - return ((int) yaw) / (360 / 24); + return ((int) yaw) / (360 / MAXROTS); } @Override From 1b92871b93700d3832e8b0afe0afd553bf7c595d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 4 Feb 2016 23:50:44 +0000 Subject: [PATCH 069/122] remove annoying debug messages --- .../src/mineplex/game/clans/clans/siege/weapon/Catapult.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 79b210a0b..38b3a3cfc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -170,8 +170,6 @@ public class Catapult extends SiegeWeapon return; } - System.out.println(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()) + ", " + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); - ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); stand.setPassenger(getRider()); From bef898afc1972c6da85e47337c920572362cbb09 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 5 Feb 2016 01:01:10 +0000 Subject: [PATCH 070/122] final fixes (? (still broken)) --- .../game/clans/clans/siege/weapon/Catapult.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 38b3a3cfc..c84642ff2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -37,8 +37,6 @@ public class Catapult extends SiegeWeapon { public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); - public static final int MAXROTS = 24; - public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager) { super(location, 1600.d, "Catapult", clan, clan.Clans, siegeManager); @@ -120,9 +118,9 @@ public class Catapult extends SiegeWeapon addEntity(armorStand, "WEAPON"); - for (int i = 0; i < MAXROTS; i++) + for (int i = 0; i < 32; i++) { - float yaw = (360.f / ((float) MAXROTS)) * i; + float yaw = (360.f / ((float) 32)) * i; ArmorStand point = _location.getWorld().spawn(UtilAlg.moveForward(_location.clone().subtract(-.5, 1, -.5), 1.3, yaw, false), ArmorStand.class); @@ -170,6 +168,7 @@ public class Catapult extends SiegeWeapon return; } + System.out.println(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()) + ", " + getRider().getLocation().getYaw()); ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); stand.setPassenger(getRider()); @@ -191,12 +190,12 @@ public class Catapult extends SiegeWeapon protected double PreRotate(double yaw) { - return (360.d / MAXROTS) * ((int) (yaw / (360.d / MAXROTS))); + return (360.d / 32.d) * ((int) (Math.abs(yaw) / (360.d / 32.d))); } private int getPoint(double yaw) { - return ((int) yaw) / (360 / MAXROTS); + return (((int) yaw) / (360 / 32) + 16) % 32; } @Override From e448046e4f9fc3bfda0e845008e4db55c61d1d91 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 5 Feb 2016 10:40:53 +0000 Subject: [PATCH 071/122] made inv get cleared on fire --- .../src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 64459b45d..0f26770c9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -249,6 +249,8 @@ public abstract class SiegeWeapon implements Listener _projectile = new WeaponProjectile(this, _location.clone().add(.5, 0, .5), _projectileAttributes, ((ArmorStand) getEntity("WEAPON")).getHeadPose().getY(), vel[0], vel[1]); + _inventory.clear(); + Fire(_projectile); } From 9dc34b5a60ddd60a3b83ea8a17d4a587f8891852 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 5 Feb 2016 19:12:12 +0000 Subject: [PATCH 072/122] better damage calculation and fixed messages for siege weapon damaging --- .../game/clans/clans/siege/weapon/Cannon.java | 4 +++- .../clans/clans/siege/weapon/Catapult.java | 4 +++- .../clans/clans/siege/weapon/SiegeWeapon.java | 23 +++++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 5b20f80b7..ac371819a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -35,7 +35,7 @@ public class Cannon extends SiegeWeapon public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager) { - super(location, 1200.d, "Cannon", clan, clan.Clans, siegeManager); + super(location, 1400.d, "Cannon", clan, clan.Clans, siegeManager); location.add(.5, 0, .5); @@ -55,6 +55,8 @@ public class Cannon extends SiegeWeapon setAmmunitionSlot(4); setMaximumAmmunitionPerSlot(1); + _baseDamage = 650; + setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d)); setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index c84642ff2..861fe32e3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -39,7 +39,7 @@ public class Catapult extends SiegeWeapon public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager) { - super(location, 1600.d, "Catapult", clan, clan.Clans, siegeManager); + super(location, 2500.d, "Catapult", clan, clan.Clans, siegeManager); setBoundingBox(3, 0); @@ -60,6 +60,8 @@ public class Catapult extends SiegeWeapon setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d)); + _baseDamage = 550; + _rotSpeed = 60.0f; setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 0f26770c9..3f585efed 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -81,6 +81,8 @@ public abstract class SiegeWeapon implements Listener private boolean _isRideable; private AccessRule _mountAccess; + protected int _baseDamage; + private AccessRule _fireAccess; // Firing stuff @@ -112,6 +114,8 @@ public abstract class SiegeWeapon implements Listener protected long _lastFired; + protected boolean _alive = true; + public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager) { _siegeManager = siegeManager; @@ -192,6 +196,7 @@ public abstract class SiegeWeapon implements Listener if (getRider() != null && getRider().getVehicle() == null) { + System.out.println("Resetting rider"); _rider = null; } @@ -357,6 +362,8 @@ public abstract class SiegeWeapon implements Listener _siegeManager.dead(this); + _alive = false; + HandlerList.unregisterAll(this); } @@ -695,17 +702,29 @@ public abstract class SiegeWeapon implements Listener event.setCancelled(true); } - int hprem = 600 + (UtilMath.random.nextInt(250)); + int hprem = _baseDamage /* base damage */; + + /* randomness */ + hprem += UtilMath.random.nextInt(250); + + /* distance calc */ + double dist = UtilMath.offset2d(event.getProjectile().getLocation(), _location); + + dist = Math.min(dist, 3); + + hprem -= (400.d /* max damage loss caused by distance */ / 3.d) * dist; removeHealth(hprem); - if (getHealth() > 0) + if (_alive) { UtilTextMiddle.display("Damage", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")", 10, 60, 10, event.getWeapon().getRider()); + UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")")); } else { UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider()); + UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".")); } } } From 9379c4190a922da16faa92e12c00df84501c275a Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 8 Feb 2016 18:31:03 +0000 Subject: [PATCH 073/122] add against clan to outpsots and also renamed "clan" to "owner" to make it more obvious --- .../clans/clans/siege/outpost/Outpost.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index fe70e3e8c..e03b02c55 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -62,7 +62,7 @@ public class Outpost implements Listener private OutpostManager _host; - private ClanInfo _clan; + private ClanInfo _owner; private Location _startCorner; private Location _origin; @@ -101,11 +101,13 @@ public class Outpost implements Listener public double _maxHealth = 4500; public double _health = _maxHealth; + public ClanInfo _against; + public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) { _host = host; - _clan = clan; + _owner = clan; _startCorner = location.clone().subtract(type._size, 1.1, type._size); _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); @@ -129,8 +131,8 @@ public class Outpost implements Listener _core = _type.getCoreLocation(_origin); - _preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); - _preHologram2 = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + _preHologram = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_owner.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); + _preHologram2 = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); _preHologram.start(); _preHologram2.start(); @@ -153,7 +155,7 @@ public class Outpost implements Listener _cannons.forEach(SiegeWeapon::kill); _cannons.clear(); - _host.queueForRemoval(_clan.getName()); + _host.queueForRemoval(_owner.getName()); } @EventHandler @@ -174,7 +176,7 @@ public class Outpost implements Listener return; } - if (!_clan.equals(_clan.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) + if (!_owner.equals(_owner.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!")); return; @@ -195,12 +197,12 @@ public class Outpost implements Listener { if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_clan.getName()) + "'s Outpost!")); + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_owner.getName()) + "'s Outpost!")); _core.getBlock().setType(Material.AIR); - _clan.inform("Your Outpost has been destroyed!", null); - UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _clan.getOnlinePlayersArray()); + _owner.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _owner.getOnlinePlayersArray()); if (getState() == OutpostState.AWAITING) { @@ -222,7 +224,7 @@ public class Outpost implements Listener { _origin.getBlock().setType(Material.AIR); _origin.getWorld().dropItem(_origin, OUTPOST_ITEM); - _clan.inform("Your Outpost block has been destroyed.", null); + _owner.inform("Your Outpost block has been destroyed.", null); cleanup(); event.setCancelled(true); return; @@ -254,7 +256,7 @@ public class Outpost implements Listener if (getLifetime() > 60000) { _origin.getBlock().setType(Material.AIR); - _clan.inform("You have lost your Outpost block, as no one activated it fast enough!", null); + _owner.inform("You have lost your Outpost block, as no one activated it fast enough!", null); cleanup(); return; } @@ -357,7 +359,7 @@ public class Outpost implements Listener } UtilServer.getPlayersCollection().stream() - .filter(player -> !_clan.isMember(player)) + .filter(player -> !_owner.isMember(player)) .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) .forEach(player -> { UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .4, true, 0.8, 0, 1.1, true); @@ -376,7 +378,7 @@ public class Outpost implements Listener _preHologram = null; _state = OutpostState.CONSTRUCTING; - _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _clan.Clans)); + _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _owner.Clans)); { Location pos = UtilBlock.getHighest(_startCorner.getWorld(), _startCorner.clone().subtract(1, 0, 1).getBlockX(), _startCorner.clone().subtract(1, 0, 1).getBlockZ()).getLocation(); @@ -384,7 +386,7 @@ public class Outpost implements Listener _builders.add(new OutpostBuilder(pos, "Peasant", _type.getWallLocations(_origin), this)); } - _clan.inform("Siege", "Your Outpost is now being constructed.", null); + _owner.inform("Siege", "Your Outpost is now being constructed.", null); _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); @@ -397,11 +399,11 @@ public class Outpost implements Listener { for (int chunkZ = -3; chunkZ < 3; chunkZ++) { - ClanTerritory territory = _clan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); + ClanTerritory territory = _owner.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); if (territory != null && ClansBlacklist.isValidClanName(territory.Owner)) { - ClanInfo clan = _clan.Clans.getClanUtility().getClanByClanName(territory.Owner); + ClanInfo clan = _owner.Clans.getClanUtility().getClanByClanName(territory.Owner); clan.inform("A siege has begun near your territory!", null); UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray()); @@ -461,7 +463,7 @@ public class Outpost implements Listener UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false); - fall.setMetadata("ClansOutpost", new FixedMetadataValue(_clan.Clans.getPlugin(), _clan.getName())); + fall.setMetadata("ClansOutpost", new FixedMetadataValue(_owner.Clans.getPlugin(), _owner.getName())); block.restore(); }); @@ -469,7 +471,7 @@ public class Outpost implements Listener cleanup(); }, wait.get() + 5L); - _clan.inform("Your Clan's Outpost has been destroyed.", null); + _owner.inform("Your Clan's Outpost has been destroyed.", null); } @EventHandler @@ -486,9 +488,9 @@ public class Outpost implements Listener } } - public ClanInfo getClan() + public ClanInfo getOwner() { - return _clan; + return _owner; } public long getLifetime() From 3ee3059bc7fd26d56936313f913e765ec0417d1b Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 8 Feb 2016 18:38:30 +0000 Subject: [PATCH 074/122] against clan needs to have a getter --- .../mineplex/game/clans/clans/siege/outpost/Outpost.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index e03b02c55..b1447490d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -11,6 +11,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.HumanEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; @@ -555,4 +556,9 @@ public class Outpost implements Listener { setHealth(_health + health); } + + public ClanInfo getAgainst() + { + return _against; + } } From b8471d7a8ec899e9030587e82f70a3f5584a3a50 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 8 Feb 2016 20:46:15 +0000 Subject: [PATCH 075/122] getter for crater size --- .../clans/siege/weapon/projectile/WeaponProjectile.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java index 4707bffe1..7133afae7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java @@ -176,4 +176,9 @@ public class WeaponProjectile implements Listener tnt.setVelocity(velocity); } } + + public int getCraterSize() + { + return _attributes._craterSize; + } } From 2c13824f9be43b9162803746845e8e73c78f8e2c Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 8 Feb 2016 20:58:40 +0000 Subject: [PATCH 076/122] possesive method in UtilText --- .../mineplex/core/common/util/UtilText.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 0b03aca9a..7c1fc6c3a 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -9,11 +9,10 @@ import java.util.HashMap; import javax.imageio.ImageIO; -import mineplex.core.common.CurrencyType; - import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; + +import mineplex.core.common.CurrencyType; public class UtilText { @@ -682,6 +681,21 @@ public class UtilText } return(prefix == null ? "" : prefix + ChatColor.RESET + " ") + progressBar + (suffix == null ? "" : ChatColor.RESET + " " + suffix); + } + + public static String possesive(String possesiveNoun, String noun) + { + if (possesiveNoun == null || noun == null) + { + return "???"; + } + + if (possesiveNoun.isEmpty() || noun.isEmpty()) + { + return "???"; + } + + return possesiveNoun.endsWith("s") ? possesiveNoun + "' " + noun : possesiveNoun + "'s " + noun; } } \ No newline at end of file From 052d3c338031502af59f61de914ec560d381045e Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 8 Feb 2016 21:33:12 +0000 Subject: [PATCH 077/122] siege system updates --- .../mineplex/core/common/util/UtilColor.java | 5 + .../game/clans/clans/siege/SiegeManager.java | 144 +++++++++++++++--- .../clans/clans/siege/outpost/Outpost.java | 110 ++++++++++++- .../clans/siege/outpost/OutpostManager.java | 137 +++++++++++++++-- .../game/clans/clans/siege/weapon/Cannon.java | 5 +- .../clans/clans/siege/weapon/Catapult.java | 9 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 31 +++- 7 files changed, 392 insertions(+), 49 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java index 32244ece9..3af6afcee 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java @@ -84,4 +84,9 @@ public class UtilColor { return (red << 16 | green << 8 | blue); } + + public static RGBData rgb(int r, int g, int b) + { + return new RGBData(r, g, b); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index f72c6bbbb..989e4e13f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -4,22 +4,27 @@ import java.util.ArrayList; import java.util.List; import org.bukkit.Location; -import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; +import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.core.repository.ClanTerritory; public class SiegeManager extends MiniPlugin { @@ -44,6 +49,39 @@ public class SiegeManager extends MiniPlugin Instance = this; } + @EventHandler + public void projectileHit(ProjectileHitEvent event) + { + Projectile projectile = event.getEntity(); + + if (projectile.hasMetadata("OutpostData")) + { + String[] data = projectile.getMetadata("OutpostData").get(0).asString().split(";"); + + ClanInfo clan = _clans.getClanUtility().getClanByClanName(data[0]); + + Player player = UtilPlayer.searchExact(data[1]); + + if (_outpostManager.Get(clan) != null && player != null) + { + ClanTerritory territory = _clans.getClanUtility().getClaim(projectile.getLocation()); + + if (ClansBlacklist.isValidClanName(territory.Owner) && !territory.Owner.equals(clan.getName())) + { + _outpostManager.Get(clan).declareOn(player, _clans.getClanUtility().getClanByClanName(territory.Owner)); + } + else + { + UtilPlayer.message(player, F.main("Clans", "You did not fire the Siege Declaration arrow into a valid rival Clan's territory. Grab another arrow from the Outpost and try again.")); + } + + _outpostManager.Get(clan).setDeclarationArrow(null); + } + + projectile.remove(); + } + } + @EventHandler public void onBlockPlace(BlockPlaceEvent event) { @@ -74,60 +112,113 @@ public class SiegeManager extends MiniPlugin { if (!_clans.isInClan(player)) { - UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon.")); + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Cannon.")); return false; } + Outpost placedOutpost = null; + ClanInfo clan = _clans.getClanUtility().getClanByPlayer(player); + if (_clans.getClanUtility().isClaimed(location)) { - UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in unclaimed territory.")); - return false; + if (!_clans.getClanUtility().getClaim(location).Owner.equals(clan.getName())) + { + UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); + return false; + } + } + else + { + boolean allowed = false; + + for (Outpost outpost : _outpostManager.getOutposts()) + { + if (!outpost.getOwner().getName().equals(clan.getName())) + { + UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); + return false; + } + + if (outpost.isInSiegeArea(location)) + { + placedOutpost = outpost; + allowed = true; + break; + } + } + + if (!allowed) + { + UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); + return false; + } } -// if (!isInOutpostSiegeArea(location, _clans.getClan(player))) -// { -// UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); -// return false; -// } - spawnCannon(player, location); + spawnCannon(player, location, placedOutpost); return true; } - public void spawnCannon(Player player, Location location) + public void spawnCannon(Player player, Location location, Outpost outpost) { - new Cannon(location, _clans.getClan(player), this); + new Cannon(location, _clans.getClan(player), this, outpost); } public boolean trySpawnCatapult(Player player, Location location) { if (!_clans.isInClan(player)) { - UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a catapult.")); + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a CanCatapultnon.")); return false; } + ClanInfo clan = _clans.getClanUtility().getClanByPlayer(player); + Outpost placedOutpost = null; + if (_clans.getClanUtility().isClaimed(location)) { - UtilPlayer.message(player, F.main("Clans", "A catapult must be placed in unclaimed territory.")); - return false; + if (!_clans.getClanUtility().getClaim(location).Owner.equals(clan.getName())) + { + UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); + return false; + } + } + else + { + boolean allowed = false; + + for (Outpost outpost : _outpostManager.getOutposts()) + { + if (!outpost.getOwner().getName().equals(clan.getName())) + { + UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); + return false; + } + + if (outpost.isInSiegeArea(location)) + { + placedOutpost = outpost; + allowed = true; + break; + } + } + + if (!allowed) + { + UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); + return false; + } } -// if (!isInOutpostSiegeArea(location, _clans.getClan(player))) -// { -// UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost.")); -// return false; -// } - - spawnCatapult(player, location); + spawnCatapult(player, location, placedOutpost); return true; } - public void spawnCatapult(Player player, Location location) + public void spawnCatapult(Player player, Location location, Outpost outpost) { - Catapult catapult = new Catapult(location, _clans.getClan(player), this); + Catapult catapult = new Catapult(location, _clans.getClan(player), this, outpost); _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(catapult, _outpostManager.getPlugin()); } @@ -137,4 +228,9 @@ public class SiegeManager extends MiniPlugin LiveSiegeWeapons.remove(weapon); } + public OutpostManager getOutpostManager() + { + return _outpostManager; + } + } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index b1447490d..c8a3caf05 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -10,21 +10,26 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.entity.Arrow; import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; +import com.google.common.collect.Lists; + import mineplex.core.common.util.C; import mineplex.core.common.util.ColorFader; import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.LoopIterator; import mineplex.core.common.util.NonFinalInteger; import mineplex.core.common.util.RGBData; @@ -43,6 +48,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; @@ -59,8 +65,11 @@ public class Outpost implements Listener { protected static final long MAX_LIFETIME = 5 * 60 * 1000; // 30 minutes public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build(); + public static final ItemStack SIEGE_DECLARATION_ARROW = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cAquaB + "Siege Declaration Arrow").setLore(UtilText.splitLineToArray(C.cWhite + "Fire a bow with this arrow at a rival Clan's base to declare Siege on them. Note that you are required to do this before being able to place Siege Weapons in your Outpost.", LineFormat.LORE)).build(); public static final byte OUTPOST_BLOCK_DATA = (byte) 137; + public static final long PREP_TIME = 2 * 60 * 1000; + private OutpostManager _host; private ClanInfo _owner; @@ -96,6 +105,12 @@ public class Outpost implements Listener private List _removalQueue; private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6)); + private LoopIterator _arrowColors = new LoopIterator<>(Lists.newArrayList( + UtilColor.rgb(203, 156, 16), + UtilColor.rgb(240, 196, 66), + UtilColor.rgb(203, 212, 17), + UtilColor.rgb(147, 212, 17), + UtilColor.rgb(150, 199, 51))); private long _spawnTime; @@ -104,6 +119,9 @@ public class Outpost implements Listener public ClanInfo _against; + private long _prepBegin = -1; + private Arrow _declarationArrow; + public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) { _host = host; @@ -193,6 +211,41 @@ public class Outpost implements Listener } } + @EventHandler + public void fireBow(EntityShootBowEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + Player player = (Player) event.getEntity(); + + if (_owner.isMember(player)) + { + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + ItemStack item = player.getInventory().getItem(slot); + + if (item == null) + { + continue; + } + + if (item.isSimilar(SIEGE_DECLARATION_ARROW)) + { + if (_against == null && !event.getProjectile().hasMetadata("OutpostData")) + { + event.getProjectile().setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); + _declarationArrow = (Arrow) event.getProjectile(); + } + + player.getInventory().setItem(slot, null); + } + } + } + } + @EventHandler public void onBlockDamage(BlockDamageEvent event) { @@ -262,6 +315,15 @@ public class Outpost implements Listener return; } + if (_declarationArrow != null) + { + _declarationArrow.setFireTicks(20); + + RGBData color = _arrowColors.next(); + + UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX); + } + _preHologram2.setText(UtilText.getProgress(null, UtilMath.clamp(getLifetime(), 0., 60000.) / 60000., null, true)); RGBData color = UtilColor.RgbLightBlue; @@ -561,4 +623,50 @@ public class Outpost implements Listener { return _against; } + + public void declareOn(Player declarer, ClanInfo against) + { + if (_against != null) + { + UtilPlayer.message(declarer, F.main("Clans", "Your Clan has already declared Siege against " + F.elem(_against.getName()) + ".")); + } + else + { + if (_host.isInSiege(against)) + { + UtilPlayer.message(declarer, F.main("Clans", F.elem(against.getName()) + " is already in a Siege.")); + } + + _against = against; + _prepBegin = System.currentTimeMillis(); + + _owner.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_against.getName()) + "."), null); + _owner.inform("Siege", "Your Clan has declared a Siege against " + F.elem(_against.getName()), null); + _owner.inform("Siege", F.elem(_against.getName()) + " has " + F.time(UtilTime.MakeStr(PREP_TIME)) + " before you can fire any Siege Weapons.", null); + + _against.inform(F.main("Clans", F.elem(_owner.getName()) + " has declared a Siege against your Clan."), null); + _against.inform(F.main("Clans", "You have " + F.time(UtilTime.MakeStr(PREP_TIME)) + " to prepare for the upcoming Siege."), null); + _against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege against your Clan.", null); + } + } + + public long getPrepBegin() + { + return _prepBegin; + } + + public long getPrepTimeLeft() + { + return System.currentTimeMillis() - getPrepBegin(); + } + + public void setDeclarationArrow(Arrow arrow) + { + _declarationArrow = arrow; + } + + public Arrow getDeclarationArrow() + { + return _declarationArrow; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index cdcf11c3f..57bc91613 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -5,7 +5,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -13,20 +17,28 @@ import org.bukkit.event.HandlerList; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; +import com.google.common.collect.Lists; + import mineplex.core.MiniPlugin; import mineplex.core.common.events.ServerShutdownEvent; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; +import mineplex.game.clans.core.repository.ClanTerritory; public class OutpostManager extends MiniPlugin { @@ -73,7 +85,7 @@ public class OutpostManager extends MiniPlugin return false; } - if (location.getBlockY() < 10) + if (location.getBlockY() < 30) { UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this deep.")); return false; @@ -124,13 +136,52 @@ public class OutpostManager extends MiniPlugin if (UtilBlock.airFoliage(location.clone().add(x, -1, z).getBlock())) { - UtilPlayer.message(player, F.main("Clans", "An Outpost cannot be placed floating.")); + Block block = location.clone().add(x, -1, z).getBlock(); + + while (block.getType() == Material.AIR) + { + if (block.getLocation().getY() <= 30) + { + break; + } + + _clansManager.getBlockRestore().add(block, Material.DIRT.getId(), (byte) 0, Outpost.MAX_LIFETIME); + block = block.getRelative(BlockFace.DOWN); + } + return false; } } } } + for (int x = -5; x < 5; x++) + { + for (int z = -5; z < 5; z++) + { + Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); + + ClanTerritory claim = _clansManager.getClanUtility().getClaim(chunk); + + if (claim != null) + { + if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner)) + { + if (UtilMath.clamp(x, -2, 2) == x || UtilMath.clamp(z, -2, 2) == z) + { + UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this close to a Clan's Territory.")); + return false; + } + else + { + UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed near a rival Clan's territory.")); + return false; + } + } + } + } + } + _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); _plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin); @@ -164,7 +215,7 @@ public class OutpostManager extends MiniPlugin if (outpost.getBounds().b(UtilAlg.toBoundingBox(event.getClaimedChunk().getBlock(0, 0, 0).getLocation(), event.getClaimedChunk().getBlock(15, 254, 15).getLocation()))) { event.setCancelled(true); - UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getClan().getName()) + "'s Outpost.")); + UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getOwner().getName()) + "'s Outpost.")); break; } } @@ -214,18 +265,78 @@ public class OutpostManager extends MiniPlugin _removalQueue.add(name); } - public boolean isInOutpostSiegeArea(Location location, ClanInfo clan) - { - if (!_outposts.containsKey(clan.getName().toLowerCase())) - { - return false; - } - - return _outposts.get(clan.getName().toLowerCase()).isInSiegeArea(location); - } - public SiegeManager getSiegeManager() { return _siegeManager; } + + public List getOutposts() + { + return Lists.newArrayList(_outposts.values()); + } + + @EventHandler + public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) + { + Outpost outpost = _siegeManager.getOutpostManager().outpostInArea(event.getProjectile().getLocation(), event.getProjectile().getCraterSize() + 1); + + if (outpost != null) + { + if (event.getWeapon().getOwner().getName().equals(outpost.getAgainst().getName())) + { + if (outpost.getHealth() > 0) + { + int hprem = event.getWeapon().getBaseDamage(); + + hprem += UtilMath.random.nextInt(250); + + outpost.removeHealth(hprem); + + UtilTextMiddle.display("Damage", "You damaged " + F.elem(outpost.getOwner().getName()) + "'s Outpost for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + outpost.getHealth() + C.cGray + ")", 10, 60, 10, event.getWeapon().getRider()); + UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You damaged " + F.elem(outpost.getOwner().getName()) + "'s Outpost for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + outpost.getHealth() + C.cGray + ")")); + + if (outpost.getHealth() == 0) + { + event.getWeapon().getOwner().inform(F.main("Clans", UtilText.possesive(F.elem(outpost.getOwner().getName()), "Outpost") + " is now vulnerable to physical damage by Siege Weapons."), null); + event.getWeapon().getOwner().inform("Siege", UtilText.possesive(F.elem(outpost.getOwner().getName()), "Outpost") + " is now vulnerable to physical damage", null); + } + } + } + else + { + event.setCancelled(true); + } + } + } + + public Outpost outpostInArea(Location location, int radius) + { + for (Outpost outpost : _outposts.values()) + { + if (outpost == null) + { + return null; + } + + if (outpost.getExactMiddle().distance(location) >= outpost._type._size + radius) + { + return outpost; + } + } + + return null; + } + + public boolean isInSiege(ClanInfo clan) + { + for (Outpost outpost : _outposts.values()) + { + if (clan.equals(outpost.getOwner()) || clan.equals(outpost.getAgainst())) + { + return true; + } + } + + return false; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index ac371819a..ead6a6079 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -23,6 +23,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -33,9 +34,9 @@ public class Cannon extends SiegeWeapon { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); - public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager) + public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) { - super(location, 1400.d, "Cannon", clan, clan.Clans, siegeManager); + super(location, 1400.d, "Cannon", clan, clan.Clans, siegeManager, outpost); location.add(.5, 0, .5); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 861fe32e3..94d849bc9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -6,12 +6,8 @@ import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; import mineplex.core.common.util.C; @@ -27,6 +23,7 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -37,9 +34,9 @@ public class Catapult extends SiegeWeapon { public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); - public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager) + public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) { - super(location, 2500.d, "Catapult", clan, clan.Clans, siegeManager); + super(location, 2500.d, "Catapult", clan, clan.Clans, siegeManager, outpost); setBoundingBox(3, 0); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 3f585efed..cfe3857b3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -38,6 +38,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -45,6 +46,7 @@ import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; +import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; @@ -57,6 +59,11 @@ public abstract class SiegeWeapon implements Listener protected ClansManager _clans; protected SiegeManager _siegeManager; + /** + * THIS MAY BE NULL IF NOT PLACED IN OUTPOST + */ + protected Outpost _outpost; + protected ClanInfo _owner; protected final String _name; protected final double _maxHealth; @@ -116,8 +123,9 @@ public abstract class SiegeWeapon implements Listener protected boolean _alive = true; - public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager) + public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) { + _outpost = outpost; _siegeManager = siegeManager; _location = location; _name = name; @@ -136,7 +144,12 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; } - private ClanInfo getOwner() + public int getBaseDamage() + { + return _baseDamage; + } + + public ClanInfo getOwner() { return _owner; } @@ -148,7 +161,11 @@ public abstract class SiegeWeapon implements Listener protected void damage(Player player) { + int health = 1 + UtilMath.random.nextInt(10); + removeHealth(health); + + UtilTextMiddle.display(UtilText.possesive(_owner.getName(), _name), C.cRed + "-" + health, 5, 15, 5); } protected abstract double[] getProjectileVelocity(); @@ -248,6 +265,14 @@ public abstract class SiegeWeapon implements Listener private void fire(Player player) { + if (_outpost != null) + { + if (_outpost.getPrepTimeLeft() > 0) + { + UtilPlayer.message(player, F.main("Clans", "You must wait for preparation time to end before firing any weapons. (" + F.time(UtilTime.MakeStr(_outpost.getPrepTimeLeft()) + ")"))); + } + } + _lastFired = System.currentTimeMillis(); double[] vel = getProjectileVelocity(); @@ -332,7 +357,7 @@ public abstract class SiegeWeapon implements Listener // Riding - protected Player getRider() + public Player getRider() { return _rider; } From dd2fe36a3d48f97af86e46c1efe00e9de40ee5e7 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 8 Feb 2016 22:23:26 +0000 Subject: [PATCH 078/122] added "Borderlands" to Clan name blacklist --- .../src/mineplex/game/clans/clans/ClansBlacklist.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java index 1483b9949..f30564a7f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansBlacklist.java @@ -19,7 +19,7 @@ public class ClansBlacklist "Fields", "Sr.Mod", "Sr. Mod", "Dev", "Jr.Dev", "Jr. Dev", "create", "join", "leave", "map", "cc", "ac", "invite", "kick", "neutral", "enemy", "trust", "unclaim", "claim", "delete", "SrMod", "Twitch", "YouTube", "Event", - "Media", "MapLead", "JrDev", "Developer", "Leader", "LT", "Support" + "Media", "MapLead", "JrDev", "Developer", "Leader", "LT", "Support", "Borderlands" }); /** From 99ece6eaeafa67eb0acda37bb227453a01de896a Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 05:53:37 +0000 Subject: [PATCH 079/122] add chest with arrwos to outpost. test for clans in area --- .../mineplex/core/common/util/UtilWorld.java | 1 + .../clans/clans/siege/outpost/Outpost.java | 15 +++ .../clans/siege/outpost/OutpostManager.java | 92 +++++++++++-------- 3 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java index 321ba7ee9..f156f7f5a 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilWorld.java @@ -209,4 +209,5 @@ public class UtilWorld origin.getBlock().getRelative(BlockFace.SOUTH), origin.getBlock().getRelative(BlockFace.WEST)); } + } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index c8a3caf05..9dab4eb76 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -10,6 +10,8 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; import org.bukkit.entity.Arrow; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; @@ -348,6 +350,19 @@ public class Outpost implements Listener { _state = OutpostState.LIVE; + for (OutpostBlock block : _blocks.values()) + { + if (block._id == Material.CHEST.getId()) + { + for (int slot = 0; slot < 8; slot++) + { + ((Chest) block._loc.getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW); + } + + break; + } + } + return; } else diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 57bc91613..62c56c71c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -30,6 +30,7 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; @@ -120,40 +121,7 @@ public class OutpostManager extends MiniPlugin } } - for (int x = -type._size; x < type._size; x++) - { - for (int y = -1; y < type._ySize; y++) - { - for (int z = -type._size; z < type._size; z++) - { - Location loc = location.clone().add(x, y, z); - - if (_clansManager.getClanUtility().isClaimed(loc)) - { - UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost where it may intersect with claimed territory.")); - return false; - } - - if (UtilBlock.airFoliage(location.clone().add(x, -1, z).getBlock())) - { - Block block = location.clone().add(x, -1, z).getBlock(); - - while (block.getType() == Material.AIR) - { - if (block.getLocation().getY() <= 30) - { - break; - } - - _clansManager.getBlockRestore().add(block, Material.DIRT.getId(), (byte) 0, Outpost.MAX_LIFETIME); - block = block.getRelative(BlockFace.DOWN); - } - - return false; - } - } - } - } + boolean gut = false; for (int x = -5; x < 5; x++) { @@ -167,15 +135,65 @@ public class OutpostManager extends MiniPlugin { if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner)) { - if (UtilMath.clamp(x, -2, 2) == x || UtilMath.clamp(z, -2, 2) == z) + if (Math.abs(x) <= 2 || Math.abs(z) <= 2) { UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this close to a Clan's Territory.")); return false; } else { - UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed near a rival Clan's territory.")); - return false; + gut = true; + break; + } + } + } + } + } + + + // das ist nicht gut + if (!gut) + { + UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed near a rival Clan's territory.")); + return false; + } + + for (int x = -type._size; x < type._size; x++) + { + for (int y = -1; y < type._ySize; y++) + { + for (int z = -type._size; z < type._size; z++) + { + Location loc = location.clone().add(x, y, z); + + if (_clansManager.getClanUtility().isClaimed(loc)) + { + UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost where it may intersect with claimed territory.")); + return false; + } + } + } + } + + for (int x = -type._size; x < type._size; x++) + { + for (int y = -1; y < type._ySize; y++) + { + for (int z = -type._size; z < type._size; z++) + { + if (UtilBlock.airFoliage(location.clone().add(x, -1, z).getBlock())) + { + Block block = location.clone().add(x, -1, z).getBlock(); + + while (block.getType() == Material.AIR) + { + if (block.getLocation().getY() <= 30) + { + break; + } + + _clansManager.getBlockRestore().add(block, Material.DIRT.getId(), (byte) 0, Outpost.MAX_LIFETIME); + block = block.getRelative(BlockFace.DOWN); } } } From 9342bee3719410e5182ec03d428a86bffb25d936 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 17:05:59 +0000 Subject: [PATCH 080/122] das ist gut --- .../clans/siege/outpost/OutpostManager.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 62c56c71c..7b5c9acd3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -121,11 +121,9 @@ public class OutpostManager extends MiniPlugin } } - boolean gut = false; - - for (int x = -5; x < 5; x++) + for (int x = -4; x < 4; x++) { - for (int z = -5; z < 5; z++) + for (int z = -4; z < 4; z++) { Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); @@ -135,26 +133,40 @@ public class OutpostManager extends MiniPlugin { if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner)) { - if (Math.abs(x) <= 2 || Math.abs(z) <= 2) - { - UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this close to a Clan's Territory.")); - return false; - } - else - { - gut = true; - break; - } + UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost this close to a Clan's Territory.")); + return false; } } } } + boolean gut = false; - // das ist nicht gut + for (int x = -6; x < 6; x++) + { + for (int z = -6; z < 6; z++) + { + Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); + + ClanTerritory claim = _clansManager.getClanUtility().getClaim(chunk); + + if (claim != null) + { + System.out.println(claim.Owner + ", " + clan.getName()); + + if (!claim.Owner.equals(clan.getName()) && ClansBlacklist.isValidClanName(claim.Owner)) + { + gut = true; /* das ist gut!!! */ + break; + } + } + } + } + + /* das ist schlecht */ if (!gut) { - UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed near a rival Clan's territory.")); + UtilPlayer.message(player, F.main("Clans", "An Outpost must be placed near a rival Clan's Territory.")); return false; } From 67d1bffe82e537df8f09e22079dda2ad913b7eef Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 19:47:42 +0000 Subject: [PATCH 081/122] npe and clan minimum players set for siege --- .../src/mineplex/game/clans/clans/siege/SiegeManager.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 989e4e13f..d6821fe4d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -66,8 +66,14 @@ public class SiegeManager extends MiniPlugin { ClanTerritory territory = _clans.getClanUtility().getClaim(projectile.getLocation()); - if (ClansBlacklist.isValidClanName(territory.Owner) && !territory.Owner.equals(clan.getName())) + if (territory != null && ClansBlacklist.isValidClanName(territory.Owner) && !territory.Owner.equals(clan.getName())) { + if (clan.getOnlinePlayerCount() < 2) + { + UtilPlayer.message(player, F.main("Clans", "A Clan must have at least 2 online players for you to declared siege on them. Grab another arrow from the Outpost and try again elsewhere.")); + return; + } + _outpostManager.Get(clan).declareOn(player, _clans.getClanUtility().getClanByClanName(territory.Owner)); } else From 2b44b88ea2a3ff901284e2161ce029468069711a Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 19:53:44 +0000 Subject: [PATCH 082/122] not being able to fire bow without the correct class and changed arrow to actually be an arrow --- .../game/clans/clans/siege/outpost/Outpost.java | 14 ++++++++------ .../src/mineplex/game/clans/gameplay/Gameplay.java | 5 +++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 9dab4eb76..efa15687a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -16,6 +16,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; 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.BlockDamageEvent; @@ -67,7 +68,7 @@ public class Outpost implements Listener { protected static final long MAX_LIFETIME = 5 * 60 * 1000; // 30 minutes public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build(); - public static final ItemStack SIEGE_DECLARATION_ARROW = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cAquaB + "Siege Declaration Arrow").setLore(UtilText.splitLineToArray(C.cWhite + "Fire a bow with this arrow at a rival Clan's base to declare Siege on them. Note that you are required to do this before being able to place Siege Weapons in your Outpost.", LineFormat.LORE)).build(); + public static final ItemStack SIEGE_DECLARATION_ARROW = new ItemBuilder(Material.ARROW, 1).setRawTitle(C.cAquaB + "Siege Declaration Arrow").setLore(UtilText.splitLineToArray(C.cWhite + "Fire a bow with this arrow at a rival Clan's base to declare Siege on them. Note that you are required to do this before being able to place Siege Weapons in your Outpost.", LineFormat.LORE)).build(); public static final byte OUTPOST_BLOCK_DATA = (byte) 137; public static final long PREP_TIME = 2 * 60 * 1000; @@ -213,7 +214,7 @@ public class Outpost implements Listener } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void fireBow(EntityShootBowEvent event) { if (!(event.getEntity() instanceof Player)) @@ -239,6 +240,7 @@ public class Outpost implements Listener if (_against == null && !event.getProjectile().hasMetadata("OutpostData")) { event.getProjectile().setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); + event.getProjectile().setMetadata("BypassFiring", new FixedMetadataValue(_host.getPlugin(), "x")); _declarationArrow = (Arrow) event.getProjectile(); } @@ -656,12 +658,12 @@ public class Outpost implements Listener _prepBegin = System.currentTimeMillis(); _owner.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_against.getName()) + "."), null); - _owner.inform("Siege", "Your Clan has declared a Siege against " + F.elem(_against.getName()), null); - _owner.inform("Siege", F.elem(_against.getName()) + " has " + F.time(UtilTime.MakeStr(PREP_TIME)) + " before you can fire any Siege Weapons.", null); + _owner.inform("Siege", "Your Clan has declared a Siege", null); + _owner.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); _against.inform(F.main("Clans", F.elem(_owner.getName()) + " has declared a Siege against your Clan."), null); - _against.inform(F.main("Clans", "You have " + F.time(UtilTime.MakeStr(PREP_TIME)) + " to prepare for the upcoming Siege."), null); - _against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege against your Clan.", null); + _against.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); + _against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege.", null); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index e3a425c34..73e493958 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -162,6 +162,11 @@ public class Gameplay extends MiniPlugin if (!playerClass.IsGameClass(ClassType.Assassin, ClassType.Ranger)) { + if (event.getProjectile().hasMetadata("BypassFiring")) + { + return; + } + notify(player, "You cannot use bows without the proper class!"); event.setCancelled(true); } From e7820975637eb4baf0a9ab8ba243631eafa7eb15 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 20:04:13 +0000 Subject: [PATCH 083/122] shouldn't be able to fire weapons whilst in siege wait time --- .../src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index cfe3857b3..3e5ee853f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -270,6 +270,7 @@ public abstract class SiegeWeapon implements Listener if (_outpost.getPrepTimeLeft() > 0) { UtilPlayer.message(player, F.main("Clans", "You must wait for preparation time to end before firing any weapons. (" + F.time(UtilTime.MakeStr(_outpost.getPrepTimeLeft()) + ")"))); + return; } } From e74cefeee8e1e78a49999b478afa44ebe2a87d5d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 19:59:01 +0000 Subject: [PATCH 084/122] increased siege weapon placement area, and made outposts handle siege weapons that are placed within them --- .../game/clans/clans/siege/SiegeManager.java | 12 ++++++-- .../clans/clans/siege/outpost/Outpost.java | 29 ++++++++++++------- .../clans/siege/outpost/OutpostManager.java | 1 - 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index d6821fe4d..152116dac 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -168,7 +168,12 @@ public class SiegeManager extends MiniPlugin public void spawnCannon(Player player, Location location, Outpost outpost) { - new Cannon(location, _clans.getClan(player), this, outpost); + Cannon cannon = new Cannon(location, _clans.getClan(player), this, outpost); + + if (outpost != null) + { + outpost.addWeapon(cannon); + } } public boolean trySpawnCatapult(Player player, Location location) @@ -226,7 +231,10 @@ public class SiegeManager extends MiniPlugin { Catapult catapult = new Catapult(location, _clans.getClan(player), this, outpost); - _outpostManager.getPlugin().getServer().getPluginManager().registerEvents(catapult, _outpostManager.getPlugin()); + if (outpost != null) + { + outpost.addWeapon(catapult); + } } public void dead(SiegeWeapon weapon) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index efa15687a..c6b29be13 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -10,7 +10,6 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.entity.Arrow; import org.bukkit.entity.FallingBlock; @@ -92,11 +91,11 @@ public class Outpost implements Listener private LinkedHashMap _blocks; private LinkedHashMap _buildQueue; + private List _weapons; + protected OutpostType _type; private OutpostState _state; - private List _cannons; - private Hologram _preHologram; private Hologram _preHologram2; @@ -107,6 +106,8 @@ public class Outpost implements Listener private List _removalQueue; + private double _siegeWeaponDistance; + private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6)); private LoopIterator _arrowColors = new LoopIterator<>(Lists.newArrayList( UtilColor.rgb(203, 156, 16), @@ -129,6 +130,8 @@ public class Outpost implements Listener { _host = host; + _siegeWeaponDistance = type._size + 27.5; + _owner = clan; _startCorner = location.clone().subtract(type._size, 1.1, type._size); @@ -136,8 +139,7 @@ public class Outpost implements Listener _builders = new ArrayList<>(); _removalQueue = new ArrayList<>(); - - _cannons = new ArrayList<>(); + _weapons = new ArrayList<>(); _forceFieldStart = _startCorner.clone().subtract(3, 0, 3); _forceFieldEnd = _endCorner.clone().add(3, 0, 3); @@ -174,8 +176,8 @@ public class Outpost implements Listener _state = OutpostState.DEAD; - _cannons.forEach(SiegeWeapon::kill); - _cannons.clear(); + _weapons.forEach(SiegeWeapon::kill); + _weapons.clear(); _host.queueForRemoval(_owner.getName()); } @@ -520,9 +522,9 @@ public class Outpost implements Listener NonFinalInteger wait = new NonFinalInteger(0); - _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).forEach(block -> + _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block -> _host.runSyncLater(() -> { - UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, block._loc, new Vector(0,0,0), 1f, 2, ViewDist.NORMAL); + UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block._loc, new Vector(0,0,0), 1f, 1, ViewDist.MAX); _origin.getWorld().playSound(block._loc, Sound.EXPLODE, 1.0f, 1.0f); }, wait.add(4 + UtilMath.random.nextInt(4)).get()) ); @@ -601,7 +603,7 @@ public class Outpost implements Listener // AREA IN WHICH CANNONS AND OTHER SIEGE WEAPONS CAN BE PLACED public boolean isInSiegeArea(Location location) { - return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd.clone().add(.9, 0, .9)); + return UtilMath.offset2d(location, _core) <= _siegeWeaponDistance; } // Health Management @@ -663,7 +665,7 @@ public class Outpost implements Listener _against.inform(F.main("Clans", F.elem(_owner.getName()) + " has declared a Siege against your Clan."), null); _against.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); - _against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege.", null); + _against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege", null); } } @@ -686,4 +688,9 @@ public class Outpost implements Listener { return _declarationArrow; } + + public void addWeapon(SiegeWeapon weapon) + { + _weapons.add(weapon); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 7b5c9acd3..a6c1cd15b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -30,7 +30,6 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilWorld; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; From 43cf4d38efe97a7e809dbc532d4d1c2d07e1a6cb Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 9 Feb 2016 21:36:58 +0000 Subject: [PATCH 085/122] give player arrow back after failed territory siege declaration arrow thingy fire thingy ehh grammar is not needed at night :} --- .../mineplex/game/clans/clans/siege/SiegeManager.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 152116dac..a9b8f3878 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -68,17 +68,20 @@ public class SiegeManager extends MiniPlugin if (territory != null && ClansBlacklist.isValidClanName(territory.Owner) && !territory.Owner.equals(clan.getName())) { - if (clan.getOnlinePlayerCount() < 2) + if (clan.getOnlinePlayerCount() < 1) { UtilPlayer.message(player, F.main("Clans", "A Clan must have at least 2 online players for you to declared siege on them. Grab another arrow from the Outpost and try again elsewhere.")); - return; + player.getInventory().addItem(Outpost.SIEGE_DECLARATION_ARROW); + } + else + { + _outpostManager.Get(clan).declareOn(player, _clans.getClanUtility().getClanByClanName(territory.Owner)); } - - _outpostManager.Get(clan).declareOn(player, _clans.getClanUtility().getClanByClanName(territory.Owner)); } else { UtilPlayer.message(player, F.main("Clans", "You did not fire the Siege Declaration arrow into a valid rival Clan's territory. Grab another arrow from the Outpost and try again.")); + player.getInventory().addItem(Outpost.SIEGE_DECLARATION_ARROW); } _outpostManager.Get(clan).setDeclarationArrow(null); From 35f016288266d1d8b46411c239e8f4b6bc503f79 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 10 Feb 2016 11:09:17 +0000 Subject: [PATCH 086/122] make catapults rideableeeeeee --- .../mineplex/core/common/util/UtilEnt.java | 7 +- .../game/clans/clans/siege/weapon/Cannon.java | 4 +- .../clans/clans/siege/weapon/Catapult.java | 65 +++++-------------- 3 files changed, 25 insertions(+), 51 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index 566be1092..90f176359 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -818,7 +818,12 @@ public class UtilEnt ((EntityInsentient)e.getHandle()).k(!ai); } } - + + public static double getBlockSizeOfSlime(int size) + { + return .51 * ((double) size); + } + public static boolean inWater(LivingEntity ent) { return ent.getLocation().getBlock().getTypeId() == 8 || ent.getLocation().getBlock().getTypeId() == 9; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index ead6a6079..5ef7f26fc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -116,7 +116,7 @@ public class Cannon extends SiegeWeapon slime.setSize(-1); slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - addEntity(slime, "Filler"); + addEntity(slime, "Filler_1"); slime = _location.getWorld().spawn(_location, Slime.class); @@ -126,7 +126,7 @@ public class Cannon extends SiegeWeapon slime.setSize(-1); slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - getEntity("Filler").setPassenger(slime); + getEntity("Filler_1").setPassenger(slime); addEntity(slime, "PLAYERMOUNT"); ArmorStand armorStand = _location.getWorld().spawn(_location, ArmorStand.class); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 94d849bc9..5ce685020 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -4,15 +4,15 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; @@ -117,17 +117,20 @@ public class Catapult extends SiegeWeapon addEntity(armorStand, "WEAPON"); - for (int i = 0; i < 32; i++) - { - float yaw = (360.f / ((float) 32)) * i; - - ArmorStand point = _location.getWorld().spawn(UtilAlg.moveForward(_location.clone().subtract(-.5, 1, -.5), 1.3, yaw, false), ArmorStand.class); - - point.setVisible(false); - point.setGravity(false); - - addEntity(point, "Point_" + i); - } + Slime filler = _location.getWorld().spawn(_location, Slime.class); + + filler.setSize(-1); + filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0)); + + addEntity(filler, "Filler_1"); + + ArmorStand mount = _location.getWorld().spawn(_location, ArmorStand.class); + + mount.setVisible(false); + mount.setGravity(false); + filler.setPassenger(mount); + + addEntity(mount, "PLAYERMOUNT"); } @Override @@ -161,40 +164,6 @@ public class Catapult extends SiegeWeapon { UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); } - - if (getRider() == null) - { - return; - } - - System.out.println(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()) + ", " + getRider().getLocation().getYaw()); - ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); - - stand.setPassenger(getRider()); - } - - protected boolean CustomDismountCheck(Player player, Entity dismounted) - { - return _comprisedOf.contains(dismounted); - } - - protected boolean OverrideMount(Player player) - { - ArmorStand stand = (ArmorStand) getEntity("Point_" + getPoint(Math.toDegrees(((ArmorStand) getEntity("WEAPON")).getHeadPose().getY()))); - - stand.setPassenger(player); - - return true; - } - - protected double PreRotate(double yaw) - { - return (360.d / 32.d) * ((int) (Math.abs(yaw) / (360.d / 32.d))); - } - - private int getPoint(double yaw) - { - return (((int) yaw) / (360 / 32) + 16) % 32; } @Override From 2be917e623e274f4da3a5543a092fd00f2696cb3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 10 Feb 2016 13:01:31 +0000 Subject: [PATCH 087/122] give enemy info about time before siege and after outpost is built, the health of the outpost --- .../mineplex/core/common/util/UtilText.java | 15 +++++++++++++ .../clans/clans/siege/outpost/Outpost.java | 21 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 7c1fc6c3a..5c289d176 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Map; import javax.imageio.ImageIO; @@ -696,6 +697,20 @@ public class UtilText } return possesiveNoun.endsWith("s") ? possesiveNoun + "' " + noun : possesiveNoun + "'s " + noun; + } + + public static String colorPercentage(int percentage) + { + Map colors = new HashMap<>(); + + colors.put(Integer.valueOf(100), C.cGreen); + colors.put(Integer.valueOf(80), C.cDGreen); + colors.put(Integer.valueOf(60), C.cYellow); + colors.put(Integer.valueOf(40), C.cGold); + colors.put(Integer.valueOf(20), C.cRed); + colors.put(Integer.valueOf(0), C.cDRed); + + return colors.get(Integer.valueOf(percentage / colors.size())); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index c6b29be13..514153dbb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -49,6 +49,7 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; @@ -311,6 +312,16 @@ public class Outpost implements Listener protected void update() { + if (_against != null && getPrepTimeLeft() > 0) + { + _against.getOnlinePlayers().forEach(this::informTimeToSiege); + _owner.getOnlinePlayers().forEach(this::informTimeToSiege); + } + else if (_against != null) + { + UtilTextBottom.display("Enemy Outpost Health: " + UtilText.colorPercentage(getHealthPercentage()) + "%", _against.getOnlinePlayersArray()); + } + if (_state == OutpostState.AWAITING) { if (getLifetime() > 60000) @@ -608,6 +619,11 @@ public class Outpost implements Listener // Health Management + public final int getHealthPercentage() + { + return ((int) ((_health / _maxHealth) * 100.d)); + } + public final double getHealth() { return _health; @@ -669,6 +685,11 @@ public class Outpost implements Listener } } + public void informTimeToSiege(Player player) + { + UtilTextBottom.display("Time to Siege: " + F.time(UtilTime.MakeStr(getPrepTimeLeft())), player); + } + public long getPrepBegin() { return _prepBegin; From b308d1759fcef106980cda37759c2b8dd41e2504 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 10 Feb 2016 13:08:50 +0000 Subject: [PATCH 088/122] renamed stuff to more sensible stuff. :} --- .../game/clans/clans/siege/outpost/Outpost.java | 16 ++++++++-------- .../clans/clans/siege/weapon/SiegeWeapon.java | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 514153dbb..8754613cc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -124,7 +124,7 @@ public class Outpost implements Listener public ClanInfo _against; - private long _prepBegin = -1; + private long _siegeDeclaredTime = -1; private Arrow _declarationArrow; public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) @@ -312,7 +312,7 @@ public class Outpost implements Listener protected void update() { - if (_against != null && getPrepTimeLeft() > 0) + if (_against != null && getTimeToSiege() > 0) { _against.getOnlinePlayers().forEach(this::informTimeToSiege); _owner.getOnlinePlayers().forEach(this::informTimeToSiege); @@ -673,7 +673,7 @@ public class Outpost implements Listener } _against = against; - _prepBegin = System.currentTimeMillis(); + _siegeDeclaredTime = System.currentTimeMillis(); _owner.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_against.getName()) + "."), null); _owner.inform("Siege", "Your Clan has declared a Siege", null); @@ -687,17 +687,17 @@ public class Outpost implements Listener public void informTimeToSiege(Player player) { - UtilTextBottom.display("Time to Siege: " + F.time(UtilTime.MakeStr(getPrepTimeLeft())), player); + UtilTextBottom.display("Time to Siege: " + F.time(UtilTime.MakeStr(getTimeToSiege())), player); } - public long getPrepBegin() + public long getTimeSiegeDeclared() { - return _prepBegin; + return _siegeDeclaredTime; } - public long getPrepTimeLeft() + public long getTimeToSiege() { - return System.currentTimeMillis() - getPrepBegin(); + return System.currentTimeMillis() - getTimeSiegeDeclared(); } public void setDeclarationArrow(Arrow arrow) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 3e5ee853f..240ab2315 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -267,9 +267,9 @@ public abstract class SiegeWeapon implements Listener { if (_outpost != null) { - if (_outpost.getPrepTimeLeft() > 0) + if (_outpost.getTimeToSiege() > 0) { - UtilPlayer.message(player, F.main("Clans", "You must wait for preparation time to end before firing any weapons. (" + F.time(UtilTime.MakeStr(_outpost.getPrepTimeLeft()) + ")"))); + UtilPlayer.message(player, F.main("Clans", "You must wait for preparation time to end before firing any weapons. (" + F.time(UtilTime.MakeStr(_outpost.getTimeToSiege()) + ")"))); return; } } From 67b12f3ae284019e37c5bd6131163b01923747dc Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 10 Feb 2016 19:24:57 +0000 Subject: [PATCH 089/122] loads of progress --- .../core/common/file/DataFileInStream.java | 40 +++ .../core/common/file/DataFileOutStream.java | 100 ++++++ .../mineplex/core/common/file/UtilFile.java | 79 +++++ .../core/common/file/chunks/DataChunk.java | 20 ++ .../common/file/chunks/DataChunkByte.java | 35 ++ .../core/common/file/chunks/DataChunkInt.java | 45 +++ .../common/file/chunks/DataChunkLong.java | 36 ++ .../common/file/chunks/DataChunkString.java | 74 +++++ .../mineplex/core/common/util/FileUtil.java | 2 +- .../mineplex/core/common/util/UtilEncode.java | 116 +++++++ .../mineplex/core/common/util/UtilFile.java | 310 ------------------ .../clans/clans/siege/outpost/Outpost.java | 44 +-- .../clans/siege/outpost/OutpostManager.java | 25 -- .../game/clans/gameplay/Gameplay.java | 4 +- .../game/clans/gameplay/safelog/SafeLog.java | 15 +- .../gameplay/safelog/npc/CombatLogNPC.java | 12 +- 16 files changed, 568 insertions(+), 389 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java new file mode 100644 index 000000000..a8d34b3a0 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java @@ -0,0 +1,40 @@ +package mineplex.core.common.file; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang3.ArrayUtils; + +import com.google.common.collect.Lists; + +public class DataFileInStream +{ + private Iterator _iterator; + + public DataFileInStream(String file) throws IOException + { + this(Lists.newArrayList(ArrayUtils.toObject(UtilFile.readAllBytes(file)))); + } + + public DataFileInStream(List chunks) + { + _iterator = chunks.iterator(); + } + + public DataFileInStream(Byte[] chunks) + { + this(Lists.newArrayList(chunks)); + } + + public Byte read() + { + return _iterator.next(); + } + + public void dispose() + { + _iterator = null; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java new file mode 100644 index 000000000..6d6666811 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java @@ -0,0 +1,100 @@ +package mineplex.core.common.file; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.google.common.collect.Lists; + +import mineplex.core.common.file.chunks.DataChunk; + +public class DataFileOutStream +{ + private List> _chunks; + + public DataFileOutStream() + { + _chunks = new ArrayList<>(); + } + + public DataFileOutStream(List> chunks) + { + _chunks = chunks; + } + + public DataFileOutStream(DataChunk[] chunks) + { + this(Lists.newArrayList(chunks)); + } + + public void add(DataChunk chunk) + { + _chunks.add(chunk); + } + + private byte[] ensureSize(byte[] bytes, int size) + { + byte[] newBytes = bytes; + + if (bytes.length < size) + { + newBytes = Arrays.copyOf(bytes, size); + } + + return newBytes; + } + + public void writeToFile(String file) throws IOException + { + byte[] bytes = new byte[1]; + + for (DataChunk chunk : _chunks) + { + int oldLength = bytes.length; + + byte[] chunkBytes = chunk.toBytes(); + + bytes = ensureSize(bytes, chunkBytes.length + bytes.length); + + for (int i = oldLength; i < chunkBytes.length; i++) + { + bytes[i - 1] = chunkBytes[(i - 1) - oldLength]; + } + } + + UtilFile.writeToFile(file, bytes); + } + + public String writeBytesToString() + { + byte[] bytes = new byte[1]; + + for (DataChunk chunk : _chunks) + { + int oldLength = bytes.length; + + byte[] chunkBytes = chunk.toBytes(); + + bytes = ensureSize(bytes, chunkBytes.length + bytes.length); + + for (int i = oldLength; i < chunkBytes.length; i++) + { + bytes[i - 1] = chunkBytes[(i - 1) - oldLength]; + } + } + + return new String(bytes); + } + + public void release() + { + _chunks.clear(); + } + + public List> getChunks() + { + return _chunks; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java new file mode 100644 index 000000000..887747ac6 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java @@ -0,0 +1,79 @@ +package mineplex.core.common.file; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class UtilFile +{ + public static void writePlainFile(File file, String text) throws FileNotFoundException + { + PrintWriter writer = new PrintWriter(file); + writer.print(text); + writer.close(); + } + + /** + * Will read the specified file, and return the contents, or a null value, + * if an exception is thrown. Will handle all exceptions, and simply ignore + * them and return null. No stack trace printed or anything. + */ + public static String readIgnoreErrors(File file) + { + try + { + return readToStr(file); + } + catch (IOException exception) + { + return null; + } + } + + public static String readToStr(File file) throws IOException + { + return new String(readAllBytes(file)); + } + + public static byte[] readAllBytes(File file) throws IOException + { + return Files.readAllBytes(Paths.get(file.toURI())); + } + + public static void writePlainFile(String file, String text) throws FileNotFoundException + { + writePlainFile(new File(file), text); + } + + /** + * Will read the specified file, and return the contents, or a null value, + * if an exception is thrown. Will handle all exceptions, and simply ignore + * them and return null. No stack trace printed or anything. + */ + public static String readIgnoreErrors(String file) + { + return readIgnoreErrors(new File(file)); + } + + public static String readToStr(String file) throws IOException + { + return readToStr(new File(file)); + } + + public static byte[] readAllBytes(String file) throws IOException + { + return readAllBytes(new File(file)); + } + + public static void writeToFile(String file, byte[] bytes) throws IOException + { + FileOutputStream stream = new FileOutputStream(new File(file)); + stream.write(bytes); + stream.close(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java new file mode 100644 index 000000000..9b6ae472e --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java @@ -0,0 +1,20 @@ +package mineplex.core.common.file.chunks; + +import java.io.DataOutputStream; +import java.io.IOException; + +public abstract class DataChunk +{ + protected Type _value; + + public DataChunk(Type value) + { + _value = value; + } + + public abstract void WriteTo(DataOutputStream stream) throws IOException; + + public abstract byte[] toBytes(); + + public abstract boolean IsValid(Type value); +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java new file mode 100644 index 000000000..50e0ef3e2 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java @@ -0,0 +1,35 @@ +package mineplex.core.common.file.chunks; + +import java.io.DataOutputStream; +import java.io.IOException; + +import mineplex.core.common.file.DataFileInStream; + +public class DataChunkByte extends DataChunk +{ + public DataChunkByte(byte value) + { + super(Byte.valueOf(value)); + } + + public boolean IsValid(Byte value) + { + return value != null; + } + + public void WriteTo(DataOutputStream stream) throws IOException + { + stream.write(toBytes()); + } + + public static Byte ReadFrom(DataFileInStream stream) throws IOException + { + return stream.read(); + } + + public byte[] toBytes() + { + return new byte[] { _value.byteValue() }; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java new file mode 100644 index 000000000..d61d97620 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java @@ -0,0 +1,45 @@ +package mineplex.core.common.file.chunks; + +import java.io.DataOutputStream; +import java.io.IOException; + +import mineplex.core.common.file.DataFileInStream; + +public class DataChunkInt extends DataChunk +{ + public DataChunkInt(int value) + { + super(Integer.valueOf(value)); + } + + public boolean IsValid(Integer value) + { + return value != null; + } + + public void WriteTo(DataOutputStream stream) throws IOException + { + stream.write(toBytes()); + } + + public static Integer ReadFrom(DataFileInStream stream) throws IOException + { + int part1 = stream.read().byteValue(); + int part2 = stream.read().byteValue(); + int part3 = stream.read().byteValue(); + int part4 = stream.read().byteValue(); + + return Integer.valueOf(part1 << 24 + part2 << 16 + part3 << 8 + part4); + } + + public byte[] toBytes() + { + byte part1 = (byte) ((_value.intValue() >>> 24) & 0xFF); + byte part2 = (byte) ((_value.intValue() >>> 16) & 0xFF); + byte part3 = (byte) ((_value.intValue() >>> 8) & 0xFF); + byte part4 = (byte) (_value.intValue() & 0xFF); + + return new byte[] { part1, part2, part3, part4 }; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java new file mode 100644 index 000000000..d2d6c91cf --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java @@ -0,0 +1,36 @@ +package mineplex.core.common.file.chunks; + +import java.io.DataOutputStream; +import java.io.IOException; + +import mineplex.core.common.file.DataFileInStream; +import mineplex.core.common.util.UtilEncode; + +public class DataChunkLong extends DataChunk +{ + public DataChunkLong(long value) + { + super(Long.valueOf(value)); + } + + public boolean IsValid(Long value) + { + return value != null; + } + + public void WriteTo(DataOutputStream stream) throws IOException + { + stream.write(toBytes()); + } + + public static Long ReadFrom(DataFileInStream stream) throws IOException + { + return Long.valueOf(UtilEncode.bytesToLong(new byte[] { stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue() })); + } + + public byte[] toBytes() + { + return UtilEncode.longToBytes(_value.longValue()); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java new file mode 100644 index 000000000..e9df4c5ad --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java @@ -0,0 +1,74 @@ +package mineplex.core.common.file.chunks; + +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.ArrayUtils; + +import mineplex.core.common.file.DataFileInStream; +import mineplex.core.common.util.UtilEncode; + +public class DataChunkString extends DataChunk +{ + private static final String ENCODING = "UTF-8"; + + public DataChunkString(String value) + { + super(value); + } + + public boolean IsValid(String value) + { + return value != null; + } + + public void WriteTo(DataOutputStream stream) throws IOException + { + stream.write(toBytes()); + } + + public static String ReadFrom(DataFileInStream stream) throws IOException + { + int length = DataChunkInt.ReadFrom(stream).intValue(); + + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < length; i++) + { + builder.append(DataChunkByte.ReadFrom(stream)); + } + + return null; + } + + public byte[] toBytes() + { + try + { + /* four extra bytes reserved for the size of the string represented as an int */ + byte[] bytes = new byte[4 + _value.getBytes(ENCODING).length]; + + byte[] intBytes = UtilEncode.intToBytes(_value.getBytes(ENCODING).length); + + for (int i = 0; i < intBytes.length; i++) + { + bytes[i] = intBytes[i]; + } + + for (int i = 0; i < _value.getBytes(ENCODING).length; i++) + { + bytes[4 + i] = _value.getBytes(ENCODING)[i]; + } + + return bytes; + } + catch (Exception e) + { + return UtilEncode.intToBytes(0); + } + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/FileUtil.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/FileUtil.java index 61a9f3ad5..871e2d55f 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/FileUtil.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/FileUtil.java @@ -7,7 +7,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -public class FileUtil +public class FileUtil { public static void DeleteFolder(File folder) { diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java new file mode 100644 index 000000000..59ccae5e0 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java @@ -0,0 +1,116 @@ +package mineplex.core.common.util; + +public class UtilEncode +{ + public static byte[] intToBytes(int value) + { + byte part1 = (byte) ((value >>> 24) & 0xFF); + byte part2 = (byte) ((value >>> 16) & 0xFF); + byte part3 = (byte) ((value >>> 8) & 0xFF); + byte part4 = (byte) (value & 0xFF); + + return new byte[] { part1, part2, part3, part4 }; + } + + public static byte[] booleanToBytes(boolean value) + { + return new byte[] { (byte) (value ? 1 : 0) }; + } + + public static byte[] doubleToBytes(double value) + { + return longToBytes(Double.doubleToLongBits(value)); + } + + public static byte[] floatToBytes(float value) + { + return intToBytes(Float.floatToIntBits(value)); + } + + public static byte[] charToBytes(char value) + { + byte part1 = (byte) ((value >>> 24) & 0xFF); + byte part2 = (byte) (value & 0xFF); + + return new byte[] { part1, part2 }; + } + + public static byte[] shortToBytes(short value) + { + byte part1 = (byte) ((value >>> 24) & 0xFF); + byte part2 = (byte) (value & 0xFF); + + return new byte[] { part1, part2 }; + } + + public static byte[] longToBytes(long value) + { + byte part1 = (byte) (value >>> 56); + byte part2 = (byte) (value >>> 48); + byte part3 = (byte) (value >>> 40); + byte part4 = (byte) (value >>> 32); + byte part5 = (byte) (value >>> 24); + byte part6 = (byte) (value >>> 16); + byte part7 = (byte) (value >>> 8); + byte part8 = (byte) (value); + + + return new byte[] { part1, part2, part3, part4, part5, part6, part7, part8 }; + } + + public static long bytesToLong(byte[] bytes) + { + long part1 = ((long) bytes[0]) << 56; + long part2 = (((long) bytes[1]) & 255) << 48; + long part3 = (((long) bytes[2]) & 255) << 40; + long part4 = (((long) bytes[3]) & 255) << 32; + long part5 = (((long) bytes[4]) & 255) << 24; + long part6 = (((long) bytes[5]) & 255) << 16; + long part7 = (((long) bytes[6]) & 255) << 8; + long part8 = (((long) bytes[7]) & 255); + + return part1 + part2 + part3 + part4 + part5 + part6 + part7 + part8; + } + + public static int bytesToInt(byte[] bytes) + { + int part1 = ((int) bytes[0]) << 24; + int part2 = ((int) bytes[1]) << 16; + int part3 = ((int) bytes[2]) << 8; + int part4 = ((int) bytes[3]); + + return part1 + part2 + part3 + part4; + } + + public static boolean bytesToBoolean(byte[] bytes) + { + return bytes[0] == 1; + } + +// public static byte[] bytesToDouble(byte[] bytes) +// { +// return Double.longBitsToDouble(); +// } +// +// public static byte[] floatToBytes(float value) +// { +// return intToBytes(Float.floatToIntBits(value)); +// } +// +// public static byte[] charToBytes(char value) +// { +// byte part1 = (byte) ((value >>> 24) & 0xFF); +// byte part2 = (byte) (value & 0xFF); +// +// return new byte[] { part1, part2 }; +// } +// +// public static byte[] shortToBytes(short value) +// { +// byte part1 = (byte) ((value >>> 24) & 0xFF); +// byte part2 = (byte) (value & 0xFF); +// +// return new byte[] { part1, part2 }; +// } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java deleted file mode 100644 index 5429f0107..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java +++ /dev/null @@ -1,310 +0,0 @@ -package mineplex.core.common.util; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.Paths; - -public class UtilFile -{ - public static void writePlainFile(File file, String text) throws FileNotFoundException - { - PrintWriter writer = new PrintWriter(file); - writer.print(text); - writer.close(); - } - - /** - * Will read the specified file, and return the contents, or a null value, - * if an exception is thrown. Will handle all exceptions, and simply ignore - * them and return null. No stack trace printed or anything. - */ - public static String readIgnoreErrors(File file) - { - try - { - return readToStr(file); - } - catch (IOException exception) - { - return null; - } - } - - public static String readToStr(File file) throws IOException - { - return new String(readAllBytes(file)); - } - - public static byte[] readAllBytes(File file) throws IOException - { - return Files.readAllBytes(Paths.get(file.toURI())); - } - - public static void writePlainFile(String file, String text) throws FileNotFoundException - { - writePlainFile(new File(file), text); - } - - /** - * Will read the specified file, and return the contents, or a null value, - * if an exception is thrown. Will handle all exceptions, and simply ignore - * them and return null. No stack trace printed or anything. - */ - public static String readIgnoreErrors(String file) - { - return readIgnoreErrors(new File(file)); - } - - public static String readToStr(String file) throws IOException - { - return readToStr(new File(file)); - } - - public static byte[] readAllBytes(String file) throws IOException - { - return readAllBytes(new File(file)); - } - - public static void writeDataFile(File file, DataFileChunk... chunks) throws IOException - { - DataOutputStream stream = new DataOutputStream(new FileOutputStream(file)); - for (DataFileChunk chunk : chunks) - { - chunk.writeTo(stream); - } - stream.close(); - } - - public static DataFileReader beginReading(String file) throws FileNotFoundException - { - return beginReading(new File(file)); - } - - public static DataFileReader beginReading(File file) throws FileNotFoundException - { - return new DataFileReader(file); - } - - public static void writeDataFile(String file, DataFileChunk... chunks) throws IOException - { - writeDataFile(new File(file), chunks); - } - - public static class DataFileChunk - { - private ChunkType _type; - private Object _value; - - public DataFileChunk(ChunkType type, Object value) - { - if (type == null) - { - throw new RuntimeException("ChunkType can NOT be null."); - } - - _type = type; - - if (!_type.isValid(value)) - { - throw new RuntimeException("Invalid value provided for the specified ChunkType."); - } - - _value = value; - } - - public void writeTo(DataOutputStream stream) throws IOException - { - _type.writeTo(stream, _value); - } - } - - public static enum ChunkType - { - STRING(new ChunkImpl() - { - public void writeTo(DataOutputStream stream, Object value) throws IOException - { - String str = (String) value; - - INTEGER.writeTo(stream, str.length()); - for (char b : str.toCharArray()) - { - CHAR.writeTo(stream, b); - } - } - - public boolean isValid(Object value) - { - return value.getClass().equals(String.class); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - int length = (int) INTEGER.readFrom(stream); - - StringBuilder string = new StringBuilder(); - - for (int i = 0; i < length; i++) - { - string.append(CHAR.readFrom(stream)); - } - - return string.toString(); - } - }), - DOUBLE(new ChunkImpl() - { - public void writeTo(DataOutputStream stream, Object value) throws IOException - { - double number = (double) value; - - stream.writeDouble(number); - } - - public boolean isValid(Object value) - { - return value.getClass().equals(Double.class); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - return stream.readDouble(); - } - }), - INTEGER(new ChunkImpl() - { - public void writeTo(DataOutputStream stream, Object value) throws IOException - { - int number = (int) value; - - stream.writeInt(number); - } - - public boolean isValid(Object value) - { - return value.getClass().equals(Integer.class); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - return stream.readInt(); - } - }), - BYTE(new ChunkImpl() - { - public void writeTo(DataOutputStream stream, Object value) throws IOException - { - byte number = (byte) value; - - stream.writeByte(number); - } - - public boolean isValid(Object value) - { - return value.getClass().equals(Byte.class); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - return stream.readByte(); - } - }), - CHAR(new ChunkImpl() - { - public void writeTo(DataOutputStream stream, Object value) throws IOException - { - char number = (char) value; - - stream.writeChar(number); - } - - public boolean isValid(Object value) - { - return value.getClass().equals(Character.class); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - return stream.readChar(); - } - }), - LONG(new ChunkImpl() - { - public void writeTo(DataOutputStream stream, Object value) throws IOException - { - long number = (long) value; - - stream.writeLong(number); - } - - public boolean isValid(Object value) - { - return value.getClass().equals(Long.class); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - return stream.readLong(); - } - }); - - private ChunkImpl _impl; - - ChunkType(ChunkImpl impl) - { - _impl = impl; - } - - protected void writeTo(DataOutputStream stream, Object value) throws IOException - { - _impl.writeTo(stream, value); - } - - protected boolean isValid(Object value) - { - return value != null && _impl.isValid(value); - } - - public Object readFrom(DataInputStream stream) throws IOException - { - return _impl.readFrom(stream); - } - } - - public static class DataFileReader - { - private DataInputStream _stream; - - public DataFileReader(File file) throws FileNotFoundException - { - _stream = new DataInputStream(new FileInputStream(file)); - } - - public Object readChunk(ChunkType type) throws IOException - { - return type.readFrom(_stream); - } - - public void close() throws IOException - { - _stream.close(); - } - } - - protected interface ChunkImpl - { - void writeTo(DataOutputStream stream, Object value) throws IOException; - - Object readFrom(DataInputStream stream) throws IOException; - - boolean isValid(Object value); - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 8754613cc..806ba7a3d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.Material; @@ -59,14 +60,13 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; -import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; public class Outpost implements Listener { - protected static final long MAX_LIFETIME = 5 * 60 * 1000; // 30 minutes + protected static final long MAX_LIFETIME = 30 * 60 * 1000; // 30 minutes public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build(); public static final ItemStack SIEGE_DECLARATION_ARROW = new ItemBuilder(Material.ARROW, 1).setRawTitle(C.cAquaB + "Siege Declaration Arrow").setLore(UtilText.splitLineToArray(C.cWhite + "Fire a bow with this arrow at a rival Clan's base to declare Siege on them. Note that you are required to do this before being able to place Siege Weapons in your Outpost.", LineFormat.LORE)).build(); public static final byte OUTPOST_BLOCK_DATA = (byte) 137; @@ -75,15 +75,14 @@ public class Outpost implements Listener private OutpostManager _host; + private UUID _uuid = UUID.randomUUID(); + private ClanInfo _owner; private Location _startCorner; private Location _origin; private Location _endCorner; - private Location _siegeAreaStart; - private Location _siegeAreaEnd; - private Location _forceFieldStart; private Location _forceFieldEnd; @@ -103,10 +102,6 @@ public class Outpost implements Listener private LoopIterator _circleStages; private LoopIterator _reverseCircleStages; - private List _builders; - - private List _removalQueue; - private double _siegeWeaponDistance; private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6)); @@ -138,16 +133,11 @@ public class Outpost implements Listener _startCorner = location.clone().subtract(type._size, 1.1, type._size); _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); - _builders = new ArrayList<>(); - _removalQueue = new ArrayList<>(); _weapons = new ArrayList<>(); _forceFieldStart = _startCorner.clone().subtract(3, 0, 3); _forceFieldEnd = _endCorner.clone().add(3, 0, 3); - _siegeAreaStart = _startCorner.clone().subtract(7, 0, 7); - _siegeAreaEnd = _endCorner.clone().add(7, 0, 7); - _origin = location.clone(); _type = type; @@ -243,7 +233,6 @@ public class Outpost implements Listener if (_against == null && !event.getProjectile().hasMetadata("OutpostData")) { event.getProjectile().setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); - event.getProjectile().setMetadata("BypassFiring", new FixedMetadataValue(_host.getPlugin(), "x")); _declarationArrow = (Arrow) event.getProjectile(); } @@ -433,19 +422,6 @@ public class Outpost implements Listener @EventHandler public void forcefield(UpdateEvent event) { - if (!_removalQueue.isEmpty()) - { - _builders.remove(_removalQueue.remove(0)); - } - - if (event.getType() == UpdateType.TICK && getState() == OutpostState.CONSTRUCTING) - { - for (OutpostBuilder builder : _builders) - { - builder.tick(); - } - } - if (event.getType() != UpdateType.FAST || getState() != OutpostState.CONSTRUCTING) { return; @@ -473,12 +449,6 @@ public class Outpost implements Listener _state = OutpostState.CONSTRUCTING; _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _owner.Clans)); - { - Location pos = UtilBlock.getHighest(_startCorner.getWorld(), _startCorner.clone().subtract(1, 0, 1).getBlockX(), _startCorner.clone().subtract(1, 0, 1).getBlockZ()).getLocation(); - - _builders.add(new OutpostBuilder(pos, "Peasant", _type.getWallLocations(_origin), this)); - } - _owner.inform("Siege", "Your Outpost is now being constructed.", null); _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); @@ -605,11 +575,6 @@ public class Outpost implements Listener { return _state; } - - public void queueForRemoval(OutpostBuilder builder) - { - _removalQueue.add(builder); - } // AREA IN WHICH CANNONS AND OTHER SIEGE WEAPONS CAN BE PLACED public boolean isInSiegeArea(Location location) @@ -670,6 +635,7 @@ public class Outpost implements Listener if (_host.isInSiege(against)) { UtilPlayer.message(declarer, F.main("Clans", F.elem(against.getName()) + " is already in a Siege.")); + return; } _against = against; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index a6c1cd15b..d0702fbb5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -186,31 +186,6 @@ public class OutpostManager extends MiniPlugin } } - for (int x = -type._size; x < type._size; x++) - { - for (int y = -1; y < type._ySize; y++) - { - for (int z = -type._size; z < type._size; z++) - { - if (UtilBlock.airFoliage(location.clone().add(x, -1, z).getBlock())) - { - Block block = location.clone().add(x, -1, z).getBlock(); - - while (block.getType() == Material.AIR) - { - if (block.getLocation().getY() <= 30) - { - break; - } - - _clansManager.getBlockRestore().add(block, Material.DIRT.getId(), (byte) 0, Outpost.MAX_LIFETIME); - block = block.getRelative(BlockFace.DOWN); - } - } - } - } - } - _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); _plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index c7b896692..a7e4d801e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -154,7 +154,7 @@ public class Gameplay extends MiniPlugin } } - @EventHandler + @EventHandler(priority = EventPriority.LOWEST) public void onBowShoot(EntityShootBowEvent event) { if (event.getEntity() instanceof Player) @@ -164,7 +164,7 @@ public class Gameplay extends MiniPlugin if (!playerClass.IsGameClass(ClassType.Assassin, ClassType.Ranger)) { - if (event.getProjectile().hasMetadata("BypassFiring")) + if (event.getProjectile().hasMetadata("OutpostData")) { return; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java index f07a24ea6..4b7bc5f4b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java @@ -13,11 +13,11 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.common.file.DataFileInStream; +import mineplex.core.common.file.chunks.DataChunkLong; +import mineplex.core.common.file.chunks.DataChunkString; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilFile; -import mineplex.core.common.util.UtilFile.ChunkType; -import mineplex.core.common.util.UtilFile.DataFileReader; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; @@ -77,10 +77,10 @@ public class SafeLog extends MiniPlugin { try { - DataFileReader reader = UtilFile.beginReading(_clansManager.UserDataDir + String.format("DEATH_%s.dat", player.getUniqueId().toString())); + DataFileInStream stream = new DataFileInStream(_clansManager.UserDataDir + String.format("DEATH_%s.dat", player.getUniqueId().toString())); - final long time = (long) reader.readChunk(ChunkType.LONG); - final String killerName = (String) reader.readChunk(ChunkType.STRING); + final long time = DataChunkLong.ReadFrom(stream).longValue(); + final String killerName = DataChunkString.ReadFrom(stream); UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { @@ -91,7 +91,8 @@ public class SafeLog extends MiniPlugin UtilTextMiddle.display("Offline Death", "Log out in a safer place next time!", 15, 80, 40, player); } }, 15); - reader.close(); + + stream.dispose(); deathFile.delete(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java index c37e78a56..eacca4e90 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java @@ -15,12 +15,11 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; import org.bukkit.metadata.FixedMetadataValue; +import mineplex.core.common.file.DataFileOutStream; +import mineplex.core.common.file.UtilFile; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEnt; -import mineplex.core.common.util.UtilFile; -import mineplex.core.common.util.UtilFile.ChunkType; -import mineplex.core.common.util.UtilFile.DataFileChunk; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTime; @@ -28,7 +27,6 @@ import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramManager; -import mineplex.game.clans.Clans; import mineplex.game.clans.clans.ClansManager; public class CombatLogNPC @@ -101,7 +99,11 @@ public class CombatLogNPC try { - UtilFile.writeDataFile(new File(_userDataPath + String.format("DEATH_%s.dat", _playerInfo.getPlayerUuid())), new DataFileChunk(ChunkType.LONG, System.currentTimeMillis()), new DataFileChunk(ChunkType.STRING, killerName)); + DataFileOutStream stream = new DataFileOutStream(); + + stream.writeToFile(_userDataPath + String.format("DEATH_%s.dat", _playerInfo.getPlayerUuid())); + + stream.release(); } catch (IOException e) { From 90570c1185fc70349e0a1ef0f20af79a92aced72 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 11 Feb 2016 17:08:05 +0000 Subject: [PATCH 090/122] progress on saving outposts/wepaons so far. not finished. probably going to change it to a different format --- .../core/common/file/DataFileInStream.java | 40 ---- .../core/common/file/DataFileOutStream.java | 100 --------- .../mineplex/core/common/file/UtilFile.java | 79 ------- .../core/common/file/chunks/DataChunk.java | 20 -- .../common/file/chunks/DataChunkByte.java | 35 --- .../core/common/file/chunks/DataChunkInt.java | 45 ---- .../common/file/chunks/DataChunkLong.java | 36 ---- .../common/file/chunks/DataChunkString.java | 74 ------- .../core/common/gson/UUIDTypeAdapter.java | 43 ++++ .../mineplex/core/common/util/UtilEncode.java | 116 ---------- .../mineplex/core/common/util/UtilMath.java | 88 ++++++++ .../src/mineplex/game/clans/clans/Test.java | 24 +++ .../game/clans/clans/siege/SiegeManager.java | 89 ++++++++ .../clans/clans/siege/outpost/Outpost.java | 117 +++++++--- .../clans/siege/outpost/OutpostManager.java | 199 ++++++++++++++++-- .../game/clans/clans/siege/weapon/Cannon.java | 2 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 43 +++- .../weapon/serialization/OutpostToken.java | 19 ++ .../serialization/SiegeWeaponToken.java | 22 ++ .../siege/weapon/serialization/TokenInfo.java | 6 + .../game/clans/gameplay/Gameplay.java | 5 - .../game/clans/gameplay/safelog/SafeLog.java | 21 +- .../gameplay/safelog/npc/CombatLogNPC.java | 16 +- 23 files changed, 633 insertions(+), 606 deletions(-) delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java deleted file mode 100644 index a8d34b3a0..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileInStream.java +++ /dev/null @@ -1,40 +0,0 @@ -package mineplex.core.common.file; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.lang3.ArrayUtils; - -import com.google.common.collect.Lists; - -public class DataFileInStream -{ - private Iterator _iterator; - - public DataFileInStream(String file) throws IOException - { - this(Lists.newArrayList(ArrayUtils.toObject(UtilFile.readAllBytes(file)))); - } - - public DataFileInStream(List chunks) - { - _iterator = chunks.iterator(); - } - - public DataFileInStream(Byte[] chunks) - { - this(Lists.newArrayList(chunks)); - } - - public Byte read() - { - return _iterator.next(); - } - - public void dispose() - { - _iterator = null; - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java deleted file mode 100644 index 6d6666811..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/DataFileOutStream.java +++ /dev/null @@ -1,100 +0,0 @@ -package mineplex.core.common.file; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.google.common.collect.Lists; - -import mineplex.core.common.file.chunks.DataChunk; - -public class DataFileOutStream -{ - private List> _chunks; - - public DataFileOutStream() - { - _chunks = new ArrayList<>(); - } - - public DataFileOutStream(List> chunks) - { - _chunks = chunks; - } - - public DataFileOutStream(DataChunk[] chunks) - { - this(Lists.newArrayList(chunks)); - } - - public void add(DataChunk chunk) - { - _chunks.add(chunk); - } - - private byte[] ensureSize(byte[] bytes, int size) - { - byte[] newBytes = bytes; - - if (bytes.length < size) - { - newBytes = Arrays.copyOf(bytes, size); - } - - return newBytes; - } - - public void writeToFile(String file) throws IOException - { - byte[] bytes = new byte[1]; - - for (DataChunk chunk : _chunks) - { - int oldLength = bytes.length; - - byte[] chunkBytes = chunk.toBytes(); - - bytes = ensureSize(bytes, chunkBytes.length + bytes.length); - - for (int i = oldLength; i < chunkBytes.length; i++) - { - bytes[i - 1] = chunkBytes[(i - 1) - oldLength]; - } - } - - UtilFile.writeToFile(file, bytes); - } - - public String writeBytesToString() - { - byte[] bytes = new byte[1]; - - for (DataChunk chunk : _chunks) - { - int oldLength = bytes.length; - - byte[] chunkBytes = chunk.toBytes(); - - bytes = ensureSize(bytes, chunkBytes.length + bytes.length); - - for (int i = oldLength; i < chunkBytes.length; i++) - { - bytes[i - 1] = chunkBytes[(i - 1) - oldLength]; - } - } - - return new String(bytes); - } - - public void release() - { - _chunks.clear(); - } - - public List> getChunks() - { - return _chunks; - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java deleted file mode 100644 index 887747ac6..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/UtilFile.java +++ /dev/null @@ -1,79 +0,0 @@ -package mineplex.core.common.file; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.Paths; - -public class UtilFile -{ - public static void writePlainFile(File file, String text) throws FileNotFoundException - { - PrintWriter writer = new PrintWriter(file); - writer.print(text); - writer.close(); - } - - /** - * Will read the specified file, and return the contents, or a null value, - * if an exception is thrown. Will handle all exceptions, and simply ignore - * them and return null. No stack trace printed or anything. - */ - public static String readIgnoreErrors(File file) - { - try - { - return readToStr(file); - } - catch (IOException exception) - { - return null; - } - } - - public static String readToStr(File file) throws IOException - { - return new String(readAllBytes(file)); - } - - public static byte[] readAllBytes(File file) throws IOException - { - return Files.readAllBytes(Paths.get(file.toURI())); - } - - public static void writePlainFile(String file, String text) throws FileNotFoundException - { - writePlainFile(new File(file), text); - } - - /** - * Will read the specified file, and return the contents, or a null value, - * if an exception is thrown. Will handle all exceptions, and simply ignore - * them and return null. No stack trace printed or anything. - */ - public static String readIgnoreErrors(String file) - { - return readIgnoreErrors(new File(file)); - } - - public static String readToStr(String file) throws IOException - { - return readToStr(new File(file)); - } - - public static byte[] readAllBytes(String file) throws IOException - { - return readAllBytes(new File(file)); - } - - public static void writeToFile(String file, byte[] bytes) throws IOException - { - FileOutputStream stream = new FileOutputStream(new File(file)); - stream.write(bytes); - stream.close(); - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java deleted file mode 100644 index 9b6ae472e..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunk.java +++ /dev/null @@ -1,20 +0,0 @@ -package mineplex.core.common.file.chunks; - -import java.io.DataOutputStream; -import java.io.IOException; - -public abstract class DataChunk -{ - protected Type _value; - - public DataChunk(Type value) - { - _value = value; - } - - public abstract void WriteTo(DataOutputStream stream) throws IOException; - - public abstract byte[] toBytes(); - - public abstract boolean IsValid(Type value); -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java deleted file mode 100644 index 50e0ef3e2..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkByte.java +++ /dev/null @@ -1,35 +0,0 @@ -package mineplex.core.common.file.chunks; - -import java.io.DataOutputStream; -import java.io.IOException; - -import mineplex.core.common.file.DataFileInStream; - -public class DataChunkByte extends DataChunk -{ - public DataChunkByte(byte value) - { - super(Byte.valueOf(value)); - } - - public boolean IsValid(Byte value) - { - return value != null; - } - - public void WriteTo(DataOutputStream stream) throws IOException - { - stream.write(toBytes()); - } - - public static Byte ReadFrom(DataFileInStream stream) throws IOException - { - return stream.read(); - } - - public byte[] toBytes() - { - return new byte[] { _value.byteValue() }; - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java deleted file mode 100644 index d61d97620..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkInt.java +++ /dev/null @@ -1,45 +0,0 @@ -package mineplex.core.common.file.chunks; - -import java.io.DataOutputStream; -import java.io.IOException; - -import mineplex.core.common.file.DataFileInStream; - -public class DataChunkInt extends DataChunk -{ - public DataChunkInt(int value) - { - super(Integer.valueOf(value)); - } - - public boolean IsValid(Integer value) - { - return value != null; - } - - public void WriteTo(DataOutputStream stream) throws IOException - { - stream.write(toBytes()); - } - - public static Integer ReadFrom(DataFileInStream stream) throws IOException - { - int part1 = stream.read().byteValue(); - int part2 = stream.read().byteValue(); - int part3 = stream.read().byteValue(); - int part4 = stream.read().byteValue(); - - return Integer.valueOf(part1 << 24 + part2 << 16 + part3 << 8 + part4); - } - - public byte[] toBytes() - { - byte part1 = (byte) ((_value.intValue() >>> 24) & 0xFF); - byte part2 = (byte) ((_value.intValue() >>> 16) & 0xFF); - byte part3 = (byte) ((_value.intValue() >>> 8) & 0xFF); - byte part4 = (byte) (_value.intValue() & 0xFF); - - return new byte[] { part1, part2, part3, part4 }; - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java deleted file mode 100644 index d2d6c91cf..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkLong.java +++ /dev/null @@ -1,36 +0,0 @@ -package mineplex.core.common.file.chunks; - -import java.io.DataOutputStream; -import java.io.IOException; - -import mineplex.core.common.file.DataFileInStream; -import mineplex.core.common.util.UtilEncode; - -public class DataChunkLong extends DataChunk -{ - public DataChunkLong(long value) - { - super(Long.valueOf(value)); - } - - public boolean IsValid(Long value) - { - return value != null; - } - - public void WriteTo(DataOutputStream stream) throws IOException - { - stream.write(toBytes()); - } - - public static Long ReadFrom(DataFileInStream stream) throws IOException - { - return Long.valueOf(UtilEncode.bytesToLong(new byte[] { stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue(), stream.read().byteValue() })); - } - - public byte[] toBytes() - { - return UtilEncode.longToBytes(_value.longValue()); - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java deleted file mode 100644 index e9df4c5ad..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/file/chunks/DataChunkString.java +++ /dev/null @@ -1,74 +0,0 @@ -package mineplex.core.common.file.chunks; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang.ArrayUtils; - -import mineplex.core.common.file.DataFileInStream; -import mineplex.core.common.util.UtilEncode; - -public class DataChunkString extends DataChunk -{ - private static final String ENCODING = "UTF-8"; - - public DataChunkString(String value) - { - super(value); - } - - public boolean IsValid(String value) - { - return value != null; - } - - public void WriteTo(DataOutputStream stream) throws IOException - { - stream.write(toBytes()); - } - - public static String ReadFrom(DataFileInStream stream) throws IOException - { - int length = DataChunkInt.ReadFrom(stream).intValue(); - - StringBuilder builder = new StringBuilder(); - - for (int i = 0; i < length; i++) - { - builder.append(DataChunkByte.ReadFrom(stream)); - } - - return null; - } - - public byte[] toBytes() - { - try - { - /* four extra bytes reserved for the size of the string represented as an int */ - byte[] bytes = new byte[4 + _value.getBytes(ENCODING).length]; - - byte[] intBytes = UtilEncode.intToBytes(_value.getBytes(ENCODING).length); - - for (int i = 0; i < intBytes.length; i++) - { - bytes[i] = intBytes[i]; - } - - for (int i = 0; i < _value.getBytes(ENCODING).length; i++) - { - bytes[4 + i] = _value.getBytes(ENCODING)[i]; - } - - return bytes; - } - catch (Exception e) - { - return UtilEncode.intToBytes(0); - } - } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java new file mode 100644 index 000000000..73aef088d --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java @@ -0,0 +1,43 @@ +package mineplex.core.common.gson; + +import java.io.IOException; +import java.util.UUID; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +public class UUIDTypeAdapter extends TypeAdapter +{ + public UUID read(JsonReader reader) throws IOException + { + String uuid = null; + + reader.beginObject(); + + read: + while (reader.hasNext()) + { + switch (reader.nextName()) + { + case "bytes": + { + uuid = reader.nextString(); + break read; + } + } + } + + reader.endObject(); + + return UUID.fromString(uuid); + } + + public void write(JsonWriter writer, UUID uuid) throws IOException + { + writer.beginObject(); + writer.name("bytes").value(uuid.toString()); + writer.endObject(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java deleted file mode 100644 index 59ccae5e0..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEncode.java +++ /dev/null @@ -1,116 +0,0 @@ -package mineplex.core.common.util; - -public class UtilEncode -{ - public static byte[] intToBytes(int value) - { - byte part1 = (byte) ((value >>> 24) & 0xFF); - byte part2 = (byte) ((value >>> 16) & 0xFF); - byte part3 = (byte) ((value >>> 8) & 0xFF); - byte part4 = (byte) (value & 0xFF); - - return new byte[] { part1, part2, part3, part4 }; - } - - public static byte[] booleanToBytes(boolean value) - { - return new byte[] { (byte) (value ? 1 : 0) }; - } - - public static byte[] doubleToBytes(double value) - { - return longToBytes(Double.doubleToLongBits(value)); - } - - public static byte[] floatToBytes(float value) - { - return intToBytes(Float.floatToIntBits(value)); - } - - public static byte[] charToBytes(char value) - { - byte part1 = (byte) ((value >>> 24) & 0xFF); - byte part2 = (byte) (value & 0xFF); - - return new byte[] { part1, part2 }; - } - - public static byte[] shortToBytes(short value) - { - byte part1 = (byte) ((value >>> 24) & 0xFF); - byte part2 = (byte) (value & 0xFF); - - return new byte[] { part1, part2 }; - } - - public static byte[] longToBytes(long value) - { - byte part1 = (byte) (value >>> 56); - byte part2 = (byte) (value >>> 48); - byte part3 = (byte) (value >>> 40); - byte part4 = (byte) (value >>> 32); - byte part5 = (byte) (value >>> 24); - byte part6 = (byte) (value >>> 16); - byte part7 = (byte) (value >>> 8); - byte part8 = (byte) (value); - - - return new byte[] { part1, part2, part3, part4, part5, part6, part7, part8 }; - } - - public static long bytesToLong(byte[] bytes) - { - long part1 = ((long) bytes[0]) << 56; - long part2 = (((long) bytes[1]) & 255) << 48; - long part3 = (((long) bytes[2]) & 255) << 40; - long part4 = (((long) bytes[3]) & 255) << 32; - long part5 = (((long) bytes[4]) & 255) << 24; - long part6 = (((long) bytes[5]) & 255) << 16; - long part7 = (((long) bytes[6]) & 255) << 8; - long part8 = (((long) bytes[7]) & 255); - - return part1 + part2 + part3 + part4 + part5 + part6 + part7 + part8; - } - - public static int bytesToInt(byte[] bytes) - { - int part1 = ((int) bytes[0]) << 24; - int part2 = ((int) bytes[1]) << 16; - int part3 = ((int) bytes[2]) << 8; - int part4 = ((int) bytes[3]); - - return part1 + part2 + part3 + part4; - } - - public static boolean bytesToBoolean(byte[] bytes) - { - return bytes[0] == 1; - } - -// public static byte[] bytesToDouble(byte[] bytes) -// { -// return Double.longBitsToDouble(); -// } -// -// public static byte[] floatToBytes(float value) -// { -// return intToBytes(Float.floatToIntBits(value)); -// } -// -// public static byte[] charToBytes(char value) -// { -// byte part1 = (byte) ((value >>> 24) & 0xFF); -// byte part2 = (byte) (value & 0xFF); -// -// return new byte[] { part1, part2 }; -// } -// -// public static byte[] shortToBytes(short value) -// { -// byte part1 = (byte) ((value >>> 24) & 0xFF); -// byte part2 = (byte) (value & 0xFF); -// -// return new byte[] { part1, part2 }; -// } - -} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index d089bad59..82bbb711f 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -189,5 +189,93 @@ public class UtilMath public static boolean isEven(int size) { return size % 2 == 0; + } + + public static byte[] getBits(int value) + { + byte[] bits = new byte[32]; + + String bit = Long.toBinaryString(value); + + while (bit.length() < 32) + { + bit = "0" + bit; + } + + int index = 0; + for (char c : bit.toCharArray()) + { + bits[index] = (byte) (c == '1' ? '1' : '0'); + + index++; + } + + return bits; + } + + public static byte[] getBits(long value) + { + byte[] bits = new byte[64]; + + String bit = Long.toBinaryString(value); + + while (bit.length() < 64) + { + bit = "0" + bit; + } + + int index = 0; + for (char c : bit.toCharArray()) + { + bits[index] = (byte) (c == '1' ? '1' : '0'); + + index++; + } + + return bits; + } + + public static byte[] getBits(byte value) + { + byte[] bits = new byte[8]; + + String bit = Long.toBinaryString(value); + + while (bit.length() < 8) + { + bit = "0" + bit; + } + + int index = 0; + for (char c : bit.toCharArray()) + { + bits[index] = (byte) (c == '1' ? '1' : '0'); + + index++; + } + + return bits; + } + + public static byte[] getBits(short value) + { + byte[] bits = new byte[16]; + + String bit = Long.toBinaryString(value); + + while (bit.length() < 16) + { + bit = "0" + bit; + } + + int index = 0; + for (char c : bit.toCharArray()) + { + bits[index] = (byte) (c == '1' ? '1' : '0'); + + index++; + } + + return bits; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java new file mode 100644 index 000000000..46daab300 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java @@ -0,0 +1,24 @@ +package mineplex.game.clans.clans; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class Test { + public static void main(String[] args) throws IOException + { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(stream); + + dos.writeByte(91); + dos.flush(); + stream.flush(); + + System.out.println(new String(stream.toByteArray())); + + dos.close(); + stream.close(); + + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index a9b8f3878..35a8a8935 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -2,8 +2,11 @@ package mineplex.game.clans.clans.siege; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -11,7 +14,11 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.plugin.java.JavaPlugin; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + import mineplex.core.MiniPlugin; +import mineplex.core.common.gson.UUIDTypeAdapter; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; @@ -24,7 +31,9 @@ import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.clans.siege.weapon.serialization.TokenInfo; import mineplex.game.clans.core.repository.ClanTerritory; +import mineplex.game.clans.spawn.Spawn; public class SiegeManager extends MiniPlugin { @@ -36,19 +45,99 @@ public class SiegeManager extends MiniPlugin public List LiveSiegeWeapons = new ArrayList<>(); + private Gson _gson; + public SiegeManager(JavaPlugin plugin, ClansManager clans) { super("Siege", plugin); + _gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); + _clans = clans; _outpostManager = new OutpostManager(clans, this); + _outpostManager.loadExistingOutposts(); + + loadExistingWeapons(); + addCommand(new CommandSiegeSupplies(_outpostManager)); Instance = this; } + /** + * data clusters: + * STRING : { + * int(4BYTE) length; + * byte[] bytes; + * } + * + * LOCATION : { + * STRING world; + * int(4BYTE) x; + * int(4BYTE) y; + * int(4BYTE) z; + * } + * + * ITEM : { + * STRING material; + * byte data; + * int amount; + * } + * + * INVENTORY : { + * int numOfEntries; + * ITEM[] item; + * } + * + * data format: + * Outpost { + * STRING clanOwner; + * int weaponType; + * STRING outpostId; + * LOCATION location; + * INVENTORY inventory; + * MAP comprisedOf; + * double health; + * double yaw; + * String rider; + * long lastFired; + * } + */ + private void loadExistingWeapons() + { + try + { + for (Entity entity : Spawn.getSpawnWorld().getEntities()) + { + if (!(entity instanceof ArmorStand)) + { + continue; + } + + if (!entity.hasMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$") ||!entity.hasMetadata("$TOKEN_INFO$")) + { + continue; + } + + ArmorStand stand = (ArmorStand) entity; + + String data = entity.getMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$").get(0).asString(); + String type = entity.getMetadata("$TOKEN_INFO$").get(0).asString(); + + SiegeWeapon weapon = _gson.fromJson(data, _gson.fromJson(type, TokenInfo.class).Type); + + + + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + @EventHandler public void projectileHit(ProjectileHitEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 806ba7a3d..3c3e82886 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -1,5 +1,7 @@ package mineplex.game.clans.clans.siege.outpost; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -12,6 +14,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Chest; +import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; @@ -75,7 +78,7 @@ public class Outpost implements Listener private OutpostManager _host; - private UUID _uuid = UUID.randomUUID(); + private final String _id; private ClanInfo _owner; @@ -122,10 +125,56 @@ public class Outpost implements Listener private long _siegeDeclaredTime = -1; private Arrow _declarationArrow; + private ArmorStand _dataEntity; + + public Outpost(OutpostManager outpostManager, String id, Location origin, ClanInfo ownerClan, OutpostType outpostType, double health, long spawnTime, ClanInfo againstClan, long siegeDeclaredTime, OutpostState outpostState) + { + _host = outpostManager; + + _health = health; + + _siegeDeclaredTime = siegeDeclaredTime; + _against = againstClan; + + _id = id; + + _siegeWeaponDistance = outpostType._size + 27.5; + + _owner = ownerClan; + + _startCorner = origin.clone().subtract(outpostType._size, 1.1, outpostType._size); + _endCorner = origin.clone().add(outpostType._size + .9, outpostType._ySize - 1, outpostType._size + .9); + + _weapons = new ArrayList<>(); + + _forceFieldStart = _startCorner.clone().subtract(4, 0, 4); + _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); + + _origin = origin; + + _type = outpostType; + + _spawnTime = spawnTime; + + _core = _type.getCoreLocation(_origin); + + _preHologram = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_owner.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); + _preHologram2 = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + + _preHologram.start(); + _preHologram2.start(); + + _dataEntity = origin.getWorld().spawn(origin, ArmorStand.class); + + _state = outpostState; + } + public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) { _host = host; + _id = Integer.toString(UtilMath.random.nextInt(13333337)); + _siegeWeaponDistance = type._size + 27.5; _owner = clan; @@ -135,8 +184,8 @@ public class Outpost implements Listener _weapons = new ArrayList<>(); - _forceFieldStart = _startCorner.clone().subtract(3, 0, 3); - _forceFieldEnd = _endCorner.clone().add(3, 0, 3); + _forceFieldStart = _startCorner.clone().subtract(4, 0, 4); + _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); _origin = location.clone(); @@ -152,9 +201,27 @@ public class Outpost implements Listener _preHologram.start(); _preHologram2.start(); + _dataEntity = location.getWorld().spawn(location, ArmorStand.class); + _state = OutpostState.AWAITING; } + private void updateData() + { + try + { + String data = ""; + + + + _dataEntity.setMetadata("$SERIALIZED_OUTPOST_DATA$", new FixedMetadataValue(_host.getPlugin(), data)); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + private void cleanup() { _blocks = null; @@ -210,12 +277,16 @@ public class Outpost implements Listener @EventHandler(priority = EventPriority.HIGHEST) public void fireBow(EntityShootBowEvent event) { - if (!(event.getEntity() instanceof Player)) + if (!(event.getEntity() instanceof Player) || !(event.getProjectile() instanceof Arrow)) { return; } + + event.setCancelled(true); + Player player = (Player) event.getEntity(); + Arrow arrow = player.shootArrow(); if (_owner.isMember(player)) { @@ -230,10 +301,10 @@ public class Outpost implements Listener if (item.isSimilar(SIEGE_DECLARATION_ARROW)) { - if (_against == null && !event.getProjectile().hasMetadata("OutpostData")) + if (_against == null && !arrow.hasMetadata("OutpostData")) { - event.getProjectile().setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); - _declarationArrow = (Arrow) event.getProjectile(); + arrow.setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); + _declarationArrow = (Arrow) arrow; } player.getInventory().setItem(slot, null); @@ -301,6 +372,15 @@ public class Outpost implements Listener protected void update() { + if (_declarationArrow != null) + { + _declarationArrow.setFireTicks(20); + + RGBData color = _arrowColors.next(); + + UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX); + } + if (_against != null && getTimeToSiege() > 0) { _against.getOnlinePlayers().forEach(this::informTimeToSiege); @@ -321,15 +401,6 @@ public class Outpost implements Listener return; } - if (_declarationArrow != null) - { - _declarationArrow.setFireTicks(20); - - RGBData color = _arrowColors.next(); - - UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX); - } - _preHologram2.setText(UtilText.getProgress(null, UtilMath.clamp(getLifetime(), 0., 60000.) / 60000., null, true)); RGBData color = UtilColor.RgbLightBlue; @@ -490,13 +561,6 @@ public class Outpost implements Listener return list; } - public void instakill() - { - _blocks.values().forEach(OutpostBlock::restore); - - cleanup(); - } - public void kill() { _state = OutpostState.DESTRUCTING; @@ -663,7 +727,7 @@ public class Outpost implements Listener public long getTimeToSiege() { - return System.currentTimeMillis() - getTimeSiegeDeclared(); + return PREP_TIME - (System.currentTimeMillis() - getTimeSiegeDeclared()); } public void setDeclarationArrow(Arrow arrow) @@ -680,4 +744,9 @@ public class Outpost implements Listener { _weapons.add(weapon); } + + public String getId() + { + return _id; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index d0702fbb5..3034e6f0d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -1,15 +1,18 @@ package mineplex.game.clans.clans.siege.outpost; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -20,11 +23,9 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; -import mineplex.core.common.events.ServerShutdownEvent; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; -import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; @@ -39,12 +40,14 @@ import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.core.repository.ClanTerritory; +import mineplex.game.clans.spawn.Spawn; public class OutpostManager extends MiniPlugin { private ClansManager _clansManager; private Map _outposts = new HashMap<>(); + private Map _idToOutpost = new HashMap<>(); private List _removalQueue; @@ -61,6 +64,182 @@ public class OutpostManager extends MiniPlugin _removalQueue = new ArrayList<>(); } + public void loadExistingOutposts() + { + try + { + for (Entity entity : Spawn.getSpawnWorld().getEntities()) + { + if (!(entity instanceof ArmorStand)) + { + continue; + } + + if (!entity.hasMetadata("$SERIALIZED_OUTPOST_DATA$")) + { + continue; + } + + ArmorStand stand = (ArmorStand) entity; + + String data = entity.getMetadata("$SERIALIZED_OUTPOST_DATA$").get(0).asString(); + + ByteArrayInputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); + DataInputStream dis = new DataInputStream(stream); + + String id; + Location origin; + OutpostType outpostType; + ClanInfo ownerClan; + double health; + long spawnTime; + ClanInfo againstClan; + long siegeDeclaredTime; + OutpostState outpostState; + + // Read UUID + { + int uuidLength = dis.readInt(); + + StringBuilder clanName = new StringBuilder(); + + for (int i = 0; i < uuidLength; i++) + { + clanName.append((char) dis.readByte()); + } + + id = clanName.toString(); + } + + // Read origin location + { + int worldLength = dis.readInt(); + + StringBuilder worldName = new StringBuilder(); + + for (int i = 0; i < worldLength; i++) + { + worldName.append((char) dis.readByte()); + } + + String world = worldName.toString(); + + int x = dis.readInt(); + int y = dis.readInt(); + int z = dis.readInt(); + + origin = new Location(Bukkit.getWorld(world), x, y, z); + } + + // Read outpost type + { + int typeLength = dis.readInt(); + + StringBuilder type = new StringBuilder(); + + for (int i = 0; i < typeLength; i++) + { + type.append((char) dis.readByte()); + } + + outpostType = OutpostType.valueOf(type.toString()); + } + + // Read owner clan + { + int clanNameLength = dis.readInt(); + + StringBuilder clanName = new StringBuilder(); + + for (int i = 0; i < clanNameLength; i++) + { + clanName.append((char) dis.readByte()); + } + + ClanInfo clan = _clansManager.getClanUtility().getClanByClanName(clanName.toString()); + + if (clan == null) + { + System.out.println("OUTPOSTMANAGER: Tried to load Outpost (ID: " + id + ") but did not find owner clan."); + return; + } + + ownerClan = clan; + } + + // Read health + { + health = dis.readDouble(); + } + + // Read spawn time + { + spawnTime = dis.readLong(); + } + + // Read "against" clan + { + int clanNameLength = dis.readInt(); + + if (clanNameLength == 0) + { + againstClan = null; + } + else + { + StringBuilder clanName = new StringBuilder(); + + for (int i = 0; i < clanNameLength; i++) + { + clanName.append((char) dis.readByte()); + } + + ClanInfo clan = _clansManager.getClanUtility().getClanByClanName(clanName.toString()); + + if (clan == null) + { + System.out.println("OUTPOSTMANAGER: Tried to load Outpost (ID: " + id + ") but did not find against clan."); + return; + } + + againstClan = clan; + } + } + + // Read siegeDeclaredTime + { + siegeDeclaredTime = dis.readLong(); + } + + // Read outpost state + { + int stateLength = dis.readInt(); + + StringBuilder state = new StringBuilder(); + + for (int i = 0; i < stateLength; i++) + { + state.append((char) dis.readByte()); + } + + outpostState = OutpostState.valueOf(state.toString()); + } + + dis.close(); + stream.close(); + + Outpost outpost = new Outpost(this, id, origin, ownerClan, outpostType, health, spawnTime, againstClan, siegeDeclaredTime, outpostState); + + _outposts.put(ownerClan.getName(), outpost); + _idToOutpost.put(id, outpost); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + @EventHandler(priority = EventPriority.LOWEST) public void onPlaceBlock(BlockPlaceEvent event) { @@ -187,6 +366,7 @@ public class OutpostManager extends MiniPlugin } _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); + _idToOutpost.put(_outposts.get(clan.getName()).getId(), _outposts.get(clan.getName())); _plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin); @@ -202,15 +382,6 @@ public class OutpostManager extends MiniPlugin } } - @EventHandler - public void onServerShutdown(ServerShutdownEvent event) - { - for (Outpost outpost : _outposts.values()) - { - outpost.instakill(); - } - } - @EventHandler public void onClaim(PlayerClaimTerritoryEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 5ef7f26fc..ea1ddbee3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -136,7 +136,7 @@ public class Cannon extends SiegeWeapon armorStand.setVisible(false); armorStand.setGravity(false); - armorStand.setPassenger(getEntity("Filler")); + armorStand.setPassenger(getEntity("Filler_1")); addEntity(armorStand, "WEAPON"); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 240ab2315..f15d5f1d9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -1,7 +1,10 @@ package mineplex.game.clans.clans.siege.weapon; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; import org.apache.commons.lang.Validate; import org.bukkit.Location; @@ -49,6 +52,7 @@ import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox; @@ -123,8 +127,12 @@ public abstract class SiegeWeapon implements Listener protected boolean _alive = true; - public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) + protected final int _weaponTypeIdentifier; + + public SiegeWeapon(int typeId, Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) { + _weaponTypeIdentifier = typeId; + _outpost = outpost; _siegeManager = siegeManager; _location = location; @@ -144,6 +152,39 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; } + public SiegeWeaponToken tokenize() + { + SiegeWeaponToken token = new SiegeWeaponToken(); + + Map comprisedOf = new HashMap<>(); + + for (Entry entry : _entityMapping.entrySet()) + { + comprisedOf.put(entry.getKey(), entry.getValue().getUniqueId()); + } + + + token.ComprisedOf = comprisedOf; + + token.OwnerClan = _owner; + + token.WeaponType = _weaponTypeIdentifier; + + token.OutpostId = _outpost == null ? null : _outpost.getId(); + + token.Location = _location; + + token.Health = _health; + + token.Yaw = _yaw; + + token.Rider = _rider; + + token.LastFired = _lastFired; + + return token; + } + public int getBaseDamage() { return _baseDamage; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java new file mode 100644 index 000000000..3ba7ee23f --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java @@ -0,0 +1,19 @@ +package mineplex.game.clans.clans.siege.weapon.serialization; + +import org.bukkit.Location; + +import mineplex.game.clans.clans.siege.outpost.OutpostState; +import mineplex.game.clans.clans.siege.outpost.OutpostType; + +public class OutpostToken +{ + public String Id; + public Location Origin; + public OutpostType Type; + public String OwnerClan; + public double Health; + public long TimeSpawned; + public String againstClan; + public long siegeDeclaredTime; + public OutpostState outpostState; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java new file mode 100644 index 000000000..858214ae4 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java @@ -0,0 +1,22 @@ +package mineplex.game.clans.clans.siege.weapon.serialization; + +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import mineplex.game.clans.clans.ClanInfo; + +public class SiegeWeaponToken +{ + public ClanInfo OwnerClan; + public int WeaponType; + public String OutpostId; + public Location Location; + public Map ComprisedOf; + public double Health; + public double Yaw; + public Player Rider; + public long LastFired; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java new file mode 100644 index 000000000..2bab907e6 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java @@ -0,0 +1,6 @@ +package mineplex.game.clans.clans.siege.weapon.serialization; + +public class TokenInfo +{ + public Class Type; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index a7e4d801e..ac061de02 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -164,11 +164,6 @@ public class Gameplay extends MiniPlugin if (!playerClass.IsGameClass(ClassType.Assassin, ClassType.Ranger)) { - if (event.getProjectile().hasMetadata("OutpostData")) - { - return; - } - notify(player, "You cannot use bows without the proper class!"); event.setCancelled(true); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java index 4b7bc5f4b..7dbdfd162 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/SafeLog.java @@ -1,6 +1,8 @@ package mineplex.game.clans.gameplay.safelog; +import java.io.DataInputStream; import java.io.File; +import java.io.FileInputStream; import java.util.ArrayList; import java.util.List; @@ -13,9 +15,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; -import mineplex.core.common.file.DataFileInStream; -import mineplex.core.common.file.chunks.DataChunkLong; -import mineplex.core.common.file.chunks.DataChunkString; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; @@ -77,10 +76,18 @@ public class SafeLog extends MiniPlugin { try { - DataFileInStream stream = new DataFileInStream(_clansManager.UserDataDir + String.format("DEATH_%s.dat", player.getUniqueId().toString())); + DataInputStream stream = new DataInputStream(new FileInputStream(deathFile)); - final long time = DataChunkLong.ReadFrom(stream).longValue(); - final String killerName = DataChunkString.ReadFrom(stream); + final long time = stream.readLong(); + final int length = stream.readInt(); + final StringBuilder killerName = new StringBuilder(); + + for (int i = 0; i < length; i++) + { + killerName.append((char) stream.readByte()); + } + + stream.close(); UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() { @@ -92,8 +99,6 @@ public class SafeLog extends MiniPlugin } }, 15); - stream.dispose(); - deathFile.delete(); } catch (Exception e) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java index eacca4e90..f83a7b0cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/safelog/npc/CombatLogNPC.java @@ -1,6 +1,8 @@ package mineplex.game.clans.gameplay.safelog.npc; +import java.io.DataOutputStream; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.util.List; @@ -15,8 +17,6 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; import org.bukkit.metadata.FixedMetadataValue; -import mineplex.core.common.file.DataFileOutStream; -import mineplex.core.common.file.UtilFile; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEnt; @@ -90,20 +90,20 @@ public class CombatLogNPC { killerName = ((CraftPlayer) killer).getName(); } - else if (killer != null) + else { killerName = UtilEnt.getName(killer); } - System.out.println(killerName); - try { - DataFileOutStream stream = new DataFileOutStream(); + DataOutputStream stream = new DataOutputStream(new FileOutputStream(_userDataPath + String.format("DEATH_%s.dat", _playerInfo.getPlayerUuid()))); - stream.writeToFile(_userDataPath + String.format("DEATH_%s.dat", _playerInfo.getPlayerUuid())); + stream.writeLong(System.currentTimeMillis()); + stream.writeInt(killerName.length()); + stream.writeBytes(killerName); - stream.release(); + stream.close(); } catch (IOException e) { From e6eb43ada84cf62cd2f2cf11bbe18ddf8245efd9 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Fri, 12 Feb 2016 19:58:40 +0000 Subject: [PATCH 091/122] PUSHING CODE BECAUSE MY HDD MIGHT BE BREAKING DOWN. THIS CODE IS UNTESTED PROBABLY DOESN'T WORK --- .../mineplex/core/common/GsonLocation.java | 80 +++++++++ .../src/mineplex/core/common/Pair.java | 2 +- .../core/common/gson/UUIDTypeAdapter.java | 43 ----- .../src/mineplex/core/updater/UpdateType.java | 4 + .../game/clans/clans/siege/SiegeManager.java | 129 ++++++++------ .../clans/clans/siege/outpost/Outpost.java | 93 ++++++++-- .../clans/siege/outpost/OutpostManager.java | 167 ++---------------- .../game/clans/clans/siege/weapon/Cannon.java | 77 +++++++- .../clans/clans/siege/weapon/Catapult.java | 74 +++++++- .../clans/clans/siege/weapon/SiegeWeapon.java | 103 ++++++++++- .../weapon/serialization/OutpostToken.java | 13 +- .../serialization/SiegeWeaponToken.java | 11 +- 12 files changed, 512 insertions(+), 284 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/GsonLocation.java delete mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/GsonLocation.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/GsonLocation.java new file mode 100644 index 000000000..2e4ac3446 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/GsonLocation.java @@ -0,0 +1,80 @@ +package mineplex.core.common; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; + +public class GsonLocation +{ + private String _world; + private double _posX; + private double _posY; + private double _posZ; + private float _yaw; + private float _pitch; + + public GsonLocation(Location location) + { + _world = location.getWorld().getName(); + _posX = location.getX(); + _posY = location.getY(); + _posZ = location.getZ(); + _yaw = location.getYaw(); + _pitch = location.getPitch(); + } + + public GsonLocation(String world, double x, double y, double z) + { + this(Bukkit.getWorld(world), x, y, z, .0f, .0f); + } + + public GsonLocation(String world, double x, double y, double z, float yaw, float pitch) + { + this(Bukkit.getWorld(world), x, y, z, yaw, pitch); + } + + public GsonLocation(World world, double x, double y, double z, float yaw, float pitch) + { + _world = world.getName(); + _posX = x; + _posY = y; + _posZ = z; + _yaw = yaw; + _pitch = pitch; + } + + public GsonLocation(double x, double y, double z) + { + this(x, y, z, .0f, .0f); + } + + public GsonLocation(double x, double y, double z, float yaw, float pitch) + { + this("world", x, y, z, yaw, pitch); + } + + public Location bukkit() + { + return new Location(Bukkit.getWorld(_world), _posX, _posY, _posZ); + } + + public String getWorld() + { + return _world; + } + + public double getX() + { + return _posX; + } + + public double getY() + { + return _posY; + } + + public double getZ() + { + return _posZ; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java index b39c3dce5..7ec401ed6 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/Pair.java @@ -8,7 +8,7 @@ public class Pair implements Serializable { private L left; private R right; - + public static Pair create(L left, R right) { return new Pair(left, right); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java deleted file mode 100644 index 73aef088d..000000000 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/gson/UUIDTypeAdapter.java +++ /dev/null @@ -1,43 +0,0 @@ -package mineplex.core.common.gson; - -import java.io.IOException; -import java.util.UUID; - -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - -public class UUIDTypeAdapter extends TypeAdapter -{ - public UUID read(JsonReader reader) throws IOException - { - String uuid = null; - - reader.beginObject(); - - read: - while (reader.hasNext()) - { - switch (reader.nextName()) - { - case "bytes": - { - uuid = reader.nextString(); - break read; - } - } - } - - reader.endObject(); - - return UUID.fromString(uuid); - } - - public void write(JsonWriter writer, UUID uuid) throws IOException - { - writer.beginObject(); - writer.name("bytes").value(uuid.toString()); - writer.endObject(); - } - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java b/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java index 52d63e2a1..419ace87c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/updater/UpdateType.java @@ -64,6 +64,10 @@ public enum UpdateType * Once every 8 seconds */ SEC_08(8000), + /** + * Once every 5 seconds + */ + SEC_05(5000), /** * Once every 4 seconds */ diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 35a8a8935..1e9621533 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,8 +1,7 @@ package mineplex.game.clans.clans.siege; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.HashMap; +import java.util.Map; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; @@ -18,10 +17,11 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import mineplex.core.MiniPlugin; -import mineplex.core.common.gson.UUIDTypeAdapter; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; @@ -31,7 +31,7 @@ import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; -import mineplex.game.clans.clans.siege.weapon.serialization.TokenInfo; +import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.spawn.Spawn; @@ -43,7 +43,7 @@ public class SiegeManager extends MiniPlugin public static SiegeManager Instance; - public List LiveSiegeWeapons = new ArrayList<>(); + public Map LiveSiegeWeapons = new HashMap<>(); private Gson _gson; @@ -51,7 +51,7 @@ public class SiegeManager extends MiniPlugin { super("Siege", plugin); - _gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create(); + _gson = new Gson(); _clans = clans; @@ -66,45 +66,17 @@ public class SiegeManager extends MiniPlugin Instance = this; } - /** - * data clusters: - * STRING : { - * int(4BYTE) length; - * byte[] bytes; - * } - * - * LOCATION : { - * STRING world; - * int(4BYTE) x; - * int(4BYTE) y; - * int(4BYTE) z; - * } - * - * ITEM : { - * STRING material; - * byte data; - * int amount; - * } - * - * INVENTORY : { - * int numOfEntries; - * ITEM[] item; - * } - * - * data format: - * Outpost { - * STRING clanOwner; - * int weaponType; - * STRING outpostId; - * LOCATION location; - * INVENTORY inventory; - * MAP comprisedOf; - * double health; - * double yaw; - * String rider; - * long lastFired; - * } - */ + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() == UpdateType.SLOWER) + { + _outpostManager.loadExistingOutposts(); + + loadExistingWeapons(); + } + } + private void loadExistingWeapons() { try @@ -121,14 +93,55 @@ public class SiegeManager extends MiniPlugin continue; } - ArmorStand stand = (ArmorStand) entity; - String data = entity.getMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$").get(0).asString(); - String type = entity.getMetadata("$TOKEN_INFO$").get(0).asString(); - SiegeWeapon weapon = _gson.fromJson(data, _gson.fromJson(type, TokenInfo.class).Type); + SiegeWeaponToken token = _gson.fromJson(data, SiegeWeaponToken.class); + if (LiveSiegeWeapons.containsKey(token.Id)) + { + continue; + } + if (_clans.getClan(token.OwnerClan) == null) + { + for (Entity other : Spawn.getSpawnWorld().getEntities()) + { + if (token.ComprisedOf.values().contains(other.getUniqueId())) + { + other.remove(); + } + else if (other.getUniqueId().equals(token.DataEntityUUID)) + { + other.remove(); + } + } + + continue; + } + + SiegeWeapon weapon = null; + + switch (token.WeaponType) + { + case 1: + { + weapon = new Catapult(this, token); + break; + } + + case 2: + { + weapon = new Cannon(this, token); + break; + } + } + + LiveSiegeWeapons.put(token.Id, weapon); + + if (_outpostManager.Get(token.OutpostId) != null) + { + _outpostManager.Get(token.OutpostId).addWeapon(weapon); + } } } @@ -266,6 +279,8 @@ public class SiegeManager extends MiniPlugin { outpost.addWeapon(cannon); } + + LiveSiegeWeapons.put(cannon.getId(), cannon); } public boolean trySpawnCatapult(Player player, Location location) @@ -327,11 +342,13 @@ public class SiegeManager extends MiniPlugin { outpost.addWeapon(catapult); } + + LiveSiegeWeapons.put(catapult.getId(), catapult); } public void dead(SiegeWeapon weapon) { - LiveSiegeWeapons.remove(weapon); + LiveSiegeWeapons.remove(weapon.getId()); } public OutpostManager getOutpostManager() @@ -339,4 +356,14 @@ public class SiegeManager extends MiniPlugin return _outpostManager; } + public Gson getGson() + { + return _gson; + } + + public ClansManager getClansManager() + { + return _clans; + } + } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 3c3e82886..41269da61 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -1,14 +1,17 @@ package mineplex.game.clans.clans.siege.outpost; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; +import java.util.Random; import java.util.UUID; +import java.util.Map.Entry; import org.bukkit.Location; import org.bukkit.Material; @@ -16,6 +19,7 @@ import org.bukkit.Sound; import org.bukkit.block.Chest; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -64,6 +68,7 @@ import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.clans.siege.weapon.serialization.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; @@ -127,34 +132,34 @@ public class Outpost implements Listener private ArmorStand _dataEntity; - public Outpost(OutpostManager outpostManager, String id, Location origin, ClanInfo ownerClan, OutpostType outpostType, double health, long spawnTime, ClanInfo againstClan, long siegeDeclaredTime, OutpostState outpostState) + public Outpost(OutpostManager outpostManager, OutpostToken token) { _host = outpostManager; - _health = health; + _health = token.Health; - _siegeDeclaredTime = siegeDeclaredTime; - _against = againstClan; + _siegeDeclaredTime = token.SiegeDeclaredTime; + _against = outpostManager.getClansManager().getClan(token.AgainstClan); - _id = id; + _id = token.Id; - _siegeWeaponDistance = outpostType._size + 27.5; + _siegeWeaponDistance = token.Type._size + 27.5; - _owner = ownerClan; + _owner = outpostManager.getClansManager().getClan(token.OwnerClan); - _startCorner = origin.clone().subtract(outpostType._size, 1.1, outpostType._size); - _endCorner = origin.clone().add(outpostType._size + .9, outpostType._ySize - 1, outpostType._size + .9); + _startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size); + _endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9); _weapons = new ArrayList<>(); _forceFieldStart = _startCorner.clone().subtract(4, 0, 4); _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); - _origin = origin; + _origin = token.Origin; - _type = outpostType; + _type = token.Type; - _spawnTime = spawnTime; + _spawnTime = token.TimeSpawned; _core = _type.getCoreLocation(_origin); @@ -164,15 +169,23 @@ public class Outpost implements Listener _preHologram.start(); _preHologram2.start(); - _dataEntity = origin.getWorld().spawn(origin, ArmorStand.class); + _state = token.OutpostState; - _state = outpostState; + for (Entity entity : token.Origin.getWorld().getEntities()) + { + if (entity.getUniqueId().equals(token.DataEntityUUID)) + { + _dataEntity = (ArmorStand) entity; + } + } } public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) { _host = host; + location.add(.5, 0, .5); + _id = Integer.toString(UtilMath.random.nextInt(13333337)); _siegeWeaponDistance = type._size + 27.5; @@ -201,18 +214,49 @@ public class Outpost implements Listener _preHologram.start(); _preHologram2.start(); - _dataEntity = location.getWorld().spawn(location, ArmorStand.class); + _dataEntity = location.getWorld().spawn(location.subtract(0, 5, 0), ArmorStand.class); + _dataEntity.setVisible(false); + _dataEntity.setGravity(false); _state = OutpostState.AWAITING; } + + public OutpostToken tokenize() + { + OutpostToken token = new OutpostToken(); + + token.Id = _id; + + token.Origin = _origin; + + token.Type = _type; + + token.OwnerClan = _owner.getName(); + + token.Health = _health; + + token.TimeSpawned = _spawnTime; + + token.AgainstClan = _against != null ? _against.getName() : null; + + token.DataEntityUUID = _dataEntity.getUniqueId(); + + token.SiegeDeclaredTime = _siegeDeclaredTime; + + token.OutpostState = _state; + + return token; + } private void updateData() { try { - String data = ""; - + String data = _host.getSiegeManager().getGson().toJson(tokenize()); + PrintWriter writer = new PrintWriter(new FileWriter(new File("H:\\" + new Random().nextInt()))); + writer.print(data); + writer.close(); _dataEntity.setMetadata("$SERIALIZED_OUTPOST_DATA$", new FixedMetadataValue(_host.getPlugin(), data)); } @@ -222,6 +266,15 @@ public class Outpost implements Listener } } + @EventHandler + public void saveData(UpdateEvent event) + { + if (event.getType() == UpdateType.SEC_05) + { + updateData(); + } + } + private void cleanup() { _blocks = null; @@ -237,6 +290,8 @@ public class Outpost implements Listener _weapons.forEach(SiegeWeapon::kill); _weapons.clear(); + _dataEntity.remove(); + _host.queueForRemoval(_owner.getName()); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 3034e6f0d..d032a9b6b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -1,14 +1,10 @@ package mineplex.game.clans.clans.siege.outpost; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; @@ -39,6 +35,7 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; +import mineplex.game.clans.clans.siege.weapon.serialization.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.spawn.Spawn; @@ -80,158 +77,12 @@ public class OutpostManager extends MiniPlugin continue; } - ArmorStand stand = (ArmorStand) entity; - String data = entity.getMetadata("$SERIALIZED_OUTPOST_DATA$").get(0).asString(); - ByteArrayInputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); - DataInputStream dis = new DataInputStream(stream); + Outpost outpost = new Outpost(this, _siegeManager.getGson().fromJson(data, OutpostToken.class)); - String id; - Location origin; - OutpostType outpostType; - ClanInfo ownerClan; - double health; - long spawnTime; - ClanInfo againstClan; - long siegeDeclaredTime; - OutpostState outpostState; - - // Read UUID - { - int uuidLength = dis.readInt(); - - StringBuilder clanName = new StringBuilder(); - - for (int i = 0; i < uuidLength; i++) - { - clanName.append((char) dis.readByte()); - } - - id = clanName.toString(); - } - - // Read origin location - { - int worldLength = dis.readInt(); - - StringBuilder worldName = new StringBuilder(); - - for (int i = 0; i < worldLength; i++) - { - worldName.append((char) dis.readByte()); - } - - String world = worldName.toString(); - - int x = dis.readInt(); - int y = dis.readInt(); - int z = dis.readInt(); - - origin = new Location(Bukkit.getWorld(world), x, y, z); - } - - // Read outpost type - { - int typeLength = dis.readInt(); - - StringBuilder type = new StringBuilder(); - - for (int i = 0; i < typeLength; i++) - { - type.append((char) dis.readByte()); - } - - outpostType = OutpostType.valueOf(type.toString()); - } - - // Read owner clan - { - int clanNameLength = dis.readInt(); - - StringBuilder clanName = new StringBuilder(); - - for (int i = 0; i < clanNameLength; i++) - { - clanName.append((char) dis.readByte()); - } - - ClanInfo clan = _clansManager.getClanUtility().getClanByClanName(clanName.toString()); - - if (clan == null) - { - System.out.println("OUTPOSTMANAGER: Tried to load Outpost (ID: " + id + ") but did not find owner clan."); - return; - } - - ownerClan = clan; - } - - // Read health - { - health = dis.readDouble(); - } - - // Read spawn time - { - spawnTime = dis.readLong(); - } - - // Read "against" clan - { - int clanNameLength = dis.readInt(); - - if (clanNameLength == 0) - { - againstClan = null; - } - else - { - StringBuilder clanName = new StringBuilder(); - - for (int i = 0; i < clanNameLength; i++) - { - clanName.append((char) dis.readByte()); - } - - ClanInfo clan = _clansManager.getClanUtility().getClanByClanName(clanName.toString()); - - if (clan == null) - { - System.out.println("OUTPOSTMANAGER: Tried to load Outpost (ID: " + id + ") but did not find against clan."); - return; - } - - againstClan = clan; - } - } - - // Read siegeDeclaredTime - { - siegeDeclaredTime = dis.readLong(); - } - - // Read outpost state - { - int stateLength = dis.readInt(); - - StringBuilder state = new StringBuilder(); - - for (int i = 0; i < stateLength; i++) - { - state.append((char) dis.readByte()); - } - - outpostState = OutpostState.valueOf(state.toString()); - } - - dis.close(); - stream.close(); - - Outpost outpost = new Outpost(this, id, origin, ownerClan, outpostType, health, spawnTime, againstClan, siegeDeclaredTime, outpostState); - - _outposts.put(ownerClan.getName(), outpost); - _idToOutpost.put(id, outpost); + _outposts.put(outpost.getOwner().getName(), outpost); + _idToOutpost.put(outpost.getId(), outpost); } } catch (Exception e) @@ -514,4 +365,14 @@ public class OutpostManager extends MiniPlugin return false; } + + public Outpost Get(String outpostId) + { + return _idToOutpost.get(outpostId); + } + + public ClansManager getClansManager() + { + return _clansManager; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index ea1ddbee3..0be4de966 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -1,9 +1,13 @@ package mineplex.game.clans.clans.siege.weapon; +import java.util.Map.Entry; +import java.util.UUID; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; @@ -26,6 +30,7 @@ import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; @@ -34,11 +39,77 @@ public class Cannon extends SiegeWeapon { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + public Cannon(SiegeManager siegeManager, SiegeWeaponToken token) + { + super(1400.d, "Cannon", token, siegeManager.getClansManager(), siegeManager); + + setBoundingBox(1); + + setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); + setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0)); + + setFirepowerType(Material.SULPHUR); + setAmmunitionType(Material.TNT); + + setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7)); + setMaximumFirepowerPerSlot(3); + + setAmmunitionSlot(4); + setMaximumAmmunitionPerSlot(1); + + _baseDamage = 650; + + setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d)); + + setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { + if (!isRiding(player)) + { + return false; + } + + if (!_owner.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); + return false; + } + + if (!canBeFired()) + { + UtilPlayer.message(player, F.main("Clans", "Cannon is not loaded correctly.")); + return false; + } + + if (System.currentTimeMillis() - _lastFired < 20000) + { + UtilPlayer.message(player, F.main("Clans", "Cannon is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")")); + return false; + } + + return true; + })); + + enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); + + setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { + if (!_owner.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); + return false; + } + + if (getRider() != null && !getRider().equals(player)) + { + UtilPlayer.message(player, F.main("Clans", "Someone is already riding this cannon.")); + return false; + } + + return !player.equals(getRider()); + })); + } + public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) { - super(location, 1400.d, "Cannon", clan, clan.Clans, siegeManager, outpost); - - location.add(.5, 0, .5); + super(2, location, 1400.d, "Cannon", clan, clan.Clans, siegeManager, outpost); setBoundingBox(1); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 5ce685020..6b0200754 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -26,6 +26,7 @@ import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; +import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; @@ -34,9 +35,80 @@ public class Catapult extends SiegeWeapon { public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); + public Catapult(SiegeManager siegeManager, SiegeWeaponToken token) + { + super(1400.d, "Catapult", token, siegeManager.getClansManager(), siegeManager); + + setBoundingBox(3, 0); + + setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0)); + setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0)); + setStateInfo("Fired", new WeaponStateInfo(Material.LAPIS_BLOCK, (byte) 0)); + + setFirepowerType(Material.FIREBALL); + setAmmunitionType(Material.COBBLESTONE); + + setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7)); + setMaximumFirepowerPerSlot(3); + + setAmmunitionSlot(4); + setMaximumAmmunitionPerSlot(1); + + setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d)); + + _baseDamage = 550; + + _rotSpeed = 60.0f; + + setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> { + if (!isRiding(player)) + { + return false; + } + + if (!_owner.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); + return false; + } + + if (!canBeFired()) + { + UtilPlayer.message(player, F.main("Clans", "Catapult is not loaded correctly.")); + return false; + } + + if (System.currentTimeMillis() - _lastFired < 20000) + { + UtilPlayer.message(player, F.main("Clans", "Catapult is cooling down (" + F.time(UtilTime.MakeStr(20000 - (System.currentTimeMillis() - _lastFired))) + ")")); + return false; + } + + return true; + })); + + enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); + + setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { + if (!_owner.isMember(player)) + { + UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); + return false; + } + + if (getRider() != null && !getRider().equals(player)) + { + UtilPlayer.message(player, F.main("Clans", "Someone is already riding this Catapult.")); + return false; + } + + return !player.equals(getRider()); + })); + } + public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) { - super(location, 2500.d, "Catapult", clan, clan.Clans, siegeManager, outpost); + super(1, location, 2500.d, "Catapult", clan, clan.Clans, siegeManager, outpost); setBoundingBox(3, 0); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index f15d5f1d9..e7ca2fd56 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -7,6 +7,7 @@ import java.util.Map.Entry; import java.util.UUID; import org.apache.commons.lang.Validate; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -27,6 +28,7 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.EulerAngle; import org.spigotmc.event.entity.EntityDismountEvent; @@ -50,6 +52,7 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.Outpost; +import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; @@ -63,6 +66,8 @@ public abstract class SiegeWeapon implements Listener protected ClansManager _clans; protected SiegeManager _siegeManager; + protected String _id; + /** * THIS MAY BE NULL IF NOT PLACED IN OUTPOST */ @@ -87,7 +92,7 @@ public abstract class SiegeWeapon implements Listener protected final List _comprisedOf; // Friendly-name mapping to index in _comprisedOf for easier management of entities. - private final Map _entityMapping; + protected final Map _entityMapping; private boolean _isRideable; private AccessRule _mountAccess; @@ -129,8 +134,60 @@ public abstract class SiegeWeapon implements Listener protected final int _weaponTypeIdentifier; + private ArmorStand _dataEntity; + + public SiegeWeapon(double maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager) + { + _weaponTypeIdentifier = token.WeaponType; + + _id = token.Id; + + _outpost = siegeManager.getOutpostManager().Get(token.OutpostId); + _siegeManager = siegeManager; + _location = token.Location; + _name = name; + _health = _maxHealth = maxHealth; + _owner = clansManager.getClan(token.OwnerClan); + + _comprisedOf = Lists.newArrayList(); + _registeredStates = Maps.newHashMap(); + _entityMapping = Maps.newHashMap(); + + _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); + _infoHologram.start(); + + UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); + + _clans = clansManager; + + for (Entity entity : token.Location.getWorld().getEntities()) + { + for (Entry entry : token.ComprisedOf.entrySet()) + { + if (entity.getUniqueId().equals(entry.getValue())) + { + _comprisedOf.add(entity); + _entityMapping.put(entry.getKey(), entity); + } + } + + if (entity.getUniqueId().equals(token.DataEntityUUID)) + { + _dataEntity = (ArmorStand) entity; + } + } + + + _yaw = token.Yaw; + _rider = Bukkit.getPlayer(token.Rider); + _lastFired = token.LastFired; + + _health = token.Health; + } + public SiegeWeapon(int typeId, Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) { + _id = Integer.toString(UtilMath.random.nextInt(13333337)); _weaponTypeIdentifier = typeId; _outpost = outpost; @@ -150,6 +207,10 @@ public abstract class SiegeWeapon implements Listener UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); _clans = clansManager; + + _dataEntity = location.getWorld().spawn(location.subtract(0, 5, 0), ArmorStand.class); + _dataEntity.setVisible(false); + _dataEntity.setGravity(false); } public SiegeWeaponToken tokenize() @@ -166,11 +227,13 @@ public abstract class SiegeWeapon implements Listener token.ComprisedOf = comprisedOf; - token.OwnerClan = _owner; + token.OwnerClan = _owner.getName(); token.WeaponType = _weaponTypeIdentifier; - token.OutpostId = _outpost == null ? null : _outpost.getId(); + token.OutpostId = _outpost.getId(); + + token.Id = _id; token.Location = _location; @@ -178,13 +241,38 @@ public abstract class SiegeWeapon implements Listener token.Yaw = _yaw; - token.Rider = _rider; + token.DataEntityUUID = _dataEntity.getUniqueId(); + + token.Rider = _rider.getUniqueId(); token.LastFired = _lastFired; return token; } + private void updateData() + { + try + { + String data = _siegeManager.getGson().toJson(tokenize()); + + _dataEntity.setMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$", new FixedMetadataValue(_siegeManager.getPlugin(), data)); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + @EventHandler + public void saveData(UpdateEvent event) + { + if (event.getType() == UpdateType.SEC_05) + { + updateData(); + } + } + public int getBaseDamage() { return _baseDamage; @@ -409,6 +497,11 @@ public abstract class SiegeWeapon implements Listener return player.equals(getRider()); } + public String getId() + { + return _id; + } + protected void setRideable(AccessRule accessRule) { _isRideable = true; @@ -427,6 +520,8 @@ public abstract class SiegeWeapon implements Listener _comprisedOf.clear(); _infoHologram.stop(); + _dataEntity.remove(); + _siegeManager.dead(this); _alive = false; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java index 3ba7ee23f..2810ad924 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java @@ -1,19 +1,24 @@ package mineplex.game.clans.clans.siege.weapon.serialization; +import java.util.UUID; + import org.bukkit.Location; +import mineplex.core.common.GsonLocation; +import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.outpost.OutpostState; import mineplex.game.clans.clans.siege.outpost.OutpostType; public class OutpostToken { public String Id; - public Location Origin; + public GsonLocation Origin; public OutpostType Type; public String OwnerClan; public double Health; public long TimeSpawned; - public String againstClan; - public long siegeDeclaredTime; - public OutpostState outpostState; + public String AgainstClan; + public long SiegeDeclaredTime; + public OutpostState OutpostState; + public UUID DataEntityUUID; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java index 858214ae4..e6a941a27 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java @@ -4,19 +4,20 @@ import java.util.Map; import java.util.UUID; import org.bukkit.Location; -import org.bukkit.entity.Player; -import mineplex.game.clans.clans.ClanInfo; +import mineplex.core.common.GsonLocation; public class SiegeWeaponToken { - public ClanInfo OwnerClan; + public String OwnerClan; public int WeaponType; public String OutpostId; - public Location Location; + public GsonLocation Location; public Map ComprisedOf; public double Health; public double Yaw; - public Player Rider; + public UUID Rider; + public String Id; public long LastFired; + public UUID DataEntityUUID; } From 93a5ca677715020d2920ac5db24168e8f014f469 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 13 Feb 2016 18:45:45 +0000 Subject: [PATCH 092/122] weapons need to be centered --- .../src/mineplex/game/clans/clans/siege/weapon/Cannon.java | 2 +- .../src/mineplex/game/clans/clans/siege/weapon/Catapult.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 0be4de966..15557fc9e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -200,7 +200,7 @@ public class Cannon extends SiegeWeapon getEntity("Filler_1").setPassenger(slime); addEntity(slime, "PLAYERMOUNT"); - ArmorStand armorStand = _location.getWorld().spawn(_location, ArmorStand.class); + ArmorStand armorStand = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class); UtilEnt.setFakeHead(armorStand, true); armorStand.teleport(_location); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 6b0200754..fdbbba338 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -196,7 +196,7 @@ public class Catapult extends SiegeWeapon addEntity(filler, "Filler_1"); - ArmorStand mount = _location.getWorld().spawn(_location, ArmorStand.class); + ArmorStand mount = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class); mount.setVisible(false); mount.setGravity(false); From e25accfba4a7205b5ea3325f316ee4db13be8cb6 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 15 Feb 2016 11:24:29 +0000 Subject: [PATCH 093/122] outpost saving and loadi9ng --- .../core/database/RepositoryBase.java | 5 +- .../clans/core/repository/ClanRepository.java | 5 + .../game/clans/clans/ClansManager.java | 8 +- .../game/clans/clans/ClansUtility.java | 13 + .../game/clans/clans/siege/SiegeManager.java | 113 ++----- .../CommandSiegeSupplies.java | 4 +- .../clans/clans/siege/outpost/Outpost.java | 287 ++++++++---------- .../clans/siege/outpost/OutpostBlock.java | 57 ---- .../clans/siege/outpost/OutpostBuilder.java | 18 -- .../clans/siege/outpost/OutpostManager.java | 166 +++++++--- .../clans/siege/outpost/OutpostState.java | 38 ++- .../clans/siege/outpost/OutpostType.java | 31 +- .../siege/outpost/build/OutpostBlock.java | 82 +++++ .../{ => build}/OutpostBlockBanner.java | 8 +- .../siege/repository/OutpostRepository.java | 152 ++++++++++ .../repository/SiegeWeaponRepository.java | 124 ++++++++ .../tokens}/OutpostToken.java | 16 +- .../repository/tokens/SiegeWeaponToken.java | 22 ++ .../game/clans/clans/siege/weapon/Cannon.java | 14 +- .../clans/clans/siege/weapon/Catapult.java | 14 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 121 ++------ .../serialization/SiegeWeaponToken.java | 23 -- .../siege/weapon/serialization/TokenInfo.java | 6 - .../game/clans/gameplay/Gameplay.java | 7 +- Plugins/database-config.dat | 4 + Plugins/redis-config.dat | 4 + 26 files changed, 800 insertions(+), 542 deletions(-) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/{outpost => commands}/CommandSiegeSupplies.java (86%) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlock.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/{ => build}/OutpostBlockBanner.java (82%) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/{weapon/serialization => repository/tokens}/OutpostToken.java (54%) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java create mode 100644 Plugins/database-config.dat create mode 100644 Plugins/redis-config.dat diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index 55acc83ed..2df578f9b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -146,7 +146,10 @@ public abstract class RepositoryBase implements Listener try (ResultSet resultSet = statement.executeQuery()) { - callable.processResultSet(resultSet); + if (callable != null) + { + callable.processResultSet(resultSet); + } } } catch (SQLException exception) diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java index 70f9d082b..061306b40 100644 --- a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/ClanRepository.java @@ -560,6 +560,11 @@ public class ClanRepository extends RepositoryBase // new ColumnInt("clanScore", clanScore), new ColumnInt("otherClanScore", otherClanScore), new ColumnInt("clanKills", clanKills), // new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId)); // } + + public int getServerId() + { + return _serverId; + } public boolean updateClanGenerator(int clanId, String generator, int generatorStock) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 682afca84..81891c6b7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -256,7 +256,6 @@ public class ClansManager extends MiniClientPluginimplements IRelati _itemMapManager = new ItemMapManager(this, _worldEvent); new TntGeneratorManager(plugin, this); new SupplyDropManager(plugin, this); - new SiegeManager(plugin, this); _explosion = new Explosion(plugin, blockRestore); _warPointEvasion = new WarPointEvasion(plugin); @@ -383,6 +382,8 @@ public class ClansManager extends MiniClientPluginimplements IRelati } Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); + + new SiegeManager(plugin, this); } @Override @@ -1174,4 +1175,9 @@ public class ClansManager extends MiniClientPluginimplements IRelati return null; } + + public int getServerId() + { + return _clanDataAccess.getRepository().getServerId(); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java index 4e466128c..a57f0470e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java @@ -206,6 +206,19 @@ public class ClansUtility return Clans.getClan(clan); } + public ClanInfo getClanById(int id) + { + for (ClanInfo clan : Clans.getClanMap().values()) + { + if (clan.getId() == id) + { + return clan; + } + } + + return null; + } + public ClanInfo getClanByPlayer(Player player) { return getClanByUUID(player.getUniqueId()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 1e9621533..bd4b3a8e0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -4,8 +4,6 @@ import java.util.HashMap; import java.util.Map; import org.bukkit.Location; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -14,26 +12,24 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.plugin.java.JavaPlugin; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import mineplex.core.MiniPlugin; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; +import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; -import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.core.repository.ClanTerritory; -import mineplex.game.clans.spawn.Spawn; public class SiegeManager extends MiniPlugin { @@ -43,7 +39,7 @@ public class SiegeManager extends MiniPlugin public static SiegeManager Instance; - public Map LiveSiegeWeapons = new HashMap<>(); + public Map LiveSiegeWeapons = new HashMap<>(); private Gson _gson; @@ -57,98 +53,32 @@ public class SiegeManager extends MiniPlugin _outpostManager = new OutpostManager(clans, this); - _outpostManager.loadExistingOutposts(); - - loadExistingWeapons(); - addCommand(new CommandSiegeSupplies(_outpostManager)); Instance = this; + + _outpostManager.loadOutposts(); + loadSiegeWeapons(); } @EventHandler - public void onUpdate(UpdateEvent event) + public void save(UpdateEvent event) { if (event.getType() == UpdateType.SLOWER) { - _outpostManager.loadExistingOutposts(); - - loadExistingWeapons(); + _outpostManager.saveOutposts(); + saveSiegeWeapons(); } } - private void loadExistingWeapons() + private void loadSiegeWeapons() { - try - { - for (Entity entity : Spawn.getSpawnWorld().getEntities()) - { - if (!(entity instanceof ArmorStand)) - { - continue; - } - - if (!entity.hasMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$") ||!entity.hasMetadata("$TOKEN_INFO$")) - { - continue; - } - - String data = entity.getMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$").get(0).asString(); - - SiegeWeaponToken token = _gson.fromJson(data, SiegeWeaponToken.class); - - if (LiveSiegeWeapons.containsKey(token.Id)) - { - continue; - } - - if (_clans.getClan(token.OwnerClan) == null) - { - for (Entity other : Spawn.getSpawnWorld().getEntities()) - { - if (token.ComprisedOf.values().contains(other.getUniqueId())) - { - other.remove(); - } - else if (other.getUniqueId().equals(token.DataEntityUUID)) - { - other.remove(); - } - } - - continue; - } - - SiegeWeapon weapon = null; - - switch (token.WeaponType) - { - case 1: - { - weapon = new Catapult(this, token); - break; - } - - case 2: - { - weapon = new Cannon(this, token); - break; - } - } - - LiveSiegeWeapons.put(token.Id, weapon); - - if (_outpostManager.Get(token.OutpostId) != null) - { - _outpostManager.Get(token.OutpostId).addWeapon(weapon); - } - - } - } - catch (Exception e) - { - e.printStackTrace(); - } + + } + + private void saveSiegeWeapons() + { + } @EventHandler @@ -280,7 +210,7 @@ public class SiegeManager extends MiniPlugin outpost.addWeapon(cannon); } - LiveSiegeWeapons.put(cannon.getId(), cannon); + LiveSiegeWeapons.put(cannon.getUniqueId(), cannon); } public boolean trySpawnCatapult(Player player, Location location) @@ -343,12 +273,12 @@ public class SiegeManager extends MiniPlugin outpost.addWeapon(catapult); } - LiveSiegeWeapons.put(catapult.getId(), catapult); + LiveSiegeWeapons.put(catapult.getUniqueId(), catapult); } public void dead(SiegeWeapon weapon) { - LiveSiegeWeapons.remove(weapon.getId()); + LiveSiegeWeapons.remove(weapon.getUniqueId()); } public OutpostManager getOutpostManager() @@ -366,4 +296,9 @@ public class SiegeManager extends MiniPlugin return _clans; } + public int randomId() + { + return Math.abs(UtilMath.random.nextInt()); + } + } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java similarity index 86% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java index 4de674758..3e9f4cae1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/CommandSiegeSupplies.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.outpost; +package mineplex.game.clans.clans.siege.commands; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -7,6 +7,8 @@ import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.siege.outpost.Outpost; +import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 41269da61..fed50eb70 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -1,25 +1,17 @@ package mineplex.game.clans.clans.siege.outpost; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; -import java.util.Random; -import java.util.UUID; -import java.util.Map.Entry; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Chest; -import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Arrow; -import org.bukkit.entity.Entity; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -49,6 +41,7 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilColor; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; @@ -67,8 +60,9 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; +import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock; +import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; -import mineplex.game.clans.clans.siege.weapon.serialization.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; @@ -81,11 +75,11 @@ public class Outpost implements Listener public static final long PREP_TIME = 2 * 60 * 1000; - private OutpostManager _host; + private OutpostManager _outpostManager; - private final String _id; + private final int _uniqueId; - private ClanInfo _owner; + private ClanInfo _ownerClan; private Location _startCorner; private Location _origin; @@ -120,32 +114,32 @@ public class Outpost implements Listener UtilColor.rgb(147, 212, 17), UtilColor.rgb(150, 199, 51))); - private long _spawnTime; + private long _timeSpawned; - public double _maxHealth = 4500; - public double _health = _maxHealth; + public int _maxHealth = 4500; + public int _health = _maxHealth; - public ClanInfo _against; + public ClanInfo _againstClan; private long _siegeDeclaredTime = -1; private Arrow _declarationArrow; - private ArmorStand _dataEntity; - public Outpost(OutpostManager outpostManager, OutpostToken token) { - _host = outpostManager; + _outpostManager = outpostManager; - _health = token.Health; + System.out.println(token.OutpostState + ", " + token.Type); + + setHealth(token.Health); _siegeDeclaredTime = token.SiegeDeclaredTime; - _against = outpostManager.getClansManager().getClan(token.AgainstClan); + _againstClan = token.AgainstClan; - _id = token.Id; + _uniqueId = token.UniqueId; _siegeWeaponDistance = token.Type._size + 27.5; - _owner = outpostManager.getClansManager().getClan(token.OwnerClan); + _ownerClan = token.OwnerClan; _startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size); _endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9); @@ -155,42 +149,43 @@ public class Outpost implements Listener _forceFieldStart = _startCorner.clone().subtract(4, 0, 4); _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); - _origin = token.Origin; + _origin = token.Origin.clone(); _type = token.Type; - _spawnTime = token.TimeSpawned; + _timeSpawned = token.TimeSpawned; _core = _type.getCoreLocation(_origin); - _preHologram = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_owner.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); - _preHologram2 = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + _preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); + _preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); - _preHologram.start(); - _preHologram2.start(); + if (token.OutpostState == OutpostState.AWAITING) + { + _preHologram.start(); + _preHologram2.start(); + } + + _blocks = _type.createBuildQueue(_origin, _ownerClan.Clans); _state = token.OutpostState; - for (Entity entity : token.Origin.getWorld().getEntities()) - { - if (entity.getUniqueId().equals(token.DataEntityUUID)) - { - _dataEntity = (ArmorStand) entity; - } - } + _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); + + List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); + Collections.reverse(reverse); + _reverseCircleStages = new LoopIterator(reverse); } - public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) + public Outpost(OutpostManager outpostManager, ClanInfo clan, Location location, OutpostType type) { - _host = host; + _outpostManager = outpostManager; - location.add(.5, 0, .5); - - _id = Integer.toString(UtilMath.random.nextInt(13333337)); + _uniqueId = outpostManager.getSiegeManager().randomId(); _siegeWeaponDistance = type._size + 27.5; - _owner = clan; + _ownerClan = clan; _startCorner = location.clone().subtract(type._size, 1.1, type._size); _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); @@ -204,77 +199,29 @@ public class Outpost implements Listener _type = type; - _spawnTime = System.currentTimeMillis(); + _timeSpawned = System.currentTimeMillis(); _core = _type.getCoreLocation(_origin); - _preHologram = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_owner.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); - _preHologram2 = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + _preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); + _preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); _preHologram.start(); _preHologram2.start(); - _dataEntity = location.getWorld().spawn(location.subtract(0, 5, 0), ArmorStand.class); - _dataEntity.setVisible(false); - _dataEntity.setGravity(false); - _state = OutpostState.AWAITING; + + _outpostManager.getRepository().insertOutpost(toToken()); + + _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); + + List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); + Collections.reverse(reverse); + _reverseCircleStages = new LoopIterator(reverse); + + UtilServer.registerEvents(this); } - public OutpostToken tokenize() - { - OutpostToken token = new OutpostToken(); - - token.Id = _id; - - token.Origin = _origin; - - token.Type = _type; - - token.OwnerClan = _owner.getName(); - - token.Health = _health; - - token.TimeSpawned = _spawnTime; - - token.AgainstClan = _against != null ? _against.getName() : null; - - token.DataEntityUUID = _dataEntity.getUniqueId(); - - token.SiegeDeclaredTime = _siegeDeclaredTime; - - token.OutpostState = _state; - - return token; - } - - private void updateData() - { - try - { - String data = _host.getSiegeManager().getGson().toJson(tokenize()); - - PrintWriter writer = new PrintWriter(new FileWriter(new File("H:\\" + new Random().nextInt()))); - writer.print(data); - writer.close(); - - _dataEntity.setMetadata("$SERIALIZED_OUTPOST_DATA$", new FixedMetadataValue(_host.getPlugin(), data)); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @EventHandler - public void saveData(UpdateEvent event) - { - if (event.getType() == UpdateType.SEC_05) - { - updateData(); - } - } - private void cleanup() { _blocks = null; @@ -290,9 +237,7 @@ public class Outpost implements Listener _weapons.forEach(SiegeWeapon::kill); _weapons.clear(); - _dataEntity.remove(); - - _host.queueForRemoval(_owner.getName()); + _outpostManager.queueForRemoval(_ownerClan.getName()); } @EventHandler @@ -313,7 +258,7 @@ public class Outpost implements Listener return; } - if (!_owner.equals(_owner.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) + if (!_ownerClan.equals(_ownerClan.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!")); return; @@ -337,13 +282,12 @@ public class Outpost implements Listener return; } - event.setCancelled(true); Player player = (Player) event.getEntity(); Arrow arrow = player.shootArrow(); - if (_owner.isMember(player)) + if (_ownerClan.isMember(player)) { for (int slot = 0; slot < player.getInventory().getSize(); slot++) { @@ -356,13 +300,13 @@ public class Outpost implements Listener if (item.isSimilar(SIEGE_DECLARATION_ARROW)) { - if (_against == null && !arrow.hasMetadata("OutpostData")) + if (_againstClan == null && !arrow.hasMetadata("OutpostData")) { - arrow.setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); + arrow.setMetadata("OutpostData", new FixedMetadataValue(_outpostManager.getPlugin(), _ownerClan.getName() + ";" + player.getName())); _declarationArrow = (Arrow) arrow; + player.getInventory().setItem(slot, UtilInv.decrement(item)); + break; } - - player.getInventory().setItem(slot, null); } } } @@ -373,12 +317,12 @@ public class Outpost implements Listener { if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_owner.getName()) + "'s Outpost!")); + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); _core.getBlock().setType(Material.AIR); - _owner.inform("Your Outpost has been destroyed!", null); - UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _owner.getOnlinePlayersArray()); + _ownerClan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); if (getState() == OutpostState.AWAITING) { @@ -400,7 +344,7 @@ public class Outpost implements Listener { _origin.getBlock().setType(Material.AIR); _origin.getWorld().dropItem(_origin, OUTPOST_ITEM); - _owner.inform("Your Outpost block has been destroyed.", null); + _ownerClan.inform("Your Outpost block has been destroyed.", null); cleanup(); event.setCancelled(true); return; @@ -436,14 +380,14 @@ public class Outpost implements Listener UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX); } - if (_against != null && getTimeToSiege() > 0) + if (_againstClan != null && getTimeToSiege() > 150) { - _against.getOnlinePlayers().forEach(this::informTimeToSiege); - _owner.getOnlinePlayers().forEach(this::informTimeToSiege); + _againstClan.getOnlinePlayers().forEach(this::informTimeToSiege); + _ownerClan.getOnlinePlayers().forEach(this::informTimeToSiege); } - else if (_against != null) + else if (_againstClan != null) { - UtilTextBottom.display("Enemy Outpost Health: " + UtilText.colorPercentage(getHealthPercentage()) + "%", _against.getOnlinePlayersArray()); + UtilTextBottom.display("Enemy Outpost Health: " + UtilText.colorPercentage(getHealthPercentage()) + "%", _againstClan.getOnlinePlayersArray()); } if (_state == OutpostState.AWAITING) @@ -451,7 +395,7 @@ public class Outpost implements Listener if (getLifetime() > 60000) { _origin.getBlock().setType(Material.AIR); - _owner.inform("You have lost your Outpost block, as no one activated it fast enough!", null); + _ownerClan.inform("You have lost your Outpost block, as no one activated it fast enough!", null); cleanup(); return; } @@ -482,11 +426,11 @@ public class Outpost implements Listener for (OutpostBlock block : _blocks.values()) { - if (block._id == Material.CHEST.getId()) + if (block.getId() == Material.CHEST.getId()) { for (int slot = 0; slot < 8; slot++) { - ((Chest) block._loc.getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW); + ((Chest) block.getLocation().getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW); } break; @@ -554,7 +498,7 @@ public class Outpost implements Listener } UtilServer.getPlayersCollection().stream() - .filter(player -> !_owner.isMember(player)) + .filter(player -> !_ownerClan.isMember(player)) .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) .forEach(player -> { UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .4, true, 0.8, 0, 1.1, true); @@ -573,26 +517,20 @@ public class Outpost implements Listener _preHologram = null; _state = OutpostState.CONSTRUCTING; - _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _owner.Clans)); + _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _ownerClan.Clans)); - _owner.inform("Siege", "Your Outpost is now being constructed.", null); - - _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); - - List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); - Collections.reverse(reverse); - _reverseCircleStages = new LoopIterator(reverse); + _ownerClan.inform("Siege", "Your Outpost is now being constructed.", null); //Inform nearby Clans for (int chunkX = -3; chunkX < 3; chunkX++) { for (int chunkZ = -3; chunkZ < 3; chunkZ++) { - ClanTerritory territory = _owner.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); + ClanTerritory territory = _ownerClan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); if (territory != null && ClansBlacklist.isValidClanName(territory.Owner)) { - ClanInfo clan = _owner.Clans.getClanUtility().getClanByClanName(territory.Owner); + ClanInfo clan = _ownerClan.Clans.getClanUtility().getClanByClanName(territory.Owner); clan.inform("A siege has begun near your territory!", null); UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray()); @@ -623,15 +561,15 @@ public class Outpost implements Listener NonFinalInteger wait = new NonFinalInteger(0); _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block -> - _host.runSyncLater(() -> { - UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block._loc, new Vector(0,0,0), 1f, 1, ViewDist.MAX); - _origin.getWorld().playSound(block._loc, Sound.EXPLODE, 1.0f, 1.0f); + _outpostManager.runSyncLater(() -> { + UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX); + _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); }, wait.add(4 + UtilMath.random.nextInt(4)).get()) ); - _host.runSyncLater(() -> { + _outpostManager.runSyncLater(() -> { _blocks.values().forEach(block -> { - Material mat = Material.getMaterial(block._id); + Material mat = Material.getMaterial(block.getId()); if (UtilItem.isTranslucent(mat)) { @@ -639,13 +577,13 @@ public class Outpost implements Listener return; } - FallingBlock fall = block._loc.getWorld().spawnFallingBlock(block._loc, block._id, block._data); + FallingBlock fall = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), block.getId(), block.getData()); fall.setDropItem(false); Vector vec = UtilAlg.getTrajectory(fall.getLocation(), getExactMiddle()); UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false); - fall.setMetadata("ClansOutpost", new FixedMetadataValue(_owner.Clans.getPlugin(), _owner.getName())); + fall.setMetadata("ClansOutpost", new FixedMetadataValue(_ownerClan.Clans.getPlugin(), _ownerClan.getName())); block.restore(); }); @@ -653,7 +591,7 @@ public class Outpost implements Listener cleanup(); }, wait.get() + 5L); - _owner.inform("Your Clan's Outpost has been destroyed.", null); + _ownerClan.inform("Your Clan's Outpost has been destroyed.", null); } @EventHandler @@ -672,12 +610,12 @@ public class Outpost implements Listener public ClanInfo getOwner() { - return _owner; + return _ownerClan; } public long getLifetime() { - return System.currentTimeMillis() - _spawnTime; + return System.currentTimeMillis() - _timeSpawned; } public AxisAlignedBB getBounds() @@ -705,20 +643,20 @@ public class Outpost implements Listener public final int getHealthPercentage() { - return ((int) ((_health / _maxHealth) * 100.d)); + return ((int) ((((double) _health) / ((double) _maxHealth)) * 100.d)); } - public final double getHealth() + public final int getHealth() { return _health; } public final String getDisplayHealth() { - return UtilText.getProgress(null, _health / _maxHealth, null, false, 12); + return UtilText.getProgress(null, ((double) _health) / ((double) _maxHealth), null, false, 12); } - public final void setHealth(double health) + public final void setHealth(int health) { _health = UtilMath.clamp(health, 0, _maxHealth); @@ -728,51 +666,51 @@ public class Outpost implements Listener } } - public final void removeHealth(double health) + public final void removeHealth(int health) { setHealth(_health - health); } - public final void addHealth(double health) + public final void addHealth(int health) { setHealth(_health + health); } public ClanInfo getAgainst() { - return _against; + return _againstClan; } public void declareOn(Player declarer, ClanInfo against) { - if (_against != null) + if (_againstClan != null) { - UtilPlayer.message(declarer, F.main("Clans", "Your Clan has already declared Siege against " + F.elem(_against.getName()) + ".")); + UtilPlayer.message(declarer, F.main("Clans", "Your Clan has already declared Siege against " + F.elem(_againstClan.getName()) + ".")); } else { - if (_host.isInSiege(against)) + if (_outpostManager.isInSiege(against)) { UtilPlayer.message(declarer, F.main("Clans", F.elem(against.getName()) + " is already in a Siege.")); return; } - _against = against; + _againstClan = against; _siegeDeclaredTime = System.currentTimeMillis(); - _owner.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_against.getName()) + "."), null); - _owner.inform("Siege", "Your Clan has declared a Siege", null); - _owner.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); + _ownerClan.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_againstClan.getName()) + "."), null); + _ownerClan.inform("Siege", "Your Clan has declared a Siege", null); + _ownerClan.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); - _against.inform(F.main("Clans", F.elem(_owner.getName()) + " has declared a Siege against your Clan."), null); - _against.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); - _against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege", null); + _againstClan.inform(F.main("Clans", F.elem(_ownerClan.getName()) + " has declared a Siege against your Clan."), null); + _againstClan.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); + _againstClan.inform("Siege", F.elem(_ownerClan.getName()) + " has declared a Siege", null); } } public void informTimeToSiege(Player player) { - UtilTextBottom.display("Time to Siege: " + F.time(UtilTime.MakeStr(getTimeToSiege())), player); + UtilTextBottom.display(C.Bold + "Time to Siege: " + F.time(UtilTime.MakeStr(getTimeToSiege())), player); } public long getTimeSiegeDeclared() @@ -800,8 +738,25 @@ public class Outpost implements Listener _weapons.add(weapon); } - public String getId() + public int getUniqueId() { - return _id; + return _uniqueId; + } + + public OutpostToken toToken() + { + OutpostToken token = new OutpostToken(); + + token.UniqueId = _uniqueId; + token.Origin = _origin; + token.Type = _type; + token.OwnerClan = _ownerClan; + token.Health = _health; + token.TimeSpawned = _timeSpawned; + token.AgainstClan = _againstClan; + token.SiegeDeclaredTime = _siegeDeclaredTime; + token.OutpostState = _state; + + return token; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java deleted file mode 100644 index f9dde3d53..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlock.java +++ /dev/null @@ -1,57 +0,0 @@ -package mineplex.game.clans.clans.siege.outpost; - -import java.util.Map; - -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.BlockState; - -import mineplex.core.common.util.UtilWorld; - -public class OutpostBlock -{ - protected Location _loc; - protected int _id; - protected byte _data; - - protected int _originalId; - protected byte _originalData; - - public OutpostBlock(Map blocks, Location loc, int id, byte data) - { - _loc = loc; - _id = id; - _data = data; - - String locStr = UtilWorld.locToStr(loc); - - if (blocks.containsKey(locStr)) - { - _originalId = blocks.get(locStr)._originalId; - _originalData = blocks.get(locStr)._originalData; - } - else - { - _originalId = _loc.getBlock().getTypeId(); - _originalData = _loc.getBlock().getData(); - } - } - - public void set() - { - _loc.getBlock().setTypeIdAndData(_id, _data, false); - if (_id != 0) - { - _loc.getWorld().playEffect(_loc, Effect.STEP_SOUND, Material.getMaterial(_id), 10); - } - } - - public void restore() - { - BlockState state = _loc.getBlock().getState(); - state.setTypeId(_originalId); - state.setRawData(_originalData); - state.update(true, false); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java deleted file mode 100644 index 89ac4d68e..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBuilder.java +++ /dev/null @@ -1,18 +0,0 @@ -package mineplex.game.clans.clans.siege.outpost; - -import java.util.List; - -import org.bukkit.Location; - -public class OutpostBuilder -{ - public OutpostBuilder(Location pos, String string, List wallLocations, Outpost outpost) - { - } - - public void tick() - { - - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index d032a9b6b..e365b380d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -1,26 +1,26 @@ package mineplex.game.clans.clans.siege.outpost; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import java.util.Stack; import org.bukkit.Chunk; import org.bukkit.Location; -import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; @@ -35,21 +35,25 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; -import mineplex.game.clans.clans.siege.weapon.serialization.OutpostToken; +import mineplex.game.clans.clans.siege.repository.OutpostRepository; +import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; -import mineplex.game.clans.spawn.Spawn; public class OutpostManager extends MiniPlugin { private ClansManager _clansManager; - private Map _outposts = new HashMap<>(); - private Map _idToOutpost = new HashMap<>(); + private NautHashMap _outposts = new NautHashMap<>(); + private NautHashMap _idToOutpost = new NautHashMap<>(); private List _removalQueue; private SiegeManager _siegeManager; + private OutpostRepository _repository; + + private Stack _addQueue = new Stack<>(); + public OutpostManager(ClansManager clansManager, SiegeManager siegeManager) { super("Outpost Manager", clansManager.getPlugin()); @@ -58,45 +62,17 @@ public class OutpostManager extends MiniPlugin _clansManager = clansManager; + _repository= new OutpostRepository(clansManager.getPlugin(), this); + _removalQueue = new ArrayList<>(); } - public void loadExistingOutposts() - { - try - { - for (Entity entity : Spawn.getSpawnWorld().getEntities()) - { - if (!(entity instanceof ArmorStand)) - { - continue; - } - - if (!entity.hasMetadata("$SERIALIZED_OUTPOST_DATA$")) - { - continue; - } - - String data = entity.getMetadata("$SERIALIZED_OUTPOST_DATA$").get(0).asString(); - - Outpost outpost = new Outpost(this, _siegeManager.getGson().fromJson(data, OutpostToken.class)); - - _outposts.put(outpost.getOwner().getName(), outpost); - _idToOutpost.put(outpost.getId(), outpost); - } - } - catch (Exception e) - { - e.printStackTrace(); - } - } - @EventHandler(priority = EventPriority.LOWEST) public void onPlaceBlock(BlockPlaceEvent event) { if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) { - if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3)) + if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_III)) { event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); } @@ -217,9 +193,7 @@ public class OutpostManager extends MiniPlugin } _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); - _idToOutpost.put(_outposts.get(clan.getName()).getId(), _outposts.get(clan.getName())); - - _plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin); + _idToOutpost.put(_outposts.get(clan.getName()).getUniqueId(), _outposts.get(clan.getName())); return true; } @@ -250,6 +224,13 @@ public class OutpostManager extends MiniPlugin @EventHandler public void update(UpdateEvent event) { + if (!_addQueue.isEmpty()) + { + Outpost outpost = _addQueue.pop(); + + _outposts.put(outpost.getOwner().getName(), outpost); + } + for (Outpost outpost : _outposts.values()) { if (outpost.getState() != OutpostState.DEAD) @@ -265,7 +246,7 @@ public class OutpostManager extends MiniPlugin { if (!_removalQueue.isEmpty()) { - HandlerList.unregisterAll(_outposts.remove(_removalQueue.remove(0))); + HandlerList.unregisterAll(_idToOutpost.remove(Integer.valueOf(_outposts.remove(_removalQueue.remove(0)).getUniqueId()))); } } @@ -283,6 +264,11 @@ public class OutpostManager extends MiniPlugin public Outpost Get(ClanInfo clan) { + if (clan == null) + { + return null; + } + return _outposts.get(clan.getName().toLowerCase()); } @@ -301,6 +287,34 @@ public class OutpostManager extends MiniPlugin return Lists.newArrayList(_outposts.values()); } + @EventHandler + public void onQuit(PlayerQuitEvent event) + { + Player player = (Player) event.getPlayer(); + ClanInfo clan = _clansManager.getClan(player); + + if (Get(clan) != null) + { + return; + } + + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + ItemStack item = player.getInventory().getItem(slot); + + if (item == null) + { + continue; + } + + if (item.isSimilar(Outpost.SIEGE_DECLARATION_ARROW)) + { + player.getInventory().setItem(slot, null); + break; + } + } + } + @EventHandler public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) { @@ -366,13 +380,75 @@ public class OutpostManager extends MiniPlugin return false; } - public Outpost Get(String outpostId) + public Outpost Get(int outpostId) { - return _idToOutpost.get(outpostId); + return _idToOutpost.get(Integer.valueOf(outpostId)); } public ClansManager getClansManager() { return _clansManager; } + + public void loadOutposts() + { + System.out.println("[OUTPOSTS] LOADING OUTPOSTS FROM DATABASE"); + + _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> { + for (OutpostToken token : tokens) + { + if ((System.currentTimeMillis() - token.TimeSpawned) > Outpost.MAX_LIFETIME) + { + System.out.println("[OUTPOSTS] SKIPPING & REMOVING OUTPOST [" + token.UniqueId + "] BECAUSE OF OLD AGE"); + + _repository.deleteOutpost(token.UniqueId); + + continue; + } + + Outpost outpost = new Outpost(this, token); + + System.out.println("[OUTPOSTS] INITIALIZED OUTPOST FROM DATABASE SAVE"); + + _addQueue.push(outpost); + } + }); + } + + public void saveOutposts() + { + final Stack queue = new Stack<>(); + + for (final Outpost outpost : _outposts.values()) + { + final OutpostToken token = outpost.toToken(); + + queue.push(() -> { + _repository.updateOutpost(token); + }); + } + + runAsync(() -> { + while (!queue.isEmpty()) + { + queue.pop().run(); + } + }); + + runAsync(() -> + _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> + tokens.forEach(token -> { + if (!_idToOutpost.containsKey(Integer.valueOf(token.UniqueId))) + { + _repository.deleteOutpost(token.UniqueId); + } + }) + ) + ); + } + + public OutpostRepository getRepository() + { + return _repository; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java index ffa3162ec..8d37671fa 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostState.java @@ -2,9 +2,37 @@ package mineplex.game.clans.clans.siege.outpost; public enum OutpostState { - AWAITING, - CONSTRUCTING, - LIVE, - DESTRUCTING, - DEAD; + /** + * this much space between them so that there is some room for any potential new states. + */ + AWAITING(10), + CONSTRUCTING(20), + LIVE(30), + DESTRUCTING(40), + DEAD(50); + + private byte _id; + + OutpostState(int id) + { + _id = (byte) id; + } + + public static OutpostState ById(byte id) + { + for (OutpostState state : values()) + { + if (state._id == id) + { + return state; + } + } + + return null; + } + + public byte getId() + { + return _id; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java index 73d9c63a5..134e6b000 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostType.java @@ -14,11 +14,13 @@ import mineplex.core.common.block.schematic.Schematic; import mineplex.core.common.block.schematic.UtilSchematic; import mineplex.core.common.util.UtilWorld; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock; +import mineplex.game.clans.clans.siege.outpost.build.OutpostBlockBanner; import net.minecraft.server.v1_8_R3.NBTTagCompound; public enum OutpostType { - ORIGINAL_CLANS(3, 6) { + MK_I(1, 3, 6) { public LinkedHashMap createBuildQueue(Location location, ClansManager clans) { LinkedHashMap build = new LinkedHashMap<>(); @@ -229,7 +231,7 @@ public enum OutpostType return location.clone().subtract(0, 1, 0); } }, - MK2(5, 25) { + MK_II(2, 5, 25) { public LinkedHashMap createBuildQueue(Location location, ClansManager clans) { try @@ -289,7 +291,7 @@ public enum OutpostType return location.clone().subtract(0, 1, 0); } }, - MK3(5, 25) { + MK_III(3, 5, 25) { public LinkedHashMap createBuildQueue(Location location, ClansManager clans) { try @@ -358,10 +360,18 @@ public enum OutpostType protected int _size; protected int _ySize; - OutpostType(int size, int ySize) + private int _id; + + OutpostType(int id, int size, int ySize) { _size = size; _ySize = ySize; + _id = id; + } + + public int getId() + { + return _id; } public abstract LinkedHashMap createBuildQueue(Location location, ClansManager clans); @@ -369,4 +379,17 @@ public enum OutpostType public abstract Location getCoreLocation(Location location); public abstract List getWallLocations(Location location); + + public static OutpostType ById(byte id) + { + for (OutpostType type : values()) + { + if (type._id == id) + { + return type; + } + } + + return null; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlock.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlock.java new file mode 100644 index 000000000..c0f2f490e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlock.java @@ -0,0 +1,82 @@ +package mineplex.game.clans.clans.siege.outpost.build; + +import java.util.Map; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.BlockState; + +import mineplex.core.common.util.UtilWorld; + +public class OutpostBlock +{ + private Location _location; + private int _id; + private byte _data; + + private int _originalId; + private byte _originalData; + + public OutpostBlock(Map blocks, Location loc, int id, byte data) + { + _location = loc; + _id = id; + _data = data; + + String locStr = UtilWorld.locToStr(loc); + + if (blocks.containsKey(locStr)) + { + _originalId = blocks.get(locStr)._originalId; + _originalData = blocks.get(locStr)._originalData; + } + else + { + _originalId = _location.getBlock().getTypeId(); + _originalData = _location.getBlock().getData(); + } + } + + public void set() + { + _location.getBlock().setTypeIdAndData(_id, _data, false); + if (_id != 0) + { + _location.getWorld().playEffect(_location, Effect.STEP_SOUND, Material.getMaterial(_id), 10); + } + } + + public void restore() + { + BlockState state = _location.getBlock().getState(); + state.setTypeId(_originalId); + state.setRawData(_originalData); + state.update(true, false); + } + + public int getId() + { + return _id; + } + + public byte getData() + { + return _data; + } + + public int getOriginalId() + { + return _originalId; + } + + public int getOriginalData() + { + return _originalData; + } + + public Location getLocation() + { + return _location; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlockBanner.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlockBanner.java similarity index 82% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlockBanner.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlockBanner.java index fe537ed63..02ec95e86 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostBlockBanner.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/build/OutpostBlockBanner.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.siege.outpost; +package mineplex.game.clans.clans.siege.outpost.build; import java.util.ArrayList; import java.util.Arrays; @@ -10,6 +10,10 @@ import org.bukkit.Location; import org.bukkit.block.Banner; import org.bukkit.block.banner.Pattern; +/** + * Special block for Mk III Outpost + * + */ public class OutpostBlockBanner extends OutpostBlock { private DyeColor _baseColor; @@ -27,7 +31,7 @@ public class OutpostBlockBanner extends OutpostBlock { super.set(); - Banner banner = (Banner) _loc.getBlock().getState(); + Banner banner = (Banner) getLocation().getBlock().getState(); banner.setBaseColor(_baseColor); banner.setPatterns(_patterns); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java new file mode 100644 index 000000000..d6bcb600a --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java @@ -0,0 +1,152 @@ +package mineplex.game.clans.clans.siege.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.List; + +import org.bukkit.plugin.java.JavaPlugin; + +import com.google.common.collect.Lists; + +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UtilWorld; +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.column.ColumnByte; +import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.column.ColumnTimestamp; +import mineplex.core.database.column.ColumnVarChar; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.siege.outpost.OutpostManager; +import mineplex.game.clans.clans.siege.outpost.OutpostState; +import mineplex.game.clans.clans.siege.outpost.OutpostType; +import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; + +public class OutpostRepository extends RepositoryBase +{ + private OutpostManager _manager; + + private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansOutposts (uniqueId INT NOT NULL," + + "serverId INT NOT NULL," + + "origin VARCHAR(30)," + + "outpostType TINYINT NOT NULL," + + "ownerClan INT NOT NULL," + + "health INT NOT NULL," + + "timeSpawned LONG," + + "againstClan INT," + + "siegeDeclaredTime LONG," + + "outpostState TINYINT NOT NULL);"; + + private static final String GET_OUTPOST_BY_ID = "SELECT * FROM clansOutposts WHERE uniqueId=?;"; + private static final String GET_OUTPOST_BY_CLAN = "SELECT * FROM clansOutposts WHERE ownerClan=?;"; + private static final String GET_OUTPOSTS_BY_SERVER = "SELECT * FROM clansOutposts WHERE serverId=?;"; + + private static final String UPDATE_OUTPOST = "UPDATE clansOutposts SET health=?,againstClan=?,siegeDeclaredTime=?,outpostState=? WHERE uniqueId=?;"; + private static final String INSERT_OUTPOST = "INSERT INTO clansOutposts VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; + + private static final String DELETE_OUTPOST = "DELETE FROM clansOutposts WHERE uniqueId=?;"; + + public OutpostRepository(JavaPlugin plugin, OutpostManager manager) + { + super(plugin, DBPool.getAccount()); + + _manager = manager; + } + + public void deleteOutpost(final int uniqueId) + { + executeUpdate(DELETE_OUTPOST, new ColumnInt("uniqueId", uniqueId)); + } + + public void getOutpostById(final int uniqueId, final Callback callback) + { + executeQuery(GET_OUTPOST_BY_ID, resultSet -> { + OutpostToken token = new OutpostToken(); + + resultSet.next(); + + load(token, resultSet); + + callback.run(token); + }, new ColumnInt("uniqueId", uniqueId)); + } + + public void getOutpostByClan(final ClanInfo clan, final Callback callback) + { + executeQuery(GET_OUTPOST_BY_CLAN, resultSet -> { + resultSet.next(); + + OutpostToken token = new OutpostToken(); + + load(token, resultSet); + + callback.run(token); + }, new ColumnInt("ownerClan", clan.getId())); + } + + public void getOutpostsByServer(final int serverId, final Callback> callback) + { + executeQuery(GET_OUTPOSTS_BY_SERVER, resultSet -> { + List tokens = Lists.newArrayList(); + + while (resultSet.next()) + { + OutpostToken token = new OutpostToken(); + load(token, resultSet); + tokens.add(token); + } + + callback.run(tokens); + }, new ColumnInt("serverId", serverId)); + } + + private void load(OutpostToken token, ResultSet columns) throws SQLException + { + token.UniqueId = columns.getInt("uniqueId"); + token.Origin = UtilWorld.strToLoc(columns.getString("origin")); + token.Type = OutpostType.ById(columns.getByte("outpostType")); + token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan")); + token.Health = columns.getShort("health"); + token.TimeSpawned = columns.getTimestamp("timeSpawned").getTime(); + token.AgainstClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("againstClan")); + token.SiegeDeclaredTime = columns.getTimestamp("siegeDeclaredTime").getTime(); + token.OutpostState = OutpostState.ById(columns.getByte("outpostState")); + } + + @Override + protected void initialize() + { + executeUpdate(CREATE); + } + + @Override + protected void update() + { + } + + public void updateOutpost(OutpostToken token) + { + executeUpdate(UPDATE_OUTPOST, + new ColumnInt("health", token.Health), + new ColumnInt("againstClan", token.AgainstClan == null ? 0 : token.AgainstClan.getId()), + new ColumnTimestamp("siegeDeclaredTime", new Timestamp(token.SiegeDeclaredTime)), + new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId())), + new ColumnInt("uniqueId", token.UniqueId)); + } + + public void insertOutpost(OutpostToken token) + { + executeUpdate(INSERT_OUTPOST, + new ColumnInt("uniqueId", token.UniqueId), + new ColumnInt("serverId", _manager.getClansManager().getServerId()), + new ColumnVarChar("origin", 30, UtilWorld.locToStr(token.Origin)), + new ColumnInt("outpostType", token.Type.getId()), + new ColumnInt("ownerClan", token.OwnerClan.getId()), + new ColumnInt("health", token.Health), + new ColumnTimestamp("timeSpawned", new Timestamp(token.TimeSpawned)), + new ColumnInt("againstClan", token.AgainstClan == null ? 0 : token.AgainstClan.getId()), + new ColumnTimestamp("siegeDeclaredTime", new Timestamp(token.SiegeDeclaredTime)), + new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId()))); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java new file mode 100644 index 000000000..4a325efac --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -0,0 +1,124 @@ +package mineplex.game.clans.clans.siege.repository; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +import org.bukkit.plugin.java.JavaPlugin; + +import com.google.common.collect.Lists; + +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UtilWorld; +import mineplex.core.database.DBPool; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.column.ColumnInt; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.siege.SiegeManager; +import mineplex.game.clans.clans.siege.outpost.Outpost; +import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; + +public class SiegeWeaponRepository extends RepositoryBase +{ + private SiegeManager _manager; + + private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansSiegeWeapons (uniqueId INT NOT NULL," + + "serverId INT NOT NULL," + + "location VARCHAR(30)," + + "ownerClan INT NOT NULL," + + "outpostId INT," + + "weaponType TINYINT NOT NULL," + + "health int NOT NULL," + + "yaw int NOT NULL," + + "lastFired LONG);"; + + private static final String GET_WEAPON_BY_ID = "SELECT * FROM clansSiegeWeapons WHERE uniqueId=?;"; + private static final String GET_WEAPONS_BY_CLAN = "SELECT * FROM clansSiegeWeapons WHERE ownerClan=?;"; + private static final String GET_WEAPONS_BY_OUTPOST = "SELECT * FROM clansSiegeWeapons WHERE outpostId=?;"; + + private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;"; + + public SiegeWeaponRepository(JavaPlugin plugin, SiegeManager manager) + { + super(plugin, DBPool.getAccount()); + + _manager = manager; + } + + public void deleteWeapon(final int uniqueId) + { + executeUpdate(DELETE_WEAPON, new ColumnInt("uniqueId", uniqueId)); + } + + public void getWeaponById(final int uniqueId, final Callback callback) + { + executeQuery(GET_WEAPON_BY_ID, resultSet -> { + SiegeWeaponToken token = new SiegeWeaponToken(); + + resultSet.next(); + + load(token, resultSet); + + callback.run(token); + }, new ColumnInt("uniqueId", uniqueId)); + } + + public void getWeaponsByClan(final ClanInfo clan, final Callback> callback) + { + executeQuery(GET_WEAPONS_BY_CLAN, resultSet -> { + List tokens = Lists.newArrayList(); + + while (resultSet.next()) + { + SiegeWeaponToken token = new SiegeWeaponToken(); + + load(token, resultSet); + + tokens.add(token); + } + + callback.run(tokens); + }, new ColumnInt("ownerClan", clan.getId())); + } + + public void getWeaponsByOutpost(final Outpost outpost, final Callback> callback) + { + executeQuery(GET_WEAPONS_BY_OUTPOST, resultSet -> { + List tokens = Lists.newArrayList(); + + while (resultSet.next()) + { + SiegeWeaponToken token = new SiegeWeaponToken(); + + load(token, resultSet); + + tokens.add(token); + } + + callback.run(tokens); + }, new ColumnInt("outpostId", outpost.getUniqueId())); + } + + private void load(SiegeWeaponToken token, ResultSet columns) throws SQLException + { + token.Id = columns.getInt("uniqueId"); + token.Location = UtilWorld.strToLoc(columns.getString("location")); + token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan")); + token.OutpostId = columns.getInt("outpostId"); + token.WeaponType = columns.getByte("weaponType"); + token.Health = columns.getShort("health"); + token.Yaw = columns.getShort("yaw"); + token.LastFired = columns.getTimestamp("lastFired").getTime(); + } + + @Override + protected void initialize() + { + executeUpdate(CREATE); + } + + @Override + protected void update() + { + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java similarity index 54% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java index 2810ad924..1bd6c1912 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/OutpostToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java @@ -1,24 +1,20 @@ -package mineplex.game.clans.clans.siege.weapon.serialization; - -import java.util.UUID; +package mineplex.game.clans.clans.siege.repository.tokens; import org.bukkit.Location; -import mineplex.core.common.GsonLocation; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.outpost.OutpostState; import mineplex.game.clans.clans.siege.outpost.OutpostType; public class OutpostToken { - public String Id; - public GsonLocation Origin; + public int UniqueId; + public Location Origin; public OutpostType Type; - public String OwnerClan; - public double Health; + public ClanInfo OwnerClan; + public int Health; public long TimeSpawned; - public String AgainstClan; + public ClanInfo AgainstClan; public long SiegeDeclaredTime; public OutpostState OutpostState; - public UUID DataEntityUUID; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java new file mode 100644 index 000000000..b07edf267 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java @@ -0,0 +1,22 @@ +package mineplex.game.clans.clans.siege.repository.tokens; + +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Location; + +import mineplex.game.clans.clans.ClanInfo; + +public class SiegeWeaponToken +{ + public int Id; + public ClanInfo OwnerClan; + public byte WeaponType; + public int OutpostId; + public Location Location; + public Map ComprisedOf; + public int Health; + public int Yaw; + public UUID Rider; + public long LastFired; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 15557fc9e..e760c2d2a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -28,9 +28,9 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.outpost.Outpost; +import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; -import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; @@ -41,7 +41,7 @@ public class Cannon extends SiegeWeapon public Cannon(SiegeManager siegeManager, SiegeWeaponToken token) { - super(1400.d, "Cannon", token, siegeManager.getClansManager(), siegeManager); + super(1400, "Cannon", token, siegeManager.getClansManager(), siegeManager); setBoundingBox(1); @@ -67,7 +67,7 @@ public class Cannon extends SiegeWeapon return false; } - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); return false; @@ -91,7 +91,7 @@ public class Cannon extends SiegeWeapon enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); return false; @@ -109,7 +109,7 @@ public class Cannon extends SiegeWeapon public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) { - super(2, location, 1400.d, "Cannon", clan, clan.Clans, siegeManager, outpost); + super(2, location, 1400, "Cannon", clan, clan.Clans, siegeManager, outpost); setBoundingBox(1); @@ -137,7 +137,7 @@ public class Cannon extends SiegeWeapon return false; } - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); return false; @@ -161,7 +161,7 @@ public class Cannon extends SiegeWeapon enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); return false; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index fdbbba338..d4e70a40e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -24,9 +24,9 @@ import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.outpost.Outpost; +import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; -import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; @@ -37,7 +37,7 @@ public class Catapult extends SiegeWeapon public Catapult(SiegeManager siegeManager, SiegeWeaponToken token) { - super(1400.d, "Catapult", token, siegeManager.getClansManager(), siegeManager); + super(1400, "Catapult", token, siegeManager.getClansManager(), siegeManager); setBoundingBox(3, 0); @@ -66,7 +66,7 @@ public class Catapult extends SiegeWeapon return false; } - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); return false; @@ -90,7 +90,7 @@ public class Catapult extends SiegeWeapon enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); return false; @@ -108,7 +108,7 @@ public class Catapult extends SiegeWeapon public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) { - super(1, location, 2500.d, "Catapult", clan, clan.Clans, siegeManager, outpost); + super(1, location, 2500, "Catapult", clan, clan.Clans, siegeManager, outpost); setBoundingBox(3, 0); @@ -139,7 +139,7 @@ public class Catapult extends SiegeWeapon return false; } - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); return false; @@ -163,7 +163,7 @@ public class Catapult extends SiegeWeapon enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); return false; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index e7ca2fd56..5955b5287 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -1,6 +1,5 @@ package mineplex.game.clans.clans.siege.weapon; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -28,7 +27,6 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.EulerAngle; import org.spigotmc.event.entity.EntityDismountEvent; @@ -52,10 +50,9 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.Outpost; -import mineplex.game.clans.clans.siege.outpost.OutpostManager; +import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; -import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox; @@ -66,17 +63,17 @@ public abstract class SiegeWeapon implements Listener protected ClansManager _clans; protected SiegeManager _siegeManager; - protected String _id; + protected int _uniqueId; /** * THIS MAY BE NULL IF NOT PLACED IN OUTPOST */ protected Outpost _outpost; - protected ClanInfo _owner; + protected ClanInfo _ownerClan; protected final String _name; - protected final double _maxHealth; - protected double _health; + protected final int _maxHealth; + protected int _health; protected Inventory _inventory; protected AccessRule _inventoryAccess; @@ -134,20 +131,18 @@ public abstract class SiegeWeapon implements Listener protected final int _weaponTypeIdentifier; - private ArmorStand _dataEntity; - - public SiegeWeapon(double maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager) + public SiegeWeapon(int maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager) { _weaponTypeIdentifier = token.WeaponType; - _id = token.Id; + _uniqueId = token.Id; _outpost = siegeManager.getOutpostManager().Get(token.OutpostId); _siegeManager = siegeManager; _location = token.Location; _name = name; _health = _maxHealth = maxHealth; - _owner = clansManager.getClan(token.OwnerClan); + _ownerClan = token.OwnerClan; _comprisedOf = Lists.newArrayList(); _registeredStates = Maps.newHashMap(); @@ -156,7 +151,7 @@ public abstract class SiegeWeapon implements Listener _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); _infoHologram.start(); - UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); + UtilServer.registerEvents(this); _clans = clansManager; @@ -170,14 +165,8 @@ public abstract class SiegeWeapon implements Listener _entityMapping.put(entry.getKey(), entity); } } - - if (entity.getUniqueId().equals(token.DataEntityUUID)) - { - _dataEntity = (ArmorStand) entity; - } } - _yaw = token.Yaw; _rider = Bukkit.getPlayer(token.Rider); _lastFired = token.LastFired; @@ -185,9 +174,9 @@ public abstract class SiegeWeapon implements Listener _health = token.Health; } - public SiegeWeapon(int typeId, Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) + public SiegeWeapon(int typeId, Location location, int maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) { - _id = Integer.toString(UtilMath.random.nextInt(13333337)); + _uniqueId = siegeManager.randomId(); _weaponTypeIdentifier = typeId; _outpost = outpost; @@ -195,7 +184,7 @@ public abstract class SiegeWeapon implements Listener _location = location; _name = name; _health = _maxHealth = maxHealth; - _owner = owner; + _ownerClan = owner; _comprisedOf = Lists.newArrayList(); _registeredStates = Maps.newHashMap(); @@ -207,70 +196,6 @@ public abstract class SiegeWeapon implements Listener UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); _clans = clansManager; - - _dataEntity = location.getWorld().spawn(location.subtract(0, 5, 0), ArmorStand.class); - _dataEntity.setVisible(false); - _dataEntity.setGravity(false); - } - - public SiegeWeaponToken tokenize() - { - SiegeWeaponToken token = new SiegeWeaponToken(); - - Map comprisedOf = new HashMap<>(); - - for (Entry entry : _entityMapping.entrySet()) - { - comprisedOf.put(entry.getKey(), entry.getValue().getUniqueId()); - } - - - token.ComprisedOf = comprisedOf; - - token.OwnerClan = _owner.getName(); - - token.WeaponType = _weaponTypeIdentifier; - - token.OutpostId = _outpost.getId(); - - token.Id = _id; - - token.Location = _location; - - token.Health = _health; - - token.Yaw = _yaw; - - token.DataEntityUUID = _dataEntity.getUniqueId(); - - token.Rider = _rider.getUniqueId(); - - token.LastFired = _lastFired; - - return token; - } - - private void updateData() - { - try - { - String data = _siegeManager.getGson().toJson(tokenize()); - - _dataEntity.setMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$", new FixedMetadataValue(_siegeManager.getPlugin(), data)); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - @EventHandler - public void saveData(UpdateEvent event) - { - if (event.getType() == UpdateType.SEC_05) - { - updateData(); - } } public int getBaseDamage() @@ -280,7 +205,7 @@ public abstract class SiegeWeapon implements Listener public ClanInfo getOwner() { - return _owner; + return _ownerClan; } public ClansManager getClans() @@ -294,7 +219,7 @@ public abstract class SiegeWeapon implements Listener removeHealth(health); - UtilTextMiddle.display(UtilText.possesive(_owner.getName(), _name), C.cRed + "-" + health, 5, 15, 5); + UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 5, 15, 5); } protected abstract double[] getProjectileVelocity(); @@ -497,9 +422,9 @@ public abstract class SiegeWeapon implements Listener return player.equals(getRider()); } - public String getId() + public int getUniqueId() { - return _id; + return _uniqueId; } protected void setRideable(AccessRule accessRule) @@ -520,8 +445,6 @@ public abstract class SiegeWeapon implements Listener _comprisedOf.clear(); _infoHologram.stop(); - _dataEntity.remove(); - _siegeManager.dead(this); _alive = false; @@ -624,7 +547,7 @@ public abstract class SiegeWeapon implements Listener return; } - if (!_owner.isMember(player)) + if (!_ownerClan.isMember(player)) { damage(player); } @@ -696,17 +619,17 @@ public abstract class SiegeWeapon implements Listener // Health Management - public final double getHealth() + public final int getHealth() { return _health; } public final String getDisplayHealth() { - return UtilText.getProgress(null, _health / _maxHealth, null, false, 12); + return UtilText.getProgress(null, ((double) _health) / ((double) _maxHealth), null, false, 12); } - public final void setHealth(double health) + public final void setHealth(int health) { _health = UtilMath.clamp(health, 0, _maxHealth); @@ -718,12 +641,12 @@ public abstract class SiegeWeapon implements Listener } } - public final void removeHealth(double health) + public final void removeHealth(int health) { setHealth(_health - health); } - public final void addHealth(double health) + public final void addHealth(int health) { setHealth(_health + health); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java deleted file mode 100644 index e6a941a27..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/SiegeWeaponToken.java +++ /dev/null @@ -1,23 +0,0 @@ -package mineplex.game.clans.clans.siege.weapon.serialization; - -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Location; - -import mineplex.core.common.GsonLocation; - -public class SiegeWeaponToken -{ - public String OwnerClan; - public int WeaponType; - public String OutpostId; - public GsonLocation Location; - public Map ComprisedOf; - public double Health; - public double Yaw; - public UUID Rider; - public String Id; - public long LastFired; - public UUID DataEntityUUID; -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java deleted file mode 100644 index 2bab907e6..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/serialization/TokenInfo.java +++ /dev/null @@ -1,6 +0,0 @@ -package mineplex.game.clans.clans.siege.weapon.serialization; - -public class TokenInfo -{ - public Class Type; -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index ac061de02..0d6daad86 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -154,9 +154,14 @@ public class Gameplay extends MiniPlugin } } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBowShoot(EntityShootBowEvent event) { + if (event.isCancelled()) + { + return; + } + if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); diff --git a/Plugins/database-config.dat b/Plugins/database-config.dat new file mode 100644 index 000000000..97bb8b2f7 --- /dev/null +++ b/Plugins/database-config.dat @@ -0,0 +1,4 @@ +ACCOUNT 10.33.53.17/Account MilitantPaladin ga.Usarathehe6up +QUEUE 10.33.53.17/Queue MilitantPaladin ga.Usarathehe6up +MINEPLEX 10.33.53.17/Mineplex MilitantPaladin ga.Usarathehe6up +STATS_MINEPLEX 10.33.53.17/Mineplex MilitantPaladin ga.Usarathehe6up diff --git a/Plugins/redis-config.dat b/Plugins/redis-config.dat new file mode 100644 index 000000000..ff7e4defb --- /dev/null +++ b/Plugins/redis-config.dat @@ -0,0 +1,4 @@ +10.33.53.17 6379 master ServerStatus +10.33.53.17 6378 slave ServerStatus +10.33.53.17 6379 master +10.33.53.17 6378 slave \ No newline at end of file From a5de88e6eef45d6fd3744a047d08ae20b3aec1e8 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 15 Feb 2016 11:25:33 +0000 Subject: [PATCH 094/122] accidentally added those ifles --- Plugins/database-config.dat | 4 ---- Plugins/redis-config.dat | 4 ---- 2 files changed, 8 deletions(-) delete mode 100644 Plugins/database-config.dat delete mode 100644 Plugins/redis-config.dat diff --git a/Plugins/database-config.dat b/Plugins/database-config.dat deleted file mode 100644 index 97bb8b2f7..000000000 --- a/Plugins/database-config.dat +++ /dev/null @@ -1,4 +0,0 @@ -ACCOUNT 10.33.53.17/Account MilitantPaladin ga.Usarathehe6up -QUEUE 10.33.53.17/Queue MilitantPaladin ga.Usarathehe6up -MINEPLEX 10.33.53.17/Mineplex MilitantPaladin ga.Usarathehe6up -STATS_MINEPLEX 10.33.53.17/Mineplex MilitantPaladin ga.Usarathehe6up diff --git a/Plugins/redis-config.dat b/Plugins/redis-config.dat deleted file mode 100644 index ff7e4defb..000000000 --- a/Plugins/redis-config.dat +++ /dev/null @@ -1,4 +0,0 @@ -10.33.53.17 6379 master ServerStatus -10.33.53.17 6378 slave ServerStatus -10.33.53.17 6379 master -10.33.53.17 6378 slave \ No newline at end of file From 8507bb1bd82e828bb4b2e8848956d07ceb8dcedc Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 18 Feb 2016 21:29:42 +0000 Subject: [PATCH 095/122] all progress over this week --- .../mineplex/core/common/util/UtilItem.java | 10 ++ .../mineplex/core/common/util/UtilText.java | 15 -- .../src/mineplex/core/stats/StatsManager.java | 2 + .../game/clans/clans/ClansManager.java | 2 +- .../game/clans/clans/siege/SiegeManager.java | 155 ++++++++++++++---- .../clans/clans/siege/outpost/Outpost.java | 93 +++++++++-- .../clans/siege/outpost/OutpostManager.java | 44 +++-- .../repository/SiegeWeaponRepository.java | 54 +++++- .../repository/tokens/SiegeWeaponToken.java | 7 +- .../game/clans/clans/siege/weapon/Cannon.java | 66 +++++--- .../clans/clans/siege/weapon/Catapult.java | 63 +++++-- .../clans/clans/siege/weapon/SiegeWeapon.java | 64 +++++--- .../game/clans/gameplay/Gameplay.java | 20 ++- 13 files changed, 436 insertions(+), 159 deletions(-) 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 22a7f4a7e..dc970e4eb 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 @@ -878,6 +878,16 @@ public class UtilItem return isLeaf(stack == null ? null : stack.getType()); } + public static boolean isDoor(Material type) + { + return type == null ? false : (contains(type, ItemCategory.DOOR)); + } + + public static boolean isDoor(ItemStack stack) + { + return isDoor(stack == null ? null : stack.getType()); + } + public static boolean isTool(Material material) { return material == null ? false : (contains(material, ItemCategory.TOOL)); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java index 5c289d176..fff061956 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilText.java @@ -698,19 +698,4 @@ public class UtilText return possesiveNoun.endsWith("s") ? possesiveNoun + "' " + noun : possesiveNoun + "'s " + noun; } - - public static String colorPercentage(int percentage) - { - Map colors = new HashMap<>(); - - colors.put(Integer.valueOf(100), C.cGreen); - colors.put(Integer.valueOf(80), C.cDGreen); - colors.put(Integer.valueOf(60), C.cYellow); - colors.put(Integer.valueOf(40), C.cGold); - colors.put(Integer.valueOf(20), C.cRed); - colors.put(Integer.valueOf(0), C.cDRed); - - return colors.get(Integer.valueOf(percentage / colors.size())); - } - } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java index ae88b6cb1..8c2bc5e06 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/stats/StatsManager.java @@ -294,6 +294,8 @@ public class StatsManager extends MiniDbClientPlugin }); } + + public int getStatId(String statName) { return _stats.get(statName); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 81891c6b7..ff4aa3648 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -383,7 +383,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); - new SiegeManager(plugin, this); + new SiegeManager(this); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index bd4b3a8e0..8c05ae2f2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -1,7 +1,6 @@ package mineplex.game.clans.clans.siege; -import java.util.HashMap; -import java.util.Map; +import java.util.Stack; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -9,12 +8,12 @@ import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.plugin.java.JavaPlugin; import com.google.gson.Gson; import mineplex.core.MiniPlugin; import mineplex.core.common.util.F; +import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; @@ -26,6 +25,8 @@ import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.OutpostManager; +import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository; +import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; @@ -33,23 +34,25 @@ import mineplex.game.clans.core.repository.ClanTerritory; public class SiegeManager extends MiniPlugin { - private ClansManager _clans; + private ClansManager _clansManager; private OutpostManager _outpostManager; public static SiegeManager Instance; - public Map LiveSiegeWeapons = new HashMap<>(); + public NautHashMap LiveSiegeWeapons = new NautHashMap<>(); private Gson _gson; - public SiegeManager(JavaPlugin plugin, ClansManager clans) + private SiegeWeaponRepository _repository; + + public SiegeManager(ClansManager clans) { - super("Siege", plugin); + super("Siege", clans.getPlugin()); _gson = new Gson(); - _clans = clans; + _clansManager = clans; _outpostManager = new OutpostManager(clans, this); @@ -57,8 +60,11 @@ public class SiegeManager extends MiniPlugin Instance = this; - _outpostManager.loadOutposts(); - loadSiegeWeapons(); + _repository = new SiegeWeaponRepository(clans.getPlugin(), this); + + _outpostManager.loadOutposts(() -> { + loadSiegeWeapons(); + }); } @EventHandler @@ -66,19 +72,96 @@ public class SiegeManager extends MiniPlugin { if (event.getType() == UpdateType.SLOWER) { - _outpostManager.saveOutposts(); - saveSiegeWeapons(); + _outpostManager.saveOutposts(() -> { + saveSiegeWeapons(); + }); } } private void loadSiegeWeapons() { - + _repository.getWeaponsByServer(_clansManager.getServerId(), tokens -> + tokens.forEach(token -> { + SiegeWeapon weapon = null; + + switch(token.WeaponType) + { + case 1: + weapon = new Catapult(this, token); + break; + case 2: + weapon = new Cannon(this, token); + break; + default: + System.out.println("[WEAPONS] ERROR WHILST LOADING WEAPON: INVALID WEAPON TYPE"); + return; + } + + if (!weapon.getLocation().getChunk().load()) + { + System.out.println("[WEAPONS] SKIPPING & REMOVING WEAPON [" + token.UniqueId + "] BECAUSE OF CHUNK LOADING FAILURE"); + + weapon.kill(); + + _repository.deleteWeapon(token.UniqueId); + return; + } + + if (token.OutpostId != 0) + { + Outpost outpost = _outpostManager.Get(token.OutpostId); + + if (outpost == null) + { + System.out.println("[WEAPONS] SKIPPING & REMOVING WEAPON [" + token.UniqueId + "] BECAUSE OF PARENT OUTPOST DEATH"); + + weapon.kill(); + + _repository.deleteWeapon(token.UniqueId); + + return; + } + + outpost.addWeapon(weapon); + } + + System.out.println("[WEAPONS] LOADED SIEGE WEAPON " + weapon.getClass().getSimpleName() + " [" + token.UniqueId + "]"); + + LiveSiegeWeapons.put(Integer.valueOf(token.UniqueId), weapon); + }) + ); } private void saveSiegeWeapons() { + final Stack queue = new Stack<>(); + for (final SiegeWeapon weapon : LiveSiegeWeapons.values()) + { + final SiegeWeaponToken token = weapon.toToken(); + + queue.push(() -> { + _repository.updateWeapon(token); + }); + } + + runAsync(() -> { + while (!queue.isEmpty()) + { + queue.pop().run(); + } + }); + + runAsync(() -> + _repository.getWeaponsByServer(_clansManager.getServerId(), tokens -> + tokens.forEach(token -> { + if (!LiveSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId))) + { + _repository.deleteWeapon(token.UniqueId); + } + }) + ) + ); } @EventHandler @@ -90,13 +173,13 @@ public class SiegeManager extends MiniPlugin { String[] data = projectile.getMetadata("OutpostData").get(0).asString().split(";"); - ClanInfo clan = _clans.getClanUtility().getClanByClanName(data[0]); + ClanInfo clan = _clansManager.getClanUtility().getClanByClanName(data[0]); Player player = UtilPlayer.searchExact(data[1]); if (_outpostManager.Get(clan) != null && player != null) { - ClanTerritory territory = _clans.getClanUtility().getClaim(projectile.getLocation()); + ClanTerritory territory = _clansManager.getClanUtility().getClaim(projectile.getLocation()); if (territory != null && ClansBlacklist.isValidClanName(territory.Owner) && !territory.Owner.equals(clan.getName())) { @@ -107,7 +190,7 @@ public class SiegeManager extends MiniPlugin } else { - _outpostManager.Get(clan).declareOn(player, _clans.getClanUtility().getClanByClanName(territory.Owner)); + _outpostManager.Get(clan).declareOn(player, _clansManager.getClanUtility().getClanByClanName(territory.Owner)); } } else @@ -151,18 +234,18 @@ public class SiegeManager extends MiniPlugin public boolean trySpawnCannon(Player player, Location location) { - if (!_clans.isInClan(player)) + if (!_clansManager.isInClan(player)) { UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Cannon.")); return false; } Outpost placedOutpost = null; - ClanInfo clan = _clans.getClanUtility().getClanByPlayer(player); + ClanInfo clan = _clansManager.getClanUtility().getClanByPlayer(player); - if (_clans.getClanUtility().isClaimed(location)) + if (_clansManager.getClanUtility().isClaimed(location)) { - if (!_clans.getClanUtility().getClaim(location).Owner.equals(clan.getName())) + if (!_clansManager.getClanUtility().getClaim(location).Owner.equals(clan.getName())) { UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); return false; @@ -203,30 +286,30 @@ public class SiegeManager extends MiniPlugin public void spawnCannon(Player player, Location location, Outpost outpost) { - Cannon cannon = new Cannon(location, _clans.getClan(player), this, outpost); + Cannon cannon = new Cannon(location, _clansManager.getClan(player), this, outpost); if (outpost != null) { outpost.addWeapon(cannon); } - LiveSiegeWeapons.put(cannon.getUniqueId(), cannon); + LiveSiegeWeapons.put(Integer.valueOf(cannon.getUniqueId()), cannon); } public boolean trySpawnCatapult(Player player, Location location) { - if (!_clans.isInClan(player)) + if (!_clansManager.isInClan(player)) { UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a CanCatapultnon.")); return false; } - ClanInfo clan = _clans.getClanUtility().getClanByPlayer(player); + ClanInfo clan = _clansManager.getClanUtility().getClanByPlayer(player); Outpost placedOutpost = null; - if (_clans.getClanUtility().isClaimed(location)) + if (_clansManager.getClanUtility().isClaimed(location)) { - if (!_clans.getClanUtility().getClaim(location).Owner.equals(clan.getName())) + if (!_clansManager.getClanUtility().getClaim(location).Owner.equals(clan.getName())) { UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); return false; @@ -266,19 +349,21 @@ public class SiegeManager extends MiniPlugin public void spawnCatapult(Player player, Location location, Outpost outpost) { - Catapult catapult = new Catapult(location, _clans.getClan(player), this, outpost); + Catapult catapult = new Catapult(location, _clansManager.getClan(player), this, outpost); if (outpost != null) { outpost.addWeapon(catapult); } - LiveSiegeWeapons.put(catapult.getUniqueId(), catapult); + LiveSiegeWeapons.put(Integer.valueOf(catapult.getUniqueId()), catapult); } public void dead(SiegeWeapon weapon) { - LiveSiegeWeapons.remove(weapon.getUniqueId()); + LiveSiegeWeapons.remove(Integer.valueOf(weapon.getUniqueId())); + + _repository.deleteWeapon(weapon.getUniqueId()); } public OutpostManager getOutpostManager() @@ -293,12 +378,20 @@ public class SiegeManager extends MiniPlugin public ClansManager getClansManager() { - return _clans; + return _clansManager; } public int randomId() { - return Math.abs(UtilMath.random.nextInt()); + /** + * prevents id from ever being 0 (which is used internally as NULL) + */ + return 1 + UtilMath.random.nextInt(Integer.MAX_VALUE - 1); + } + + public SiegeWeaponRepository getRepository() + { + return _repository; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index fed50eb70..545a9c329 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -17,6 +17,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; @@ -59,6 +60,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; +import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock; import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; @@ -124,6 +126,8 @@ public class Outpost implements Listener private long _siegeDeclaredTime = -1; private Arrow _declarationArrow; + private List _nameHolograms; + public Outpost(OutpostManager outpostManager, OutpostToken token) { _outpostManager = outpostManager; @@ -141,6 +145,8 @@ public class Outpost implements Listener _ownerClan = token.OwnerClan; + _nameHolograms = new ArrayList<>(); + _startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size); _endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9); @@ -157,8 +163,8 @@ public class Outpost implements Listener _core = _type.getCoreLocation(_origin); - _preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); - _preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + _preHologram = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); + _preHologram2 = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); if (token.OutpostState == OutpostState.AWAITING) { @@ -175,6 +181,16 @@ public class Outpost implements Listener List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); Collections.reverse(reverse); _reverseCircleStages = new LoopIterator(reverse); + + if (token.OutpostState == OutpostState.CONSTRUCTING || token.OutpostState == OutpostState.LIVE) + { + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); + + _nameHolograms.forEach(Hologram::start); + } } public Outpost(OutpostManager outpostManager, ClanInfo clan, Location location, OutpostType type) @@ -220,6 +236,11 @@ public class Outpost implements Listener _reverseCircleStages = new LoopIterator(reverse); UtilServer.registerEvents(this); + + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); } private void cleanup() @@ -237,12 +258,47 @@ public class Outpost implements Listener _weapons.forEach(SiegeWeapon::kill); _weapons.clear(); + _nameHolograms.forEach(Hologram::stop); + _outpostManager.queueForRemoval(_ownerClan.getName()); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onInteract(PlayerInteractEvent event) { + if (getState() == OutpostState.LIVE) + { + do + { + if (event.getClickedBlock() == null) + { + break; + } + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + { + break; + } + + if (!UtilItem.isDoor(event.getClickedBlock().getType())) + { + break; + } + + if (_ownerClan.isMember(event.getPlayer())) + { + break; + } + + if (UtilAlg.inBoundingBox(event.getClickedBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You cannot open the doors of this Outpost.")); + event.setCancelled(true); + return; + } + } while(false); + } + if (getState() != OutpostState.AWAITING) { return; @@ -274,7 +330,7 @@ public class Outpost implements Listener } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler public void fireBow(EntityShootBowEvent event) { if (!(event.getEntity() instanceof Player) || !(event.getProjectile() instanceof Arrow)) @@ -282,10 +338,7 @@ public class Outpost implements Listener return; } - event.setCancelled(true); - Player player = (Player) event.getEntity(); - Arrow arrow = player.shootArrow(); if (_ownerClan.isMember(player)) { @@ -300,6 +353,8 @@ public class Outpost implements Listener if (item.isSimilar(SIEGE_DECLARATION_ARROW)) { + Arrow arrow = (Arrow) event.getProjectile(); + if (_againstClan == null && !arrow.hasMetadata("OutpostData")) { arrow.setMetadata("OutpostData", new FixedMetadataValue(_outpostManager.getPlugin(), _ownerClan.getName() + ";" + player.getName())); @@ -357,7 +412,7 @@ public class Outpost implements Listener }; } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { if (event.isCancelled()) return; @@ -368,6 +423,16 @@ public class Outpost implements Listener event.setCancelled(true); } } + + @EventHandler(priority = EventPriority.HIGH) + public void claimTerritory(PlayerClaimTerritoryEvent event) + { + if (UtilMath.offset2d(event.getClaimedChunk().getBlock(8, 0, 8).getLocation(), _origin) < 32) + { + UtilPlayer.message(event.getClaimer(), F.main("Clans", "You may not claim this close to an Outpost.")); + event.setCancelled(true); + } + } protected void update() { @@ -387,7 +452,7 @@ public class Outpost implements Listener } else if (_againstClan != null) { - UtilTextBottom.display("Enemy Outpost Health: " + UtilText.colorPercentage(getHealthPercentage()) + "%", _againstClan.getOnlinePlayersArray()); + UtilTextBottom.display("Enemy Outpost Health: " + C.cYellow + getHealthPercentage() + "%", _againstClan.getOnlinePlayersArray()); } if (_state == OutpostState.AWAITING) @@ -428,12 +493,10 @@ public class Outpost implements Listener { if (block.getId() == Material.CHEST.getId()) { - for (int slot = 0; slot < 8; slot++) + for (int slot = 0; slot < ((Chest) block.getLocation().getBlock().getState()).getInventory().getSize(); slot++) { ((Chest) block.getLocation().getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW); } - - break; } } @@ -537,6 +600,8 @@ public class Outpost implements Listener } } } + + _nameHolograms.forEach(Hologram::start); } private List circleAround(Vector origin, int points, double radius) @@ -560,7 +625,7 @@ public class Outpost implements Listener NonFinalInteger wait = new NonFinalInteger(0); - _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block -> + _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block -> _outpostManager.runSyncLater(() -> { UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX); _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); @@ -680,7 +745,7 @@ public class Outpost implements Listener { return _againstClan; } - + public void declareOn(Player declarer, ClanInfo against) { if (_againstClan != null) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index e365b380d..45d57bfb0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -52,8 +52,6 @@ public class OutpostManager extends MiniPlugin private OutpostRepository _repository; - private Stack _addQueue = new Stack<>(); - public OutpostManager(ClansManager clansManager, SiegeManager siegeManager) { super("Outpost Manager", clansManager.getPlugin()); @@ -224,13 +222,6 @@ public class OutpostManager extends MiniPlugin @EventHandler public void update(UpdateEvent event) { - if (!_addQueue.isEmpty()) - { - Outpost outpost = _addQueue.pop(); - - _outposts.put(outpost.getOwner().getName(), outpost); - } - for (Outpost outpost : _outposts.values()) { if (outpost.getState() != OutpostState.DEAD) @@ -322,7 +313,7 @@ public class OutpostManager extends MiniPlugin if (outpost != null) { - if (event.getWeapon().getOwner().getName().equals(outpost.getAgainst().getName())) + if (outpost.getAgainst() != null && event.getWeapon().getOwner().getName().equals(outpost.getAgainst().getName())) { if (outpost.getHealth() > 0) { @@ -390,32 +381,38 @@ public class OutpostManager extends MiniPlugin return _clansManager; } - public void loadOutposts() + public void loadOutposts(Runnable post) { System.out.println("[OUTPOSTS] LOADING OUTPOSTS FROM DATABASE"); _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> { - for (OutpostToken token : tokens) - { + tokens.forEach(token -> { + Outpost outpost = new Outpost(this, token); + if ((System.currentTimeMillis() - token.TimeSpawned) > Outpost.MAX_LIFETIME) { System.out.println("[OUTPOSTS] SKIPPING & REMOVING OUTPOST [" + token.UniqueId + "] BECAUSE OF OLD AGE"); _repository.deleteOutpost(token.UniqueId); + outpost.kill(); - continue; + return; } - Outpost outpost = new Outpost(this, token); - System.out.println("[OUTPOSTS] INITIALIZED OUTPOST FROM DATABASE SAVE"); - _addQueue.push(outpost); + _outposts.put(token.OwnerClan.getName(), outpost); + }); + + if (post != null) + { + post.run(); } + }); } - public void saveOutposts() + public void saveOutposts(Runnable post) { final Stack queue = new Stack<>(); @@ -435,16 +432,17 @@ public class OutpostManager extends MiniPlugin } }); - runAsync(() -> - _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> + runAsync(() -> { + _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> { tokens.forEach(token -> { if (!_idToOutpost.containsKey(Integer.valueOf(token.UniqueId))) { + System.out.println("[OUTPOSTS] OUTPOST [" + token.UniqueId + "] NO LONGER EXISTS, DELETING"); _repository.deleteOutpost(token.UniqueId); } - }) - ) - ); + }); + }); + }); } public OutpostRepository getRepository() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java index 4a325efac..0027d92c7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -2,6 +2,7 @@ package mineplex.game.clans.clans.siege.repository; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.List; import org.bukkit.plugin.java.JavaPlugin; @@ -13,6 +14,8 @@ import mineplex.core.common.util.UtilWorld; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; import mineplex.core.database.column.ColumnInt; +import mineplex.core.database.column.ColumnTimestamp; +import mineplex.core.database.column.ColumnVarChar; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.outpost.Outpost; @@ -28,13 +31,17 @@ public class SiegeWeaponRepository extends RepositoryBase + "ownerClan INT NOT NULL," + "outpostId INT," + "weaponType TINYINT NOT NULL," - + "health int NOT NULL," - + "yaw int NOT NULL," + + "health INT NOT NULL," + + "yaw INT NOT NULL," + "lastFired LONG);"; private static final String GET_WEAPON_BY_ID = "SELECT * FROM clansSiegeWeapons WHERE uniqueId=?;"; private static final String GET_WEAPONS_BY_CLAN = "SELECT * FROM clansSiegeWeapons WHERE ownerClan=?;"; private static final String GET_WEAPONS_BY_OUTPOST = "SELECT * FROM clansSiegeWeapons WHERE outpostId=?;"; + private static final String GET_WEAPONS_BY_SERVER = "SELECT * FROM clansSiegeWeapons WHERE serverId=?;"; + + private static final String UPDATE_WEAPON = "UPDATE clansSiegeWeapons SET health=?,yaw=?,lastFired=? WHERE uniqueId=?;"; + private static final String INSERT_WEAPON = "INSERT INTO clansSiegeWeapons VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"; private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;"; @@ -62,6 +69,24 @@ public class SiegeWeaponRepository extends RepositoryBase callback.run(token); }, new ColumnInt("uniqueId", uniqueId)); } + + public void getWeaponsByServer(final int serverId, final Callback> callback) + { + executeQuery(GET_WEAPONS_BY_SERVER, resultSet -> { + List tokens = Lists.newArrayList(); + + while (resultSet.next()) + { + SiegeWeaponToken token = new SiegeWeaponToken(); + + load(token, resultSet); + + tokens.add(token); + } + + callback.run(tokens); + }, new ColumnInt("serverId", serverId)); + } public void getWeaponsByClan(final ClanInfo clan, final Callback> callback) { @@ -101,7 +126,7 @@ public class SiegeWeaponRepository extends RepositoryBase private void load(SiegeWeaponToken token, ResultSet columns) throws SQLException { - token.Id = columns.getInt("uniqueId"); + token.UniqueId = columns.getInt("uniqueId"); token.Location = UtilWorld.strToLoc(columns.getString("location")); token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan")); token.OutpostId = columns.getInt("outpostId"); @@ -110,6 +135,29 @@ public class SiegeWeaponRepository extends RepositoryBase token.Yaw = columns.getShort("yaw"); token.LastFired = columns.getTimestamp("lastFired").getTime(); } + + public void updateWeapon(SiegeWeaponToken token) + { + executeUpdate(UPDATE_WEAPON, + new ColumnInt("health", token.Health), + new ColumnInt("yaw", token.Yaw), + new ColumnTimestamp("lastFired", new Timestamp(token.LastFired)), + new ColumnInt("uniqueId", token.UniqueId)); + } + + public void insertWeapon(SiegeWeaponToken token) + { + executeUpdate(INSERT_WEAPON, + new ColumnInt("uniqueId", token.UniqueId), + new ColumnInt("serverId", _manager.getClansManager().getServerId()), + new ColumnVarChar("location", 30, UtilWorld.locToStr(token.Location)), + new ColumnInt("ownerClan", token.OwnerClan.getId()), + new ColumnInt("outpostId", token.OutpostId), + new ColumnInt("weaponType", token.WeaponType), + new ColumnInt("health", token.Health), + new ColumnInt("yaw", token.Yaw), + new ColumnTimestamp("lastFired", new Timestamp(token.LastFired))); + } @Override protected void initialize() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java index b07edf267..167c7ed2f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java @@ -1,22 +1,17 @@ package mineplex.game.clans.clans.siege.repository.tokens; -import java.util.Map; -import java.util.UUID; - import org.bukkit.Location; import mineplex.game.clans.clans.ClanInfo; public class SiegeWeaponToken { - public int Id; + public int UniqueId; public ClanInfo OwnerClan; public byte WeaponType; public int OutpostId; public Location Location; - public Map ComprisedOf; public int Health; public int Yaw; - public UUID Rider; public long LastFired; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index e760c2d2a..5c7c38522 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -1,20 +1,21 @@ package mineplex.game.clans.clans.siege.weapon; -import java.util.Map.Entry; -import java.util.UUID; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import com.google.common.collect.Lists; + import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEnt; @@ -179,37 +180,56 @@ public class Cannon extends SiegeWeapon private void loadEntities() { - Slime slime = _location.getWorld().spawn(_location, Slime.class); + Slime filler = _location.getWorld().spawn(_location, Slime.class); - UtilEnt.silence(slime, true); - UtilEnt.Vegetate(slime); + UtilEnt.silence(filler, true); + UtilEnt.Vegetate(filler); - slime.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + filler.setSize(-1); + filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - addEntity(slime, "Filler_1"); + addEntity(filler, "Filler_1"); - slime = _location.getWorld().spawn(_location, Slime.class); + Slime playerMount = _location.getWorld().spawn(_location, Slime.class); - UtilEnt.silence(slime, true); - UtilEnt.Vegetate(slime); + UtilEnt.silence(playerMount, true); + UtilEnt.Vegetate(playerMount); - slime.setSize(-1); - slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + playerMount.setSize(-1); + playerMount.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); - getEntity("Filler_1").setPassenger(slime); - addEntity(slime, "PLAYERMOUNT"); + getEntity("Filler_1").setPassenger(playerMount); + addEntity(playerMount, "PLAYERMOUNT"); - ArmorStand armorStand = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class); + ArmorStand weapon = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class); - UtilEnt.setFakeHead(armorStand, true); - armorStand.teleport(_location); - armorStand.setVisible(false); - armorStand.setGravity(false); + UtilEnt.setFakeHead(weapon, true); + weapon.teleport(_location); + weapon.setVisible(false); + weapon.setGravity(false); - armorStand.setPassenger(getEntity("Filler_1")); + weapon.setPassenger(getEntity("Filler_1")); - addEntity(armorStand, "WEAPON"); + addEntity(weapon, "WEAPON"); + + weapon.setMetadata("WeaponId", new FixedMetadataValue(_siegeManager.getPlugin(), Integer.valueOf(_uniqueId))); + } + + @Override + public void FindEntities() + { + Lists.newArrayList(_location.getChunk().getEntities()) + .stream() + .filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND)) + .filter(entity -> entity.hasMetadata("WeaponId")) + .filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId) + .forEach(entity -> { + + addEntity(entity, "WEAPON"); + addEntity(entity.getPassenger(), "Filler_1"); + addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT"); + + }); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index d4e70a40e..8e2abebef 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -4,13 +4,18 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Slime; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import com.google.common.collect.Lists; + import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilEnt; @@ -56,6 +61,8 @@ public class Catapult extends SiegeWeapon setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d)); + _invertRotation = true; + _baseDamage = 550; _rotSpeed = 60.0f; @@ -181,28 +188,56 @@ public class Catapult extends SiegeWeapon private void loadEntities() { - ArmorStand armorStand = _location.getWorld().spawn(_location.clone().add(.5, .1, .5), ArmorStand.class); - - UtilEnt.setFakeHead(armorStand, true); - armorStand.setVisible(false); - armorStand.setGravity(false); - - addEntity(armorStand, "WEAPON"); - Slime filler = _location.getWorld().spawn(_location, Slime.class); + UtilEnt.silence(filler, true); + UtilEnt.Vegetate(filler); + filler.setSize(-1); - filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0)); + filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); addEntity(filler, "Filler_1"); - ArmorStand mount = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class); + Slime playerMount = _location.getWorld().spawn(_location, Slime.class); - mount.setVisible(false); - mount.setGravity(false); - filler.setPassenger(mount); + UtilEnt.silence(playerMount, true); + UtilEnt.Vegetate(playerMount); - addEntity(mount, "PLAYERMOUNT"); + playerMount.setSize(-1); + playerMount.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false)); + + getEntity("Filler_1").setPassenger(playerMount); + addEntity(playerMount, "PLAYERMOUNT"); + + ArmorStand weapon = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), ArmorStand.class); + + UtilEnt.setFakeHead(weapon, true); + weapon.teleport(_location); + weapon.setVisible(false); + weapon.setGravity(false); + + weapon.setPassenger(getEntity("Filler_1")); + + addEntity(weapon, "WEAPON"); + + weapon.setMetadata("WeaponId", new FixedMetadataValue(_siegeManager.getPlugin(), Integer.valueOf(_uniqueId))); + } + + @Override + public void FindEntities() + { + Lists.newArrayList(_location.getChunk().getEntities()) + .stream() + .filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND)) + .filter(entity -> entity.hasMetadata("WeaponId")) + .filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId) + .forEach(entity -> { + + addEntity(entity, "WEAPON"); + addEntity(entity.getPassenger(), "Filler_1"); + addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT"); + + }); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 5955b5287..981ef34b7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -2,11 +2,8 @@ package mineplex.game.clans.clans.siege.weapon; import java.util.List; import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; import org.apache.commons.lang.Validate; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -25,6 +22,7 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; @@ -129,13 +127,13 @@ public abstract class SiegeWeapon implements Listener protected boolean _alive = true; - protected final int _weaponTypeIdentifier; + protected final byte _weaponTypeIdentifier; public SiegeWeapon(int maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager) { _weaponTypeIdentifier = token.WeaponType; - _uniqueId = token.Id; + _uniqueId = token.UniqueId; _outpost = siegeManager.getOutpostManager().Get(token.OutpostId); _siegeManager = siegeManager; @@ -155,29 +153,18 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; - for (Entity entity : token.Location.getWorld().getEntities()) - { - for (Entry entry : token.ComprisedOf.entrySet()) - { - if (entity.getUniqueId().equals(entry.getValue())) - { - _comprisedOf.add(entity); - _entityMapping.put(entry.getKey(), entity); - } - } - } - _yaw = token.Yaw; - _rider = Bukkit.getPlayer(token.Rider); _lastFired = token.LastFired; _health = token.Health; + + FindEntities(); } public SiegeWeapon(int typeId, Location location, int maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) { _uniqueId = siegeManager.randomId(); - _weaponTypeIdentifier = typeId; + _weaponTypeIdentifier = (byte) typeId; _outpost = outpost; _siegeManager = siegeManager; @@ -193,6 +180,8 @@ public abstract class SiegeWeapon implements Listener _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); _infoHologram.start(); + _siegeManager.getRepository().insertWeapon(toToken()); + UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); _clans = clansManager; @@ -222,6 +211,8 @@ public abstract class SiegeWeapon implements Listener UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 5, 15, 5); } + protected abstract void FindEntities(); + protected abstract double[] getProjectileVelocity(); protected abstract String getNextState(); @@ -265,17 +256,15 @@ public abstract class SiegeWeapon implements Listener checkInv(); } - if (getRider() != null && getRider().getVehicle() == null) - { - System.out.println("Resetting rider"); - _rider = null; - } + _rider = (Player) getEntity("PLAYERMOUNT").getPassenger(); if (!getNextState().equals(_currentState)) { setState(getNextState()); } + + if (_projectile != null) { if (_projectile.hasDied()) @@ -459,8 +448,6 @@ public abstract class SiegeWeapon implements Listener getEntity("PLAYERMOUNT").setPassenger(player); } - _rider = player; - OnMount(player); } @@ -508,7 +495,6 @@ public abstract class SiegeWeapon implements Listener private void dismount(Player player) { player.teleport(player.getLocation().add(0, 1, 0)); - _rider = null; } private void handleLeftClick(Player player) @@ -930,6 +916,15 @@ public abstract class SiegeWeapon implements Listener } } + @EventHandler + public void chunkUnload(ChunkUnloadEvent event) + { + if (_comprisedOf.stream().anyMatch(entity -> entity.getLocation().getChunk().equals(event.getChunk()))) + { + event.setCancelled(true); + } + } + @EventHandler public void update(UpdateEvent event) { @@ -952,5 +947,20 @@ public abstract class SiegeWeapon implements Listener { return _boundingBoxSize; } + + public SiegeWeaponToken toToken() + { + SiegeWeaponToken token = new SiegeWeaponToken(); + + token.UniqueId = _uniqueId; + token.OwnerClan = _ownerClan; + token.WeaponType = _weaponTypeIdentifier; + token.OutpostId = _outpost == null ? 0 : _outpost.getUniqueId(); + token.Location = _location; + token.Health = _health; + token.Yaw = (int) _yaw; + + return token; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 0d6daad86..b30233eee 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -14,7 +14,6 @@ import org.bukkit.Sound; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; import org.bukkit.entity.EntityType; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; @@ -66,6 +65,7 @@ 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.siege.outpost.Outpost; import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; @@ -154,7 +154,7 @@ public class Gameplay extends MiniPlugin } } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + @EventHandler public void onBowShoot(EntityShootBowEvent event) { if (event.isCancelled()) @@ -165,6 +165,22 @@ public class Gameplay extends MiniPlugin if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); + + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + ItemStack item = player.getInventory().getItem(slot); + + if (item == null) + { + continue; + } + + if (item.isSimilar(Outpost.SIEGE_DECLARATION_ARROW)) + { + return; + } + } + ClientClass playerClass = _clansManager.getClassManager().Get(player); if (!playerClass.IsGameClass(ClassType.Assassin, ClassType.Ranger)) From 24b834370ba029f880d6222e9a299fd25920e91a Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 18 Feb 2016 21:37:13 +0000 Subject: [PATCH 096/122] null pointers with siege weaponl oading --- .../game/clans/clans/siege/weapon/Cannon.java | 8 +++++ .../clans/clans/siege/weapon/Catapult.java | 30 ++++++++++++------- .../clans/clans/siege/weapon/SiegeWeapon.java | 7 +++-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 5c7c38522..5e83d48d2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -223,6 +223,9 @@ public class Cannon extends SiegeWeapon .filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND)) .filter(entity -> entity.hasMetadata("WeaponId")) .filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId) + .filter(entity -> entity.getPassenger() != null) + .filter(entity -> entity.getPassenger().getPassenger() != null) + .limit(1l) .forEach(entity -> { addEntity(entity, "WEAPON"); @@ -230,6 +233,11 @@ public class Cannon extends SiegeWeapon addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT"); }); + + if (getEntity("WEAPON") == null || getEntity("Filler_1") == null || getEntity("PLAYERMOUNT") == null) + { + kill(); + } } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 8e2abebef..87c8ee263 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -227,17 +227,25 @@ public class Catapult extends SiegeWeapon public void FindEntities() { Lists.newArrayList(_location.getChunk().getEntities()) - .stream() - .filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND)) - .filter(entity -> entity.hasMetadata("WeaponId")) - .filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId) - .forEach(entity -> { - - addEntity(entity, "WEAPON"); - addEntity(entity.getPassenger(), "Filler_1"); - addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT"); - - }); + .stream() + .filter(entity -> entity.getType().equals(EntityType.ARMOR_STAND)) + .filter(entity -> entity.hasMetadata("WeaponId")) + .filter(entity -> entity.getMetadata("WeaponId").get(0).asInt() == _uniqueId) + .filter(entity -> entity.getPassenger() != null) + .filter(entity -> entity.getPassenger().getPassenger() != null) + .limit(1l) + .forEach(entity -> { + + addEntity(entity, "WEAPON"); + addEntity(entity.getPassenger(), "Filler_1"); + addEntity(entity.getPassenger().getPassenger(), "PLAYERMOUNT"); + + }); + + if (getEntity("WEAPON") == null || getEntity("Filler_1") == null || getEntity("PLAYERMOUNT") == null) + { + kill(); + } } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 981ef34b7..735280d58 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -256,15 +256,16 @@ public abstract class SiegeWeapon implements Listener checkInv(); } - _rider = (Player) getEntity("PLAYERMOUNT").getPassenger(); + if (getEntity("PLAYERMOUNT").getPassenger() != null) + { + _rider = (Player) getEntity("PLAYERMOUNT").getPassenger(); + } if (!getNextState().equals(_currentState)) { setState(getNextState()); } - - if (_projectile != null) { if (_projectile.hasDied()) From dc5fe21f3d50d2a8544fffc47b655f4578ceebed Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 18 Feb 2016 21:53:55 +0000 Subject: [PATCH 097/122] more npe checking --- .../mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 735280d58..2639dfc09 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -251,6 +251,11 @@ public abstract class SiegeWeapon implements Listener private void updateWeapon() { + if (getEntity("WEAPON") == null || getEntity("PLAYERMOUNT") == null) + { + kill(); + } + if (_inventory != null) { checkInv(); From db7382d01e30b72dc8c309728763f1e780602d53 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 21 Feb 2016 01:34:13 +0000 Subject: [PATCH 098/122] testing github? --- .../game/clans/clans/siege/SiegeManager.java | 187 ++------------- .../siege/commands/CommandSiegeSupplies.java | 6 +- .../clans/clans/siege/outpost/Outpost.java | 225 +----------------- .../clans/siege/outpost/OutpostManager.java | 99 +------- .../siege/repository/OutpostRepository.java | 16 +- .../repository/SiegeWeaponRepository.java | 23 -- .../siege/repository/tokens/OutpostToken.java | 3 - .../repository/tokens/SiegeWeaponToken.java | 1 - .../game/clans/clans/siege/weapon/Cannon.java | 4 +- .../clans/clans/siege/weapon/Catapult.java | 6 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 21 +- .../clans/siege/weapon/projectile/Crater.java | 27 ++- 12 files changed, 57 insertions(+), 561 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 8c05ae2f2..3f398b4e8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -4,10 +4,8 @@ import java.util.Stack; import org.bukkit.Location; import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.ProjectileHitEvent; import com.google.gson.Gson; @@ -19,18 +17,14 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClanInfo; -import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies; -import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; -import mineplex.game.clans.core.repository.ClanTerritory; public class SiegeManager extends MiniPlugin { @@ -107,24 +101,6 @@ public class SiegeManager extends MiniPlugin return; } - if (token.OutpostId != 0) - { - Outpost outpost = _outpostManager.Get(token.OutpostId); - - if (outpost == null) - { - System.out.println("[WEAPONS] SKIPPING & REMOVING WEAPON [" + token.UniqueId + "] BECAUSE OF PARENT OUTPOST DEATH"); - - weapon.kill(); - - _repository.deleteWeapon(token.UniqueId); - - return; - } - - outpost.addWeapon(weapon); - } - System.out.println("[WEAPONS] LOADED SIEGE WEAPON " + weapon.getClass().getSimpleName() + " [" + token.UniqueId + "]"); LiveSiegeWeapons.put(Integer.valueOf(token.UniqueId), weapon); @@ -164,48 +140,6 @@ public class SiegeManager extends MiniPlugin ); } - @EventHandler - public void projectileHit(ProjectileHitEvent event) - { - Projectile projectile = event.getEntity(); - - if (projectile.hasMetadata("OutpostData")) - { - String[] data = projectile.getMetadata("OutpostData").get(0).asString().split(";"); - - ClanInfo clan = _clansManager.getClanUtility().getClanByClanName(data[0]); - - Player player = UtilPlayer.searchExact(data[1]); - - if (_outpostManager.Get(clan) != null && player != null) - { - ClanTerritory territory = _clansManager.getClanUtility().getClaim(projectile.getLocation()); - - if (territory != null && ClansBlacklist.isValidClanName(territory.Owner) && !territory.Owner.equals(clan.getName())) - { - if (clan.getOnlinePlayerCount() < 1) - { - UtilPlayer.message(player, F.main("Clans", "A Clan must have at least 2 online players for you to declared siege on them. Grab another arrow from the Outpost and try again elsewhere.")); - player.getInventory().addItem(Outpost.SIEGE_DECLARATION_ARROW); - } - else - { - _outpostManager.Get(clan).declareOn(player, _clansManager.getClanUtility().getClanByClanName(territory.Owner)); - } - } - else - { - UtilPlayer.message(player, F.main("Clans", "You did not fire the Siege Declaration arrow into a valid rival Clan's territory. Grab another arrow from the Outpost and try again.")); - player.getInventory().addItem(Outpost.SIEGE_DECLARATION_ARROW); - } - - _outpostManager.Get(clan).setDeclarationArrow(null); - } - - projectile.remove(); - } - } - @EventHandler public void onBlockPlace(BlockPlaceEvent event) { @@ -220,16 +154,16 @@ public class SiegeManager extends MiniPlugin } } - if (event.getItemInHand().isSimilar(Catapult.CATAPULT_ITEM)) - { - event.setCancelled(true); - - if (trySpawnCatapult(event.getPlayer(), event.getBlock().getLocation())) - { - event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); - return; - } - } +// if (event.getItemInHand().isSimilar(Catapult.CATAPULT_ITEM)) +// { +// event.setCancelled(true); +// +// if (trySpawnCatapult(event.getPlayer(), event.getBlock().getLocation())) +// { +// event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); +// return; +// } +// } } public boolean trySpawnCannon(Player player, Location location) @@ -240,59 +174,15 @@ public class SiegeManager extends MiniPlugin return false; } - Outpost placedOutpost = null; - ClanInfo clan = _clansManager.getClanUtility().getClanByPlayer(player); - - if (_clansManager.getClanUtility().isClaimed(location)) - { - if (!_clansManager.getClanUtility().getClaim(location).Owner.equals(clan.getName())) - { - UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); - return false; - } - } - else - { - boolean allowed = false; - - for (Outpost outpost : _outpostManager.getOutposts()) - { - if (!outpost.getOwner().getName().equals(clan.getName())) - { - UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); - return false; - } - - if (outpost.isInSiegeArea(location)) - { - placedOutpost = outpost; - allowed = true; - break; - } - } - - if (!allowed) - { - UtilPlayer.message(player, F.main("Clans", "A Cannon must be placed in your own territory or your Outpost in the case of a Siege.")); - return false; - } - } - - - spawnCannon(player, location, placedOutpost); + spawnCannon(player, location); return true; } - public void spawnCannon(Player player, Location location, Outpost outpost) + public void spawnCannon(Player player, Location location) { - Cannon cannon = new Cannon(location, _clansManager.getClan(player), this, outpost); + Cannon cannon = new Cannon(location, _clansManager.getClan(player), this); - if (outpost != null) - { - outpost.addWeapon(cannon); - } - LiveSiegeWeapons.put(Integer.valueOf(cannon.getUniqueId()), cannon); } @@ -304,57 +194,14 @@ public class SiegeManager extends MiniPlugin return false; } - ClanInfo clan = _clansManager.getClanUtility().getClanByPlayer(player); - Outpost placedOutpost = null; - - if (_clansManager.getClanUtility().isClaimed(location)) - { - if (!_clansManager.getClanUtility().getClaim(location).Owner.equals(clan.getName())) - { - UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); - return false; - } - } - else - { - boolean allowed = false; - - for (Outpost outpost : _outpostManager.getOutposts()) - { - if (!outpost.getOwner().getName().equals(clan.getName())) - { - UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); - return false; - } - - if (outpost.isInSiegeArea(location)) - { - placedOutpost = outpost; - allowed = true; - break; - } - } - - if (!allowed) - { - UtilPlayer.message(player, F.main("Clans", "A Catapult must be placed in your own territory or your Outpost in the case of a Siege.")); - return false; - } - } - - spawnCatapult(player, location, placedOutpost); + spawnCatapult(player, location); return true; } - public void spawnCatapult(Player player, Location location, Outpost outpost) + public void spawnCatapult(Player player, Location location) { - Catapult catapult = new Catapult(location, _clansManager.getClan(player), this, outpost); - - if (outpost != null) - { - outpost.addWeapon(catapult); - } + Catapult catapult = new Catapult(location, _clansManager.getClan(player), this); LiveSiegeWeapons.put(Integer.valueOf(catapult.getUniqueId()), catapult); } @@ -380,7 +227,7 @@ public class SiegeManager extends MiniPlugin { return _clansManager; } - + public int randomId() { /** diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java index 3e9f4cae1..7b11d30f2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/commands/CommandSiegeSupplies.java @@ -24,15 +24,15 @@ public class CommandSiegeSupplies extends CommandBase { ItemStack outpost = new ItemStack(Outpost.OUTPOST_ITEM); ItemStack cannons = new ItemStack(Cannon.CANNON_ITEM); - ItemStack catapults = new ItemStack(Catapult.CATAPULT_ITEM); +// ItemStack catapults = new ItemStack(Catapult.CATAPULT_ITEM); outpost.setAmount(64); cannons.setAmount(64); - catapults.setAmount(64); +// catapults.setAmount(64); caller.getInventory().addItem(outpost); caller.getInventory().addItem(cannons); - caller.getInventory().addItem(catapults); +// caller.getInventory().addItem(catapults); UtilPlayer.message(caller, F.main("Clans", "Received supplies for a siege.")); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 545a9c329..6234d1eba 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -72,7 +72,6 @@ public class Outpost implements Listener { protected static final long MAX_LIFETIME = 30 * 60 * 1000; // 30 minutes public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build(); - public static final ItemStack SIEGE_DECLARATION_ARROW = new ItemBuilder(Material.ARROW, 1).setRawTitle(C.cAquaB + "Siege Declaration Arrow").setLore(UtilText.splitLineToArray(C.cWhite + "Fire a bow with this arrow at a rival Clan's base to declare Siege on them. Note that you are required to do this before being able to place Siege Weapons in your Outpost.", LineFormat.LORE)).build(); public static final byte OUTPOST_BLOCK_DATA = (byte) 137; public static final long PREP_TIME = 2 * 60 * 1000; @@ -95,8 +94,6 @@ public class Outpost implements Listener private LinkedHashMap _blocks; private LinkedHashMap _buildQueue; - private List _weapons; - protected OutpostType _type; private OutpostState _state; @@ -106,43 +103,20 @@ public class Outpost implements Listener private LoopIterator _circleStages; private LoopIterator _reverseCircleStages; - private double _siegeWeaponDistance; - private ColorFader _fader = new ColorFader(30, UtilColor.hexToRgb(0x00A296), UtilColor.hexToRgb(0x29E6B6)); - private LoopIterator _arrowColors = new LoopIterator<>(Lists.newArrayList( - UtilColor.rgb(203, 156, 16), - UtilColor.rgb(240, 196, 66), - UtilColor.rgb(203, 212, 17), - UtilColor.rgb(147, 212, 17), - UtilColor.rgb(150, 199, 51))); private long _timeSpawned; - public int _maxHealth = 4500; - public int _health = _maxHealth; - public ClanInfo _againstClan; - private long _siegeDeclaredTime = -1; - private Arrow _declarationArrow; - private List _nameHolograms; public Outpost(OutpostManager outpostManager, OutpostToken token) { _outpostManager = outpostManager; - System.out.println(token.OutpostState + ", " + token.Type); - - setHealth(token.Health); - - _siegeDeclaredTime = token.SiegeDeclaredTime; - _againstClan = token.AgainstClan; - _uniqueId = token.UniqueId; - _siegeWeaponDistance = token.Type._size + 27.5; - _ownerClan = token.OwnerClan; _nameHolograms = new ArrayList<>(); @@ -150,8 +124,6 @@ public class Outpost implements Listener _startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size); _endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9); - _weapons = new ArrayList<>(); - _forceFieldStart = _startCorner.clone().subtract(4, 0, 4); _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); @@ -199,15 +171,11 @@ public class Outpost implements Listener _uniqueId = outpostManager.getSiegeManager().randomId(); - _siegeWeaponDistance = type._size + 27.5; - _ownerClan = clan; _startCorner = location.clone().subtract(type._size, 1.1, type._size); _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); - _weapons = new ArrayList<>(); - _forceFieldStart = _startCorner.clone().subtract(4, 0, 4); _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); @@ -255,9 +223,6 @@ public class Outpost implements Listener _state = OutpostState.DEAD; - _weapons.forEach(SiegeWeapon::kill); - _weapons.clear(); - _nameHolograms.forEach(Hologram::stop); _outpostManager.queueForRemoval(_ownerClan.getName()); @@ -330,43 +295,6 @@ public class Outpost implements Listener } } - @EventHandler - public void fireBow(EntityShootBowEvent event) - { - if (!(event.getEntity() instanceof Player) || !(event.getProjectile() instanceof Arrow)) - { - return; - } - - Player player = (Player) event.getEntity(); - - if (_ownerClan.isMember(player)) - { - for (int slot = 0; slot < player.getInventory().getSize(); slot++) - { - ItemStack item = player.getInventory().getItem(slot); - - if (item == null) - { - continue; - } - - if (item.isSimilar(SIEGE_DECLARATION_ARROW)) - { - Arrow arrow = (Arrow) event.getProjectile(); - - if (_againstClan == null && !arrow.hasMetadata("OutpostData")) - { - arrow.setMetadata("OutpostData", new FixedMetadataValue(_outpostManager.getPlugin(), _ownerClan.getName() + ";" + player.getName())); - _declarationArrow = (Arrow) arrow; - player.getInventory().setItem(slot, UtilInv.decrement(item)); - break; - } - } - } - } - } - @EventHandler public void onBlockDamage(BlockDamageEvent event) { @@ -436,25 +364,6 @@ public class Outpost implements Listener protected void update() { - if (_declarationArrow != null) - { - _declarationArrow.setFireTicks(20); - - RGBData color = _arrowColors.next(); - - UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX); - } - - if (_againstClan != null && getTimeToSiege() > 150) - { - _againstClan.getOnlinePlayers().forEach(this::informTimeToSiege); - _ownerClan.getOnlinePlayers().forEach(this::informTimeToSiege); - } - else if (_againstClan != null) - { - UtilTextBottom.display("Enemy Outpost Health: " + C.cYellow + getHealthPercentage() + "%", _againstClan.getOnlinePlayersArray()); - } - if (_state == OutpostState.AWAITING) { if (getLifetime() > 60000) @@ -489,17 +398,6 @@ public class Outpost implements Listener { _state = OutpostState.LIVE; - for (OutpostBlock block : _blocks.values()) - { - if (block.getId() == Material.CHEST.getId()) - { - for (int slot = 0; slot < ((Chest) block.getLocation().getBlock().getState()).getInventory().getSize(); slot++) - { - ((Chest) block.getLocation().getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW); - } - } - } - return; } else @@ -564,7 +462,7 @@ public class Outpost implements Listener .filter(player -> !_ownerClan.isMember(player)) .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) .forEach(player -> { - UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .4, true, 0.8, 0, 1.1, true); + UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .65, true, 0.8, 0, 1.1, true); UtilPlayer.message(player, F.main("Clans", "This Outpost is still under construction!")); player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); }); @@ -625,7 +523,7 @@ public class Outpost implements Listener NonFinalInteger wait = new NonFinalInteger(0); - _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block -> + _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(13).forEach(block -> _outpostManager.runSyncLater(() -> { UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX); _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); @@ -633,7 +531,7 @@ public class Outpost implements Listener ); _outpostManager.runSyncLater(() -> { - _blocks.values().forEach(block -> { + _blocks.values().stream().filter(block -> Math.random() > 0.66).forEach(block -> { Material mat = Material.getMaterial(block.getId()); if (UtilItem.isTranslucent(mat)) @@ -659,20 +557,6 @@ public class Outpost implements Listener _ownerClan.inform("Your Clan's Outpost has been destroyed.", null); } - @EventHandler - public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) - { - if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _startCorner.clone().subtract(4, 2, 4), _endCorner.clone().add(4, 2, 4))) - { - if (getHealth() > 700) - { - event.setCancelled(true); - } - - removeHealth(800); - } - } - public ClanInfo getOwner() { return _ownerClan; @@ -698,111 +582,11 @@ public class Outpost implements Listener return _state; } - // AREA IN WHICH CANNONS AND OTHER SIEGE WEAPONS CAN BE PLACED - public boolean isInSiegeArea(Location location) - { - return UtilMath.offset2d(location, _core) <= _siegeWeaponDistance; - } - - // Health Management - - public final int getHealthPercentage() - { - return ((int) ((((double) _health) / ((double) _maxHealth)) * 100.d)); - } - - public final int getHealth() - { - return _health; - } - - public final String getDisplayHealth() - { - return UtilText.getProgress(null, ((double) _health) / ((double) _maxHealth), null, false, 12); - } - - public final void setHealth(int health) - { - _health = UtilMath.clamp(health, 0, _maxHealth); - - if (_health == 0) - { - kill(); - } - } - - public final void removeHealth(int health) - { - setHealth(_health - health); - } - - public final void addHealth(int health) - { - setHealth(_health + health); - } - public ClanInfo getAgainst() { return _againstClan; } - public void declareOn(Player declarer, ClanInfo against) - { - if (_againstClan != null) - { - UtilPlayer.message(declarer, F.main("Clans", "Your Clan has already declared Siege against " + F.elem(_againstClan.getName()) + ".")); - } - else - { - if (_outpostManager.isInSiege(against)) - { - UtilPlayer.message(declarer, F.main("Clans", F.elem(against.getName()) + " is already in a Siege.")); - return; - } - - _againstClan = against; - _siegeDeclaredTime = System.currentTimeMillis(); - - _ownerClan.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_againstClan.getName()) + "."), null); - _ownerClan.inform("Siege", "Your Clan has declared a Siege", null); - _ownerClan.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); - - _againstClan.inform(F.main("Clans", F.elem(_ownerClan.getName()) + " has declared a Siege against your Clan."), null); - _againstClan.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); - _againstClan.inform("Siege", F.elem(_ownerClan.getName()) + " has declared a Siege", null); - } - } - - public void informTimeToSiege(Player player) - { - UtilTextBottom.display(C.Bold + "Time to Siege: " + F.time(UtilTime.MakeStr(getTimeToSiege())), player); - } - - public long getTimeSiegeDeclared() - { - return _siegeDeclaredTime; - } - - public long getTimeToSiege() - { - return PREP_TIME - (System.currentTimeMillis() - getTimeSiegeDeclared()); - } - - public void setDeclarationArrow(Arrow arrow) - { - _declarationArrow = arrow; - } - - public Arrow getDeclarationArrow() - { - return _declarationArrow; - } - - public void addWeapon(SiegeWeapon weapon) - { - _weapons.add(weapon); - } - public int getUniqueId() { return _uniqueId; @@ -816,10 +600,7 @@ public class Outpost implements Listener token.Origin = _origin; token.Type = _type; token.OwnerClan = _ownerClan; - token.Health = _health; token.TimeSpawned = _timeSpawned; - token.AgainstClan = _againstClan; - token.SiegeDeclaredTime = _siegeDeclaredTime; token.OutpostState = _state; return token; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 45d57bfb0..ceb0f4c36 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -18,15 +18,12 @@ import org.bukkit.inventory.ItemStack; import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; -import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilText; -import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; @@ -34,7 +31,6 @@ import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.siege.SiegeManager; -import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.repository.OutpostRepository; import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; @@ -70,7 +66,7 @@ public class OutpostManager extends MiniPlugin { if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) { - if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_III)) + if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_I)) { event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); } @@ -278,99 +274,6 @@ public class OutpostManager extends MiniPlugin return Lists.newArrayList(_outposts.values()); } - @EventHandler - public void onQuit(PlayerQuitEvent event) - { - Player player = (Player) event.getPlayer(); - ClanInfo clan = _clansManager.getClan(player); - - if (Get(clan) != null) - { - return; - } - - for (int slot = 0; slot < player.getInventory().getSize(); slot++) - { - ItemStack item = player.getInventory().getItem(slot); - - if (item == null) - { - continue; - } - - if (item.isSimilar(Outpost.SIEGE_DECLARATION_ARROW)) - { - player.getInventory().setItem(slot, null); - break; - } - } - } - - @EventHandler - public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) - { - Outpost outpost = _siegeManager.getOutpostManager().outpostInArea(event.getProjectile().getLocation(), event.getProjectile().getCraterSize() + 1); - - if (outpost != null) - { - if (outpost.getAgainst() != null && event.getWeapon().getOwner().getName().equals(outpost.getAgainst().getName())) - { - if (outpost.getHealth() > 0) - { - int hprem = event.getWeapon().getBaseDamage(); - - hprem += UtilMath.random.nextInt(250); - - outpost.removeHealth(hprem); - - UtilTextMiddle.display("Damage", "You damaged " + F.elem(outpost.getOwner().getName()) + "'s Outpost for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + outpost.getHealth() + C.cGray + ")", 10, 60, 10, event.getWeapon().getRider()); - UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You damaged " + F.elem(outpost.getOwner().getName()) + "'s Outpost for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + outpost.getHealth() + C.cGray + ")")); - - if (outpost.getHealth() == 0) - { - event.getWeapon().getOwner().inform(F.main("Clans", UtilText.possesive(F.elem(outpost.getOwner().getName()), "Outpost") + " is now vulnerable to physical damage by Siege Weapons."), null); - event.getWeapon().getOwner().inform("Siege", UtilText.possesive(F.elem(outpost.getOwner().getName()), "Outpost") + " is now vulnerable to physical damage", null); - } - } - } - else - { - event.setCancelled(true); - } - } - } - - public Outpost outpostInArea(Location location, int radius) - { - for (Outpost outpost : _outposts.values()) - { - if (outpost == null) - { - return null; - } - - if (outpost.getExactMiddle().distance(location) >= outpost._type._size + radius) - { - return outpost; - } - } - - return null; - } - - public boolean isInSiege(ClanInfo clan) - { - for (Outpost outpost : _outposts.values()) - { - if (clan.equals(outpost.getOwner()) || clan.equals(outpost.getAgainst())) - { - return true; - } - } - - return false; - } - public Outpost Get(int outpostId) { return _idToOutpost.get(Integer.valueOf(outpostId)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java index d6bcb600a..0dda938b8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java @@ -32,18 +32,15 @@ public class OutpostRepository extends RepositoryBase + "origin VARCHAR(30)," + "outpostType TINYINT NOT NULL," + "ownerClan INT NOT NULL," - + "health INT NOT NULL," + "timeSpawned LONG," - + "againstClan INT," - + "siegeDeclaredTime LONG," + "outpostState TINYINT NOT NULL);"; private static final String GET_OUTPOST_BY_ID = "SELECT * FROM clansOutposts WHERE uniqueId=?;"; private static final String GET_OUTPOST_BY_CLAN = "SELECT * FROM clansOutposts WHERE ownerClan=?;"; private static final String GET_OUTPOSTS_BY_SERVER = "SELECT * FROM clansOutposts WHERE serverId=?;"; - private static final String UPDATE_OUTPOST = "UPDATE clansOutposts SET health=?,againstClan=?,siegeDeclaredTime=?,outpostState=? WHERE uniqueId=?;"; - private static final String INSERT_OUTPOST = "INSERT INTO clansOutposts VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; + private static final String UPDATE_OUTPOST = "UPDATE clansOutposts SET outpostState=? WHERE uniqueId=?;"; + private static final String INSERT_OUTPOST = "INSERT INTO clansOutposts VALUES (?, ?, ?, ?, ?, ?, ?);"; private static final String DELETE_OUTPOST = "DELETE FROM clansOutposts WHERE uniqueId=?;"; @@ -107,10 +104,7 @@ public class OutpostRepository extends RepositoryBase token.Origin = UtilWorld.strToLoc(columns.getString("origin")); token.Type = OutpostType.ById(columns.getByte("outpostType")); token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan")); - token.Health = columns.getShort("health"); token.TimeSpawned = columns.getTimestamp("timeSpawned").getTime(); - token.AgainstClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("againstClan")); - token.SiegeDeclaredTime = columns.getTimestamp("siegeDeclaredTime").getTime(); token.OutpostState = OutpostState.ById(columns.getByte("outpostState")); } @@ -128,9 +122,6 @@ public class OutpostRepository extends RepositoryBase public void updateOutpost(OutpostToken token) { executeUpdate(UPDATE_OUTPOST, - new ColumnInt("health", token.Health), - new ColumnInt("againstClan", token.AgainstClan == null ? 0 : token.AgainstClan.getId()), - new ColumnTimestamp("siegeDeclaredTime", new Timestamp(token.SiegeDeclaredTime)), new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId())), new ColumnInt("uniqueId", token.UniqueId)); } @@ -143,10 +134,7 @@ public class OutpostRepository extends RepositoryBase new ColumnVarChar("origin", 30, UtilWorld.locToStr(token.Origin)), new ColumnInt("outpostType", token.Type.getId()), new ColumnInt("ownerClan", token.OwnerClan.getId()), - new ColumnInt("health", token.Health), new ColumnTimestamp("timeSpawned", new Timestamp(token.TimeSpawned)), - new ColumnInt("againstClan", token.AgainstClan == null ? 0 : token.AgainstClan.getId()), - new ColumnTimestamp("siegeDeclaredTime", new Timestamp(token.SiegeDeclaredTime)), new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId()))); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java index 0027d92c7..df53012cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -18,7 +18,6 @@ import mineplex.core.database.column.ColumnTimestamp; import mineplex.core.database.column.ColumnVarChar; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; -import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; public class SiegeWeaponRepository extends RepositoryBase @@ -29,7 +28,6 @@ public class SiegeWeaponRepository extends RepositoryBase + "serverId INT NOT NULL," + "location VARCHAR(30)," + "ownerClan INT NOT NULL," - + "outpostId INT," + "weaponType TINYINT NOT NULL," + "health INT NOT NULL," + "yaw INT NOT NULL," @@ -37,7 +35,6 @@ public class SiegeWeaponRepository extends RepositoryBase private static final String GET_WEAPON_BY_ID = "SELECT * FROM clansSiegeWeapons WHERE uniqueId=?;"; private static final String GET_WEAPONS_BY_CLAN = "SELECT * FROM clansSiegeWeapons WHERE ownerClan=?;"; - private static final String GET_WEAPONS_BY_OUTPOST = "SELECT * FROM clansSiegeWeapons WHERE outpostId=?;"; private static final String GET_WEAPONS_BY_SERVER = "SELECT * FROM clansSiegeWeapons WHERE serverId=?;"; private static final String UPDATE_WEAPON = "UPDATE clansSiegeWeapons SET health=?,yaw=?,lastFired=? WHERE uniqueId=?;"; @@ -106,30 +103,11 @@ public class SiegeWeaponRepository extends RepositoryBase }, new ColumnInt("ownerClan", clan.getId())); } - public void getWeaponsByOutpost(final Outpost outpost, final Callback> callback) - { - executeQuery(GET_WEAPONS_BY_OUTPOST, resultSet -> { - List tokens = Lists.newArrayList(); - - while (resultSet.next()) - { - SiegeWeaponToken token = new SiegeWeaponToken(); - - load(token, resultSet); - - tokens.add(token); - } - - callback.run(tokens); - }, new ColumnInt("outpostId", outpost.getUniqueId())); - } - private void load(SiegeWeaponToken token, ResultSet columns) throws SQLException { token.UniqueId = columns.getInt("uniqueId"); token.Location = UtilWorld.strToLoc(columns.getString("location")); token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan")); - token.OutpostId = columns.getInt("outpostId"); token.WeaponType = columns.getByte("weaponType"); token.Health = columns.getShort("health"); token.Yaw = columns.getShort("yaw"); @@ -152,7 +130,6 @@ public class SiegeWeaponRepository extends RepositoryBase new ColumnInt("serverId", _manager.getClansManager().getServerId()), new ColumnVarChar("location", 30, UtilWorld.locToStr(token.Location)), new ColumnInt("ownerClan", token.OwnerClan.getId()), - new ColumnInt("outpostId", token.OutpostId), new ColumnInt("weaponType", token.WeaponType), new ColumnInt("health", token.Health), new ColumnInt("yaw", token.Yaw), diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java index 1bd6c1912..0436fbda9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/OutpostToken.java @@ -12,9 +12,6 @@ public class OutpostToken public Location Origin; public OutpostType Type; public ClanInfo OwnerClan; - public int Health; public long TimeSpawned; - public ClanInfo AgainstClan; - public long SiegeDeclaredTime; public OutpostState OutpostState; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java index 167c7ed2f..ca40e582a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java @@ -9,7 +9,6 @@ public class SiegeWeaponToken public int UniqueId; public ClanInfo OwnerClan; public byte WeaponType; - public int OutpostId; public Location Location; public int Health; public int Yaw; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 5e83d48d2..bad203a4c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -108,9 +108,9 @@ public class Cannon extends SiegeWeapon })); } - public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) + public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager) { - super(2, location, 1400, "Cannon", clan, clan.Clans, siegeManager, outpost); + super(2, location, 1400, "Cannon", clan, clan.Clans, siegeManager); setBoundingBox(1); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index 87c8ee263..a4999c956 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -38,7 +38,7 @@ import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; public class Catapult extends SiegeWeapon { - public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); +// public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build(); public Catapult(SiegeManager siegeManager, SiegeWeaponToken token) { @@ -113,9 +113,9 @@ public class Catapult extends SiegeWeapon })); } - public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) + public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager) { - super(1, location, 2500, "Catapult", clan, clan.Clans, siegeManager, outpost); + super(1, location, 2500, "Catapult", clan, clan.Clans, siegeManager); setBoundingBox(3, 0); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 2639dfc09..703c833cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -39,7 +39,6 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -47,7 +46,6 @@ import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; -import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; @@ -63,11 +61,6 @@ public abstract class SiegeWeapon implements Listener protected int _uniqueId; - /** - * THIS MAY BE NULL IF NOT PLACED IN OUTPOST - */ - protected Outpost _outpost; - protected ClanInfo _ownerClan; protected final String _name; protected final int _maxHealth; @@ -135,7 +128,6 @@ public abstract class SiegeWeapon implements Listener _uniqueId = token.UniqueId; - _outpost = siegeManager.getOutpostManager().Get(token.OutpostId); _siegeManager = siegeManager; _location = token.Location; _name = name; @@ -161,12 +153,11 @@ public abstract class SiegeWeapon implements Listener FindEntities(); } - public SiegeWeapon(int typeId, Location location, int maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) + public SiegeWeapon(int typeId, Location location, int maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager) { _uniqueId = siegeManager.randomId(); _weaponTypeIdentifier = (byte) typeId; - _outpost = outpost; _siegeManager = siegeManager; _location = location; _name = name; @@ -314,15 +305,6 @@ public abstract class SiegeWeapon implements Listener private void fire(Player player) { - if (_outpost != null) - { - if (_outpost.getTimeToSiege() > 0) - { - UtilPlayer.message(player, F.main("Clans", "You must wait for preparation time to end before firing any weapons. (" + F.time(UtilTime.MakeStr(_outpost.getTimeToSiege()) + ")"))); - return; - } - } - _lastFired = System.currentTimeMillis(); double[] vel = getProjectileVelocity(); @@ -961,7 +943,6 @@ public abstract class SiegeWeapon implements Listener token.UniqueId = _uniqueId; token.OwnerClan = _ownerClan; token.WeaponType = _weaponTypeIdentifier; - token.OutpostId = _outpost == null ? 0 : _outpost.getUniqueId(); token.Location = _location; token.Health = _health; token.Yaw = (int) _yaw; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java index acd074e38..0d21e4e4b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java @@ -23,9 +23,9 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.siege.SiegeManager; -import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; +import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.core.repository.ClanTerritory; public class Crater implements Listener { @@ -98,6 +98,13 @@ public class Crater implements Listener private void createExplosion() { + ClanTerritory terr = _weapon.getClans().getClanUtility().getClaim(_origin); + + if (terr != null && !ClansBlacklist.isValidClanName(terr.Owner)) + { + return; + } + _blocks.add(new CraterBlock(_origin, 0, Material.AIR)); HashMap blockList = new HashMap(); @@ -124,6 +131,14 @@ public class Crater implements Listener for (Entry entry : blockList.entrySet()) { Block block = entry.getKey(); + + ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation()); + + if (territory != null && !ClansBlacklist.isValidClanName(territory.Owner)) + { + continue; + } + double distance = entry.getValue().doubleValue(); boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d); @@ -156,6 +171,14 @@ public class Crater implements Listener for (Entry entry : blockList.entrySet()) { Block block = entry.getKey(); + + ClanTerritory territory = _weapon.getClans().getClanUtility().getClaim(block.getLocation()); + + if (territory != null && !ClansBlacklist.isValidClanName(territory.Owner)) + { + continue; + } + double distance = entry.getValue().doubleValue(); if (block.getType() == Material.AIR) continue; From 76cf65c26710090a2d294f06dbf25041ff1e4fe3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 21 Feb 2016 20:33:52 +0000 Subject: [PATCH 099/122] siege system changes --- .../game/clans/clans/siege/SiegeManager.java | 21 ++++- .../repository/SiegeWeaponRepository.java | 2 +- .../game/clans/clans/siege/weapon/Cannon.java | 79 +++++++++++++++++-- .../clans/clans/siege/weapon/SiegeWeapon.java | 66 +++++++--------- .../game/clans/gameplay/Gameplay.java | 15 ---- 5 files changed, 124 insertions(+), 59 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 3f398b4e8..95b8733e7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -17,14 +17,17 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies; +import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; +import mineplex.game.clans.core.repository.ClanTerritory; public class SiegeManager extends MiniPlugin { @@ -174,6 +177,14 @@ public class SiegeManager extends MiniPlugin return false; } + ClanTerritory claim = _clansManager.getClanUtility().getClaim(location); + + if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName())) + { + UtilPlayer.message(player, F.main("Clans", "You must place a Cannon in the Wilderness or your own Territory.")); + return false; + } + spawnCannon(player, location); return true; @@ -190,7 +201,15 @@ public class SiegeManager extends MiniPlugin { if (!_clansManager.isInClan(player)) { - UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a CanCatapultnon.")); + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Catapult.")); + return false; + } + + ClanTerritory claim = _clansManager.getClanUtility().getClaim(location); + + if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName())) + { + UtilPlayer.message(player, F.main("Clans", "You must place a Catapult in the Wilderness or your own Territory.")); return false; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java index df53012cb..7757c6893 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -38,7 +38,7 @@ public class SiegeWeaponRepository extends RepositoryBase private static final String GET_WEAPONS_BY_SERVER = "SELECT * FROM clansSiegeWeapons WHERE serverId=?;"; private static final String UPDATE_WEAPON = "UPDATE clansSiegeWeapons SET health=?,yaw=?,lastFired=? WHERE uniqueId=?;"; - private static final String INSERT_WEAPON = "INSERT INTO clansSiegeWeapons VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);"; + private static final String INSERT_WEAPON = "INSERT INTO clansSiegeWeapons VALUES (?, ?, ?, ?, ?, ?, ?, ?);"; private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;"; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index bad203a4c..257483973 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -4,9 +4,11 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.ArmorStand; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.entity.Slime; +import org.bukkit.event.EventHandler; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; @@ -19,6 +21,7 @@ import com.google.common.collect.Lists; import mineplex.core.common.util.C; import mineplex.core.common.util.F; 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; @@ -28,7 +31,6 @@ import mineplex.core.common.util.UtilTime; import mineplex.core.itemstack.ItemBuilder; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; -import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; @@ -40,6 +42,8 @@ public class Cannon extends SiegeWeapon { public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build(); + private int _firepower = 1; + public Cannon(SiegeManager siegeManager, SiegeWeaponToken token) { super(1400, "Cannon", token, siegeManager.getClansManager(), siegeManager); @@ -49,12 +53,8 @@ public class Cannon extends SiegeWeapon setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); setStateInfo("Loaded", new WeaponStateInfo(Material.SPONGE, (byte) 0)); - setFirepowerType(Material.SULPHUR); setAmmunitionType(Material.TNT); - setFirepowerSlots(Integer.valueOf(1), Integer.valueOf(3), Integer.valueOf(5), Integer.valueOf(7)); - setMaximumFirepowerPerSlot(3); - setAmmunitionSlot(4); setMaximumAmmunitionPerSlot(1); @@ -178,6 +178,66 @@ public class Cannon extends SiegeWeapon })); } + @EventHandler + protected void InventoryClick(InventoryClickEvent event) + { + if (!event.getClickedInventory().equals(_inventory)) + { + return; + } + + if (event.getSlot() == 0) + { + int oldFirepower = _firepower; + + _firepower = UtilMath.clamp(--_firepower, 1, 3); + + if (oldFirepower != _firepower) + { + ((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f); + } + else + { + ((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); + } + + event.setCancelled(true); + } + else if (event.getSlot() == 1) + { + event.setCancelled(true); + } + else if (event.getSlot() == 2) + { + int oldFirepower = _firepower; + + _firepower = UtilMath.clamp(++_firepower, 1, 3); + + if (oldFirepower != _firepower) + { + ((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_PLING, 1.0f, 1.0f); + } + else + { + ((Player) event.getWhoClicked()).playSound(event.getWhoClicked().getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); + } + + event.setCancelled(true); + } + } + + private void updateInventory() + { + _inventory.setItem(0, new ItemBuilder(Material.LEVER).setTitle(C.cRed + "-1 Firepower").build()); + _inventory.setItem(1, new ItemBuilder(Material.SULPHUR).setTitle(C.cWhiteB + "Firepower: " + C.cYellow + _firepower).build()); + _inventory.setItem(2, new ItemBuilder(Material.LEVER).setTitle(C.cGreen + "+1 Firepower").build()); + } + + protected boolean CustomInventoryValid(int slot, ItemStack item) + { + return slot == 0 || slot == 1 || slot == 2; + } + private void loadEntities() { Slime filler = _location.getWorld().spawn(_location, Slime.class); @@ -260,9 +320,16 @@ public class Cannon extends SiegeWeapon return "Unloaded"; } + protected int getPowerLevel() + { + return _firepower; + } + @Override protected void Tick() { + updateInventory(); + if (getProjectile() != null) { UtilParticle.PlayParticleToAll(ParticleType.LARGE_SMOKE, getProjectile().getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 703c833cb..1715c8353 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -18,6 +18,7 @@ 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.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -195,7 +196,7 @@ public abstract class SiegeWeapon implements Listener protected void damage(Player player) { - int health = 1 + UtilMath.random.nextInt(10); + int health = 3 + UtilMath.random.nextInt(10); removeHealth(health); @@ -249,13 +250,10 @@ public abstract class SiegeWeapon implements Listener if (_inventory != null) { - checkInv(); + checkInventory(); } - if (getEntity("PLAYERMOUNT").getPassenger() != null) - { - _rider = (Player) getEntity("PLAYERMOUNT").getPassenger(); - } + _rider = (Player) getEntity("PLAYERMOUNT").getPassenger(); if (!getNextState().equals(_currentState)) { @@ -480,6 +478,11 @@ public abstract class SiegeWeapon implements Listener } } + protected boolean CustomInventoryValid(int slot, ItemStack item) + { + return false; + } + private void dismount(Player player) { player.teleport(player.getLocation().add(0, 1, 0)); @@ -658,7 +661,7 @@ public abstract class SiegeWeapon implements Listener return _registeredStates.get(state); } - public void checkInv() + public void checkInventory() { for (int slot = 0; slot < _inventory.getSize(); slot++) { @@ -673,6 +676,11 @@ public abstract class SiegeWeapon implements Listener { if (item.getType() != _ammunitionType) { + if (CustomInventoryValid(slot, item)) + { + continue; + } + if (getRider() != null) { getRider().getInventory().addItem(item); @@ -705,6 +713,11 @@ public abstract class SiegeWeapon implements Listener { if (item.getType() != _firepowerType) { + if (CustomInventoryValid(slot, item)) + { + continue; + } + if (getRider() != null) { getRider().getInventory().addItem(item); @@ -735,6 +748,11 @@ public abstract class SiegeWeapon implements Listener } else { + if (CustomInventoryValid(slot, item)) + { + continue; + } + if (getRider() != null) { getRider().getInventory().addItem(item); @@ -754,37 +772,13 @@ public abstract class SiegeWeapon implements Listener @EventHandler public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) { - if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _location.clone().subtract(4, 2, 4), _location.clone().add(4, 2, 4))) + if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _location.clone().subtract(3, 2, 3), _location.clone().add(3, 2, 3))) { - if (getHealth() > 750) - { - event.setCancelled(true); - } + kill(); - int hprem = _baseDamage /* base damage */; - - /* randomness */ - hprem += UtilMath.random.nextInt(250); - - /* distance calc */ - double dist = UtilMath.offset2d(event.getProjectile().getLocation(), _location); - - dist = Math.min(dist, 3); - - hprem -= (400.d /* max damage loss caused by distance */ / 3.d) * dist; - - removeHealth(hprem); - - if (_alive) - { - UtilTextMiddle.display("Damage", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")", 10, 60, 10, event.getWeapon().getRider()); - UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You damaged " + F.elem(getOwner().getName()) + "'s " + _name + " for " + C.cRed + "-" + hprem + C.mBody + " health. (Current health: " + C.cGreen + getHealth() + C.cGray + ")")); - } - else - { - UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider()); - UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".")); - } + _ownerClan.inform("One of your Cannons has been destroyed!", null); + UtilTextMiddle.display("Damage", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".", 10, 60, 10, event.getWeapon().getRider()); + UtilPlayer.message(event.getWeapon().getRider(), F.main("Clans", "You destroyed " + F.elem(getOwner().getName()) + "'s " + _name + ".")); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index b30233eee..267006e0a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -165,21 +165,6 @@ public class Gameplay extends MiniPlugin if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); - - for (int slot = 0; slot < player.getInventory().getSize(); slot++) - { - ItemStack item = player.getInventory().getItem(slot); - - if (item == null) - { - continue; - } - - if (item.isSimilar(Outpost.SIEGE_DECLARATION_ARROW)) - { - return; - } - } ClientClass playerClass = _clansManager.getClassManager().Get(player); From f0fc2fd5192ecda57a4827cad477fe18add3c53c Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 22 Feb 2016 20:44:00 +0000 Subject: [PATCH 100/122] progress [testing github] --- .../core/common/util/NautArrayList.java | 13 +++- .../core/common/util/NautHashMap.java | 16 +++- .../core/common/util/UtilCollections.java | 50 +++++++++++++ .../mineplex/core/common/util/UtilMath.java | 5 ++ .../game/clans/clans/siege/weapon/Cannon.java | 11 +++ .../clans/clans/siege/weapon/SiegeWeapon.java | 73 ++++++++++++++----- 6 files changed, 145 insertions(+), 23 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java 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 a61b1d411..3fa3f7507 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 @@ -8,10 +8,19 @@ import java.util.ListIterator; import java.util.function.Consumer; import java.util.stream.Stream; -public class NautArrayList +public class NautArrayList implements Iterable { private ArrayList _wrappedArrayList = new ArrayList(); - + + public NautArrayList() + { + } + + public NautArrayList(Elem[] elements) + { + UtilCollections.addAll(elements, _wrappedArrayList); + } + public boolean add(Elem elem) { return _wrappedArrayList.add(elem); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautHashMap.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautHashMap.java index e6d74c9d5..2f43abed9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautHashMap.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/NautHashMap.java @@ -3,12 +3,26 @@ package mineplex.core.common.util; import java.util.Collection; import java.util.HashMap; import java.util.Map.Entry; + +import org.apache.commons.lang3.Validate; + import java.util.Set; public class NautHashMap { private HashMap _wrappedHashMap = new HashMap(); - + + public NautHashMap() + { + } + + public NautHashMap(KeyType[] keys, ValueType[] values) + { + Validate.isTrue(keys.length == values.length, "Keys array and values array must be the same size when making a Map"); + + UtilCollections.loop(0, keys.length, i -> _wrappedHashMap.put(keys[i.intValue()], values[i.intValue()])); + } + public boolean containsKey(KeyType key) { return _wrappedHashMap.containsKey(key); diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java new file mode 100644 index 000000000..b88a66880 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java @@ -0,0 +1,50 @@ +package mineplex.core.common.util; + +import java.util.Collection; +import java.util.function.Consumer; + +public class UtilCollections +{ + @SafeVarargs + public static NautArrayList newNautList(E... elements) + { + return new NautArrayList(elements); + } + + public static NautArrayList newNautList() + { + return new NautArrayList(); + } + + public static NautHashMap newNautMap(K[] keys, V[] values) + { + return new NautHashMap(keys, values); + } + + public static NautHashMap newNautMap() + { + return new NautHashMap(); + } + + public static void forEach(E[] elements, Consumer consumer) + { + for (int i = 0; i < elements.length; i++) + { + consumer.accept(elements[i]); + } + } + + public static void addAll(E[] elements, Collection collection) + { + forEach(elements, collection::add); + } + + public static void loop(int min, int max, Consumer consumer) + { + for (int i = min; i < max; i++) + { + consumer.accept(Integer.valueOf(i)); + } + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 82bbb711f..bd9e1600c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -278,4 +278,9 @@ public class UtilMath return bits; } + + public static double getDecimalPoints(double n) + { + return n - ((int) ((int) n)); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 257483973..27ba0087b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -238,6 +238,17 @@ public class Cannon extends SiegeWeapon return slot == 0 || slot == 1 || slot == 2; } + protected void ResetEntities() + { + removeEntity("Filler_1"); + removeEntity("PLAYERMOUNT"); + removeEntity("WEAPON"); + + loadEntities(); + + getEntity("PLAYERMOUNT").setPassenger(_rider); + } + private void loadEntities() { Slime filler = _location.getWorld().spawn(_location, Slime.class); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 1715c8353..bf7c44780 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -1,8 +1,5 @@ package mineplex.game.clans.clans.siege.weapon; -import java.util.List; -import java.util.Map; - import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; @@ -18,7 +15,6 @@ 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.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -29,12 +25,13 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.util.EulerAngle; import org.spigotmc.event.entity.EntityDismountEvent; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.NautArrayList; +import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; @@ -54,6 +51,7 @@ import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; +import mineplex.game.clans.items.PlayerGear; public abstract class SiegeWeapon implements Listener { @@ -75,13 +73,13 @@ public abstract class SiegeWeapon implements Listener protected final Location _location; - private final Map _registeredStates; + private final NautHashMap _registeredStates; private String _currentState; - protected final List _comprisedOf; + protected final NautArrayList _comprisedOf; // Friendly-name mapping to index in _comprisedOf for easier management of entities. - protected final Map _entityMapping; + protected final NautHashMap _entityMapping; private boolean _isRideable; private AccessRule _mountAccess; @@ -97,7 +95,7 @@ public abstract class SiegeWeapon implements Listener private Material _firepowerType; private Material _ammunitionType; - private List _firepowerSlots; + private NautArrayList _firepowerSlots; private int _ammunitionSlot; private int _maxAmmunition; @@ -135,9 +133,9 @@ public abstract class SiegeWeapon implements Listener _health = _maxHealth = maxHealth; _ownerClan = token.OwnerClan; - _comprisedOf = Lists.newArrayList(); - _registeredStates = Maps.newHashMap(); - _entityMapping = Maps.newHashMap(); + _comprisedOf = new NautArrayList<>(); + _registeredStates = new NautHashMap<>(); + _entityMapping = new NautHashMap<>(); _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); _infoHologram.start(); @@ -165,9 +163,9 @@ public abstract class SiegeWeapon implements Listener _health = _maxHealth = maxHealth; _ownerClan = owner; - _comprisedOf = Lists.newArrayList(); - _registeredStates = Maps.newHashMap(); - _entityMapping = Maps.newHashMap(); + _comprisedOf = new NautArrayList<>(); + _registeredStates = new NautHashMap<>(); + _entityMapping = new NautHashMap<>(); _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); _infoHologram.start(); @@ -196,13 +194,36 @@ public abstract class SiegeWeapon implements Listener protected void damage(Player player) { - int health = 3 + UtilMath.random.nextInt(10); + int health = getHandDamage(player); removeHealth(health); UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 5, 15, 5); } + + protected int getHandDamage(Player player) + { + ItemStack stack = player.getItemInHand(); + PlayerGear gear = _clans.getGearManager().getPlayerGear(player); + + if (stack == null) + { + return 1 ; + } + + if (gear.getWeapon() != null) + { + + } + + return UtilItem.getAttackDamage(player); + } + + protected void ResetEntities() + { + } + protected abstract void FindEntities(); protected abstract double[] getProjectileVelocity(); @@ -246,6 +267,13 @@ public abstract class SiegeWeapon implements Listener if (getEntity("WEAPON") == null || getEntity("PLAYERMOUNT") == null) { kill(); + return; + } + + if (UtilMath.getDecimalPoints(getEntity("WEAPON").getLocation().getX()) != .5) + { + ResetEntities(); + return; } if (_inventory != null) @@ -331,7 +359,7 @@ public abstract class SiegeWeapon implements Listener protected void setFirepowerSlots(Integer... slots) { - _firepowerSlots = Lists.newArrayList(slots); + _firepowerSlots = UtilCollections.newNautList(slots); } protected void setMaximumFirepowerPerSlot(int maxFirepowerPerSlot) @@ -586,7 +614,12 @@ public abstract class SiegeWeapon implements Listener protected final void removeEntity(String uniqueName) { - _comprisedOf.remove(_entityMapping.remove(getEntity(uniqueName))); + Entity entity = _entityMapping.get(uniqueName); + + _entityMapping.remove(uniqueName); + _comprisedOf.remove(entity); + + entity.remove(); } protected final Entity getEntity(String uniqueName) From de4568d4481793a409eadde4c3a9fd08a2c98cfa Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 13:03:50 +0000 Subject: [PATCH 101/122] accurate-ish weapon damage tracking --- .../clans/clans/siege/weapon/SiegeWeapon.java | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index bf7c44780..d7db58e5e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -52,6 +52,12 @@ import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; import mineplex.game.clans.items.PlayerGear; +import mineplex.game.clans.items.legendaries.AlligatorsTooth; +import mineplex.game.clans.items.legendaries.GiantsBroadsword; +import mineplex.game.clans.items.legendaries.HyperAxe; +import mineplex.game.clans.items.legendaries.LegendaryItem; +import mineplex.game.clans.items.legendaries.MagneticMaul; +import mineplex.game.clans.items.legendaries.WindBlade; public abstract class SiegeWeapon implements Listener { @@ -201,7 +207,6 @@ public abstract class SiegeWeapon implements Listener UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 5, 15, 5); } - protected int getHandDamage(Player player) { ItemStack stack = player.getItemInHand(); @@ -209,15 +214,34 @@ public abstract class SiegeWeapon implements Listener if (stack == null) { - return 1 ; + return 1; } - if (gear.getWeapon() != null) + if (gear.getWeapon() != null && gear.getWeapon() instanceof LegendaryItem) { - + if (gear.getWeapon() instanceof AlligatorsTooth) + { + return 8; + } + else if (gear.getWeapon() instanceof GiantsBroadsword) + { + return 10; + } + else if (gear.getWeapon() instanceof HyperAxe) + { + return 3; + } + else if (gear.getWeapon() instanceof MagneticMaul) + { + return 8; + } + else if (gear.getWeapon() instanceof WindBlade) + { + return 7; + } } - return UtilItem.getAttackDamage(player); + return (int) UtilItem.getAttackDamage(stack.getType()); } protected void ResetEntities() From 306e56980c1708f970e761288e6288b5027936f0 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 14:44:07 +0000 Subject: [PATCH 102/122] remove weapon teleport fix --- .../src/mineplex/game/clans/clans/siege/weapon/Cannon.java | 4 ++-- .../mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 27ba0087b..67beb670a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -251,7 +251,7 @@ public class Cannon extends SiegeWeapon private void loadEntities() { - Slime filler = _location.getWorld().spawn(_location, Slime.class); + Slime filler = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), Slime.class); UtilEnt.silence(filler, true); UtilEnt.Vegetate(filler); @@ -261,7 +261,7 @@ public class Cannon extends SiegeWeapon addEntity(filler, "Filler_1"); - Slime playerMount = _location.getWorld().spawn(_location, Slime.class); + Slime playerMount = _location.getWorld().spawn(_location.clone().add(.5, 0, .5), Slime.class); UtilEnt.silence(playerMount, true); UtilEnt.Vegetate(playerMount); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index d7db58e5e..a324c5114 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -294,12 +294,6 @@ public abstract class SiegeWeapon implements Listener return; } - if (UtilMath.getDecimalPoints(getEntity("WEAPON").getLocation().getX()) != .5) - { - ResetEntities(); - return; - } - if (_inventory != null) { checkInventory(); From bcd4480f230a1e4e21c7eb0865c9547573ac1ae7 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 15:57:12 +0000 Subject: [PATCH 103/122] stop recruits from opening trapped chests --- .../mineplex/game/clans/clans/ClansGame.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java index 05413244e..737481910 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java @@ -210,15 +210,18 @@ public class ClansGame extends MiniPlugin } // Disallow Recruit Chest - if (_clans.getClanUtility().isClaimed(event.getBlock().getLocation())) if (event.getBlock().getTypeId() == 54) + if (_clans.getClanUtility().isClaimed(event.getBlock().getLocation())) { - if (_clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT) + if (event.getBlock().getType() == Material.CHEST || event.getBlock().getType() == Material.TRAPPED_CHEST) { - // Disallow - event.setCancelled(true); - - // Inform - UtilPlayer.message(event.getPlayer(), F.main("Clans", "Clan Recruits cannot break " + F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) + ".")); + if (_clans.getClanUtility().getRole(event.getPlayer()) == ClanRole.RECRUIT) + { + // Disallow + event.setCancelled(true); + + // Inform + UtilPlayer.message(event.getPlayer(), F.main("Clans", "Clan Recruits cannot break " + F.elem(ItemStackFactory.Instance.GetName(event.getBlock(), true)) + ".")); + } } } From 41e140d5caf5cac6e3ddf2e53f6f7eb23f568add Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 16:07:12 +0000 Subject: [PATCH 104/122] stop players from placing water in outposts --- .../mineplex/core/common/util/UtilServer.java | 6 +++ .../clans/event/ClansWaterPlaceEvent.java | 53 +++++++++++++++++++ .../clans/clans/siege/outpost/Outpost.java | 28 +++++----- .../game/clans/gameplay/Gameplay.java | 22 ++++++-- 4 files changed, 93 insertions(+), 16 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansWaterPlaceEvent.java 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 921344101..17765ceb5 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 @@ -11,6 +11,7 @@ import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; @@ -97,4 +98,9 @@ public class UtilServer { return getServer().getPluginManager(); } + + public static void callEvent(Event event) + { + getPluginManager().callEvent(event); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansWaterPlaceEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansWaterPlaceEvent.java new file mode 100644 index 000000000..c6826eeef --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansWaterPlaceEvent.java @@ -0,0 +1,53 @@ +package mineplex.game.clans.clans.event; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ClansWaterPlaceEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private Block _block; + + private boolean _cancelled; + + public ClansWaterPlaceEvent(Player player, Block block) + { + _player = player; + _block = block; + } + + public Player getPlayer() + { + return _player; + } + + public Block getBlock() + { + return _block; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 6234d1eba..263c3349b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -10,10 +10,7 @@ import java.util.List; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.block.Chest; -import org.bukkit.entity.Arrow; import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -21,18 +18,14 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; -import com.google.common.collect.Lists; - import mineplex.core.common.util.C; import mineplex.core.common.util.ColorFader; import mineplex.core.common.util.F; -import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.LoopIterator; import mineplex.core.common.util.NonFinalInteger; import mineplex.core.common.util.RGBData; @@ -42,7 +35,6 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilColor; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; -import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; @@ -51,20 +43,17 @@ import mineplex.core.common.util.UtilParticle.ViewDist; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; -import mineplex.core.common.util.UtilTextBottom; import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansBlacklist; +import mineplex.game.clans.clans.event.ClansWaterPlaceEvent; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; -import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock; import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; -import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; @@ -340,10 +329,23 @@ public class Outpost implements Listener }; } + @EventHandler + public void onWaterPlace(ClansWaterPlaceEvent event) + { + if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place water in Outposts.")); + event.setCancelled(true); + } + } + @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { - if (event.isCancelled()) return; + if (event.isCancelled()) + { + return; + } if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 267006e0a..6235642cd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -56,6 +56,7 @@ import mineplex.core.common.util.UtilGear; 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.UtilTime; import mineplex.core.common.weight.Weight; import mineplex.core.common.weight.WeightSet; @@ -65,7 +66,7 @@ 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.siege.outpost.Outpost; +import mineplex.game.clans.clans.event.ClansWaterPlaceEvent; import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; @@ -334,12 +335,27 @@ public class Gameplay extends MiniPlugin @EventHandler public void LapisPlace(BlockPlaceEvent event) { - if (event.isCancelled()) return; + if (event.isCancelled()) + { + return; + } - if (event.getBlock().getType() != Material.LAPIS_BLOCK) return; + if (event.getBlock().getType() != Material.LAPIS_BLOCK) + { + return; + } event.setCancelled(true); + ClansWaterPlaceEvent placeEvent = new ClansWaterPlaceEvent(event.getPlayer(), event.getBlock()); + + UtilServer.callEvent(placeEvent); + + if (placeEvent.isCancelled()) + { + return; + } + UtilInv.remove(event.getPlayer(), Material.LAPIS_BLOCK, (byte) 0, 1); final Block block = event.getBlock(); From 205e3885b8396b53fab38ae676a77b1ffe6ecf72 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 16:14:56 +0000 Subject: [PATCH 105/122] disallow players on pvp timer to use bows --- .../game/clans/clans/pvptimer/PvpTimer.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java index 6e9150c54..b8cbfadce 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityShootBowEvent; import org.bukkit.event.player.PlayerJoinEvent; import mineplex.core.MiniClientPlugin; @@ -75,6 +76,23 @@ public class PvpTimer extends MiniClientPlugin }, caller, "PvpTimer.Skipped"); } + @EventHandler + public void fireBow(EntityShootBowEvent event) + { + if (!(event.getEntity() instanceof Player)) + { + return; + } + + if (hasTimer((Player) event.getEntity())) + { + UtilPlayer.message(event.getEntity(), F.main("Clans", "You may not fire bows while on a PvP timer.")); + UtilPlayer.message(event.getEntity(), C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, type " + C.cGreen + "/pvp" + C.cGold + "."); + + event.setCancelled(true); + } + } + @EventHandler public void outYouGo(UpdateEvent event) { @@ -94,14 +112,7 @@ public class PvpTimer extends MiniClientPlugin UtilPlayer.message(player, " "); UtilPlayer.message(player, C.cDRedB + ">>" + C.cRed + " You are not permitted to enter the Borderlands while under PvP Safety."); - - new JsonMessage(C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, click ") - .extra("here") - .color("yellow") - .click(ClickEvent.RUN_COMMAND, "/pvptimer yesiconfirmthatiwouldliketodisablemypvptimerforever") - .extra(".") - .color("gray") - .sendToPlayer(player); + UtilPlayer.message(player, C.cGoldB + "> " + C.cGold + "To permanently disable PvP Safety, type " + C.cGreen + "/pvp" + C.cGold + "."); UtilPlayer.message(player, " "); } From deb22fd4e74175e4b945f48af21595dcb0289920 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 16:54:07 +0000 Subject: [PATCH 106/122] add 'time till despawn' hologram on outposts and the owner clan of the outpopsts above doors --- .../clans/clans/siege/outpost/Outpost.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 263c3349b..b42d959f9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -44,6 +44,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; @@ -100,6 +101,8 @@ public class Outpost implements Listener private List _nameHolograms; + private Hologram _lifetimeLeft; + public Outpost(OutpostManager outpostManager, OutpostToken token) { _outpostManager = outpostManager; @@ -127,6 +130,8 @@ public class Outpost implements Listener _preHologram = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); _preHologram2 = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); + _lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME))); + if (token.OutpostState == OutpostState.AWAITING) { _preHologram.start(); @@ -151,6 +156,8 @@ public class Outpost implements Listener _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); _nameHolograms.forEach(Hologram::start); + + _lifetimeLeft.start(); } } @@ -175,6 +182,7 @@ public class Outpost implements Listener _timeSpawned = System.currentTimeMillis(); _core = _type.getCoreLocation(_origin); + _nameHolograms = new ArrayList<>(); _preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); _preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); @@ -194,10 +202,12 @@ public class Outpost implements Listener UtilServer.registerEvents(this); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); + _lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME))); + + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); } private void cleanup() @@ -394,6 +404,11 @@ public class Outpost implements Listener return; } + if (_lifetimeLeft != null) + { + _lifetimeLeft.setText("Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME - (System.currentTimeMillis() - _timeSpawned)))); + } + if (_state == OutpostState.CONSTRUCTING) { if (_buildQueue.isEmpty()) @@ -479,6 +494,8 @@ public class Outpost implements Listener _preHologram = null; _preHologram = null; + _lifetimeLeft.start(); + _state = OutpostState.CONSTRUCTING; _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _ownerClan.Clans)); @@ -556,6 +573,10 @@ public class Outpost implements Listener cleanup(); }, wait.get() + 5L); + if (_lifetimeLeft != null) _lifetimeLeft.stop(); + + _lifetimeLeft = null; + _ownerClan.inform("Your Clan's Outpost has been destroyed.", null); } From 879a211a418d9250d06de3001a425ce8ea9290ac Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 17:00:14 +0000 Subject: [PATCH 107/122] change siege weapon damage indicator display length --- .../src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index a324c5114..92270185b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -204,7 +204,7 @@ public abstract class SiegeWeapon implements Listener removeHealth(health); - UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 5, 15, 5); + UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 0, 10, 0, player); } protected int getHandDamage(Player player) From 2956b18821f589a9d9ded43036cc2f54a79c78e0 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 18:45:04 +0000 Subject: [PATCH 108/122] some hologram work --- .../mineplex/core/common/util/UtilEnt.java | 26 +++--- .../src/mineplex/core/hologram/Hologram.java | 2 +- .../clans/clans/siege/outpost/Outpost.java | 79 +++++++++++++++++-- 3 files changed, 88 insertions(+), 19 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java index 90f176359..d64a11370 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilEnt.java @@ -163,7 +163,7 @@ public class UtilEnt if (entity instanceof CraftCreature) { - EntityCreature creature = ((CraftCreature)entity).getHandle(); + EntityCreature creature = ((CraftCreature) entity).getHandle(); if (_bsRestrictionGoal == null) { @@ -176,26 +176,26 @@ public class UtilEnt if (((CraftEntity)entity).getHandle() instanceof EntityInsentient) { - EntityInsentient creature = (EntityInsentient)((CraftEntity)entity).getHandle(); + EntityInsentient creature = (EntityInsentient) ((CraftEntity) entity).getHandle(); creature.setVegetated(true); creature.setSilent(mute); - ((List) _pathfinderBList.get(((PathfinderGoalSelector)_goalSelector.get(creature)))).clear(); - ((List)_pathfinderCList.get(((PathfinderGoalSelector)_goalSelector.get(creature)))).clear(); + ((List) _pathfinderBList.get(((PathfinderGoalSelector) _goalSelector.get(creature)))).clear(); + ((List) _pathfinderCList.get(((PathfinderGoalSelector) _goalSelector.get(creature)))).clear(); - ((List)_pathfinderBList.get(((PathfinderGoalSelector)_targetSelector.get(creature)))).clear(); - ((List)_pathfinderCList.get(((PathfinderGoalSelector)_targetSelector.get(creature)))).clear(); + ((List) _pathfinderBList.get(((PathfinderGoalSelector) _targetSelector.get(creature)))).clear(); + ((List) _pathfinderCList.get(((PathfinderGoalSelector) _targetSelector.get(creature)))).clear(); } if (((CraftEntity)entity).getHandle() instanceof EntityBat) { - ((EntityBat)((CraftEntity)entity).getHandle()).setVegetated(true); + ((EntityBat) ((CraftEntity) entity).getHandle()).setVegetated(true); } - if (((CraftEntity)entity).getHandle() instanceof EntityEnderDragon) + if (((CraftEntity) entity).getHandle() instanceof EntityEnderDragon) { - EntityEnderDragon creature = (EntityEnderDragon)((CraftEntity)entity).getHandle(); + EntityEnderDragon creature = (EntityEnderDragon) ((CraftEntity) entity).getHandle(); creature.setVegetated(true); } @@ -442,7 +442,7 @@ public class UtilEnt if (offset < dR) { - ents.put(ent, 1 - (offset/dR)); + ents.put(ent, Double.valueOf(1 - (offset/dR))); continue; } @@ -451,7 +451,7 @@ public class UtilEnt if (offset < dR) { - ents.put(ent, 1 - (offset/dR)); + ents.put(ent, Double.valueOf(1 - (offset/dR))); continue; } } @@ -473,7 +473,7 @@ public class UtilEnt if (offset < dR) { - ents.put(cur, 1 - (offset/dR)); + ents.put(cur, Double.valueOf(1 - (offset/dR))); continue; } } @@ -778,7 +778,7 @@ public class UtilEnt field.setAccessible(true); int entityId = field.getInt(null); if (modifynumber) { - field.set(null, entityId+1); + field.set(null, Integer.valueOf(entityId + 1)); } return entityId; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java index a569b9612..682a697ff 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/hologram/Hologram.java @@ -257,7 +257,7 @@ public class Hologram for (int i = _entityIds.size(); i < _hologramText.length; i++) { - _entityIds.add(UtilEnt.getNewEntityId()); + _entityIds.add(Integer.valueOf(UtilEnt.getNewEntityId())); } } else diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index b42d959f9..42244fb36 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -11,6 +11,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -18,6 +19,8 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.inventory.ClickType; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; @@ -46,6 +49,7 @@ import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramInteraction; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; @@ -57,6 +61,7 @@ import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock; import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; +import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity; public class Outpost implements Listener { @@ -131,6 +136,28 @@ public class Outpost implements Listener _preHologram2 = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); _lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME))); + _lifetimeLeft.setInteraction(new HologramInteraction() + { + public void onClick(Player player, ClickType clickType) + { + if (_ownerClan.isMember(player)) + { + return; + } + + if (_state != OutpostState.LIVE) + { + return; + } + + if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) + { + kill(); + } + } + + }); + if (token.OutpostState == OutpostState.AWAITING) { @@ -150,11 +177,11 @@ public class Outpost implements Listener if (token.OutpostState == OutpostState.CONSTRUCTING || token.OutpostState == OutpostState.LIVE) { - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1), C.cGreen + _ownerClan.getName())); - + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.forEach(Hologram::start); _lifetimeLeft.start(); @@ -203,6 +230,26 @@ public class Outpost implements Listener UtilServer.registerEvents(this); _lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME))); + _lifetimeLeft.setInteraction(new HologramInteraction() + { + public void onClick(Player player, ClickType clickType) + { + if (_ownerClan.isMember(player)) + { + return; + } + + if (_state != OutpostState.LIVE) + { + return; + } + + if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) + { + kill(); + } + } + }); _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); @@ -332,6 +379,28 @@ public class Outpost implements Listener return; } + if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); + + _core.getBlock().setType(Material.AIR); + + _ownerClan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); + + if (getState() == OutpostState.AWAITING) + { + cleanup(); + } + else + { + kill(); + } + + event.setCancelled(true); + return; + } + if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks in Outposts.")); From d65bf965c402636363b69772f2e2668253934304 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 18:51:34 +0000 Subject: [PATCH 109/122] fix only some blocks of outpost being reset and explosion particles not showing up --- .../mineplex/game/clans/clans/siege/outpost/Outpost.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 42244fb36..20a2938c1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -548,7 +548,7 @@ public class Outpost implements Listener .filter(player -> !_ownerClan.isMember(player)) .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) .forEach(player -> { - UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .65, true, 0.8, 0, 1.1, true); + UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .77, true, 0.8, 0, 1.1, true); UtilPlayer.message(player, F.main("Clans", "This Outpost is still under construction!")); player.playSound(player.getLocation(), Sound.NOTE_BASS, 1.0f, 1.0f); }); @@ -613,13 +613,13 @@ public class Outpost implements Listener _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean() && UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(13).forEach(block -> _outpostManager.runSyncLater(() -> { - UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX); + UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX); _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); }, wait.add(4 + UtilMath.random.nextInt(4)).get()) ); _outpostManager.runSyncLater(() -> { - _blocks.values().stream().filter(block -> Math.random() > 0.66).forEach(block -> { + _blocks.values().stream().forEach(block -> { Material mat = Material.getMaterial(block.getId()); if (UtilItem.isTranslucent(mat)) From d524645ddd9b76579cf019992f1297a467fb4e2b Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Tue, 23 Feb 2016 19:11:29 +0000 Subject: [PATCH 110/122] placed the clan name hologram thingy correctly because it's inside the outpost!!! --- .../clans/clans/siege/outpost/Outpost.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 20a2938c1..99834cdf2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -177,10 +177,10 @@ public class Outpost implements Listener if (token.OutpostState == OutpostState.CONSTRUCTING || token.OutpostState == OutpostState.LIVE) { - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); _nameHolograms.forEach(Hologram::start); @@ -251,10 +251,10 @@ public class Outpost implements Listener } }); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(1, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); - _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 1).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add((_type._size / 2) + 1, 2, 0).add(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract((_type._size / 2) + 1, -2, 0).subtract(2, 0, 0).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0, 2, (_type._size / 2) + 1).add(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); + _nameHolograms.add(new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().subtract(0, -2, (_type._size / 2) + 1).subtract(0, 0, 2).add(.5, 0, .5), C.cGreen + _ownerClan.getName())); } private void cleanup() @@ -617,7 +617,11 @@ public class Outpost implements Listener _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f); }, wait.add(4 + UtilMath.random.nextInt(4)).get()) ); - + + _outpostManager.runSyncLater(() -> { + _blocks.values().stream().forEach(OutpostBlock::restore); + }, wait.get() + 5L); + _outpostManager.runSyncLater(() -> { _blocks.values().stream().forEach(block -> { Material mat = Material.getMaterial(block.getId()); @@ -640,7 +644,7 @@ public class Outpost implements Listener }); cleanup(); - }, wait.get() + 5L); + }, wait.get() + 6L); if (_lifetimeLeft != null) _lifetimeLeft.stop(); From 73d8870daf896652a4f363b267302e8b64ee1fbb Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 2 Mar 2016 19:42:53 +0000 Subject: [PATCH 111/122] nether work (forgot to commit days ago oops) --- .../src/mineplex/core/common/util/C.java | 2 + .../src/mineplex/core/common/util/F.java | 5 + .../mineplex/core/common/util/UtilAlg.java | 39 +-- .../core/common/util/UtilCollections.java | 139 ++++++++++ .../mineplex/core/common/util/UtilFile.java | 54 ++++ .../src/mineplex/core/MiniPlugin.java | 3 +- .../src/mineplex/core/task/TaskManager.java | 2 +- .../mineplex/game/clans/clans/ClanTips.java | 5 + .../game/clans/clans/ClansDisplay.java | 45 ++-- .../game/clans/clans/ClansManager.java | 18 ++ .../game/clans/clans/ClansUtility.java | 208 +++++++------- .../src/mineplex/game/clans/clans/Test.java | 21 +- .../clans/clans/commands/ClansCommand.java | 253 ++++++++++-------- .../clans/clans/gui/button/ClanButton.java | 2 +- .../clans/gui/button/ClanTerritoryButton.java | 8 + .../clans/clans/gui/page/ClanMainPage.java | 2 +- .../clans/clans/nether/NetherManager.java | 195 ++++++++++++++ .../game/clans/clans/nether/Portal.java | 112 ++++++++ .../game/clans/clans/pvptimer/PvpTimer.java | 12 +- .../clans/clans/regions/ClansRegions.java | 2 +- .../elements/ScoreboardElementPlayer.java | 6 + .../game/clans/clans/siege/SiegeManager.java | 19 +- .../clans/siege/outpost/OutpostManager.java | 8 + .../game/clans/gameplay/Gameplay.java | 5 + .../Mineplex.Game.Clans/src/test/Test.java | 25 ++ 25 files changed, 910 insertions(+), 280 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java create mode 100644 Plugins/Mineplex.Game.Clans/src/test/Test.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/C.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/C.java index bab76df51..cbaa6ea16 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/C.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/C.java @@ -75,6 +75,8 @@ public class C public static String chatAdminHead = "" + ChatColor.DARK_PURPLE; public static String chatAdminBody = "" + ChatColor.LIGHT_PURPLE; + public static String cClansNether = "" + ChatColor.RED; + public static String listTitle = "" + ChatColor.WHITE; public static String listValue = "" + ChatColor.YELLOW; public static String listValueOn = "" + ChatColor.GREEN; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java index 998b57d7c..2c06ace26 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/F.java @@ -215,4 +215,9 @@ public class F ? "an" : "a"; } + public static String clansNether(String word) + { + return C.cClansNether + word + C.mBody; + } + } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index 978ff1812..ef41e9450 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -218,7 +218,7 @@ public class UtilAlg return cross(vec, getRight(vec)); } - public static Location getAverageLocation(ArrayList locs) + public static Location getAverageLocation(List locs) { if (locs.isEmpty()) return null; @@ -236,8 +236,27 @@ public class UtilAlg return vec.toLocation(locs.get(0).getWorld()); } + + public static Location getAverageBlockLocation(List locs) + { + if (locs.isEmpty()) + return null; + + Vector vec = new Vector(0,0,0); + double amount = 0; + + for (Block loc : locs) + { + vec.add(loc.getLocation().toVector()); + amount++; + } + + vec.multiply(1d/amount); + + return vec.toLocation(locs.get(0).getWorld()); + } - public static Vector getAverageBump(Location source, ArrayList locs) + public static Vector getAverageBump(Location source, List locs) { if (locs.isEmpty()) return null; @@ -543,20 +562,4 @@ public class UtilAlg return new Location(location.getWorld(), x, location.getY(), z, location.getYaw(), location.getPitch()); } - - public static Location moveForward(Location location, double strength, float yaw, float pitch, boolean reverse) - { - double x = location.getX(); - double y = location.getY(); - double z = location.getZ(); - - double yawAngle = Math.toRadians(yaw); - double pitchAngle = Math.toRadians(pitch); - - x = reverse ? (x + strength * Math.sin(yawAngle)) : (x - strength * Math.sin(yawAngle)); - y = reverse ? (y + strength * Math.sin(pitchAngle)) : (y - strength * Math.sin(pitchAngle)); - z = reverse ? (z - strength * Math.cos(yawAngle)) : (z + strength * Math.cos(yawAngle)); - - return new Location(location.getWorld(), x, y, z); - } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java index b88a66880..f6f7543bc 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java @@ -1,7 +1,13 @@ package mineplex.core.common.util; +import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.function.Consumer; +import java.util.function.Function; + +import org.bukkit.Location; +import org.bukkit.block.Block; public class UtilCollections { @@ -26,6 +32,45 @@ public class UtilCollections return new NautHashMap(); } + public static T getLast(List list) + { + return list.isEmpty() ? null : list.get(list.size() - 1); + } + + public static T getFirst(List list) + { + return list.isEmpty() ? null : list.get(0); + } + + public static T getLast(NautArrayList list) + { + return list.isEmpty() ? null : list.get(list.size() - 1); + } + + public static T getFirst(NautArrayList list) + { + return list.isEmpty() ? null : list.get(0); + } + + public static void forEach(E[] elements, Function filter, Consumer consumer) + { + for (int i = 0; i < elements.length; i++) + { + consumer.accept(filter.apply(elements[i])); + } + } + + public static void forEachFilter(E[] elements, Function filter, Consumer consumer) + { + for (int i = 0; i < elements.length; i++) + { + if (filter.apply(elements[i]).booleanValue()) + { + consumer.accept(elements[i]); + } + } + } + public static void forEach(E[] elements, Consumer consumer) { for (int i = 0; i < elements.length; i++) @@ -38,6 +83,11 @@ public class UtilCollections { forEach(elements, collection::add); } + + public static void addAll(E[] elements, Function filter, Collection collection) + { + forEachFilter(elements, filter, collection::add); + } public static void loop(int min, int max, Consumer consumer) { @@ -47,4 +97,93 @@ public class UtilCollections } } + public static byte[] ensureSize(byte[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static boolean[] ensureSize(boolean[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static int[] ensureSize(int[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static long[] ensureSize(long[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static short[] ensureSize(short[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static char[] ensureSize(char[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static float[] ensureSize(float[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static double[] ensureSize(double[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } + + public static Object[] ensureSize(Object[] array, int size) + { + if (array.length <= size) + { + return array; + } + + return Arrays.copyOf(array, size); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java new file mode 100644 index 000000000..1a02a7110 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilFile.java @@ -0,0 +1,54 @@ +package mineplex.core.common.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +public class UtilFile +{ + public static String read(File file) + { + try + { + return new String(readBytes(file)); + } + catch (IOException e) + { + return null; + } + } + + /** + * @param file + * @return + * @throws IOException + */ + public static byte[] readBytes(File file) throws IOException + { + FileInputStream stream = new FileInputStream(file); + + byte[] bytes = new byte[stream.available() /* estimated bytes available */]; + + int pointer = 0; + while (true) + { + int read = stream.read(); + + if (read == -1) + { + break; + } + + bytes = UtilCollections.ensureSize(bytes, bytes.length + 1); + + bytes[pointer] = (byte) read; + + ++pointer; + } + + stream.close(); + + return bytes; + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java index 732c13816..863ec5462 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/MiniPlugin.java @@ -1,5 +1,6 @@ package mineplex.core; +import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; @@ -100,7 +101,7 @@ public abstract class MiniPlugin implements Listener public void log(String message) { - System.out.println(F.main(_moduleName, message)); + Bukkit.getConsoleSender().sendMessage(F.main(_moduleName, message)); } public void runAsync(Runnable runnable) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java b/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java index 85608613e..0427cb53e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/task/TaskManager.java @@ -118,7 +118,7 @@ public class TaskManager extends MiniDbClientPlugin { public void run(Boolean success) { - if (!success) + if (!success.booleanValue()) { System.out.println("Add task FAILED for " + player.getName()); 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 cc941f8fa..4f2c6e166 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 @@ -224,6 +224,11 @@ public class ClanTips extends MiniPlugin 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." }), + ENTER_NETHER( + new String[] { + C.cDAqua + "The Nether", + C.cAqua + "Welcome to the Nether. This is a very scary place full of fire and is a place for people to battle to the death! TODO: Write something better about the nether here" + }), ; // this is only LinkedList because UtilPlayer.message wants it diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java index 46f5a3708..284264f3b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java @@ -24,13 +24,13 @@ import mineplex.game.clans.core.repository.ClanTerritory; public class ClansDisplay extends MiniPlugin { - private ClansManager Clans; + private ClansManager _clansManager; public ClansDisplay(JavaPlugin plugin, ClansManager clans) { super("Clans Display", plugin); - Clans = clans; + _clansManager = clans; } @EventHandler @@ -46,7 +46,7 @@ public class ClansDisplay extends MiniPlugin { if (player.getWorld().getEnvironment() != Environment.NORMAL) return; - ClientClan client = Clans.Get(player); + ClientClan client = _clansManager.Get(player); if (client == null) return; // Same Chunk @@ -56,16 +56,16 @@ public class ClansDisplay extends MiniPlugin client.setTerritory(UtilWorld.chunkToStr(player.getLocation().getChunk())); // AutoClaim - if (client.isAutoClaim()) Clans.getClanAdmin().claim(player); + if (client.isAutoClaim()) _clansManager.getClanAdmin().claim(player); // Map String owner = "Wilderness"; - ClanInfo ownerClan = Clans.getClanUtility().getOwner(player.getLocation()); + ClanInfo ownerClan = _clansManager.getClanUtility().getOwner(player.getLocation()); if (ownerClan != null) owner = ownerClan.getName(); - boolean safe = Clans.getClanUtility().isSafe(player); + boolean safe = _clansManager.getClanUtility().isSafe(player); - PlayerEnterTerritoryEvent event = new PlayerEnterTerritoryEvent(player, client.getOwner(), owner, owner.equals("Wilderness") ? false : Clans.getClanUtility().getClaim(player.getLocation()).isSafe(player.getLocation()), true); + PlayerEnterTerritoryEvent event = new PlayerEnterTerritoryEvent(player, client.getOwner(), owner, owner.equals("Wilderness") ? false : _clansManager.getClanUtility().getClaim(player.getLocation()).isSafe(player.getLocation()), true); UtilServer.getServer().getPluginManager().callEvent(event); @@ -105,19 +105,26 @@ public class ClansDisplay extends MiniPlugin // Name String ownerString = C.xWilderness + "Wilderness"; - ClanTerritory claim = Clans.getClanUtility().getClaim(player.getLocation()); + ClanTerritory claim = _clansManager.getClanUtility().getClaim(player.getLocation()); if (claim != null) { // Relation - ClanRelation relation = Clans.getClanUtility().relPT(player, claim.Chunk); + ClanRelation relation = _clansManager.getClanUtility().relPT(player, claim.Chunk); // Name - ownerString = Clans.getClanUtility().mRel(relation, claim.Owner, false); + ownerString = _clansManager.getClanUtility().mRel(relation, claim.Owner, false); // Trust if (relation == ClanRelation.ALLY_TRUST) ownerString += " " + C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")"; } + if (_clansManager.getNetherManager().isInNether(player)) + { + _clansManager.message(player, "You are not allowed to claim territory in " + F.clansNether("The Nether") + "."); + + ownerString = C.cRed + "The Nether"; + } + UtilTextMiddle.display("", ownerString, 0, 25, 10, player); UtilPlayer.message(player, F.main("Territory", ownerString)); } @@ -137,7 +144,7 @@ public class ClansDisplay extends MiniPlugin if (player.getItemInHand().getType() == Material.MAP) { - ClanInfo clan = Clans.getClanUtility().getClanByPlayer(player); + ClanInfo clan = _clansManager.getClanUtility().getClanByPlayer(player); if (clan != null) if (clan.getHome() != null) home = mLocalMap(player, clan.getHome().getChunk(), false); } @@ -177,14 +184,14 @@ public class ClansDisplay extends MiniPlugin } // Get Data - ClanInfo curOwner = Clans.getClanUtility().getOwner(UtilWorld.chunkToStr(curChunk)); - ClanTerritory curClaim = Clans.getClanUtility().getClaim(UtilWorld.chunkToStr(curChunk)); + ClanInfo curOwner = _clansManager.getClanUtility().getOwner(UtilWorld.chunkToStr(curChunk)); + ClanTerritory curClaim = _clansManager.getClanUtility().getClaim(UtilWorld.chunkToStr(curChunk)); // Add Icon if (i == chunk.getX() && j == chunk.getZ()) - output += getMapIcon(Clans.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, true, local); + output += getMapIcon(_clansManager.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, true, local); else - output += getMapIcon(Clans.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, false, local); + output += getMapIcon(_clansManager.getClanUtility().relPC(player, curOwner), curClaim, curOwner, curChunk, pCount, false, local); } output += ">"; @@ -236,7 +243,7 @@ public class ClansDisplay extends MiniPlugin { if (players > 0) return "" + C.xSelf + players; - else if (Clans.getClanUtility().isChunkHome(owner, chunk)) + else if (_clansManager.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xSelf + "H"; else return "" + C.xSelf + "#"; @@ -246,7 +253,7 @@ public class ClansDisplay extends MiniPlugin { if (players > 0) return "" + C.xAlly + players; - else if (Clans.getClanUtility().isChunkHome(owner, chunk)) + else if (_clansManager.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xAlly + "H"; else return "" + C.xAlly + "#"; @@ -256,7 +263,7 @@ public class ClansDisplay extends MiniPlugin { if (players > 0) return "" + C.xdAlly + players; - else if (Clans.getClanUtility().isChunkHome(owner, chunk)) + else if (_clansManager.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xdAlly + "H"; else return "" + C.xdAlly + "#"; @@ -264,7 +271,7 @@ public class ClansDisplay extends MiniPlugin if (players > 0) return "" + C.xEnemy + players; - else if (Clans.getClanUtility().isChunkHome(owner, chunk)) + else if (_clansManager.getClanUtility().isChunkHome(owner, chunk)) return "" + C.xEnemy + "H"; else return "" + C.xEnemy + "#"; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index ff4aa3648..fdd9d2293 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -84,6 +84,7 @@ import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; import mineplex.game.clans.clans.gui.ClanShop; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; +import mineplex.game.clans.clans.nether.NetherManager; import mineplex.game.clans.clans.observer.ObserverManager; import mineplex.game.clans.clans.playtime.Playtime; import mineplex.game.clans.clans.potato.PotatoManager; @@ -162,6 +163,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati private GearManager _gearManager; private LootManager _lootManager; private DonationManager _donationManager; + private NetherManager _netherManager; private Playtime _playTracker; @@ -384,6 +386,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); new SiegeManager(this); + _netherManager = new NetherManager(this); } @Override @@ -1180,4 +1183,19 @@ public class ClansManager extends MiniClientPluginimplements IRelati { return _clanDataAccess.getRepository().getServerId(); } + + public NetherManager getNetherManager() + { + return _netherManager; + } + + public void message(Player player, String message) + { + UtilPlayer.message(player, F.main("Clans", message)); + } + + public boolean masterBypass(Player player) + { + return player.getName().equals("NewGarbo"); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java index a57f0470e..33cabdc98 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansUtility.java @@ -28,11 +28,11 @@ import mineplex.game.clans.spawn.Spawn; public class ClansUtility { - private ClansManager Clans; + private ClansManager _clansManager; public ClansUtility(ClansManager clans) { - Clans = clans; + _clansManager = clans; } public enum ClanRelation @@ -115,7 +115,7 @@ public class ClansUtility // CLAN LinkedList clanMatchList = new LinkedList(); - for (ClanInfo cur : Clans.getClanMap().values()) + for (ClanInfo cur : _clansManager.getClanMap().values()) { if (cur.getName().equalsIgnoreCase(name)) return cur; @@ -135,7 +135,7 @@ public class ClansUtility // PLAYER LinkedList playerMatchList = new LinkedList(); - for (ClanInfo clanInfo : Clans.getClanMap().values()) + for (ClanInfo clanInfo : _clansManager.getClanMap().values()) { for (ClansPlayer player : clanInfo.getMembers().values()) { @@ -158,10 +158,10 @@ public class ClansUtility if (inform) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + (clanMatchList.size() + playerMatchList.size()) + C.mBody + " matches for [" + C.mElem + name + C.mBody + "].")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + (clanMatchList.size() + playerMatchList.size()) + C.mBody + " matches for [" + C.mElem + name + C.mBody + "].")); - Clans.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Clan", clanMatchString)); - Clans.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Player", playerMatchString)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Clan", clanMatchString)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.desc("Matches via Player", playerMatchString)); } return null; @@ -171,7 +171,7 @@ public class ClansUtility { LinkedList matchList = new LinkedList(); - for (ClanInfo cur : Clans.getClanMap().values()) + for (ClanInfo cur : _clansManager.getClanMap().values()) { if (cur.getName().equalsIgnoreCase(name)) return cur; @@ -184,7 +184,7 @@ public class ClansUtility if (!inform) return null; // Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + matchList.size() + C.mBody + " matches for [" + C.mElem + name + C.mBody + "].")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mCount + matchList.size() + C.mBody + " matches for [" + C.mElem + name + C.mBody + "].")); if (matchList.size() > 0) { @@ -192,7 +192,7 @@ public class ClansUtility for (ClanInfo cur : matchList) matchString += cur.getName() + " "; - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mBody + " Matches [" + C.mElem + matchString + C.mBody + "].")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clan Search", "" + C.mBody + " Matches [" + C.mElem + matchString + C.mBody + "].")); } return null; @@ -203,12 +203,12 @@ public class ClansUtility public ClanInfo getClanByClanName(String clan) { - return Clans.getClan(clan); + return _clansManager.getClan(clan); } public ClanInfo getClanById(int id) { - for (ClanInfo clan : Clans.getClanMap().values()) + for (ClanInfo clan : _clansManager.getClanMap().values()) { if (clan.getId() == id) { @@ -226,7 +226,7 @@ public class ClansUtility public ClanInfo getClanByUUID(UUID uuid) { - return Clans.getClanMemberUuidMap().get(uuid); + return _clansManager.getClanMemberUuidMap().get(uuid); } // @Deprecated @@ -252,16 +252,16 @@ public class ClansUtility public boolean isSafe(Player player) { - if (!UtilTime.elapsed(Clans.getCombatManager().Get(player).GetLastDamaged(), Spawn.COMBAT_TAG_DURATION)) return false; + if (!UtilTime.elapsed(_clansManager.getCombatManager().Get(player).GetLastDamaged(), Spawn.COMBAT_TAG_DURATION)) return false; return isSafe(player.getLocation()); } public boolean isSafe(Location loc) { - if (!Clans.getClaimMap().containsKey(UtilWorld.chunkToStr(loc.getChunk()))) return false; + if (!_clansManager.getClaimMap().containsKey(UtilWorld.chunkToStr(loc.getChunk()))) return false; - return Clans.getClaimMap().get(UtilWorld.chunkToStr(loc.getChunk())).isSafe(loc); + return _clansManager.getClaimMap().get(UtilWorld.chunkToStr(loc.getChunk())).isSafe(loc); } public boolean isChunkHome(ClanInfo clan, Chunk chunk) @@ -276,7 +276,7 @@ public class ClansUtility public ClanTerritory getClaim(Chunk chunk) { String chunkTag = UtilWorld.chunkToStr(chunk); - return Clans.getClaimMap().get(chunkTag); + return _clansManager.getClaimMap().get(chunkTag); } /** @@ -294,7 +294,7 @@ public class ClansUtility public ClanTerritory getClaim(String chunk) { - return Clans.getClaimMap().get(chunk); + return _clansManager.getClaimMap().get(chunk); } public ClanInfo getOwner(String chunk) @@ -361,7 +361,7 @@ public class ClansUtility { String chunk = UtilWorld.chunkToStr(loc.getChunk()); - return Clans.getClaimMap().containsKey(chunk); + return _clansManager.getClaimMap().containsKey(chunk); } // public boolean isAlliance(String player, Location loc) @@ -378,7 +378,7 @@ public class ClansUtility public boolean isSelf(Player player, Location loc) { - ClanInfo clan = Clans.getClan(player); + ClanInfo clan = _clansManager.getClan(player); if (clan == null) return false; @@ -408,9 +408,9 @@ public class ClansUtility ClanInfo owner = getOwner(loc); ClanInfo clan = getClanByPlayer(player); - String mimic = Clans.Get(player).getMimic(); + String mimic = _clansManager.Get(player).getMimic(); - if (mimic.length() != 0) clan = Clans.getClanUtility().searchClanPlayer(player, mimic, false); + if (mimic.length() != 0) clan = _clansManager.getClanUtility().searchClanPlayer(player, mimic, false); if (owner == null) return ClanRelation.SELF; @@ -566,38 +566,38 @@ public class ClansUtility public void join(final Player caller, final ClanInfo clanInfo) { - if (Clans.getClanMemberUuidMap().containsKey(caller.getUniqueId())) + if (_clansManager.getClanMemberUuidMap().containsKey(caller.getUniqueId())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan.")); return; } - if (!Clans.Get(caller).canJoin()) + if (!_clansManager.Get(caller).canJoin()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Clans.Get(caller).getDelay(), 1, UtilTime.TimeUnit.FIT) + C.mBody + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - _clansManager.Get(caller).getDelay(), 1, UtilTime.TimeUnit.FIT) + C.mBody + ".")); return; } if (clanInfo == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error: Clan does not exist")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error: Clan does not exist")); return; } if (!clanInfo.isInvited(caller.getName())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clanInfo.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clanInfo.getName()) + ".")); return; } if (clanInfo.getSize() >= clanInfo.getMaxSize()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clanInfo.getName()) + " is full and cannot be joined!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clanInfo.getName()) + " is full and cannot be joined!")); return; } // Task - Clans.getClanDataAccess().join(clanInfo, caller, ClanRole.RECRUIT, new Callback() + _clansManager.getClanDataAccess().join(clanInfo, caller, ClanRole.RECRUIT, new Callback() { @Override public void run(Boolean data) @@ -605,12 +605,12 @@ public class ClansUtility if (data) { // Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clanInfo.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clanInfo.getName()) + ".")); clanInfo.inform(F.name(caller.getName()) + " has joined your Clan.", caller.getName()); } else { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request")); } } }); @@ -623,13 +623,13 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (clan.getMembers().get(caller.getUniqueId()).getRole() == ClanRole.LEADER && clan.getMembers().size() > 1) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving.")); return; } @@ -637,13 +637,13 @@ public class ClansUtility if (clan.getMembers().size() > 1) { // Task - Clans.getClanDataAccess().leave(clan, caller, new Callback() + _clansManager.getClanDataAccess().leave(clan, caller, new Callback() { @Override public void run(Boolean data) { // Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + ".")); clan.inform(F.name(caller.getName()) + " has left your Clan.", null); clan.left(caller.getName()); @@ -662,13 +662,13 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (getRole(caller) != ClanRole.LEADER) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can disband the Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can disband the Clan.")); return; } @@ -681,21 +681,21 @@ public class ClansUtility return; } - Clans.messageClan(clan, C.cYellow + caller.getName() + C.cGray + " has disbanded the Clan."); + _clansManager.messageClan(clan, C.cYellow + caller.getName() + C.cGray + " has disbanded the Clan."); // Task - Clans.getClanDataAccess().delete(clan, new Callback() + _clansManager.getClanDataAccess().delete(clan, new Callback() { @Override public void run(Boolean data) { - if (!data) + if (!data.booleanValue()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request. Try again later")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request. Try again later")); } else { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You disbanded your Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You disbanded your Clan.")); } } }); @@ -714,28 +714,28 @@ public class ClansUtility { return false; } - + if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return false; } if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can claim Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can claim Territory.")); return false; } if (!ClansManager.isClaimable(caller.getLocation())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim territory at this location!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim territory at this location!")); return false; } if (clan.getEnergy() == 0) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must purchase energy at a shop before you can claim land.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must purchase energy at a shop before you can claim land.")); return false; } @@ -751,14 +751,14 @@ public class ClansUtility } else { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is owned by " + mRel(Clans.getClanUtility().relPC(caller, ownerClan), ownerClan.getName(), true) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is owned by " + mRel(_clansManager.getClanUtility().relPC(caller, ownerClan), ownerClan.getName(), true) + ".")); return false; } } if (clan.getClaims() >= clan.getClaimsMax()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan cannot claim more Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan cannot claim more Territory.")); return false; } @@ -784,8 +784,8 @@ public class ClansUtility if (checkBox(caller.getWorld().getChunkAt(caller.getLocation().getChunk().getX() + x, caller.getLocation().getChunk().getZ() + z), 3)) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box.")); - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed.")); return false; } @@ -795,7 +795,7 @@ public class ClansUtility } else if (rel(clan, adjClan) != ClanRelation.SELF) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim Territory next to " + mRel(rel(ownerClan, adjClan), adjClan.getName(), true) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim Territory next to " + mRel(rel(ownerClan, adjClan), adjClan.getName(), true) + ".")); return false; } } @@ -804,36 +804,36 @@ public class ClansUtility // Boxed if (checkBox(caller.getLocation().getChunk(), 4)) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box.")); - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim this Territory, it causes a box.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This means a Territory has all sides claimed.")); return false; } if (isNearAdminClaim(caller.getLocation())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim so close to administrative territory!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim so close to administrative territory!")); return false; } // Not Next to Self if (!selfAdj && !clan.getClaimSet().isEmpty()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must claim next to your other Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must claim next to your other Territory.")); return false; } // Claim Timer - if (Clans.getUnclaimMap().containsKey(chunk)) + if (_clansManager.getUnclaimMap().containsKey(chunk)) { - if (!UtilTime.elapsed(Clans.getUnclaimMap().get(chunk), Clans.getReclaimTime())) + if (!UtilTime.elapsed(_clansManager.getUnclaimMap().get(chunk).longValue(), _clansManager.getReclaimTime())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory cannot be claimed for " + F.time(UtilTime.convertString(Clans.getReclaimTime() - (System.currentTimeMillis() - Clans.getUnclaimMap().get(chunk)), 1, UtilTime.TimeUnit.FIT)) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory cannot be claimed for " + F.time(UtilTime.convertString(_clansManager.getReclaimTime() - (System.currentTimeMillis() - _clansManager.getUnclaimMap().get(chunk).longValue()), 1, UtilTime.TimeUnit.FIT)) + ".")); return false; } else { - Clans.getUnclaimMap().remove(chunk); + _clansManager.getUnclaimMap().remove(chunk); } } @@ -842,7 +842,7 @@ public class ClansUtility { if (UtilMath.offset(cur, caller) < 16) if (playerEnemy(caller, cur)) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim while enemies are nearby.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot claim while enemies are nearby.")); return false; } } @@ -861,10 +861,10 @@ public class ClansUtility } // Task - Clans.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false); + _clansManager.getClanDataAccess().claim(clan.getName(), chunk, caller.getName(), false); // Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".")); clan.inform(F.name(caller.getName()) + " claimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName()); return true; @@ -895,19 +895,19 @@ public class ClansUtility public boolean unclaimSteal(Player caller, ClanInfo clientClan, ClanInfo ownerClan) { - if (!Clans.canUnclaimChunk(clientClan, ownerClan)) + if (!_clansManager.canUnclaimChunk(clientClan, ownerClan)) { return false; } // Change Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!")); // Inform UtilServer.broadcast(F.main("Clans", F.elem(clientClan.getName()) + " unclaimed from " + F.elem(ownerClan.getName()) + " at " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + ".")); // Unclaim - Clans.getClanDataAccess().unclaim(UtilWorld.chunkToStr(caller.getLocation().getChunk()), caller.getName(), true); + _clansManager.getClanDataAccess().unclaim(UtilWorld.chunkToStr(caller.getLocation().getChunk()), caller.getName(), true); return true; } @@ -918,7 +918,7 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } @@ -929,13 +929,13 @@ public class ClansUtility if (target.equals(caller.getName())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot promote yourself.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot promote yourself.")); return; } if (self.getRole().ordinal() <= target.getRole().ordinal()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + ".")); return; } @@ -943,21 +943,21 @@ public class ClansUtility String newRank = "?"; if (target.getRole() == ClanRole.RECRUIT) { - Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER); + _clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER); newRank = "Member"; } else if (target.getRole() == ClanRole.MEMBER) { - Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.ADMIN); + _clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.ADMIN); newRank = "Admin"; } else if (target.getRole() == ClanRole.ADMIN) { - Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.LEADER); + _clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.LEADER); newRank = "Leader"; // Give Leader - Clans.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.ADMIN); + _clansManager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.ADMIN); } // Inform @@ -970,7 +970,7 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } @@ -981,19 +981,19 @@ public class ClansUtility if (target.equals(caller.getName())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote yourself.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote yourself.")); return; } if (self.getRole().ordinal() <= target.getRole().ordinal()) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + ".")); return; } if (target.getRole() == ClanRole.RECRUIT) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote " + F.name(other) + " any further.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot demote " + F.name(other) + " any further.")); return; } @@ -1001,12 +1001,12 @@ public class ClansUtility String newRank = "?"; if (target.getRole() == ClanRole.MEMBER) { - Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.RECRUIT); + _clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.RECRUIT); newRank = "Recruit"; } else if (target.getRole() == ClanRole.ADMIN) { - Clans.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER); + _clansManager.getClanDataAccess().role(clan, target.getUuid(), ClanRole.MEMBER); newRank = "Member"; } @@ -1020,7 +1020,7 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } @@ -1031,20 +1031,20 @@ public class ClansUtility if (self.getRole() != ClanRole.LEADER && self.getRole() != ClanRole.ADMIN) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can kick members.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can kick members.")); return; } if (clansPlayer.getRole() == ClanRole.LEADER) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan leaders cannot be kicked.")); - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "To disband a clan, use /c disband")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan leaders cannot be kicked.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "To disband a clan, use /c disband")); return; } if ((clansPlayer.getRole() == ClanRole.LEADER && self.getRole() == ClanRole.ADMIN) || (clansPlayer.getRole() == ClanRole.ADMIN && self.getRole() == ClanRole.ADMIN)) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You do not outrank " + F.name(other) + ".")); return; } @@ -1056,17 +1056,17 @@ public class ClansUtility public void run(Boolean data) { // Inform - if (player != null) Clans.getTutorials().sendTutorialMsg(player, F.main("Clans", F.name(caller.getName()) + " kicked you from " + F.elem("Clan " + clan.getName()) + ".")); - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You kicked " + F.name(other) + " from your Clan.")); + if (player != null) _clansManager.getTutorials().sendTutorialMsg(player, F.main("Clans", F.name(caller.getName()) + " kicked you from " + F.elem("Clan " + clan.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You kicked " + F.name(other) + " from your Clan.")); clan.inform(F.main("Clans", F.name(caller.getName()) + " kicked " + F.name(other) + " from your Clan."), caller.getName()); } }; // Task if (player != null) - Clans.getClanDataAccess().leave(clan, player, callback); + _clansManager.getClanDataAccess().leave(clan, player, callback); else - Clans.getClanDataAccess().leave(clan, clansPlayer, callback); + _clansManager.getClanDataAccess().leave(clan, clansPlayer, callback); } public boolean unclaim(final Player caller, final Chunk c) @@ -1075,7 +1075,7 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return false; } @@ -1088,14 +1088,14 @@ public class ClansUtility // Role if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can unclaim Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can unclaim Territory.")); return false; } // Not Claimed if (ownerClan == null || !ownerClan.equals(clan)) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is not owned by you.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This Territory is not owned by you.")); return false; } @@ -1110,10 +1110,10 @@ public class ClansUtility } // Task - Clans.getClanDataAccess().unclaim(chunk, caller.getName(), true); + _clansManager.getClanDataAccess().unclaim(chunk, caller.getName(), true); // Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".")); clan.inform(F.name(caller.getName()) + " unclaimed Territory " + F.elem(UtilWorld.chunkToStrClean(caller.getLocation().getChunk())) + ".", caller.getName()); return true; @@ -1125,13 +1125,13 @@ public class ClansUtility if (clan == null) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return false; } if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can unclaim all Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader can unclaim all Territory.")); return false; } @@ -1145,11 +1145,11 @@ public class ClansUtility for (String chunk : toUnclaim) { - Clans.getClanDataAccess().unclaim(chunk, caller.getName(), true); + _clansManager.getClanDataAccess().unclaim(chunk, caller.getName(), true); } // Inform - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed all your Clans Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You unclaimed all your Clans Territory.")); clan.inform(F.name(caller.getName()) + " unclaimed all your Clans Territory.", caller.getName()); return true; @@ -1159,24 +1159,24 @@ public class ClansUtility { if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can send invites.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can send invites.")); return; } if (target.getName().equals(caller.getName())) { - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot invite yourself.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot invite yourself.")); return; } // Inform clan.inform(F.name(caller.getName()) + " invited " + F.name(target.getName()) + " to join your Clan.", caller.getName()); - Clans.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You invited " + F.name(target.getName()) + " to join your Clan.")); - Clans.getTutorials().sendTutorialMsg(target, F.main("Clans", F.name(caller.getName()) + " invited you to join " + F.elem("Clan " + clan.getName()) + ".")); - Clans.getTutorials().sendTutorialMsg(target, F.main("Clans", "Type " + F.elem("/c join " + clan.getName()) + " to accept!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You invited " + F.name(target.getName()) + " to join your Clan.")); + _clansManager.getTutorials().sendTutorialMsg(target, F.main("Clans", F.name(caller.getName()) + " invited you to join " + F.elem("Clan " + clan.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(target, F.main("Clans", "Type " + F.elem("/c join " + clan.getName()) + " to accept!")); // Task - Clans.getClanDataAccess().invite(clan, target.getName(), caller.getName()); + _clansManager.getClanDataAccess().invite(clan, target.getName(), caller.getName()); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java index 46daab300..8b3dde1d7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java @@ -1,23 +1,16 @@ package mineplex.game.clans.clans; -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; import java.io.IOException; -public class Test { +import org.bukkit.Location; + +import mineplex.core.common.util.UtilWorld; + +public class Test +{ public static void main(String[] args) throws IOException { - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(stream); - - dos.writeByte(91); - dos.flush(); - stream.flush(); - - System.out.println(new String(stream.toByteArray())); - - dos.close(); - stream.close(); + System.out.println(UtilWorld.locToStr(new Location(null, 30, 30, 30))); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index ee20486a9..176320170 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -43,12 +43,12 @@ import net.minecraft.server.v1_8_R3.EnumDirection; public class ClansCommand extends CommandBase { - private ClansManager _manager; + private ClansManager _clansManager; public ClansCommand(ClansManager plugin) { super(plugin, Rank.ALL, "c", "clan", "clans", "factions"); - _manager = plugin; + _clansManager = plugin; } @Override @@ -56,7 +56,7 @@ public class ClansCommand extends CommandBase { if (args == null || args.length == 0) { - _manager.getClanShop().attemptShopOpen(caller); + _clansManager.getClanShop().attemptShopOpen(caller); return; } @@ -140,7 +140,7 @@ public class ClansCommand extends CommandBase { if (!Plugin.getClientManager().hasRank(caller, Rank.ADMIN) && !caller.getUniqueId().toString().equals("d8646a35-33a8-43c6-9e7c-2e871a6b86c9") /* My UUID (NewGarbo) */) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This requires ADMIN+ permission.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This requires ADMIN+ permission.")); return; } @@ -150,18 +150,18 @@ public class ClansCommand extends CommandBase if (clan != null) { - _manager.getClanUtility().join(caller, clan); - _manager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER); - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have successfully joined " + F.elem(clan.getName()) + " and are now Leader Role.")); + _clansManager.getClanUtility().join(caller, clan); + _clansManager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have successfully joined " + F.elem(clan.getName()) + " and are now Leader Role.")); } else { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan provided does not exist.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan provided does not exist.")); } } else { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No clan provided.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No clan provided.")); } } @@ -170,7 +170,7 @@ public class ClansCommand extends CommandBase if (args.length == 0) { Plugin.Get(caller).setClanChat(!Plugin.Get(caller).isClanChat()); - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan Chat: " + F.oo(Plugin.Get(caller).isClanChat()))); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan Chat: " + F.oo(Plugin.Get(caller).isClanChat()))); return; } @@ -179,7 +179,7 @@ public class ClansCommand extends CommandBase { ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); if (clan == null) - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); else Plugin.chatClan(clan, caller, F.combine(args, 0, null, false)); } @@ -190,7 +190,7 @@ public class ClansCommand extends CommandBase if (args.length == 0) { Plugin.Get(caller).setAllyChat(!Plugin.Get(caller).isAllyChat()); - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Ally Chat: " + F.oo(Plugin.Get(caller).isAllyChat()))); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Ally Chat: " + F.oo(Plugin.Get(caller).isAllyChat()))); return; } @@ -199,7 +199,7 @@ public class ClansCommand extends CommandBase { ClanInfo clan = Plugin.getClanUtility().getClanByPlayer(caller); if (clan == null) - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); else Plugin.chatAlly(clan, caller, F.combine(args, 0, null, false)); } @@ -215,32 +215,32 @@ public class ClansCommand extends CommandBase return; } - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Commands List;")); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c create ", "Create new Clan", Rank.ALL)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c join ", "Join a Clan", Rank.ALL)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c leave ", "Leave your Clan", Rank.ALL)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c map ", "View Clan Map", Rank.ALL)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/cc (Message)", "Clan Chat (Toggle)", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Commands List;")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c create ", "Create new Clan", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c join ", "Join a Clan", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c leave ", "Leave your Clan", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c map ", "View Clan Map", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/cc (Message)", "Clan Chat (Toggle)", Rank.ALL)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c stuck", "Teleports you to the nearest Wilderness location", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c stuck", "Teleports you to the nearest Wilderness location", Rank.ALL)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c promote ", "Promote Player in Clan", Rank.MODERATOR)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c demote ", "Demote Player in Clan", Rank.MODERATOR)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c promote ", "Promote Player in Clan", Rank.MODERATOR)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c demote ", "Demote Player in Clan", Rank.MODERATOR)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c home (set)", "Teleport to Clan Home", Rank.MODERATOR)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c home (set)", "Teleport to Clan Home", Rank.MODERATOR)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c invite ", "Invite Player to Clan", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c kick ", "Kick Player from Clan", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c neutral ", "Request Neutrality with Clan", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c enemy ", "Declare ClanWar with Clan", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c ally ", "Send Alliance to Clan", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c trust ", "Give Trust to Clan", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c claim", "Claim Territory", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c unclaim (all)", "Unclaim Territory", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c invite ", "Invite Player to Clan", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c kick ", "Kick Player from Clan", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c neutral ", "Request Neutrality with Clan", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c enemy ", "Declare ClanWar with Clan", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c ally ", "Send Alliance to Clan", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c trust ", "Give Trust to Clan", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c claim", "Claim Territory", Rank.ADMIN)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c unclaim (all)", "Unclaim Territory", Rank.ADMIN)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c delete", "Delete your Clan", Rank.OWNER)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c delete", "Delete your Clan", Rank.OWNER)); - _manager.getTutorials().sendTutorialMsg(caller, F.help("/c ", "View Clan Information", Rank.ALL)); + _clansManager.getTutorials().sendTutorialMsg(caller, F.help("/c ", "View Clan Information", Rank.ALL)); } public void create(final Player caller, final String[] args) @@ -251,13 +251,13 @@ public class ClansCommand extends CommandBase if (Plugin.getClanMemberUuidMap().containsKey(caller.getUniqueId())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan.")); return; } if (Plugin.leftRecently(caller.getUniqueId(), 5 * 60 * 1000) != null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot create a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot create a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + ".")); return; } @@ -270,37 +270,37 @@ public class ClansCommand extends CommandBase if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name.")); return; } if (!UtilInput.valid(args[1])) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name.")); return; } if (args[1].length() < Plugin.getNameMin()) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too short. Minimum length is " + (Plugin.getNameMin()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too short. Minimum length is " + (Plugin.getNameMin()) + ".")); return; } if (args[1].length() > Plugin.getNameMax()) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too long. Maximum length is " + (Plugin.getNameMax()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name too long. Maximum length is " + (Plugin.getNameMax()) + ".")); return; } if (Plugin.getChat().getFilteredMessage(caller, args[1]).contains("*")) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name inappropriate. Please try a different name")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name inappropriate. Please try a different name")); return; } if (!ClansBlacklist.isValidClanName(args[1])) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is blacklisted! Please try a different name.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is blacklisted! Please try a different name.")); return; } @@ -311,7 +311,7 @@ public class ClansCommand extends CommandBase { if (clanExists) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is already in use by another Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan name is already in use by another Clan.")); } else { @@ -323,11 +323,11 @@ public class ClansCommand extends CommandBase if (data == null) { // Hopefully shouldn't happen! - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error creating the clan. Please try again")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error creating the clan. Please try again")); } else { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You created Clan " + C.cYellow + data.getName() + C.cGray + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You created Clan " + C.cYellow + data.getName() + C.cGray + ".")); } } }); @@ -347,13 +347,13 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input an invitee.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input an invitee.")); return; } @@ -365,13 +365,20 @@ public class ClansCommand extends CommandBase public void stuck(final Player caller) { + if (_clansManager.getNetherManager().isInNether(caller)) + { + _clansManager.message(caller, "You are not allowed to free yourself in " + F.clansNether("The Nether") + "."); + + return; + } + ClanTerritory territory = Plugin.getClanUtility().getClaim(caller.getLocation()); String clanName = Plugin.getClanUtility().getClanByPlayer(caller) == null ? null : Plugin.getClanUtility().getClanByPlayer(caller).getName(); if (territory == null || territory.Safe || territory.Owner.equals(clanName)) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must be in another Clan's territory to use this.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must be in another Clan's territory to use this.")); return; } @@ -384,14 +391,14 @@ public class ClansCommand extends CommandBase if (loc == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error whilst finding location to teleport to.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Error whilst finding location to teleport to.")); return; } player.getPlayer().teleport(loc); // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to the Wilderness.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to the Wilderness.")); } }, new Callback() { public void run(DelayedTaskClient client) @@ -444,31 +451,31 @@ public class ClansCommand extends CommandBase { if (Plugin.getClanMemberUuidMap().containsKey(caller.getUniqueId())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already in a Clan.")); return; } if (Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000) != null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.MakeStr(Plugin.leftRecently(caller.getUniqueId(), 20 * 60 * 1000).getRight()) + C.mBody + ".")); return; } if (!Plugin.Get(caller).canJoin()) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Plugin.Get(caller).getDelay(), 1, TimeUnit.FIT) + C.mBody + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot join a Clan for " + C.mTime + UtilTime.convertString(System.currentTimeMillis() - Plugin.Get(caller).getDelay(), 1, TimeUnit.FIT) + C.mBody + ".")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan name.")); return; } if (!UtilInput.valid(args[1])) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Invalid characters in Clan name.")); return; } @@ -477,13 +484,13 @@ public class ClansCommand extends CommandBase if (!clan.isInvited(caller.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clan.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not invited to " + F.elem("Clan " + clan.getName()) + ".")); return; } if (clan.getSize() >= clan.getMaxSize()) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clan.getName()) + " is full and cannot be joined!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "The clan " + F.elem("Clan " + clan.getName()) + " is full and cannot be joined!")); return; } @@ -500,12 +507,12 @@ public class ClansCommand extends CommandBase if (data) { // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You joined " + F.elem("Clan " + clan.getName()) + ".")); clan.inform(F.name(caller.getName()) + " has joined your Clan.", caller.getName()); } else { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "There was an error processing your request")); } } }); @@ -518,13 +525,13 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (clan.getMembers().get(caller.getUniqueId()).getRole() == ClanRole.LEADER && clan.getMembers().size() > 1) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must pass on " + F.elem("Leadership") + " before leaving.")); return; } @@ -538,7 +545,7 @@ public class ClansCommand extends CommandBase public void run(Boolean data) { // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You left " + F.elem("Clan " + clan.getName()) + ".")); clan.inform(F.name(caller.getName()) + " has left your Clan.", null); } }); @@ -555,19 +562,19 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Player to kick.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Player to kick.")); return; } final String target = UtilPlayer.searchCollection(caller, args[1], clan.getMemberNameSet(), "Clan Member", true); - _manager.getClanUtility().kick(caller, target); + _clansManager.getClanUtility().kick(caller, target); } public void promote(Player caller, String[] args) @@ -576,19 +583,19 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to promote.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to promote.")); return; } final String targetName = UtilPlayer.searchCollection(caller, args[1], clan.getMemberNameSet(), "Clan Member", true); - _manager.getClanUtility().promote(caller, targetName); + _clansManager.getClanUtility().promote(caller, targetName); } public void demote(Player caller, String[] args) @@ -597,19 +604,19 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to demote.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input player to demote.")); return; } final String targetName = UtilPlayer.searchCollection(caller, args[1], clan.getMemberNameSet(), "Clan Member", true); - _manager.getClanUtility().demote(caller, targetName); + _clansManager.getClanUtility().demote(caller, targetName); } public void ally(Player caller, String[] args) @@ -618,19 +625,19 @@ public class ClansCommand extends CommandBase if (cA == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Alliances.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Alliances.")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to ally.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to ally.")); return; } @@ -640,31 +647,31 @@ public class ClansCommand extends CommandBase if (cA.isSelf(cB.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot ally with yourself.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot ally with yourself.")); return; } if (cA.isAlly(cB.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already allies with Clan" + F.elem(cB.getName())) + "."); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already allies with Clan" + F.elem(cB.getName())) + "."); return; } if (cA.getAllies() >= cA.getAlliesMax()) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot have any more allies.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You cannot have any more allies.")); return; } if (cB.getAllies() >= cB.getAlliesMax()) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan " + F.elem(cB.getName()) + " cannot have any more allies.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Clan " + F.elem(cB.getName()) + " cannot have any more allies.")); return; } if (!Recharge.Instance.usable(caller, "AllyReq" + cB.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Please do not spam alliance requests.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Please do not spam alliance requests.")); return; } @@ -674,7 +681,7 @@ public class ClansCommand extends CommandBase Plugin.getClanDataAccess().ally(cA, cB, caller.getName()); // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You accepted alliance with Clan " + F.elem(cB.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You accepted alliance with Clan " + F.elem(cB.getName()) + ".")); cA.inform(F.name(caller.getName()) + " accepted alliance with Clan " + F.elem(cB.getName()) + ".", caller.getName()); cB.inform("Clan " + F.elem(cA.getName()) + " has accepted alliance with you.", null); } @@ -684,7 +691,7 @@ public class ClansCommand extends CommandBase Plugin.getClanDataAccess().requestAlly(cA, cB, caller.getName()); // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You requested alliance with Clan " + F.elem(cB.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You requested alliance with Clan " + F.elem(cB.getName()) + ".")); cA.inform(F.name(caller.getName()) + " has requested alliance with Clan " + F.elem(cB.getName()) + ".", caller.getName()); cB.inform("Clan " + F.elem(cA.getName()) + " has requested alliance with you.", null); @@ -747,19 +754,19 @@ public class ClansCommand extends CommandBase if (cA == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && cA.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage relationships.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage relationships.")); return; } if (args.length < 2) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to set neutrality with.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a Clan to set neutrality with.")); return; } @@ -769,11 +776,11 @@ public class ClansCommand extends CommandBase if (cB.isSelf(cA.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You prefer to think of yourself positively...")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You prefer to think of yourself positively...")); } else if (cB.isNeutral(cA.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already neutral with " + F.elem("Clan " + cB.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are already neutral with " + F.elem("Clan " + cB.getName()) + ".")); } else if (cB.isAlly(cA.getName())) { @@ -781,7 +788,7 @@ public class ClansCommand extends CommandBase Plugin.getClanDataAccess().neutral(cA, cB, caller.getName(), true); // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You revoked alliance with " + F.elem("Clan " + cB.getName()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You revoked alliance with " + F.elem("Clan " + cB.getName()) + ".")); cA.inform(F.name(caller.getName()) + " revoked alliance with " + F.elem("Clan " + cB.getName()) + ".", caller.getName()); cB.inform(F.elem("Clan " + cA.getName()) + " has revoked alliance with you.", null); } @@ -797,11 +804,25 @@ public class ClansCommand extends CommandBase return; } + if (_clansManager.getNetherManager().isInNether(caller)) + { + _clansManager.message(caller, "You are not allowed to claim territory in " + F.clansNether("The Nether") + "."); + + return; + } + Plugin.getClanUtility().claim(caller); } public void unclaim(Player caller, String[] args) { + if (_clansManager.getNetherManager().isInNether(caller)) + { + _clansManager.message(caller, "You are not allowed to unclaim territory in " + F.clansNether("The Nether") + "."); + + return; + } + if (args.length > 1) { if (args[1].equalsIgnoreCase("all") || args[1].equalsIgnoreCase("a")) @@ -816,13 +837,13 @@ public class ClansCommand extends CommandBase public boolean unclaimSteal(Player caller, ClanInfo clientClan, ClanInfo ownerClan) { - if (!_manager.canUnclaimChunk(clientClan, ownerClan)) + if (!_clansManager.canUnclaimChunk(clientClan, ownerClan)) { return false; } // Change Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You can no longer 'steal' territory. " + "You simply unclaim it and it can not be reclaimed by anyone for 30 mintes." + "This was done to improve gameplay. Enjoy!")); // Inform UtilServer.broadcast(F.main("Clans", F.elem(clientClan.getName()) + " unclaimed from " + F.elem(ownerClan.getName()) + " at " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + ".")); @@ -858,19 +879,19 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } if (clan.getHome() == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has not set a Home")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has not set a Home")); return; } if (!clan.getClaimSet().contains(UtilWorld.chunkToStr(clan.getHome().getChunk()))) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has lost its Home Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan has lost its Home Territory.")); return; } @@ -878,7 +899,7 @@ public class ClansCommand extends CommandBase if (!(home.getBlock().getType().equals(Material.BED_BLOCK) && home.add(0, 1, 0).getBlock().getType().equals(Material.AIR)) && home.add(0, 2, 0).getBlock().getType().equals(Material.AIR)) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan's bed has been destroyed, or is obstructed.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Your Clan's bed has been destroyed, or is obstructed.")); return; } @@ -904,7 +925,7 @@ public class ClansCommand extends CommandBase Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You teleported to your Clan Home " + UtilWorld.locToStrClean(caller.getLocation()) + ".")); } }, new Callback() { public void run(DelayedTaskClient client) @@ -934,31 +955,38 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + return; + } + + if (_clansManager.getNetherManager().isInNether(caller)) + { + _clansManager.message(caller, "You are not allowed to set your Clan Home in " + F.clansNether("The Nether") + "."); + return; } if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Clan Home.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "Only the Clan Leader and Admins can manage Clan Home.")); return; } if (Plugin.getClanUtility().getOwner(caller.getLocation()) == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory.")); return; } if (!Plugin.getClanUtility().getOwner(caller.getLocation()).isSelf(clan.getName())) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You must set your Clan Home in your own Territory.")); return; } if (!(caller.getLocation().add(0, 1, 0).getBlock().getType().equals(Material.AIR) && caller.getLocation().add(0, 2, 0).getBlock().getType().equals(Material.AIR))) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed.")); return; } @@ -967,7 +995,7 @@ public class ClansCommand extends CommandBase if (!bedPlaced) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "This is not a suitable place for a bed.")); return; } @@ -983,7 +1011,7 @@ public class ClansCommand extends CommandBase Plugin.ClanTips.displayTip(TipType.SETHOME, caller); // Inform - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You set Clan Home to " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + ".")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You set Clan Home to " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + ".")); clan.inform(caller.getName() + " set Clan Home to " + F.elem(UtilWorld.locToStrClean(caller.getLocation())) + ".", caller.getName()); } @@ -993,7 +1021,7 @@ public class ClansCommand extends CommandBase if (search == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter.")); return; } @@ -1008,20 +1036,20 @@ public class ClansCommand extends CommandBase ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true); if (clan == null) return; - _manager.getClanShop().openClanWho(caller, clan); + _clansManager.getClanShop().openClanWho(caller, clan); } public void forceJoinClan(Player caller, String search) { - if (_manager.getClientManager().hasRank(caller, Rank.ADMIN)) + if (_clansManager.getClientManager().hasRank(caller, Rank.ADMIN)) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No no no, this command is not for you ;-)")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "No no no, this command is not for you ;-)")); return; } if (search == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You did not input a search parameter.")); return; } @@ -1036,8 +1064,8 @@ public class ClansCommand extends CommandBase ClanInfo clan = Plugin.getClanUtility().searchClanPlayer(caller, search, true); if (clan == null) return; - _manager.getClanUtility().join(caller, clan); - _manager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER); + _clansManager.getClanUtility().join(caller, clan); + _clansManager.getClanDataAccess().role(clan, caller.getUniqueId(), ClanRole.LEADER); } @@ -1050,7 +1078,7 @@ public class ClansCommand extends CommandBase if (clan == null) { - _manager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); + _clansManager.getTutorials().sendTutorialMsg(caller, F.main("Clans", "You are not in a Clan.")); return; } } @@ -1060,6 +1088,13 @@ public class ClansCommand extends CommandBase if (clan == null) return; - _manager.getTutorials().sendTutorialMsg(caller, clan.mTerritory()); + if (_clansManager.getNetherManager().isInNether(caller)) + { + _clansManager.message(caller, "You are currently in " + F.clansNether("The Nether") + "."); + + return; + } + + _clansManager.getTutorials().sendTutorialMsg(caller, clan.mTerritory()); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanButton.java index 1abdda431..055a4eed2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanButton.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanButton.java @@ -12,7 +12,7 @@ import mineplex.game.clans.clans.gui.ClanShop; public abstract class ClanButton implements IButton { private ClanShop _shop; - private ClansManager _clansManager; + protected ClansManager _clansManager; private Player _player; private ClanInfo _clanInfo; private ClanRole _clanRole; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java index b718a5132..a18156e4c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.common.util.UtilWorld; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanRole; @@ -22,6 +23,13 @@ public class ClanTerritoryButton extends ClanButton @Override public void onClick(Player player, ClickType clickType) { + if (_clansManager.getNetherManager().isInNether(player)) + { + _clansManager.message(player, "You are not allowed to do anything with Territory while in " + F.clansNether("The Nether") + "."); + player.closeInventory(); + return; + } + if (clickType == ClickType.LEFT) { player.closeInventory(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanMainPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanMainPage.java index e9738de3f..f85de461b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanMainPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/page/ClanMainPage.java @@ -44,7 +44,7 @@ public class ClanMainPage extends ClanPageBase public ClanMainPage(ClansManager plugin, ClanShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) { super(plugin, shop, clientManager, donationManager, "Manage Clan", player, 54); - + buildPage(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java new file mode 100644 index 000000000..f3bffa07a --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java @@ -0,0 +1,195 @@ +package mineplex.game.clans.clans.nether; + +import java.io.File; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.WorldBorder; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerPortalEvent; +import org.bukkit.inventory.ItemStack; + +import com.google.common.collect.Lists; + +import mineplex.core.MiniPlugin; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilFile; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.common.util.UtilWorld; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClanTips.TipType; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.core.repository.ClanTerritory; + +public class NetherManager extends MiniPlugin +{ + private ClansManager _clansManager; + + private World _netherWorld; + + private List _portals = Lists.newArrayList(); + + private File _portalCfg; + + public NetherManager(ClansManager clansManager) + { + super("Nether Manager", clansManager.getPlugin()); + _clansManager = clansManager; + + _portalCfg = new File(UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "nether.cfg"); + + begin(); + } + + public void begin() + { + _netherWorld = Bukkit.getWorld("world_nether"); + + WorldBorder worldBorder = _netherWorld.getWorldBorder(); + worldBorder.setCenter(0, 0); + worldBorder.setSize(200 * 2); + + parsePortals(); + } + + private void parsePortals() + { + String data = UtilFile.read(_portalCfg); + + if (data.length() < 5) + { + return; + } + + UtilCollections.forEach(data.split("\n"), string -> string.trim(), sPortal -> { + + String[] destinations = sPortal.split(">>"); + + Location from = UtilWorld.strToLoc(destinations[0]); + Location to = UtilWorld.strToLoc(destinations[1].split(":")[0]); + + Portal portal = Portal.create(from, to, UtilWorld.strToLoc(to.getWorld().getName() + "," + destinations[1].split(":")[1])); + + if (portal == null) + { + log("FAILED TO LOAD PORTAL [" + sPortal + "]"); + } + else + { + _portals.add(portal); + } + }); + } + + @EventHandler + public void breakBlock(BlockBreakEvent event) + { + Block block = event.getBlock(); + Player player = event.getPlayer(); + ItemStack item = player.getItemInHand(); + + if (!block.getWorld().equals(_netherWorld)) + { + return; + } + + if (player.getGameMode() == GameMode.CREATIVE) + { + return; + } + + if (!item.getType().equals(Material.GOLD_PICKAXE)) + { + UtilPlayer.message(player, F.main("Clans", "You can only break blocks in the Nether with a " + F.elem("Golden Pickaxe") + ".")); + event.setCancelled(true); + return; + } + + if (block.getType().equals(Material.OBSIDIAN) || block.getType().equals(Material.PORTAL)) + { + UtilPlayer.message(player, F.main("Clans", "You are not allowed to break this block.")); + event.setCancelled(true); + return; + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() == UpdateType.SEC_08) + { + _portals.forEach(portal -> { + portal.getFromObsidianBlocks().forEach(block -> block.setType(Material.OBSIDIAN)); + portal.getFromPortalBlocks().forEach(block -> block.setType(Material.PORTAL)); + + portal.getToObsidianBlocks().forEach(block -> block.setType(Material.OBSIDIAN)); + portal.getToPortalBlocks().forEach(block -> block.setType(Material.PORTAL)); + }); + } + } + + @EventHandler + public void onPortal(PlayerPortalEvent event) + { + Player player = event.getPlayer(); + Location location = player.getLocation(); + + ClanTerritory territory = _clansManager.getClanUtility().getClaim(location); + + event.setCancelled(true); + + if (territory != null && territory.Owner.equals("Borderlands")) + { + if (event.getTo().getWorld().equals(_netherWorld)) + { + _portals + .stream() + .filter(portal -> + portal.getToPortalBlocks() + .stream() + .filter(block -> player.getLocation().distance(block.getLocation()) <= 2) + .iterator().hasNext() + ).limit(1) + .forEach(portal -> { + player.teleport(portal.getToOut()); + _clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player); + }); + } + else + { + _portals + .stream() + .filter(portal -> + portal.getFromPortalBlocks() + .stream() + .filter(block -> player.getLocation().distance(block.getLocation()) <= 2) + .iterator().hasNext() + ).limit(1) + .forEach(portal -> { + player.teleport(UtilAlg.getAverageBlockLocation(portal.getToPortalBlocks())); + }); + } + } + } + + public World getNetherWorld() + { + return _netherWorld; + } + + public boolean isInNether(Player player) + { + return player.getWorld().equals(_netherWorld); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java new file mode 100644 index 000000000..ba3396aee --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java @@ -0,0 +1,112 @@ +package mineplex.game.clans.clans.nether; + +import java.util.List; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +import com.google.common.collect.Lists; + +import mineplex.core.common.util.UtilBlock; + +public class Portal +{ + private List _fromPortalBlocks; + private List _fromObsidianBlocks; + + private List _toPortalBlocks; + private List _toObsidianBlocks; + + private Location _toOut; + + public final boolean Success; + + public Portal(Location from, Location to, Location toOut) + { + _fromPortalBlocks = Lists.newArrayList(); + _fromObsidianBlocks = Lists.newArrayList(); + + _toPortalBlocks = Lists.newArrayList(); + _toObsidianBlocks = Lists.newArrayList(); + + _toOut = toOut; + + if (!isValidPortalBlock(from.getBlock()) || !isValidPortalBlock(to.getBlock())) + { + System.out.println("[PORTAL] INVALID PORTAL PROVIDED (" + from + " --> " + to + ")"); + + Success = false; + + return; + } + + for (Block other : UtilBlock.getInRadius(from, 7.5d).keySet()) + { + if (other.getType() == Material.OBSIDIAN) + { + _fromObsidianBlocks.add(other); + } + else if (other.getType() == Material.PORTAL) + { + _fromPortalBlocks.add(other); + } + } + + for (Block other : UtilBlock.getInRadius(to, 7.5d).keySet()) + { + if (other.getType() == Material.OBSIDIAN) + { + _toObsidianBlocks.add(other); + } + else if (other.getType() == Material.PORTAL) + { + _toPortalBlocks.add(other); + } + } + + Success = true; + } + + public Location getToOut() + { + return _toOut; + } + + public List getFromPortalBlocks() + { + return _fromPortalBlocks; + } + + public List getFromObsidianBlocks() + { + return _fromObsidianBlocks; + } + + public List getToPortalBlocks() + { + return _toPortalBlocks; + } + + public List getToObsidianBlocks() + { + return _toObsidianBlocks; + } + + private boolean isValidPortalBlock(Block block) + { + return block.getType() == Material.OBSIDIAN || block.getType() == Material.PORTAL; + } + + public static Portal create(Location from, Location to, Location toOut) + { + Portal portal = new Portal(from, to, toOut); + + if (!portal.Success) + { + return null; + } + + return portal; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java index b8cbfadce..a814a1439 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/pvptimer/PvpTimer.java @@ -66,14 +66,10 @@ public class PvpTimer extends MiniClientPlugin public void disableFor(final Player caller) { - TaskManager.Instance.completedTask(new Callback() { - @Override - public void run(Boolean data) - { - Get(caller).Skipped = true; - caller.playSound(caller.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f); - } - }, caller, "PvpTimer.Skipped"); + Get(caller).Skipped = true; + caller.playSound(caller.getLocation(), Sound.ENDERDRAGON_GROWL, 1f, 0.75f); + + TaskManager.Instance.completedTask(null, caller, "PvpTimer.Skipped"); } @EventHandler diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java index bb80a711e..f79aba758 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/regions/ClansRegions.java @@ -137,7 +137,7 @@ public class ClansRegions extends MiniPlugin * @param claimOffset - the initial offset in claim (creating a 'hole' with chunk offset radius) * @param safe - whether the chunk claimed is considered a 'safe' (pvp-free) region. */ - private void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, final boolean addNegative, final Location... locations) + public void claimArea(final String clanName, final int chunkRadius, final int claimOffset, final boolean safe, final boolean addNegative, final Location... locations) { final ClanInfo clan = _manager.getClan(clanName); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java index d0d710721..ec93dc660 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java @@ -44,6 +44,12 @@ public class ScoreboardElementPlayer implements ScoreboardElement regionString += C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")"; } + + if (_clansManager.getNetherManager().isInNether(player)) + { + regionString = C.cRed + "The Nether"; + } + output.add(regionString); return output; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 95b8733e7..03b8d45b2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -10,6 +10,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import com.google.gson.Gson; import mineplex.core.MiniPlugin; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilInv; @@ -17,10 +18,8 @@ import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies; -import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.repository.SiegeWeaponRepository; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; @@ -45,7 +44,7 @@ public class SiegeManager extends MiniPlugin public SiegeManager(ClansManager clans) { - super("Siege", clans.getPlugin()); + super("Siege Manager", clans.getPlugin()); _gson = new Gson(); @@ -171,6 +170,13 @@ public class SiegeManager extends MiniPlugin public boolean trySpawnCannon(Player player, Location location) { + if (_clansManager.getNetherManager().isInNether(player)) + { + _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); + + return false; + } + if (!_clansManager.isInClan(player)) { UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Cannon.")); @@ -199,6 +205,13 @@ public class SiegeManager extends MiniPlugin public boolean trySpawnCatapult(Player player, Location location) { + if (_clansManager.getNetherManager().isInNether(player)) + { + _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); + + return false; + } + if (!_clansManager.isInClan(player)) { UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Catapult.")); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index ceb0f4c36..e600554c1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -18,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; +import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilAlg; @@ -79,6 +80,13 @@ public class OutpostManager extends MiniPlugin public boolean spawnOutpost(Player player, Location location, OutpostType type) { + if (_clansManager.getNetherManager().isInNether(player)) + { + _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); + + return false; + } + if (!_clansManager.isInClan(player)) { UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place an Outpost.")); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 6235642cd..693d0b2ff 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -246,6 +246,11 @@ public class Gameplay extends MiniPlugin @EventHandler(priority = EventPriority.LOWEST) public void ObsidianCancel(BlockPlaceEvent event) { + if (_clansManager.masterBypass(event.getPlayer())) + { + return; + } + if (event.getBlock().getType() == Material.OBSIDIAN) { UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot place " + F.item("Obsidian") + ".")); diff --git a/Plugins/Mineplex.Game.Clans/src/test/Test.java b/Plugins/Mineplex.Game.Clans/src/test/Test.java new file mode 100644 index 000000000..2ae94a373 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/test/Test.java @@ -0,0 +1,25 @@ +package test; + + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +public class Test { + public static void main(String[] args) throws IOException + { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(stream); + + dos.writeByte(91); + dos.flush(); + stream.flush(); + + System.out.println(new String(stream.toByteArray())); + + dos.close(); + stream.close(); + + + } +} From 7b9ff288f380e07de039aa49a0562abefdc0808d Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 3 Mar 2016 23:23:20 +0000 Subject: [PATCH 112/122] nether progresssisiannsnsssss --- .../mineplex/core/common/util/UtilBlock.java | 18 +++++ .../clans/clans/nether/NetherManager.java | 70 ++++++++++++------- .../game/clans/clans/nether/Portal.java | 15 +++- .../items/legendaries/EnergyCrossbow.java | 54 ++++++++++++++ .../items/legendaries/LegendaryItem.java | 2 +- 5 files changed, 129 insertions(+), 30 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index c6db06459..6593bd931 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -1439,4 +1439,22 @@ public class UtilBlock return gr.getBlock().getLocation(); } + + public static boolean setSilent(Block block, Material type) + { + return setSilent(block, type, (byte) 0); + } + + /** + * Sets block data without causing a block update. + */ + public static boolean setSilent(Block block, Material type, byte data) + { + BlockState state = block.getState(); + + state.setType(type); + state.setRawData(data); + + return state.update(false, false); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java index f3bffa07a..38470f58a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java @@ -12,15 +12,19 @@ import org.bukkit.WorldBorder; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.inventory.ItemStack; import com.google.common.collect.Lists; import mineplex.core.MiniPlugin; +import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilCollections; import mineplex.core.common.util.UtilFile; import mineplex.core.common.util.UtilPlayer; @@ -91,6 +95,22 @@ public class NetherManager extends MiniPlugin } }); } + + + @EventHandler + public void cmd(PlayerCommandPreprocessEvent event) + { + if (!_clansManager.getClientManager().hasRank(event.getPlayer(), Rank.JNR_DEV)) + { + return; + } + + if (event.getMessage().startsWith("/nether")) + { + event.getPlayer().teleport(new Location(_netherWorld, 0, 90, 0)); + event.setCancelled(true); + } + } @EventHandler public void breakBlock(BlockBreakEvent event) @@ -127,19 +147,19 @@ public class NetherManager extends MiniPlugin @EventHandler public void update(UpdateEvent event) { - if (event.getType() == UpdateType.SEC_08) + if (event.getType() == UpdateType.SLOW) { _portals.forEach(portal -> { - portal.getFromObsidianBlocks().forEach(block -> block.setType(Material.OBSIDIAN)); - portal.getFromPortalBlocks().forEach(block -> block.setType(Material.PORTAL)); + portal.getFromObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN)); + portal.getFromPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL)); - portal.getToObsidianBlocks().forEach(block -> block.setType(Material.OBSIDIAN)); - portal.getToPortalBlocks().forEach(block -> block.setType(Material.PORTAL)); + portal.getToObsidianBlocks().forEach(block -> UtilBlock.setSilent(block, Material.OBSIDIAN)); + portal.getToPortalBlocks().forEach(block -> UtilBlock.setSilent(block, Material.PORTAL)); }); } } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onPortal(PlayerPortalEvent event) { Player player = event.getPlayer(); @@ -147,26 +167,9 @@ public class NetherManager extends MiniPlugin ClanTerritory territory = _clansManager.getClanUtility().getClaim(location); - event.setCancelled(true); - - if (territory != null && territory.Owner.equals("Borderlands")) + if (event.getTo().getWorld().equals(_netherWorld)) { - if (event.getTo().getWorld().equals(_netherWorld)) - { - _portals - .stream() - .filter(portal -> - portal.getToPortalBlocks() - .stream() - .filter(block -> player.getLocation().distance(block.getLocation()) <= 2) - .iterator().hasNext() - ).limit(1) - .forEach(portal -> { - player.teleport(portal.getToOut()); - _clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player); - }); - } - else + if (territory != null && territory.Owner.equals("Borderlands")) { _portals .stream() @@ -177,10 +180,25 @@ public class NetherManager extends MiniPlugin .iterator().hasNext() ).limit(1) .forEach(portal -> { - player.teleport(UtilAlg.getAverageBlockLocation(portal.getToPortalBlocks())); + event.setTo(portal.getToOut()); + _clansManager.ClanTips.displayTip(TipType.ENTER_NETHER, player); }); } } + else + { + _portals + .stream() + .filter(portal -> + portal.getToPortalBlocks() + .stream() + .filter(block -> player.getLocation().distance(block.getLocation()) <= 2) + .iterator().hasNext() + ).limit(1) + .forEach(portal -> { + event.setTo(UtilAlg.getAverageBlockLocation(portal.getFromPortalBlocks())); + }); + } } public World getNetherWorld() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java index ba3396aee..9c14b384c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java @@ -34,11 +34,20 @@ public class Portal if (!isValidPortalBlock(from.getBlock()) || !isValidPortalBlock(to.getBlock())) { - System.out.println("[PORTAL] INVALID PORTAL PROVIDED (" + from + " --> " + to + ")"); + if (!isValidPortalBlock(from.getBlock())) + from = UtilBlock.getInRadius(from.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation(); - Success = false; + if (!isValidPortalBlock(to.getBlock())) + to = UtilBlock.getInRadius(to.getBlock(), 4).keySet().stream().filter(this::isValidPortalBlock).limit(1).iterator().next().getLocation(); - return; + if (to == null || from == null) + { + System.out.println("[PORTAL] INVALID PORTAL PROVIDED (" + from + " --> " + to + ")"); + + Success = false; + + return; + } } for (Block other : UtilBlock.getInRadius(from, 7.5d).keySet()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java new file mode 100644 index 000000000..e81701ff9 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java @@ -0,0 +1,54 @@ +package mineplex.game.clans.items.legendaries; + +import org.bukkit.Material; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilText; + +public class EnergyCrossbow extends LegendaryItem +{ + private static final long COOLDOWN = 30000; + + private long _lastFire = System.currentTimeMillis(); + private long _interactWait; + + public EnergyCrossbow() + { + super("Energy Crossbow", UtilText.splitLinesToArray(new String[] { + C.cWhite + "This deadly tooth was stolen from a nest of reptillian beasts long ago. " + + "Legends say that the holder is granted the underwater agility of an Alligator", + " ", + "#" + C.cYellow + "Right-Click" + C.cWhite + " to use" + C.cGreen + " Swim" + }, LineFormat.LORE), Material.RECORD_4); + } + + @Override + public void update(Player wielder) + { + if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) + { + if ((System.currentTimeMillis() - _lastFire) >= COOLDOWN) + { + fire(wielder); + + _interactWait = System.currentTimeMillis(); + } + else + { + UtilPlayer.message(wielder, F.main("Clans", "Energy Crossbow is cooling down!")); + } + } + } + + private void fire(Player wielder) + { + final Arrow arrow = wielder.shootArrow(); + + _lastFire = System.currentTimeMillis(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java index 45c32ed17..0d21efc43 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/LegendaryItem.java @@ -15,7 +15,7 @@ public class LegendaryItem extends CustomItem { public final long BLOCK_COOLDOWN = 200l; // Right clicking activates right click for 200ms - private long _lastBlock; // Timestamp of last block from wielder + protected long _lastBlock; // Timestamp of last block from wielder public long timeSinceLastBlock() { return System.currentTimeMillis() - _lastBlock; } public LegendaryItem(String name, String[] description, Material material) From d79107eaaa5a1df68edf4c079f8798d2ce1d1c5f Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 5 Mar 2016 03:07:25 +0000 Subject: [PATCH 113/122] new legendary weapons and nether finzlizations --- .../mineplex/core/common/util/RGBData.java | 17 ++ .../mineplex/core/common/util/UtilAlg.java | 1 + .../core/common/util/UtilCollections.java | 53 ++++- .../mineplex/core/common/util/UtilTrig.java | 24 ++ .../game/clans/clans/ClansManager.java | 27 ++- .../game/clans/clans/map/ItemMapManager.java | 13 ++ .../clans/clans/nether/NetherManager.java | 71 +++++- .../game/clans/clans/nether/Portal.java | 18 ++ .../clans/clans/siege/outpost/Outpost.java | 25 +- .../game/clans/clans/siege/weapon/Cannon.java | 6 +- .../game/clans/gameplay/Gameplay.java | 2 +- .../game/clans/items/GearManager.java | 8 +- .../items/legendaries/ChitauriScepter.java | 213 ++++++++++++++++++ .../items/legendaries/EnergyCrossbow.java | 151 +++++++++++-- .../clans/items/legendaries/HyperAxe.java | 24 +- .../game/clans/items/ui/GearPage.java | 8 +- 16 files changed, 589 insertions(+), 72 deletions(-) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java index 912516d17..adbe9749c 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/RGBData.java @@ -1,5 +1,7 @@ package mineplex.core.common.util; +import org.bukkit.util.Vector; + public class RGBData { private double _red; @@ -50,4 +52,19 @@ public class RGBData + "green=" + (int) (_green * 255) + ", " + "blue=" + (int) (_blue * 255) + "]"; } + + public Vector ToVector() + { + return new Vector(Math.max(0.001, _red), _green, _blue); + } + + public RGBData Darken() + { + return new RGBData(getFullRed() - 25, getFullGreen() - 25, getFullBlue() - 25); + } + + public RGBData Lighten() + { + return new RGBData(getFullRed() + 25, getFullGreen() + 25, getFullBlue() + 25); + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index ef41e9450..b2e7a6777 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -3,6 +3,7 @@ package mineplex.core.common.util; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.TreeSet; diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java index f6f7543bc..dadb62564 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java @@ -3,14 +3,14 @@ package mineplex.core.common.util; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Random; import java.util.function.Consumer; import java.util.function.Function; -import org.bukkit.Location; -import org.bukkit.block.Block; - public class UtilCollections { + public static Random Random = new Random(); + @SafeVarargs public static NautArrayList newNautList(E... elements) { @@ -177,7 +177,7 @@ public class UtilCollections return Arrays.copyOf(array, size); } - public static Object[] ensureSize(Object[] array, int size) + public static T[] ensureSize(T[] array, int size) { if (array.length <= size) { @@ -186,4 +186,49 @@ public class UtilCollections return Arrays.copyOf(array, size); } + + public static byte random(byte[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static short random(short[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static char random(char[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static boolean random(boolean[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static int random(int[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static long random(long[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static double random(double[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static float random(float[] array) + { + return array[Random.nextInt(array.length)]; + } + + public static T random(T[] array) + { + return array[Random.nextInt(array.length)]; + } } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java new file mode 100644 index 000000000..fd0f566e7 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java @@ -0,0 +1,24 @@ +package mineplex.core.common.util; + +import java.util.LinkedList; +import java.util.List; + +import org.bukkit.util.Vector; + +public class UtilTrig +{ + public static List GetCirclePoints(Vector origin, int points, double radius) + { + List list = new LinkedList<>(); + + double slice = 2 * Math.PI / points; + + for (int point = 0; point < points; point++) + { + double angle = slice * point; + list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle))); + } + + return list; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index fdd9d2293..f9d8b511d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -207,6 +207,8 @@ public class ClansManager extends MiniClientPluginimplements IRelati private NautHashMap _claimMap = new NautHashMap(); private NautHashMap _unclaimMap = new NautHashMap(); + private DamageManager _damageManager; + public String UserDataDir = UtilServer.getServer().getWorlds().get(0).getWorldFolder().getPath() + File.separator + ".." + File.separator + "CLANS_USER_DATA" + File.separator; public ClanTips ClanTips; @@ -240,9 +242,9 @@ public class ClansManager extends MiniClientPluginimplements IRelati Creature creature = new Creature(plugin); _npcManager = new NpcManager(plugin, creature); _condition = new SkillConditionManager(plugin); - DamageManager damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition); - damageManager.addCommand(new KillCommand(damageManager)); - _worldEvent = new WorldEventManager(plugin, this, damageManager, _lootManager, blockRestore, _clanRegions, null); + _damageManager = new DamageManager(plugin, _combatManager, _npcManager, _disguiseManager, _condition); + _damageManager.addCommand(new KillCommand(_damageManager)); + _worldEvent = new WorldEventManager(plugin, this, _damageManager, _lootManager, blockRestore, _clanRegions, null); TaskManager taskManager = new TaskManager(plugin, _clientManager, webServerAddress); @@ -286,16 +288,16 @@ public class ClansManager extends MiniClientPluginimplements IRelati new PotatoManager(plugin, this); new Weapon(plugin, energy); - new Gameplay(plugin, this, blockRestore, damageManager); + new Gameplay(plugin, this, blockRestore, _damageManager); _projectileManager = new ProjectileManager(plugin); - Fire fire = new Fire(plugin, _condition, damageManager); + Fire fire = new Fire(plugin, _condition, _damageManager); HashSet itemIgnore = new HashSet(); itemIgnore.add("Proximity Explosive"); itemIgnore.add("Proximity Zapper"); - ItemFactory itemFactory = new ItemFactory(plugin, blockRestore, _condition, damageManager, energy, fire, _projectileManager, webServerAddress, itemIgnore); - SkillFactory skillManager = new SkillFactory(plugin, damageManager, this, _combatManager, _condition, _projectileManager, _disguiseManager, blockRestore, fire, new Movement(plugin), teleport, energy, webServerAddress); + ItemFactory itemFactory = new ItemFactory(plugin, blockRestore, _condition, _damageManager, energy, fire, _projectileManager, webServerAddress, itemIgnore); + SkillFactory skillManager = new SkillFactory(plugin, _damageManager, this, _combatManager, _condition, _projectileManager, _disguiseManager, blockRestore, fire, new Movement(plugin), teleport, energy, webServerAddress); skillManager.RemoveSkill("Dwarf Toss", "Block Toss"); skillManager.removeSkill("Whirlwind Axe"); skillManager.removeSkill("Shield Smash"); @@ -1059,6 +1061,12 @@ public class ClansManager extends MiniClientPluginimplements IRelati public void onJoin(PlayerLoginEvent event) { Rank rank = _clientManager.Get(event.getPlayer()).GetRank(); + + if (_serverName.equals("GClans-1")) + { + return; + } + if (!event.getPlayer().isWhitelisted() && !rank.has(Rank.LEGEND)) { event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Clans is currently in Legend+ only Alpha!"); @@ -1198,4 +1206,9 @@ public class ClansManager extends MiniClientPluginimplements IRelati { return player.getName().equals("NewGarbo"); } + + public DamageManager getDamageManager() + { + return _damageManager; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/map/ItemMapManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/map/ItemMapManager.java index 1a6268a76..ad18709cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/map/ItemMapManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/map/ItemMapManager.java @@ -438,6 +438,19 @@ public class ItemMapManager extends MiniPlugin event.getEntity().remove(); } } + + public void removeMap(Player player) + { + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + ItemStack item = player.getInventory().getItem(slot); + + if (item != null && item.getType() == Material.MAP && item.getDurability() >= _mapId && item.getDurability() <= _mapId + 100) + { + player.getInventory().setItem(slot, null); + } + } + } public ClansUtility getClansUtility() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java index 38470f58a..2ba9aeb80 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/NetherManager.java @@ -14,6 +14,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.inventory.ItemStack; @@ -27,6 +28,8 @@ import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilCollections; import mineplex.core.common.util.UtilFile; +import mineplex.core.common.util.UtilItem; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilWorld; @@ -119,15 +122,24 @@ public class NetherManager extends MiniPlugin Player player = event.getPlayer(); ItemStack item = player.getItemInHand(); + if (player.getGameMode() == GameMode.CREATIVE) + { + return; + } + if (!block.getWorld().equals(_netherWorld)) { return; } - if (player.getGameMode() == GameMode.CREATIVE) - { - return; - } + _portals + .stream() + .filter(portal -> UtilAlg.getAverageBlockLocation(portal.getToBlocks()).distance(block.getLocation()) < 15) + .limit(1) + .forEach(portal -> { + UtilPlayer.message(player, F.main("Clans", "You are not allowed to break this block.")); + event.setCancelled(true); + }); if (!item.getType().equals(Material.GOLD_PICKAXE)) { @@ -144,9 +156,60 @@ public class NetherManager extends MiniPlugin } } + @EventHandler + public void placeBlock(BlockPlaceEvent event) + { + Block block = event.getBlock(); + Player player = event.getPlayer(); + ItemStack item = player.getItemInHand(); + + if (player.getGameMode() == GameMode.CREATIVE) + { + return; + } + + if (!block.getWorld().equals(_netherWorld)) + { + return; + } + + if (!UtilItem.isFromNether(item)) + { + UtilPlayer.message(player, F.main("Clans", "You can only place blocks here that come from " + F.clansNether("The Nether") + ".")); + event.setCancelled(true); + return; + } + + _portals + .stream() + .filter(portal -> UtilAlg.getAverageBlockLocation(portal.getToBlocks()).distance(block.getLocation()) < 15) + .limit(1) + .forEach(portal -> { + UtilPlayer.message(player, F.main("Clans", "You are not allowed to place blocks here.")); + event.setCancelled(true); + }); + + if (block.getType().equals(Material.OBSIDIAN) || block.getType().equals(Material.PORTAL)) + { + UtilPlayer.message(player, F.main("Clans", "You are not allowed to place blocks here.")); + event.setCancelled(true); + return; + } + } + @EventHandler public void update(UpdateEvent event) { + if (event.getType() == UpdateType.FAST) + { + UtilServer.getPlayersCollection() + .stream() + .filter(player -> player.getWorld().equals(_netherWorld)) + .forEach(player -> { + player.setCompassTarget(new Location(_netherWorld, -200.d + UtilMath.r(400), player.getLocation().getY(), -200.d + UtilMath.r(400))); + _clansManager.getItemMapManager().removeMap(player); + }); + } if (event.getType() == UpdateType.SLOW) { _portals.forEach(portal -> { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java index 9c14b384c..ad3cc1803 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java @@ -18,6 +18,9 @@ public class Portal private List _toPortalBlocks; private List _toObsidianBlocks; + private List _fromBlocks; + private List _toBlocks; + private Location _toOut; public final boolean Success; @@ -74,6 +77,11 @@ public class Portal } } + _fromBlocks.addAll(_fromObsidianBlocks); + _fromBlocks.addAll(_fromPortalBlocks); + _toBlocks.addAll(_toObsidianBlocks); + _toBlocks.addAll(_toPortalBlocks); + Success = true; } @@ -102,6 +110,16 @@ public class Portal return _toObsidianBlocks; } + public List getFromBlocks() + { + return _fromBlocks; + } + + public List getToBlocks() + { + return _toBlocks; + } + private boolean isValidPortalBlock(Block block) { return block.getType() == Material.OBSIDIAN || block.getType() == Material.PORTAL; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 99834cdf2..a3811e4bc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -48,6 +48,7 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; +import mineplex.core.common.util.UtilTrig; import mineplex.core.hologram.Hologram; import mineplex.core.hologram.HologramInteraction; import mineplex.core.itemstack.ItemBuilder; @@ -169,9 +170,9 @@ public class Outpost implements Listener _state = token.OutpostState; - _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); + _circleStages = new LoopIterator(UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d)); - List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); + List reverse = UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d); Collections.reverse(reverse); _reverseCircleStages = new LoopIterator(reverse); @@ -221,9 +222,9 @@ public class Outpost implements Listener _outpostManager.getRepository().insertOutpost(toToken()); - _circleStages = new LoopIterator(circleAround(new Vector(0., 0., 0.), 40, .6d)); + _circleStages = new LoopIterator(UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d)); - List reverse = circleAround(new Vector(0., 0., 0.), 40, .6d); + List reverse = UtilTrig.GetCirclePoints(new Vector(0., 0., 0.), 40, .6d); Collections.reverse(reverse); _reverseCircleStages = new LoopIterator(reverse); @@ -328,7 +329,6 @@ public class Outpost implements Listener if (!_ownerClan.equals(_ownerClan.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!")); - return; } if (event.getClickedBlock() != null && _origin.equals(event.getClickedBlock().getLocation())) @@ -590,21 +590,6 @@ public class Outpost implements Listener _nameHolograms.forEach(Hologram::start); } - private List circleAround(Vector origin, int points, double radius) - { - List list = new LinkedList<>(); - - double slice = 2 * Math.PI / points; - - for (int point = 0; point < points; point++) - { - double angle = slice * point; - list.add(new Vector(origin.getX() + radius * Math.cos(angle), 0, origin.getZ() + radius * Math.sin(angle))); - } - - return list; - } - public void kill() { _state = OutpostState.DESTRUCTING; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 67beb670a..03327d6e0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -357,17 +357,17 @@ public class Cannon extends SiegeWeapon if (firepower == 1) { - hMult = 0.6; + hMult = 1.2; yAdd = 0.5; } else if (firepower == 2) { - hMult = 1; + hMult = 1.7; yAdd = 0.55; } else if (firepower >= 3) { - hMult = 1.5; + hMult = 2.35; yAdd = 0.6; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index 693d0b2ff..e595c74e8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -237,7 +237,7 @@ public class Gameplay extends MiniPlugin HashSet remove = new HashSet(); for (Block cur : _bucketWater.keySet()) - if (UtilTime.elapsed(_bucketWater.get(cur), 2000)) remove.add(cur); + if (UtilTime.elapsed(_bucketWater.get(cur).longValue(), 2000)) remove.add(cur); for (Block cur : remove) _bucketWater.remove(cur); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 73242f881..63464da3c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -29,6 +29,8 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; +import mineplex.core.common.weight.Weight; +import mineplex.core.common.weight.WeightSet; import mineplex.core.donation.DonationManager; import mineplex.core.packethandler.IPacketHandler; import mineplex.core.packethandler.PacketHandler; @@ -56,9 +58,9 @@ import mineplex.game.clans.items.attributes.weapon.JaggedAttribute; import mineplex.game.clans.items.attributes.weapon.SharpAttribute; import mineplex.game.clans.items.commands.GearCommand; import mineplex.game.clans.items.economy.GoldToken; -import mineplex.core.common.weight.Weight; -import mineplex.core.common.weight.WeightSet; import mineplex.game.clans.items.legendaries.AlligatorsTooth; +import mineplex.game.clans.items.legendaries.ChitauriScepter; +import mineplex.game.clans.items.legendaries.EnergyCrossbow; import mineplex.game.clans.items.legendaries.GiantsBroadsword; import mineplex.game.clans.items.legendaries.HyperAxe; import mineplex.game.clans.items.legendaries.LegendaryItem; @@ -153,7 +155,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable // TODO: Initialize list of attributes and types // Initialize various LegendaryItem types - _legendaryWeights = new WeightSet>(AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); + _legendaryWeights = new WeightSet>(ChitauriScepter.class, EnergyCrossbow.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); // TODO: Add rest of legendaries, find better way? // Register listeners diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java new file mode 100644 index 000000000..1f1f0a29b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java @@ -0,0 +1,213 @@ +package mineplex.game.clans.items.legendaries; + +import java.util.Random; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.RGBData; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilColor; +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.UtilShapes; +import mineplex.core.common.util.UtilText; +import mineplex.core.recharge.Recharge; +import mineplex.game.clans.clans.ClansManager; + +public class ChitauriScepter extends LegendaryItem +{ + private long _lastFire = System.currentTimeMillis(); + private long _interactWait; + + private RGBData[] colors = { UtilColor.RgbLightBlue, UtilColor.RgbLightBlue.Lighten(), UtilColor.RgbLightBlue.Darken() }; + + public ChitauriScepter() + { + super("Chitauri Scepter", UtilText.splitLinesToArray(new String[] { + C.cWhite + "Legend says " + + " ", + "#" + C.cYellow + "Right-Click" + C.cWhite + " to use Scepter." + }, LineFormat.LORE), Material.RECORD_7); + } + + @Override + public void update(Player wielder) + { + if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) + { + if (Recharge.Instance.use(wielder, getDisplayName(), 4000, true, true)) + { + fire(wielder); + + _interactWait = System.currentTimeMillis(); + } + } + } + + private void fire(final Player player) + { + final Location missileLocation = player.getEyeLocation(); + final Location shotFrom = missileLocation.clone(); + final Vector direction = missileLocation.getDirection().normalize().multiply(0.3); + final int maxRange = 40; + final int maxDings = maxRange * 3; + final int damage = 6; + + new BukkitRunnable() + { + private int dingsDone; + private Location previousLocation = missileLocation; + + private void burst() + { + for (Entity cur : missileLocation.getWorld().getEntities()) + { + if (cur == player || !(cur instanceof LivingEntity) || (cur instanceof Player && UtilPlayer.isSpectator(cur))) + continue; + + LivingEntity entity = (LivingEntity) cur; + + Location eLoc = entity.getLocation(); + + // If they are less than 0.5 blocks away + if (eLoc.clone().add(0, missileLocation.getY() - eLoc.getY(), 0).distance(missileLocation) <= 0.7) + { + // If it is in their body height + if (Math.abs((eLoc.getY() + (entity.getEyeHeight() / 1.5)) - missileLocation.getY()) <= entity + .getEyeHeight() / 2) + { + if (entity != player && (!(entity instanceof Player))) + { + ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, player, null, DamageCause.CUSTOM, damage, true, + true, false, getDisplayName(), getDisplayName()); + + UtilPlayer.message(entity, F.main("Clans", F.elem(entity.getName()) + " hit you with a " + getDisplayName() + C.mBody + ".")); + UtilPlayer.message(player, F.main("Clans", "You hit " + F.elem(player.getName()) + " with your " + getDisplayName() + C.mBody + ".")); + } + } + } + } + + playParticle(missileLocation, previousLocation); + + missileLocation.getWorld().playSound(missileLocation, Sound.BAT_TAKEOFF, 1.2F, 1); + cancel(); + } + + public void run() + { + if (dingsDone >= maxDings || !player.isOnline()) + { + burst(); + } + else + { + for (int i = 0; i < 2; i++) + { + Player closestPlayer = null; + double dist = 0; + + for (Player closest : UtilServer.getPlayers()) + { + if (!closest.getWorld().equals(missileLocation.getWorld())) + { + continue; + } + + Location loc = closest.getLocation(); + + if (closest != player) + { + double dist1 = loc.distance(shotFrom); + if (dist1 < maxRange + 10) + { + double dist2 = missileLocation.distance(loc); + if (closestPlayer == null || dist2 < dist) + { + double dist3 = missileLocation.clone().add(direction).distance(loc); + + if (dist3 < dist2) + { + closestPlayer = closest; + dist = dist2; + } + } + } + } + } + + if (closestPlayer != null) + { + Vector newDirection = closestPlayer.getLocation().add(0, 1, 0).toVector() + .subtract(missileLocation.toVector()); + + direction.add(newDirection.normalize().multiply(0.01)).normalize().multiply(0.3); + } + + missileLocation.add(direction); + + for (Entity cur : missileLocation.getWorld().getEntities()) + { + + if (cur == player || !(cur instanceof LivingEntity) + || (cur instanceof Player && UtilPlayer.isSpectator(cur))) + continue; + + LivingEntity ent = (LivingEntity) cur; + + Location eLoc = ent.getLocation(); + + // If they are less than 0.5 blocks away + if (eLoc.clone().add(0, missileLocation.getY() - eLoc.getY(), 0).distance(missileLocation) <= 0.7) + { + // If it is in their body height + if (Math.abs((eLoc.getY() + (ent.getEyeHeight() / 1.5)) - missileLocation.getY()) <= ent + .getEyeHeight() / 2) + { + burst(); + return; + } + } + } + + if (UtilBlock.solid(missileLocation.getBlock())) + { + burst(); + return; + } + + playParticle(missileLocation, previousLocation); + previousLocation = missileLocation.clone(); + + dingsDone++; + } + + missileLocation.getWorld().playSound(missileLocation, Sound.ORB_PICKUP, 0.7F, 0); + } + } + }.runTaskTimer(ClansManager.getInstance().getPlugin(), 0, 0); + } + + private void playParticle(Location start, Location end) + { + for (Location loc : UtilShapes.getLinesDistancedPoints(start, end, 0.06)) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, loc, UtilCollections.random(colors).ToVector(), 1f, 0, ViewDist.LONG); + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java index e81701ff9..3b7f02f37 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java @@ -1,30 +1,50 @@ package mineplex.game.clans.items.legendaries; +import java.util.HashMap; + +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.entity.Arrow; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.ProjectileHitEvent; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; import mineplex.core.common.util.LineFormat; -import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.RGBData; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilColor; +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.UtilServer; +import mineplex.core.common.util.UtilShapes; import mineplex.core.common.util.UtilText; +import mineplex.core.recharge.Recharge; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; public class EnergyCrossbow extends LegendaryItem { - private static final long COOLDOWN = 30000; - private long _lastFire = System.currentTimeMillis(); private long _interactWait; public EnergyCrossbow() { super("Energy Crossbow", UtilText.splitLinesToArray(new String[] { - C.cWhite + "This deadly tooth was stolen from a nest of reptillian beasts long ago. " - + "Legends say that the holder is granted the underwater agility of an Alligator", - " ", - "#" + C.cYellow + "Right-Click" + C.cWhite + " to use" + C.cGreen + " Swim" - }, LineFormat.LORE), Material.RECORD_4); + C.cWhite + "Legend says " + + " ", + "#" + C.cYellow + "Right-Click" + C.cWhite + " to fire Crossbow." + }, LineFormat.LORE), Material.RECORD_6); } @Override @@ -32,22 +52,121 @@ public class EnergyCrossbow extends LegendaryItem { if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) { - if ((System.currentTimeMillis() - _lastFire) >= COOLDOWN) + if (Recharge.Instance.use(wielder, "Crossbow", 4000, true, true)) { fire(wielder); _interactWait = System.currentTimeMillis(); } - else - { - UtilPlayer.message(wielder, F.main("Clans", "Energy Crossbow is cooling down!")); - } } } - private void fire(Player wielder) + private void fire(final Player player) { - final Arrow arrow = wielder.shootArrow(); + UtilServer.registerEvents(new Listener() { + private Location _lastLoc; + + private Arrow _arrow; + private Player _player; + + private RGBData[] colors = { UtilColor.RgbLightBlue, UtilColor.RgbLightBlue.Lighten(), UtilColor.RgbLightBlue.Darken() }; + + { + _player = player; + + Arrow arrow = _player.shootArrow(); + + arrow.setShooter(_player); + + _arrow = arrow; + + _player.playSound(_arrow.getLocation(), Sound.BAT_TAKEOFF, 2.f, 2.f); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (_arrow == null || _arrow.isDead()) + { + HandlerList.unregisterAll(this); + + return; + } + + if (_lastLoc != null) + { + Location lastLoc = _lastLoc.clone(); + + while (UtilMath.offset(lastLoc, _arrow.getLocation()) > 0.1) + { + lastLoc.add(UtilAlg.getTrajectory(lastLoc, _arrow.getLocation()).multiply(0.1)); + + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, lastLoc, UtilCollections.random(colors).ToVector(), 1f, 0, ViewDist.MAX); + } + } + + _lastLoc = _arrow.getLocation(); + } + + private void hit() + { + HandlerList.unregisterAll(this); + + for (Location point : UtilShapes.getSphereBlocks(_arrow.getLocation(), 1, 1, true)) + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _arrow.getLocation().add(point), UtilCollections.random(colors).ToVector(), 1f, 0, ViewDist.MAX); + + HashMap targets = UtilEnt.getInRadius(_arrow.getLocation(), 3.d); + for (LivingEntity entity : targets.keySet()) + { + if (entity.equals(_arrow.getShooter())) + continue; + + ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, _player, _arrow, + DamageCause.CUSTOM, 6, true, true, false, + _player.getName(), "Energy Crossbow"); + } + + _arrow.remove(); + _arrow = null; + } + + @EventHandler + public void projectileHit(ProjectileHitEvent event) + { + if (!event.getEntity().equals(_arrow)) + { + return; + } + + ClansManager.getInstance().runSyncLater(this::hit, 1); + } + + @EventHandler + public void entityHurt(EntityDamageByEntityEvent event) + { + if (!event.getDamager().equals(_arrow)) + { + return; + } + + if (event.getEntity().equals(_arrow.getShooter()) || !(event.getEntity() instanceof LivingEntity)) + { + _arrow.remove(); + _arrow = null; + + return; + } + + event.setCancelled(true); + + ClansManager.getInstance().getDamageManager().NewDamageEvent((LivingEntity) event.getEntity(), _player, _arrow, + DamageCause.CUSTOM, 1.5d, true, true, false, + _player.getName(), "Energy Crossbow"); + + hit(); + } + + }); _lastFire = System.currentTimeMillis(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperAxe.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperAxe.java index c9630b26c..a01774651 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperAxe.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperAxe.java @@ -12,7 +12,7 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent; public class HyperAxe extends LegendaryItem { - public static final long ATTACK_RATE_DURATION = 200; + public static final long ATTACK_RATE_DURATION = 1000 / 17; private static ValueDistribution amountGen = generateDistribution(0, 3); // [1, 4] speed amount private static ValueDistribution durationGen = generateDistribution(80, 320); // [4, 16] seconds speed duration @@ -20,11 +20,10 @@ public class HyperAxe extends LegendaryItem private int _speedDuration; private long _lastAttack; - public long timeSinceLastAttack() { return System.currentTimeMillis() - _lastAttack; } public HyperAxe() { - super("Hyper Axe", new String[]{ + super("Hyper Axe", new String[] { C.cWhite + "Of all the weapons known to man,", C.cWhite + "none is more prevalent than the", C.cWhite + "Hyper Axe. Infused with rabbit's", @@ -43,10 +42,9 @@ public class HyperAxe extends LegendaryItem @Override public void update(Player wielder) { - if (isHoldingRightClick() && canBuff()) + if (isHoldingRightClick() && canBuff(wielder)) { buffPlayer(wielder); - _lastAttack = System.currentTimeMillis(); } } @@ -56,9 +54,9 @@ public class HyperAxe extends LegendaryItem if (timeSinceLastAttack() >= ATTACK_RATE_DURATION) { event.SetIgnoreRate(true); -// log("Ignoring rate!"); - event.AddMod("Hyper Axe", 1); + event.AddMod("Hyper Axe", 9); + _lastAttack = System.currentTimeMillis(); } else { @@ -66,18 +64,22 @@ public class HyperAxe extends LegendaryItem } } + public long timeSinceLastAttack() + { + return System.currentTimeMillis() - _lastAttack; + } + private void buffPlayer(Player wielder) { - if (!Recharge.Instance.use(wielder, "Hyper Rush", 16000, true, true)) - return; + Recharge.Instance.use(wielder, "Hyper Rush", 16000, true, false); // Give player speed buff wielder.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, _speedDuration, _speedAmount)); log("Buffing"); } - private boolean canBuff() + private boolean canBuff(Player wielder) { - return true; // TODO: Implement cooldown? (None specified in docs, sounds OP) + return Recharge.Instance.usable(wielder, "Hyper Rush", true); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java index 536c94df1..e2d96b6ec 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.commons.lang3.text.WordUtils; +import org.apache.commons.lang3.tuple.Triple; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; @@ -40,13 +42,13 @@ import mineplex.game.clans.items.attributes.weapon.HasteAttribute; import mineplex.game.clans.items.attributes.weapon.JaggedAttribute; import mineplex.game.clans.items.attributes.weapon.SharpAttribute; import mineplex.game.clans.items.legendaries.AlligatorsTooth; +import mineplex.game.clans.items.legendaries.ChitauriScepter; +import mineplex.game.clans.items.legendaries.EnergyCrossbow; import mineplex.game.clans.items.legendaries.GiantsBroadsword; import mineplex.game.clans.items.legendaries.HyperAxe; import mineplex.game.clans.items.legendaries.LegendaryItem; import mineplex.game.clans.items.legendaries.MagneticMaul; import mineplex.game.clans.items.legendaries.WindBlade; -import org.apache.commons.lang3.text.WordUtils; -import org.apache.commons.lang3.tuple.Triple; public class GearPage extends ShopPageBase { @@ -98,7 +100,7 @@ public class GearPage extends ShopPageBase } }; - _legendaryItems = Arrays.> asList(AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); + _legendaryItems = Arrays.> asList(ChitauriScepter.class, EnergyCrossbow.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); _armorSuperPrefixes = Arrays.> asList(LavaAttribute.class); _armorPrefixes = Arrays.> asList(PaddedAttribute.class, ReinforcedAttribute.class, SlantedAttribute.class); From e88736c1aa1e00ac7aa5834e3e2c118b27e1b0b3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 5 Mar 2016 20:46:24 +0000 Subject: [PATCH 114/122] changes to scepter, NPE fix --- .../mineplex/core/common/util/UtilServer.java | 15 ++++- .../game/clans/clans/nether/Portal.java | 4 ++ .../items/legendaries/ChitauriScepter.java | 62 +++++++++---------- 3 files changed, 48 insertions(+), 33 deletions(-) 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 17765ceb5..0b01e4bb0 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 @@ -13,7 +13,10 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; public class UtilServer { @@ -91,7 +94,12 @@ public class UtilServer public static void registerEvents(Listener listener) { - getPluginManager().registerEvents(listener, getPluginManager().getPlugins()[0]); + getPluginManager().registerEvents(listener, getPlugin()); + } + + public static Plugin getPlugin() + { + return getPluginManager().getPlugins()[0]; } public static PluginManager getPluginManager() @@ -103,4 +111,9 @@ public class UtilServer { getPluginManager().callEvent(event); } + + public static void repeat(BukkitRunnable runnable, long time) + { + runnable.runTaskTimer(getPlugin(), time, time); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java index ad3cc1803..c5160433c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/nether/Portal.java @@ -1,5 +1,6 @@ package mineplex.game.clans.clans.nether; +import java.util.ArrayList; import java.util.List; import org.bukkit.Location; @@ -77,6 +78,9 @@ public class Portal } } + _fromBlocks = new ArrayList<>(); + _toBlocks = new ArrayList<>(); + _fromBlocks.addAll(_fromObsidianBlocks); _fromBlocks.addAll(_fromPortalBlocks); _toBlocks.addAll(_toObsidianBlocks); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java index 1f1f0a29b..78ef539cd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java @@ -61,21 +61,21 @@ public class ChitauriScepter extends LegendaryItem private void fire(final Player player) { - final Location missileLocation = player.getEyeLocation(); - final Location shotFrom = missileLocation.clone(); - final Vector direction = missileLocation.getDirection().normalize().multiply(0.3); - final int maxRange = 40; - final int maxDings = maxRange * 3; + final Location projectile = player.getEyeLocation(); + final Location origin = player.getEyeLocation(); + final Vector direction = player.getEyeLocation().getDirection().normalize().multiply(0.25); + final int maxRange = 50; + final int maxDings = maxRange * 4; final int damage = 6; - - new BukkitRunnable() + + UtilServer.repeat(new BukkitRunnable() { private int dingsDone; - private Location previousLocation = missileLocation; + private Location previousLocation = projectile; private void burst() { - for (Entity cur : missileLocation.getWorld().getEntities()) + for (Entity cur : projectile.getWorld().getEntities()) { if (cur == player || !(cur instanceof LivingEntity) || (cur instanceof Player && UtilPlayer.isSpectator(cur))) continue; @@ -85,13 +85,13 @@ public class ChitauriScepter extends LegendaryItem Location eLoc = entity.getLocation(); // If they are less than 0.5 blocks away - if (eLoc.clone().add(0, missileLocation.getY() - eLoc.getY(), 0).distance(missileLocation) <= 0.7) + if (eLoc.clone().add(0, projectile.getY() - eLoc.getY(), 0).distance(projectile) <= 0.7) { // If it is in their body height - if (Math.abs((eLoc.getY() + (entity.getEyeHeight() / 1.5)) - missileLocation.getY()) <= entity + if (Math.abs((eLoc.getY() + (entity.getEyeHeight() / 1.5)) - projectile.getY()) <= entity .getEyeHeight() / 2) { - if (entity != player && (!(entity instanceof Player))) + if (entity != player) { ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, player, null, DamageCause.CUSTOM, damage, true, true, false, getDisplayName(), getDisplayName()); @@ -103,9 +103,9 @@ public class ChitauriScepter extends LegendaryItem } } - playParticle(missileLocation, previousLocation); + playParticle(projectile, previousLocation); - missileLocation.getWorld().playSound(missileLocation, Sound.BAT_TAKEOFF, 1.2F, 1); + projectile.getWorld().playSound(projectile, Sound.BAT_TAKEOFF, 1.2F, 1); cancel(); } @@ -124,7 +124,7 @@ public class ChitauriScepter extends LegendaryItem for (Player closest : UtilServer.getPlayers()) { - if (!closest.getWorld().equals(missileLocation.getWorld())) + if (!closest.getWorld().equals(projectile.getWorld())) { continue; } @@ -133,13 +133,13 @@ public class ChitauriScepter extends LegendaryItem if (closest != player) { - double dist1 = loc.distance(shotFrom); + double dist1 = loc.distance(origin); if (dist1 < maxRange + 10) { - double dist2 = missileLocation.distance(loc); + double dist2 = projectile.distance(loc); if (closestPlayer == null || dist2 < dist) { - double dist3 = missileLocation.clone().add(direction).distance(loc); + double dist3 = projectile.clone().add(direction).distance(loc); if (dist3 < dist2) { @@ -150,20 +150,19 @@ public class ChitauriScepter extends LegendaryItem } } } - + if (closestPlayer != null) { Vector newDirection = closestPlayer.getLocation().add(0, 1, 0).toVector() - .subtract(missileLocation.toVector()); + .subtract(projectile.toVector()); - direction.add(newDirection.normalize().multiply(0.01)).normalize().multiply(0.3); + direction.add(newDirection.normalize().multiply(0.01)).normalize().multiply(0.25); } - missileLocation.add(direction); + projectile.add(direction); - for (Entity cur : missileLocation.getWorld().getEntities()) + for (Entity cur : projectile.getWorld().getEntities()) { - if (cur == player || !(cur instanceof LivingEntity) || (cur instanceof Player && UtilPlayer.isSpectator(cur))) continue; @@ -173,11 +172,10 @@ public class ChitauriScepter extends LegendaryItem Location eLoc = ent.getLocation(); // If they are less than 0.5 blocks away - if (eLoc.clone().add(0, missileLocation.getY() - eLoc.getY(), 0).distance(missileLocation) <= 0.7) + if (eLoc.clone().add(0, projectile.getY() - eLoc.getY(), 0).distance(projectile) <= 0.7) { // If it is in their body height - if (Math.abs((eLoc.getY() + (ent.getEyeHeight() / 1.5)) - missileLocation.getY()) <= ent - .getEyeHeight() / 2) + if (Math.abs((eLoc.getY() + (ent.getEyeHeight() / 1.5)) - projectile.getY()) <= ent.getEyeHeight() / 2) { burst(); return; @@ -185,22 +183,22 @@ public class ChitauriScepter extends LegendaryItem } } - if (UtilBlock.solid(missileLocation.getBlock())) + if (UtilBlock.solid(projectile.getBlock())) { burst(); return; } - playParticle(missileLocation, previousLocation); - previousLocation = missileLocation.clone(); + playParticle(projectile, previousLocation); + previousLocation = projectile.clone(); dingsDone++; } - missileLocation.getWorld().playSound(missileLocation, Sound.ORB_PICKUP, 0.7F, 0); + projectile.getWorld().playSound(projectile, Sound.ORB_PICKUP, 0.7F, 0); } } - }.runTaskTimer(ClansManager.getInstance().getPlugin(), 0, 0); + }, 0); } private void playParticle(Location start, Location end) From d92f817efcde9f0fcdea59c2c0d95d27c0a89584 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 5 Mar 2016 22:50:06 +0000 Subject: [PATCH 115/122] fixed some teleportation bugs and a bit of cleanup --- .../core/delayedtask/DelayedTask.java | 10 ++ .../game/clans/clans/ClansManager.java | 2 - .../clans/clans/commands/ClansCommand.java | 14 ++- .../game/clans/clans/stuck/StuckManager.java | 109 ------------------ .../stuck/commands/ClansSpawnCommand.java | 77 +++++++++++++ .../clans/stuck/commands/StuckCommand.java | 48 -------- .../items/legendaries/ChitauriScepter.java | 11 +- .../src/mineplex/game/clans/spawn/Spawn.java | 8 ++ 8 files changed, 112 insertions(+), 167 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/StuckCommand.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java index bd02855fe..da5c6c7c0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/delayedtask/DelayedTask.java @@ -62,4 +62,14 @@ public class DelayedTask extends MiniClientPlugin { return new DelayedTaskClient(Bukkit.getPlayer(player)); } + + public boolean HasTask(Player player, String task) + { + return Get(player).getStartTime(task) != -1; + } + + public boolean HasTask(String player, String task) + { + return HasTask(Bukkit.getPlayer(player), task); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index f9d8b511d..7a9cfd82a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -94,7 +94,6 @@ import mineplex.game.clans.clans.redis.ClanLoadCommandHandler; import mineplex.game.clans.clans.regions.ClansRegions; import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager; import mineplex.game.clans.clans.siege.SiegeManager; -import mineplex.game.clans.clans.stuck.StuckManager; import mineplex.game.clans.clans.supplyDrop.SupplyDropManager; import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager; import mineplex.game.clans.clans.war.WarManager; @@ -281,7 +280,6 @@ public class ClansManager extends MiniClientPluginimplements IRelati new ObserverManager(plugin, _condition, this); new ClanEnergyTracker(plugin, this); - new StuckManager(this); // new ClansAlphaManager(this, taskManager); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 176320170..9c6257294 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -1,3 +1,4 @@ + package mineplex.game.clans.clans.commands; import java.util.Collections; @@ -9,7 +10,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import com.google.common.collect.Lists; @@ -20,7 +20,6 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilInput; -import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; @@ -372,6 +371,13 @@ public class ClansCommand extends CommandBase return; } + if (DelayedTask.Instance.HasTask(caller, "Spawn Teleport")) + { + _clansManager.message(caller, "You are already unsticking yourself."); + + return; + } + ClanTerritory territory = Plugin.getClanUtility().getClaim(caller.getLocation()); String clanName = Plugin.getClanUtility().getClanByPlayer(caller) == null ? null : Plugin.getClanUtility().getClanByPlayer(caller).getName(); @@ -913,7 +919,7 @@ public class ClansCommand extends CommandBase * } */ - if (!Recharge.Instance.use(caller, "Home Teleport", 5 * 60 * 1000, true, false)) + if (!Recharge.Instance.usable(caller, "Home Teleport", true)) { return; } @@ -921,6 +927,8 @@ public class ClansCommand extends CommandBase DelayedTask.Instance.doDelay(caller, "Home Teleport", new Callback() { public void run(DelayedTaskClient player) { + Recharge.Instance.use(caller, "Home Teleport", 5 * 60 * 1000, true, false); + // Do Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckManager.java deleted file mode 100644 index 4dd767615..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckManager.java +++ /dev/null @@ -1,109 +0,0 @@ -package mineplex.game.clans.clans.stuck; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - -import mineplex.core.MiniClientPlugin; -import mineplex.core.common.util.F; -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.recharge.Recharge; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.stuck.commands.StuckCommand; -import mineplex.game.clans.spawn.Spawn; - -public class StuckManager extends MiniClientPlugin -{ - public static final long UNSTICK_WAIT_TIME = UtilTime.convert(35, TimeUnit.SECONDS, TimeUnit.MILLISECONDS); - - public StuckManager(ClansManager clans) - { - super("Stuck Handler", clans.getPlugin()); - } - - @Override - public void addCommands() - { - addCommand(new StuckCommand(this)); - } - - @Override - protected StuckClient AddPlayer(String player) - { - return new StuckClient(); - } - - public void unstick(Player player) - { - Get(player).UnstickStartTime = System.currentTimeMillis(); - Get(player).UnstickEndTime = Get(player).UnstickStartTime + UNSTICK_WAIT_TIME; - Get(player).StartLoc = player.getLocation(); - } - - public boolean isUnsticking(Player caller) - { - return Get(caller).UnstickStartTime != -1; - } - - @EventHandler - public void updateTeleport(UpdateEvent event) - { - if (event.getType() != UpdateType.FASTER) - { - for (Player player : Bukkit.getOnlinePlayers()) - { - if (isUnsticking(player)) - { - if (player.getLocation().distance(Get(player).StartLoc) >= 0.75) - { - cancelTeleport(player); - break; - } - - UtilTextMiddle.display("", "Teleporting to Spawn in " + F.elem(UtilTime.MakeStr(Get(player).getTimeLeft())), 0, 20, 60, player); - - if (Get(player).getTimeLeft() <= 500) - { - teleport(player); - } - } - } - } - } - - private void cancelTeleport(Player player) - { - UtilPlayer.message(player, F.main("Clans", "You have moved, and cancelled the teleport.")); - - Get(player).UnstickStartTime = -1; - Get(player).UnstickEndTime = -1; - Get(player).StartLoc = null; - } - - private void teleport(Player player) - { - Recharge.Instance.use(player, "Spawn Teleport", UtilTime.convert(15, TimeUnit.MINUTES, TimeUnit.MILLISECONDS), false, false); - - UtilPlayer.message(player, F.main("Clans", "You have been teleported to Spawn.")); - - Get(player).UnstickStartTime = -1; - Get(player).UnstickEndTime = -1; - Get(player).StartLoc = null; - - if (Math.random() < .5) - { - player.teleport(Spawn.getEastSpawn()); - } - else - { - player.teleport(Spawn.getWestSpawn()); - } - - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java new file mode 100644 index 000000000..1c7f31c8f --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java @@ -0,0 +1,77 @@ +package mineplex.game.clans.clans.stuck.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.common.util.UtilTime; +import mineplex.core.delayedtask.DelayedTask; +import mineplex.core.delayedtask.DelayedTaskClient; +import mineplex.core.recharge.Recharge; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.spawn.Spawn; + +public class ClansSpawnCommand extends CommandBase +{ + public ClansSpawnCommand(Spawn spawn) + { + super(spawn, Rank.ALL, "spawn", "stuck", "unstick", "unstuck"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (DelayedTask.Instance.HasTask(caller, "Spawn Teleport")) + { + UtilPlayer.message(caller, F.main("Clans", "You are already teleporting to Spawn.")); + + return; + } + + if (!Recharge.Instance.usable(caller, "Spawn Teleport", true)) + { + return; + } + + if(ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()) != null && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Borderlands") && + !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Shops") && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Spawn")) + { + UtilPlayer.message(caller, F.main("Clans", "You must be in the Wilderness/Borderlands/Shops/Spawn to use this command.")); + + return; + } + + DelayedTask.Instance.doDelay(caller, "Spawn Teleport", new Callback() { + public void run(DelayedTaskClient player) + { + // Do + + if (Math.random() < .5) + { + caller.teleport(Spawn.getEastSpawn()); + } + else + { + caller.teleport(Spawn.getWestSpawn()); + } + + // Inform + Plugin.getClansManager().getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to Spawn.")); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilTextMiddle.display("", "Teleporting to Spawn in " + F.elem(UtilTime.MakeStr(Math.max(0, client.getTimeLeft("Spawn Teleport")))), 0, 5, 0, client.getPlayer()); + } + }, new Callback() { + public void run(DelayedTaskClient client) + { + UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); + } + }, 2 * 60 * 1000, false); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/StuckCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/StuckCommand.java deleted file mode 100644 index f43064682..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/StuckCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package mineplex.game.clans.clans.stuck.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilTime; -import mineplex.core.recharge.Recharge; -import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.stuck.StuckManager; - -public class StuckCommand extends CommandBase -{ - public StuckCommand(StuckManager plugin) - { - super(plugin, Rank.ALL, "spawn", "stuck", "unstick", "unstuck"); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (Plugin.isUnsticking(caller)) - { - UtilPlayer.message(caller, F.main("Clans", "You are already teleporting to Spawn.")); - - return; - } - - if (!Recharge.Instance.usable(caller, "Spawn Teleport", true)) - { - return; - } - - if(ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()) != null && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Borderlands") && - !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Shops") && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Spawn")) - { - UtilPlayer.message(caller, F.main("Clans", "You must be in the Wilderness/Borderlands/Shops/Spawn to use this command.")); - - return; - } - - UtilPlayer.message(caller, F.main("Clans", "Teleporting to Spawn... Please do not move for " + F.elem(UtilTime.MakeStr(StuckManager.UNSTICK_WAIT_TIME))) + "."); - - Plugin.unstick(caller); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java index 78ef539cd..ff6f46913 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java @@ -50,7 +50,7 @@ public class ChitauriScepter extends LegendaryItem { if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) { - if (Recharge.Instance.use(wielder, getDisplayName(), 4000, true, true)) + if (Recharge.Instance.use(wielder, "Chitauri Scepter", 4000, true, true)) { fire(wielder); @@ -93,11 +93,12 @@ public class ChitauriScepter extends LegendaryItem { if (entity != player) { - ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, player, null, DamageCause.CUSTOM, damage, true, - true, false, getDisplayName(), getDisplayName()); + ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, player, null, + DamageCause.CUSTOM, damage, true, true, false, + player.getName(), "Chitauri Scepter"); - UtilPlayer.message(entity, F.main("Clans", F.elem(entity.getName()) + " hit you with a " + getDisplayName() + C.mBody + ".")); - UtilPlayer.message(player, F.main("Clans", "You hit " + F.elem(player.getName()) + " with your " + getDisplayName() + C.mBody + ".")); + UtilPlayer.message(entity, F.main("Clans", F.elem(entity.getName()) + " hit you with a " + F.elem("Chitauri Scepter") + C.mBody + ".")); + UtilPlayer.message(player, F.main("Clans", "You hit " + F.elem(player.getName()) + " with your " + F.elem("Chitauri Scepter") + C.mBody + ".")); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java index a04d444d0..7ae590aa5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java @@ -42,6 +42,7 @@ import mineplex.core.common.util.UtilTime.TimeUnit; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.stuck.commands.ClansSpawnCommand; import mineplex.core.common.weight.WeightSet; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; import mineplex.minecraft.game.classcombat.item.event.WebTossEvent; @@ -77,6 +78,8 @@ public class Spawn extends MiniPlugin _spawns = new WeightSet(getEastSpawn(), getWestSpawn()); _shops = new WeightSet(getNorthTown(), getSouthTown()); _clansManager = clansManager; + + addCommand(new ClansSpawnCommand(this)); } /** @@ -537,4 +540,9 @@ public class Spawn extends MiniPlugin _songWestLast = System.currentTimeMillis(); } } + + public ClansManager getClansManager() + { + return _clansManager; + } } From 8cfbe20a0814042f5706f2ef511fb70f56eaa51e Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 5 Mar 2016 23:09:57 +0000 Subject: [PATCH 116/122] re-added delay to /spawn --- .../game/clans/clans/stuck/commands/ClansSpawnCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java index 1c7f31c8f..c060a8000 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java @@ -59,6 +59,8 @@ public class ClansSpawnCommand extends CommandBase caller.teleport(Spawn.getWestSpawn()); } + Recharge.Instance.use(caller, "Spawn Teleport", 13 * 60 * 1000, false, false); + // Inform Plugin.getClansManager().getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to Spawn.")); } @@ -72,6 +74,6 @@ public class ClansSpawnCommand extends CommandBase { UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); } - }, 2 * 60 * 1000, false); + }, 35 * 1000, false); } } From 7e2086df1c477bee73fe519e21bda820556bfdd6 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sun, 6 Mar 2016 19:55:58 +0000 Subject: [PATCH 117/122] flash fix, rares update, and outpost fixes --- .../core/common/util/UtilCollections.java | 7 ++ .../clans/clans/siege/outpost/Outpost.java | 17 ++++- .../siege/repository/OutpostRepository.java | 14 ++-- .../repository/SiegeWeaponRepository.java | 12 +-- .../mineplex/game/clans/items/CustomItem.java | 19 ++--- .../game/clans/items/GearManager.java | 68 +++++++++++------ .../mineplex/game/clans/items/ItemType.java | 2 + .../mineplex/game/clans/items/PlayerGear.java | 42 ++++++----- .../game/clans/items/RareItemFactory.java | 24 +++++- ...tauriScepter.java => MeridianScepter.java} | 16 ++-- .../game/clans/items/ui/GearPage.java | 75 ++++++++++++++----- .../classcombat/Skill/Assassin/Flash.java | 8 +- 12 files changed, 202 insertions(+), 102 deletions(-) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/{ChitauriScepter.java => MeridianScepter.java} (93%) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java index dadb62564..9dc33ddeb 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java @@ -7,6 +7,8 @@ import java.util.Random; import java.util.function.Consumer; import java.util.function.Function; +import com.google.common.collect.Lists; + public class UtilCollections { public static Random Random = new Random(); @@ -231,4 +233,9 @@ public class UtilCollections { return array[Random.nextInt(array.length)]; } + + public static Collection toList(T[] array) + { + return Lists.newArrayList(array); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index a3811e4bc..50d5a36f4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.LinkedList; import java.util.List; import org.bukkit.Location; @@ -19,10 +18,10 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.inventory.ClickType; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.Door; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; @@ -62,7 +61,6 @@ import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock; import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; import mineplex.game.clans.core.repository.ClanTerritory; import net.minecraft.server.v1_8_R3.AxisAlignedBB; -import net.minecraft.server.v1_8_R3.PacketPlayInUseEntity; public class Outpost implements Listener { @@ -185,6 +183,19 @@ public class Outpost implements Listener _nameHolograms.forEach(Hologram::start); + _nameHolograms.forEach(hologram -> { + hologram.setInteraction((player, click) -> { + UtilBlock.getInRadius(hologram.getLocation(), 2, 2).forEach((block, dist) -> { + if (block.getType() == Material.IRON_DOOR) + { + Door door = (Door) block.getState(); + + door.setOpen(!door.isOpen()); + } + }); + }); + }); + _lifetimeLeft.start(); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java index 0dda938b8..70ca881d0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/OutpostRepository.java @@ -11,17 +11,17 @@ import com.google.common.collect.Lists; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilWorld; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.column.ColumnByte; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnTimestamp; -import mineplex.core.database.column.ColumnVarChar; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.outpost.OutpostState; import mineplex.game.clans.clans.siege.outpost.OutpostType; import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnByte; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnTimestamp; +import mineplex.serverdata.database.column.ColumnVarChar; public class OutpostRepository extends RepositoryBase { @@ -46,7 +46,7 @@ public class OutpostRepository extends RepositoryBase public OutpostRepository(JavaPlugin plugin, OutpostManager manager) { - super(plugin, DBPool.getAccount()); + super(DBPool.getAccount()); _manager = manager; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java index 7757c6893..84217c157 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/SiegeWeaponRepository.java @@ -11,14 +11,14 @@ import com.google.common.collect.Lists; import mineplex.core.common.util.Callback; import mineplex.core.common.util.UtilWorld; -import mineplex.core.database.DBPool; -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.column.ColumnInt; -import mineplex.core.database.column.ColumnTimestamp; -import mineplex.core.database.column.ColumnVarChar; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken; +import mineplex.serverdata.database.DBPool; +import mineplex.serverdata.database.RepositoryBase; +import mineplex.serverdata.database.column.ColumnInt; +import mineplex.serverdata.database.column.ColumnTimestamp; +import mineplex.serverdata.database.column.ColumnVarChar; public class SiegeWeaponRepository extends RepositoryBase { @@ -44,7 +44,7 @@ public class SiegeWeaponRepository extends RepositoryBase public SiegeWeaponRepository(JavaPlugin plugin, SiegeManager manager) { - super(plugin, DBPool.getAccount()); + super(DBPool.getAccount()); _manager = manager; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java index ab9a84425..37cacd5f2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java @@ -1,23 +1,22 @@ package mineplex.game.clans.items; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.UUID; -import mineplex.core.common.util.UtilInv; -import mineplex.game.clans.items.attributes.AttributeContainer; -import mineplex.game.clans.items.attributes.ItemAttribute; -import mineplex.minecraft.game.core.damage.CustomDamageEvent; - import org.bukkit.ChatColor; import org.bukkit.Material; -import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilServer; +import mineplex.game.clans.items.attributes.AttributeContainer; +import mineplex.game.clans.items.attributes.ItemAttribute; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + /** * Represents a customizable wrapper for an {@link ItemStack}, enabling the * possession of special abilities, attributes, and triggers on item. @@ -25,7 +24,7 @@ import org.bukkit.inventory.meta.ItemMeta; * @author MrTwiggy * */ -public class CustomItem +public class CustomItem implements Listener { private static final ChatColor TITLE_COLOR = ChatColor.GOLD; // Chat color @@ -69,6 +68,8 @@ public class CustomItem _material = material; _attributes = new AttributeContainer(); _uuid = UUID.randomUUID().toString(); + + UtilServer.registerEvents(this); } public CustomItem(Material material) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 63464da3c..0a324e4de 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -16,6 +16,9 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.java.JavaPlugin; @@ -59,13 +62,16 @@ import mineplex.game.clans.items.attributes.weapon.SharpAttribute; import mineplex.game.clans.items.commands.GearCommand; import mineplex.game.clans.items.economy.GoldToken; import mineplex.game.clans.items.legendaries.AlligatorsTooth; -import mineplex.game.clans.items.legendaries.ChitauriScepter; import mineplex.game.clans.items.legendaries.EnergyCrossbow; import mineplex.game.clans.items.legendaries.GiantsBroadsword; import mineplex.game.clans.items.legendaries.HyperAxe; import mineplex.game.clans.items.legendaries.LegendaryItem; import mineplex.game.clans.items.legendaries.MagneticMaul; +import mineplex.game.clans.items.legendaries.MeridianScepter; import mineplex.game.clans.items.legendaries.WindBlade; +import mineplex.game.clans.items.rares.Crossbow; +import mineplex.game.clans.items.rares.RareItem; +import mineplex.game.clans.items.rares.RunedPickaxe; import mineplex.game.clans.items.smelting.SmeltingListener; import mineplex.game.clans.items.ui.GearShop; import mineplex.serverdata.serialization.RuntimeTypeAdapterFactory; @@ -101,18 +107,21 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable // currently in Creative gamemode // Legendary generation - private WeightSet> _legendaryWeights; + public WeightSet> LegendaryWeights; + + // Rare generation + public WeightSet> RareWeights; // Weapon generation - private WeightSet _weaponTypes; + public WeightSet WeaponTypes; // Armor generation - private WeightSet _armorTypes; + public WeightSet ArmorTypes; // Attribute generation - private WeightSet> _weaponAttributes; - private WeightSet> _armorAttributes; - private WeightSet> _bowAttributes; + public WeightSet> WeaponAttributes; + public WeightSet> ArmorAttributes; + public WeightSet> BowAttributes; // Attribute Masks private EnumSet _maskAttributes; @@ -138,24 +147,26 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable new Weight(23, ItemType.BOW)); // Weapon-based attributes - _weaponAttributes = new WeightSet>(FrostedAttribute.class, SharpAttribute.class, JaggedAttribute.class, HasteAttribute.class, FlamingAttribute.class, ConqueringAttribute.class); + WeaponAttributes = new WeightSet>(FrostedAttribute.class, SharpAttribute.class, JaggedAttribute.class, HasteAttribute.class, FlamingAttribute.class, ConqueringAttribute.class); // Armor-based attributes - _armorAttributes = new WeightSet>(SlantedAttribute.class, ReinforcedAttribute.class, ConqueringArmorAttribute.class, PaddedAttribute.class, LavaAttribute.class); + ArmorAttributes = new WeightSet>(SlantedAttribute.class, ReinforcedAttribute.class, ConqueringArmorAttribute.class, PaddedAttribute.class, LavaAttribute.class); // Bow-based attributes - _bowAttributes = new WeightSet>(HeavyArrowsAttribute.class, HuntingAttribute.class, InverseAttribute.class, LeechingAttribute.class, RecursiveAttribute.class, ScorchingAttribute.class, SlayingAttribute.class); + BowAttributes = new WeightSet>(HeavyArrowsAttribute.class, HuntingAttribute.class, InverseAttribute.class, LeechingAttribute.class, RecursiveAttribute.class, ScorchingAttribute.class, SlayingAttribute.class); // Weapon material types - _weaponTypes = new WeightSet(Material.DIAMOND_SWORD, Material.GOLD_SWORD, Material.IRON_SWORD, Material.DIAMOND_AXE, Material.GOLD_AXE, Material.IRON_AXE); + WeaponTypes = new WeightSet(Material.DIAMOND_SWORD, Material.GOLD_SWORD, Material.IRON_SWORD, Material.DIAMOND_AXE, Material.GOLD_AXE, Material.IRON_AXE); // Armor material types - _armorTypes = new WeightSet(Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS, Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS); + ArmorTypes = new WeightSet(Material.DIAMOND_HELMET, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_LEGGINGS, Material.DIAMOND_BOOTS, Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, Material.IRON_BOOTS, Material.GOLD_HELMET, Material.GOLD_CHESTPLATE, Material.GOLD_LEGGINGS, Material.GOLD_BOOTS); // TODO: Initialize list of attributes and types // Initialize various LegendaryItem types - _legendaryWeights = new WeightSet>(ChitauriScepter.class, EnergyCrossbow.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); + LegendaryWeights = new WeightSet>(MeridianScepter.class, EnergyCrossbow.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); + + RareWeights = new WeightSet>(RunedPickaxe.class, Crossbow.class); // TODO: Add rest of legendaries, find better way? // Register listeners @@ -165,15 +176,15 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable // Initialize attribute types factory for JSON handling of polymorphism. RuntimeTypeAdapterFactory attributeFactory = RuntimeTypeAdapterFactory.of(ItemAttribute.class); - for (Class attributeType : _armorAttributes.elements()) + for (Class attributeType : ArmorAttributes.elements()) { attributeFactory.registerSubtype(attributeType); } - for (Class attributeType : _weaponAttributes.elements()) + for (Class attributeType : WeaponAttributes.elements()) { attributeFactory.registerSubtype(attributeType); } - for (Class attributeType : _bowAttributes.elements()) + for (Class attributeType : BowAttributes.elements()) { attributeFactory.registerSubtype(attributeType); } @@ -184,7 +195,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable customItemType.registerSubtype(CustomItem.class); customItemType.registerSubtype(LegendaryItem.class); customItemType.registerSubtype(GoldToken.class); - for (Class itemType : _legendaryWeights.elements()) + for (Class itemType : LegendaryWeights.elements()) { customItemType.registerSubtype(itemType); } @@ -240,6 +251,15 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable } } + @EventHandler + public void quit(PlayerQuitEvent event) + { + if (_playerGears.get(event.getPlayer().getName()) != null) + { + HandlerList.unregisterAll(_playerGears.get(event.getPlayer().getName()).getWeapon()); + } + } + /** * @param player - the player whose {@link PlayerGear} set is to be fetched. * @return the cached or newly instantiated {@link PlayerGear} associated @@ -266,15 +286,15 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable if (itemType == ItemType.LEGENDARY) { - factory.setLegendary(_legendaryWeights.generateRandom()); + factory.setLegendary(LegendaryWeights.generateRandom()); } else if (itemType == ItemType.ARMOR) { - factory.setType(_armorTypes.generateRandom()); + factory.setType(ArmorTypes.generateRandom()); } else if (itemType == ItemType.WEAPON) { - factory.setType(_weaponTypes.generateRandom()); + factory.setType(WeaponTypes.generateRandom()); } else if (itemType == ItemType.BOW) { @@ -325,13 +345,13 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable switch (type) { case ARMOR: - sampleAttribute = instantiate(_armorAttributes.generateRandom()); + sampleAttribute = instantiate(ArmorAttributes.generateRandom()); break; case WEAPON: - sampleAttribute = instantiate(_weaponAttributes.generateRandom()); + sampleAttribute = instantiate(WeaponAttributes.generateRandom()); break; case BOW: - sampleAttribute = instantiate(_bowAttributes.generateRandom()); + sampleAttribute = instantiate(BowAttributes.generateRandom()); break; default: break; @@ -551,7 +571,7 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable } } - if (ci != null && _legendaryWeights.elements().contains(ci.getClass())) + if (ci != null && LegendaryWeights.elements().contains(ci.getClass())) { lore.add(C.cWhite + "Original Owner: " + C.cYellow + (ci.OriginalOwner == null ? "You" : Bukkit.getOfflinePlayer(UUID.fromString(ci.OriginalOwner)).getName())); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemType.java index 4d854879a..bcd0f9def 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ItemType.java @@ -4,6 +4,8 @@ public enum ItemType { LEGENDARY, + RARE, + ARMOR, WEAPON, diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java index a57bdc824..2496da4b9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/PlayerGear.java @@ -5,6 +5,7 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.inventory.ItemStack; @@ -29,11 +30,11 @@ public class PlayerGear private String _playerName; // Name of player who owns the gear // Cached custom item information for player's gear - private CustomItem weapon; - private CustomItem helmet; - private CustomItem chestplate; - private CustomItem leggings; - private CustomItem boots; + private CustomItem _weapon; + private CustomItem _helmet; + private CustomItem _chestplate; + private CustomItem _leggings; + private CustomItem _boots; /** * Class constructor @@ -160,60 +161,61 @@ public class PlayerGear { ItemStack weaponItem = getPlayer().getInventory().getItemInHand(); - if (!itemsMatch(weapon, weaponItem)) + if (!itemsMatch(_weapon, weaponItem)) { - weapon = parseItem(weaponItem); + HandlerList.unregisterAll(_weapon); + _weapon = parseItem(weaponItem); } - return weapon; + return _weapon; } public CustomItem getHelmet() { ItemStack helmetItem = getPlayer().getInventory().getHelmet(); - if (!itemsMatch(helmet, helmetItem)) + if (!itemsMatch(_helmet, helmetItem)) { - helmet = parseItem(helmetItem); + _helmet = parseItem(helmetItem); } - return helmet; + return _helmet; } public CustomItem getChestplate() { ItemStack chestplateItem = getPlayer().getInventory().getChestplate(); - if (!itemsMatch(chestplate, chestplateItem)) + if (!itemsMatch(_chestplate, chestplateItem)) { - chestplate = parseItem(chestplateItem); + _chestplate = parseItem(chestplateItem); } - return chestplate; + return _chestplate; } public CustomItem getLeggings() { ItemStack leggingsItem = getPlayer().getInventory().getLeggings(); - if (!itemsMatch(leggings, leggingsItem)) + if (!itemsMatch(_leggings, leggingsItem)) { - leggings = parseItem(leggingsItem); + _leggings = parseItem(leggingsItem); } - return leggings; + return _leggings; } public CustomItem getBoots() { ItemStack bootsItem = getPlayer().getInventory().getBoots(); - if (!itemsMatch(boots, bootsItem)) + if (!itemsMatch(_boots, bootsItem)) { - boots = parseItem(bootsItem); + _boots = parseItem(bootsItem); } - return boots; + return _boots; } /** diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/RareItemFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/RareItemFactory.java index a2723f7e6..7f1af9015 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/RareItemFactory.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/RareItemFactory.java @@ -3,9 +3,9 @@ package mineplex.game.clans.items; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import mineplex.core.common.util.UtilInv; import mineplex.game.clans.items.attributes.ItemAttribute; import mineplex.game.clans.items.legendaries.LegendaryItem; +import mineplex.game.clans.items.rares.RareItem; /** * Quick little guide on how to use this thing: @@ -75,6 +75,28 @@ public class RareItemFactory return this; } + public RareItemFactory setRare(Class rare) + { + if (_itemType.equals(ItemType.RARE)) + { + try + { + _item = rare.newInstance(); + _material = _item.getMaterial(); + } + catch (InstantiationException | IllegalAccessException e) + { + e.printStackTrace(); + } + } + else + { + throw new RuntimeException("Unexpected call to setRare(RareType)"); + } + + return this; + } + public RareItemFactory setSuperPrefix(Class superPrefix) { _superPrefix = superPrefix; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java similarity index 93% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java index ff6f46913..70f37273a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/ChitauriScepter.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java @@ -1,7 +1,5 @@ package mineplex.game.clans.items.legendaries; -import java.util.Random; - import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -29,16 +27,16 @@ import mineplex.core.common.util.UtilText; import mineplex.core.recharge.Recharge; import mineplex.game.clans.clans.ClansManager; -public class ChitauriScepter extends LegendaryItem +public class MeridianScepter extends LegendaryItem { private long _lastFire = System.currentTimeMillis(); private long _interactWait; private RGBData[] colors = { UtilColor.RgbLightBlue, UtilColor.RgbLightBlue.Lighten(), UtilColor.RgbLightBlue.Darken() }; - public ChitauriScepter() + public MeridianScepter() { - super("Chitauri Scepter", UtilText.splitLinesToArray(new String[] { + super("Meridian Scepter", UtilText.splitLinesToArray(new String[] { C.cWhite + "Legend says " + " ", "#" + C.cYellow + "Right-Click" + C.cWhite + " to use Scepter." @@ -50,7 +48,7 @@ public class ChitauriScepter extends LegendaryItem { if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) { - if (Recharge.Instance.use(wielder, "Chitauri Scepter", 4000, true, true)) + if (Recharge.Instance.use(wielder, "Meridian Scepter", 4000, true, true)) { fire(wielder); @@ -95,10 +93,10 @@ public class ChitauriScepter extends LegendaryItem { ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, player, null, DamageCause.CUSTOM, damage, true, true, false, - player.getName(), "Chitauri Scepter"); + player.getName(), "Meridian Scepter"); - UtilPlayer.message(entity, F.main("Clans", F.elem(entity.getName()) + " hit you with a " + F.elem("Chitauri Scepter") + C.mBody + ".")); - UtilPlayer.message(player, F.main("Clans", "You hit " + F.elem(player.getName()) + " with your " + F.elem("Chitauri Scepter") + C.mBody + ".")); + UtilPlayer.message(entity, F.main("Clans", F.elem(entity.getName()) + " hit you with a " + F.elem("Meridian Scepter") + C.mBody + ".")); + UtilPlayer.message(player, F.main("Clans", "You hit " + F.elem(player.getName()) + " with your " + F.elem("Meridian Scepter") + C.mBody + ".")); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java index e2d96b6ec..d8e9f8ebe 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java @@ -14,6 +14,7 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Pair; import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilCollections; import mineplex.core.common.util.UtilUI; import mineplex.core.donation.DonationManager; import mineplex.core.shop.item.IButton; @@ -42,13 +43,16 @@ import mineplex.game.clans.items.attributes.weapon.HasteAttribute; import mineplex.game.clans.items.attributes.weapon.JaggedAttribute; import mineplex.game.clans.items.attributes.weapon.SharpAttribute; import mineplex.game.clans.items.legendaries.AlligatorsTooth; -import mineplex.game.clans.items.legendaries.ChitauriScepter; import mineplex.game.clans.items.legendaries.EnergyCrossbow; import mineplex.game.clans.items.legendaries.GiantsBroadsword; import mineplex.game.clans.items.legendaries.HyperAxe; import mineplex.game.clans.items.legendaries.LegendaryItem; import mineplex.game.clans.items.legendaries.MagneticMaul; +import mineplex.game.clans.items.legendaries.MeridianScepter; import mineplex.game.clans.items.legendaries.WindBlade; +import mineplex.game.clans.items.rares.Crossbow; +import mineplex.game.clans.items.rares.RareItem; +import mineplex.game.clans.items.rares.RunedPickaxe; public class GearPage extends ShopPageBase { @@ -76,6 +80,7 @@ public class GearPage extends ShopPageBase private List> _bowSuffixes; private List> _legendaryItems; + private List> _rareItems; private List _weaponTypes; private List _armorTypes; @@ -100,7 +105,9 @@ public class GearPage extends ShopPageBase } }; - _legendaryItems = Arrays.> asList(ChitauriScepter.class, EnergyCrossbow.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); + _legendaryItems = Arrays.> asList(MeridianScepter.class, EnergyCrossbow.class, AlligatorsTooth.class, WindBlade.class, GiantsBroadsword.class, HyperAxe.class, MagneticMaul.class); + + _rareItems = Arrays.> asList(Crossbow.class, RunedPickaxe.class); _armorSuperPrefixes = Arrays.> asList(LavaAttribute.class); _armorPrefixes = Arrays.> asList(PaddedAttribute.class, ReinforcedAttribute.class, SlantedAttribute.class); @@ -143,7 +150,7 @@ public class GearPage extends ShopPageBase { Triple stage2 = doStageTwo(); - if (stage2.getLeft()) + if (stage2.getLeft().booleanValue()) { return; } @@ -158,7 +165,7 @@ public class GearPage extends ShopPageBase { Triple stage3 = doStageThree(); - if (stage3.getLeft()) + if (stage3.getLeft().booleanValue()) { return; } @@ -216,8 +223,10 @@ public class GearPage extends ShopPageBase { String stageTitle; + int[] indices = UtilUI.getIndicesFor(4, 1, 1); + stageTitle = "1. Select Item Type"; - addButton(9 + 1, Material.GOLD_RECORD, 0, C.cGold + "Legendary", new IButton() + addButton(indices[0], Material.GOLD_RECORD, 0, C.cGold + "Legendary", new IButton() { public void onClick(Player player, ClickType clickType) { @@ -227,17 +236,17 @@ public class GearPage extends ShopPageBase } }, _factory != null && ItemType.LEGENDARY.equals(_factory.getItemType()), new String[] { _factory != null && ItemType.LEGENDARY.equals(_factory.getItemType()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" }); - addButton(9 + 3, Material.DIAMOND_AXE, 0, C.cDAqua + "Weapon", new IButton() + addButton(indices[1], Material.RECORD_8, 0, C.cAqua + "Rare", new IButton() { public void onClick(Player player, ClickType clickType) { - _factory = RareItemFactory.begin(ItemType.WEAPON); + _factory = RareItemFactory.begin(ItemType.RARE); performNext(); buildPage(); } - }, _factory != null && ItemType.WEAPON.equals(_factory.getItemType()), new String[] { _factory != null && ItemType.WEAPON.equals(_factory.getItemType()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" }); + }, _factory != null && ItemType.RARE.equals(_factory.getItemType()), new String[] { _factory != null && ItemType.RARE.equals(_factory.getItemType()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" }); - addButton(9 + 5, Material.DIAMOND_CHESTPLATE, 0, C.cDGreen + "Armor", new IButton() + addButton(indices[2], Material.DIAMOND_CHESTPLATE, 0, C.cDGreen + "Armor", new IButton() { public void onClick(Player player, ClickType clickType) { @@ -247,7 +256,7 @@ public class GearPage extends ShopPageBase } }, _factory != null && ItemType.ARMOR.equals(_factory.getItemType()), new String[] { _factory != null && ItemType.ARMOR.equals(_factory.getItemType()) ? C.cGreen + "Selected" : C.cRed + "Not Selected" }); - addButton(9 + 7, Material.BOW, 0, C.cDGreen + "Bow", new IButton() + addButton(indices[3], Material.BOW, 0, C.cDGreen + "Bow", new IButton() { public void onClick(Player player, ClickType clickType) { @@ -264,15 +273,47 @@ public class GearPage extends ShopPageBase { String stageTitle = "Fatal Error"; Material stageMaterial = null; - boolean _return = false; + boolean $return = false; if (_factory == null || _factory.getItemType() == null) { performBack(); - return Triple.of(true, stageTitle, stageMaterial); + return Triple.of(Boolean.valueOf(true), stageTitle, stageMaterial); } - if (_factory.getItemType().equals(ItemType.LEGENDARY)) + if (_factory.getItemType().equals(ItemType.RARE)) + { + stageTitle = "2. Select Rare Item"; + stageMaterial = _factory.getMaterial() == null ? stageMaterial : _factory.getMaterial(); + + int[] indices = UtilUI.getIndicesFor(_rareItems.size(), 1); + + int index = 0; + for (final Class rare : _rareItems) + { + final RareItem item = rare.newInstance(); + + List lore = new ArrayList<>(); + + lore.addAll(UtilCollections.toList(item.getDescription())); + + lore.add(" "); + lore.add(item.getDisplayName().equals(_factory.getWrapper() == null ? null : _factory.getWrapper().getDisplayName()) ? C.cGreen + "Selected" : C.cRed + "Not Selected"); + + addButton(indices[index], item.toItemStack().getType(), 0, C.cGold + item.getDisplayName(), new IButton() + { + public void onClick(Player player, ClickType clickType) + { + _factory.setRare(rare); + performNext(); + buildPage(); + } + }, item.getDisplayName().equals(_factory.getWrapper() == null ? null : _factory.getWrapper().getDisplayName()), lore.toArray(new String[lore.size()])); + + index++; + } + } + else if (_factory.getItemType().equals(ItemType.LEGENDARY)) { stageTitle = "2. Select Legendary Item"; stageMaterial = _factory.getMaterial() == null ? stageMaterial : _factory.getMaterial(); @@ -371,13 +412,13 @@ public class GearPage extends ShopPageBase _factory.setType(Material.BOW); _stage = 2; buildPage(); - _return = true; + $return = true; break; } } } - return Triple.of(_return, stageTitle, stageMaterial); + return Triple.of(Boolean.valueOf($return), stageTitle, stageMaterial); } private Triple doStageThree() throws InstantiationException, IllegalAccessException @@ -387,7 +428,7 @@ public class GearPage extends ShopPageBase if (_factory.getMaterial() == null) { performBack(); - return Triple.of(true, null, null); + return Triple.of(Boolean.valueOf(true), null, null); } Material stageMaterial = _factory.getMaterial(); @@ -483,7 +524,7 @@ public class GearPage extends ShopPageBase } } - return Triple.of(false, stageTitle, stageMaterial); + return Triple.of(Boolean.valueOf(false), stageTitle, stageMaterial); } private Pair doStageFour() throws InstantiationException, IllegalAccessException diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java index 494900104..1c1d66311 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java @@ -158,15 +158,11 @@ public class Flash extends SkillActive if(aboveTargetData <= 7) aboveTargetSlabIsBottom = true; } - // Doors - if (UtilItem.is(newTarget.getBlock(), UtilItem.ItemCategory.DOOR)) - break; - - if ((!newTargetSlabIsBottom && UtilBlock.fullSolid(newTarget.getBlock())) || (!aboveTargetSlabIsBottom && UtilBlock.fullSolid(aboveTarget.getBlock()))) + if ((!newTargetSlabIsBottom && !UtilItem.isBoundless(aboveTarget.getBlock().getType()) || (!aboveTargetSlabIsBottom && !UtilItem.isBoundless(aboveTarget.getBlock().getType())))) break; //Progress Forwards - curRange += 0.2; + curRange += 0.1; //Smoke Trail UtilParticle.PlayParticle(ParticleType.FIREWORKS_SPARK, newTarget.clone().add(0, 0.5, 0), 0, 0, 0, 0, 1, From ae42aaaab13f5e3aba4f22f735b38b7dac22c4f3 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Mon, 7 Mar 2016 03:25:22 +0000 Subject: [PATCH 118/122] Sammy changes + cleanup --- .../mineplex/core/common/util/UtilColor.java | 2 + .../mineplex/core/common/util/UtilShapes.java | 2 +- .../mineplex/core/common/util/UtilTrig.java | 56 +++ .../game/clans/clans/ClansDisplay.java | 12 +- .../game/clans/clans/ClansManager.java | 12 +- .../clans/clans/commands/ClansCommand.java | 60 +-- .../clans/gui/button/ClanTerritoryButton.java | 12 +- .../elements/ScoreboardElementPlayer.java | 8 +- .../game/clans/clans/siege/SiegeManager.java | 24 +- .../clans/clans/siege/outpost/Outpost.java | 80 +-- .../clans/siege/outpost/OutpostManager.java | 104 ++-- .../game/clans/clans/siege/weapon/Cannon.java | 10 +- .../clans/clans/siege/weapon/Catapult.java | 8 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 456 ++++++------------ .../game/clans/items/GearManager.java | 6 + .../items/legendaries/EnergyCrossbow.java | 29 +- .../items/legendaries/MeridianScepter.java | 11 +- .../game/clans/items/ui/GearPage.java | 4 +- .../classcombat/Skill/Assassin/Flash.java | 34 +- 19 files changed, 375 insertions(+), 555 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java index 3af6afcee..6be674535 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilColor.java @@ -10,6 +10,8 @@ public class UtilColor public static final RGBData RgbRed = hexToRgb(0xee0100); public static final RGBData RgbGold = hexToRgb(0xffd014); public static final RGBData RgbLightBlue = hexToRgb(0x61fff7); + public static final RGBData RgbLightRed = hexToRgb(0xeb1c1c); + public static final RGBData RgbPurple = hexToRgb(0x9c17a3); public static byte chatColorToClayData(ChatColor chatColor) { diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java index dfff5bd5c..0498625e4 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilShapes.java @@ -51,7 +51,7 @@ public class UtilShapes return circleblocks; } - + /** * Gets the block at the exact corners, will return a diagonal. * diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java index fd0f566e7..5eb5311f5 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilTrig.java @@ -1,8 +1,10 @@ package mineplex.core.common.util; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import org.bukkit.Location; import org.bukkit.util.Vector; public class UtilTrig @@ -21,4 +23,58 @@ public class UtilTrig return list; } + + public static ArrayList GetSpherePoints(Location loc, double radius, double height, boolean hollow, double addition) + { + ArrayList circleblocks = new ArrayList(); + double cx = loc.getBlockX(); + double cy = loc.getBlockY(); + double cz = loc.getBlockZ(); + + for (double y = cy - radius; y < cy + radius; y += addition) + { + for (double x = cx - radius; x <= cx + radius; x += addition) + { + for (double z = cz - radius; z <= cz + radius; z += addition) + { + double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (cy - y) * (cy - y); + + if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1))) + { + Location l = new Location(loc.getWorld(), x, y, z); + circleblocks.add(l); + } + } + } + } + + return circleblocks; + } + + public static List GetSpherePoints(Vector vector, double radius, double height, boolean hollow, double addition) + { + List circleblocks = new ArrayList<>(); + double cx = vector.getX(); + double cy = vector.getY(); + double cz = vector.getZ(); + + for (double y = cy - radius; y < cy + radius; y += addition) + { + for (double x = cx - radius; x <= cx + radius; x += addition) + { + for (double z = cz - radius; z <= cz + radius; z += addition) + { + double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (cy - y) * (cy - y); + + if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1))) + { + Vector l = new Vector(x, y, z); + circleblocks.add(l); + } + } + } + } + + return circleblocks; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java index 284264f3b..17d27fc9c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java @@ -118,12 +118,12 @@ public class ClansDisplay extends MiniPlugin if (relation == ClanRelation.ALLY_TRUST) ownerString += " " + C.mBody + "(" + C.mElem + "Trusted" + C.mBody + ")"; } - if (_clansManager.getNetherManager().isInNether(player)) - { - _clansManager.message(player, "You are not allowed to claim territory in " + F.clansNether("The Nether") + "."); - - ownerString = C.cRed + "The Nether"; - } +// if (_clansManager.getNetherManager().isInNether(player)) +// { +// _clansManager.message(player, "You are not allowed to claim territory in " + F.clansNether("The Nether") + "."); +// +// ownerString = C.cRed + "The Nether"; +// } UtilTextMiddle.display("", ownerString, 0, 25, 10, player); UtilPlayer.message(player, F.main("Territory", ownerString)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 1b489c5a2..5a30b025f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -162,7 +162,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati private GearManager _gearManager; private LootManager _lootManager; private DonationManager _donationManager; - private NetherManager _netherManager; +// private NetherManager _netherManager; private Playtime _playTracker; @@ -386,7 +386,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); new SiegeManager(this); - _netherManager = new NetherManager(this); +// _netherManager = new NetherManager(this); } @Override @@ -1194,10 +1194,10 @@ public class ClansManager extends MiniClientPluginimplements IRelati return _clanDataAccess.getRepository().getServerId(); } - public NetherManager getNetherManager() - { - return _netherManager; - } +// public NetherManager getNetherManager() +// { +// return _netherManager; +// } public void message(Player player, String message) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 9c6257294..2997af3b7 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -364,12 +364,12 @@ public class ClansCommand extends CommandBase public void stuck(final Player caller) { - if (_clansManager.getNetherManager().isInNether(caller)) - { - _clansManager.message(caller, "You are not allowed to free yourself in " + F.clansNether("The Nether") + "."); - - return; - } +// if (_clansManager.getNetherManager().isInNether(caller)) +// { +// _clansManager.message(caller, "You are not allowed to free yourself in " + F.clansNether("The Nether") + "."); +// +// return; +// } if (DelayedTask.Instance.HasTask(caller, "Spawn Teleport")) { @@ -810,24 +810,24 @@ public class ClansCommand extends CommandBase return; } - if (_clansManager.getNetherManager().isInNether(caller)) - { - _clansManager.message(caller, "You are not allowed to claim territory in " + F.clansNether("The Nether") + "."); - - return; - } +// if (_clansManager.getNetherManager().isInNether(caller)) +// { +// _clansManager.message(caller, "You are not allowed to claim territory in " + F.clansNether("The Nether") + "."); +// +// return; +// } Plugin.getClanUtility().claim(caller); } public void unclaim(Player caller, String[] args) { - if (_clansManager.getNetherManager().isInNether(caller)) - { - _clansManager.message(caller, "You are not allowed to unclaim territory in " + F.clansNether("The Nether") + "."); - - return; - } +// if (_clansManager.getNetherManager().isInNether(caller)) +// { +// _clansManager.message(caller, "You are not allowed to unclaim territory in " + F.clansNether("The Nether") + "."); +// +// return; +// } if (args.length > 1) { @@ -967,12 +967,12 @@ public class ClansCommand extends CommandBase return; } - if (_clansManager.getNetherManager().isInNether(caller)) - { - _clansManager.message(caller, "You are not allowed to set your Clan Home in " + F.clansNether("The Nether") + "."); - - return; - } +// if (_clansManager.getNetherManager().isInNether(caller)) +// { +// _clansManager.message(caller, "You are not allowed to set your Clan Home in " + F.clansNether("The Nether") + "."); +// +// return; +// } if (clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.LEADER && clan.getMembers().get(caller.getUniqueId()).getRole() != ClanRole.ADMIN) { @@ -1096,12 +1096,12 @@ public class ClansCommand extends CommandBase if (clan == null) return; - if (_clansManager.getNetherManager().isInNether(caller)) - { - _clansManager.message(caller, "You are currently in " + F.clansNether("The Nether") + "."); - - return; - } +// if (_clansManager.getNetherManager().isInNether(caller)) +// { +// _clansManager.message(caller, "You are currently in " + F.clansNether("The Nether") + "."); +// +// return; +// } _clansManager.getTutorials().sendTutorialMsg(caller, clan.mTerritory()); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java index a18156e4c..27c4ac02e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/gui/button/ClanTerritoryButton.java @@ -23,12 +23,12 @@ public class ClanTerritoryButton extends ClanButton @Override public void onClick(Player player, ClickType clickType) { - if (_clansManager.getNetherManager().isInNether(player)) - { - _clansManager.message(player, "You are not allowed to do anything with Territory while in " + F.clansNether("The Nether") + "."); - player.closeInventory(); - return; - } +// if (_clansManager.getNetherManager().isInNether(player)) +// { +// _clansManager.message(player, "You are not allowed to do anything with Territory while in " + F.clansNether("The Nether") + "."); +// player.closeInventory(); +// return; +// } if (clickType == ClickType.LEFT) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java index ec93dc660..e110c98eb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/scoreboard/elements/ScoreboardElementPlayer.java @@ -45,10 +45,10 @@ public class ScoreboardElementPlayer implements ScoreboardElement } - if (_clansManager.getNetherManager().isInNether(player)) - { - regionString = C.cRed + "The Nether"; - } +// if (_clansManager.getNetherManager().isInNether(player)) +// { +// regionString = C.cRed + "The Nether"; +// } output.add(regionString); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index 03b8d45b2..390d47a32 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -170,12 +170,12 @@ public class SiegeManager extends MiniPlugin public boolean trySpawnCannon(Player player, Location location) { - if (_clansManager.getNetherManager().isInNether(player)) - { - _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); - - return false; - } +// if (_clansManager.getNetherManager().isInNether(player)) +// { +// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); +// +// return false; +// } if (!_clansManager.isInClan(player)) { @@ -205,12 +205,12 @@ public class SiegeManager extends MiniPlugin public boolean trySpawnCatapult(Player player, Location location) { - if (_clansManager.getNetherManager().isInNether(player)) - { - _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); - - return false; - } +// if (_clansManager.getNetherManager().isInNether(player)) +// { +// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); +// +// return false; +// } if (!_clansManager.isInClan(player)) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index 50d5a36f4..a80c02da9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -66,7 +66,6 @@ public class Outpost implements Listener { protected static final long MAX_LIFETIME = 30 * 60 * 1000; // 30 minutes public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.NETHERRACK, 1).setRawTitle(C.cBlue + "Outpost").setLore(C.cWhite + "It appears to be a contraption of some sort!").build(); - public static final byte OUTPOST_BLOCK_DATA = (byte) 137; public static final long PREP_TIME = 2 * 60 * 1000; @@ -139,20 +138,11 @@ public class Outpost implements Listener { public void onClick(Player player, ClickType clickType) { - if (_ownerClan.isMember(player)) - { + if (_ownerClan.isMember(player) || _state != OutpostState.LIVE) return; - } - - if (_state != OutpostState.LIVE) - { - return; - } if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) - { kill(); - } } }); @@ -183,8 +173,8 @@ public class Outpost implements Listener _nameHolograms.forEach(Hologram::start); - _nameHolograms.forEach(hologram -> { - hologram.setInteraction((player, click) -> { + _nameHolograms.forEach(hologram -> + hologram.setInteraction((player, click) -> UtilBlock.getInRadius(hologram.getLocation(), 2, 2).forEach((block, dist) -> { if (block.getType() == Material.IRON_DOOR) { @@ -192,9 +182,9 @@ public class Outpost implements Listener door.setOpen(!door.isOpen()); } - }); - }); - }); + }) + ) + ); _lifetimeLeft.start(); } @@ -246,20 +236,11 @@ public class Outpost implements Listener { public void onClick(Player player, ClickType clickType) { - if (_ownerClan.isMember(player)) - { + if (_ownerClan.isMember(player) || _state != OutpostState.LIVE) return; - } - - if (_state != OutpostState.LIVE) - { - return; - } if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) - { kill(); - } } }); @@ -294,24 +275,16 @@ public class Outpost implements Listener do { if (event.getClickedBlock() == null) - { break; - } if (event.getAction() != Action.RIGHT_CLICK_BLOCK) - { break; - } if (!UtilItem.isDoor(event.getClickedBlock().getType())) - { break; - } if (_ownerClan.isMember(event.getPlayer())) - { break; - } if (UtilAlg.inBoundingBox(event.getClickedBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { @@ -323,23 +296,18 @@ public class Outpost implements Listener } if (getState() != OutpostState.AWAITING) - { return; - } if (!UtilEvent.isAction(event, ActionType.R_BLOCK)) - { return; - } if (getLifetime() <= 2000) - { return; - } if (!_ownerClan.equals(_ownerClan.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!")); + return; } if (event.getClickedBlock() != null && _origin.equals(event.getClickedBlock().getLocation())) @@ -365,13 +333,9 @@ public class Outpost implements Listener UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); if (getState() == OutpostState.AWAITING) - { cleanup(); - } else - { kill(); - } event.setCancelled(true); } @@ -400,13 +364,9 @@ public class Outpost implements Listener UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); if (getState() == OutpostState.AWAITING) - { cleanup(); - } else - { kill(); - } event.setCancelled(true); return; @@ -416,7 +376,7 @@ public class Outpost implements Listener { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not break blocks in Outposts.")); event.setCancelled(true); - }; + } } @EventHandler @@ -433,9 +393,7 @@ public class Outpost implements Listener public void onBlockPlace(BlockPlaceEvent event) { if (event.isCancelled()) - { return; - } if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) { @@ -471,23 +429,15 @@ public class Outpost implements Listener RGBData color = UtilColor.RgbLightBlue; for (int x = -_type._size; x <= _type._size; x++) - { for (int z = -_type._size; z <= _type._size; z++) - { if (x == -_type._size || x == _type._size || z == -_type._size || z == _type._size) - { UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, UtilBlock.getHighest(_origin.getWorld(), _origin.clone().add(x + .5, .1, z + .5).getBlockX(), _origin.clone().add(x + .5, .1, z + .5).getBlockZ()).getLocation().add(0.5, 0, 0.5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL); - } - } - } return; } if (_lifetimeLeft != null) - { _lifetimeLeft.setText("Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME - (System.currentTimeMillis() - _timeSpawned)))); - } if (_state == OutpostState.CONSTRUCTING) { @@ -502,24 +452,16 @@ public class Outpost implements Listener Iterator iterator = _buildQueue.keySet().iterator(); if (iterator.hasNext()) - { _buildQueue.remove(iterator.next()).set(); - } } // Forcefield RGBData color = UtilColor.RgbLightBlue; for (int x = _forceFieldStart.getBlockX(); x <= _forceFieldEnd.getBlockX(); x++) - { for (int z = _forceFieldStart.getBlockZ(); z <= _forceFieldEnd.getBlockZ(); z++) - { if (x == _forceFieldStart.getBlockX() || x == _forceFieldEnd.getBlockX() || z == _forceFieldStart.getBlockZ() || z == _forceFieldEnd.getBlockZ()) - { UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, new Location(_core.getWorld(), x + .5, UtilBlock.getHighest(_core.getWorld(), x, z).getY() + .15, z + .5), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.NORMAL); - } - } - } } RGBData next = _fader.next(); @@ -551,9 +493,7 @@ public class Outpost implements Listener public void forcefield(UpdateEvent event) { if (event.getType() != UpdateType.FAST || getState() != OutpostState.CONSTRUCTING) - { return; - } UtilServer.getPlayersCollection().stream() .filter(player -> !_ownerClan.isMember(player)) @@ -583,7 +523,6 @@ public class Outpost implements Listener //Inform nearby Clans for (int chunkX = -3; chunkX < 3; chunkX++) - { for (int chunkZ = -3; chunkZ < 3; chunkZ++) { ClanTerritory territory = _ownerClan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); @@ -596,7 +535,6 @@ public class Outpost implements Listener UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray()); } } - } _nameHolograms.forEach(Hologram::start); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index e600554c1..e2076a611 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -57,7 +57,7 @@ public class OutpostManager extends MiniPlugin _clansManager = clansManager; - _repository= new OutpostRepository(clansManager.getPlugin(), this); + _repository = new OutpostRepository(clansManager.getPlugin(), this); _removalQueue = new ArrayList<>(); } @@ -66,26 +66,18 @@ public class OutpostManager extends MiniPlugin public void onPlaceBlock(BlockPlaceEvent event) { if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) - { - if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_I)) - { - event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); - } - else - { + if (!spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_III)) event.setCancelled(true); - } - } } public boolean spawnOutpost(Player player, Location location, OutpostType type) { - if (_clansManager.getNetherManager().isInNether(player)) - { - _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); - - return false; - } +// if (_clansManager.getNetherManager().isInNether(player)) +// { +// _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); +// +// return false; +// } if (!_clansManager.isInClan(player)) { @@ -129,7 +121,6 @@ public class OutpostManager extends MiniPlugin } for (int x = -4; x < 4; x++) - { for (int z = -4; z < 4; z++) { Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); @@ -145,12 +136,10 @@ public class OutpostManager extends MiniPlugin } } } - } boolean gut = false; for (int x = -6; x < 6; x++) - { for (int z = -6; z < 6; z++) { Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); @@ -168,7 +157,6 @@ public class OutpostManager extends MiniPlugin } } } - } /* das ist schlecht */ if (!gut) @@ -178,9 +166,7 @@ public class OutpostManager extends MiniPlugin } for (int x = -type._size; x < type._size; x++) - { for (int y = -1; y < type._ySize; y++) - { for (int z = -type._size; z < type._size; z++) { Location loc = location.clone().add(x, y, z); @@ -191,8 +177,6 @@ public class OutpostManager extends MiniPlugin return false; } } - } - } _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); _idToOutpost.put(_outposts.get(clan.getName()).getUniqueId(), _outposts.get(clan.getName())); @@ -204,67 +188,43 @@ public class OutpostManager extends MiniPlugin public void onBlockFall(EntityChangeBlockEvent event) { if (event.getEntity().hasMetadata("ClansOutpost")) - { event.setCancelled(true); - } } @EventHandler public void onClaim(PlayerClaimTerritoryEvent event) { for (Outpost outpost : _outposts.values()) - { if (outpost.getBounds().b(UtilAlg.toBoundingBox(event.getClaimedChunk().getBlock(0, 0, 0).getLocation(), event.getClaimedChunk().getBlock(15, 254, 15).getLocation()))) { event.setCancelled(true); UtilPlayer.message(event.getClaimer(), F.main("Clans", "You cannot claim this territory as it overlaps with " + F.elem(outpost.getOwner().getName()) + "'s Outpost.")); break; } - } } @EventHandler public void update(UpdateEvent event) { - for (Outpost outpost : _outposts.values()) - { - if (outpost.getState() != OutpostState.DEAD) - { - if (outpost.getState() == OutpostState.CONSTRUCTING ? event.getType() == UpdateType.TICK : event.getType() == UpdateType.TICK) - { - outpost.update(); - } - } - } + _outposts.values() + .stream() + .filter(outpost -> outpost.getState() == OutpostState.CONSTRUCTING ? event.getType() == UpdateType.TICK : event.getType() == UpdateType.TICK) + .forEach(Outpost::update); if (event.getType() == UpdateType.FASTER) - { if (!_removalQueue.isEmpty()) - { HandlerList.unregisterAll(_idToOutpost.remove(Integer.valueOf(_outposts.remove(_removalQueue.remove(0)).getUniqueId()))); - } - } if (event.getType() == UpdateType.TWOSEC) - { - for (Outpost outpost : _outposts.values()) - { - if (outpost.getState() == OutpostState.LIVE && outpost.getLifetime() > Outpost.MAX_LIFETIME) - { - outpost.kill(); - } - } - } + _outposts.values() + .stream() + .filter(outpost -> outpost.getState() == OutpostState.LIVE && outpost.getLifetime() > Outpost.MAX_LIFETIME) + .forEach(Outpost::kill); } public Outpost Get(ClanInfo clan) { - if (clan == null) - { - return null; - } - - return _outposts.get(clan.getName().toLowerCase()); + return clan == null ? null : _outposts.get(clan.getName().toLowerCase()); } public void queueForRemoval(String name) @@ -316,10 +276,7 @@ public class OutpostManager extends MiniPlugin }); if (post != null) - { post.run(); - } - }); } @@ -327,33 +284,28 @@ public class OutpostManager extends MiniPlugin { final Stack queue = new Stack<>(); - for (final Outpost outpost : _outposts.values()) - { + _outposts.values().forEach(outpost -> { final OutpostToken token = outpost.toToken(); - queue.push(() -> { - _repository.updateOutpost(token); - }); - } - - runAsync(() -> { - while (!queue.isEmpty()) - { - queue.pop().run(); - } + queue.push(() -> _repository.updateOutpost(token)); }); runAsync(() -> { - _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> { + while (!queue.isEmpty()) + queue.pop().run(); + }); + + runAsync(() -> + _repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> tokens.forEach(token -> { if (!_idToOutpost.containsKey(Integer.valueOf(token.UniqueId))) { System.out.println("[OUTPOSTS] OUTPOST [" + token.UniqueId + "] NO LONGER EXISTS, DELETING"); _repository.deleteOutpost(token.UniqueId); } - }); - }); - }); + }) + ) + ); } public OutpostRepository getRepository() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 03327d6e0..aab98a18e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -312,7 +312,7 @@ public class Cannon extends SiegeWeapon } @Override - public void Fire(WeaponProjectile projectile) + public void CustomFire(WeaponProjectile projectile) { projectile.setLocation(projectile.getLocation().add(.0, .2, .0)); @@ -321,7 +321,7 @@ public class Cannon extends SiegeWeapon } @Override - public String getNextState() + public String GetNextState() { if (getAmmunition() > 0) { @@ -337,7 +337,7 @@ public class Cannon extends SiegeWeapon } @Override - protected void Tick() + protected void CustomTick() { updateInventory(); @@ -348,7 +348,7 @@ public class Cannon extends SiegeWeapon } @Override - protected double[] getProjectileVelocity() + protected double[] GetProjectileVelocity() { int firepower = getPowerLevel(); @@ -371,7 +371,7 @@ public class Cannon extends SiegeWeapon yAdd = 0.6; } - return new double[] { hMult, yAdd }; + return new double[] { yAdd, hMult }; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java index a4999c956..6a22a4030 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Catapult.java @@ -249,7 +249,7 @@ public class Catapult extends SiegeWeapon } @Override - public void Fire(WeaponProjectile projectile) + public void CustomFire(WeaponProjectile projectile) { projectile.setLocation(projectile.getLocation().add(.0, 2.7, .0)); @@ -257,7 +257,7 @@ public class Catapult extends SiegeWeapon } @Override - public String getNextState() + public String GetNextState() { if (System.currentTimeMillis() - _lastFired < 4500) { @@ -273,7 +273,7 @@ public class Catapult extends SiegeWeapon } @Override - protected void Tick() + protected void CustomTick() { if (getProjectile() != null) { @@ -282,7 +282,7 @@ public class Catapult extends SiegeWeapon } @Override - protected double[] getProjectileVelocity() + protected double[] GetProjectileVelocity() { int firepower = getPowerLevel(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 92270185b..150bc4d45 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -61,71 +61,69 @@ import mineplex.game.clans.items.legendaries.WindBlade; public abstract class SiegeWeapon implements Listener { + // Constants + protected final int _maxHealth; + protected final byte _weaponTypeIdentifier; + + // Managers protected ClansManager _clans; protected SiegeManager _siegeManager; - protected int _uniqueId; - - protected ClanInfo _ownerClan; - protected final String _name; - protected final int _maxHealth; - protected int _health; - - protected Inventory _inventory; - protected AccessRule _inventoryAccess; - - private Hologram _infoHologram; - private BarrierCollisionBox _collisionBox; + // Info + protected final int _uniqueId; + protected final ClanInfo _ownerClan; protected final Location _location; + protected final String _name; - private final NautHashMap _registeredStates; - private String _currentState; + protected int _health; + protected String _currentState; + protected boolean _alive = true; + // Mechanics protected final NautArrayList _comprisedOf; - // Friendly-name mapping to index in _comprisedOf for easier management of entities. - protected final NautHashMap _entityMapping; + protected Player _rider; + protected Inventory _inventory; + protected AccessRule _inventoryAccess; + protected BarrierCollisionBox _collisionBox; - private boolean _isRideable; - private AccessRule _mountAccess; + protected AccessRule _fireAccess; - protected int _baseDamage; - - private AccessRule _fireAccess; - - // Firing stuff - - protected boolean _invertRotation; - - private Material _firepowerType; - private Material _ammunitionType; - - private NautArrayList _firepowerSlots; - private int _ammunitionSlot; - - private int _maxAmmunition; - private int _maxFirepowerPerSlot; - - private int _boundingBoxSize; - - private ProjectileAttributes _projectileAttributes; - private WeaponProjectile _projectile; - - protected float _rotSpeed = 20.f; - - private long _lastRight = -1; - private long _lastLeft = -1; + protected int _boundingBoxSize; protected double _yaw; - protected Player _rider; + protected long _lastRight = -1; + protected long _lastLeft = -1; + protected long _lastFired = -1; - protected long _lastFired; + // Display + protected Hologram _infoHologram; - protected boolean _alive = true; + // Utility + protected final NautHashMap _registeredStates; + protected final NautHashMap _entityMapping; - protected final byte _weaponTypeIdentifier; + // Customizability + protected boolean _isRideable; + protected boolean _invertRotation; + protected AccessRule _mountAccess; + + protected float _rotSpeed = 20.f; + + protected int _ammunitionSlot; + protected Material _ammunitionType; + protected int _maxAmmunition; + + protected NautArrayList _firepowerSlots; + protected Material _firepowerType; + protected int _maxFirepowerPerSlot; + + protected int _baseDamage; + + protected ProjectileAttributes _projectileAttributes; + protected WeaponProjectile _projectile; public SiegeWeapon(int maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager) { @@ -183,77 +181,29 @@ public abstract class SiegeWeapon implements Listener _clans = clansManager; } - public int getBaseDamage() - { - return _baseDamage; - } - - public ClanInfo getOwner() - { - return _ownerClan; - } - - public ClansManager getClans() - { - return _clans; - } - - protected void damage(Player player) - { - int health = getHandDamage(player); - - removeHealth(health); - - UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 0, 10, 0, player); - } - - protected int getHandDamage(Player player) + protected int calculateDamage(Player player) { ItemStack stack = player.getItemInHand(); PlayerGear gear = _clans.getGearManager().getPlayerGear(player); if (stack == null) - { return 1; - } if (gear.getWeapon() != null && gear.getWeapon() instanceof LegendaryItem) - { if (gear.getWeapon() instanceof AlligatorsTooth) - { return 8; - } else if (gear.getWeapon() instanceof GiantsBroadsword) - { return 10; - } else if (gear.getWeapon() instanceof HyperAxe) - { return 3; - } else if (gear.getWeapon() instanceof MagneticMaul) - { return 8; - } else if (gear.getWeapon() instanceof WindBlade) - { return 7; - } - } return (int) UtilItem.getAttackDamage(stack.getType()); } - protected void ResetEntities() - { - } - - protected abstract void FindEntities(); - - protected abstract double[] getProjectileVelocity(); - - protected abstract String getNextState(); - protected void enableInventory(Inventory inventory, AccessRule accessRule) { _inventory = inventory; @@ -286,7 +236,7 @@ public abstract class SiegeWeapon implements Listener _collisionBox.registerLeft((block, player) -> handleLeftClick(player)); } - private void updateWeapon() + private void update() { if (getEntity("WEAPON") == null || getEntity("PLAYERMOUNT") == null) { @@ -295,24 +245,15 @@ public abstract class SiegeWeapon implements Listener } if (_inventory != null) - { checkInventory(); - } _rider = (Player) getEntity("PLAYERMOUNT").getPassenger(); - if (!getNextState().equals(_currentState)) - { - setState(getNextState()); - } + if (!GetNextState().equals(_currentState)) + setState(GetNextState()); - if (_projectile != null) - { - if (_projectile.hasDied()) - { - _projectile = null; - } - } + if (_projectile != null && _projectile.hasDied()) + _projectile = null; ArmorStand armorStand = (ArmorStand) getEntity("WEAPON"); double standYaw = _yaw % 360; @@ -321,43 +262,30 @@ public abstract class SiegeWeapon implements Listener { double riderYaw = (getRider().getLocation().getYaw() + (_invertRotation ? 180 : 0)) % 360; - // riderYaw = 350 and standYaw = 20 - // dif should be -30 and not 330 double dif = riderYaw - standYaw; if (dif > 180) dif -= 360; if (dif < -180) dif += 360; double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f)); - _yaw = yaw; - - armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(PreRotate(_yaw)), 0)); + armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(CustomRotate(_yaw = yaw)), 0)); } } - // Firing - protected boolean canBeFired() { return getPowerLevel() > 0 && getAmmunition() > 0 && _projectile == null; } - protected WeaponProjectile getProjectile() - { - return _projectile; - } - private void fire(Player player) { _lastFired = System.currentTimeMillis(); - double[] vel = getProjectileVelocity(); - - _projectile = new WeaponProjectile(this, _location.clone().add(.5, 0, .5), _projectileAttributes, ((ArmorStand) getEntity("WEAPON")).getHeadPose().getY(), vel[0], vel[1]); + double[] vel = GetProjectileVelocity(); _inventory.clear(); - Fire(_projectile); + CustomFire(_projectile = new WeaponProjectile(this, _location.clone().add(.5, 0, .5), _projectileAttributes, ((ArmorStand) getEntity("WEAPON")).getHeadPose().getY(), vel[0], vel[1])); } protected void setFireRule(AccessRule rule) @@ -400,65 +328,20 @@ public abstract class SiegeWeapon implements Listener _projectileAttributes = projectileAttributes; } - protected int getAmmunition() - { - ItemStack item = _inventory.getItem(_ammunitionSlot); - - if (item != null && item.getType().equals(_ammunitionType)) - { - return item.getAmount(); - } - - return 0; - } - - protected int getPowerLevel() - { - int power = 0; - - for (int slot : _firepowerSlots) - { - ItemStack item = _inventory.getItem(slot); - - if (item == null || !item.getType().equals(_firepowerType)) - { - continue; - } - - power += _inventory.getItem(slot).getAmount(); - } - - return power / 4; - } - - // Riding - - public Player getRider() - { - return _rider; - } - protected boolean isRiding(Player player) { return player.equals(getRider()); } - public int getUniqueId() - { - return _uniqueId; - } - protected void setRideable(AccessRule accessRule) { _isRideable = true; _mountAccess = accessRule; } - // Internal - public void kill() { - Cleanup(); + CustomCleanup(); _comprisedOf.forEach(Entity::remove); @@ -475,12 +358,12 @@ public abstract class SiegeWeapon implements Listener private void handleMount(Player player) { - if (!OverrideMount(player)) + if (!CustomMount(player)) { getEntity("PLAYERMOUNT").setPassenger(player); } - OnMount(player); + CustomOnMount(player); } private void handleInventoryOpen(Player player) @@ -504,7 +387,7 @@ public abstract class SiegeWeapon implements Listener _lastRight = System.currentTimeMillis(); - RightClick(player); + CustomRightClick(player); if (_isRideable && _mountAccess.allow(AccessType.RCLICK_BB, player)) { @@ -550,7 +433,7 @@ public abstract class SiegeWeapon implements Listener _lastLeft = System.currentTimeMillis(); - LeftClick(player); + CustomLeftClick(player); if (_isRideable && _mountAccess.allow(AccessType.LCLICK_BB, player)) { @@ -572,56 +455,29 @@ public abstract class SiegeWeapon implements Listener if (!_ownerClan.isMember(player)) { - damage(player); + int health = calculateDamage(player); + + removeHealth(health); + + UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 0, 10, 0, player); } } - // Methods for implementation by sub-classes - protected void Tick() - { - } - - protected void OnMount(Player player) - { - } - - protected void LeftClick(Player player) - { - } - - protected void RightClick(Player player) - { - } - - protected double PreRotate(double yaw) - { - return yaw; - } - - protected void Cleanup() - { - } - - protected void UpdateState(String state) - { - } - - protected boolean CustomDismountCheck(Player player, Entity entity) - { - return false; - } - - protected boolean OverrideMount(Player player) - { - return false; - } - - protected void Fire(WeaponProjectile projectile) - { - } - - // Entity Management + protected abstract double[] GetProjectileVelocity(); + protected abstract String GetNextState(); + protected abstract void FindEntities(); + protected void ResetEntities() { return; } + protected void CustomTick() { return; } + protected void CustomOnMount(Player player) { return; } + protected void CustomLeftClick(Player player) { return; } + protected void CustomRightClick(Player player) { return; } + protected void CustomCleanup() { return; } + protected void CustomUpdateState(String state) { return; } + protected void CustomFire(WeaponProjectile projectile) { return; } + protected double CustomRotate(double yaw) { return yaw; } + protected boolean CustomDismount(Player player, Entity entity) { return false; } + protected boolean CustomMount(Player player) { return false; } protected final void addEntity(Entity entity, String uniqueName) { @@ -645,8 +501,6 @@ public abstract class SiegeWeapon implements Listener return _entityMapping.get(uniqueName); } - // Health Management - public final int getHealth() { return _health; @@ -664,9 +518,7 @@ public abstract class SiegeWeapon implements Listener _infoHologram.setText(_name + " Health", getDisplayHealth()); if (_health == 0) - { kill(); - } } public final void removeHealth(int health) @@ -679,22 +531,13 @@ public abstract class SiegeWeapon implements Listener setHealth(_health + health); } - //State Management - public final void setState(String state) { Validate.isTrue(_registeredStates.containsKey(state), "Provided state has not yet been registered."); ((ArmorStand) getEntity("WEAPON")).setHelmet(new ItemStack(_registeredStates.get(state).getType(), 1, (short) 0, (byte) _registeredStates.get(state).getData())); - _currentState = state; - - UpdateState(state); - } - - public final String getState() - { - return _currentState; + CustomUpdateState(_currentState = state); } public final void setStateInfo(String state, WeaponStateInfo info) @@ -705,9 +548,7 @@ public abstract class SiegeWeapon implements Listener public final WeaponStateInfo getStateInfo(String state) { if (!_registeredStates.containsKey(state)) - { _registeredStates.put(state, new WeaponStateInfo(Material.STONE, (byte) 101)); - } return _registeredStates.get(state); } @@ -719,27 +560,19 @@ public abstract class SiegeWeapon implements Listener ItemStack item = _inventory.getItem(slot); if (item == null) - { continue; - } if (slot == _ammunitionSlot) { if (item.getType() != _ammunitionType) { if (CustomInventoryValid(slot, item)) - { continue; - } if (getRider() != null) - { getRider().getInventory().addItem(item); - } else - { _location.getWorld().dropItem(_location, item); - } _inventory.setItem(slot, null); } @@ -748,13 +581,9 @@ public abstract class SiegeWeapon implements Listener if (item.getAmount() > _maxAmmunition) { if (getRider() != null) - { getRider().getInventory().addItem(new ItemStack(_ammunitionType, item.getAmount() - _maxAmmunition)); - } else - { _location.getWorld().dropItem(_location, item); - } _inventory.setItem(slot, new ItemStack(_ammunitionType, _maxAmmunition)); } @@ -765,18 +594,12 @@ public abstract class SiegeWeapon implements Listener if (item.getType() != _firepowerType) { if (CustomInventoryValid(slot, item)) - { continue; - } if (getRider() != null) - { getRider().getInventory().addItem(item); - } else - { _location.getWorld().dropItem(_location, item); - } _inventory.setItem(slot, null); } @@ -785,13 +608,9 @@ public abstract class SiegeWeapon implements Listener if (item.getAmount() > _maxFirepowerPerSlot) { if (getRider() != null) - { getRider().getInventory().addItem(new ItemStack(_firepowerType, item.getAmount() - _maxFirepowerPerSlot)); - } else - { _location.getWorld().dropItem(_location, item); - } _inventory.setItem(slot, new ItemStack(_firepowerType, _maxFirepowerPerSlot)); } @@ -800,26 +619,18 @@ public abstract class SiegeWeapon implements Listener else { if (CustomInventoryValid(slot, item)) - { continue; - } if (getRider() != null) - { getRider().getInventory().addItem(item); - } else - { _location.getWorld().dropItem(_location, item); - } _inventory.setItem(slot, null); } } } - // Events - @EventHandler public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) { @@ -837,56 +648,33 @@ public abstract class SiegeWeapon implements Listener public void onDamage(EntityDamageEvent event) { if (_comprisedOf.contains(event.getEntity())) - { event.setCancelled(true); - } } @EventHandler(priority = EventPriority.HIGHEST) public void onDmg(EntityDamageByEntityEvent event) { - if (!_comprisedOf.contains(event.getEntity())) - { - return; - } - - if (event.getDamager() instanceof Player) - { + if (!_comprisedOf.contains(event.getEntity()) && event.getDamager() instanceof Player) handleLeftClick((Player) event.getDamager()); - } } @EventHandler public void onCloseInv(InventoryCloseEvent event) { if (!event.getInventory().equals(_inventory)) - { return; - } ClansManager.getInstance().runSyncLater(() -> { - if (event.getPlayer().getInventory().equals(_inventory)) - { - return; - } - - if (canBeFired()) - { + if (!event.getPlayer().getInventory().equals(_inventory) && canBeFired()) UtilTextMiddle.display(_name + " Ready", "Power Level: " + C.cGreen + UtilText.repeat("▌", getPowerLevel()) + C.cRed + UtilText.repeat("▌", _maxFirepowerPerSlot - getPowerLevel()), 20, 100, 20, (Player) event.getPlayer()); - } }, 3L); } @EventHandler public void onDismount(EntityDismountEvent event) { - if (event.getEntity() instanceof Player) - { - if (event.getDismounted().equals(getEntity("PLAYERMOUNT")) || CustomDismountCheck((Player) event.getEntity(), event.getDismounted())) - { + if (event.getEntity() instanceof Player && (event.getDismounted().equals(getEntity("PLAYERMOUNT")) || CustomDismount((Player) event.getEntity(), event.getDismounted()))) dismount((Player) event.getEntity()); - } - } } @EventHandler @@ -931,12 +719,7 @@ public abstract class SiegeWeapon implements Listener public boolean inProtection(Block block) { - if (block.getLocation().distance(_location) < _boundingBoxSize + 1.65 && block.getLocation().getY() <= _location.getY() + 2) - { - return true; - } - - return false; + return block.getLocation().distance(_location) < _boundingBoxSize + 1.65 && block.getLocation().getY() <= _location.getY() + 2; } @EventHandler @@ -953,22 +736,18 @@ public abstract class SiegeWeapon implements Listener public void chunkUnload(ChunkUnloadEvent event) { if (_comprisedOf.stream().anyMatch(entity -> entity.getLocation().getChunk().equals(event.getChunk()))) - { event.setCancelled(true); - } } @EventHandler public void update(UpdateEvent event) { if (event.getType() != UpdateType.TICK) - { return; - } - updateWeapon(); + update(); - Tick(); + CustomTick(); } public Location getLocation() @@ -980,7 +759,70 @@ public abstract class SiegeWeapon implements Listener { return _boundingBoxSize; } + + public int getBaseDamage() + { + return _baseDamage; + } + + public ClanInfo getOwner() + { + return _ownerClan; + } + + public ClansManager getClans() + { + return _clans; + } + + protected WeaponProjectile getProjectile() + { + return _projectile; + } + + protected int getAmmunition() + { + ItemStack item = _inventory.getItem(_ammunitionSlot); + + if (item != null && item.getType().equals(_ammunitionType)) + return item.getAmount(); + + return 0; + } + + protected int getPowerLevel() + { + int power = 0; + + for (int slot : _firepowerSlots) + { + ItemStack item = _inventory.getItem(slot); + + if (item == null || !item.getType().equals(_firepowerType)) + continue; + + power += _inventory.getItem(slot).getAmount(); + } + + return power / 4; + } + + public int getUniqueId() + { + return _uniqueId; + } + + public Player getRider() + { + return _rider; + } + + public final String getState() + { + return _currentState; + } + public SiegeWeaponToken toToken() { SiegeWeaponToken token = new SiegeWeaponToken(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java index 0a324e4de..79880bf9e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/GearManager.java @@ -194,12 +194,18 @@ public class GearManager extends MiniPlugin implements IPacketHandler, Runnable RuntimeTypeAdapterFactory customItemType = RuntimeTypeAdapterFactory.of(CustomItem.class); customItemType.registerSubtype(CustomItem.class); customItemType.registerSubtype(LegendaryItem.class); + customItemType.registerSubtype(RareItem.class); customItemType.registerSubtype(GoldToken.class); for (Class itemType : LegendaryWeights.elements()) { customItemType.registerSubtype(itemType); } + for (Class itemType : RareWeights.elements()) + { + customItemType.registerSubtype(itemType); + } + // Build GSON instance off factories for future serialization of items. _gson = new GsonBuilder().registerTypeAdapterFactory(attributeFactory).registerTypeAdapterFactory(customItemType).create(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java index 3b7f02f37..cd9b4d7a2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java @@ -1,6 +1,7 @@ package mineplex.game.clans.items.legendaries; import java.util.HashMap; +import java.util.List; import org.bukkit.Location; import org.bukkit.Material; @@ -14,6 +15,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.ProjectileHitEvent; +import org.bukkit.util.Vector; import mineplex.core.common.util.C; import mineplex.core.common.util.LineFormat; @@ -27,8 +29,8 @@ 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.UtilServer; -import mineplex.core.common.util.UtilShapes; import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTrig; import mineplex.core.recharge.Recharge; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; @@ -38,6 +40,14 @@ public class EnergyCrossbow extends LegendaryItem private long _lastFire = System.currentTimeMillis(); private long _interactWait; + private static List _preCalculatedSphere; + + { + ClansManager.getInstance().runAsync(() -> + _preCalculatedSphere = UtilTrig.GetSpherePoints(new Vector(0, 0, 0), 1.8d, 1.8d, true, .4d) + ); + } + public EnergyCrossbow() { super("Energy Crossbow", UtilText.splitLinesToArray(new String[] { @@ -52,7 +62,7 @@ public class EnergyCrossbow extends LegendaryItem { if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) { - if (Recharge.Instance.use(wielder, "Crossbow", 4000, true, true)) + if (Recharge.Instance.use(wielder, "Crossbow", 6500, true, true)) { fire(wielder); @@ -69,18 +79,21 @@ public class EnergyCrossbow extends LegendaryItem private Arrow _arrow; private Player _player; - private RGBData[] colors = { UtilColor.RgbLightBlue, UtilColor.RgbLightBlue.Lighten(), UtilColor.RgbLightBlue.Darken() }; + private RGBData[] colors = { UtilColor.RgbLightRed, UtilColor.RgbLightRed.Lighten(), UtilColor.RgbLightRed.Darken() }; { _player = player; Arrow arrow = _player.shootArrow(); + arrow.setVelocity(arrow.getVelocity().multiply(3.4444444444444)); + arrow.setShooter(_player); _arrow = arrow; - _player.playSound(_arrow.getLocation(), Sound.BAT_TAKEOFF, 2.f, 2.f); + _player.playSound(_arrow.getLocation(), Sound.BAT_TAKEOFF, 0.1f, 2.f); + _player.playSound(_arrow.getLocation(), Sound.ZOMBIE_WOODBREAK, 0.5f, .5f); } @EventHandler @@ -112,8 +125,10 @@ public class EnergyCrossbow extends LegendaryItem { HandlerList.unregisterAll(this); - for (Location point : UtilShapes.getSphereBlocks(_arrow.getLocation(), 1, 1, true)) - UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _arrow.getLocation().add(point), UtilCollections.random(colors).ToVector(), 1f, 0, ViewDist.MAX); + for (Vector vector : _preCalculatedSphere) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, _arrow.getLocation().add(vector), UtilColor.RgbLightRed.ToVector(), 1.0f, 0, ViewDist.MAX); + } HashMap targets = UtilEnt.getInRadius(_arrow.getLocation(), 3.d); for (LivingEntity entity : targets.keySet()) @@ -122,7 +137,7 @@ public class EnergyCrossbow extends LegendaryItem continue; ClansManager.getInstance().getDamageManager().NewDamageEvent(entity, _player, _arrow, - DamageCause.CUSTOM, 6, true, true, false, + DamageCause.CUSTOM, 8, true, true, false, _player.getName(), "Energy Crossbow"); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java index 70f37273a..2c73519e8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MeridianScepter.java @@ -32,7 +32,7 @@ public class MeridianScepter extends LegendaryItem private long _lastFire = System.currentTimeMillis(); private long _interactWait; - private RGBData[] colors = { UtilColor.RgbLightBlue, UtilColor.RgbLightBlue.Lighten(), UtilColor.RgbLightBlue.Darken() }; + private RGBData[] colors = { UtilColor.RgbPurple, UtilColor.RgbPurple.Lighten(), UtilColor.RgbPurple.Darken() }; public MeridianScepter() { @@ -104,7 +104,6 @@ public class MeridianScepter extends LegendaryItem playParticle(projectile, previousLocation); - projectile.getWorld().playSound(projectile, Sound.BAT_TAKEOFF, 1.2F, 1); cancel(); } @@ -157,15 +156,15 @@ public class MeridianScepter extends LegendaryItem direction.add(newDirection.normalize().multiply(0.01)).normalize().multiply(0.25); } - + projectile.add(direction); - + for (Entity cur : projectile.getWorld().getEntities()) { if (cur == player || !(cur instanceof LivingEntity) || (cur instanceof Player && UtilPlayer.isSpectator(cur))) continue; - + LivingEntity ent = (LivingEntity) cur; Location eLoc = ent.getLocation(); @@ -194,7 +193,7 @@ public class MeridianScepter extends LegendaryItem dingsDone++; } - projectile.getWorld().playSound(projectile, Sound.ORB_PICKUP, 0.7F, 0); + projectile.getWorld().playSound(projectile, Sound.BLAZE_BREATH, 0.2F, 1f); } } }, 0); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java index d8e9f8ebe..88af7671a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/ui/GearPage.java @@ -300,7 +300,7 @@ public class GearPage extends ShopPageBase lore.add(" "); lore.add(item.getDisplayName().equals(_factory.getWrapper() == null ? null : _factory.getWrapper().getDisplayName()) ? C.cGreen + "Selected" : C.cRed + "Not Selected"); - addButton(indices[index], item.toItemStack().getType(), 0, C.cGold + item.getDisplayName(), new IButton() + addButton(indices[index], item.toItemStack().getType(), 0, C.cAqua + item.getDisplayName(), new IButton() { public void onClick(Player player, ClickType clickType) { @@ -433,7 +433,7 @@ public class GearPage extends ShopPageBase Material stageMaterial = _factory.getMaterial(); - if (_factory.getItemType().equals(ItemType.LEGENDARY)) + if (_factory.getItemType().equals(ItemType.LEGENDARY) || _factory.getItemType().equals(ItemType.RARE)) { finish(); stageTitle = "The End"; diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java index 1c1d66311..110b30524 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Assassin/Flash.java @@ -3,11 +3,9 @@ package mineplex.minecraft.game.classcombat.Skill.Assassin; import java.util.HashMap; import org.bukkit.Bukkit; -import org.bukkit.Effect; 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.entity.Player; import org.bukkit.event.EventHandler; @@ -15,16 +13,16 @@ import org.bukkit.event.block.Action; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; -import mineplex.core.common.util.UtilItem; -import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.core.common.util.F; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; 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.updater.event.UpdateEvent; +import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.minecraft.game.classcombat.Skill.SkillActive; import mineplex.minecraft.game.classcombat.Skill.SkillFactory; import mineplex.minecraft.game.classcombat.Skill.event.SkillTeleportEvent; @@ -157,10 +155,17 @@ public class Flash extends SkillActive if(aboveTargetData <= 7) aboveTargetSlabIsBottom = true; } - - if ((!newTargetSlabIsBottom && !UtilItem.isBoundless(aboveTarget.getBlock().getType()) || (!aboveTargetSlabIsBottom && !UtilItem.isBoundless(aboveTarget.getBlock().getType())))) + + if ((!newTargetSlabIsBottom && + !UtilItem.isBoundless(aboveTarget.getBlock().getType()) + || (!aboveTargetSlabIsBottom) + && !UtilItem.isBoundless(aboveTarget.getBlock().getType()))) break; - + + if (!UtilItem.isBoundless(newTarget.getBlock().getType()) && UtilItem.isBoundless(aboveTarget.getBlock().getType()) + || !UtilItem.isBoundless(aboveTarget.getBlock().getType()) && !UtilItem.isBoundless(newTarget.getBlock().getType())) + break; + //Progress Forwards curRange += 0.1; @@ -176,7 +181,12 @@ public class Flash extends SkillActive //Destination Location loc = getDestination(player, curRange); - + + if (UtilItem.isBoundless(UtilAlg.moveForward(loc, 0.15d, player.getLocation().getYaw(), false).getBlock().getType())) + { + loc = UtilAlg.moveForward(loc, 0.25d, player.getLocation().getYaw(), true); + } + if (curRange > 0) player.teleport(loc); From 48cfe4d91c6c64ca72b5d94430df0c2ac3381e55 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 8 Mar 2016 00:27:06 +0000 Subject: [PATCH 119/122] fixed & inv see? --- .../core/common/util/UtilCollections.java | 36 +++++---- .../mineplex/core/common/util/UtilServer.java | 25 +++++- .../game/clans/clans/ClansManager.java | 4 +- .../src/mineplex/game/clans/clans/Test.java | 10 +-- .../clans/clans/commands/ClansCommand.java | 4 +- .../clans/clans/siege/outpost/Outpost.java | 2 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 2 +- .../weapon/util/BarrierCollisionBox.java | 2 +- .../game/clans/clans/stuck/StuckClient.java | 15 ---- .../stuck/commands/ClansSpawnCommand.java | 79 ------------------- .../mineplex/game/clans/items/CustomItem.java | 2 +- .../items/legendaries/EnergyCrossbow.java | 2 +- .../src/mineplex/game/clans/spawn/Spawn.java | 5 +- 13 files changed, 57 insertions(+), 131 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckClient.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java index 9dc33ddeb..5e615a9ab 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilCollections.java @@ -4,8 +4,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Random; +import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; +import java.util.stream.Stream; + +import org.bukkit.inventory.ItemStack; import com.google.common.collect.Lists; @@ -62,17 +66,6 @@ public class UtilCollections } } - public static void forEachFilter(E[] elements, Function filter, Consumer consumer) - { - for (int i = 0; i < elements.length; i++) - { - if (filter.apply(elements[i]).booleanValue()) - { - consumer.accept(elements[i]); - } - } - } - public static void forEach(E[] elements, Consumer consumer) { for (int i = 0; i < elements.length; i++) @@ -80,17 +73,20 @@ public class UtilCollections consumer.accept(elements[i]); } } + + public static void forEach(E[] elements, BiConsumer consumer) + { + for (int i = 0; i < elements.length; i++) + { + consumer.accept(Integer.valueOf(i), elements[i]); + } + } public static void addAll(E[] elements, Collection collection) { forEach(elements, collection::add); } - public static void addAll(E[] elements, Function filter, Collection collection) - { - forEachFilter(elements, filter, collection::add); - } - public static void loop(int min, int max, Consumer consumer) { for (int i = min; i < max; i++) @@ -233,9 +229,15 @@ public class UtilCollections { return array[Random.nextInt(array.length)]; } - + public static Collection toList(T[] array) { return Lists.newArrayList(array); } + + public static boolean equal(T1[] array1, T2[] array2) + { + return Arrays.equals(array1, array2); + } + } 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 0b01e4bb0..08315ef41 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 @@ -8,14 +8,15 @@ import java.util.LinkedList; import java.util.List; import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; public class UtilServer @@ -92,11 +93,16 @@ public class UtilServer return (double)getPlayers().length / (double)UtilServer.getServer().getMaxPlayers(); } - public static void registerEvents(Listener listener) + public static void RegisterEvents(Listener listener) { getPluginManager().registerEvents(listener, getPlugin()); } + public static void Unregister(Listener listener) + { + HandlerList.unregisterAll(listener); + } + public static Plugin getPlugin() { return getPluginManager().getPlugins()[0]; @@ -116,4 +122,19 @@ public class UtilServer { runnable.runTaskTimer(getPlugin(), time, time); } + + public static boolean IsOnline(String name) + { + return !UtilStreams.IsEmpty(getPlayersCollection().stream().filter(player -> player.getName().equals(name))); + } + + public static Player GetPlayer(String name) + { + return UtilStreams.GetFirst(getPlayersCollection().stream().filter(player -> player.getName().equals(name))); + } + + public static OfflinePlayer GetOffline(String player) + { + return getServer().getOfflinePlayer(player); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 5a30b025f..33896b83b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -82,9 +82,9 @@ import mineplex.game.clans.clans.commands.RegionsCommand; import mineplex.game.clans.clans.data.PlayerClan; import mineplex.game.clans.clans.event.ClansPlayerDeathEvent; import mineplex.game.clans.clans.gui.ClanShop; +import mineplex.game.clans.clans.invsee.Invsee; import mineplex.game.clans.clans.loot.LootManager; import mineplex.game.clans.clans.map.ItemMapManager; -import mineplex.game.clans.clans.nether.NetherManager; import mineplex.game.clans.clans.observer.ObserverManager; import mineplex.game.clans.clans.playtime.Playtime; import mineplex.game.clans.clans.potato.PotatoManager; @@ -260,6 +260,8 @@ public class ClansManager extends MiniClientPluginimplements IRelati new TntGeneratorManager(plugin, this); new SupplyDropManager(plugin, this); + new Invsee(this); + _explosion = new Explosion(plugin, blockRestore); _warPointEvasion = new WarPointEvasion(plugin); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java index 8b3dde1d7..96de74f98 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/Test.java @@ -1,17 +1,15 @@ package mineplex.game.clans.clans; +import java.io.File; import java.io.IOException; -import org.bukkit.Location; - -import mineplex.core.common.util.UtilWorld; +import mineplex.core.common.util.UtilOfflinePlayer; public class Test { public static void main(String[] args) throws IOException { - System.out.println(UtilWorld.locToStr(new Location(null, 30, 30, 30))); - - + System.out.println("wtf"); + UtilOfflinePlayer.loadOfflineInventory(new File("M:/Clans/a797d3ef-dd25-4e18-a002-6537b19b3603.dat")); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 2997af3b7..a10f9498d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -927,7 +927,7 @@ public class ClansCommand extends CommandBase DelayedTask.Instance.doDelay(caller, "Home Teleport", new Callback() { public void run(DelayedTaskClient player) { - Recharge.Instance.use(caller, "Home Teleport", 5 * 60 * 1000, true, false); + Recharge.Instance.use(caller, "Home Teleport", 30 * 60 * 1000, true, false); // Do Plugin.getTeleport().TP(caller, clan.getHome().add(0, 1, 0)); @@ -945,7 +945,7 @@ public class ClansCommand extends CommandBase { UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); } - }, (Plugin.getClanUtility().getClaim(caller.getLocation()) != null ? 30 : 20) * 1000, false); + }, 15 * 1000, false); } public void homeSet(Player caller) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index a80c02da9..332ec8f47 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -229,7 +229,7 @@ public class Outpost implements Listener Collections.reverse(reverse); _reverseCircleStages = new LoopIterator(reverse); - UtilServer.registerEvents(this); + UtilServer.RegisterEvents(this); _lifetimeLeft = new Hologram(outpostManager.getClansManager().getHologramManager(), _origin.clone().add(0.5, 1.5, 0.5), "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME))); _lifetimeLeft.setInteraction(new HologramInteraction() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 150bc4d45..b5edf7e9c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -144,7 +144,7 @@ public abstract class SiegeWeapon implements Listener _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); _infoHologram.start(); - UtilServer.registerEvents(this); + UtilServer.RegisterEvents(this); _clans = clansManager; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/BarrierCollisionBox.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/BarrierCollisionBox.java index 3d5dcb0cf..f450df88a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/BarrierCollisionBox.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/util/BarrierCollisionBox.java @@ -54,7 +54,7 @@ public class BarrierCollisionBox implements Listener { setBlocks(); - UtilServer.registerEvents(this); + UtilServer.RegisterEvents(this); } public void Destruct() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckClient.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckClient.java deleted file mode 100644 index ab5a8b285..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/StuckClient.java +++ /dev/null @@ -1,15 +0,0 @@ -package mineplex.game.clans.clans.stuck; - -import org.bukkit.Location; - -public class StuckClient -{ - public Location StartLoc = null; - public long UnstickStartTime = -1; - public long UnstickEndTime = -1; - - public long getTimeLeft() - { - return UnstickEndTime - System.currentTimeMillis(); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java deleted file mode 100644 index c060a8000..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/stuck/commands/ClansSpawnCommand.java +++ /dev/null @@ -1,79 +0,0 @@ -package mineplex.game.clans.clans.stuck.commands; - -import org.bukkit.entity.Player; - -import mineplex.core.command.CommandBase; -import mineplex.core.common.Rank; -import mineplex.core.common.util.Callback; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilTextMiddle; -import mineplex.core.common.util.UtilTime; -import mineplex.core.delayedtask.DelayedTask; -import mineplex.core.delayedtask.DelayedTaskClient; -import mineplex.core.recharge.Recharge; -import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.spawn.Spawn; - -public class ClansSpawnCommand extends CommandBase -{ - public ClansSpawnCommand(Spawn spawn) - { - super(spawn, Rank.ALL, "spawn", "stuck", "unstick", "unstuck"); - } - - @Override - public void Execute(Player caller, String[] args) - { - if (DelayedTask.Instance.HasTask(caller, "Spawn Teleport")) - { - UtilPlayer.message(caller, F.main("Clans", "You are already teleporting to Spawn.")); - - return; - } - - if (!Recharge.Instance.usable(caller, "Spawn Teleport", true)) - { - return; - } - - if(ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()) != null && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Borderlands") && - !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Shops") && !ClansManager.getInstance().getClanUtility().getClaim(caller.getLocation()).Owner.equals("Spawn")) - { - UtilPlayer.message(caller, F.main("Clans", "You must be in the Wilderness/Borderlands/Shops/Spawn to use this command.")); - - return; - } - - DelayedTask.Instance.doDelay(caller, "Spawn Teleport", new Callback() { - public void run(DelayedTaskClient player) - { - // Do - - if (Math.random() < .5) - { - caller.teleport(Spawn.getEastSpawn()); - } - else - { - caller.teleport(Spawn.getWestSpawn()); - } - - Recharge.Instance.use(caller, "Spawn Teleport", 13 * 60 * 1000, false, false); - - // Inform - Plugin.getClansManager().getTutorials().sendTutorialMsg(caller, F.main("Clans", "You have been teleported to Spawn.")); - } - }, new Callback() { - public void run(DelayedTaskClient client) - { - UtilTextMiddle.display("", "Teleporting to Spawn in " + F.elem(UtilTime.MakeStr(Math.max(0, client.getTimeLeft("Spawn Teleport")))), 0, 5, 0, client.getPlayer()); - } - }, new Callback() { - public void run(DelayedTaskClient client) - { - UtilPlayer.message(client.getPlayer(), F.main("Clans", "Teleport has been cancelled due to movement.")); - } - }, 35 * 1000, false); - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java index 37cacd5f2..0f3a4f696 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/CustomItem.java @@ -69,7 +69,7 @@ public class CustomItem implements Listener _attributes = new AttributeContainer(); _uuid = UUID.randomUUID().toString(); - UtilServer.registerEvents(this); + UtilServer.RegisterEvents(this); } public CustomItem(Material material) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java index cd9b4d7a2..473627884 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/EnergyCrossbow.java @@ -73,7 +73,7 @@ public class EnergyCrossbow extends LegendaryItem private void fire(final Player player) { - UtilServer.registerEvents(new Listener() { + UtilServer.RegisterEvents(new Listener() { private Location _lastLoc; private Arrow _arrow; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java index 7ae590aa5..5cb9ed898 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/spawn/Spawn.java @@ -39,11 +39,10 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; +import mineplex.core.common.weight.WeightSet; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.clans.stuck.commands.ClansSpawnCommand; -import mineplex.core.common.weight.WeightSet; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; import mineplex.minecraft.game.classcombat.item.event.WebTossEvent; import mineplex.minecraft.game.core.condition.Condition.ConditionType; @@ -78,8 +77,6 @@ public class Spawn extends MiniPlugin _spawns = new WeightSet(getEastSpawn(), getWestSpawn()); _shops = new WeightSet(getNorthTown(), getSouthTown()); _clansManager = clansManager; - - addCommand(new ClansSpawnCommand(this)); } /** From 9953388b92b2e3725ed6a82060c575d60ca45315 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 8 Mar 2016 00:32:36 +0000 Subject: [PATCH 120/122] iunvseeeeeeeeeeee --- .../game/clans/clans/invsee/Invsee.java | 23 +++++ .../clans/invsee/commands/InvseeCommand.java | 54 +++++++++++ .../clans/invsee/ui/InvseeInventory.java | 95 +++++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/Invsee.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/commands/InvseeCommand.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/ui/InvseeInventory.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/Invsee.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/Invsee.java new file mode 100644 index 000000000..3409089ea --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/Invsee.java @@ -0,0 +1,23 @@ +package mineplex.game.clans.clans.invsee; + +import mineplex.core.MiniPlugin; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.invsee.commands.InvseeCommand; + +public class Invsee extends MiniPlugin +{ + private ClansManager _clansManager; + + public Invsee(ClansManager clansManager) + { + super("Inventory Viewer", clansManager.getPlugin()); + + _clansManager = clansManager; + } + + public void addCommands() + { + addCommand(new InvseeCommand(this)); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/commands/InvseeCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/commands/InvseeCommand.java new file mode 100644 index 000000000..a4fd436bd --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/commands/InvseeCommand.java @@ -0,0 +1,54 @@ +package mineplex.game.clans.clans.invsee.commands; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; + +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.game.clans.clans.invsee.Invsee; +import mineplex.game.clans.clans.invsee.ui.InvseeInventory; + +public class InvseeCommand extends CommandBase +{ + public InvseeCommand(Invsee plugin) + { + super(plugin, Rank.ADMIN, "invsee"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length == 0) + { + + } + else + { + String name = args[0]; + + OfflinePlayer player; + + if (UtilServer.IsOnline(name)) + { + player = UtilServer.GetPlayer(name); + } + else + { + player = UtilServer.GetOffline(name); + } + + if (player == null) + { + UtilPlayer.message(caller, F.main("Clans", "Specified player is neither online nor is offline. Perhaps they changed their name?")); + return; + } + + new InvseeInventory(player).ShowTo(caller); + } + } + + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/ui/InvseeInventory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/ui/InvseeInventory.java new file mode 100644 index 000000000..91b27a267 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/invsee/ui/InvseeInventory.java @@ -0,0 +1,95 @@ +package mineplex.game.clans.clans.invsee.ui; + +import org.bukkit.OfflinePlayer; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilServer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class InvseeInventory implements Listener +{ + private OfflinePlayer _player; + private Inventory _inventory; + + private boolean _online; + + private Player _admin; + + public InvseeInventory(OfflinePlayer player) + { + _online = (_player = player) instanceof Player; + + _inventory = UtilServer.getServer().createInventory(null, 54, player.getName() + " " + (_online ? C.cGreen + "ONLINE" : C.cRed + "OFFLINE")); + + UtilServer.RegisterEvents(this); + } + + public void ShowTo(Player admin) + { + _admin = admin; + admin.openInventory(_inventory); + } + + @EventHandler + public void quit(PlayerQuitEvent event) + { + if (_online && event.getPlayer().equals(_player)) + { + _admin.closeInventory(); + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + { + return; + } + + if (_online) + { + if (!UtilCollections.equal(_inventory.getContents(), ((Player) _player).getInventory().getContents())) + { + _inventory.setContents(((Player) _player).getInventory().getContents()); + } + } + } + + @EventHandler + public void inventoryClick(InventoryClickEvent event) + { + if (event.getClickedInventory().equals(_inventory)) + { + if (_online) + { + ((Player) _player).getInventory().setContents(_inventory.getContents()); + } + } + } + + @EventHandler + public void closeInventory(InventoryCloseEvent event) + { + if (event.getInventory().equals(_inventory)) + { + UtilServer.Unregister(this); + + if (!_online) + { + // save offline inv + } + } + } + +} From 263e3e77689fde0c2589b5cac844f518aead5f62 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 8 Mar 2016 01:07:35 +0000 Subject: [PATCH 121/122] forgot to push --- .../core/common/util/UtilOfflinePlayer.java | 29 +++++++++++++ .../core/common/util/UtilStreams.java | 42 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java new file mode 100644 index 000000000..cbc537082 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilOfflinePlayer.java @@ -0,0 +1,29 @@ +package mineplex.core.common.util; + +import java.io.File; +import java.io.FileInputStream; + +import org.bukkit.inventory.ItemStack; + +import com.java.sk89q.jnbt.NBTInputStream; +import com.java.sk89q.jnbt.NamedTag; + +public class UtilOfflinePlayer +{ + public static ItemStack loadOfflineInventory(File file) + { + try (NBTInputStream stream = new NBTInputStream(new FileInputStream(file))) + { + NamedTag tag = stream.readNamedTag(); + + System.out.println(tag); + + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java new file mode 100644 index 000000000..94774c9e8 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilStreams.java @@ -0,0 +1,42 @@ +package mineplex.core.common.util; + +import java.util.stream.Stream; + +public class UtilStreams +{ + public static boolean IsEmpty(Stream stream) + { + return Sum(stream) != 0; + } + + public static int Sum(Stream stream) + { + return stream.mapToInt(v -> 1).sum(); + } + + public static Object[] ToArray(Stream stream) + { + return stream.toArray(); + } + + public static T Get(int index, Stream stream) + { + if (Sum(stream) < index + 1) + { + return null; + } + + return (T) ToArray(stream)[index]; + } + + public static T GetFirst(Stream stream) + { + return Get(0, stream); + } + + public static T GetLast(Stream stream) + { + return Get(Sum(stream) + 1, stream); + } + +} From d86ef81056df0a261b2d85733c9aecc88aa6538d Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 8 Mar 2016 01:11:16 +0000 Subject: [PATCH 122/122] weaps oops --- .../mineplex/core/common/util/UtilServer.java | 4 +- .../game/clans/items/rares/Crossbow.java | 62 ++++++++++++ .../game/clans/items/rares/RareItem.java | 98 +++++++++++++++++++ .../game/clans/items/rares/RunedPickaxe.java | 86 ++++++++++++++++ 4 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/Crossbow.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RareItem.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RunedPickaxe.java 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 08315ef41..0d6555bec 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 @@ -19,6 +19,8 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.scheduler.BukkitRunnable; +import mineplex.core.vanish.events.PreVanishEvent; + public class UtilServer { public static Player[] getPlayers() @@ -113,7 +115,7 @@ public class UtilServer return getServer().getPluginManager(); } - public static void callEvent(Event event) + public static T callEvent(T event) { getPluginManager().callEvent(event); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/Crossbow.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/Crossbow.java new file mode 100644 index 000000000..99b983de9 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/Crossbow.java @@ -0,0 +1,62 @@ +package mineplex.game.clans.items.rares; + +import org.bukkit.Material; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilInv; +import mineplex.core.common.util.UtilText; +import mineplex.core.recharge.Recharge; + +public class Crossbow extends RareItem +{ + private static final Material LOADED_TYPE = Material.COMMAND_MINECART; + private static final Material UNLOADED_TYPE = Material.RECORD_6; + + private long _lastFire = System.currentTimeMillis(); + private long _interactWait; + + public Crossbow() + { + super("Crossbow", UtilText.splitLinesToArray(new String[] { + "#" + C.cYellow + "Right-Click" + C.cWhite + " to fire Crossbow." + }, LineFormat.LORE), UNLOADED_TYPE); + } + + @Override + public void update(Player wielder) + { + if (UtilInv.contains(wielder, Material.ARROW, (byte) 0, 1)) + { + wielder.getItemInHand().setType(LOADED_TYPE); + } + else + { + wielder.getItemInHand().setType(UNLOADED_TYPE); + } + + if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) + { + if (UtilInv.remove(wielder, Material.ARROW, (byte) 0, 1)) + { + if (Recharge.Instance.use(wielder, "Crossbow", 4000, true, true)) + { + fire(wielder); + + _interactWait = System.currentTimeMillis(); + } + } + } + } + + private void fire(final Player player) + { + Arrow arrow = player.shootArrow(); + + arrow.setShooter(player); + + _lastFire = System.currentTimeMillis(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RareItem.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RareItem.java new file mode 100644 index 000000000..a986b1840 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RareItem.java @@ -0,0 +1,98 @@ +package mineplex.game.clans.items.rares; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import mineplex.game.clans.items.CustomItem; +import mineplex.game.clans.items.generation.ValueDistribution; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; + +public class RareItem extends CustomItem +{ + public final long BLOCK_COOLDOWN = 200l; // Right clicking activates right click for 200ms + + protected long _lastBlock; // Timestamp of last block from wielder + public long timeSinceLastBlock() { return System.currentTimeMillis() - _lastBlock; } + + public RareItem(String name, String[] description, Material material) + { + super(name, description, material); + + _lastBlock = 0l; + } + + public void update(Player wielder) + { + // Leave implementation to potential subtypes + } + + public void preUpdate(Player wielder) + { + } + + public void onAttack(CustomDamageEvent event, Player wielder) + { + // Leave implementation to potential subtypes + } + + @Override + public void onAttack(CustomDamageEvent event) + { + if (event.GetDamagerPlayer(true) != null) + { + onAttack(event, event.GetDamagerPlayer(true)); + } + + super.onAttack(event); + } + + public void onInteract(PlayerInteractEvent event) + { + Action action = event.getAction(); + + if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) + { + _lastBlock = System.currentTimeMillis(); + } + + super.onInteract(event); + } + + public boolean isHoldingRightClick() + { + return timeSinceLastBlock() <= BLOCK_COOLDOWN; + } + + protected void log(String message) + { + System.out.println("[Custom Item - " + _displayName + "] " + message); + } + + /** + * @param minValue - the minimum value for attribute value range + * @param maxValue - the maximum value for attribute value range + * @return newly instantiated {@link ValueDistribution} for attribute values in range [{@code minValue}. {@code maxValue}]. + */ + public static ValueDistribution generateDistribution(double minValue, double maxValue) + { + return new ValueDistribution(minValue, maxValue); + } + + /** + * Add a {@link PotionEffect} to {@code player} with specified {@code type}, {@code amplifier} (power) and + * {@code tickDuration} of the effect. + * @param player - the player to receive the potion effect + * @param type - the type of potion to apply + * @param tickDuration - the duration (in ticks) to apply the potion for + * @param amplifier - the amplifier (level/power, zero-based) of the potion effect + */ + public static void grantPotionEffect(Player player, PotionEffectType type, int tickDuration, int amplifier) + { + player.removePotionEffect(type); + player.addPotionEffect(new PotionEffect(type, amplifier, tickDuration)); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RunedPickaxe.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RunedPickaxe.java new file mode 100644 index 000000000..b7309568b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/rares/RunedPickaxe.java @@ -0,0 +1,86 @@ +package mineplex.game.clans.items.rares; + +import org.bukkit.Effect; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockDamageEvent; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.RGBData; +import mineplex.core.common.util.UtilCollections; +import mineplex.core.common.util.UtilColor; +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.UtilShapes; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTime; +import mineplex.core.recharge.Recharge; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.items.PlayerGear; + +public class RunedPickaxe extends RareItem +{ + private long _lastFire = System.currentTimeMillis(); + private long _interactWait; + + private long _instamineEnabled; + + private RGBData[] colors = { UtilColor.RgbLightBlue, UtilColor.RgbLightBlue.Lighten(), UtilColor.RgbLightBlue.Darken() }; + + public RunedPickaxe() + { + super("Runed Pickaxe", UtilText.splitLinesToArray(new String[] { + "#" + C.cYellow + "Right-Click" + C.cWhite + " to use " + F.elem("Instant mine") + "." + }, LineFormat.LORE), Material.RECORD_8); + } + + @Override + public void update(Player wielder) + { + if ((System.currentTimeMillis() - _lastBlock) < 98 && (System.currentTimeMillis() - _interactWait) >= 98) + { + if (Recharge.Instance.use(wielder, "Instant Mine", 30000, true, true)) + { + fire(wielder); + + _interactWait = System.currentTimeMillis(); + + _instamineEnabled = System.currentTimeMillis(); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void blockDamage(BlockDamageEvent event) + { + PlayerGear gear = ClansManager.getInstance().getGearManager().getPlayerGear(event.getPlayer()); + + if (gear.getWeapon() == this && !UtilTime.elapsed(_instamineEnabled, 12000)) + { + event.setInstaBreak(true); + + event.getBlock().getWorld().playEffect(event.getBlock().getLocation(), Effect.STEP_SOUND, event.getBlock().getType(), 10); + + event.getPlayer().playSound(event.getBlock().getLocation(), Sound.LAVA_POP, 1.f, 1.f); + } + } + + private void fire(final Player player) + { + } + + private void playParticle(Location start, Location end) + { + for (Location loc : UtilShapes.getLinesDistancedPoints(start, end, 0.06)) + { + UtilParticle.PlayParticleToAll(ParticleType.RED_DUST, loc, UtilCollections.random(colors).ToVector(), 1f, 0, ViewDist.LONG); + } + } +}