Java Code Examples for org.bukkit.entity.Player#resetTitle()

The following examples show how to use org.bukkit.entity.Player#resetTitle() . 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: Titles.java    From XSeries with MIT License 6 votes vote down vote up
/**
 * Clears the title and subtitle message from the player's screen.
 *
 * @param player the player to clear the title from.
 * @since 1.0.0
 */
public static void clearTitle(@Nonnull Player player) {
    Objects.requireNonNull(player, "Cannot clear title from null player");
    if (supported) {
        player.resetTitle();
        return;
    }
    Object clearPacket = null;

    try {
        clearPacket = PACKET.invoke(CLEAR, null, -1, -1, -1);
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }

    ReflectionUtils.sendPacket(player, clearPacket);
}
 
Example 2
Source File: UIRenderer.java    From SubServers-2 with Apache License 2.0 5 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 {
            Player player = Bukkit.getPlayer(this.player);
            if (plugin.api.getGameVersion().compareTo(new Version("1.11")) >= 0) {
                if (ChatColor.stripColor(line1).length() == 0 && ChatColor.stripColor(line2).length() == 0) {
                    player.resetTitle();
                } else {
                    player.sendTitle(line1, line2, (fadein >= 0)?fadein:10, (stay >= 0)?stay:70, (fadeout >= 0)?fadeout:20);
                }
                return true;
            } else if (Bukkit.getPluginManager().getPlugin("TitleManager") != null) {
                if (Util.isException(() -> Util.reflect(Class.forName("io.puharesource.mc.titlemanager.api.v2.TitleManagerAPI").getMethod("sendTitles", Player.class, String.class, String.class, int.class, int.class, int.class),
                        Bukkit.getPluginManager().getPlugin("TitleManager"), player, line1, line2, (fadein >= 0)?fadein:10, (stay >= 0)?stay:70, (fadeout >= 0)?fadeout:20))) { // Attempt TitleAPI v2

                    // Fallback to TitleAPI v1
                    io.puharesource.mc.titlemanager.api.TitleObject obj = io.puharesource.mc.titlemanager.api.TitleObject.class.getConstructor(String.class, String.class).newInstance(line1, line2);
                    if (fadein >= 0) obj.setFadeIn(fadein);
                    if (stay >= 0) obj.setStay(stay);
                    if (fadeout >= 0) obj.setFadeOut(fadeout);
                    obj.send(player);
                }
                return true;
            } else return false;
        } catch (Throwable e) {
            return false;
        }
    } else return false;
}
 
Example 3
Source File: EffResetTitle.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void execute(Event e) {
	for (Player recipient : recipients.getArray(e))
		recipient.resetTitle();
}