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

View file

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

View file

@ -23,8 +23,15 @@ import java.util.UUID;
public class PlayerInfo {
public UUID uuid;
public int hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths;
public final UUID uuid;
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) {
this.uuid = uuid;

View file

@ -34,7 +34,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
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) {
if(!COMMAND_REGISTER.containsKey(command.getLabel())) {

View file

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

View file

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

View file

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