outpost saving and loadi9ng

This commit is contained in:
NewGarbo 2016-02-15 11:24:29 +00:00
parent 93a5ca6777
commit e25accfba4
26 changed files with 800 additions and 542 deletions

View File

@ -145,10 +145,13 @@ public abstract class RepositoryBase implements Listener
} }
try (ResultSet resultSet = statement.executeQuery()) try (ResultSet resultSet = statement.executeQuery())
{
if (callable != null)
{ {
callable.processResultSet(resultSet); callable.processResultSet(resultSet);
} }
} }
}
catch (SQLException exception) catch (SQLException exception)
{ {
exception.printStackTrace(); exception.printStackTrace();

View File

@ -561,6 +561,11 @@ public class ClanRepository extends RepositoryBase
// new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId)); // new ColumnInt("otherClanKills", otherClanKills), new ColumnInt("clanId", clanId), new ColumnInt("otherClanId", otherClanId));
// } // }
public int getServerId()
{
return _serverId;
}
public boolean updateClanGenerator(int clanId, String generator, int generatorStock) public boolean updateClanGenerator(int clanId, String generator, int generatorStock)
{ {
return executeUpdate(UPDATE_CLAN_GENERATOR, new ColumnVarChar("generator", 140, generator), new ColumnInt("generatorStock", generatorStock), new ColumnInt("clanId", clanId)) return executeUpdate(UPDATE_CLAN_GENERATOR, new ColumnVarChar("generator", 140, generator), new ColumnInt("generatorStock", generatorStock), new ColumnInt("clanId", clanId))

View File

@ -256,7 +256,6 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
_itemMapManager = new ItemMapManager(this, _worldEvent); _itemMapManager = new ItemMapManager(this, _worldEvent);
new TntGeneratorManager(plugin, this); new TntGeneratorManager(plugin, this);
new SupplyDropManager(plugin, this); new SupplyDropManager(plugin, this);
new SiegeManager(plugin, this);
_explosion = new Explosion(plugin, blockRestore); _explosion = new Explosion(plugin, blockRestore);
_warPointEvasion = new WarPointEvasion(plugin); _warPointEvasion = new WarPointEvasion(plugin);
@ -383,6 +382,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
} }
Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict"); Bukkit.getMessenger().registerOutgoingPluginChannel(plugin, "Replay|Restrict");
new SiegeManager(plugin, this);
} }
@Override @Override
@ -1174,4 +1175,9 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
return null; return null;
} }
public int getServerId()
{
return _clanDataAccess.getRepository().getServerId();
}
} }

View File

@ -206,6 +206,19 @@ public class ClansUtility
return Clans.getClan(clan); return Clans.getClan(clan);
} }
public ClanInfo getClanById(int id)
{
for (ClanInfo clan : Clans.getClanMap().values())
{
if (clan.getId() == id)
{
return clan;
}
}
return null;
}
public ClanInfo getClanByPlayer(Player player) public ClanInfo getClanByPlayer(Player player)
{ {
return getClanByUUID(player.getUniqueId()); return getClanByUUID(player.getUniqueId());

View File

@ -4,8 +4,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -14,26 +12,24 @@ import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv; import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies; import mineplex.game.clans.clans.siege.commands.CommandSiegeSupplies;
import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Cannon;
import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.Catapult;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken;
import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.spawn.Spawn;
public class SiegeManager extends MiniPlugin public class SiegeManager extends MiniPlugin
{ {
@ -43,7 +39,7 @@ public class SiegeManager extends MiniPlugin
public static SiegeManager Instance; public static SiegeManager Instance;
public Map<String, SiegeWeapon> LiveSiegeWeapons = new HashMap<>(); public Map<Integer, SiegeWeapon> LiveSiegeWeapons = new HashMap<>();
private Gson _gson; private Gson _gson;
@ -57,98 +53,32 @@ public class SiegeManager extends MiniPlugin
_outpostManager = new OutpostManager(clans, this); _outpostManager = new OutpostManager(clans, this);
_outpostManager.loadExistingOutposts();
loadExistingWeapons();
addCommand(new CommandSiegeSupplies(_outpostManager)); addCommand(new CommandSiegeSupplies(_outpostManager));
Instance = this; Instance = this;
_outpostManager.loadOutposts();
loadSiegeWeapons();
} }
@EventHandler @EventHandler
public void onUpdate(UpdateEvent event) public void save(UpdateEvent event)
{ {
if (event.getType() == UpdateType.SLOWER) if (event.getType() == UpdateType.SLOWER)
{ {
_outpostManager.loadExistingOutposts(); _outpostManager.saveOutposts();
saveSiegeWeapons();
loadExistingWeapons();
} }
} }
private void loadExistingWeapons() private void loadSiegeWeapons()
{ {
try
{
for (Entity entity : Spawn.getSpawnWorld().getEntities())
{
if (!(entity instanceof ArmorStand))
{
continue;
}
if (!entity.hasMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$") ||!entity.hasMetadata("$TOKEN_INFO$"))
{
continue;
}
String data = entity.getMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$").get(0).asString();
SiegeWeaponToken token = _gson.fromJson(data, SiegeWeaponToken.class);
if (LiveSiegeWeapons.containsKey(token.Id))
{
continue;
}
if (_clans.getClan(token.OwnerClan) == null)
{
for (Entity other : Spawn.getSpawnWorld().getEntities())
{
if (token.ComprisedOf.values().contains(other.getUniqueId()))
{
other.remove();
}
else if (other.getUniqueId().equals(token.DataEntityUUID))
{
other.remove();
}
}
continue;
}
SiegeWeapon weapon = null;
switch (token.WeaponType)
{
case 1:
{
weapon = new Catapult(this, token);
break;
}
case 2:
{
weapon = new Cannon(this, token);
break;
}
}
LiveSiegeWeapons.put(token.Id, weapon);
if (_outpostManager.Get(token.OutpostId) != null)
{
_outpostManager.Get(token.OutpostId).addWeapon(weapon);
}
} }
}
catch (Exception e) private void saveSiegeWeapons()
{ {
e.printStackTrace();
}
} }
@EventHandler @EventHandler
@ -280,7 +210,7 @@ public class SiegeManager extends MiniPlugin
outpost.addWeapon(cannon); outpost.addWeapon(cannon);
} }
LiveSiegeWeapons.put(cannon.getId(), cannon); LiveSiegeWeapons.put(cannon.getUniqueId(), cannon);
} }
public boolean trySpawnCatapult(Player player, Location location) public boolean trySpawnCatapult(Player player, Location location)
@ -343,12 +273,12 @@ public class SiegeManager extends MiniPlugin
outpost.addWeapon(catapult); outpost.addWeapon(catapult);
} }
LiveSiegeWeapons.put(catapult.getId(), catapult); LiveSiegeWeapons.put(catapult.getUniqueId(), catapult);
} }
public void dead(SiegeWeapon weapon) public void dead(SiegeWeapon weapon)
{ {
LiveSiegeWeapons.remove(weapon.getId()); LiveSiegeWeapons.remove(weapon.getUniqueId());
} }
public OutpostManager getOutpostManager() public OutpostManager getOutpostManager()
@ -366,4 +296,9 @@ public class SiegeManager extends MiniPlugin
return _clans; return _clans;
} }
public int randomId()
{
return Math.abs(UtilMath.random.nextInt());
}
} }

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.siege.outpost; package mineplex.game.clans.clans.siege.commands;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -7,6 +7,8 @@ import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.weapon.Cannon; import mineplex.game.clans.clans.siege.weapon.Cannon;
import mineplex.game.clans.clans.siege.weapon.Catapult; import mineplex.game.clans.clans.siege.weapon.Catapult;

View File

