use of com.laytonsmith.abstraction.events.MCPlayerCommandEvent in project CommandHelper by EngineHub.
the class CommandHelperListener method onPlayerCommandPreprocess.
/**
* Called when a player attempts to use a command
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if (CommandHelperPlugin.self.interpreterListener.isInInterpreterMode(event.getPlayer().getName())) {
// They are in interpreter mode, so we want it to handle this, not everything else.
return;
}
MCPlayerCommandEvent mpce = new BukkitPlayerEvents.BukkitMCPlayerCommandEvent(event);
EventUtils.TriggerListener(Driver.PLAYER_COMMAND, "player_command", mpce);
if (mpce.isCancelled()) {
return;
}
String cmd = event.getMessage();
MCPlayer player = new BukkitMCPlayer(event.getPlayer());
BukkitDirtyRegisteredListener.PlayDirty();
if (!Prefs.PlayDirty()) {
if (event.isCancelled()) {
return;
}
}
try {
if (runAlias(event.getMessage(), player)) {
event.setCancelled(true);
if (Prefs.PlayDirty()) {
// Super cancel the event
BukkitDirtyRegisteredListener.setCancelled(event);
}
}
} catch (InternalException e) {
logger.log(Level.SEVERE, e.getMessage());
} catch (ConfigRuntimeException e) {
logger.log(Level.WARNING, e.getMessage());
} catch (Throwable e) {
player.sendMessage(MCChatColor.RED + "Command failed with following reason: " + e.getMessage());
// Obviously the command is registered, but it somehow failed. Cancel the event.
event.setCancelled(true);
e.printStackTrace();
}
}
Aggregations