Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

put some chunk of code to SimplyVanishCOmmand

  • Loading branch information...
commit d63bb3d456ae2519c9ba8e5003ec785bcf15e3d0 1 parent d35557e
asofold authored April 16, 2012
140  SimplyVanish/src/asofold/simplyvanish/SimplyVanish.java
... ...
@@ -1,11 +1,9 @@
1 1
 package asofold.simplyvanish;
2 2
 
3 3
 import java.io.File;
4  
-import java.util.HashMap;
5 4
 import java.util.HashSet;
6 5
 import java.util.LinkedList;
7 6
 import java.util.List;
8  
-import java.util.Map;
9 7
 import java.util.Set;
10 8
 
11 9
 import org.bukkit.ChatColor;
@@ -19,6 +17,7 @@
19 17
 
20 18
 import asofold.simplyvanish.api.hooks.Hook;
21 19
 import asofold.simplyvanish.command.LightCommands;
  20
+import asofold.simplyvanish.command.SimplyVanishCommand;
22 21
 import asofold.simplyvanish.config.Path;
23 22
 import asofold.simplyvanish.config.Settings;
24 23
 import asofold.simplyvanish.config.VanishConfig;
@@ -41,7 +40,7 @@
41 40
 		"vanish", "reappear", "tvanish", "simplyvanish","vanished", "vanflag",
42 41
 	};
43 42
 	
44  
-	private static final String cmdNoOpArg = "??NOOP??";
  43
+	public static final String cmdNoOpArg = "??NOOP??";
45 44
 	private static final String cmdNoOp = "simplyvanish "+cmdNoOpArg;
46 45
 	
47 46
 	public static final String msgLabel = ChatColor.GOLD+"[SimplyVanish]"+ChatColor.GRAY+" ";
@@ -60,10 +59,7 @@
60 59
 		stats.setLogStats(false);
61 60
 	}
62 61
 	
63  
-	/**
64  
-	 * Map aliases to recognized labels.
65  
-	 */
66  
-	Map<String, String> commandAliases = new HashMap<String, String>();
  62
+	SimplyVanishCommand cmdExe;
67 63
 	
68 64
 	/**
69 65
 	 *  Dynamic "fake" commands.
@@ -74,6 +70,7 @@
74 70
 	 * Constructor: set some defualt configuration values.
75 71
 	 */
76 72
 	public SimplyVanish(){
  73
+		cmdExe = new SimplyVanishCommand(core);
77 74
 	}
78 75
 	
79 76
 	@Override
@@ -183,7 +180,7 @@ else if (ref.getLabel().equalsIgnoreCase(cmd)){
183 180
 			if (getCommand(cmd) != null) aliasManager.removeAlias(cmd); // the command is registered already.
184 181
 			for ( String alias: needed){
185 182
 				alias = alias.trim().toLowerCase();
186  
-				commandAliases.put(alias, cmd);
  183
+				cmdExe.commandAliases.put(alias, cmd);
187 184
 			}
188 185
 		
189 186
 		}
@@ -196,138 +193,15 @@ else if (ref.getLabel().equalsIgnoreCase(cmd)){
196 193
 			List<String> aliases = command.getAliases();
197 194
 			if ( aliases == null) continue;
198 195
 			for ( String alias: aliases){
199  
-				commandAliases.put(alias.trim().toLowerCase(), cmd);
  196
+				cmdExe.commandAliases.put(alias.trim().toLowerCase(), cmd);
200 197
 			}
201 198
 		}
202 199
 	}
203 200
 	
204  
-	/**
205  
-	 * Get standardized lower-case label, possibly mapped from an alias.
206  
-	 * @param label
207  
-	 * @return
208  
-	 */
209  
-	String getMappedCommandLabel(String label){
210  
-		label = label.toLowerCase();
211  
-		String mapped = commandAliases.get(label);
212  
-		if (mapped == null) return label;
213  
-		else return mapped;
214  
-	}
215  
-	
216 201
 	@Override
