Changed way to save and load Arenas.
This commit is contained in:
parent
6993fc1068
commit
1ae55cabf8
45
src/nl/Steffion/BlockHunt/Arena.java
Normal file
45
src/nl/Steffion/BlockHunt/Arena.java
Normal file
@ -0,0 +1,45 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Arena {
|
||||
public String arenaName;
|
||||
public LocationSerializable pos1;
|
||||
public LocationSerializable pos2;
|
||||
public int maxPlayers;
|
||||
public int minPlayers;
|
||||
public int amountSeekersOnStart;
|
||||
public int timeInLobbyUntilStart;
|
||||
public int waitingTimeSeeker;
|
||||
public int gameTime;
|
||||
public List<Player> playersInArena;
|
||||
|
||||
public Arena (String arenaName, LocationSerializable pos1,
|
||||
LocationSerializable pos2, int maxPlayers, int minPlayers,
|
||||
int amountSeekersOnStart, int timeInLobbyUntilStart,
|
||||
int waitingTimeSeeker, int gameTime, List<Player> playersInArena) {
|
||||
this.arenaName = arenaName;
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
this.maxPlayers = maxPlayers;
|
||||
this.minPlayers = minPlayers;
|
||||
this.amountSeekersOnStart = amountSeekersOnStart;
|
||||
this.timeInLobbyUntilStart = timeInLobbyUntilStart;
|
||||
this.waitingTimeSeeker = waitingTimeSeeker;
|
||||
this.gameTime = gameTime;
|
||||
this.playersInArena = playersInArena;
|
||||
}
|
||||
|
||||
public enum ArenaType {
|
||||
maxPlayers,
|
||||
minPlayers,
|
||||
amountSeekersOnStart,
|
||||
timeInLobbyUntilStart,
|
||||
waitingTimeSeeker,
|
||||
gameTime;
|
||||
}
|
||||
}
|
44
src/nl/Steffion/BlockHunt/ArenaHandler.java
Normal file
44
src/nl/Steffion/BlockHunt/ArenaHandler.java
Normal file
@ -0,0 +1,44 @@
|
||||
package nl.Steffion.BlockHunt;
|
||||
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM.CType;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ArenaHandler {
|
||||
public static void loadArenas() {
|
||||
W.arenaList.clear();
|
||||
for (String arenaName : W.arenas.getFile().getKeys(false)) {
|
||||
W.arenaList.add((Arena) W.arenas.getFile().get(arenaName));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(Arena arena, String message, Boolean tag,
|
||||
String... vars) {
|
||||
for (Player player : arena.playersInArena) {
|
||||
String pMessage = message.replaceAll("%player%", player.getName());
|
||||
player.sendMessage(MessageM.replaceAll(CType.TAG(tag) + pMessage,
|
||||
vars));
|
||||
}
|
||||
message = message.replaceAll("%player%", "Console");
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
MessageM.replaceAll(CType.TAG(tag) + message, vars));
|
||||
}
|
||||
|
||||
public static void sendFMessage(Arena arena, ConfigC location, Boolean tag,
|
||||
String... vars) {
|
||||
for (Player player : arena.playersInArena) {
|
||||
String pMessage = location.config.getFile()
|
||||
.get(location.getLocation()).toString()
|
||||
.replaceAll("%player%", player.getName());
|
||||
player.sendMessage(MessageM.replaceAll(CType.TAG(tag) + pMessage,
|
||||
vars));
|
||||
}
|
||||
String message = location.config.getFile().get(location.getLocation())
|
||||
.toString().replaceAll("%player%", "Console");
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
MessageM.replaceAll(CType.TAG(tag) + message, vars));
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import nl.Steffion.BlockHunt.Listeners.OnPlayerInteractEvent;
|
||||
import nl.Steffion.BlockHunt.Managers.CommandC;
|
||||
import nl.Steffion.BlockHunt.Managers.ConfigC;
|
||||
import nl.Steffion.BlockHunt.Managers.MessageM;
|
||||
import nl.Steffion.BlockHunt.Serializables.ArenaSerializable;
|
||||
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
@ -21,17 +22,20 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
public void onEnable() {
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
getServer().getPluginManager().registerEvents(new OnPlayerInteractEvent(),
|
||||
this);
|
||||
getServer().getPluginManager().registerEvents(
|
||||
new OnInventoryClickEvent(),
|
||||
this);
|
||||
new OnPlayerInteractEvent(), this);
|
||||
getServer().getPluginManager().registerEvents(
|
||||
new OnInventoryClickEvent(), this);
|
||||
|
||||
ConfigurationSerialization.registerClass(LocationSerializable.class,
|
||||
"Location");
|
||||
ConfigurationSerialization.registerClass(ArenaSerializable.class,
|
||||
"Arena");
|
||||
|
||||
W.newFiles();
|
||||
|
||||
ArenaHandler.loadArenas();
|
||||
|
||||
MessageM.sendFMessage(null, ConfigC.log_Enabled, true, "name-"
|
||||
+ W.pluginName, "version-" + W.pluginVersion, "autors-"
|
||||
+ W.pluginAutors);
|
||||
|
@ -1,11 +1,13 @@
|
||||
package nl.Steffion.BlockHunt.Commands;
|
||||
|
||||
import nl.Steffion.BlockHunt.ArenaHandler;
|
||||
import nl.Steffion.BlockHunt.W;
|
||||
import nl.Steffion.BlockHunt.Managers.CommandC;
|
||||
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;
|
||||
@ -26,22 +28,15 @@ public class CMDcreate extends DefaultCMD {
|
||||
&& W.pos2.get(player) != null) {
|
||||
if (W.pos1.get(player).getWorld()
|
||||
.equals(W.pos2.get(player).getWorld())) {
|
||||
W.arenas.getFile().set(args[1] + ".name", args[1]);
|
||||
W.arenas.getFile().set(args[1] + ".pos1",
|
||||
W.pos1.get(player));
|
||||
W.arenas.getFile().set(args[1] + ".pos2",
|
||||
W.pos2.get(player));
|
||||
W.arenas.getFile().set(args[1] + ".maxPlayers", 12);
|
||||
W.arenas.getFile().set(args[1] + ".minPlayers", 3);
|
||||
W.arenas.getFile().set(
|
||||
args[1] + ".amountSeekersOnStart", 1);
|
||||
W.arenas.getFile().set(
|
||||
args[1] + ".timeInLobbyUntilStart", 90);
|
||||
W.arenas.getFile().set(
|
||||
args[1] + ".waitingTimeSeeker", 20);
|
||||
W.arenas.getFile().set(args[1] + ".gameTime", 200);
|
||||
|
||||
ArenaSerializable arena = new ArenaSerializable(
|
||||
args[1], W.pos1.get(player),
|
||||
W.pos2.get(player), 12, 3, 1, 90, 20, 200,
|
||||
null);
|
||||
W.arenas.getFile().set(args[1], arena);
|
||||
W.arenas.save();
|
||||
ArenaHandler.loadArenas();
|
||||
|
||||
MessageM.sendFMessage(player,
|
||||
ConfigC.normal_createCreatedArena, true,
|
||||
"name-" + args[1]);
|
||||
|
@ -0,0 +1,55 @@
|
||||
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;
|
||||
|
||||
@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, List<Player> playersInArena) {
|
||||
super(arenaName, pos1, pos2, maxPlayers, minPlayers,
|
||||
amountSeekersOnStart, timeInLobbyUntilStart, waitingTimeSeeker,
|
||||
gameTime, playersInArena);
|
||||
}
|
||||
|
||||
@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);
|
||||
return map;
|
||||
}
|
||||
|
||||
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), new ArrayList<Player>());
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ public class W {
|
||||
public static ConfigM config = new ConfigM("config", "");
|
||||
public static ConfigM messages = new ConfigM("messages", "");
|
||||
public static ConfigM arenas = new ConfigM("arenas", "");
|
||||
public static ArrayList<Arena> arenaList = new ArrayList<Arena>();
|
||||
|
||||
public static void newFiles() {
|
||||
ConfigM.setDefaults();
|
||||
|
Loading…
x
Reference in New Issue
Block a user