From 6b0fcc87127f5c1ad4659b8ebc7eb688a1bfd98c Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Wed, 22 May 2019 14:40:56 -0400 Subject: [PATCH] Removed some null checks and fixed some variable names --- .../com/boydti/fawe/bukkit/FaweBukkit.java | 25 ++++++++----------- .../boydti/fawe/bukkit/chat/Reflection.java | 4 --- .../bukkit/listener/BukkitImageListener.java | 4 +-- .../bukkit/listener/CFIPacketListener.java | 5 ++-- .../fawe/bukkit/regions/FactionsFeature.java | 5 ++-- .../fawe/bukkit/v0/BukkitQueue_All.java | 4 +-- .../boydti/fawe/bukkit/v0/ChunkListener.java | 18 ++++++------- .../fawe/bukkit/wrapper/AsyncBlock.java | 1 - .../main/java/com/boydti/fawe/config/BBC.java | 10 ++------ 9 files changed, 27 insertions(+), 49 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 4566813b9..adc5c9b29 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -110,8 +110,8 @@ public class FaweBukkit implements IFawe, Listener { } try { Fawe.get().setChatManager(new BukkitChatManager()); - } catch (Throwable ignore) { - ignore.printStackTrace(); + } catch (Throwable throwable) { + throwable.printStackTrace(); } } catch (final Throwable e) { MainUtil.handleError(e); @@ -226,11 +226,7 @@ public class FaweBukkit implements IFawe, Listener { @Override public void debug(final String s) { ConsoleCommandSender console = Bukkit.getConsoleSender(); - if (console != null) { - console.sendMessage(BBC.color(s)); - } else { - Bukkit.getLogger().info(BBC.color(s)); - } + console.sendMessage(BBC.color(s)); } @Override @@ -266,7 +262,7 @@ public class FaweBukkit implements IFawe, Listener { Player player = (Player) obj; FawePlayer existing = Fawe.get().getCachedPlayer(player.getName()); return existing != null ? existing : new BukkitPlayer(player); - } else if (obj != null && obj.getClass().getName().contains("EntityPlayer")) { + } else if (obj.getClass().getName().contains("EntityPlayer")) { try { Method method = obj.getClass().getDeclaredMethod("getBukkitEntity"); return wrap(method.invoke(obj)); @@ -314,7 +310,6 @@ public class FaweBukkit implements IFawe, Listener { @Override public String getDebugInfo() { StringBuilder msg = new StringBuilder(); - List pl = new ArrayList<>(); msg.append("server.version: " + Bukkit.getVersion() + "\n"); msg.append("Plugins: \n"); for (Plugin p : Bukkit.getPluginManager().getPlugins()) { @@ -350,7 +345,7 @@ public class FaweBukkit implements IFawe, Listener { } try { return getQueue(world); - } catch (Throwable ignore) { + } catch (Throwable throwable) { // Disable incompatible settings Settings.IMP.QUEUE.PARALLEL_THREADS = 1; // BukkitAPI placer is too slow to parallel thread at the chunk level Settings.IMP.HISTORY.COMBINE_STAGES = false; // Performing a chunk copy (if possible) wouldn't be faster using the BukkitAPI @@ -365,7 +360,7 @@ public class FaweBukkit implements IFawe, Listener { debug("Download the version of FAWE for your platform"); debug(" - http://ci.athion.net/job/FastAsyncWorldEdit/lastSuccessfulBuild/artifact/target"); debug("======================================="); - ignore.printStackTrace(); + throwable.printStackTrace(); debug("======================================="); TaskManager.IMP.laterAsync( () -> MainUtil.sendAdmin("&cNo NMS placer found, see console!"), 1); @@ -398,11 +393,11 @@ public class FaweBukkit implements IFawe, Listener { } catch (Throwable ignore) { } } - Throwable error = null; + Throwable error; try { return getQueue(world); - } catch (Throwable ignore) { - error = ignore; + } catch (Throwable throwable) { + error = throwable; } // Disable incompatible settings Settings.IMP.QUEUE.PARALLEL_THREADS = 1; // BukkitAPI placer is too slow to parallel thread at the chunk level @@ -598,7 +593,7 @@ public class FaweBukkit implements IFawe, Listener { BukkitQueue_0.checkVersion(v.name()); this.version = tmp = v; break; - } catch (IllegalStateException e) {} + } catch (IllegalStateException ignored) {} } } return tmp; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java index 17e5e4280..a60d4cdda 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/chat/Reflection.java @@ -40,10 +40,6 @@ public final class Reflection { */ public synchronized static String getVersion() { if (_versionString == null) { - if (Bukkit.getServer() == null) { - // The server hasn't started, static initializer call? - return null; - } String name = Bukkit.getServer().getClass().getPackage().getName(); _versionString = name.substring(name.lastIndexOf('.') + 1) + "."; } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java index e175ff1d5..a0d3d80ec 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java @@ -153,8 +153,7 @@ public class BukkitImageListener implements Listener { ImageViewer viewer = generator.getImageViewer(); if (!(viewer instanceof BukkitImageViewer)) return null; - BukkitImageViewer biv = (BukkitImageViewer) viewer; - return biv; + return (BukkitImageViewer) viewer; } private void handleInteract(PlayerEvent event, Entity entity, boolean primary) { @@ -189,7 +188,6 @@ public class BukkitImageListener implements Listener { return; } - if (tool == null) return; BrushSettings context = primary ? tool.getPrimary() : tool.getSecondary(); Brush brush = context.getBrush(); if (brush == null) return; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java index 2053d8f9c..246f4bae2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java @@ -89,7 +89,7 @@ public class CFIPacketListener implements Listener { EnumWrappers.Hand enumHand = hands.isEmpty() ? EnumWrappers.Hand.MAIN_HAND : hands.get(0); PlayerInventory inv = plr.getInventory(); ItemStack hand = enumHand == EnumWrappers.Hand.MAIN_HAND ? inv.getItemInMainHand() : inv.getItemInOffHand(); - if (hand != null && hand.getType().isBlock()) { + if (hand.getType().isBlock()) { Material type = hand.getType(); if (!type.isEmpty()) { BlockStateHolder block = BukkitAdapter.asBlockState(hand); @@ -281,8 +281,7 @@ public class CFIPacketListener implements Listener { BlockPosition loc = position.readSafely(0); if (loc == null) return null; BlockVector3 origin = generator.getOrigin().toBlockPoint(); - BlockVector3 pt = BlockVector3.at(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ()); - return pt; + return BlockVector3.at(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ()); } private void handleBlockEvent(PacketEvent event, boolean relative, RunnableVal3 task) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java index f460862f7..0fd1e943f 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FactionsFeature.java @@ -14,13 +14,12 @@ import org.bukkit.plugin.Plugin; public class FactionsFeature extends BukkitMaskManager implements Listener { FaweBukkit plugin; - Plugin factions; + private Plugin factions; public FactionsFeature(final Plugin factionsPlugin, final FaweBukkit p3) { super(factionsPlugin.getName()); this.factions = factionsPlugin; this.plugin = p3; - BoardColl.get(); } @Override @@ -45,7 +44,7 @@ public class FactionsFeature extends BukkitMaskManager implements Listener { } } else if (fac.getOnlinePlayers().contains(player)) { - if (fac.getComparisonName().equals("wilderness") == false) { + if (!fac.getComparisonName().equals("wilderness")) { final Chunk chunk = loc.getChunk(); final Location pos1 = new Location(loc.getWorld(), chunk.getX() * 16, 0, chunk.getZ() * 16); final Location pos2 = new Location(loc.getWorld(), (chunk.getX() * 16) + 15, 156, (chunk.getZ() * 16) + 15); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index 015b3b8fc..5a56af496 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -120,8 +120,8 @@ public class BukkitQueue_All extends BukkitQueue_0 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) { - for (Entity ent : world.getEntities()) { - if (ent.getType() == EntityType.FIREWORK) { - Vector velocity = ent.getVelocity(); - double vertical = Math.abs(velocity.getY()); - if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) { - Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation()); - ent.remove(); - } + if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) { + for (Entity ent : world.getEntities()) { + if (ent.getType() == EntityType.FIREWORK) { + Vector velocity = ent.getVelocity(); + double vertical = Math.abs(velocity.getY()); + if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) { + Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation()); + ent.remove(); } } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java index 8a90b76f8..c2e547800 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/wrapper/AsyncBlock.java @@ -1,6 +1,5 @@ package com.boydti.fawe.bukkit.wrapper; -import com.boydti.fawe.FaweCache; import com.boydti.fawe.bukkit.wrapper.state.AsyncSign; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.util.TaskManager; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java b/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java index 0e3b06423..b47350b6c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/config/BBC.java @@ -410,9 +410,7 @@ public enum BBC { */ BBC(final String d, final boolean prefix, final String cat) { this.d = d; - if (this.s == null) { - this.s = d; - } + this.s = d; this.prefix = prefix; this.cat = cat.toLowerCase(); } @@ -559,11 +557,7 @@ public enum BBC { Method method = actor.getClass().getMethod("print", String.class); method.setAccessible(true); method.invoke(actor, (PREFIX.isEmpty() ? "" : PREFIX.s() + " ") + this.format(args)); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } }