Skip to content

Commit

Permalink
Recover Version 4.0.4 source code.
Browse files Browse the repository at this point in the history
 * Decompile 4.0.4-SNAPSHOT from production servers.
 * Apply changes to the master branch.
 * Revert `synchronized` and `static` method attributes. Pointless in the
   case of `synchronized`.
 * Drop the use of PaperSpigot-specific API to prevent Phantom spawns.
   Modify the staff member's TIME_SINCE_REST statistic instead.
 * Improve handling of fire ticks and fall damage. These are now serialised
   with other saved state, preventing the abuse of ModMode for e.g.
   cancelling fall damage.
 * Fix handling of missing tracks (avoid NPE).

This version should be not significantly more flawed than the version we
have been running in production for the last year. No effort has yet been
made to fix the problem of Moderators having incorrect permissions. To
fix that requires that the plugin schedule ModMode actions in the event
handler of LuckPerms events fired when LuckPerms completes its track
promotions and demotions.
  • Loading branch information
totemo committed Jan 9, 2020
1 parent 0ed027c commit 4c2a12d
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 211 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.3</version>
<version>4.0.4</version>
<packaging>jar</packaging>
<name>ModMode</name>
<properties>
Expand Down
25 changes: 11 additions & 14 deletions src/nu/nerd/modmode/AbstractPlayerCache.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package nu.nerd.modmode;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import java.util.stream.Collectors;

// ------------------------------------------------------------------------
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

