From a0b29c1d019a1fdec38575648348ed906dbe15c8 Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Sat, 1 Aug 2020 17:46:14 -0700 Subject: [PATCH] We dont use javadoc & format fixes --- .gitignore | 1 + .../totalfreedommod/Monitors.java | 34 +++++-------- .../totalfreedommod/bridge/FAWEBridge.java | 49 +++++-------------- .../command/Command_potionspy.java | 35 ++++++------- .../totalfreedommod/util/FUtil.java | 7 --- 5 files changed, 40 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index c2ccd287..931fd6fb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ manifest.mf /.idea/discord.xml /.idea/jarRepositories.xml /.idea/workspace.xml +/.idea/uiDesigner.xml /.idea/libraries *.iml diff --git a/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java b/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java index ae05de95..a74ee0aa 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/Monitors.java @@ -41,9 +41,9 @@ public class Monitors extends FreedomService int potionsThrown = playerThrownPotions.size(); boolean trollPotions = false; - for(ThrownPotion potion : playerThrownPotions) + for (ThrownPotion potion : playerThrownPotions) { - if(isTrollPotion(potion)) + if (isTrollPotion(potion)) { trollPotions = true; } @@ -69,7 +69,7 @@ public class Monitors extends FreedomService if (event.getEntity().getShooter() instanceof Player) { ThrownPotion potion = event.getEntity(); - if(potion.getShooter() instanceof Player) + if (potion.getShooter() instanceof Player) { Player player = (Player)potion.getShooter(); @@ -77,11 +77,11 @@ public class Monitors extends FreedomService recentlyThrownPotions.get(player).add(potion); allThrownPotions.add(new AbstractMap.SimpleEntry<>(potion, System.currentTimeMillis())); - if(recentlyThrownPotions.get(player).size() > 128) + if (recentlyThrownPotions.get(player).size() > 128) { recentlyThrownPotions.get(player).remove(0); } - if(allThrownPotions.size() > 1024) + if (allThrownPotions.size() > 1024) { allThrownPotions.remove(0); // Remove the first element in the set. } @@ -95,7 +95,7 @@ public class Monitors extends FreedomService if (event.getEntity().getShooter() instanceof Player) { ThrownPotion potion = event.getEntity(); - if(potion.getShooter() instanceof Player) + if (potion.getShooter() instanceof Player) { Player player = (Player)potion.getShooter(); @@ -103,11 +103,11 @@ public class Monitors extends FreedomService recentlyThrownPotions.get(player).add(potion); allThrownPotions.add(new AbstractMap.SimpleEntry<>(potion, System.currentTimeMillis())); - if(recentlyThrownPotions.get(player).size() > 128) + if (recentlyThrownPotions.get(player).size() > 128) { recentlyThrownPotions.get(player).remove(0); } - if(allThrownPotions.size() > 1024) + if (allThrownPotions.size() > 1024) { allThrownPotions.remove(0); // Remove the first element in the set. } @@ -115,19 +115,14 @@ public class Monitors extends FreedomService } } - /** - * Get a list of potions the player has thrown with unix time stamps. - * @param player The player that has thrown potions. - * @return A list of map entries with the key as the thrown potion and the value as a long (unix time stamp when the throw happened). - */ public List> getPlayerThrownPotions(Player player) { List> thrownPotions = new ArrayList<>(); - for(Map.Entry potionEntry : allThrownPotions) + for (Map.Entry potionEntry : allThrownPotions) { ThrownPotion potion = potionEntry.getKey(); - if(potion.getShooter() != null && potion.getShooter().equals(player)) + if (potion.getShooter() != null && potion.getShooter().equals(player)) { thrownPotions.add(potionEntry); } @@ -136,18 +131,13 @@ public class Monitors extends FreedomService return thrownPotions; } - /** - * Detects if a thrown potion is most likely a troll potion. - * @param potion Any thrown potion that should be checked. - * @return A boolean that indicates if the potion param is most likely a troll potion. - */ public boolean isTrollPotion(ThrownPotion potion) { int badEffectsDetected = 0; - for(PotionEffect effect : potion.getEffects()) + for (PotionEffect effect : potion.getEffects()) { - if(badPotionEffects.contains(effect.getType()) && effect.getAmplifier() > 2 && effect.getDuration() > 200) + if (badPotionEffects.contains(effect.getType()) && effect.getAmplifier() > 2 && effect.getDuration() > 200) { badEffectsDetected++; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java index a7cc03ce..5a7e4143 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/bridge/FAWEBridge.java @@ -13,17 +13,12 @@ import java.util.List; import java.util.Map; import me.totalfreedom.totalfreedommod.FreedomService; import net.coreprotect.CoreProtectAPI; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; -/** - * Links TF-FAWE and the CoreProtect API together with two functions. - * @author CoolJWB - */ public class FAWEBridge extends FreedomService { private CoreProtectAPI api; @@ -39,7 +34,7 @@ public class FAWEBridge extends FreedomService /* * Iterates over blocks placed by GenerationCommands (in the EditSession) and adds them to the CoreProtect logs. */ - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() + server.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { @Override public void run() @@ -60,9 +55,9 @@ public class FAWEBridge extends FreedomService if (blockVector3 != null) { EditSession editSession = playerAndSessionEntry.getValue(); - World world = Bukkit.getWorld(editSession.getWorld().getName()); + World world = server.getWorld(editSession.getWorld().getName()); Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); - BlockData blockData = Bukkit.createBlockData(dataAndVectorEntry.get(blockVector3)); + BlockData blockData = server.createBlockData(dataAndVectorEntry.get(blockVector3)); api.logRemoval(playerAndSessionEntry.getKey(), location, blockData.getMaterial(), blockData); } } @@ -85,7 +80,7 @@ public class FAWEBridge extends FreedomService { if (blockVector3 != null && !pattern.apply(blockVector3).getBlockType().getMaterial().isAir()) { - World world = Bukkit.getWorld(playerAndSessionEntry.getValue().getWorld().getName()); + World world = server.getWorld(playerAndSessionEntry.getValue().getWorld().getName()); Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); BaseBlock block = pattern.apply(blockVector3); Material material = Material.getMaterial(block.getBlockType().getId().replaceFirst("minecraft:", "").toUpperCase()); @@ -106,26 +101,20 @@ public class FAWEBridge extends FreedomService } - /** - * Logs a single block edit to CoreProtect. - * @param playerName The name of the player. - * @param editSession A WorldEdit edit session to find the world. - * @param pattern A WorldEdit pattern for the new block placed. - * @param blockVector3 A WorldEdit BlockVector3 for coordinates. - */ + public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, BlockVector3 blockVector3) { // Cache the world used for the next iterations to come. - if(world == null || !world.getName().equals(editSession.getWorld().getName())) + if (world == null || !world.getName().equals(editSession.getWorld().getName())) { - world = Bukkit.getWorld(editSession.getWorld().getName()); + world = server.getWorld(editSession.getWorld().getName()); } Map.Entry playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession); Block block = world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()); // Add the broken block to CoreProtect if it's not air. - if(!block.getType().isAir()) + if (!block.getType().isAir()) { String blockData = block.getBlockData().getAsString(); blockData = new Gson().fromJson(new Gson().toJson(blockData), blockData.getClass()); // Overwrite original with deep clones. @@ -135,24 +124,17 @@ public class FAWEBridge extends FreedomService } // Add the placed block to CoreProtect if it's not air. - if(!pattern.apply(blockVector3).getBlockType().getMaterial().isAir()) + if (!pattern.apply(blockVector3).getBlockType().getMaterial().isAir()) { blocksPlaced.putIfAbsent(playerAndSessionEntry, new AbstractMap.SimpleEntry<>(pattern, new ArrayList<>())); blocksPlaced.get(playerAndSessionEntry).getValue().add(new Gson().fromJson(new Gson().toJson(blockVector3), blockVector3.getClass())); } } - /** - * Logs a pattern within a region to CoreProtect. - * @param playerName The name of the player. - * @param editSession A WorldEdit edit session to find the world. - * @param region A region of blocks. - * @param pattern A WorldEdit pattern for the new blocks placed. - */ public void logBlockEdits(String playerName, EditSession editSession, Region region, Pattern pattern) { // Add the broken blocks to CoreProtect. - World world = Bukkit.getWorld(region.getWorld().getName()); + World world = server.getWorld(region.getWorld().getName()); List blocks = new ArrayList<>(); for (BlockVector3 blockVector3 : region) @@ -163,20 +145,13 @@ public class FAWEBridge extends FreedomService logBlockEdit(playerName, editSession, pattern, blocks); } - /** - * Logs a list of block edits to CoreProtect. - * @param playerName The name of the player. - * @param editSession A WorldEdit edit session to find the world. - * @param pattern A WorldEdit pattern for the new block placed. - * @param blocks A list of blocks. - */ public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, List blocks) { Map.Entry playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> + server.getScheduler().scheduleSyncDelayedTask(plugin, () -> { - for(Block block : blocks) + for (Block block : blocks) { BlockVector3 blockVector3 = BlockVector3.at(block.getX(), block.getY(), block.getZ()); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java index f0d72a81..9a1e7a21 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potionspy.java @@ -30,7 +30,7 @@ public class Command_potionspy extends FreedomCommand { Admin admin = plugin.al.getAdmin(playerSender); - if(args.length <= 0) + if (args.length <= 0) { setPotionSpyState(admin, !admin.getPotionSpy()); return true; @@ -50,10 +50,10 @@ public class Command_potionspy extends FreedomCommand break; case "history": - if(args.length == 3) + if (args.length == 3) { Player player = Bukkit.getPlayer(args[1]); - if(player == null) + if (player == null) { msg(sender, "Please specify a valid player name."); return true; @@ -65,12 +65,12 @@ public class Command_potionspy extends FreedomCommand List potionThrowNotifications = new ArrayList<>(); int lastPage = (int)Math.ceil(thrownPotions.size() / 5.0); - if(thrownPotions.isEmpty()) + if (thrownPotions.isEmpty()) { msg(sender, noPlayerRecord); return true; } - if(!NumberUtils.isNumber(args[2])) + if (!NumberUtils.isNumber(args[2])) { msg(sender, String.format(validPageText, lastPage)); return true; @@ -79,7 +79,7 @@ public class Command_potionspy extends FreedomCommand Collections.reverse(thrownPotions); int pageIndex = Integer.parseInt(args[2]); - for(Map.Entry potionEntry : thrownPotions) + for (Map.Entry potionEntry : thrownPotions) { ThrownPotion potion = potionEntry.getKey(); boolean trollPotions = plugin.mo.isTrollPotion(potion); @@ -89,7 +89,7 @@ public class Command_potionspy extends FreedomCommand } List page = FUtil.getPageFromList(potionThrowNotifications, 5, pageIndex - 1); - if(!page.isEmpty()) + if (!page.isEmpty()) { msg(sender, ChatColor.translateAlternateColorCodes('&', titleText)); for (String potionThrowNotification : page) @@ -105,7 +105,7 @@ public class Command_potionspy extends FreedomCommand msg(sender, ChatColor.translateAlternateColorCodes('&', String.format(bottomText, pageIndex, lastPage))); } - else if(args.length == 2) + else if (args.length == 2) { List> thrownPotions = new ArrayList<>(); thrownPotions.addAll(plugin.mo.getAllThrownPotions()); // Make a copy of the list to avoid modifying the original. @@ -113,7 +113,7 @@ public class Command_potionspy extends FreedomCommand List potionThrowNotifications = new ArrayList<>(); int lastPage = (int)Math.ceil(thrownPotions.size() / 5.0); - if(thrownPotions.isEmpty()) + if (thrownPotions.isEmpty()) { if(Bukkit.getPlayer(args[1]) != null) { @@ -125,7 +125,7 @@ public class Command_potionspy extends FreedomCommand } return true; } - if(!NumberUtils.isNumber(args[1])) + if (!NumberUtils.isNumber(args[1])) { msg(sender, String.format(validPageText, lastPage)); return true; @@ -134,7 +134,7 @@ public class Command_potionspy extends FreedomCommand Collections.reverse(thrownPotions); int pageIndex = Integer.parseInt(args[1]); - for(Map.Entry potionEntry : thrownPotions) + for (Map.Entry potionEntry : thrownPotions) { ThrownPotion potion = potionEntry.getKey(); Player player = (Player)potion.getShooter(); @@ -148,7 +148,7 @@ public class Command_potionspy extends FreedomCommand } List page = FUtil.getPageFromList(potionThrowNotifications, 5, pageIndex - 1); - if(!page.isEmpty()) + if (!page.isEmpty()) { msg(sender, ChatColor.translateAlternateColorCodes('&', titleText)); for (String potionThrowNotification : page) @@ -176,11 +176,6 @@ public class Command_potionspy extends FreedomCommand return true; } - /** - * Sets and updates the potion spy state for an admin. - * @param admin The admin that the state should be changed for. - * @param state A boolean that will set the state of potion spy for the admin (enabled or disabled). - */ private void setPotionSpyState(Admin admin, boolean state) { admin.setPotionSpy(state); @@ -199,21 +194,21 @@ public class Command_potionspy extends FreedomCommand { long unix = now - past; long seconds = Math.round(unix / 1000.0); - if(seconds < 60) + if (seconds < 60) { return seconds + "s"; } else { long minutes = Math.round(seconds / 60.0); - if(minutes < 60) + if (minutes < 60) { return minutes + "m"; } else { long hours = Math.round(minutes / 60.0); - if(hours < 24) + if (hours < 24) { return hours + "h"; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index ca1c768c..db9b6332 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -782,13 +782,6 @@ public class FUtil return colors; } - /** - * Detects if two colors are alike. - * @param first The first Color to check. - * @param second The second Color to check. - * @param tresHold The maximum allowed difference between the colors. - * @return Returns true if the colors are alike. - */ public static boolean colorClose(Color first, Color second, int tresHold) { int redDelta = Math.abs(first.getRed() - second.getRed());