From 47fd57a7ac197fdc9180fe3cc940d6e4a9327fa7 Mon Sep 17 00:00:00 2001 From: Christian Koop Date: Thu, 18 May 2023 12:07:47 +0200 Subject: [PATCH] Minor code style changes (mostly use of `this.` for instance fields) --- .../songoda/epicanchors/AnchorManager.java | 26 +++++----- .../com/songoda/epicanchors/EpicAnchors.java | 6 +-- .../epicanchors/commands/sub/GiveCommand.java | 12 ++--- .../commands/sub/ReloadCommand.java | 4 +- .../commands/sub/SettingsCommand.java | 2 +- .../epicanchors/commands/sub/ShowCommand.java | 2 +- .../epicanchors/files/DataManager.java | 2 +- .../files/migration/AnchorMigration.java | 2 +- .../songoda/epicanchors/guis/AnchorGui.java | 12 ++--- .../guis/DestroyConfirmationGui.java | 8 +-- .../epicanchors/listener/AnchorListener.java | 16 +++--- .../epicanchors/listener/BlockListener.java | 12 ++--- .../epicanchors/listener/WorldListener.java | 4 +- .../songoda/epicanchors/tasks/AnchorTask.java | 10 ++-- .../epicanchors/tasks/VisualizeTask.java | 10 ++-- .../epicanchors/utils/ReflectionUtils.java | 52 ------------------- .../songoda/epicanchors/utils/ThreadSync.java | 14 ++--- 17 files changed, 70 insertions(+), 124 deletions(-) delete mode 100644 src/main/java/com/songoda/epicanchors/utils/ReflectionUtils.java diff --git a/src/main/java/com/songoda/epicanchors/AnchorManager.java b/src/main/java/com/songoda/epicanchors/AnchorManager.java index 592f02c..ce878c9 100644 --- a/src/main/java/com/songoda/epicanchors/AnchorManager.java +++ b/src/main/java/com/songoda/epicanchors/AnchorManager.java @@ -58,13 +58,13 @@ public class AnchorManager { } protected void saveAll() { - for (Set anchorSet : anchors.values()) { + for (Set anchorSet : this.anchors.values()) { this.dataManager.updateAnchors(anchorSet, null); } } protected void deInitAll() { - for (World world : anchors.keySet().toArray(new World[0])) { + for (World world : this.anchors.keySet().toArray(new World[0])) { deInitAnchors(world); } } @@ -123,18 +123,18 @@ public class AnchorManager { protected void setReady() { this.ready = true; - Bukkit.getScheduler().runTaskTimer(plugin, this::saveAll, 20L * 60 * 5, 20L * 60 * 5); + Bukkit.getScheduler().runTaskTimer(this.plugin, this::saveAll, 20L * 60 * 5, 20L * 60 * 5); } @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean isReady(World world) { - return this.ready && anchors.containsKey(world); + return this.ready && this.anchors.containsKey(world); } /* Getter */ public Anchor[] getAnchors(@NotNull World world) { - Set set = anchors.get(world); + Set set = this.anchors.get(world); if (set != null) { return set.toArray(new Anchor[0]); @@ -149,7 +149,7 @@ public class AnchorManager { } Location bLoc = b.getLocation(); - Set set = anchors.get(b.getWorld()); + Set set = this.anchors.get(b.getWorld()); if (set != null) { for (Anchor anchor : set) { @@ -171,7 +171,7 @@ public class AnchorManager { throw new IllegalStateException(ERR_WORLD_NOT_READY); } - Set set = anchors.get(chunk.getWorld()); + Set set = this.anchors.get(chunk.getWorld()); if (set != null) { for (Anchor anchor : set) { @@ -237,7 +237,7 @@ public class AnchorManager { Block b = loc.getBlock(); b.setType(Settings.MATERIAL.getMaterial().getMaterial()); - anchors.computeIfAbsent(anchor.getWorld(), k -> new HashSet<>()) + this.anchors.computeIfAbsent(anchor.getWorld(), k -> new HashSet<>()) .add(anchor); updateHologram(anchor); @@ -259,7 +259,7 @@ public class AnchorManager { throw new IllegalStateException(ERR_WORLD_NOT_READY); } - for (Set value : anchors.values()) { + for (Set value : this.anchors.values()) { value.remove(anchor); } @@ -293,9 +293,9 @@ public class AnchorManager { @SuppressWarnings("unused") public void registerAccessCheck(AnchorAccessCheck accessCheck) { - if (!accessChecks.contains(accessCheck)) { + if (!this.accessChecks.contains(accessCheck)) { // Adding at the start of the list makes sure the default check is - accessChecks.add(accessCheck); + this.accessChecks.add(accessCheck); } } @@ -306,7 +306,7 @@ public class AnchorManager { */ @SuppressWarnings("unused") public boolean unregisterAccessCheck(AnchorAccessCheck accessCheck) { - return accessChecks.remove(accessCheck); + return this.accessChecks.remove(accessCheck); } public boolean hasAccess(@NotNull Anchor anchor, @NotNull OfflinePlayer p) { @@ -314,7 +314,7 @@ public class AnchorManager { } /** - * Checks if a player has access to an Anchor. By default only the owner has access to an Anchor. + * Checks if a player has access to an Anchor. By default, only the owner has access to an Anchor. *
* Other plugins can grant access to other players (e.g. friends). *
diff --git a/src/main/java/com/songoda/epicanchors/EpicAnchors.java b/src/main/java/com/songoda/epicanchors/EpicAnchors.java index ed63ade..862d157 100644 --- a/src/main/java/com/songoda/epicanchors/EpicAnchors.java +++ b/src/main/java/com/songoda/epicanchors/EpicAnchors.java @@ -45,15 +45,13 @@ public final class EpicAnchors extends SongodaPlugin { @Override public void onPluginEnable() { - // Songoda Updater SongodaCore.registerPlugin(this, 31, CompatibleMaterial.END_PORTAL_FRAME); // Initialize database this.getLogger().info("Initializing SQLite..."); DatabaseConnector dbCon = new SQLiteConnector(this); this.dataManager = new DataManager(dbCon, this); - AnchorMigration anchorMigration = new AnchorMigration(dbCon, this.dataManager, - new _1_InitialMigration()); + AnchorMigration anchorMigration = new AnchorMigration(dbCon, this.dataManager, new _1_InitialMigration()); anchorMigration.runMigrations(); anchorMigration.migrateLegacyData(this); @@ -74,7 +72,7 @@ public final class EpicAnchors extends SongodaPlugin { // Event Listener this.guiManager = new GuiManager(this); - guiManager.init(); + this.guiManager.init(); PluginManager pluginManager = Bukkit.getPluginManager(); pluginManager.registerEvents(new WorldListener( world -> this.anchorManager.initAnchorsAsync(world, null), diff --git a/src/main/java/com/songoda/epicanchors/commands/sub/GiveCommand.java b/src/main/java/com/songoda/epicanchors/commands/sub/GiveCommand.java index c90c96c..29f26d6 100644 --- a/src/main/java/com/songoda/epicanchors/commands/sub/GiveCommand.java +++ b/src/main/java/com/songoda/epicanchors/commands/sub/GiveCommand.java @@ -32,7 +32,7 @@ public class GiveCommand extends AbstractCommand { if (target == null && !args[0].trim().equalsIgnoreCase("all") && !args[0].trim().equalsIgnoreCase("@a")) { - plugin.getLocale().newMessage("&cThat is not a player...").sendPrefixedMessage(sender); + this.plugin.getLocale().newMessage("&cThat is not a player...").sendPrefixedMessage(sender); return ReturnType.SYNTAX_ERROR; } @@ -40,22 +40,22 @@ public class GiveCommand extends AbstractCommand { ItemStack itemStack; if (Utils.isInt(args[1]) && Integer.parseInt(args[1]) > 0) { - itemStack = plugin.getAnchorManager().createAnchorItem(Integer.parseInt(args[1]) * 20 * 60 * 60); + itemStack = this.plugin.getAnchorManager().createAnchorItem(Integer.parseInt(args[1]) * 20 * 60 * 60); } else if (args[1].equalsIgnoreCase("infinite")) { - itemStack = plugin.getAnchorManager().createAnchorItem(-1); + itemStack = this.plugin.getAnchorManager().createAnchorItem(-1); } else { - plugin.getLocale().newMessage("&cYou can only use positive whole numbers...").sendPrefixedMessage(sender); + this.plugin.getLocale().newMessage("&cYou can only use positive whole numbers...").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (target != null) { target.getInventory().addItem(itemStack); - plugin.getLocale().getMessage("command.give.success").sendPrefixedMessage(target); + this.plugin.getLocale().getMessage("command.give.success").sendPrefixedMessage(target); } else { for (Player online : Bukkit.getOnlinePlayers()) { online.getInventory().addItem(itemStack); - plugin.getLocale().getMessage("command.give.success").sendPrefixedMessage(online); + this.plugin.getLocale().getMessage("command.give.success").sendPrefixedMessage(online); } } diff --git a/src/main/java/com/songoda/epicanchors/commands/sub/ReloadCommand.java b/src/main/java/com/songoda/epicanchors/commands/sub/ReloadCommand.java index e8a7ccd..1258955 100644 --- a/src/main/java/com/songoda/epicanchors/commands/sub/ReloadCommand.java +++ b/src/main/java/com/songoda/epicanchors/commands/sub/ReloadCommand.java @@ -17,8 +17,8 @@ public class ReloadCommand extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - plugin.reloadConfig(); - plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); + this.plugin.reloadConfig(); + this.plugin.getLocale().getMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/epicanchors/commands/sub/SettingsCommand.java b/src/main/java/com/songoda/epicanchors/commands/sub/SettingsCommand.java index eaa4733..692376b 100644 --- a/src/main/java/com/songoda/epicanchors/commands/sub/SettingsCommand.java +++ b/src/main/java/com/songoda/epicanchors/commands/sub/SettingsCommand.java @@ -23,7 +23,7 @@ public class SettingsCommand extends AbstractCommand { @Override protected ReturnType runCommand(CommandSender sender, String... args) { - guiManager.showGUI((Player) sender, new PluginConfigGui(instance)); + this.guiManager.showGUI((Player) sender, new PluginConfigGui(this.instance)); return AbstractCommand.ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/epicanchors/commands/sub/ShowCommand.java b/src/main/java/com/songoda/epicanchors/commands/sub/ShowCommand.java index 63bd88a..62a5377 100644 --- a/src/main/java/com/songoda/epicanchors/commands/sub/ShowCommand.java +++ b/src/main/java/com/songoda/epicanchors/commands/sub/ShowCommand.java @@ -30,7 +30,7 @@ public class ShowCommand extends AbstractCommand { boolean visualize = this.plugin.getAnchorManager().toggleChunkVisualized((Player) sender); - plugin.getLocale().getMessage("command.show." + (visualize ? "start" : "stop")) + this.plugin.getLocale().getMessage("command.show." + (visualize ? "start" : "stop")) .sendPrefixedMessage(sender); return ReturnType.SUCCESS; diff --git a/src/main/java/com/songoda/epicanchors/files/DataManager.java b/src/main/java/com/songoda/epicanchors/files/DataManager.java index 21ad7d0..cde7a33 100644 --- a/src/main/java/com/songoda/epicanchors/files/DataManager.java +++ b/src/main/java/com/songoda/epicanchors/files/DataManager.java @@ -159,7 +159,7 @@ public class DataManager extends DataManagerAbstract { for (int i : batchRes) { if (i < 0 && i != Statement.SUCCESS_NO_INFO) { - throw new AssertionError("Batch-INSERT failed for at least one statement with code " + i + ""); + throw new AssertionError("Batch-INSERT failed for at least one statement with code " + i); } } } catch (SQLException ex) { diff --git a/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java b/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java index 891830c..31a65a0 100644 --- a/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java +++ b/src/main/java/com/songoda/epicanchors/files/migration/AnchorMigration.java @@ -67,7 +67,7 @@ public class AnchorMigration extends DataMigrationManager { int z = Location.locToBlock(Double.parseDouble(locArgs[3])); int finalTicksLeft = ticksLeft; - dataManager.exists(worldName, x, y, z, (ex, anchorExists) -> { + this.dataManager.exists(worldName, x, y, z, (ex, anchorExists) -> { if (ex == null) { if (anchorExists) { cfgSection.set(locationStr, null); diff --git a/src/main/java/com/songoda/epicanchors/guis/AnchorGui.java b/src/main/java/com/songoda/epicanchors/guis/AnchorGui.java index 83d4fb9..86ade12 100644 --- a/src/main/java/com/songoda/epicanchors/guis/AnchorGui.java +++ b/src/main/java/com/songoda/epicanchors/guis/AnchorGui.java @@ -36,26 +36,26 @@ public class AnchorGui extends Gui { prepareGui(this.plugin, this, this.anchor); if (Settings.ADD_TIME_WITH_XP.getBoolean()) { - String itemName = plugin.getLocale().getMessage("interface.button.addtimewithxp").getMessage(); - String itemLore = plugin.getLocale().getMessage("interface.button.addtimewithxplore") + String itemName = this.plugin.getLocale().getMessage("interface.button.addtimewithxp").getMessage(); + String itemLore = this.plugin.getLocale().getMessage("interface.button.addtimewithxplore") .processPlaceholder("cost", Settings.XP_COST.getInt()) .getMessage(); setButton(11, GuiUtils.createButtonItem(Settings.XP_ICON.getMaterial(CompatibleMaterial.EXPERIENCE_BOTTLE), itemName, itemLore), - event -> buyTime(anchor, event.player, false)); + event -> buyTime(this.anchor, event.player, false)); } if (EconomyManager.isEnabled() && Settings.ADD_TIME_WITH_ECONOMY.getBoolean()) { - String itemName = plugin.getLocale().getMessage("interface.button.addtimewitheconomy").getMessage(); - String itemLore = plugin.getLocale().getMessage("interface.button.addtimewitheconomylore") + String itemName = this.plugin.getLocale().getMessage("interface.button.addtimewitheconomy").getMessage(); + String itemLore = this.plugin.getLocale().getMessage("interface.button.addtimewitheconomylore") // EconomyManager#formatEconomy adds its own prefix/suffix .processPlaceholder("cost", EconomyManager.formatEconomy(Settings.ECONOMY_COST.getDouble())) .getMessage(); setButton(15, GuiUtils.createButtonItem(Settings.ECO_ICON.getMaterial(CompatibleMaterial.SUNFLOWER), itemName, itemLore), - event -> buyTime(anchor, event.player, true)); + event -> buyTime(this.anchor, event.player, true)); } } diff --git a/src/main/java/com/songoda/epicanchors/guis/DestroyConfirmationGui.java b/src/main/java/com/songoda/epicanchors/guis/DestroyConfirmationGui.java index 8eda9ac..69e168f 100644 --- a/src/main/java/com/songoda/epicanchors/guis/DestroyConfirmationGui.java +++ b/src/main/java/com/songoda/epicanchors/guis/DestroyConfirmationGui.java @@ -46,18 +46,18 @@ public class DestroyConfirmationGui extends Gui { private void constructGUI() { AnchorGui.prepareGui(this.plugin, this, this.anchor); - String cancelLore = plugin.getLocale().getMessage("interface.button.cancelDestroyLore").getMessage(); - String confirmLore = plugin.getLocale().getMessage("interface.button." + + String cancelLore = this.plugin.getLocale().getMessage("interface.button.cancelDestroyLore").getMessage(); + String confirmLore = this.plugin.getLocale().getMessage("interface.button." + (Settings.ALLOW_ANCHOR_BREAKING.getBoolean() ? "confirmDestroyLore" : "confirmDestroyLoreNoDrops")) .getMessage(); setButton(11, GuiUtils.createButtonItem(CompatibleMaterial.RED_TERRACOTTA, - plugin.getLocale().getMessage("interface.button.cancelDestroy").getMessage(), + this.plugin.getLocale().getMessage("interface.button.cancelDestroy").getMessage(), cancelLore.isEmpty() ? new String[0] : new String[] {cancelLore}), event -> this.handler.accept(null, false)); setButton(15, GuiUtils.createButtonItem(CompatibleMaterial.GREEN_TERRACOTTA, - plugin.getLocale().getMessage("interface.button.confirmDestroy").getMessage(), + this.plugin.getLocale().getMessage("interface.button.confirmDestroy").getMessage(), confirmLore.isEmpty() ? new String[0] : new String[] {confirmLore}), event -> this.handler.accept(null, true)); } diff --git a/src/main/java/com/songoda/epicanchors/listener/AnchorListener.java b/src/main/java/com/songoda/epicanchors/listener/AnchorListener.java index 543fc53..d330af0 100644 --- a/src/main/java/com/songoda/epicanchors/listener/AnchorListener.java +++ b/src/main/java/com/songoda/epicanchors/listener/AnchorListener.java @@ -37,7 +37,7 @@ public class AnchorListener implements Listener { if (item.hasItemMeta() && item.getItemMeta().hasDisplayName() && Settings.MATERIAL.getMaterial().getMaterial() == e.getBlock().getType()) { - if (!plugin.getAnchorManager().isReady(e.getBlock().getWorld())) { + if (!this.plugin.getAnchorManager().isReady(e.getBlock().getWorld())) { e.setCancelled(true); e.getPlayer().sendMessage("Anchors are still being initialized - Please wait a moment"); // TODO } else { @@ -46,7 +46,7 @@ public class AnchorListener implements Listener { if (ticksLeft != 0) { boolean dropOnErr = e.getPlayer().getGameMode() != GameMode.CREATIVE; - plugin.getAnchorManager().createAnchor(e.getBlock().getLocation(), e.getPlayer().getUniqueId(), ticksLeft, + this.plugin.getAnchorManager().createAnchor(e.getBlock().getLocation(), e.getPlayer().getUniqueId(), ticksLeft, (ex, result) -> { if (ex != null) { Utils.logException(this.plugin, ex, "SQLite"); @@ -59,7 +59,7 @@ public class AnchorListener implements Listener { if (dropOnErr) { e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), - plugin.getAnchorManager().createAnchorItem(ticksLeft, item.getType())); + this.plugin.getAnchorManager().createAnchorItem(ticksLeft, item.getType())); } }); } @@ -72,10 +72,10 @@ public class AnchorListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockInteract(PlayerInteractEvent e) { if (e.getClickedBlock() == null || - !plugin.getAnchorManager().isReady(e.getClickedBlock().getWorld())) return; + !this.plugin.getAnchorManager().isReady(e.getClickedBlock().getWorld())) return; Player p = e.getPlayer(); - Anchor anchor = plugin.getAnchorManager().getAnchor(e.getClickedBlock()); + Anchor anchor = this.plugin.getAnchorManager().getAnchor(e.getClickedBlock()); if (anchor != null) { e.setCancelled(true); @@ -90,7 +90,7 @@ public class AnchorListener implements Listener { Bukkit.getPluginManager().callEvent(blockBreakEvent); if (!blockBreakEvent.isCancelled()) { - plugin.getAnchorManager().destroyAnchor(anchor); + this.plugin.getAnchorManager().destroyAnchor(anchor); } } })); @@ -115,11 +115,11 @@ public class AnchorListener implements Listener { anchor.getLocation().add(.5, .5, .5), 100, .5, .5, .5); } } else { - plugin.getGuiManager().showGUI(p, new AnchorGui(plugin, anchor)); + this.plugin.getGuiManager().showGUI(p, new AnchorGui(this.plugin, anchor)); } } } else { - plugin.getLocale().getMessage("event.general.nopermission").sendMessage(p); + this.plugin.getLocale().getMessage("event.general.nopermission").sendMessage(p); } } } diff --git a/src/main/java/com/songoda/epicanchors/listener/BlockListener.java b/src/main/java/com/songoda/epicanchors/listener/BlockListener.java index fb0ab77..366bba2 100644 --- a/src/main/java/com/songoda/epicanchors/listener/BlockListener.java +++ b/src/main/java/com/songoda/epicanchors/listener/BlockListener.java @@ -22,7 +22,7 @@ public class BlockListener implements Listener { private void onBlockBurn(BlockBurnEvent e) { if (!this.manager.isReady(e.getBlock().getWorld())) return; - if (manager.isAnchor(e.getBlock())) { + if (this.manager.isAnchor(e.getBlock())) { e.setCancelled(true); } } @@ -31,7 +31,7 @@ public class BlockListener implements Listener { private void onBlockPiston(BlockPistonExtendEvent e) { if (!this.manager.isReady(e.getBlock().getWorld())) return; - if (manager.isAnchor(e.getBlock())) { + if (this.manager.isAnchor(e.getBlock())) { e.setCancelled(true); } } @@ -40,7 +40,7 @@ public class BlockListener implements Listener { private void onBlockPiston(BlockPistonRetractEvent e) { if (!this.manager.isReady(e.getBlock().getWorld())) return; - if (manager.isAnchor(e.getBlock())) { + if (this.manager.isAnchor(e.getBlock())) { e.setCancelled(true); } } @@ -49,7 +49,7 @@ public class BlockListener implements Listener { private void onBlockPhysics(BlockPhysicsEvent e) { if (!this.manager.isReady(e.getBlock().getWorld())) return; - if (manager.isAnchor(e.getBlock())) { + if (this.manager.isAnchor(e.getBlock())) { e.setCancelled(true); } } @@ -58,7 +58,7 @@ public class BlockListener implements Listener { private void onBlockPiston(LeavesDecayEvent e) { if (!this.manager.isReady(e.getBlock().getWorld())) return; - if (manager.isAnchor(e.getBlock())) { + if (this.manager.isAnchor(e.getBlock())) { e.setCancelled(true); } } @@ -68,7 +68,7 @@ public class BlockListener implements Listener { if (!this.manager.isReady(e.getWorld())) return; for (Block b : e.getBlocks()) { - if (manager.isAnchor(b)) { + if (this.manager.isAnchor(b)) { e.setCancelled(true); break; } diff --git a/src/main/java/com/songoda/epicanchors/listener/WorldListener.java b/src/main/java/com/songoda/epicanchors/listener/WorldListener.java index 8e389ab..124856e 100644 --- a/src/main/java/com/songoda/epicanchors/listener/WorldListener.java +++ b/src/main/java/com/songoda/epicanchors/listener/WorldListener.java @@ -20,11 +20,11 @@ public class WorldListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) private void onWorldLoad(WorldLoadEvent e) { - initAnchorsInWorld.accept(e.getWorld()); + this.initAnchorsInWorld.accept(e.getWorld()); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) private void onWorldUnload(WorldUnloadEvent e) { - deInitAnchorsInWorld.accept(e.getWorld()); + this.deInitAnchorsInWorld.accept(e.getWorld()); } } diff --git a/src/main/java/com/songoda/epicanchors/tasks/AnchorTask.java b/src/main/java/com/songoda/epicanchors/tasks/AnchorTask.java index c7226f6..8d19451 100644 --- a/src/main/java/com/songoda/epicanchors/tasks/AnchorTask.java +++ b/src/main/java/com/songoda/epicanchors/tasks/AnchorTask.java @@ -69,7 +69,7 @@ public class AnchorTask extends BukkitRunnable { WorldUtils.loadAnchoredChunk(chunk, this.plugin); } - if (!randomTicksFailed) { + if (!this.randomTicksFailed) { try { NmsManager.getWorld().randomTickChunk(chunk, randomTicks); } catch (ReflectiveOperationException ex) { @@ -77,11 +77,11 @@ public class AnchorTask extends BukkitRunnable { () -> "Failed to do random ticks on this server implementation(/version) - " + "Skipping further random ticks."); - randomTicksFailed = true; + this.randomTicksFailed = true; } } - if (!spawnerTicksFailed) { + if (!this.spawnerTicksFailed) { try { NmsManager.getWorld().tickInactiveSpawners(chunk, TASK_INTERVAL); } catch (ReflectiveOperationException ex) { @@ -89,7 +89,7 @@ public class AnchorTask extends BukkitRunnable { () -> "Failed to do spawner ticks on this server implementation(/version) - " + "Skipping further spawner ticks."); - spawnerTicksFailed = true; + this.spawnerTicksFailed = true; } } } @@ -113,7 +113,7 @@ public class AnchorTask extends BukkitRunnable { } // Update holograms on queued anchors - anchorManager.updateHolograms(toUpdateHolo); + this.anchorManager.updateHolograms(toUpdateHolo); } } catch (Exception ex) { Utils.logException(this.plugin, ex); diff --git a/src/main/java/com/songoda/epicanchors/tasks/VisualizeTask.java b/src/main/java/com/songoda/epicanchors/tasks/VisualizeTask.java index b0b1b0b..7c0e5c8 100644 --- a/src/main/java/com/songoda/epicanchors/tasks/VisualizeTask.java +++ b/src/main/java/com/songoda/epicanchors/tasks/VisualizeTask.java @@ -30,7 +30,7 @@ public class VisualizeTask extends BukkitRunnable { } public void startTask() { - runTaskTimer(plugin, TASK_INTERVAL, TASK_INTERVAL); + runTaskTimer(this.plugin, TASK_INTERVAL, TASK_INTERVAL); } @Override @@ -55,10 +55,10 @@ public class VisualizeTask extends BukkitRunnable { Location pLoc = p.getLocation(); // start and stop chunk coordinates - int cxi = (pLoc.getBlockX() >> 4) - radius; - int cxn = cxi + radius * 2; - int czi = (pLoc.getBlockZ() >> 4) - radius; - int czn = czi + radius * 2; + int cxi = (pLoc.getBlockX() >> 4) - this.radius; + int cxn = cxi + this.radius * 2; + int czi = (pLoc.getBlockZ() >> 4) - this.radius; + int czn = czi + this.radius * 2; // loop through the chunks to find applicable ones for (int cx = cxi; cx < cxn; ++cx) { diff --git a/src/main/java/com/songoda/epicanchors/utils/ReflectionUtils.java b/src/main/java/com/songoda/epicanchors/utils/ReflectionUtils.java deleted file mode 100644 index 2c3d452..0000000 --- a/src/main/java/com/songoda/epicanchors/utils/ReflectionUtils.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.songoda.epicanchors.utils; - -import java.lang.reflect.Field; - -public class ReflectionUtils { - private ReflectionUtils() { - throw new IllegalStateException("Utility class"); - } - - public static Object getFieldValue(Object instance, String fieldName) throws NoSuchFieldException, IllegalAccessException { - Field f = getField(instance, fieldName); - boolean accessible = f.isAccessible(); - - f.setAccessible(true); - - Object result = f.get(instance); - - f.setAccessible(accessible); - - return result; - } - - public static void setFieldValue(Object instance, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { - Field f = getField(instance, fieldName); - boolean accessible = f.isAccessible(); - - f.setAccessible(true); - - f.set(instance, value); - - f.setAccessible(accessible); - } - - private static Field getField(Object instance, String fieldName) throws NoSuchFieldException { - Field f = null; - - Class currClass = instance.getClass(); - do { - try { - f = currClass.getDeclaredField(fieldName); - } catch (NoSuchFieldException ex) { - currClass = currClass.getSuperclass(); - - if (currClass == null) { - throw ex; - } - } - } while (f == null); - - return f; - } -} diff --git a/src/main/java/com/songoda/epicanchors/utils/ThreadSync.java b/src/main/java/com/songoda/epicanchors/utils/ThreadSync.java index cd24b20..7957f0a 100644 --- a/src/main/java/com/songoda/epicanchors/utils/ThreadSync.java +++ b/src/main/java/com/songoda/epicanchors/utils/ThreadSync.java @@ -7,10 +7,10 @@ public class ThreadSync { private final AtomicReference waiting = new AtomicReference<>(true); public void waitForRelease() { - synchronized (syncObj) { - while (waiting.get()) { + synchronized (this.syncObj) { + while (this.waiting.get()) { try { - syncObj.wait(); + this.syncObj.wait(); } catch (Exception ignore) { } } @@ -18,13 +18,13 @@ public class ThreadSync { } public void release() { - synchronized (syncObj) { - waiting.set(false); - syncObj.notifyAll(); + synchronized (this.syncObj) { + this.waiting.set(false); + this.syncObj.notifyAll(); } } public void reset() { - waiting.set(true); + this.waiting.set(true); } }