mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 18:55:28 +01:00
Closes gh-289. Closes gh-290. Along with inventory, now saving full player state: health, foodLevel, saturation, exhaustion and gamemode. Switching creative people to survival. Full state is restored when player leaves the zone.
This commit is contained in:
parent
1266462635
commit
599e6b11d5
@ -56,7 +56,7 @@ public class War extends JavaPlugin {
|
||||
private final List<String> zoneMakerNames = new ArrayList<String>();
|
||||
private final List<String> commandWhitelist = new ArrayList<String>();
|
||||
private final List<String> zoneMakersImpersonatingPlayers = new ArrayList<String>();
|
||||
private HashMap<String, InventoryStash> disconnected = new HashMap<String, InventoryStash>();
|
||||
private HashMap<String, PlayerState> disconnected = new HashMap<String, PlayerState>();
|
||||
private final HashMap<String, String> wandBearers = new HashMap<String, String>(); // playername to zonename
|
||||
|
||||
// Global settings
|
||||
@ -1057,11 +1057,11 @@ public class War extends JavaPlugin {
|
||||
return this.defaultFlagReturn;
|
||||
}
|
||||
|
||||
public HashMap<String, InventoryStash> getDisconnected() {
|
||||
public HashMap<String, PlayerState> getDisconnected() {
|
||||
return this.disconnected;
|
||||
}
|
||||
|
||||
public void setDisconnected(HashMap<String, InventoryStash> disconnected) {
|
||||
public void setDisconnected(HashMap<String, PlayerState> disconnected) {
|
||||
this.disconnected = disconnected;
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if (War.war.getWarHub() != null) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
zone.keepPlayerInventory(player);
|
||||
zone.keepPlayerState(player);
|
||||
War.war.msg(player, "Your inventory is in storage until exit with '/war leave'.");
|
||||
zone.respawnPlayer(event, team, player);
|
||||
for (Team t : zone.getTeams()) {
|
||||
@ -441,8 +441,8 @@ public class WarPlayerListener extends PlayerListener {
|
||||
// flags can be captured at own spawn or own flag pole
|
||||
playerTeam.addPoint();
|
||||
if (playerTeam.getPoints() >= playerWarzone.getScoreCap()) {
|
||||
if (playerWarzone.hasPlayerInventory(player.getName())) {
|
||||
playerWarzone.restorePlayerInventory(player);
|
||||
if (playerWarzone.hasPlayerState(player.getName())) {
|
||||
playerWarzone.restorePlayerState(player);
|
||||
}
|
||||
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
|
||||
event.setTo(playerWarzone.getTeleport());
|
||||
|
@ -57,7 +57,7 @@ public class DeleteZoneCommand extends AbstractZoneMakerCommand {
|
||||
|
||||
// reset inventory
|
||||
for (Player p : t.getPlayers()) {
|
||||
zone.restorePlayerInventory(p);
|
||||
zone.restorePlayerState(p);
|
||||
}
|
||||
}
|
||||
for (Monument m : zone.getMonuments()) {
|
||||
|
@ -98,8 +98,8 @@ public class JoinCommand extends AbstractWarCommand {
|
||||
boolean foundTeam = false;
|
||||
for (Team team : teams) {
|
||||
if (team.getName().startsWith(name) || team.getKind() == kind) {
|
||||
if (!zone.hasPlayerInventory(player.getName())) {
|
||||
zone.keepPlayerInventory(player);
|
||||
if (!zone.hasPlayerState(player.getName())) {
|
||||
zone.keepPlayerState(player);
|
||||
this.msg("Your inventory is in storage until you use '/war leave'.");
|
||||
}
|
||||
if (team.getPlayers().size() < zone.getTeamCap()) {
|
||||
|
@ -43,7 +43,7 @@ public class ResetZoneCommand extends AbstractZoneMakerCommand {
|
||||
for (Team team : zone.getTeams()) {
|
||||
team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams...");
|
||||
for (Player p : team.getPlayers()) {
|
||||
zone.restorePlayerInventory(p);
|
||||
zone.restorePlayerState(p);
|
||||
p.teleport(zone.getTeleport());
|
||||
War.war.msg(p, "You have left the warzone. Your inventory has been restored.");
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -23,7 +24,7 @@ import bukkit.tommytony.war.War;
|
||||
import com.tommytony.war.jobs.InitZoneJob;
|
||||
import com.tommytony.war.jobs.LoadoutResetJob;
|
||||
import com.tommytony.war.jobs.ScoreCapReachedJob;
|
||||
import com.tommytony.war.utils.InventoryStash;
|
||||
import com.tommytony.war.utils.PlayerState;
|
||||
import com.tommytony.war.volumes.ZoneVolume;
|
||||
|
||||
/**
|
||||
@ -49,7 +50,7 @@ public class Warzone {
|
||||
private TeamSpawnStyle spawnStyle = TeamSpawnStyle.BIG;
|
||||
private HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
|
||||
|
||||
private HashMap<String, InventoryStash> inventories = new HashMap<String, InventoryStash>();
|
||||
private HashMap<String, PlayerState> playerStates = new HashMap<String, PlayerState>();
|
||||
private HashMap<String, Team> flagThieves = new HashMap<String, Team>();
|
||||
private HashMap<String, Integer> newlyRespawned = new HashMap<String, Integer>();
|
||||
private World world;
|
||||
@ -70,7 +71,7 @@ public class Warzone {
|
||||
private boolean resetOnLoad = false;
|
||||
private boolean resetOnUnload = false;
|
||||
|
||||
private HashMap<String, InventoryStash> deadMenInventories = new HashMap<String, InventoryStash>();
|
||||
private HashMap<String, PlayerState> deadMenInventories = new HashMap<String, PlayerState>();
|
||||
private Location rallyPoint;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -316,6 +317,12 @@ public class Warzone {
|
||||
// Fill hp
|
||||
player.setRemainingAir(300);
|
||||
player.setHealth(20);
|
||||
player.setFoodLevel(20);
|
||||
player.setSaturation(20);
|
||||
player.setExhaustion(0);
|
||||
if (player.getGameMode() == GameMode.CREATIVE) {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
if (!this.getNewlyRespawned().keySet().contains(player.getName())) {
|
||||
this.getNewlyRespawned().put(player.getName(), 0);
|
||||
}
|
||||
@ -444,25 +451,32 @@ public class Warzone {
|
||||
return this.monumentHeal;
|
||||
}
|
||||
|
||||
public boolean hasPlayerInventory(String playerName) {
|
||||
return this.inventories.containsKey(playerName);
|
||||
public boolean hasPlayerState(String playerName) {
|
||||
return this.playerStates.containsKey(playerName);
|
||||
}
|
||||
|
||||
public void keepPlayerInventory(Player player) {
|
||||
public void keepPlayerState(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack[] contents = inventory.getContents();
|
||||
this.inventories.put(player.getName(), new InventoryStash(contents, inventory.getHelmet(), inventory.getChestplate(), inventory.getLeggings(), inventory.getBoots()));
|
||||
this.playerStates.put(player.getName(), new PlayerState(player.getGameMode(),
|
||||
contents, inventory.getHelmet(), inventory.getChestplate(), inventory.getLeggings(), inventory.getBoots(),
|
||||
player.getHealth(), player.getExhaustion(), player.getSaturation(), player.getFoodLevel()));
|
||||
}
|
||||
|
||||
public void restorePlayerInventory(Player player) {
|
||||
InventoryStash originalContents = this.inventories.remove(player.getName());
|
||||
public void restorePlayerState(Player player) {
|
||||
PlayerState originalContents = this.playerStates.remove(player.getName());
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
if (originalContents != null) {
|
||||
this.playerInvFromInventoryStash(playerInv, originalContents);
|
||||
player.setGameMode(originalContents.getGamemode());
|
||||
player.setHealth(originalContents.getHealth());
|
||||
player.setExhaustion(originalContents.getExhaustion());
|
||||
player.setSaturation(originalContents.getSaturation());
|
||||
player.setFoodLevel(originalContents.getFoodLevel());
|
||||
}
|
||||
}
|
||||
|
||||
private void playerInvFromInventoryStash(PlayerInventory playerInv, InventoryStash originalContents) {
|
||||
private void playerInvFromInventoryStash(PlayerInventory playerInv, PlayerState originalContents) {
|
||||
playerInv.clear();
|
||||
playerInv.clear(playerInv.getSize() + 0);
|
||||
playerInv.clear(playerInv.getSize() + 1);
|
||||
@ -487,9 +501,9 @@ public class Warzone {
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryStash getPlayerInventory(String playerName) {
|
||||
if (this.inventories.containsKey(playerName)) {
|
||||
return this.inventories.get(playerName);
|
||||
public PlayerState getPlayerState(String playerName) {
|
||||
if (this.playerStates.containsKey(playerName)) {
|
||||
return this.playerStates.get(playerName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -723,8 +737,8 @@ public class Warzone {
|
||||
if (lowestNoOfPlayers != null) {
|
||||
lowestNoOfPlayers.addPlayer(player);
|
||||
lowestNoOfPlayers.resetSign();
|
||||
if (!this.hasPlayerInventory(player.getName())) {
|
||||
this.keepPlayerInventory(player);
|
||||
if (!this.hasPlayerState(player.getName())) {
|
||||
this.keepPlayerState(player);
|
||||
}
|
||||
War.war.msg(player, "Your inventory is in storage until you use '/war leave'.");
|
||||
this.respawnPlayer(lowestNoOfPlayers, player);
|
||||
@ -878,10 +892,9 @@ public class Warzone {
|
||||
if (this.getLobby() != null) {
|
||||
this.getLobby().resetTeamGateSign(playerTeam);
|
||||
}
|
||||
if (this.hasPlayerInventory(player.getName())) {
|
||||
this.restorePlayerInventory(player);
|
||||
if (this.hasPlayerState(player.getName())) {
|
||||
this.restorePlayerState(player);
|
||||
}
|
||||
player.setHealth(20);
|
||||
player.setFireTicks(0);
|
||||
player.setRemainingAir(300);
|
||||
|
||||
|
@ -28,8 +28,8 @@ public class ScoreCapReachedJob implements Runnable {
|
||||
}
|
||||
tp.setFireTicks(0);
|
||||
tp.setRemainingAir(300);
|
||||
if (this.zone.hasPlayerInventory(tp.getName())) {
|
||||
this.zone.restorePlayerInventory(tp);
|
||||
if (this.zone.hasPlayerState(tp.getName())) {
|
||||
this.zone.restorePlayerState(tp);
|
||||
}
|
||||
if (this.winnersStr.contains(t.getName())) {
|
||||
// give reward
|
||||
|
92
war/src/main/java/com/tommytony/war/utils/PlayerState.java
Normal file
92
war/src/main/java/com/tommytony/war/utils/PlayerState.java
Normal file
@ -0,0 +1,92 @@
|
||||
package com.tommytony.war.utils;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PlayerState {
|
||||
private ItemStack[] contents;
|
||||
private ItemStack helmet;
|
||||
private ItemStack chest;
|
||||
private ItemStack legs;
|
||||
private ItemStack feet;
|
||||
private final float exhaustion;
|
||||
private final float saturation;
|
||||
private final int foodLevel;
|
||||
private final int health;
|
||||
private final GameMode gamemode;
|
||||
|
||||
|
||||
public PlayerState(GameMode gamemode, ItemStack[] contents, ItemStack helmet, ItemStack chest, ItemStack legs, ItemStack feet, int health, float exhaustion, float saturation, int foodLevel) {
|
||||
this.gamemode = gamemode;
|
||||
this.health = health;
|
||||
this.exhaustion = exhaustion;
|
||||
this.saturation = saturation;
|
||||
this.foodLevel = foodLevel;
|
||||
this.setContents(contents);
|
||||
this.setHelmet(helmet);
|
||||
this.setChest(chest);
|
||||
this.setLegs(legs);
|
||||
this.setFeet(feet);
|
||||
}
|
||||
|
||||
public void setContents(ItemStack[] contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
public ItemStack[] getContents() {
|
||||
return this.contents;
|
||||
}
|
||||
|
||||
public void setHelmet(ItemStack helmet) {
|
||||
this.helmet = helmet;
|
||||
}
|
||||
|
||||
public ItemStack getHelmet() {
|
||||
return this.helmet;
|
||||
}
|
||||
|
||||
public void setChest(ItemStack chest) {
|
||||
this.chest = chest;
|
||||
}
|
||||
|
||||
public ItemStack getChest() {
|
||||
return this.chest;
|
||||
}
|
||||
|
||||
public void setLegs(ItemStack legs) {
|
||||
this.legs = legs;
|
||||
}
|
||||
|
||||
public ItemStack getLegs() {
|
||||
return this.legs;
|
||||
}
|
||||
|
||||
public void setFeet(ItemStack feet) {
|
||||
this.feet = feet;
|
||||
}
|
||||
|
||||
public ItemStack getFeet() {
|
||||
return this.feet;
|
||||
}
|
||||
|
||||
public float getExhaustion() {
|
||||
return exhaustion;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public int getFoodLevel() {
|
||||
return foodLevel;
|
||||
}
|
||||
|
||||
public int getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public GameMode getGamemode() {
|
||||
return gamemode;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user