Java Code Examples for org.spongepowered.api.command.CommandSource#sendMessage()

The following examples show how to use org.spongepowered.api.command.CommandSource#sendMessage() . 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: SrCommand.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
@Subcommand("props") @CommandPermission("%srProps")
@CommandCompletion("@players")
@Description("%helpSrProps")
public void onProps(CommandSource source, OnlinePlayer target) {
    Collection<ProfileProperty> prop = target.getPlayer().getProfile().getPropertyMap().get("textures");

    if (prop == null) {
        source.sendMessage(plugin.parseMessage(Locale.NO_SKIN_DATA));
        return;
    }

    prop.forEach(profileProperty -> {
        source.sendMessage(plugin.parseMessage("\n§aName: §8" + profileProperty.getName()));
        source.sendMessage(plugin.parseMessage("\n§aValue : §8" + profileProperty.getValue()));
        source.sendMessage(plugin.parseMessage("\n§aSignature : §8" + profileProperty.getSignature()));

        byte[] decoded = Base64.getDecoder().decode(profileProperty.getValue());
        source.sendMessage(plugin.parseMessage("\n§aValue Decoded: §e" + Arrays.toString(decoded)));

        source.sendMessage(plugin.parseMessage("\n§e" + Arrays.toString(decoded)));

        source.sendMessage(plugin.parseMessage("§cMore info in console!"));
    });
}
 
Example 2
Source File: MuteExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Player p = ctx.<Player> getOne("player").get();

	// Uses the TimespanParser.
	Optional<Long> time = ctx.<Long> getOne("time");

	if (time.isPresent())
	{
		Task.Builder taskBuilder = game.getScheduler().createTaskBuilder();
		taskBuilder.execute(() -> {
			if (EssentialCmds.muteList.contains(p.getUniqueId()))
				EssentialCmds.muteList.remove(p.getUniqueId());
		}).delay(time.get(), TimeUnit.SECONDS).name("EssentialCmds - Remove previous mutes").submit(EssentialCmds.getEssentialCmds());
	}

	EssentialCmds.muteList.add(p.getUniqueId());
	Utils.addMute(p.getUniqueId());
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player muted."));
}
 
Example 3
Source File: AFKExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (EssentialCmds.afkList.containsKey(player.getUniqueId()))
		{
			EssentialCmds.afkList.remove(player.getUniqueId());
		}

		int timeBeforeAFK = (int) Utils.getAFK();
		long timeToSet = System.currentTimeMillis() - timeBeforeAFK - 1000;
		AFK afk = new AFK(timeToSet);
		EssentialCmds.afkList.put(player.getUniqueId(), afk);
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /afk!"));
	}

	return CommandResult.success();
}
 
Example 4
Source File: CommandClaimBasic.java    From GriefPrevention with MIT License 6 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());
    playerData.shovelMode = ShovelMode.Basic;
    playerData.claimSubdividing = null;
    GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimModeBasic.toText());

    return CommandResult.success();
}
 
Example 5
Source File: SetWarpExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	String warpName = ctx.<String> getOne("warp name").get();

	if (src instanceof Player)
	{
		if (Utils.isWarpInConfig(warpName))
		{
			Utils.deleteWarp(warpName);
		}
		Player player = (Player) src;
		Utils.setWarp(player.getTransform(), warpName);
		src.sendMessage(Text.of(TextColors.GREEN, "Success: ", TextColors.YELLOW, "Warp set."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /setwarp!"));
	}
}
 
Example 6
Source File: TPAAllExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext ctx)
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		for (Player p : Sponge.getServer().getOnlinePlayers())
		{
			Sponge.getEventManager().post(new TPAHereEvent(player, p));
		}

		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Requested for all players to be teleported to you"));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /tpaall!"));
	}
}
 
Example 7
Source File: NationadminFlagExecutor.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() || !ctx.<String>getOne("flag").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na flag <nation> <flag> [true|false]"));
		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();
	}
	String flag = ctx.<String>getOne("flag").get();
	boolean bool = (ctx.<Boolean>getOne("bool").isPresent()) ? ctx.<Boolean>getOne("bool").get() : !nation.getFlag(flag);
	nation.setFlag(flag, bool);
	DataHandler.saveNation(nation.getUUID());
	src.sendMessage(Utils.formatNationDescription(nation, Utils.CLICKER_ADMIN));
	return CommandResult.success();
}
 
