~ Combined ArenaSerializable with the Arena class. (Less code!)

This commit is contained in:
Steffion 2013-08-10 14:46:33 +02:00
parent 78673d5da4
commit 8c22316b78
3 changed files with 57 additions and 84 deletions

View File

@ -1,14 +1,21 @@
package nl.Steffion.BlockHunt;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import nl.Steffion.BlockHunt.Serializables.M;
import org.bukkit.Bukkit;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class Arena {
@SerializableAs("Arena")
public class Arena implements ConfigurationSerializable {
public String arenaName;
public LocationSerializable pos1;
public LocationSerializable pos2;
@ -72,4 +79,49 @@ public class Arena {
public enum ArenaState {
WAITING, STARTING, INGAME, RESTARTING, DISABLED;
}
@Override
public Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("arenaName", arenaName);
map.put("pos1", pos1);
map.put("pos2", pos2);
map.put("maxPlayers", maxPlayers);
map.put("minPlayers", minPlayers);
map.put("amountSeekersOnStart", amountSeekersOnStart);
map.put("timeInLobbyUntilStart", timeInLobbyUntilStart);
map.put("waitingTimeSeeker", waitingTimeSeeker);
map.put("gameTime", gameTime);
map.put("disguiseBlocks", disguiseBlocks);
map.put("lobbyWarp", lobbyWarp);
map.put("hidersWarp", hidersWarp);
map.put("seekersWarp", seekersWarp);
map.put("seekersWinCommans", seekersWinCommands);
map.put("hidersWinCommands", hidersWinCommands);
return map;
}
@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) M.g(map, "arenaName", "UNKNOWN_NAME"),
(LocationSerializable) M.g(map, "pos1", loc),
(LocationSerializable) M.g(map, "pos2", loc), (Integer) M.g(
map, "maxPlayers", 12), (Integer) M.g(map,
"minPlayers", 3), (Integer) M.g(map,
"amountSeekersOnStart", 1), (Integer) M.g(map,
"timeInLobbyUntilStart", 90), (Integer) M.g(map,
"waitingTimeSeeker", 20), (Integer) M.g(map,
"gameTime", 200), (ArrayList<ItemStack>) M.g(map,
"disguiseBlocks", new ArrayList<ItemStack>()),
(LocationSerializable) M.g(map, "lobbyWarp", loc),
(LocationSerializable) M.g(map, "hidersWarp", loc),
(LocationSerializable) M.g(map, "seekersWarp", loc),
(ArrayList<String>) M.g(map, "seekersWinCommands",
new ArrayList<String>()), (ArrayList<String>) M.g(map,
"hidersWinCommands", new ArrayList<String>()),
new ArrayList<Player>(), ArenaState.WAITING, 0,
new ArrayList<Player>());
}
}

View File

@ -2,6 +2,7 @@ package nl.Steffion.BlockHunt.Commands;
import java.util.ArrayList;
import nl.Steffion.BlockHunt.Arena;
import nl.Steffion.BlockHunt.ArenaHandler;
import nl.Steffion.BlockHunt.W;
import nl.Steffion.BlockHunt.Managers.CommandC;
@ -9,7 +10,6 @@ import nl.Steffion.BlockHunt.Managers.ConfigC;
import nl.Steffion.BlockHunt.Managers.MessageM;
import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import nl.Steffion.BlockHunt.Serializables.ArenaSerializable;
import org.bukkit.command.Command;
import org.bukkit.entity.Player;
@ -31,9 +31,9 @@ public class CMDcreate extends DefaultCMD {
&& W.pos2.get(player) != null) {
if (W.pos1.get(player).getWorld()
.equals(W.pos2.get(player).getWorld())) {
ArenaSerializable arena = new ArenaSerializable(
args[1], W.pos1.get(player),
W.pos2.get(player), 12, 3, 1, 90, 20, 300,
Arena arena = new Arena(args[1],
W.pos1.get(player), W.pos2.get(player), 12,
3, 1, 90, 20, 300,
new ArrayList<ItemStack>(), null, null,
null, new ArrayList<String>(),
new ArrayList<String>(), null, null, 0,

View File

@ -1,79 +0,0 @@
package nl.Steffion.BlockHunt.Serializables;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import nl.Steffion.BlockHunt.Arena;
import org.bukkit.Bukkit;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@SerializableAs("Arena")
public class ArenaSerializable extends Arena implements
ConfigurationSerializable {
public ArenaSerializable (String arenaName, LocationSerializable pos1,
LocationSerializable pos2, int maxPlayers, int minPlayers,
int amountSeekersOnStart, int timeInLobbyUntilStart,
int waitingTimeSeeker, int gameTime,
ArrayList<ItemStack> disguiseBlocks,
LocationSerializable lobbyWarp, LocationSerializable hidersWarp,
LocationSerializable seekersWarp, List<String> seekersWinCommands,
List<String> hidersWinCommands, List<Player> playersInArena,
ArenaState gameState, int timer, List<Player> seekers) {
super(arenaName, pos1, pos2, maxPlayers, minPlayers,
amountSeekersOnStart, timeInLobbyUntilStart, waitingTimeSeeker,
gameTime, disguiseBlocks, lobbyWarp, hidersWarp, seekersWarp,
seekersWinCommands, hidersWinCommands, playersInArena,
gameState, timer, seekers);
}
@Override
public Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("arenaName", arenaName);
map.put("pos1", pos1);
map.put("pos2", pos2);
map.put("maxPlayers", maxPlayers);
map.put("minPlayers", minPlayers);
map.put("amountSeekersOnStart", amountSeekersOnStart);
map.put("timeInLobbyUntilStart", timeInLobbyUntilStart);
map.put("waitingTimeSeeker", waitingTimeSeeker);
map.put("gameTime", gameTime);
map.put("disguiseBlocks", disguiseBlocks);
map.put("lobbyWarp", lobbyWarp);
map.put("hidersWarp", hidersWarp);
map.put("seekersWarp", seekersWarp);
map.put("seekersWinCommans", seekersWinCommands);
map.put("hidersWinCommands", hidersWinCommands);
return map;
}
@SuppressWarnings("unchecked")
public static ArenaSerializable deserialize(Map<String, Object> map) {
LocationSerializable loc = new LocationSerializable(
Bukkit.getWorld("world"), 0, 0, 0, 0, 0);
return new ArenaSerializable((String) M.g(map, "arenaName",
"UNKNOWN_NAME"), (LocationSerializable) M.g(map, "pos1", loc),
(LocationSerializable) M.g(map, "pos2", loc), (Integer) M.g(
map, "maxPlayers", 12), (Integer) M.g(map,
"minPlayers", 3), (Integer) M.g(map,
"amountSeekersOnStart", 1), (Integer) M.g(map,
"timeInLobbyUntilStart", 90), (Integer) M.g(map,
"waitingTimeSeeker", 20), (Integer) M.g(map,
"gameTime", 200), (ArrayList<ItemStack>) M.g(map,
"disguiseBlocks", new ArrayList<ItemStack>()),
(LocationSerializable) M.g(map, "lobbyWarp", loc),
(LocationSerializable) M.g(map, "hidersWarp", loc),
(LocationSerializable) M.g(map, "seekersWarp", loc),
(ArrayList<String>) M.g(map, "seekersWinCommands",
new ArrayList<String>()), (ArrayList<String>) M.g(map,
"hidersWinCommands", new ArrayList<String>()),
new ArrayList<Player>(), ArenaState.WAITING, 0,
new ArrayList<Player>());
}
}