org.spongepowered.api.command.CommandSource Java Examples

The following examples show how to use org.spongepowered.api.command.CommandSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CitizenNameElement.java    From Nations with MIT License 6 votes vote down vote up
@Override
protected Iterable<String> getChoices(CommandSource src)
{
	if (!(src instanceof Player))
	{
		return Collections.emptyList();
	}
	Player player = (Player) src;
	Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
	if (nation == null)
	{
		return Collections.emptyList();
	}
	return nation
			.getCitizens()
			.stream()
			.map(uuid -> DataHandler.getPlayerName(uuid))
			.collect(Collectors.toList());
}
 
Example #2
Source File: SetTimeCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, TimePermissions.UC_TIME_TIME_TICKS);

    World world;
    if (!args.hasAny("world")) {
        checkIfPlayer(sender);
        world = ((Player) sender).getWorld();
    } else {
        world = args.<World>getOne("world").get();
    }

    Integer ticks = args.<Integer>getOne("time").get();
    world.getProperties().setWorldTime(ticks);
    Messages.send(sender, "time.command.time.set.ticks", "%ticks%", ticks);
    return CommandResult.success();
}
 
Example #3
Source File: WorldsBase.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		player.getWorld().getProperties().setSpawnPosition(player.getLocation().getBlockPosition());
		src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "World spawn set."));
	}
	else if (src instanceof ConsoleSource || src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /world setspawn!"));
	}

	return CommandResult.success();
}
 
Example #4
Source File: TopCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    checkIfPlayer(src);
    Player p = (Player) src;

    Location<World> top = LocationUtil.getHighestLoc(p.getLocation()).orElse(null);
    if (top == null) {
        throw Messages.error(src, "teleport.command.top.fail");
    }

    //Found suitable location
    Teleportation request = UltimateCore.get().getTeleportService().createTeleportation(p, Arrays.asList(p), new Transform<>(top, p.getRotation(), p.getScale()), teleportRequest -> {
        //Complete
        Messages.send(p, "teleport.command.top.success");
    }, (teleportRequest, reason) -> {
    }, true, false);
    request.start();
    return CommandResult.success();

}
 
Example #5
Source File: CmdBlockUpdatesStop.java    From Web-API with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<BlockOperation> op = args.getOne("uuid");
    if (!op.isPresent()) {
        src.sendMessage(Text.builder("Invalid block operation uuid!")
                .color(TextColors.DARK_RED)
                .build());
        return CommandResult.empty();
    }

    op.get().stop(null);
    src.sendMessage(Text.builder("Successfully cancelled block operation")
            .color(TextColors.DARK_GREEN)
            .build());
    return CommandResult.success();
}
 
Example #6
Source File: CommandUnseparate.java    From GriefPrevention with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    final User targetPlayer = args.<User>getOne("player1").get();
    final User targetPlayer2 = args.<User>getOne("player2").get();
    GriefPreventionPlugin.instance.setIgnoreStatus(player.getWorld(), targetPlayer, targetPlayer2, IgnoreMode.None);
    GriefPreventionPlugin.instance.setIgnoreStatus(player.getWorld(), targetPlayer2, targetPlayer, IgnoreMode.None);
    GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.playerUnseparate.toText());
    return CommandResult.success();
}
 
Example #7
Source File: NationadminDeleteExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("nation").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na delete <nation>"));
		return CommandResult.success();
	}
	String nationName = ctx.<String>getOne("nation").get();
	Nation nation = DataHandler.getNation(nationName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADNATIONNAME));
		return CommandResult.success();
	}
	DataHandler.removeNation(nation.getUUID());
	MessageChannel.TO_ALL.send(Text.of(TextColors.AQUA, LanguageHandler.INFO_NATIONFALL.replaceAll("\\{NATION\\}", nation.getName())));
	return CommandResult.success();
}
 
