From cfb84dd54530bc6e51c3a025041ed17a43e1abc2 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 24 Mar 2016 21:14:13 +0000 Subject: [PATCH 1/2] fixes for shaun --- .../tutorials/clans/objective/goals/clan/AttackEnemyGoal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java index 5c24fc9ce..c0f004618 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java @@ -41,7 +41,7 @@ public class AttackEnemyGoal extends ObjectiveGoal _cannon = SiegeManager.Instance.spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON)); - _cannon.SetForcedVelocity(0.4, -2.45); + _cannon.SetForcedVelocity(0.4, 2.45); } // use this event for figuring out if the cannon hit the base From af87dc93844124dd564ca4f7f623e979b9adf043 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 24 Mar 2016 21:26:40 +0000 Subject: [PATCH 2/2] unsynchronized siege weapon support --- .../game/clans/clans/siege/SiegeManager.java | 19 +++++++++++++++---- .../game/clans/clans/siege/weapon/Cannon.java | 4 +++- .../clans/clans/siege/weapon/SiegeWeapon.java | 10 +++++++++- .../objective/goals/clan/AttackEnemyGoal.java | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index b84f912b2..68cce9ada 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -42,6 +42,7 @@ public class SiegeManager extends MiniPlugin public static SiegeManager Instance; public NautHashMap LiveSiegeWeapons = new NautHashMap<>(); + public NautHashMap UnsyncedSiegeWeapons = new NautHashMap<>(); private Gson _gson; @@ -174,6 +175,9 @@ public class SiegeManager extends MiniPlugin { final SiegeWeaponToken token = weapon.toToken(); + if (UnsyncedSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId))) + continue; + queue.push(() -> { _repository.updateWeapon(token); }); @@ -190,7 +194,7 @@ public class SiegeManager extends MiniPlugin _repository.getWeaponsByServer(_clansManager.getServerId(), tokens -> { tokens.forEach(token -> { - if (!LiveSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId))) + if (!LiveSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId)) && !UnsyncedSiegeWeapons.containsKey(Integer.valueOf(token.UniqueId))) { System.out.println("LiveSiegeWeapons no longer contains old weapon " + token.UniqueId + ", deleting."); _repository.deleteWeapon(token.UniqueId); @@ -264,9 +268,14 @@ public class SiegeManager extends MiniPlugin public Cannon spawnCannon(Player player, Location location) { - Cannon cannon = new Cannon(location, _clansManager.getClan(player), this); + return spawnCannon(player, location, true); + } - LiveSiegeWeapons.put(Integer.valueOf(cannon.getUniqueId()), cannon); + public Cannon spawnCannon(Player player, Location location, boolean syncWithDb) + { + Cannon cannon = new Cannon(location, _clansManager.getClan(player), this, syncWithDb); + + UnsyncedSiegeWeapons.put(Integer.valueOf(cannon.getUniqueId()), cannon); return cannon; } @@ -274,8 +283,10 @@ public class SiegeManager extends MiniPlugin public void dead(SiegeWeapon weapon) { LiveSiegeWeapons.remove(Integer.valueOf(weapon.getUniqueId())); + SiegeWeapon unsynced = UnsyncedSiegeWeapons.remove(Integer.valueOf(weapon.getUniqueId())); - _repository.deleteWeapon(weapon.getUniqueId()); + if (unsynced == null) + _repository.deleteWeapon(weapon.getUniqueId()); } public OutpostManager getOutpostManager() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java index 2cdc6ed89..bba2dfe74 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/Cannon.java @@ -122,10 +122,12 @@ public class Cannon extends SiegeWeapon })); } - public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager) + public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, boolean syncWithDb) { super(2, location, 1400, "Cannon", clan, clan.Clans, siegeManager); + _syncWithDb = syncWithDb; + setBoundingBox(1); setStateInfo("Unloaded", new WeaponStateInfo(Material.SPONGE, (byte) 1)); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 6182b788b..5fbd2d890 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -112,6 +112,8 @@ public abstract class SiegeWeapon implements Listener protected final NautHashMap _registeredStates; protected final NautHashMap _entityMapping; + protected boolean _syncWithDb; + // Customizability private double[] _forcedVelocity; @@ -202,7 +204,8 @@ public abstract class SiegeWeapon implements Listener protected void insert() { - _siegeManager.getRepository().insertWeapon(toToken()); + if (_syncWithDb) + _siegeManager.getRepository().insertWeapon(toToken()); } protected int calculateDamage(Player player) @@ -882,6 +885,11 @@ public abstract class SiegeWeapon implements Listener return _currentState; } + public final boolean shouldSyncWithDb() + { + return _syncWithDb; + } + public SiegeWeaponToken toToken() { SiegeWeaponToken token = new SiegeWeaponToken(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java index e1b531fb2..d11f22f51 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/clans/objective/goals/clan/AttackEnemyGoal.java @@ -39,7 +39,7 @@ public class AttackEnemyGoal extends ObjectiveGoal { UtilInv.give(player, Material.TNT); - _cannon = SiegeManager.Instance.spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON)); + _cannon = SiegeManager.Instance.spawnCannon(player, getObjective().getPlugin().getPoint(getObjective().getPlugin().getRegion(player), Point.CANNON), false); _cannon.SetForcedVelocity(0.4, 2.45); }