Command sets coordinates for the spawnflyarea
This commit is contained in:
parent
d452f76007
commit
7fe63c08b5
@ -3,9 +3,12 @@ package dev.kske.spawnfly;
|
||||
import org.bukkit.command.*;
|
||||
|
||||
public class SpawnCommand implements CommandExecutor {
|
||||
|
||||
SpawnFly spawnFly;
|
||||
|
||||
public SpawnCommand(SpawnFly spawnFly) { this.spawnFly = spawnFly;}
|
||||
public SpawnCommand(SpawnFly spawnFly) {
|
||||
this.spawnFly = spawnFly;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label,
|
||||
@ -21,18 +24,19 @@ public class SpawnCommand implements CommandExecutor {
|
||||
// sender.sendMessage("Argument " +(i + 1) + " is " + value);
|
||||
cnt++;
|
||||
} catch (Exception e) {
|
||||
//sender.sendMessage("Argument " + (i + 1) + " is not valid as a coordinate!");
|
||||
// sender.sendMessage("Argument " + (i + 1) + " is not valid as a
|
||||
// coordinate!");
|
||||
}
|
||||
}
|
||||
if (cnt == 6) {
|
||||
spawnFly.setCoordinates(cords[0], cords[1], cords[2], cords[3], cords[4], cords[5]);
|
||||
}
|
||||
else {
|
||||
spawnFly.setCoordinates(cords[0], cords[1], cords[2], cords[3], cords[4],
|
||||
cords[5]);
|
||||
} else {
|
||||
sender.sendMessage("Please use valid coordinates!");
|
||||
}
|
||||
}
|
||||
} else
|
||||
sender.sendMessage("Please use 6 coordinates!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,8 @@ import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
|
||||
public class SpawnListener implements Listener {
|
||||
int x1, y1, z1, x2, y2, z2;
|
||||
|
||||
int x1 = 0, y1 = 0, z1 = 0, x2 = 0, y2 = 0, z2 = 0;
|
||||
|
||||
Map<String, Boolean> canceledEvents = new HashMap<>();
|
||||
|
||||
@ -18,7 +19,8 @@ public class SpawnListener implements Listener {
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
Player player = e.getPlayer();
|
||||
Location location = player.getLocation();
|
||||
if(isInSpawn(location) && player.getVelocity().getY() < 0 && !player.isOnGround() && !canceledEvents.get(player.getName()) && player.getFallDistance() > 1) {
|
||||
if (isInSpawn(location) && player.getVelocity().getY() < 0 && !player.isOnGround()
|
||||
&& !canceledEvents.get(player.getName()) && player.getFallDistance() > 1) {
|
||||
player.setGliding(true);
|
||||
canceledEvents.put(player.getName(), true);
|
||||
}
|
||||
@ -35,13 +37,26 @@ public class SpawnListener implements Listener {
|
||||
}
|
||||
|
||||
private boolean isInSpawn(Location location) {
|
||||
return (location.getX() <= -277 + 3 && location.getX() >= -302 - 3)
|
||||
&& (location.getZ() <= -172 + 3 && location.getZ() >= -191 - 3);
|
||||
if (x1 != 0 && y1 != 0 && z1 != 0 && x2 != 0 && y2 != 0 && z2 != 0) {
|
||||
if (isInRange(x1, x2, (int) location.getX()) && isInRange(y1, y2, (int) location.getY())
|
||||
&& isInRange(z1, z2, (int) location.getZ())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isInRange(int rangeEnd1, int rangeEnd2, int intToCheck) {
|
||||
if (rangeEnd1 > rangeEnd2 && intToCheck <= rangeEnd1 && intToCheck >= rangeEnd2) {
|
||||
return true;
|
||||
} else if (rangeEnd1 < rangeEnd2 && intToCheck >= rangeEnd1 && intToCheck <= rangeEnd2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void cancelEvent(EntityToggleGlideEvent e) {
|
||||
if(canceledEvents.get(e.getEntity().getName()) && e.getEntity().getVelocity().getY() != 0 && !e.getEntity().isOnGround())
|
||||
if (canceledEvents.get(e.getEntity().getName()) && e.getEntity().getVelocity().getY() != 0
|
||||
&& !e.getEntity().isOnGround())
|
||||
e.setCancelled(true);
|
||||
else {
|
||||
e.setCancelled(false);
|
||||
|
Loading…
Reference in New Issue
Block a user