use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class Script method enforceLabelPermissions.
public void enforceLabelPermissions() {
String label = CurrentEnv.getEnv(GlobalEnv.class).GetLabel();
if (label == null || label.equals(Static.GLOBAL_PERMISSION)) {
return;
}
MCPlayer p = CurrentEnv.getEnv(CommandHelperEnvironment.class).GetPlayer();
if (p == null) {
// labels only apply to players
CurrentEnv.getEnv(GlobalEnv.class).SetLabel(Static.GLOBAL_PERMISSION);
} else if (label.startsWith("~")) {
// group labels
String[] groups = label.substring(1).split("/");
for (String group : groups) {
if (group.startsWith("-") && p.inGroup(group.substring(1))) {
// negative permission
throw new CREInsufficientPermissionException("You do not have permission to use that script.", Target.UNKNOWN);
} else if (p.inGroup(group)) {
// they have explicit permission.
CurrentEnv.getEnv(GlobalEnv.class).SetLabel(Static.GLOBAL_PERMISSION);
return;
}
}
} else if (label.indexOf('.') != -1) {
// custom permission label
if (p.hasPermission(label)) {
CurrentEnv.getEnv(GlobalEnv.class).SetLabel(Static.GLOBAL_PERMISSION);
}
} else if (p.hasPermission("ch.alias." + label) || p.hasPermission("commandhelper.alias." + label)) {
CurrentEnv.getEnv(GlobalEnv.class).SetLabel(Static.GLOBAL_PERMISSION);
}
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class CommandHelperInterpreterListener method onPlayerChat.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(final AsyncPlayerChatEvent event) {
if (interpreterMode.contains(event.getPlayer().getName())) {
final MCPlayer p = new BukkitMCPlayer(event.getPlayer());
event.setCancelled(true);
StaticLayer.SetFutureRunnable(null, 0, new Runnable() {
@Override
public void run() {
textLine(p, event.getMessage());
}
});
}
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class AliasCore method alias.
/**
* This is the workhorse function. It takes a given command, then converts it into the actual command(s). If the
* command maps to a defined alias, it will run the specified alias. It will search through the global list of
* aliases, as well as the aliases defined for that specific player. This function doesn't handle the /alias command
* however.
*
* @param command
* @return
*/
public boolean alias(String command, final MCCommandSender player) {
if (scripts == null) {
throw ConfigRuntimeException.CreateUncatchableException("Cannot run alias commands, no config file is loaded", Target.UNKNOWN);
}
boolean match = false;
try {
// actually add the player to the array.
if (player != null && player instanceof MCPlayer && echoCommand.contains(((MCPlayer) player).getName())) {
// we are running one of the expanded commands, so exit with false
return false;
}
for (Script s : scripts) {
try {
if (s.match(command)) {
this.addPlayerReference(player);
if (Prefs.ConsoleLogCommands() && s.doLog()) {
StringBuilder b = new StringBuilder("CH: Running original command ");
if (player instanceof MCPlayer) {
b.append("on player ").append(((MCPlayer) player).getName());
} else {
b.append("from a MCCommandSender");
}
b.append(" ----> ").append(command);
Static.getLogger().log(Level.INFO, b.toString());
}
GlobalEnv gEnv = new GlobalEnv(parent.executionQueue, parent.profiler, parent.persistenceNetwork, MethodScriptFileLocations.getDefault().getConfigDirectory(), parent.profiles, new TaskManager());
CommandHelperEnvironment cEnv = new CommandHelperEnvironment();
cEnv.SetCommandSender(player);
Environment env = Environment.createEnvironment(gEnv, cEnv);
try {
env.getEnv(CommandHelperEnvironment.class).SetCommand(command);
ProfilePoint alias = env.getEnv(GlobalEnv.class).GetProfiler().start("Global Alias - \"" + command + "\"", LogLevel.ERROR);
try {
s.run(s.getVariables(command), env, new MethodScriptComplete() {
@Override
public void done(String output) {
try {
if (output != null) {
if (!output.trim().isEmpty() && output.trim().startsWith("/")) {
if (Prefs.DebugMode()) {
if (player instanceof MCPlayer) {
Static.getLogger().log(Level.INFO, "[CommandHelper]: Executing command on " + ((MCPlayer) player).getName() + ": " + output.trim());
} else {
Static.getLogger().log(Level.INFO, "[CommandHelper]: Executing command from console equivalent: " + output.trim());
}
}
if (player instanceof MCPlayer) {
((MCPlayer) player).chat(output.trim());
} else {
Static.getServer().dispatchCommand(player, output.trim().substring(1));
}
}
}
} catch (Throwable e) {
StreamUtils.GetSystemErr().println(e.getMessage());
player.sendMessage(MCChatColor.RED + e.getMessage());
} finally {
Static.getAliasCore().removePlayerReference(player);
}
}
});
} finally {
alias.stop();
}
} catch (ConfigRuntimeException ex) {
ex.setEnv(env);
ConfigRuntimeException.HandleUncaughtException(ex, env);
} catch (Throwable e) {
// This is not a simple user script error, this is a deeper problem, so we always handle this.
StreamUtils.GetSystemErr().println("An unexpected exception occured: " + e.getClass().getSimpleName());
player.sendMessage("An unexpected exception occured: " + MCChatColor.RED + e.getClass().getSimpleName());
e.printStackTrace();
} finally {
Static.getAliasCore().removePlayerReference(player);
}
match = true;
break;
}
} catch (Exception e) {
StreamUtils.GetSystemErr().println("An unexpected exception occured inside the command " + s.toString());
e.printStackTrace();
}
}
} catch (Throwable e) {
// Not only did an error happen, an error happened in our error handler
throw new InternalException(TermColors.RED + "An unexpected error occured in the CommandHelper plugin. " + "Further, this is likely an error with the error handler, so it may be caused by your script, " + "however, there is no more information at this point. Check your script, but also report this " + "as a bug in CommandHelper. Also, it's possible that some commands will no longer work. As a temporary " + "workaround, restart the server, and avoid doing whatever it is you did to make this happen.\nThe error is as follows: " + e.toString() + "\n" + TermColors.reset() + "Stack Trace:\n" + StringUtils.Join(Arrays.asList(e.getStackTrace()), "\n"));
}
return match;
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class BukkitEntityListener method onTargetLiving.
@EventIdentifier(event = Driver.TARGET_ENTITY, className = "org.bukkit.event.entity.EntityTargetEvent")
public void onTargetLiving(Event event) {
BukkitMCTargetEvent ete = new BukkitMCTargetEvent(event);
MCEntity target = ete.getTarget();
if (target == null || !(target instanceof MCPlayer)) {
return;
}
EventUtils.TriggerListener(Driver.TARGET_ENTITY, "target_player", ete);
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class BukkitMCPluginMeta method sendIncomingMessage0.
@Override
protected void sendIncomingMessage0(MCPlayer player, String channel, byte[] message) {
Player p = ((BukkitMCPlayer) player)._Player();
Bukkit.getMessenger().dispatchIncomingMessage(p, channel, message);
}
Aggregations