Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ void load(String player, String serial) {
* @param value New value
*/
public void setValue(UUID player, T value) {
T oldValue = getValue(player);
values.put(player, value);
if (listeners != null) {
T oldValue = getValue(player);
for (SettingChangeListener<T> listener : listeners) {
listener.handle(player, this, oldValue, value);

}
}
values.put(player, value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.bukkit.event.Listener;
import sh.okx.railswitch.commands.DestinationCommand;
import sh.okx.railswitch.glue.CitadelGlue;
import sh.okx.railswitch.settings.SettingsListener;
import sh.okx.railswitch.settings.SettingsManager;
import sh.okx.railswitch.switches.SwitchListener;
import vg.civcraft.mc.civmodcore.ACivMod;
Expand All @@ -21,6 +22,7 @@ public void onEnable() {
SettingsManager.init(this);
registerListener(new CitadelGlue(this));
registerListener(new SwitchListener());
registerListener(new SettingsListener());
commandManager = new CommandManager(this);
commandManager.init();
commandManager.registerCommand(new DestinationCommand());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.base.Strings;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import vg.civcraft.mc.civmodcore.players.settings.impl.StringSetting;
Expand All @@ -23,5 +24,4 @@ public String toText(String value) {
}
return value;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package sh.okx.railswitch.settings;

import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import static sh.okx.railswitch.settings.SettingsManager.updateDestScoreboardHud;

public class SettingsListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent pje) {
updateDestScoreboardHud(pje.getPlayer());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import sh.okx.railswitch.RailSwitchPlugin;
import vg.civcraft.mc.civmodcore.players.scoreboard.bottom.BottomLine;
import vg.civcraft.mc.civmodcore.players.scoreboard.bottom.BottomLineAPI;
import vg.civcraft.mc.civmodcore.players.scoreboard.side.CivScoreBoard;
import vg.civcraft.mc.civmodcore.players.scoreboard.side.ScoreBoardAPI;
import vg.civcraft.mc.civmodcore.players.settings.PlayerSetting;
import vg.civcraft.mc.civmodcore.players.settings.impl.DisplayLocationSetting;

/**
* Manages the initialisation and registration of menu settings.
Expand All @@ -16,6 +25,10 @@ public final class SettingsManager {
private static DestinationSetting destSetting;

private static ResetSetting resetSetting;
private static DisplayLocationSetting destDisplayLocation;

private static CivScoreBoard destScoreBoard;
private static BottomLine destBottomLine;

/**
* Initialise the settings manager. This should only be called within RailSwitch onEnable().
Expand All @@ -27,10 +40,33 @@ public static void init(RailSwitchPlugin plugin) {
menu = new RailSwitchMenu();
destSetting = new DestinationSetting(plugin);
resetSetting = new ResetSetting(plugin, destSetting);
destDisplayLocation = new DisplayLocationSetting(plugin, DisplayLocationSetting.DisplayLocation.SIDEBAR,
"Dest Display Location", "destDisplayLocation", new ItemStack(Material.ARROW), "destination");

// Register those elements
menu.registerToParentMenu();
menu.registerSetting(destSetting);
menu.registerSetting(resetSetting);
Comment thread
Huskydog9988 marked this conversation as resolved.
menu.registerSetting(destDisplayLocation);

destScoreBoard = ScoreBoardAPI.createBoard("RailSwitchDestDisplay");
destBottomLine = BottomLineAPI.createBottomLine("RailSwitchDestDisplay", 4);

// update player ui if dest setting is changed
destSetting.registerListener((UUID uuid, PlayerSetting<String> setting, String oldValue, String newValue) -> {
Player player = plugin.getServer().getPlayer(uuid);
if (player != null) {
updateDestScoreboardHud(player);
}
});

// update player ui if scoreboard display location setting is changed
destDisplayLocation.registerListener((UUID uuid, PlayerSetting<String> setting, String oldValue, String newValue) -> {
Player player = plugin.getServer().getPlayer(uuid);
if (player != null) {
updateDestScoreboardHud(player);
}
});
}

/**
Expand Down Expand Up @@ -82,4 +118,26 @@ public static String getDestination(Player player) {
return value;
}

public static void updateDestScoreboardHud(Player p) {
String dest = getDestination(p);
if (Strings.isNullOrEmpty(dest)) {
// remove if dest is empty
destScoreBoard.hide(p);
destBottomLine.removePlayer(p);
} else {
// set dest on hud
if (destDisplayLocation.showOnSidebar(p.getUniqueId())) {
destScoreBoard.set(p, ChatColor.GOLD + "Dest: " + ChatColor.AQUA + dest);
} else {
// remove if disabled as the dest might still be showing on the sidebar from before
destScoreBoard.hide(p);
}
if (destDisplayLocation.showOnActionbar(p.getUniqueId())) {
destBottomLine.updatePlayer(p, ChatColor.GOLD + "Dest: " + ChatColor.AQUA + dest);
} else {
// remove if disabled as the dest might still be showing on the actionbar from before
destBottomLine.removePlayer(p);
}
}
}
}
Loading