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 (Chunk chunk : world.getLoadedChunks()) {
if (chunk.unload() == true) {
if (chunk.unload()) {
chunkCount++;
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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