use of org.spongepowered.api.command.source.ConsoleSource in project Nucleus by NucleusPowered.
the class SingleKit method redeemKitCommands.
@Override
public void redeemKitCommands(Player player) {
ConsoleSource source = Sponge.getServer().getConsole();
String playerName = player.getName();
getCommands().forEach(x -> Sponge.getCommandManager().process(source, x.replace("{{player}}", playerName)));
}
use of org.spongepowered.api.command.source.ConsoleSource in project SpongeCommon by SpongePowered.
the class TimingsExport method run.
@Override
public void run() {
this.sender.sendMessage(Text.of(TextColors.GREEN, "Preparing Timings Report..."));
this.out.add("data", JSONUtil.mapArray(this.history, TimingHistory::export));
String response = null;
try {
String hostname = "localhost";
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (IOException e) {
SpongeImpl.getLogger().warn("Could not get own server hostname when uploading timings - falling back to 'localhost'", e);
}
HttpURLConnection con = (HttpURLConnection) new URL("http://timings.aikar.co/post").openConnection();
con.setDoOutput(true);
con.setRequestProperty("User-Agent", "Sponge/" + getServerName() + "/" + hostname);
con.setRequestMethod("POST");
con.setInstanceFollowRedirects(false);
OutputStream request = new GZIPOutputStream(con.getOutputStream()) {
{
this.def.setLevel(7);
}
};
request.write(JSONUtil.toString(this.out).getBytes("UTF-8"));
request.close();
response = getResponse(con);
if (con.getResponseCode() != 302) {
this.sender.sendMessage(Text.of(TextColors.RED, "Upload Error: " + con.getResponseCode() + ": " + con.getResponseMessage()));
this.sender.sendMessage(Text.of(TextColors.RED, "Check your logs for more information"));
if (response != null) {
SpongeImpl.getLogger().fatal(response);
}
return;
}
String location = con.getHeaderField("Location");
this.sender.sendMessage(Text.of(TextColors.GREEN, "View Timings Report: ", TextActions.openUrl(new URL(location)), location));
if (!(this.sender instanceof ConsoleSource)) {
SpongeImpl.getLogger().info("View Timings Report: " + location);
}
if (response != null && !response.isEmpty()) {
SpongeImpl.getLogger().info("Timing Response: " + response);
}
} catch (IOException ex) {
this.sender.sendMessage(Text.of(TextColors.RED, "Error uploading timings, check your logs for more information"));
if (response != null) {
SpongeImpl.getLogger().fatal(response);
}
SpongeImpl.getLogger().fatal("Could not paste timings", ex);
}
}
use of org.spongepowered.api.command.source.ConsoleSource in project LanternServer by LanternPowered.
the class CommandOp method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(new CommandElement(Text.of("player")) {
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
return args.next();
}
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
final String prefix = args.nextIfPresent().orElse("");
final UserConfig<OpsEntry> config = Lantern.getGame().getOpsConfig();
return Lantern.getGame().getGameProfileManager().getCache().getProfiles().stream().filter(p -> p.getName().isPresent() && !config.getEntryByUUID(p.getUniqueId()).isPresent()).map(p -> p.getName().get()).filter(new StartsWithPredicate(prefix)).collect(ImmutableList.toImmutableList());
}
}, GenericArguments.optional(GenericArguments.integer(Text.of("level")))).executor((src, args) -> {
String playerName = args.<String>getOne("player").get();
UserConfig<OpsEntry> config = Lantern.getGame().getOpsConfig();
if (!(src instanceof ConsoleSource) && args.hasAny("level")) {
throw new CommandException(Text.of("Only the console may specify the op level."));
}
int opLevel = args.<Integer>getOne("level").orElse(Lantern.getGame().getGlobalConfig().getDefaultOpPermissionLevel());
Lantern.getGame().getGameProfileManager().get(playerName).whenComplete((profile, error) -> {
if (error != null) {
src.sendMessage(t("commands.op.failed", playerName));
} else {
src.sendMessage(t("commands.op.success", playerName));
config.addEntry(new OpsEntry(((LanternGameProfile) profile).withoutProperties(), opLevel));
}
});
return CommandResult.success();
});
}
use of org.spongepowered.api.command.source.ConsoleSource in project Nucleus by NucleusPowered.
the class MessageHandler method sendMessage.
@Override
public boolean sendMessage(CommandSource sender, CommandSource receiver, String message) {
// Message is about to be sent. Send the event out. If canceled, then that's that.
boolean isBlocked = false;
boolean isCancelled = Sponge.getEventManager().post(new InternalNucleusMessageEvent(sender, receiver, message));
if (isCancelled) {
sender.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("message.cancel"));
// Only continue to show Social Spy messages if the subject is muted.
if (!messageConfig.isShowMessagesInSocialSpyWhileMuted()) {
return false;
}
}
// What about msgtoggle?
if (receiver instanceof Player && !sender.hasPermission(this.msgToggleBypass) && ucl.get((Player) receiver).map(x -> !x.get(MessageUserDataModule.class).isMsgToggle()).orElse(false)) {
isCancelled = true;
isBlocked = true;
sender.sendMessage(Nucleus.getNucleus().getMessageProvider().getTextMessageWithTextFormat("message.blocked", Nucleus.getNucleus().getNameUtil().getName((Player) receiver)));
if (!messageConfig.isShowMessagesInSocialSpyWhileMuted()) {
return false;
}
}
// Social Spies.
final UUID uuidSender = getUUID(sender);
final UUID uuidReceiver = getUUID(receiver);
final Map<String, Object> variables = Maps.newHashMap();
variables.put("from", sender);
variables.put("to", receiver);
// Create the tokens.
Map<String, Function<CommandSource, Optional<Text>>> tokens = Maps.newHashMap();
tokens.put("from", cs -> getNameFromCommandSource(sender, textParsingUtils::addCommandToName));
tokens.put("to", cs -> getNameFromCommandSource(receiver, textParsingUtils::addCommandToName));
tokens.put("fromdisplay", cs -> getNameFromCommandSource(sender, textParsingUtils::addCommandToDisplayName));
tokens.put("todisplay", cs -> getNameFromCommandSource(receiver, textParsingUtils::addCommandToDisplayName));
Text tm = useMessage(sender, message);
if (!isCancelled) {
sender.sendMessage(constructMessage(sender, tm, messageConfig.getMessageSenderPrefix(), tokens, variables));
receiver.sendMessage(constructMessage(sender, tm, messageConfig.getMessageReceiverPrefix(), tokens, variables));
}
NucleusTextTemplateImpl prefix = messageConfig.getMessageSocialSpyPrefix();
if (isBlocked) {
prefix = NucleusTextTemplateFactory.createFromAmpersandString(messageConfig.getBlockedTag() + prefix.getRepresentation());
}
if (isCancelled) {
prefix = NucleusTextTemplateFactory.createFromAmpersandString(messageConfig.getMutedTag() + prefix.getRepresentation());
}
MessageConfig.Targets targets = messageConfig.spyOn();
if (sender instanceof Player && targets.isPlayer() || sender instanceof ConsoleSource && targets.isCustom() || targets.isCustom()) {
Set<CommandSource> lm = onlinePlayersCanSpyOn(!uuidSender.equals(Util.consoleFakeUUID) && !uuidReceiver.equals(Util.consoleFakeUUID), sender, receiver);
MessageChannel mc = MessageChannel.fixed(lm);
if (!mc.getMembers().isEmpty()) {
mc.send(constructMessage(sender, tm, prefix, tokens, variables));
}
}
// Add the UUIDs to the reply list - the receiver will now reply to the sender.
if (!isCancelled) {
messagesReceived.put(uuidReceiver, uuidSender);
}
return !isCancelled;
}
use of org.spongepowered.api.command.source.ConsoleSource in project Nucleus by NucleusPowered.
the class BorderCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties wp = getWorldFromUserOrArgs(src, worldKey, args);
List<Text> worldBorderInfo = Lists.newArrayList();
Vector3d centre = wp.getWorldBorderCenter();
int currentDiameter = (int) wp.getWorldBorderDiameter();
int targetDiameter = (int) wp.getWorldBorderTargetDiameter();
// Border centre
worldBorderInfo.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.border.centre", String.valueOf(centre.getFloorX()), String.valueOf(centre.getFloorZ())));
worldBorderInfo.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.border.currentdiameter", String.valueOf(wp.getWorldBorderDiameter())));
if (currentDiameter != targetDiameter) {
worldBorderInfo.add(plugin.getMessageProvider().getTextMessageWithFormat("command.world.border.targetdiameter", String.valueOf(targetDiameter), String.valueOf(wp.getWorldBorderTimeRemaining() / 1000)));
}
PaginationList.Builder pb = Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().contents(worldBorderInfo).title(plugin.getMessageProvider().getTextMessageWithFormat("command.world.border.title", wp.getWorldName())).padding(Text.of(TextColors.GREEN, "="));
if (src instanceof ConsoleSource) {
pb.linesPerPage(-1);
}
pb.sendTo(src);
return CommandResult.success();
}
Aggregations