@ -1,25 +1,17 @@
package mineplex.game.clans.clans.siege.outpost; package mineplex.game.clans.clans.siege.outpost;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.Map.Entry;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Arrow; import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock; import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -49,6 +41,7 @@ import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilColor; import mineplex.core.common.util.UtilColor;
import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle;
@ -67,8 +60,9 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist; import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon; import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
import mineplex.game.clans.clans.siege.weapon.serialization.OutpostToken;
import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.core.repository.ClanTerritory;
import net.minecraft.server.v1_8_R3.AxisAlignedBB; import net.minecraft.server.v1_8_R3.AxisAlignedBB;
@ -81,11 +75,11 @@ public class Outpost implements Listener
public static final long PREP_TIME = 2 * 60 * 1000; public static final long PREP_TIME = 2 * 60 * 1000;
private OutpostManager _host; private OutpostManager _outpostManager;
private final String _id; private final int _uniqueId;
private ClanInfo _owner; private ClanInfo _ownerClan;
private Location _startCorner; private Location _startCorner;
private Location _origin; private Location _origin;
@ -120,32 +114,32 @@ public class Outpost implements Listener
UtilColor.rgb(147, 212, 17), UtilColor.rgb(147, 212, 17),
UtilColor.rgb(150, 199, 51))); UtilColor.rgb(150, 199, 51)));
private long _spawnTime; private long _timeSpawned;
public double _maxHealth = 4500; public int _maxHealth = 4500;
public double _health = _maxHealth; public int _health = _maxHealth;
public ClanInfo _against; public ClanInfo _againstClan;
private long _siegeDeclaredTime = -1; private long _siegeDeclaredTime = -1;
private Arrow _declarationArrow; private Arrow _declarationArrow;
private ArmorStand _dataEntity;
public Outpost(OutpostManager outpostManager, OutpostToken token) public Outpost(OutpostManager outpostManager, OutpostToken token)
{ {
_host = outpostManager; _outpostManager = outpostManager;
_health = token.Health; System.out.println(token.OutpostState + ", " + token.Type);
setHealth(token.Health);
_siegeDeclaredTime = token.SiegeDeclaredTime; _siegeDeclaredTime = token.SiegeDeclaredTime;
_against = outpostManager.getClansManager().getClan(token.AgainstClan); _againstClan = token.AgainstClan;
_id = token.Id; _uniqueId = token.UniqueId;
_siegeWeaponDistance = token.Type._size + 27.5; _siegeWeaponDistance = token.Type._size + 27.5;
_owner = outpostManager.getClansManager().getClan(token.OwnerClan); _ownerClan = token.OwnerClan;
_startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size); _startCorner = token.Origin.clone().subtract(token.Type._size, 1.1, token.Type._size);
_endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9); _endCorner = token.Origin.clone().add(token.Type._size + .9, token.Type._ySize - 1, token.Type._size + .9);
@ -155,42 +149,43 @@ public class Outpost implements Listener
_forceFieldStart = _startCorner.clone().subtract(4, 0, 4); _forceFieldStart = _startCorner.clone().subtract(4, 0, 4);
_forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5); _forceFieldEnd = _endCorner.clone().add(4.5, 0, 4.5);
_origin = token.Origin; _origin = token.Origin.clone();
_type = token.Type; _type = token.Type;
_spawnTime = token.TimeSpawned; _timeSpawned = token.TimeSpawned;
_core = _type.getCoreLocation(_origin); _core = _type.getCoreLocation(_origin);
_preHologram = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_owner.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); _preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)");
_preHologram2 = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); _preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true));
if (token.OutpostState == OutpostState.AWAITING)
{
_preHologram.start(); _preHologram.start();
_preHologram2.start(); _preHologram2.start();
}
_blocks = _type.createBuildQueue(_origin, _ownerClan.Clans);
_state = token.OutpostState; _state = token.OutpostState;
for (Entity entity : token.Origin.getWorld().getEntities()) _circleStages = new LoopIterator<Vector>(circleAround(new Vector(0., 0., 0.), 40, .6d));
{
if (entity.getUniqueId().equals(token.DataEntityUUID)) List<Vector> reverse = circleAround(new Vector(0., 0., 0.), 40, .6d);
{ Collections.reverse(reverse);
_dataEntity = (ArmorStand) entity; _reverseCircleStages = new LoopIterator<Vector>(reverse);
}
}
} }
public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type) public Outpost(OutpostManager outpostManager, ClanInfo clan, Location location, OutpostType type)
{ {
_host = host; _outpostManager = outpostManager;
location.add(.5, 0, .5); _uniqueId = outpostManager.getSiegeManager().randomId();
_id = Integer.toString(UtilMath.random.nextInt(13333337));
_siegeWeaponDistance = type._size + 27.5; _siegeWeaponDistance = type._size + 27.5;
_owner = clan; _ownerClan = clan;
_startCorner = location.clone().subtract(type._size, 1.1, type._size); _startCorner = location.clone().subtract(type._size, 1.1, type._size);
_endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9); _endCorner = location.clone().add(type._size + .9, type._ySize - 1, type._size + .9);
@ -204,75 +199,27 @@ public class Outpost implements Listener
_type = type; _type = type;
_spawnTime = System.currentTimeMillis(); _timeSpawned = System.currentTimeMillis();
_core = _type.getCoreLocation(_origin); _core = _type.getCoreLocation(_origin);
_preHologram = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_owner.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)"); _preHologram = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_ownerClan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)");
_preHologram2 = new Hologram(_owner.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true)); _preHologram2 = new Hologram(_ownerClan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true));
_preHologram.start(); _preHologram.start();
_preHologram2.start(); _preHologram2.start();
_dataEntity = location.getWorld().spawn(location.subtract(0, 5, 0), ArmorStand.class);
_dataEntity.setVisible(false);
_dataEntity.setGravity(false);
_state = OutpostState.AWAITING; _state = OutpostState.AWAITING;
}
public OutpostToken tokenize() _outpostManager.getRepository().insertOutpost(toToken());
{
OutpostToken token = new OutpostToken();
token.Id = _id; _circleStages = new LoopIterator<Vector>(circleAround(new Vector(0., 0., 0.), 40, .6d));
token.Origin = _origin; List<Vector> reverse = circleAround(new Vector(0., 0., 0.), 40, .6d);
Collections.reverse(reverse);
_reverseCircleStages = new LoopIterator<Vector>(reverse);
token.Type = _type; UtilServer.registerEvents(this);
token.OwnerClan = _owner.getName();
token.Health = _health;
token.TimeSpawned = _spawnTime;
token.AgainstClan = _against != null ? _against.getName() : null;
token.DataEntityUUID = _dataEntity.getUniqueId();
token.SiegeDeclaredTime = _siegeDeclaredTime;
token.OutpostState = _state;
return token;
}
private void updateData()
{
try
{
String data = _host.getSiegeManager().getGson().toJson(tokenize());
PrintWriter writer = new PrintWriter(new FileWriter(new File("H:\\" + new Random().nextInt())));
writer.print(data);
writer.close();
_dataEntity.setMetadata("$SERIALIZED_OUTPOST_DATA$", new FixedMetadataValue(_host.getPlugin(), data));
}
catch (Exception e)
{
e.printStackTrace();
}
}
@EventHandler
public void saveData(UpdateEvent event)
{
if (event.getType() == UpdateType.SEC_05)
{
updateData();
}
} }
private void cleanup() private void cleanup()
@ -290,9 +237,7 @@ public class Outpost implements Listener
_weapons.forEach(SiegeWeapon::kill); _weapons.forEach(SiegeWeapon::kill);
_weapons.clear(); _weapons.clear();
_dataEntity.remove(); _outpostManager.queueForRemoval(_ownerClan.getName());
_host.queueForRemoval(_owner.getName());
} }
@EventHandler @EventHandler
@ -313,7 +258,7 @@ public class Outpost implements Listener
return; return;
} }
if (!_owner.equals(_owner.Clans.getClanUtility().getClanByPlayer(event.getPlayer()))) if (!_ownerClan.equals(_ownerClan.Clans.getClanUtility().getClanByPlayer(event.getPlayer())))
{ {
UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!")); UtilPlayer.message(event.getPlayer(), F.main("Clans", "This is not yours to activate!"));
return; return;
@ -337,13 +282,12 @@ public class Outpost implements Listener
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
Arrow arrow = player.shootArrow(); Arrow arrow = player.shootArrow();
if (_owner.isMember(player)) if (_ownerClan.isMember(player))
{ {
for (int slot = 0; slot < player.getInventory().getSize(); slot++) for (int slot = 0; slot < player.getInventory().getSize(); slot++)
{ {
@ -356,13 +300,13 @@ public class Outpost implements Listener
if (item.isSimilar(SIEGE_DECLARATION_ARROW)) if (item.isSimilar(SIEGE_DECLARATION_ARROW))
{ {
if (_against == null && !arrow.hasMetadata("OutpostData")) if (_againstClan == null && !arrow.hasMetadata("OutpostData"))
{ {
arrow.setMetadata("OutpostData", new FixedMetadataValue(_host.getPlugin(), _owner.getName() + ";" + player.getName())); arrow.setMetadata("OutpostData", new FixedMetadataValue(_outpostManager.getPlugin(), _ownerClan.getName() + ";" + player.getName()));
_declarationArrow = (Arrow) arrow; _declarationArrow = (Arrow) arrow;
player.getInventory().setItem(slot, UtilInv.decrement(item));
break;
} }
player.getInventory().setItem(slot, null);
} }
} }
} }
@ -373,12 +317,12 @@ public class Outpost implements Listener
{ {
if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE)
{ {
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_owner.getName()) + "'s Outpost!")); UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!"));
_core.getBlock().setType(Material.AIR); _core.getBlock().setType(Material.AIR);
_owner.inform("Your Outpost has been destroyed!", null); _ownerClan.inform("Your Outpost has been destroyed!", null);
UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _owner.getOnlinePlayersArray()); UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray());
if (getState() == OutpostState.AWAITING) if (getState() == OutpostState.AWAITING)
{ {
@ -400,7 +344,7 @@ public class Outpost implements Listener
{ {
_origin.getBlock().setType(Material.AIR); _origin.getBlock().setType(Material.AIR);
_origin.getWorld().dropItem(_origin, OUTPOST_ITEM); _origin.getWorld().dropItem(_origin, OUTPOST_ITEM);
_owner.inform("Your Outpost block has been destroyed.", null); _ownerClan.inform("Your Outpost block has been destroyed.", null);
cleanup(); cleanup();
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -436,14 +380,14 @@ public class Outpost implements Listener
UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX); UtilParticle.PlayParticle(ParticleType.MOB_SPELL, _declarationArrow.getLocation(), new Vector(color.getRed(), color.getGreen(), color.getBlue()), 1f, 0, ViewDist.MAX);
} }
if (_against != null && getTimeToSiege() > 0) if (_againstClan != null && getTimeToSiege() > 150)
{ {
_against.getOnlinePlayers().forEach(this::informTimeToSiege); _againstClan.getOnlinePlayers().forEach(this::informTimeToSiege);
_owner.getOnlinePlayers().forEach(this::informTimeToSiege); _ownerClan.getOnlinePlayers().forEach(this::informTimeToSiege);
} }
else if (_against != null) else if (_againstClan != null)
{ {
UtilTextBottom.display("Enemy Outpost Health: " + UtilText.colorPercentage(getHealthPercentage()) + "%", _against.getOnlinePlayersArray()); UtilTextBottom.display("Enemy Outpost Health: " + UtilText.colorPercentage(getHealthPercentage()) + "%", _againstClan.getOnlinePlayersArray());
} }
if (_state == OutpostState.AWAITING) if (_state == OutpostState.AWAITING)
@ -451,7 +395,7 @@ public class Outpost implements Listener
if (getLifetime() > 60000) if (getLifetime() > 60000)
{ {
_origin.getBlock().setType(Material.AIR); _origin.getBlock().setType(Material.AIR);
_owner.inform("You have lost your Outpost block, as no one activated it fast enough!", null); _ownerClan.inform("You have lost your Outpost block, as no one activated it fast enough!", null);
cleanup(); cleanup();
return; return;
} }
@ -482,11 +426,11 @@ public class Outpost implements Listener
for (OutpostBlock block : _blocks.values()) for (OutpostBlock block : _blocks.values())
{ {
if (block._id == Material.CHEST.getId()) if (block.getId() == Material.CHEST.getId())
{ {
for (int slot = 0; slot < 8; slot++) for (int slot = 0; slot < 8; slot++)
{ {
((Chest) block._loc.getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW); ((Chest) block.getLocation().getBlock().getState()).getInventory().setItem(slot, SIEGE_DECLARATION_ARROW);
} }
break; break;
@ -554,7 +498,7 @@ public class Outpost implements Listener
} }
UtilServer.getPlayersCollection().stream() UtilServer.getPlayersCollection().stream()
.filter(player -> !_owner.isMember(player)) .filter(player -> !_ownerClan.isMember(player))
.filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd)) .filter(player -> UtilAlg.inBoundingBox(player.getLocation(), _forceFieldStart, _forceFieldEnd))
.forEach(player -> { .forEach(player -> {
UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .4, true, 0.8, 0, 1.1, true); UtilAction.velocity(player, UtilAlg.getTrajectory2d(_core, player.getLocation()), .4, true, 0.8, 0, 1.1, true);
@ -573,26 +517,20 @@ public class Outpost implements Listener
_preHologram = null; _preHologram = null;
_state = OutpostState.CONSTRUCTING; _state = OutpostState.CONSTRUCTING;
_blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _owner.Clans)); _blocks = new LinkedHashMap<>(_buildQueue = _type.createBuildQueue(_origin, _ownerClan.Clans));
_owner.inform("Siege", "Your Outpost is now being constructed.", null); _ownerClan.inform("Siege", "Your Outpost is now being constructed.", null);
_circleStages = new LoopIterator<Vector>(circleAround(new Vector(0., 0., 0.), 40, .6d));
List<Vector> reverse = circleAround(new Vector(0., 0., 0.), 40, .6d);
Collections.reverse(reverse);
_reverseCircleStages = new LoopIterator<Vector>(reverse);
//Inform nearby Clans //Inform nearby Clans
for (int chunkX = -3; chunkX < 3; chunkX++) for (int chunkX = -3; chunkX < 3; chunkX++)
{ {
for (int chunkZ = -3; chunkZ < 3; chunkZ++) for (int chunkZ = -3; chunkZ < 3; chunkZ++)
{ {
ClanTerritory territory = _owner.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); ClanTerritory territory = _ownerClan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ));
if (territory != null && ClansBlacklist.isValidClanName(territory.Owner)) if (territory != null && ClansBlacklist.isValidClanName(territory.Owner))
{ {
ClanInfo clan = _owner.Clans.getClanUtility().getClanByClanName(territory.Owner); ClanInfo clan = _ownerClan.Clans.getClanUtility().getClanByClanName(territory.Owner);
clan.inform("A siege has begun near your territory!", null); clan.inform("A siege has begun near your territory!", null);
UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray()); UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray());
@ -623,15 +561,15 @@ public class Outpost implements Listener
NonFinalInteger wait = new NonFinalInteger(0); NonFinalInteger wait = new NonFinalInteger(0);
_blocks.values().stream().filter(block -> UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block -> _blocks.values().stream().filter(block -> UtilMath.random.nextBoolean()).filter(block -> UtilMath.random.nextBoolean()).limit(20).forEach(block ->
_host.runSyncLater(() -> { _outpostManager.runSyncLater(() -> {
UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block._loc, new Vector(0,0,0), 1f, 1, ViewDist.MAX); UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, block.getLocation(), new Vector(0,0,0), 1f, 1, ViewDist.MAX);
_origin.getWorld().playSound(block._loc, Sound.EXPLODE, 1.0f, 1.0f); _origin.getWorld().playSound(block.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
}, wait.add(4 + UtilMath.random.nextInt(4)).get()) }, wait.add(4 + UtilMath.random.nextInt(4)).get())
); );
_host.runSyncLater(() -> { _outpostManager.runSyncLater(() -> {
_blocks.values().forEach(block -> { _blocks.values().forEach(block -> {
Material mat = Material.getMaterial(block._id); Material mat = Material.getMaterial(block.getId());
if (UtilItem.isTranslucent(mat)) if (UtilItem.isTranslucent(mat))
{ {
@ -639,13 +577,13 @@ public class Outpost implements Listener
return; return;
} }
FallingBlock fall = block._loc.getWorld().spawnFallingBlock(block._loc, block._id, block._data); FallingBlock fall = block.getLocation().getWorld().spawnFallingBlock(block.getLocation(), block.getId(), block.getData());
fall.setDropItem(false); fall.setDropItem(false);
Vector vec = UtilAlg.getTrajectory(fall.getLocation(), getExactMiddle()); Vector vec = UtilAlg.getTrajectory(fall.getLocation(), getExactMiddle());
UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false); UtilAction.velocity(fall, vec, 1, false, 0, 0.6, 10, false);
fall.setMetadata("ClansOutpost", new FixedMetadataValue(_owner.Clans.getPlugin(), _owner.getName())); fall.setMetadata("ClansOutpost", new FixedMetadataValue(_ownerClan.Clans.getPlugin(), _ownerClan.getName()));
block.restore(); block.restore();
}); });
@ -653,7 +591,7 @@ public class Outpost implements Listener
cleanup(); cleanup();
}, wait.get() + 5L); }, wait.get() + 5L);
_owner.inform("Your Clan's Outpost has been destroyed.", null); _ownerClan.inform("Your Clan's Outpost has been destroyed.", null);
} }
@EventHandler @EventHandler
@ -672,12 +610,12 @@ public class Outpost implements Listener
public ClanInfo getOwner() public ClanInfo getOwner()
{ {
return _owner; return _ownerClan;
} }
public long getLifetime() public long getLifetime()
{ {
return System.currentTimeMillis() - _spawnTime; return System.currentTimeMillis() - _timeSpawned;
} }
public AxisAlignedBB getBounds() public AxisAlignedBB getBounds()
@ -705,20 +643,20 @@ public class Outpost implements Listener
public final int getHealthPercentage() public final int getHealthPercentage()
{ {
return ((int) ((_health / _maxHealth) * 100.d)); return ((int) ((((double) _health) / ((double) _maxHealth)) * 100.d));
} }
public final double getHealth() public final int getHealth()
{ {
return _health; return _health;
} }
public final String getDisplayHealth() public final String getDisplayHealth()
{ {
return UtilText.getProgress(null, _health / _maxHealth, null, false, 12); return UtilText.getProgress(null, ((double) _health) / ((double) _maxHealth), null, false, 12);
} }
public final void setHealth(double health) public final void setHealth(int health)
{ {
_health = UtilMath.clamp(health, 0, _maxHealth); _health = UtilMath.clamp(health, 0, _maxHealth);
@ -728,51 +666,51 @@ public class Outpost implements Listener
} }
} }
public final void removeHealth(double health) public final void removeHealth(int health)
{ {
setHealth(_health - health); setHealth(_health - health);
} }
public final void addHealth(double health) public final void addHealth(int health)
{ {
setHealth(_health + health); setHealth(_health + health);
} }
public ClanInfo getAgainst() public ClanInfo getAgainst()
{ {
return _against; return _againstClan;
} }
public void declareOn(Player declarer, ClanInfo against) public void declareOn(Player declarer, ClanInfo against)
{ {
if (_against != null) if (_againstClan != null)
{ {
UtilPlayer.message(declarer, F.main("Clans", "Your Clan has already declared Siege against " + F.elem(_against.getName()) + ".")); UtilPlayer.message(declarer, F.main("Clans", "Your Clan has already declared Siege against " + F.elem(_againstClan.getName()) + "."));
} }
else else
{ {
if (_host.isInSiege(against)) if (_outpostManager.isInSiege(against))
{ {
UtilPlayer.message(declarer, F.main("Clans", F.elem(against.getName()) + " is already in a Siege.")); UtilPlayer.message(declarer, F.main("Clans", F.elem(against.getName()) + " is already in a Siege."));
return; return;
} }
_against = against; _againstClan = against;
_siegeDeclaredTime = System.currentTimeMillis(); _siegeDeclaredTime = System.currentTimeMillis();
_owner.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_against.getName()) + "."), null); _ownerClan.inform(F.main("Clans", "Your Clan has declared a Siege against " + F.elem(_againstClan.getName()) + "."), null);
_owner.inform("Siege", "Your Clan has declared a Siege", null); _ownerClan.inform("Siege", "Your Clan has declared a Siege", null);
_owner.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); _ownerClan.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null);
_against.inform(F.main("Clans", F.elem(_owner.getName()) + " has declared a Siege against your Clan."), null); _againstClan.inform(F.main("Clans", F.elem(_ownerClan.getName()) + " has declared a Siege against your Clan."), null);
_against.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null); _againstClan.inform(F.main("Clans", F.time(UtilTime.MakeStr(PREP_TIME)) + " to Siege."), null);
_against.inform("Siege", F.elem(_owner.getName()) + " has declared a Siege", null); _againstClan.inform("Siege", F.elem(_ownerClan.getName()) + " has declared a Siege", null);
} }
} }
public void informTimeToSiege(Player player) public void informTimeToSiege(Player player)
{ {
UtilTextBottom.display("Time to Siege: " + F.time(UtilTime.MakeStr(getTimeToSiege())), player); UtilTextBottom.display(C.Bold + "Time to Siege: " + F.time(UtilTime.MakeStr(getTimeToSiege())), player);
} }
public long getTimeSiegeDeclared() public long getTimeSiegeDeclared()
@ -800,8 +738,25 @@ public class Outpost implements Listener
_weapons.add(weapon); _weapons.add(weapon);
} }
public String getId() public int getUniqueId()
{ {
return _id; return _uniqueId;
}
public OutpostToken toToken()
{
OutpostToken token = new OutpostToken();
token.UniqueId = _uniqueId;
token.Origin = _origin;
token.Type = _type;
token.OwnerClan = _ownerClan;
token.Health = _health;
token.TimeSpawned = _timeSpawned;
token.AgainstClan = _againstClan;
token.SiegeDeclaredTime = _siegeDeclaredTime;
token.OutpostState = _state;
return token;
} }
} }