Example 8
Source File: ZoneDelownerExecutor.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.getNation(player.getLocation());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDSTANDNATION));
			return CommandResult.success();
		}
		Zone zone = nation.getZone(player.getLocation());
		if (zone == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDSTANDZONESELF));
			return CommandResult.success();
		}
		if (!zone.isOwner(player.getUniqueId()) && !nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOOWNER));
			return CommandResult.success();
		}
		zone.resetCoowners();
		zone.setOwner(null);
		DataHandler.saveNation(nation.getUUID());
		src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.INFO_NOOWNER.replaceAll("\\{ZONE\\}", zone.getName())));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example 9
Source File: SrCommand.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
@Subcommand("status") @CommandPermission("%srStatus")
@Description("%helpSrStatus")
public void onStatus(CommandSource source) {
    source.sendMessage(plugin.parseMessage("§3----------------------------------------------"));
    source.sendMessage(plugin.parseMessage("§7Checking needed services for SR to work properly..."));

    Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
        ServiceChecker checker = new ServiceChecker();
        checker.setMojangAPI(plugin.getMojangAPI());
        checker.checkServices();

        ServiceChecker.ServiceCheckResponse response = checker.getResponse();
        List<String> results = response.getResults();

        for (String result : results) {
            source.sendMessage(plugin.parseMessage(result));
        }
        source.sendMessage(plugin.parseMessage("§7Working UUID API count: §6" + response.getWorkingUUID()));
        source.sendMessage(plugin.parseMessage("§7Working Profile API count: §6" + response.getWorkingProfile()));
        if (response.getWorkingUUID() >= 1 && response.getWorkingProfile() >= 1)
            source.sendMessage(plugin.parseMessage("§aThe plugin currently is in a working state."));
        else
            source.sendMessage(plugin.parseMessage("§cPlugin currently can't fetch new skins. You might check out our discord at https://discord.me/servers/skinsrestorer"));
        source.sendMessage(plugin.parseMessage("§3----------------------------------------------"));
        source.sendMessage(plugin.parseMessage("§7SkinsRestorer §6v" + plugin.getVersion()));
        source.sendMessage(plugin.parseMessage("§7Server: §6" + Sponge.getGame().getPlatform().getMinecraftVersion()));
        source.sendMessage(plugin.parseMessage("§7BungeeMode: §6Sponge-Plugin"));
        source.sendMessage(plugin.parseMessage("§7Finished checking services."));
        source.sendMessage(plugin.parseMessage("§3----------------------------------------------"));
    });
}
 
Example 10
Source File: CommandClaimFlagDebug.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());
    playerData.executingClaimDebug = true;
    final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());
    final Text result = claim.allowEdit(player);
    if (result != null) {
        GriefPreventionPlugin.sendMessage(src, result);
        playerData.executingClaimDebug = false;
        return CommandResult.success();
    }

    playerData.debugClaimPermissions = !playerData.debugClaimPermissions;

    if (!playerData.debugClaimPermissions) {
        GriefPreventionPlugin.sendMessage(player, Text.of(TextColors.WHITE, "Claim flags debug ", TextColors.RED, "OFF"));
    } else {
        GriefPreventionPlugin.sendMessage(player, Text.of(TextColors.WHITE, "Claim flags debug ", TextColors.GREEN, "ON"));
    }

    playerData.executingClaimDebug = false;
    return CommandResult.success();
}
 
Example 11
Source File: BlockInfoExecutor.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;

		BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(5).build();
		BlockRayHit<World> finalHitRay = null;

		while (playerBlockRay.hasNext())
		{
			BlockRayHit<World> currentHitRay = playerBlockRay.next();

			if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR))
			{
				finalHitRay = currentHitRay;
				break;
			}
		}

		if (finalHitRay != null)
		{
			player.sendMessage(Text.of(TextColors.GOLD, "The name of the block you're looking at is: ", TextColors.GRAY, finalHitRay.getLocation().getBlock().getType().getTranslation().get()));
			player.sendMessage(Text.of(TextColors.GOLD, "The ID of the block you're looking at is: ", TextColors.GRAY, finalHitRay.getLocation().getBlock().getName()));
			Optional<Object> metaDataQuery = finalHitRay.getLocation().getBlock().toContainer().get(DataQuery.of("UnsafeMeta"));
			player.sendMessage(Text.of(TextColors.GOLD, "The meta of the block you're looking at is: ", TextColors.GRAY, metaDataQuery.isPresent() ? metaDataQuery.get().toString() : 0));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You're not looking at any block within range."));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use this command."));
	}

	return CommandResult.success();
}
 