217 202
 	public boolean onCommand(CommandSender sender, Command command,
218 203
 			String label, String[] args) {
219  
-		label = getMappedCommandLabel(label);
220  
-		int len = args.length;
221  
-		boolean hasFlags = false;
222  
-		for ( int i=args.length-1; i>=0; i--){
223  
-			if (args[i].startsWith("+") || args[i].startsWith("-") || args [i].startsWith("*")){
224  
-				len --;
225  
-				hasFlags = true;
226  
-			} 
227  
-			else break;
228  
-		}
229  
-		
230  
-		if ( label.equals("vanish") && len==0 ){
231  
-			if ( !Utils.checkPlayer(sender)) return true;
232  
-			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.self")) return true;
233  
-			// Make sure the player is vanished...
234  
-			if (hasFlags) core.setFlags(((Player) sender).getName(), args, len, sender, false, false, false);
235  
-			if (!setVanished((Player) sender, true)) Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
236  
-			return true;
237  
-		} 
238  
-		else if ( label.equals("vanish") && len==1 ){
239  
-			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.other")) return true;
240  
-			// Make sure the other player is vanished...
241  
-			String name = args[0].trim();
242  
-			if (hasFlags) core.setFlags(name, args, len, sender, false, true, false);
243  
-			if (setVanished(name, true)) Utils.send(sender, msgLabel + "Vanish player: "+name);
244  
-			else Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
245  
-			return true;
246  
-		} 
247  
-		else if (label.equals("reappear") && len==0 ){
248  
-			if ( !Utils.checkPlayer(sender)) return true;
249  
-			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.self") && !Utils.checkPerm(sender, "simplyvanish.reappear.self")) return true;
250  
-			// Let the player be seen...
251  
-			if (hasFlags) core.setFlags(((Player) sender).getName(), args, len, sender, false, false, false);
252  
-			if (!setVanished((Player) sender, false)) Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
253  
-			return true;
254  
-		} 
255  
-		else if ( label.equals("reappear") && len==1 ){
256  
-			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.other") && !Utils.checkPerm(sender, "simplyvanish.reappear.other")) return true;
257  
-			// Make sure the other player is shown...
258  
-			String name = args[0].trim();
259  
-			if (hasFlags) core.setFlags(name, args, len, sender, false, true, false);
260  
-			if (setVanished(name, false)) Utils.send(sender, msgLabel + "Show player: "+name);
261  
-			else Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
262  
-			return true;
263  
-		} 
264  
-		else if ( label.equals("tvanish") && len==0 ){
265  
-			if ( !Utils.checkPlayer(sender)) return true;
266  
-			Player player = (Player) sender;
267  
-			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.self")) return true;
268  
-			if (hasFlags) core.setFlags(player.getName(), args, len, sender, false, false, false);
269  
-			if (!setVanished(player, !isVanished(player))) Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
270  
-			return true;
271  
-		}
272  
-		else if (label.equals("vanished")){
273  
-			if ( !Utils.checkPerm(sender, "simplyvanish.vanished")) return true;
274  
-			Utils.send(sender, core.getVanishedMessage());
275  
-			return true;
276  
-		} 
277  
-		else if ( label.equals("simplyvanish") || label.equals("vanflag")){
278  
-			
279  
-			if (label.equals("simplyvanish")){
280  
-				if (!hasFlags && len==1 && args[0].equalsIgnoreCase("reload")){
281  
-					if ( !Utils.checkPerm(sender, "simplyvanish.reload")) return true;
282  
-					loadSettings();
283  
-					Utils.send(sender, msgLabel + ChatColor.YELLOW+"Settings reloaded.");
284  
-					return true;
285  
-				}
286  
-				else if (!hasFlags && len==1 && args[0].equalsIgnoreCase("drop")){
287  
-					if ( !Utils.checkPerm(sender, "simplyvanish.cmd.drop")) return true;
288  
-					if (!Utils.checkPlayer(sender)) return true;
289  
-					Utils.dropItemInHand((Player) sender);
290  
-					return true;
291  
-				}
292  
-				else if (len==1 && args[0].equals(SimplyVanish.cmdNoOpArg)) return true;
293  
-				else if (len==1 && args[0].equalsIgnoreCase("stats")){
294  
-					if ( !Utils.checkPerm(sender, "simplyvanish.stats.display")) return true;
295  
-					Utils.send(sender, stats.getStatsStr(true));
296  
-					return true;
297  
-				} 
298  
-				else if (len==2 && args[0].equalsIgnoreCase("stats") && args[1].equalsIgnoreCase("reset")){
299  
-					if ( !Utils.checkPerm(sender, "simplyvanish.stats.reset")) return true;
300  
-					stats.clear();
301  
-					Utils.send(sender, msgLabel+"Stats reset.");
302  
-					return true;
303  
-				}
304  
-			}
305  
-			
306  
-			if (hasFlags && len == 0){
307  
-				if (!Utils.checkPlayer(sender)) return true;
308  
-				core.setFlags(((Player)sender).getName(), args, len, sender, false, false, true);
309  
-				if (Utils.hasPermission(sender, "simplyvanish.flags.display.self")) core.onShowFlags((Player) sender, null);
310  
-				return true;
311  
-			} 
312  
-			else if (len == 0){
313  
-				if (!Utils.checkPlayer(sender)) return true;
314  
-				if (Utils.hasPermission(sender, "simplyvanish.flags.display.self")) core.onShowFlags((Player) sender, null);
315  
-				else sender.sendMessage(SimplyVanish.msgLabel+ChatColor.RED+"You do not have permission to display flags.");
316  
-				return true;
317  
-			} 
318  
-			else if (hasFlags && len==1){
319  
-				core.setFlags(args[0], args, len, sender, false, true, true);
320  
-				if (Utils.hasPermission(sender, "simplyvanish.flags.display.other")) core.onShowFlags(sender, args[0]);
321  
-				return true;
322  
-			}
323  
-			else if (len==1){
324  
-				if (Utils.hasPermission(sender, "simplyvanish.flags.display.other")) core.onShowFlags(sender, args[0]);
325  
-				else sender.sendMessage(SimplyVanish.msgLabel+ChatColor.RED+"You do not have permission to display flags of others.");
326  
-				return true;
327  
-			}
328  
-		}
329  
-		Utils.send(sender, msgLabel + ChatColor.DARK_RED+"Unrecognized command or number of arguments.");
330  
-		return false;
  204
+		return cmdExe.onCommand(sender, command, label, args);
331 205
 	}