View File

@ -1,57 +0,0 @@
package mineplex.game.clans.clans.siege.outpost;
import java.util.Map;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import mineplex.core.common.util.UtilWorld;
public class OutpostBlock
{
protected Location _loc;
protected int _id;
protected byte _data;
protected int _originalId;
protected byte _originalData;
public OutpostBlock(Map<String, OutpostBlock> blocks, Location loc, int id, byte data)
{
_loc = loc;
_id = id;
_data = data;
String locStr = UtilWorld.locToStr(loc);
if (blocks.containsKey(locStr))
{
_originalId = blocks.get(locStr)._originalId;
_originalData = blocks.get(locStr)._originalData;
}
else
{
_originalId = _loc.getBlock().getTypeId();
_originalData = _loc.getBlock().getData();
}
}
public void set()
{
_loc.getBlock().setTypeIdAndData(_id, _data, false);
if (_id != 0)
{
_loc.getWorld().playEffect(_loc, Effect.STEP_SOUND, Material.getMaterial(_id), 10);
}
}
public void restore()
{
BlockState state = _loc.getBlock().getState();
state.setTypeId(_originalId);
state.setRawData(_originalData);
state.update(true, false);
}
}

View File

@ -1,18 +0,0 @@
package mineplex.game.clans.clans.siege.outpost;
import java.util.List;
import org.bukkit.Location;
public class OutpostBuilder
{
public OutpostBuilder(Location pos, String string, List<Location> wallLocations, Outpost outpost)
{
}
public void tick()
{
}
}

