mirror of
https://github.com/kaboomserver/extras.git
synced 2024-10-31 16:59:24 +00:00
Refactor static final fields in PlayerPrefix module to be consistent
This commit is contained in:
parent
4183481143
commit
d68dfb5b01
|
@ -23,14 +23,14 @@ import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class PlayerPrefix implements Listener {
|
public final class PlayerPrefix implements Listener {
|
||||||
private static final Main plugin = JavaPlugin.getPlugin(Main.class);
|
private static final Main PLUGIN = JavaPlugin.getPlugin(Main.class);
|
||||||
private static final File PREFIX_CONFIG_FILE = plugin.getPrefixConfigFile();
|
private static final File PREFIX_CONFIG_FILE = PLUGIN.getPrefixConfigFile();
|
||||||
private static final FileConfiguration PREFIX_CONFIG = plugin.getPrefixConfig();
|
private static final FileConfiguration PREFIX_CONFIG = PLUGIN.getPrefixConfig();
|
||||||
private static final FileConfiguration PLUGIN_CONFIGURATION = plugin.getConfig();
|
private static final FileConfiguration PLUGIN_CONFIGURATION = PLUGIN.getConfig();
|
||||||
private static final Component opTag;
|
private static final Component OP_TAG;
|
||||||
private static final Component deOpTag;
|
private static final Component DE_OP_TAG;
|
||||||
private static final Map<Player, Boolean> opMap = new HashMap<>();
|
private static final Map<Player, Boolean> OP_MAP = new HashMap<>();
|
||||||
private static final Map<Player, Component> displayNameMap = new HashMap<>();
|
private static final Map<Player, Component> DISPLAY_NAME_MAP = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
final String legacyOpTag = PLUGIN_CONFIGURATION.getString("opTag");
|
final String legacyOpTag = PLUGIN_CONFIGURATION.getString("opTag");
|
||||||
|
@ -40,14 +40,14 @@ public final class PlayerPrefix implements Listener {
|
||||||
throw new RuntimeException("Invalid plugin configuration!");
|
throw new RuntimeException("Invalid plugin configuration!");
|
||||||
}
|
}
|
||||||
|
|
||||||
opTag = LegacyComponentSerializer.legacySection().deserialize(legacyOpTag);
|
OP_TAG = LegacyComponentSerializer.legacySection().deserialize(legacyOpTag);
|
||||||
deOpTag = LegacyComponentSerializer.legacySection().deserialize(legacyDeOpTag);
|
DE_OP_TAG = LegacyComponentSerializer.legacySection().deserialize(legacyDeOpTag);
|
||||||
|
|
||||||
final BukkitScheduler scheduler = Bukkit.getScheduler();
|
final BukkitScheduler scheduler = Bukkit.getScheduler();
|
||||||
|
|
||||||
scheduler.runTaskTimerAsynchronously(plugin, PlayerPrefix::checkOpStatus,
|
scheduler.runTaskTimerAsynchronously(PLUGIN, PlayerPrefix::checkOpStatus,
|
||||||
0L, 1L);
|
0L, 1L);
|
||||||
scheduler.runTaskTimerAsynchronously(plugin, PlayerPrefix::checkDisplayNames,
|
scheduler.runTaskTimerAsynchronously(PLUGIN, PlayerPrefix::checkDisplayNames,
|
||||||
0L, 1L);
|
0L, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ public final class PlayerPrefix implements Listener {
|
||||||
final String legacyPrefix = PREFIX_CONFIG.getString(stringifiedUUID);
|
final String legacyPrefix = PREFIX_CONFIG.getString(stringifiedUUID);
|
||||||
|
|
||||||
if (legacyPrefix == null) {
|
if (legacyPrefix == null) {
|
||||||
return player.isOp() ? opTag : deOpTag;
|
return player.isOp() ? OP_TAG : DE_OP_TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
return LegacyComponentSerializer.legacyAmpersand()
|
return LegacyComponentSerializer.legacyAmpersand()
|
||||||
|
@ -89,7 +89,7 @@ public final class PlayerPrefix implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component getDefaultPrefix(Player player) {
|
public static Component getDefaultPrefix(Player player) {
|
||||||
return player.isOp() ? opTag : deOpTag;
|
return player.isOp() ? OP_TAG : DE_OP_TAG;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onUpdate(Player player) throws IOException {
|
private static void onUpdate(Player player) throws IOException {
|
||||||
|
@ -105,8 +105,8 @@ public final class PlayerPrefix implements Listener {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
final boolean isOp = player.isOp();
|
final boolean isOp = player.isOp();
|
||||||
|
|
||||||
opMap.put(player, isOp);
|
OP_MAP.put(player, isOp);
|
||||||
displayNameMap.put(player, player.displayName());
|
DISPLAY_NAME_MAP.put(player, player.displayName());
|
||||||
onUpdate(player);
|
onUpdate(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,8 +114,8 @@ public final class PlayerPrefix implements Listener {
|
||||||
public void onPlayerQuitEvent(PlayerQuitEvent event) {
|
public void onPlayerQuitEvent(PlayerQuitEvent event) {
|
||||||
final Player player = event.getPlayer();
|
final Player player = event.getPlayer();
|
||||||
|
|
||||||
opMap.remove(player);
|
OP_MAP.remove(player);
|
||||||
displayNameMap.remove(player);
|
DISPLAY_NAME_MAP.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkOpStatus() {
|
private static void checkOpStatus() {
|
||||||
|
@ -125,17 +125,17 @@ public final class PlayerPrefix implements Listener {
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
final boolean isOp = player.isOp();
|
final boolean isOp = player.isOp();
|
||||||
|
|
||||||
if (!opMap.containsKey(player)) {
|
if (!OP_MAP.containsKey(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean storedOp = opMap.get(player);
|
final boolean storedOp = OP_MAP.get(player);
|
||||||
|
|
||||||
if (isOp == storedOp) {
|
if (isOp == storedOp) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
opMap.put(player, isOp);
|
OP_MAP.put(player, isOp);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onUpdate(player);
|
onUpdate(player);
|
||||||
|
@ -152,17 +152,17 @@ public final class PlayerPrefix implements Listener {
|
||||||
for (Player player : players) {
|
for (Player player : players) {
|
||||||
final Component displayName = player.displayName();
|
final Component displayName = player.displayName();
|
||||||
|
|
||||||
if (!displayNameMap.containsKey(player)) {
|
if (!DISPLAY_NAME_MAP.containsKey(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Component storedDisplayName = displayNameMap.get(player);
|
final Component storedDisplayName = DISPLAY_NAME_MAP.get(player);
|
||||||
|
|
||||||
if (displayName.equals(storedDisplayName)) {
|
if (displayName.equals(storedDisplayName)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayNameMap.put(player, displayName);
|
DISPLAY_NAME_MAP.put(player, displayName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onUpdate(player);
|
onUpdate(player);
|
||||||
|
|
Loading…
Reference in a new issue