diff --git a/src/main/java/de/j/deathMinigames/dmUtil/DmUtil.java b/src/main/java/de/j/deathMinigames/dmUtil/DmUtil.java index bcc89b0b..2718cd89 100644 --- a/src/main/java/de/j/deathMinigames/dmUtil/DmUtil.java +++ b/src/main/java/de/j/deathMinigames/dmUtil/DmUtil.java @@ -1,16 +1,17 @@ package de.j.deathMinigames.dmUtil; -import de.j.deathMinigames.main.Config; import de.j.deathMinigames.main.HandlePlayers; import de.j.deathMinigames.main.PlayerData; -import de.j.stationofdoom.main.Main; +import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.entity.Item; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; public class DmUtil { private static DmUtil instance; diff --git a/src/main/java/de/j/deathMinigames/dmUtil/TestCMD.java b/src/main/java/de/j/deathMinigames/dmUtil/TestCMD.java deleted file mode 100644 index d5e10d00..00000000 --- a/src/main/java/de/j/deathMinigames/dmUtil/TestCMD.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.j.deathMinigames.dmUtil; - -import io.papermc.paper.command.brigadier.BasicCommand; -import io.papermc.paper.command.brigadier.CommandSourceStack; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class TestCMD implements BasicCommand { - - /** - * Determines if the given command sender can use this command. - * - *

This command can only be used by {@link Player}s. - * - * @param sender the command sender to check - * @return true if the command sender can use this command, false otherwise - */ - @Override - public boolean canUse(@NotNull CommandSender sender) { - return sender instanceof Player; - } - - /** - * Executes the command for the given command source stack. - * - *

- * This method retrieves the player from the command source stack and sends a test message followed by the - * database connection information. Each key-value pair in the connection info is sent as a message to the player. - * - * @param stack the command source stack - * @param args the arguments provided with the command - */ - @Override - public void execute(@NotNull CommandSourceStack stack, @NotNull String[] args) { - Player player = (Player) stack.getSender(); - player.sendMessage("test"); - } -} diff --git a/src/main/java/de/j/deathMinigames/listeners/AnvilListener.java b/src/main/java/de/j/deathMinigames/listeners/AnvilListener.java new file mode 100644 index 00000000..7218257b --- /dev/null +++ b/src/main/java/de/j/deathMinigames/listeners/AnvilListener.java @@ -0,0 +1,118 @@ +package de.j.deathMinigames.listeners; + +import de.j.deathMinigames.dmUtil.DmUtil; +import de.j.deathMinigames.settings.MainMenu; +import de.j.stationofdoom.main.Main; +import de.j.stationofdoom.util.Tablist; +import de.j.stationofdoom.util.translations.TranslationFactory; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.inventory.PrepareAnvilEvent; +import org.bukkit.inventory.AnvilInventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.view.AnvilView; + +public class AnvilListener implements Listener { + private String serverName; + private String hostName; + private TranslationFactory tf = new TranslationFactory(); + + @EventHandler + public void onAnvilPrepare(PrepareAnvilEvent event) { + if(!(event.getViewers().getFirst() instanceof Player player)) { + Main.getMainLogger().warning("Anvil prepare event has invalid viewer type"); + return; + } + Location loc = event.getInventory().getLocation(); + if(loc == null) { + Main.getMainLogger().warning("Anvil prepare event has no location"); + return; + } + AnvilView anvilView = event.getView(); + if(anvilView == null) { + Main.getMainLogger().warning("Anvil prepare event has no anvilView"); + return; + } + String renameText = anvilView.getRenameText(); + if(MainMenu.getSetHost().compareLocIDTo(loc)) { + finishAnvilInvAfterOpening(event, player); + if(renameText == null) return; + hostName = renameText; + } + else if(MainMenu.getSetServerName().compareLocIDTo(loc)) { + finishAnvilInvAfterOpening(event, player); + if(renameText == null) return; + serverName = renameText; + } + } + + @EventHandler + public void onAnvilClick(InventoryClickEvent event) { + if(event.getInventory().getType() == InventoryType.ANVIL) { + Location loc = event.getInventory().getLocation(); + if (loc == null) return; + Player player = (Player) event.getWhoClicked(); + if(player == null) return; + if(event.getSlot() != 2) return; + if (MainMenu.getSetHost().compareLocIDTo(loc)) { + event.setCancelled(true); + if (hostName == null) return; + Tablist.setHostedBy(hostName); + event.getView().close(); + DmUtil.getInstance().playSoundAtLocation(player.getLocation(), 0.5f, Sound.BLOCK_ANVIL_USE); + player.sendMessage(Component.text("Host name: " + hostName).color(NamedTextColor.GOLD)); + } else if (MainMenu.getSetServerName().compareLocIDTo(loc)) { + event.setCancelled(true); + if (serverName == null) return; + Tablist.setServerName(serverName); + event.getView().close(); + DmUtil.getInstance().playSoundAtLocation(player.getLocation(), 0.5f, Sound.BLOCK_ANVIL_USE); + player.sendMessage(Component.text("Server name: " + serverName).color(NamedTextColor.GOLD)); + } + + } + } + + @EventHandler + public void onAnvilClose(InventoryCloseEvent event) { + if(event.getInventory().getType() == InventoryType.ANVIL) { + Location loc = event.getInventory().getLocation(); + if(loc == null) return; + AnvilInventory anvilInventory = (AnvilInventory) event.getView().getTopInventory(); + if(MainMenu.getSetHost().compareLocIDTo(loc)) { + anvilInventory.clear(); + } + else if(MainMenu.getSetServerName().compareLocIDTo(loc)) { + anvilInventory.clear(); + } + } + } + + private void finishAnvilInvAfterOpening(PrepareAnvilEvent event, Player player) { + if(event == null || player == null) { + Main.getMainLogger().warning("parameters are null: " + event + " " + player + "!"); + return; + } + ItemStack output = new ItemStack(Material.GREEN_CONCRETE); + ItemMeta outputItemMeta = output.getItemMeta(); + if(outputItemMeta == null) { + Main.getMainLogger().warning("outputItemMeta is null!"); + return; + } + outputItemMeta.displayName(Component.text(tf.getTranslation(player, "anvilOutput"))); + output.setItemMeta(outputItemMeta); + event.setResult(output); + + event.getView().setRepairCost(0); + } +} diff --git a/src/main/java/de/j/deathMinigames/listeners/InventoryListener.java b/src/main/java/de/j/deathMinigames/listeners/InventoryListener.java index 359a44a8..f0168023 100755 --- a/src/main/java/de/j/deathMinigames/listeners/InventoryListener.java +++ b/src/main/java/de/j/deathMinigames/listeners/InventoryListener.java @@ -1,7 +1,9 @@ package de.j.deathMinigames.listeners; +import de.j.deathMinigames.dmUtil.DmUtil; import de.j.deathMinigames.main.HandlePlayers; import de.j.deathMinigames.main.PlayerData; +import de.j.deathMinigames.settings.AnvilUI; import de.j.deathMinigames.settings.MainMenu.InventoryMenus; import de.j.stationofdoom.util.translations.TranslationFactory; import net.kyori.adventure.text.Component; @@ -13,12 +15,16 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.inventory.InventoryHolder; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.event.inventory.PrepareAnvilEvent; +import org.bukkit.inventory.*; import de.j.deathMinigames.main.Config; import de.j.stationofdoom.main.Main; import de.j.deathMinigames.minigames.Minigame; import de.j.deathMinigames.settings.GUI; import de.j.deathMinigames.settings.MainMenu; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.view.AnvilView; import java.util.HashMap; import java.util.UUID; @@ -37,7 +43,6 @@ public void onSettingsClick(InventoryClickEvent event) { MainMenu mainMenu = new MainMenu(); InventoryHolder invHolder = event.getInventory().getHolder(); Minigame minigame = Minigame.getInstance(); - UUID ID; int slot = event.getSlot(); if(slot < 0) { @@ -245,6 +250,12 @@ private void handleMainMenuGUI(InventoryClickEvent event, Player player, MainMen MainMenu.getDifficulty().addBackButton(player); MainMenu.getDifficulty().showInventory(player); break; + case 4: + MainMenu.getSetHost().showInventory(player); + break; + case 5: + MainMenu.getSetServerName().showInventory(player); + break; } } diff --git a/src/main/java/de/j/deathMinigames/main/Config.java b/src/main/java/de/j/deathMinigames/main/Config.java index 43675485..e9467aed 100644 --- a/src/main/java/de/j/deathMinigames/main/Config.java +++ b/src/main/java/de/j/deathMinigames/main/Config.java @@ -1,12 +1,11 @@ package de.j.deathMinigames.main; -import de.j.deathMinigames.database.PlayerDataDatabase; +import de.j.stationofdoom.util.Tablist; import org.bukkit.Location; import de.j.stationofdoom.main.Main; import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import java.util.*; @@ -115,6 +114,15 @@ public void cloneConfigToPlugin() { config.set("Database.schema", "public"); Main.getPlugin().saveConfig(); } + //Tablist + if(config.contains("Tablist")) { + if(config.contains("Tablist.ServerName") && config.get("Tablist.ServerName") != null) { + Tablist.setServerName(config.getString("Tablist.ServerName")); + } + if(config.contains("Tablist.HostedBy") && config.get("Tablist.HostedBy") != null) { + Tablist.setHostedBy(config.getString("Tablist.HostedBy")); + } + } } public void cloneWaitingListLocationToPlugin(World world) { @@ -195,7 +203,6 @@ public synchronized void setCostToLowerTheDifficulty(int cost) { * @param time The time limit for minigame decision in seconds to be set. */ public synchronized void setTimeToDecideWhenRespawning(int time) { - configTimeToDecideWhenRespawning = time; Main.getPlugin().getConfig().set("TimeToDecideWhenRespawning", time); Main.getPlugin().saveConfig(); @@ -313,4 +320,46 @@ public HashMap getDatabaseConfig() { } return databaseConnectionInfo; } + + public synchronized void setServerName(String serverName) { + if(serverName == null) { + Main.getMainLogger().warning("ServerName is null!"); + return; + } + if(!Main.getPlugin().getConfig().contains("Tablist.ServerName")) { + Main.getPlugin().getConfig().set("Tablist.ServerName", serverName); + Main.getPlugin().saveConfig(); + } + else if(!Main.getPlugin().getConfig().getString("Tablist.ServerName").equals(serverName)) { + Main.getPlugin().getConfig().set("Tablist.ServerName", serverName); + Main.getPlugin().saveConfig(); + } + } + + public String getServerName() { + if(Main.getPlugin().getConfig().contains("Tablist.ServerName")) { + return Main.getPlugin().getConfig().getString("Tablist.ServerName"); + } + else { + Main.getMainLogger().warning("ServerName not found in config!"); + return null; + } + } + + public synchronized void setHostedBy(String serverName) { + if(!Main.getPlugin().getConfig().contains("Tablist.HostedBy") || !Main.getPlugin().getConfig().getString("Tablist.HostedBy").equals(serverName)) { + Main.getPlugin().getConfig().set("Tablist.HostedBy", serverName); + Main.getPlugin().saveConfig(); + } + } + + public String getHostedBy() { + if(Main.getPlugin().getConfig().contains("Tablist.HostedBy")) { + return Main.getPlugin().getConfig().getString("Tablist.HostedBy"); + } + else { + Main.getMainLogger().warning("HostedBy not found in config!"); + return null; + } + } } diff --git a/src/main/java/de/j/deathMinigames/settings/AnvilUI.java b/src/main/java/de/j/deathMinigames/settings/AnvilUI.java new file mode 100644 index 00000000..a3e5ef2c --- /dev/null +++ b/src/main/java/de/j/deathMinigames/settings/AnvilUI.java @@ -0,0 +1,82 @@ +package de.j.deathMinigames.settings; + +import de.j.stationofdoom.util.Tablist; +import de.j.stationofdoom.util.translations.TranslationFactory; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.ThreadLocalRandom; + +public class AnvilUI implements InventoryHolder { + private Location loc = null; + private ItemStack input = new ItemStack(Material.RED_CONCRETE); + Player player = null; + private MainMenu.AnvilUIs title; + + public AnvilUI(MainMenu.AnvilUIs title) { + if(title == null) throw new IllegalArgumentException("Title cannot be null"); + this.title = title; + createUniqueLocation(); + } + + public void showInventory(Player playerToShowTheInvTo) { + if(playerToShowTheInvTo == null) return; + this.player = playerToShowTheInvTo; + playerToShowTheInvTo.openAnvil(loc, true); + setInputMeta(playerToShowTheInvTo); + playerToShowTheInvTo.getOpenInventory().getTopInventory().setItem(0, input); + } + + @Override + public @NotNull Inventory getInventory() { + return null; + } + + /** + * Random location used as a unique identifier for the anvil UI. + * This prevents conflicts between multiple anvil UIs. + */ + private void createUniqueLocation() { + World world = Bukkit.getWorld("world"); + if(world == null) throw new IllegalStateException("world `world´ could not be found"); + loc = new Location(world, + ThreadLocalRandom.current().nextInt(0, 1000), + ThreadLocalRandom.current().nextInt(0, 1000), + ThreadLocalRandom.current().nextInt(0, 1000)); + } + + public boolean compareLocIDTo(Location loc) { + return loc.getBlockX() == this.loc.getBlockX() && loc.getBlockZ() == this.loc.getBlockZ(); + } + + private void setInputMeta(Player player) { + ItemMeta inputMeta = input.getItemMeta(); + String inputItemName = null; + if(player == null) { + inputMeta.displayName(Component.text("default")); + } + else { + switch (title) { + case SET_HOST_NAME -> inputItemName = Tablist.getHostedBy(); + case SET_SERVER_NAME -> inputItemName = Tablist.getServerName(); + default -> throw new IllegalArgumentException("Title: " + title + " is not supported"); + } + if(inputItemName == null) { + inputMeta.displayName(Component.text(new TranslationFactory().getTranslation(player, "noNameSet"))); + } + else { + inputMeta.displayName(Component.text(inputItemName)); + } + } + input.setItemMeta(inputMeta); + } +} diff --git a/src/main/java/de/j/deathMinigames/settings/GUI.java b/src/main/java/de/j/deathMinigames/settings/GUI.java index 5430015e..f0a6908c 100755 --- a/src/main/java/de/j/deathMinigames/settings/GUI.java +++ b/src/main/java/de/j/deathMinigames/settings/GUI.java @@ -59,7 +59,6 @@ public void addPlayerHeads(HashMap knownPlayers) { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta skullMeta = (SkullMeta) head.getItemMeta(); skullMeta.setOwnerProfile(Bukkit.createProfile(playerData.getUUID())); - Main.getMainLogger().info("Skull has owner: " + skullMeta.hasOwner()); skullMeta.displayName(Component.text(playerData.getName())); head.setItemMeta(skullMeta); diff --git a/src/main/java/de/j/deathMinigames/settings/MainMenu.java b/src/main/java/de/j/deathMinigames/settings/MainMenu.java index 083d864d..74bf6e73 100755 --- a/src/main/java/de/j/deathMinigames/settings/MainMenu.java +++ b/src/main/java/de/j/deathMinigames/settings/MainMenu.java @@ -1,5 +1,6 @@ package de.j.deathMinigames.settings; +import de.j.stationofdoom.main.Main; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -25,7 +26,15 @@ public enum InventoryMenus { PARKOUR_START_HEIGHT, PARKOUR_LENGTH, COST_TO_LOWER_THE_DIFFICULTY, - TIME_TO_DECIDE_WHEN_RESPAWNING + TIME_TO_DECIDE_WHEN_RESPAWNING, + SET_HOST, + SET_SERVER_NAME + } + + public enum AnvilUIs { + SET_SERVER_NAME, + SET_HOST_NAME, + DEFAULT // usage when the input slot item should have no name } public MainMenu() { @@ -68,6 +77,14 @@ public synchronized static GUI getTimeToDecideWhenRespawning() { return timeToDecideWhenRespawning; } + public synchronized static AnvilUI getSetHost() { + return setHost; + } + + public synchronized static AnvilUI getSetServerName() { + return setServerName; + } + private static final GUI introduction = new GUI("Introduction", true, false); private static final GUI difficulty = new GUI("Difficulty", true, true); private static final GUI usesPlugin = new GUI("UsesPlugin", true, false); @@ -77,6 +94,8 @@ public synchronized static GUI getTimeToDecideWhenRespawning() { private static final GUI parkourLength = new GUI("ParkourLength", false, false); private static final GUI costToLowerTheDifficulty = new GUI("CostToLowerTheDifficulty", false, false); private static final GUI timeToDecideWhenRespawning = new GUI("TimeToDecideWhenRespawning", false, false); + private static final AnvilUI setHost = new AnvilUI(AnvilUIs.SET_HOST_NAME); + private static final AnvilUI setServerName = new AnvilUI(AnvilUIs.SET_SERVER_NAME); /** * Opens the main menu for the given player, where the player can @@ -108,6 +127,8 @@ private void addSubmenus() { addClickableItemStack("Introduction", Material.GREEN_CONCRETE, 1, 1); addClickableItemStack("UsesPlugin", Material.GREEN_CONCRETE, 1, 2); addClickableItemStack("Difficulty", Material.RED_CONCRETE, 1, 3); + addClickableItemStack("SetHost", Material.BOOK, 1, 4); + addClickableItemStack("SetServerName", Material.BOOK, 1, 5); } /** diff --git a/src/main/java/de/j/stationofdoom/listener/PlayerJoin.java b/src/main/java/de/j/stationofdoom/listener/PlayerJoin.java index 5431c776..09b18c8d 100644 --- a/src/main/java/de/j/stationofdoom/listener/PlayerJoin.java +++ b/src/main/java/de/j/stationofdoom/listener/PlayerJoin.java @@ -12,11 +12,11 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.checkerframework.common.aliasing.qual.Unique; import java.io.IOException; import java.util.UUID; @@ -70,14 +70,26 @@ public void onPlayerJoin(PlayerJoinEvent event) { AtomicInteger phase = new AtomicInteger(); asyncScheduler.runAtFixedRate(Main.getPlugin(), scheduledTask -> { int ping = player.getPing(); - tablist.tabTPS(player, mm.deserialize(" StationOfDoom "), - mm.deserialize(" Hosted by LuckyProgrammer Plugin by LuckyProgrammer") - .append(Component.text(String.format("\nTPS: %s; %s; %s", (int) Main.getPlugin().getServer().getTPS()[0], (int) Main.getPlugin().getServer().getTPS()[1], (int) Main.getPlugin().getServer().getTPS()[2]), NamedTextColor.LIGHT_PURPLE)) - .append(Component.text("\n Ping: ") - .append(Component.text(String.valueOf(ping)) - .color(ping > 30 ? NamedTextColor.RED : NamedTextColor.GREEN))) - .append(Component.text("\n") - .append(tablist.getTimeComponent(player)))); + if(Tablist.getHostedBy() == null) { + tablist.tabTPS(player, mm.deserialize(" <1> ", Placeholder.component("1", Component.text(Tablist.getServerName()))), + mm.deserialize(" Plugin by LuckyProgrammer") + .append(Component.text(String.format("\nTPS: %s; %s; %s", (int) Main.getPlugin().getServer().getTPS()[0], (int) Main.getPlugin().getServer().getTPS()[1], (int) Main.getPlugin().getServer().getTPS()[2]), NamedTextColor.LIGHT_PURPLE)) + .append(Component.text("\n Ping: ") + .append(Component.text(String.valueOf(ping)) + .color(ping > 30 ? NamedTextColor.RED : NamedTextColor.GREEN))) + .append(Component.text("\n") + .append(tablist.getTimeComponent(player)))); + } + else { + tablist.tabTPS(player, mm.deserialize(" <1> ", Placeholder.component("1", Component.text(Tablist.getServerName()))), + mm.deserialize(" Hosted by <2> Plugin by LuckyProgrammer", Placeholder.component("2", Component.text(Tablist.getHostedBy()))) + .append(Component.text(String.format("\nTPS: %s; %s; %s", (int) Main.getPlugin().getServer().getTPS()[0], (int) Main.getPlugin().getServer().getTPS()[1], (int) Main.getPlugin().getServer().getTPS()[2]), NamedTextColor.LIGHT_PURPLE)) + .append(Component.text("\n Ping: ") + .append(Component.text(String.valueOf(ping)) + .color(ping > 30 ? NamedTextColor.RED : NamedTextColor.GREEN))) + .append(Component.text("\n") + .append(tablist.getTimeComponent(player)))); + } phase.getAndIncrement(); if (phase.get() >= 14) { phase.set(0); diff --git a/src/main/java/de/j/stationofdoom/main/Main.java b/src/main/java/de/j/stationofdoom/main/Main.java index 92f7cb71..2b799252 100755 --- a/src/main/java/de/j/stationofdoom/main/Main.java +++ b/src/main/java/de/j/stationofdoom/main/Main.java @@ -2,7 +2,6 @@ import de.j.deathMinigames.commands.GameCMD; import de.j.deathMinigames.commands.LeaderboardCMD; -import de.j.deathMinigames.dmUtil.TestCMD; import de.j.deathMinigames.listeners.*; import de.j.deathMinigames.main.Config; import de.j.deathMinigames.database.Database; @@ -24,7 +23,6 @@ import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import org.bukkit.Bukkit; -import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -89,7 +87,6 @@ public void onEnable() { COMMANDS.register("voterestart", new VoteRestartCMD()); COMMANDS.register("sit", new PlayerSitListener()); COMMANDS.register("game", "game related commands", new GameCMD()); - COMMANDS.register("test", "testing", new TestCMD()); COMMANDS.register("leaderboard", "showing the leaderboard of the minigame", new LeaderboardCMD()); }); @@ -115,6 +112,7 @@ public void onEnable() { pluginManager.registerEvents(new InventoryListener(), this); pluginManager.registerEvents(new InitWaitingListLocationOnJoin(), this); pluginManager.registerEvents(new LeaveListener(), this); + pluginManager.registerEvents(new AnvilListener(), this); //CustomEnchants.register(); -> see custom enchants class for more info diff --git a/src/main/java/de/j/stationofdoom/util/Tablist.java b/src/main/java/de/j/stationofdoom/util/Tablist.java index ca205b08..b6ff7e11 100644 --- a/src/main/java/de/j/stationofdoom/util/Tablist.java +++ b/src/main/java/de/j/stationofdoom/util/Tablist.java @@ -1,5 +1,6 @@ package de.j.stationofdoom.util; +import de.j.deathMinigames.main.Config; import de.j.stationofdoom.main.Main; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; @@ -16,6 +17,8 @@ import java.util.stream.Stream; public class Tablist { + private volatile static String serverName = Bukkit.getServer().getName(); + private volatile static String hostedBy = null; private static Scoreboard scoreboard; public static HashMap rank; @@ -158,4 +161,31 @@ public Component getTimeComponent(Player player) { String formattedTime = String.format("%02d:%02d", (int) time, (int) ((time % 1) * 60)); return Component.text(formattedTime).color(NamedTextColor.GOLD); } + + public static String getServerName() { + return serverName; + } + + public static void setServerName(String serverName) { + Tablist.serverName = serverName; + if(Config.getInstance().getServerName() == null) Config.getInstance().setServerName(serverName); + else if(!Config.getInstance().getServerName().equals(serverName)) { + Config.getInstance().setServerName(serverName); + } + } + + public static void setHostedBy(String hostedBy) { + if(hostedBy == null) { + Main.getMainLogger().warning("Hosted by is null"); + return; + } + Tablist.hostedBy = hostedBy; + if(Config.getInstance().getHostedBy() == null || !Config.getInstance().getHostedBy().equals(hostedBy)) { + Config.getInstance().setHostedBy(hostedBy); + } + } + + public static String getHostedBy() { + return hostedBy; + } } diff --git a/src/main/resources/translations.json b/src/main/resources/translations.json index 6056dd68..03f7afb4 100755 --- a/src/main/resources/translations.json +++ b/src/main/resources/translations.json @@ -81,7 +81,9 @@ "newRecord": "Du hast deine alte Rekordzeit um %ss verbessert!", "cmdUsageLength1": "Dein Command hat nicht geklappt, versuche /game ", "somethingWentWrong": "Etwas ist schief gelaufen", - "invalidDifficulty": "Die Schwierigkeit muss zwischen 0 und 10 sein" + "invalidDifficulty": "Die Schwierigkeit muss zwischen 0 und 10 sein", + "anvilOutput": "klicke hier um zu bestätigen", + "noNameSet": "kein Name gesetzt" } ], "en-US": [ @@ -166,7 +168,9 @@ "newRecord": "You beat your old record by %ss!", "cmdUsageLength1": "Your command did not work, try /game ", "somethingWentWrong": "Something went wrong", - "invalidDifficulty": "The difficulty has to be between 0 and 10" + "invalidDifficulty": "The difficulty has to be between 0 and 10", + "anvilOutput": "Click here to accept", + "noNameSet": "No name set" } ] } \ No newline at end of file