SteamWar/FightSystem
Archiviert
13
1

Merge branch 'codeCleanup' into 'master'

Code cleanup

See merge request Yaruma3341/fightsystem!6
Dieser Commit ist enthalten in:
Yaruma3341 2019-02-23 17:46:23 +01:00
Commit 884be9beb3
13 geänderte Dateien mit 204 neuen und 221 gelöschten Zeilen

Datei anzeigen

@ -6,15 +6,14 @@ import me.yaruma.fightsystem.commands.AkCommand;
import me.yaruma.fightsystem.fight.*; import me.yaruma.fightsystem.fight.*;
import me.yaruma.fightsystem.listener.*; import me.yaruma.fightsystem.listener.*;
import me.yaruma.fightsystem.manager.FileManager; import me.yaruma.fightsystem.manager.FileManager;
import me.yaruma.fightsystem.utils.countdown.Countdown; import me.yaruma.fightsystem.utils.WorldEdit;
import me.yaruma.fightsystem.utils.countdown.FinishNoPlayersOnline; import me.yaruma.fightsystem.utils.countdown.*;
import me.yaruma.fightsystem.utils.countdown.FinishSetupOver;
import me.yaruma.fightsystem.utils.countdown.FinishSpectateOver;
import me.yaruma.fightsystem.utils.scoreboard.Scoreboard; import me.yaruma.fightsystem.utils.scoreboard.Scoreboard;
import me.yaruma.fightsystem.winconditions.WinconditionAllDead; import me.yaruma.fightsystem.winconditions.WinconditionAllDead;
import me.yaruma.fightsystem.winconditions.WinconditionCaptainDead; import me.yaruma.fightsystem.winconditions.WinconditionCaptainDead;
import me.yaruma.fightsystem.winconditions.WinconditionPercentSystem; import me.yaruma.fightsystem.winconditions.WinconditionPercentSystem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -225,21 +224,55 @@ public class FightSystem extends JavaPlugin {
} }
public void setPreRunningState() { public void setPreRunningState() {
if(this.fightState == FightState.SETUP) { if(this.fightState != FightState.SETUP)
return;
this.fightState = FightState.PRE_RUNNING; this.fightState = FightState.PRE_RUNNING;
int time = fileManager.getIntegerFromConfig("Times.PreFightDuration");
Countdown countdown = new Countdown(time, new FinishPreRunning());
countdown.startTimer(this);
for(FightPlayer allFightPlayers : Fight.getBlueTeam().getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
}
for(FightPlayer allFightPlayers : Fight.getRedTeam().getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
}
instance.getFightManager().teleportAllToFightSpawn();
WorldEdit.replace(Fight.getBlueTeam().getLeader().getPlayer(), team1cornerX, team1cornerY, team1cornerZ, team1cornerX + schemsizeX, team1cornerY + schemsizeY, team1cornerZ + schemsizeZ);
WorldEdit.replace(Fight.getRedTeam().getLeader().getPlayer(), team2cornerX, team2cornerY, team2cornerZ, team2cornerX + schemsizeX, team2cornerY + schemsizeY, team2cornerZ + schemsizeZ);
}
private void setAllPlayersGM(GameMode gm){
for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){
fightPlayer.getPlayer().setGameMode(gm);
}
for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){
fightPlayer.getPlayer().setGameMode(gm);
} }
} }
public void setRunningState() { public void setRunningState() {
if(this.fightState == FightState.PRE_RUNNING) { if(this.fightState != FightState.PRE_RUNNING)
return;
this.fightState = FightState.RUNNING; this.fightState = FightState.RUNNING;
setAllPlayersGM(GameMode.SURVIVAL);
if(fileManager.getBooleanFromConfig("WinConditions.Timeout")) {
int time = fileManager.getIntegerFromConfig("WinConditionParams.TimeoutTime");
Countdown countdown = new Countdown(time, new FinishTimeOver());
countdown.startTimer(FightSystem.getPlugin());
} }
Bukkit.broadcastMessage("§aArena freigegeben!");
} }
public void setSpectateState(FightTeam winFightTeam) { public void setSpectateState(FightTeam winFightTeam) {
if(this.fightState == FightState.RUNNING) { if(this.fightState != FightState.RUNNING):
return;
this.fightState = FightState.SPECTATE; this.fightState = FightState.SPECTATE;
setAllPlayersGM(GameMode.SPECTATOR);
entern = true;
Bukkit.broadcastMessage(" "); Bukkit.broadcastMessage(" ");
if(winFightTeam != null) { if(winFightTeam != null) {
@ -270,7 +303,6 @@ public class FightSystem extends JavaPlugin {
Countdown countdown = new Countdown(20*60, new FinishSpectateOver()); Countdown countdown = new Countdown(20*60, new FinishSpectateOver());
countdown.startTimer(FightSystem.getPlugin()); countdown.startTimer(FightSystem.getPlugin());
} }
}
public int getMoneyToPay(String moneyPath) { public int getMoneyToPay(String moneyPath) {
return fileManager.getIntegerFromConfig(moneyPath); return fileManager.getIntegerFromConfig(moneyPath);

Datei anzeigen

@ -10,48 +10,34 @@ public class Fight {
public static FightTeam getPlayerTeam(Player player) { public static FightTeam getPlayerTeam(Player player) {
if(redTeam.isPlayerInTeam(player)) { if(redTeam.isPlayerInTeam(player))
return redTeam; return redTeam;
} if(blueTeam.isPlayerInTeam(player))
if(blueTeam.isPlayerInTeam(player)) {
return blueTeam; return blueTeam;
}
return null; return null;
} }
public static FightTeam getOpposite(FightTeam fightTeam) { public static FightTeam getOpposite(FightTeam fightTeam) {
if(fightTeam == redTeam) { if(fightTeam == redTeam)
return blueTeam; return blueTeam;
} if(fightTeam == blueTeam)
if(fightTeam == blueTeam) {
return redTeam; return redTeam;
}
return null; return null;
} }
public static FightTeam getInvitedTeam(Player player){ public static FightTeam getInvitedTeam(Player player){
if(redTeam.getInvited().contains(player)) { if(redTeam.getInvited().contains(player))
return redTeam; return redTeam;
}else if(blueTeam.getInvited().contains(player)) { else if(blueTeam.getInvited().contains(player))
return blueTeam; return blueTeam;
}
return null; return null;
} }
public void broadcast(String message) {
blueTeam.broadcast(message);
redTeam.broadcast(message);
}
public static FightPlayer getFightPlayer(Player player) { public static FightPlayer getFightPlayer(Player player) {
if(redTeam.isPlayerInTeam(player)) { if(redTeam.isPlayerInTeam(player))
FightPlayer fightPlayer = redTeam.getFightPlayer(player); return redTeam.getFightPlayer(player);
return fightPlayer; if(blueTeam.isPlayerInTeam(player))
} return blueTeam.getFightPlayer(player);
if(blueTeam.isPlayerInTeam(player)) {
FightPlayer fightPlayer = blueTeam.getFightPlayer(player);
return fightPlayer;
}
return null; return null;
} }

Datei anzeigen

@ -8,18 +8,16 @@ public class FightPlayer {
private boolean isOut; private boolean isOut;
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (!(obj instanceof Player)) { if (!(obj instanceof Player))
return false; return false;
}
Player comp = (Player)obj; Player comp = (Player)obj;
return this.player.getUniqueId().equals(comp.getUniqueId()); return this.player.getUniqueId().equals(comp.getUniqueId());
} }
public void sendMessage(String message) { public void sendMessage(String message) {
if (this.player.isOnline()) { if (this.player != null && this.player.isOnline())
this.player.sendMessage(message); this.player.sendMessage(message);
} }
}
public FightPlayer(Player player, boolean isOut) { public FightPlayer(Player player, boolean isOut) {
this.player = player; this.player = player;
@ -39,10 +37,7 @@ public class FightPlayer {
} }
public boolean isLeader() { public boolean isLeader() {
if(Fight.getPlayerTeam(player).getLeader().getPlayer() == player) { return Fight.getPlayerTeam(player).getLeader().getPlayer() == player;
return true;
} else
return false;
} }

Datei anzeigen

@ -24,88 +24,71 @@ public class FightTeam {
public FightTeam(Player leader, FightSystem plugin) { public FightTeam(Player leader, FightSystem plugin) {
this.plugin = plugin; this.plugin = plugin;
this.leader = new FightPlayer(leader, false); this.leader = new FightPlayer(leader, false);
this.players = new ArrayList<>(); players = new ArrayList<>();
this.invited = new ArrayList<>(); invited = new ArrayList<>();
} }
public FightPlayer getFightPlayer(Player player) { public FightPlayer getFightPlayer(Player player) {
if(this.leader.getPlayer().equals(player)) { if(leader.getPlayer().equals(player))
return this.leader; return leader;
} for(FightPlayer fightPlayer : players) {
for(FightPlayer fightPlayer : this.players) { if(fightPlayer.getPlayer().equals(player))
if(!fightPlayer.getPlayer().equals(player)) continue;
return fightPlayer; return fightPlayer;
} }
return null; return null;
} }
public void setPlayerOut(Player player) { public void setPlayerOut(Player player) {
this.getFightPlayer(player).setOut(true); getFightPlayer(player).setOut(true);
} }
public boolean allPlayersOut() { public boolean allPlayersOut() {
boolean allout = true;
if(!this.leader.isOut()) { if(!this.leader.isOut()) {
allout = false; return false;
} }
for(FightPlayer fightPlayer : this.players) { for(FightPlayer fightPlayer : this.players) {
if(fightPlayer.isOut()) continue; if(!fightPlayer.isOut())
allout = false; return false;
} }
return allout; return true;
} }
public boolean isPlayerInTeam(Player player) { public boolean isPlayerInTeam(Player player) {
for(FightPlayer fightPlayer : this.players) { for(FightPlayer fightPlayer : this.players) {
if(!fightPlayer.getPlayer().equals(player)) continue; if(fightPlayer.getPlayer().equals(player))
return true; return true;
} }
if(this.leader.getPlayer() == null) return false; return leader.getPlayer() != null && leader.getPlayer().equals(player);
if(this.leader.getPlayer().equals(player)) {
return true;
}
return false;
} }
public boolean isPlayerLeader(Player player) { public boolean isPlayerLeader(Player player) {
if(this.leader.getPlayer().equals(player)) { return leader.getPlayer().equals(player);
return true;
}
return false;
} }
public boolean isPlayerMember(Player player) { public boolean isPlayerMember(Player player) {
for(FightPlayer fightPlayer : this.players) { return isPlayerInTeam(player) && !isPlayerLeader(player);
if(!fightPlayer.getPlayer().equals(player)) continue;
return true;
}
return false;
} }
public void broadcast(String message) { public void broadcast(String message) {
this.leader.sendMessage(message); leader.sendMessage(message);
for(FightPlayer fightPlayer : this.players) { for(FightPlayer fightPlayer : players) {
fightPlayer.sendMessage(message); fightPlayer.sendMessage(message);
} }
} }
public void addMember(Player player) { public void addMember(Player player) {
FightPlayer fightPlayer = new FightPlayer(player, false); FightPlayer fightPlayer = new FightPlayer(player, false);
this.players.add(fightPlayer); players.add(fightPlayer);
this.invited.remove(player); invited.remove(player);
} }
public void removePlayer(Player player) { public void removePlayer(Player player) {
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
this.players.remove(fightPlayer); players.remove(fightPlayer);
} }
public boolean hasTeamLeader() { public boolean hasTeamLeader() {
if(this.leader != null) { return leader.getPlayer() != null;
return true;
} else
return false;
} }
public FightPlayer getLeader() { public FightPlayer getLeader() {
@ -145,18 +128,6 @@ public class FightTeam {
broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!"); broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit!");
if(Fight.getOpposite(fightTeam).isReady()) { if(Fight.getOpposite(fightTeam).isReady()) {
instance.setPreRunningState(); instance.setPreRunningState();
int time = instance.getFileManager().getIntegerFromConfig("Times.PreFightDuration");
Countdown countdown = new Countdown(time, new FinishPreRunning());
countdown.startTimer(instance);
for(FightPlayer allFightPlayers : fightTeam.getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
}
for(FightPlayer allFightPlayers : Fight.getOpposite(fightTeam).getPlayers()) {
allFightPlayers.getPlayer().getInventory().clear();
}
instance.getFightManager().teleportAllToFightSpawn();
WorldEdit.replace(fightTeam.getLeader().getPlayer(), instance.getTeam1cornerX(), instance.getTeam1cornerY(), instance.getTeam1cornerZ(), instance.getTeam1cornerX() + instance.getSchemsizeX(), instance.getTeam1cornerY() + instance.getSchemsizeY(), instance.getTeam1cornerZ() + instance.getSchemsizeZ());
WorldEdit.replace(Fight.getOpposite(fightTeam).getLeader().getPlayer(), instance.getTeam2cornerX(), instance.getTeam2cornerY(), instance.getTeam2cornerZ(), instance.getTeam2cornerX() + instance.getSchemsizeX(), instance.getTeam2cornerY() + instance.getSchemsizeY(), instance.getTeam2cornerZ() + instance.getSchemsizeZ());
} }
} else { } else {
fightTeam.getLeader().getPlayer().getInventory().setItem(3, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); fightTeam.getLeader().getPlayer().getInventory().setItem(3, new ItemBuilder(Material.INK_SACK, (short) 10).removeAllAtributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build());

Datei anzeigen

@ -14,19 +14,15 @@ public class BlockBreakListener implements Listener {
public void handleBlockBreak(BlockBreakEvent event) { public void handleBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(Fight.getPlayerTeam(player) == null) { if(Fight.getPlayerTeam(player) == null)
event.setCancelled(true); event.setCancelled(true);
return; else if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) {
}
if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) {
event.setCancelled(true); event.setCancelled(true);
if(FightSystem.getPlugin().getFightState() == FightState.RUNNING || FightSystem.getPlugin().getFightState() == FightState.PRE_RUNNING) { if(FightSystem.getPlugin().getFightState() == FightState.PRE_RUNNING) {
player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke setzen!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke abbauen!");
} else } else
player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr setzen!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr abbauen!");
return;
} }
} }
} }

Datei anzeigen

@ -14,19 +14,14 @@ public class BlockPlaceListener implements Listener {
public void handleBlockPlace(BlockPlaceEvent event) { public void handleBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(Fight.getPlayerTeam(player) == null) { if(Fight.getPlayerTeam(player) == null)
event.setCancelled(true); event.setCancelled(true);
return; else if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) {
}
if(FightSystem.getPlugin().getFightState() != FightState.RUNNING) {
event.setCancelled(true); event.setCancelled(true);
if(FightSystem.getPlugin().getFightState() == FightState.PRE_RUNNING) { if(FightSystem.getPlugin().getFightState() == FightState.PRE_RUNNING) {
player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke setzen!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst erst nach Fightbeginn Blöcke setzen!");
} else } else
player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr setzen!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst keine Blöcke mehr setzen!");
return;
} }
} }
} }

Datei anzeigen

@ -22,17 +22,13 @@ public class PlayerDeathListener implements Listener {
fightTeam.getFightPlayer(player).setOut(true); fightTeam.getFightPlayer(player).setOut(true);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §cist gestorben!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler §6" + player.getName() + " §cist gestorben!");
if(fightTeam.allPlayersOut()) { if(fightTeam.allPlayersOut()) {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team von " + fightTeam.getLeader().getPlayer().getName() + " §csind gestorben!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team " + fightTeam.getLeader().getPlayer().getName() + " §csind gestorben!");
instance.setSpectateState(oppositeFightTeam); instance.setSpectateState(oppositeFightTeam);
return;
} else { } else {
if(Fight.getPlayerTeam(player) == Fight.redTeam) { if(Fight.getPlayerTeam(player) == Fight.redTeam){
player.teleport(instance.getFightManager().getRedTeleportLocation()); player.teleport(instance.getFightManager().getRedTeleportLocation());
return; }else{
} player.teleport(instance.getFightManager().getBlueTeleportLocation());
if(Fight.getPlayerTeam(player) == Fight.blueTeam) {
player.teleport(instance.getFightManager().getRedTeleportLocation());
return;
} }
} }
} }

Datei anzeigen

@ -28,18 +28,15 @@ public class PlayerInteractListener implements Listener {
@EventHandler @EventHandler
public void handlePlayerInteract(PlayerInteractEvent event) { public void handlePlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(instance.getFightState() == FightState.SETUP &&
event.getItem() != null &&
Fight.getPlayerTeam(player) != null) {
Material material = event.getItem().getType(); Material material = event.getItem().getType();
ItemMeta itemMeta = event.getItem().getItemMeta(); ItemMeta itemMeta = event.getItem().getItemMeta();
String displayName = itemMeta.getDisplayName(); String displayName = itemMeta.getDisplayName();
if(instance.getFightState() == FightState.SETUP) {
if(Fight.getPlayerTeam(player) == null) return;
FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player); FightPlayer fightPlayer = Fight.getPlayerTeam(player).getFightPlayer(player);
if(fightPlayer.isLeader()) { if(fightPlayer.isLeader() && material == Material.INK_SACK) {
if(material == null) return;
if(material == Material.INK_SACK) {
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
switch (displayName) { switch (displayName) {
@ -54,7 +51,6 @@ public class PlayerInteractListener implements Listener {
Countdown countdown = new Countdown(20*30, new FinishNoPlayersOnline()); Countdown countdown = new Countdown(20*30, new FinishNoPlayersOnline());
countdown.startTimer(instance); countdown.startTimer(instance);
break; break;
default: default:
event.setCancelled(true); event.setCancelled(true);
break; break;
@ -62,7 +58,6 @@ public class PlayerInteractListener implements Listener {
} }
} }
} }
}
} }

Datei anzeigen

@ -47,32 +47,30 @@ public class PlayerJoinListener implements Listener {
FightTeam fightTeam = Fight.getPlayerTeam(player); FightTeam fightTeam = Fight.getPlayerTeam(player);
if(Fight.getPlayerTeam(player) != null) { if(fightTeam != null) {
FightPlayer fightPlayer = fightTeam.getFightPlayer(player); FightPlayer fightPlayer = fightTeam.getFightPlayer(player);
if(instance.getFightState() == FightState.SETUP) { if(instance.getFightState() == FightState.SETUP) {
if(fightTeam == Fight.redTeam) { if(fightTeam == Fight.redTeam)
player.teleport(instance.getFightManager().getRedTeleportLocation()); player.teleport(instance.getFightManager().getRedTeleportLocation());
} else else
player.teleport(instance.getFightManager().getBlueTeleportLocation()); player.teleport(instance.getFightManager().getBlueTeleportLocation());
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.ADVENTURE);
if(fightPlayer.isLeader()) SetupItems.giveSetupItems(player); if(fightPlayer.isLeader()) SetupItems.giveSetupItems(player);
if(fightPlayer.isOut()) {
fightPlayer.setOut(false); fightPlayer.setOut(false);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightPlayer.getPlayer().getName() + " §aist dem Kampf wieder beigetreten!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §6" + fightPlayer.getPlayer().getName() + " §aist dem Kampf wieder beigetreten!");
}
} else { } else {
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
if(fightTeam == Fight.redTeam) { if(fightTeam == Fight.redTeam)
player.teleport(FightSystem.getPlugin().getTeam1SpawnLoc()); player.teleport(instance.getFightManager().getRedTeleportLocation());
} else else
player.teleport(FightSystem.getPlugin().getTeam2SpawnLoc()); player.teleport(instance.getFightManager().getBlueTeleportLocation());
} }
} }
if(Fight.getRedTeam().getLeader().getPlayer() != null && Fight.getBlueTeam().getLeader().getPlayer() != null) { if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader()) {
int setupDuration = fileManager.getIntegerFromConfig("Times.SetupDuration"); int setupDuration = fileManager.getIntegerFromConfig("Times.SetupDuration");
Countdown countdown = new Countdown(setupDuration, new FinishSetupOver()); Countdown countdown = new Countdown(setupDuration, new FinishSetupOver());
countdown.startTimer(instance); countdown.startTimer(instance);

Datei anzeigen

@ -2,6 +2,7 @@ package me.yaruma.fightsystem.listener;
import me.yaruma.fightsystem.FightSystem; import me.yaruma.fightsystem.FightSystem;
import me.yaruma.fightsystem.fight.Fight; import me.yaruma.fightsystem.fight.Fight;
import me.yaruma.fightsystem.fight.FightState;
import me.yaruma.fightsystem.fight.FightTeam; import me.yaruma.fightsystem.fight.FightTeam;
import me.yaruma.fightsystem.manager.FileManager; import me.yaruma.fightsystem.manager.FileManager;
import me.yaruma.fightsystem.utils.Region; import me.yaruma.fightsystem.utils.Region;
@ -21,36 +22,44 @@ public class PlayerMoveListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location to = event.getTo(); Location to = event.getTo();
Location from = event.getFrom(); Location from = event.getFrom();
FightTeam fightTeam = Fight.getPlayerTeam(player);
if(Fight.getPlayerTeam(player) == null) { //Check in Arena
if(Region.isInRegion(to, instance.getTeam1cornerX(), instance.getTeam1cornerY(), instance.getTeam1cornerZ(), instance.getTeam1cornerX() + instance.getSchemsizeX(), instance.getTeam1cornerY() + instance.getSchemsizeY(), instance.getTeam1cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic")) || Region.isInRegion(to, instance.getTeam2cornerX(), instance.getTeam2cornerY(), instance.getTeam2cornerZ(), instance.getTeam2cornerX() + instance.getSchemsizeX(), instance.getTeam2cornerY() + instance.getSchemsizeY(), instance.getTeam2cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) { if(!Region.isIn2DRegion(to, instance.ArenaMinX, instance.ArenaMinZ, instance.ArenaMaxX, instance.ArenaMaxZ)){
player.teleport(from); player.teleport(from);
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht weiter zu den Kämpfern!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst die Arena nicht verlassen!");
}
return; return;
} }
if(!instance.isEntern()) { //Check under Arena
if(to.getBlockY() <= fileManager.getIntegerFromConfig("Arena.underArenaBorder")) {
FightTeam fightTeam = Fight.getPlayerTeam(player); if(fightTeam == null){
if(Region.isInRegion(to, instance.getTeam1cornerX(), instance.getTeam1cornerY(), instance.getTeam1cornerZ(), instance.getTeam1cornerX() + instance.getSchemsizeX(), instance.getTeam1cornerY() + instance.getSchemsizeY(), instance.getTeam1cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) {
if(fightTeam == Fight.blueTeam) {
player.teleport(from); player.teleport(from);
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht zu Team " + fileManager.getStringFromConfig("Output.TeamRedColor") + fileManager.getStringFromConfig("Output.TeamRedName") + " §c!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst die Arena nicht verlassen!");
}else if(instance.getCurrentFightState() == FightState.RUNNING)
player.damage(2);
else if(fightTeam == Fight.redTeam)
player.teleport(instance.getFightManager().getRedTeleportLocation());
else
player.teleport(instance.getFightManager().getBlueTeleportLocation());
return;
} }
} else if(Region.isInRegion(to, instance.getTeam2cornerX(), instance.getTeam2cornerY(), instance.getTeam2cornerZ(), instance.getTeam2cornerX() + instance.getSchemsizeX(), instance.getTeam2cornerY() + instance.getSchemsizeY(), instance.getTeam2cornerZ() + instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"))) {
if(fightTeam == Fight.redTeam) { //Check TeamAreas
boolean inBlueArea = Region.isIn2DRange(to, instance.getTeam1cornerX(), instance.getTeam1cornerZ(), instance.getSchemsizeX(), instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"));
boolean inRedArea = Region.isIn2DRange(to, instance.getTeam2cornerX(), instance.getTeam2cornerZ(), instance.getSchemsizeX(), instance.getSchemsizeZ(), fileManager.getIntegerFromConfig("Arena.BorderFromSchematic"));
if(inBlueArea || inRedArea) {
if(fightTeam == null){
player.teleport(from); player.teleport(from);
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht weiter zu den Kämpfern!");
}
}else if(fightTeam != null && !instance.isEntern()){
player.teleport(from);
if (fightTeam == Fight.blueTeam)
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht zu Team " + fileManager.getStringFromConfig("Output.TeamRedColor") + fileManager.getStringFromConfig("Output.TeamRedName") + " §c!");
else
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht zu Team " + fileManager.getStringFromConfig("Output.TeamBlueColor") + fileManager.getStringFromConfig("Output.TeamBlueName") + " §c!"); player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht zu Team " + fileManager.getStringFromConfig("Output.TeamBlueColor") + fileManager.getStringFromConfig("Output.TeamBlueName") + " §c!");
} }
} }
}
if(to.getBlockY() <= fileManager.getIntegerFromConfig("Arena.underArenaBorder")) {
player.damage(2);
}
}
} }

