use of org.spongepowered.api.command.spec.CommandSpec in project PokexpMultiplier by happyzleaf.
the class PokexpMultiplier method init.
@Listener
public void init(GameInitializationEvent event) {
PlaceholderUtility.init();
PokexpConfig.getInstance().setup(configFile, configLoader);
Pixelmon.EVENT_BUS.register(this);
CommandSpec reload = CommandSpec.builder().executor((src, args) -> {
PokexpConfig.getInstance().loadConfig();
src.sendMessage(Text.of(TextColors.DARK_GREEN, "[" + PLUGIN_NAME + "]", TextColors.GREEN, " Config(s) reloaded!"));
return CommandResult.success();
}).description(Text.of("Reload configs.")).permission(PLUGIN_ID + ".admin.reload").build();
CommandSpec info = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.onlyOne(GenericArguments.player(Text.of("player"))), PLUGIN_ID + ".info.others"))).executor((src, args) -> {
if (args.hasAny("player")) {
Player player = (Player) args.getOne("player").get();
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(AlgorithmUtilities.parseInfoWithValues(player, AlgorithmUtilities.algorithmPerUser(player))));
return CommandResult.success();
} else {
if (src instanceof Player) {
src.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(AlgorithmUtilities.parseInfoWithValues((Player) src, AlgorithmUtilities.algorithmPerUser((Player) src))));
return CommandResult.success();
} else {
src.sendMessage(Text.of(TextColors.DARK_RED, "[" + PLUGIN_NAME + "]", TextColors.RED, " Your MUST be in-game in order to execute this command."));
return CommandResult.successCount(0);
}
}
}).permission(PLUGIN_ID + ".info.me").description(Text.of("Get the player's experience algorithm info.")).build();
CommandSpec pokexp = CommandSpec.builder().child(reload, "reload").child(info, "info").build();
Sponge.getGame().getCommandManager().register(this, pokexp, "pokexp", "pkexp");
// Just to check if the method works well
/*Sponge.getGame().getCommandManager().register(this, CommandSpec.builder()
.arguments(GenericArguments.onlyOne(GenericArguments.remainingJoinedStrings(Text.of("operation"))))
.executor(((src, args) -> {
src.sendMessage(Text.of(TextColors.GREEN, "result: " + AlgorithmUtilities.eval((String) args.getOne("operation").get())));
return CommandResult.success();
}))
.build(), "math");*/
LOGGER.info("Loaded!");
}
use of org.spongepowered.api.command.spec.CommandSpec in project TotalEconomy by Erigitic.
the class TotalEconomy method createAndRegisterCommands.
/**
* Create commands and registers them with the CommandManager
*/
private void createAndRegisterCommands() {
CommandSpec adminPayCommand = CommandSpec.builder().description(Text.of("Pay a player without removing money from your balance.")).permission("totaleconomy.command.adminpay").executor(new AdminPayCommand(this, accountManager, messageManager)).arguments(GenericArguments.user(Text.of("player")), GenericArguments.string(Text.of("amount")), GenericArguments.optional(GenericArguments.string(Text.of("currencyName")))).build();
CommandSpec balanceCommand = CommandSpec.builder().description(Text.of("Display your balance")).permission("totaleconomy.command.balance").executor(new BalanceCommand(this, accountManager, messageManager)).arguments(GenericArguments.optional(GenericArguments.string(Text.of("currencyName")))).build();
CommandSpec balanceTopCommand = CommandSpec.builder().description(Text.of("Display top balances")).permission("totaleconomy.command.balancetop").executor(new BalanceTopCommand(this, accountManager)).build();
CommandSpec payCommand = CommandSpec.builder().description(Text.of("Pay another player")).permission("totaleconomy.command.pay").executor(new PayCommand(this, accountManager, messageManager)).arguments(GenericArguments.player(Text.of("player")), GenericArguments.string(Text.of("amount")), GenericArguments.optional(GenericArguments.string(Text.of("currencyName")))).build();
CommandSpec setBalanceCommand = CommandSpec.builder().description(Text.of("Set a player's balance")).permission("totaleconomy.command.setbalance").executor(new SetBalanceCommand(this, accountManager, messageManager)).arguments(GenericArguments.user(Text.of("player")), GenericArguments.string(Text.of("amount")), GenericArguments.optional(GenericArguments.string(Text.of("currencyName")))).build();
CommandSpec viewBalanceCommand = CommandSpec.builder().description(Text.of("View the balance of another player")).permission("totaleconomy.command.viewbalance").executor(new ViewBalanceCommand(this, accountManager, messageManager)).arguments(GenericArguments.user(Text.of("player")), GenericArguments.optional(GenericArguments.string(Text.of("currencyName")))).build();
if (jobFeatureEnabled) {
game.getCommandManager().register(this, new JobCommand(this, accountManager, jobManager, messageManager).commandSpec(), "job");
}
if (chestShopEnabled) {
game.getCommandManager().register(this, new ShopCommand(this, accountManager, shopManager, messageManager).getCommandSpec(), "shop");
}
game.getCommandManager().register(this, payCommand, "pay");
game.getCommandManager().register(this, adminPayCommand, "adminpay");
game.getCommandManager().register(this, balanceCommand, "balance", "bal", "money");
game.getCommandManager().register(this, viewBalanceCommand, "viewbalance", "vbal");
game.getCommandManager().register(this, setBalanceCommand, "setbalance", "setbal");
game.getCommandManager().register(this, balanceTopCommand, "balancetop", "baltop");
}
use of org.spongepowered.api.command.spec.CommandSpec in project UltimateChat by FabioZumbi12.
the class UCCommands method uchat.
private CommandCallable uchat() {
CommandSpec msgtoggle = CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.requiringPermission(GenericArguments.player(Text.of("player")), "uchat.msgtoggle.others"))).description(Text.of("Disable private messages.")).permission("uchat.cmd.msgtoggle").executor((src, args) -> {
{
if (args.<Player>getOne("player").isPresent()) {
Player p = args.<Player>getOne("player").get();
if (UChat.get().msgTogglePlayers.contains(p.getName())) {
UChat.get().msgTogglePlayers.remove(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.enabled");
} else {
UChat.get().msgTogglePlayers.add(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.disabled");
}
return CommandResult.success();
}
if (src instanceof Player) {
Player p = (Player) src;
if (UChat.get().msgTogglePlayers.contains(p.getName())) {
UChat.get().msgTogglePlayers.remove(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.enabled");
} else {
UChat.get().msgTogglePlayers.add(p.getName());
UChat.get().getLang().sendMessage(p, "cmd.msgtoggle.disabled");
}
} else {
throw new CommandException(Text.of("Only players can use this command or add a player name as last argument."), true);
}
return CommandResult.success();
}
}).build();
CommandSpec delchannel = CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel"))).description(Text.of("Deletes a channel.")).permission("uchat.cmd.delchannel").executor((src, args) -> {
{
// uchat delchannel <channel>
Optional<UCChannel> optch = args.getOne("channel");
if (!optch.isPresent()) {
throw new CommandException(UChat.get().getLang().getText("channel.dontexist"), true);
}
UCChannel ch = optch.get();
List<String> toAdd = new ArrayList<>(ch.getMembers());
toAdd.forEach(m -> {
UChat.get().getDefChannel(src instanceof Player ? ((Player) src).getWorld().getName() : null).addMember(m);
// fire event
if (Sponge.getServer().getPlayer(m).isPresent()) {
PlayerChangeChannelEvent event = new PlayerChangeChannelEvent(Sponge.getServer().getPlayer(m).get(), null, UChat.get().getDefChannel(src instanceof Player ? ((Player) src).getWorld().getName() : null));
Sponge.getEventManager().post(event);
}
});
UChat.get().getConfig().delChannel(ch);
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("cmd.delchannel.success").replace("{channel}", ch.getName()));
return CommandResult.success();
}
}).build();
CommandSpec newchannel = CommandSpec.builder().arguments(GenericArguments.string(Text.of("channel")), GenericArguments.string(Text.of("alias")), GenericArguments.string(Text.of("color"))).description(Text.of("Creates a new channel channel.")).permission("uchat.cmd.newchannel").executor((src, args) -> {
{
// uchat newchannel <channel> <alias> <color>
String ch = args.<String>getOne("channel").get();
String alias = args.<String>getOne("alias").get();
String color = args.<String>getOne("color").get();
if (color.length() != 2 || !color.matches("(&([a-fk-or0-9]))$")) {
throw new CommandException(UChat.get().getLang().getText("channel.invalidcolor"), true);
}
UCChannel newch = new UCChannel(ch, alias, color);
try {
UChat.get().getConfig().addChannel(newch);
registerChannelAliases();
} catch (Exception e) {
e.printStackTrace();
}
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("cmd.newchannel.success").replace("{channel}", newch.getName()));
return CommandResult.success();
}
}).build();
CommandSpec chconfig = CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel")), GenericArguments.choices(Text.of("key"), getChKeys()), GenericArguments.string(Text.of("value"))).description(Text.of("Edit the config of a channel.")).permission("uchat.cmd.chconfig").executor((src, args) -> {
{
// uchat chconfig <channel> <key> <value>
Optional<UCChannel> optch = args.getOne("channel");
if (!optch.isPresent()) {
throw new CommandException(UChat.get().getLang().getText("channel.dontexist"), true);
}
UCChannel ch = optch.get();
String key = args.<String>getOne("key").get();
String value = args.<String>getOne("value").get();
if (!ch.getProperties().containsKey(key)) {
throw new CommandException(UChat.get().getLang().getText("cmd.chconfig.invalidkey"), true);
}
UChat.get().getConfig().delChannel(ch);
ch.setProperty(key, value);
try {
UChat.get().getConfig().addChannel(ch);
} catch (Exception e) {
e.printStackTrace();
}
UChat.get().getLang().sendMessage(src, "cmd.chconfig.success");
return CommandResult.success();
}
}).build();
CommandSpec reload = CommandSpec.builder().description(Text.of("Command to reload uchat.")).permission("uchat.cmd.reload").executor((src, args) -> {
{
// uchat reload
try {
UChat.get().reload();
UChat.get().getLang().sendMessage(src, "plugin.reloaded");
} catch (Exception e) {
e.printStackTrace();
}
return CommandResult.success();
}
}).build();
CommandSpec clear = CommandSpec.builder().description(Text.of("Clear your chat.")).permission("uchat.cmd.clear").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat clear
for (int i = 0; i < 100; i++) {
p.sendMessage(Text.of(" "));
}
UChat.get().getLang().sendMessage(src, "cmd.clear.cleared");
}
return CommandResult.success();
}
}).build();
CommandSpec clearAll = CommandSpec.builder().description(Text.of("Clear the chat of all online players.")).permission("uchat.cmd.clear-all").executor((src, args) -> {
{
// uchat clear-all
for (Player play : Sponge.getServer().getOnlinePlayers()) {
for (int i = 0; i < 100; i++) {
if (!play.isOnline()) {
continue;
}
play.sendMessage(Text.of(" "));
}
}
return CommandResult.success();
}
}).build();
CommandSpec spy = CommandSpec.builder().description(Text.of("Turn on the social spy.")).permission("uchat.cmd.spy").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat spy
if (!UChat.get().isSpy.contains(p.getName())) {
UChat.get().isSpy.add(p.getName());
UChat.get().getLang().sendMessage(src, "cmd.spy.enabled");
} else {
UChat.get().isSpy.remove(p.getName());
UChat.get().getLang().sendMessage(src, "cmd.spy.disabled");
}
}
return CommandResult.success();
}
}).build();
CommandSpec ignorePlayer = CommandSpec.builder().arguments(GenericArguments.player(Text.of("player"))).description(Text.of("Ignore a player.")).permission("uchat.cmd.ignore.player").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat ignore player
Player pi = args.<Player>getOne("player").get();
if (pi.equals(p)) {
throw new CommandException(UChat.get().getLang().getText("cmd.ignore.self"), true);
}
if (!UChat.get().getPerms().canIgnore(p, pi)) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.cantignore"));
return CommandResult.success();
}
if (UCMessages.isIgnoringPlayers(p.getName(), pi.getName())) {
UCMessages.unIgnorePlayer(p.getName(), pi.getName());
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("player.unignoring").replace("{player}", pi.getName()));
} else {
UCMessages.ignorePlayer(p.getName(), pi.getName());
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("player.ignoring").replace("{player}", pi.getName()));
}
}
return CommandResult.success();
}
}).build();
CommandSpec ignoreChannel = CommandSpec.builder().arguments(new ChannelCommandElement(Text.of("channel"))).description(Text.of("Ignore a channel.")).permission("uchat.cmd.ignore.channel").executor((src, args) -> {
{
if (src instanceof Player) {
Player p = (Player) src;
// uchat ignore channel
Optional<UCChannel> optch = args.getOne("channel");
if (!optch.isPresent()) {
throw new CommandException(UChat.get().getLang().getText("channel.dontexist"), true);
}
UCChannel ch = optch.get();
if (!UChat.get().getPerms().canIgnore(p, ch)) {
UChat.get().getLang().sendMessage(p, UChat.get().getLang().get("chat.cantignore"));
return CommandResult.success();
}
if (ch.isIgnoring(p.getName())) {
ch.unIgnoreThis(p.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.notignoring").replace("{channel}", ch.getName()));
} else {
ch.ignoreThis(p.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.ignoring").replace("{channel}", ch.getName()));
}
}
return CommandResult.success();
}
}).build();
CommandSpec mute = CommandSpec.builder().arguments(GenericArguments.player(Text.of("player")), GenericArguments.optional(new ChannelCommandElement(Text.of("channel")))).description(Text.of("Mute a player.")).permission("uchat.cmd.mute").executor((src, args) -> {
{
// uchat mute player channel
Player play = args.<Player>getOne("player").get();
if (args.<UCChannel>getOne("channel").isPresent()) {
UCChannel ch = args.<UCChannel>getOne("channel").get();
if (ch.isMuted(play.getName())) {
ch.unMuteThis(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.unmuted.this").replace("{player}", play.getName()).replace("{channel}", ch.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, UChat.get().getLang().get("channel.player.unmuted.this").replace("{channel}", ch.getName()));
}
} else {
ch.muteThis(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.muted.this").replace("{player}", play.getName()).replace("{channel}", ch.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, UChat.get().getLang().get("channel.player.muted.this").replace("{channel}", ch.getName()));
}
}
} else {
if (UChat.get().mutes.contains(play.getName())) {
UChat.get().mutes.remove(play.getName());
UChat.get().unMuteInAllChannels(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.unmuted.all").replace("{player}", play.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, "channel.player.unmuted.all");
}
} else {
UChat.get().mutes.add(play.getName());
UChat.get().muteInAllChannels(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.muted.all").replace("{player}", play.getName()));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, "channel.player.muted.all");
}
}
}
return CommandResult.success();
}
}).build();
CommandSpec tempmute = CommandSpec.builder().arguments(GenericArguments.integer(Text.of("time")), GenericArguments.player(Text.of("player"))).description(Text.of("Temporary mute a player.")).permission("uchat.cmd.tempmute").executor((src, args) -> {
{
// uchat tempmute time player
Player play = args.<Player>getOne("player").get();
int time = args.<Integer>getOne("time").get();
if (UChat.get().mutes.contains(play.getName())) {
UChat.get().getLang().sendMessage(src, "channel.already.muted");
} else {
UChat.get().mutes.add(play.getName());
UChat.get().muteInAllChannels(play.getName());
UChat.get().getLang().sendMessage(src, UChat.get().getLang().get("channel.tempmuted.all").replace("{player}", play.getName()).replace("{time}", String.valueOf(time)));
if (play.isOnline()) {
UChat.get().getLang().sendMessage(play, UChat.get().getLang().get("channel.player.tempmuted.all").replace("{time}", String.valueOf(time)));
}
// mute counter
Task.builder().execute(new MuteCountDown(play.getName(), time)).interval(1, TimeUnit.SECONDS).name("Mute Counter").submit(UChat.get().instance());
}
return CommandResult.success();
}
}).build();
CommandSpec help = CommandSpec.builder().description(Text.of("Se help about commands.")).executor((src, args) -> {
{
sendHelp(src);
return CommandResult.success();
}
}).build();
// uchat <args...>
return CommandSpec.builder().description(Text.of("Main command for uchat.")).executor((src, args) -> {
{
// no args
src.sendMessage(UCUtil.toText("&b---------------- " + UChat.get().instance().getName() + " " + UChat.get().instance().getVersion().get() + " ---------------"));
src.sendMessage(UCUtil.toText("&bDeveloped by &6" + UChat.get().instance().getAuthors().get(0) + "."));
src.sendMessage(UCUtil.toText("&bFor more information about the commands, type [" + "&6/uchat ?&b]."));
src.sendMessage(UCUtil.toText("&b---------------------------------------------------"));
return CommandResult.success();
}
}).child(help, "?").child(chconfig, "chconfig").child(delchannel, "delchannel").child(newchannel, "newchannel").child(reload, "reload").child(clear, "clear").child(clearAll, "clear-all").child(spy, "spy").child(CommandSpec.builder().child(ignorePlayer, "player").child(ignoreChannel, "channel").build(), "ignore").child(mute, "mute").child(tempmute, "tempmute").child(msgtoggle, "msgtoggle").build();
}
Aggregations