Example #8
Source File: SubCommand.java    From SubServers-2 with Apache License 2.0 6 votes vote down vote up
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    if (canRun(sender)) {
        Optional<String> subcommand = args.getOne(Text.of("subcommand"));
        if (subcommand.isPresent()) {
            sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Subcommand").replace("$str$", subcommand.get())));
            return CommandResult.builder().successCount(0).build();
        } else {
            if (sender.hasPermission("subservers.interface") && sender instanceof Player && plugin.gui != null) {
                plugin.gui.getRenderer((Player) sender).newUI();
            } else {
                sender.sendMessages(printHelp());
            }
            return CommandResult.builder().successCount(1).build();
        }
    } else {
        sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
        return CommandResult.builder().successCount(0).build();
    }
}
 
Example #9
Source File: VirtualSetCommand.java    From EconomyLite with MIT License 6 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    if (args.getOne("account").isPresent() && args.getOne("amount").isPresent()) {
        String target = args.<String>getOne("account").get();
        BigDecimal newBal = BigDecimal.valueOf(args.<Double>getOne("amount").get());
        Optional<Account> aOpt = EconomyLite.getEconomyService().getOrCreateAccount(target);
        if (aOpt.isPresent()) {
            Account targetAccount = aOpt.get();
            if (targetAccount.setBalance(EconomyLite.getCurrencyService().getCurrentCurrency(), newBal,
                    Cause.of(EventContext.empty(), (EconomyLite.getInstance()))).getResult().equals(ResultType.SUCCESS)) {
                src.sendMessage(messageStorage.getMessage("command.econ.setsuccess", "name", targetAccount.getDisplayName().toPlain()));
            } else {
                src.sendMessage(messageStorage.getMessage("command.econ.setfail", "name", targetAccount.getDisplayName().toPlain()));
            }
        } else {
            src.sendMessage(messageStorage.getMessage("command.error"));
        }
    } else {
        src.sendMessage(messageStorage.getMessage("command.error"));
    }
}
 
Example #10
Source File: VersionCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    try
    {
        source.sendMessage(Text.of(
                TextActions.showText(Text.of(TextColors.BLUE, "Click to view Github")),
                TextActions.openUrl(new URL("https://github.com/Aquerr/EagleFactions")),
                PluginInfo.PLUGIN_PREFIX, TextColors.AQUA, PluginInfo.NAME, TextColors.WHITE, " - ", TextColors.GOLD, Messages.VERSION + " ", PluginInfo.VERSION, TextColors.WHITE, " made by ", TextColors.GOLD, PluginInfo.AUTHOR));
    }
    catch(final MalformedURLException e)
    {
        e.printStackTrace();
    }
    return CommandResult.success();
}
 
Example #11
Source File: DeafCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, DeafPermissions.UC_DEAF_DEAF_BASE);
    Player t = args.<Player>getOne("player").get();
    Long time = args.hasAny("time") ? args.<Long>getOne("time").get() : -1L;
    Text reason = args.hasAny("reason") ? Text.of(args.<String>getOne("reason").get()) : Messages.getFormatted("deaf.command.deaf.defaultreason");

    if ((DeafPermissions.UC_DEAF_EXEMPTPOWER.getIntFor(t) > DeafPermissions.UC_DEAF_POWER.getIntFor(sender)) && sender instanceof Player) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "deaf.command.deaf.exempt", "%player%", t));
    }

    Long endtime = time == -1L ? -1L : System.currentTimeMillis() + time;
    Long starttime = System.currentTimeMillis();
    UUID deafr = sender instanceof Player ? ((Player) sender).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000");
    UUID deafd = t.getUniqueId();

    Deaf deaf = new Deaf(deafd, deafr, endtime, starttime, reason);
    UltimateUser ut = UltimateCore.get().getUserService().getUser(t);
    ut.offer(DeafKeys.DEAF, deaf);

    Messages.send(sender, "deaf.command.deaf.success", "%player%", VariableUtil.getNameEntity(t), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason);
    Messages.send(t, "deaf.deafed", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason);
    return CommandResult.success();
}
 
Example #12
Source File: UnmuteExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	Player p = ctx.<Player> getOne("player").get();

	if (EssentialCmds.muteList.remove(p.getUniqueId()))
	{
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player un-muted."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "This player is not muted."));
	}

	Utils.removeMute(p.getUniqueId());
}
 
