Rework of PlayerMoveListener
Dieser Commit ist enthalten in:
Ursprung
ce3bac464d
Commit
78ff15831c
@ -37,7 +37,7 @@ public class FightPlayer {
|
||||
}
|
||||
|
||||
public boolean isLeader() {
|
||||
return Fight.getPlayerTeam(player).getLeader().getPlayer() == player);
|
||||
return Fight.getPlayerTeam(player).getLeader().getPlayer() == player;
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,9 +63,9 @@ public class PlayerJoinListener implements Listener {
|
||||
} else {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
if(fightTeam == Fight.redTeam)
|
||||
player.teleport(FightSystem.getPlugin().getTeam1SpawnLoc());
|
||||
player.teleport(instance.getFightManager().getRedTeleportLocation());
|
||||
else
|
||||
player.teleport(FightSystem.getPlugin().getTeam2SpawnLoc());
|
||||
player.teleport(instance.getFightManager().getBlueTeleportLocation());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package me.yaruma.fightsystem.listener;
|
||||
|
||||
import me.yaruma.fightsystem.FightSystem;
|
||||
import me.yaruma.fightsystem.fight.Fight;
|
||||
import me.yaruma.fightsystem.fight.FightState;
|
||||
import me.yaruma.fightsystem.fight.FightTeam;
|
||||
import me.yaruma.fightsystem.manager.FileManager;
|
||||
import me.yaruma.fightsystem.utils.Region;
|
||||
@ -21,36 +22,44 @@ public class PlayerMoveListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||
|
||||
if(Fight.getPlayerTeam(player) == 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")) || 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"))) {
|
||||
player.teleport(from);
|
||||
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht weiter zu den Kämpfern!");
|
||||
}
|
||||
//Check in Arena
|
||||
if(!Region.isIn2DRegion(to, instance.ArenaMinX, instance.ArenaMinZ, instance.ArenaMaxX, instance.ArenaMaxZ)){
|
||||
player.teleport(from);
|
||||
player.sendMessage(FightSystem.PREFIX + "§cDu darfst die Arena nicht verlassen!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!instance.isEntern()) {
|
||||
|
||||
FightTeam fightTeam = Fight.getPlayerTeam(player);
|
||||
|
||||
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.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht zu Team " + fileManager.getStringFromConfig("Output.TeamRedColor") + fileManager.getStringFromConfig("Output.TeamRedName") + " §c!");
|
||||
}
|
||||
} 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) {
|
||||
player.teleport(from);
|
||||
player.sendMessage(FightSystem.PREFIX + "§cDu darfst nicht zu Team " + fileManager.getStringFromConfig("Output.TeamBlueColor") + fileManager.getStringFromConfig("Output.TeamBlueName") + " §c!");
|
||||
}
|
||||
}
|
||||
//Check under Arena
|
||||
if(to.getBlockY() <= fileManager.getIntegerFromConfig("Arena.underArenaBorder")) {
|
||||
if(fightTeam == null){
|
||||
player.teleport(from);
|
||||
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;
|
||||
}
|
||||
|
||||
if(to.getBlockY() <= fileManager.getIntegerFromConfig("Arena.underArenaBorder")) {
|
||||
player.damage(2);
|
||||
//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.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!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,13 +5,31 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class Region {
|
||||
|
||||
public static boolean isInRegion(Location location, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int border) {
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren