mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-09 20:31:28 +01:00
parent
dceadc399b
commit
60f2a497dd
@ -237,62 +237,61 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
}
|
||||
|
||||
DClass dClass = plugin.getDClasses().getByName(className);
|
||||
if (dClass != null) {
|
||||
if (this.dClass != dClass) {
|
||||
this.dClass = dClass;
|
||||
if (dClass == null || this.dClass == dClass) {
|
||||
return;
|
||||
}
|
||||
this.dClass = dClass;
|
||||
|
||||
/* Set Dog */
|
||||
if (wolf != null) {
|
||||
wolf.remove();
|
||||
wolf = null;
|
||||
}
|
||||
/* Set Dog */
|
||||
if (wolf != null) {
|
||||
wolf.remove();
|
||||
wolf = null;
|
||||
}
|
||||
|
||||
if (dClass.hasDog()) {
|
||||
wolf = (Wolf) getWorld().spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
|
||||
wolf.setTamed(true);
|
||||
wolf.setOwner(getPlayer());
|
||||
if (dClass.hasDog()) {
|
||||
wolf = (Wolf) getWorld().spawnEntity(getPlayer().getLocation(), EntityType.WOLF);
|
||||
wolf.setTamed(true);
|
||||
wolf.setOwner(getPlayer());
|
||||
|
||||
double maxHealth = ((Damageable) wolf).getMaxHealth();
|
||||
wolf.setHealth(maxHealth);
|
||||
}
|
||||
double maxHealth = ((Damageable) wolf).getMaxHealth();
|
||||
wolf.setHealth(maxHealth);
|
||||
}
|
||||
|
||||
/* Delete Inventory */
|
||||
getPlayer().getInventory().clear();
|
||||
getPlayer().getInventory().setArmorContents(null);
|
||||
getPlayer().getInventory().setItemInHand(new ItemStack(Material.AIR));
|
||||
/* Delete Inventory */
|
||||
getPlayer().getInventory().clear();
|
||||
getPlayer().getInventory().setArmorContents(null);
|
||||
getPlayer().getInventory().setItemInHand(new ItemStack(Material.AIR));
|
||||
|
||||
// Remove Potion Effects
|
||||
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
|
||||
getPlayer().removePotionEffect(effect.getType());
|
||||
}
|
||||
// Remove Potion Effects
|
||||
for (PotionEffect effect : getPlayer().getActivePotionEffects()) {
|
||||
getPlayer().removePotionEffect(effect.getType());
|
||||
}
|
||||
|
||||
// Reset lvl
|
||||
getPlayer().setTotalExperience(0);
|
||||
getPlayer().setLevel(0);
|
||||
// Reset lvl
|
||||
getPlayer().setTotalExperience(0);
|
||||
getPlayer().setLevel(0);
|
||||
|
||||
/* Set Inventory */
|
||||
for (ItemStack istack : dClass.getItems()) {
|
||||
/* Set Inventory */
|
||||
for (ItemStack istack : dClass.getItems()) {
|
||||
|
||||
// Leggings
|
||||
if (istack.getType() == Material.LEATHER_LEGGINGS || istack.getType() == Material.CHAINMAIL_LEGGINGS || istack.getType() == Material.IRON_LEGGINGS
|
||||
|| istack.getType() == Material.DIAMOND_LEGGINGS || istack.getType() == LegacyUtil.GOLDEN_LEGGINGS) {
|
||||
getPlayer().getInventory().setLeggings(istack);
|
||||
} // Helmet
|
||||
else if (istack.getType() == Material.LEATHER_HELMET || istack.getType() == Material.CHAINMAIL_HELMET || istack.getType() == Material.IRON_HELMET
|
||||
|| istack.getType() == Material.DIAMOND_HELMET || istack.getType() == LegacyUtil.GOLDEN_HELMET) {
|
||||
getPlayer().getInventory().setHelmet(istack);
|
||||
} // Chestplate
|
||||
else if (istack.getType() == Material.LEATHER_CHESTPLATE || istack.getType() == Material.CHAINMAIL_CHESTPLATE || istack.getType() == Material.IRON_CHESTPLATE
|
||||
|| istack.getType() == Material.DIAMOND_CHESTPLATE || istack.getType() == LegacyUtil.GOLDEN_CESTPLATE) {
|
||||
getPlayer().getInventory().setChestplate(istack);
|
||||
} // Boots
|
||||
else if (istack.getType() == Material.LEATHER_BOOTS || istack.getType() == Material.CHAINMAIL_BOOTS || istack.getType() == Material.IRON_BOOTS
|
||||
|| istack.getType() == Material.DIAMOND_BOOTS || istack.getType() == LegacyUtil.GOLDEN_BOOTS) {
|
||||
getPlayer().getInventory().setBoots(istack);
|
||||
} else {
|
||||
getPlayer().getInventory().addItem(istack);
|
||||
}
|
||||
}
|
||||
// Leggings
|
||||
if (istack.getType() == Material.LEATHER_LEGGINGS || istack.getType() == Material.CHAINMAIL_LEGGINGS || istack.getType() == Material.IRON_LEGGINGS
|
||||
|| istack.getType() == Material.DIAMOND_LEGGINGS || istack.getType() == LegacyUtil.GOLDEN_LEGGINGS) {
|
||||
getPlayer().getInventory().setLeggings(istack);
|
||||
} // Helmet
|
||||
else if (istack.getType() == Material.LEATHER_HELMET || istack.getType() == Material.CHAINMAIL_HELMET || istack.getType() == Material.IRON_HELMET
|
||||
|| istack.getType() == Material.DIAMOND_HELMET || istack.getType() == LegacyUtil.GOLDEN_HELMET) {
|
||||
getPlayer().getInventory().setHelmet(istack);
|
||||
} // Chestplate
|
||||
else if (istack.getType() == Material.LEATHER_CHESTPLATE || istack.getType() == Material.CHAINMAIL_CHESTPLATE || istack.getType() == Material.IRON_CHESTPLATE
|
||||
|| istack.getType() == Material.DIAMOND_CHESTPLATE || istack.getType() == LegacyUtil.GOLDEN_CESTPLATE) {
|
||||
getPlayer().getInventory().setChestplate(istack);
|
||||
} // Boots
|
||||
else if (istack.getType() == Material.LEATHER_BOOTS || istack.getType() == Material.CHAINMAIL_BOOTS || istack.getType() == Material.IRON_BOOTS
|
||||
|| istack.getType() == Material.DIAMOND_BOOTS || istack.getType() == LegacyUtil.GOLDEN_BOOTS) {
|
||||
getPlayer().getInventory().setBoots(istack);
|
||||
} else {
|
||||
getPlayer().getInventory().addItem(istack);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -487,10 +486,12 @@ public class DGamePlayer extends DInstancePlayer {
|
||||
GameRuleProvider rules = game.getRules();
|
||||
delete();
|
||||
|
||||
if (finished) {
|
||||
reset(rules.getKeepInventoryOnFinish());
|
||||
} else {
|
||||
reset(rules.getKeepInventoryOnEscape());
|
||||
if (player.isOnline()) {
|
||||
if (finished) {
|
||||
reset(rules.getKeepInventoryOnFinish());
|
||||
} else {
|
||||
reset(rules.getKeepInventoryOnEscape());
|
||||
}
|
||||
}
|
||||
|
||||
// Permission bridge
|
||||
|
@ -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());
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
@ -363,19 +363,12 @@ 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 (!player.hasPlayedBefore() && config.isTutorialActivated()) {
|
||||
dPlayer.startTutorial();
|
||||
}
|
||||
|
||||
if (DGamePlayer.getByPlayer(player) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
dPlayer.startTutorial();
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
|
Loading…
Reference in New Issue
Block a user