332 206
 	
333 207
 	/**
155  SimplyVanish/src/asofold/simplyvanish/command/SimplyVanishCommand.java
... ...
@@ -0,0 +1,155 @@
  1
+package asofold.simplyvanish.command;
  2
+
  3
+import java.util.HashMap;
  4
+import java.util.Map;
  5
+
  6
+import org.bukkit.ChatColor;
  7
+import org.bukkit.command.Command;
  8
+import org.bukkit.command.CommandSender;
  9
+import org.bukkit.entity.Player;
  10
+
  11
+import asofold.simplyvanish.SimplyVanish;
  12
+import asofold.simplyvanish.SimplyVanishCore;
  13
+import asofold.simplyvanish.util.Utils;
  14
+
  15
+public class SimplyVanishCommand{
  16
+	/**
  17
+	 * Map aliases to recognized labels.
  18
+	 */
  19
+	public Map<String, String> commandAliases = new HashMap<String, String>();
  20
+	private SimplyVanishCore core;
  21
+	
  22
+	public SimplyVanishCommand(SimplyVanishCore core) {
  23
+		this.core = core;
  24
+	}
  25
+
  26
+	/**
  27
+	 * Get standardized lower-case label, possibly mapped from an alias.
  28
+	 * @param label
  29
+	 * @return
  30
+	 */
  31
+	String getMappedCommandLabel(String label){
  32
+		label = label.toLowerCase();
  33
+		String mapped = commandAliases.get(label);
  34
+		if (mapped == null) return label;
  35
+		else return mapped;
  36
+	}
  37
+
  38
