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

The following examples show how to use org.bukkit.entity.Player#sendTitle() . 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: Title.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void sendTitle(Player player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
	try {
		player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
	} catch (Throwable t) {
		try {
			Object titleComponent = getMethod(ChatSerializer, "a,field_150700_a", String.class)
				.invokeStatic("{\"text\": \"" + title + "\"}");
			Object subtitleComponent = getMethod(ChatSerializer, "a,field_150700_a", String.class)
				.invokeStatic("{\"text\": \"" + subtitle + "\"}");
			
			Object titlePacket = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent)
				.newInstance(findEnumConstant(EnumTitleAction, "TITLE"), titleComponent);
			Object subtitlePacket = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent)
				.newInstance(findEnumConstant(EnumTitleAction, "SUBTITLE"), subtitleComponent);
			Object timesPacket = PacketPlayOutTitle
				.getConstructor(EnumTitleAction, IChatBaseComponent, int.class, int.class, int.class)
				.newInstance(findEnumConstant(EnumTitleAction, "TIMES"), null, fadeIn, stay, fadeOut);
			
			sendPacket(player, titlePacket);
			sendPacket(player, subtitlePacket);
			sendPacket(player, timesPacket);
		} catch (Throwable ignored) {
		}
	}
}
 
Example 2
Source File: Title.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void sendTitle(Player player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
	try {
		player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
	} catch (Throwable t) {
		try {
			Object titleComponent = getMethod(ChatSerializer, "a,field_150700_a", String.class)
				.invokeStatic("{\"text\": \"" + title + "\"}");
			Object subtitleComponent = getMethod(ChatSerializer, "a,field_150700_a", String.class)
				.invokeStatic("{\"text\": \"" + subtitle + "\"}");
			
			Object titlePacket = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent)
				.newInstance(findEnumConstant(EnumTitleAction, "TITLE"), titleComponent);
			Object subtitlePacket = PacketPlayOutTitle.getConstructor(EnumTitleAction, IChatBaseComponent)
				.newInstance(findEnumConstant(EnumTitleAction, "SUBTITLE"), subtitleComponent);
			Object timesPacket = PacketPlayOutTitle
				.getConstructor(EnumTitleAction, IChatBaseComponent, int.class, int.class, int.class)
				.newInstance(findEnumConstant(EnumTitleAction, "TIMES"), null, fadeIn, stay, fadeOut);
			
			sendPacket(player, titlePacket);
			sendPacket(player, subtitlePacket);
			sendPacket(player, timesPacket);
		} catch (Throwable ignored) {
		}
	}
}
 
Example 3
Source File: CommonScheduler.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private void enterTown(Player player, Civilian civilian, Town town, TownType townType) {
    PlayerEnterTownEvent playerEnterTownEvent = new PlayerEnterTownEvent(player.getUniqueId(),
            town, townType);
    Bukkit.getPluginManager().callEvent(playerEnterTownEvent);
    Government government = GovernmentManager.getInstance().getGovernment(town.getGovernmentType());
    String govName = "Unknown";
    if (government != null) {
        govName = LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                government.getName().toLowerCase() + LocaleConstants.NAME_SUFFIX);
    }
    if (ConfigManager.getInstance().isEnterExitMessagesUseTitles()) {
        player.sendTitle(ChatColor.GREEN + town.getName(), ChatColor.BLUE + govName, 5, 40, 5);
    } else {
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                "town-enter").replace("$1", town.getName())
                .replace("$2", govName));
    }
}
 
Example 4
Source File: CommonScheduler.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private void exitTown(Player player, Civilian civilian, Town town, TownType townType) {
    PlayerExitTownEvent playerExitTownEvent = new PlayerExitTownEvent(player.getUniqueId(),
            town, townType);
    Bukkit.getPluginManager().callEvent(playerExitTownEvent);
    Government government = GovernmentManager.getInstance().getGovernment(town.getGovernmentType());
    String govName = "Unknown";
    if (government != null) {
        govName = LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                government.getName().toLowerCase() + LocaleConstants.NAME_SUFFIX);
    }
    if (ConfigManager.getInstance().isEnterExitMessagesUseTitles()) {
        String wild = LocaleManager.getInstance().getTranslation(civilian.getLocale(), "wild");
        player.sendTitle(ChatColor.GREEN + wild, "", 5, 40, 5);
    } else {
        player.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslation(civilian.getLocale(),
                "town-exit").replace("$1", town.getName())
                .replace("$2", govName));
    }
}
 
