Merge remote-tracking branch 'origin/clans/beta' into clans/beta

This commit is contained in:
Shaun Bennett 2016-03-25 08:44:08 +11:00
commit 628604c353
4 changed files with 29 additions and 8 deletions

View File

@ -42,6 +42,7 @@ public class SiegeManager extends MiniPlugin
public static SiegeManager Instance;
public NautHashMap<Integer, SiegeWeapon> LiveSiegeWeapons = new NautHashMap<>();
public NautHashMap<Integer, SiegeWeapon> 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()

View File

@ -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));

View File

@ -112,6 +112,8 @@ public abstract class SiegeWeapon implements Listener
protected final NautHashMap<String, WeaponStateInfo> _registeredStates;
protected final NautHashMap<String, Entity> _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();

View File

@ -36,9 +36,9 @@ public class AttackEnemyGoal extends ObjectiveGoal<ClanObjective>
{
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);
_cannon.SetForcedVelocity(0.4, 2.45);
}
// use this event for figuring out if the cannon hit the base