Fix player relog state resets. Resolves #240; resolves #244

This commit is contained in:
Daniel Saukel 2018-04-28 02:50:38 +02:00
parent dceadc399b
commit 60f2a497dd
6 changed files with 90 additions and 79 deletions

View File

@ -237,8 +237,9 @@ public class DGamePlayer extends DInstancePlayer {
}
DClass dClass = plugin.getDClasses().getByName(className);
if (dClass != null) {
if (this.dClass != dClass) {
if (dClass == null || this.dClass == dClass) {
return;
}
this.dClass = dClass;
/* Set Dog */
@ -294,8 +295,6 @@ public class DGamePlayer extends DInstancePlayer {
}
}
}
}
}
/**
* @return the checkpoint
@ -487,11 +486,13 @@ public class DGamePlayer extends DInstancePlayer {
GameRuleProvider rules = game.getRules();
delete();
if (player.isOnline()) {
if (finished) {
reset(rules.getKeepInventoryOnFinish());
} else {
reset(rules.getKeepInventoryOnEscape());
}
}
// Permission bridge
if (plugin.getPermissionProvider() != null) {

View File

@ -47,6 +47,8 @@ public class DGlobalPlayer implements PlayerWrapper {
DungeonsXL plugin = DungeonsXL.getInstance();
boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals());
protected Player player;
private DPlayerData data;
@ -328,12 +330,12 @@ public class DGlobalPlayer implements PlayerWrapper {
}
player.getInventory().setContents(data.getOldInventory().toArray(new ItemStack[36]));
player.getInventory().setArmorContents(data.getOldArmor().toArray(new ItemStack[4]));
if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
if (is1_9) {
player.getInventory().setItemInOffHand(data.getOldOffHand());
}
player.setLevel(data.getOldLevel());
player.setExp(data.getOldExp());
if (Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals())) {
if (is1_9) {
player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(data.getOldMaxHealth());
}
player.setHealth(data.getOldHealth() <= data.getOldMaxHealth() ? data.getOldHealth() : data.getOldMaxHealth());

View File

@ -60,7 +60,7 @@ public class DGroup {
DPlayerCache dPlayers = plugin.getDPlayers();
private String name;
private UUID captain;
private Player captain;
private PlayerCollection players = new PlayerCollection();
private PlayerCollection invitedPlayers = new PlayerCollection();
private Dungeon dungeon;
@ -114,8 +114,8 @@ public class DGroup {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.captain = captain.getUniqueId();
this.players.add(captain.getUniqueId());
this.captain = captain;
this.players.add(captain);
}
for (Player player : players) {
@ -155,12 +155,12 @@ public class DGroup {
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
this.captain = captain.getUniqueId();
this.players.add(captain.getUniqueId());
this.captain = captain;
this.players.add(captain);
}
for (Player player : players) {
if (!this.players.contains(player.getUniqueId())) {
if (!this.players.contains(player)) {
addPlayer(player);
}
}
@ -205,7 +205,7 @@ public class DGroup {
* @return the captain
*/
public Player getCaptain() {
return Bukkit.getPlayer(captain);
return captain;
}
/**
@ -213,7 +213,7 @@ public class DGroup {
* the captain to set
*/
public void setCaptain(Player captain) {
this.captain = captain.getUniqueId();
this.captain = captain;
}
/**
@ -818,6 +818,7 @@ public class DGroup {
continue;
}
dPlayer.getData().logTimeLastStarted(getDungeonName());
dPlayer.getData().setKeepInventoryAfterLogout(rules.getKeepInventoryOnEscape());
dPlayer.respawn();

View File

@ -166,11 +166,6 @@ public class DPlayerCache {
return false;
}
DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer());
if (dGroup != null) {
dGroup.removePlayer(dPlayer.getPlayer());
dGroup.addPlayer(player);
}
dPlayer.setPlayer(player);
dPlayer.setOfflineTime(0);
return true;

View File

@ -48,12 +48,13 @@ public class DPlayerData extends DREConfig {
boolean is1_9 = Internals.andHigher(Internals.v1_9_R1).contains(CompatibilityHandler.getInstance().getInternals());
public static final int CONFIG_VERSION = 3;
public static final int CONFIG_VERSION = 4;
public static final String PREFIX_STATE_PERSISTENCE = "savePlayer.";
public static final String PREFIX_STATS = "stats.";
// State persistence
private boolean keepInventoryAfterLogout = true;
private Location oldLocation;
private List<ItemStack> oldInventory;
private List<ItemStack> oldArmor;
@ -88,6 +89,23 @@ public class DPlayerData extends DREConfig {
return config.contains(PREFIX_STATE_PERSISTENCE);
}
/**
* @return if the inventory shall be reset after a logout
*/
public boolean getKeepInventoryAfterLogout() {
return keepInventoryAfterLogout;
}
/**
* @param keepInventoryOnEscape
* set if the inventory shall be reset after a logout
*/
public void setKeepInventoryAfterLogout(boolean keepInventoryAfterLogout) {
this.keepInventoryAfterLogout = keepInventoryAfterLogout;
config.set(PREFIX_STATE_PERSISTENCE + "keepInventoryAfterLogout", keepInventoryAfterLogout);
super.save();
}
/**
* @return the old location
*/
@ -390,6 +408,7 @@ public class DPlayerData extends DREConfig {
return;
}
keepInventoryAfterLogout = config.getBoolean(PREFIX_STATE_PERSISTENCE + "keepInventoryAfterLogout");
oldInventory = (List<ItemStack>) config.get(PREFIX_STATE_PERSISTENCE + "oldInventory");
oldArmor = (List<ItemStack>) config.get(PREFIX_STATE_PERSISTENCE + "oldArmor");
oldOffHand = (ItemStack) config.get(PREFIX_STATE_PERSISTENCE + "oldOffHand");

View File

@ -363,20 +363,13 @@ public class DPlayerListener implements Listener {
}
DGlobalPlayer dPlayer = new DGlobalPlayer(player);
if (player.hasPlayedBefore()) {
return;
if (dPlayer.getData().wasInGame()) {
dPlayer.reset(dPlayer.getData().getKeepInventoryAfterLogout());
}
if (!config.isTutorialActivated()) {
return;
}
if (DGamePlayer.getByPlayer(player) != null) {
return;
}
if (!player.hasPlayedBefore() && config.isTutorialActivated()) {
dPlayer.startTutorial();
}
}
@EventHandler(ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) {