+	public boolean onCommand(CommandSender sender, Command command, String label,
  39
+			String[] args) {
  40
+		SimplyVanish plugin = core.getPlugin();
  41
+		label = getMappedCommandLabel(label);
  42
+		int len = args.length;
  43
+		boolean hasFlags = false;
  44
+		for ( int i=args.length-1; i>=0; i--){
  45
+			if (args[i].startsWith("+") || args[i].startsWith("-") || args [i].startsWith("*")){
  46
+				len --;
  47
+				hasFlags = true;
  48
+			} 
  49
+			else break;
  50
+		}
  51
+		
  52
+		if ( label.equals("vanish") && len==0 ){
  53
+			if ( !Utils.checkPlayer(sender)) return true;
  54
+			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.self")) return true;
  55
+			// Make sure the player is vanished...
  56
+			if (hasFlags) core.setFlags(((Player) sender).getName(), args, len, sender, false, false, false);
  57
+			if (!SimplyVanish.setVanished((Player) sender, true)) Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
  58
+			return true;
  59
+		} 
  60
+		else if ( label.equals("vanish") && len==1 ){
  61
+			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.other")) return true;
  62
+			// Make sure the other player is vanished...
  63
+			String name = args[0].trim();
  64
+			if (hasFlags) core.setFlags(name, args, len, sender, false, true, false);
  65
+			if (SimplyVanish.setVanished(name, true)) Utils.send(sender, SimplyVanish.msgLabel + "Vanish player: "+name);
  66
+			else Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
  67
+			return true;
  68
+		} 
  69
+		else if (label.equals("reappear") && len==0 ){
  70
+			if ( !Utils.checkPlayer(sender)) return true;
  71
+			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.self") && !Utils.checkPerm(sender, "simplyvanish.reappear.self")) return true;
  72
+			// Let the player be seen...
  73
+			if (hasFlags) core.setFlags(((Player) sender).getName(), args, len, sender, false, false, false);
  74
+			if (!SimplyVanish.setVanished((Player) sender, false)) Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
  75
+			return true;
  76
+		} 
  77
+		else if ( label.equals("reappear") && len==1 ){
  78
+			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.other") && !Utils.checkPerm(sender, "simplyvanish.reappear.other")) return true;
  79
+			// Make sure the other player is shown...
  80
+			String name = args[0].trim();
  81
+			if (hasFlags) core.setFlags(name, args, len, sender, false, true, false);
  82
+			if (SimplyVanish.setVanished(name, false)) Utils.send(sender, SimplyVanish.msgLabel + "Show player: "+name);
  83
+			else Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
  84
+			return true;
  85
+		} 
  86
+		else if ( label.equals("tvanish") && len==0 ){
  87
+			if ( !Utils.checkPlayer(sender)) return true;
  88
+			Player player = (Player) sender;
  89
+			if ( !Utils.checkPerm(sender, "simplyvanish.vanish.self")) return true;
  90
+			if (hasFlags) core.setFlags(player.getName(), args, len, sender, false, false, false);
  91
+			if (!SimplyVanish.setVanished(player, !SimplyVanish.isVanished(player))) Utils.send(sender, SimplyVanish.msgLabel+ChatColor.RED+"Action was prevented by hooks.");
  92
+			return true;
  93
+		}
  94
+		else if (label.equals("vanished")){
  95
+			if ( !Utils.checkPerm(sender, "simplyvanish.vanished")) return true;
  96
+			Utils.send(sender, core.getVanishedMessage());
  97
+			return true;
  98
+		} 
  99
+		else if ( label.equals("simplyvanish") || label.equals("vanflag")){
  100
+			
  101
+			if (label.equals("simplyvanish")){
  102
+				if (!hasFlags && len==1 && args[0].equalsIgnoreCase("reload")){
  103
+					if ( !Utils.checkPerm(sender, "simplyvanish.reload")) return true;
  104
+					plugin.loadSettings();
  105
+					Utils.send(sender, SimplyVanish.msgLabel + ChatColor.YELLOW+"Settings reloaded.");
  106
+					return true;
  107
+				}
  108
+				else if (!hasFlags && len==1 && args[0].equalsIgnoreCase("drop")){
  109
+					if ( !Utils.checkPerm(sender, "simplyvanish.cmd.drop")) return true;
  110
+					if (!Utils.checkPlayer(sender)) return true;
  111
+					Utils.dropItemInHand((Player) sender);
  112
+					return true;
  113
+				}
  114
+				else if (len==1 && args[0].equals(SimplyVanish.cmdNoOpArg)) return true;
  115
+				else if (len==1 && args[0].equalsIgnoreCase("stats")){
  116
+					if ( !Utils.checkPerm(sender, "simplyvanish.stats.display")) return true;
  117
+					Utils.send(sender, SimplyVanish.stats.getStatsStr(true));
  118
+					return true;
  119
+				} 
  120
+				else if (len==2 && args[0].equalsIgnoreCase("stats") && args[1].equalsIgnoreCase("reset")){
  121
+					if ( !Utils.checkPerm(sender, "simplyvanish.stats.reset")) return true;
  122
+					SimplyVanish.stats.clear();
  123
+					Utils.send(sender, SimplyVanish.msgLabel+"Stats reset.");
  124
+					return true;
  125
+				}
  126
+			}
  127
+			
  128
+			if (hasFlags && len == 0){
  129
+				if (!Utils.checkPlayer(sender)) return true;
  130
+				core.setFlags(((Player)sender).getName(), args, len, sender, false, false, true);
  131
+				if (Utils.hasPermission(sender, "simplyvanish.flags.display.self")) core.onShowFlags((Player) sender, null);
  132
+				return true;
  133
+			} 
  134
+			else if (len == 0){
  135
+				if (!Utils.checkPlayer(sender)) return true;
  136
+				if (Utils.hasPermission(sender, "simplyvanish.flags.display.self")) core.onShowFlags((Player) sender, null);
  137
+				else sender.sendMessage(SimplyVanish.msgLabel+ChatColor.RED+"You do not have permission to display flags.");
  138
+				return true;
  139
+			} 
  140
+			else if (hasFlags && len==1){
  141
+				core.setFlags(args[0], args, len, sender, false, true, true);
  142
+				if (Utils.hasPermission(sender, "simplyvanish.flags.display.other")) core.onShowFlags(sender, args[0]);
  143
+				return true;
  144
+			}
  145
+			else if (len==1){
  146
+				if (Utils.hasPermission(sender, "simplyvanish.flags.display.other")) core.onShowFlags(sender, args[0]);
  147
+				else sender.sendMessage(SimplyVanish.msgLabel+ChatColor.RED+"You do not have permission to display flags of others.");
  148
+				return true;
  149
+			}
  150
+		}
  151
+		Utils.send(sender, SimplyVanish.msgLabel + ChatColor.DARK_RED+"Unrecognized command or number of arguments.");
  152
+		return false;
  153
+	}
  154
+
  155
+}

0 notes on commit d63bb3d

Please sign in to comment.
Something went wrong with that request. Please try again.