refactor: clean up reused code

This commit is contained in:
bobby29831 2022-05-13 11:28:13 -05:00
parent 619377c72f
commit f900dd3268
7 changed files with 37 additions and 38 deletions

View file

@ -44,7 +44,7 @@ public class SetBorder implements ICommand {
addToConfig("worldBorder.enabled",false); addToConfig("worldBorder.enabled",false);
saveConfig(); saveConfig();
sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE")); sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
Game.resetWorldborder(spawnWorld); Game.resetWorldBorder(spawnWorld);
return; return;
} }
int num,delay,change; int num,delay,change;
@ -90,7 +90,7 @@ public class SetBorder implements ICommand {
addToConfig("worldBorder.move", worldborderChange); addToConfig("worldBorder.move", worldborderChange);
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
saveConfig(); saveConfig();
Game.resetWorldborder(spawnWorld); Game.resetWorldBorder(spawnWorld);
} }
public String getLabel() { public String getLabel() {

View file

@ -39,7 +39,7 @@ import java.util.Optional;
public class Config { public class Config {
private static ConfigManager config, leaderboard; private static ConfigManager config;
public static String public static String
messagePrefix, messagePrefix,
@ -150,7 +150,7 @@ public class Config {
config = ConfigManager.create("config.yml"); config = ConfigManager.create("config.yml");
config.saveConfig(); config.saveConfig();
leaderboard = ConfigManager.create("leaderboard.yml"); ConfigManager leaderboard = ConfigManager.create("leaderboard.yml");
//Spawn //Spawn
spawnPosition = new Vector( spawnPosition = new Vector(

View file

@ -23,8 +23,15 @@ import java.util.UUID;
public class PlayerInfo { public class PlayerInfo {
public UUID uuid; public final UUID uuid;
public int hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths; public final int hider_wins;
public final int seeker_wins;
public final int hider_games;
public final int seeker_games;
public final int hider_kills;
public final int seeker_kills;
public final int hider_deaths;
public final int seeker_deaths;
public PlayerInfo(UUID uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths) { public PlayerInfo(UUID uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths) {
this.uuid = uuid; this.uuid = uuid;

View file

@ -34,7 +34,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class CommandHandler { public class CommandHandler {
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>(); public static final Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>();
private static void registerCommand(ICommand command) { private static void registerCommand(ICommand command) {
if(!COMMAND_REGISTER.containsKey(command.getLabel())) { if(!COMMAND_REGISTER.containsKey(command.getLabel())) {

View file

@ -76,32 +76,27 @@ public class EventListener implements Listener {
} }
} }
@EventHandler(priority = EventPriority.MONITOR) private void handleLeave(Player player) {
public void onQuit(PlayerQuitEvent event) { Board.remove(player);
Board.remove(event.getPlayer());
if(Game.status == Status.STANDBY) { if(Game.status == Status.STANDBY) {
Board.reloadLobbyBoards(); Board.reloadLobbyBoards();
} else { } else {
Board.reloadGameBoards(); Board.reloadGameBoards();
} }
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){ for(PotionEffect effect : player.getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
Game.removeItems(event.getPlayer()); Game.removeItems(player);
}
@EventHandler(priority = EventPriority.MONITOR)
public void onQuit(PlayerQuitEvent event) {
handleLeave(event.getPlayer());
} }
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onKick(PlayerKickEvent event) { public void onKick(PlayerKickEvent event) {
Board.remove(event.getPlayer()); handleLeave(event.getPlayer());
if(Game.status == Status.STANDBY) {
Board.reloadLobbyBoards();
} else {
Board.reloadGameBoards();
}
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
Game.removeItems(event.getPlayer());
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)

View file

@ -204,14 +204,7 @@ public class Game {
Board.removeBoard(player); Board.removeBoard(player);
Board.remove(player); Board.remove(player);
player.getInventory().clear(); player.getInventory().clear();
if(bungeeLeave) { handleBungeeLeave(player);
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(leaveServer);
player.sendPluginMessage(Main.plugin, "BungeeCord", out.toByteArray());
} else {
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
}
} else { } else {
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ())); player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
Board.createLobbyBoard(player); Board.createLobbyBoard(player);
@ -274,7 +267,7 @@ public class Game {
} }
} }
public static void leave(Player player){ public static void leave(Player player) {
player.setFlying(false); player.setFlying(false);
player.setAllowFlight(false); player.setAllowFlight(false);
player.setFallDistance(0.0F); player.setFallDistance(0.0F);
@ -299,7 +292,11 @@ public class Game {
for(PotionEffect effect : player.getActivePotionEffects()){ for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
if(bungeeLeave) { handleBungeeLeave(player);
}
private static void handleBungeeLeave(Player player) {
if (bungeeLeave) {
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect"); out.writeUTF("Connect");
out.writeUTF(leaveServer); out.writeUTF(leaveServer);
@ -336,7 +333,7 @@ public class Game {
} }
} }
private static void whileStarting(){ private static void whileStarting() {
for(Player spectator : Board.getSpectators()){ for(Player spectator : Board.getSpectators()){
spectator.setFlying(spectator.getAllowFlight()); spectator.setFlying(spectator.getAllowFlight());
} }
@ -388,7 +385,7 @@ public class Game {
checkWinConditions(); checkWinConditions();
} }
public static void resetWorldborder(String worldName){ public static void resetWorldBorder(String worldName){
worldBorder = new Border(); worldBorder = new Border();
worldBorder.resetWorldborder(worldName); worldBorder.resetWorldborder(worldName);
} }

View file

@ -31,8 +31,8 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class WorldLoader { public class WorldLoader {
String mapname; final String mapname;
String savename; final String savename;
public WorldLoader(String mapname) { public WorldLoader(String mapname) {
this.mapname = mapname; this.mapname = mapname;