Code cleanup

This commit is contained in:
mathias 2019-08-03 09:34:26 +03:00
parent b4ce76cfa9
commit 1d7a4166b1
8 changed files with 117 additions and 55 deletions

View file

@ -17,7 +17,7 @@ class CommandUnloadChunks implements CommandExecutor {
for (World world : Bukkit.getServer().getWorlds()) { for (World world : Bukkit.getServer().getWorlds()) {
for (Chunk chunk : world.getLoadedChunks()) { for (Chunk chunk : world.getLoadedChunks()) {
if (chunk.unload() == true) { if (chunk.unload()) {
chunkCount++; chunkCount++;
} }
} }

View file

@ -79,9 +79,9 @@ class BlockPhysics implements Listener {
if (block.getRelative(BlockFace.UP).getType() == Material.WATER && if (block.getRelative(BlockFace.UP).getType() == Material.WATER &&
solid != true) { !solid) {
event.setCancelled(true); event.setCancelled(true);
} else if (cancel == true) { } else if (cancel) {
event.setCancelled(true); event.setCancelled(true);
} }
} }

View file

@ -1,6 +1,7 @@
package pw.kaboom.extras; package pw.kaboom.extras;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
@ -28,6 +29,9 @@ import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.entity.SpawnerSpawnEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.PotionMeta;
import com.destroystokyo.paper.event.block.TNTPrimeEvent; import com.destroystokyo.paper.event.block.TNTPrimeEvent;
@ -35,6 +39,8 @@ import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
import org.bukkit.block.banner.Pattern;
class EntitySpawn implements Listener { class EntitySpawn implements Listener {
@EventHandler @EventHandler
void onBlockDispense(BlockDispenseEvent event) { void onBlockDispense(BlockDispenseEvent event) {
@ -75,7 +81,19 @@ class EntitySpawn implements Listener {
final LivingEntity mob = (LivingEntity) event.getEntity(); final LivingEntity mob = (LivingEntity) event.getEntity();
try { try {
mob.getEquipment().getArmorContents(); for (ItemStack item : mob.getEquipment().getArmorContents()) {
if (item.getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) item.getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
mob.getEquipment().setArmorContents(
new ItemStack[] {null, null, null, null}
);
}
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
mob.getEquipment().setArmorContents( mob.getEquipment().setArmorContents(
new ItemStack[] {null, null, null, null} new ItemStack[] {null, null, null, null}
@ -83,13 +101,29 @@ class EntitySpawn implements Listener {
} }
try { try {
mob.getEquipment().getItemInMainHand(); if (mob.getEquipment().getItemInMainHand().getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) mob.getEquipment().getItemInMainHand().getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
mob.getEquipment().setItemInMainHand(null);
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
mob.getEquipment().setItemInMainHand(null); mob.getEquipment().setItemInMainHand(null);
} }
try { try {
mob.getEquipment().getItemInOffHand(); if (mob.getEquipment().getItemInOffHand().getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) mob.getEquipment().getItemInOffHand().getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
mob.getEquipment().setItemInOffHand(null);
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
mob.getEquipment().setItemInOffHand(null); mob.getEquipment().setItemInOffHand(null);
} }
@ -118,8 +152,8 @@ class EntitySpawn implements Listener {
@EventHandler @EventHandler
void onEntityAddToWorld(EntityAddToWorldEvent event) { void onEntityAddToWorld(EntityAddToWorldEvent event) {
if (event.getEntityType() != EntityType.PLAYER) { if (event.getEntityType() != EntityType.PLAYER) {
if (event.getEntity().getLocation().isGenerated() == true && if (event.getEntity().getLocation().isGenerated() &&
event.getEntity().getLocation().isChunkLoaded() == true) { event.getEntity().getLocation().isChunkLoaded()) {
final Entity entity = event.getEntity(); final Entity entity = event.getEntity();
final int count = entity.getLocation().getChunk().getEntities().length; final int count = entity.getLocation().getChunk().getEntities().length;
@ -142,7 +176,19 @@ class EntitySpawn implements Listener {
final LivingEntity mob = (LivingEntity) event.getEntity(); final LivingEntity mob = (LivingEntity) event.getEntity();
try { try {
mob.getEquipment().getArmorContents(); for (ItemStack item : mob.getEquipment().getArmorContents()) {
if (item.getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) item.getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
mob.getEquipment().setArmorContents(
new ItemStack[] {null, null, null, null}
);
}
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
mob.getEquipment().setArmorContents( mob.getEquipment().setArmorContents(
new ItemStack[] {null, null, null, null} new ItemStack[] {null, null, null, null}
@ -150,13 +196,29 @@ class EntitySpawn implements Listener {
} }
try { try {
mob.getEquipment().getItemInMainHand(); if (mob.getEquipment().getItemInMainHand().getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) mob.getEquipment().getItemInMainHand().getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
mob.getEquipment().setItemInMainHand(null);
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
mob.getEquipment().setItemInMainHand(null); mob.getEquipment().setItemInMainHand(null);
} }
try { try {
mob.getEquipment().getItemInOffHand(); if (mob.getEquipment().getItemInOffHand().getItemMeta() instanceof BannerMeta) {
final BannerMeta banner = (BannerMeta) mob.getEquipment().getItemInOffHand().getItemMeta();
for (Pattern pattern : banner.getPatterns()) {
if (pattern.getColor() == null) {
mob.getEquipment().setItemInOffHand(null);
}
}
}
} catch (Exception exception) { } catch (Exception exception) {
mob.getEquipment().setItemInOffHand(null); mob.getEquipment().setItemInOffHand(null);
} }
@ -167,8 +229,8 @@ class EntitySpawn implements Listener {
@EventHandler @EventHandler
void onEntitySpawn(EntitySpawnEvent event) { void onEntitySpawn(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.PLAYER) { if (event.getEntityType() != EntityType.PLAYER) {
if (event.getLocation().isGenerated() == true && if (event.getLocation().isGenerated() &&
event.getLocation().isChunkLoaded() == true) { event.getLocation().isChunkLoaded()) {
final int entityCount = event.getLocation().getChunk().getEntities().length; final int entityCount = event.getLocation().getChunk().getEntities().length;
if (entityCount > 50) { if (entityCount > 50) {
@ -190,8 +252,8 @@ class EntitySpawn implements Listener {
@EventHandler @EventHandler
void onPreCreatureSpawn(PreCreatureSpawnEvent event) { void onPreCreatureSpawn(PreCreatureSpawnEvent event) {
if (event.getType() != EntityType.PLAYER) { if (event.getType() != EntityType.PLAYER) {
if (event.getSpawnLocation().isGenerated() == true && if (event.getSpawnLocation().isGenerated() &&
event.getSpawnLocation().isChunkLoaded() == true) { event.getSpawnLocation().isChunkLoaded()) {
final int entityCount = event.getSpawnLocation().getChunk().getEntities().length; final int entityCount = event.getSpawnLocation().getChunk().getEntities().length;
if (entityCount > 50) { if (entityCount > 50) {

View file

@ -33,15 +33,15 @@ class PlayerCommand implements Listener {
return; return;
} }
if (("/minecraft:gamerule".equals(arr[0].toLowerCase()) || if (("/minecraft:gamerule".equalsIgnoreCase(arr[0]) ||
"/gamerule".equals(arr[0].toLowerCase())) && "/gamerule".equalsIgnoreCase(arr[0])) &&
arr.length >= 3) { arr.length >= 3) {
if ("randomtickspeed".equals(arr[1].toLowerCase()) && if ("randomTickSpeed".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 6) { Double.parseDouble(arr[2]) > 6) {
event.setMessage(command.replaceFirst(arr[2], "6")); event.setMessage(command.replaceFirst(arr[2], "6"));
} }
} else if (("/minecraft:particle".equals(arr[0].toLowerCase()) || } else if (("/minecraft:particle".equalsIgnoreCase(arr[0]) ||
"/particle".equals(arr[0].toLowerCase())) && "/particle".equalsIgnoreCase(arr[0])) &&
arr.length >= 10) { arr.length >= 10) {
if (Double.parseDouble(arr[9]) > 10) { if (Double.parseDouble(arr[9]) > 10) {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
@ -56,29 +56,29 @@ class PlayerCommand implements Listener {
event.setMessage(stringBuilder.toString()); event.setMessage(stringBuilder.toString());
} }
} else if (("/bukkit:reload".equals(arr[0].toLowerCase()) || } else if (("/bukkit:reload".equalsIgnoreCase(arr[0]) ||
"/bukkit:rl".equals(arr[0].toLowerCase()) || "/bukkit:rl".equalsIgnoreCase(arr[0]) ||
"/reload".equals(arr[0].toLowerCase()) || "/reload".equalsIgnoreCase(arr[0]) ||
"/rl".equals(arr[0].toLowerCase())) && "/rl".equalsIgnoreCase(arr[0])) &&
event.getPlayer().hasPermission("bukkit.command.reload")) { event.getPlayer().hasPermission("bukkit.command.reload")) {
if (arr.length >= 2 && if (arr.length >= 2 &&
"confirm".equals(arr[1].toLowerCase())) { "confirm".equalsIgnoreCase(arr[1])) {
event.setCancelled(true); event.setCancelled(true);
Command.broadcastCommandMessage(event.getPlayer(), ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins."); Command.broadcastCommandMessage(event.getPlayer(), ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
Command.broadcastCommandMessage(event.getPlayer(), ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server."); Command.broadcastCommandMessage(event.getPlayer(), ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
Command.broadcastCommandMessage(event.getPlayer(), ChatColor.GREEN + "Reload complete."); Command.broadcastCommandMessage(event.getPlayer(), ChatColor.GREEN + "Reload complete.");
} }
} else if (("/restart".equals(arr[0].toLowerCase()) || } else if (("/restart".equalsIgnoreCase(arr[0]) ||
"/spigot:restart".equals(arr[0].toLowerCase())) && "/spigot:restart".equalsIgnoreCase(arr[0])) &&
event.getPlayer().hasPermission("bukkit.command.restart")) { event.getPlayer().hasPermission("bukkit.command.restart")) {
event.setCancelled(true); event.setCancelled(true);
} else if (("/minecraft:save-off".equals(arr[0].toLowerCase()) || } else if (("/minecraft:save-off".equalsIgnoreCase(arr[0]) ||
"/save-off".equals(arr[0].toLowerCase())) && "/save-off".equalsIgnoreCase(arr[0])) &&
event.getPlayer().hasPermission("minecraft.command.save.disable")) { event.getPlayer().hasPermission("minecraft.command.save.disable")) {
event.setCancelled(true); event.setCancelled(true);
Command.broadcastCommandMessage(event.getPlayer(), "Automatic saving is now disabled"); Command.broadcastCommandMessage(event.getPlayer(), "Automatic saving is now disabled");
} else if (("/minecraft:stop".equals(arr[0].toLowerCase()) || } else if (("/minecraft:stop".equalsIgnoreCase(arr[0]) ||
"/stop".equals(arr[0].toLowerCase())) && "/stop".equalsIgnoreCase(arr[0])) &&
event.getPlayer().hasPermission("minecraft.command.stop")) { event.getPlayer().hasPermission("minecraft.command.stop")) {
event.setCancelled(true); event.setCancelled(true);
Command.broadcastCommandMessage(event.getPlayer(), "Stopping the server"); Command.broadcastCommandMessage(event.getPlayer(), "Stopping the server");

View file

@ -108,7 +108,7 @@ class PlayerConnection implements Listener {
final int stay = 160; final int stay = 160;
final int fadeOut = 5; final int fadeOut = 5;
if (player.hasPlayedBefore() == true) { if (player.hasPlayedBefore()) {
try { try {
player.getInventory().getContents(); player.getInventory().getContents();
} catch (Exception exception) { } catch (Exception exception) {

View file

@ -63,7 +63,7 @@ class PlayerDamage implements Listener {
if ((player.getLastDamageCause() != null && if ((player.getLastDamageCause() != null &&
player.getLastDamageCause().getCause() == DamageCause.SUICIDE && player.getLastDamageCause().getCause() == DamageCause.SUICIDE &&
player.getLastDamageCause().getDamage() == Float.MAX_VALUE) || player.getLastDamageCause().getDamage() == Float.MAX_VALUE) ||
maxHealthLow == true) { maxHealthLow) {
return; return;
} }
@ -71,10 +71,10 @@ class PlayerDamage implements Listener {
player.teleportAsync(player.getBedSpawnLocation()); player.teleportAsync(player.getBedSpawnLocation());
} else { } else {
final World world = Bukkit.getWorld("world"); final World world = Bukkit.getWorld("world");
final Location spawnLoc = world.getSpawnLocation(); final Location spawnLocation = world.getSpawnLocation();
for (double y = spawnLoc.getY(); y <= 256; y++) { for (double y = spawnLocation.getY(); y <= 256; y++) {
final Location yLocation = new Location(world, spawnLoc.getX(), y, spawnLoc.getZ()); final Location yLocation = new Location(world, spawnLocation.getX(), y, spawnLocation.getZ());
final Block coordBlock = world.getBlockAt(yLocation); final Block coordBlock = world.getBlockAt(yLocation);
if (!coordBlock.getType().isSolid() && if (!coordBlock.getType().isSolid() &&

View file

@ -23,15 +23,15 @@ class ServerCommand implements Listener {
if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) { if (main.consoleCommandBlacklist.contains(arr[0].toLowerCase())) {
event.setCancelled(true); event.setCancelled(true);
} else if (("minecraft:gamerule".equals(arr[0].toLowerCase()) || } else if (("minecraft:gamerule".equalsIgnoreCase(arr[0]) ||
"gamerule".equals(arr[0].toLowerCase())) && "gamerule".equalsIgnoreCase(arr[0])) &&
arr.length >= 3) { arr.length >= 3) {
if ("randomtickspeed".equals(arr[1].toLowerCase()) && if ("randomTickSpeed".equalsIgnoreCase(arr[1]) &&
Double.parseDouble(arr[2]) > 6) { Double.parseDouble(arr[2]) > 6) {
event.setCommand(command.replaceFirst(arr[2], "6")); event.setCommand(command.replaceFirst(arr[2], "6"));
} }
} else if (("minecraft:particle".equals(arr[0].toLowerCase()) || } else if (("minecraft:particle".equalsIgnoreCase(arr[0]) ||
"particle".equals(arr[0].toLowerCase())) && "particle".equalsIgnoreCase(arr[0])) &&
arr.length >= 10) { arr.length >= 10) {
if (Double.parseDouble(arr[9]) > 10) { if (Double.parseDouble(arr[9]) > 10) {
final StringBuilder stringBuilder = new StringBuilder(); final StringBuilder stringBuilder = new StringBuilder();
@ -46,26 +46,26 @@ class ServerCommand implements Listener {
event.setCommand(stringBuilder.toString()); event.setCommand(stringBuilder.toString());
} }
} else if ("bukkit:reload".equals(arr[0].toLowerCase()) || } else if ("bukkit:reload".equalsIgnoreCase(arr[0]) ||
"bukkit:rl".equals(arr[0].toLowerCase()) || "bukkit:rl".equalsIgnoreCase(arr[0]) ||
"reload".equals(arr[0].toLowerCase()) || "reload".equalsIgnoreCase(arr[0]) ||
"rl".equals(arr[0].toLowerCase())) { "rl".equalsIgnoreCase(arr[0])) {
if (arr.length >= 2 && if (arr.length >= 2 &&
"confirm".equals(arr[1].toLowerCase())) { "confirm".equalsIgnoreCase(arr[1])) {
event.setCancelled(true); event.setCancelled(true);
Command.broadcastCommandMessage(event.getSender(), ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins."); Command.broadcastCommandMessage(event.getSender(), ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
Command.broadcastCommandMessage(event.getSender(), ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server."); Command.broadcastCommandMessage(event.getSender(), ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
Command.broadcastCommandMessage(event.getSender(), ChatColor.GREEN + "Reload complete."); Command.broadcastCommandMessage(event.getSender(), ChatColor.GREEN + "Reload complete.");
} }
} else if ("restart".equals(arr[0].toLowerCase()) || } else if ("restart".equalsIgnoreCase(arr[0]) ||
"spigot:restart".equals(arr[0].toLowerCase())) { "spigot:restart".equalsIgnoreCase(arr[0])) {
event.setCancelled(true); event.setCancelled(true);
} else if ("minecraft:save-off".equals(arr[0].toLowerCase()) || } else if ("minecraft:save-off".equalsIgnoreCase(arr[0]) ||
"save-off".equals(arr[0].toLowerCase())) { "save-off".equalsIgnoreCase(arr[0])) {
event.setCancelled(true); event.setCancelled(true);
Command.broadcastCommandMessage(event.getSender(), "Automatic saving is now disabled"); Command.broadcastCommandMessage(event.getSender(), "Automatic saving is now disabled");
} else if (("minecraft:stop".equals(arr[0].toLowerCase()) || } else if (("minecraft:stop".equalsIgnoreCase(arr[0]) ||
"stop".equals(arr[0].toLowerCase())) && "stop".equalsIgnoreCase(arr[0])) &&
!(event.getSender() instanceof BlockCommandSender)) { !(event.getSender() instanceof BlockCommandSender)) {
event.setCancelled(true); event.setCancelled(true);
Command.broadcastCommandMessage(event.getSender(), "Stopping the server"); Command.broadcastCommandMessage(event.getSender(), "Stopping the server");

View file

@ -8,10 +8,10 @@ import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
class ServerPing implements Listener { class ServerPing implements Listener {
@EventHandler @EventHandler
void onServerListPing(PaperServerListPingEvent event) { void onServerListPing(PaperServerListPingEvent event) {
if (event.getClient().getProtocolVersion() != -1) { if (event.getClient().getProtocolVersion() == -1) {
event.setProtocolVersion(event.getClient().getProtocolVersion());
} else {
event.setProtocolVersion(498); event.setProtocolVersion(498);
} else {
event.setProtocolVersion(event.getClient().getProtocolVersion());
} }
event.setVersion("1.14.4"); event.setVersion("1.14.4");
} }