forked from kaboomserver/extras
Add teleport boundary limits
This commit is contained in:
parent
8c5763047d
commit
4fca7c8c80
5 changed files with 100 additions and 0 deletions
|
@ -412,6 +412,7 @@ public class Main extends JavaPlugin {
|
|||
this.getServer().getPluginManager().registerEvents(new EntityExplosion(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new EntityKnockback(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new EntitySpawn(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new EntityTeleport(), this);
|
||||
|
||||
/* Player-related modules */
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerChat(), this);
|
||||
|
@ -419,6 +420,7 @@ public class Main extends JavaPlugin {
|
|||
this.getServer().getPluginManager().registerEvents(new PlayerConnection(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerDamage(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerInteract(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerTeleport(), this);
|
||||
|
||||
/* Server-related modules */
|
||||
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
||||
|
|
|
@ -169,6 +169,19 @@ class EntitySpawn implements Listener {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean isOutsideBoundaries(double X, double Y, double Z) {
|
||||
int roundedX = (int) Math.round(X);
|
||||
int roundedY = (int) Math.round(Y);
|
||||
int roundedZ = (int) Math.round(Z);
|
||||
|
||||
if (X != roundedX ||
|
||||
Y != roundedY ||
|
||||
Z != roundedZ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*public static boolean isIllegalItem(ItemStack item) {
|
||||
try {
|
||||
if (item != null &&
|
||||
|
@ -257,6 +270,15 @@ class EntitySpawn implements Listener {
|
|||
@EventHandler
|
||||
void onEntityAddToWorld(EntityAddToWorldEvent event) {
|
||||
final Entity entity = event.getEntity();
|
||||
double X = entity.getLocation().getX();
|
||||
double Y = entity.getLocation().getY();
|
||||
double Z = entity.getLocation().getZ();
|
||||
|
||||
if (isOutsideBoundaries(X, Y, Z)) {
|
||||
entity.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
final World world = entity.getWorld();
|
||||
final Chunk chunk = entity.getChunk();
|
||||
|
||||
|
@ -277,8 +299,35 @@ class EntitySpawn implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
/*@EventHandler
|
||||
void onEntityAirChangeEvent(EntityAirChangeEvent event) {
|
||||
final Entity entity = event.getEntity();
|
||||
double X = entity.getLocation().getX();
|
||||
double Y = entity.getLocation().getY();
|
||||
double Z = entity.getLocation().getZ();
|
||||
|
||||
System.out.println(X);
|
||||
System.out.println(Y);
|
||||
System.out.println(Z);
|
||||
System.out.println(entity.getChunk().getX());
|
||||
System.out.println(entity.getChunk().getZ());
|
||||
|
||||
if (isOutsideBoundaries(X, Y, Z)) {
|
||||
entity.remove();
|
||||
}
|
||||
}*/
|
||||
|
||||
@EventHandler
|
||||
void onEntitySpawn(EntitySpawnEvent event) {
|
||||
double X = event.getLocation().getX();
|
||||
double Y = event.getLocation().getY();
|
||||
double Z = event.getLocation().getZ();
|
||||
|
||||
if (isOutsideBoundaries(X, Y, Z)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final Entity entity = event.getEntity();
|
||||
final EntityType entityType = entity.getType();
|
||||
final Chunk chunk = entity.getChunk();
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package pw.kaboom.extras;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import org.bukkit.event.entity.EntityTeleportEvent;
|
||||
|
||||
class EntityTeleport implements Listener {
|
||||
@EventHandler
|
||||
void onEntityTeleport(EntityTeleportEvent event) {
|
||||
final World world = event.getTo().getWorld();
|
||||
int X = (int) Math.round(event.getTo().getX());
|
||||
int Y = (int) Math.round(event.getTo().getY());
|
||||
int Z = (int) Math.round(event.getTo().getZ());
|
||||
|
||||
event.setTo(
|
||||
new Location(world, X, Y, Z)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -21,6 +21,9 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
|||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
import org.bukkit.event.entity.EntityTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
class PlayerDamage implements Listener {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package pw.kaboom.extras;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
class PlayerTeleport implements Listener {
|
||||
@EventHandler
|
||||
void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
final World world = event.getTo().getWorld();
|
||||
int X = (int) Math.round(event.getTo().getX());
|
||||
int Y = (int) Math.round(event.getTo().getY());
|
||||
int Z = (int) Math.round(event.getTo().getZ());
|
||||
|
||||
event.setTo(
|
||||
new Location(world, X, Y, Z)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue