Skip to content

Commit

Permalink
Version 4.1.0.
Browse files Browse the repository at this point in the history
Code quality.

 * Local style conventions (as "constants") for public data
   members of Configuration.
 * Rename, document and more accurately type SUPPRESSED_LOGIN_MESSAGE
   (joinedVanished).
  • Loading branch information
totemo committed Feb 12, 2020
1 parent a8f0bd9 commit 2dbd0de
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 94 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>nu.nerd</groupId>
<artifactId>ModMode</artifactId>
<version>4.0.5</version>
<version>4.1.0</version>
<packaging>jar</packaging>
<name>ModMode</name>
<properties>
Expand Down
168 changes: 87 additions & 81 deletions src/nu/nerd/modmode/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,86 @@
* Handles and exposes this plugin's configuration.
*/
class Configuration {
// ------------------------------------------------------------------------
/**
* Name of the track that Moderators are promoted along to enter ModMode.
*/
public String MODMODE_TRACK_NAME;

/**
* The configuration.
* Name of the track that foreign server admins are promoted along to enter
* ModMode.
*/
private FileConfiguration _config;
public String FOREIGN_SERVER_ADMIN_MODMODE_TRACK_NAME;

/**
* For Moderators in ModMode, this is persistent storage for their vanish
* state when they log out. Moderators out of ModMode are assumed to always
* be visible.
*
* For Admins who can vanish without transitioning into ModMode, this
* variable stores their vanish state between logins only when not in
* ModMode. If they log out in ModMode, they are re-vanished automatically
* when they log in. When they leave ModMode, their vanish state is set
* according to membership in this set.
*
* This is NOT the set of currently vanished players, which is instead
* maintained by the VanishNoPacket plugin.
*/
public Set<UUID> LOGGED_OUT_VANISHED = new HashSet<>();

/**
* This is a map of player UUID to login announcement message for those
* players that joined vanished. It is used to replay that login message
* when the player unvanishes on leaving ModMode if that message was
* initially suppressed when they logged in vanished.
*/
public Map<UUID, String> SUPPRESSED_LOGIN_MESSAGE = new HashMap<>();

/**
* If true, players in ModMode will be able to fly.
*/
public boolean ALLOW_FLIGHT;

/**
* If true, player data loads and saves are logged to the console.
*/
public boolean DEBUG_PLAYER_DATA;

/**
* Commands executed immediately before ModMode is activated.
*/
public List<String> BEFORE_ACTIVATION_COMMANDS;

/**
* Commands executed immediately after ModMode is activated.
*/
public List<String> AFTER_ACTIVATION_COMMANDS;

/**
* Commands executed immediately before ModMode is deactivated.
*/
public List<String> BEFORE_DEACTIVATION_COMMANDS;

/**
* Commands executed immediately after ModMode is deactivated.
*/
public List<String> AFTER_DEACTIVATION_COMMANDS;

/**
* Delay in ticks to wait before setting the player's vanish state.
*/
public int VANISH_DELAY;

/**
* A cache of players (UUIDs) currently in ModMode.
*/
public PlayerUuidSet MODMODE_CACHE = new PlayerUuidSet("modmode");

/**
* A cache of players (UUIDs) currently in ModMode.
*/
public PlayerUuidSet MODMODE_PENDING = new PlayerUuidSet("modmode-pending");

// ------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -81,8 +156,8 @@ synchronized void reload() {
MODMODE_CACHE.load(_config);
MODMODE_PENDING.load(_config);

joinedVanished = new HashMap<>();
allowFlight = _config.getBoolean("allow.flight", true);
SUPPRESSED_LOGIN_MESSAGE.clear();
ALLOW_FLIGHT = _config.getBoolean("allow.flight", true);

// update collisions for players in ModMode
NerdBoardHook.setAllowCollisions(_config.getBoolean("allow.collisions", true));
Expand All @@ -91,12 +166,12 @@ synchronized void reload() {
FOREIGN_SERVER_ADMIN_MODMODE_TRACK_NAME = _config.getString("permissions.tracks.foreign-server-admins",
"foreign-server-admins-modmode-track");

debugPlayerData = _config.getBoolean("debug.playerdata");
DEBUG_PLAYER_DATA = _config.getBoolean("debug.playerdata");

beforeActivationCommands = _config.getStringList("commands.activate.before");
afterActivationCommands = _config.getStringList("commands.activate.after");
beforeDeactivationCommands = _config.getStringList("commands.deactivate.before");
afterDeactivationCommands = _config.getStringList("commands.deactivate.after");
BEFORE_ACTIVATION_COMMANDS = _config.getStringList("commands.activate.before");
AFTER_ACTIVATION_COMMANDS = _config.getStringList("commands.activate.after");
BEFORE_DEACTIVATION_COMMANDS = _config.getStringList("commands.deactivate.before");
AFTER_DEACTIVATION_COMMANDS = _config.getStringList("commands.deactivate.after");
}

// ------------------------------------------------------------------------
Expand All @@ -109,84 +184,15 @@ synchronized void save() {
.collect(Collectors.toList())));
MODMODE_CACHE.save(_config);
MODMODE_PENDING.save(_config);
_config.set("allow.flight", allowFlight);
_config.set("allow.flight", ALLOW_FLIGHT);
_config.set("allow.collisions", NerdBoardHook.allowsCollisions());
ModMode.PLUGIN.saveConfig();
}