Example 5
Source File: Titles.java    From XSeries with MIT License 5 votes vote down vote up
/**
 * Sends a title message with title and subtitle to a player.
 *
 * @param player   the player to send the title to.
 * @param fadeIn   the amount of ticks for title to fade in.
 * @param stay     the amount of ticks for the title to stay.
 * @param fadeOut  the amount of ticks for the title to fade out.
 * @param title    the title message.
 * @param subtitle the subtitle message.
 * @see #clearTitle(Player)
 * @since 1.0.0
 */
public static void sendTitle(@Nonnull Player player,
                             int fadeIn, int stay, int fadeOut,
                             @Nullable String title, @Nullable String subtitle) {
    Objects.requireNonNull(player, "Cannot send title to null player");
    if (title == null && subtitle == null) return;
    if (supported) {
        player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
        return;
    }

    try {
        Object timesPacket = PACKET.invoke(TIMES, CHAT_COMPONENT_TEXT.invoke(title), fadeIn, stay, fadeOut);
        ReflectionUtils.sendPacket(player, timesPacket);

        if (title != null) {
            Object titlePacket = PACKET.invoke(TITLE, CHAT_COMPONENT_TEXT.invoke(title), fadeIn, stay, fadeOut);
            ReflectionUtils.sendPacket(player, titlePacket);
        }
        if (subtitle != null) {
            Object subtitlePacket = PACKET.invoke(SUBTITLE, CHAT_COMPONENT_TEXT.invoke(subtitle), fadeIn, stay, fadeOut);
            ReflectionUtils.sendPacket(player, subtitlePacket);
        }
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
}
 
Example 6
Source File: ForSaleEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public static void sendTitleForSale(Region region, RegionType regionType, Player player) {

        Civilian civilian = CivilianManager.getInstance().getCivilian(player.getUniqueId());
        if (civilian.isAtMax(regionType) != null) {
            return;
        }
        String title = " ";
        String subTitle = LocaleManager.getInstance().getTranslation(civilian.getLocale(), "region-sale-set")
                .replace("$1", regionType.getName())
                .replace("$2", Util.getNumberFormat(region.getForSale(), civilian.getLocale()));
        player.sendTitle(title, subTitle, 5, 40, 5);
    }
 
Example 7
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 8
Source File: TitleNotifyIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendNotify(String message, Collection<? extends Player> players) {
    for (Player player : players) {
        player.sendTitle(Utils.format(message), Utils.format(subTitle), fadeIn, stay, fadeOut);
    }

    super.sendNotify(message, players);
}
 
Example 9
Source File: SubTitleNotifyIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void sendNotify(String message, Collection<? extends Player> players) {
    for (Player player : players) {
        player.sendTitle("", Utils.format(message), fadeIn, stay, fadeOut);
    }

    super.sendNotify(message, players);
}
 
Example 10
Source File: TeleportationManager.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void cancel(UUID uuid, Player p) {
    teleporterUsers.remove(uuid);

    if (p != null) {
        p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.cancelled")), ChatColors.color("&c&k40&f&c%"), 20, 60, 20);
    }
}
 
Example 11
Source File: TeleportationManager.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void updateProgress(UUID uuid, int speed, int progress, Location source, Location destination, boolean resistance) {
    Player p = Bukkit.getPlayer(uuid);

    if (isValid(p, source)) {
        if (progress > 99) {
            p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.teleported")), ChatColors.color("&b100%"), 20, 60, 20);
            p.teleport(destination);

            if (resistance) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 600, 20));
                SlimefunPlugin.getLocalization().sendMessage(p, "machines.TELEPORTER.invulnerability");
            }

            destination.getWorld().spawnParticle(Particle.PORTAL, new Location(destination.getWorld(), destination.getX(), destination.getY() + 1, destination.getZ()), progress * 2, 0.2F, 0.8F, 0.2F);
            destination.getWorld().playSound(destination, Sound.BLOCK_BEACON_ACTIVATE, 1F, 1F);
            teleporterUsers.remove(uuid);
        }
        else {
            p.sendTitle(ChatColors.color(SlimefunPlugin.getLocalization().getMessage(p, "machines.TELEPORTER.teleporting")), ChatColors.color("&b" + progress + "%"), 0, 60, 0);

            source.getWorld().spawnParticle(Particle.PORTAL, source, progress * 2, 0.2F, 0.8F, 0.2F);
            source.getWorld().playSound(source, Sound.BLOCK_BEACON_AMBIENT, 1F, 0.6F);

            Slimefun.runSync(() -> updateProgress(uuid, speed, progress + speed, source, destination, resistance), 10L);
        }
    }
    else {
        cancel(uuid, p);
    }
}
 