View File

@ -1,26 +1,26 @@
package mineplex.game.clans.clans.siege.outpost; package mineplex.game.clans.clans.siege.outpost;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Stack;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilMath;
@ -35,21 +35,25 @@ import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent; import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.weapon.serialization.OutpostToken; import mineplex.game.clans.clans.siege.repository.OutpostRepository;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
import mineplex.game.clans.core.repository.ClanTerritory; import mineplex.game.clans.core.repository.ClanTerritory;
import mineplex.game.clans.spawn.Spawn;
public class OutpostManager extends MiniPlugin public class OutpostManager extends MiniPlugin
{ {
private ClansManager _clansManager; private ClansManager _clansManager;
private Map<String, Outpost> _outposts = new HashMap<>(); private NautHashMap<String, Outpost> _outposts = new NautHashMap<>();
private Map<String, Outpost> _idToOutpost = new HashMap<>(); private NautHashMap<Integer, Outpost> _idToOutpost = new NautHashMap<>();
private List<String> _removalQueue; private List<String> _removalQueue;
private SiegeManager _siegeManager; private SiegeManager _siegeManager;
private OutpostRepository _repository;
private Stack<Outpost> _addQueue = new Stack<>();
public OutpostManager(ClansManager clansManager, SiegeManager siegeManager) public OutpostManager(ClansManager clansManager, SiegeManager siegeManager)
{ {
super("Outpost Manager", clansManager.getPlugin()); super("Outpost Manager", clansManager.getPlugin());
@ -58,45 +62,17 @@ public class OutpostManager extends MiniPlugin
_clansManager = clansManager; _clansManager = clansManager;
_repository= new OutpostRepository(clansManager.getPlugin(), this);
_removalQueue = new ArrayList<>(); _removalQueue = new ArrayList<>();
} }
public void loadExistingOutposts()
{
try
{
for (Entity entity : Spawn.getSpawnWorld().getEntities())
{
if (!(entity instanceof ArmorStand))
{
continue;
}
if (!entity.hasMetadata("$SERIALIZED_OUTPOST_DATA$"))
{
continue;
}
String data = entity.getMetadata("$SERIALIZED_OUTPOST_DATA$").get(0).asString();
Outpost outpost = new Outpost(this, _siegeManager.getGson().fromJson(data, OutpostToken.class));
_outposts.put(outpost.getOwner().getName(), outpost);
_idToOutpost.put(outpost.getId(), outpost);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlaceBlock(BlockPlaceEvent event) public void onPlaceBlock(BlockPlaceEvent event)
{ {
if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM)) if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM))
{ {
if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3)) if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK_III))
{ {
event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA); event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA);
} }
@ -217,9 +193,7 @@ public class OutpostManager extends MiniPlugin
} }
_outposts.put(clan.getName(), new Outpost(this, clan, location, type)); _outposts.put(clan.getName(), new Outpost(this, clan, location, type));
_idToOutpost.put(_outposts.get(clan.getName()).getId(), _outposts.get(clan.getName())); _idToOutpost.put(_outposts.get(clan.getName()).getUniqueId(), _outposts.get(clan.getName()));
_plugin.getServer().getPluginManager().registerEvents(_outposts.get(clan.getName()), _plugin);
return true; return true;
} }
@ -250,6 +224,13 @@ public class OutpostManager extends MiniPlugin
@EventHandler @EventHandler
public void update(UpdateEvent event) public void update(UpdateEvent event)
{ {
if (!_addQueue.isEmpty())
{
Outpost outpost = _addQueue.pop();
_outposts.put(outpost.getOwner().getName(), outpost);
}
for (Outpost outpost : _outposts.values()) for (Outpost outpost : _outposts.values())
{ {
if (outpost.getState() != OutpostState.DEAD) if (outpost.getState() != OutpostState.DEAD)
@ -265,7 +246,7 @@ public class OutpostManager extends MiniPlugin
{ {
if (!_removalQueue.isEmpty()) if (!_removalQueue.isEmpty())
{ {
HandlerList.unregisterAll(_outposts.remove(_removalQueue.remove(0))); HandlerList.unregisterAll(_idToOutpost.remove(Integer.valueOf(_outposts.remove(_removalQueue.remove(0)).getUniqueId())));
} }
} }
@ -283,6 +264,11 @@ public class OutpostManager extends MiniPlugin
public Outpost Get(ClanInfo clan) public Outpost Get(ClanInfo clan)
{ {
if (clan == null)
{
return null;
}
return _outposts.get(clan.getName().toLowerCase()); return _outposts.get(clan.getName().toLowerCase());
} }
@ -301,6 +287,34 @@ public class OutpostManager extends MiniPlugin
return Lists.newArrayList(_outposts.values()); return Lists.newArrayList(_outposts.values());
} }
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
Player player = (Player) event.getPlayer();
ClanInfo clan = _clansManager.getClan(player);
if (Get(clan) != null)
{
return;
}
for (int slot = 0; slot < player.getInventory().getSize(); slot++)
{
ItemStack item = player.getInventory().getItem(slot);
if (item == null)
{
continue;
}
if (item.isSimilar(Outpost.SIEGE_DECLARATION_ARROW))
{
player.getInventory().setItem(slot, null);
break;
}
}
}
@EventHandler @EventHandler
public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event) public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event)
{ {
@ -366,13 +380,75 @@ public class OutpostManager extends MiniPlugin
return false; return false;
} }
public Outpost Get(String outpostId) public Outpost Get(int outpostId)
{ {
return _idToOutpost.get(outpostId); return _idToOutpost.get(Integer.valueOf(outpostId));
} }
public ClansManager getClansManager() public ClansManager getClansManager()
{ {
return _clansManager; return _clansManager;
} }
public void loadOutposts()
{
System.out.println("[OUTPOSTS] LOADING OUTPOSTS FROM DATABASE");
_repository.getOutpostsByServer(_clansManager.getServerId(), tokens -> {
for (OutpostToken token : tokens)
{
if ((System.currentTimeMillis() - token.TimeSpawned) > Outpost.MAX_LIFETIME)
{
System.out.println("[OUTPOSTS] SKIPPING & REMOVING OUTPOST [" + token.UniqueId + "] BECAUSE OF OLD AGE");
_repository.deleteOutpost(token.UniqueId);
continue;
}
Outpost outpost = new Outpost(this, token);
System.out.println("[OUTPOSTS] INITIALIZED OUTPOST FROM DATABASE SAVE");
_addQueue.push(outpost);
}
});
}
public void saveOutposts()
{
final Stack<Runnable> queue = new Stack<>();
for (final Outpost outpost : _outposts.values())
{
final OutpostToken token = outpost.toToken();
queue.push(() -> {
_repository.updateOutpost(token);
});
}
runAsync(() -> {
while (!queue.isEmpty())
{
queue.pop().run();
}
});
runAsync(() ->
_repository.getOutpostsByServer(_clansManager.getServerId(), tokens ->
tokens.forEach(token -> {
if (!_idToOutpost.containsKey(Integer.valueOf(token.UniqueId)))
{
_repository.deleteOutpost(token.UniqueId);
}
})
)
);
}
public OutpostRepository getRepository()
{
return _repository;
}
} }