// ----------------------------------------------------------------------------
/**
* Represents an abstract cache of players.
*/
Expand All @@ -17,7 +17,7 @@ class AbstractPlayerCache {
/**
* The cache of players.
*/
private final HashSet<UUID> CACHE = new HashSet<>();
private HashSet<UUID> CACHE = new HashSet<>();

/**
* This cache's YAML key, for (de)serialization.
Expand All @@ -40,7 +40,7 @@ class AbstractPlayerCache {
*
* @param player the player.
*/
synchronized void add(Player player) {
void add(Player player) {
CACHE.add(player.getUniqueId());
}

Expand All @@ -50,7 +50,7 @@ synchronized void add(Player player) {
*
* @param player the player.
*/
synchronized void remove(Player player) {
void remove(Player player) {
CACHE.remove(player.getUniqueId());
}

Expand All @@ -61,7 +61,7 @@ synchronized void remove(Player player) {
* @param player the player.
* @return true if the given player is in the cache.
*/
synchronized boolean contains(Player player) {
boolean contains(Player player) {
return CACHE.contains(player.getUniqueId());
}

Expand All @@ -71,7 +71,7 @@ synchronized boolean contains(Player player) {
*
* @param config the configuration.
*/
synchronized void save(FileConfiguration config) {
void save(FileConfiguration config) {
config.set(_configKey, new ArrayList<>(CACHE.stream().map(UUID::toString).collect(Collectors.toSet())));
}

Expand All @@ -81,11 +81,8 @@ synchronized void save(FileConfiguration config) {
*
* @param config the configuration.
*/
synchronized void load(FileConfiguration config) {
CACHE.clear();
config.getStringList(_configKey).stream()
.map(UUID::fromString)
.forEach(CACHE::add);
void load(FileConfiguration config) {
CACHE = config.getStringList(this._configKey).stream().map(UUID::fromString).collect(Collectors.toCollection(HashSet::new));
}

}
163 changes: 43 additions & 120 deletions src/nu/nerd/modmode/Configuration.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package nu.nerd.modmode;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -16,7 +9,10 @@
import java.util.UUID;
import java.util.stream.Collectors;

// ------------------------------------------------------------------------
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;

// ----------------------------------------------------------------------------
/**
* Handles and exposes this plugin's configuration.
*/
Expand All @@ -35,60 +31,14 @@ class Configuration {
reload();
}

// ------------------------------------------------------------------------
/**
* Returns true if the given groups is configured to be persistent.
*
* @param group the group.
* @return true if the given groups is configured to be persistent.
*/
static boolean isPersistentGroup(String group) {
return PERSISTENT_GROUPS.contains(group);
}

// ------------------------------------------------------------------------
/**
* Returns the given player's serialized groups. If none exist, an empty
* List will be returned.
*
* @param player the player.
* @return the player's serialized groups; if none, an empty list.
*/
static List<String> getSerializedGroups(Player player) {
String playerUuid = player.getUniqueId().toString();
return new ArrayList<>(SERIALIZED_GROUPS.getStringList(playerUuid));
}

// ------------------------------------------------------------------------
/**
* Serializes the given groups for the given player.
*
* @param player the player.
* @param groups the groups to serialize.
*/
static void serializeGroups(Player player, Collection<String> groups) {
SERIALIZED_GROUPS.set(player.getUniqueId().toString(), new ArrayList<>(groups));
}

// ------------------------------------------------------------------------
/**
* Sanitizes the configuration file by removing artifacts from the player's
* last ModMode toggle.
*
* @param player the player.
*/
static void sanitizeSerializedGroups(Player player) {
SERIALIZED_GROUPS.set(player.getUniqueId().toString(), null);
}

// ------------------------------------------------------------------------
/**
* Returns true if the given player logged out while vanished.
*
* @param player the player.
* @return true if the given player logged out while vanished.
*/
static synchronized boolean loggedOutVanished(Player player) {
boolean loggedOutVanished(Player player) {
return LOGGED_OUT_VANISHED.contains(player.getUniqueId());
}

Expand All @@ -99,7 +49,7 @@ static synchronized boolean loggedOutVanished(Player player) {
* @param player the player.
* @param state the new state.
*/
static synchronized void setLoggedOutVanished(Player player, boolean state) {
void setLoggedOutVanished(Player player, boolean state) {
if (state) {
LOGGED_OUT_VANISHED.add(player.getUniqueId());
} else {
Expand All @@ -116,38 +66,29 @@ synchronized void reload() {
ModMode.PLUGIN.reloadConfig();
_config = ModMode.PLUGIN.getConfig();

VANISH_DELAY = this._config.getInt("vanish-delay-ticks", 1);
if (VANISH_DELAY <= 0) {
ModMode.log("Configuration error: vanish-delay-ticks must be a positive integer");
VANISH_DELAY = 1;
}

// clear logged-out-vanished list and repopulate from config
LOGGED_OUT_VANISHED.clear();
_config.getStringList("logged-out-vanished").stream()
.map(UUID::fromString)
.forEach(LOGGED_OUT_VANISHED::add);
.map(UUID::fromString)
.forEach(LOGGED_OUT_VANISHED::add);

// reload modmode cache
ModMode.getModModeCache().load(_config);
MODMODE_CACHE.load(_config);

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

// update collisions for players in ModMode
NerdBoardHook.setAllowCollisions(_config.getBoolean("allow.collisions", true));

// load persistent groups
PERSISTENT_GROUPS = new HashSet<>(_config.getStringList("permissions.persistent-groups"));

// load permission worlds
PERMISSION_WORLDS = _config.getStringList("permissions.worlds")
.stream()
.map(Bukkit::getWorld)
.collect(Collectors.toCollection(HashSet::new));

// store reference to the serialized groups configuration section
SERIALIZED_GROUPS = _config.getConfigurationSection("serialized-groups");
if (SERIALIZED_GROUPS == null) {
SERIALIZED_GROUPS = _config.createSection("serialized-groups");
}

MODERATOR_GROUP = _config.getString("permissions.moderator-group", "moderators");
MODMODE_GROUP = _config.getString("permissions.modmode-group", "ModMode");
MODMODE_TRACK_NAME = _config.getString("permissions.tracks.moderators", "modmode-track");
FOREIGN_SERVER_ADMIN_MODMODE_TRACK_NAME = _config.getString("permissions.tracks.foreign-server-admins",
"foreign-server-admins-modmode-track");

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

Expand All @@ -163,20 +104,26 @@ synchronized void reload() {
*/
synchronized void save() {
_config.set("logged-out-vanished", new ArrayList<>(LOGGED_OUT_VANISHED.stream()
.map(UUID::toString)
.collect(Collectors.toList())));
ModMode.getModModeCache().save(_config);
.map(UUID::toString)
.collect(Collectors.toList())));
MODMODE_CACHE.save(_config);
_config.set("allow.flight", allowFlight);
_config.set("allow.collisions", NerdBoardHook.allowsCollisions());
_config.set("permissions.persistent-groups", new ArrayList<>(PERSISTENT_GROUPS));
_config.set("permissions.worlds", PERMISSION_WORLDS.stream()
.map(World::getName)
.collect(Collectors.toList()));
_config.set("permissions.modmode-group", MODMODE_GROUP);
_config.set("permissions.moderator-group", MODERATOR_GROUP);
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
Expand All @@ -191,7 +138,7 @@ synchronized void save() {
* This is NOT the set of currently vanished players, which is instead
* maintained by the VanishNoPacket plugin.
*/
private static Set<UUID> LOGGED_OUT_VANISHED = new HashSet<>();
Set<UUID> LOGGED_OUT_VANISHED = new HashSet<>();

Map<String, String> joinedVanished;

Expand All @@ -205,39 +152,6 @@ synchronized void save() {
*/
boolean debugPlayerData;

/**
* The name of the moderator permission group.
*/
String MODERATOR_GROUP;

/**
* The name of the ModMode permission group.
*/
String MODMODE_GROUP;

/**
* A set of groups which should be retained when entering ModMode.
*/
private static HashSet<String> PERSISTENT_GROUPS = new HashSet<>();

/**
* A set of worlds with relevant permissions, i.e. when a player enters
* ModMode, their permissions from these worlds will be serialized and
* reapplied after they exit. Usually just "WORLD".
*/
static HashSet<World> PERMISSION_WORLDS = new HashSet<>();

/**
* When a player enters ModMode, their current permission groups will be
* serialized into the mapping
*
* Player -> {group_1, group_2, ..., group_n},
*
* of which all values (groups) will be re-applied after said player exits
* ModMode.
*/
private static ConfigurationSection SERIALIZED_GROUPS;

/**
* Commands executed immediately before ModMode is activated.
*/
Expand All @@ -258,4 +172,13 @@ synchronized void save() {
*/
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.
*/
AbstractPlayerCache MODMODE_CACHE = new AbstractPlayerCache("modmode");
}
9 changes: 5 additions & 4 deletions src/nu/nerd/modmode/LogBlockListener.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package nu.nerd.modmode;

import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.events.BlockChangePreLogEvent;
import java.util.UUID;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

import java.util.UUID;
import de.diddiz.LogBlock.Actor;
import de.diddiz.LogBlock.events.BlockChangePreLogEvent;

// ------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/**
* The LogBlock event-handling class.
*/
Expand Down
Loading

0 comments on commit 4c2a12d

Please sign in to comment.