From 4ac4e9d72949653caa23aad544e37f7fa7eeea40 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 30 Apr 2015 13:15:20 -0500 Subject: [PATCH 01/16] Start of world event framework --- .../artifacts/Mineplex_Game_Clans_jar.xml | 2 +- .../src/mineplex/game/clans/Clans.java | 3 + .../clans/worldevent/AbstractWorldEvent.java | 69 ++++++++++++++ .../worldevent/ConcreteWorldEventFactory.java | 26 ++++++ .../clans/worldevent/WorldEventFactory.java | 12 +++ .../clans/worldevent/WorldEventListener.java | 6 ++ .../clans/worldevent/WorldEventManager.java | 69 ++++++++++++++ .../clans/worldevent/WorldEventType.java | 6 ++ .../clans/worldevent/boss/AbstractBoss.java | 90 +++++++++++++++++++ .../clans/worldevent/boss/GiantBoss.java | 38 ++++++++ .../worldevent/command/StartCommand.java | 34 +++++++ .../worldevent/command/WorldEventCommand.java | 23 +++++ 12 files changed, 377 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/WorldEventCommand.java diff --git a/Plugins/.idea/artifacts/Mineplex_Game_Clans_jar.xml b/Plugins/.idea/artifacts/Mineplex_Game_Clans_jar.xml index 85ea6bec4..d88c9bbd4 100644 --- a/Plugins/.idea/artifacts/Mineplex_Game_Clans_jar.xml +++ b/Plugins/.idea/artifacts/Mineplex_Game_Clans_jar.xml @@ -5,7 +5,6 @@ - @@ -18,6 +17,7 @@ + \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 6c61713e8..50714d661 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -27,6 +27,7 @@ import mineplex.core.teleport.Teleport; import mineplex.core.updater.FileUpdater; import mineplex.core.updater.Updater; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.shop.building.BuildingShop; import mineplex.game.clans.shop.pvp.PvpShop; @@ -90,6 +91,8 @@ public class Clans extends JavaPlugin new Farming(this); new BuildingShop(clans, _clientManager, _donationManager); new PvpShop(clans, _clientManager, _donationManager); + + new WorldEventManager(this); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java new file mode 100644 index 000000000..42076e89b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java @@ -0,0 +1,69 @@ +package mineplex.game.clans.clans.worldevent; + +import java.util.ArrayList; +import java.util.List; + +public abstract class AbstractWorldEvent +{ + private List _listeners; + + private boolean _running; + private int _ticks; + + public AbstractWorldEvent() + { + _listeners = new ArrayList(); + } + + public final void start() + { + _running = true; + customStart(); + } + + protected abstract void customStart(); + + public final void cancel() + { + _running = false; + customCancel(); + } + + protected abstract void customCancel(); + + public void tick() + { + _ticks++; + } + + public boolean isRunning() + { + return _running; + } + + public void addListener(WorldEventListener listener) + { + _listeners.add(listener); + } + + public void removeListener(WorldEventListener listener) + { + _listeners.remove(listener); + } + + protected List getListeners() + { + return _listeners; + } + + public void clearListeners() + { + _listeners.clear(); + } + + public int getTicks() + { + return _ticks; + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java new file mode 100644 index 000000000..c44b682ef --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java @@ -0,0 +1,26 @@ +package mineplex.game.clans.clans.worldevent; + +import org.bukkit.Location; + +import mineplex.game.clans.clans.worldevent.boss.GiantBoss; + +public class ConcreteWorldEventFactory implements WorldEventFactory +{ + @Override + public AbstractWorldEvent fromName(Location location, String name) + { + return new GiantBoss(location); + } + + @Override + public AbstractWorldEvent random(Location location) + { + return null; + } + + @Override + public AbstractWorldEvent randomFromType(Location locationm, WorldEventType type) + { + return null; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java new file mode 100644 index 000000000..1c63b90f6 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java @@ -0,0 +1,12 @@ +package mineplex.game.clans.clans.worldevent; + +import org.bukkit.Location; + +public interface WorldEventFactory +{ + public AbstractWorldEvent fromName(Location location, String name); + + public AbstractWorldEvent random(Location location); + + public AbstractWorldEvent randomFromType(Location locationm, WorldEventType type); +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java new file mode 100644 index 000000000..65ccc2331 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java @@ -0,0 +1,6 @@ +package mineplex.game.clans.clans.worldevent; + +public interface WorldEventListener +{ + public void onComplete(AbstractWorldEvent event); +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java new file mode 100644 index 000000000..34e102d19 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -0,0 +1,69 @@ +package mineplex.game.clans.clans.worldevent; + +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.event.EventHandler; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.worldevent.command.WorldEventCommand; + +public class WorldEventManager extends MiniPlugin implements WorldEventListener +{ + private final WorldEventFactory _factory; + private final Set _events; + + public WorldEventManager(JavaPlugin plugin) + { + super("World Event", plugin); + + _factory = new ConcreteWorldEventFactory(); + _events = new HashSet(); + } + + private void initializeEvent(AbstractWorldEvent event) + { + assert(event != null); + + event.start(); + event.addListener(this); + _events.add(event); + } + + public AbstractWorldEvent startEventFromName(Location location, String name) + { + AbstractWorldEvent event = _factory.fromName(location, name); + if (event != null) initializeEvent(event); + return event; + } + + @Override + public void onComplete(AbstractWorldEvent event) + { + // TODO + Bukkit.broadcastMessage("World Event Manager On Complete"); + _events.remove(event); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) return; + + for (AbstractWorldEvent e : _events) + { + e.tick(); + } + } + + @Override + public void addCommands() + { + addCommand(new WorldEventCommand(this)); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java new file mode 100644 index 000000000..322130393 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java @@ -0,0 +1,6 @@ +package mineplex.game.clans.clans.worldevent; + +public enum WorldEventType +{ + BOSS_FIGHT; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java new file mode 100644 index 000000000..5f48ea7a5 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java @@ -0,0 +1,90 @@ +package mineplex.game.clans.clans.worldevent.boss; + +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilTextBottom; +import mineplex.game.clans.clans.worldevent.AbstractWorldEvent; +import mineplex.game.clans.clans.worldevent.WorldEventListener; + +public abstract class AbstractBoss extends AbstractWorldEvent +{ + private String _name; + private double _maxHealth; + private double _health; + private double _lastHealth; + + // Action Bar Messages + private Location _center; + private float _radiusSquared; + + + public AbstractBoss(String name, Location center, float radius, double maxHealth) + { + _center = center; + _name = name; + _health = maxHealth; + _maxHealth = maxHealth; + setRadius(radius); + } + + @Override + public void tick() + { + super.tick(); + + if (_lastHealth != _health || getTicks() % 20 == 0) + { + for (Player player : Bukkit.getServer().getOnlinePlayers()) + { + if (player.getWorld().equals(_center.getWorld()) && _center.distanceSquared(player.getLocation()) < _radiusSquared) + { + UtilTextBottom.displayProgress(_name, _health / _maxHealth, player); + } + } + } + + _lastHealth = _health; + + if (_health <= 0) + { + onDeath(); + for (WorldEventListener listener : getListeners()) listener.onComplete(this); + } + } + + public void setRadius(float radius) + { + _radiusSquared = radius * radius; + } + + protected abstract void onDeath(); + + protected void damage(double health) + { + _health -= health; + } + + protected void setMaxHealth(double maxHealth) + { + _maxHealth = maxHealth; + } + + public double getHealth() + { + return _health; + } + + public double getMaxHealth() + { + return _maxHealth; + } + + public boolean inRange(Location loc) + { + return loc.distanceSquared(_center) <= _radiusSquared; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java new file mode 100644 index 000000000..a2a23b334 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java @@ -0,0 +1,38 @@ +package mineplex.game.clans.clans.worldevent.boss; + +import org.bukkit.Bukkit; +import org.bukkit.Location; + +public class GiantBoss extends AbstractBoss +{ + public GiantBoss(Location center) + { + super("Giant", center, 20, 300); + } + + @Override + protected void customStart() + { + Bukkit.broadcastMessage("Custom Start"); + } + + @Override + protected void customCancel() + { + Bukkit.broadcastMessage("Custom Cancel"); + } + + @Override + public void tick() + { + super.tick(); + + damage(0.1); + } + + @Override + protected void onDeath() + { + Bukkit.broadcastMessage("GIANT DEATH"); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java new file mode 100644 index 000000000..0649bd563 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java @@ -0,0 +1,34 @@ +package mineplex.game.clans.clans.worldevent.command; + +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.game.clans.clans.worldevent.AbstractWorldEvent; +import mineplex.game.clans.clans.worldevent.WorldEventManager; + +public class StartCommand extends CommandBase +{ + public StartCommand(WorldEventManager plugin) + { + super(plugin, Rank.DEVELOPER, "start", "create"); + } + + @Override + public void Execute(Player caller, String[] args) + { + // start specific world event type + if (args != null && args.length == 1) + { + AbstractWorldEvent event = Plugin.startEventFromName(caller.getLocation(), args[0]); + if (event == null) + UtilPlayer.message(caller, F.main("WorldEvent", "Could not find a WorldEvent with the name " + F.elem(args[0]))); + else + { + UtilPlayer.message(caller, F.main("worldEvent", "Started WorldEvent " + F.elem(args[0]) + " at your current location")); + } + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/WorldEventCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/WorldEventCommand.java new file mode 100644 index 000000000..5a3e47de8 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/WorldEventCommand.java @@ -0,0 +1,23 @@ +package mineplex.game.clans.clans.worldevent.command; + +import org.bukkit.entity.Player; + +import mineplex.core.command.MultiCommandBase; +import mineplex.core.common.Rank; +import mineplex.game.clans.clans.worldevent.WorldEventManager; + +public class WorldEventCommand extends MultiCommandBase +{ + public WorldEventCommand(WorldEventManager plugin) + { + super(plugin, Rank.DEVELOPER, "worldevent", "we", "event"); + + AddCommand(new StartCommand(Plugin)); + } + + @Override + protected void Help(Player caller, String[] args) + { + + } +} From ff377a3e5c33929545d78e2155874c0f56411e9d Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 21 May 2015 15:33:02 -0500 Subject: [PATCH 02/16] [Clans] World event state system --- Plugins/.idea/misc.xml | 3 - .../clans/worldevent/AbstractWorldEvent.java | 69 ---------- .../worldevent/ConcreteWorldEventFactory.java | 6 +- .../clans/worldevent/WorldEventFactory.java | 3 + .../clans/worldevent/WorldEventListener.java | 2 + .../clans/worldevent/WorldEventManager.java | 1 + .../clans/worldevent/WorldEventType.java | 6 - .../worldevent/command/StartCommand.java | 2 +- .../worldevent/event/AbstractWorldEvent.java | 120 ++++++++++++++++++ .../worldevent/event/WorldEventType.java | 6 + .../{ => event}/boss/AbstractBoss.java | 11 +- .../boss/slime/SlimeBoss.java} | 8 +- .../event/boss/state/BossState.java | 20 +++ .../event/boss/state/SlamState.java | 27 ++++ .../worldevent/event/state/EventState.java | 39 ++++++ 15 files changed, 235 insertions(+), 88 deletions(-) delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java delete mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/WorldEventType.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/{ => event}/boss/AbstractBoss.java (79%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/{boss/GiantBoss.java => event/boss/slime/SlimeBoss.java} (67%) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java diff --git a/Plugins/.idea/misc.xml b/Plugins/.idea/misc.xml index d5107f5ca..76fba6e9f 100644 --- a/Plugins/.idea/misc.xml +++ b/Plugins/.idea/misc.xml @@ -10,7 +10,4 @@ - - - \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java deleted file mode 100644 index 42076e89b..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/AbstractWorldEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -package mineplex.game.clans.clans.worldevent; - -import java.util.ArrayList; -import java.util.List; - -public abstract class AbstractWorldEvent -{ - private List _listeners; - - private boolean _running; - private int _ticks; - - public AbstractWorldEvent() - { - _listeners = new ArrayList(); - } - - public final void start() - { - _running = true; - customStart(); - } - - protected abstract void customStart(); - - public final void cancel() - { - _running = false; - customCancel(); - } - - protected abstract void customCancel(); - - public void tick() - { - _ticks++; - } - - public boolean isRunning() - { - return _running; - } - - public void addListener(WorldEventListener listener) - { - _listeners.add(listener); - } - - public void removeListener(WorldEventListener listener) - { - _listeners.remove(listener); - } - - protected List getListeners() - { - return _listeners; - } - - public void clearListeners() - { - _listeners.clear(); - } - - public int getTicks() - { - return _ticks; - } - -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java index c44b682ef..798574ea1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java @@ -2,14 +2,16 @@ package mineplex.game.clans.clans.worldevent; import org.bukkit.Location; -import mineplex.game.clans.clans.worldevent.boss.GiantBoss; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; +import mineplex.game.clans.clans.worldevent.event.WorldEventType; +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss; public class ConcreteWorldEventFactory implements WorldEventFactory { @Override public AbstractWorldEvent fromName(Location location, String name) { - return new GiantBoss(location); + return new SlimeBoss(location); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java index 1c63b90f6..30c719f15 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventFactory.java @@ -2,6 +2,9 @@ package mineplex.game.clans.clans.worldevent; import org.bukkit.Location; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; +import mineplex.game.clans.clans.worldevent.event.WorldEventType; + public interface WorldEventFactory { public AbstractWorldEvent fromName(Location location, String name); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java index 65ccc2331..606745c7a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventListener.java @@ -1,5 +1,7 @@ package mineplex.game.clans.clans.worldevent; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; + public interface WorldEventListener { public void onComplete(AbstractWorldEvent event); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index 34e102d19..a23b9b2ec 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -12,6 +12,7 @@ import mineplex.core.MiniPlugin; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.worldevent.command.WorldEventCommand; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; public class WorldEventManager extends MiniPlugin implements WorldEventListener { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java deleted file mode 100644 index 322130393..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java +++ /dev/null @@ -1,6 +0,0 @@ -package mineplex.game.clans.clans.worldevent; - -public enum WorldEventType -{ - BOSS_FIGHT; -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java index 0649bd563..093f78807 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/command/StartCommand.java @@ -6,7 +6,7 @@ import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.game.clans.clans.worldevent.AbstractWorldEvent; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; import mineplex.game.clans.clans.worldevent.WorldEventManager; public class StartCommand extends CommandBase diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java new file mode 100644 index 000000000..d79d6f40e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java @@ -0,0 +1,120 @@ +package mineplex.game.clans.clans.worldevent.event; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.game.clans.clans.worldevent.WorldEventListener; +import mineplex.game.clans.clans.worldevent.WorldEventManager; +import mineplex.game.clans.clans.worldevent.event.state.EventState; + +public abstract class AbstractWorldEvent +{ + private WorldEventManager _eventManager; + + private List _listeners; + + private boolean _running; + private int _ticks; + private Random _random; + + // Event States + private List _states; + private int _maxTicksPerState; + private int _minTicksPerState; + private EventState _currentState; + + public AbstractWorldEvent(WorldEventManager eventManager) + { + _eventManager = eventManager; + _listeners = new ArrayList(); + _states = new ArrayList(); + _random = new Random(); + } + + public final void start() + { + _running = true; + customStart(); + } + + protected abstract void customStart(); + + public final void cancel() + { + _running = false; + customCancel(); + } + + protected abstract void customCancel(); + + public void tick() + { + _ticks++; + if (_currentState != null) _currentState.tick(); + } + + public boolean isRunning() + { + return _running; + } + + public void addListener(WorldEventListener listener) + { + _listeners.add(listener); + } + + public void removeListener(WorldEventListener listener) + { + _listeners.remove(listener); + } + + protected List getListeners() + { + return _listeners; + } + + public void clearListeners() + { + _listeners.clear(); + } + + public int getTicks() + { + return _ticks; + } + + public WorldEventManager getEventManager() + { + return _eventManager; + } + + public EventState getRandomState() + { + return _states.get(_random.nextInt(_states.size())); + } + + public void setState(EventState state) + { + JavaPlugin plugin = _eventManager.getPlugin(); + + // Unregister old state listener + HandlerList.unregisterAll(_currentState); + _currentState.onStateStop(); + + // Register new state listener + plugin.getServer().getPluginManager().registerEvents(state, plugin); + state.onStateStart(); + + _currentState = state; + } + + public void addState(EventState state) + { + _states.add(state); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/WorldEventType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/WorldEventType.java new file mode 100644 index 000000000..f5a9bc050 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/WorldEventType.java @@ -0,0 +1,6 @@ +package mineplex.game.clans.clans.worldevent.event; + +public enum WorldEventType +{ + BOSS_FIGHT; +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java similarity index 79% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java index 5f48ea7a5..5e3f133c5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/AbstractBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java @@ -1,5 +1,6 @@ -package mineplex.game.clans.clans.worldevent.boss; +package mineplex.game.clans.clans.worldevent.event.boss; +import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; @@ -7,8 +8,10 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import mineplex.core.common.util.UtilTextBottom; -import mineplex.game.clans.clans.worldevent.AbstractWorldEvent; +import mineplex.game.clans.clans.worldevent.WorldEventManager; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; import mineplex.game.clans.clans.worldevent.WorldEventListener; +import mineplex.game.clans.clans.worldevent.event.state.EventState; public abstract class AbstractBoss extends AbstractWorldEvent { @@ -21,9 +24,9 @@ public abstract class AbstractBoss extends AbstractWorldEvent private Location _center; private float _radiusSquared; - - public AbstractBoss(String name, Location center, float radius, double maxHealth) + public AbstractBoss(WorldEventManager eventManager, String name, Location center, float radius, double maxHealth) { + super(eventManager); _center = center; _name = name; _health = maxHealth; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java similarity index 67% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index a2a23b334..33171229f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/boss/GiantBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -1,11 +1,13 @@ -package mineplex.game.clans.clans.worldevent.boss; +package mineplex.game.clans.clans.worldevent.event.boss.slime; import org.bukkit.Bukkit; import org.bukkit.Location; -public class GiantBoss extends AbstractBoss +import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; + +public class SlimeBoss extends AbstractBoss { - public GiantBoss(Location center) + public SlimeBoss(Location center) { super("Giant", center, 20, 300); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java new file mode 100644 index 000000000..fc8460302 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java @@ -0,0 +1,20 @@ +package mineplex.game.clans.clans.worldevent.event.boss.state; + +import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; +import mineplex.game.clans.clans.worldevent.event.state.EventState; + +public abstract class BossState extends EventState +{ + private AbstractBoss _boss; + + public BossState(AbstractBoss boss) + { + super(boss); + _boss = boss; + } + + public AbstractBoss getBoss() + { + return _boss; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java new file mode 100644 index 000000000..83d69c229 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java @@ -0,0 +1,27 @@ +package mineplex.game.clans.clans.worldevent.event.boss.state; + +import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; + +public class SlamState extends BossState +{ + public SlamState(AbstractBoss boss) + { + super(boss); + } + + @Override + public void onTick() + { + + } + + @Override + public void onStateStart() + { + } + + @Override + public void onStateStop() + { + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java new file mode 100644 index 000000000..6a13025e4 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java @@ -0,0 +1,39 @@ +package mineplex.game.clans.clans.worldevent.event.state; + +import org.bukkit.event.Listener; + +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; + +public abstract class EventState implements Listener +{ + private AbstractWorldEvent _event; + private int _ticks; + + public EventState(AbstractWorldEvent event) + { + _event = event; + _ticks = 0; + } + + public AbstractWorldEvent getEvent() + { + return _event; + } + + public final void tick() + { + _ticks++; + onTick(); + } + + public int getTicks() + { + return _ticks; + } + + public abstract void onTick(); + + public abstract void onStateStart(); + + public abstract void onStateStop(); +} From 20fadcd187a5cc992208629f15717b08034d6eb2 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sun, 24 May 2015 01:37:16 -0500 Subject: [PATCH 03/16] [Clans] Work on world events/slime boss --- .../worldevent/ConcreteWorldEventFactory.java | 9 +- .../clans/worldevent/WorldEventManager.java | 5 +- .../worldevent/event/AbstractWorldEvent.java | 21 +++-- .../worldevent/event/boss/AbstractBoss.java | 5 ++ .../event/boss/slime/SlimeBoss.java | 53 ++++++++++- .../event/boss/state/SlamState.java | 88 ++++++++++++++++++- 6 files changed, 168 insertions(+), 13 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java index 798574ea1..79ccccc15 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java @@ -8,10 +8,17 @@ import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss; public class ConcreteWorldEventFactory implements WorldEventFactory { + private WorldEventManager _eventManager; + + public ConcreteWorldEventFactory(WorldEventManager eventManager) + { + _eventManager = eventManager; + } + @Override public AbstractWorldEvent fromName(Location location, String name) { - return new SlimeBoss(location); + return new SlimeBoss(_eventManager, location); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index a23b9b2ec..acb47ce5c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -6,6 +6,7 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; @@ -23,7 +24,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener { super("World Event", plugin); - _factory = new ConcreteWorldEventFactory(); + _factory = new ConcreteWorldEventFactory(this); _events = new HashSet(); } @@ -33,6 +34,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener event.start(); event.addListener(this); + getPlugin().getServer().getPluginManager().registerEvents(event, getPlugin()); _events.add(event); } @@ -48,6 +50,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener { // TODO Bukkit.broadcastMessage("World Event Manager On Complete"); + HandlerList.unregisterAll(event); _events.remove(event); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java index d79d6f40e..94ed1369f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java @@ -5,13 +5,14 @@ import java.util.List; import java.util.Random; import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import mineplex.game.clans.clans.worldevent.WorldEventListener; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.state.EventState; -public abstract class AbstractWorldEvent +public abstract class AbstractWorldEvent implements Listener { private WorldEventManager _eventManager; @@ -101,13 +102,19 @@ public abstract class AbstractWorldEvent { JavaPlugin plugin = _eventManager.getPlugin(); - // Unregister old state listener - HandlerList.unregisterAll(_currentState); - _currentState.onStateStop(); + if (_currentState != null) + { + // Unregister old state listener + HandlerList.unregisterAll(_currentState); + _currentState.onStateStop(); + } - // Register new state listener - plugin.getServer().getPluginManager().registerEvents(state, plugin); - state.onStateStart(); + if (state != null) + { + // Register new state listener + plugin.getServer().getPluginManager().registerEvents(state, plugin); + state.onStateStart(); + } _currentState = state; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java index 5e3f133c5..3b888a50d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java @@ -86,6 +86,11 @@ public abstract class AbstractBoss extends AbstractWorldEvent return _maxHealth; } + public Location getCenter() + { + return _center; + } + public boolean inRange(Location loc) { return loc.distanceSquared(_center) <= _radiusSquared; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index 33171229f..342c7abcd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -1,15 +1,32 @@ package mineplex.game.clans.clans.worldevent.event.boss.slime; +import java.util.List; + import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.entity.Spider; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; +import mineplex.game.clans.clans.worldevent.event.boss.state.SlamState; public class SlimeBoss extends AbstractBoss { - public SlimeBoss(Location center) + private Slime _slimeEntity; + + public SlimeBoss(WorldEventManager eventManager, Location center) { - super("Giant", center, 20, 300); + super(eventManager, "Slime King", center, 100, 300); + + _slimeEntity = center.getWorld().spawn(center, Slime.class); + _slimeEntity.setSize(10); + _slimeEntity.setMaxHealth(100); + _slimeEntity.setHealth(100); } @Override @@ -29,12 +46,42 @@ public class SlimeBoss extends AbstractBoss { super.tick(); - damage(0.1); + if (!inRange(_slimeEntity.getLocation())) + { + _slimeEntity.teleport(getCenter()); + } + + if (getTicks() % (20 * 15) == 0) + { + List nearby = _slimeEntity.getNearbyEntities(10, 10, 10); + for (Entity near : nearby) + { + if (near instanceof Player) + { + Player player = ((Player) near); + Bukkit.broadcastMessage("SLAM ON " + player.getDisplayName()); + setState(new SlamState(this, _slimeEntity, player)); + break; + } + } + } + } + + @EventHandler + public void onSlimeDamage(EntityDamageEvent event) + { + if (event.getEntity().equals(_slimeEntity)) + { + _slimeEntity.setHealth(100); + damage(20); + event.setDamage(1); + } } @Override protected void onDeath() { + _slimeEntity.setHealth(0); Bukkit.broadcastMessage("GIANT DEATH"); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java index 83d69c229..ee7566ac3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java @@ -1,23 +1,109 @@ package mineplex.game.clans.clans.worldevent.event.boss.state; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Creature; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; public class SlamState extends BossState { - public SlamState(AbstractBoss boss) + private static final int FOLLOW_TICKS = 60; + private static final int JUMP_TICKS = 80; + private static final int DIVE_TICKS = 20 * 5; + + private LivingEntity _entity; + private Player _target; + private Location _targetLocation; + + public SlamState(AbstractBoss boss, LivingEntity entity, Player target) { super(boss); + _entity = entity; + _target = target; } @Override public void onTick() { + if (getTicks() < FOLLOW_TICKS) + { + _targetLocation = _target.getLocation(); + } + else if (getTicks() == FOLLOW_TICKS) + { + Bukkit.broadcastMessage("TARGET LOCKED"); + } + else if (getTicks() == JUMP_TICKS) + { + Bukkit.broadcastMessage("SLIME BOSS JUMPED INTO THE AIR"); + } + else if (getTicks() > JUMP_TICKS && getTicks() < DIVE_TICKS) + { + Location loc = _entity.getLocation(); + loc.setDirection(loc.toVector().add(_targetLocation.toVector()).normalize()); + Vector direction = UtilAlg.getTrajectory2d(_entity.getLocation(), _targetLocation); + direction.multiply(0.4); + direction.setY(2 * (1 - ((getTicks() - 100.0) / 60.0))); + _entity.setVelocity(direction); + } + else if (getTicks() == DIVE_TICKS) + { + _entity.setVelocity(new Vector(0, -3, 0)); + } + if (_entity instanceof Creature) ((Creature) _entity).setTarget(_target); + + // display particles X + + double x = 0.5 * Math.sin(getTicks() / 10.0 * 2 * Math.PI); + double z = 0.5 * Math.cos(getTicks() / 10.0 * 2 * Math.PI); + Location loc = _targetLocation.clone().add(x, 0.1, z); + UtilParticle.PlayParticle(UtilParticle.ParticleType.FIREWORKS_SPARK, loc, 0, 0, 0, 0, 1); } + @Override public void onStateStart() { + Bukkit.broadcastMessage("Target placed on " + _target.getName()); + } + + + @EventHandler + public void onDamage(EntityDamageEvent event) + { + if (event.getEntity().equals(_entity) && event.getCause() == EntityDamageEvent.DamageCause.FALL) + { + Location fallLoc = _entity.getLocation(); + List nearby = _entity.getNearbyEntities(4, 4, 4); + for (Entity near : nearby) + { + if (near instanceof LivingEntity) + { + LivingEntity le = ((LivingEntity) near); + le.damage(4); + le.setVelocity(UtilAlg.getTrajectory2d(fallLoc, le.getLocation()).setY(0.2)); + } + } + + UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, fallLoc, 2, 0.5F, 2, 0, 100); + fallLoc.getWorld().playSound(fallLoc, Sound.ANVIL_LAND, 10, 0.5F); + + event.setCancelled(true); + getBoss().setState(null); + } } @Override From 6b10d9f3c9912d1d5b0fe390bcaed737683a5097 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 28 May 2015 15:20:43 -0500 Subject: [PATCH 04/16] [Clans] More work on world events --- .../src/mineplex/game/clans/Clans.java | 2 +- .../game/clans/clans/ClansManager.java | 12 +- .../clans/worldevent/WorldEventManager.java | 11 +- .../event/boss/state/SlamState.java | 3 +- .../worldevent/event/state/RocketState.java | 154 ++++++++++++++++++ 5 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 50714d661..353522fd0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -92,7 +92,7 @@ public class Clans extends JavaPlugin new BuildingShop(clans, _clientManager, _donationManager); new PvpShop(clans, _clientManager, _donationManager); - new WorldEventManager(this); + new WorldEventManager(this, clans); //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); 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 61753ea16..09555ab76 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -77,6 +77,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat private ClassCombatShop _classShop; private ClassManager _classManager; private WarManager _warManager; + private ProjectileManager _projectileManager; private int _inviteExpire = 2; private int _nameMin = 3; @@ -124,15 +125,15 @@ public class ClansManager extends MiniClientPlugin implements IRelat new Weapon(plugin, energy); new Gameplay(plugin, this, blockRestore, damageManager); - ProjectileManager throwManager = new ProjectileManager(plugin); + _projectileManager = new ProjectileManager(plugin); 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, throwManager, webServerAddress, itemIgnore); - SkillFactory skillManager = new SkillFactory(plugin, damageManager, this, _combatManager, _condition, throwManager, 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"); _classManager = new ClassManager(plugin, _clientManager, donationManager, skillManager, itemFactory, webServerAddress); @@ -498,6 +499,11 @@ public class ClansManager extends MiniClientPlugin implements IRelat return _warManager; } + public ProjectileManager getProjectile() + { + return _projectileManager; + } + public int convertGoldToEnergy(int gold) { return gold * 4; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index acb47ce5c..7cf801020 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -12,6 +12,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.worldevent.command.WorldEventCommand; import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; @@ -20,10 +21,13 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener private final WorldEventFactory _factory; private final Set _events; - public WorldEventManager(JavaPlugin plugin) + private ClansManager _clansManager; + + public WorldEventManager(JavaPlugin plugin, ClansManager clansManager) { super("World Event", plugin); + _clansManager = clansManager; _factory = new ConcreteWorldEventFactory(this); _events = new HashSet(); } @@ -45,6 +49,11 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener return event; } + public ClansManager getClans() + { + return _clansManager; + } + @Override public void onComplete(AbstractWorldEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java index ee7566ac3..e90098e04 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java @@ -16,6 +16,7 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilParticle; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; +import mineplex.game.clans.clans.worldevent.event.state.RocketState; public class SlamState extends BossState { @@ -102,7 +103,7 @@ public class SlamState extends BossState fallLoc.getWorld().playSound(fallLoc, Sound.ANVIL_LAND, 10, 0.5F); event.setCancelled(true); - getBoss().setState(null); + getBoss().setState(new RocketState(getBoss(), _entity)); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java new file mode 100644 index 000000000..bd4eaf780 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java @@ -0,0 +1,154 @@ +package mineplex.game.clans.clans.worldevent.event.state; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.projectile.IThrown; +import mineplex.core.projectile.ProjectileManager; +import mineplex.core.projectile.ProjectileUser; +import mineplex.core.updater.UpdateType; +import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; +import mineplex.game.clans.clans.worldevent.event.boss.state.BossState; + +public class RocketState extends BossState implements IThrown +{ + private LivingEntity _shooter; + private LinkedList _shots; + + public RocketState(AbstractBoss boss, LivingEntity shooter) + { + super(boss); + _shooter = shooter; + _shots = new LinkedList(); + } + + @Override + public void onTick() + { + if (getTicks() % 20 == 0) + { + int c = getTicks() / 20; + double mod = (c / 5.0) * Math.PI; + double x = Math.sin(mod); + double z = Math.cos(mod); + double y = -0.1; + + List entities = _shooter.getNearbyEntities(20, 20, 20); + + for (Entity e : entities) + { + if (e instanceof Player) + { +// Vector v = UtilAlg.getTrajectory(_shooter.getEyeLocation(), e.getLocation()); + fireProjectile(((Player) e)); + } + } + +// fireProjectile(new Vector(x, y, z)); + + if (c == 5) + { + getBoss().setState(null); + } + } + + Iterator it = _shots.iterator(); + + while (it.hasNext()) + { + ShotData next = it.next(); + + if (next.getEntity().isDead()) + { + it.remove(); + } + else + { + Vector v = UtilAlg.getTrajectory(next.getEntity(), next.getTarget()); + next.getEntity().setVelocity(v.multiply(new Vector(0.3, 0.1, 0.3))); + } + + } + } + + @Override + public void onStateStart() + { + + } + + @Override + public void onStateStop() + { + + } + + private void fireProjectile(LivingEntity target) + { + Location loc = _shooter.getEyeLocation(); + loc.add(loc.getDirection().normalize().multiply(2)); + Slime projectile = loc.getWorld().spawn(loc, Slime.class); + projectile.setSize(2); +// projectile.setVelocity(direction); + _shots.add(new ShotData(projectile, target)); + + ProjectileManager pm = getBoss().getEventManager().getClans().getProjectile(); + pm.AddThrow(projectile, _shooter, this, -1, true, true, true, null, 0, 0, UtilParticle.ParticleType.SLIME, UpdateType.FASTEST, 1F); + Bukkit.broadcastMessage("Shot Slime"); + } + + @Override + public void Collide(LivingEntity target, Block block, ProjectileUser data) + { + Bukkit.broadcastMessage("COLLIDE " + target); + UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + } + + @Override + public void Idle(ProjectileUser data) + { + Bukkit.broadcastMessage("IDLE"); + UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + } + + @Override + public void Expire(ProjectileUser data) + { + Bukkit.broadcastMessage("EXPIRE"); + UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + } + + private static class ShotData + { + private LivingEntity _entity; + private LivingEntity _target; + + public ShotData(LivingEntity entity, LivingEntity target) + { + _entity = entity; + _target = target; + } + + public LivingEntity getEntity() + { + return _entity; + } + + public LivingEntity getTarget() + { + return _target; + } + } +} From dc994956e11999bbf3422f5414f02d678efd2f07 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 28 May 2015 18:56:03 -0500 Subject: [PATCH 05/16] [Clans] Slime absorb work --- .../mineplex/core/common/util/UtilPlayer.java | 12 +- .../Mineplex.Game.Clans.iml | 2 +- .../src/mineplex/game/clans/Clans.java | 2 - .../game/clans/clans/ClansManager.java | 3 + .../worldevent/ConcreteWorldEventFactory.java | 2 +- .../clans/worldevent/WorldEventManager.java | 10 +- .../worldevent/event/AbstractWorldEvent.java | 22 +++- .../worldevent/event/boss/AbstractBoss.java | 9 +- .../event/boss/slime/SlimeBoss.java | 7 +- .../worldevent/event/state/AbsorbState.java | 119 ++++++++++++++++++ .../worldevent/event/state/RocketState.java | 5 +- 11 files changed, 175 insertions(+), 18 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index 322a55134..438f6660e 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -450,7 +450,7 @@ public class UtilPlayer return best; } - public static Player getClosest(Location loc, Entity ignore) + public static Player getClosest(Location loc, Entity... ignore) { Player best = null; double bestDist = 0; @@ -463,8 +463,14 @@ public class UtilPlayer if (cur.isDead()) continue; - if (ignore != null && ignore.equals(cur)) - continue; + if (ignore != null) + { + for (int i = 0; i < ignore.length; i++) + { + if (cur.equals(ignore[i])) + continue; + } + } double dist = UtilMath.offset(cur.getLocation(), loc); diff --git a/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml b/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml index 82d2e5104..f02d9d7cf 100644 --- a/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml +++ b/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml @@ -5,7 +5,6 @@ - @@ -15,5 +14,6 @@ + \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 353522fd0..b54f0b8bd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -92,8 +92,6 @@ public class Clans extends JavaPlugin new BuildingShop(clans, _clientManager, _donationManager); new PvpShop(clans, _clientManager, _donationManager); - new WorldEventManager(this, clans); - //Updates getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1); 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 09555ab76..0082036aa 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 @@ -41,6 +41,7 @@ import mineplex.game.clans.clans.repository.tokens.ClanMemberToken; import mineplex.game.clans.clans.repository.tokens.ClanTerritoryToken; import mineplex.game.clans.clans.repository.tokens.ClanToken; import mineplex.game.clans.clans.war.WarManager; +import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.fields.Field; import mineplex.game.clans.gameplay.Gameplay; import mineplex.minecraft.game.classcombat.Class.ClassManager; @@ -145,6 +146,8 @@ public class ClansManager extends MiniClientPlugin implements IRelat _warManager = new WarManager(plugin, this); ClanEnergyManager clanEnergyManager = new ClanEnergyManager(plugin, this, clientManager, donationManager); + + new WorldEventManager(plugin, this, damageManager); for (ClanToken token : _clanDataAccess.getRepository().retrieveClans()) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java index 79ccccc15..5bc8a60c9 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java @@ -18,7 +18,7 @@ public class ConcreteWorldEventFactory implements WorldEventFactory @Override public AbstractWorldEvent fromName(Location location, String name) { - return new SlimeBoss(_eventManager, location); + return new SlimeBoss(_eventManager, _eventManager.getDamage(), location); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index 7cf801020..6506db8a6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -15,6 +15,7 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.worldevent.command.WorldEventCommand; import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; +import mineplex.minecraft.game.core.damage.DamageManager; public class WorldEventManager extends MiniPlugin implements WorldEventListener { @@ -22,12 +23,14 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener private final Set _events; private ClansManager _clansManager; + private DamageManager _damageManager; - public WorldEventManager(JavaPlugin plugin, ClansManager clansManager) + public WorldEventManager(JavaPlugin plugin, ClansManager clansManager, DamageManager damageManager) { super("World Event", plugin); _clansManager = clansManager; + _damageManager = damageManager; _factory = new ConcreteWorldEventFactory(this); _events = new HashSet(); } @@ -54,6 +57,11 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener return _clansManager; } + public DamageManager getDamage() + { + return _damageManager; + } + @Override public void onComplete(AbstractWorldEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java index 94ed1369f..e381c1af0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java @@ -11,13 +11,16 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.game.clans.clans.worldevent.WorldEventListener; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.state.EventState; +import mineplex.minecraft.game.core.damage.DamageManager; public abstract class AbstractWorldEvent implements Listener { private WorldEventManager _eventManager; + private DamageManager _damageManager; private List _listeners; + private String _name; private boolean _running; private int _ticks; private Random _random; @@ -28,9 +31,11 @@ public abstract class AbstractWorldEvent implements Listener private int _minTicksPerState; private EventState _currentState; - public AbstractWorldEvent(WorldEventManager eventManager) + public AbstractWorldEvent(WorldEventManager eventManager, DamageManager damageManager, String name) { _eventManager = eventManager; + _damageManager = damageManager; + _name = name; _listeners = new ArrayList(); _states = new ArrayList(); _random = new Random(); @@ -93,6 +98,11 @@ public abstract class AbstractWorldEvent implements Listener return _eventManager; } + public DamageManager getDamageManager() + { + return _damageManager; + } + public EventState getRandomState() { return _states.get(_random.nextInt(_states.size())); @@ -119,6 +129,16 @@ public abstract class AbstractWorldEvent implements Listener _currentState = state; } + public EventState getState() + { + return _currentState; + } + + public String getName() + { + return _name; + } + public void addState(EventState state) { _states.add(state); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java index 3b888a50d..4f4f82c40 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java @@ -12,10 +12,10 @@ import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; import mineplex.game.clans.clans.worldevent.WorldEventListener; import mineplex.game.clans.clans.worldevent.event.state.EventState; +import mineplex.minecraft.game.core.damage.DamageManager; public abstract class AbstractBoss extends AbstractWorldEvent { - private String _name; private double _maxHealth; private double _health; private double _lastHealth; @@ -24,11 +24,10 @@ public abstract class AbstractBoss extends AbstractWorldEvent private Location _center; private float _radiusSquared; - public AbstractBoss(WorldEventManager eventManager, String name, Location center, float radius, double maxHealth) + public AbstractBoss(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth) { - super(eventManager); + super(eventManager, damageManager, name); _center = center; - _name = name; _health = maxHealth; _maxHealth = maxHealth; setRadius(radius); @@ -45,7 +44,7 @@ public abstract class AbstractBoss extends AbstractWorldEvent { if (player.getWorld().equals(_center.getWorld()) && _center.distanceSquared(player.getLocation()) < _radiusSquared) { - UtilTextBottom.displayProgress(_name, _health / _maxHealth, player); + UtilTextBottom.displayProgress(getName(), _health / _maxHealth, player); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index 342c7abcd..9a10b6345 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -14,14 +14,15 @@ import org.bukkit.event.entity.EntityDamageEvent; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; import mineplex.game.clans.clans.worldevent.event.boss.state.SlamState; +import mineplex.minecraft.game.core.damage.DamageManager; public class SlimeBoss extends AbstractBoss { private Slime _slimeEntity; - public SlimeBoss(WorldEventManager eventManager, Location center) + public SlimeBoss(WorldEventManager eventManager, DamageManager damageManager, Location center) { - super(eventManager, "Slime King", center, 100, 300); + super(eventManager, damageManager, "Slime King", center, 100, 300); _slimeEntity = center.getWorld().spawn(center, Slime.class); _slimeEntity.setSize(10); @@ -51,7 +52,7 @@ public class SlimeBoss extends AbstractBoss _slimeEntity.teleport(getCenter()); } - if (getTicks() % (20 * 15) == 0) + if (getState() == null && getTicks() % (20 * 15) == 0) { List nearby = _slimeEntity.getNearbyEntities(10, 10, 10); for (Entity near : nearby) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java new file mode 100644 index 000000000..d01ee854d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java @@ -0,0 +1,119 @@ +package mineplex.game.clans.clans.worldevent.event.state; + +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; +import mineplex.game.clans.clans.worldevent.event.boss.state.BossState; + +public class AbsorbState extends BossState +{ + private Slime _entity; + private boolean _hasRider; + private int _riderTickCount; + private int _ticksPerPulse; + private int _pulseCount; + private int _slimeSize; + + public AbsorbState(AbstractBoss boss, Slime entity, int ticksPerPulse) + { + super(boss); + _entity = entity; + _pulseCount = 10; + _hasRider = false; + _riderTickCount = 0; + _ticksPerPulse = ticksPerPulse; + _slimeSize = entity.getSize(); + } + + @Override + public void onTick() + { + if (!_hasRider) + { + int mod = getTicks() % _ticksPerPulse; + + if (mod == 0) + { + pulse(); + _pulseCount++; + _entity.setSize(_slimeSize); + UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, _entity.getLocation(), 2F, 2F, 2F, 0, 50); + _entity.getWorld().playSound(_entity.getLocation(), Sound.SLIME_WALK, 0.5F, 1); + } + else if (mod > _ticksPerPulse - 10) + { + int ticksLeft = _ticksPerPulse - mod; + _entity.setSize(_entity.getSize() + 1); + + int count = 20 + (10 - ticksLeft); + for (int i = 0; i < count; i++) + { + double radius = (10 - ticksLeft) * 2; + double q = i / 10.0 * Math.PI; + double x = radius * Math.sin(q); + double z = radius * Math.cos(q); + Location loc = _entity.getLocation().clone(); + loc.add(x, 0.2, z); + UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10); + } + } + + // Check rider + if (getTicks() % 5 == 0) + { + Player closest = UtilPlayer.getClosest(_entity.getLocation()); + if (closest != null) + { + double dist = closest.getLocation().distance(_entity.getLocation()); + if (dist < 5) + { + _entity.setPassenger(closest); + _hasRider = true; + } + } + } + } + else + { + // Check for rider + } + } + + private void pulse() + { + Bukkit.broadcastMessage("Pulse"); + List nearby = UtilPlayer.getNearby(_entity.getLocation(), 20); + + for (Player player : nearby) + { + Vector dir = UtilAlg.getTrajectory2d(player, _entity); + dir.setY(0.4); + player.setVelocity(dir); + getBoss().getDamageManager().NewDamageEvent(player, _entity, null, EntityDamageEvent.DamageCause.MAGIC, 1.0, + false, false, false, getBoss().getName(), "Absorb"); + } + } + + @Override + public void onStateStart() + { + + } + + @Override + public void onStateStop() + { + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java index bd4eaf780..e1fc1f994 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java @@ -60,7 +60,7 @@ public class RocketState extends BossState implements IThrown if (c == 5) { - getBoss().setState(null); + getBoss().setState(new AbsorbState(getBoss(), ((Slime) _shooter), 20 * 2)); } } @@ -114,6 +114,7 @@ public class RocketState extends BossState implements IThrown { Bukkit.broadcastMessage("COLLIDE " + target); UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + data.GetThrown().remove(); } @Override @@ -121,6 +122,7 @@ public class RocketState extends BossState implements IThrown { Bukkit.broadcastMessage("IDLE"); UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + data.GetThrown().remove(); } @Override @@ -128,6 +130,7 @@ public class RocketState extends BossState implements IThrown { Bukkit.broadcastMessage("EXPIRE"); UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + data.GetThrown().remove(); } private static class ShotData From 68b708e32e457265b012e0baa6d5426edaf7ddd4 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Fri, 29 May 2015 18:23:46 -0500 Subject: [PATCH 06/16] Schematic Utilities for Clans --- Plugins/.idea/misc.xml | 2 +- .../src/com/java/sk89q/jnbt/ByteArrayTag.java | 57 +++ .../src/com/java/sk89q/jnbt/ByteTag.java | 49 ++ .../src/com/java/sk89q/jnbt/CompoundTag.java | 420 +++++++++++++++++ .../java/sk89q/jnbt/CompoundTagBuilder.java | 204 +++++++++ .../src/com/java/sk89q/jnbt/DoubleTag.java | 50 ++ .../src/com/java/sk89q/jnbt/EndTag.java | 37 ++ .../src/com/java/sk89q/jnbt/FloatTag.java | 49 ++ .../src/com/java/sk89q/jnbt/IntArrayTag.java | 60 +++ .../src/com/java/sk89q/jnbt/IntTag.java | 49 ++ .../src/com/java/sk89q/jnbt/ListTag.java | 431 ++++++++++++++++++ .../com/java/sk89q/jnbt/ListTagBuilder.java | 119 +++++ .../src/com/java/sk89q/jnbt/LongTag.java | 50 ++ .../src/com/java/sk89q/jnbt/NBTConstants.java | 81 ++++ .../com/java/sk89q/jnbt/NBTInputStream.java | 171 +++++++ .../com/java/sk89q/jnbt/NBTOutputStream.java | 294 ++++++++++++ .../src/com/java/sk89q/jnbt/NBTUtils.java | 170 +++++++ .../src/com/java/sk89q/jnbt/NamedTag.java | 63 +++ .../src/com/java/sk89q/jnbt/ShortTag.java | 49 ++ .../src/com/java/sk89q/jnbt/StringTag.java | 52 +++ .../src/com/java/sk89q/jnbt/Tag.java | 34 ++ .../core/common/schematic/Schematic.java | 51 +++ .../core/common/schematic/UtilSchematic.java | 55 +++ .../worldevent/event/AbstractWorldEvent.java | 16 +- .../worldevent/event/kinghill/KingHill.java | 49 ++ 25 files changed, 2659 insertions(+), 3 deletions(-) create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteArrayTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTagBuilder.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/DoubleTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/EndTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/FloatTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntArrayTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTagBuilder.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/LongTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTConstants.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTInputStream.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTOutputStream.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTUtils.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NamedTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ShortTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/StringTag.java create mode 100755 Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/Tag.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java create mode 100644 Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/UtilSchematic.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java diff --git a/Plugins/.idea/misc.xml b/Plugins/.idea/misc.xml index 76fba6e9f..0bef5b45e 100644 --- a/Plugins/.idea/misc.xml +++ b/Plugins/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteArrayTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteArrayTag.java new file mode 100755 index 000000000..8a246e5a4 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteArrayTag.java @@ -0,0 +1,57 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Byte_Array} tag. + */ +public final class ByteArrayTag extends Tag { + + private final byte[] value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public ByteArrayTag(byte[] value) { + super(); + this.value = value; + } + + @Override + public byte[] getValue() { + return value; + } + + @Override + public String toString() { + StringBuilder hex = new StringBuilder(); + for (byte b : value) { + String hexDigits = Integer.toHexString(b).toUpperCase(); + if (hexDigits.length() == 1) { + hex.append("0"); + } + hex.append(hexDigits).append(" "); + } + return "TAG_Byte_Array(" + hex + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteTag.java new file mode 100755 index 000000000..715902be6 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ByteTag.java @@ -0,0 +1,49 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Byte} tag. + */ +public final class ByteTag extends Tag { + + private final byte value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public ByteTag(byte value) { + super(); + this.value = value; + } + + @Override + public Byte getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_Byte(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTag.java new file mode 100755 index 000000000..7a6d55d87 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTag.java @@ -0,0 +1,420 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * The {@code TAG_Compound} tag. + */ +public final class CompoundTag extends Tag { + + private final Map value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public CompoundTag(Map value) { + super(); + this.value = Collections.unmodifiableMap(value); + } + + /** + * Returns whether this compound tag contains the given key. + * + * @param key the given key + * @return true if the tag contains the given key + */ + public boolean containsKey(String key) { + return value.containsKey(key); + } + + @Override + public Map getValue() { + return value; + } + + /** + * Return a new compound tag with the given values. + * + * @param value the value + * @return the new compound tag + */ + public CompoundTag setValue(Map value) { + return new CompoundTag(value); + } + + /** + * Create a compound tag builder. + * + * @return the builder + */ + public CompoundTagBuilder createBuilder() { + return new CompoundTagBuilder(new HashMap(value)); + } + + /** + * Get a byte array named with the given key. + * + *

If the key does not exist or its value is not a byte array tag, + * then an empty byte array will be returned.

+ * + * @param key the key + * @return a byte array + */ + public byte[] getByteArray(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteArrayTag) { + return ((ByteArrayTag) tag).getValue(); + } else { + return new byte[0]; + } + } + + /** + * Get a byte named with the given key. + * + *

If the key does not exist or its value is not a byte tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a byte + */ + public byte getByte(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + } else { + return (byte) 0; + } + } + + /** + * Get a double named with the given key. + * + *

If the key does not exist or its value is not a double tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a double + */ + public double getDouble(String key) { + Tag tag = value.get(key); + if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a double named with the given key, even if it's another + * type of number. + * + *

If the key does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a double + */ + public double asDouble(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + + } else { + return 0; + } + } + + /** + * Get a float named with the given key. + * + *

If the key does not exist or its value is not a float tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a float + */ + public float getFloat(String key) { + Tag tag = value.get(key); + if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a {@code int[]} named with the given key. + * + *

If the key does not exist or its value is not an int array tag, + * then an empty array will be returned.

+ * + * @param key the key + * @return an int array + */ + public int[] getIntArray(String key) { + Tag tag = value.get(key); + if (tag instanceof IntArrayTag) { + return ((IntArrayTag) tag).getValue(); + } else { + return new int[0]; + } + } + + /** + * Get an int named with the given key. + * + *

If the key does not exist or its value is not an int tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return an int + */ + public int getInt(String key) { + Tag tag = value.get(key); + if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get an int named with the given key, even if it's another + * type of number. + * + *

If the key does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return an int + */ + public int asInt(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue().intValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().intValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().intValue(); + + } else { + return 0; + } + } + + /** + * Get a list of tags named with the given key. + * + *

If the key does not exist or its value is not a list tag, + * then an empty list will be returned.

+ * + * @param key the key + * @return a list of tags + */ + public List getList(String key) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + return ((ListTag) tag).getValue(); + } else { + return Collections.emptyList(); + } + } + + /** + * Get a {@code TagList} named with the given key. + * + *

If the key does not exist or its value is not a list tag, + * then an empty tag list will be returned.

+ * + * @param key the key + * @return a tag list instance + */ + public ListTag getListTag(String key) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + return (ListTag) tag; + } else { + return new ListTag(StringTag.class, Collections.emptyList()); + } + } + + /** + * Get a list of tags named with the given key. + * + *

If the key does not exist or its value is not a list tag, + * then an empty list will be returned. If the given key references + * a list but the list of of a different type, then an empty + * list will also be returned.

+ * + * @param key the key + * @param listType the class of the contained type + * @return a list of tags + * @param the type of list + */ + @SuppressWarnings("unchecked") + public List getList(String key, Class listType) { + Tag tag = value.get(key); + if (tag instanceof ListTag) { + ListTag listTag = (ListTag) tag; + if (listTag.getType().equals(listType)) { + return (List) listTag.getValue(); + } else { + return Collections.emptyList(); + } + } else { + return Collections.emptyList(); + } + } + + /** + * Get a long named with the given key. + * + *

If the key does not exist or its value is not a long tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a long + */ + public long getLong(String key) { + Tag tag = value.get(key); + if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + } else { + return 0L; + } + } + + /** + * Get a long named with the given key, even if it's another + * type of number. + * + *

If the key does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a long + */ + public long asLong(String key) { + Tag tag = value.get(key); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().longValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().longValue(); + + } else { + return 0L; + } + } + + /** + * Get a short named with the given key. + * + *

If the key does not exist or its value is not a short tag, + * then {@code 0} will be returned.

+ * + * @param key the key + * @return a short + */ + public short getShort(String key) { + Tag tag = value.get(key); + if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a string named with the given key. + * + *

If the key does not exist or its value is not a string tag, + * then {@code ""} will be returned.

+ * + * @param key the key + * @return a string + */ + public String getString(String key) { + Tag tag = value.get(key); + if (tag instanceof StringTag) { + return ((StringTag) tag).getValue(); + } else { + return ""; + } + } + + @Override + public String toString() { + StringBuilder bldr = new StringBuilder(); + bldr.append("TAG_Compound").append(": ").append(value.size()).append(" entries\r\n{\r\n"); + for (Map.Entry entry : value.entrySet()) { + bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); + } + bldr.append("}"); + return bldr.toString(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTagBuilder.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTagBuilder.java new file mode 100755 index 000000000..ad90a097c --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/CompoundTagBuilder.java @@ -0,0 +1,204 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.util.HashMap; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Helps create compound tags. + */ +public class CompoundTagBuilder { + + private final Map entries; + + /** + * Create a new instance. + */ + CompoundTagBuilder() { + this.entries = new HashMap(); + } + + /** + * Create a new instance and use the given map (which will be modified). + * + * @param value the value + */ + CompoundTagBuilder(Map value) { + checkNotNull(value); + this.entries = value; + } + + /** + * Put the given key and tag into the compound tag. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder put(String key, Tag value) { + checkNotNull(key); + checkNotNull(value); + entries.put(key, value); + return this; + } + + /** + * Put the given key and value into the compound tag as a + * {@code ByteArrayTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putByteArray(String key, byte[] value) { + return put(key, new ByteArrayTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code ByteTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putByte(String key, byte value) { + return put(key, new ByteTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code DoubleTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putDouble(String key, double value) { + return put(key, new DoubleTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code FloatTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putFloat(String key, float value) { + return put(key, new FloatTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code IntArrayTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putIntArray(String key, int[] value) { + return put(key, new IntArrayTag(value)); + } + + /** + * Put the given key and value into the compound tag as an {@code IntTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putInt(String key, int value) { + return put(key, new IntTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code LongTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putLong(String key, long value) { + return put(key, new LongTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code ShortTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putShort(String key, short value) { + return put(key, new ShortTag(value)); + } + + /** + * Put the given key and value into the compound tag as a + * {@code StringTag}. + * + * @param key they key + * @param value the value + * @return this object + */ + public CompoundTagBuilder putString(String key, String value) { + return put(key, new StringTag(value)); + } + + /** + * Put all the entries from the given map into this map. + * + * @param value the map of tags + * @return this object + */ + public CompoundTagBuilder putAll(Map value) { + checkNotNull(value); + for (Map.Entry entry : value.entrySet()) { + put(entry.getKey(), entry.getValue()); + } + return this; + } + + /** + * Build an unnamed compound tag with this builder's entries. + * + * @return the new compound tag + */ + public CompoundTag build() { + return new CompoundTag(new HashMap(entries)); + } + + /** + * Create a new builder instance. + * + * @return a new builder + */ + public static CompoundTagBuilder create() { + return new CompoundTagBuilder(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/DoubleTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/DoubleTag.java new file mode 100755 index 000000000..dd53071a6 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/DoubleTag.java @@ -0,0 +1,50 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Double} tag. + * + */ +public final class DoubleTag extends Tag { + + private final double value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public DoubleTag(double value) { + super(); + this.value = value; + } + + @Override + public Double getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_Double(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/EndTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/EndTag.java new file mode 100755 index 000000000..e2d2e3118 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/EndTag.java @@ -0,0 +1,37 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_End} tag. + */ +public final class EndTag extends Tag { + + @Override + public Object getValue() { + return null; + } + + @Override + public String toString() { + return "TAG_End"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/FloatTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/FloatTag.java new file mode 100755 index 000000000..4a18525ef --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/FloatTag.java @@ -0,0 +1,49 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Float} tag. + */ +public final class FloatTag extends Tag { + + private final float value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public FloatTag(float value) { + super(); + this.value = value; + } + + @Override + public Float getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_Float(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntArrayTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntArrayTag.java new file mode 100755 index 000000000..7a036013f --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntArrayTag.java @@ -0,0 +1,60 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * The {@code TAG_Int_Array} tag. + */ +public final class IntArrayTag extends Tag { + + private final int[] value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public IntArrayTag(int[] value) { + super(); + checkNotNull(value); + this.value = value; + } + + @Override + public int[] getValue() { + return value; + } + + @Override + public String toString() { + StringBuilder hex = new StringBuilder(); + for (int b : value) { + String hexDigits = Integer.toHexString(b).toUpperCase(); + if (hexDigits.length() == 1) { + hex.append("0"); + } + hex.append(hexDigits).append(" "); + } + return "TAG_Int_Array(" + hex + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntTag.java new file mode 100755 index 000000000..2b549ebf5 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/IntTag.java @@ -0,0 +1,49 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Int} tag. + */ +public final class IntTag extends Tag { + + private final int value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public IntTag(int value) { + super(); + this.value = value; + } + + @Override + public Integer getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_Int(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTag.java new file mode 100755 index 000000000..c82650924 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTag.java @@ -0,0 +1,431 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.List; +import java.util.NoSuchElementException; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * The {@code TAG_List} tag. + */ +public final class ListTag extends Tag { + + private final Class type; + private final List value; + + /** + * Creates the tag with an empty name. + * + * @param type the type of tag + * @param value the value of the tag + */ + public ListTag(Class type, List value) { + super(); + checkNotNull(value); + this.type = type; + this.value = Collections.unmodifiableList(value); + } + + /** + * Gets the type of item in this list. + * + * @return The type of item in this list. + */ + public Class getType() { + return type; + } + + @Override + public List getValue() { + return value; + } + + /** + * Create a new list tag with this tag's name and type. + * + * @param list the new list + * @return a new list tag + */ + public ListTag setValue(List list) { + return new ListTag(getType(), list); + } + + /** + * Get the tag if it exists at the given index. + * + * @param index the index + * @return the tag or null + */ + @Nullable + public Tag getIfExists(int index) { + try { + return value.get(index); + } catch (NoSuchElementException e) { + return null; + } + } + + /** + * Get a byte array named with the given index. + * + *

If the index does not exist or its value is not a byte array tag, + * then an empty byte array will be returned.

+ * + * @param index the index + * @return a byte array + */ + public byte[] getByteArray(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteArrayTag) { + return ((ByteArrayTag) tag).getValue(); + } else { + return new byte[0]; + } + } + + /** + * Get a byte named with the given index. + * + *

If the index does not exist or its value is not a byte tag, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a byte + */ + public byte getByte(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + } else { + return (byte) 0; + } + } + + /** + * Get a double named with the given index. + * + *

If the index does not exist or its value is not a double tag, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a double + */ + public double getDouble(int index) { + Tag tag = getIfExists(index); + if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a double named with the given index, even if it's another + * type of number. + * + *

If the index does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a double + */ + public double asDouble(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue(); + + } else { + return 0; + } + } + + /** + * Get a float named with the given index. + * + *

If the index does not exist or its value is not a float tag, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a float + */ + public float getFloat(int index) { + Tag tag = getIfExists(index); + if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a {@code int[]} named with the given index. + * + *

If the index does not exist or its value is not an int array tag, + * then an empty array will be returned.

+ * + * @param index the index + * @return an int array + */ + public int[] getIntArray(int index) { + Tag tag = getIfExists(index); + if (tag instanceof IntArrayTag) { + return ((IntArrayTag) tag).getValue(); + } else { + return new int[0]; + } + } + + /** + * Get an int named with the given index. + * + *

If the index does not exist or its value is not an int tag, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return an int + */ + public int getInt(int index) { + Tag tag = getIfExists(index); + if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get an int named with the given index, even if it's another + * type of number. + * + *

If the index does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return an int + */ + public int asInt(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue().intValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().intValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().intValue(); + + } else { + return 0; + } + } + + /** + * Get a list of tags named with the given index. + * + *

If the index does not exist or its value is not a list tag, + * then an empty list will be returned.

+ * + * @param index the index + * @return a list of tags + */ + public List getList(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ListTag) { + return ((ListTag) tag).getValue(); + } else { + return Collections.emptyList(); + } + } + + /** + * Get a {@code TagList} named with the given index. + * + *

If the index does not exist or its value is not a list tag, + * then an empty tag list will be returned.

+ * + * @param index the index + * @return a tag list instance + */ + public ListTag getListTag(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ListTag) { + return (ListTag) tag; + } else { + return new ListTag(StringTag.class, Collections.emptyList()); + } + } + + /** + * Get a list of tags named with the given index. + * + *

If the index does not exist or its value is not a list tag, + * then an empty list will be returned. If the given index references + * a list but the list of of a different type, then an empty + * list will also be returned.

+ * + * @param index the index + * @param listType the class of the contained type + * @return a list of tags + * @param the NBT type + */ + @SuppressWarnings("unchecked") + public List getList(int index, Class listType) { + Tag tag = getIfExists(index); + if (tag instanceof ListTag) { + ListTag listTag = (ListTag) tag; + if (listTag.getType().equals(listType)) { + return (List) listTag.getValue(); + } else { + return Collections.emptyList(); + } + } else { + return Collections.emptyList(); + } + } + + /** + * Get a long named with the given index. + * + *

If the index does not exist or its value is not a long tag, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a long + */ + public long getLong(int index) { + Tag tag = getIfExists(index); + if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + } else { + return 0L; + } + } + + /** + * Get a long named with the given index, even if it's another + * type of number. + * + *

If the index does not exist or its value is not a number, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a long + */ + public long asLong(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ByteTag) { + return ((ByteTag) tag).getValue(); + + } else if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + + } else if (tag instanceof IntTag) { + return ((IntTag) tag).getValue(); + + } else if (tag instanceof LongTag) { + return ((LongTag) tag).getValue(); + + } else if (tag instanceof FloatTag) { + return ((FloatTag) tag).getValue().longValue(); + + } else if (tag instanceof DoubleTag) { + return ((DoubleTag) tag).getValue().longValue(); + + } else { + return 0; + } + } + + /** + * Get a short named with the given index. + * + *

If the index does not exist or its value is not a short tag, + * then {@code 0} will be returned.

+ * + * @param index the index + * @return a short + */ + public short getShort(int index) { + Tag tag = getIfExists(index); + if (tag instanceof ShortTag) { + return ((ShortTag) tag).getValue(); + } else { + return 0; + } + } + + /** + * Get a string named with the given index. + * + *

If the index does not exist or its value is not a string tag, + * then {@code ""} will be returned.

+ * + * @param index the index + * @return a string + */ + public String getString(int index) { + Tag tag = getIfExists(index); + if (tag instanceof StringTag) { + return ((StringTag) tag).getValue(); + } else { + return ""; + } + } + + @Override + public String toString() { + StringBuilder bldr = new StringBuilder(); + bldr.append("TAG_List").append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n"); + for (Tag t : value) { + bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); + } + bldr.append("}"); + return bldr.toString(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTagBuilder.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTagBuilder.java new file mode 100755 index 000000000..31cae46c9 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ListTagBuilder.java @@ -0,0 +1,119 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Helps create list tags. + */ +public class ListTagBuilder { + + private final Class type; + private final List entries; + + /** + * Create a new instance. + * + * @param type of tag contained in this list + */ + ListTagBuilder(Class type) { + checkNotNull(type); + this.type = type; + this.entries = new ArrayList(); + } + + /** + * Add the given tag. + * + * @param value the tag + * @return this object + */ + public ListTagBuilder add(Tag value) { + checkNotNull(value); + if (!type.isInstance(value)) { + throw new IllegalArgumentException(value.getClass().getCanonicalName() + " is not of expected type " + type.getCanonicalName()); + } + entries.add(value); + return this; + } + + /** + * Add all the tags in the given list. + * + * @param value a list of tags + * @return this object + */ + public ListTagBuilder addAll(Collection value) { + checkNotNull(value); + for (Tag v : value) { + add(v); + } + return this; + } + + /** + * Build an unnamed list tag with this builder's entries. + * + * @return the new list tag + */ + public ListTag build() { + return new ListTag(type, new ArrayList(entries)); + } + + /** + * Create a new builder instance. + * + * @return a new builder + */ + public static ListTagBuilder create(Class type) { + return new ListTagBuilder(type); + } + + /** + * Create a new builder instance. + * + * @return a new builder + */ + public static ListTagBuilder createWith(T ... entries) { + checkNotNull(entries); + + if (entries.length == 0) { + throw new IllegalArgumentException("This method needs an array of at least one entry"); + } + + Class type = entries[0].getClass(); + for (int i = 1; i < entries.length; i++) { + if (!type.isInstance(entries[i])) { + throw new IllegalArgumentException("An array of different tag types was provided"); + } + } + + ListTagBuilder builder = new ListTagBuilder(type); + builder.addAll(Arrays.asList(entries)); + return builder; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/LongTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/LongTag.java new file mode 100755 index 000000000..d5371dd79 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/LongTag.java @@ -0,0 +1,50 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Long} tag. + * + */ +public final class LongTag extends Tag { + + private final long value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public LongTag(long value) { + super(); + this.value = value; + } + + @Override + public Long getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_Long(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTConstants.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTConstants.java new file mode 100755 index 000000000..21743b1ea --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTConstants.java @@ -0,0 +1,81 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.nio.charset.Charset; + +/** + * A class which holds constant values. + */ +public final class NBTConstants { + + public static final Charset CHARSET = Charset.forName("UTF-8"); + + public static final int TYPE_END = 0, TYPE_BYTE = 1, TYPE_SHORT = 2, + TYPE_INT = 3, TYPE_LONG = 4, TYPE_FLOAT = 5, TYPE_DOUBLE = 6, + TYPE_BYTE_ARRAY = 7, TYPE_STRING = 8, TYPE_LIST = 9, + TYPE_COMPOUND = 10, TYPE_INT_ARRAY = 11; + + /** + * Default private constructor. + */ + private NBTConstants() { + + } + + /** + * Convert a type ID to its corresponding {@link Tag} class. + * + * @param id type ID + * @return tag class + * @throws IllegalArgumentException thrown if the tag ID is not valid + */ + public static Class getClassFromType(int id) { + switch (id) { + case TYPE_END: + return EndTag.class; + case TYPE_BYTE: + return ByteTag.class; + case TYPE_SHORT: + return ShortTag.class; + case TYPE_INT: + return IntTag.class; + case TYPE_LONG: + return LongTag.class; + case TYPE_FLOAT: + return FloatTag.class; + case TYPE_DOUBLE: + return DoubleTag.class; + case TYPE_BYTE_ARRAY: + return ByteArrayTag.class; + case TYPE_STRING: + return StringTag.class; + case TYPE_LIST: + return ListTag.class; + case TYPE_COMPOUND: + return CompoundTag.class; + case TYPE_INT_ARRAY: + return IntArrayTag.class; + default: + throw new IllegalArgumentException("Unknown tag type ID of " + id); + } + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTInputStream.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTInputStream.java new file mode 100755 index 000000000..2080cbcd3 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTInputStream.java @@ -0,0 +1,171 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.io.Closeable; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This class reads NBT, or Named Binary Tag + * streams, and produces an object graph of subclasses of the {@code Tag} + * object. + * + *

The NBT format was created by Markus Persson, and the specification may be + * found at + * http://www.minecraft.net/docs/NBT.txt.

+ */ +public final class NBTInputStream implements Closeable { + + private final DataInputStream is; + + /** + * Creates a new {@code NBTInputStream}, which will source its data + * from the specified input stream. + * + * @param is the input stream + * @throws IOException if an I/O error occurs + */ + public NBTInputStream(InputStream is) throws IOException { + this.is = new DataInputStream(is); + } + + /** + * Reads an NBT tag from the stream. + * + * @return The tag that was read. + * @throws IOException if an I/O error occurs. + */ + public NamedTag readNamedTag() throws IOException { + return readNamedTag(0); + } + + /** + * Reads an NBT from the stream. + * + * @param depth the depth of this tag + * @return The tag that was read. + * @throws IOException if an I/O error occurs. + */ + private NamedTag readNamedTag(int depth) throws IOException { + int type = is.readByte() & 0xFF; + + String name; + if (type != NBTConstants.TYPE_END) { + int nameLength = is.readShort() & 0xFFFF; + byte[] nameBytes = new byte[nameLength]; + is.readFully(nameBytes); + name = new String(nameBytes, NBTConstants.CHARSET); + } else { + name = ""; + } + + return new NamedTag(name, readTagPayload(type, depth)); + } + + /** + * Reads the payload of a tag given the type. + * + * @param type the type + * @param depth the depth + * @return the tag + * @throws IOException if an I/O error occurs. + */ + private Tag readTagPayload(int type, int depth) throws IOException { + switch (type) { + case NBTConstants.TYPE_END: + if (depth == 0) { + throw new IOException( + "TAG_End found without a TAG_Compound/TAG_List tag preceding it."); + } else { + return new EndTag(); + } + case NBTConstants.TYPE_BYTE: + return new ByteTag(is.readByte()); + case NBTConstants.TYPE_SHORT: + return new ShortTag(is.readShort()); + case NBTConstants.TYPE_INT: + return new IntTag(is.readInt()); + case NBTConstants.TYPE_LONG: + return new LongTag(is.readLong()); + case NBTConstants.TYPE_FLOAT: + return new FloatTag(is.readFloat()); + case NBTConstants.TYPE_DOUBLE: + return new DoubleTag(is.readDouble()); + case NBTConstants.TYPE_BYTE_ARRAY: + int length = is.readInt(); + byte[] bytes = new byte[length]; + is.readFully(bytes); + return new ByteArrayTag(bytes); + case NBTConstants.TYPE_STRING: + length = is.readShort(); + bytes = new byte[length]; + is.readFully(bytes); + return new StringTag(new String(bytes, NBTConstants.CHARSET)); + case NBTConstants.TYPE_LIST: + int childType = is.readByte(); + length = is.readInt(); + + List tagList = new ArrayList(); + for (int i = 0; i < length; ++i) { + Tag tag = readTagPayload(childType, depth + 1); + if (tag instanceof EndTag) { + throw new IOException("TAG_End not permitted in a list."); + } + tagList.add(tag); + } + + return new ListTag(NBTUtils.getTypeClass(childType), tagList); + case NBTConstants.TYPE_COMPOUND: + Map tagMap = new HashMap(); + while (true) { + NamedTag namedTag = readNamedTag(depth + 1); + Tag tag = namedTag.getTag(); + if (tag instanceof EndTag) { + break; + } else { + tagMap.put(namedTag.getName(), tag); + } + } + + return new CompoundTag(tagMap); + case NBTConstants.TYPE_INT_ARRAY: + length = is.readInt(); + int[] data = new int[length]; + for (int i = 0; i < length; i++) { + data[i] = is.readInt(); + } + return new IntArrayTag(data); + default: + throw new IOException("Invalid tag type: " + type + "."); + } + } + + @Override + public void close() throws IOException { + is.close(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTOutputStream.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTOutputStream.java new file mode 100755 index 000000000..bb10e135a --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTOutputStream.java @@ -0,0 +1,294 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.io.Closeable; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * This class writes NBT, or Named Binary Tag + * {@code Tag} objects to an underlying {@code OutputStream}. + * + *

The NBT format was created by Markus Persson, and the specification may be + * found at + * http://www.minecraft.net/docs/NBT.txt.

+ */ +public final class NBTOutputStream implements Closeable { + + /** + * The output stream. + */ + private final DataOutputStream os; + + /** + * Creates a new {@code NBTOutputStream}, which will write data to the + * specified underlying output stream. + * + * @param os + * The output stream. + * @throws IOException + * if an I/O error occurs. + */ + public NBTOutputStream(OutputStream os) throws IOException { + this.os = new DataOutputStream(os); + } + + /** + * Writes a tag. + * + * @param tag + * The tag to write. + * @throws IOException + * if an I/O error occurs. + */ + public void writeNamedTag(String name, Tag tag) throws IOException { + checkNotNull(name); + checkNotNull(tag); + + int type = NBTUtils.getTypeCode(tag.getClass()); + byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); + + os.writeByte(type); + os.writeShort(nameBytes.length); + os.write(nameBytes); + + if (type == NBTConstants.TYPE_END) { + throw new IOException("Named TAG_End not permitted."); + } + + writeTagPayload(tag); + } + + /** + * Writes tag payload. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeTagPayload(Tag tag) throws IOException { + int type = NBTUtils.getTypeCode(tag.getClass()); + switch (type) { + case NBTConstants.TYPE_END: + writeEndTagPayload((EndTag) tag); + break; + case NBTConstants.TYPE_BYTE: + writeByteTagPayload((ByteTag) tag); + break; + case NBTConstants.TYPE_SHORT: + writeShortTagPayload((ShortTag) tag); + break; + case NBTConstants.TYPE_INT: + writeIntTagPayload((IntTag) tag); + break; + case NBTConstants.TYPE_LONG: + writeLongTagPayload((LongTag) tag); + break; + case NBTConstants.TYPE_FLOAT: + writeFloatTagPayload((FloatTag) tag); + break; + case NBTConstants.TYPE_DOUBLE: + writeDoubleTagPayload((DoubleTag) tag); + break; + case NBTConstants.TYPE_BYTE_ARRAY: + writeByteArrayTagPayload((ByteArrayTag) tag); + break; + case NBTConstants.TYPE_STRING: + writeStringTagPayload((StringTag) tag); + break; + case NBTConstants.TYPE_LIST: + writeListTagPayload((ListTag) tag); + break; + case NBTConstants.TYPE_COMPOUND: + writeCompoundTagPayload((CompoundTag) tag); + break; + case NBTConstants.TYPE_INT_ARRAY: + writeIntArrayTagPayload((IntArrayTag) tag); + break; + default: + throw new IOException("Invalid tag type: " + type + "."); + } + } + + /** + * Writes a {@code TAG_Byte} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeByteTagPayload(ByteTag tag) throws IOException { + os.writeByte(tag.getValue()); + } + + /** + * Writes a {@code TAG_Byte_Array} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException { + byte[] bytes = tag.getValue(); + os.writeInt(bytes.length); + os.write(bytes); + } + + /** + * Writes a {@code TAG_Compound} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeCompoundTagPayload(CompoundTag tag) throws IOException { + for (Map.Entry entry : tag.getValue().entrySet()) { + writeNamedTag(entry.getKey(), entry.getValue()); + } + os.writeByte((byte) 0); // end tag - better way? + } + + /** + * Writes a {@code TAG_List} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeListTagPayload(ListTag tag) throws IOException { + Class clazz = tag.getType(); + List tags = tag.getValue(); + int size = tags.size(); + + os.writeByte(NBTUtils.getTypeCode(clazz)); + os.writeInt(size); + for (Tag tag1 : tags) { + writeTagPayload(tag1); + } + } + + /** + * Writes a {@code TAG_String} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeStringTagPayload(StringTag tag) throws IOException { + byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET); + os.writeShort(bytes.length); + os.write(bytes); + } + + /** + * Writes a {@code TAG_Double} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeDoubleTagPayload(DoubleTag tag) throws IOException { + os.writeDouble(tag.getValue()); + } + + /** + * Writes a {@code TAG_Float} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeFloatTagPayload(FloatTag tag) throws IOException { + os.writeFloat(tag.getValue()); + } + + /** + * Writes a {@code TAG_Long} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeLongTagPayload(LongTag tag) throws IOException { + os.writeLong(tag.getValue()); + } + + /** + * Writes a {@code TAG_Int} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeIntTagPayload(IntTag tag) throws IOException { + os.writeInt(tag.getValue()); + } + + /** + * Writes a {@code TAG_Short} tag. + * + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. + */ + private void writeShortTagPayload(ShortTag tag) throws IOException { + os.writeShort(tag.getValue()); + } + + /** + * Writes a {@code TAG_Empty} tag. + * + * @param tag the tag + */ + private void writeEndTagPayload(EndTag tag) { + /* empty */ + } + + private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { + int[] data = tag.getValue(); + os.writeInt(data.length); + for (int aData : data) { + os.writeInt(aData); + } + } + + @Override + public void close() throws IOException { + os.close(); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTUtils.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTUtils.java new file mode 100755 index 000000000..bafd00135 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NBTUtils.java @@ -0,0 +1,170 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import java.util.Map; + +/** + * A class which contains NBT-related utility methods. + * + */ +public final class NBTUtils { + + /** + * Default private constructor. + */ + private NBTUtils() { + } + + /** + * Gets the type name of a tag. + * + * @param clazz the tag class + * @return The type name. + */ + public static String getTypeName(Class clazz) { + if (clazz.equals(ByteArrayTag.class)) { + return "TAG_Byte_Array"; + } else if (clazz.equals(ByteTag.class)) { + return "TAG_Byte"; + } else if (clazz.equals(CompoundTag.class)) { + return "TAG_Compound"; + } else if (clazz.equals(DoubleTag.class)) { + return "TAG_Double"; + } else if (clazz.equals(EndTag.class)) { + return "TAG_End"; + } else if (clazz.equals(FloatTag.class)) { + return "TAG_Float"; + } else if (clazz.equals(IntTag.class)) { + return "TAG_Int"; + } else if (clazz.equals(ListTag.class)) { + return "TAG_List"; + } else if (clazz.equals(LongTag.class)) { + return "TAG_Long"; + } else if (clazz.equals(ShortTag.class)) { + return "TAG_Short"; + } else if (clazz.equals(StringTag.class)) { + return "TAG_String"; + } else if (clazz.equals(IntArrayTag.class)) { + return "TAG_Int_Array"; + } else { + throw new IllegalArgumentException("Invalid tag classs (" + + clazz.getName() + ")."); + } + } + + /** + * Gets the type code of a tag class. + * + * @param clazz the tag class + * @return The type code. + * @throws IllegalArgumentException if the tag class is invalid. + */ + public static int getTypeCode(Class clazz) { + if (clazz.equals(ByteArrayTag.class)) { + return NBTConstants.TYPE_BYTE_ARRAY; + } else if (clazz.equals(ByteTag.class)) { + return NBTConstants.TYPE_BYTE; + } else if (clazz.equals(CompoundTag.class)) { + return NBTConstants.TYPE_COMPOUND; + } else if (clazz.equals(DoubleTag.class)) { + return NBTConstants.TYPE_DOUBLE; + } else if (clazz.equals(EndTag.class)) { + return NBTConstants.TYPE_END; + } else if (clazz.equals(FloatTag.class)) { + return NBTConstants.TYPE_FLOAT; + } else if (clazz.equals(IntTag.class)) { + return NBTConstants.TYPE_INT; + } else if (clazz.equals(ListTag.class)) { + return NBTConstants.TYPE_LIST; + } else if (clazz.equals(LongTag.class)) { + return NBTConstants.TYPE_LONG; + } else if (clazz.equals(ShortTag.class)) { + return NBTConstants.TYPE_SHORT; + } else if (clazz.equals(StringTag.class)) { + return NBTConstants.TYPE_STRING; + } else if (clazz.equals(IntArrayTag.class)) { + return NBTConstants.TYPE_INT_ARRAY; + } else { + throw new IllegalArgumentException("Invalid tag classs (" + + clazz.getName() + ")."); + } + } + + /** + * Gets the class of a type of tag. + * + * @param type the type + * @return The class. + * @throws IllegalArgumentException if the tag type is invalid. + */ + public static Class getTypeClass(int type) { + switch (type) { + case NBTConstants.TYPE_END: + return EndTag.class; + case NBTConstants.TYPE_BYTE: + return ByteTag.class; + case NBTConstants.TYPE_SHORT: + return ShortTag.class; + case NBTConstants.TYPE_INT: + return IntTag.class; + case NBTConstants.TYPE_LONG: + return LongTag.class; + case NBTConstants.TYPE_FLOAT: + return FloatTag.class; + case NBTConstants.TYPE_DOUBLE: + return DoubleTag.class; + case NBTConstants.TYPE_BYTE_ARRAY: + return ByteArrayTag.class; + case NBTConstants.TYPE_STRING: + return StringTag.class; + case NBTConstants.TYPE_LIST: + return ListTag.class; + case NBTConstants.TYPE_COMPOUND: + return CompoundTag.class; + case NBTConstants.TYPE_INT_ARRAY: + return IntArrayTag.class; + default: + throw new IllegalArgumentException("Invalid tag type : " + type + + "."); + } + } + + /** + * Get child tag of a NBT structure. + * + * @param items the map to read from + * @param key the key to look for + * @param expected the expected NBT class type + * @return child tag + * @throws IllegalArgumentException + */ + public static T getChildTag(Map items, String key, Class expected) throws IllegalArgumentException { + if (!items.containsKey(key)) { + throw new IllegalArgumentException("Missing a \"" + key + "\" tag"); + } + Tag tag = items.get(key); + if (!expected.isInstance(tag)) { + throw new IllegalArgumentException(key + " tag is not of tag type " + expected.getName()); + } + return expected.cast(tag); + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NamedTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NamedTag.java new file mode 100755 index 000000000..30dc789a1 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/NamedTag.java @@ -0,0 +1,63 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * A tag that has a name. + */ +public class NamedTag { + + private final String name; + private final Tag tag; + + /** + * Create a new named tag. + * + * @param name the name + * @param tag the tag + */ + public NamedTag(String name, Tag tag) { + checkNotNull(name); + checkNotNull(tag); + this.name = name; + this.tag = tag; + } + + /** + * Get the name of the tag. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Get the tag. + * + * @return the tag + */ + public Tag getTag() { + return tag; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ShortTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ShortTag.java new file mode 100755 index 000000000..9fc3a74be --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/ShortTag.java @@ -0,0 +1,49 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * The {@code TAG_Short} tag. + */ +public final class ShortTag extends Tag { + + private final short value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public ShortTag(short value) { + super(); + this.value = value; + } + + @Override + public Short getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_Short(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/StringTag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/StringTag.java new file mode 100755 index 000000000..0086c2e32 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/StringTag.java @@ -0,0 +1,52 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * The {@code TAG_String} tag. + */ +public final class StringTag extends Tag { + + private final String value; + + /** + * Creates the tag with an empty name. + * + * @param value the value of the tag + */ + public StringTag(String value) { + super(); + checkNotNull(value); + this.value = value; + } + + @Override + public String getValue() { + return value; + } + + @Override + public String toString() { + return "TAG_String(" + value + ")"; + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/Tag.java b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/Tag.java new file mode 100755 index 000000000..4ccda5357 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/com/java/sk89q/jnbt/Tag.java @@ -0,0 +1,34 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.java.sk89q.jnbt; + +/** + * Represents a NBT tag. + */ +public abstract class Tag { + + /** + * Gets the value of this tag. + * + * @return the value + */ + public abstract Object getValue(); + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java new file mode 100644 index 000000000..f1903d1e4 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java @@ -0,0 +1,51 @@ +package mineplex.core.common.schematic; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; +import net.minecraft.server.v1_7_R4.World; + +public class Schematic +{ + private final short _width; + private final short _height; + private final short _length; + private final byte[] _blocks; + private final byte[] _blockData; + + public Schematic(short width, short height, short length, byte[] blocks, byte[] blockData) + { + _width = width; + _height = height; + _length = length; + _blocks = blocks; + _blockData = blockData; + } + + public void paste(Location originLocation) + { + int startX = originLocation.getBlockX(); + int startY = originLocation.getBlockY(); + int startZ = originLocation.getBlockZ(); + World nmsWorld = ((CraftWorld) originLocation.getWorld()).getHandle(); + + for (int x = 0; x < _width; x++) + { + for (int y = 0; y < _height; y++) + { + for (int z = 0; z < _length; z++) + { + int index = y * _width * _length + z * _width + x; + Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z); + block.setTypeIdAndData(_blocks[index], _blockData[index], false); + } + } + } + } + + @Override + public String toString() + { + return String.format("width: %d, length: %d, height: %d, blockLength: %d, blockDataLength: %d", _width, _length, _height, _blocks.length, _blockData.length); + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/UtilSchematic.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/UtilSchematic.java new file mode 100644 index 000000000..52f7a66df --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/UtilSchematic.java @@ -0,0 +1,55 @@ +package mineplex.core.common.schematic; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Map; +import java.util.zip.GZIPInputStream; + +import com.java.sk89q.jnbt.ByteArrayTag; +import com.java.sk89q.jnbt.CompoundTag; +import com.java.sk89q.jnbt.NBTInputStream; +import com.java.sk89q.jnbt.NamedTag; +import com.java.sk89q.jnbt.ShortTag; +import com.java.sk89q.jnbt.Tag; + +public class UtilSchematic +{ + public static Schematic loadSchematic(File file) throws IOException + { + FileInputStream fis = new FileInputStream(file); + NBTInputStream nbtStream = new NBTInputStream(new GZIPInputStream(fis)); + + NamedTag rootTag = nbtStream.readNamedTag(); + nbtStream.close(); + + if (!rootTag.getName().equals("Schematic")) + return null; + + CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); + Map schematic = schematicTag.getValue(); + + short width = getChildTag(schematic, "Width", ShortTag.class).getValue(); + short height = getChildTag(schematic, "Height", ShortTag.class).getValue(); + short length = getChildTag(schematic, "Length", ShortTag.class).getValue(); + byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); + byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); + + return new Schematic(width, height, length, blocks, blockData); + } + + + private static T getChildTag(Map items, String key, Class expected) + { + Tag tag = items.get(key); + return expected.cast(tag); + } + + public static void main(String[] args) throws IOException + { + File file = new File("test.schematic"); + System.out.println(file.getAbsoluteFile()); + Schematic m = UtilSchematic.loadSchematic(file); + System.out.println(m); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java index e381c1af0..418c3dda0 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import org.bukkit.Location; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; @@ -21,6 +22,8 @@ public abstract class AbstractWorldEvent implements Listener private List _listeners; private String _name; + private Location _centerLocation; + private boolean _running; private int _ticks; private Random _random; @@ -31,11 +34,12 @@ public abstract class AbstractWorldEvent implements Listener private int _minTicksPerState; private EventState _currentState; - public AbstractWorldEvent(WorldEventManager eventManager, DamageManager damageManager, String name) + public AbstractWorldEvent(WorldEventManager eventManager, DamageManager damageManager, String name, Location centerLocation) { _eventManager = eventManager; _damageManager = damageManager; _name = name; + _centerLocation = centerLocation; _listeners = new ArrayList(); _states = new ArrayList(); _random = new Random(); @@ -57,9 +61,12 @@ public abstract class AbstractWorldEvent implements Listener protected abstract void customCancel(); - public void tick() + protected abstract void customTick(); + + public final void tick() { _ticks++; + customTick(); if (_currentState != null) _currentState.tick(); } @@ -139,6 +146,11 @@ public abstract class AbstractWorldEvent implements Listener return _name; } + public Location getCenterLocation() + { + return _centerLocation; + } + public void addState(EventState state) { _states.add(state); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java new file mode 100644 index 000000000..a6a2e488c --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java @@ -0,0 +1,49 @@ +package mineplex.game.clans.clans.worldevent.event.kinghill; + +import java.util.HashMap; + +import org.bukkit.Location; + +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.worldevent.WorldEventManager; +import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; +import mineplex.minecraft.game.core.damage.DamageManager; + +public class KingHill extends AbstractWorldEvent +{ + private ClansManager _clansManager; + private HashMap _scoreMap; + + public KingHill(WorldEventManager eventManager, DamageManager damageManager, Location centerLocation) + { + super(eventManager, damageManager, "King of the Hill", centerLocation); + _clansManager = eventManager.getClans(); + _scoreMap = new HashMap(); + } + + @Override + protected void customStart() + { + + } + + @Override + protected void customCancel() + { + + } + + @Override + protected void customTick() + { + // Tick Hill + // Check if a clan won + } + + private static class HillData + { + public int Score; + public int + } +} From 5d431a586ae8d3422237e92de9726bc7ff8f9e4c Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 2 Jun 2015 20:44:14 -0500 Subject: [PATCH 07/16] King of the hill work --- .../core/common/schematic/Schematic.java | 13 ++- .../worldevent/ConcreteWorldEventFactory.java | 13 ++- .../worldevent/event/boss/AbstractBoss.java | 6 +- .../event/boss/slime/SlimeBoss.java | 5 +- .../worldevent/event/kinghill/HillData.java | 58 ++++++++++ .../worldevent/event/kinghill/KingHill.java | 70 ++++++++++-- .../worldevent/event/state/AbsorbState.java | 106 +++++++++++++----- 7 files changed, 229 insertions(+), 42 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java index f1903d1e4..4ba742470 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/schematic/Schematic.java @@ -1,6 +1,7 @@ package mineplex.core.common.schematic; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; import net.minecraft.server.v1_7_R4.World; @@ -37,7 +38,17 @@ public class Schematic { int index = y * _width * _length + z * _width + x; Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z); - block.setTypeIdAndData(_blocks[index], _blockData[index], false); + // some blocks were giving me negative id's in the schematic (like stairs) + // not sure why but the math.abs is my simple fix + int materialId = Math.abs(_blocks[index]); + + Material material = Material.getMaterial(materialId); + if (material == null) + { + System.out.println(materialId + " data: " + _blockData[index]); + continue; + } + block.setTypeIdAndData(materialId, _blockData[index], false); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java index 5bc8a60c9..f15e5517e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/ConcreteWorldEventFactory.java @@ -5,6 +5,7 @@ import org.bukkit.Location; import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; import mineplex.game.clans.clans.worldevent.event.WorldEventType; import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss; +import mineplex.game.clans.clans.worldevent.event.kinghill.KingHill; public class ConcreteWorldEventFactory implements WorldEventFactory { @@ -18,7 +19,17 @@ public class ConcreteWorldEventFactory implements WorldEventFactory @Override public AbstractWorldEvent fromName(Location location, String name) { - return new SlimeBoss(_eventManager, _eventManager.getDamage(), location); + if (name.equalsIgnoreCase("slime")) + { + return new SlimeBoss(_eventManager, _eventManager.getDamage(), location); + } else if (name.equalsIgnoreCase("kinghill")) + { + return new KingHill(_eventManager, _eventManager.getDamage(), location); + } + else + { + return null; + } } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java index 4f4f82c40..48836c6ad 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java @@ -26,7 +26,7 @@ public abstract class AbstractBoss extends AbstractWorldEvent public AbstractBoss(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth) { - super(eventManager, damageManager, name); + super(eventManager, damageManager, name, center); _center = center; _health = maxHealth; _maxHealth = maxHealth; @@ -34,10 +34,8 @@ public abstract class AbstractBoss extends AbstractWorldEvent } @Override - public void tick() + protected void customTick() { - super.tick(); - if (_lastHealth != _health || getTicks() % 20 == 0) { for (Player player : Bukkit.getServer().getOnlinePlayers()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index 9a10b6345..22f8da567 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Slime; import org.bukkit.entity.Spider; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityTargetEvent; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; @@ -43,9 +44,9 @@ public class SlimeBoss extends AbstractBoss } @Override - public void tick() + protected void customTick() { - super.tick(); + super.customTick(); if (!inRange(_slimeEntity.getLocation())) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java new file mode 100644 index 000000000..6e422c491 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java @@ -0,0 +1,58 @@ +package mineplex.game.clans.clans.worldevent.event.kinghill; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.Location; + +import mineplex.core.common.schematic.Schematic; +import mineplex.core.common.schematic.UtilSchematic; + +public class HillData +{ + private Schematic _schematic; + private int _hillX; + private int _hillY; + private int _hillZ; + private int _lengthX; + private int _lengthY; + private int _lengthZ; + + public HillData(String fileName, int hillX, int hillY, int hillZ, int lengthX, int lengthY, int lengthZ) throws IOException + { + File file = new File("schematic" + File.separator + fileName); + System.out.println(file.getAbsolutePath()); + _schematic = UtilSchematic.loadSchematic(file); + _hillX = hillX; + _hillY = hillY; + _hillZ = hillZ; + _lengthX = lengthX; + _lengthY = lengthY; + _lengthZ = lengthZ; + } + + public Schematic getSchematic() + { + return _schematic; + } + + public boolean isOnHill(Location location, Location eventLocation) + { + if (!location.getWorld().equals(eventLocation.getWorld())) return false; + + int minX = eventLocation.getBlockX() + _hillX; + int minY = eventLocation.getBlockY() + _hillY; + int minZ = eventLocation.getBlockZ() + _hillZ; + int maxX = minX + _lengthX; + int maxY = minY + _lengthY; + int maxZ = minZ + _lengthZ; + + double x = location.getX(); + double y = location.getY(); + double z = location.getZ(); + + return x > minX && y > minY && z > minZ && x < maxX && y < maxY && z < maxZ; + } + + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java index a6a2e488c..0622523ea 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java @@ -1,9 +1,16 @@ package mineplex.game.clans.clans.worldevent.event.kinghill; +import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.Player; +import mineplex.core.common.schematic.Schematic; +import mineplex.core.common.util.UtilServer; import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.worldevent.WorldEventManager; @@ -12,20 +19,40 @@ import mineplex.minecraft.game.core.damage.DamageManager; public class KingHill extends AbstractWorldEvent { + private static List LOADED_HILLS = new ArrayList(); + + static + { + // TODO load hills from schematic folder with extra hill data from a config file? + try + { + LOADED_HILLS.add(new HillData("hill.schematic", 28, 28, 28, 5, 5, 5)); + } + catch (IOException e) + { + e.printStackTrace(); + } + + } + private ClansManager _clansManager; - private HashMap _scoreMap; + private HashMap _scoreMap; + private HillData _hill; public KingHill(WorldEventManager eventManager, DamageManager damageManager, Location centerLocation) { super(eventManager, damageManager, "King of the Hill", centerLocation); _clansManager = eventManager.getClans(); - _scoreMap = new HashMap(); + _scoreMap = new HashMap(); + _hill = LOADED_HILLS.get(0); } @Override protected void customStart() { - + Bukkit.broadcastMessage("attempting to spawn in hill... please wait!"); + _hill.getSchematic().paste(getCenterLocation()); + Bukkit.broadcastMessage("PASTED"); } @Override @@ -37,13 +64,42 @@ public class KingHill extends AbstractWorldEvent @Override protected void customTick() { - // Tick Hill - // Check if a clan won + + if (getTicks() % 5 == 0) + tickHill(); + + + } - private static class HillData + private void tickHill() + { + int clanCount = 0; + ClanInfo lastClan = null; + + for (Player player : UtilServer.getPlayers()) + { + if (_hill.isOnHill(player.getLocation(), getCenterLocation())) + { + ClanInfo playerClan = _clansManager.getClan(player); + if (playerClan != null) + { + clanCount++; + lastClan = playerClan; + } + +// Bukkit.broadcastMessage(player.getName() + " IS ON THE HILL"); + } + } + + if (clanCount == 1 && lastClan != null) + { + Bukkit.broadcastMessage(lastClan.getName() + " owns the hill!"); + } + } + + private static class CaptureData { public int Score; - public int } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java index d01ee854d..33a6f770a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java @@ -7,7 +7,11 @@ import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; +import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAlg; @@ -19,18 +23,19 @@ import mineplex.game.clans.clans.worldevent.event.boss.state.BossState; public class AbsorbState extends BossState { private Slime _entity; - private boolean _hasRider; + private Player _rider; private int _riderTickCount; private int _ticksPerPulse; private int _pulseCount; + private int _maxPulses; private int _slimeSize; public AbsorbState(AbstractBoss boss, Slime entity, int ticksPerPulse) { super(boss); _entity = entity; - _pulseCount = 10; - _hasRider = false; + _pulseCount = 0; + _maxPulses = 10; _riderTickCount = 0; _ticksPerPulse = ticksPerPulse; _slimeSize = entity.getSize(); @@ -39,33 +44,36 @@ public class AbsorbState extends BossState @Override public void onTick() { - if (!_hasRider) + if (_rider == null) { int mod = getTicks() % _ticksPerPulse; - if (mod == 0) + if (_pulseCount < _maxPulses) { - pulse(); - _pulseCount++; - _entity.setSize(_slimeSize); - UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, _entity.getLocation(), 2F, 2F, 2F, 0, 50); - _entity.getWorld().playSound(_entity.getLocation(), Sound.SLIME_WALK, 0.5F, 1); - } - else if (mod > _ticksPerPulse - 10) - { - int ticksLeft = _ticksPerPulse - mod; - _entity.setSize(_entity.getSize() + 1); - - int count = 20 + (10 - ticksLeft); - for (int i = 0; i < count; i++) + if (mod == 0) { - double radius = (10 - ticksLeft) * 2; - double q = i / 10.0 * Math.PI; - double x = radius * Math.sin(q); - double z = radius * Math.cos(q); - Location loc = _entity.getLocation().clone(); - loc.add(x, 0.2, z); - UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10); + pulse(); + _pulseCount++; + _entity.setSize(_slimeSize); + UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, _entity.getLocation(), 2F, 2F, 2F, 0, 50); + _entity.getWorld().playSound(_entity.getLocation(), Sound.SLIME_WALK, 0.5F, 1); + } + else if (mod > _ticksPerPulse - 10) + { + int ticksLeft = _ticksPerPulse - mod; + _entity.setSize(_entity.getSize() + 1); + + int count = 20 + (10 - ticksLeft); + for (int i = 0; i < count; i++) + { + double radius = (10 - ticksLeft) * 2; + double q = i / 10.0 * Math.PI; + double x = radius * Math.sin(q); + double z = radius * Math.cos(q); + Location loc = _entity.getLocation().clone(); + loc.add(x, 0.2, z); + UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10); + } } } @@ -79,14 +87,29 @@ public class AbsorbState extends BossState if (dist < 5) { _entity.setPassenger(closest); - _hasRider = true; + _rider = closest; } } } } else { - // Check for rider + _riderTickCount++; + + if (_riderTickCount % 20 == 0) + { + getBoss().getDamageManager().NewDamageEvent(_rider, _entity, null, EntityDamageEvent.DamageCause.MAGIC, 2.0, + false, false, false, getBoss().getName(), "Absorb"); + } + + if (shouldEjectRider()) + { + Vector dir = _entity.getLocation().getDirection().normalize(); + _entity.eject(); + _rider.setVelocity(dir.add(new Vector(0, 0.5, 0))); + _rider = null; + getBoss().setState(null); + } } } @@ -105,6 +128,35 @@ public class AbsorbState extends BossState } } + private boolean shouldEjectRider() + { + return _riderTickCount >= 20 * 10; + } + + @EventHandler + public void onTarget(EntityTargetEvent event) + { + if (_rider != null) + { + if (event.getEntity().equals(_entity) && event.getTarget().equals(_rider)) + event.setCancelled(true); + } + } + + @EventHandler + public void onQuit(PlayerQuitEvent event) + { + if (event.getPlayer().equals(_rider)) + _rider = null; + } + + @EventHandler + public void onLeave(VehicleExitEvent event) + { + if (event.getExited().equals(_rider) && event.getVehicle().equals(_entity) && !shouldEjectRider()) + event.setCancelled(true); + } + @Override public void onStateStart() { From 90a7362440392ffffcf53400087ed068aa99154f Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Thu, 4 Jun 2015 00:21:09 -0500 Subject: [PATCH 08/16] Marge with twiggys code, work on slime splitting --- Plugins/.idea/modules.xml | 1 - .../core/common/util/UtilParticle.java | 2 +- .../Mineplex.Game.Clans.iml | 1 + .../worldevent/event/AbstractWorldEvent.java | 20 +-- .../event/{state => }/EventState.java | 2 +- .../worldevent/event/boss/AbstractBoss.java | 23 +-- .../event/boss/{state => }/BossState.java | 4 +- .../worldevent/event/boss/IdleState.java | 27 +++ .../event/boss/slime/SlimeBoss.java | 167 +++++++++++++++--- .../{ => boss/slime}/state/AbsorbState.java | 13 +- .../{ => boss/slime}/state/RocketState.java | 36 ++-- .../boss/{ => slime}/state/SlamState.java | 10 +- 12 files changed, 215 insertions(+), 91 deletions(-) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/{state => }/EventState.java (90%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/{state => }/BossState.java (68%) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/IdleState.java rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/{ => boss/slime}/state/AbsorbState.java (88%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/{ => boss/slime}/state/RocketState.java (76%) rename Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/{ => slime}/state/SlamState.java (89%) diff --git a/Plugins/.idea/modules.xml b/Plugins/.idea/modules.xml index bf0ac4bae..beb559c38 100644 --- a/Plugins/.idea/modules.xml +++ b/Plugins/.idea/modules.xml @@ -16,7 +16,6 @@ -
diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java index 33d33f950..0c1cb1b21 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java @@ -209,7 +209,7 @@ public class UtilParticle } public static void PlayParticle(ParticleType type,Location location, float offsetX, float offsetY, float offsetZ, - float speed, int count, ViewDist dist, Player... players) + float speed, int count, ViewDist dist, Player... players) { PlayParticle(type.particleName, location, offsetX, offsetY, offsetZ, speed, count, dist, players); } diff --git a/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml b/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml index f02d9d7cf..18f36b74f 100644 --- a/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml +++ b/Plugins/Mineplex.Game.Clans/Mineplex.Game.Clans.iml @@ -15,5 +15,6 @@ +
\ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java index 418c3dda0..3759819c2 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/AbstractWorldEvent.java @@ -11,7 +11,6 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.game.clans.clans.worldevent.WorldEventListener; import mineplex.game.clans.clans.worldevent.WorldEventManager; -import mineplex.game.clans.clans.worldevent.event.state.EventState; import mineplex.minecraft.game.core.damage.DamageManager; public abstract class AbstractWorldEvent implements Listener @@ -29,9 +28,6 @@ public abstract class AbstractWorldEvent implements Listener private Random _random; // Event States - private List _states; - private int _maxTicksPerState; - private int _minTicksPerState; private EventState _currentState; public AbstractWorldEvent(WorldEventManager eventManager, DamageManager damageManager, String name, Location centerLocation) @@ -41,7 +37,6 @@ public abstract class AbstractWorldEvent implements Listener _name = name; _centerLocation = centerLocation; _listeners = new ArrayList(); - _states = new ArrayList(); _random = new Random(); } @@ -110,11 +105,6 @@ public abstract class AbstractWorldEvent implements Listener return _damageManager; } - public EventState getRandomState() - { - return _states.get(_random.nextInt(_states.size())); - } - public void setState(EventState state) { JavaPlugin plugin = _eventManager.getPlugin(); @@ -146,14 +136,14 @@ public abstract class AbstractWorldEvent implements Listener return _name; } + protected Random getRandom() + { + return _random; + } + public Location getCenterLocation() { return _centerLocation; } - public void addState(EventState state) - { - _states.add(state); - } - } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/EventState.java similarity index 90% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/EventState.java index 6a13025e4..7199eb822 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/EventState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/EventState.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.worldevent.event.state; +package mineplex.game.clans.clans.worldevent.event; import org.bukkit.event.Listener; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java index 48836c6ad..ae3e7faec 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/AbstractBoss.java @@ -1,8 +1,5 @@ package mineplex.game.clans.clans.worldevent.event.boss; -import java.util.ArrayList; -import java.util.List; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -11,7 +8,6 @@ import mineplex.core.common.util.UtilTextBottom; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; import mineplex.game.clans.clans.worldevent.WorldEventListener; -import mineplex.game.clans.clans.worldevent.event.state.EventState; import mineplex.minecraft.game.core.damage.DamageManager; public abstract class AbstractBoss extends AbstractWorldEvent @@ -21,13 +17,11 @@ public abstract class AbstractBoss extends AbstractWorldEvent private double _lastHealth; // Action Bar Messages - private Location _center; private float _radiusSquared; public AbstractBoss(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth) { super(eventManager, damageManager, name, center); - _center = center; _health = maxHealth; _maxHealth = maxHealth; setRadius(radius); @@ -40,7 +34,7 @@ public abstract class AbstractBoss extends AbstractWorldEvent { for (Player player : Bukkit.getServer().getOnlinePlayers()) { - if (player.getWorld().equals(_center.getWorld()) && _center.distanceSquared(player.getLocation()) < _radiusSquared) + if (player.getWorld().equals(getCenterLocation().getWorld()) && getCenterLocation().distanceSquared(player.getLocation()) < _radiusSquared) { UtilTextBottom.displayProgress(getName(), _health / _maxHealth, player); } @@ -52,7 +46,8 @@ public abstract class AbstractBoss extends AbstractWorldEvent if (_health <= 0) { onDeath(); - for (WorldEventListener listener : getListeners()) listener.onComplete(this); + if (_health <= 0) // only finish if the health is still less than 0 + for (WorldEventListener listener : getListeners()) listener.onComplete(this); } } @@ -73,6 +68,11 @@ public abstract class AbstractBoss extends AbstractWorldEvent _maxHealth = maxHealth; } + public void setHealth(double health) + { + _health = health; + } + public double getHealth() { return _health; @@ -83,13 +83,8 @@ public abstract class AbstractBoss extends AbstractWorldEvent return _maxHealth; } - public Location getCenter() - { - return _center; - } - public boolean inRange(Location loc) { - return loc.distanceSquared(_center) <= _radiusSquared; + return loc.distanceSquared(getCenterLocation()) <= _radiusSquared; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/BossState.java similarity index 68% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/BossState.java index fc8460302..34ae42f3d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/BossState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/BossState.java @@ -1,7 +1,7 @@ -package mineplex.game.clans.clans.worldevent.event.boss.state; +package mineplex.game.clans.clans.worldevent.event.boss; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; -import mineplex.game.clans.clans.worldevent.event.state.EventState; +import mineplex.game.clans.clans.worldevent.event.EventState; public abstract class BossState extends EventState { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/IdleState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/IdleState.java new file mode 100644 index 000000000..5136f2e8e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/IdleState.java @@ -0,0 +1,27 @@ +package mineplex.game.clans.clans.worldevent.event.boss; + +public class IdleState extends BossState +{ + public IdleState(AbstractBoss boss) + { + super(boss); + } + + @Override + public void onTick() + { + + } + + @Override + public void onStateStart() + { + + } + + @Override + public void onStateStop() + { + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index 22f8da567..c47b0c783 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -1,34 +1,42 @@ package mineplex.game.clans.clans.worldevent.event.boss.slime; +import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.Slime; -import org.bukkit.entity.Spider; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.SlimeSplitEvent; +import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; -import mineplex.game.clans.clans.worldevent.event.boss.state.SlamState; +import mineplex.game.clans.clans.worldevent.event.boss.BossState; +import mineplex.game.clans.clans.worldevent.event.boss.slime.state.AbsorbState; +import mineplex.game.clans.clans.worldevent.event.boss.slime.state.RocketState; +import mineplex.game.clans.clans.worldevent.event.boss.slime.state.SlamState; import mineplex.minecraft.game.core.damage.DamageManager; public class SlimeBoss extends AbstractBoss { - private Slime _slimeEntity; + private static final int MAX_SIZE = 10; + private static final int MIN_SIZE = 1; + + private List _slimes; public SlimeBoss(WorldEventManager eventManager, DamageManager damageManager, Location center) { super(eventManager, damageManager, "Slime King", center, 100, 300); - _slimeEntity = center.getWorld().spawn(center, Slime.class); - _slimeEntity.setSize(10); - _slimeEntity.setMaxHealth(100); - _slimeEntity.setHealth(100); + _slimes = new ArrayList(); + + spawnSlime(center, MAX_SIZE); } @Override @@ -48,21 +56,48 @@ public class SlimeBoss extends AbstractBoss { super.customTick(); - if (!inRange(_slimeEntity.getLocation())) + for (SlimeData slimeData : _slimes) { - _slimeEntity.teleport(getCenter()); + if (slimeData.State != null) slimeData.State.tick(); } - if (getState() == null && getTicks() % (20 * 15) == 0) + if (getTicks() % 80 == 0) { - List nearby = _slimeEntity.getNearbyEntities(10, 10, 10); - for (Entity near : nearby) + SlimeData data = _slimes.get(getRandom().nextInt(_slimes.size())); + + assert(data != null); + + int num = getRandom().nextInt(3); + + BossState state; + + switch (num) { - if (near instanceof Player) + case 0: + state = new AbsorbState(this, data.Entity, 20); + break; + case 1: + state = new RocketState(this, data.Entity); + break; + default: + state = new SlamState(this, data.Entity, getRandomTarget(data.Entity.getLocation(), 10)); + } + + data.State = state; + } + } + + @EventHandler + public void onSlimeDamage(EntityDamageEvent event) + { + if (event.getEntity().getType() == EntityType.SLIME) + { + for (SlimeData slimeData : _slimes) + { + if (event.getEntity().equals(slimeData.Entity)) { - Player player = ((Player) near); - Bukkit.broadcastMessage("SLAM ON " + player.getDisplayName()); - setState(new SlamState(this, _slimeEntity, player)); +// slime.setHealth(slime.getMaxHealth()); +// event.setDamage(0); break; } } @@ -70,20 +105,104 @@ public class SlimeBoss extends AbstractBoss } @EventHandler - public void onSlimeDamage(EntityDamageEvent event) + public void onSplit(SlimeSplitEvent event) { - if (event.getEntity().equals(_slimeEntity)) + for (SlimeData slimeData : _slimes) { - _slimeEntity.setHealth(100); - damage(20); - event.setDamage(1); + if (event.getEntity().equals(slimeData.Entity)) + event.setCancelled(true); } } + @EventHandler + public void onDeath(EntityDeathEvent event) + { + if (event.getEntity().getType() == EntityType.SLIME) + { + for (SlimeData slimeData : _slimes) + { + if (slimeData.Entity.equals(event.getEntity())) + { + splitSlime(slimeData.Entity); + + checkDeath(); + } + } + } + } + + private void checkDeath() + { + if (_slimes.size() == 0) + { + setHealth(0); + } + } + + public Player getRandomTarget(Location location, double maxDist) + { + List nearby = UtilPlayer.getNearby(location, maxDist); + return nearby.get(getRandom().nextInt(nearby.size())); + } + + public void rotateState() + { + + } + + public int getSplitSize(int currSize) + { + return currSize / 2; + } + + public int getSplitCount(int currSize) + { + return 4; + } + + public double getMaxSlimeHealth(int slimeSize) + { + return slimeSize * 20; + } + + private void splitSlime(Slime slime) + { + int splitCount = getSplitCount(slime.getSize()); + int splitSize = getSplitSize(slime.getSize()); + + if (splitSize >= MIN_SIZE) + { + for (int i = 0; i < splitCount; i++) + { + spawnSlime(slime.getLocation(), splitSize); + } + } + } + + private Slime spawnSlime(Location location, int size) + { + Slime slime = location.getWorld().spawn(location, Slime.class); + slime.setSize(size); + slime.setMaxHealth(getMaxSlimeHealth(size)); + slime.setHealth(slime.getMaxHealth()); + _slimes.add(new SlimeData(slime)); + return slime; + } + @Override protected void onDeath() { - _slimeEntity.setHealth(0); - Bukkit.broadcastMessage("GIANT DEATH"); + Bukkit.broadcastMessage("DEATH"); + } + + private static class SlimeData + { + private final Slime Entity; + private BossState State; + + public SlimeData(Slime slime) + { + Entity = slime; + } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/AbsorbState.java similarity index 88% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/AbsorbState.java index 33a6f770a..e8eb53578 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/AbsorbState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/AbsorbState.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.worldevent.event.state; +package mineplex.game.clans.clans.worldevent.event.boss.slime.state; import java.util.List; @@ -17,8 +17,10 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; -import mineplex.game.clans.clans.worldevent.event.boss.state.BossState; +import mineplex.game.clans.clans.worldevent.event.boss.BossState; +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss; public class AbsorbState extends BossState { @@ -30,7 +32,7 @@ public class AbsorbState extends BossState private int _maxPulses; private int _slimeSize; - public AbsorbState(AbstractBoss boss, Slime entity, int ticksPerPulse) + public AbsorbState(SlimeBoss boss, Slime entity, int ticksPerPulse) { super(boss); _entity = entity; @@ -55,7 +57,7 @@ public class AbsorbState extends BossState pulse(); _pulseCount++; _entity.setSize(_slimeSize); - UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, _entity.getLocation(), 2F, 2F, 2F, 0, 50); + UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, _entity.getLocation(), 2F, 2F, 2F, 0, 50, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); _entity.getWorld().playSound(_entity.getLocation(), Sound.SLIME_WALK, 0.5F, 1); } else if (mod > _ticksPerPulse - 10) @@ -72,7 +74,7 @@ public class AbsorbState extends BossState double z = radius * Math.cos(q); Location loc = _entity.getLocation().clone(); loc.add(x, 0.2, z); - UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10); + UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); } } } @@ -108,7 +110,6 @@ public class AbsorbState extends BossState _entity.eject(); _rider.setVelocity(dir.add(new Vector(0, 0.5, 0))); _rider = null; - getBoss().setState(null); } } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java similarity index 76% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java index e1fc1f994..ec6757d92 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/state/RocketState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.worldevent.event.state; +package mineplex.game.clans.clans.worldevent.event.boss.slime.state; import java.util.Iterator; import java.util.LinkedList; @@ -15,19 +15,21 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilServer; import mineplex.core.projectile.IThrown; import mineplex.core.projectile.ProjectileManager; import mineplex.core.projectile.ProjectileUser; import mineplex.core.updater.UpdateType; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; -import mineplex.game.clans.clans.worldevent.event.boss.state.BossState; +import mineplex.game.clans.clans.worldevent.event.boss.BossState; public class RocketState extends BossState implements IThrown { - private LivingEntity _shooter; + private Slime _shooter; private LinkedList _shots; + private int _projectilesHit; - public RocketState(AbstractBoss boss, LivingEntity shooter) + public RocketState(AbstractBoss boss, Slime shooter) { super(boss); _shooter = shooter; @@ -37,14 +39,8 @@ public class RocketState extends BossState implements IThrown @Override public void onTick() { - if (getTicks() % 20 == 0) + if (getTicks() % 20 == 0 && getTicks() / 20 < 6) { - int c = getTicks() / 20; - double mod = (c / 5.0) * Math.PI; - double x = Math.sin(mod); - double z = Math.cos(mod); - double y = -0.1; - List entities = _shooter.getNearbyEntities(20, 20, 20); for (Entity e : entities) @@ -58,10 +54,11 @@ public class RocketState extends BossState implements IThrown // fireProjectile(new Vector(x, y, z)); - if (c == 5) - { - getBoss().setState(new AbsorbState(getBoss(), ((Slime) _shooter), 20 * 2)); - } + } + + if (_projectilesHit == 6) + { +// getBoss().setState(new AbsorbState(getBoss(), ((Slime) _shooter), 20 * 2)); } Iterator it = _shots.iterator(); @@ -113,24 +110,19 @@ public class RocketState extends BossState implements IThrown public void Collide(LivingEntity target, Block block, ProjectileUser data) { Bukkit.broadcastMessage("COLLIDE " + target); - UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); + UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); data.GetThrown().remove(); + _projectilesHit++; } @Override public void Idle(ProjectileUser data) { - Bukkit.broadcastMessage("IDLE"); - UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); - data.GetThrown().remove(); } @Override public void Expire(ProjectileUser data) { - Bukkit.broadcastMessage("EXPIRE"); - UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1); - data.GetThrown().remove(); } private static class ShotData diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java similarity index 89% rename from Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java rename to Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java index e90098e04..38d56855f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/state/SlamState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java @@ -1,4 +1,4 @@ -package mineplex.game.clans.clans.worldevent.event.boss.state; +package mineplex.game.clans.clans.worldevent.event.boss.slime.state; import java.util.List; @@ -15,8 +15,9 @@ import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilServer; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; -import mineplex.game.clans.clans.worldevent.event.state.RocketState; +import mineplex.game.clans.clans.worldevent.event.boss.BossState; public class SlamState extends BossState { @@ -71,7 +72,7 @@ public class SlamState extends BossState double x = 0.5 * Math.sin(getTicks() / 10.0 * 2 * Math.PI); double z = 0.5 * Math.cos(getTicks() / 10.0 * 2 * Math.PI); Location loc = _targetLocation.clone().add(x, 0.1, z); - UtilParticle.PlayParticle(UtilParticle.ParticleType.FIREWORKS_SPARK, loc, 0, 0, 0, 0, 1); + UtilParticle.PlayParticle(UtilParticle.ParticleType.FIREWORKS_SPARK, loc, 0, 0, 0, 0, 1, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); } @@ -99,11 +100,10 @@ public class SlamState extends BossState } } - UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, fallLoc, 2, 0.5F, 2, 0, 100); + UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, fallLoc, 2, 0.5F, 2, 0, 100, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); fallLoc.getWorld().playSound(fallLoc, Sound.ANVIL_LAND, 10, 0.5F); event.setCancelled(true); - getBoss().setState(new RocketState(getBoss(), _entity)); } } From 1f92564ea172d6b29156a410971966fcd6c4c795 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 6 Jun 2015 14:49:41 -0500 Subject: [PATCH 09/16] Changes to Slime Boss, ability to drop gold with GoldManager, small KOTH changes. [ALL UNTESTED] --- .../mineplex/core/common/util/UtilPlayer.java | 17 +- .../src/mineplex/core/reward/RewardType.java | 41 +++++ .../event/boss/slime/SlimeBoss.java | 113 ++++--------- .../event/boss/slime/SlimePart.java | 110 ++++++++++++ .../boss/slime/ability/AbsorbAbility.java | 71 ++++++++ .../boss/slime/ability/RocketAbility.java | 149 +++++++++++++++++ .../event/boss/slime/ability/SlamAbility.java | 156 ++++++++++++++++++ .../boss/slime/ability/SlimeAbility.java | 56 +++++++ .../event/boss/slime/state/RocketState.java | 25 --- .../event/boss/slime/state/SlamState.java | 13 -- .../event/boss/slime/state/SlimeState.java | 51 ++++++ .../worldevent/event/kinghill/HillData.java | 7 + .../worldevent/event/kinghill/KingHill.java | 18 +- .../game/clans/economy/GoldManager.java | 82 +++++++-- 14 files changed, 768 insertions(+), 141 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/AbsorbAbility.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/RocketAbility.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlimeAbility.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlimeState.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index 438f6660e..a9dff7549 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -4,6 +4,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Random; import java.util.UUID; import org.bukkit.ChatColor; @@ -22,6 +23,8 @@ import net.minecraft.server.v1_7_R4.PlayerConnection; public class UtilPlayer { + private static Random RANDOM = new Random(); + private static boolean hasIntersection(Vector3D p1, Vector3D p2, Vector3D min, Vector3D max) { final double epsilon = 0.0001f; @@ -530,7 +533,7 @@ public class UtilPlayer continue; //Get lower offset (eye to eye, eye to feet) - double offset = Math.min(UtilMath.offset(player.getEyeLocation(), cur.getEyeLocation()), + double offset = Math.min(UtilMath.offset(player.getEyeLocation(), cur.getEyeLocation()), UtilMath.offset(player.getEyeLocation(), cur.getLocation())); if (offset < distance && UtilAlg.isTargetInPlayerPyramid(player, cur, angleLimit)) @@ -608,6 +611,18 @@ public class UtilPlayer } } + /** + * Get a random player within maxDist of the target location + * @param location The center location to look for the player + * @param maxDist The max distance from location that the player can be + * @return A random player that is within maxDist of location, or null if no players apply + */ + public static Player getRandomTarget(Location location, double maxDist) + { + List nearby = getNearby(location, maxDist); + return nearby.get(RANDOM.nextInt(nearby.size())); + } + public static boolean isSpectator(Entity player) { if (player instanceof Player) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java index 556c7f5e0..c6c5caef8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/RewardType.java @@ -1,5 +1,7 @@ package mineplex.core.reward; +import java.util.ArrayList; + public enum RewardType { //% Chances Mythic Legend Rare Uncommon @@ -34,4 +36,43 @@ public enum RewardType return rarity; } + + public static void main(String[] args) + { + int maxCount = Integer.MAX_VALUE; + int openCount = 0; + RewardType type = RewardType.MythicalChest; + ArrayList data = new ArrayList(); + + for (RewardRarity rarity : RewardRarity.values()) + { + data.add(rarity.ordinal(), new RewardTest(rarity)); + } + + for (int i = 0; i < maxCount; i++) + { + RewardRarity rarity = type.generateRarity(false); + data.get(rarity.ordinal()).Count++; + openCount++; + if (rarity == RewardRarity.MYTHICAL) break; + } + + System.out.printf("Opened %10d rewards using type " + type.name() + "\n", openCount); + for (RewardTest test : data) + { + System.out.printf("Opened %10d of reward type %10s", test.Count, test.Rarity.name()); + System.out.println(); + } + } + + private static class RewardTest + { + public final RewardRarity Rarity; + public int Count; + + public RewardTest(RewardRarity rare) + { + Rarity = rare; + } + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index c47b0c783..fad9f2c1e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -1,26 +1,19 @@ package mineplex.game.clans.clans.worldevent.event.boss.slime; -import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.entity.Slime; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.SlimeSplitEvent; -import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss; -import mineplex.game.clans.clans.worldevent.event.boss.BossState; -import mineplex.game.clans.clans.worldevent.event.boss.slime.state.AbsorbState; -import mineplex.game.clans.clans.worldevent.event.boss.slime.state.RocketState; -import mineplex.game.clans.clans.worldevent.event.boss.slime.state.SlamState; import mineplex.minecraft.game.core.damage.DamageManager; public class SlimeBoss extends AbstractBoss @@ -28,13 +21,13 @@ public class SlimeBoss extends AbstractBoss private static final int MAX_SIZE = 10; private static final int MIN_SIZE = 1; - private List _slimes; + private List _slimes; public SlimeBoss(WorldEventManager eventManager, DamageManager damageManager, Location center) { super(eventManager, damageManager, "Slime King", center, 100, 300); - _slimes = new ArrayList(); + _slimes = new LinkedList(); spawnSlime(center, MAX_SIZE); } @@ -56,34 +49,9 @@ public class SlimeBoss extends AbstractBoss { super.customTick(); - for (SlimeData slimeData : _slimes) + for (SlimePart slimePart : _slimes) { - if (slimeData.State != null) slimeData.State.tick(); - } - - if (getTicks() % 80 == 0) - { - SlimeData data = _slimes.get(getRandom().nextInt(_slimes.size())); - - assert(data != null); - - int num = getRandom().nextInt(3); - - BossState state; - - switch (num) - { - case 0: - state = new AbsorbState(this, data.Entity, 20); - break; - case 1: - state = new RocketState(this, data.Entity); - break; - default: - state = new SlamState(this, data.Entity, getRandomTarget(data.Entity.getLocation(), 10)); - } - - data.State = state; + slimePart.tick(); } } @@ -92,9 +60,9 @@ public class SlimeBoss extends AbstractBoss { if (event.getEntity().getType() == EntityType.SLIME) { - for (SlimeData slimeData : _slimes) + for (SlimePart slimePart : _slimes) { - if (event.getEntity().equals(slimeData.Entity)) + if (event.getEntity().equals(slimePart.getEntity())) { // slime.setHealth(slime.getMaxHealth()); // event.setDamage(0); @@ -107,9 +75,9 @@ public class SlimeBoss extends AbstractBoss @EventHandler public void onSplit(SlimeSplitEvent event) { - for (SlimeData slimeData : _slimes) + for (SlimePart slimeData : _slimes) { - if (event.getEntity().equals(slimeData.Entity)) + if (event.getEntity().equals(slimeData.getEntity())) event.setCancelled(true); } } @@ -119,37 +87,38 @@ public class SlimeBoss extends AbstractBoss { if (event.getEntity().getType() == EntityType.SLIME) { - for (SlimeData slimeData : _slimes) - { - if (slimeData.Entity.equals(event.getEntity())) - { - splitSlime(slimeData.Entity); + Iterator slimeIterator = _slimes.iterator(); - checkDeath(); + while (slimeIterator.hasNext()) + { + SlimePart slimePart = slimeIterator.next(); + + if (slimePart.getEntity().equals(event.getEntity())) + { + splitSlime(slimePart); + event.setDroppedExp(0); + slimeIterator.remove(); + break; } } + + // Check if our main boss died every time a slime entity dies + checkDeath(); } } + /** + * Check if this slime boss has been defeated + */ private void checkDeath() { if (_slimes.size() == 0) { + // SLIME IS DEAD! setHealth(0); } } - public Player getRandomTarget(Location location, double maxDist) - { - List nearby = UtilPlayer.getNearby(location, maxDist); - return nearby.get(getRandom().nextInt(nearby.size())); - } - - public void rotateState() - { - - } - public int getSplitSize(int currSize) { return currSize / 2; @@ -165,7 +134,7 @@ public class SlimeBoss extends AbstractBoss return slimeSize * 20; } - private void splitSlime(Slime slime) + private void splitSlime(SlimePart slime) { int splitCount = getSplitCount(slime.getSize()); int splitSize = getSplitSize(slime.getSize()); @@ -174,19 +143,16 @@ public class SlimeBoss extends AbstractBoss { for (int i = 0; i < splitCount; i++) { - spawnSlime(slime.getLocation(), splitSize); + spawnSlime(slime.getEntity().getLocation(), splitSize); } } } - private Slime spawnSlime(Location location, int size) + private SlimePart spawnSlime(Location location, int size) { - Slime slime = location.getWorld().spawn(location, Slime.class); - slime.setSize(size); - slime.setMaxHealth(getMaxSlimeHealth(size)); - slime.setHealth(slime.getMaxHealth()); - _slimes.add(new SlimeData(slime)); - return slime; + SlimePart slimePart = new SlimePart(this, location, size, getMaxSlimeHealth(size)); + _slimes.add(slimePart); + return slimePart; } @Override @@ -194,15 +160,4 @@ public class SlimeBoss extends AbstractBoss { Bukkit.broadcastMessage("DEATH"); } - - private static class SlimeData - { - private final Slime Entity; - private BossState State; - - public SlimeData(Slime slime) - { - Entity = slime; - } - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java new file mode 100644 index 000000000..123f74066 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java @@ -0,0 +1,110 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime; + +import org.bukkit.Location; +import org.bukkit.entity.MagmaCube; +import org.bukkit.entity.Slime; + +import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.AbsorbAbility; +import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.RocketAbility; +import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlamAbility; +import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlimeAbility; + +public class SlimePart +{ + private SlimeBoss _boss; + private Slime _slime; + private SlimeAbility _currentAbility; + private Location _spawnLocation; + private boolean _enraged; + // Storing size here incase one of the slime states decide to change the slime size + private int _size; + private double _maxHealth; + private int _ticksLived; + + public SlimePart(SlimeBoss boss, Location location, int size, double maxHealth) + { + _boss = boss; + _spawnLocation = location; + _enraged = false; + _size = size; + _maxHealth = maxHealth; + _ticksLived = 0; + spawn(location); + } + + private void spawn(Location location) + { + double health = _maxHealth; + + // Remove old slime + if (_slime != null) + { + health = _slime.getHealth(); + _slime.remove(); + } + + _slime = location.getWorld().spawn(location, _enraged ? MagmaCube.class : Slime.class); + _slime.setMaxHealth(_maxHealth); + _slime.setHealth(health); + _slime.setSize(_size); + } + + public void tick() + { + _ticksLived++; + + if (_currentAbility == null || (_currentAbility.isIdle() && _currentAbility.getIdleTicks() > 80)) + { + double rand = Math.random(); + + if (rand <= 0.33) + { + _currentAbility = new AbsorbAbility(this); + } + else if (rand <= 0.66) + { + _currentAbility = new RocketAbility(this); + } + else + { + _currentAbility = new SlamAbility(this); + } + } + + _currentAbility.tick(); + } + + public void setEnraged(boolean enraged) + { + if (enraged != _enraged) + { + _enraged = enraged; + spawn(_slime.getLocation()); + } + } + + public SlimeBoss getBoss() + { + return _boss; + } + + public boolean isEnraged() + { + return _enraged; + } + + public int getSize() + { + return _size; + } + + public Location getSpawnLocation() + { + return _spawnLocation; + } + + public Slime getEntity() + { + return _slime; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/AbsorbAbility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/AbsorbAbility.java new file mode 100644 index 000000000..a8329ba00 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/AbsorbAbility.java @@ -0,0 +1,71 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; + +public class AbsorbAbility extends SlimeAbility +{ + private int _ticksPerPulse; + private int _pulseMax; + private int _pulseCount; + private int _maxDistance; + + public AbsorbAbility(SlimePart slime) + { + super(slime); + _ticksPerPulse = 20; + _pulseMax = 10; + _pulseCount = 0; + _maxDistance = 20; + } + + @Override + public void tickCustom() + { + if (getTicks() % _ticksPerPulse == 0) + { + pulse(); + _pulseCount++; + + if (_pulseCount >= _pulseMax) + { + setIdle(true); + } + } + } + + private void pulse() + { + Bukkit.broadcastMessage("Pulse"); + HashMap playerMap = UtilPlayer.getInRadius(getSlime().getEntity().getLocation(), _maxDistance); + + for (Map.Entry entry : playerMap.entrySet()) + { + Player player = entry.getKey(); + double distance = entry.getValue(); + + Vector dir = UtilAlg.getTrajectory2d(player, getSlime().getEntity()); + dir.setY(0.4); + player.setVelocity(dir); + getSlime().getBoss().getDamageManager().NewDamageEvent(player, getSlime().getEntity(), null, + EntityDamageEvent.DamageCause.MAGIC, getDamage(distance), false, false, false, getSlime().getBoss().getName(), "Absorb"); + } + } + + private double getDamage(double distance) + { + double mult = _maxDistance - distance; + + return mult * 0.25; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/RocketAbility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/RocketAbility.java new file mode 100644 index 000000000..101b89b89 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/RocketAbility.java @@ -0,0 +1,149 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; + +import java.util.Iterator; +import java.util.LinkedList; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Slime; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.core.projectile.IThrown; +import mineplex.core.projectile.ProjectileManager; +import mineplex.core.projectile.ProjectileUser; +import mineplex.core.updater.UpdateType; +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; + +public class RocketAbility extends SlimeAbility implements IThrown +{ + private int _rocketCount; + private int _rocketsFired; + private int _rocketsHit; + private LinkedList _shots; + + public RocketAbility(SlimePart slime) + { + this(slime, 5); + } + + public RocketAbility(SlimePart slime, int rocketCount) + { + super(slime); + _rocketCount = rocketCount; + _rocketsFired = 0; + _rocketsHit = 0; + _shots = new LinkedList(); + } + + @Override + public void tickCustom() + { + if (_rocketsHit >= _rocketCount) + { + // We're done here! + setIdle(true); + return; + } + + if (_rocketsFired < _rocketCount && getTicks() % 20 == 0) + { + Player target = UtilPlayer.getRandomTarget(getSlime().getEntity().getLocation(), 20); + + if (target == null && getTicks() > 20 * (_rocketCount + 10)) + { + // Give up on firing more rockets + _rocketCount = _rocketsFired; + } + + if (target != null) fireRocket(target); + } + + tickRockets(); + } + + private void tickRockets() + { + Iterator it = _shots.iterator(); + + while (it.hasNext()) + { + ShotData next = it.next(); + + if (next.getEntity().isDead()) + { + it.remove(); + } + else + { + Vector v = UtilAlg.getTrajectory(next.getEntity(), next.getTarget()); + next.getEntity().setVelocity(v.multiply(new Vector(0.3, 0.1, 0.3))); + } + + } + } + + private void fireRocket(Player target) + { + Location loc = getSlime().getEntity().getLocation(); + loc.add(loc.getDirection().normalize().multiply(2)); + Slime projectile = loc.getWorld().spawn(loc, Slime.class); + projectile.setSize(2); + _shots.add(new ShotData(projectile, target)); + + ProjectileManager pm = getSlime().getBoss().getEventManager().getClans().getProjectile(); + pm.AddThrow(projectile, getSlime().getEntity(), this, -1, true, true, true, null, 0, 0, UtilParticle.ParticleType.SLIME, UpdateType.FASTEST, 1F); + Bukkit.broadcastMessage("Shot Slime at target " + target); + + _rocketsFired++; + } + + @Override + public void Collide(LivingEntity target, Block block, ProjectileUser data) + { + Bukkit.broadcastMessage("COLLIDE " + target); + UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); + data.GetThrown().remove(); + _rocketsHit++; + } + + @Override + public void Idle(ProjectileUser data) + { + + } + + @Override + public void Expire(ProjectileUser data) + { + + } + + private static class ShotData + { + private LivingEntity _entity; + private LivingEntity _target; + + public ShotData(LivingEntity entity, LivingEntity target) + { + _entity = entity; + _target = target; + } + + public LivingEntity getEntity() + { + return _entity; + } + + public LivingEntity getTarget() + { + return _target; + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java new file mode 100644 index 000000000..1feabbd5f --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java @@ -0,0 +1,156 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; + +import java.util.LinkedList; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; + +public class SlamAbility extends SlimeAbility +{ + private int _findAttempts; + private boolean _hasTarget; + private int _foundTicks; + private Player _target; + private Location _targetLocation; + + // Timings + private final int _lockTick; + private final int _jumpTick; + private final int _diveTick; + + public SlamAbility(SlimePart slime) + { + this(slime, 40, 60, 80); + } + + public SlamAbility(SlimePart slime, int lockTick, int jumpTick, int diveTick) + { + super(slime); + _hasTarget = false; + _findAttempts = 0; + _foundTicks = 0; + + assert (jumpTick > lockTick && diveTick > jumpTick); + _lockTick = lockTick; + _jumpTick = jumpTick; + _diveTick = diveTick; + } + + @Override + public void tickCustom() + { + if (!_hasTarget) + { + if (getTicks() % 20 == 0) + { + searchForTarget(); + } + } + else + { + int ticks = getTicks() - _foundTicks; + if (ticks < _lockTick) + { + // Follow Target + displayTarget(_target.getLocation()); + } + else if (ticks == _lockTick) + { + // Lock on + Bukkit.broadcastMessage("Target Locked"); + _targetLocation = _target.getLocation(); + } + else if (ticks < _jumpTick) + { + // Target still locked + displayTarget(_targetLocation); + } + else if (ticks == _jumpTick) + { + // Target starts jump + Bukkit.broadcastMessage("Start Jump"); + } + else if (ticks > _jumpTick) + { + // Target in air + displayTarget(_targetLocation); + + Vector direction = UtilAlg.getTrajectory2d(getSlime().getEntity().getLocation(), _targetLocation); + direction.multiply(0.4); + direction.setY(2 * (1 - ((getTicks() - 100.0) / 60.0))); + getSlime().getEntity().setVelocity(direction); + } + else if (ticks == _diveTick) + { + displayTarget(_targetLocation); + + // Time to go down! + getSlime().getEntity().setVelocity(new Vector(0, -3, 0)); + getSlime().getEntity().setFallDistance(0); + } + else if (ticks > _diveTick) + { + displayTarget(_targetLocation); + + // Check for hitting ground + if (getSlime().getEntity().isOnGround()) + { + // We're done here! + setIdle(true); + + damageArea(getSlime().getEntity().getLocation()); + + } + } + + } + } + + private void damageArea(Location location) + { + // TODO Deal more damage based on how close you are to the slime? + LinkedList nearPlayers = UtilPlayer.getNearby(location, 4); + for (Player player : nearPlayers) + { + player.damage(4); + player.setVelocity(UtilAlg.getTrajectory2d(location, player.getLocation()).setY(0.2)); + } + + UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, location, 2, 0.5F, 2, 0, 100, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); + location.getWorld().playSound(location, Sound.ANVIL_LAND, 10, 0.5F); + } + + private void displayTarget(Location location) + { + UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, location, 0, 0, 0, 0, 1, UtilParticle.ViewDist.NORMAL, UtilServer.getPlayers()); + } + + private void searchForTarget() + { + if (_findAttempts >= 10) + { + // Just give up! THERE'S NO HOPE + setIdle(true); + return; + } + + Player target = UtilPlayer.getRandomTarget(getSlime().getEntity().getLocation(), 15); + if (target != null) + { + _target = target; + _foundTicks = getTicks(); + Bukkit.broadcastMessage("Target placed on " + _target); + } + + _findAttempts++; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlimeAbility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlimeAbility.java new file mode 100644 index 000000000..7d4560cc4 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlimeAbility.java @@ -0,0 +1,56 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; + +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; + +public abstract class SlimeAbility +{ + private SlimePart _slime; + private boolean _idle; + private int _ticks; + private int _idleTicks; + + public SlimeAbility(SlimePart slime) + { + _slime = slime; + } + + public final void tick() + { + if (isIdle()) + { + _idleTicks++; + } + else + { + _ticks++; + tickCustom(); + } + } + + public int getTicks() + { + return _ticks; + } + + public int getIdleTicks() + { + return _idleTicks; + } + + public boolean isIdle() + { + return _idle; + } + + public SlimePart getSlime() + { + return _slime; + } + + public abstract void tickCustom(); + + protected void setIdle(boolean idle) + { + _idle = idle; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java index ec6757d92..0b52dce01 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/RocketState.java @@ -61,23 +61,7 @@ public class RocketState extends BossState implements IThrown // getBoss().setState(new AbsorbState(getBoss(), ((Slime) _shooter), 20 * 2)); } - Iterator it = _shots.iterator(); - while (it.hasNext()) - { - ShotData next = it.next(); - - if (next.getEntity().isDead()) - { - it.remove(); - } - else - { - Vector v = UtilAlg.getTrajectory(next.getEntity(), next.getTarget()); - next.getEntity().setVelocity(v.multiply(new Vector(0.3, 0.1, 0.3))); - } - - } } @Override @@ -94,16 +78,7 @@ public class RocketState extends BossState implements IThrown private void fireProjectile(LivingEntity target) { - Location loc = _shooter.getEyeLocation(); - loc.add(loc.getDirection().normalize().multiply(2)); - Slime projectile = loc.getWorld().spawn(loc, Slime.class); - projectile.setSize(2); -// projectile.setVelocity(direction); - _shots.add(new ShotData(projectile, target)); - ProjectileManager pm = getBoss().getEventManager().getClans().getProjectile(); - pm.AddThrow(projectile, _shooter, this, -1, true, true, true, null, 0, 0, UtilParticle.ParticleType.SLIME, UpdateType.FASTEST, 1F); - Bukkit.broadcastMessage("Shot Slime"); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java index 38d56855f..168213e6b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlamState.java @@ -88,20 +88,7 @@ public class SlamState extends BossState { if (event.getEntity().equals(_entity) && event.getCause() == EntityDamageEvent.DamageCause.FALL) { - Location fallLoc = _entity.getLocation(); - List nearby = _entity.getNearbyEntities(4, 4, 4); - for (Entity near : nearby) - { - if (near instanceof LivingEntity) - { - LivingEntity le = ((LivingEntity) near); - le.damage(4); - le.setVelocity(UtilAlg.getTrajectory2d(fallLoc, le.getLocation()).setY(0.2)); - } - } - UtilParticle.PlayParticle(UtilParticle.ParticleType.LAVA, fallLoc, 2, 0.5F, 2, 0, 100, UtilParticle.ViewDist.LONG, UtilServer.getPlayers()); - fallLoc.getWorld().playSound(fallLoc, Sound.ANVIL_LAND, 10, 0.5F); event.setCancelled(true); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlimeState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlimeState.java new file mode 100644 index 000000000..03eca3058 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/state/SlimeState.java @@ -0,0 +1,51 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime.state; + +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; + +public abstract class SlimeState +{ + private SlimePart _slime; + private boolean _idle; + private int _ticks; + private int _idleTicks; + + public SlimeState(SlimePart slime) + { + _slime = slime; + } + + public final void tick() + { + if (isIdle()) + { + _idleTicks++; + } + else + { + _ticks++; + tickCustom(); + } + } + + public int getTicks() + { + return _ticks; + } + + public int getIdleTicks() + { + return _idleTicks; + } + + public boolean isIdle() + { + return _idle; + } + + public abstract void tickCustom(); + + protected void setIdle(boolean idle) + { + _idle = idle; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java index 6e422c491..d38c94556 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/HillData.java @@ -54,5 +54,12 @@ public class HillData return x > minX && y > minY && z > minZ && x < maxX && y < maxY && z < maxZ; } + public Location getHillCenter(Location eventLocation) + { + Location hill = eventLocation.clone(); + hill.add(_hillX, _hillY, _hillZ); + hill.add(_lengthX / 2.0, _lengthY / 2.0, _lengthZ / 2.0); + return hill; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java index 0622523ea..851ebdb2f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/kinghill/KingHill.java @@ -15,6 +15,7 @@ import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent; +import mineplex.game.clans.economy.GoldManager; import mineplex.minecraft.game.core.damage.DamageManager; public class KingHill extends AbstractWorldEvent @@ -67,9 +68,6 @@ public class KingHill extends AbstractWorldEvent if (getTicks() % 5 == 0) tickHill(); - - - } private void tickHill() @@ -87,19 +85,27 @@ public class KingHill extends AbstractWorldEvent clanCount++; lastClan = playerClan; } - -// Bukkit.broadcastMessage(player.getName() + " IS ON THE HILL"); } } if (clanCount == 1 && lastClan != null) { Bukkit.broadcastMessage(lastClan.getName() + " owns the hill!"); + + CaptureData capData = _scoreMap.get(lastClan); + if (capData == null) + { + capData = new CaptureData(); + _scoreMap.put(lastClan, capData); + } + capData.TicksOnHill++; + + GoldManager.getInstance().dropGold(_hill.getHillCenter(getCenterLocation()), 20); } } private static class CaptureData { - public int Score; + public int TicksOnHill; } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java index 2268a2034..af4289ac1 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -1,35 +1,31 @@ package mineplex.game.clans.economy; -import java.util.Random; +import java.util.HashSet; +import java.util.Iterator; -import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Entity; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Item; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.Vector; +import mineplex.core.common.util.UtilAction; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.items.economy.GoldToken; import mineplex.core.MiniPlugin; -import mineplex.core.common.CurrencyType; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.creature.Creature; import mineplex.core.donation.DonationManager; import mineplex.core.donation.Donor; -import mineplex.core.energy.Energy; -import mineplex.game.clans.Clans; -import mineplex.game.clans.fields.repository.FieldRepository; -import mineplex.game.clans.items.generation.WeightSet; -import mineplex.minecraft.game.core.condition.ConditionFactory; -import mineplex.minecraft.game.core.condition.ConditionManager; public class GoldManager extends MiniPlugin { @@ -39,13 +35,15 @@ public class GoldManager extends MiniPlugin public static GoldManager getInstance() { return _instance; } private DonationManager _donationManager; - + private HashSet _itemSet; + public GoldManager(JavaPlugin plugin, DonationManager donationManager) { super("Clans Gold", plugin); _instance = this; _donationManager = donationManager; + _itemSet = new HashSet(); } @EventHandler @@ -75,10 +73,41 @@ public class GoldManager extends MiniPlugin { if (event.getMessage().startsWith("/gold")) { - notify(event.getPlayer(), "Your Balance is " + C.cYellow + getGold(event.getPlayer()) + "g"); + notify(event.getPlayer(), "Your Balance is " + C.cYellow + getGold(event.getPlayer()) + "g"); event.setCancelled(true); } } + + @EventHandler + public void onPickup(PlayerPickupItemEvent event) + { + if (_itemSet.contains(event.getItem())) + { + event.setCancelled(true); + event.getItem().remove(); + event.getPlayer().playSound(event.getPlayer().getEyeLocation(), Sound.ORB_PICKUP, 1F, 1F); + addGold(event.getPlayer(), 1); + } + } + + @EventHandler + public void cleanItems(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC) return; + + Iterator itemIterator = _itemSet.iterator(); + + while (itemIterator.hasNext()) + { + Item item = itemIterator.next(); + + if (!item.isValid() || item.getTicksLived() >= 12000) // 10 minutes + { + item.remove(); + itemIterator.remove(); + } + } + } public int getGold(Player player) { @@ -101,6 +130,25 @@ public class GoldManager extends MiniPlugin addGold(player, value); notify(player, String.format("You have cashed in a gold token worth %dg!", value)); } + + public void dropGold(Location location, int amount) + { + dropGold(location, amount, 1); + } + + public void dropGold(Location location, int amount, double mult) + { + for (int i = 0; i < amount; i++) + { + Item item = location.getWorld().dropItem(location, new ItemStack(Material.GOLD_INGOT)); + item.setPickupDelay(40); + + // Velocity + double x = Math.random() * 2 * Math.PI; + Vector velocity = new Vector(Math.sin(x), 0, Math.cos(x)); + UtilAction.velocity(item, velocity, mult, false, 0, 0.2, 0.5, false); + } + } private Donor getDonor(Player player) { From b2bdfe384b90d8cfee54d2061891e30075968007 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 6 Jun 2015 15:02:16 -0500 Subject: [PATCH 10/16] Fix IllegalArgumentException with UtilPlayer method --- .../src/mineplex/core/common/util/UtilPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java index a9dff7549..ce3443851 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilPlayer.java @@ -620,7 +620,7 @@ public class UtilPlayer public static Player getRandomTarget(Location location, double maxDist) { List nearby = getNearby(location, maxDist); - return nearby.get(RANDOM.nextInt(nearby.size())); + return nearby.size() > 0 ? nearby.get(RANDOM.nextInt(nearby.size())) : null; } public static boolean isSpectator(Entity player) From 6ea000fd22bc947b60e5a3e44f5ec4c35117df9d Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 6 Jun 2015 15:16:03 -0500 Subject: [PATCH 11/16] Remove slimes when server stops --- .../game/clans/clans/worldevent/WorldEventManager.java | 9 +++++++++ .../clans/worldevent/event/boss/slime/SlimeBoss.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index 6506db8a6..35f06233d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -35,6 +35,15 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener _events = new HashSet(); } + @Override + public void disable() + { + for (AbstractWorldEvent event : _events) + { + event.cancel(); + } + } + private void initializeEvent(AbstractWorldEvent event) { assert(event != null); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index fad9f2c1e..1e19926fd 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -42,6 +42,12 @@ public class SlimeBoss extends AbstractBoss protected void customCancel() { Bukkit.broadcastMessage("Custom Cancel"); + + // Remove all the slime entities! + for (SlimePart slime : _slimes) + { + slime.getEntity().remove(); + } } @Override From 24a10168365c518d65d1bff29e34bec776334027 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 6 Jun 2015 15:39:51 -0500 Subject: [PATCH 12/16] Slime enrage --- .../worldevent/event/boss/slime/SlimeBoss.java | 15 ++++++++++----- .../worldevent/event/boss/slime/SlimePart.java | 9 ++++++++- .../event/boss/slime/ability/SlamAbility.java | 1 + .../mineplex/game/clans/economy/GoldManager.java | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java index 1e19926fd..a8eb659e8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimeBoss.java @@ -125,21 +125,26 @@ public class SlimeBoss extends AbstractBoss } } - public int getSplitSize(int currSize) + private int getSplitSize(int slimeSize) { - return currSize / 2; + return slimeSize / 2; } - public int getSplitCount(int currSize) + private int getSplitCount(int slimeSize) { return 4; } - public double getMaxSlimeHealth(int slimeSize) + private double getMaxSlimeHealth(int slimeSize) { return slimeSize * 20; } + private int getEnrageTicks(int slimeSize) + { + return 20 * slimeSize; + } + private void splitSlime(SlimePart slime) { int splitCount = getSplitCount(slime.getSize()); @@ -156,7 +161,7 @@ public class SlimeBoss extends AbstractBoss private SlimePart spawnSlime(Location location, int size) { - SlimePart slimePart = new SlimePart(this, location, size, getMaxSlimeHealth(size)); + SlimePart slimePart = new SlimePart(this, location, size, getMaxSlimeHealth(size), getEnrageTicks(size)); _slimes.add(slimePart); return slimePart; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java index 123f74066..de3391ba5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java @@ -20,8 +20,9 @@ public class SlimePart private int _size; private double _maxHealth; private int _ticksLived; + private int _enrageTicks; - public SlimePart(SlimeBoss boss, Location location, int size, double maxHealth) + public SlimePart(SlimeBoss boss, Location location, int size, double maxHealth, int enrageTicks) { _boss = boss; _spawnLocation = location; @@ -29,6 +30,7 @@ public class SlimePart _size = size; _maxHealth = maxHealth; _ticksLived = 0; + _enrageTicks = enrageTicks; spawn(location); } @@ -71,6 +73,11 @@ public class SlimePart } } + if (!_enraged && _ticksLived >= _enrageTicks) + { + setEnraged(true); + } + _currentAbility.tick(); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java index 1feabbd5f..9df74b3fe 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/SlamAbility.java @@ -147,6 +147,7 @@ public class SlamAbility extends SlimeAbility if (target != null) { _target = target; + _hasTarget = true; _foundTicks = getTicks(); Bukkit.broadcastMessage("Target placed on " + _target); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java index af4289ac1..98f2a9c76 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -85,7 +85,7 @@ public class GoldManager extends MiniPlugin { event.setCancelled(true); event.getItem().remove(); - event.getPlayer().playSound(event.getPlayer().getEyeLocation(), Sound.ORB_PICKUP, 1F, 1F); + event.getPlayer().playSound(event.getPlayer().getEyeLocation(), Sound.ORB_PICKUP, 1F, 2F); addGold(event.getPlayer(), 1); } } From ed1c275347d9e9ef6a7c5fd3ab118d922d1723b0 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 6 Jun 2015 15:48:29 -0500 Subject: [PATCH 13/16] Add Nautilus.Game.PvP to IntelliJ --- Plugins/.idea/modules.xml | 5 +++-- Plugins/Nautilus.Game.PvP/Nautilus.Game.PvP.iml | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 Plugins/Nautilus.Game.PvP/Nautilus.Game.PvP.iml diff --git a/Plugins/.idea/modules.xml b/Plugins/.idea/modules.xml index beb559c38..bcc742412 100644 --- a/Plugins/.idea/modules.xml +++ b/Plugins/.idea/modules.xml @@ -3,7 +3,7 @@ - + @@ -14,9 +14,10 @@ - + + \ No newline at end of file diff --git a/Plugins/Nautilus.Game.PvP/Nautilus.Game.PvP.iml b/Plugins/Nautilus.Game.PvP/Nautilus.Game.PvP.iml new file mode 100644 index 000000000..0a2adb96d --- /dev/null +++ b/Plugins/Nautilus.Game.PvP/Nautilus.Game.PvP.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file From 8c7faf27ddf567bcc25ade9b08af6750c4fdd344 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 6 Jun 2015 16:04:11 -0500 Subject: [PATCH 14/16] Store gold drop amounts in item metadata (might be worth switching to our own storage?) --- Plugins/.idea/compiler.xml | 6 +++-- .../game/clans/economy/GoldManager.java | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Plugins/.idea/compiler.xml b/Plugins/.idea/compiler.xml index c01fc77f0..ccd5607c1 100644 --- a/Plugins/.idea/compiler.xml +++ b/Plugins/.idea/compiler.xml @@ -2,6 +2,9 @@ - + \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java index 98f2a9c76..370a82b8f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -2,6 +2,7 @@ package mineplex.game.clans.economy; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import org.bukkit.Location; import org.bukkit.Material; @@ -13,6 +14,8 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; +import org.bukkit.metadata.MetadataValue; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -30,6 +33,7 @@ import mineplex.core.donation.Donor; public class GoldManager extends MiniPlugin { public static final double DEATH_TAX = 0.04d; // Percentage of gold lost on death + public static final String META_STRING = "clans.goldAmount"; private static GoldManager _instance; public static GoldManager getInstance() { return _instance; } @@ -84,9 +88,17 @@ public class GoldManager extends MiniPlugin if (_itemSet.contains(event.getItem())) { event.setCancelled(true); + + int goldAmount = 1; + List meta = event.getItem().getMetadata(META_STRING); + if (meta != null && meta.size() == 1) + { + goldAmount = meta.get(0).asInt(); + } + event.getItem().remove(); event.getPlayer().playSound(event.getPlayer().getEyeLocation(), Sound.ORB_PICKUP, 1F, 2F); - addGold(event.getPlayer(), 1); + addGold(event.getPlayer(), goldAmount); } } @@ -133,20 +145,23 @@ public class GoldManager extends MiniPlugin public void dropGold(Location location, int amount) { - dropGold(location, amount, 1); + dropGold(location, amount, true, 1); } - public void dropGold(Location location, int amount, double mult) + public void dropGold(Location location, int amount, boolean stacking, double velMult) { + // TODO Stacking + for (int i = 0; i < amount; i++) { Item item = location.getWorld().dropItem(location, new ItemStack(Material.GOLD_INGOT)); item.setPickupDelay(40); + item.setMetadata(META_STRING, new FixedMetadataValue(getPlugin(), 1)); // Velocity double x = Math.random() * 2 * Math.PI; Vector velocity = new Vector(Math.sin(x), 0, Math.cos(x)); - UtilAction.velocity(item, velocity, mult, false, 0, 0.2, 0.5, false); + UtilAction.velocity(item, velocity, velMult, false, 0, 0.2, 0.5, false); } } From aa9aba92cd30d021d7fc302a8e7e8da5f38532d4 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 8 Jun 2015 14:59:06 -0500 Subject: [PATCH 15/16] Commit for merge --- .../worldevent/creature/EventCreature.java | 26 ++++++++ .../event/boss/slime/SlimePart.java | 9 ++- .../event/boss/slime/ability/LeapAbility.java | 64 +++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/creature/EventCreature.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/LeapAbility.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/creature/EventCreature.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/creature/EventCreature.java new file mode 100644 index 000000000..34b0e60a2 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/creature/EventCreature.java @@ -0,0 +1,26 @@ +package mineplex.game.clans.clans.worldevent.creature; + +import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.Listener; + +public abstract class EventCreature implements Listener +{ + private T _entity; + + // Creature Data + private String _name; + private double _health; + private double _maxHealth; + + + + public EventCreature(Location spawnLocation, Class clazz) + { + + + _entity = spawnLocation.getWorld().spawn(spawnLocation, clazz); + } + + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java index de3391ba5..a0f8b2b0e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/SlimePart.java @@ -5,6 +5,7 @@ import org.bukkit.entity.MagmaCube; import org.bukkit.entity.Slime; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.AbsorbAbility; +import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.LeapAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.RocketAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlamAbility; import mineplex.game.clans.clans.worldevent.event.boss.slime.ability.SlimeAbility; @@ -59,11 +60,15 @@ public class SlimePart { double rand = Math.random(); - if (rand <= 0.33) + if (rand <= 0.25) + { + _currentAbility = new LeapAbility(this); + } + else if (rand <= 0.50) { _currentAbility = new AbsorbAbility(this); } - else if (rand <= 0.66) + else if (rand <= 0.75) { _currentAbility = new RocketAbility(this); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/LeapAbility.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/LeapAbility.java new file mode 100644 index 000000000..4efaebbc6 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/boss/slime/ability/LeapAbility.java @@ -0,0 +1,64 @@ +package mineplex.game.clans.clans.worldevent.event.boss.slime.ability; + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilPlayer; +import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart; + +public class LeapAbility extends SlimeAbility +{ + private Player _target; + private int _jumpTick; + + public LeapAbility(SlimePart slime) + { + super(slime); + + _target = UtilPlayer.getRandomTarget(slime.getEntity().getLocation(), 10); + _jumpTick = 20; + + // Only attempt to find a target once for this ability! + if (_target == null) + { + setIdle(true); + } + } + + @Override + public void tickCustom() + { + if (_target != null) + { + if (getTicks() == _jumpTick) + { + // Jump + Vector dir = UtilAlg.getTrajectory2d(getSlime().getEntity(), _target); + UtilAction.velocity(getSlime().getEntity(), dir, 1, false, 0, 1, 1, true); + } + else if (getTicks() > _jumpTick) + { + if (getSlime().getEntity().isOnGround()) + { + setIdle(true); + } + else if (getSlime().isEnraged()) + { + World world = getSlime().getEntity().getWorld(); + Block block = world.getHighestBlockAt(getSlime().getEntity().getLocation()).getRelative(BlockFace.UP); + + if (block.getType() == Material.AIR) + { + block.setType(Material.FIRE); + } + } + } + } + } +} From d1a7d168102c27bde967fff15bbae1b0329c22f6 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 8 Jun 2015 15:04:30 -0500 Subject: [PATCH 16/16] Fixes GoldManager --- .../src/mineplex/game/clans/economy/GoldManager.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java index ec312577e..0affbac4f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/GoldManager.java @@ -16,7 +16,6 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import mineplex.core.common.util.UtilAction; @@ -25,20 +24,13 @@ import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.items.economy.GoldToken; import mineplex.core.MiniPlugin; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.CurrencyType; import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; import mineplex.core.donation.Donor; -import mineplex.core.energy.Energy; -import mineplex.game.clans.Clans; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.fields.repository.FieldRepository; -import mineplex.game.clans.items.generation.WeightSet; import mineplex.game.clans.shop.bank.BankShop; -import mineplex.minecraft.game.core.condition.ConditionFactory; -import mineplex.minecraft.game.core.condition.ConditionManager; public class GoldManager extends MiniPlugin { @@ -50,8 +42,6 @@ public class GoldManager extends MiniPlugin private DonationManager _donationManager; private HashSet _itemSet; - - public GoldManager(JavaPlugin plugin, DonationManager donationManager) private BankShop _bankShop; public GoldManager(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)