View File

@ -2,9 +2,37 @@ package mineplex.game.clans.clans.siege.outpost;
public enum OutpostState public enum OutpostState
{ {
AWAITING, /**
CONSTRUCTING, * this much space between them so that there is some room for any potential new states.
LIVE, */
DESTRUCTING, AWAITING(10),
DEAD; CONSTRUCTING(20),
LIVE(30),
DESTRUCTING(40),
DEAD(50);
private byte _id;
OutpostState(int id)
{
_id = (byte) id;
}
public static OutpostState ById(byte id)
{
for (OutpostState state : values())
{
if (state._id == id)
{
return state;
}
}
return null;
}
public byte getId()
{
return _id;
}
} }

View File

@ -14,11 +14,13 @@ import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic; import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.outpost.build.OutpostBlock;
import mineplex.game.clans.clans.siege.outpost.build.OutpostBlockBanner;
import net.minecraft.server.v1_8_R3.NBTTagCompound; import net.minecraft.server.v1_8_R3.NBTTagCompound;
public enum OutpostType public enum OutpostType
{ {
ORIGINAL_CLANS(3, 6) { MK_I(1, 3, 6) {
public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans) public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans)
{ {
LinkedHashMap<String, OutpostBlock> build = new LinkedHashMap<>(); LinkedHashMap<String, OutpostBlock> build = new LinkedHashMap<>();
@ -229,7 +231,7 @@ public enum OutpostType
return location.clone().subtract(0, 1, 0); return location.clone().subtract(0, 1, 0);
} }
}, },
MK2(5, 25) { MK_II(2, 5, 25) {
public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans) public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans)
{ {
try try
@ -289,7 +291,7 @@ public enum OutpostType
return location.clone().subtract(0, 1, 0); return location.clone().subtract(0, 1, 0);
} }
}, },
MK3(5, 25) { MK_III(3, 5, 25) {
public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans) public LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans)
{ {
try try
@ -358,10 +360,18 @@ public enum OutpostType
protected int _size; protected int _size;
protected int _ySize; protected int _ySize;
OutpostType(int size, int ySize) private int _id;
OutpostType(int id, int size, int ySize)
{ {
_size = size; _size = size;
_ySize = ySize; _ySize = ySize;
_id = id;
}
public int getId()
{
return _id;
} }
public abstract LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans); public abstract LinkedHashMap<String, OutpostBlock> createBuildQueue(Location location, ClansManager clans);
@ -369,4 +379,17 @@ public enum OutpostType
public abstract Location getCoreLocation(Location location); public abstract Location getCoreLocation(Location location);
public abstract List<Location> getWallLocations(Location location); public abstract List<Location> getWallLocations(Location location);
public static OutpostType ById(byte id)
{
for (OutpostType type : values())
{
if (type._id == id)
{
return type;
}
}
return null;
}
} }

View File

