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);
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class MetaTest method testScriptas.
@Test
public void testScriptas() throws Exception {
String script = "scriptas('Player02', 'newlabel', msg(reflect_pull('label'))); msg(reflect_pull('label'))";
MCPlayer fakePlayer2 = GetOnlinePlayer("Player02", fakeServer);
when(fakeServer.getPlayer("Player02")).thenReturn(fakePlayer2);
MethodScriptCompiler.execute(MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, null, true)), env, null, null);
verify(fakePlayer2).sendMessage("newlabel");
verify(fakePlayer).sendMessage("*");
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class AbstractEvent method execute.
/**
* This function is run when the actual event occurs.
*
* @param tree The compiled parse tree
* @param b The bound event
* @param env The operating environment
* @param activeEvent The active event being executed
*/
@Override
public final void execute(ParseTree tree, BoundEvent b, Environment env, BoundEvent.ActiveEvent activeEvent) throws ConfigRuntimeException {
preExecution(env, activeEvent);
// Various events have a player to put into the env.
// Do this after preExcecution() in case the particular event needs to inject the player first.
Construct c = activeEvent.getParsedEvent().get("player");
if (c != null) {
try {
MCPlayer p = Static.GetPlayer(c, Target.UNKNOWN);
env.getEnv(CommandHelperEnvironment.class).SetPlayer(p);
} catch (CREPlayerOfflineException e) {
// Set env CommandSender to prevent incorrect inherited player from being used in a player event.
if (env.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
env.getEnv(CommandHelperEnvironment.class).SetCommandSender(Static.getServer().getConsole());
}
}
}
ProfilePoint event = null;
if (env.getEnv(GlobalEnv.class).GetProfiler() != null) {
event = env.getEnv(GlobalEnv.class).GetProfiler().start("Event " + b.getEventName() + " (defined at " + b.getTarget().toString() + ")", LogLevel.ERROR);
}
try {
try {
// Get the label from the bind time environment, and put it in the current environment.
String label = b.getEnvironment().getEnv(GlobalEnv.class).GetLabel();
if (label == null) {
// Set the permission to global if it's null, since that means
// it wasn't set, and so we aren't in a secured environment anyways.
label = Static.GLOBAL_PERMISSION;
}
env.getEnv(GlobalEnv.class).SetLabel(label);
MethodScriptCompiler.execute(tree, env, null, null);
} catch (CancelCommandException ex) {
if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
StreamUtils.GetSystemOut().println(ex.getMessage());
}
} catch (FunctionReturnException ex) {
// We simply allow this to end the event execution
} catch (ProgramFlowManipulationException ex) {
ConfigRuntimeException.HandleUncaughtException(new CREFormatException("Unexpected control flow operation used.", ex.getTarget()), env);
}
} finally {
if (event != null) {
event.stop();
}
// Finally, among other things, we need to clean-up injected players and entities
postExecution(env, activeEvent);
}
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class BukkitMCServer method getOnlinePlayers.
@Override
public Collection<MCPlayer> getOnlinePlayers() {
Collection<? extends Player> players = s.getOnlinePlayers();
Set<MCPlayer> mcpa = new HashSet<>();
for (Player p : players) {
mcpa.add(new BukkitMCPlayer(p));
}
return mcpa;
}
use of com.laytonsmith.abstraction.MCPlayer in project CommandHelper by EngineHub.
the class MetaTest method testRunas1.
@Test(timeout = 10000)
public void testRunas1() throws Exception {
String script = "runas('Player02', '/cmd yay')";
MCPlayer fakePlayer2 = GetOnlinePlayer("Player02", fakeServer);
when(fakeServer.getPlayer("Player02")).thenReturn(fakePlayer2);
when(fakePlayer.isOp()).thenReturn(true);
MethodScriptCompiler.execute(MethodScriptCompiler.compile(MethodScriptCompiler.lex(script, null, true)), env, null, null);
// verify(fakePlayer2).performCommand("cmd yay");
verify(fakeServer).dispatchCommand(fakePlayer2, "cmd yay");
}
Aggregations