Yet more minor tweaks to signs

This commit is contained in:
ME1312 2022-03-19 13:05:24 -04:00
parent 6fc8732003
commit 249b0a4fab
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8

View File

@ -122,14 +122,15 @@ public class SubSigns implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void create(SignChangeEvent e) { public void create(SignChangeEvent e) {
if (!e.isCancelled() && e.getLine(0).trim().equalsIgnoreCase("[SubServers]") && plugin.lang != null) { if (!e.isCancelled() && e.getLine(0).trim().equalsIgnoreCase("[SubServers]")) {
Player player = e.getPlayer();
String name = e.getLine(1).trim(); String name = e.getLine(1).trim();
if (name.length() > 0 && player.hasPermission("subservers.signs")) { if (name.length() > 0 && plugin.lang != null) {
Location location = e.getBlock().getLocation(); Player player = e.getPlayer();
if (location.getBlock().getState() instanceof Sign) { if (player.hasPermission("subservers.signs")) {
HashMap<Location, Supplier<?>> signs = new HashMap<Location, Supplier<?>>(SubSigns.signs);
Supplier<?> translator = translate(name); Supplier<?> translator = translate(name);
Location location = e.getBlock().getLocation();
HashMap<Location, Supplier<?>> signs = new HashMap<Location, Supplier<?>>(SubSigns.signs);
signs.put(location, translator); signs.put(location, translator);
SubSigns.data.put(new OfflineBlock(location), name); SubSigns.data.put(new OfflineBlock(location), name);
SubSigns.signs = signs; SubSigns.signs = signs;
@ -288,50 +289,53 @@ public class SubSigns implements Listener {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void interact(PlayerInteractEvent e) { public void interact(PlayerInteractEvent e) {
if (!e.isCancelled() && e.getClickedBlock() != null && signs.containsKey(e.getClickedBlock().getLocation()) && plugin.lang != null) { if (!e.isCancelled() && e.getClickedBlock() != null && e.getClickedBlock().getState() instanceof Sign) {
Player player = e.getPlayer(); Supplier<?> translator = signs.get(e.getClickedBlock().getLocation());
if (player.hasPermission("subservers.teleport") && (e.getAction() == Action.RIGHT_CLICK_BLOCK || !player.hasPermission("subservers.signs"))) { if (translator != null && plugin.lang != null) {
Object object = signs.get(e.getClickedBlock().getLocation()).get(); Player player = e.getPlayer();
if (player.hasPermission("subservers.teleport") && (e.getAction() == Action.RIGHT_CLICK_BLOCK || !player.hasPermission("subservers.signs"))) {
Object object = translator.get();
Collection<? extends Server> servers; Collection<? extends Server> servers;
if (object instanceof Server) { if (object instanceof Server) {
servers = Collections.singleton((Server) object); servers = Collections.singleton((Server) object);
} else if (object instanceof Pair) { } else if (object instanceof Pair) {
servers = ((Pair<String, List<Server>>) object).value(); servers = ((Pair<String, List<Server>>) object).value();
} else if (object instanceof Host) { } else if (object instanceof Host) {
servers = ((Host) object).getSubServers().values(); servers = ((Host) object).getSubServers().values();
} else { } else {
return; return;
} }
Text incoming, state = Text.UNKNOWN; Text incoming, state = Text.UNKNOWN;
List<Server> selected = new ArrayList<>(); List<Server> selected = new ArrayList<>();
for (Server server : servers) { for (Server server : servers) {
incoming = Text.determine(server); incoming = Text.determine(server);
if (incoming != Text.STOPPING) { if (incoming != Text.STOPPING) {
if (incoming == Text.OFFLINE) { if (incoming == Text.OFFLINE) {
SubServer subserver = (SubServer) server; SubServer subserver = (SubServer) server;
if (!(subserver.isEnabled() && subserver.isAvailable() && subserver.getCurrentIncompatibilities().size() == 0)) continue; if (!(subserver.isEnabled() && subserver.isAvailable() && subserver.getCurrentIncompatibilities().size() == 0)) continue;
} }
if (incoming.priority > state.priority) { if (incoming.priority > state.priority) {
selected.clear(); selected.clear();
state = incoming; state = incoming;
} }
if (incoming == state) { if (incoming == state) {
selected.add(server); selected.add(server);
}
} }
} }
}
if (selected.size() > 0) { if (selected.size() > 0) {
Server server = selected.get(new Random().nextInt(selected.size())); Server server = selected.get(new Random().nextInt(selected.size()));
if (state == Text.OFFLINE) { if (state == Text.OFFLINE) {
((SubServer) server).start(); ((SubServer) server).start();
} else { } else {
player.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$name$", player.getName()).replace("$str$", server.getDisplayName())); player.sendMessage(plugin.api.getLang("SubServers", "Command.Teleport").replace("$name$", player.getName()).replace("$str$", server.getDisplayName()));
plugin.pmc(player, "Connect", server.getName()); plugin.pmc(player, "Connect", server.getName());
}
} }
} }
} }
@ -342,7 +346,7 @@ public class SubSigns implements Listener {
public void delete(BlockBreakEvent e) { public void delete(BlockBreakEvent e) {
if (!e.isCancelled() && e.getBlock().getState() instanceof Sign && signs.containsKey(e.getBlock().getLocation())) { if (!e.isCancelled() && e.getBlock().getState() instanceof Sign && signs.containsKey(e.getBlock().getLocation())) {
Player player = e.getPlayer(); Player player = e.getPlayer();
if (plugin.lang != null && player.hasPermission("subservers.signs")) { if (player.hasPermission("subservers.signs") && plugin.lang != null) {
Location location = e.getBlock().getLocation(); Location location = e.getBlock().getLocation();
String name = data.remove(new OfflineBlock(location)); String name = data.remove(new OfflineBlock(location));
if (name != null) locations.remove(name.toLowerCase()); if (name != null) locations.remove(name.toLowerCase());