mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-05 02:09:48 +01:00
Save Active Potion Effects
This commit is contained in:
parent
7d7f30f3e8
commit
1f80c8bed9
@ -14,6 +14,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.getspout.spoutapi.Spout;
|
import org.getspout.spoutapi.Spout;
|
||||||
@ -57,7 +58,7 @@ public class DPlayer {
|
|||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
this.savePlayer = new DSavePlayer(player.getName(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLevel(),
|
this.savePlayer = new DSavePlayer(player.getName(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getLevel(),
|
||||||
player.getTotalExperience(), player.getHealth(), player.getFoodLevel(), player.getFireTicks(), player.getGameMode());
|
player.getTotalExperience(), player.getHealth(), player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects());
|
||||||
|
|
||||||
this.player.teleport(teleport);
|
this.player.teleport(teleport);
|
||||||
this.player.getInventory().clear();
|
this.player.getInventory().clear();
|
||||||
@ -66,6 +67,9 @@ public class DPlayer {
|
|||||||
this.player.setLevel(0);
|
this.player.setLevel(0);
|
||||||
this.player.setHealth(20);
|
this.player.setHealth(20);
|
||||||
this.player.setFoodLevel(20);
|
this.player.setFoodLevel(20);
|
||||||
|
for (PotionEffect effect : this.player.getActivePotionEffects()) {
|
||||||
|
this.player.removePotionEffect(effect.getType());
|
||||||
|
}
|
||||||
this.isEditing = isEditing;
|
this.isEditing = isEditing;
|
||||||
|
|
||||||
if (isEditing)
|
if (isEditing)
|
||||||
|
@ -3,6 +3,7 @@ package com.dre.dungeonsxl;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
@ -11,6 +12,7 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class DSavePlayer {
|
public class DSavePlayer {
|
||||||
@ -30,9 +32,10 @@ public class DSavePlayer {
|
|||||||
private int oldFoodLevel;
|
private int oldFoodLevel;
|
||||||
private int oldFireTicks;
|
private int oldFireTicks;
|
||||||
private GameMode oldGamemode;
|
private GameMode oldGamemode;
|
||||||
|
private Collection<PotionEffect> oldPotionEffects;
|
||||||
|
|
||||||
public DSavePlayer(String playerName, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, int oldLvl, int oldExp, int oldHealth, int oldFoodLevel, int oldFireTicks,
|
public DSavePlayer(String playerName, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, int oldLvl, int oldExp, int oldHealth, int oldFoodLevel, int oldFireTicks,
|
||||||
GameMode oldGamemode) {
|
GameMode oldGamemode, Collection<PotionEffect> oldPotionEffects) {
|
||||||
savePlayers.add(this);
|
savePlayers.add(this);
|
||||||
|
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
@ -46,6 +49,7 @@ public class DSavePlayer {
|
|||||||
this.oldGamemode = oldGamemode;
|
this.oldGamemode = oldGamemode;
|
||||||
this.oldLvl = oldLvl;
|
this.oldLvl = oldLvl;
|
||||||
this.oldFireTicks = oldFireTicks;
|
this.oldFireTicks = oldFireTicks;
|
||||||
|
this.oldPotionEffects = oldPotionEffects;
|
||||||
|
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
@ -63,6 +67,10 @@ public class DSavePlayer {
|
|||||||
onlinePlayer.setFoodLevel(this.oldFoodLevel);
|
onlinePlayer.setFoodLevel(this.oldFoodLevel);
|
||||||
onlinePlayer.setGameMode(this.oldGamemode);
|
onlinePlayer.setGameMode(this.oldGamemode);
|
||||||
onlinePlayer.setFireTicks(this.oldFireTicks);
|
onlinePlayer.setFireTicks(this.oldFireTicks);
|
||||||
|
for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) {
|
||||||
|
onlinePlayer.removePotionEffect(effect.getType());
|
||||||
|
}
|
||||||
|
onlinePlayer.addPotionEffects(this.oldPotionEffects);
|
||||||
} else {
|
} else {
|
||||||
/* Player is offline */
|
/* Player is offline */
|
||||||
Player offlinePlayer = p.getOfflinePlayer(this.playerName, this.oldLocation);
|
Player offlinePlayer = p.getOfflinePlayer(this.playerName, this.oldLocation);
|
||||||
@ -75,6 +83,11 @@ public class DSavePlayer {
|
|||||||
offlinePlayer.setFoodLevel(this.oldFoodLevel);
|
offlinePlayer.setFoodLevel(this.oldFoodLevel);
|
||||||
offlinePlayer.setGameMode(this.oldGamemode);
|
offlinePlayer.setGameMode(this.oldGamemode);
|
||||||
offlinePlayer.setFireTicks(this.oldFireTicks);
|
offlinePlayer.setFireTicks(this.oldFireTicks);
|
||||||
|
for (PotionEffect effect : offlinePlayer.getActivePotionEffects()) {
|
||||||
|
offlinePlayer.removePotionEffect(effect.getType());
|
||||||
|
}
|
||||||
|
//causes NP
|
||||||
|
//offlinePlayer.addPotionEffects(this.oldPotionEffects);
|
||||||
|
|
||||||
offlinePlayer.saveData();
|
offlinePlayer.saveData();
|
||||||
}
|
}
|
||||||
@ -102,6 +115,7 @@ public class DSavePlayer {
|
|||||||
configFile.set(savePlayer.playerName + ".oldLocation.yaw", savePlayer.oldLocation.getYaw());
|
configFile.set(savePlayer.playerName + ".oldLocation.yaw", savePlayer.oldLocation.getYaw());
|
||||||
configFile.set(savePlayer.playerName + ".oldLocation.pitch", savePlayer.oldLocation.getPitch());
|
configFile.set(savePlayer.playerName + ".oldLocation.pitch", savePlayer.oldLocation.getPitch());
|
||||||
configFile.set(savePlayer.playerName + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName());
|
configFile.set(savePlayer.playerName + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName());
|
||||||
|
configFile.set(savePlayer.playerName + ".oldPotionEffects", savePlayer.oldPotionEffects);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -131,6 +145,7 @@ public class DSavePlayer {
|
|||||||
int oldFoodLevel = configFile.getInt(playerName + ".oldFoodLevel");
|
int oldFoodLevel = configFile.getInt(playerName + ".oldFoodLevel");
|
||||||
int oldFireTicks = configFile.getInt(playerName + ".oldFireTicks");
|
int oldFireTicks = configFile.getInt(playerName + ".oldFireTicks");
|
||||||
GameMode oldGamemode = GameMode.getByValue(configFile.getInt(playerName + ".oldGamemode"));
|
GameMode oldGamemode = GameMode.getByValue(configFile.getInt(playerName + ".oldGamemode"));
|
||||||
|
Collection<PotionEffect> oldPotionEffects = (Collection<PotionEffect>) configFile.get(playerName + ".oldPotionEffects");
|
||||||
|
|
||||||
// Location
|
// Location
|
||||||
World world = p.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world"));
|
World world = p.getServer().getWorld(configFile.getString(playerName + ".oldLocation.world"));
|
||||||
@ -142,7 +157,7 @@ public class DSavePlayer {
|
|||||||
+ ".oldLocation.z"), configFile.getInt(playerName + ".oldLocation.yaw"), configFile.getInt(playerName + ".oldLocation.pitch"));
|
+ ".oldLocation.z"), configFile.getInt(playerName + ".oldLocation.yaw"), configFile.getInt(playerName + ".oldLocation.pitch"));
|
||||||
|
|
||||||
// Create Player
|
// Create Player
|
||||||
DSavePlayer savePlayer = new DSavePlayer(playerName, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode);
|
DSavePlayer savePlayer = new DSavePlayer(playerName, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode, oldPotionEffects);
|
||||||
savePlayer.reset();
|
savePlayer.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user