From 97b9543f15cfbde69f37a1b902b24148cd5b8950 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Thu, 1 Mar 2018 14:57:35 +0100 Subject: [PATCH] Fixed some code smells --- .../us/tastybento/bskyblock/commands/IslandCommand.java | 5 +---- .../bskyblock/listeners/PanelListenerManager.java | 6 +++--- .../bskyblock/listeners/flags/FireListener.java | 6 +----- .../bskyblock/listeners/flags/MobSpawnListener.java | 8 ++------ .../tastybento/bskyblock/listeners/flags/PVPListener.java | 1 - .../bskyblock/listeners/protection/FlyingMobEvents.java | 8 ++++---- .../us/tastybento/bskyblock/managers/LocalesManager.java | 2 +- src/main/java/us/tastybento/bskyblock/util/Util.java | 4 ++-- 8 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index 2db972899..4e0ef506f 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -50,14 +50,11 @@ public class IslandCommand extends CompositeCommand { @Override public boolean execute(User user, List args) { // If this player does not have an island, create one - if (!getPlugin().getIslands().hasIsland(user.getUniqueId())) { getSubCommand("create").ifPresent(createCmd -> createCmd.execute(user, new ArrayList<>())); - return true; } - // Otherwise, currently, just go home - getSubCommand("go").ifPresent(goCmd -> goCmd.execute(user, new ArrayList<>())); + else getSubCommand("go").ifPresent(goCmd -> goCmd.execute(user, new ArrayList<>())); return true; } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java b/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java index 13f8984c3..f296d33d9 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/PanelListenerManager.java @@ -38,10 +38,10 @@ public class PanelListenerManager implements Listener { if (slot == event.getRawSlot()) { // Check that they left clicked on it // TODO: in the future, we may want to support right clicking - panel.getItems().get(slot).getClickHandler().ifPresent(handler -> { + panel.getItems().get(slot).getClickHandler().ifPresent(handler -> // Execute the handler's onClick method and optionally cancel the event if the handler returns true - event.setCancelled(handler.onClick(user, ClickType.LEFT)); - }); + event.setCancelled(handler.onClick(user, ClickType.LEFT)) + ); } } // If there is a listener, then run it. diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java index 281b6848e..9304a3ca7 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/FireListener.java @@ -40,14 +40,10 @@ public class FireListener extends AbstractFlagListener { public boolean checkFire(Cancellable e, Location l, Flag flag) { // Check world if (!inWorld(l)) { - //Bukkit.getLogger().info("DEBUG: not in world"); return false; } - //Bukkit.getLogger().info("DEBUG: in world"); // Check if the island exists and if fire is allowed - boolean cancel = getIslands().getIslandAt(l).map(i -> { - return !i.isAllowed(flag); - }).orElse(!flag.isDefaultSetting()); + boolean cancel = getIslands().getIslandAt(l).map(i -> !i.isAllowed(flag)).orElse(!flag.isDefaultSetting()); e.setCancelled(cancel); return cancel; diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java index c4bbe04d0..e337e2fee 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/MobSpawnListener.java @@ -46,15 +46,11 @@ public class MobSpawnListener extends AbstractFlagListener { Optional island = getIslands().getIslandAt(e.getLocation()); // Cancel the event if these are true if ((e.getEntity() instanceof Monster || e.getEntity() instanceof Slime)) { - boolean cancel = island.map(i -> { - return !i.isAllowed(Flags.MOB_SPAWN); - }).orElse(!Flags.MOB_SPAWN.isDefaultSetting()); + boolean cancel = island.map(i -> !i.isAllowed(Flags.MOB_SPAWN)).orElse(!Flags.MOB_SPAWN.isDefaultSetting()); e.setCancelled(cancel); return cancel; } else if (e.getEntity() instanceof Animals) { - boolean cancel = island.map(i -> { - return !i.isAllowed(Flags.MONSTER_SPAWN); - }).orElse(!Flags.MONSTER_SPAWN.isDefaultSetting()); + boolean cancel = island.map(i -> !i.isAllowed(Flags.MONSTER_SPAWN)).orElse(!Flags.MONSTER_SPAWN.isDefaultSetting()); e.setCancelled(cancel); return cancel; } diff --git a/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java b/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java index c6af49f3a..93cfe5d4c 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/flags/PVPListener.java @@ -60,7 +60,6 @@ public class PVPListener extends AbstractFlagListener { // Find out who fired the arrow Projectile p = (Projectile) damager; if (p.getShooter() instanceof Player) { - ; if (!setUser(User.getInstance((Player)p.getShooter())).checkIsland(event, damager.getLocation(), flag)) { damager.setFireTicks(0); damager.remove(); diff --git a/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java b/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java index f87b691f7..7bd490287 100644 --- a/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java +++ b/src/main/java/us/tastybento/bskyblock/listeners/protection/FlyingMobEvents.java @@ -90,7 +90,7 @@ public class FlyingMobEvents implements Listener { } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void MobExplosion(EntityExplodeEvent e) { + public void mobExplosion(EntityExplodeEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } @@ -118,7 +118,7 @@ public class FlyingMobEvents implements Listener { * Deal with pre-explosions */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void WitherExplode(ExplosionPrimeEvent e) { + public void witherExplode(ExplosionPrimeEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } @@ -176,7 +176,7 @@ public class FlyingMobEvents implements Listener { * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void WitherChangeBlocks(EntityChangeBlockEvent e) { + public void witherChangeBlocks(EntityChangeBlockEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } @@ -203,7 +203,7 @@ public class FlyingMobEvents implements Listener { * Clean up the hashmap. It's probably not needed, but just in case. */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void MobDeath(EntityDeathEvent e) { + public void mobDeath(EntityDeathEvent e) { mobSpawnInfo.remove(e.getEntity()); } } \ No newline at end of file diff --git a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java index 49e660161..c73634b83 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/LocalesManager.java @@ -19,7 +19,7 @@ public class LocalesManager { private BSkyBlock plugin; private HashMap languages = new HashMap<>(); - final static String LOCALE_FOLDER = "locales"; + private static final String LOCALE_FOLDER = "locales"; private static final boolean DEBUG = false; public LocalesManager(BSkyBlock plugin) { diff --git a/src/main/java/us/tastybento/bskyblock/util/Util.java b/src/main/java/us/tastybento/bskyblock/util/Util.java index 1f38d10d8..54a81385f 100755 --- a/src/main/java/us/tastybento/bskyblock/util/Util.java +++ b/src/main/java/us/tastybento/bskyblock/util/Util.java @@ -53,7 +53,7 @@ public class Util { * - serialized location in format "world:x:y:z" * @return Location */ - static public Location getLocationString(final String s) { + public static Location getLocationString(final String s) { if (s == null || s.trim().equals("")) { return null; } @@ -89,7 +89,7 @@ public class Util { * @param location - the location * @return String of location */ - static public String getStringLocation(final Location location) { + public static String getStringLocation(final Location location) { if (location == null || location.getWorld() == null) { return ""; }