From d79107eaaa5a1df68edf4c079f8798d2ce1d1c5f Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Sat, 5 Mar 2016 03:07:25 +0000 Subject: [PATCH 01/10] 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 02/10] 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 03/10] 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 04/10] 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 05/10] 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 06/10] 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 07/10] 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 08/10] 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 09/10] 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 10/10] 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); + } + } +}