// ------------------------------------------------------------------------
/**
* Name of the track that Moderators are promoted along to enter ModMode.
*/
String MODMODE_TRACK_NAME;

/**
* Name of the track that foreign server admins are promoted along to enter
* ModMode.
*/
String FOREIGN_SERVER_ADMIN_MODMODE_TRACK_NAME;

/**
* For Moderators in ModMode, this is persistent storage for their vanish
* state when they log out. Moderators out of ModMode are assumed to always
* be visible.
*
* For Admins who can vanish without transitioning into ModMode, this
* variable stores their vanish state between logins only when not in
* ModMode. If they log out in ModMode, they are re-vanished automatically
* when they log in. When they leave ModMode, their vanish state is set
* according to membership in this set.
*
* This is NOT the set of currently vanished players, which is instead
* maintained by the VanishNoPacket plugin.
*/
Set<UUID> LOGGED_OUT_VANISHED = new HashSet<>();

Map<String, String> joinedVanished;

/**
* If true, players in ModMode will be able to fly.
*/
boolean allowFlight;

/**
* If true, player data loads and saves are logged to the console.
*/
boolean debugPlayerData;

/**
* Commands executed immediately before ModMode is activated.
*/
List<String> beforeActivationCommands;

/**
* Commands executed immediately after ModMode is activated.
*/
List<String> afterActivationCommands;

/**
* Commands executed immediately before ModMode is deactivated.
*/
List<String> beforeDeactivationCommands;

/**
* Commands executed immediately after ModMode is deactivated.
*/
List<String> afterDeactivationCommands;

/**
* Delay in ticks to wait before setting the player's vanish state.
*/
int VANISH_DELAY;

/**
* A cache of players (UUIDs) currently in ModMode.
*/
PlayerUuidSet MODMODE_CACHE = new PlayerUuidSet("modmode");

