diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0c9e1c8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,27 @@
+*.class
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+/target/
+/bin/
+
+# eclipse
+.settings
+*.project
+*.classpath
+
+#IntelliJ
+.idea
+
+# maven
+dependency-reduced-pom.xml
+ChallengesJoinEntities.iml
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 8671173..d387345 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
de.fanta.challenges
ChallengesJoinEntities
- 1.16.4-DEV
+ 1.18-rc3-DEV
UTF-8
UTF-8
@@ -21,9 +21,9 @@
- com.destroystokyo.paper
- paper
- 1.16.4-R0.1-SNAPSHOT
+ io.papermc.paper
+ paper-api
+ 1.18-rc3-R0.1-SNAPSHOT
provided
@@ -41,7 +41,7 @@
de.fanta.challenges
Challenges
- 1.16.1.2-DEV
+ 1.18-rc3-DEV
provided
@@ -53,7 +53,19 @@
commons-io
commons-io
- 2.6
+ 2.11.0
+
+
+ de.cubeside.nmsutils
+ nmsutils-core
+ 0.0.1-SNAPSHOT
+ provided
+
+
+ de.cubeside.nmsutils
+ nmsutils-v1_17_R1_1
+ 0.0.1-SNAPSHOT
+ provided
@@ -90,7 +102,15 @@
maven-compiler-plugin
3.8.1
- 11
+ 17
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 16
+ 16
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java
index aef27bb..2724d76 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesGlobalDataHelper.java
@@ -31,24 +31,20 @@
protected void handleMessage(ChallengeMessageType challengeMessageType, GlobalServer globalServer, DataInputStream data) throws IOException {
String serverName = data.readUTF();
switch (challengeMessageType) {
- case TIMER:
+ case TIMER -> {
boolean running = data.readBoolean();
plugin.updateTimerStatus(serverName, running);
- break;
-
- case SERVER_STATUS:
+ }
+ case SERVER_STATUS -> {
boolean online = data.readBoolean();
plugin.updateServerStatus(serverName, online);
- break;
-
- case PLAYER_COUNT: {
+ }
+ case PLAYER_COUNT -> {
int count = data.readInt();
int maxPlayers = data.readInt();
plugin.updatePlayerCount(serverName, count, maxPlayers);
- break;
}
-
- case INITIAL_DATA_REQUEST: {
+ case INITIAL_DATA_REQUEST -> {
if (Bukkit.getPluginManager().getPlugin("Challenges") != null) {
Challenges challenges = (Challenges) Bukkit.getPluginManager().getPlugin("Challenges");
boolean timerRunning = challenges.getTimer().isRunning();
@@ -57,20 +53,15 @@
sendInitialData(serverName, timerRunning, playerCount, maxPlayers);
}
- break;
}
-
- case INITIAL_DATA: {
+ case INITIAL_DATA -> {
boolean timerRunning = data.readBoolean();
int playerCount = data.readInt();
int maxPlayers = data.readInt();
plugin.updateTimerStatus(serverName, timerRunning);
plugin.updatePlayerCount(serverName, playerCount, maxPlayers);
- break;
}
-
- default:
- throw new UnsupportedOperationException();
+ default -> throw new UnsupportedOperationException();
}
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
index 1787515..3638a14 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
@@ -1,7 +1,9 @@
package de.fanta.challengesjoinentities;
-import de.fanta.challengesjoinentities.JoinEntityData.ServerStatus;
-import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureLoadCommand;
+import de.cubeside.nmsutils.NMSUtils;
+import de.fanta.challengesjoinentities.adventure.AdventureMapsConfig;
+import de.fanta.challengesjoinentities.adventure.CategoriesConfig;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.*;
import de.fanta.challengesjoinentities.commands.ChallengesCommand.ChallengesloadCommand;
import de.fanta.challengesjoinentities.commands.PiglinCommand.AddEntityCommand;
import de.fanta.challengesjoinentities.commands.PiglinCommand.RemoveEntityCommand;
@@ -10,34 +12,40 @@
import de.fanta.challengesjoinentities.listeners.EntityListener;
import de.fanta.challengesjoinentities.listeners.PlayerListener;
import de.iani.cubesideutils.bukkit.commands.CommandRouter;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextComponent;
+import net.kyori.adventure.text.format.TextColor;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
-import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPiglin;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Piglin;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.util.Consumer;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
+import java.util.*;
public class ChallengesJoinEntities extends JavaPlugin {
- public static final String PREFIX = ChatColor.of("#455aad") + "[" + ChatColor.of("#1FFF00") + "Lobby" + ChatColor.of("#455aad") + "]";
+ public static final String PREFIX = ChatUtil.BLUE + "[" + ChatUtil.GREEN + "Lobby" + ChatUtil.BLUE + "]";
+ private static final TextColor BRACKETS = TextColor.fromHexString("#87f7ea");
+
+ public static final TextComponent PREFIX_COMPONENT = Component.text("[", BRACKETS).append(Component.text("Lobby", TextColor.fromHexString("#52ff9d"))).append(Component.text("] ", BRACKETS));
+
+ private static ChallengesJoinEntities plugin;
private Config config;
private ChallengesGlobalDataHelper globalDataHelper;
private Map entityData;
private Map entityServerMapping;
private Set availableServers;
+ private CategoriesConfig categoriesConfig;
+ private AdventureMapsConfig adventureMapsConfig;
+ public NMSUtils nmsUtils;
+
public ChallengesJoinEntities() {
this.entityData = new HashMap<>();
@@ -47,8 +55,11 @@
@Override
public void onEnable() {
+ plugin = this;
+ nmsUtils = getServer().getServicesManager().load(NMSUtils.class);
this.globalDataHelper = new ChallengesGlobalDataHelper(this);
this.config = new Config(this);
+ loadCategoriesAndMaps();
if (Bukkit.getPluginManager().getPlugin("Challenges") != null) { // Challenge server -> listen on Challenge events
Bukkit.getPluginManager().registerEvents(new ChallengesEventListener(this), this);
@@ -64,6 +75,11 @@
CommandRouter adventurerouter = new CommandRouter(getCommand("adventure"));
adventurerouter.addCommandMapping(new AdventureLoadCommand(this), "load");
+ adventurerouter.addCommandMapping(new AdventureAddCategoryCommand(this), "addcategory");
+ adventurerouter.addCommandMapping(new AdventureAddMapCommand(this), "addmap");
+ adventurerouter.addCommandMapping(new AdventureMapsCommand(this), "maps");
+ adventurerouter.addCommandMapping(new AdventureTestMapCommand(this), "testmap");
+ adventurerouter.addCommandMapping(new ChallengesRemovePlayerServer(this), "removeplayerfromserver");
}
Bukkit.getPluginManager().registerEvents(new EntityListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
@@ -72,6 +88,7 @@
@Override
public void onDisable() {
+ saveCategoriesAndMaps();
getPluginConfig().getChallengeServers().forEach(Server::despawnPiglin);
getPluginConfig().getAdventureServers().forEach(Server::despawnPiglin);
}
@@ -84,19 +101,11 @@
if (entityData.containsKey(serverName)) {
despawnPiglin(entityData.get(serverName).getEntityUUID(), serverName);
}
-
- CraftPiglin piglin = (CraftPiglin) location.getWorld().spawnEntity(location, EntityType.PIGLIN, CreatureSpawnEvent.SpawnReason.CUSTOM, new Consumer() {
- @Override
- public void accept(Entity t) {
- ((Piglin) t).getEquipment().clear();
- }
- });
- piglin.setAware(false);
+ Piglin piglin = (Piglin) location.getWorld().spawnEntity(location, EntityType.PIGLIN, CreatureSpawnEvent.SpawnReason.CUSTOM, t -> ((Piglin) t).getEquipment().clear());
+ piglin.setAI(false);
piglin.setSilent(true);
piglin.setRemoveWhenFarAway(false);
piglin.setCustomNameVisible(true);
- piglin.setMaxHealth(200.0);
- piglin.setHealth(199.0);
addPiglin(piglin.getUniqueId(), serverName, gpLocationName, serverDisplayName, saveToConfig);
globalDataHelper.requestInitialData(serverName);
@@ -117,7 +126,7 @@
}
public void addPiglin(UUID piglinUUID, String serverName, String gpLocationName, String serverDisplayName, boolean saveToConfig) {
- JoinEntityData entityData = new JoinEntityData(serverName, piglinUUID, gpLocationName, serverDisplayName, ServerStatus.OFFLINE, 0, 0);
+ JoinEntityData entityData = new JoinEntityData(serverName, piglinUUID, gpLocationName, serverDisplayName, JoinEntityData.ServerStatus.OFFLINE, 0, 0);
this.entityData.put(serverName, entityData);
this.entityServerMapping.put(piglinUUID, serverName);
@@ -138,7 +147,7 @@
public void updateTimerStatus(String serverName, boolean running) {
JoinEntityData data = entityData.get(serverName);
if (data != null) {
- data.setServerStatus(running ? ServerStatus.RUNNING : ServerStatus.ONLINE);
+ data.setServerStatus(running ? JoinEntityData.ServerStatus.RUNNING : JoinEntityData.ServerStatus.ONLINE);
updatePiglinCustomName(serverName);
updatePiglinBehaviour(serverName);
@@ -149,7 +158,7 @@
JoinEntityData data = entityData.get(serverName);
if (data != null) {
- data.setServerStatus(online ? ServerStatus.ONLINE : ServerStatus.OFFLINE);
+ data.setServerStatus(online ? JoinEntityData.ServerStatus.ONLINE : JoinEntityData.ServerStatus.OFFLINE);
updatePiglinCustomName(serverName);
updatePiglinBehaviour(serverName);
@@ -168,20 +177,20 @@
}
}
- public CraftPiglin getPiglinForServerName(String serverName) {
+ public Piglin getPiglinForServerName(String serverName) {
JoinEntityData data = entityData.get(serverName);
if (data != null) {
Entity piglin = Bukkit.getEntity(data.getEntityUUID());
- if (piglin instanceof CraftPiglin) {
- return (CraftPiglin) piglin;
+ if (piglin instanceof Piglin) {
+ return (Piglin) piglin;
}
}
return null;
}
public void updatePiglinCustomName(String serverName) {
- CraftPiglin piglin = getPiglinForServerName(serverName);
+ Piglin piglin = getPiglinForServerName(serverName);
JoinEntityData data = entityData.get(serverName);
if (piglin != null && data != null) {
@@ -191,34 +200,58 @@
}
public void updatePiglinBehaviour(String serverName) {
- CraftPiglin piglin = getPiglinForServerName(serverName);
+ Piglin piglin = getPiglinForServerName(serverName);
JoinEntityData data = entityData.get(serverName);
if (piglin != null && data != null) {
if (data.getPlayerCount() < data.getMaxPlayers()) {
switch (data.getServerStatus()) {
- case ONLINE:
+ case ONLINE -> {
piglin.getEquipment().clear();
- piglin.getHandle().u(true);
- break;
-
- case OFFLINE:
- piglin.getHandle().u(false);
+ nmsUtils.getEntityUtils().setPiglinDancing(piglin, true);
+ }
+ case OFFLINE -> {
+ nmsUtils.getEntityUtils().setPiglinDancing(piglin, false);
piglin.getEquipment().setItemInOffHand(new ItemStack(Material.GOLD_INGOT));
- break;
-
- case RUNNING:
+ }
+ case RUNNING -> {
piglin.getEquipment().clear();
- piglin.getHandle().u(false);
- break;
+ nmsUtils.getEntityUtils().setPiglinDancing(piglin, false);
+ }
}
} else { // server is full
piglin.getEquipment().clear();
- piglin.getHandle().u(false);
+ nmsUtils.getEntityUtils().setPiglinDancing(piglin, false);
}
}
}
+ public void saveCategoriesAndMaps() {
+ this.adventureMapsConfig.save();
+ this.categoriesConfig.save();
+ this.adventureMapsConfig.load();
+ this.categoriesConfig.load();
+ }
+
+ public void loadCategoriesAndMaps() {
+ this.categoriesConfig = new CategoriesConfig(this);
+ this.adventureMapsConfig = new AdventureMapsConfig(this);
+ this.adventureMapsConfig.load();
+ this.categoriesConfig.load();
+ }
+
+ public static ChallengesJoinEntities getPlugin() {
+ return plugin;
+ }
+
+ public AdventureMapsConfig getAdventureMapsConfig() {
+ return this.adventureMapsConfig;
+ }
+
+ public CategoriesConfig getCategoriesConfig() {
+ return this.categoriesConfig;
+ }
+
public Config getPluginConfig() {
return config;
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java b/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java
index 6e100a0..10495ac 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java
@@ -2,28 +2,49 @@
import de.iani.cubesideutils.bukkit.ChatUtilBukkit;
import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
public class ChatUtil {
+ public static final ChatColor GREEN = ChatColor.of("#52ff9d");
+ public static final ChatColor ORANGE = ChatColor.of("#ffac4d");
+ public static final ChatColor RED = ChatColor.of("#ff6b6b");
+ public static final ChatColor BLUE = ChatColor.of("#87f7ea");
+
private ChatUtil() {
// prevent instances
}
- public static void sendMessage(CommandSender sender, String colors, Object message, Object... messageParts) {
- ChatUtilBukkit.sendMessage(sender, ChallengesJoinEntities.PREFIX, colors, message, messageParts);
+ public static void sendMessage(CommandSender sender, String colors, Object... messageParts) {
+ ChatUtilBukkit.sendMessage(sender, ChallengesJoinEntities.PREFIX, colors, messageParts);
}
- public static void sendNormalMessage(CommandSender sender, Object message, Object... messageParts) {
- sendMessage(sender, ChatColor.of("#1FFF00").toString(), message, messageParts);
+ public static void sendNormalMessage(CommandSender sender, Object... messageParts) {
+ sendMessage(sender, GREEN.toString(), messageParts);
}
- public static void sendWarningMessage(CommandSender sender, Object message, Object... messageParts) {
- sendMessage(sender, ChatColor.of("#ffe100").toString(), message, messageParts);
+ public static void sendWarningMessage(CommandSender sender, Object... messageParts) {
+ sendMessage(sender, ORANGE.toString(), messageParts);
}
- public static void sendErrorMessage(CommandSender sender, Object message, Object... messageParts) {
- sendMessage(sender, ChatColor.of("#a30202").toString(), message, messageParts);
+ public static void sendErrorMessage(CommandSender sender, Object... messageParts) {
+ sendMessage(sender, RED.toString(), messageParts);
+ }
+
+ public static void sendDebugMessage(CommandSender sender, Object... messageParts) {
+ if (sender.hasPermission("fanta.debug")) {
+ if (sender != null) {
+ sendMessage(sender, ChatColor.of("#FF04F7").toString(), messageParts);
+ }
+ }
+ }
+
+ public static void sendBrodcastMessage(Object... messageParts) {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ sendMessage(player, GREEN.toString(), messageParts);
+ }
}
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/Config.java b/src/main/java/de/fanta/challengesjoinentities/Config.java
index 35bc694..e7ce5d6 100644
--- a/src/main/java/de/fanta/challengesjoinentities/Config.java
+++ b/src/main/java/de/fanta/challengesjoinentities/Config.java
@@ -1,14 +1,13 @@
package de.fanta.challengesjoinentities;
-import com.destroystokyo.paper.HeightmapType;
import org.bukkit.Bukkit;
-import org.bukkit.HeightMap;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashSet;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -52,8 +51,8 @@
double x = locSection.getDouble("x");
double y = locSection.getDouble("y");
double z = locSection.getDouble("z");
- float yaw = (float) locSection.getDouble("yaw");
- Location location = new Location(world, x, 200, z, yaw, 0f);
+ float yaw = (float)locSection.getDouble("yaw");
+ Location location = new Location(world, x, y, z, yaw, 0.0F);
challengeServers.add(new Server(serverName, server.getString("gpLocation"), server.getString("dir"), ServerType.CHALLENGES, plugin, location));
}
@@ -67,9 +66,10 @@
ConfigurationSection locSection = server.getConfigurationSection("location");
World world = Bukkit.getWorld(locSection.getString("world"));
double x = locSection.getDouble("x");
+ double y = locSection.getDouble("y");
double z = locSection.getDouble("z");
- float pitch = (float) locSection.getDouble("pitch");
- Location location = new Location(world, x, 200, z, 0.0f, pitch);
+ float yaw = (float)locSection.getDouble("yaw");
+ Location location = new Location(world, x, y, z, yaw, 0.0F);
adventureServers.add(new Server(serverName, server.getString("gpLocation"), server.getString("dir"), ServerType.ADVENTURE, plugin, location));
}
@@ -110,5 +110,13 @@
public Set getAdventureServers() {
return adventureServers;
}
+
+ public Optional getOnlineChanllengeServer() {
+ return this.challengeServers.stream().filter(server -> !server.isOnline()).findFirst();
+ }
+
+ public Optional getOnlineAdventureServer() {
+ return this.adventureServers.stream().filter(server -> !server.isOnline()).findFirst();
+ }
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/JoinEntityData.java b/src/main/java/de/fanta/challengesjoinentities/JoinEntityData.java
index 862bea1..ac67829 100644
--- a/src/main/java/de/fanta/challengesjoinentities/JoinEntityData.java
+++ b/src/main/java/de/fanta/challengesjoinentities/JoinEntityData.java
@@ -6,10 +6,10 @@
public class JoinEntityData {
- private String serverName;
- private UUID entityUUID;
- private String globalPortLocationName;
- private String serverDisplayName;
+ private final String serverName;
+ private final UUID entityUUID;
+ private final String globalPortLocationName;
+ private final String serverDisplayName;
private ServerStatus serverStatus;
private int playerCount;
private int maxPlayers;
@@ -65,12 +65,12 @@
}
public String createCustomEntityName() {
- String statusString = serverStatus == ServerStatus.ONLINE ? ChatColor.GREEN + "ONLINE" :
- serverStatus == ServerStatus.OFFLINE ? ChatColor.RED + "OFFLINE" :
- serverStatus == ServerStatus.RUNNING ? ChatColor.GOLD + "RUNNING" : "";
- String playerCountString = ChatColor.AQUA + "(" + playerCount + "/" + maxPlayers + ")";
+ String statusString = serverStatus == ServerStatus.ONLINE ? ChatUtil.GREEN + "ONLINE" :
+ serverStatus == ServerStatus.OFFLINE ? ChatUtil.RED + "OFFLINE" :
+ serverStatus == ServerStatus.RUNNING ? ChatUtil.ORANGE + "RUNNING" : "";
+ String playerCountString = ChatUtil.BLUE + "(" + playerCount + "/" + maxPlayers + ")";
- return ChatColor.BLUE + serverDisplayName + " " + statusString + (serverStatus != ServerStatus.OFFLINE ? (" " + playerCountString) : "");
+ return ChatUtil.BLUE + serverDisplayName + " " + statusString + (serverStatus != ServerStatus.OFFLINE ? (" " + playerCountString) : "");
}
public enum ServerStatus {
diff --git a/src/main/java/de/fanta/challengesjoinentities/Server.java b/src/main/java/de/fanta/challengesjoinentities/Server.java
index 6fd0cac..32faf2f 100644
--- a/src/main/java/de/fanta/challengesjoinentities/Server.java
+++ b/src/main/java/de/fanta/challengesjoinentities/Server.java
@@ -1,27 +1,36 @@
package de.fanta.challengesjoinentities;
-import org.apache.commons.io.FileUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.entity.Player;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
+import java.util.Map;
import java.util.UUID;
+import java.util.logging.Level;
+
+import org.apache.commons.io.FileUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
public class Server {
-
public static HashMap serverPlayers = new HashMap<>();
- private ChallengesJoinEntities plugin;
- private String name;
- private String gPLocation;
- private String dir;
- private ServerType serverType;
- private Location piglinLocation;
+ private final ChallengesJoinEntities plugin;
+
+ private final String name;
+
+ private final String gPLocation;
+
+ private final String dir;
+
+ private final ServerType serverType;
+
+ private final Location piglinLocation;
+
private boolean online;
public Server(String name, String gPLocation, String dir, ServerType serverType, ChallengesJoinEntities plugin, Location piglinLocation) {
@@ -30,12 +39,22 @@
this.dir = dir;
this.serverType = serverType;
this.plugin = plugin;
- this.online = plugin.getGlobalDataHelper().getServer(name) != null;
+ this.online = (plugin.getGlobalDataHelper().getServer(name) != null);
this.piglinLocation = piglinLocation;
}
+ public static Server getServerfromPlayer(Player p) {
+ Server server = null;
+ if (serverPlayers.containsValue(p.getUniqueId()))
+ for (Map.Entry entry : serverPlayers.entrySet()) {
+ if (entry.getValue().equals(p.getUniqueId()))
+ server = entry.getKey();
+ }
+ return server;
+ }
+
public boolean isOnline() {
- return online;
+ return this.online;
}
public void setOnline(boolean online) {
@@ -43,34 +62,62 @@
}
public String getName() {
- return name;
+ return this.name;
}
public String getGPLocation() {
- return gPLocation;
+ return this.gPLocation;
}
- public void load(Player p) {
- online = true;
- Server.serverPlayers.put(this, p.getUniqueId());
+ public void loadSaved(Player p) {
+ this.online = true;
+ serverPlayers.put(this, p.getUniqueId());
UUID uuid = p.getUniqueId();
- File dir = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString());
+ File dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + uuid);
if (!dir.isDirectory()) {
ChatUtil.sendErrorMessage(p, "Du hast noch keine Map gespeichert!");
- online = false;
- Server.serverPlayers.remove(this);
+ this.online = false;
+ serverPlayers.remove(this);
return;
}
+ load(p, this.serverType.getDir(), uuid.toString());
+ }
+ public void loadSaved(Player p, String mapname) {
+ this.online = true;
+ serverPlayers.put(this, p.getUniqueId());
+ File dir = new File("/home/minecraft/" + this.serverType.getDir() + "/" + mapname);
+ if (!dir.isDirectory()) {
+ ChatUtil.sendErrorMessage(p, "Map " + mapname + " nicht gefunden!");
+ this.online = false;
+ serverPlayers.remove(this);
+ return;
+ }
+ load(p, this.serverType.getDir(), mapname);
+ }
+
+ public void loadNewAdventure(Player player, String category, String map) {
+ this.online = true;
+ serverPlayers.put(this, player.getUniqueId());
+ File dir = new File("/home/minecraft/Adventure-Maps", category + "/" + map);
+ if (!dir.isDirectory()) {
+ ChatUtil.sendErrorMessage(player, "Map " + map + " nicht gefunden!");
+ this.online = false;
+ serverPlayers.remove(this);
+ return;
+ }
+ load(player, "Adventure-Maps", category + "/" + map);
+ }
+
+ public void load(Player p, String serverTypeDir, String targetDir) {
File configs = new File("/home/minecraft/" + this.dir + "/plugins/Challenges");
File end = new File("/home/minecraft/" + this.dir + "/world_the_end");
File nether = new File("/home/minecraft/" + this.dir + "/world_nether");
File world = new File("/home/minecraft/" + this.dir + "/world");
- File saveend = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/world_the_end");
- File savenether = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/world_nether");
- File saveworld = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/world");
- File saveconfigs = new File("/home/minecraft/" + serverType.getDir() + "/" + uuid.toString() + "/Challenges");
-
+ File saveend = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world_the_end");
+ File savenether = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world_nether");
+ File saveworld = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/world");
+ File saveconfigs = new File("/home/minecraft/" + serverTypeDir + "/" + targetDir + "/Challenges");
ChatUtil.sendNormalMessage(p, "Versuche Map zu laden!");
try {
if (world.isDirectory()) {
@@ -82,44 +129,39 @@
FileUtils.copyDirectory(saveworld, world);
FileUtils.copyDirectory(savenether, nether);
FileUtils.copyDirectory(saveend, end);
-
} catch (IOException e) {
e.printStackTrace();
ChatUtil.sendErrorMessage(p, "Map konnte nicht geladen werden!");
- online = false;
- Server.serverPlayers.remove(this);
+ this.online = false;
+ serverPlayers.remove(this);
return;
}
ChatUtil.sendNormalMessage(p, "Map wurde geladen! Server wird nun gestartet!");
- start(uuid, p);
+ start(p);
}
- public void start(UUID uuid, Player player) {
+ public void start(Player player) {
ProcessBuilder processBuilder = new ProcessBuilder();
- processBuilder.command("screen", "-AmdS", uuid.toString(), "./start.sh").directory(new File("/home/minecraft/" + dir));
+ processBuilder.command("screen", "-AmdS", player.getName(), "./start.sh").directory(new File("/home/minecraft/" + this.dir));
try {
Process process = processBuilder.start();
- Bukkit.getLogger().info(serverType.toString().toLowerCase() + " Server: " + uuid + " wurde von " + player.getName() + " gestartet!");
+ Bukkit.getLogger().info(this.serverType.toString().toLowerCase() + " Server: " + this.serverType.toString().toLowerCase() + " wurde von " + player.getName() + " gestartet!");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
- while ((line = reader.readLine()) != null) {
- System.out.println(line);
- }
+ while ((line = reader.readLine()) != null)
+ plugin.getLogger().log(Level.SEVERE, line);
int exitCode = process.waitFor();
- System.out.println("Exited with error code : " + exitCode);
- } catch (IOException | InterruptedException e) {
+ plugin.getLogger().log(Level.SEVERE, "Exited with error code : " + exitCode);
+ } catch (IOException|InterruptedException e) {
e.printStackTrace();
}
}
- public void spawnPiglin(Player player){
- plugin.spawnPiglin(piglinLocation, name, gPLocation, player.getName(), false);
-
-
-
+ public void spawnPiglin(Player player) {
+ this.plugin.spawnPiglin(this.piglinLocation, this.name, this.gPLocation, player.getName(), false);
}
- public void despawnPiglin(){
- plugin.despawnPiglin(name);
+ public void despawnPiglin() {
+ this.plugin.despawnPiglin(this.name);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java
new file mode 100644
index 0000000..daec339
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java
@@ -0,0 +1,68 @@
+package de.fanta.challengesjoinentities.adventure;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import de.fanta.challengesjoinentities.ChatUtil;
+import org.bukkit.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+public class AdventureMap {
+ private final ChallengesJoinEntities plugin;
+
+ private final String name;
+
+ private final ItemStack item;
+
+ private final String creator;
+
+ private final String webLink;
+
+ public AdventureMap(ChallengesJoinEntities plugin, String name, Material material, String creator, String webLink) {
+ this.name = name;
+ this.creator = creator;
+ this.webLink = webLink;
+ this.plugin = plugin;
+ this.item = new ItemStack((material != null) ? material : Material.STONE);
+ ItemMeta meta = this.item.getItemMeta();
+ meta.setDisplayName("" + ChatUtil.ORANGE + ChatColor.BOLD + getName());
+ List lore = new ArrayList<>();
+ lore.add("");
+ lore.add(ChatUtil.GREEN + "Erbauer: " + ChatUtil.BLUE + creator);
+ lore.add(ChatUtil.GREEN + "MapLink: " + ChatUtil.BLUE + "Rechts Klick");
+ lore.add(ChatUtil.GREEN + "Map laden: " + ChatUtil.BLUE + "Links Klick");
+ meta.setLore(lore);
+ this.item.setItemMeta(meta);
+ }
+
+ public AdventureMap(ChallengesJoinEntities plugin, String name, ConfigurationSection section) {
+ this(plugin, name, Material.matchMaterial(Objects.requireNonNull(section.getString("item"))), section.getString("creator"), section.getString("web_link"));
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public ItemStack getItem() {
+ return this.item;
+ }
+
+ public String getCreator() {
+ return this.creator;
+ }
+
+ public String getWebLink() {
+ return this.webLink;
+ }
+
+ public void save(ConfigurationSection section) {
+ section.set("item", this.item.getType().getKey().toString());
+ section.set("creator", this.creator);
+ section.set("web_link", this.webLink);
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java
new file mode 100644
index 0000000..a765573
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java
@@ -0,0 +1,77 @@
+package de.fanta.challengesjoinentities.adventure;
+
+import com.google.common.collect.ImmutableMap;
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.jetbrains.annotations.Nullable;
+
+public class AdventureMapsConfig {
+ private final ChallengesJoinEntities plugin;
+
+ private final Map maps = new HashMap<>();
+
+ private final File file;
+
+ private final YamlConfiguration config;
+
+ public AdventureMapsConfig(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ this.file = new File(plugin.getDataFolder(), "adventure_maps.yml");
+ this.config = new YamlConfiguration();
+ }
+
+ private boolean fileExists() throws IOException {
+ if (!this.file.exists())
+ return this.file.createNewFile();
+ return true;
+ }
+
+ public void load() {
+ try {
+ if (fileExists()) {
+ this.config.load(this.file);
+ this.config.getKeys(false).forEach(key -> {
+ ConfigurationSection section = this.config.getConfigurationSection(key);
+ if (section != null) {
+ AdventureMap map = new AdventureMap(this.plugin, key, section);
+ if (!this.maps.containsKey(key))
+ this.maps.put(key, map);
+ }
+ });
+ }
+ } catch (IOException|org.bukkit.configuration.InvalidConfigurationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void save() {
+ this.maps.forEach((key, map) -> map.save(this.config.createSection(key)));
+ try {
+ this.config.save(this.file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public boolean addMap(AdventureMap map) {
+ if (!this.maps.containsKey(map.getName())) {
+ this.maps.put(map.getName(), map);
+ return true;
+ }
+ return false;
+ }
+
+ public Map getMaps() {
+ return ImmutableMap.copyOf(this.maps);
+ }
+
+ @Nullable
+ public AdventureMap getMap(String name) {
+ return this.maps.get(name);
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java b/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java
new file mode 100644
index 0000000..8c8740b
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java
@@ -0,0 +1,77 @@
+package de.fanta.challengesjoinentities.adventure;
+
+import com.google.common.collect.ImmutableMap;
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.jetbrains.annotations.Nullable;
+
+public class CategoriesConfig {
+ private final ChallengesJoinEntities plugin;
+
+ private final Map categories = new HashMap<>();
+
+ private final File file;
+
+ private final YamlConfiguration config;
+
+ public CategoriesConfig(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ this.file = new File(plugin.getDataFolder(), "categories.yml");
+ this.config = new YamlConfiguration();
+ }
+
+ private boolean fileExists() throws IOException {
+ if (!this.file.exists())
+ return this.file.createNewFile();
+ return true;
+ }
+
+ public void load() {
+ try {
+ if (fileExists()) {
+ this.config.load(this.file);
+ this.config.getKeys(false).forEach(key -> {
+ ConfigurationSection section = this.config.getConfigurationSection(key);
+ if (section != null) {
+ Category category = new Category(this.plugin, key, section);
+ if (!this.categories.containsKey(key))
+ this.categories.put(key, category);
+ }
+ });
+ }
+ } catch (IOException|org.bukkit.configuration.InvalidConfigurationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void save() {
+ this.categories.forEach((key, category) -> category.save(this.config.createSection(key)));
+ try {
+ this.config.save(this.file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public boolean addCategory(Category category) {
+ if (!this.categories.containsKey(category.getName())) {
+ this.categories.put(category.getName(), category);
+ return true;
+ }
+ return false;
+ }
+
+ public Map getCategories() {
+ return ImmutableMap.copyOf(this.categories);
+ }
+
+ @Nullable
+ public Category getCategory(String name) {
+ return this.categories.get(name);
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/Category.java b/src/main/java/de/fanta/challengesjoinentities/adventure/Category.java
new file mode 100644
index 0000000..0e67ae3
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/adventure/Category.java
@@ -0,0 +1,76 @@
+package de.fanta.challengesjoinentities.adventure;
+
+import de.fanta.challenges.Challenges;
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import de.fanta.challengesjoinentities.ChatUtil;
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+public class Category {
+ private final String name;
+
+ private final ItemStack item;
+
+ private final Set maps;
+
+ private final ChallengesJoinEntities plugin = ChallengesJoinEntities.getPlugin();
+
+ public Category(String name, Material material) {
+ this(name, material, new HashSet<>());
+ }
+
+ public Category(ChallengesJoinEntities plugin, String name, ConfigurationSection section) {
+ this(name, Material.matchMaterial(Objects.requireNonNull(section.getString("item"))), section.getStringList("maps").stream().map(mapName -> {
+ AdventureMap map = plugin.getAdventureMapsConfig().getMap(mapName);
+ if (map == null)
+ plugin.getLogger().warning("Die map \"" + mapName + "\" existiert nicht!");
+ return map;
+ }).filter(Objects::nonNull).collect(Collectors.toSet()));
+ }
+
+ public Category(String name, Material material, Set maps) {
+ this.name = name;
+ this.maps = maps;
+ this.item = new ItemStack((material != null) ? material : Material.STONE);
+ ItemMeta meta = this.item.getItemMeta();
+ meta.setDisplayName("" + ChatUtil.ORANGE + ChatColor.BOLD + getName());
+ List lore = new ArrayList<>();
+ lore.add("");
+ lore.add(ChatUtil.GREEN + "Maps: " + ChatUtil.BLUE + maps.size());
+ meta.setLore(lore);
+ this.item.setItemMeta(meta);
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public ItemStack getItem() {
+ return this.item;
+ }
+
+ public Set getMaps() {
+ return this.maps;
+ }
+
+ public void addMap(AdventureMap map) {
+ this.maps.add(map);
+ plugin.saveCategoriesAndMaps();
+ plugin.loadCategoriesAndMaps();
+ }
+
+ public void save(ConfigurationSection section) {
+ section.set("item", this.item.getType().getKey().toString());
+ section.set("maps", this.maps.stream().map(AdventureMap::getName).collect(Collectors.toList()));
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/ui/AdventureMapsUI.java b/src/main/java/de/fanta/challengesjoinentities/adventure/ui/AdventureMapsUI.java
new file mode 100644
index 0000000..e319296
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/adventure/ui/AdventureMapsUI.java
@@ -0,0 +1,88 @@
+package de.fanta.challengesjoinentities.adventure.ui;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.Server;
+import de.fanta.challengesjoinentities.adventure.AdventureMap;
+import de.fanta.challengesjoinentities.adventure.Category;
+import de.fanta.challengesjoinentities.utils.ui.AbstractWindow;
+import de.fanta.challengesjoinentities.utils.ui.ItemUtil;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.event.ClickEvent;
+import net.kyori.adventure.text.format.TextColor;
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
+import org.bukkit.Color;
+import org.bukkit.Material;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+public class AdventureMapsUI extends AbstractWindow {
+ private final ChallengesJoinEntities plugin;
+
+ private final Category category;
+
+ private final Map mapsPerSlot = new HashMap<>();
+
+ private final int BACK_INDEX = getInventory().getSize() - 9;
+
+ public AdventureMapsUI(ChallengesJoinEntities plugin, Category category, Player player) {
+ super(player, Bukkit.createInventory(player, 9 * (category.getMaps().size() / 7 + ((category.getMaps().size() % 7 > 0) ? 1 : 0)) + 18, ChatUtil.RED + category.getName() + "Map's "));
+ this.category = category;
+ this.plugin = plugin;
+ }
+
+ protected void rebuildInventory() {
+ List maps = this.category.getMaps().stream().sorted(Comparator.comparing(AdventureMap::getName)).toList();
+ int row = 0;
+ int cat = 0;
+ for (AdventureMap category : maps) {
+ int slot = row * 9 + cat + 10;
+ getInventory().setItem(slot, category.getItem());
+ this.mapsPerSlot.put(slot, category);
+ if (cat < 6) {
+ cat++;
+ continue;
+ }
+ row++;
+ cat = 0;
+ }
+ ItemStack backButtton = new ItemStack(Material.PAPER);
+ ItemMeta meta = backButtton.getItemMeta();
+ meta.setDisplayName("" + ChatColor.GREEN + "Zurück");
+ backButtton.setItemMeta(meta);
+ getInventory().setItem(this.BACK_INDEX, backButtton);
+ for (int i1 = 0; i1 < getInventory().getSize(); i1++) {
+ ItemStack item = getInventory().getItem(i1);
+ if (item == null)
+ getInventory().setItem(i1, ItemUtil.EMPTY_ICON);
+ }
+ }
+
+ public void onItemClicked(InventoryClickEvent event) {
+ super.onItemClicked(event);
+ int slot = event.getSlot();
+ AdventureMap map = this.mapsPerSlot.get(slot);
+ Player p = getPlayer();
+ if (map != null) {
+ if (event.isRightClick()) {
+ getPlayer().sendMessage(ChallengesJoinEntities.PREFIX_COMPONENT.append(Component.text("MapLink: klick mich :)", TextColor.color(Color.YELLOW.asRGB())).clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, map.getWebLink()))));
+ } else if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ this.plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadNewAdventure(p, category.getName(), map.getName()), () -> ChatUtil.sendErrorMessage(p, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!");
+ }
+ getPlayer().closeInventory();
+ }
+ if (slot == this.BACK_INDEX)
+ (new CategoryUI(this.plugin, this.plugin.getCategoriesConfig(), p)).open();
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/ui/CategoryUI.java b/src/main/java/de/fanta/challengesjoinentities/adventure/ui/CategoryUI.java
new file mode 100644
index 0000000..9271cd8
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/adventure/ui/CategoryUI.java
@@ -0,0 +1,66 @@
+package de.fanta.challengesjoinentities.adventure.ui;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.adventure.CategoriesConfig;
+import de.fanta.challengesjoinentities.adventure.Category;
+import de.fanta.challengesjoinentities.utils.ui.AbstractWindow;
+import de.fanta.challengesjoinentities.utils.ui.ItemUtil;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.inventory.InventoryHolder;
+import org.bukkit.inventory.ItemStack;
+
+public class CategoryUI extends AbstractWindow {
+ private final ChallengesJoinEntities plugin;
+
+ private final CategoriesConfig config;
+
+ private final Map categoryPerSlot = new HashMap<>();
+
+ public CategoryUI(ChallengesJoinEntities plugin, CategoriesConfig config, Player player) {
+ super(player, Bukkit.createInventory(player, 9 * (config.getCategories().size() / 7 + ((config.getCategories().size() % 7 > 0) ? 1 : 0)) + 18, ChatUtil.BLUE + "Adventure Map Kategorien"));
+ this.config = config;
+ this.plugin = plugin;
+ }
+
+ protected void rebuildInventory() {
+ Map categories = this.config.getCategories();
+ List sortedValues = categories.values().stream().sorted(Comparator.comparing(Category::getName)).collect(Collectors.toList());
+ int row = 0;
+ int cat = 0;
+ for (Category category : sortedValues) {
+ int slot = row * 9 + cat + 10;
+ getInventory().setItem(slot, category.getItem());
+ this.categoryPerSlot.put(slot, category);
+ if (cat < 6) {
+ cat++;
+ continue;
+ }
+ row++;
+ cat = 0;
+ }
+ for (int i1 = 0; i1 < getInventory().getSize(); i1++) {
+ ItemStack item = getInventory().getItem(i1);
+ if (item == null)
+ getInventory().setItem(i1, ItemUtil.EMPTY_ICON);
+ }
+ }
+
+ public void onItemClicked(InventoryClickEvent event) {
+ super.onItemClicked(event);
+ int slot = event.getSlot();
+ Category category = this.categoryPerSlot.get(slot);
+ if (category != null)
+ (new AdventureMapsUI(this.plugin, category, getPlayer())).open();
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddCategoryCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddCategoryCommand.java
new file mode 100644
index 0000000..4d8617c
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddCategoryCommand.java
@@ -0,0 +1,52 @@
+package de.fanta.challengesjoinentities.commands.AdventureCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.adventure.CategoriesConfig;
+import de.fanta.challengesjoinentities.adventure.Category;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class AdventureAddCategoryCommand extends SubCommand {
+ private final CategoriesConfig config;
+
+ public AdventureAddCategoryCommand(ChallengesJoinEntities plugin) {
+ this.config = plugin.getCategoriesConfig();
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ Player player;
+ CommandSender commandSender = sender;
+ if (commandSender instanceof Player) {
+ player = (Player)commandSender;
+ } else {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Du musst ein Spieler sein!" });
+ return true;
+ }
+ if (!player.hasPermission("challenges.createcategorie")) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Keine Rechte!" });
+ return true;
+ }
+ Material item = player.getInventory().getItemInMainHand().getType();
+ if (item == Material.AIR) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Du musst ein Item in der Hand haben!" });
+ return true;
+ }
+ if (args.hasNext()) {
+ String name = args.getNext();
+ Category category = new Category(name, item);
+ if (!this.config.addCategory(category)) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Die category " + name + " existiert bereits!" });
+ return true;
+ }
+ ChatUtil.sendNormalMessage(sender, new Object[] { "Die category " + name + " wurde erfolgreich hinzugefügt!" });
+ this.config.save();
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java
new file mode 100644
index 0000000..a0471db
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java
@@ -0,0 +1,74 @@
+package de.fanta.challengesjoinentities.commands.AdventureCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.adventure.AdventureMap;
+import de.fanta.challengesjoinentities.adventure.AdventureMapsConfig;
+import de.fanta.challengesjoinentities.adventure.Category;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class AdventureAddMapCommand extends SubCommand {
+ private ChallengesJoinEntities plugin;
+
+ private AdventureMapsConfig config;
+
+ public AdventureAddMapCommand(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ this.config = plugin.getAdventureMapsConfig();
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ Player player;
+ CommandSender commandSender = sender;
+ if (commandSender instanceof Player) {
+ player = (Player)commandSender;
+ } else {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Du musst ein Spieler sein!" });
+ return true;
+ }
+ if (!player.hasPermission("challenges.createadventuremap")) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Keine Rechte!" });
+ return true;
+ }
+ Material item = player.getInventory().getItemInMainHand().getType();
+ if (item == Material.AIR) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Du musst ein Item in der Hand haben!" });
+ return true;
+ }
+ if (args.hasNext()) {
+ String name = args.getNext();
+ if (args.hasNext()) {
+ String categoryName = args.getNext();
+ Category category = this.plugin.getCategoriesConfig().getCategory(categoryName);
+ if (category == null) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Die Kategorie " + categoryName + " existiert nicht!" });
+ return true;
+ }
+ if (args.hasNext()) {
+ String webLink = args.getNext();
+ webLink = webLink.equalsIgnoreCase("null") ? "" : webLink;
+ if (args.hasNext()) {
+ String creator = args.getAll(null);
+ if (creator != null) {
+ AdventureMap map = new AdventureMap(this.plugin, name, item, creator, webLink);
+ if (!this.config.addMap(map)) {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Die map " + name + " existiert bereits!" });
+ return true;
+ }
+ category.addMap(map);
+ this.plugin.saveCategoriesAndMaps();
+ ChatUtil.sendNormalMessage(sender, new Object[] { "Die map " + name + " wurde erfolgreich hinzugefügt!" });
+ return true;
+ }
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java
index d32d118..c38ba60 100644
--- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadCommand.java
@@ -10,36 +10,36 @@
import org.bukkit.entity.Player;
public class AdventureLoadCommand extends SubCommand {
-
private final ChallengesJoinEntities plugin;
public AdventureLoadCommand(ChallengesJoinEntities plugin) {
this.plugin = plugin;
}
- @Override
public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
- if (!(sender instanceof Player)) {
+ Player p;
+ CommandSender commandSender = sender;
+ if (commandSender instanceof Player) {
+ p = (Player) commandSender;
+ } else {
ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!");
return true;
}
- Player p = (Player) sender;
- if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
- boolean serverAvailable = false;
- for (Server server : plugin.getPluginConfig().getAdventureServers()) {
- if (server.isOnline())
- continue;
- server.load(p);
- serverAvailable = true;
- break;
+ if (!args.hasNext()) {
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
}
- if (!serverAvailable) {
- ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!");
- }
- } else {
- ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
+ return true;
}
+ String next = args.getNext();
+ if (sender.hasPermission("challenges.load.admin"))
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ this.plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadSaved(p, next.toLowerCase()), () -> ChatUtil.sendErrorMessage(sender, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(sender, "Du kannst nur einen Server starten!");
+ }
return true;
}
}
-
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureMapsCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureMapsCommand.java
new file mode 100644
index 0000000..5d7eb1f
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureMapsCommand.java
@@ -0,0 +1,31 @@
+package de.fanta.challengesjoinentities.commands.AdventureCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.adventure.ui.CategoryUI;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class AdventureMapsCommand extends SubCommand {
+ private final ChallengesJoinEntities plugin;
+
+ public AdventureMapsCommand(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ Player p;
+ CommandSender commandSender = sender;
+ if (commandSender instanceof Player) {
+ p = (Player)commandSender;
+ } else {
+ ChatUtil.sendErrorMessage(sender, new Object[] { "Du musst ein Spieler sein!" });
+ return true;
+ }
+ (new CategoryUI(this.plugin, this.plugin.getCategoriesConfig(), p)).open();
+ return true;
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java
new file mode 100644
index 0000000..28fc09a
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTestMapCommand.java
@@ -0,0 +1,49 @@
+package de.fanta.challengesjoinentities.commands.AdventureCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.Server;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class AdventureTestMapCommand extends SubCommand {
+ private final ChallengesJoinEntities plugin;
+
+ public AdventureTestMapCommand(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ Player p;
+ CommandSender commandSender = sender;
+ if (commandSender instanceof Player) {
+ p = (Player)commandSender;
+ } else {
+ ChatUtil.sendErrorMessage(sender, "Du musst ein Spieler sein!");
+ return true;
+ }
+ if (sender.hasPermission("challenges.starttestmap")) {
+ if (args.hasNext()) {
+ String category = args.getNext();
+ if (args.hasNext()) {
+ String map = args.getNext();
+ if (!Server.serverPlayers.containsValue(p.getUniqueId())) {
+ this.plugin.getPluginConfig().getOnlineAdventureServer().ifPresentOrElse(server -> server.loadNewAdventure(p, category, map), () -> ChatUtil.sendErrorMessage(p, "Aktuell ist kein Server Frei!"));
+ } else {
+ ChatUtil.sendErrorMessage(p, "Du kannst nur einen Server starten!");
+ }
+ } else {
+ ChatUtil.sendWarningMessage(p, "/ladventure testmap