diff --git a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java index 8c0713c..a798f25 100644 --- a/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java +++ b/src/main/java/de/fanta/challengesjoinentities/ChallengesJoinEntities.java @@ -9,6 +9,7 @@ import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureClearSavesCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureConvertMapCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureLoadCommand; +import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureLoadMapIconsCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureMapsCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureTempCommand; import de.fanta.challengesjoinentities.commands.AdventureCommand.AdventureTestMapCommand; @@ -130,6 +131,7 @@ adventurerouter.addCommandMapping(new AdventureTestMapCommand(this), "testmap"); adventurerouter.addCommandMapping(new ChallengesRemovePlayerServer(this), "removeplayerfromserver"); adventurerouter.addCommandMapping(new AdventureConvertMapCommand(this), "convertmap"); + adventurerouter.addCommandMapping(new AdventureLoadMapIconsCommand(this), "loadmapicons"); adventurerouter.addCommandMapping(new AdventureClearSavesCommand(), "clearoldsaves"); adventurerouter.addCommandMapping(new AdventureTempCommand(this), "temp"); diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java index c73d063..fe10f65 100644 --- a/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java +++ b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMap.java @@ -1,11 +1,6 @@ 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; @@ -13,10 +8,15 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + public class AdventureMap { private final ChallengesJoinEntities plugin; private final String name; + private final String version; private final ItemStack item; @@ -24,8 +24,9 @@ private final String webLink; - public AdventureMap(ChallengesJoinEntities plugin, String name, Material material, String creator, String webLink) { + public AdventureMap(ChallengesJoinEntities plugin, String name, String version, Material material, String creator, String webLink) { this.name = name; + this.version = version; this.creator = creator; this.webLink = webLink; this.plugin = plugin; @@ -35,6 +36,7 @@ List lore = new ArrayList<>(); lore.add(""); lore.add(ChatUtil.GREEN + "Erbauer: " + ChatUtil.BLUE + creator); + lore.add(ChatUtil.GREEN + "Version: " + ChatUtil.BLUE + version); lore.add(ChatUtil.GREEN + "MapLink: " + ChatUtil.BLUE + "Rechts Klick"); lore.add(ChatUtil.GREEN + "Map laden: " + ChatUtil.BLUE + "Links Klick"); meta.setLore(lore); @@ -42,13 +44,17 @@ } 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")); + this(plugin, name, section.getString("version"), Material.matchMaterial(Objects.requireNonNull(section.getString("item"))), section.getString("creator"), section.getString("web_link")); } public String getName() { return this.name; } + public String getVersion() { + return version; + } + public ItemStack getItem() { return this.item; } @@ -65,5 +71,6 @@ section.set("item", this.item.getType().getKey().toString()); section.set("creator", this.creator); section.set("web_link", this.webLink); + section.set("version", this.version); } } diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java index 8c05a97..04657c8 100644 --- a/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java +++ b/src/main/java/de/fanta/challengesjoinentities/adventure/AdventureMapsConfig.java @@ -16,28 +16,28 @@ private final Map maps = new HashMap<>(); - private final File file; + private static File file; - private final YamlConfiguration config; + private static YamlConfiguration config; public AdventureMapsConfig(ChallengesJoinEntities plugin) { this.plugin = plugin; - this.file = new File(plugin.getDataFolder(), "adventure_maps.yml"); - this.config = new YamlConfiguration(); + file = new File(plugin.getDataFolder(), "adventure_maps.yml"); + config = new YamlConfiguration(); } private boolean fileExists() throws IOException { - if (!this.file.exists()) - return this.file.createNewFile(); + if (!file.exists()) + return 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); + config.load(file); + config.getKeys(false).forEach(key -> { + ConfigurationSection section = config.getConfigurationSection(key); if (section != null) { AdventureMap map = new AdventureMap(this.plugin, key, section); if (!this.maps.containsKey(key)) { @@ -52,9 +52,9 @@ } public void save() { - this.maps.forEach((key, map) -> map.save(this.config.createSection(key))); + this.maps.forEach((key, map) -> map.save(config.createSection(key))); try { - this.config.save(this.file); + config.save(file); } catch (IOException e) { e.printStackTrace(); } @@ -76,4 +76,12 @@ public AdventureMap getMap(String name) { return this.maps.get(name); } + + public static YamlConfiguration getConfig() { + return config; + } + + public static File getFile() { + return file; + } } diff --git a/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java b/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java index 454e0c3..d77cab0 100644 --- a/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java +++ b/src/main/java/de/fanta/challengesjoinentities/adventure/CategoriesConfig.java @@ -18,28 +18,28 @@ private final Map categories = new HashMap<>(); - private final File file; + private static File file; - private final YamlConfiguration config; + private static YamlConfiguration config; public CategoriesConfig(ChallengesJoinEntities plugin) { this.plugin = plugin; - this.file = new File(plugin.getDataFolder(), "categories.yml"); - this.config = new YamlConfiguration(); + file = new File(plugin.getDataFolder(), "categories.yml"); + config = new YamlConfiguration(); } private boolean fileExists() throws IOException { - if (!this.file.exists()) - return this.file.createNewFile(); + if (!file.exists()) + return 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); + config.load(file); + config.getKeys(false).forEach(key -> { + ConfigurationSection section = config.getConfigurationSection(key); if (section != null) { Category category = new Category(this.plugin, key, section); if (!this.categories.containsKey(key)) @@ -53,9 +53,9 @@ } public void save() { - this.categories.forEach((key, category) -> category.save(this.config.createSection(key))); + this.categories.forEach((key, category) -> category.save(config.createSection(key))); try { - this.config.save(this.file); + config.save(file); } catch (IOException e) { e.printStackTrace(); } @@ -89,4 +89,11 @@ return null; } + public static File getFile() { + return file; + } + + public static YamlConfiguration getConfig() { + return config; + } } diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java index 83b6485..e5f2aa8 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureAddMapCommand.java @@ -49,21 +49,26 @@ 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, "Die map " + name + " existiert bereits!"); + String version = args.getNext(); + if (args.hasNext()) { + String creator = args.getAll(null); + if (creator != null) { + AdventureMap map = new AdventureMap(this.plugin, name, version, item, creator, webLink); + if (!this.config.addMap(map)) { + ChatUtil.sendErrorMessage(sender, "Die map " + name + " existiert bereits!"); + return true; + } + category.addMap(map); + ChatUtil.sendNormalMessage(sender, "Die map " + name + " wurde erfolgreich hinzugefügt!"); return true; } - category.addMap(map); - ChatUtil.sendNormalMessage(sender, "Die map " + name + " wurde erfolgreich hinzugefügt!"); - return true; } } + } } } - return false; + ChatUtil.sendWarningMessage(p, "/adventure addmap "); + return true; } } diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java new file mode 100644 index 0000000..b50c70a --- /dev/null +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureLoadMapIconsCommand.java @@ -0,0 +1,64 @@ +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 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.logging.Level; + +public class AdventureLoadMapIconsCommand extends SubCommand { + private final ChallengesJoinEntities plugin; + + public AdventureLoadMapIconsCommand(ChallengesJoinEntities plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + File adventureCategories = new File("/home/minecraft/Adventure-Maps/"); + File[] categories = adventureCategories.listFiles(); + if (categories != null) { + for (File mapFolder : categories) { + ChatUtil.sendNormalMessage(sender, "- " + mapFolder.getName()); + File[] maps = mapFolder.listFiles(); + if (maps != null) { + for (File map : maps) { + ChatUtil.sendDebugMessage(sender, " - " + map.getName()); + AdventureMap adventureMap = plugin.getAdventureMapsConfig().getMap(map.getName()); + if (adventureMap != null) { + File mapConfig = new File(map, "/Challenges/serverconfig.yml"); + ItemStack stack = adventureMap.getItem(); + ChatUtil.sendWarningMessage(sender, " " + adventureMap.getItem().getType()); + 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! ---"); + } + } else { + ChatUtil.sendErrorMessage(sender, "Map " + map.getName() + " nicht gefunden!"); + } + } + } + } + } + return true; + } + + @Override + public String getRequiredPermission() { + return "challenge.command.loadmapicons"; + } +} diff --git a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java index 7242ed1..0109fa1 100644 --- a/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java +++ b/src/main/java/de/fanta/challengesjoinentities/commands/AdventureCommand/AdventureTempCommand.java @@ -2,15 +2,19 @@ import de.fanta.challengesjoinentities.ChallengesJoinEntities; import de.fanta.challengesjoinentities.ChatUtil; +import de.fanta.challengesjoinentities.adventure.AdventureMapsConfig; +import de.fanta.challengesjoinentities.adventure.CategoriesConfig; 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.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; import java.io.IOException; +import java.util.List; public class AdventureTempCommand extends SubCommand { private final ChallengesJoinEntities plugin; @@ -20,6 +24,50 @@ } public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + FileConfiguration config = AdventureMapsConfig.getConfig(); + FileConfiguration catConfig = CategoriesConfig.getConfig(); + + File adventureCategories = new File("/home/minecraft/Adventure-Maps/"); + File[] categories = adventureCategories.listFiles(); + if (categories != null) { + for (File mapFolder : categories) { + ChatUtil.sendNormalMessage(sender, "- " + mapFolder.getName()); + File[] maps = mapFolder.listFiles(); + if (maps != null) { + for (File map : maps) { + if (config.getKeys(false).contains(map.getName())) { + try { + File mapConfig = new File(map, "/Challenges/serverconfig.yml"); + YamlConfiguration serverConfig = new YamlConfiguration(); + serverConfig.load(mapConfig); + config.set(map.getName() + "." + "version", serverConfig.get("serverversion")); + config.save(AdventureMapsConfig.getFile()); + + List catList = catConfig.getStringList(mapFolder.getName() + "." + "maps"); + if (!catList.contains(map.getName())) { + catList.add(map.getName()); + catConfig.set(mapFolder.getName() + "." + "maps", catList); + catConfig.save(CategoriesConfig.getFile()); + } + + } catch (IOException | InvalidConfigurationException e) { + throw new RuntimeException(e); + } + + } + } + } + } + } + + return true; + } + + + + + + /*public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { File adventureSaves = new File("/home/minecraft/saves/"); File[] players = adventureSaves.listFiles(); @@ -53,7 +101,7 @@ } } return true; - } + }*/ @Override public String getRequiredPermission() { diff --git a/src/main/java/de/fanta/challengesjoinentities/listeners/PlayerListener.java b/src/main/java/de/fanta/challengesjoinentities/listeners/PlayerListener.java index 14392c9..59b8a45 100644 --- a/src/main/java/de/fanta/challengesjoinentities/listeners/PlayerListener.java +++ b/src/main/java/de/fanta/challengesjoinentities/listeners/PlayerListener.java @@ -2,7 +2,11 @@ import de.fanta.challengesjoinentities.ChallengesJoinEntities; import de.fanta.challengesjoinentities.ChatUtil; +import de.iani.cubesideutils.bukkit.plugin.CubesideUtilsBukkit; +import de.iani.cubesideutils.bukkit.plugin.api.UtilsApiBukkit; +import de.iani.cubesideutils.plugin.api.PlayerData; import de.speedy64.globalport.GlobalApi; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -56,6 +60,20 @@ meta.getPersistentDataContainer().set(namespacedKey, PersistentDataType.STRING, "backitem"); itemStack.setItemMeta(meta); e.getPlayer().getInventory().setItem(8, itemStack); + + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> { + PlayerData data = UtilsApiBukkit.getInstance().getPlayerData(e.getPlayer()); + if (data.getLastJoin() + (5 * 1000) > System.currentTimeMillis()) { + String hosteName = CubesideUtilsBukkit.getInstance().getPlayerData(e.getPlayer()).getHostName().toLowerCase(); + if (hosteName.startsWith("challenge")) { + GlobalApi.portOnlinePlayerToLocation(e.getPlayer().getName(), "challenge"); + } else if (hosteName.startsWith("adventure")) { + GlobalApi.portOnlinePlayerToLocation(e.getPlayer().getName(), "adventure"); + } + } + }, 1L); + } @EventHandler