Example 12
Source File: CommandHelper.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Consumer<CommandSource> createFlagConsumer(CommandSource src, Subject subject, String subjectName, Set<Context> contexts, String flagPermission, Tristate flagValue, FlagType flagType) {
    return consumer -> {
        Tristate newValue = Tristate.UNDEFINED;
        if (flagValue == Tristate.TRUE) {
            newValue = Tristate.FALSE;
        } else if (flagValue == Tristate.UNDEFINED) {
            newValue = Tristate.TRUE;
        }

        Text flagTypeText = Text.of();
        if (flagType == FlagType.OVERRIDE) {
            flagTypeText = Text.of(TextColors.RED, "OVERRIDE");
        } else if (flagType == FlagType.DEFAULT) {
            flagTypeText = Text.of(TextColors.LIGHT_PURPLE, "DEFAULT");
        } else if (flagType == FlagType.CLAIM) {
            flagTypeText = Text.of(TextColors.GOLD, "CLAIM");
        }
        String target = flagPermission.replace(GPPermissions.FLAG_BASE + ".",  "");
        Set<Context> newContexts = new HashSet<>(contexts);
        subject.getSubjectData().setPermission(newContexts, flagPermission, newValue);
        src.sendMessage(Text.of(
                TextColors.GREEN, "Set ", flagTypeText, " permission ", 
                TextColors.AQUA, target, 
                TextColors.GREEN, "\n to ", 
                TextColors.LIGHT_PURPLE, getClickableText(src, subject, subjectName, newContexts, flagPermission, newValue, flagType), 
                TextColors.GREEN, " for ", 
                TextColors.GOLD, subjectName));
    };
}
 
Example 13
Source File: NationKickExecutor.java    From Nations with MIT License 4 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)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (!nation.isPresident(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONPRES));
			return CommandResult.success();
		}
		if (!ctx.<String>getOne("player").isPresent())
		{
			src.sendMessage(Text.of(TextColors.YELLOW, "/n kick <player>"));
			return CommandResult.success();
		}
		String toKick = ctx.<String>getOne("player").get();
		UUID uuid = DataHandler.getPlayerUUID(toKick);
		if (uuid == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADPLAYERNAME));
			return CommandResult.success();
		}
		if (!nation.isCitizen(uuid))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOTINNATION));
			return CommandResult.success();
		}
		if (player.getUniqueId().equals(uuid))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOKICKSELF));
			return CommandResult.success();
		}
		if (nation.isPresident(uuid))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_KICKPRESIDENT));
			return CommandResult.success();
		}
		if (nation.isMinister(uuid) && nation.isMinister(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_KICKMINISTER));
			return CommandResult.success();
		}
		nation.removeCitizen(uuid);
		DataHandler.saveNation(nation.getUUID());
		src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_KICK.replaceAll("\\{PLAYER\\}", toKick)));
		Sponge.getServer().getPlayer(uuid).ifPresent(
				p -> p.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.SUCCESS_KICK.replaceAll("\\{PLAYER\\}", player.getName()))));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example 14
Source File: WorldsBase.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	String gameRule = ctx.<String> getOne("gamerule").get();
	Optional<String> value = ctx.<String> getOne("value");
	Optional<String> worldName = ctx.<String> getOne("world");
	World world;

	if (worldName.isPresent())
	{
		if (Sponge.getServer().getWorld(worldName.get()).isPresent())
		{
			world = Sponge.getServer().getWorld(worldName.get()).get();
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!"));
			return CommandResult.empty();
		}
	}
	else
	{
		if (src instanceof Player)
		{
			Player player = (Player) src;
			world = player.getWorld();
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /world difficulty!"));
			return CommandResult.empty();
		}
	}

	if (value.isPresent())
	{
		world.getProperties().setGameRule(gameRule, value.get());
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Updated gamerule value."));
	}
	else
	{
		String val = world.getProperties().getGameRule(gameRule).orElse("none");
		src.sendMessage(Text.of(TextColors.GREEN, "Gamerule ", TextColors.GOLD, gameRule, TextColors.GREEN, " value ", TextColors.GOLD, val));
	}

	return CommandResult.success();
}
 
