Java Code Examples for org.spongepowered.api.text.Text#of()

The following examples show how to use org.spongepowered.api.text.Text#of() . 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: 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 2
Source File: AllyCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
private Text getInviteGetMessage(final Faction senderFaction)
{
	final Text clickHereText = Text.builder()
			.append(Text.of(TextColors.AQUA, "[", TextColors.GOLD, Messages.CLICK_HERE, TextColors.AQUA, "]"))
			.onClick(TextActions.runCommand("/f ally " + senderFaction.getName()))
			.onHover(TextActions.showText(Text.of(TextColors.GOLD, "/f ally " + senderFaction.getName()))).build();

	return Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.FACTION_HAS_SENT_YOU_AN_INVITE_TO_THE_ALLIANCE, TextColors.GREEN, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, senderFaction.getName()))),
               "\n", Messages.YOU_HAVE_TWO_MINUTES_TO_ACCEPT_IT,
               "\n", clickHereText, Messages.TO_ACCEPT_INVITATION_OR_TYPE, " ", TextColors.GOLD, "/f ally ", senderFaction.getName());
}
 
Example 3
Source File: EnemyCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
private Text getArmisticeRequestMessage(final Faction senderFaction)
{
    final Text clickHereText = Text.builder()
            .append(Text.of(TextColors.AQUA, "[", TextColors.GOLD, Messages.CLICK_HERE, TextColors.AQUA, "]"))
            .onClick(TextActions.runCommand("/f enemy " + senderFaction.getName()))
            .onHover(TextActions.showText(Text.of(TextColors.GOLD, "/f enemy " + senderFaction.getName()))).build();

    return Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.FACTION_HAS_SENT_YOU_AN_ARMISTICE_REQUEST, TextColors.YELLOW, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, senderFaction.getName(),
            "\n", Messages.YOU_HAVE_TWO_MINUTES_TO_ACCEPT_IT,
            "\n", clickHereText, Messages.TO_ACCEPT_IT_OR_TYPE, " ", TextColors.GOLD, "/f enemy " + senderFaction.getName()))));
}
 
Example 4
Source File: GriefPreventionPlugin.java    From GriefPrevention with MIT License 5 votes vote down vote up
public static Player checkPlayer(CommandSource src) throws CommandException {
    if (src instanceof Player) {
        final Player player = (Player) src;
        if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) {
            throw new CommandException(GriefPreventionPlugin.instance.messageData.claimDisabledWorld.toText());
        }
        return player;
    } else {
        throw new CommandException(Text.of("You must be a player to run this command!"));
    }
}
 
Example 5
Source File: GPClaim.java    From GriefPrevention with MIT License 5 votes vote down vote up
public Text getFriendlyNameType(boolean upper) {
    if (this.type == ClaimType.ADMIN) {
        if (upper) {
            return Text.of(TextColors.RED, this.type.name());
        }
        return Text.of(TextColors.RED, "Admin");
    }

    if (this.type == ClaimType.BASIC) {
        if (upper) {
            return Text.of(TextColors.YELLOW, this.type.name());
        }
        return Text.of(TextColors.YELLOW, "Basic");
    }

    if (this.type == ClaimType.SUBDIVISION) {
        if (upper) {
            return Text.of(TextColors.AQUA, this.type.name());
        }
        return Text.of(TextColors.AQUA, "Subdivision");
    }

    if (upper) {
        return Text.of(TextColors.GREEN, this.type.name());
    }
    return Text.of(TextColors.GREEN, "Town");
}
 
Example 6
Source File: DescriptionCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    final Optional<String> optionalDescription = context.<String>getOne("description");

    if (!optionalDescription.isPresent())
    {
        source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.WRONG_COMMAND_ARGUMENTS));
        source.sendMessage(Text.of(TextColors.RED, Messages.USAGE + " /f desc <description>"));
        return CommandResult.success();
    }

    if (!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player) source;
    final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    if (!optionalPlayerFaction.isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));

    //Check if player is leader
    if (!optionalPlayerFaction.get().getLeader().equals(player.getUniqueId()) && !optionalPlayerFaction.get().getOfficers().contains(player.getUniqueId()))
    {
        source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));
        return CommandResult.success();
    }

    final String description = optionalDescription.get();

    //Check description length
    if(description.length() > 255)
    {
        player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.DESCRIPTION_IS_TOO_LONG + " (" + Messages.MAX + " " + 255 + " " + Messages.CHARS + ")"));
        return CommandResult.success();
    }

    super.getPlugin().getFactionLogic().setDescription(optionalPlayerFaction.get(), description);
    player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GREEN, Messages.FACTION_DESCRIPTION_HAS_BEEN_UPDATED)));
    return CommandResult.success();
}
 