@ -0,0 +1,82 @@
package mineplex.game.clans.clans.siege.outpost.build;
import java.util.Map;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import mineplex.core.common.util.UtilWorld;
public class OutpostBlock
{
private Location _location;
private int _id;
private byte _data;
private int _originalId;
private byte _originalData;
public OutpostBlock(Map<String, OutpostBlock> blocks, Location loc, int id, byte data)
{
_location = loc;
_id = id;
_data = data;
String locStr = UtilWorld.locToStr(loc);
if (blocks.containsKey(locStr))
{
_originalId = blocks.get(locStr)._originalId;
_originalData = blocks.get(locStr)._originalData;
}
else
{
_originalId = _location.getBlock().getTypeId();
_originalData = _location.getBlock().getData();
}
}
public void set()
{
_location.getBlock().setTypeIdAndData(_id, _data, false);
if (_id != 0)
{
_location.getWorld().playEffect(_location, Effect.STEP_SOUND, Material.getMaterial(_id), 10);
}
}
public void restore()
{
BlockState state = _location.getBlock().getState();
state.setTypeId(_originalId);
state.setRawData(_originalData);
state.update(true, false);
}
public int getId()
{
return _id;
}
public byte getData()
{
return _data;
}
public int getOriginalId()
{
return _originalId;
}
public int getOriginalData()
{
return _originalData;
}
public Location getLocation()
{
return _location;
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.siege.outpost; package mineplex.game.clans.clans.siege.outpost.build;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -10,6 +10,10 @@ import org.bukkit.Location;
import org.bukkit.block.Banner; import org.bukkit.block.Banner;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
/**
* Special block for Mk III Outpost
*
*/
public class OutpostBlockBanner extends OutpostBlock public class OutpostBlockBanner extends OutpostBlock
{ {
private DyeColor _baseColor; private DyeColor _baseColor;
@ -27,7 +31,7 @@ public class OutpostBlockBanner extends OutpostBlock
{ {
super.set(); super.set();
Banner banner = (Banner) _loc.getBlock().getState(); Banner banner = (Banner) getLocation().getBlock().getState();
banner.setBaseColor(_baseColor); banner.setBaseColor(_baseColor);
banner.setPatterns(_patterns); banner.setPatterns(_patterns);

View File

@ -0,0 +1,152 @@
package mineplex.game.clans.clans.siege.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnByte;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnTimestamp;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.outpost.OutpostState;
import mineplex.game.clans.clans.siege.outpost.OutpostType;
import mineplex.game.clans.clans.siege.repository.tokens.OutpostToken;
public class OutpostRepository extends RepositoryBase
{
private OutpostManager _manager;
private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansOutposts (uniqueId INT NOT NULL,"
+ "serverId INT NOT NULL,"
+ "origin VARCHAR(30),"
+ "outpostType TINYINT NOT NULL,"
+ "ownerClan INT NOT NULL,"
+ "health INT NOT NULL,"
+ "timeSpawned LONG,"
+ "againstClan INT,"
+ "siegeDeclaredTime LONG,"
+ "outpostState TINYINT NOT NULL);";
private static final String GET_OUTPOST_BY_ID = "SELECT * FROM clansOutposts WHERE uniqueId=?;";
private static final String GET_OUTPOST_BY_CLAN = "SELECT * FROM clansOutposts WHERE ownerClan=?;";
private static final String GET_OUTPOSTS_BY_SERVER = "SELECT * FROM clansOutposts WHERE serverId=?;";
private static final String UPDATE_OUTPOST = "UPDATE clansOutposts SET health=?,againstClan=?,siegeDeclaredTime=?,outpostState=? WHERE uniqueId=?;";
private static final String INSERT_OUTPOST = "INSERT INTO clansOutposts VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
private static final String DELETE_OUTPOST = "DELETE FROM clansOutposts WHERE uniqueId=?;";
public OutpostRepository(JavaPlugin plugin, OutpostManager manager)
{
super(plugin, DBPool.getAccount());
_manager = manager;
}
public void deleteOutpost(final int uniqueId)
{
executeUpdate(DELETE_OUTPOST, new ColumnInt("uniqueId", uniqueId));
}
public void getOutpostById(final int uniqueId, final Callback<OutpostToken> callback)
{
executeQuery(GET_OUTPOST_BY_ID, resultSet -> {
OutpostToken token = new OutpostToken();
resultSet.next();
load(token, resultSet);
callback.run(token);
}, new ColumnInt("uniqueId", uniqueId));
}
public void getOutpostByClan(final ClanInfo clan, final Callback<OutpostToken> callback)
{
executeQuery(GET_OUTPOST_BY_CLAN, resultSet -> {
resultSet.next();
OutpostToken token = new OutpostToken();
load(token, resultSet);
callback.run(token);
}, new ColumnInt("ownerClan", clan.getId()));
}
public void getOutpostsByServer(final int serverId, final Callback<List<OutpostToken>> callback)
{
executeQuery(GET_OUTPOSTS_BY_SERVER, resultSet -> {
List<OutpostToken> tokens = Lists.newArrayList();
while (resultSet.next())
{
OutpostToken token = new OutpostToken();
load(token, resultSet);
tokens.add(token);
}
callback.run(tokens);
}, new ColumnInt("serverId", serverId));
}
private void load(OutpostToken token, ResultSet columns) throws SQLException
{
token.UniqueId = columns.getInt("uniqueId");
token.Origin = UtilWorld.strToLoc(columns.getString("origin"));
token.Type = OutpostType.ById(columns.getByte("outpostType"));
token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan"));
token.Health = columns.getShort("health");
token.TimeSpawned = columns.getTimestamp("timeSpawned").getTime();
token.AgainstClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("againstClan"));
token.SiegeDeclaredTime = columns.getTimestamp("siegeDeclaredTime").getTime();
token.OutpostState = OutpostState.ById(columns.getByte("outpostState"));
}
@Override
protected void initialize()
{
executeUpdate(CREATE);
}
@Override
protected void update()
{
}
public void updateOutpost(OutpostToken token)
{
executeUpdate(UPDATE_OUTPOST,
new ColumnInt("health", token.Health),
new ColumnInt("againstClan", token.AgainstClan == null ? 0 : token.AgainstClan.getId()),
new ColumnTimestamp("siegeDeclaredTime", new Timestamp(token.SiegeDeclaredTime)),
new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId())),
new ColumnInt("uniqueId", token.UniqueId));
}
public void insertOutpost(OutpostToken token)
{
executeUpdate(INSERT_OUTPOST,
new ColumnInt("uniqueId", token.UniqueId),
new ColumnInt("serverId", _manager.getClansManager().getServerId()),
new ColumnVarChar("origin", 30, UtilWorld.locToStr(token.Origin)),
new ColumnInt("outpostType", token.Type.getId()),
new ColumnInt("ownerClan", token.OwnerClan.getId()),
new ColumnInt("health", token.Health),
new ColumnTimestamp("timeSpawned", new Timestamp(token.TimeSpawned)),
new ColumnInt("againstClan", token.AgainstClan == null ? 0 : token.AgainstClan.getId()),
new ColumnTimestamp("siegeDeclaredTime", new Timestamp(token.SiegeDeclaredTime)),
new ColumnByte("outpostState", Byte.valueOf(token.OutpostState.getId())));
}
}

View File

@ -0,0 +1,124 @@
package mineplex.game.clans.clans.siege.repository;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.common.collect.Lists;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
public class SiegeWeaponRepository extends RepositoryBase
{
private SiegeManager _manager;
private static final String CREATE = "CREATE TABLE IF NOT EXISTS clansSiegeWeapons (uniqueId INT NOT NULL,"
+ "serverId INT NOT NULL,"
+ "location VARCHAR(30),"
+ "ownerClan INT NOT NULL,"
+ "outpostId INT,"
+ "weaponType TINYINT NOT NULL,"
+ "health int NOT NULL,"
+ "yaw int NOT NULL,"
+ "lastFired LONG);";
private static final String GET_WEAPON_BY_ID = "SELECT * FROM clansSiegeWeapons WHERE uniqueId=?;";
private static final String GET_WEAPONS_BY_CLAN = "SELECT * FROM clansSiegeWeapons WHERE ownerClan=?;";
private static final String GET_WEAPONS_BY_OUTPOST = "SELECT * FROM clansSiegeWeapons WHERE outpostId=?;";
private static final String DELETE_WEAPON = "DELETE FROM clansSiegeWeapons WHERE uniqueId=?;";
public SiegeWeaponRepository(JavaPlugin plugin, SiegeManager manager)
{
super(plugin, DBPool.getAccount());
_manager = manager;
}
public void deleteWeapon(final int uniqueId)
{
executeUpdate(DELETE_WEAPON, new ColumnInt("uniqueId", uniqueId));
}
public void getWeaponById(final int uniqueId, final Callback<SiegeWeaponToken> callback)
{
executeQuery(GET_WEAPON_BY_ID, resultSet -> {
SiegeWeaponToken token = new SiegeWeaponToken();
resultSet.next();
load(token, resultSet);
callback.run(token);
}, new ColumnInt("uniqueId", uniqueId));
}
public void getWeaponsByClan(final ClanInfo clan, final Callback<List<SiegeWeaponToken>> callback)
{
executeQuery(GET_WEAPONS_BY_CLAN, resultSet -> {
List<SiegeWeaponToken> tokens = Lists.newArrayList();
while (resultSet.next())
{
SiegeWeaponToken token = new SiegeWeaponToken();
load(token, resultSet);
tokens.add(token);
}
callback.run(tokens);
}, new ColumnInt("ownerClan", clan.getId()));
}
public void getWeaponsByOutpost(final Outpost outpost, final Callback<List<SiegeWeaponToken>> callback)
{
executeQuery(GET_WEAPONS_BY_OUTPOST, resultSet -> {
List<SiegeWeaponToken> tokens = Lists.newArrayList();
while (resultSet.next())
{
SiegeWeaponToken token = new SiegeWeaponToken();
load(token, resultSet);
tokens.add(token);
}
callback.run(tokens);
}, new ColumnInt("outpostId", outpost.getUniqueId()));
}
private void load(SiegeWeaponToken token, ResultSet columns) throws SQLException
{
token.Id = columns.getInt("uniqueId");
token.Location = UtilWorld.strToLoc(columns.getString("location"));
token.OwnerClan = _manager.getClansManager().getClanUtility().getClanById(columns.getInt("ownerClan"));
token.OutpostId = columns.getInt("outpostId");
token.WeaponType = columns.getByte("weaponType");
token.Health = columns.getShort("health");
token.Yaw = columns.getShort("yaw");
token.LastFired = columns.getTimestamp("lastFired").getTime();
}
@Override
protected void initialize()
{
executeUpdate(CREATE);
}
@Override
protected void update()
{
}
}

View File

@ -1,24 +1,20 @@
package mineplex.game.clans.clans.siege.weapon.serialization; package mineplex.game.clans.clans.siege.repository.tokens;
import java.util.UUID;
import org.bukkit.Location; import org.bukkit.Location;
import mineplex.core.common.GsonLocation;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.outpost.OutpostState; import mineplex.game.clans.clans.siege.outpost.OutpostState;
import mineplex.game.clans.clans.siege.outpost.OutpostType; import mineplex.game.clans.clans.siege.outpost.OutpostType;
public class OutpostToken public class OutpostToken
{ {
public String Id; public int UniqueId;
public GsonLocation Origin; public Location Origin;
public OutpostType Type; public OutpostType Type;
public String OwnerClan; public ClanInfo OwnerClan;
public double Health; public int Health;
public long TimeSpawned; public long TimeSpawned;
public String AgainstClan; public ClanInfo AgainstClan;
public long SiegeDeclaredTime; public long SiegeDeclaredTime;
public OutpostState OutpostState; public OutpostState OutpostState;
public UUID DataEntityUUID;
} }

View File

@ -0,0 +1,22 @@
package mineplex.game.clans.clans.siege.repository.tokens;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import mineplex.game.clans.clans.ClanInfo;
public class SiegeWeaponToken
{
public int Id;
public ClanInfo OwnerClan;
public byte WeaponType;
public int OutpostId;
public Location Location;
public Map<String, UUID> ComprisedOf;
public int Health;
public int Yaw;
public UUID Rider;
public long LastFired;
}

View File

@ -28,9 +28,9 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
@ -41,7 +41,7 @@ public class Cannon extends SiegeWeapon
public Cannon(SiegeManager siegeManager, SiegeWeaponToken token) public Cannon(SiegeManager siegeManager, SiegeWeaponToken token)
{ {
super(1400.d, "Cannon", token, siegeManager.getClansManager(), siegeManager); super(1400, "Cannon", token, siegeManager.getClansManager(), siegeManager);
setBoundingBox(1); setBoundingBox(1);
@ -67,7 +67,7 @@ public class Cannon extends SiegeWeapon
return false; return false;
} }
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false; return false;
@ -91,7 +91,7 @@ public class Cannon extends SiegeWeapon
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false; return false;
@ -109,7 +109,7 @@ public class Cannon extends SiegeWeapon
public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost)
{ {
super(2, location, 1400.d, "Cannon", clan, clan.Clans, siegeManager, outpost); super(2, location, 1400, "Cannon", clan, clan.Clans, siegeManager, outpost);
setBoundingBox(1); setBoundingBox(1);
@ -137,7 +137,7 @@ public class Cannon extends SiegeWeapon
return false; return false;
} }
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false; return false;
@ -161,7 +161,7 @@ public class Cannon extends SiegeWeapon
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
return false; return false;

View File

@ -24,9 +24,9 @@ import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClanInfo; import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo; import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
@ -37,7 +37,7 @@ public class Catapult extends SiegeWeapon
public Catapult(SiegeManager siegeManager, SiegeWeaponToken token) public Catapult(SiegeManager siegeManager, SiegeWeaponToken token)
{ {
super(1400.d, "Catapult", token, siegeManager.getClansManager(), siegeManager); super(1400, "Catapult", token, siegeManager.getClansManager(), siegeManager);
setBoundingBox(3, 0); setBoundingBox(3, 0);
@ -66,7 +66,7 @@ public class Catapult extends SiegeWeapon
return false; return false;
} }
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false; return false;
@ -90,7 +90,7 @@ public class Catapult extends SiegeWeapon
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false; return false;
@ -108,7 +108,7 @@ public class Catapult extends SiegeWeapon
public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost) public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager, Outpost outpost)
{ {
super(1, location, 2500.d, "Catapult", clan, clan.Clans, siegeManager, outpost); super(1, location, 2500, "Catapult", clan, clan.Clans, siegeManager, outpost);
setBoundingBox(3, 0); setBoundingBox(3, 0);
@ -139,7 +139,7 @@ public class Catapult extends SiegeWeapon
return false; return false;
} }
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false; return false;
@ -163,7 +163,7 @@ public class Catapult extends SiegeWeapon
enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider()))); enableInventory(UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cDAquaB + _name), new AccessRule(AccessType.RCLICK_BB, player -> player.equals(getRider())));
setRideable(new AccessRule(AccessType.RCLICK_BB, player -> { setRideable(new AccessRule(AccessType.RCLICK_BB, player -> {
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan.")); UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
return false; return false;

View File

@ -1,6 +1,5 @@
package mineplex.game.clans.clans.siege.weapon; package mineplex.game.clans.clans.siege.weapon;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -28,7 +27,6 @@ import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.EulerAngle; import org.bukkit.util.EulerAngle;
import org.spigotmc.event.entity.EntityDismountEvent; import org.spigotmc.event.entity.EntityDismountEvent;
@ -52,10 +50,9 @@ import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent; import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
import mineplex.game.clans.clans.siege.outpost.Outpost; import mineplex.game.clans.clans.siege.outpost.Outpost;
import mineplex.game.clans.clans.siege.outpost.OutpostManager; import mineplex.game.clans.clans.siege.repository.tokens.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes; import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile; import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
import mineplex.game.clans.clans.siege.weapon.serialization.SiegeWeaponToken;
import mineplex.game.clans.clans.siege.weapon.util.AccessRule; import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
import mineplex.game.clans.clans.siege.weapon.util.AccessType; import mineplex.game.clans.clans.siege.weapon.util.AccessType;
import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox; import mineplex.game.clans.clans.siege.weapon.util.BarrierCollisionBox;
@ -66,17 +63,17 @@ public abstract class SiegeWeapon implements Listener
protected ClansManager _clans; protected ClansManager _clans;
protected SiegeManager _siegeManager; protected SiegeManager _siegeManager;
protected String _id; protected int _uniqueId;
/** /**
* THIS MAY BE NULL IF NOT PLACED IN OUTPOST * THIS MAY BE NULL IF NOT PLACED IN OUTPOST
*/ */
protected Outpost _outpost; protected Outpost _outpost;
protected ClanInfo _owner; protected ClanInfo _ownerClan;
protected final String _name; protected final String _name;
protected final double _maxHealth; protected final int _maxHealth;
protected double _health; protected int _health;
protected Inventory _inventory; protected Inventory _inventory;
protected AccessRule _inventoryAccess; protected AccessRule _inventoryAccess;
@ -134,20 +131,18 @@ public abstract class SiegeWeapon implements Listener
protected final int _weaponTypeIdentifier; protected final int _weaponTypeIdentifier;
private ArmorStand _dataEntity; public SiegeWeapon(int maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager)
public SiegeWeapon(double maxHealth, String name, SiegeWeaponToken token, ClansManager clansManager, SiegeManager siegeManager)
{ {
_weaponTypeIdentifier = token.WeaponType; _weaponTypeIdentifier = token.WeaponType;
_id = token.Id; _uniqueId = token.Id;
_outpost = siegeManager.getOutpostManager().Get(token.OutpostId); _outpost = siegeManager.getOutpostManager().Get(token.OutpostId);
_siegeManager = siegeManager; _siegeManager = siegeManager;
_location = token.Location; _location = token.Location;
_name = name; _name = name;
_health = _maxHealth = maxHealth; _health = _maxHealth = maxHealth;
_owner = clansManager.getClan(token.OwnerClan); _ownerClan = token.OwnerClan;
_comprisedOf = Lists.newArrayList(); _comprisedOf = Lists.newArrayList();
_registeredStates = Maps.newHashMap(); _registeredStates = Maps.newHashMap();
@ -156,7 +151,7 @@ public abstract class SiegeWeapon implements Listener
_infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth()); _infoHologram = new Hologram(ClansManager.getInstance().getHologramManager(), _location.clone().add(.5, 3, .5), _name + " Health", getDisplayHealth());
_infoHologram.start(); _infoHologram.start();
UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); UtilServer.registerEvents(this);
_clans = clansManager; _clans = clansManager;
@ -170,13 +165,7 @@ public abstract class SiegeWeapon implements Listener
_entityMapping.put(entry.getKey(), entity); _entityMapping.put(entry.getKey(), entity);
} }
} }
if (entity.getUniqueId().equals(token.DataEntityUUID))
{
_dataEntity = (ArmorStand) entity;
} }
}
_yaw = token.Yaw; _yaw = token.Yaw;
_rider = Bukkit.getPlayer(token.Rider); _rider = Bukkit.getPlayer(token.Rider);
@ -185,9 +174,9 @@ public abstract class SiegeWeapon implements Listener
_health = token.Health; _health = token.Health;
} }
public SiegeWeapon(int typeId, Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost) public SiegeWeapon(int typeId, Location location, int maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager, Outpost outpost)
{ {
_id = Integer.toString(UtilMath.random.nextInt(13333337)); _uniqueId = siegeManager.randomId();
_weaponTypeIdentifier = typeId; _weaponTypeIdentifier = typeId;
_outpost = outpost; _outpost = outpost;
@ -195,7 +184,7 @@ public abstract class SiegeWeapon implements Listener
_location = location; _location = location;
_name = name; _name = name;
_health = _maxHealth = maxHealth; _health = _maxHealth = maxHealth;
_owner = owner; _ownerClan = owner;
_comprisedOf = Lists.newArrayList(); _comprisedOf = Lists.newArrayList();
_registeredStates = Maps.newHashMap(); _registeredStates = Maps.newHashMap();
@ -207,70 +196,6 @@ public abstract class SiegeWeapon implements Listener
UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin()); UtilServer.getPluginManager().registerEvents(this, clansManager.getPlugin());
_clans = clansManager; _clans = clansManager;
_dataEntity = location.getWorld().spawn(location.subtract(0, 5, 0), ArmorStand.class);
_dataEntity.setVisible(false);
_dataEntity.setGravity(false);
}
public SiegeWeaponToken tokenize()
{
SiegeWeaponToken token = new SiegeWeaponToken();
Map<String, UUID> comprisedOf = new HashMap<>();
for (Entry<String, Entity> entry : _entityMapping.entrySet())
{
comprisedOf.put(entry.getKey(), entry.getValue().getUniqueId());
}
token.ComprisedOf = comprisedOf;
token.OwnerClan = _owner.getName();
token.WeaponType = _weaponTypeIdentifier;
token.OutpostId = _outpost.getId();
token.Id = _id;
token.Location = _location;
token.Health = _health;
token.Yaw = _yaw;
token.DataEntityUUID = _dataEntity.getUniqueId();
token.Rider = _rider.getUniqueId();
token.LastFired = _lastFired;
return token;
}
private void updateData()
{
try
{
String data = _siegeManager.getGson().toJson(tokenize());
_dataEntity.setMetadata("$SERIALIZED_SIEGE_WEAPON_DATA$", new FixedMetadataValue(_siegeManager.getPlugin(), data));
}
catch (Exception e)
{
e.printStackTrace();
}
}
@EventHandler
public void saveData(UpdateEvent event)
{
if (event.getType() == UpdateType.SEC_05)
{
updateData();
}
} }
public int getBaseDamage() public int getBaseDamage()
@ -280,7 +205,7 @@ public abstract class SiegeWeapon implements Listener
public ClanInfo getOwner() public ClanInfo getOwner()
{ {
return _owner; return _ownerClan;
} }
public ClansManager getClans() public ClansManager getClans()
@ -294,7 +219,7 @@ public abstract class SiegeWeapon implements Listener
removeHealth(health); removeHealth(health);
UtilTextMiddle.display(UtilText.possesive(_owner.getName(), _name), C.cRed + "-" + health, 5, 15, 5); UtilTextMiddle.display(UtilText.possesive(_ownerClan.getName(), _name), C.cRed + "-" + health, 5, 15, 5);
} }
protected abstract double[] getProjectileVelocity(); protected abstract double[] getProjectileVelocity();
@ -497,9 +422,9 @@ public abstract class SiegeWeapon implements Listener
return player.equals(getRider()); return player.equals(getRider());
} }
public String getId() public int getUniqueId()
{ {
return _id; return _uniqueId;
} }
protected void setRideable(AccessRule accessRule) protected void setRideable(AccessRule accessRule)
@ -520,8 +445,6 @@ public abstract class SiegeWeapon implements Listener
_comprisedOf.clear(); _comprisedOf.clear();
_infoHologram.stop(); _infoHologram.stop();
_dataEntity.remove();
_siegeManager.dead(this); _siegeManager.dead(this);
_alive = false; _alive = false;
@ -624,7 +547,7 @@ public abstract class SiegeWeapon implements Listener
return; return;
} }
if (!_owner.isMember(player)) if (!_ownerClan.isMember(player))
{ {
damage(player); damage(player);
} }
@ -696,17 +619,17 @@ public abstract class SiegeWeapon implements Listener
// Health Management // Health Management
public final double getHealth() public final int getHealth()
{ {
return _health; return _health;
} }
public final String getDisplayHealth() public final String getDisplayHealth()
{ {
return UtilText.getProgress(null, _health / _maxHealth, null, false, 12); return UtilText.getProgress(null, ((double) _health) / ((double) _maxHealth), null, false, 12);
} }
public final void setHealth(double health) public final void setHealth(int health)
{ {
_health = UtilMath.clamp(health, 0, _maxHealth); _health = UtilMath.clamp(health, 0, _maxHealth);
@ -718,12 +641,12 @@ public abstract class SiegeWeapon implements Listener
} }
} }
public final void removeHealth(double health) public final void removeHealth(int health)
{ {
setHealth(_health - health); setHealth(_health - health);
} }
public final void addHealth(double health) public final void addHealth(int health)
{ {
setHealth(_health + health); setHealth(_health + health);
} }

