Commits

t00thpick1 authored and EvilSeph committed e6be37d9e39
[Bleeding] Add direct addresses for command aliases.
No tags

src/main/java/org/bukkit/command/SimpleCommandMap.java

Modified
95 95 public boolean register(String fallbackPrefix, Command command) {
96 96 return register(command.getName(), fallbackPrefix, command);
97 97 }
98 98
99 99 /**
100 100 * {@inheritDoc}
101 101 */
102 102 public boolean register(String label, String fallbackPrefix, Command command) {
103 103 label = label.toLowerCase().trim();
104 104 fallbackPrefix = fallbackPrefix.toLowerCase().trim();
105 - boolean registered = register(label, command, false);
106 - knownCommands.put(fallbackPrefix + ":" + label, command);
105 + boolean registered = register(label, command, false, fallbackPrefix);
107 106
108 107 Iterator<String> iterator = command.getAliases().iterator();
109 108 while (iterator.hasNext()) {
110 - if (!register(iterator.next(), command, true)) {
109 + if (!register(iterator.next(), command, true, fallbackPrefix)) {
111 110 iterator.remove();
112 111 }
113 112 }
114 113
115 114 // If we failed to register under the real name, we need to set the command label to the direct address
116 115 if (!registered) {
117 116 command.setLabel(fallbackPrefix + ":" + label);
118 117 }
119 118
120 119 // Register to us so further updates of the commands label and aliases are postponed until its reregistered
121 120 command.register(this);
122 121
123 122 return registered;
124 123 }
125 124
126 125 /**
127 - * Registers a command with the given name is possible.
126 + * Registers a command with the given name is possible. Also uses
127 + * fallbackPrefix to create a unique name.
128 128 *
129 129 * @param label the name of the command, without the '/'-prefix.
130 130 * @param command the command to register
131 + * @param isAlias whether the command is an alias
132 + * @param fallbackPrefix a prefix which is prepended to the command for a
133 + * unique address
131 134 * @return true if command was registered, false otherwise.
132 135 */
133 - private synchronized boolean register(String label, Command command, boolean isAlias) {
136 + private synchronized boolean register(String label, Command command, boolean isAlias, String fallbackPrefix) {
137 + knownCommands.put(fallbackPrefix + ":" + label, command);
134 138 if ((command instanceof VanillaCommand || isAlias) && knownCommands.containsKey(label)) {
135 139 // Request is for an alias/fallback command and it conflicts with
136 140 // a existing command or previous alias ignore it
137 141 // Note: This will mean it gets removed from the commands list of active aliases
138 142 return false;
139 143 }
140 144
141 145 boolean registered = true;
142 146
143 147 // If the command exists but is an alias we overwrite it, otherwise we return

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut