From 91e74845a2b6af0674b8cb04eb047761f4eb5d25 Mon Sep 17 00:00:00 2001 From: graywolf336 Date: Fri, 12 Jun 2015 22:13:09 -0500 Subject: [PATCH] Add update to the sign commands, same as refresh. --- .../command/subcommands/JailSignsCommand.java | 280 +++++++++--------- 1 file changed, 140 insertions(+), 140 deletions(-) diff --git a/src/main/java/com/graywolf336/jail/command/subcommands/JailSignsCommand.java b/src/main/java/com/graywolf336/jail/command/subcommands/JailSignsCommand.java index 18f6e14..6523ae7 100644 --- a/src/main/java/com/graywolf336/jail/command/subcommands/JailSignsCommand.java +++ b/src/main/java/com/graywolf336/jail/command/subcommands/JailSignsCommand.java @@ -1,140 +1,140 @@ -package com.graywolf336.jail.command.subcommands; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - -import org.bukkit.command.CommandSender; -import org.bukkit.util.StringUtil; - -import com.graywolf336.jail.JailManager; -import com.graywolf336.jail.Util; -import com.graywolf336.jail.beans.Cell; -import com.graywolf336.jail.beans.Jail; -import com.graywolf336.jail.command.Command; -import com.graywolf336.jail.command.CommandInfo; -import com.graywolf336.jail.enums.Lang; - -@CommandInfo( - maxArgs = -1, - minimumArgs = 2, - needsPlayer = false, - pattern = "signs", - permission = "jail.command.jailsigns", - usage = "/jail signs [clean|refresh|verify] [jail] (cell)..." - ) -public class JailSignsCommand implements Command { - private static final String[] options = new String[] { "clean", "refresh", "verify" }; - - public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception { - if(!jm.isValidJail(args[2])) { - sender.sendMessage(" " + Lang.NOJAIL.get(args[1])); - return true; - } - - Jail j = jm.getJail(args[2]); - - HashMap> items = new HashMap>(); - - if(args[1].equalsIgnoreCase("clean")) { - //if they type clean, we can remove all signs which are no longer signs - //then provide them a list of signs which got cleaned up - - for(Cell c : j.getCells()) { - if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) { - if(c.hasSigns()) { - List cleaned = c.cleanSigns(); - if(!cleaned.isEmpty()) { - items.put(c.getName(), cleaned); - } - } - } - } - - if(items.isEmpty()) { - sender.sendMessage(Lang.NOINVALIDSIGNS.get()); - }else { - sender.sendMessage(Lang.CLEANEDSIGNS.get()); - for(Entry> e : items.entrySet()) { - sender.sendMessage(" " + e.getKey()); - for(String s : e.getValue()) - sender.sendMessage(" Sign: " + s); - } - } - - return true; - }else if(args[1].equalsIgnoreCase("refresh")) { - //if they type refresh, we will go through all the signs and update them to - //display the correct message on the sign whether empty or time - - int cells = 0; - int updated = 0; - int removed = 0; - - for(Cell c : j.getCells()) { - if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) { - HashMap> results = c.updateSigns(); - updated += results.get("updated").size(); - removed += results.get("removed").size(); - cells++; - } - } - - sender.sendMessage(Lang.SIGNSREFRESHED.get(new String[] { String.valueOf(updated), String.valueOf(removed), String.valueOf(cells) })); - return true; - }else if(args[1].equalsIgnoreCase("verify")) { - //if they type verify, we will go through all the signs and then provide them - //as a list of cells which have signs that aren't actually signs and provide - //the location where the signs are - - for(Cell c : j.getCells()) { - if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) { - List invalids = c.getInvalidSigns(); - if(!invalids.isEmpty()) { - items.put(c.getName(), invalids); - } - } - } - - if(items.isEmpty()) { - sender.sendMessage(Lang.NOINVALIDSIGNS.get()); - }else { - sender.sendMessage(Lang.INVALIDSIGNS.get()); - for(Entry> e : items.entrySet()) { - sender.sendMessage(" " + e.getKey()); - for(String s : e.getValue()) - sender.sendMessage(" " + Lang.SIGN.get() + ": " + s); - } - } - return true; - }else - return false; - } - - public List provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception { - List results = new ArrayList(); - - switch(args.length) { - case 2: - for(String s : options) - if(args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1])) - results.add(s); - break; - case 3: - results.addAll(jm.getJailsByPrefix(args[2])); - break; - default: - if(jm.isValidJail(args[2])) - for(Cell c : jm.getJail(args[2]).getCells()) - if(!Util.isStringInsideArray(c.getName(), args)) - results.add(c.getName()); - break; - } - - Collections.sort(results); - - return results; - } -} +package com.graywolf336.jail.command.subcommands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; + +import org.bukkit.command.CommandSender; +import org.bukkit.util.StringUtil; + +import com.graywolf336.jail.JailManager; +import com.graywolf336.jail.Util; +import com.graywolf336.jail.beans.Cell; +import com.graywolf336.jail.beans.Jail; +import com.graywolf336.jail.command.Command; +import com.graywolf336.jail.command.CommandInfo; +import com.graywolf336.jail.enums.Lang; + +@CommandInfo( + maxArgs = -1, + minimumArgs = 2, + needsPlayer = false, + pattern = "signs", + permission = "jail.command.jailsigns", + usage = "/jail signs [clean|refresh|update|verify] [jail] (cell)..." + ) +public class JailSignsCommand implements Command { + private static final String[] options = new String[] { "clean", "refresh", "verify" }; + + public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception { + if(!jm.isValidJail(args[2])) { + sender.sendMessage(" " + Lang.NOJAIL.get(args[1])); + return true; + } + + Jail j = jm.getJail(args[2]); + + HashMap> items = new HashMap>(); + + if(args[1].equalsIgnoreCase("clean")) { + //if they type clean, we can remove all signs which are no longer signs + //then provide them a list of signs which got cleaned up + + for(Cell c : j.getCells()) { + if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) { + if(c.hasSigns()) { + List cleaned = c.cleanSigns(); + if(!cleaned.isEmpty()) { + items.put(c.getName(), cleaned); + } + } + } + } + + if(items.isEmpty()) { + sender.sendMessage(Lang.NOINVALIDSIGNS.get()); + }else { + sender.sendMessage(Lang.CLEANEDSIGNS.get()); + for(Entry> e : items.entrySet()) { + sender.sendMessage(" " + e.getKey()); + for(String s : e.getValue()) + sender.sendMessage(" Sign: " + s); + } + } + + return true; + }else if(args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update")) { + //if they type refresh, we will go through all the signs and update them to + //display the correct message on the sign whether empty or time + + int cells = 0; + int updated = 0; + int removed = 0; + + for(Cell c : j.getCells()) { + if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) { + HashMap> results = c.updateSigns(); + updated += results.get("updated").size(); + removed += results.get("removed").size(); + cells++; + } + } + + sender.sendMessage(Lang.SIGNSREFRESHED.get(new String[] { String.valueOf(updated), String.valueOf(removed), String.valueOf(cells) })); + return true; + }else if(args[1].equalsIgnoreCase("verify")) { + //if they type verify, we will go through all the signs and then provide them + //as a list of cells which have signs that aren't actually signs and provide + //the location where the signs are + + for(Cell c : j.getCells()) { + if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) { + List invalids = c.getInvalidSigns(); + if(!invalids.isEmpty()) { + items.put(c.getName(), invalids); + } + } + } + + if(items.isEmpty()) { + sender.sendMessage(Lang.NOINVALIDSIGNS.get()); + }else { + sender.sendMessage(Lang.INVALIDSIGNS.get()); + for(Entry> e : items.entrySet()) { + sender.sendMessage(" " + e.getKey()); + for(String s : e.getValue()) + sender.sendMessage(" " + Lang.SIGN.get() + ": " + s); + } + } + return true; + }else + return false; + } + + public List provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception { + List results = new ArrayList(); + + switch(args.length) { + case 2: + for(String s : options) + if(args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1])) + results.add(s); + break; + case 3: + results.addAll(jm.getJailsByPrefix(args[2])); + break; + default: + if(jm.isValidJail(args[2])) + for(Cell c : jm.getJail(args[2]).getCells()) + if(!Util.isStringInsideArray(c.getName(), args)) + results.add(c.getName()); + break; + } + + Collections.sort(results); + + return results; + } +}