Example 15
Source File: CommandClaimDelete.java    From GriefPrevention with MIT License 4 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();
    }

    // determine which claim the player is standing in
    final GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    final GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAt(player.getLocation());
    final boolean isTown = claim.isTown();

    if (claim.isWilderness()) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimNotFound.toText());
        return CommandResult.success();
    }

    final Text message = GriefPreventionPlugin.instance.messageData.permissionClaimDelete
            .apply(ImmutableMap.of(
            "type", claim.getType().name())).build();

    if (claim.isAdminClaim() && !player.hasPermission(GPPermissions.DELETE_CLAIM_ADMIN)) {
        GriefPreventionPlugin.sendMessage(player, message);
        return CommandResult.success();
    }
    if (claim.isBasicClaim() && !player.hasPermission(GPPermissions.DELETE_CLAIM_BASIC)) {
        GriefPreventionPlugin.sendMessage(player, message);
        return CommandResult.success();
    }

    if (!this.deleteTopLevelClaim && !claim.isTown() && claim.children.size() > 0 && !playerData.warnedAboutMajorDeletion) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimChildrenWarning.toText());
        playerData.warnedAboutMajorDeletion = true;
        return CommandResult.success();
    }

    try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(src);
        ClaimResult
            claimResult =
            GriefPreventionPlugin.instance.dataStore.deleteClaim(claim, !this.deleteTopLevelClaim);
        if (!claimResult.successful()) {
            player.sendMessage(
                Text.of(TextColors.RED, claimResult.getMessage().orElse(Text.of("Could not delete claim. A plugin has denied it."))));
            return CommandResult.success();
        }

        claim.removeSurfaceFluids(null);
        // clear permissions
        GriefPreventionPlugin.GLOBAL_SUBJECT.getSubjectData().clearPermissions(ImmutableSet.of(claim.getContext()));
        // if in a creative mode world, /restorenature the claim
        if (GriefPreventionPlugin.instance
            .claimModeIsActive(claim.getLesserBoundaryCorner().getExtent().getProperties(), ClaimsMode.Creative)) {
            GriefPreventionPlugin.instance.restoreClaim(claim, 0);
        }

        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimDeleted.toText());
        GriefPreventionPlugin.addLogEntry(
            player.getName() + " deleted " + claim.getOwnerName() + "'s claim at "
            + GriefPreventionPlugin.getfriendlyLocationString(claim.getLesserBoundaryCorner()),
            CustomLogEntryTypes.AdminActivity);

        // revert any current visualization
        playerData.revertActiveVisual(player);

        playerData.warnedAboutMajorDeletion = false;
        if (isTown) {
            playerData.inTown = false;
            playerData.townChat = false;
        }
    }

    return CommandResult.success();
}
 
Example 16
Source File: EconCommand.java    From EconomyLite with MIT License 4 votes vote down vote up
@Override
public void run(CommandSource src, CommandContext args) {
    src.sendMessage(messageStorage.getMessage("command.usage", "command", "/econ", "subcommands", "add | set | remove <player> <amount>"));
    src.sendMessage(messageStorage.getMessage("command.usage", "command", "/econ", "subcommands", "setall <amount>"));
}
 
Example 17
Source File: EssentialCmdsExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public void executeAsync(CommandSource src, CommandContext args) {
	Config.getConfig().load();
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Config reloaded."));
}
 
Example 18
Source File: ZoneRenameExecutor.java    From Nations with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		String zoneName = null;
		if (ctx.<String>getOne("name").isPresent())
		{
			zoneName = ctx.<String>getOne("name").get();
		}
		if (zoneName != null && !zoneName.matches("[\\p{Alnum}\\p{IsIdeographic}\\p{IsLetter}\"_\"]*{1,30}"))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ALPHASPAWN
					.replaceAll("\\{MIN\\}", "1")
					.replaceAll("\\{MAX\\}", "30")));
			return CommandResult.success();
		}
		Player player = (Player) src;
		Nation nation = DataHandler.getNation(player.getLocation());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDSTANDNATION));
			return CommandResult.success();
		}
		Zone currentZone = nation.getZone(player.getLocation());
		if (currentZone == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NEEDSTANDZONESELF));
			return CommandResult.success();
		}
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOOWNER));
			return CommandResult.success();
		}
		if (zoneName != null)
		{
			for (Zone zone : nation.getZones().values())
			{
				if (zone.isNamed() && zone.getRealName().equalsIgnoreCase(zoneName))
				{
					src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_ZONENAME));
					return CommandResult.success();
				}
			}
		}
		currentZone.setName(zoneName);
		DataHandler.saveNation(nation.getUUID());
		src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_ZONERENAME.replaceAll("\\{ZONE\\}", currentZone.getName())));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example 19
