Save armour and location only in Bridges

This commit is contained in:
Sam 2018-07-23 15:00:59 +01:00 committed by Alexander Meech
parent ec1038bce6
commit 9a2ebdfb33
2 changed files with 59 additions and 3 deletions

View File

@ -272,7 +272,9 @@ public class Bridge extends TeamGame implements OreObsfucation
.setGiveCompassToAlive(true)
.register(this);
_rejoinModule = new RejoinModule(manager);
_rejoinModule = new RejoinModule(manager)
.setSaveInventory(true)
.setSaveLocation(true);
_rejoinModule.register(this);
// So that we can be 110% sure

View File

@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilServer;
import mineplex.core.game.region.GameRejoinManager;
@ -26,6 +27,8 @@ public class RejoinModule extends Module
private final GameRejoinManager _manager;
private final Map<UUID, PlayerGameInfo> _rejoinData;
private boolean _saveInventory, _saveLocation;
public RejoinModule(ArcadeManager manager)
{
_manager = new GameRejoinManager(manager);
@ -47,6 +50,18 @@ public class RejoinModule extends Module
UtilServer.Unregister(_manager);
}
public RejoinModule setSaveInventory(boolean saveInventory)
{
_saveInventory = saveInventory;
return this;
}
public RejoinModule setSaveLocation(boolean saveLocation)
{
_saveLocation = saveLocation;
return this;
}
public void disableRejoining()
{
getGame().QuitOut = true;
@ -69,8 +84,23 @@ public class RejoinModule extends Module
return;
}
_rejoinData.put(player.getUniqueId(), new PlayerGameInfo(player.getHealth(), getGame().GetKit(player), team));
PlayerGameInfo data;
if (_saveInventory)
{
data = new PlayerGameInfo(player.getHealth(), player.getInventory().getContents(), player.getInventory().getArmorContents(), getGame().GetKit(player), team);
}
else
{
data = new PlayerGameInfo(player.getHealth(), getGame().GetKit(player), team);
}
_rejoinData.put(player.getUniqueId(), data);
if (_saveLocation)
{
getGame().GetLocationStore().putIfAbsent(player.getName(), player.getLocation());
}
team.RemovePlayer(player);
@ -130,6 +160,12 @@ public class RejoinModule extends Module
}
player.setHealth(Math.min(info.getHealth(), player.getHealth()));
if (_saveInventory)
{
player.getInventory().setArmorContents(info.getInventoryArmour());
player.getInventory().setContents(info.getInventoryContents());
}
}
private boolean isEnabled()
@ -140,13 +176,21 @@ public class RejoinModule extends Module
public class PlayerGameInfo
{
private final double _health;
private final ItemStack[] _inventoryContents, _inventoryArmour;
private final Kit _kit;
private GameTeam _team;
private boolean _cancelled;
PlayerGameInfo(double health, Kit kit, GameTeam team)
{
this(health, null, null, kit, team);
}
PlayerGameInfo(double health, ItemStack[] inventoryContents, ItemStack[] inventoryArmour, Kit kit, GameTeam team)
{
_health = health;
_inventoryContents = inventoryContents;
_inventoryArmour = inventoryArmour;
_kit = kit;
_team = team;
}
@ -156,6 +200,16 @@ public class RejoinModule extends Module
return _health;
}
public ItemStack[] getInventoryContents()
{
return _inventoryContents;
}
public ItemStack[] getInventoryArmour()
{
return _inventoryArmour;
}
public Kit getKit()
{
return _kit;