Example #13
Source File: TeleportdenyCommand.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkIfPlayer(sender);
    checkPermission(sender, TeleportPermissions.UC_TELEPORT_TELEPORTDENY_BASE);
    Player p = (Player) sender;

    //Find request
    String id = args.hasAny("tpid") ? args.<String>getOne("tpid").get() : null;
    List<TpaRequest> requests = TeleportUtil.getRequestsFor(p, id);
    if (requests.isEmpty()) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "teleport.command.teleportdeny.none"));
    }
    requests.forEach(request -> request.getTeleportation().cancel("tpdeny"));
    requests = requests.stream().filter(request -> request.getAskerPlayer().isPresent()).collect(Collectors.toList());

    Messages.send(sender, "teleport.command.teleportdeny.success", "%player%", requests.get(0).getAskerPlayer().get());
    return CommandResult.success();
}
 
Example #14
Source File: LastLoginCommand.java    From FlexibleLogin with MIT License 6 votes vote down vote up
private void onAccLoaded(UUID src, Account account) {
    CommandSource receiver = Sponge.getServer().getConsole();
    if (src != null) {
        Optional<Player> player = Sponge.getServer().getPlayer(src);
        if (!player.isPresent()) {
            return;
        }

        receiver = player.get();
    }

    if (account == null) {
        receiver.sendMessage(settings.getText().getAccountNotFound());
    } else {
        String username = account.getUsername().orElseGet(() -> account.getId().toString());
        String timeFormat = timeFormatter.withLocale(receiver.getLocale()).format(account.getLastLogin());
        Text message = settings.getText().getLastOnline(username, timeFormat);
        receiver.sendMessage(message);
    }
}
 
Example #15
Source File: NickExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Player player = ctx.<Player>getOne("player").get();
	String nick = ctx.<String>getOne("nick").get();

	if (src instanceof Player && ((Player) src).getUniqueId() != player.getUniqueId() && src.hasPermission("essentialcmds.nick.others"))
	{
		Utils.setNick(nick, player.getUniqueId());
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Nick successfully set!"));
	}
	else if (src instanceof Player && ((Player) src).getUniqueId() != player.getUniqueId())
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You do not have permission to make changes to other player's nicknames.!"));
	}
	else
	{
		Utils.setNick(nick, player.getUniqueId());
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Nick successfully set!"));
	}

	return CommandResult.success();
}
 
Example #16
Source File: BoundedDoubleArgument.java    From UltimateCore with MIT License 6 votes vote down vote up
@Nullable
@Override
public Double parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String value = args.next();
    if (!ArgumentUtil.isDouble(value)) {
        throw args.createError(Messages.getFormatted("core.number.invalid", "%number%", value));
    }
    Double num = Double.parseDouble(value);
    if (max != null && num > max) {
        throw args.createError(Messages.getFormatted("core.number.toohigh", "%number%", value));
    }
    if (min != null && num < min) {
        throw args.createError(Messages.getFormatted("core.number.toolow", "%number%", value, "%min%", min));
    }
    return num;
}
 
Example #17
Source File: TPADenyExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Player sender = null;

		PendingInvitation cancel = null;

		for (PendingInvitation invitation : EssentialCmds.pendingInvites)
		{
			if (invitation.recipient == player)
			{
				sender = invitation.sender;
				cancel = invitation;
				break;
			}
		}

		if (cancel != null && sender != null)
		{
			sender.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Your TPA Request was Denied by " + player.getName() + "!"));
			EssentialCmds.pendingInvites.remove(cancel);
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.WHITE, "TPA Request Denied."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Pending TPA request not found!"));
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpadeny!"));
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpadeny!"));
	}
	return CommandResult.success();
}
 
Example #18
Source File: ChangeSkinSponge.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void sendMessage(CommandSource receiver, String key) {
    String message = core.getMessage(key);
    if (message != null && receiver != null) {
        receiver.sendMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(message));
    }
}
 
Example #19
Source File: NationCitizenExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("player").isPresent())
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDPLAYERNAME));
		return CommandResult.success();
	}
	String name = ctx.<String>getOne("player").get();
	src.sendMessage(Utils.formatCitizenDescription(name));
	return CommandResult.success();
}
 
Example #20
Source File: UuidVariable.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public Optional<Text> getValue(@Nullable Object player) {
    if (player instanceof CommandSource) {
        return Optional.of(Text.of(((CommandSource) player).getIdentifier()));
    } else if (player instanceof User) {
        return Optional.of(Text.of(((User) player).getIdentifier()));
    }
    return Optional.empty();
}
 
Example #21
Source File: GriefPreventionPlugin.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onGameReload(GameReloadEvent event) {
    this.loadConfig();
    if (event.getSource() instanceof CommandSource) {
        sendMessage((CommandSource) event.getSource(), this.messageData.pluginReload.toText());
    }
}
 
Example #22
Source File: CommandClaimInherit.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) {
    Player player;
    try {
        player = GriefPreventionPlugin.checkPlayer(src);
    } catch (CommandException e) {
        src.sendMessage(e.getText());
        return CommandResult.success();
    }

    final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    final Text result = claim.allowEdit(player);
    if (result != null) {
        GriefPreventionPlugin.sendMessage(player, result);
        return CommandResult.success();
    }

    if (claim.parent == null) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.commandInherit.toText());
        return CommandResult.success();
    }
    claim.getData().setInheritParent(!claim.getData().doesInheritParent());
    claim.getInternalClaimData().setRequiresSave(true);

    if (!claim.getData().doesInheritParent()) {
        GriefPreventionPlugin.sendMessage(player, Text.of(TextColors.WHITE, "Parent claim inheritance ", TextColors.RED, "OFF"));
    } else {
        GriefPreventionPlugin.sendMessage(player, Text.of(TextColors.WHITE, "Parent claim inheritance ", TextColors.GREEN, "ON"));
    }

    return CommandResult.success();
}
 
Example #23
Source File: DirectionExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		// Credit to kenzierocks for the following line. =D
		player.sendMessage(Text.of(TextColors.GOLD, "You are facing: ", TextColors.GRAY, Direction.getClosest(player.getTransform().getRotationAsQuaternion().getDirection()).toString()));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /direction!"));
	}
	
	return CommandResult.success();
}
 
Example #24
Source File: NationChatExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			player.setMessageChannel(MessageChannel.TO_ALL);
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		NationMessageChannel channel = nation.getMessageChannel();

		if (!ctx.<String>getOne("msg").isPresent())
		{
			if (player.getMessageChannel().equals(channel)) {
				player.setMessageChannel(MessageChannel.TO_ALL);
				src.sendMessage(Text.of(TextColors.YELLOW, LanguageHandler.INFO_NATIONCHAT_OFF));
			} else {
				player.setMessageChannel(channel);
				src.sendMessage(Text.of(TextColors.YELLOW, LanguageHandler.INFO_NATIONCHATON_ON));
			}
		}
		else
		{
			Text header = TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(player.getUniqueId())));
			
			Text msg = Text.of(header, TextColors.RESET, player.getName(), TextColors.WHITE, ": ", TextColors.YELLOW, ctx.<String>getOne("msg").get());
			channel.send(player, msg);
			DataHandler.getSpyChannel().send(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, msg));
		}

	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #25
Source File: SetuppermissionsUltimatecoreCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    PermissionLevel level = args.<PermissionLevel>getOne("level").get();
    Subject group = args.<Subject>getOne("group").get();

    //For each permission, grant if level is equal
    for (Permission perm : UltimateCore.get().getPermissionService().getPermissions()) {
        if (perm.getLevel() == level) {
            group.getSubjectData().setPermission(new HashSet<>(), perm.get(), Tristate.TRUE);
        }
    }

    Messages.send(src, "core.command.ultimatecore.setuppermissions.success", "%group%", group.getIdentifier(), "%level%", level.name().toLowerCase());
    return CommandResult.success();
}
 
Example #26
Source File: GeyserSpongeCommandExecutor.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public List<String> getSuggestions(CommandSource source, String arguments, @Nullable Location<World> targetPosition) throws CommandException {
    if (arguments.split(" ").length == 1) {
        return Arrays.asList("?", "help", "reload", "shutdown", "stop");
    }
    return new ArrayList<>();
}
 