Example 12
Source File: QualityArmory.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
public static void sendHotbarGunAmmoCount(final Player p, final CustomBaseObject gun,
			ItemStack usedItem, boolean reloading, int currentAmountInGun, int maxAmount) {

	final Gun g;
	AttachmentBase base = null;
	if(gun instanceof AttachmentBase){
		base = (AttachmentBase)gun;
		g = base.getBaseGun();
	}else{
		g = (Gun) gun;
	}

	int ammoamount = getAmmoInInventory(p, g.getAmmoType());

	if (QAMain.showOutOfAmmoOnTitle && ammoamount <= 0 && Gun.getAmount(usedItem) < 1) {
		p.sendTitle(" ", QAMain.S_OUT_OF_AMMO, 0, 20, 1);
	} else if (QAMain.showReloadOnTitle && reloading) {
		for (int i = 1; i < g.getReloadTime() * 20; i += 2) {
			final int id = i;
			new BukkitRunnable() {
				@Override
				public void run() {
					StringBuilder sb = new StringBuilder();
					sb.append(ChatColor.GRAY);
					sb.append(StringUtils.repeat("#", (int) (20 * (1.0 * id / (20 * g.getReloadTime())))));
					sb.append(ChatColor.DARK_GRAY);
					sb.append(StringUtils.repeat("#", (int) (20 - ((int) (20.0 * id / (20 * g.getReloadTime()))))));
					p.sendTitle(QAMain.S_RELOADING_MESSAGE, sb.toString(), 0, 4, 0);
				}
			}.runTaskLater(QAMain.getInstance(), i);
		}
	} else {

		try {
			String message = QAMain.S_HOTBAR_FORMAT;

			if (QAMain.disableHotBarMessageOnOutOfAmmo && QAMain.disableHotBarMessageOnReload
					&& QAMain.disableHotBarMessageOnShoot)
				return;
			if (reloading && QAMain.disableHotBarMessageOnReload)
				return;
			if (ammoamount <= 0 && QAMain.disableHotBarMessageOnOutOfAmmo)
				return;
			if (!reloading && ammoamount > 0 && QAMain.disableHotBarMessageOnShoot)
				return;

			if (message.contains("%name%"))
				message = message.replace("%name%",
						(base != null ? base.getDisplayName() : g.getDisplayName()));
			if (message.contains("%amount%"))
				message = message.replace("%amount%", currentAmountInGun + "");
			if (message.contains("%max%"))
				message = message.replace("%max%", maxAmount + "");

			if (message.contains("%state%"))
				message = message.replace("%state%", reloading ? QAMain.S_RELOADING_MESSAGE
						: ammoamount <= 0 ? QAMain.S_OUT_OF_AMMO : QAMain.S_MAX_FOUND);
			if (message.contains("%total%"))
				message = message.replace("%total%", "" + ammoamount);

			if (QAMain.unknownTranslationKeyFixer) {
				message = ChatColor.stripColor(message);
			} else {
				message = ChatColor.translateAlternateColorCodes('&', message);
			}
			HotbarMessager.sendHotBarMessage(p, message);
		} catch (Error | Exception e5) {
		}
	}
}
 
Example 13
Source File: Title_Bukkit.java    From Quests with MIT License 4 votes vote down vote up
@Override
public void sendTitle(Player player, String message, String submessage) {
    player.sendTitle(message, submessage, 10, 100, 10);
}
 
Example 14
Source File: Title_BukkitNoTimings.java    From Quests with MIT License 4 votes vote down vote up
@Override
public void sendTitle(Player player, String message, String submessage) {
    player.sendTitle(message, submessage);
}
 
Example 15
Source File: CommandHandler.java    From EliteMobs with GNU General Public License v3.0 4 votes vote down vote up
public static boolean permCheck(String permission, CommandSender commandSender) {

        if (commandSender.hasPermission(permission)) return true;

        if (commandSender instanceof Player &&
                Bukkit.getPluginManager().getPlugin(MetadataHandler.ELITE_MOBS).getConfig().getBoolean(DefaultConfig.ENABLE_PERMISSION_TITLES)) {

            Player player = (Player) commandSender;

            player.sendTitle(ConfigValues.translationConfig.getString(TranslationConfig.MISSING_PERMISSION_TITLE).replace("$username", player.getDisplayName()),
                    ConfigValues.translationConfig.getString(TranslationConfig.MISSING_PERMISSION_SUBTITLE).replace("$permission", permission));

        } else {

            commandSender.sendMessage("[EliteMobs] You may not run this command.");
            commandSender.sendMessage("[EliteMobs] You don't have the permission " + permission);

        }

        return false;

    }
 
Example 16
Source File: Utils.java    From ArmorStandTools with MIT License 4 votes vote down vote up
static void actionBarMsg(Player p, String msg) {
    p.sendTitle("", msg, 0, 70, 0);
}