Example 7
Source File: TruceCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
private Text getInviteGetMessage(final Faction senderFaction)
{
	final Text clickHereText = Text.builder()
			.append(Text.of(TextColors.AQUA, "[", TextColors.GOLD, Messages.CLICK_HERE, TextColors.AQUA, "]"))
			.onClick(TextActions.runCommand("/f truce " + senderFaction.getName()))
			.onHover(TextActions.showText(Text.of(TextColors.GOLD, "/f truce " + senderFaction.getName()))).build();

	return Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.FACTION_HAS_SENT_YOU_AN_INVITE_TO_THE_TRUCE, TextColors.GREEN, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, senderFaction.getName()))),
			"\n", Messages.YOU_HAVE_TWO_MINUTES_TO_ACCEPT_IT,
			"\n", clickHereText, Messages.TO_ACCEPT_INVITATION_OR_TYPE, " ", TextColors.GOLD, "/f truce ", senderFaction.getName());
}
 
Example 8
Source File: ChatModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Full chat management, including group formats");
}
 
Example 9
Source File: GPClaim.java    From GriefPrevention with MIT License 4 votes vote down vote up
public ClaimResult changeType(ClaimType type, Optional<UUID> ownerUniqueId, CommandSource src) {
    if (type == this.type) {
        return new GPClaimResult(ClaimResultType.SUCCESS);
    }

    GPChangeClaimEvent.Type event = new GPChangeClaimEvent.Type(this, type);
    Sponge.getEventManager().post(event);
    if (event.isCancelled()) {
        return new GPClaimResult(ClaimResultType.CLAIM_EVENT_CANCELLED, event.getMessage().orElse(null));
    }

    final GPClaimManager claimWorldManager = GriefPreventionPlugin.instance.dataStore.getClaimWorldManager(this.world.getProperties());
    final GPPlayerData sourcePlayerData = src != null && src instanceof Player ? claimWorldManager.getOrCreatePlayerData(((Player) src).getUniqueId()) : null;
    UUID newOwnerUUID = ownerUniqueId.orElse(this.ownerUniqueId);
    final ClaimResult result = this.validateClaimType(type, newOwnerUUID, sourcePlayerData);
    if (!result.successful()) {
        return result;
    }

    if (type == ClaimType.ADMIN) {
        newOwnerUUID = GriefPreventionPlugin.ADMIN_USER_UUID;
    }

    final String fileName = this.getClaimStorage().filePath.getFileName().toString();
    final Path newPath = this.getClaimStorage().folderPath.getParent().resolve(type.name().toLowerCase()).resolve(fileName);
    try {
        if (Files.notExists(newPath.getParent())) {
            Files.createDirectories(newPath.getParent());
        }
        Files.move(this.getClaimStorage().filePath, newPath);
        if (type == ClaimType.TOWN) {
            this.setClaimStorage(new TownStorageData(newPath, this.getWorldUniqueId(), newOwnerUUID, this.cuboid));
        } else {
            this.setClaimStorage(new ClaimStorageData(newPath, this.getWorldUniqueId(), (ClaimDataConfig) this.getInternalClaimData()));
        }
        this.claimData = this.claimStorage.getConfig();
        this.getClaimStorage().save();
    } catch (IOException e) {
        e.printStackTrace();
        return new GPClaimResult(ClaimResultType.CLAIM_NOT_FOUND, Text.of(e.getMessage()));
    }

    // If switched to admin or new owner, remove from player claim list
    if (type == ClaimType.ADMIN || !this.ownerUniqueId.equals(newOwnerUUID)) {
        final Set<Claim> currentPlayerClaims = claimWorldManager.getInternalPlayerClaims(this.ownerUniqueId);
        if (currentPlayerClaims != null) {
            currentPlayerClaims.remove(this);
        }
    }
    if (type != ClaimType.ADMIN) {
        final Set<Claim> newPlayerClaims = claimWorldManager.getInternalPlayerClaims(newOwnerUUID);
        if (newPlayerClaims != null && !newPlayerClaims.contains(this)) {
            newPlayerClaims.add(this);
        }
    }

    if (!this.isAdminClaim() && this.ownerPlayerData != null) {
        final Player player = Sponge.getServer().getPlayer(this.ownerUniqueId).orElse(null);
        if (player != null) {
            this.ownerPlayerData.revertActiveVisual(player);
        }
    }

    // revert visuals for all players watching this claim
    List<UUID> playersWatching = new ArrayList<>(this.playersWatching);
    for (UUID playerUniqueId : playersWatching) {
        final Player spongePlayer = Sponge.getServer().getPlayer(playerUniqueId).orElse(null);
        final GPPlayerData playerData = claimWorldManager.getOrCreatePlayerData(playerUniqueId);
        if (spongePlayer != null) {
            playerData.revertActiveVisual(spongePlayer);
        }
    }

    if (!newOwnerUUID.equals(GriefPreventionPlugin.ADMIN_USER_UUID)) {
        this.setOwnerUniqueId(newOwnerUUID);
    }
    this.setType(type);
    this.visualization = null;
    this.getInternalClaimData().setRequiresSave(true);
    this.getClaimStorage().save();
    return new GPClaimResult(ClaimResultType.SUCCESS);
}
 
