We dont use javadoc & format fixes

This commit is contained in:
Seth 2020-08-01 17:46:14 -07:00
parent 76bb2d08ac
commit a0b29c1d01
No known key found for this signature in database
GPG key ID: A7BAB4E14F089CF3
5 changed files with 40 additions and 86 deletions

1
.gitignore vendored
View file

@ -23,6 +23,7 @@ manifest.mf
/.idea/discord.xml /.idea/discord.xml
/.idea/jarRepositories.xml /.idea/jarRepositories.xml
/.idea/workspace.xml /.idea/workspace.xml
/.idea/uiDesigner.xml
/.idea/libraries /.idea/libraries
*.iml *.iml

View file

@ -41,9 +41,9 @@ public class Monitors extends FreedomService
int potionsThrown = playerThrownPotions.size(); int potionsThrown = playerThrownPotions.size();
boolean trollPotions = false; boolean trollPotions = false;
for(ThrownPotion potion : playerThrownPotions) for (ThrownPotion potion : playerThrownPotions)
{ {
if(isTrollPotion(potion)) if (isTrollPotion(potion))
{ {
trollPotions = true; trollPotions = true;
} }
@ -69,7 +69,7 @@ public class Monitors extends FreedomService
if (event.getEntity().getShooter() instanceof Player) if (event.getEntity().getShooter() instanceof Player)
{ {
ThrownPotion potion = event.getEntity(); ThrownPotion potion = event.getEntity();
if(potion.getShooter() instanceof Player) if (potion.getShooter() instanceof Player)
{ {
Player player = (Player)potion.getShooter(); Player player = (Player)potion.getShooter();
@ -77,11 +77,11 @@ public class Monitors extends FreedomService
recentlyThrownPotions.get(player).add(potion); recentlyThrownPotions.get(player).add(potion);
allThrownPotions.add(new AbstractMap.SimpleEntry<>(potion, System.currentTimeMillis())); 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); recentlyThrownPotions.get(player).remove(0);
} }
if(allThrownPotions.size() > 1024) if (allThrownPotions.size() > 1024)
{ {
allThrownPotions.remove(0); // Remove the first element in the set. 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) if (event.getEntity().getShooter() instanceof Player)
{ {
ThrownPotion potion = event.getEntity(); ThrownPotion potion = event.getEntity();
if(potion.getShooter() instanceof Player) if (potion.getShooter() instanceof Player)
{ {
Player player = (Player)potion.getShooter(); Player player = (Player)potion.getShooter();
@ -103,11 +103,11 @@ public class Monitors extends FreedomService
recentlyThrownPotions.get(player).add(potion); recentlyThrownPotions.get(player).add(potion);
allThrownPotions.add(new AbstractMap.SimpleEntry<>(potion, System.currentTimeMillis())); 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); recentlyThrownPotions.get(player).remove(0);
} }
if(allThrownPotions.size() > 1024) if (allThrownPotions.size() > 1024)
{ {
allThrownPotions.remove(0); // Remove the first element in the set. 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<Map.Entry<ThrownPotion, Long>> getPlayerThrownPotions(Player player) public List<Map.Entry<ThrownPotion, Long>> getPlayerThrownPotions(Player player)
{ {
List<Map.Entry<ThrownPotion, Long>> thrownPotions = new ArrayList<>(); List<Map.Entry<ThrownPotion, Long>> thrownPotions = new ArrayList<>();
for(Map.Entry<ThrownPotion, Long> potionEntry : allThrownPotions) for (Map.Entry<ThrownPotion, Long> potionEntry : allThrownPotions)
{ {
ThrownPotion potion = potionEntry.getKey(); ThrownPotion potion = potionEntry.getKey();
if(potion.getShooter() != null && potion.getShooter().equals(player)) if (potion.getShooter() != null && potion.getShooter().equals(player))
{ {
thrownPotions.add(potionEntry); thrownPotions.add(potionEntry);
} }
@ -136,18 +131,13 @@ public class Monitors extends FreedomService
return thrownPotions; 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) public boolean isTrollPotion(ThrownPotion potion)
{ {
int badEffectsDetected = 0; 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++; badEffectsDetected++;
} }

View file

@ -13,17 +13,12 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.FreedomService;
import net.coreprotect.CoreProtectAPI; import net.coreprotect.CoreProtectAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
/**
* Links TF-FAWE and the CoreProtect API together with two functions.
* @author CoolJWB
*/
public class FAWEBridge extends FreedomService public class FAWEBridge extends FreedomService
{ {
private CoreProtectAPI api; 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. * 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 @Override
public void run() public void run()
@ -60,9 +55,9 @@ public class FAWEBridge extends FreedomService
if (blockVector3 != null) if (blockVector3 != null)
{ {
EditSession editSession = playerAndSessionEntry.getValue(); 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()); 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); 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()) 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()); Location location = new Location(world, blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
BaseBlock block = pattern.apply(blockVector3); BaseBlock block = pattern.apply(blockVector3);
Material material = Material.getMaterial(block.getBlockType().getId().replaceFirst("minecraft:", "").toUpperCase()); 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) public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, BlockVector3 blockVector3)
{ {
// Cache the world used for the next iterations to come. // 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<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession); Map.Entry<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession);
Block block = world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ()); Block block = world.getBlockAt(blockVector3.getBlockX(), blockVector3.getBlockY(), blockVector3.getBlockZ());
// Add the broken block to CoreProtect if it's not air. // Add the broken block to CoreProtect if it's not air.
if(!block.getType().isAir()) if (!block.getType().isAir())
{ {
String blockData = block.getBlockData().getAsString(); String blockData = block.getBlockData().getAsString();
blockData = new Gson().fromJson(new Gson().toJson(blockData), blockData.getClass()); // Overwrite original with deep clones. 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. // 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.putIfAbsent(playerAndSessionEntry, new AbstractMap.SimpleEntry<>(pattern, new ArrayList<>()));
blocksPlaced.get(playerAndSessionEntry).getValue().add(new Gson().fromJson(new Gson().toJson(blockVector3), blockVector3.getClass())); 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) public void logBlockEdits(String playerName, EditSession editSession, Region region, Pattern pattern)
{ {
// Add the broken blocks to CoreProtect. // Add the broken blocks to CoreProtect.
World world = Bukkit.getWorld(region.getWorld().getName()); World world = server.getWorld(region.getWorld().getName());
List<Block> blocks = new ArrayList<>(); List<Block> blocks = new ArrayList<>();
for (BlockVector3 blockVector3 : region) for (BlockVector3 blockVector3 : region)
@ -163,20 +145,13 @@ public class FAWEBridge extends FreedomService
logBlockEdit(playerName, editSession, pattern, blocks); 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<Block> blocks) public void logBlockEdit(String playerName, EditSession editSession, Pattern pattern, List<Block> blocks)
{ {
Map.Entry<String, EditSession> playerAndSessionEntry = new AbstractMap.SimpleEntry(playerName, editSession); Map.Entry<String, EditSession> 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()); BlockVector3 blockVector3 = BlockVector3.at(block.getX(), block.getY(), block.getZ());

View file

@ -30,7 +30,7 @@ public class Command_potionspy extends FreedomCommand
{ {
Admin admin = plugin.al.getAdmin(playerSender); Admin admin = plugin.al.getAdmin(playerSender);
if(args.length <= 0) if (args.length <= 0)
{ {
setPotionSpyState(admin, !admin.getPotionSpy()); setPotionSpyState(admin, !admin.getPotionSpy());
return true; return true;
@ -50,10 +50,10 @@ public class Command_potionspy extends FreedomCommand
break; break;
case "history": case "history":
if(args.length == 3) if (args.length == 3)
{ {
Player player = Bukkit.getPlayer(args[1]); Player player = Bukkit.getPlayer(args[1]);
if(player == null) if (player == null)
{ {
msg(sender, "Please specify a valid player name."); msg(sender, "Please specify a valid player name.");
return true; return true;
@ -65,12 +65,12 @@ public class Command_potionspy extends FreedomCommand
List<String> potionThrowNotifications = new ArrayList<>(); List<String> potionThrowNotifications = new ArrayList<>();
int lastPage = (int)Math.ceil(thrownPotions.size() / 5.0); int lastPage = (int)Math.ceil(thrownPotions.size() / 5.0);
if(thrownPotions.isEmpty()) if (thrownPotions.isEmpty())
{ {
msg(sender, noPlayerRecord); msg(sender, noPlayerRecord);
return true; return true;
} }
if(!NumberUtils.isNumber(args[2])) if (!NumberUtils.isNumber(args[2]))
{ {
msg(sender, String.format(validPageText, lastPage)); msg(sender, String.format(validPageText, lastPage));
return true; return true;
@ -79,7 +79,7 @@ public class Command_potionspy extends FreedomCommand
Collections.reverse(thrownPotions); Collections.reverse(thrownPotions);
int pageIndex = Integer.parseInt(args[2]); int pageIndex = Integer.parseInt(args[2]);
for(Map.Entry<ThrownPotion, Long> potionEntry : thrownPotions) for (Map.Entry<ThrownPotion, Long> potionEntry : thrownPotions)
{ {
ThrownPotion potion = potionEntry.getKey(); ThrownPotion potion = potionEntry.getKey();
boolean trollPotions = plugin.mo.isTrollPotion(potion); boolean trollPotions = plugin.mo.isTrollPotion(potion);
@ -89,7 +89,7 @@ public class Command_potionspy extends FreedomCommand
} }
List<String> page = FUtil.getPageFromList(potionThrowNotifications, 5, pageIndex - 1); List<String> page = FUtil.getPageFromList(potionThrowNotifications, 5, pageIndex - 1);
if(!page.isEmpty()) if (!page.isEmpty())
{ {
msg(sender, ChatColor.translateAlternateColorCodes('&', titleText)); msg(sender, ChatColor.translateAlternateColorCodes('&', titleText));
for (String potionThrowNotification : page) for (String potionThrowNotification : page)
@ -105,7 +105,7 @@ public class Command_potionspy extends FreedomCommand
msg(sender, ChatColor.translateAlternateColorCodes('&', String.format(bottomText, pageIndex, lastPage))); msg(sender, ChatColor.translateAlternateColorCodes('&', String.format(bottomText, pageIndex, lastPage)));
} }
else if(args.length == 2) else if (args.length == 2)
{ {
List<Map.Entry<ThrownPotion, Long>> thrownPotions = new ArrayList<>(); List<Map.Entry<ThrownPotion, Long>> thrownPotions = new ArrayList<>();
thrownPotions.addAll(plugin.mo.getAllThrownPotions()); // Make a copy of the list to avoid modifying the original. 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<String> potionThrowNotifications = new ArrayList<>(); List<String> potionThrowNotifications = new ArrayList<>();
int lastPage = (int)Math.ceil(thrownPotions.size() / 5.0); int lastPage = (int)Math.ceil(thrownPotions.size() / 5.0);
if(thrownPotions.isEmpty()) if (thrownPotions.isEmpty())
{ {
if(Bukkit.getPlayer(args[1]) != null) if(Bukkit.getPlayer(args[1]) != null)
{ {
@ -125,7 +125,7 @@ public class Command_potionspy extends FreedomCommand
} }
return true; return true;
} }
if(!NumberUtils.isNumber(args[1])) if (!NumberUtils.isNumber(args[1]))
{ {
msg(sender, String.format(validPageText, lastPage)); msg(sender, String.format(validPageText, lastPage));
return true; return true;
@ -134,7 +134,7 @@ public class Command_potionspy extends FreedomCommand
Collections.reverse(thrownPotions); Collections.reverse(thrownPotions);
int pageIndex = Integer.parseInt(args[1]); int pageIndex = Integer.parseInt(args[1]);
for(Map.Entry<ThrownPotion, Long> potionEntry : thrownPotions) for (Map.Entry<ThrownPotion, Long> potionEntry : thrownPotions)
{ {
ThrownPotion potion = potionEntry.getKey(); ThrownPotion potion = potionEntry.getKey();
Player player = (Player)potion.getShooter(); Player player = (Player)potion.getShooter();
@ -148,7 +148,7 @@ public class Command_potionspy extends FreedomCommand
} }
List<String> page = FUtil.getPageFromList(potionThrowNotifications, 5, pageIndex - 1); List<String> page = FUtil.getPageFromList(potionThrowNotifications, 5, pageIndex - 1);
if(!page.isEmpty()) if (!page.isEmpty())
{ {
msg(sender, ChatColor.translateAlternateColorCodes('&', titleText)); msg(sender, ChatColor.translateAlternateColorCodes('&', titleText));
for (String potionThrowNotification : page) for (String potionThrowNotification : page)
@ -176,11 +176,6 @@ public class Command_potionspy extends FreedomCommand
return true; 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) private void setPotionSpyState(Admin admin, boolean state)
{ {
admin.setPotionSpy(state); admin.setPotionSpy(state);
@ -199,21 +194,21 @@ public class Command_potionspy extends FreedomCommand
{ {
long unix = now - past; long unix = now - past;
long seconds = Math.round(unix / 1000.0); long seconds = Math.round(unix / 1000.0);
if(seconds < 60) if (seconds < 60)
{ {
return seconds + "s"; return seconds + "s";
} }
else else
{ {
long minutes = Math.round(seconds / 60.0); long minutes = Math.round(seconds / 60.0);
if(minutes < 60) if (minutes < 60)
{ {
return minutes + "m"; return minutes + "m";
} }
else else
{ {
long hours = Math.round(minutes / 60.0); long hours = Math.round(minutes / 60.0);
if(hours < 24) if (hours < 24)
{ {
return hours + "h"; return hours + "h";
} }

View file

@ -782,13 +782,6 @@ public class FUtil
return colors; 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) public static boolean colorClose(Color first, Color second, int tresHold)
{ {
int redDelta = Math.abs(first.getRed() - second.getRed()); int redDelta = Math.abs(first.getRed() - second.getRed());