diff --git a/.gitignore b/.gitignore index 3c0693654182e90a745f329e663650a8aaac513d..4328f17483e58b17d1188b7e17ff7c5cd3f67cb4 100644 --- a/.gitignore +++ b/.gitignore @@ -29,11 +29,13 @@ hs_err_pid* *.json # Folders +/!* +/.gradle /bin -/.settings -/0Media +/build /config /crash-reports +/gradle /logs /saves /world diff --git a/README.md b/README.md index 281140e551251c3cf95a59bcfe5811a76ec71d7a..864879d045bc2bdbffa07431074d73cb58d6699c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# PvP-Utilities +# PvP Utilities This is a server side mod, adding lots of useful utilities for Minecraft PvP, be it modded or Vanilla.\ It was originally made for a private PvP project using FTB Trident and it's my first mod. -The mod can be downloaded on [CurseForge](https://www.curseforge.com/minecraft/mc-mods/pvp-utilities) +The mod can be downloaded on [CurseForge](https://www.curseforge.com/minecraft/mc-mods/pvp-utilities). Features:\ (All modules can be turned off in the config) diff --git a/src/java/rsge/mods/pvputils/commands/CmdBase.java b/src/java/rsge/mods/pvputils/commands/CmdBase.java index 4cffc2e9896a9dcd49c8e4a531b1463bb3c1c4ea..b2a5f702066f5d178190f0c9c4f4448050da057b 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdBase.java +++ b/src/java/rsge/mods/pvputils/commands/CmdBase.java @@ -17,16 +17,14 @@ import net.minecraft.util.ChatComponentText; * * @author Rsge */ -public abstract class CmdBase implements ISubCmd -{ +public abstract class CmdBase implements ISubCmd { private String name; private List<String> subCommands = new ArrayList<>(); protected int permissionLevel = 0; /* ————————————————————————————————————————————————————— */ - public CmdBase(String name, String... subCommands) - { + public CmdBase(String name, String... subCommands) { this.name = name; this.subCommands = Arrays.asList(subCommands); } @@ -40,8 +38,7 @@ public abstract class CmdBase implements ISubCmd * @return if player is op */ @SuppressWarnings("unlikely-arg-type") - public static boolean isPlayerOp(GameProfile user) - { + public static boolean isPlayerOp(GameProfile user) { // Returns "true" if either // "user" is allowed to use commands return MinecraftServer.getServer().getConfigurationManager().func_152596_g(user) @@ -55,11 +52,9 @@ public abstract class CmdBase implements ISubCmd * @param cmdsender Command sender * @return if player is allowed to use op-commands */ - public static boolean isCmdsAllowed(ICommandSender cmdsender) - { + public static boolean isCmdsAllowed(ICommandSender cmdsender) { // If the command-sender is a player - if (cmdsender instanceof EntityPlayer) - { + if (cmdsender instanceof EntityPlayer){ EntityPlayer p = (EntityPlayer) cmdsender; GameProfile user = p.getGameProfile(); return isPlayerOp(user); @@ -76,8 +71,7 @@ public abstract class CmdBase implements ISubCmd * @param cmdsender Player to send chat to * @param s String to send */ - protected void sendChat(ICommandSender cmdsender, String s) - { + protected void sendChat(ICommandSender cmdsender, String s) { cmdsender.addChatMessage(new ChatComponentText(s)); } @@ -88,8 +82,7 @@ public abstract class CmdBase implements ISubCmd * @return Name of command */ @Override - public String getCommandName() - { + public String getCommandName() { return name; } @@ -97,8 +90,7 @@ public abstract class CmdBase implements ISubCmd * @return Permission level of command as integer */ @Override - public int getPermissionLevel() - { + public int getPermissionLevel() { return permissionLevel; } @@ -110,17 +102,13 @@ public abstract class CmdBase implements ISubCmd * @return Autocompletion options */ @Override - public List<String> addTabCompletionOptions(ICommandSender cmdsender, String[] args) - { + public List<String> addTabCompletionOptions(ICommandSender cmdsender, String[] args) { List<String> res = new ArrayList<>(); - if (args.length == 1) - { + if (args.length == 1){ // Goes through all "subCommands" and put them in "s" consecutively - for (String s : subCommands) - { + for (String s : subCommands){ // If the current "subCommand" starts the same as the input "s" - if (s.startsWith(args[0])) - { + if (s.startsWith(args[0])){ // adds it to the list of possible results res.add(s); } @@ -137,8 +125,7 @@ public abstract class CmdBase implements ISubCmd * @return if sender can see command */ @Override - public boolean isVisible(ICommandSender cmdsender) - { + public boolean isVisible(ICommandSender cmdsender) { return getPermissionLevel() <= 0 || isCmdsAllowed(cmdsender); } @@ -149,8 +136,7 @@ public abstract class CmdBase implements ISubCmd * @return Syntax options for command */ @Override - public int[] getSyntaxOptions(ICommandSender cmdsender) - { + public int[] getSyntaxOptions(ICommandSender cmdsender) { return new int[] {0}; } } diff --git a/src/java/rsge/mods/pvputils/commands/CmdHandler.java b/src/java/rsge/mods/pvputils/commands/CmdHandler.java index 8b2b199340828371b0f3904160fbcde6c86bb356..ba68b645e893497adf65b4e12eaefa14cf625fbf 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdHandler.java +++ b/src/java/rsge/mods/pvputils/commands/CmdHandler.java @@ -19,8 +19,7 @@ import rsge.mods.pvputils.config.Config; * * @author Rsge */ -public class CmdHandler extends CommandBase -{ +public class CmdHandler extends CommandBase { public static Map<String, ISubCmd> commands = new LinkedHashMap<>(); public static CmdHandler instance = new CmdHandler(); @@ -32,8 +31,7 @@ public class CmdHandler extends CommandBase * * @param cmd to register */ - public static void register(ISubCmd cmd) - { + public static void register(ISubCmd cmd) { commands.put(cmd.getCommandName(), cmd); } @@ -43,8 +41,7 @@ public class CmdHandler extends CommandBase * @param name of command * @return if command is registered */ - public static boolean commandExists(String name) - { + public static boolean commandExists(String name) { return commands.containsKey(name); } @@ -53,12 +50,10 @@ public class CmdHandler extends CommandBase /** * List of all commands after base command to register */ - static - { + static{ register(new CmdHelp()); register(new CmdVersion()); - if (Config.livesEnabled || Config.timeEnabled) - { + if (Config.livesEnabled || Config.timeEnabled){ register(new CmdSave()); register(new CmdReload()); if (Config.livesEnabled) @@ -72,8 +67,7 @@ public class CmdHandler extends CommandBase // Overrides standard setting: @Override - public boolean canCommandSenderUseCommand(ICommandSender cmdsender) - { + public boolean canCommandSenderUseCommand(ICommandSender cmdsender) { // Everyone can use this command return true; } @@ -82,8 +76,7 @@ public class CmdHandler extends CommandBase * @return Name of command */ @Override - public String getCommandName() - { + public String getCommandName() { return "pvputils"; } @@ -92,8 +85,7 @@ public class CmdHandler extends CommandBase /** * @return Aliases of command */ - public List<String> getCommandAliases() - { + public List<String> getCommandAliases() { this.alias = new ArrayList<String>(); this.alias.add("pvputils"); return this.alias; @@ -102,24 +94,20 @@ public class CmdHandler extends CommandBase /** * @return "/[Command name] help" */ - public String getCommandUsage(ICommandSender cmdsender) - { + public String getCommandUsage(ICommandSender cmdsender) { return "/" + getCommandName() + " help"; // ==> /pvputils help } @Override @SuppressWarnings(value = {"unchecked", "rawtypes"}) - public List addTabCompletionOptions(ICommandSender cmdsender, String[] args) - { - if (args.length == 1) - { + public List addTabCompletionOptions(ICommandSender cmdsender, String[] args) { + if (args.length == 1){ // "s" is given the value of "args" at the position 0 String s = args[0]; List res = new ArrayList(); // Goes through each command in the "commands"-list - for (ISubCmd cmd : commands.values()) - { + for (ISubCmd cmd : commands.values()){ // If the command is visible to the sender and starts with "s" if (cmd.isVisible(cmdsender) && cmd.getCommandName().startsWith(s)) // adds it to the results-list @@ -127,8 +115,7 @@ public class CmdHandler extends CommandBase } return res; } - else if (commands.containsKey(args[0]) && commands.get(args[0]).isVisible(cmdsender)) - { + else if (commands.containsKey(args[0]) && commands.get(args[0]).isVisible(cmdsender)){ return commands.get(args[0]).addTabCompletionOptions(cmdsender, Arrays.copyOfRange(args, 1, args.length)); } return null; @@ -140,20 +127,16 @@ public class CmdHandler extends CommandBase * @param cmdsender Player who send command * @param args Arguments of command */ - public void processCommand(ICommandSender cmdsender, String[] args) - { + public void processCommand(ICommandSender cmdsender, String[] args) { // If there are no arguments - if (args.length < 1) - { + if (args.length < 1){ // starts the help command args = new String[] {"help"}; } ISubCmd cmd = commands.get(args[0]); - if (cmd != null) - { + if (cmd != null){ if (cmd.isVisible(cmdsender) && (cmdsender.canCommandSenderUseCommand(cmd.getPermissionLevel(), getCommandName() + " " + cmd.getCommandName()) - || (cmdsender instanceof EntityPlayerMP && cmd.getPermissionLevel() <= 0))) - { + || (cmdsender instanceof EntityPlayerMP && cmd.getPermissionLevel() <= 0))){ cmd.handleCommand(cmdsender, Arrays.copyOfRange(args, 1, args.length)); return; } diff --git a/src/java/rsge/mods/pvputils/commands/CmdHelp.java b/src/java/rsge/mods/pvputils/commands/CmdHelp.java index b552139a4e533c13974dda569435b0382ee02a56..4ed5f6ed524f62334d6ef164b8d6d53836bf5885 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdHelp.java +++ b/src/java/rsge/mods/pvputils/commands/CmdHelp.java @@ -10,10 +10,8 @@ import rsge.mods.pvputils.main.Reference; * * @author Rsge */ -public class CmdHelp extends CmdBase -{ - public CmdHelp() - { +public class CmdHelp extends CmdBase { + public CmdHelp() { super("help"); permissionLevel = -1; } @@ -22,34 +20,28 @@ public class CmdHelp extends CmdBase // Overrides @Override - public boolean isVisible(ICommandSender cmdsender) - { + public boolean isVisible(ICommandSender cmdsender) { return true; } @Override - public int getPermissionLevel() - { + public int getPermissionLevel() { return -1; } @Override - public void handleCommand(ICommandSender cmdsender, String[] args) - { + public void handleCommand(ICommandSender cmdsender, String[] args) { sendChat(cmdsender, "/" + Reference.MODID + " version"); - if (isCmdsAllowed(cmdsender)) - { + if (isCmdsAllowed(cmdsender)){ sendChat(cmdsender, "/" + Reference.MODID + " save"); sendChat(cmdsender, "/" + Reference.MODID + " reload"); - if (Config.livesEnabled) - { + if (Config.livesEnabled){ sendChat(cmdsender, "/" + Reference.MODID + " lives <playername/uuid/enable/disable/reset/add/remove>"); sendChat(cmdsender, "/" + Reference.MODID + " lives [reset/add/remove] [playername/uuid/all]"); sendChat(cmdsender, "/" + Reference.MODID + " lives [set/add/remove] [amount]"); sendChat(cmdsender, "/" + Reference.MODID + " lives [set/add/remove] [playername/uuid/all] [amount]"); } - if (Config.timeEnabled) - { + if (Config.timeEnabled){ sendChat(cmdsender, "/" + Reference.MODID + " time <playername/uuid/enable/disable/reset/add/remove/start/stop>"); sendChat(cmdsender, "/" + Reference.MODID + " time [reset/add/remove/start/stop] [playername]"); sendChat(cmdsender, "/" + Reference.MODID + " time [reset/add/remove] [uuid/all]"); @@ -59,8 +51,7 @@ public class CmdHelp extends CmdBase sendChat(cmdsender, "/" + Reference.MODID + " time set multiplier [playername/uuid/all] [percentage]"); } } - else - { + else{ if (Config.livesEnabled) sendChat(cmdsender, "/" + Reference.MODID + " lives <playername/uuid>"); if (Config.timeEnabled) diff --git a/src/java/rsge/mods/pvputils/commands/CmdLives.java b/src/java/rsge/mods/pvputils/commands/CmdLives.java index fddb756595f36f1fcdc4597714378c876a61a6e3..2fdc59301f9942087608e6c15ffb1afd5fb3fcfc 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdLives.java +++ b/src/java/rsge/mods/pvputils/commands/CmdLives.java @@ -26,10 +26,8 @@ import rsge.mods.pvputils.main.Logger; * * @author Rsge */ -public class CmdLives extends CmdBase -{ - public CmdLives() - { +public class CmdLives extends CmdBase { + public CmdLives() { super("lives", "enable", "disable", "reset", "add", "remove"); permissionLevel = 0; } @@ -38,14 +36,12 @@ public class CmdLives extends CmdBase // Overrides @Override - public boolean isVisible(ICommandSender cmdsender) - { + public boolean isVisible(ICommandSender cmdsender) { return true; } @Override - public List<String> addTabCompletionOptions(ICommandSender cmdsender, String[] args) - { + public List<String> addTabCompletionOptions(ICommandSender cmdsender, String[] args) { if (isCmdsAllowed(cmdsender)) return super.addTabCompletionOptions(cmdsender, args); else @@ -53,48 +49,41 @@ public class CmdLives extends CmdBase } @Override - public int[] getSyntaxOptions(ICommandSender cmdsender) - { + public int[] getSyntaxOptions(ICommandSender cmdsender) { return isCmdsAllowed(cmdsender) ? new int[] {0, 1, 2, 3} : super.getSyntaxOptions(cmdsender); } /* ————————————————————————————————————————————————————— */ @Override - public void handleCommand(ICommandSender cmdsender, String[] args) - { + public void handleCommand(ICommandSender cmdsender, String[] args) { String s; String max = "You reached the max amount of lives."; EntityPlayerMP p; // With no extra argument // /pvputils lives - if (args.length == 0 && cmdsender instanceof EntityPlayer) - { + if (args.length == 0 && cmdsender instanceof EntityPlayer){ p = (EntityPlayerMP) cmdsender; Lives.chatLives(p); } // With 1 argument // /pvputils lives <enable/disable/reset/add/remove/playername/uuid> - else if (args.length == 1 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 1 && cmdsender instanceof EntityPlayer){ p = (EntityPlayerMP) cmdsender; - - switch (args[0].toLowerCase()) - { + + switch (args[0].toLowerCase()) { // /pvputils lives enable case "enable": if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); - try - { + try{ Lives.init(); Config.livesEnabled = true; } - catch (IOException e) - { + catch (IOException e){ throw new CommandException("pvputils.command.ioException"); } @@ -136,14 +125,12 @@ public class CmdLives extends CmdBase Lives.addLives(p, 1); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Added 1 life to "; sendChat(cmdsender, s + "yourself."); Logger.logCmd(cmdsender, s + "him-/herself."); } - else - { + else{ sendChat(cmdsender, max); Logger.logCmd(cmdsender, "Tried adding life, reached max amount."); Lives.tooManyAdded = false; @@ -168,8 +155,7 @@ public class CmdLives extends CmdBase // /pvputils lives [playername/uuid] default: // /pvputils lives [uuid] - try - { + try{ UUID u = UUID.fromString(args[0]); byte l = Lives.getLives(u); @@ -187,18 +173,15 @@ public class CmdLives extends CmdBase msgFinal.setChatStyle(new ChatStyle().setBold(true)); cmdsender.addChatMessage(msgFinal); } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex){ // /pvputils lives [playername] - try - { + try{ String name = args[0]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); EntityPlayer receiver = (EntityPlayer) cmdsender; Lives.chatLivesTo(p, receiver); } - catch (NullPointerException e) - { + catch (NullPointerException e){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } @@ -208,34 +191,29 @@ public class CmdLives extends CmdBase // With 2 arguments // /pvputils lives [reset/set/add/remove] [playername/uuid/all/amount] - else if (args.length == 2 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 2 && cmdsender instanceof EntityPlayer){ p = (EntityPlayerMP) cmdsender; - + if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); // /pvputils lives [set/add/remove] [amount] - if (StringUtils.isNumeric(args[1])) - { + if (StringUtils.isNumeric(args[1])){ int a = Integer.parseInt(args[1]); if (a < 0) throw new WrongUsageException("pvputils.command.positiveNumbers"); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils lives set [amount] case "set": Lives.setLives(p, a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ sendChat(cmdsender, "Set your lives to " + a + "."); Logger.logCmd(cmdsender, "Set his/her lives to " + a + "."); } - else - { + else{ sendChat(cmdsender, max); Logger.logCmd(cmdsender, "Set his/her lives to max."); Lives.tooManyAdded = false; @@ -246,14 +224,12 @@ public class CmdLives extends CmdBase case "add": Lives.addLives(p, a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Added " + a + " lives to "; sendChat(cmdsender, s + "yourself."); Logger.logCmd(cmdsender, s + "him-/herself."); } - else - { + else{ sendChat(cmdsender, max); Logger.logCmd(cmdsender, "Tried adding " + a + " lives to him-/herself, reached max."); Lives.tooManyAdded = false; @@ -264,14 +240,12 @@ public class CmdLives extends CmdBase case "remove": Lives.removeLives(p, a); - if (!Lives.playerBanned) - { + if (!Lives.playerBanned){ s = "Removed " + a + " lives from "; sendChat(cmdsender, s + "yourself."); Logger.logCmd(cmdsender, s + "him-/herself."); } - else - { + else{ Logger.logCmd(cmdsender, "Removed all his/her remaining lives."); Lives.playerBanned = false; } @@ -279,10 +253,8 @@ public class CmdLives extends CmdBase } } // /pvputils lives [reset/add/remove] all - else if (args[1].equalsIgnoreCase("all")) - { - switch (args[0].toLowerCase()) - { + else if (args[1].equalsIgnoreCase("all")){ + switch (args[0].toLowerCase()) { // /pvputils lives reset all case "reset": Lives.resetAllLives(); @@ -299,8 +271,7 @@ public class CmdLives extends CmdBase s = "Added 1 life to everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Lives.tooManyAdded) - { + if (Lives.tooManyAdded){ sendChat(cmdsender, "In the process someone reached the max amount of lives."); Lives.tooManyAdded = false; } @@ -313,8 +284,7 @@ public class CmdLives extends CmdBase s = "Removed 1 life from everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Lives.playerBanned) - { + if (Lives.playerBanned){ sendChat(cmdsender, "In the process someone ran out of lives and was banned."); Lives.playerBanned = false; } @@ -322,15 +292,12 @@ public class CmdLives extends CmdBase } } // /pvputils lives [reset/add/remove] [playername/uuid] - else - { + else{ // /pvputils lives [reset/add/remove] [uuid] - try - { + try{ UUID u = UUID.fromString(args[1]); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils lives reset [uuid] case "reset": Lives.resetLives(u); @@ -343,14 +310,12 @@ public class CmdLives extends CmdBase case "add": Lives.addLives(u, 1); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Added 1 life to "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ sendChat(cmdsender, "This guy reached the max amount of lives."); Logger.logCmd(cmdsender, "Tried adding 1 life to " + u.toString() + ", reached max."); Lives.tooManyAdded = false; @@ -361,14 +326,12 @@ public class CmdLives extends CmdBase case "remove": Lives.removeLives(u, 1); - if (!Lives.playerBanned) - { + if (!Lives.playerBanned){ s = "Removed 1 life from "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ s = "Removed remaining life from "; sendChat(cmdsender, s + "this guy. Player banned!"); Logger.logCmd(cmdsender, s + u.toString() + ". Player banned."); @@ -377,16 +340,13 @@ public class CmdLives extends CmdBase break; } } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex){ // /pvputils lives [reset/add/remove] [playername] - try - { + try{ String name = args[1]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils lives reset [playername] case "reset": Lives.resetLives(p); @@ -400,14 +360,12 @@ public class CmdLives extends CmdBase case "add": Lives.addLives(p, 1); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Added 1 life to " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, name + " reached the max amount of lives."); Logger.logCmd(cmdsender, "Tried adding 1 life to " + name + ", reached max."); Lives.tooManyAdded = false; @@ -418,14 +376,12 @@ public class CmdLives extends CmdBase case "remove": Lives.removeLives(p, 1); - if (!Lives.playerBanned) - { + if (!Lives.playerBanned){ s = "Removed 1 life from " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ s = "Removed remaining life from " + name + ". Player banned!"; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); @@ -434,8 +390,7 @@ public class CmdLives extends CmdBase break; } } - catch (NullPointerException e) - { + catch (NullPointerException e){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } @@ -444,40 +399,33 @@ public class CmdLives extends CmdBase // With all 3 arguments // /pvputils lives [set/add/remove] [playername/uuid/all] [amount] - else if (args.length == 3 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 3 && cmdsender instanceof EntityPlayer){ if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); int a = 0; - try - { + try{ a = Integer.parseInt(args[2]); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex){ throw new SyntaxErrorException("pvputils.command.notFound"); } if (a < 0) throw new WrongUsageException("pvputils.command.positiveNumbers"); // /pvputils lives [set/add/remove] all [amount] - if (args[1].equalsIgnoreCase("all")) - { - switch (args[0].toLowerCase()) - { + if (args[1].equalsIgnoreCase("all")){ + switch (args[0].toLowerCase()) { // /pvputils lives set all [amount] case "set": Lives.setAllLives(a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Set everyone's lives to " + a + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, "Everyone now has the max amount of lives."); Logger.logCmd(cmdsender, "Set everyone's lives to max."); Lives.tooManyAdded = false; @@ -491,8 +439,7 @@ public class CmdLives extends CmdBase s = "Added " + a + " lives to everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Lives.tooManyAdded) - { + if (Lives.tooManyAdded){ sendChat(cmdsender, "In the process someone reached the max amount of lives."); Lives.tooManyAdded = false; } @@ -505,8 +452,7 @@ public class CmdLives extends CmdBase s = "Removed " + a + " lives from everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Lives.playerBanned) - { + if (Lives.playerBanned){ sendChat(cmdsender, "In the process someone lost his/her last live . Player(s) banned!"); Lives.playerBanned = false; } @@ -514,26 +460,21 @@ public class CmdLives extends CmdBase } } // /pvputils lives [set/add/remove] [playername/uuid] [amount] - else - { + else{ // /pvputils lives [set/add/remove] [uuid] [amount] - try - { + try{ UUID u = UUID.fromString(args[1]); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils lives set [uuid] [amount] case "set": Lives.setLives(u, a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ sendChat(cmdsender, "Set this guy's lives to " + a + "."); Logger.logCmd(cmdsender, "Set lives of " + u.toString() + " to " + a + "."); } - else - { + else{ sendChat(cmdsender, "This guy reached the max amount of lives."); Logger.logCmd(cmdsender, "Set lives of " + u.toString() + " to max."); Lives.tooManyAdded = false; @@ -544,14 +485,12 @@ public class CmdLives extends CmdBase case "add": Lives.addLives(u, a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Added " + a + " lives to "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ sendChat(cmdsender, "This guy reached the max amount of lives."); Logger.logCmd(cmdsender, "Tried adding " + a + " lives to " + u.toString() + ", reached max."); Lives.tooManyAdded = false; @@ -562,14 +501,12 @@ public class CmdLives extends CmdBase case "remove": Lives.removeLives(u, a); - if (!Lives.playerBanned) - { + if (!Lives.playerBanned){ s = "Removed " + a + " lives from"; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ s = "Removed remaining lives from "; sendChat(cmdsender, s + "this guy. Player banned!"); Logger.logCmd(cmdsender, s + u.toString() + ". Player banned!"); @@ -578,27 +515,22 @@ public class CmdLives extends CmdBase break; } } - catch (IllegalArgumentException ex) - { - try - { + catch (IllegalArgumentException ex){ + try{ String name = args[1]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils lives set [playername] [amount] case "set": Lives.setLives(p, a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Set " + name + "'s lives to " + a + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, name + " reached the max amount of lives."); Logger.logCmd(cmdsender, "Set " + name + "'s lives to max."); Lives.tooManyAdded = false; @@ -609,14 +541,12 @@ public class CmdLives extends CmdBase case "add": Lives.addLives(p, a); - if (!Lives.tooManyAdded) - { + if (!Lives.tooManyAdded){ s = "Added " + a + " lives to " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, name + " reached the max amount of lives."); Logger.logCmd(cmdsender, "Tried adding " + a + " lives to " + name + ", reached max."); Lives.tooManyAdded = false; @@ -627,14 +557,12 @@ public class CmdLives extends CmdBase case "remove": Lives.removeLives(p, a); - if (!Lives.playerBanned) - { + if (!Lives.playerBanned){ s = "Removed " + a + " lives from " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ s = "Removed remaining lives from " + name + ". Player banned!"; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); @@ -643,8 +571,7 @@ public class CmdLives extends CmdBase break; } } - catch (NullPointerException e) - { + catch (NullPointerException e){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } diff --git a/src/java/rsge/mods/pvputils/commands/CmdReload.java b/src/java/rsge/mods/pvputils/commands/CmdReload.java index 3ee113f8bbcedbca807a29c47be9fed71cbd00eb..8bab37a812a240c90c557b285089b25807b7a876 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdReload.java +++ b/src/java/rsge/mods/pvputils/commands/CmdReload.java @@ -15,18 +15,15 @@ import rsge.mods.pvputils.data.Time; * * @author Rsge */ -public class CmdReload extends CmdBase -{ - public CmdReload() - { +public class CmdReload extends CmdBase { + public CmdReload() { super("reload"); permissionLevel = 3; } // Overrides @Override - public boolean isVisible(ICommandSender cmdsender) - { + public boolean isVisible(ICommandSender cmdsender) { if (isCmdsAllowed(cmdsender)) return true; else @@ -34,18 +31,15 @@ public class CmdReload extends CmdBase } @Override - public int getPermissionLevel() - { + public int getPermissionLevel() { return 3; } @Override - public void handleCommand(ICommandSender cmdsender, String[] args) - { + public void handleCommand(ICommandSender cmdsender, String[] args) { if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); - try - { + try{ if (Config.livesEnabled) Lives.init(); if (Config.timeEnabled) @@ -53,8 +47,7 @@ public class CmdReload extends CmdBase sendChat(cmdsender, "Data reloaded"); } - catch (IOException ex) - { + catch (IOException ex){ throw new CommandException("pvputils.command.ioException"); } } diff --git a/src/java/rsge/mods/pvputils/commands/CmdSave.java b/src/java/rsge/mods/pvputils/commands/CmdSave.java index 1b46b411713fc0ccd561afb310a1a04344a312fc..fc46047236aeb42b272bbe04bf6cbcf89f06272c 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdSave.java +++ b/src/java/rsge/mods/pvputils/commands/CmdSave.java @@ -15,18 +15,15 @@ import rsge.mods.pvputils.data.Time; * * @author Rsge */ -public class CmdSave extends CmdBase -{ - public CmdSave() - { +public class CmdSave extends CmdBase { + public CmdSave() { super("save"); permissionLevel = 3; } // Overrides @Override - public boolean isVisible(ICommandSender cmdsender) - { + public boolean isVisible(ICommandSender cmdsender) { if (isCmdsAllowed(cmdsender)) return true; else @@ -34,26 +31,22 @@ public class CmdSave extends CmdBase } @Override - public int getPermissionLevel() - { + public int getPermissionLevel() { return 3; } @Override - public void handleCommand(ICommandSender cmdsender, String[] args) - { + public void handleCommand(ICommandSender cmdsender, String[] args) { if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); - try - { + try{ if (Config.livesEnabled) Lives.save(); if (Config.timeEnabled) Time.save(); } - catch (IOException e) - { + catch (IOException e){ throw new CommandException("pvputils.command.ioException"); } diff --git a/src/java/rsge/mods/pvputils/commands/CmdTime.java b/src/java/rsge/mods/pvputils/commands/CmdTime.java index c8f00056cdaaf59bb856f6fab2b41b245243beee..2fff3df064b3ab842c6aad1796770fb8d2477355 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdTime.java +++ b/src/java/rsge/mods/pvputils/commands/CmdTime.java @@ -27,10 +27,8 @@ import rsge.mods.pvputils.main.Logger; * * @author Rsge */ -public class CmdTime extends CmdBase -{ - public CmdTime() - { +public class CmdTime extends CmdBase { + public CmdTime() { super("time", "enable", "disable", "start", "stop", "reset", "add", "remove"); permissionLevel = 0; } @@ -39,14 +37,12 @@ public class CmdTime extends CmdBase // Overrides @Override - public boolean isVisible(ICommandSender cmdsender) - { + public boolean isVisible(ICommandSender cmdsender) { return true; } @Override - public List<String> addTabCompletionOptions(ICommandSender cmdsender, String[] args) - { + public List<String> addTabCompletionOptions(ICommandSender cmdsender, String[] args) { if (isCmdsAllowed(cmdsender)) return super.addTabCompletionOptions(cmdsender, args); else @@ -54,48 +50,41 @@ public class CmdTime extends CmdBase } @Override - public int[] getSyntaxOptions(ICommandSender cmdsender) - { + public int[] getSyntaxOptions(ICommandSender cmdsender) { return isCmdsAllowed(cmdsender) ? new int[] {0, 1, 2, 3} : super.getSyntaxOptions(cmdsender); } /* ————————————————————————————————————————————————————— */ @Override - public void handleCommand(ICommandSender cmdsender, String[] args) - { + public void handleCommand(ICommandSender cmdsender, String[] args) { String s; String max = "You reached the max possible time."; EntityPlayerMP p; // With no extra arguments // /pvputils time - if (args.length == 0 && cmdsender instanceof EntityPlayer) - { + if (args.length == 0 && cmdsender instanceof EntityPlayer){ p = (EntityPlayerMP) cmdsender; Time.chatTime(p); } // With 1 argument // /pvputils time <enable/disable/start/stop/reset/add/remove/playername/uuid> - else if (args.length == 1 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 1 && cmdsender instanceof EntityPlayer){ p = (EntityPlayerMP) cmdsender; - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils time enable case "enable": if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); - try - { + try{ Time.init(); Config.timeEnabled = true; } - catch (IOException e) - { + catch (IOException e){ throw new CommandException("pvputils.command.ioException"); } @@ -159,14 +148,12 @@ public class CmdTime extends CmdBase Time.addTime(p, Config.addedTime); - if (!Time.tooMuchAdded) - { + if (!Time.tooMuchAdded){ s = "Added " + Config.addedTime / 60 + " minutes to "; sendChat(cmdsender, s + "yourself."); Logger.logCmd(cmdsender, s + "him-/herself."); } - else - { + else{ sendChat(cmdsender, max); Logger.logCmd(cmdsender, "Tried adding " + Config.addedTime / 60 + " minutes, reached max amount."); Time.tooMuchAdded = false; @@ -191,8 +178,7 @@ public class CmdTime extends CmdBase // /pvputils time [playername/uuid] default: // /pvputils time [uuid] - try - { + try{ UUID u = UUID.fromString(args[0]); long t = Time.getTime(u); @@ -204,17 +190,14 @@ public class CmdTime extends CmdBase msgFinal.setChatStyle(new ChatStyle().setBold(true)); cmdsender.addChatMessage(msgFinal); } - catch (IllegalArgumentException ex) - { - try - { + catch (IllegalArgumentException ex){ + try{ String name = args[0]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); EntityPlayer receiver = (EntityPlayer) cmdsender; Time.chatTimeTo(p, receiver); } - catch (Exception exc) - { + catch (Exception exc){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } @@ -224,38 +207,32 @@ public class CmdTime extends CmdBase // With 2 arguments // /pvputils time [start/stop/reset/set/add/remove] [playername/uuid/all/amount] - else if (args.length == 2 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 2 && cmdsender instanceof EntityPlayer){ if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); // /pvputils time [set/add/remove] [amount] - if (StringUtils.isNumeric(args[1])) - { + if (StringUtils.isNumeric(args[1])){ int a = Integer.parseInt(args[1]) * 60; if (a < 0) throw new WrongUsageException("pvputils.command.positiveNumbers"); p = (EntityPlayerMP) cmdsender; - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils time set [amount] case "set": Time.setTime(p, a); - if (Time.tooMuchAdded) - { + if (Time.tooMuchAdded){ sendChat(cmdsender, max); Logger.logCmd(cmdsender, "Set his/her time to max."); Time.tooMuchAdded = false; } - else if (Time.playerOutOfTime) - { + else if (Time.playerOutOfTime){ Logger.logCmd(cmdsender, "Removed his/her remaining time."); Time.playerOutOfTime = false; } - else - { + else{ sendChat(cmdsender, "Set your time to " + a / 60 + " minutes."); Logger.logCmd(cmdsender, "Set his/her time to " + a / 60 + " minutes."); } @@ -265,14 +242,12 @@ public class CmdTime extends CmdBase case "add": Time.addTime(p, a); - if (!Time.tooMuchAdded) - { + if (!Time.tooMuchAdded){ s = "Added " + a / 60 + " minutes to "; sendChat(cmdsender, s + "yourself."); Logger.logCmd(cmdsender, s + "him-/herself."); } - else - { + else{ sendChat(cmdsender, max); Logger.logCmd(cmdsender, "Tried adding " + a + " minutes him-/herself, reached max."); Time.tooMuchAdded = false; @@ -283,14 +258,12 @@ public class CmdTime extends CmdBase case "remove": Time.removeTime(p, a); - if (!Time.playerOutOfTime) - { + if (!Time.playerOutOfTime){ s = "Removed " + a / 60 + " minutes from "; sendChat(cmdsender, "yourself."); Logger.logCmd(cmdsender, s + "him-/herself."); } - else - { + else{ Logger.logCmd(cmdsender, "Removed his/her remaining time."); Time.playerOutOfTime = false; } @@ -298,10 +271,8 @@ public class CmdTime extends CmdBase } } // /pvputils time [start/stop/reset/add/remove] [playername/uuid/all] - else if (args[1].equalsIgnoreCase("all")) - { - switch (args[0].toLowerCase()) - { + else if (args[1].equalsIgnoreCase("all")){ + switch (args[0].toLowerCase()) { // /pvputils time reset all case "reset": Time.resetAllTime(); @@ -318,8 +289,7 @@ public class CmdTime extends CmdBase s = "Added " + Config.addedTime / 60 + " minutes to everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Time.tooMuchAdded) - { + if (Time.tooMuchAdded){ sendChat(cmdsender, "In the process someone reached the max possible minutes."); Time.tooMuchAdded = false; } @@ -332,8 +302,7 @@ public class CmdTime extends CmdBase s = "Removed " + Config.addedTime / 60 + " minutes from everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Time.playerOutOfTime) - { + if (Time.playerOutOfTime){ sendChat(cmdsender, "In the process someone ran out of time."); Time.playerOutOfTime = false; } @@ -341,15 +310,12 @@ public class CmdTime extends CmdBase } } // / pvputils time [start/stop/reset/add/remove] [playername/uuid] - else - { + else{ // /pvputils time [reset/add/remove] [uuid] - try - { + try{ UUID u = UUID.fromString(args[1]); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils time reset [uuid] case "reset": Time.resetTime(u); @@ -362,14 +328,12 @@ public class CmdTime extends CmdBase case "add": Time.addTime(u, Config.addedTime); - if (!Time.tooMuchAdded) - { + if (!Time.tooMuchAdded){ s = "Added " + Config.addedTime / 60 + " minutes to "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ sendChat(cmdsender, "This guy reached the max possible minutes."); Logger.logCmd(cmdsender, "Tried adding " + Config.addedTime / 60 + " minutes to " + u.toString() + ", reached max."); Time.tooMuchAdded = false; @@ -380,14 +344,12 @@ public class CmdTime extends CmdBase case "remove": Time.removeTime(u, Config.addedTime); - if (!Time.playerOutOfTime) - { + if (!Time.playerOutOfTime){ s = "Removed " + Config.addedTime + " minutes from "; sendChat(cmdsender, s + " this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ s = "Removed remaining time from "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); @@ -396,16 +358,13 @@ public class CmdTime extends CmdBase break; } } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex){ // /pvputils time [start/stop/reset/add/remove] [playername] - try - { + try{ String name = args[1]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils time start [playername] case "start": Time.startTime(p); @@ -437,14 +396,12 @@ public class CmdTime extends CmdBase case "add": Time.addTime(p, Config.addedTime); - if (!Time.tooMuchAdded) - { + if (!Time.tooMuchAdded){ s = "Added " + Config.addedTime / 60 + " minutes to " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, name + " reached the max possible time."); Logger.logCmd(cmdsender, "Tried adding " + Config.addedTime / 60 + " minutes to " + name + ", reached max."); Time.tooMuchAdded = false; @@ -455,14 +412,12 @@ public class CmdTime extends CmdBase case "remove": Time.removeTime(p, Config.addedTime); - if (!Time.playerOutOfTime) - { + if (!Time.playerOutOfTime){ s = "Removed " + Config.addedTime / 60 + " minutes from " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ s = "Removed remaining time from " + name + "."; sendChat(cmdsender, "Removed remaining time from " + name + ". Player kicked!"); Logger.logCmd(cmdsender, s); @@ -472,40 +427,33 @@ public class CmdTime extends CmdBase break; } } - catch (NullPointerException e) - { + catch (NullPointerException e){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } } } - + // With 3 arguments // /pvputils time [set/add/remove] [playername/uuid/all/multiplier] [amount/percentage] - else if (args.length == 3 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 3 && cmdsender instanceof EntityPlayer){ if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); int a = 0; - try - { + try{ a = Integer.parseInt(args[2]); if (a < 0) throw new WrongUsageException("pvputils.command.positiveNumbers"); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex){ throw new SyntaxErrorException("pvputils.command.notFound"); } // /pvputils time set multiplier [percentage] - if (args[1].equalsIgnoreCase("multiplier")) - { - if (args[0].equalsIgnoreCase("set")) - { - if (a < 0) - { + if (args[1].equalsIgnoreCase("multiplier")){ + if (args[0].equalsIgnoreCase("set")){ + if (a < 0){ p = (EntityPlayerMP) cmdsender; float m = (float) a / 100.0f; Time.setTimeMultiplier(p, m); @@ -520,22 +468,18 @@ public class CmdTime extends CmdBase a *= 60; // /pvputils time [set/add/remove] all [amount] - if (args[1].equalsIgnoreCase("all")) - { - switch (args[0].toLowerCase()) - { + if (args[1].equalsIgnoreCase("all")){ + switch (args[0].toLowerCase()) { // /pvputils set all [amount] case "set": - if (Lives.tooManyAdded) - { + if (Lives.tooManyAdded){ Time.setAllTime(a); s = "Set everyone's time to " + a / 60 + "minutes."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, "Everyone has the max possible time."); Logger.logCmd(cmdsender, "Set everyone's time to max."); Time.tooMuchAdded = false; @@ -549,8 +493,7 @@ public class CmdTime extends CmdBase s = "Added " + Config.addedTime / 60 + " minutes to everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Time.tooMuchAdded) - { + if (Time.tooMuchAdded){ sendChat(cmdsender, "In the process someone reached the max possible minutes."); Time.tooMuchAdded = false; } @@ -563,8 +506,7 @@ public class CmdTime extends CmdBase s = "Removed " + a / 60 + " minutes from everyone."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); - if (Time.playerOutOfTime) - { + if (Time.playerOutOfTime){ sendChat(cmdsender, "In the process someone lost his/her last remaining time."); Time.playerOutOfTime = false; } @@ -572,32 +514,26 @@ public class CmdTime extends CmdBase } } // /pvputils time [set/add/remove] [playername/uuid] [amount] - else - { + else{ // /pvputils time [set/add/remove] [uuid] [amount] - try - { + try{ UUID u = UUID.fromString(args[1]); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils time set [uuid] [amount] case "set": Time.setTime(u, a); - if (Time.tooMuchAdded) - { + if (Time.tooMuchAdded){ sendChat(cmdsender, "This guy reached the max possible time."); Logger.logCmd(cmdsender, "Set time of " + u.toString() + " to max."); Time.tooMuchAdded = false; } - else if (Time.playerOutOfTime) - { + else if (Time.playerOutOfTime){ Logger.logCmd(cmdsender, "Removed this guy's remaining time."); Time.playerOutOfTime = false; } - else - { + else{ sendChat(cmdsender, "Set this guy's time to " + a / 60 + " minutes."); Logger.logCmd(cmdsender, "Set time of " + u.toString() + " to " + a / 60 + " minutes."); } @@ -607,14 +543,12 @@ public class CmdTime extends CmdBase case "add": Time.addTime(u, a); - if (!Time.tooMuchAdded) - { + if (!Time.tooMuchAdded){ s = "Added " + a / 60 + " minutes to "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ sendChat(cmdsender, "This guy reached the max possible time."); Logger.logCmd(cmdsender, "Tried adding " + a / 60 + " minutes to " + u.toString() + ", reached max."); Time.tooMuchAdded = false; @@ -625,14 +559,12 @@ public class CmdTime extends CmdBase case "remove": Time.removeTime(u, a); - if (!Time.playerOutOfTime) - { + if (!Time.playerOutOfTime){ s = "Removed " + a / 60 + " minutes from "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); } - else - { + else{ s = "Removed remaining time from "; sendChat(cmdsender, s + "this guy."); Logger.logCmd(cmdsender, s + u.toString() + "."); @@ -640,34 +572,28 @@ public class CmdTime extends CmdBase break; } } - catch (IllegalArgumentException ex) - { - try - { + catch (IllegalArgumentException ex){ + try{ String name = args[1]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); - switch (args[0].toLowerCase()) - { + switch (args[0].toLowerCase()) { // /pvputils time set [playername] [amount] case "set": Time.setTime(p, a); - if (Time.tooMuchAdded) - { + if (Time.tooMuchAdded){ s = "Set " + name + "'s time to " + a / 60 + " minutes."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else if (Time.playerOutOfTime) - { + else if (Time.playerOutOfTime){ s = "Removed remaining time from " + name + ". Player kicked!"; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); Time.playerOutOfTime = false; } - else - { + else{ sendChat(cmdsender, name + " reached the max possible time."); Logger.logCmd(cmdsender, "Set " + name + "'s time to max."); Time.tooMuchAdded = false; @@ -678,14 +604,12 @@ public class CmdTime extends CmdBase case "add": Time.addTime(p, a); - if (!Time.tooMuchAdded) - { + if (!Time.tooMuchAdded){ s = "Added " + a / 60 + " minutes to " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ sendChat(cmdsender, name + " reached the max possible time."); Logger.logCmd(cmdsender, "Tried adding " + a / 60 + " minutes to " + name + ", reached max."); Time.tooMuchAdded = false; @@ -696,14 +620,12 @@ public class CmdTime extends CmdBase case "remove": Time.removeTime(p, a); - if (!Time.playerOutOfTime) - { + if (!Time.playerOutOfTime){ s = "Removed " + a / 60 + " minutes from " + name + "."; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); } - else - { + else{ s = "Removed remaining time from " + name + ". Player kicked!"; sendChat(cmdsender, s); Logger.logCmd(cmdsender, s); @@ -713,8 +635,7 @@ public class CmdTime extends CmdBase break; } } - catch (NullPointerException e) - { + catch (NullPointerException e){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } @@ -722,52 +643,41 @@ public class CmdTime extends CmdBase } // With all 4 arguments // /pvputils time set multiplier [playername/uuid/all] [percentage] - else if (args.length == 4 && cmdsender instanceof EntityPlayer) - { + else if (args.length == 4 && cmdsender instanceof EntityPlayer){ if (!isCmdsAllowed(cmdsender)) throw new CommandException("pvputils.command.noPermission"); - - if (args[1].equalsIgnoreCase("multiplier")) - { - if (args[0].equalsIgnoreCase("set")) - { + + if (args[1].equalsIgnoreCase("multiplier")){ + if (args[0].equalsIgnoreCase("set")){ int a = 1; - try - { + try{ a = Integer.parseInt(args[3]); if (a < 0) throw new WrongUsageException("pvputils.command.positiveNumbers"); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex){ throw new SyntaxErrorException("pvputils.command.notFound"); } float m = (float) a / 100.0f; - + // /pvputils time set multiplier all [percentage] - if(args[2].equalsIgnoreCase("all")) - { + if (args[2].equalsIgnoreCase("all")){ Time.setAllTimeMultipliers(m); } - else - { + else{ // /pvputils time set multiplier [uuid] [percentage] - try - { + try{ UUID u = UUID.fromString(args[2]); Time.setTimeMultiplier(u, m); } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex){ // /pvputils time set multiplier [playername] [percentage] - try - { + try{ String name = args[2]; p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(name); Time.setTimeMultiplier(p, m); } - catch (NullPointerException e) - { + catch (NullPointerException e){ throw new SyntaxErrorException("pvputils.command.realPlayer"); } } diff --git a/src/java/rsge/mods/pvputils/commands/CmdVersion.java b/src/java/rsge/mods/pvputils/commands/CmdVersion.java index a73b60dd325ea865f9dff67cf8822b49c845b3f0..343fe7879bbb27aaa25865a57c8ef5768f1f639b 100644 --- a/src/java/rsge/mods/pvputils/commands/CmdVersion.java +++ b/src/java/rsge/mods/pvputils/commands/CmdVersion.java @@ -9,17 +9,14 @@ import rsge.mods.pvputils.main.Reference; * * @author Rsge */ -public class CmdVersion extends CmdBase -{ - public CmdVersion() - { +public class CmdVersion extends CmdBase { + public CmdVersion() { super("version"); permissionLevel = 0; } @Override - public void handleCommand(ICommandSender cmdsender, String[] s) - { + public void handleCommand(ICommandSender cmdsender, String[] s) { sendChat(cmdsender, "Currently using "/* "pvputils.message.version.1" */ + Reference.VERSION + " of PvP Utilities"/* "pvputils.message.version.2" */); } diff --git a/src/java/rsge/mods/pvputils/commands/ISubCmd.java b/src/java/rsge/mods/pvputils/commands/ISubCmd.java index 7307d35361d02ffc8e5a35946b4c2e4b597900b7..800e9c7920f14f768600765156604ebdd6689ad5 100644 --- a/src/java/rsge/mods/pvputils/commands/ISubCmd.java +++ b/src/java/rsge/mods/pvputils/commands/ISubCmd.java @@ -10,8 +10,7 @@ import net.minecraft.command.ICommandSender; * * @author Rsge */ -public interface ISubCmd -{ +public interface ISubCmd { /** * @return Permission level of command as integer */ diff --git a/src/java/rsge/mods/pvputils/config/Config.java b/src/java/rsge/mods/pvputils/config/Config.java index 3f9ef593201b30adc327cdf0cecbfeca803f7b12..e7f69d5a3283d5299734a37cd39da9127ed5b6bd 100644 --- a/src/java/rsge/mods/pvputils/config/Config.java +++ b/src/java/rsge/mods/pvputils/config/Config.java @@ -11,8 +11,7 @@ import rsge.mods.pvputils.main.Logger; * * @author Rsge */ -public class Config -{ +public class Config { private static final String CAT_MODULES_KEY = "1_Modules"; private static final String CAT_MODULES_COMMENT = "Options to enable and disable parts of the mod."; @@ -183,11 +182,9 @@ public class Config * * @param file Config file */ - public static void init(File file) - { + public static void init(File file) { // If the "config"-Variable is not yet initialized... - if (config == null) - { + if (config == null){ config = new Configuration(file); loadConfig(); if (debugLogging) @@ -199,16 +196,15 @@ public class Config * Load PvPUtils config <br> * Initialize config-related variables */ - private static void loadConfig() - { + private static void loadConfig() { config.load(); /* ————————————————————————————————————————————————————— */ - + // Modules // Variable definitions config.setCategoryComment(CAT_MODULES_KEY, CAT_MODULES_COMMENT); - + cmdlogEnabled = config.get(CAT_MODULES_KEY, CMDLOG_ENABLED_KEY, CMDLOG_ENABLED_DEFAULT, CMDLOG_ENABLED_COMMENT).getBoolean(); macroDisable = config.get(CAT_MODULES_KEY, MACRO_DISABLE_KEY, MACRO_DISABLE_DEFAULT, MACRO_DISABLE_COMMENT).getBoolean(); xpLockEnabled = config.get(CAT_MODULES_KEY, XPLOCK_DISABLE_KEY, XPLOCK_DISABLE_DEFAULT, XPLOCK_DISABLE_COMMENT).getBoolean(); @@ -220,10 +216,9 @@ public class Config // Command Log // Variable definition & error handling config.setCategoryComment(CAT_COMMAND_LOG_KEY, CAT_COMMAND_LOG_COMMENT); - + cmdlogWhere = config.get(CAT_COMMAND_LOG_KEY, CMDLOG_WHERE_KEY, CMDLOG_WHERE_DEFAULT, CMDLOG_WHERE_COMMENT).getInt(); - if (cmdlogWhere < 1 || cmdlogWhere > 3) - { + if (cmdlogWhere < 1 || cmdlogWhere > 3){ Logger.warn("Config Error: \"" + CMDLOG_WHERE_KEY + "\" not in defined area! Read the Comment ; ) - Setting to default value!"); cmdlogWhere = CMDLOG_WHERE_DEFAULT; config.get(CAT_COMMAND_LOG_KEY, CMDLOG_WHERE_KEY, CMDLOG_WHERE_DEFAULT, CMDLOG_WHERE_COMMENT).set(cmdlogWhere); @@ -234,18 +229,16 @@ public class Config // Macros // Variable definition & error handling config.setCategoryComment(CAT_MACROS_KEY, CAT_MACROS_COMMENT); - + macroTreshold = config.get(CAT_MACROS_KEY, MACRO_TRESHOLD_KEY, MACRO_TRESHOLD_DEFAULT, MACRO_TRESHOLD_COMMENT).getInt(); - if (macroTreshold < 1) - { + if (macroTreshold < 1){ Logger.warn("Config Error: '" + MACRO_TRESHOLD_KEY + "' < 1! Setting to last usable number!"); macroTreshold = 1; config.get(CAT_MACROS_KEY, MACRO_TRESHOLD_KEY, MACRO_TRESHOLD_DEFAULT, MACRO_TRESHOLD_COMMENT).set(macroTreshold); } macroKicker = config.get(CAT_MACROS_KEY, MACRO_KICKER_KEY, MACRO_KICKER_DEFAULT, MACRO_KICKER_COMMENT).getBoolean(); - if (!macroDisable && macroKicker) - { + if (!macroDisable && macroKicker){ Logger.warn("Config Error: \"" + MACRO_KICKER_KEY + "\" enabled although \"" + MACRO_DISABLE_KEY + "\" is disabled... Setting \"" + MACRO_KICKER_KEY + "\" to \"false\""); macroKicker = false; @@ -253,8 +246,7 @@ public class Config } macroKickerTreshold = config.get(CAT_MACROS_KEY, MACRO_KICKER_TRESHOLD_KEY, MACRO_KICKER_TRESHOLD_DEFAULT, MACRO_KICKER_TRESHOLD_COMMENT).getInt(); - if (macroKickerTreshold < 1) - { + if (macroKickerTreshold < 1){ Logger.warn("Config Error: '" + MACRO_KICKER_TRESHOLD_KEY + "' < 1! Setting to last usable number!"); macroKickerTreshold = 1; config.get(CAT_MACROS_KEY, MACRO_KICKER_TRESHOLD_KEY, MACRO_KICKER_TRESHOLD_DEFAULT, MACRO_KICKER_TRESHOLD_COMMENT).set(macroKickerTreshold); @@ -274,28 +266,24 @@ public class Config config.setCategoryComment(CAT_LIVES, CAT_LIVES_COMMENT); int baseStartlives = config.get(CAT_LIVES, LIVES_KEY, LIVES_DEFAULT, LIVES_COMMENT).getInt(); - if (baseStartlives < 1) - { + if (baseStartlives < 1){ Logger.warn("Config Error: '" + LIVES_KEY + "' < 1! Settting to last usable number!"); baseStartlives = 1; config.get(CAT_LIVES, LIVES_KEY, LIVES_DEFAULT, LIVES_COMMENT).set(baseStartlives); } int baseMaxlives = config.get(CAT_LIVES, MAXLIVES_KEY, MAXLIVES_DEFAULT, MAXLIVES_COMMENT).getInt(); - if (baseMaxlives < 1) - { + if (baseMaxlives < 1){ Logger.warn("Config Error: '" + MAXLIVES_KEY + "' < 1! Setting to last usable number!"); baseMaxlives = 1; config.get(CAT_LIVES, MAXLIVES_KEY, MAXLIVES_DEFAULT, MAXLIVES_COMMENT).set(baseMaxlives); } - else if (baseMaxlives > 255) - { + else if (baseMaxlives > 255){ Logger.warn("Config Error: '" + MAXLIVES_KEY + "' > 255! Setting to last usable number!"); baseMaxlives = 255; config.get(CAT_LIVES, MAXLIVES_KEY, MAXLIVES_DEFAULT, MAXLIVES_COMMENT).set(baseMaxlives); } - if (baseMaxlives < baseStartlives) - { + if (baseMaxlives < baseStartlives){ Logger.warn("Config Error: '" + MAXLIVES_KEY + "' < '" + LIVES_KEY + "'! Setting '" + MAXLIVES_KEY + "' equal to '" + LIVES_KEY + "'!"); baseMaxlives = baseStartlives; config.get(CAT_LIVES, MAXLIVES_KEY, MAXLIVES_DEFAULT, MAXLIVES_COMMENT).set(baseMaxlives); @@ -304,8 +292,7 @@ public class Config maxLives = (byte) baseMaxlives; livesTakenBy = config.get(CAT_LIVES, LIVES_TAKEN_KEY, LIVES_TAKEN_DEFAULT, LIVES_TAKEN_COMMENT).getInt(); - if (livesTakenBy < 1 || livesTakenBy > 3) - { + if (livesTakenBy < 1 || livesTakenBy > 3){ Logger.warn("Config Error: '" + LIVES_TAKEN_KEY + "' not in defined area! Read the Comment ; ) Setting to default value!"); livesTakenBy = LIVES_TAKEN_DEFAULT; config.get(CAT_LIVES, LIVES_TAKEN_KEY, LIVES_TAKEN_DEFAULT, LIVES_TAKEN_COMMENT).set(livesTakenBy); @@ -315,8 +302,7 @@ public class Config scoreboardEnabled = config.get(CAT_LIVES, SCOREBOARD_ENABLED_KEY, SCOREBOARD_ENABLED_DEFAULT, SCOREBOARD_ENABLED_COMMENT).getBoolean(); scoreboardType = config.get(CAT_LIVES, SCOREBOARD_TYPE_KEY, SCOREBOARD_TYPE_DEFAULT, SCOREBOARD_TYPE_COMMENT).getInt(); - if (scoreboardType < 1 || scoreboardType > 3) - { + if (scoreboardType < 1 || scoreboardType > 3){ Logger.warn("Config Error: '" + SCOREBOARD_TYPE_KEY + "' not in defined area! Read the Comment ; ) Setting to default value!"); scoreboardType = SCOREBOARD_TYPE_DEFAULT; config.get(CAT_LIVES, SCOREBOARD_TYPE_KEY, SCOREBOARD_TYPE_DEFAULT, SCOREBOARD_TYPE_COMMENT).set(scoreboardType); @@ -330,38 +316,33 @@ public class Config config.setCategoryComment(CAT_TIME, CAT_TIME_COMMENT); addedTime = config.get(CAT_TIME, ADD_TIME_KEY, ADD_TIME_DEFAULT, ADD_TIME_COMMENT).getInt() * 60; - if (addedTime < 0) - { + if (addedTime < 0){ Logger.warn("Config Error: '" + ADD_TIME_KEY + "' < 0! Setting to last usable number!"); addedTime = 0; config.get(CAT_TIME, ADD_TIME_KEY, ADD_TIME_DEFAULT, ADD_TIME_COMMENT).set(addedTime); } startTime = config.get(CAT_TIME, START_TIME_KEY, START_TIME_DEFAULT, START_TIME_COMMENT).getInt() * 60; - if (startTime < 1) - { + if (startTime < 1){ Logger.warn("Config Error: '" + START_TIME_KEY + "' < 1! Setting to last usable number!"); startTime = 1; config.get(CAT_TIME, START_TIME_KEY, START_TIME_DEFAULT, START_TIME_COMMENT).set(startTime); } maxTime = config.get(CAT_TIME, MAXTIME_KEY, MAXTIME_DEFAULT, MAXTIME_COMMENT).getInt() * 60; - if (maxTime < 1) - { + if (maxTime < 1){ Logger.warn("Config Error: '" + MAXTIME_KEY + "' < 1! Setting to last usable number!"); maxTime = 1; config.get(CAT_TIME, MAXTIME_KEY, MAXTIME_DEFAULT, MAXTIME_COMMENT).set(maxTime); } - if (maxTime < addedTime) - { + if (maxTime < addedTime){ Logger.warn("Config Error: '" + MAXTIME_KEY + "' < '" + ADD_TIME_KEY + "'! Setting '" + MAXTIME_KEY + "' equal to '" + ADD_TIME_KEY + "'!"); maxTime = addedTime; config.get(CAT_TIME, MAXTIME_KEY, MAXTIME_DEFAULT, MAXTIME_COMMENT).set(maxTime); } - if (maxTime < startTime) - { + if (maxTime < startTime){ Logger.warn("Config Error: '" + MAXTIME_KEY + "' < '" + START_TIME_KEY + "'! Setting '" + MAXTIME_KEY + "' equal to '" + START_TIME_KEY + "'!"); maxTime = startTime; config.get(CAT_TIME, MAXTIME_KEY, MAXTIME_DEFAULT, MAXTIME_COMMENT).set(maxTime); @@ -376,11 +357,11 @@ public class Config // Debug // Variable definition config.setCategoryComment(CAT_DEBUG_KEY, CAT_DEBUG_COMMENT); - + debugLogging = config.get(CAT_DEBUG_KEY, DEBUG_LOGGING_KEY, DEBUG_LOGGING_DEFAULT).getBoolean(); excessiveLogging = config.get(CAT_DEBUG_KEY, EXCESSIVE_LOGGING_KEY, EXCESSIVE_LOGGING_DEFAULT, EXCESSIVE_LOGGING_COMMENT).getBoolean(); - constantExcessiveLogging = config.get(CAT_DEBUG_KEY, CONSTANT_EXCESSIVE_LOGGING_KEY, CONSTANT_EXCESSIVE_LOGGING_DEFAULT, CONSTANT_EXCESSIVE_LOGGING_COMMENT) - .getBoolean(); + constantExcessiveLogging = config + .get(CAT_DEBUG_KEY, CONSTANT_EXCESSIVE_LOGGING_KEY, CONSTANT_EXCESSIVE_LOGGING_DEFAULT, CONSTANT_EXCESSIVE_LOGGING_COMMENT).getBoolean(); /* ————————————————————————————————————————————————————— */ diff --git a/src/java/rsge/mods/pvputils/data/Lives.java b/src/java/rsge/mods/pvputils/data/Lives.java index 5295226b04a3c63de4e85d2990362155a376ccc9..6b8fbc5fd78871a2feb3d5c57ea2c8b9a91fee8b 100644 --- a/src/java/rsge/mods/pvputils/data/Lives.java +++ b/src/java/rsge/mods/pvputils/data/Lives.java @@ -37,8 +37,7 @@ import rsge.mods.pvputils.main.Reference; * * @author Rsge */ -public class Lives -{ +public class Lives { public static boolean tooManyAdded; public static boolean playerBanned; public static boolean worldDelete; @@ -51,28 +50,23 @@ public class Lives * * @throws IOException */ - public static void init() throws IOException - { + public static void init() throws IOException { Reference.lifeData = new File(Reference.dataDir, "lives.dat"); - if (!Reference.lifeData.exists()) - { + if (!Reference.lifeData.exists()){ // Create the life-data and exit Reference.lifeData.createNewFile(); Logger.info("lives.dat created"); return; } - try (BufferedReader br = Files.newBufferedReader(Reference.lifeData.toPath());) - { + try (BufferedReader br = Files.newBufferedReader(Reference.lifeData.toPath());){ int entries = Integer.parseInt(br.readLine()); - for (int i = 0; i < entries; i++) - { + for (int i = 0; i < entries; i++){ String uuid = br.readLine(); UUID u = null; String lives = br.readLine(); byte l; - try - { + try{ u = UUID.fromString(uuid); l = Byte.parseByte(lives); @@ -81,16 +75,14 @@ public class Lives if (Config.debugLogging) Logger.info(u + " has " + lives + " lives left"); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex){ l = Config.startLives; String clog = "ERROR Trying to get " + uuid + "'s lives (Found " + lives + "). Resetting to starting lives."; String flog = "[Found " + lives + " instead of number. Reset to default.]"; logError(uuid, clog, flog); } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex){ String clog = "ERROR: " + uuid + " is not a valid UUID. It had " + lives + " associated with it. Deleting now!"; String flog = "[Not a valid UUID. It had " + lives + " associated with it. Deleted entry.]"; logError(uuid, clog, flog); @@ -98,8 +90,7 @@ public class Lives } br.close(); } - catch (NullPointerException ex) - { + catch (NullPointerException ex){ if (Config.debugLogging) Logger.info("lives.dat-File empty! This is not an Error!"); } @@ -112,19 +103,16 @@ public class Lives * @param clog Console log string * @param flog File log string */ - private static void logError(String uuid, String clog, String flog) - { + private static void logError(String uuid, String clog, String flog) { // Log to console Logger.error(clog); // Log to Cmdlog-File - try (BufferedWriter bw = Files.newBufferedWriter(Reference.loggedCmds.toPath(), StandardOpenOption.APPEND)) - { + try (BufferedWriter bw = Files.newBufferedWriter(Reference.loggedCmds.toPath(), StandardOpenOption.APPEND)){ DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.UK); flog = "[" + LocalDateTime.now().format(dtf) + "] [" + uuid + "] " + flog + "\n"; bw.write(flog); } - catch (Exception exc) - { + catch (Exception exc){ Logger.error("ERROR Trying to log this reset"); } } @@ -134,19 +122,15 @@ public class Lives /** * Save data and clear for new init */ - public static boolean stop() - { - try - { + public static boolean stop() { + try{ save(); } - catch (IOException ex) - { + catch (IOException ex){ Logger.error("Lives saving failed: " + ex.getLocalizedMessage()); return false; } - finally - { + finally{ playerLives.clear(); } return true; @@ -157,14 +141,12 @@ public class Lives * * @throws IOException */ - public static void save() throws IOException - { + public static void save() throws IOException { BufferedWriter bw = Files.newBufferedWriter(Reference.lifeData.toPath()); bw.write(Integer.toString(playerLives.size())); bw.newLine(); - for (Entry<UUID, Byte> entry : playerLives.entrySet()) - { + for (Entry<UUID, Byte> entry : playerLives.entrySet()){ String uuid = entry.getKey().toString(); String lives = Byte.toString(entry.getValue()); @@ -185,11 +167,9 @@ public class Lives * * @param p Player */ - public static void initPlayer(EntityPlayerMP p) - { + public static void initPlayer(EntityPlayerMP p) { UUID u = p.getGameProfile().getId(); - if (!playerLives.containsKey(u)) - { + if (!playerLives.containsKey(u)){ playerLives.put(u, Config.startLives); Logger.info("Initialized Player " + u.toString() + " with " + Config.startLives + " lives"); } @@ -203,8 +183,7 @@ public class Lives * * @param p Player */ - public static void chatLives(EntityPlayer p) - { + public static void chatLives(EntityPlayer p) { chatLivesTo(p, p); } @@ -214,8 +193,7 @@ public class Lives * @param p Player who's lives to look at * @param rec Player who sent command and receives info */ - public static void chatLivesTo(EntityPlayer p, EntityPlayer rec) - { + public static void chatLivesTo(EntityPlayer p, EntityPlayer rec) { UUID u = p.getGameProfile().getId(); byte l = getLives(u); IChatComponent msgStart; @@ -251,8 +229,7 @@ public class Lives * @param l Amount of lives as byte * @return Chat-component of lives in appropriate color */ - public static IChatComponent formatLives(byte l) - { + public static IChatComponent formatLives(byte l) { double compare = (double) l / (double) Config.maxLives; IChatComponent msgLives = new ChatComponentText(Long.toString(l)); // Show the number of lives in different colors depending on their ratio to the max lives @@ -281,21 +258,17 @@ public class Lives * @param p EntityPlayerMP of player * @param src Damage source that killed player */ - public static void death(EntityPlayerMP p, DamageSource src) - { + public static void death(EntityPlayerMP p, DamageSource src) { boolean wasPlayer = src.getDamageType().equals("player") || src.getEntity() instanceof EntityPlayer; boolean wasMonster = src.getDamageType().equals("mob") || src.getEntity() instanceof EntityLiving; - if (Config.livesTakenBy == 1 && wasPlayer) - { + if (Config.livesTakenBy == 1 && wasPlayer){ removeLives(p, 1); } - else if (Config.livesTakenBy == 2 && (wasMonster || wasPlayer)) - { + else if (Config.livesTakenBy == 2 && (wasMonster || wasPlayer)){ removeLives(p, 1); } - else if (Config.livesTakenBy == 3) - { + else if (Config.livesTakenBy == 3){ removeLives(p, 1); } } @@ -307,10 +280,8 @@ public class Lives * * @param l Amount of lives */ - public static void addLivesToAll(int l) - { - for (UUID u : playerLives.keySet()) - { + public static void addLivesToAll(int l) { + for (UUID u : playerLives.keySet()){ addLives(u, l); } } @@ -321,8 +292,7 @@ public class Lives * @param p EntityPlayerMP of player * @param l Amount of lives */ - public static void addLives(EntityPlayerMP p, int l) - { + public static void addLives(EntityPlayerMP p, int l) { UUID u = p.getGameProfile().getId(); addLives(u, l); } @@ -333,8 +303,7 @@ public class Lives * @param u UUID of player * @param l Amount of lives */ - public static void addLives(UUID u, int l) - { + public static void addLives(UUID u, int l) { byte lives = getLives(u); setLives(u, lives + l); } @@ -346,10 +315,8 @@ public class Lives * * @param l Amount of lives */ - public static void removeLivesFromAll(int l) - { - for (UUID u : playerLives.keySet()) - { + public static void removeLivesFromAll(int l) { + for (UUID u : playerLives.keySet()){ removeLives(u, l); } } @@ -360,8 +327,7 @@ public class Lives * @param p EntityPlayerMP of player * @param l Amount of lives */ - public static void removeLives(EntityPlayerMP p, int l) - { + public static void removeLives(EntityPlayerMP p, int l) { UUID u = p.getGameProfile().getId(); byte lives = getLives(u); setLives(p, lives - l); @@ -373,8 +339,7 @@ public class Lives * @param u UUID of player * @param l Amount of lives */ - public static void removeLives(UUID u, int l) - { + public static void removeLives(UUID u, int l) { byte lives = getLives(u); setLives(u, lives - l); } @@ -384,8 +349,7 @@ public class Lives /** * Reset lives of all players to starting value */ - public static void resetAllLives() - { + public static void resetAllLives() { setAllLives(Config.startLives); } @@ -394,8 +358,7 @@ public class Lives * * @param p EntityPlayerMP of player */ - public static void resetLives(EntityPlayerMP p) - { + public static void resetLives(EntityPlayerMP p) { setLives(p, Config.startLives); } @@ -404,11 +367,10 @@ public class Lives * * @param u UUID of player */ - public static void resetLives(UUID u) - { + public static void resetLives(UUID u) { setLives(u, Config.startLives); } - + /* ————————————————————————————————————————————————————— */ /** @@ -416,10 +378,8 @@ public class Lives * * @param l Amount of lives */ - public static void setAllLives(int l) - { - for (UUID u : playerLives.keySet()) - { + public static void setAllLives(int l) { + for (UUID u : playerLives.keySet()){ setLives(u, l); } } @@ -430,20 +390,17 @@ public class Lives * @param p EntityPlayerMP of player * @param l Amount of lives */ - public static void setLives(EntityPlayerMP p, int l) - { + public static void setLives(EntityPlayerMP p, int l) { UUID u = p.getGameProfile().getId(); - if (l > 0) - { + if (l > 0){ setLives(u, l); } - else - { + else{ playerLives.replace(u, (byte) 0); outOfLives(p); playerBanned = true; } - + if (Config.scoreboardEnabled) ScoreBoard.updatePlayer(p); } @@ -454,17 +411,14 @@ public class Lives * @param u UUID of player * @param l Amount of lives */ - public static void setLives(UUID u, int l) - { + public static void setLives(UUID u, int l) { if (l <= Config.maxLives && l > 0) playerLives.replace(u, (byte) l); - else if (l > Config.maxLives) - { + else if (l > Config.maxLives){ playerLives.replace(u, Config.maxLives); Lives.tooManyAdded = true; } - else - { + else{ playerLives.replace(u, (byte) 0); outOfLives(u); playerBanned = true; @@ -477,8 +431,7 @@ public class Lives * @param u of player * @return lives of player with UUID */ - public static byte getLives(UUID u) - { + public static byte getLives(UUID u) { return playerLives.get(u); } @@ -489,8 +442,7 @@ public class Lives * * @param p UUID of player */ - private static void outOfLives(UUID u) - { + private static void outOfLives(UUID u) { GameProfile g = new GameProfile(u, null); MinecraftServer mcs = MinecraftServer.getServer(); EntityPlayerMP p = mcs.getConfigurationManager().createPlayerForUser(g); @@ -502,8 +454,7 @@ public class Lives * * @param p EntityPlayerMP of player */ - private static void outOfLives(EntityPlayerMP p) - { + private static void outOfLives(EntityPlayerMP p) { // HQM had some problems with TConstruct, so I'll clear the player's inventory to prevent them, too O:) p.inventory.clearInventory(null, -1); @@ -511,14 +462,12 @@ public class Lives String deathMessage = "You're out of Lives! Sorry, the battle is over for you :("; String banReason = "Out of lives in battle"; - if (mcs.isSinglePlayer() && p.getCommandSenderName().equals(mcs.getServerOwner())) - { + if (mcs.isSinglePlayer() && p.getCommandSenderName().equals(mcs.getServerOwner())){ worldDelete = true; ((EntityPlayerMP) p).playerNetServerHandler.kickPlayerFromServer(deathMessage); mcs.deleteWorldAndStopServer(); } - else - { + else{ UserListBansEntry banEntry = new UserListBansEntry(p.getGameProfile(), (Date) null, Reference.NAME, (Date) null, banReason); mcs.getConfigurationManager().func_152608_h().func_152687_a(banEntry); p.playerNetServerHandler.kickPlayerFromServer(deathMessage); diff --git a/src/java/rsge/mods/pvputils/data/ScoreBoard.java b/src/java/rsge/mods/pvputils/data/ScoreBoard.java index 20bcc42c8bf644aebb0dff77c55d8b9a6f792192..04566b5b1ac8f546f4baba3c33e201023997339e 100644 --- a/src/java/rsge/mods/pvputils/data/ScoreBoard.java +++ b/src/java/rsge/mods/pvputils/data/ScoreBoard.java @@ -14,19 +14,16 @@ import rsge.mods.pvputils.main.Logger; * * @author Rsge */ -public class ScoreBoard -{ +public class ScoreBoard { public static Scoreboard sb; /** * Initializing scoreboard for lives */ - public static void init() - { + public static void init() { sb = MinecraftServer.getServer().worldServerForDimension(0).getScoreboard(); - if (sb.getObjective("Lives") != null && sb.getObjective("Lives").getCriteria() != IScoreObjectiveCriteria.field_96641_b) - { + if (sb.getObjective("Lives") != null && sb.getObjective("Lives").getCriteria() != IScoreObjectiveCriteria.field_96641_b){ sb.func_96519_k(sb.getObjective("Lives")); sb.addScoreObjective("Lives", IScoreObjectiveCriteria.field_96641_b); } @@ -44,8 +41,7 @@ public class ScoreBoard * * @param p Player */ - public static void updatePlayer(EntityPlayer p) - { + public static void updatePlayer(EntityPlayer p) { Score s = sb.func_96529_a(p.getCommandSenderName(), sb.getObjective("Lives")); s.setScorePoints(Lives.getLives(p.getGameProfile().getId())); } diff --git a/src/java/rsge/mods/pvputils/data/Time.java b/src/java/rsge/mods/pvputils/data/Time.java index 55a9a64a04fe8ab53c285463fd52c76afcccf8db..b714d25ab96401d84997ff1ec108cf11c9fcdd18 100644 --- a/src/java/rsge/mods/pvputils/data/Time.java +++ b/src/java/rsge/mods/pvputils/data/Time.java @@ -36,8 +36,7 @@ import rsge.mods.pvputils.main.Reference; * * @author Rsge */ -public class Time -{ +public class Time { public static boolean tooMuchAdded; public static boolean playerOutOfTime; private static HashMap<UUID, Long> playerTimes = new HashMap<UUID, Long>(); @@ -55,16 +54,14 @@ public class Time * * @throws IOException */ - public static void init() throws IOException - { + public static void init() throws IOException { // Finding the spawn point spawn = DimensionManager.getWorld(0).getSpawnPoint(); Logger.info("Spawnpoint at " + spawn.posX + ", " + spawn.posY + ", " + spawn.posZ); // Creating needed file or ... Reference.timeData = new File(Reference.dataDir, "times.dat"); - if (!Reference.timeData.exists()) - { + if (!Reference.timeData.exists()){ Reference.timeData.createNewFile(); Logger.info("times.dat created"); @@ -73,13 +70,11 @@ public class Time } // ... reading out the file - try (BufferedReader br = Files.newBufferedReader(Reference.timeData.toPath());) - { + try (BufferedReader br = Files.newBufferedReader(Reference.timeData.toPath());){ lastDate = LocalDate.parse(br.readLine()); int entries = Integer.parseInt(br.readLine()); - for (int i = 0; i < entries; i++) - { + for (int i = 0; i < entries; i++){ String uuid = br.readLine(); UUID u = null; String time = br.readLine(); @@ -87,39 +82,33 @@ public class Time String mult = br.readLine(); float m = 0.0f; - try - { + try{ u = UUID.fromString(uuid); t = Long.parseLong(time); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex){ t = Config.startTime; String clog = "ERROR Trying to get " + uuid + "'s time (Found " + time + "). Resetting to default time"; String flog = "[Found " + time + " instead of number. Reset to default.]"; logError(uuid, clog, flog); } - catch (IllegalArgumentException ex) - { + catch (IllegalArgumentException ex){ String clog = "ERROR: " + uuid + " is not a valid UUID. It had " + time + " associated with it. Deleting now!"; String flog = "[Not a valid UUID. It had " + time + " associated with it. Deleted entry.]"; logError(uuid, clog, flog); } - try - { + try{ m = Float.parseFloat(mult); - if (m < 0.0f || m > 50.0f) - { + if (m < 0.0f || m > 50.0f){ m = 1.0f; throw new NumberFormatException(); } if (m > 10.0f) Logger.warn("Time-multiplier for " + uuid + " is very high (" + mult + ") - possible error?"); } - catch (NumberFormatException ex) - { + catch (NumberFormatException ex){ m = 1.0f; String clog = "ERROR Trying to process multiplier. Resetting to default."; String flog = "[Multiplier reset to default because of error]"; @@ -138,8 +127,7 @@ public class Time } br.close(); } - catch (NullPointerException ex) - { + catch (NullPointerException ex){ lastDate = LocalDate.now(); if (Config.debugLogging) @@ -154,21 +142,18 @@ public class Time * @param clog Console log string * @param flog File log string */ - private static void logError(String uuid, String clog, String flog) - { + private static void logError(String uuid, String clog, String flog) { // Log to Console Logger.error(clog); // Log to Cmdlog-File - try (BufferedWriter bw = Files.newBufferedWriter(Reference.loggedCmds.toPath(), StandardOpenOption.APPEND)) - { + try (BufferedWriter bw = Files.newBufferedWriter(Reference.loggedCmds.toPath(), StandardOpenOption.APPEND)){ DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.UK); String log = "[" + LocalDateTime.now().format(dtf) + "] [" + uuid + "] " + flog + "\n"; bw.write(log); } - catch (Exception exc) - { + catch (Exception exc){ Logger.error("ERROR Trying to log this reset"); } } @@ -178,19 +163,15 @@ public class Time /** * Save data and clear for new init */ - public static boolean stop() - { - try - { + public static boolean stop() { + try{ save(); } - catch (IOException ex) - { + catch (IOException ex){ Logger.error("Time saving failed: " + ex.getLocalizedMessage()); return false; } - finally - { + finally{ playerTimes.clear(); playerTimeMultiplier.clear(); } @@ -202,16 +183,14 @@ public class Time * * @throws IOException */ - public static void save() throws IOException - { + public static void save() throws IOException { BufferedWriter bw = Files.newBufferedWriter(Reference.timeData.toPath()); bw.write(LocalDate.now().toString()); bw.newLine(); bw.write(Integer.toString(playerTimes.size())); bw.newLine(); - for (Entry<UUID, Long> entry : playerTimes.entrySet()) - { + for (Entry<UUID, Long> entry : playerTimes.entrySet()){ UUID u = entry.getKey(); Long t = entry.getValue(); Float m = playerTimeMultiplier.get(u); @@ -238,13 +217,11 @@ public class Time * * @param p Player to initialize */ - public static void initPlayer(EntityPlayerMP p) - { + public static void initPlayer(EntityPlayerMP p) { UUID u = p.getGameProfile().getId(); float m = 1.0f; - if (!playerTimes.containsKey(u)) - { + if (!playerTimes.containsKey(u)){ long time = Config.startTime; playerTimes.put(u, time); Logger.info("Initialized Player " + u.toString() + " with " + Config.startTime / 60 + " minutes and " + m + " time-get-modifier"); @@ -262,8 +239,7 @@ public class Time * * @param p Player */ - public static void startTime(EntityPlayerMP p) - { + public static void startTime(EntityPlayerMP p) { UUID u = p.getGameProfile().getId(); if (!MinecraftServer.getServer().isSinglePlayer() && playerTimes.get(u) == 0) @@ -277,8 +253,7 @@ public class Time * * @param p Player */ - public static void stopTime(EntityPlayerMP p) - { + public static void stopTime(EntityPlayerMP p) { UUID u = p.getGameProfile().getId(); playerOnline.put(u, false); @@ -289,18 +264,15 @@ public class Time /** * Manage time per second */ - public static void second() - { + public static void second() { // For each player... - for (Entry<UUID, Long> entry : playerTimes.entrySet()) - { + for (Entry<UUID, Long> entry : playerTimes.entrySet()){ UUID u = entry.getKey(); long t = entry.getValue(); boolean on = playerOnline.get(u); // ... if player is online - if (on) - { + if (on){ // Get the player entity from the player's UUID // This is probably a lot more efficient than the old version... GameProfile g = new GameProfile(u, null); @@ -308,19 +280,15 @@ public class Time EntityPlayerMP p = mcs.getConfigurationManager().createPlayerForUser(g); // Stop time if player is in spawn area - if (Config.stopInSpawn) - { + if (Config.stopInSpawn){ // Squared distance makes all this much easier and the radius a circle double d = Math.sqrt(p.getPlayerCoordinates().getDistanceSquared(spawn.posX, spawn.posY, spawn.posZ)); if (Config.constantExcessiveLogging) Logger.info("Distance to spawn of " + u.toString() + ": " + d + " blocks"); - if (d > Config.stopInSpawnRadius) - { - try - { - if (!playerInSpawn.get(u)) - { + if (d > Config.stopInSpawnRadius){ + try{ + if (!playerInSpawn.get(u)){ playerInSpawn.put(u, true); p.addChatMessage(new ChatComponentText("You left the spawnzone, your time started again.") .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW))); @@ -331,17 +299,13 @@ public class Time if (Config.constantExcessiveLogging) Logger.info(u.toString() + "'s second passed"); } - catch (NullPointerException ex) - { + catch (NullPointerException ex){ playerInSpawn.put(u, false); } } - else - { - try - { - if (playerInSpawn.get(u)) - { + else{ + try{ + if (playerInSpawn.get(u)){ playerInSpawn.put(u, false); p.addChatMessage(new ChatComponentText("You entered the spawnzone, your time stopped.") .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW))); @@ -350,8 +314,7 @@ public class Time if (Config.constantExcessiveLogging) Logger.info(u.toString() + "'s second didn't pass"); } - catch (NullPointerException ex) - {} + catch (NullPointerException ex){} } } else @@ -368,14 +331,11 @@ public class Time * @param p EntityPlayer of player * @param t Time in seconds */ - private static void passTime(UUID u, EntityPlayer p, long t) - { + private static void passTime(UUID u, EntityPlayer p, long t) { // Remind the player of his remaining time - if (t == 1800 || t == 600 || t == 60 || t == 10 || t <= 5) - { + if (t == 1800 || t == 600 || t == 60 || t == 10 || t <= 5){ // If player has no time left - if (t <= 0) - { + if (t <= 0){ t = 0; outOfTime((EntityPlayerMP) p); return; @@ -394,8 +354,7 @@ public class Time * * @param p Player */ - public static void chatTime(EntityPlayer p) - { + public static void chatTime(EntityPlayer p) { chatTimeTo(p, p); } @@ -405,8 +364,7 @@ public class Time * @param p Player who's time to look at * @param rec Player who sent command and receives info */ - public static void chatTimeTo(EntityPlayer p, EntityPlayer rec) - { + public static void chatTimeTo(EntityPlayer p, EntityPlayer rec) { UUID u = p.getGameProfile().getId(); long t = Time.getTime(u); IChatComponent msgStart; @@ -433,8 +391,7 @@ public class Time rec.addChatMessage(msgFinal); } - public static IChatComponent formatTime(long t) - { + public static IChatComponent formatTime(long t) { IChatComponent msgHour; IChatComponent msgMin; IChatComponent msgSec; @@ -446,15 +403,13 @@ public class Time double compare = (double) t / (double) (Config.addedTime); // Use correct Grammar - if (t % 3600 == 0) - { + if (t % 3600 == 0){ if (h == 1) msgHour = new ChatComponentText(h + " hour "); else msgHour = new ChatComponentText(h + " hours "); } - else if (t % 60 == 0 && h > 0) - { + else if (t % 60 == 0 && h > 0){ if (h == 1) msgHour = new ChatComponentText(h + " hour and "); else @@ -514,10 +469,8 @@ public class Time * * @param t Amount of time in seconds */ - public static void addTimeToAll(long t) - { - for (UUID u : playerTimes.keySet()) - { + public static void addTimeToAll(long t) { + for (UUID u : playerTimes.keySet()){ addTime(u, t); } } @@ -528,8 +481,7 @@ public class Time * @param p EntityPlayerMP of player * @param t Amount of time in seconds */ - public static void addTime(EntityPlayerMP p, long t) - { + public static void addTime(EntityPlayerMP p, long t) { UUID u = p.getGameProfile().getId(); addTime(u, t); } @@ -540,8 +492,7 @@ public class Time * @param u UUID of player * @param t Amount of time in seconds */ - public static void addTime(UUID u, long t) - { + public static void addTime(UUID u, long t) { long time = getTime(u); setTime(u, time + t); } @@ -553,10 +504,8 @@ public class Time * * @param t Amount of time in seconds */ - public static void removeTimeFromAll(long t) - { - for (UUID u : playerTimes.keySet()) - { + public static void removeTimeFromAll(long t) { + for (UUID u : playerTimes.keySet()){ removeTime(u, t); } } @@ -567,8 +516,7 @@ public class Time * @param p EntityPlayerMP of player * @param t Amount of time in seconds */ - public static void removeTime(EntityPlayerMP p, long t) - { + public static void removeTime(EntityPlayerMP p, long t) { UUID u = p.getGameProfile().getId(); long time = getTime(u); setTime(p, time - t); @@ -580,8 +528,7 @@ public class Time * @param u UUID of player * @param t Amount of time in seconds */ - public static void removeTime(UUID u, long t) - { + public static void removeTime(UUID u, long t) { long time = getTime(u); setTime(u, time - t); } @@ -591,8 +538,7 @@ public class Time /** * Reset time of all players to starting value */ - public static void resetAllTime() - { + public static void resetAllTime() { setAllTime(Config.startTime); } @@ -601,18 +547,16 @@ public class Time * * @param p EntityPlayerMP of player */ - public static void resetTime(EntityPlayerMP p) - { + public static void resetTime(EntityPlayerMP p) { setTime(p, Config.startTime); } - + /** * Reset time of player with UUID to starting value * * @param u UUID of player */ - public static void resetTime(UUID u) - { + public static void resetTime(UUID u) { setTime(u, Config.startTime); } @@ -623,10 +567,8 @@ public class Time * * @param t Amount of time in seconds */ - public static void setAllTime(long t) - { - for (UUID u : playerTimes.keySet()) - { + public static void setAllTime(long t) { + for (UUID u : playerTimes.keySet()){ setTime(u, t); } } @@ -637,15 +579,12 @@ public class Time * @param p EntityPlayerMP of player * @param t Amount of time in seconds */ - public static void setTime(EntityPlayerMP p, long t) - { + public static void setTime(EntityPlayerMP p, long t) { UUID u = p.getGameProfile().getId(); - if (t > 0) - { + if (t > 0){ setTime(u, t); } - else - { + else{ playerTimes.replace(u, (long) 0); outOfTime(p); playerOutOfTime = true; @@ -658,57 +597,50 @@ public class Time * @param u UUID of player * @param t Amount of time in seconds */ - public static void setTime(UUID u, long t) - { + public static void setTime(UUID u, long t) { if (t <= Config.maxTime && t > 0) playerTimes.replace(u, t); - else if (t > Config.maxTime) - { + else if (t > Config.maxTime){ playerTimes.replace(u, Config.maxTime); Time.tooMuchAdded = true; } - else - { + else{ playerTimes.replace(u, (long) 0); playerOutOfTime = true; } } - + /* ————————————————————————————————————————————————————— */ - + /** * Set time multiplier of all players to given value * * @param m Multiplier as float */ - public static void setAllTimeMultipliers(Float m) - { - for (UUID u : playerTimeMultiplier.keySet()) - { + public static void setAllTimeMultipliers(Float m) { + for (UUID u : playerTimeMultiplier.keySet()){ setTimeMultiplier(u, m); } } - + /** * Set time multiplier of player to given value * * @param p EntityPlayerMP of player * @param m Multiplier as float */ - public static void setTimeMultiplier(EntityPlayerMP p, Float m) - { + public static void setTimeMultiplier(EntityPlayerMP p, Float m) { UUID u = p.getGameProfile().getId(); setTimeMultiplier(u, m); } - + /** * Set time multiplier of player with UUID to given value * * @param u UUID of player * @param m Multiplier as float */ - public static void setTimeMultiplier(UUID u, Float m) - { + public static void setTimeMultiplier(UUID u, Float m) { playerTimeMultiplier.replace(u, m); } @@ -720,8 +652,7 @@ public class Time * @param UUID of player * @return Amount of time of player with UUID in seconds */ - public static long getTime(UUID u) - { + public static long getTime(UUID u) { return (long) playerTimes.get(u); } @@ -734,10 +665,8 @@ public class Time * @param uuid UUID of player * @return true, if time was added due to a new day; false else */ - private static boolean newDay(UUID u, long t) - { - if (Config.addedTime != 0 && !lastDate.equals(LocalDate.now()) && t < Config.maxTime) - { + private static boolean newDay(UUID u, long t) { + if (Config.addedTime != 0 && !lastDate.equals(LocalDate.now()) && t < Config.maxTime){ float m = playerTimeMultiplier.get(u); long addedTime = (long) (Config.addedTime * m); if (t + addedTime > Config.maxTime) @@ -759,8 +688,7 @@ public class Time * * @param p EntityPlayerMP of player */ - private static void outOfTime(EntityPlayerMP p) - { + private static void outOfTime(EntityPlayerMP p) { String msg = "You're out of Time! Log in again tomorrow."; p.playerNetServerHandler.kickPlayerFromServer(msg); diff --git a/src/java/rsge/mods/pvputils/listeners/CommandEventListener.java b/src/java/rsge/mods/pvputils/listeners/CommandEventListener.java index 0dc01ccb07a4c2732d508639d16664673bc45773..e89219d0e5997e6bdf1363a1998335d489c5f75d 100644 --- a/src/java/rsge/mods/pvputils/listeners/CommandEventListener.java +++ b/src/java/rsge/mods/pvputils/listeners/CommandEventListener.java @@ -22,10 +22,8 @@ import rsge.mods.pvputils.main.Reference; * * @author Rsge */ -public class CommandEventListener -{ - public CommandEventListener() - { +public class CommandEventListener { + public CommandEventListener() { MinecraftForge.EVENT_BUS.register(this); } @@ -35,16 +33,14 @@ public class CommandEventListener * @param e Command event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onCmd(CommandEvent e) - { + public void onCmd(CommandEvent e) { boolean unimportant = e.command.getCommandName().startsWith(Reference.MODID) || e.command.getCommandName().contains("help") || e.command.getCommandName().startsWith("list") || e.command.getCommandName().startsWith("save") || e.command.getCommandName().startsWith("say") || e.command.getCommandName().startsWith("tell") || e.command.getCommandName().startsWith("whisper") || e.command.getCommandName().startsWith("ping") || e.command.getCommandName().startsWith("rules"); - if (Config.cmdlogWhere == 1) - { + if (Config.cmdlogWhere == 1){ logToConsole(e, unimportant); logToFile(e, unimportant); } @@ -60,13 +56,10 @@ public class CommandEventListener * @param e Command event * @param unimportant Boolean, if command is too unimportant to log */ - private void logToConsole(CommandEvent e, boolean unimportant) - { - if (!unimportant) - { + private void logToConsole(CommandEvent e, boolean unimportant) { + if (!unimportant){ String log = "Player \"" + e.sender.getCommandSenderName() + "\" used command \"/" + e.command.getCommandName(); - for (int i = 0; i < e.parameters.length; i++) - { + for (int i = 0; i < e.parameters.length; i++){ log += (" " + e.parameters[i]); } log += "\""; @@ -81,17 +74,13 @@ public class CommandEventListener * @param e Command event * @param unimportant Boolean, if command is too unimportant to log */ - private void logToFile(CommandEvent e, boolean unimportant) - { - if (!unimportant) - { - try (BufferedWriter bw = Files.newBufferedWriter(Reference.loggedCmds.toPath(), StandardOpenOption.APPEND)) - { + private void logToFile(CommandEvent e, boolean unimportant) { + if (!unimportant){ + try (BufferedWriter bw = Files.newBufferedWriter(Reference.loggedCmds.toPath(), StandardOpenOption.APPEND)){ DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.UK); String l = ""; - for (int i = 0; i < e.parameters.length; i++) - { + for (int i = 0; i < e.parameters.length; i++){ l += (" " + e.parameters[i]); } @@ -99,8 +88,7 @@ public class CommandEventListener bw.write(log); } - catch (Exception ex) - { + catch (Exception ex){ Logger.error("ERROR trying to log a command"); } } diff --git a/src/java/rsge/mods/pvputils/listeners/PlayerAttackInteractEventListener.java b/src/java/rsge/mods/pvputils/listeners/PlayerAttackInteractEventListener.java index ad29036db0d99460b98de3f5ef88ac81f370b894..f9d3feff268d6eddaf7ba416bd53ef76171545e7 100644 --- a/src/java/rsge/mods/pvputils/listeners/PlayerAttackInteractEventListener.java +++ b/src/java/rsge/mods/pvputils/listeners/PlayerAttackInteractEventListener.java @@ -22,10 +22,8 @@ import rsge.mods.pvputils.main.Logger; * * @author Rsge */ -public class PlayerAttackInteractEventListener -{ - public PlayerAttackInteractEventListener() - { +public class PlayerAttackInteractEventListener { + public PlayerAttackInteractEventListener() { if (Config.macroDisable) MinecraftForge.EVENT_BUS.register(this); } @@ -40,33 +38,29 @@ public class PlayerAttackInteractEventListener * @param p Player entity * @param e PlayerInteractEvent || AttackEntityEvent */ - private static void macroDenial(EntityPlayer p, Event e) - { + private static void macroDenial(EntityPlayer p, Event e) { boolean cancelEvent = false; ArrayList<Long> interactMacroTimes = new ArrayList<Long>(); // Filling the HashMaps first - if (!playerAttackMacroTime.containsKey(p) && e instanceof AttackEntityEvent) - { + if (!playerAttackMacroTime.containsKey(p) && e instanceof AttackEntityEvent){ playerAttackMacroTime.put(p, System.currentTimeMillis()); return; } - if (!playerInteractMacroTimes.containsKey(p) && e instanceof PlayerInteractEvent) - { + if (!playerInteractMacroTimes.containsKey(p) && e instanceof PlayerInteractEvent){ interactMacroTimes.add(System.currentTimeMillis()); playerInteractMacroTimes.put(p, interactMacroTimes); return; } - //TODO how to find if clientside + // TODO how to find if clientside MinecraftServer mcs = MinecraftServer.getServer(); if (Config.excessiveLogging) Logger.info(e.toString() + " - " + mcs.isSinglePlayer()); // Attack events are always fired just once per click and are the more important ones to block, // so block them instantly when fired too fast after the other. - if (e instanceof AttackEntityEvent) - { + if (e instanceof AttackEntityEvent){ long attackInterval = System.currentTimeMillis() - playerAttackMacroTime.get(p); if (Config.excessiveLogging) Logger.info("AttackEvent-Interval: " + attackInterval + " from Player " + p.getDisplayName()); @@ -74,19 +68,16 @@ public class PlayerAttackInteractEventListener } // Interact events are sometimes fired in strange ways and in strange intervals, // so check for multiple short intervals in succession, before counting it as macro. - else if (e instanceof PlayerInteractEvent) - { + else if (e instanceof PlayerInteractEvent){ ArrayList<Long> interactTimes = new ArrayList<Long>(); interactTimes = playerInteractMacroTimes.get(p); - if (interactTimes.size() < 3) - { + if (interactTimes.size() < 3){ interactTimes.add(System.currentTimeMillis()); playerInteractMacroTimes.put(p, interactTimes); return; } - for (int i = 1; i < interactTimes.size(); i++) - { + for (int i = 1; i < interactTimes.size(); i++){ long interactInterval = interactTimes.get(i) - interactTimes.get(i - 1); if (Config.excessiveLogging && i == interactTimes.size() - 1) Logger.info("InteractEvent-Interval: " + interactInterval + " from Player " + p.getDisplayName()); @@ -97,8 +88,7 @@ public class PlayerAttackInteractEventListener } // Canceling event when necessary - if (cancelEvent) - { + if (cancelEvent){ e.setCanceled(true); if (Config.debugLogging) Logger.info("Attack/Interact-Event canceled."); @@ -109,12 +99,10 @@ public class PlayerAttackInteractEventListener p.addChatMessage(new ChatComponentText(msg)); // Handling kicking of player if necessary - if (Config.macroKicker) - { + if (Config.macroKicker){ byte macroViolation = 0; - if (!playerMacroViolation.containsKey(p)) - { + if (!playerMacroViolation.containsKey(p)){ playerMacroViolation.put(p, macroViolation); return; } @@ -122,19 +110,15 @@ public class PlayerAttackInteractEventListener macroViolation = playerMacroViolation.get(p); macroViolation += 1; - if (macroViolation >= Config.macroKickerTreshold) - { - try - { + if (macroViolation >= Config.macroKickerTreshold){ + try{ EntityPlayerMP pmp = (EntityPlayerMP) p; pmp.playerNetServerHandler.kickPlayerFromServer(msg); } - catch (ClassCastException ex) - { + catch (ClassCastException ex){ Logger.error("Error trying to convert player entity for kicking"); } - finally - { + finally{ macroViolation = 0; playerMacroViolation.put(p, macroViolation); } @@ -146,8 +130,7 @@ public class PlayerAttackInteractEventListener // Updating macro times if (e instanceof AttackEntityEvent) playerAttackMacroTime.put(p, System.currentTimeMillis()); - else if (e instanceof PlayerInteractEvent) - { + else if (e instanceof PlayerInteractEvent){ interactMacroTimes.remove(0); interactMacroTimes.add(System.currentTimeMillis()); playerInteractMacroTimes.put(p, interactMacroTimes); @@ -160,8 +143,7 @@ public class PlayerAttackInteractEventListener * @param e Attack entity event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onPlayerAttack(AttackEntityEvent e) - { + public void onPlayerAttack(AttackEntityEvent e) { macroDenial(e.entityPlayer, e); } @@ -171,8 +153,7 @@ public class PlayerAttackInteractEventListener * @param e Player interact event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onPlayerInteract(PlayerInteractEvent e) - { + public void onPlayerInteract(PlayerInteractEvent e) { macroDenial(e.entityPlayer, e); } @@ -181,8 +162,7 @@ public class PlayerAttackInteractEventListener * * @param p Player entity */ - public static void logout(EntityPlayer p) - { + public static void logout(EntityPlayer p) { playerAttackMacroTime.remove(p); playerInteractMacroTimes.remove(p); playerMacroViolation.remove(p); diff --git a/src/java/rsge/mods/pvputils/listeners/PlayerDeathEventListener.java b/src/java/rsge/mods/pvputils/listeners/PlayerDeathEventListener.java index d167d4c3cc46b03e0bdf2c15ae767a36ed34b78c..adefdde774be16038325c7e3abab5a9d68fd9022 100644 --- a/src/java/rsge/mods/pvputils/listeners/PlayerDeathEventListener.java +++ b/src/java/rsge/mods/pvputils/listeners/PlayerDeathEventListener.java @@ -18,10 +18,8 @@ import rsge.mods.pvputils.main.Logger; * * @author Rsge */ -public class PlayerDeathEventListener -{ - public PlayerDeathEventListener() - { +public class PlayerDeathEventListener { + public PlayerDeathEventListener() { MinecraftForge.EVENT_BUS.register(this); } @@ -31,15 +29,13 @@ public class PlayerDeathEventListener * @param e Player death event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onPlayerDeath(LivingDeathEvent e) - { + public void onPlayerDeath(LivingDeathEvent e) { if (Config.excessiveLogging) Logger.info("\"" + e.entityLiving.getCommandSenderName() + "\" died"); else if (Config.debugLogging && e.entityLiving instanceof EntityPlayerMP) Logger.info("Player \"" + e.entityLiving.getCommandSenderName() + "\" died"); - if (e.entityLiving instanceof EntityPlayerMP) - { + if (e.entityLiving instanceof EntityPlayerMP){ EntityPlayerMP p = (EntityPlayerMP) e.entityLiving; Lives.death(p, e.source); @@ -54,13 +50,11 @@ public class PlayerDeathEventListener * @param e Player respawn event */ @SubscribeEvent(priority = EventPriority.LOWEST) - public void onPlayerRespawn(PlayerRespawnEvent e) - { + public void onPlayerRespawn(PlayerRespawnEvent e) { if (Config.debugLogging) Logger.info("Player \"" + e.player.getCommandSenderName() + "\" respawned"); - if (!Config.noLifeChat) - { + if (!Config.noLifeChat){ EntityPlayerMP p = (EntityPlayerMP) e.player; Lives.chatLives(p); } diff --git a/src/java/rsge/mods/pvputils/listeners/XpPickupListener.java b/src/java/rsge/mods/pvputils/listeners/XpPickupListener.java index 2c931d8d232cf9101800d997413601b49e1a2d1e..0941bb0bc9db82d3cbadf44bd25e5f07edfeaacc 100644 --- a/src/java/rsge/mods/pvputils/listeners/XpPickupListener.java +++ b/src/java/rsge/mods/pvputils/listeners/XpPickupListener.java @@ -13,10 +13,8 @@ import rsge.mods.pvputils.config.Config; * * @author Rsge */ -public class XpPickupListener -{ - public XpPickupListener() - { +public class XpPickupListener { + public XpPickupListener() { if (Config.xpLockEnabled) MinecraftForge.EVENT_BUS.register(this); } @@ -27,8 +25,7 @@ public class XpPickupListener * @param e Player XP pickup event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onXpPickup(PlayerPickupXpEvent e) - { + public void onXpPickup(PlayerPickupXpEvent e) { if (Config.xpLockEnabled && e.entityPlayer.experienceLevel >= Config.xpLockLevel) e.setCanceled(true); } diff --git a/src/java/rsge/mods/pvputils/main/Legacy.java b/src/java/rsge/mods/pvputils/main/Legacy.java index 32b54d6dde4832560fd9951d83f20d89074d4a05..a5a1756dcb3d48db0945884d4d5aeea88c094e8d 100644 --- a/src/java/rsge/mods/pvputils/main/Legacy.java +++ b/src/java/rsge/mods/pvputils/main/Legacy.java @@ -25,8 +25,7 @@ import rsge.mods.pvputils.config.Config; * * @author Rsge */ -public class Legacy -{ +public class Legacy { private static HashMap<String, Byte> playerlives = new HashMap<String, Byte>(); private static HashMap<UUID, Long> playerTimes = new HashMap<UUID, Long>(); private static HashMap<UUID, Boolean> playerOnline = new HashMap<UUID, Boolean>(); @@ -37,16 +36,13 @@ public class Legacy @SuppressWarnings("unused") private static LocalDate lastDate; - public static void init() throws IOException - { + public static void init() throws IOException { // Figure out, why this isn't working... // Lives DataInputStream datain = new DataInputStream(new FileInputStream(Reference.lifeData)); - try - { + try{ int entries = datain.readInt(); - for (int i = 0; i < entries; i++) - { + for (int i = 0; i < entries; i++){ String uuid = datain.readUTF(); byte lives = datain.readByte(); playerlives.put(uuid, lives); @@ -54,8 +50,7 @@ public class Legacy Logger.info(uuid + " has " + lives + " lives left"); } } - catch (EOFException ex) - { + catch (EOFException ex){ if (Config.debugLogging) Logger.warn("lives.dat-File empty! (This is not an Error!)"); } @@ -63,15 +58,12 @@ public class Legacy } - public static void save() - { + public static void save() { // Lives - try - { + try{ DataOutputStream dataout = new DataOutputStream(new FileOutputStream(Reference.lifeData)); dataout.writeInt(playerlives.size()); - for (Entry<String, Byte> entry : playerlives.entrySet()) - { + for (Entry<String, Byte> entry : playerlives.entrySet()){ String uuid = entry.getKey(); byte lives = entry.getValue(); dataout.writeUTF(uuid); @@ -80,12 +72,10 @@ public class Legacy dataout.flush(); dataout.close(); - if (Config.debugLogging) - { + if (Config.debugLogging){ DataInputStream datain = new DataInputStream(new FileInputStream(Reference.timeData)); int entries = datain.readInt(); - for (int i = 1; i < entries; i++) - { + for (int i = 1; i < entries; i++){ String uuid = datain.readUTF(); byte lives = datain.readByte(); Logger.info("File: " + uuid + " has " + lives + " lives left"); @@ -93,8 +83,7 @@ public class Legacy datain.close(); } } - catch (Exception ex) - { + catch (Exception ex){ throw new RuntimeException(ex); } } @@ -102,30 +91,24 @@ public class Legacy /** * Old second Method */ - public static void second() - { + public static void second() { // For each player... - for (Entry<UUID, Long> entry : playerTimes.entrySet()) - { + for (Entry<UUID, Long> entry : playerTimes.entrySet()){ UUID u = entry.getKey(); long t = entry.getValue(); boolean on = playerOnline.get(u); // ... if player is online - if (on) - { + if (on){ // Old Version of: Get the player entity from the player's UUID @SuppressWarnings("unchecked") List<EntityPlayer> ps = MinecraftServer.getServer().getConfigurationManager().playerEntityList; - for (EntityPlayer p : ps) - { + for (EntityPlayer p : ps){ UUID u2 = p.getGameProfile().getId(); - if (u.equals(u2)) - { + if (u.equals(u2)){ // Stop time if player is in spawn area - if (Config.stopInSpawn) - { + if (Config.stopInSpawn){ // Much longer old version with square radius: int playerX = p.getPlayerCoordinates().posX; @@ -141,15 +124,11 @@ public class Legacy boolean inRangeZ = comparedZ >= -Config.stopInSpawnRadius && comparedZ <= Config.stopInSpawnRadius; if (Config.constantExcessiveLogging) Logger.info(u.toString() + " ComparedX = " + comparedX + " ComparedY = " + comparedY + " ComparedZ = " + comparedZ); - if (!inRangeX || !inRangeY || !inRangeZ) - { - - if (comparedX > Config.stopInSpawnRadius || comparedY > Config.stopInSpawnRadius || comparedZ > Config.stopInSpawnRadius) - { - try - { - if (!playerInSpawn.get(u)) - { + if (!inRangeX || !inRangeY || !inRangeZ){ + + if (comparedX > Config.stopInSpawnRadius || comparedY > Config.stopInSpawnRadius || comparedZ > Config.stopInSpawnRadius){ + try{ + if (!playerInSpawn.get(u)){ playerInSpawn.put(u, true); p.addChatMessage(new ChatComponentText("You left the spawnzone, your time started again.") .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW))); @@ -160,17 +139,13 @@ public class Legacy if (Config.constantExcessiveLogging) Logger.info(u.toString() + "'s second passed"); } - catch (NullPointerException ex) - { + catch (NullPointerException ex){ playerInSpawn.put(u, false); } } - else - { - try - { - if (playerInSpawn.get(u)) - { + else{ + try{ + if (playerInSpawn.get(u)){ playerInSpawn.put(u, false); p.addChatMessage(new ChatComponentText("You entered the spawnzone, your time stopped.") .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.YELLOW))); @@ -179,8 +154,7 @@ public class Legacy if (Config.constantExcessiveLogging) Logger.info(u.toString() + "'s second didn't pass"); } - catch (NullPointerException ex) - {} + catch (NullPointerException ex){} } } else @@ -193,6 +167,5 @@ public class Legacy lastDate = LocalDate.now(); } - private static void passTime(UUID u, EntityPlayer p, long t) - {} + private static void passTime(UUID u, EntityPlayer p, long t) {} } diff --git a/src/java/rsge/mods/pvputils/main/Logger.java b/src/java/rsge/mods/pvputils/main/Logger.java index 1cee923bcef45cd81c4b70f364c86aa256e5b709..913594311b4e4fa08476bb2405e69779a5d96c1b 100644 --- a/src/java/rsge/mods/pvputils/main/Logger.java +++ b/src/java/rsge/mods/pvputils/main/Logger.java @@ -21,16 +21,14 @@ import net.minecraft.command.ICommandSender; * * @author Rsge */ -public class Logger -{ +public class Logger { /** * Basic logging command * * @param logLevel Level of logging * @param object to be logged */ - private static void log(Level logLevel, Object object) - { + private static void log(Level logLevel, Object object) { FMLLog.log(Reference.NAME, logLevel, String.valueOf(object)); } @@ -39,8 +37,7 @@ public class Logger * * @param object to be logged */ - public static void off(Object object) - { + public static void off(Object object) { log(Level.OFF, object); } @@ -49,8 +46,7 @@ public class Logger * * @param object to be logged */ - public static void fatal(Object object) - { + public static void fatal(Object object) { log(Level.FATAL, object); } @@ -59,8 +55,7 @@ public class Logger * * @param object to be logged */ - public static void error(Object object) - { + public static void error(Object object) { log(Level.ERROR, object); } @@ -69,8 +64,7 @@ public class Logger * * @param object to be logged */ - public static void warn(Object object) - { + public static void warn(Object object) { log(Level.WARN, object); } @@ -79,8 +73,7 @@ public class Logger * * @param object to be logged */ - public static void info(Object object) - { + public static void info(Object object) { log(Level.INFO, object); } @@ -89,8 +82,7 @@ public class Logger * * @param object to be logged */ - public static void debug(Object object) - { + public static void debug(Object object) { log(Level.DEBUG, object); } @@ -99,8 +91,7 @@ public class Logger * * @param object to be logged */ - public static void trace(Object object) - { + public static void trace(Object object) { log(Level.TRACE, object); } @@ -109,8 +100,7 @@ public class Logger * * @param object to be logged */ - public static void all(Object object) - { + public static void all(Object object) { log(Level.ALL, object); } @@ -120,18 +110,15 @@ public class Logger * @param cmdsender Sender of command * @param s String to log */ - public static void logCmd(ICommandSender cmdsender, String s) - { - try - { + public static void logCmd(ICommandSender cmdsender, String s) { + try{ DateTimeFormatter dtf = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(Locale.UK); String l = "[" + LocalDateTime.now().format(dtf) + "] [" + cmdsender.getCommandSenderName() + "] [" + s + "]"; List<String> log = Arrays.asList(l); Files.write(Paths.get(Reference.loggedCmds.getAbsolutePath()), log, StandardOpenOption.APPEND); } - catch (Exception ex) - { + catch (Exception ex){ Logger.error("ERROR while trying to log a PvP-Utilities-command"); } } diff --git a/src/java/rsge/mods/pvputils/main/PvPUtils.java b/src/java/rsge/mods/pvputils/main/PvPUtils.java index 3fd1974843b5ed8e5a430a642df0614381c5ee53..2cf33be321bee055f67d402d5f4e75820e5aa8a8 100644 --- a/src/java/rsge/mods/pvputils/main/PvPUtils.java +++ b/src/java/rsge/mods/pvputils/main/PvPUtils.java @@ -49,8 +49,7 @@ import rsge.mods.pvputils.proxies.CommonProxy; * @author Rsge */ @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, dependencies = Reference.DEPENDENCIES, acceptedMinecraftVersions = Reference.MCVERSIONS, acceptableRemoteVersions = Reference.REMOTEVERSIONS) -public class PvPUtils -{ +public class PvPUtils { /** * PvPUtils Instance */ @@ -74,8 +73,7 @@ public class PvPUtils * @param e Pre-Initialization event */ @EventHandler - public void preInit(FMLPreInitializationEvent e) - { + public void preInit(FMLPreInitializationEvent e) { Reference.configPath = e.getModConfigurationDirectory().getAbsolutePath(); Reference.configFile = new File(Reference.configPath + File.separator + Reference.MODID + ".cfg"); Config.init(Reference.configFile); @@ -87,8 +85,7 @@ public class PvPUtils * @param e Initialization event */ @EventHandler - public void init(FMLInitializationEvent e) - { + public void init(FMLInitializationEvent e) { FMLCommonHandler.instance().bus().register(instance); if (Config.cmdlogEnabled) new CommandEventListener(); @@ -108,8 +105,7 @@ public class PvPUtils * @param e Post-Initialization event */ @EventHandler - public void postInit(FMLPostInitializationEvent e) - { + public void postInit(FMLPostInitializationEvent e) { Logger.info("Kleine Katzen leben laenger mit Calgon, Nyan, Nyan!"); if (Config.debugLogging) Logger.info("Debug-logging enabled"); @@ -125,8 +121,7 @@ public class PvPUtils * @param e Server starting event */ @EventHandler - public void serverLoad(FMLServerStartingEvent e) - { + public void serverLoad(FMLServerStartingEvent e) { e.registerServerCommand(CmdHandler.instance); } @@ -136,18 +131,14 @@ public class PvPUtils * @param e Server started event */ @EventHandler - public void serverLoaded(FMLServerStartedEvent e) - { - try - { - if (Config.livesEnabled || Config.timeEnabled || Config.cmdlogEnabled) - { + public void serverLoaded(FMLServerStartedEvent e) { + try{ + if (Config.livesEnabled || Config.timeEnabled || Config.cmdlogEnabled){ Reference.dataDir = new File(DimensionManager.getCurrentSaveRootDirectory(), Reference.MODID); if (!Reference.dataDir.exists()) Reference.dataDir.mkdirs(); - if (Config.livesEnabled) - { + if (Config.livesEnabled){ Lives.init(); if (Config.scoreboardEnabled) @@ -157,16 +148,14 @@ public class PvPUtils if (Config.timeEnabled) Time.init(); - if (Config.cmdlogEnabled) - { + if (Config.cmdlogEnabled){ Reference.loggedCmds = new File(Reference.dataDir, "LoggedCommands.txt"); if (!Reference.loggedCmds.exists()) Reference.loggedCmds.createNewFile(); } } } - catch (Exception ex) - { + catch (Exception ex){ throw new RuntimeException(ex); } } @@ -177,16 +166,13 @@ public class PvPUtils * @param e Server stopped event */ @EventHandler - public void serverStop(FMLServerStoppedEvent e) - { + public void serverStop(FMLServerStoppedEvent e) { // Because the owner (sometimes?) doesn't seem to log out of a SP-world MinecraftServer mcs = MinecraftServer.getServer(); - if (mcs.isSinglePlayer()) - { + if (mcs.isSinglePlayer()){ @SuppressWarnings("rawtypes") List players = mcs.getConfigurationManager().playerEntityList; - if (!players.isEmpty()) - { + if (!players.isEmpty()){ EntityPlayerMP owner = (EntityPlayerMP) players.get(0); if (Config.timeEnabled) @@ -196,8 +182,7 @@ public class PvPUtils Logger.info("Player '" + owner.getCommandSenderName() + "' with ID " + owner.getGameProfile().getId().toString() + " logged out"); } - if (!Lives.worldDelete) - { + if (!Lives.worldDelete){ // Safe data if (Config.livesEnabled) Lives.stop(); @@ -228,18 +213,15 @@ public class PvPUtils * @param e Player logged in event */ @SubscribeEvent(priority = EventPriority.LOWEST) - public void onPlayerLogin(PlayerLoggedInEvent e) - { + public void onPlayerLogin(PlayerLoggedInEvent e) { if (Config.debugLogging) Logger.info("Player '" + e.player.getCommandSenderName() + "' with ID '" + e.player.getGameProfile().getId().toString() + "' logged in"); - if (e.player instanceof EntityPlayerMP) - { + if (e.player instanceof EntityPlayerMP){ EntityPlayerMP p = (EntityPlayerMP) e.player; // Lives - if (Config.livesEnabled) - { + if (Config.livesEnabled){ Lives.initPlayer(p); if (!Config.noLifeChat) @@ -250,8 +232,7 @@ public class PvPUtils } // Time - if (Config.timeEnabled) - { + if (Config.timeEnabled){ Time.initPlayer(p); if (!Config.noTimeChat) @@ -269,41 +250,32 @@ public class PvPUtils * @param e Player logged out event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onPlayerLogout(PlayerLoggedOutEvent e) - { + public void onPlayerLogout(PlayerLoggedOutEvent e) { if (Config.debugLogging) Logger.info("Player '" + e.player.getCommandSenderName() + "' with ID " + e.player.getGameProfile().getId().toString() + " logged out"); - if (e.player instanceof EntityPlayerMP) - { + if (e.player instanceof EntityPlayerMP){ EntityPlayerMP p = (EntityPlayerMP) e.player; - if (Config.livesEnabled) - { - try - { + if (Config.livesEnabled){ + try{ Lives.save(); } - catch(IOException ex) - { + catch (IOException ex){ Logger.error("Lives saving failed: " + ex.getLocalizedMessage()); } } - if (Config.timeEnabled) - { + if (Config.timeEnabled){ if (!MinecraftServer.getServer().isSinglePlayer()) Time.stopTime(p); - try - { + try{ Time.save(); } - catch(IOException ex) - { + catch (IOException ex){ Logger.error("Time saving failed: " + ex.getLocalizedMessage()); } } - if (Config.macroDisable) - { + if (Config.macroDisable){ PlayerAttackInteractEventListener.logout(e.player); } } @@ -317,12 +289,10 @@ public class PvPUtils * @param e Server tick event */ @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onServerTick(ServerTickEvent e) - { + public void onServerTick(ServerTickEvent e) { i += 1; - if (i == 40) - { + if (i == 40){ if (Config.constantExcessiveLogging) Logger.info("Second passed"); @@ -341,29 +311,24 @@ public class PvPUtils * @param e Player tick event */ @SubscribeEvent(priority = EventPriority.LOWEST) - public void onPlayerTick(PlayerTickEvent e) - { - if (Config.xpLockEnabled) - { + public void onPlayerTick(PlayerTickEvent e) { + if (Config.xpLockEnabled){ if (!msgRec.containsKey(e.player)) msgRec.put(e.player, new Boolean[] {false, false}); - if (!msgRec.get(e.player)[0] && e.player.experienceLevel == Config.xpLockLevel - 1) - { + if (!msgRec.get(e.player)[0] && e.player.experienceLevel == Config.xpLockLevel - 1){ ChatComponentText msg = new ChatComponentText("You are one level away from max!"); msg.getChatStyle().setColor(EnumChatFormatting.RED); e.player.addChatMessage(msg); msgRec.put(e.player, new Boolean[] {true, msgRec.get(e.player)[1]}); } - else if (!msgRec.get(e.player)[1] && e.player.experienceLevel == Config.xpLockLevel) - { + else if (!msgRec.get(e.player)[1] && e.player.experienceLevel == Config.xpLockLevel){ ChatComponentText msg = new ChatComponentText("You reached max level! XP-orbs won't be collected! Any further XP will be deleted!"); msg.getChatStyle().setColor(EnumChatFormatting.RED); e.player.addChatMessage(msg); msgRec.put(e.player, new Boolean[] {msgRec.get(e.player)[0], true}); } - else if (msgRec.get(e.player)[0] && e.player.experienceLevel < Config.xpLockLevel - 1) - { + else if (msgRec.get(e.player)[0] && e.player.experienceLevel < Config.xpLockLevel - 1){ msgRec.put(e.player, new Boolean[] {false, false}); } diff --git a/src/java/rsge/mods/pvputils/main/Reference.java b/src/java/rsge/mods/pvputils/main/Reference.java index 73659bbca742dbf350043367dd024a870bc2d842..e640666e71bfada88cb70f77db22a1c8ed48e8d8 100644 --- a/src/java/rsge/mods/pvputils/main/Reference.java +++ b/src/java/rsge/mods/pvputils/main/Reference.java @@ -8,8 +8,7 @@ import java.io.File; * * @author Rsge */ -public class Reference -{ +public class Reference { /** Mod ID */ public static final String MODID = "pvputils"; /** Mod name */ diff --git a/src/java/rsge/mods/pvputils/proxies/ClientProxy.java b/src/java/rsge/mods/pvputils/proxies/ClientProxy.java index 141b15e8b143ba5bb1b6d35460dc6a97d90d12c4..ce619b15028b013035b0201aceb6b50b488012ea 100644 --- a/src/java/rsge/mods/pvputils/proxies/ClientProxy.java +++ b/src/java/rsge/mods/pvputils/proxies/ClientProxy.java @@ -1,15 +1,13 @@ package rsge.mods.pvputils.proxies; -public class ClientProxy extends CommonProxy -{ +public class ClientProxy extends CommonProxy { /** * If proxy is clientside * * @return true */ @Override - public boolean isClient() - { + public boolean isClient() { return true; } @@ -19,8 +17,7 @@ public class ClientProxy extends CommonProxy * @return false */ @Override - public boolean isServer() - { + public boolean isServer() { return false; } } diff --git a/src/java/rsge/mods/pvputils/proxies/CommonProxy.java b/src/java/rsge/mods/pvputils/proxies/CommonProxy.java index 0773aedf11196f281956bf91051aa92c1e0efa74..d39198c3563c255f6c9ce8354e701601a1867a50 100644 --- a/src/java/rsge/mods/pvputils/proxies/CommonProxy.java +++ b/src/java/rsge/mods/pvputils/proxies/CommonProxy.java @@ -5,15 +5,13 @@ package rsge.mods.pvputils.proxies; * * @author Rsge */ -public class CommonProxy -{ +public class CommonProxy { /** * If proxy is clientside * * @return false */ - public boolean isClient() - { + public boolean isClient() { return false; } @@ -22,8 +20,7 @@ public class CommonProxy * * @return true */ - public boolean isServer() - { + public boolean isServer() { return true; } }