Source File: CommandClaimFlagPlayer.java    From GriefPrevention with MIT License 4 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();
    }

    User user = ctx.<User>getOne("player").get();
    String name = user.getName();
    String flag = ctx.<String>getOne("flag").orElse(null);
    String source = ctx.<String>getOne("source").orElse(null);
    String target = null;
    // Workaround command API issue not handling onlyOne arguments with sequences properly
    List<String> targetValues = new ArrayList<>(ctx.<String>getAll("target"));
    if (targetValues.size() > 0) {
        if (targetValues.size() > 1) {
            target = targetValues.get(1);
        } else {
            target = targetValues.get(0);
        }
    }

    if (source != null && source.equalsIgnoreCase("any")) {
        source = null;
    }

    this.subject = user;
    this.friendlySubjectName = user.getName();
    Tristate value = ctx.<Tristate>getOne("value").orElse(null);
    String context = ctx.<String>getOne("context").orElse(null);
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAtPlayer(playerData, player.getLocation());

    String reason = ctx.<String>getOne("reason").orElse(null);
    Text reasonText = null;
    if (reason != null) {
        reasonText = TextSerializers.FORMATTING_CODE.deserialize(reason);
    }
    if (flag == null && value == null) {
        showFlagPermissions(src, claim, FlagType.ALL, source);
        return CommandResult.success();
    }

    if (!ClaimFlag.contains(flag)) {
        src.sendMessage(Text.of(TextColors.RED, "Flag not found."));
        return CommandResult.success();
    }
    Context claimContext = claim.getContext();
    if (context != null) {
        claimContext = CommandHelper.validateCustomContext(src, claim, context);
        if (claimContext == null) {
            final Text message = GriefPreventionPlugin.instance.messageData.flagInvalidContext
                    .apply(ImmutableMap.of(
                    "context", context,
                    "flag", flag)).build();
            GriefPreventionPlugin.sendMessage(src, message);
            return CommandResult.success();
        }
    }

    if (user.hasPermission(GPPermissions.COMMAND_ADMIN_CLAIMS) && !src.hasPermission(GPPermissions.SET_ADMIN_FLAGS)) {
        GriefPreventionPlugin.sendMessage(src, GriefPreventionPlugin.instance.messageData.permissionSetAdminFlags.toText());
        return CommandResult.success();
    }

    try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(src);
        claim.setPermission(user, name, ClaimFlag.getEnum(flag), source, target, value, claimContext, reasonText);
    }
    return CommandResult.success();
}
 
Example 20
Source File: HomeExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	String homeName = ctx.<String> getOne("home name").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (Utils.isHomeInConfig(player.getUniqueId(), homeName))
		{
			try
			{
				if (Utils.isTeleportCooldownEnabled() && !player.hasPermission("essentialcmds.teleport.cooldown.override"))
				{
					EssentialCmds.teleportingPlayers.add(player.getUniqueId());
					src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleporting to home " + Utils.getConfigHomeName(player.getUniqueId(), homeName) + ". Please wait " + Utils.getTeleportCooldown() + " seconds."));

					Sponge.getScheduler().createTaskBuilder().execute(() -> {
						if (EssentialCmds.teleportingPlayers.contains(player.getUniqueId()))
						{
							Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

							if (Objects.equals(player.getWorld().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId()))
							{
								player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
							}
							else
							{
								player.transferToWorld(Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getPosition());
								player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
							}

							src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to home " + Utils.getConfigHomeName(player.getUniqueId(), homeName)));
							EssentialCmds.teleportingPlayers.remove(player.getUniqueId());
						}
					}).delay(Utils.getTeleportCooldown(), TimeUnit.SECONDS).name("EssentialCmds - Back Timer").submit(Sponge.getGame().getPluginManager().getPlugin(PluginInfo.ID).get().getInstance().get());
				}
				else
				{
					Utils.setLastTeleportOrDeathLocation(player.getUniqueId(), player.getLocation());

					if (Objects.equals(player.getWorld().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId()))
					{
						player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
					}
					else
					{
						player.transferToWorld(Utils.getHome(player.getUniqueId(), homeName).getExtent().getUniqueId(), Utils.getHome(player.getUniqueId(), homeName).getPosition());
						player.setTransform(Utils.getHome(player.getUniqueId(), homeName));
					}

					src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Teleported to home " + Utils.getConfigHomeName(player.getUniqueId(), homeName)));
				}
			}
			catch (PositionOutOfBoundsException e)
			{
				src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Home is in invalid coordinates!"));
			}
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must first set your home!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /home!"));
	}

	return CommandResult.success();
}