SteamWar/FightSystem
Archiviert
13
1

Rework of PlayerMoveListener

Dieser Commit ist enthalten in:
lixfel 2019-02-23 16:59:25 +01:00
Ursprung ce3bac464d
Commit 78ff15831c
4 geänderte Dateien mit 60 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -37,7 +37,7 @@ public class FightPlayer {
} }
public boolean isLeader() { public boolean isLeader() {
return Fight.getPlayerTeam(player).getLeader().getPlayer() == player); return Fight.getPlayerTeam(player).getLeader().getPlayer() == player;
} }

Datei anzeigen

@ -63,9 +63,9 @@ public class PlayerJoinListener implements Listener {
} 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());
} }
} }

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

@ -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;
}
} }