org.spongepowered.api.text.title.Title Java Examples

The following examples show how to use org.spongepowered.api.text.title.Title. 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: UIRenderer.java    From SubServers-2 with Apache License 2.0 6 votes vote down vote up
/**
 * Attempt to send a Title Message
 *
 * @param str Message
 * @param fadein FadeIn Transition length (in ticks)
 * @param stay How long the message should stay (in ticks)
 * @param fadeout FadeOut Transition length (in ticks)
 * @return Success Status
 */
public boolean sendTitle(String str, int fadein, int stay, int fadeout) {
    if (Util.isNull(str, fadein, stay, fadeout)) throw new NullPointerException();
    if (plugin.config.get().getMap("Settings").getBoolean("Use-Title-Messages", true)) {
        String line1, line2;
        if (!str.startsWith("\n") && str.contains("\n")) {
            line1 = str.split("\\n")[0];
            line2 = str.split("\\n")[1];
        } else {
            line1 = str.replace("\n", "");
            line2 = ChatColor.RESET.toString();
        }
        try {
            if (ChatColor.stripColor(line1).length() == 0 && ChatColor.stripColor(line2).length() == 0) {
                Sponge.getServer().getPlayer(player).get().resetTitle();
            } else {
                Sponge.getServer().getPlayer(player).get().sendTitle(Title.builder().title(ChatColor.convertColor(line1)).subtitle(ChatColor.convertColor(line2)).fadeIn((fadein >= 0)?fadein:10).stay((stay >= 0)?stay:70).fadeOut((fadeout >= 0)?fadeout:20).build());
            }
            return true;
        } catch (Throwable e) {
            return false;
        }
    } else return false;
}
 
Example #2
Source File: AfkKeys.java    From UltimateCore with MIT License 6 votes vote down vote up
@Override
public void save(UltimateUser user, Boolean data) {
    if (data) {
        //Make sure the player is not un-afked instantly
        AfkDetectionListener.afktime.put(user.getIdentifier(), 0L);
        if (user.getPlayer().isPresent()) {
            user.offer(AfkKeys.LAST_LOCATION, new Transform<>(user.getPlayer().get().getLocation(), user.getPlayer().get().getRotation(), user.getPlayer().get().getScale()));
        }
    } else {
        //Player is no longer afk
        if (user.getPlayer().isPresent()) {
            user.getPlayer().get().sendTitle(Title.builder().clear().title(Text.empty()).subtitle(Text.empty()).build());
        }
        //Make sure the player is not afked instantly
        AfkDetectionListener.afktime.put(user.getIdentifier(), System.currentTimeMillis());
    }
}
 
Example #3
Source File: SpongePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendTitle(String head, String sub) { // Not supported
    Text headText = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(BBC.color(head));
    Text subText = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(BBC.color(sub));
    final Title title = Title.builder().title(headText).subtitle(subText).fadeIn(0).stay(60).fadeOut(20).build();
    parent.sendTitle(title);
}
 
Example #4
Source File: SpongePlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendTitle(String head, String sub) { // Not supported
    Text headText = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(BBC.color(head));
    Text subText = TextSerializers.LEGACY_FORMATTING_CODE.deserialize(BBC.color(sub));
    final Title title = Title.builder().title(headText).subtitle(subText).fadeIn(0).stay(60).fadeOut(20).build();
    parent.sendTitle(title);
}
 
Example #5
Source File: AfkTitleTask.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public void run() {
    CommentedConfigurationNode config = Modules.AFK.get().getConfig().get().get();
    for (Player player : Sponge.getServer().getOnlinePlayers()) {
        UltimateUser user = UltimateCore.get().getUserService().getUser(player);
        if (user.get(AfkKeys.IS_AFK).get()) {
            Text title = Messages.getFormatted("afk.title.title");
            Text subtitle;
            long timediff = (config.getNode("time", "kicktime").getInt() * 1000) - (System.currentTimeMillis() - user.get(AfkKeys.AFK_TIME).get());
            if (config.getNode("time", "kicktime").getInt() != -1 && timediff <= 0 && !player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get())) {
                player.kick(Messages.getFormatted("afk.kick.reason"));
            }
            if (player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get()) || config.getNode("time", "kicktime").getInt() == -1) {
                subtitle = Messages.getFormatted("afk.title.subtitle.exempt");
            } else if (config.getNode("title", "subtitle-show-seconds").getBoolean(true)) {
                subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(timediff, 3, null));
            } else {
                subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(timediff, 3, 11));
            }
            if (config.getNode("title", "subtitle").getBoolean(false) && (!player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get()) || config.getNode("title", "subtitle-exempt").getBoolean(false))) {
                //Show subtitle
                player.sendTitle(Title.builder().title(title).subtitle(subtitle).fadeIn(0).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build());
            } else {
                //Don't show subtitle
                //TODO refresh?
                player.sendTitle(Title.builder().title(title).fadeIn(0).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build());
            }
        }
    }
}
 
Example #6
Source File: AfkSwitchListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onAfkSwitch(DataOfferEvent<Boolean> event) {
    if (event.getKey().equals(AfkKeys.IS_AFK) && event.getValue().isPresent()) {
        Player player = event.getCause().first(Player.class).orElse(null);
        if (player == null) {
            Messages.log("Invalid DataOfferEvent! (No player found)");
            return;
        }
        UltimateUser user = UltimateCore.get().getUserService().getUser(player);
        CommentedConfigurationNode config = Modules.AFK.get().getConfig().get().get();
        if (config.getNode("title", "enabled").getBoolean(true)) {
            if (event.getValue().get()) {
                //Player went afk
                Text title = Messages.getFormatted("afk.title.title");
                Text subtitle;
                if (player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get())) {
                    subtitle = Messages.getFormatted("afk.title.subtitle.exempt");
                } else if (config.getNode("title", "subtitle-show-seconds").getBoolean(true)) {
                    subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(config.getNode("time", "kicktime").getInt() * 1000, 3, null));
                } else {
                    subtitle = Messages.getFormatted("afk.title.subtitle.kick", "%time%", TimeUtil.format(config.getNode("time", "kicktime").getInt() * 1000, 3, 11));
                }
                if (config.getNode("title", "subtitle").getBoolean(false) && (!player.hasPermission(AfkPermissions.UC_AFK_EXEMPT.get()) || config.getNode("title", "subtitle-exempt").getBoolean(false))) {
                    //Show subtitle
                    player.sendTitle(Title.builder().title(title).subtitle(subtitle).fadeIn(20).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build());
                } else {
                    //Don't show subtitle
                    //TODO refresh?
                    player.sendTitle(Title.builder().title(title).fadeIn(20).fadeOut(20).stay(config.getNode("title", "subtitle-refresh").getInt()).build());
                }
            }
        }
    }
}