Example 10
Source File: WarpModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Let the admin set certain locations where a player can teleport to.");
}
 
Example 11
Source File: BurnModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Set a player on fire using the /burn command.");
}
 
Example 12
Source File: IpCommand.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public CommandElement[] getArguments() {
    return new CommandElement[]{new GameprofileArgument(Text.of("player"))};
}
 
Example 13
Source File: TeleportModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("A module with multiple teleport command.");
}
 
Example 14
Source File: WeatherModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Change the minecraft world's weather, or disable it.");
}
 
Example 15
Source File: ImplementationConfig.java    From ChatUI with MIT License 4 votes vote down vote up
@Override
public Text getTitle() {
    return Text.of("Sponge Config");
}
 
Example 16
Source File: HealModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Allows you to refill or change a player's health bar.");
}
 
Example 17
Source File: ExecuteMethodParam.java    From Web-API with MIT License 4 votes vote down vote up
public Tuple<Class, Object> toObject()
        throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
    String val = value;
    String[] vals = val.split(":");

    switch (type) {
        case INT:
        case INTEGER:
            return new Tuple<>(Integer.class, Integer.parseInt(val));
        case FLOAT:
            return new Tuple<>(Float.class, Float.parseFloat(val));
        case DOUBLE:
            return new Tuple<>(Double.class, Double.parseDouble(val));
        case BOOL:
        case BOOLEAN:
            return new Tuple<>(Boolean.class, Boolean.parseBoolean(val));
        case BYTE:
            return new Tuple<>(Byte.class, Byte.parseByte(val));
        case CHAR:
            return new Tuple<>(Character.class, val.charAt(0));
        case LONG:
            return new Tuple<>(Long.class, Long.parseLong(val));
        case SHORT:
            return new Tuple<>(Short.class, Short.parseShort(val));
        case STRING:
            return new Tuple<>(String.class, val);
        case CLASS:
            return new Tuple<>(Class.class, Class.forName(val));
        case ENUM:
            Class clazz = Class.forName(vals[0]);
            return new Tuple<Class, Object>(clazz, Enum.valueOf(clazz, vals[1]));

        case VECTOR3D:
            return new Tuple<>(Vector3d.class, new Vector3d(
                    Double.parseDouble(vals[0]), Double.parseDouble(vals[1]), Double.parseDouble(vals[2])));

        case VECTOR3I:
            return new Tuple<>(Vector3i.class, new Vector3i(
                    Integer.parseInt(vals[0]), Integer.parseInt(vals[1]), Integer.parseInt(vals[2])));

        case TEXT:
            return new Tuple<>(Text.class, Text.of(val));

        case WORLD:
            Optional<World> w = Sponge.getServer().getWorld(UUID.fromString(val));
            return new Tuple<>(World.class, w.orElse(null));

        case PLAYER:
            Optional<Player> p = Sponge.getServer().getPlayer(UUID.fromString(val));
            return new Tuple<>(Player.class, p.orElse(null));

        case ITEMSTACK:
            Optional<ItemType> t = Sponge.getRegistry().getType(ItemType.class, vals[0]);
            if (!t.isPresent())
                throw new ClassNotFoundException(vals[0]);

            return new Tuple<>(ItemStack.class, ItemStack.of(t.get(), Integer.parseInt(vals[1])));

        case STATIC:
            Class c = Class.forName(vals[0]);
            Field f = c.getField(vals[1]);
            return new Tuple<>(f.getType(), f.get(null));

        default:
            return null;
    }
}
 
Example 18
Source File: MuteModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Allows you to mute a player and the player won't be able to send chat, but will be able to see the chat.");
}
 
Example 19
Source File: RandomModule.java    From UltimateCore with MIT License 4 votes vote down vote up
@Override
public Text getDescription() {
    return Text.of("Generate random numbers with a simple command");
}
 
Example 20
Source File: ConfigEntry.java    From ChatUI with MIT License 4 votes vote down vote up
public UnknownValueType(Object value) {
    this.text = Text.of("[Unknown] ", value);
}