Use constants when possible

This commit is contained in:
Kaboom 2021-09-13 22:47:29 +03:00 committed by GitHub
parent aa460520ba
commit 5e12d92010
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -23,16 +24,18 @@ import pw.kaboom.extras.Main;
import pw.kaboom.extras.modules.server.ServerTabComplete; import pw.kaboom.extras.modules.server.ServerTabComplete;
public final class PlayerConnection implements Listener { public final class PlayerConnection implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private final String title = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinTitle"); private static final String TITLE = CONFIG.getString("playerJoinTitle");
private final String subtitle = JavaPlugin.getPlugin(Main.class).getConfig().getString("playerJoinSubtitle"); private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
private final int fadeIn = 10; private static final int FADE_IN = 10;
private final int stay = 160; private static final int STAY = 160;
private final int fadeOut = 5; private static final int FADE_OUT = 5;
private final boolean enableKick = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableKick");
private final boolean enableJoinRestrictions = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("enableJoinRestrictions"); private static final boolean ENABLE_KICK = CONFIG.getBoolean("enableKick");
private final boolean allowJoinOnFullServer = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("allowJoinOnFullServer"); private static final boolean ENABLE_JOIN_RESTRICTIONS = CONFIG.getBoolean("enableJoinRestrictions");
private final boolean opOnJoin = JavaPlugin.getPlugin(Main.class).getConfig().getBoolean("opOnJoin"); private static final boolean ALLOW_JOIN_ON_FULL_SERVER = CONFIG.getBoolean("allowJoinOnFullServer");
private static final boolean OP_ON_JOIN = CONFIG.getBoolean("opOnJoin");
@EventHandler @EventHandler
void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) { void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
@ -58,14 +61,14 @@ public final class PlayerConnection implements Listener {
void onPlayerJoin(final PlayerJoinEvent event) { void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (title != null if (TITLE != null
|| subtitle != null) { || SUBTITLE != null) {
player.sendTitle( player.sendTitle(
title, TITLE,
subtitle, SUBTITLE,
fadeIn, FADE_IN,
stay, STAY,
fadeOut FADE_OUT
); );
} }
@ -74,7 +77,7 @@ public final class PlayerConnection implements Listener {
@EventHandler @EventHandler
void onPlayerKick(final PlayerKickEvent event) { void onPlayerKick(final PlayerKickEvent event) {
if (!enableKick) { if (!ENABLE_KICK) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@ -87,17 +90,17 @@ public final class PlayerConnection implements Listener {
return; return;
} }
if (!enableJoinRestrictions) { if (!ENABLE_JOIN_RESTRICTIONS) {
event.allow(); event.allow();
} }
if (Result.KICK_FULL.equals(event.getResult()) && allowJoinOnFullServer) { if (Result.KICK_FULL.equals(event.getResult()) && ALLOW_JOIN_ON_FULL_SERVER) {
event.allow(); event.allow();
} }
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (opOnJoin && !player.isOp()) { if (OP_ON_JOIN && !player.isOp()) {
player.setOp(true); player.setOp(true);
} }