From c74f495aec480375835aa2e4a3de07721d1b7d45 Mon Sep 17 00:00:00 2001 From: Leander <47365075+Le4nderS@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:30:52 +0100 Subject: [PATCH] fix actionbar when linked worlds disabled --- .../commands/OffsetCommand.java | 2 +- .../events/PlayerMoveEvent.java | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/btegermany/terraplusminus/commands/OffsetCommand.java b/src/main/java/de/btegermany/terraplusminus/commands/OffsetCommand.java index 1e38049..0a457f4 100644 --- a/src/main/java/de/btegermany/terraplusminus/commands/OffsetCommand.java +++ b/src/main/java/de/btegermany/terraplusminus/commands/OffsetCommand.java @@ -15,7 +15,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command return true; } Player player = (Player) commandSender; - if (player.hasPermission("t+-.offset")) { + if (!player.hasPermission("t+-.offset")) { player.sendMessage(Terraplusminus.config.getString("prefix") + "§7No permission for /offset"); return true; } diff --git a/src/main/java/de/btegermany/terraplusminus/events/PlayerMoveEvent.java b/src/main/java/de/btegermany/terraplusminus/events/PlayerMoveEvent.java index 8368eb6..787f440 100644 --- a/src/main/java/de/btegermany/terraplusminus/events/PlayerMoveEvent.java +++ b/src/main/java/de/btegermany/terraplusminus/events/PlayerMoveEvent.java @@ -19,6 +19,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.logging.Level; + +import static java.lang.String.valueOf; +import static org.bukkit.ChatColor.BOLD; public class PlayerMoveEvent implements Listener { @@ -44,23 +48,27 @@ public PlayerMoveEvent(Plugin plugin) { this.zOffset = Terraplusminus.config.getInt("terrain_offset.z"); this.linkedWorldsEnabled = Terraplusminus.config.getBoolean("linked_worlds.enabled"); this.linkedWorldsMethod = Terraplusminus.config.getString("linked_worlds.method"); - this.worlds = ConfigurationHelper.getWorlds(); this.worldHashMap = new HashMap<>(); if (this.linkedWorldsEnabled && this.linkedWorldsMethod.equalsIgnoreCase("MULTIVERSE")) { + this.worlds = ConfigurationHelper.getWorlds(); for (LinkedWorld world : worlds) { this.worldHashMap.put(world.getWorldName(), world.getOffset()); } - } else { - for (World world : Bukkit.getWorlds()) { + Bukkit.getLogger().log(Level.INFO, "[T+-] Linked worlds enabled, using Multiverse method."); + } /* + else { + for (World world : Bukkit.getServer().getWorlds()) { // plugin loaded before worlds initialized, so that does not work this.worldHashMap.put(world.getName(), yOffsetConfigEntry); } } + */ this.startKeepActionBarAlive(); } @EventHandler void onPlayerMove(org.bukkit.event.player.PlayerMoveEvent event) { - setHeightInActionBar(event.getPlayer()); + Player player = event.getPlayer(); + setHeightInActionBar(player); } private void startKeepActionBarAlive() { @@ -72,9 +80,10 @@ private void startKeepActionBarAlive() { } private void setHeightInActionBar(Player p) { + worldHashMap.putIfAbsent(p.getWorld().getName(), yOffsetConfigEntry); if (p.getInventory().getItemInMainHand().getType() != Material.DEBUG_STICK) { int height = p.getLocation().getBlockY() - worldHashMap.get(p.getWorld().getName()); - p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("§l" + height + "m")); + p.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(BOLD + valueOf(height) + "m")); } }