mirror of
https://github.com/kaboomserver/extras.git
synced 2024-11-30 03:15:41 -05:00
Remove some unnecessary checks
This commit is contained in:
parent
7cbaf7f812
commit
7b51a42080
8 changed files with 3 additions and 261 deletions
|
@ -12,12 +12,10 @@ import pw.kaboom.extras.modules.block.BlockPhysics;
|
|||
import pw.kaboom.extras.modules.entity.EntityExplosion;
|
||||
import pw.kaboom.extras.modules.entity.EntityKnockback;
|
||||
import pw.kaboom.extras.modules.entity.EntitySpawn;
|
||||
import pw.kaboom.extras.modules.entity.EntityTeleport;
|
||||
import pw.kaboom.extras.modules.player.*;
|
||||
import pw.kaboom.extras.modules.server.ServerCommand;
|
||||
import pw.kaboom.extras.modules.server.ServerGameRule;
|
||||
import pw.kaboom.extras.modules.server.ServerTabComplete;
|
||||
import pw.kaboom.extras.modules.server.ServerTick;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
@ -28,16 +26,6 @@ public final class Main extends JavaPlugin {
|
|||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
/* Fill lists */
|
||||
Collections.addAll(
|
||||
BlockPhysics.getBlockFaces(),
|
||||
BlockFace.NORTH,
|
||||
BlockFace.SOUTH,
|
||||
BlockFace.WEST,
|
||||
BlockFace.EAST,
|
||||
BlockFace.UP
|
||||
);
|
||||
|
||||
/* Load missing config.yml defaults */
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
|
@ -80,7 +68,6 @@ public final 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);
|
||||
|
@ -96,7 +83,6 @@ public final class Main extends JavaPlugin {
|
|||
this.getServer().getPluginManager().registerEvents(new ServerCommand(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ServerGameRule(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ServerTabComplete(), this);
|
||||
this.getServer().getPluginManager().registerEvents(new ServerTick(), this);
|
||||
|
||||
/* Custom worlds */
|
||||
this.getServer().createWorld(
|
||||
|
|
|
@ -3,39 +3,13 @@ package pw.kaboom.extras.modules.block;
|
|||
import org.bukkit.Chunk;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
public final class BlockCheck implements Listener {
|
||||
@EventHandler
|
||||
void onBlockPlace(final BlockPlaceEvent event) {
|
||||
try {
|
||||
final int maxItemStringLength = 3019;
|
||||
|
||||
if (event.getItemInHand().toString().length() > maxItemStringLength) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
event.getBlockPlaced().getState();
|
||||
} catch (Exception exception) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onChunkUnload(final ChunkUnloadEvent event) {
|
||||
for (Chunk chunk : event.getChunk().getWorld().getForceLoadedChunks()) {
|
||||
chunk.setForceLoaded(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onSignChange(final SignChangeEvent event) {
|
||||
try {
|
||||
event.getLines();
|
||||
} catch (Exception exception) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,109 +24,11 @@ public final class BlockPhysics implements Listener {
|
|||
// This class contains code to prevent large areas of non-solid blocks
|
||||
// from crashing the server
|
||||
private static double tps = 20;
|
||||
private static HashSet<BlockFace> blockFaces = new HashSet<BlockFace>();
|
||||
|
||||
@EventHandler
|
||||
void onBlockDestroy(final BlockDestroyEvent event) {
|
||||
try {
|
||||
if (!event.getBlock().getType().isSolid()) {
|
||||
for (BlockFace face : getBlockFaces()) {
|
||||
if (event.getBlock().getRelative(face).getType()
|
||||
!= event.getBlock().getType()) {
|
||||
return;
|
||||
}
|
||||
if (!event.getBlock().getType().equals(Material.AIR)) {
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
}
|
||||
if (!event.isCancelled()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception | StackOverflowError e) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onBlockFade(final BlockFadeEvent event) {
|
||||
try {
|
||||
if (event.getBlock().getType() == Material.FIRE) {
|
||||
event.getBlock().setType(Material.AIR, false);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
} catch (Exception | StackOverflowError e) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onBlockForm(final BlockFormEvent event) {
|
||||
try {
|
||||
if (event.getBlock().getType() == Material.LAVA
|
||||
|| event.getBlock().getType() == Material.WATER) {
|
||||
for (BlockFace face : getBlockFaces()) {
|
||||
if (event.getBlock().getRelative(face).getType() != Material.LAVA
|
||||
&& event.getBlock().getRelative(face).getType() != Material.WATER) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
} catch (Exception | StackOverflowError e) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onBlockFromTo(final BlockFromToEvent event) {
|
||||
try {
|
||||
if (event.getBlock().getType() == Material.LAVA
|
||||
|| event.getBlock().getType() == Material.WATER) {
|
||||
boolean lavaFound = false;
|
||||
boolean waterFound = false;
|
||||
|
||||
for (BlockFace face : getBlockFaces()) {
|
||||
if (event.getBlock().getRelative(face).getType() == Material.LAVA
|
||||
&& !lavaFound) {
|
||||
lavaFound = true;
|
||||
} else if (event.getBlock().getRelative(face).getType() == Material.WATER
|
||||
&& !waterFound) {
|
||||
waterFound = true;
|
||||
}
|
||||
|
||||
if (lavaFound && waterFound) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception | StackOverflowError e) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onBlockPhysics(final BlockPhysicsEvent event) {
|
||||
try {
|
||||
switch (event.getChangedType()) {
|
||||
case ACTIVATOR_RAIL:
|
||||
case DETECTOR_RAIL:
|
||||
case POWERED_RAIL:
|
||||
case RAIL:
|
||||
case COMPARATOR:
|
||||
case REDSTONE_TORCH:
|
||||
case REDSTONE_WIRE:
|
||||
case REPEATER:
|
||||
case TRIPWIRE:
|
||||
if (!event.getBlock().getRelative(BlockFace.DOWN).getType().isSolid()
|
||||
&& !Material.AIR.equals(event.getBlock().getRelative(BlockFace.DOWN)
|
||||
.getType())
|
||||
&& !Material.CAVE_AIR.equals(event.getBlock()
|
||||
.getRelative(BlockFace.DOWN).getType())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
case COMMAND_BLOCK:
|
||||
case CHAIN_COMMAND_BLOCK:
|
||||
case REPEATING_COMMAND_BLOCK:
|
||||
|
@ -167,10 +69,6 @@ public final class BlockPhysics implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
public static HashSet<BlockFace> getBlockFaces() {
|
||||
return blockFaces;
|
||||
}
|
||||
|
||||
private static void updateTPS() {
|
||||
final double[] tpsValues = Bukkit.getTPS();
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.bukkit.entity.Vehicle;
|
|||
import org.bukkit.entity.minecart.ExplosiveMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.TNTPrimeEvent;
|
||||
import org.bukkit.event.entity.AreaEffectCloudApplyEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
|
@ -27,7 +28,6 @@ import org.bukkit.event.entity.SpawnerSpawnEvent;
|
|||
import org.bukkit.event.vehicle.VehicleCreateEvent;
|
||||
import org.bukkit.event.weather.LightningStrikeEvent;
|
||||
|
||||
import com.destroystokyo.paper.event.block.TNTPrimeEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
|
||||
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -107,21 +107,6 @@ public final class EntitySpawn implements Listener {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean isOutsideBoundaries(final double x, final double y, final double z) {
|
||||
final int maxValue = 30000000;
|
||||
final int minValue = -30000000;
|
||||
|
||||
if (x > maxValue
|
||||
|| x < minValue
|
||||
|| y > maxValue
|
||||
|| y < minValue
|
||||
|| z > maxValue
|
||||
|| z < minValue) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void limitAreaEffectCloudRadius(final AreaEffectCloud cloud) {
|
||||
if (cloud.getRadius() > 40) {
|
||||
cloud.setRadius(40);
|
||||
|
@ -187,11 +172,6 @@ public final class EntitySpawn implements Listener {
|
|||
final double y = event.getLocation().getY();
|
||||
final double z = event.getLocation().getZ();
|
||||
|
||||
if (isOutsideBoundaries(x, y, z)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityType entityType = event.getEntityType();
|
||||
final Chunk chunk = event.getLocation().getChunk();
|
||||
final World world = event.getLocation().getWorld();
|
||||
|
@ -225,11 +205,6 @@ public final class EntitySpawn implements Listener {
|
|||
final double y = lightning.getLocation().getY();
|
||||
final double z = lightning.getLocation().getZ();
|
||||
|
||||
if (isOutsideBoundaries(x, y, z)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityType entityType = EntityType.LIGHTNING;
|
||||
final Chunk chunk = lightning.getChunk();
|
||||
final World world = event.getWorld();
|
||||
|
@ -273,17 +248,9 @@ public final class EntitySpawn implements Listener {
|
|||
|
||||
@EventHandler
|
||||
void onTNTPrime(final TNTPrimeEvent event) {
|
||||
switch (event.getReason()) {
|
||||
case EXPLOSION:
|
||||
case FIRE:
|
||||
case REDSTONE:
|
||||
if (ThreadLocalRandom.current().nextBoolean()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -293,11 +260,6 @@ public final class EntitySpawn implements Listener {
|
|||
final double y = vehicle.getLocation().getY();
|
||||
final double z = vehicle.getLocation().getZ();
|
||||
|
||||
if (isOutsideBoundaries(x, y, z)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final EntityType entityType = vehicle.getType();
|
||||
final Chunk chunk = vehicle.getChunk();
|
||||
final World world = vehicle.getWorld();
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package pw.kaboom.extras.modules.entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTeleportEvent;
|
||||
|
||||
public final class EntityTeleport implements Listener {
|
||||
public static Location limitLocation(final Location location) {
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
double z = location.getZ();
|
||||
|
||||
final int maxValue = 30000000;
|
||||
final int minValue = -30000000;
|
||||
|
||||
if (x > maxValue) {
|
||||
location.setX(maxValue);
|
||||
}
|
||||
if (x < minValue) {
|
||||
location.setX(minValue);
|
||||
}
|
||||
if (y > maxValue) {
|
||||
location.setY(maxValue);
|
||||
}
|
||||
if (y < minValue) {
|
||||
location.setY(minValue);
|
||||
}
|
||||
if (z > maxValue) {
|
||||
location.setZ(maxValue);
|
||||
}
|
||||
if (z < minValue) {
|
||||
location.setZ(minValue);
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onEntityTeleport(final EntityTeleportEvent event) {
|
||||
event.setTo(limitLocation(event.getTo()));
|
||||
}
|
||||
}
|
|
@ -14,15 +14,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
public final class PlayerInteract implements Listener {
|
||||
//static HashMap<UUID, Long> interactMillisList = new HashMap<UUID, Long>();
|
||||
|
||||
@EventHandler
|
||||
void onInventoryClick(final InventoryClickEvent event) {
|
||||
try {
|
||||
event.getSlot();
|
||||
} catch (Exception exception) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerInteract(final PlayerInteractEvent event) {
|
||||
/*final UUID playerUuid = event.getPlayer().getUniqueId();
|
||||
|
|
|
@ -6,8 +6,6 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import pw.kaboom.extras.modules.entity.EntityTeleport;
|
||||
|
||||
public final class PlayerTeleport implements Listener {
|
||||
@EventHandler
|
||||
void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
|
||||
|
@ -19,9 +17,4 @@ public final class PlayerTeleport implements Listener {
|
|||
player.setMaxHealth(20);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||
event.setTo(EntityTeleport.limitLocation(event.getTo()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package pw.kaboom.extras.modules.server;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
|
||||
|
||||
public final class ServerTick implements Listener {
|
||||
@EventHandler
|
||||
void onPlayerStatisticIncrement(final PlayerStatisticIncrementEvent event) {
|
||||
final World world = event.getPlayer().getWorld();
|
||||
|
||||
if (!world.isAutoSave()) {
|
||||
world.setAutoSave(true);
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue