Skip to content

Commit

Permalink
fix actionbar when linked worlds disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Le4nderS committed Nov 21, 2023
1 parent 111e495 commit c74f495
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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() {
Expand All @@ -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"));
}
}

Expand Down

0 comments on commit c74f495

Please sign in to comment.