/**
* A cache of players (UUIDs) currently in ModMode.
* The configuration.
*/
PlayerUuidSet MODMODE_PENDING = new PlayerUuidSet("modmode-pending");
private FileConfiguration _config;

}
18 changes: 9 additions & 9 deletions src/nu/nerd/modmode/ModMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ private File getStateFile(Player player, boolean isModMode) {
*/
private void savePlayerData(Player player, boolean isModMode) {
File stateFile = getStateFile(player, isModMode);
if (CONFIG.debugPlayerData) {
if (CONFIG.DEBUG_PLAYER_DATA) {
log("savePlayerData(): " + stateFile);
}

Expand Down Expand Up @@ -336,7 +336,7 @@ private void savePlayerData(Player player, boolean isModMode) {
*/
private void loadPlayerData(Player player, boolean isModMode) {
File stateFile = getStateFile(player, isModMode);
if (CONFIG.debugPlayerData) {
if (CONFIG.DEBUG_PLAYER_DATA) {
log("loadPlayerData(): " + stateFile);
}

Expand Down Expand Up @@ -425,9 +425,9 @@ private void loadPlayerData(Player player, boolean isModMode) {
private void startToggleModMode(Player player, boolean enabled) {
// log("startToggleModMode()");
if (enabled) {
runCommands(player, CONFIG.beforeActivationCommands);
runCommands(player, CONFIG.BEFORE_ACTIVATION_COMMANDS);
} else {
runCommands(player, CONFIG.beforeDeactivationCommands);
runCommands(player, CONFIG.BEFORE_DEACTIVATION_COMMANDS);
}

// Save player data for the old ModMode state and load for the new.
Expand Down Expand Up @@ -515,9 +515,9 @@ void finishToggleModMode(Player player, boolean enabled) {
restoreFlight(player, enabled);

if (enabled) {
runCommands(player, CONFIG.afterActivationCommands);
runCommands(player, CONFIG.AFTER_ACTIVATION_COMMANDS);
} else {
runCommands(player, CONFIG.afterDeactivationCommands);
runCommands(player, CONFIG.AFTER_DEACTIVATION_COMMANDS);
}

// All done bar the shouting.
Expand All @@ -531,8 +531,8 @@ void finishToggleModMode(Player player, boolean enabled) {
player.sendMessage(ChatColor.RED + "You are now in ModMode!");
} else {
if (!PERMISSIONS.isAdmin(player)) {
if (CONFIG.joinedVanished.containsKey(player.getUniqueId().toString())) {
getServer().broadcastMessage(CONFIG.joinedVanished.get(player.getUniqueId().toString()));
if (CONFIG.SUPPRESSED_LOGIN_MESSAGE.containsKey(player.getUniqueId())) {
getServer().broadcastMessage(CONFIG.SUPPRESSED_LOGIN_MESSAGE.get(player.getUniqueId()));
}
}
player.sendMessage(ChatColor.RED + "You are no longer in ModMode!");
Expand Down Expand Up @@ -629,7 +629,7 @@ protected void onUserTrackEvent(UserTrackEvent event) {
* @param isInModMode true if the player is in ModMode.
*/
void restoreFlight(Player player, boolean isInModMode) {
player.setAllowFlight((isInModMode && CONFIG.allowFlight) || player.getGameMode() == GameMode.CREATIVE);
player.setAllowFlight((isInModMode && CONFIG.ALLOW_FLIGHT) || player.getGameMode() == GameMode.CREATIVE);
}

// ------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/nu/nerd/modmode/ModModeListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {

if (vanished) {
ModMode.PLUGIN.setVanish(player, true);
CONFIG.joinedVanished.put(player.getUniqueId().toString(), event.getJoinMessage());
CONFIG.SUPPRESSED_LOGIN_MESSAGE.put(player.getUniqueId(), event.getJoinMessage());
event.setJoinMessage(null);
}

Expand All @@ -83,7 +83,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
CONFIG.joinedVanished.remove(player.getUniqueId().toString());
CONFIG.SUPPRESSED_LOGIN_MESSAGE.remove(player.getUniqueId());

// Suppress quit messages when vanished.
if (ModMode.PLUGIN.isVanished(player)) {
Expand Down Expand Up @@ -193,7 +193,7 @@ else if (ModMode.PLUGIN.isModMode(victim) && !ModMode.PLUGIN.isVanished(victim))
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.CREATIVE) {
if (CONFIG.allowFlight) {
if (CONFIG.ALLOW_FLIGHT) {
boolean flightState = ModMode.PLUGIN.isModMode(player);
player.setAllowFlight(flightState);
}
Expand Down

0 comments on commit 2dbd0de

Please sign in to comment.