Added command intercepter tool, used it for //calc #49
44
misc.py
44
misc.py
@ -55,7 +55,10 @@ class CommandInterceptions:
|
|||||||
# But without this snippet, the server shuts itself down because
|
# But without this snippet, the server shuts itself down because
|
||||||
# commands can't be aliases for themselves (shrug) :)
|
# commands can't be aliases for themselves (shrug) :)
|
||||||
aliases = wrapped.getAliases()
|
aliases = wrapped.getAliases()
|
||||||
aliases.remove(wrapped.getLabel())
|
try:
|
||||||
|
aliases.remove(wrapped.getLabel())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
self.setAliases(aliases)
|
self.setAliases(aliases)
|
||||||
self.wrapped = wrapped
|
self.wrapped = wrapped
|
||||||
self.intercepter = intercepter
|
self.intercepter = intercepter
|
||||||
@ -74,19 +77,15 @@ class CommandInterceptions:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_interception(key, intercepted):
|
def add_interception(key, intercepted):
|
||||||
try:
|
registration = CommandInterceptions.registrations[key]
|
||||||
info("Adding interception for /" + key)
|
tab_completer = registration[1]
|
||||||
registration = CommandInterceptions.registrations[key]
|
if tab_completer is None:
|
||||||
tab_completer = registration[1]
|
tab_completer = lambda original_completions, sender, alias, args: original_completions
|
||||||
if tab_completer is None:
|
cmd_intercepter = CommandInterceptions.Intercepter(intercepted, registration[0], tab_completer)
|
||||||
tab_completer = lambda original_completions, sender, alias, args: original_completions
|
CommandInterceptions.interceptions[intercepted] = cmd_intercepter
|
||||||
cmd_intercepter = CommandInterceptions.Intercepter(intercepted, registration[0], tab_completer)
|
for entry in CommandInterceptions.cmd_map.entrySet():
|
||||||
CommandInterceptions.interceptions[intercepted] = cmd_intercepter
|
if entry.getValue() is intercepted:
|
||||||
for entry in CommandInterceptions.cmd_map.entrySet():
|
entry.setValue(cmd_intercepter)
|
||||||
if entry.getValue() is intercepted:
|
|
||||||
entry.setValue(cmd_intercepter)
|
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_interceptions():
|
def init_interceptions():
|
||||||
@ -103,16 +102,13 @@ class CommandInterceptions:
|
|||||||
return HashMap.put(self, key, value)
|
return HashMap.put(self, key, value)
|
||||||
|
|
||||||
def put(self, key, value):
|
def put(self, key, value):
|
||||||
try:
|
for intercepted in CommandInterceptions.interceptions:
|
||||||
for intercepted in CommandInterceptions.interceptions:
|
if value is intercepted:
|
||||||
if value is intercepted:
|
return self.java_put(key, CommandInterceptions.interceptions[intercepted])
|
||||||
return self.java_put(key, CommandInterceptions.interceptions[intercepted])
|
ret = self.java_put(key, value)
|
||||||
ret = self.java_put(key, value)
|
if key in CommandInterceptions.registrations:
|
||||||
if key in CommandInterceptions.registrations:
|
CommandInterceptions.add_interception(key, value)
|
||||||
CommandInterceptions.add_interception(key, value)
|
return ret
|
||||||
return ret
|
|
||||||
except:
|
|
||||||
error(trace())
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
map_field = server.getPluginManager().getClass().getDeclaredField("commandMap")
|
map_field = server.getPluginManager().getClass().getDeclaredField("commandMap")
|
||||||
|
Reference in New Issue
Block a user