Finalize fields where possible (#1021)

This commit is contained in:
Adam 2020-09-20 12:01:37 -04:00 committed by GitHub
parent bf214afe2e
commit 26124d3dee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 87 additions and 87 deletions

View File

@ -11,9 +11,9 @@ import java.util.ArrayList;
//automatically extends a claim downward based on block types detected //automatically extends a claim downward based on block types detected
class AutoExtendClaimTask implements Runnable class AutoExtendClaimTask implements Runnable
{ {
private Claim claim; private final Claim claim;
private ArrayList<ChunkSnapshot> chunks; private final ArrayList<ChunkSnapshot> chunks;
private Environment worldType; private final Environment worldType;
public AutoExtendClaimTask(Claim claim, ArrayList<ChunkSnapshot> chunks, Environment worldType) public AutoExtendClaimTask(Claim claim, ArrayList<ChunkSnapshot> chunks, Environment worldType)
{ {
@ -113,8 +113,8 @@ class AutoExtendClaimTask implements Runnable
//runs in the main execution thread, where it can safely change claims and save those changes //runs in the main execution thread, where it can safely change claims and save those changes
private class ExecuteExtendClaimTask implements Runnable private class ExecuteExtendClaimTask implements Runnable
{ {
private Claim claim; private final Claim claim;
private int newY; private final int newY;
public ExecuteExtendClaimTask(Claim claim, int newY) public ExecuteExtendClaimTask(Claim claim, int newY)
{ {

View File

@ -76,9 +76,9 @@ import java.util.UUID;
public class BlockEventHandler implements Listener public class BlockEventHandler implements Listener
{ {
//convenience reference to singleton datastore //convenience reference to singleton datastore
private DataStore dataStore; private final DataStore dataStore;
private ArrayList<Material> trashBlocks; private final ArrayList<Material> trashBlocks;
//constructor //constructor
public BlockEventHandler(DataStore dataStore) public BlockEventHandler(DataStore dataStore)

View File

@ -24,7 +24,7 @@ import org.bukkit.Bukkit;
//used to send delayed messages, for example a quit message after the player has been gone a while //used to send delayed messages, for example a quit message after the player has been gone a while
class BroadcastMessageTask implements Runnable class BroadcastMessageTask implements Runnable
{ {
private String message; private final String message;
public BroadcastMessageTask(String message) public BroadcastMessageTask(String message)
{ {

View File

@ -30,10 +30,10 @@ class CheckForPortalTrapTask extends BukkitRunnable
{ {
GriefPrevention instance; GriefPrevention instance;
//player who recently teleported via nether portal //player who recently teleported via nether portal
private Player player; private final Player player;
//where to send the player back to if he hasn't left the portal frame //where to send the player back to if he hasn't left the portal frame
private Location returnLocation; private final Location returnLocation;
public CheckForPortalTrapTask(Player player, GriefPrevention plugin, Location locationToReturn) public CheckForPortalTrapTask(Player player, GriefPrevention plugin, Location locationToReturn)
{ {

View File

@ -37,7 +37,7 @@ class CustomLogger
private final int secondsBetweenWrites = 300; private final int secondsBetweenWrites = 300;
//stringbuilder is not thread safe, stringbuffer is //stringbuilder is not thread safe, stringbuffer is
private StringBuffer queuedEntries = new StringBuffer(); private final StringBuffer queuedEntries = new StringBuffer();
CustomLogger() CustomLogger()
{ {

View File

@ -512,7 +512,7 @@ public abstract class DataStore
} }
//turns a location into a string, useful in data storage //turns a location into a string, useful in data storage
private String locationStringDelimiter = ";"; private final String locationStringDelimiter = ";";
String locationToString(Location location) String locationToString(Location location)
{ {
@ -1198,7 +1198,7 @@ public abstract class DataStore
} }
//timestamp for each siege cooldown to end //timestamp for each siege cooldown to end
private HashMap<String, Long> siegeCooldownRemaining = new HashMap<>(); private final HashMap<String, Long> siegeCooldownRemaining = new HashMap<>();
//whether or not a sieger can siege a particular victim or claim, considering only cooldowns //whether or not a sieger can siege a particular victim or claim, considering only cooldowns
synchronized public boolean onCooldown(Player attacker, Player defender, Claim defenderClaim) synchronized public boolean onCooldown(Player attacker, Player defender, Claim defenderClaim)
@ -1838,8 +1838,8 @@ public abstract class DataStore
private class SavePlayerDataThread extends Thread private class SavePlayerDataThread extends Thread
{ {
private UUID playerID; private final UUID playerID;
private PlayerData playerData; private final PlayerData playerData;
SavePlayerDataThread(UUID playerID, PlayerData playerData) SavePlayerDataThread(UUID playerID, PlayerData playerData)
{ {

View File

@ -45,9 +45,9 @@ public class DatabaseDataStore extends DataStore
{ {
private Connection databaseConnection = null; private Connection databaseConnection = null;
private String databaseUrl; private final String databaseUrl;
private String userName; private final String userName;
private String password; private final String password;
private String updateNameSQL; private String updateNameSQL;
private String insertClaimSQL; private String insertClaimSQL;

View File

@ -28,9 +28,9 @@ import java.util.Collection;
//runs every 5 minutes in the main thread, grants blocks per hour / 12 to each online player who appears to be actively playing //runs every 5 minutes in the main thread, grants blocks per hour / 12 to each online player who appears to be actively playing
class DeliverClaimBlocksTask implements Runnable class DeliverClaimBlocksTask implements Runnable
{ {
private Player player; private final Player player;
private GriefPrevention instance; private final GriefPrevention instance;
private int idleThresholdSquared; private final int idleThresholdSquared;
public DeliverClaimBlocksTask(Player player, GriefPrevention instance) public DeliverClaimBlocksTask(Player player, GriefPrevention instance)
{ {

View File

@ -35,7 +35,7 @@ import java.util.List;
class EntityCleanupTask implements Runnable class EntityCleanupTask implements Runnable
{ {
//where to start cleaning in the list of entities //where to start cleaning in the list of entities
private double percentageStart; private final double percentageStart;
public EntityCleanupTask(double percentageStart) public EntityCleanupTask(double percentageStart)
{ {

View File

@ -106,8 +106,8 @@ import java.util.UUID;
public class EntityEventHandler implements Listener public class EntityEventHandler implements Listener
{ {
//convenience reference for the singleton datastore //convenience reference for the singleton datastore
private DataStore dataStore; private final DataStore dataStore;
GriefPrevention instance; private final GriefPrevention instance;
private final NamespacedKey luredByPlayer; private final NamespacedKey luredByPlayer;
public EntityEventHandler(DataStore dataStore, GriefPrevention plugin) public EntityEventHandler(DataStore dataStore, GriefPrevention plugin)

View File

@ -27,7 +27,7 @@ import org.bukkit.inventory.EquipmentSlot;
class EquipShovelProcessingTask implements Runnable class EquipShovelProcessingTask implements Runnable
{ {
//player data //player data
private Player player; private final Player player;
public EquipShovelProcessingTask(Player player) public EquipShovelProcessingTask(Player player)
{ {

View File

@ -3137,8 +3137,8 @@ public class GriefPrevention extends JavaPlugin
//thread to build the above cache //thread to build the above cache
private class CacheOfflinePlayerNamesThread extends Thread private class CacheOfflinePlayerNamesThread extends Thread
{ {
private OfflinePlayer[] offlinePlayers; private final OfflinePlayer[] offlinePlayers;
private ConcurrentHashMap<String, UUID> playerNameToIDMap; private final ConcurrentHashMap<String, UUID> playerNameToIDMap;
CacheOfflinePlayerNamesThread(OfflinePlayer[] offlinePlayers, ConcurrentHashMap<String, UUID> playerNameToIDMap) CacheOfflinePlayerNamesThread(OfflinePlayer[] offlinePlayers, ConcurrentHashMap<String, UUID> playerNameToIDMap)
{ {

View File

@ -11,8 +11,8 @@ import java.util.concurrent.ConcurrentHashMap;
//loads ignore data from file into a hash map //loads ignore data from file into a hash map
class IgnoreLoaderThread extends Thread class IgnoreLoaderThread extends Thread
{ {
private UUID playerToLoad; private final UUID playerToLoad;
private ConcurrentHashMap<UUID, Boolean> destinationMap; private final ConcurrentHashMap<UUID, Boolean> destinationMap;
IgnoreLoaderThread(UUID playerToLoad, ConcurrentHashMap<UUID, Boolean> destinationMap) IgnoreLoaderThread(UUID playerToLoad, ConcurrentHashMap<UUID, Boolean> destinationMap)
{ {

View File

@ -107,23 +107,23 @@ import java.util.regex.Pattern;
class PlayerEventHandler implements Listener class PlayerEventHandler implements Listener
{ {
private DataStore dataStore; private final DataStore dataStore;
private GriefPrevention instance; private final GriefPrevention instance;
//list of temporarily banned ip's //list of temporarily banned ip's
private ArrayList<IpBanInfo> tempBannedIps = new ArrayList<>(); private final ArrayList<IpBanInfo> tempBannedIps = new ArrayList<>();
//number of milliseconds in a day //number of milliseconds in a day
private final long MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24; private final long MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24;
//timestamps of login and logout notifications in the last minute //timestamps of login and logout notifications in the last minute
private ArrayList<Long> recentLoginLogoutNotifications = new ArrayList<>(); private final ArrayList<Long> recentLoginLogoutNotifications = new ArrayList<>();
//regex pattern for the "how do i claim land?" scanner //regex pattern for the "how do i claim land?" scanner
private Pattern howToClaimPattern = null; private Pattern howToClaimPattern = null;
//matcher for banned words //matcher for banned words
private WordFinder bannedWordFinder; private final WordFinder bannedWordFinder;
//spam tracker //spam tracker
SpamDetector spamDetector = new SpamDetector(); SpamDetector spamDetector = new SpamDetector();
@ -537,7 +537,7 @@ class PlayerEventHandler implements Listener
} }
} }
private ConcurrentHashMap<String, CommandCategory> commandCategoryMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, CommandCategory> commandCategoryMap = new ConcurrentHashMap<>();
private CommandCategory getCommandCategory(String commandName) private CommandCategory getCommandCategory(String commandName)
{ {
@ -618,7 +618,7 @@ class PlayerEventHandler implements Listener
GriefPrevention.AddLogEntry(entryBuilder.toString(), CustomLogEntryTypes.SocialActivity, true); GriefPrevention.AddLogEntry(entryBuilder.toString(), CustomLogEntryTypes.SocialActivity, true);
} }
private ConcurrentHashMap<UUID, Date> lastLoginThisServerSessionMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<UUID, Date> lastLoginThisServerSessionMap = new ConcurrentHashMap<>();
//when a player attempts to join the server... //when a player attempts to join the server...
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@ -875,7 +875,7 @@ class PlayerEventHandler implements Listener
} }
//when a player dies... //when a player dies...
private HashMap<UUID, Long> deathTimestamps = new HashMap<>(); private final HashMap<UUID, Long> deathTimestamps = new HashMap<>();
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
void onPlayerDeath(PlayerDeathEvent event) void onPlayerDeath(PlayerDeathEvent event)
@ -908,7 +908,7 @@ class PlayerEventHandler implements Listener
} }
//when a player quits... //when a player quits...
private HashMap<UUID, Integer> heldLogoutMessages = new HashMap<>(); private final HashMap<UUID, Integer> heldLogoutMessages = new HashMap<>();
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
void onPlayerQuit(PlayerQuitEvent event) void onPlayerQuit(PlayerQuitEvent event)
@ -1449,8 +1449,8 @@ class PlayerEventHandler implements Listener
} }
//block use of buckets within other players' claims //block use of buckets within other players' claims
private HashSet<Material> commonAdjacentBlocks_water = new HashSet<>(Arrays.asList(Material.WATER, Material.FARMLAND, Material.DIRT, Material.STONE)); private final HashSet<Material> commonAdjacentBlocks_water = new HashSet<>(Arrays.asList(Material.WATER, Material.FARMLAND, Material.DIRT, Material.STONE));
private HashSet<Material> commonAdjacentBlocks_lava = new HashSet<>(Arrays.asList(Material.LAVA, Material.DIRT, Material.STONE)); private final HashSet<Material> commonAdjacentBlocks_lava = new HashSet<>(Arrays.asList(Material.LAVA, Material.DIRT, Material.STONE));
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent bucketEvent) public void onPlayerBucketEmpty(PlayerBucketEmptyEvent bucketEvent)
@ -2623,7 +2623,7 @@ class PlayerEventHandler implements Listener
} }
//determines whether a block type is an inventory holder. uses a caching strategy to save cpu time //determines whether a block type is an inventory holder. uses a caching strategy to save cpu time
private ConcurrentHashMap<Material, Boolean> inventoryHolderCache = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Material, Boolean> inventoryHolderCache = new ConcurrentHashMap<>();
private boolean isInventoryHolder(Block clickedBlock) private boolean isInventoryHolder(Block clickedBlock)
{ {

View File

@ -28,16 +28,16 @@ import org.bukkit.entity.Player;
class PlayerKickBanTask implements Runnable class PlayerKickBanTask implements Runnable
{ {
//player to kick or ban //player to kick or ban
private Player player; private final Player player;
//message to send player. //message to send player.
private String reason; private final String reason;
//source of ban //source of ban
private String source; private final String source;
//whether to ban //whether to ban
private boolean ban; private final boolean ban;
public PlayerKickBanTask(Player player, String reason, String source, boolean ban) public PlayerKickBanTask(Player player, String reason, String source, boolean ban)
{ {

View File

@ -27,13 +27,13 @@ import org.bukkit.entity.Player;
class PlayerRescueTask implements Runnable class PlayerRescueTask implements Runnable
{ {
//original location where /trapped was used //original location where /trapped was used
private Location location; private final Location location;
//rescue destination, may be decided at instantiation or at execution //rescue destination, may be decided at instantiation or at execution
private Location destination; private Location destination;
//player data //player data
private Player player; private final Player player;
public PlayerRescueTask(Player player, Location location, Location destination) public PlayerRescueTask(Player player, Location location, Location destination)
{ {

View File

@ -24,7 +24,7 @@ import org.bukkit.entity.Player;
//used to send delayed messages, for example help text triggered by a player's chat //used to send delayed messages, for example help text triggered by a player's chat
class PvPImmunityValidationTask implements Runnable class PvPImmunityValidationTask implements Runnable
{ {
private Player player; private final Player player;
public PvPImmunityValidationTask(Player player) public PvPImmunityValidationTask(Player player)
{ {

View File

@ -36,15 +36,15 @@ class RestoreNatureExecutionTask implements Runnable
{ {
//results from processing thread //results from processing thread
//will be applied to the world //will be applied to the world
private BlockSnapshot[][][] snapshots; private final BlockSnapshot[][][] snapshots;
//boundaries for changes //boundaries for changes
private int miny; private final int miny;
private Location lesserCorner; private final Location lesserCorner;
private Location greaterCorner; private final Location greaterCorner;
//player who should be notified about the result (will see a visualization when the restoration is complete) //player who should be notified about the result (will see a visualization when the restoration is complete)
private Player player; private final Player player;
public RestoreNatureExecutionTask(BlockSnapshot[][][] snapshots, int miny, Location lesserCorner, Location greaterCorner, Player player) public RestoreNatureExecutionTask(BlockSnapshot[][][] snapshots, int miny, Location lesserCorner, Location greaterCorner, Player player)
{ {

View File

@ -36,23 +36,23 @@ class RestoreNatureProcessingTask implements Runnable
{ {
//world information captured from the main thread //world information captured from the main thread
//will be updated and sent back to main thread to be applied to the world //will be updated and sent back to main thread to be applied to the world
private BlockSnapshot[][][] snapshots; private final BlockSnapshot[][][] snapshots;
//other information collected from the main thread. //other information collected from the main thread.
//not to be updated, only to be passed back to main thread to provide some context about the operation //not to be updated, only to be passed back to main thread to provide some context about the operation
private int miny; private int miny;
private Environment environment; private final Environment environment;
private Location lesserBoundaryCorner; private final Location lesserBoundaryCorner;
private Location greaterBoundaryCorner; private final Location greaterBoundaryCorner;
private Player player; //absolutely must not be accessed. not thread safe. private final Player player; //absolutely must not be accessed. not thread safe.
private Biome biome; private final Biome biome;
private boolean creativeMode; private final boolean creativeMode;
private int seaLevel; private final int seaLevel;
private boolean aggressiveMode; private final boolean aggressiveMode;
//two lists of materials //two lists of materials
private ArrayList<Material> notAllowedToHang; //natural blocks which don't naturally hang in their air private final ArrayList<Material> notAllowedToHang; //natural blocks which don't naturally hang in their air
private ArrayList<Material> playerBlocks; //a "complete" list of player-placed blocks. MUST BE MAINTAINED as patches introduce more private final ArrayList<Material> playerBlocks; //a "complete" list of player-placed blocks. MUST BE MAINTAINED as patches introduce more
public RestoreNatureProcessingTask(BlockSnapshot[][][] snapshots, int miny, Environment environment, Biome biome, Location lesserBoundaryCorner, Location greaterBoundaryCorner, int seaLevel, boolean aggressiveMode, boolean creativeMode, Player player) public RestoreNatureProcessingTask(BlockSnapshot[][][] snapshots, int miny, Environment environment, Biome biome, Location lesserBoundaryCorner, Location greaterBoundaryCorner, int seaLevel, boolean aggressiveMode, boolean creativeMode, Player player)

View File

@ -25,7 +25,7 @@ import java.util.Collection;
//secures a claim after a siege looting window has closed //secures a claim after a siege looting window has closed
class SecureClaimTask implements Runnable class SecureClaimTask implements Runnable
{ {
private SiegeData siegeData; private final SiegeData siegeData;
public SecureClaimTask(SiegeData siegeData) public SecureClaimTask(SiegeData siegeData)
{ {

View File

@ -25,9 +25,9 @@ import org.bukkit.entity.Player;
//used to send delayed messages, for example help text triggered by a player's chat //used to send delayed messages, for example help text triggered by a player's chat
class SendPlayerMessageTask implements Runnable class SendPlayerMessageTask implements Runnable
{ {
private Player player; private final Player player;
private ChatColor color; private final ChatColor color;
private String message; private final String message;
public SendPlayerMessageTask(Player player, ChatColor color, String message) public SendPlayerMessageTask(Player player, ChatColor color, String message)
{ {

View File

@ -24,7 +24,7 @@ import org.bukkit.entity.Player;
//for example, defender escaped or attacker gave up and left //for example, defender escaped or attacker gave up and left
class SiegeCheckupTask implements Runnable class SiegeCheckupTask implements Runnable
{ {
private SiegeData siegeData; private final SiegeData siegeData;
public SiegeCheckupTask(SiegeData siegeData) public SiegeCheckupTask(SiegeData siegeData)
{ {

View File

@ -230,7 +230,7 @@ class ChatterData
public boolean spamWarned = false; //whether the player has received a warning recently public boolean spamWarned = false; //whether the player has received a warning recently
//all recent message lengths and their total //all recent message lengths and their total
private ConcurrentLinkedQueue<LengthTimestampPair> recentMessageLengths = new ConcurrentLinkedQueue<>(); private final ConcurrentLinkedQueue<LengthTimestampPair> recentMessageLengths = new ConcurrentLinkedQueue<>();
private int recentTotalLength = 0; private int recentTotalLength = 0;
public void AddMessage(String message, long timestamp) public void AddMessage(String message, long timestamp)

View File

@ -23,9 +23,9 @@ import org.bukkit.entity.Player;
//applies a visualization for a player by sending him block change packets //applies a visualization for a player by sending him block change packets
class VisualizationApplicationTask implements Runnable class VisualizationApplicationTask implements Runnable
{ {
private Visualization visualization; private final Visualization visualization;
private Player player; private final Player player;
private PlayerData playerData; private final PlayerData playerData;
public VisualizationApplicationTask(Player player, PlayerData playerData, Visualization visualization) public VisualizationApplicationTask(Player player, PlayerData playerData, Visualization visualization)
{ {

View File

@ -27,9 +27,9 @@ import java.util.Collections;
//applies a visualization for a player by sending him block change packets //applies a visualization for a player by sending him block change packets
class VisualizationReversionTask implements Runnable class VisualizationReversionTask implements Runnable
{ {
private Visualization visualization; private final Visualization visualization;
private Player player; private final Player player;
private PlayerData playerData; private final PlayerData playerData;
public VisualizationReversionTask(Player player, PlayerData playerData, Visualization visualization) public VisualizationReversionTask(Player player, PlayerData playerData, Visualization visualization)
{ {

View File

@ -9,7 +9,7 @@ import org.bukkit.inventory.meta.BookMeta;
public class WelcomeTask implements Runnable public class WelcomeTask implements Runnable
{ {
private Player player; private final Player player;
public WelcomeTask(Player player) public WelcomeTask(Player player)
{ {

View File

@ -26,7 +26,7 @@ public class AccrueClaimBlocksEvent extends Event
return handlers; return handlers;
} }
private Player player; private final Player player;
private int blocksToAccrue; private int blocksToAccrue;
private boolean isIdle = false; private boolean isIdle = false;
private boolean cancelled = false; private boolean cancelled = false;

View File

@ -21,7 +21,7 @@ public class ClaimDeletedEvent extends Event
return handlers; return handlers;
} }
private Claim claim; private final Claim claim;
public ClaimDeletedEvent(Claim claim) public ClaimDeletedEvent(Claim claim)
{ {

View File

@ -24,7 +24,7 @@ public class ClaimModifiedEvent extends Event implements Cancellable
private final Claim from; private final Claim from;
private final Claim to; private final Claim to;
private CommandSender modifier; private final CommandSender modifier;
private boolean cancelled; private boolean cancelled;
public ClaimModifiedEvent(Claim from, Claim to, CommandSender modifier) public ClaimModifiedEvent(Claim from, Claim to, CommandSender modifier)

View File

@ -25,10 +25,10 @@ public class PlayerKickBanEvent extends Event
return handlers; return handlers;
} }
private Player player; private final Player player;
private String reason; private final String reason;
private String source; private final String source;
private boolean ban; private final boolean ban;
private boolean cancelled = false; private boolean cancelled = false;
/** /**

View File

@ -10,7 +10,7 @@ public class PreventBlockBreakEvent extends Event implements Cancellable
{ {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false; private boolean cancelled = false;
private BlockBreakEvent innerEvent; private final BlockBreakEvent innerEvent;
public static HandlerList getHandlerList() public static HandlerList getHandlerList()
{ {

View File

@ -50,7 +50,7 @@ public class Metrics {
private static final String URL = "https://bStats.org/submitData/bukkit"; private static final String URL = "https://bStats.org/submitData/bukkit";
// Is bStats enabled on this server? // Is bStats enabled on this server?
private boolean enabled; private final boolean enabled;
// Should failed requests be logged? // Should failed requests be logged?
private static boolean logFailedRequests; private static boolean logFailedRequests;

View File

@ -13,7 +13,7 @@ import java.util.concurrent.Callable;
*/ */
public class MetricsHandler public class MetricsHandler
{ {
private Metrics metrics; private final Metrics metrics;
public MetricsHandler(GriefPrevention plugin, String dataMode) public MetricsHandler(GriefPrevention plugin, String dataMode)
{ {