Datei anzeigen

@ -28,7 +28,6 @@ public class PlayerQuitListener implements Listener {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team von §6" + fightTeam.getLeader().getPlayer() + " §chaben den Kampf verlassen! \n §4Stoppe Server in 30 Sekunden..."); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team von §6" + fightTeam.getLeader().getPlayer() + " §chaben den Kampf verlassen! \n §4Stoppe Server in 30 Sekunden...");
Countdown countdown = new Countdown(30*20, new FinishNoPlayersOnline()); Countdown countdown = new Countdown(30*20, new FinishNoPlayersOnline());
countdown.startTimer(FightSystem.getPlugin()); countdown.startTimer(FightSystem.getPlugin());
return;
} else { } else {
Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team von §6" + fightTeam.getLeader().getPlayer() + " §csind tot oder haben den Kampf verlassen! \n §60 Sekunden Zeit zum Begutachten!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§cAlle Spieler aus dem Team von §6" + fightTeam.getLeader().getPlayer() + " §csind tot oder haben den Kampf verlassen! \n §60 Sekunden Zeit zum Begutachten!");
FightSystem.getPlugin().setSpectateState(Fight.getOpposite(fightTeam)); FightSystem.getPlugin().setSpectateState(Fight.getOpposite(fightTeam));

Datei anzeigen

@ -5,13 +5,31 @@ import org.bukkit.entity.Player;
public class Region { public class Region {
public static boolean isInRegion(Location location, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int border) { public static boolean isInRange(Location location, int minX, int minY, int minZ, int xRange, int yRange, int zRange, int margin) {
return isInRegion(location, minX, minY, minZ, minX + xRange, minY + yRange, minZ + zRange, margin);
if(location.getBlockX() >= (minX - border) && location.getBlockX() <= (maxX + border) && location.getBlockY() >= (minY - border) && location.getBlockY() <= (maxY + border) && location.getBlockZ() >= (minZ - border) && location.getBlockZ() <= (maxX + border)) {
return true;
} else
return false;
} }
public static boolean isInRegion(Location location, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int margin) {
return isIn2DRegion(location, minX, minZ, maxX, maxZ, margin) && inRange(location.getBlockY(), minY, maxY, margin);
}
public static boolean isIn2DRange(Location location, int minX, int minZ, int xRange, int zRange, int margin){
return isIn2DRegion(location, minX, minZ, minX + xRange, minZ + zRange, margin);
}
public static boolean isIn2DRegion(Location location, int minX, int minZ, int maxX, int maxZ, int margin){
return inRange(location.getBlockX(), minX, maxX, margin) && inRange(location.getBlockZ(), minZ, maxZ, margin);
}
public static boolean isIn2DRegion(Location location, int minX, int minZ, int maxX, int maxZ){
return inRange(location.getBlockX(), minX, maxX, margin) && inRange(location.getBlockZ(), minZ, maxZ, margin);
}
public static boolean inRange(double value, int min, int max, int margin){
return inRange(value, min-margin, max+margin);
}
public static boolean inRange(double value, int min, int max){
return min <= value && value <= max;
}
} }

Datei anzeigen

@ -16,12 +16,5 @@ public class FinishPreRunning implements CountdownCallback {
@Override @Override
public void countdownFinished() { public void countdownFinished() {
FightSystem.getPlugin().setRunningState(); FightSystem.getPlugin().setRunningState();
if(fileManager.getBooleanFromConfig("WinConditions.Timeout")) {
int time = fileManager.getIntegerFromConfig("WinConditionParams.TimeoutTime");
Countdown countdown = new Countdown(time, new FinishTimeOver());
countdown.startTimer(FightSystem.getPlugin());
}
Bukkit.broadcastMessage("§aArena freigegeben!");
} }
} }