Example #27
Source File: CommandClaimList.java    From GriefPrevention with MIT License 5 votes vote down vote up
private Consumer<CommandSource> createClaimListConsumer(Player src, User user, String type, WorldProperties worldProperties) {
    return consumer -> {
        if (type.equalsIgnoreCase("ALL")) {
            this.displayOwned = false;
        } else {
            this.displayOwned = true;
        }
        showClaimList(src, user, null, worldProperties);
    };
}
 
Example #28
Source File: TPChunkExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	int x = ctx.<Integer> getOne("x").get();
	int z = ctx.<Integer> getOne("z").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;
		Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

		if (Sponge.getServer().getChunkLayout().isValidChunk(new Vector3i(x, 0, z)))
		{
			Location<World> location = new Location<World>(player.getWorld(), Sponge.getServer().getChunkLayout().forceToWorld(new Vector3i(x, 0, z)));
			player.setLocation(location);
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to chunk."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Invalid chunk!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You cannot teleport, you are not a player!"));
	}

	return CommandResult.success();
}
 
Example #29
Source File: MuteCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    checkPermission(sender, MutePermissions.UC_MUTE_MUTE_BASE);

    //Get player & Check exempt
    Player t = args.<Player>getOne("player").get();
    if ((MutePermissions.UC_MUTE_EXEMPTPOWER.getIntFor(t) > MutePermissions.UC_MUTE_POWER.getIntFor(sender)) && sender instanceof Player) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "mute.command.mute.exempt", "%player%", t));
    }

    //Get time & reason
    Long time = args.hasAny("time") ? args.<Long>getOne("time").get() : -1L;
    Text reason = args.hasAny("reason") ? Text.of(args.<String>getOne("reason").get()) : Messages.getFormatted("mute.command.mute.defaultreason");

    Long endtime = time == -1L ? -1L : System.currentTimeMillis() + time;
    Long starttime = System.currentTimeMillis();
    UUID muter = sender instanceof Player ? ((Player) sender).getUniqueId() : UUID.fromString("00000000-0000-0000-0000-000000000000");
    UUID muted = t.getUniqueId();

    Mute mute = new Mute(muted, muter, endtime, starttime, reason);
    UltimateUser ut = UltimateCore.get().getUserService().getUser(t);
    ut.offer(MuteKeys.MUTE, mute);

    Messages.send(sender, "mute.command.mute.success", "%player%", VariableUtil.getNameEntity(t), "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason);
    Messages.send(t, "mute.muted", "%time%", (time == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.format(time)), "%reason%", reason);
    return CommandResult.success();
}
 
Example #30
Source File: SendMailCommand.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    //Get sender
    checkIfPlayer(src);
    Player p = (Player) src;
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);

    //Get target & construct mail
    GameProfile t = args.<GameProfile>getOne("player").get();
    UltimateUser ut = UltimateCore.get().getUserService().getUser(t.getUniqueId()).get();
    String message = args.<String>getOne("message").get();
    Mail mail = new Mail(p.getUniqueId(), Arrays.asList(t.getUniqueId()), System.currentTimeMillis(), message);

    //Offer to data api
    List<Mail> sentMail = up.get(MailKeys.MAILS_SENT).get();
    sentMail.add(mail);
    up.offer(MailKeys.MAILS_SENT, sentMail);
    List<Mail> receivedMail = ut.get(MailKeys.MAILS_RECEIVED).get();
    receivedMail.add(mail);
    ut.offer(MailKeys.MAILS_RECEIVED, receivedMail);

    //Increase unread count
    up.offer(MailKeys.UNREAD_MAIL, up.get(MailKeys.UNREAD_MAIL).get() + 1);

    Messages.send(src, "mail.command.mail.send", "%player%", t.getName().orElse(""));
    if (ut.getPlayer().isPresent()) {
        ut.getPlayer().get().sendMessage(Messages.getFormatted(ut.getPlayer().get(), "mail.command.mail.newmail", "%count%", up.get(MailKeys.UNREAD_MAIL).get()).toBuilder().onHover(TextActions.showText(Messages.getFormatted(ut.getPlayer().get(), "mail.command.mail.newmail.hover"))).onClick(TextActions.runCommand("/mail read")).build());
    }
    return CommandResult.success();
}