View File

@ -1,23 +0,0 @@
package mineplex.game.clans.clans.siege.weapon.serialization;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import mineplex.core.common.GsonLocation;
public class SiegeWeaponToken
{
public String OwnerClan;
public int WeaponType;
public String OutpostId;
public GsonLocation Location;
public Map<String, UUID> ComprisedOf;
public double Health;
public double Yaw;
public UUID Rider;
public String Id;
public long LastFired;
public UUID DataEntityUUID;
}

View File

@ -1,6 +0,0 @@
package mineplex.game.clans.clans.siege.weapon.serialization;
public class TokenInfo
{
public Class<?> Type;
}

View File

@ -154,9 +154,14 @@ public class Gameplay extends MiniPlugin
} }
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBowShoot(EntityShootBowEvent event) public void onBowShoot(EntityShootBowEvent event)
{ {
if (event.isCancelled())
{
return;
}
if (event.getEntity() instanceof Player) if (event.getEntity() instanceof Player)
{ {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();

View File

@ -0,0 +1,4 @@
ACCOUNT 10.33.53.17/Account MilitantPaladin ga.Usarathehe6up
QUEUE 10.33.53.17/Queue MilitantPaladin ga.Usarathehe6up
MINEPLEX 10.33.53.17/Mineplex MilitantPaladin ga.Usarathehe6up
STATS_MINEPLEX 10.33.53.17/Mineplex MilitantPaladin ga.Usarathehe6up

4
Plugins/redis-config.dat Normal file
View File

@ -0,0 +1,4 @@
10.33.53.17 6379 master ServerStatus
10.33.53.17 6378 slave ServerStatus
10.33.53.17 6379 master
10.33.53.17 6378 slave