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.*;
|
import org.bukkit.command.*;
|
||||||
|
|
||||||
public class SpawnCommand implements CommandExecutor {
|
public class SpawnCommand implements CommandExecutor {
|
||||||
|
|
||||||
SpawnFly spawnFly;
|
SpawnFly spawnFly;
|
||||||
|
|
||||||
public SpawnCommand(SpawnFly spawnFly) { this.spawnFly = spawnFly;}
|
public SpawnCommand(SpawnFly spawnFly) {
|
||||||
|
this.spawnFly = spawnFly;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, org.bukkit.command.Command command, String label,
|
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);
|
// sender.sendMessage("Argument " +(i + 1) + " is " + value);
|
||||||
cnt++;
|
cnt++;
|
||||||
} catch (Exception e) {
|
} 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) {
|
if (cnt == 6) {
|
||||||
spawnFly.setCoordinates(cords[0], cords[1], cords[2], cords[3], cords[4], cords[5]);
|
spawnFly.setCoordinates(cords[0], cords[1], cords[2], cords[3], cords[4],
|
||||||
}
|
cords[5]);
|
||||||
else {
|
} else {
|
||||||
sender.sendMessage("Please use valid coordinates!");
|
sender.sendMessage("Please use valid coordinates!");
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
sender.sendMessage("Please use 6 coordinates!");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,8 @@ import org.bukkit.event.entity.EntityToggleGlideEvent;
|
|||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
|
|
||||||
public class SpawnListener implements Listener {
|
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<>();
|
Map<String, Boolean> canceledEvents = new HashMap<>();
|
||||||
|
|
||||||
@ -18,7 +19,8 @@ public class SpawnListener implements Listener {
|
|||||||
public void onMove(PlayerMoveEvent e) {
|
public void onMove(PlayerMoveEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
Location location = player.getLocation();
|
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);
|
player.setGliding(true);
|
||||||
canceledEvents.put(player.getName(), true);
|
canceledEvents.put(player.getName(), true);
|
||||||
}
|
}
|
||||||
@ -35,13 +37,26 @@ public class SpawnListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInSpawn(Location location) {
|
private boolean isInSpawn(Location location) {
|
||||||
return (location.getX() <= -277 + 3 && location.getX() >= -302 - 3)
|
if (x1 != 0 && y1 != 0 && z1 != 0 && x2 != 0 && y2 != 0 && z2 != 0) {
|
||||||
&& (location.getZ() <= -172 + 3 && location.getZ() >= -191 - 3);
|
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
|
@EventHandler
|
||||||
public void cancelEvent(EntityToggleGlideEvent e) {
|
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);
|
e.setCancelled(true);
|
||||||
else {
|
else {
|
||||||
e.setCancelled(false);
|
e.setCancelled(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user