Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make variables final if they can be. #1843

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class Addon {
private FileConfiguration config;
private File dataFolder;
private File file;
private Map<String, AddonRequestHandler> requestHandlers = new HashMap<>();
private final Map<String, AddonRequestHandler> requestHandlers = new HashMap<>();

protected Addon() {
state = State.DISABLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
public class AddonClassLoader extends URLClassLoader {

private final Map<String, Class<?>> classes = new HashMap<>();
private Addon addon;
private AddonsManager loader;
private final Addon addon;
private final AddonsManager loader;

public AddonClassLoader(AddonsManager addonsManager, YamlConfiguration data, File jarFile, ClassLoader parent)
throws InvalidAddonInheritException,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,12 @@ public ConfigurationSection getPermissions() {
}

public static class Builder {
private @NonNull String main;
private @NonNull String name;
private @NonNull String version;
private @NonNull
final String main;
private @NonNull
final String name;
private @NonNull
final String version;
private @NonNull String description = "";
private @NonNull List<String> authors = new ArrayList<>();
private @NonNull List<String> dependencies = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AddonRequestBuilder
{
private String addonName;
private String requestLabel;
private Map<String, Object> metaData = new HashMap<>();
private final Map<String, Object> metaData = new HashMap<>();

/**
* Define the addon you wish to request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
/**
* Map of sub commands
*/
private Map<String, CompositeCommand> subCommands;
private final Map<String, CompositeCommand> subCommands;

/**
* Map of aliases for subcommands
*/
private Map<String, CompositeCommand> subCommandAliases;
private final Map<String, CompositeCommand> subCommandAliases;
/**
* The command chain from the very top, e.g., island team promote
*/
Expand All @@ -93,7 +93,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
* The prefix to be used in this command
*/
@Nullable
private String permissionPrefix;
private final String permissionPrefix;

/**
* The world that this command operates in. This is an overworld and will cover any associated nether or end
Expand All @@ -104,17 +104,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
/**
* The addon creating this command, if any
*/
private Addon addon;
private final Addon addon;

/**
* The top level label
*/
private String topLabel;
private final String topLabel;

/**
* Cool down tracker
*/
private Map<String, Map<String, Long>> cooldowns = new HashMap<>();
private final Map<String, Map<String, Long>> cooldowns = new HashMap<>();

/**
* Top level command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class ConfirmableCommand extends CompositeCommand {
/**
* Confirmation tracker
*/
private static Map<User, Confirmer> toBeConfirmed = new HashMap<>();
private static final Map<User, Confirmer> toBeConfirmed = new HashMap<>();

/**
* Top level command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class DelayedTeleportCommand extends CompositeCommand implements
/**
* User monitor map
*/
private static Map<UUID, DelayedCommand> toBeMonitored = new HashMap<>();
private static final Map<UUID, DelayedCommand> toBeMonitored = new HashMap<>();

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class AdminResetFlagsCommand extends ConfirmableCommand {

private List<String> options;
private final List<String> options;

public AdminResetFlagsCommand(CompositeCommand parent) {
super(parent, "resetflags");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AdminSettingsCommand extends CompositeCommand {
private final List<String> PROTECTION_FLAG_NAMES;
private Island island;
private final List<String> SETTING_FLAG_NAMES;
private List<String> WORLD_SETTING_FLAG_NAMES;
private final List<String> WORLD_SETTING_FLAG_NAMES;
private @NonNull Optional<Flag> flag = Optional.empty();
private boolean activeState;
private int rank;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AdminRangeDisplayCommand extends CompositeCommand {
private static final String HIDE = "hide";

// Map of users to which ranges must be displayed
private Map<User, Integer> displayRanges = new HashMap<>();
private final Map<User, Integer> displayRanges = new HashMap<>();

public AdminRangeDisplayCommand(CompositeCommand parent) {
super(parent, DISPLAY, SHOW, HIDE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class IslandTeamCommand extends CompositeCommand {
* Invited list. Key is the invited party, value is the invite.
* @since 1.8.0
*/
private Map<UUID, Invite> inviteMap;
private final Map<UUID, Invite> inviteMap;

public IslandTeamCommand(CompositeCommand parent) {
super(parent, "team");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class IslandTeamCoopCommand extends CompositeCommand {

private IslandTeamCommand itc;
private final IslandTeamCommand itc;
private @Nullable UUID targetUUID;

public IslandTeamCoopCommand(IslandTeamCommand parentCommand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {

private IslandTeamCommand itc;
private final IslandTeamCommand itc;
private UUID playerUUID;
private UUID prospectiveOwnerUUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class IslandTeamInviteCommand extends CompositeCommand {

private IslandTeamCommand itc;
private final IslandTeamCommand itc;
private @Nullable User invitedPlayer;

public IslandTeamInviteCommand(IslandTeamCommand parent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class IslandTeamInviteRejectCommand extends CompositeCommand {

private IslandTeamCommand itc;
private final IslandTeamCommand itc;

public IslandTeamInviteRejectCommand(IslandTeamCommand islandTeamCommand) {
super(islandTeamCommand, "reject");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
*/
public class Config<T> {

private AbstractDatabaseHandler<T> handler;
private Logger logger;
private final AbstractDatabaseHandler<T> handler;
private final Logger logger;
private Addon addon;

public Config(BentoBox plugin, Class<T> type) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/world/bentobox/bentobox/api/flags/Flag.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public enum Type {
*/
WORLD_SETTING(Material.GRASS_BLOCK);

private @NonNull Material icon;
private @NonNull
final Material icon;

Type(@NonNull Material icon) {
this.icon = icon;
Expand Down Expand Up @@ -482,8 +483,8 @@ public int compareTo(Flag o) {
*/
public static class Builder {
// Mandatory fields
private String id;
private Material icon;
private final String id;
private final Material icon;

// Listener
private Listener listener;
Expand Down Expand Up @@ -512,7 +513,7 @@ public static class Builder {
private Mode mode = Mode.EXPERT;

// Subflags
private Set<Flag> subflags;
private final Set<Flag> subflags;

/**
* Builder for making flags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
public class IslandToggleClick implements ClickHandler {

private BentoBox plugin = BentoBox.getInstance();
private String id;
private final BentoBox plugin = BentoBox.getInstance();
private final String id;

/**
* @param id - the flag ID that this click listener is associated with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public class BentoBoxLocale {

private static final String UNKNOWN = "unknown";

private Locale locale;
private YamlConfiguration config;
private ItemStack banner;
private List<String> authors;
private final Locale locale;
private final YamlConfiguration config;
private final ItemStack banner;
private final List<String> authors;

/**
* List of available prefixes in this locale.
* @since 1.12.0
*/
private Set<String> prefixes;
private final Set<String> prefixes;

public BentoBoxLocale(Locale locale, YamlConfiguration config) {
this.locale = locale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Map<String, String> getData() {

public static class Builder {
private long timestamp;
private String type;
private final String type;
private Map<String, String> data;

public Builder(@NonNull String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static PanelItem empty() {
private String name;
private boolean glow;
private ItemMeta meta;
private String playerHeadName;
private final String playerHeadName;
private boolean invisible;

public PanelItem(PanelItemBuilder builtItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class TabbedPanel extends Panel implements PanelListener {
private static final String PROTECTION_PANEL = "protection.panel.";
private static final long ITEMS_PER_PAGE = 36;
private final TabbedPanelBuilder tpb;
private @NonNull BentoBox plugin = BentoBox.getInstance();
private @NonNull
final BentoBox plugin = BentoBox.getInstance();
private int activeTab;
private int activePage;
private boolean closed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import world.bentobox.bentobox.api.addons.Addon;

public class AddonPlaceholderExpansion extends BasicPlaceholderExpansion {
private Addon addon;
private final Addon addon;

public AddonPlaceholderExpansion(Addon addon) {
this.addon = addon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
abstract class BasicPlaceholderExpansion extends PlaceholderExpansion {
@NonNull
private Map<@NonNull String, @NonNull PlaceholderReplacer> placeholders;
private final Map<@NonNull String, @NonNull PlaceholderReplacer> placeholders;

BasicPlaceholderExpansion() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import world.bentobox.bentobox.BentoBox;

public class BentoBoxPlaceholderExpansion extends BasicPlaceholderExpansion {
private BentoBox plugin;
private final BentoBox plugin;

public BentoBoxPlaceholderExpansion(BentoBox plugin) {
super();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/world/bentobox/bentobox/api/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*/
public class User implements MetaDataAble {

private static Map<UUID, User> users = new HashMap<>();
private static final Map<UUID, User> users = new HashMap<>();

/**
* Clears all users from the user list
Expand Down Expand Up @@ -136,7 +136,7 @@ public static void removePlayer(Player player) {
private static BentoBox plugin = BentoBox.getInstance();

@Nullable
private Player player;
private final Player player;
private OfflinePlayer offlinePlayer;
private final UUID playerUUID;
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public class BlueprintClipboard {
private boolean copying;
private int index;
private int lastPercentage;
private Map<Vector, List<BlueprintEntity>> bpEntities = new LinkedHashMap<>();
private Map<Vector, BlueprintBlock> bpAttachable = new LinkedHashMap<>();
private Map<Vector, BlueprintBlock> bpBlocks = new LinkedHashMap<>();
private BentoBox plugin = BentoBox.getInstance();
private final Map<Vector, List<BlueprintEntity>> bpEntities = new LinkedHashMap<>();
private final Map<Vector, BlueprintBlock> bpAttachable = new LinkedHashMap<>();
private final Map<Vector, BlueprintBlock> bpBlocks = new LinkedHashMap<>();
private final BentoBox plugin = BentoBox.getInstance();

/**
* Create a clipboard for blueprint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ enum PasteState {

private static final Map<String, String> BLOCK_CONVERSION = ImmutableMap.of("sign", "oak_sign", "wall_sign", "oak_wall_sign");

private BentoBox plugin;
private final BentoBox plugin;
// The minimum block position (x,y,z)
private Location pos1;
// The maximum block position (x,y,z)
Expand All @@ -85,19 +85,19 @@ enum PasteState {
* The Blueprint to paste.
*/
@NonNull
private Blueprint blueprint;
private final Blueprint blueprint;

/**
* The Location to paste to.
*/
@NonNull
private Location location;
private final Location location;

/**
* Island related to this paste, may be null.
*/
@Nullable
private Island island;
private final Island island;

/**
* Paste a clipboard to a location and run task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
public class DescriptionPrompt extends StringPrompt {

private static final String DESCRIPTION = "description";
private GameModeAddon addon;
private BlueprintBundle bb;
private final GameModeAddon addon;
private final BlueprintBundle bb;

public DescriptionPrompt(GameModeAddon addon, BlueprintBundle bb) {
this.addon = addon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

public class DescriptionSuccessPrompt extends MessagePrompt {

private GameModeAddon addon;
private BlueprintBundle bb;
private final GameModeAddon addon;
private final BlueprintBundle bb;

/**
* @param addon game mode addon
Expand Down
Loading