Add update to the sign commands, same as refresh.
This commit is contained in:
parent
4c7166251f
commit
91e74845a2
@ -1,140 +1,140 @@
|
|||||||
package com.graywolf336.jail.command.subcommands;
|
package com.graywolf336.jail.command.subcommands;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.util.StringUtil;
|
import org.bukkit.util.StringUtil;
|
||||||
|
|
||||||
import com.graywolf336.jail.JailManager;
|
import com.graywolf336.jail.JailManager;
|
||||||
import com.graywolf336.jail.Util;
|
import com.graywolf336.jail.Util;
|
||||||
import com.graywolf336.jail.beans.Cell;
|
import com.graywolf336.jail.beans.Cell;
|
||||||
import com.graywolf336.jail.beans.Jail;
|
import com.graywolf336.jail.beans.Jail;
|
||||||
import com.graywolf336.jail.command.Command;
|
import com.graywolf336.jail.command.Command;
|
||||||
import com.graywolf336.jail.command.CommandInfo;
|
import com.graywolf336.jail.command.CommandInfo;
|
||||||
import com.graywolf336.jail.enums.Lang;
|
import com.graywolf336.jail.enums.Lang;
|
||||||
|
|
||||||
@CommandInfo(
|
@CommandInfo(
|
||||||
maxArgs = -1,
|
maxArgs = -1,
|
||||||
minimumArgs = 2,
|
minimumArgs = 2,
|
||||||
needsPlayer = false,
|
needsPlayer = false,
|
||||||
pattern = "signs",
|
pattern = "signs",
|
||||||
permission = "jail.command.jailsigns",
|
permission = "jail.command.jailsigns",
|
||||||
usage = "/jail signs [clean|refresh|verify] [jail] (cell)..."
|
usage = "/jail signs [clean|refresh|update|verify] [jail] (cell)..."
|
||||||
)
|
)
|
||||||
public class JailSignsCommand implements Command {
|
public class JailSignsCommand implements Command {
|
||||||
private static final String[] options = new String[] { "clean", "refresh", "verify" };
|
private static final String[] options = new String[] { "clean", "refresh", "verify" };
|
||||||
|
|
||||||
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||||
if(!jm.isValidJail(args[2])) {
|
if(!jm.isValidJail(args[2])) {
|
||||||
sender.sendMessage(" " + Lang.NOJAIL.get(args[1]));
|
sender.sendMessage(" " + Lang.NOJAIL.get(args[1]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Jail j = jm.getJail(args[2]);
|
Jail j = jm.getJail(args[2]);
|
||||||
|
|
||||||
HashMap<String, List<String>> items = new HashMap<String, List<String>>();
|
HashMap<String, List<String>> items = new HashMap<String, List<String>>();
|
||||||
|
|
||||||
if(args[1].equalsIgnoreCase("clean")) {
|
if(args[1].equalsIgnoreCase("clean")) {
|
||||||
//if they type clean, we can remove all signs which are no longer signs
|
//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
|
//then provide them a list of signs which got cleaned up
|
||||||
|
|
||||||
for(Cell c : j.getCells()) {
|
for(Cell c : j.getCells()) {
|
||||||
if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) {
|
if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) {
|
||||||
if(c.hasSigns()) {
|
if(c.hasSigns()) {
|
||||||
List<String> cleaned = c.cleanSigns();
|
List<String> cleaned = c.cleanSigns();
|
||||||
if(!cleaned.isEmpty()) {
|
if(!cleaned.isEmpty()) {
|
||||||
items.put(c.getName(), cleaned);
|
items.put(c.getName(), cleaned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(items.isEmpty()) {
|
if(items.isEmpty()) {
|
||||||
sender.sendMessage(Lang.NOINVALIDSIGNS.get());
|
sender.sendMessage(Lang.NOINVALIDSIGNS.get());
|
||||||
}else {
|
}else {
|
||||||
sender.sendMessage(Lang.CLEANEDSIGNS.get());
|
sender.sendMessage(Lang.CLEANEDSIGNS.get());
|
||||||
for(Entry<String, List<String>> e : items.entrySet()) {
|
for(Entry<String, List<String>> e : items.entrySet()) {
|
||||||
sender.sendMessage(" " + e.getKey());
|
sender.sendMessage(" " + e.getKey());
|
||||||
for(String s : e.getValue())
|
for(String s : e.getValue())
|
||||||
sender.sendMessage(" Sign: " + s);
|
sender.sendMessage(" Sign: " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else if(args[1].equalsIgnoreCase("refresh")) {
|
}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
|
//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
|
//display the correct message on the sign whether empty or time
|
||||||
|
|
||||||
int cells = 0;
|
int cells = 0;
|
||||||
int updated = 0;
|
int updated = 0;
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
|
|
||||||
for(Cell c : j.getCells()) {
|
for(Cell c : j.getCells()) {
|
||||||
if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) {
|
if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) {
|
||||||
HashMap<String, List<String>> results = c.updateSigns();
|
HashMap<String, List<String>> results = c.updateSigns();
|
||||||
updated += results.get("updated").size();
|
updated += results.get("updated").size();
|
||||||
removed += results.get("removed").size();
|
removed += results.get("removed").size();
|
||||||
cells++;
|
cells++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(Lang.SIGNSREFRESHED.get(new String[] { String.valueOf(updated), String.valueOf(removed), String.valueOf(cells) }));
|
sender.sendMessage(Lang.SIGNSREFRESHED.get(new String[] { String.valueOf(updated), String.valueOf(removed), String.valueOf(cells) }));
|
||||||
return true;
|
return true;
|
||||||
}else if(args[1].equalsIgnoreCase("verify")) {
|
}else if(args[1].equalsIgnoreCase("verify")) {
|
||||||
//if they type verify, we will go through all the signs and then provide them
|
//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
|
//as a list of cells which have signs that aren't actually signs and provide
|
||||||
//the location where the signs are
|
//the location where the signs are
|
||||||
|
|
||||||
for(Cell c : j.getCells()) {
|
for(Cell c : j.getCells()) {
|
||||||
if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) {
|
if(Util.isStringInsideArray(c.getName(), args) || args.length == 3) {
|
||||||
List<String> invalids = c.getInvalidSigns();
|
List<String> invalids = c.getInvalidSigns();
|
||||||
if(!invalids.isEmpty()) {
|
if(!invalids.isEmpty()) {
|
||||||
items.put(c.getName(), invalids);
|
items.put(c.getName(), invalids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(items.isEmpty()) {
|
if(items.isEmpty()) {
|
||||||
sender.sendMessage(Lang.NOINVALIDSIGNS.get());
|
sender.sendMessage(Lang.NOINVALIDSIGNS.get());
|
||||||
}else {
|
}else {
|
||||||
sender.sendMessage(Lang.INVALIDSIGNS.get());
|
sender.sendMessage(Lang.INVALIDSIGNS.get());
|
||||||
for(Entry<String, List<String>> e : items.entrySet()) {
|
for(Entry<String, List<String>> e : items.entrySet()) {
|
||||||
sender.sendMessage(" " + e.getKey());
|
sender.sendMessage(" " + e.getKey());
|
||||||
for(String s : e.getValue())
|
for(String s : e.getValue())
|
||||||
sender.sendMessage(" " + Lang.SIGN.get() + ": " + s);
|
sender.sendMessage(" " + Lang.SIGN.get() + ": " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}else
|
}else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
|
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
|
||||||
List<String> results = new ArrayList<String>();
|
List<String> results = new ArrayList<String>();
|
||||||
|
|
||||||
switch(args.length) {
|
switch(args.length) {
|
||||||
case 2:
|
case 2:
|
||||||
for(String s : options)
|
for(String s : options)
|
||||||
if(args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1]))
|
if(args[1].isEmpty() || StringUtil.startsWithIgnoreCase(s, args[1]))
|
||||||
results.add(s);
|
results.add(s);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
results.addAll(jm.getJailsByPrefix(args[2]));
|
results.addAll(jm.getJailsByPrefix(args[2]));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(jm.isValidJail(args[2]))
|
if(jm.isValidJail(args[2]))
|
||||||
for(Cell c : jm.getJail(args[2]).getCells())
|
for(Cell c : jm.getJail(args[2]).getCells())
|
||||||
if(!Util.isStringInsideArray(c.getName(), args))
|
if(!Util.isStringInsideArray(c.getName(), args))
|
||||||
results.add(c.getName());
|
results.add(c.getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(results);
|
Collections.sort(results);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user