Removed LocationSerializable. Was only half implemented and broke old configs anyway
This commit is contained in:
parent
1a84072f75
commit
dc3b9e0563
@ -5,9 +5,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,8 +16,8 @@ import org.bukkit.scoreboard.Scoreboard;
|
||||
@SerializableAs("BlockHuntArena")
|
||||
public class Arena implements ConfigurationSerializable {
|
||||
public String arenaName;
|
||||
public LocationSerializable pos1;
|
||||
public LocationSerializable pos2;
|
||||
public Location pos1;
|
||||
public Location pos2;
|
||||
public int maxPlayers;
|
||||
public int minPlayers;
|
||||
public int amountSeekersOnStart;
|
||||
@ -33,10 +32,10 @@ public class Arena implements ConfigurationSerializable {
|
||||
public boolean seekersTakeFallDamage;
|
||||
public boolean hidersTakeFallDamage;
|
||||
public ArrayList<ItemStack> disguiseBlocks;
|
||||
public LocationSerializable lobbyWarp;
|
||||
public LocationSerializable hidersWarp;
|
||||
public LocationSerializable seekersWarp;
|
||||
public LocationSerializable spawnWarp;
|
||||
public Location lobbyWarp;
|
||||
public Location hidersWarp;
|
||||
public Location seekersWarp;
|
||||
public Location spawnWarp;
|
||||
public List<String> seekersWinCommands;
|
||||
public List<String> hidersWinCommands;
|
||||
public List<String> allowedCommands;
|
||||
@ -50,10 +49,10 @@ public class Arena implements ConfigurationSerializable {
|
||||
public List<Player> seekers;
|
||||
public Scoreboard scoreboard;
|
||||
|
||||
public Arena(String arenaName, LocationSerializable pos1, LocationSerializable pos2, int maxPlayers, int minPlayers, int amountSeekersOnStart,
|
||||
public Arena(String arenaName, Location pos1, Location pos2, int maxPlayers, int minPlayers, int amountSeekersOnStart,
|
||||
int timeInLobbyUntilStart, int waitingTimeSeeker, int gameTime, int timeUntilHidersSword, int blockAnnouncerTime,
|
||||
boolean seekersCanHurtSeekers, boolean hidersCanHurtSeekers, boolean hidersCanHurtHiders, boolean seekersTakeFallDamage, boolean hidersTakeFallDamage,
|
||||
ArrayList<ItemStack> disguiseBlocks, LocationSerializable lobbyWarp, LocationSerializable hidersWarp, LocationSerializable seekersWarp, LocationSerializable spawnWarp,
|
||||
ArrayList<ItemStack> disguiseBlocks, Location lobbyWarp, Location hidersWarp, Location seekersWarp, Location spawnWarp,
|
||||
List<String> seekersWinCommands, List<String> hidersWinCommands, List<String> allowedCommands, int seekersTokenWin, int hidersTokenWin, int killTokens,
|
||||
List<Player> playersInArena, ArenaState gameState, int timer, List<Player> seekers, Scoreboard scoreboard) {
|
||||
this.arenaName = arenaName;
|
||||
@ -143,13 +142,13 @@ public class Arena implements ConfigurationSerializable {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Arena deserialize(Map<String, Object> map) {
|
||||
LocationSerializable loc = new LocationSerializable(Bukkit.getWorld("world"), 0, 0, 0, 0, 0);
|
||||
return new Arena((String) map.getOrDefault("arenaName", "UNKNOWN_NAME"), (LocationSerializable) map.getOrDefault("pos1", loc), (LocationSerializable) map.getOrDefault( "pos2", loc),
|
||||
Location loc = new Location(Bukkit.getWorld("world"), 0, 0, 0, 0, 0);
|
||||
return new Arena((String) map.getOrDefault("arenaName", "UNKNOWN_NAME"), (Location) map.getOrDefault("pos1", loc), (Location) map.getOrDefault( "pos2", loc),
|
||||
(Integer) map.getOrDefault( "maxPlayers", 12), (Integer) map.getOrDefault( "minPlayers", 3), (Integer) map.getOrDefault( "amountSeekersOnStart", 1), (Integer) map.getOrDefault( "timeInLobbyUntilStart", 90),
|
||||
(Integer) map.getOrDefault( "waitingTimeSeeker", 20), (Integer) map.getOrDefault( "gameTime", 200), (Integer) map.getOrDefault( "timeUntilHidersSword", 30),(Integer) map.getOrDefault( "blockAnnouncerTime", 45),
|
||||
(Boolean) map.getOrDefault( "seekersCanHurtSeekers", false),(Boolean) map.getOrDefault( "hidersCanHurtSeekers", false),(Boolean) map.getOrDefault( "hidersCanHurtHiders", false),(Boolean) map.getOrDefault( "seekersTakeFallDamage", false),(Boolean) map.getOrDefault( "hidersTakeFallDamage", false),
|
||||
(ArrayList<ItemStack>) map.getOrDefault( "disguiseBlocks", new ArrayList<ItemStack>()),(LocationSerializable) map.getOrDefault( "lobbyWarp", loc), (LocationSerializable) map.getOrDefault( "hidersWarp", loc), (LocationSerializable) map.getOrDefault( "seekersWarp", loc),
|
||||
(LocationSerializable) map.getOrDefault( "spawnWarp", loc), (ArrayList<String>) map.getOrDefault( "seekersWinCommands", new ArrayList<String>()),
|
||||
(ArrayList<ItemStack>) map.getOrDefault( "disguiseBlocks", new ArrayList<ItemStack>()),(Location) map.getOrDefault( "lobbyWarp", loc), (Location) map.getOrDefault( "hidersWarp", loc), (Location) map.getOrDefault( "seekersWarp", loc),
|
||||
(Location) map.getOrDefault( "spawnWarp", loc), (ArrayList<String>) map.getOrDefault( "seekersWinCommands", new ArrayList<String>()),
|
||||
(ArrayList<String>) map.getOrDefault("hidersWinCommands", new ArrayList<String>()), (ArrayList<String>) map.getOrDefault( "allowedCommands", new ArrayList<String>()),
|
||||
(Integer) map.getOrDefault( "seekersTokenWin", 10), (Integer) map.getOrDefault( "hidersTokenWin", 50), (Integer) map.getOrDefault( "killTokens", 8), new ArrayList<>(),
|
||||
ArenaState.WAITING, 0, new ArrayList<>(), Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
|
@ -39,7 +39,6 @@ import nl.Steffion.BlockHunt.Managers.CommandManager;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigManager;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
import nl.Steffion.BlockHunt.Managers.PermissionsManager;
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
@ -132,7 +131,6 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerQuitEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(new OnSignChangeEvent(), this);
|
||||
|
||||
ConfigurationSerialization.registerClass(LocationSerializable.class, "BlockHuntLocation");
|
||||
ConfigurationSerialization.registerClass(Arena.class, "BlockHuntArena");
|
||||
|
||||
pdfFile = getDescription();
|
||||
|
@ -7,7 +7,6 @@ import nl.Steffion.BlockHunt.Arena.ArenaState;
|
||||
import nl.Steffion.BlockHunt.MemoryStorage;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -22,7 +21,7 @@ public class CMDcreate extends DefaultCMD {
|
||||
} else {
|
||||
if (MemoryStorage.pos1.get(player) != null && MemoryStorage.pos2.get(player) != null) {
|
||||
if (MemoryStorage.pos1.get(player).getWorld().equals(MemoryStorage.pos2.get(player).getWorld())) {
|
||||
Arena arena = new Arena(args[1], new LocationSerializable(MemoryStorage.pos1.get(player)), new LocationSerializable(MemoryStorage.pos2.get(player)), 12, 3, 1, 50, 20, 300, 30, 45, false, false, false, false, false, new ArrayList<>(), null, null, null,
|
||||
Arena arena = new Arena(args[1], MemoryStorage.pos1.get(player), MemoryStorage.pos2.get(player), 12, 3, 1, 50, 20, 300, 30, 45, false, false, false, false, false, new ArrayList<>(), null, null, null,
|
||||
null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), 10, 50, 8, new ArrayList<>(), ArenaState.WAITING,
|
||||
0, new ArrayList<>(), Bukkit.getScoreboardManager().getNewScoreboard());
|
||||
MemoryStorage.arenas.getFile().set(args[1], arena);
|
||||
|
@ -4,7 +4,6 @@ import nl.Steffion.BlockHunt.*;
|
||||
import nl.Steffion.BlockHunt.MemoryStorage;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -29,19 +28,19 @@ public class CMDsetwarp extends DefaultCMD {
|
||||
if (arena != null) {
|
||||
Location loc = player.getLocation();
|
||||
if (warpname.equalsIgnoreCase("lobby")) {
|
||||
arena.lobbyWarp = new LocationSerializable(loc);
|
||||
arena.lobbyWarp = loc;
|
||||
save(arena);
|
||||
MessageManager.sendFMessage(player, ConfigC.normal_setwarpWarpSet, "warp-" + warpname);
|
||||
} else if (warpname.equalsIgnoreCase("hiders")) {
|
||||
arena.hidersWarp = new LocationSerializable(loc);
|
||||
arena.hidersWarp = loc;
|
||||
save(arena);
|
||||
MessageManager.sendFMessage(player, ConfigC.normal_setwarpWarpSet, "warp-" + warpname);
|
||||
} else if (warpname.equalsIgnoreCase("seekers")) {
|
||||
arena.seekersWarp = new LocationSerializable(loc);
|
||||
arena.seekersWarp = loc;
|
||||
save(arena);
|
||||
MessageManager.sendFMessage(player, ConfigC.normal_setwarpWarpSet, "warp-" + warpname);
|
||||
} else if (warpname.equalsIgnoreCase("spawn")) {
|
||||
arena.spawnWarp = new LocationSerializable(loc);
|
||||
arena.spawnWarp = loc;
|
||||
save(arena);
|
||||
MessageManager.sendFMessage(player, ConfigC.normal_setwarpWarpSet, "warp-" + warpname);
|
||||
} else {
|
||||
|
@ -1,66 +0,0 @@
|
||||
package nl.Steffion.BlockHunt.Serializables;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import nl.Steffion.BlockHunt.Managers.MessageManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
|
||||
/**
|
||||
* No longer required as a location is already serializable
|
||||
*/
|
||||
|
||||
@SerializableAs("BlockHuntLocation")
|
||||
@Deprecated
|
||||
public class LocationSerializable extends Location {
|
||||
public LocationSerializable(World world, double x, double y, double z, float yaw, float pitch) {
|
||||
super(world, x, y, z, yaw, pitch);
|
||||
}
|
||||
|
||||
public LocationSerializable(Location loc) {
|
||||
super(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof LocationSerializable || o instanceof Location) {
|
||||
Location loc = (Location) o;
|
||||
return loc.getWorld().getName().equals(getWorld().getName()) && loc.getX() == getX() && loc.getY() == getY() && loc.getZ() == getZ()
|
||||
&& loc.getYaw() == getYaw() && loc.getPitch() == getPitch();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("world", getWorld().getName());
|
||||
map.put("x", getX());
|
||||
map.put("y", getY());
|
||||
map.put("z", getZ());
|
||||
if (getYaw() != 0D)
|
||||
map.put("yaw", getYaw());
|
||||
if (getPitch() != 0D)
|
||||
map.put("pitch", getPitch());
|
||||
return map;
|
||||
}
|
||||
|
||||
public static LocationSerializable deserialize(Map<String, Object> map) {
|
||||
World w = Bukkit.getWorld((String)map.getOrDefault( "w", ""));
|
||||
if (w == null) {
|
||||
MessageManager.sendMessage(null, "%EError deserializing Location - world not found! (%A%w%%E)", "w-" + w);
|
||||
return null;
|
||||
}
|
||||
return new LocationSerializable(w, (Double) map.getOrDefault( "x", 0D), (Double) map.getOrDefault( "y", 0D), (Double) map.getOrDefault( "z", 0D), ((Double) map.getOrDefault( "a", 0D)).floatValue(),
|
||||
((Double) map.getOrDefault( "p", 0D)).floatValue());
|
||||
}
|
||||
|
||||
public static Location getLocation(LocationSerializable ser){
|
||||
return new Location(ser.getWorld(),ser.getX(),ser.getY(),ser.getZ(),ser.getYaw(),ser.getPitch());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user