diff --git a/pom.xml b/pom.xml
index 312b12e..e91939c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,6 +22,11 @@
everything
https://repo.citizensnpcs.co/
+
+ codemc-repo
+ https://repo.codemc.org/repository/maven-public/
+ default
+
@@ -89,6 +94,12 @@
1.1.0
provided
+
+ de.tr7zw
+ item-nbt-api-plugin
+ 2.10.0-SNAPSHOT
+ provided
+
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
index 56f4cfd..8c0713c 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java
@@ -10,6 +10,7 @@
import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureConvertMapCommand;
import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureLoadCommand;
import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureMapsCommand;
+import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureTempCommand;
import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureTestMapCommand;
import de.fanta.challengesjoinentities.commands.AdventureCommand.ChallengeClearSavesCommand;
import de.fanta.challengesjoinentities.commands.AdventureCommand.ChallengesRemovePlayerServer;
@@ -130,6 +131,7 @@
adventurerouter.addCommandMapping(new ChallengesRemovePlayerServer(this), "removeplayerfromserver");
adventurerouter.addCommandMapping(new AdventureConvertMapCommand(this), "convertmap");
adventurerouter.addCommandMapping(new AdventureClearSavesCommand(), "clearoldsaves");
+ adventurerouter.addCommandMapping(new AdventureTempCommand(this), "temp");
Bukkit.getPluginManager().registerEvents(new EntityListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
diff --git a/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java b/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java
index 10495ac..11023f9 100644
--- a/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java
+++ b/src/main/java/de/fanta/challengesjoinentities/ChatUtil.java
@@ -12,6 +12,7 @@
public static final ChatColor ORANGE = ChatColor.of("#ffac4d");
public static final ChatColor RED = ChatColor.of("#ff6b6b");
public static final ChatColor BLUE = ChatColor.of("#87f7ea");
+ public static final ChatColor PINK = ChatColor.of("#FF04F7");
private ChatUtil() {
// prevent instances
@@ -36,7 +37,7 @@
public static void sendDebugMessage(CommandSender sender, Object... messageParts) {
if (sender.hasPermission("fanta.debug")) {
if (sender != null) {
- sendMessage(sender, ChatColor.of("#FF04F7").toString(), messageParts);
+ sendMessage(sender, PINK.toString(), messageParts);
}
}
}
diff --git a/src/main/java/de/fanta/challengesjoinentities/SaveSlot.java b/src/main/java/de/fanta/challengesjoinentities/SaveSlot.java
new file mode 100644
index 0000000..79a08f3
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/SaveSlot.java
@@ -0,0 +1,25 @@
+package de.fanta.challengesjoinentities;
+
+public enum SaveSlot {
+
+ SLOT_1("1", "challenge.save.slot1"),
+ SLOT_2("2", "challenge.save.slot2"),
+ SLOT_3("3", "challenge.save.slot3"),
+ SLOT_AUTO("autosave", "challenge.save.slotauto");
+
+ private final String slot;
+ private final String permission;
+
+ SaveSlot(String prefix, String permission) {
+ this.slot = prefix;
+ this.permission = permission;
+ }
+
+ public String getSlot() {
+ return slot;
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java
new file mode 100644
index 0000000..491a334
--- /dev/null
+++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java
@@ -0,0 +1,120 @@
+package de.fanta.challengesjoinentities.commands.AdventureCommand;
+
+import de.fanta.challengesjoinentities.ChallengesJoinEntities;
+import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.adventure.AdventureMap;
+import de.iani.cubesideutils.bukkit.commands.SubCommand;
+import de.iani.cubesideutils.commands.ArgsParser;
+import de.tr7zw.nbtapi.NBTCompound;
+import de.tr7zw.nbtapi.NBTFile;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.inventory.ItemStack;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.logging.Level;
+
+public class AdventureTempCommand extends SubCommand {
+ private final ChallengesJoinEntities plugin;
+
+ public AdventureTempCommand(ChallengesJoinEntities plugin) {
+ this.plugin = plugin;
+ }
+
+ public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) {
+ int count = 0;
+ HashMap list = new HashMap<>();
+
+ File adventureMapsFolder = new File("/home/minecraft/Adventure-Maps/");
+ File[] categories = adventureMapsFolder.listFiles();
+ if (categories != null) {
+ for (File category : categories) {
+ ChatUtil.sendNormalMessage(sender, "- " + category.getName());
+ File[] maps = category.listFiles();
+ if (maps != null) {
+ for (File map : maps) {
+ ChatUtil.sendDebugMessage(sender, " - " + map.getName());
+ AdventureMap adventureMap = plugin.getAdventureMapsConfig().getMap(map.getName());
+ if (adventureMap != null) {
+ try {
+ NBTFile file = new NBTFile(new File(map, "/world/level.dat"));
+ NBTCompound data = file.getCompound("Data");
+ NBTCompound worldgen = data.getCompound("WorldGenSettings");
+ Long seed = null;
+ if (worldgen != null) {
+ seed = worldgen.getLong("seed");
+ }
+ if (seed == null || seed == 0) {
+ seed = data.getLong("RandomSeed");
+ }
+
+ if (seed != null) {
+ count++;
+ list.put(seed, adventureMap.getItem());
+ ChatUtil.sendWarningMessage(sender, " " + seed);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+ }
+ }
+ ChatUtil.sendDebugMessage(sender, "Maps: " + count + " - List: " + list.size());
+
+ File adventureSaves = new File("/home/minecraft/Adventure-saves/");
+ File[] players = adventureSaves.listFiles();
+ if (players != null) {
+ for (File player : players) {
+ ChatUtil.sendNormalMessage(sender, "- " + player.getName());
+ File[] maps = player.listFiles();
+ if (maps != null) {
+ for (File map : maps) {
+ ChatUtil.sendDebugMessage(sender, " - " + map.getName());
+ try {
+ NBTFile file = new NBTFile(new File(map, "/world/level.dat"));
+ NBTCompound data = file.getCompound("Data");
+ NBTCompound worldgen = data.getCompound("WorldGenSettings");
+ Long seed = null;
+ if (worldgen != null) {
+ seed = worldgen.getLong("seed");
+ }
+ if (seed == null || seed == 0) {
+ seed = data.getLong("RandomSeed");
+ }
+ if (seed != null && list.containsKey(seed)) {
+ ChatUtil.sendWarningMessage(sender, " " + seed);
+ File mapConfig = new File(map, "/Challenges/serverconfig.yml");
+ ItemStack stack = list.get(seed);
+ ChatUtil.sendWarningMessage(sender, " " + stack.getType().toString());
+ try {
+ YamlConfiguration serverConfig = new YamlConfiguration();
+ serverConfig.load(mapConfig);
+ serverConfig.set("displayItem.item", stack.getType().toString());
+ serverConfig.set("displayItem.name", stack.getItemMeta().getDisplayName());
+ serverConfig.save(mapConfig);
+ } catch (IOException | InvalidConfigurationException ex) {
+ plugin.getLogger().log(Level.SEVERE, "Fehler beim ändern der Config", ex);
+ ChatUtil.sendErrorMessage(sender, " --- Map " + map.getName() + ": Fehler beim ändern der Config! ---");
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String getRequiredPermission() {
+ return "challenge.command.temp";
+ }
+}
diff --git a/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java b/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java
index 0b63a7b..40ffae6 100644
--- a/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java
+++ b/src/main/java/de/fanta/challengesjoinentities/loadgui/AdventureLoadGUI.java
@@ -2,6 +2,7 @@
import de.fanta.challengesjoinentities.ChallengesJoinEntities;
import de.fanta.challengesjoinentities.ChatUtil;
+import de.fanta.challengesjoinentities.SaveSlot;
import de.fanta.challengesjoinentities.Server;
import de.fanta.challengesjoinentities.utils.guiutils.GUIUtils;
import de.fanta.challengesjoinentities.utils.ui.AbstractWindow;
@@ -9,9 +10,12 @@
import de.iani.playerUUIDCache.CachedPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
import java.io.IOException;
@@ -19,7 +23,9 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.HashMap;
+import java.util.List;
import java.util.UUID;
+import java.util.logging.Level;
public class AdventureLoadGUI extends AbstractWindow {
@@ -40,8 +46,8 @@
@Override
protected void rebuildInventory() {
- Player p = getPlayer();
- UUID savePlayerID = savePlayerList.get(p.getUniqueId());
+ Player player = getPlayer();
+ UUID savePlayerID = savePlayerList.get(player.getUniqueId());
File adventureSave1 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/1");
File adventureSave2 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/2");
File adventureSave3 = new File("/home/minecraft/Adventure-saves/" + savePlayerID + "/3");
@@ -50,53 +56,10 @@
for (int i = 0; i < WINDOW_SIZE; i++) {
ItemStack item;
switch (i) {
- case SAVE_1_INDEX -> {
- if (p.hasPermission("challenge.save.slot1")) {
- if (adventureSave1.isDirectory()) {
- item = GUIUtils.createGuiItem(Material.MAP, ChatUtil.GREEN + "Save 1", ChatUtil.GREEN + "Klicken zum laden.", ChatUtil.GREEN + "Gespeichert am " + getFileDate(adventureSave1));
- } else {
- item = GUIUtils.createGuiItem(Material.LIME_STAINED_GLASS_PANE, ChatUtil.GREEN + "Frei");
- }
- } else {
- item = GUIUtils.createGuiItem(Material.BARRIER, ChatUtil.RED + "Für diesen Slot hast du keine Rechte");
- }
- }
-
- case SAVE_2_INDEX -> {
- if (p.hasPermission("challenge.save.slot2")) {
- if (adventureSave2.isDirectory()) {
- item = GUIUtils.createGuiItem(Material.MAP, ChatUtil.GREEN + "Save 2", ChatUtil.GREEN + "Klicken zum laden.", ChatUtil.GREEN + "Gespeichert am " + getFileDate(adventureSave2));
- } else {
- item = GUIUtils.createGuiItem(Material.LIME_STAINED_GLASS_PANE, ChatUtil.GREEN + "Frei");
- }
- } else {
- item = GUIUtils.createGuiItem(Material.BARRIER, ChatUtil.RED + "Für diesen Slot brauchst du VIP");
- }
- }
-
- case SAVE_3_INDEX -> {
- if (p.hasPermission("challenge.save.slot3")) {
- if (adventureSave3.isDirectory()) {
- item = GUIUtils.createGuiItem(Material.MAP, ChatUtil.GREEN + "Save 3", ChatUtil.GREEN + "Klicken zum laden.", ChatUtil.GREEN + "Gespeichert am " + getFileDate(adventureSave3));
- } else {
- item = GUIUtils.createGuiItem(Material.LIME_STAINED_GLASS_PANE, ChatUtil.GREEN + "Frei");
- }
- } else {
- item = GUIUtils.createGuiItem(Material.BARRIER, ChatUtil.RED + "Für diesen Slot brauchst du VIP");
- }
- }
-
- case SAVE_AUTO_INDEX -> {
- if (p.hasPermission("challenge.save.slotauto")) {
- if (adventureSaveAuto.isDirectory()) {
- item = GUIUtils.createGuiItem(Material.CLOCK, ChatUtil.GREEN + "AutoSave", ChatUtil.GREEN + "Klicken zum laden.", ChatUtil.GREEN + "Gespeichert am " + getFileDate(adventureSaveAuto));
- } else {
- item = GUIUtils.createGuiItem(Material.LIME_STAINED_GLASS_PANE, ChatUtil.GREEN + "AutoSave");
- }
- } else {
- item = GUIUtils.createGuiItem(Material.BARRIER, ChatUtil.RED + "Für diesen Slot hast du keine Rechte");
- }
- }
+ case SAVE_1_INDEX -> item = getDisplayItem(player, SaveSlot.SLOT_1, adventureSave1);
+ case SAVE_2_INDEX -> item = getDisplayItem(player, SaveSlot.SLOT_2, adventureSave2);
+ case SAVE_3_INDEX -> item = getDisplayItem(player, SaveSlot.SLOT_3, adventureSave3);
+ case SAVE_AUTO_INDEX -> item = getDisplayItem(player, SaveSlot.SLOT_AUTO, adventureSaveAuto);
default -> item = GUIUtils.EMPTY_ICON;
}
this.getInventory().setItem(i, item);
@@ -204,4 +167,46 @@
}
return StringUtil.formatDate(fileTime.toMillis());
}
+
+ private static ItemStack getDisplayItem(Player player, SaveSlot saveSlot, File save) {
+ ItemStack item;
+ if (player.hasPermission(saveSlot.getPermission())) {
+ if (save.isDirectory()) {
+ File mapConfig = new File(save, "/Challenges/serverconfig.yml");
+ Material displayItem = null;
+ String displayName = null;
+ try {
+ YamlConfiguration serverConfig = new YamlConfiguration();
+ serverConfig.load(mapConfig);
+ String itemType = serverConfig.getString("displayItem.item");
+ String itemName = serverConfig.getString("displayItem.name");
+ if (itemType != null) {
+ try {
+ displayItem = Material.valueOf(itemType);
+ } catch (IllegalArgumentException ignore) {
+ }
+ }
+ if (itemName != null) {
+ displayName = itemName;
+ }
+ } catch (IOException | InvalidConfigurationException ex) {
+ plugin.getLogger().log(Level.SEVERE, "Fehler beim laden der config", ex);
+ }
+
+ ItemStack stack = new ItemStack(displayItem != null ? displayItem : Material.MAP);
+ ItemMeta meta = stack.getItemMeta();
+ meta.setDisplayName(displayName != null ? displayName : ChatUtil.GREEN + "Save " + saveSlot.getSlot());
+ meta.setLore(List.of(ChatUtil.GREEN + "Gespeichert am " + getFileDate(save)));
+ stack.setItemMeta(meta);
+ item = stack;
+
+
+ } else {
+ item = GUIUtils.createGuiItem(Material.LIME_STAINED_GLASS_PANE, ChatUtil.GREEN + "Frei");
+ }
+ } else {
+ item = GUIUtils.createGuiItem(Material.BARRIER, ChatUtil.RED + "Für diesen Slot brauchst du VIP");
+ }
+ return item;
+ }
}