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

The following examples show how to use org.bukkit.entity.Player#getLocale() . 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: VersionUtil.java    From ExploitFixer with GNU General Public License v3.0 5 votes vote down vote up
public static String getLocale(final Player player) {
	final String locale;

	if (VersionUtil.isOneDotFifteen()) {
		locale = player.getLocale();
	} else {
		locale = player.spigot().getLocale();
	}

	if (locale != null && locale.length() > 1) {
		return locale.substring(0, 2);
	} else {
		return "en";
	}
}
 
Example 2
Source File: SpectatorTools.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    ItemStack item = event.getCurrentItem();
    Player player = (Player) event.getWhoClicked();
    String locale = player.getLocale();
    if (item == null) return;
    if (event.getInventory().getName().equals(getSpectatorMenuTitle(event.getActor().getLocale()))) {
        if (item.isSimilar(getTeleportItem(locale))) {
            player.openInventory(getTeamsMenu(player));
        } else if (item.isSimilar(getVisibilityItem(locale))) {
            Bukkit.dispatchCommand(player, "toggle obs");
            player.closeInventory();
        } else if (item.isSimilar(getElytraItem(locale))) {
            Bukkit.dispatchCommand(player, "toggle elytra");
            player.closeInventory();
        } else if (item.isSimilar(getEffectsItem(locale))) {
            player.openInventory(getEffectsMenu(player));
        } else if (item.isSimilar(getGamemodeItem(locale))) {
            player.setGameMode(player.getGameMode().equals(GameMode.CREATIVE) ? GameMode.SPECTATOR : GameMode.CREATIVE);
            if (player.getGameMode().equals(GameMode.CREATIVE)) Bukkit.dispatchCommand(player, "!");
            player.closeInventory();
        }
    } else if (event.getInventory().getName().equals(getTeamsMenuTitle(locale))) {
        if (item.isSimilar(getGoBackItem(locale))) {
            player.openInventory(getSpectatorMenu(player));
        } else if (item.getType().equals(Material.LEATHER_HELMET) && item.getItemMeta().hasDisplayName() && !item.isSimilar(TeamPicker.getTeamPicker(locale))){
            TeamModule team = Teams.getTeamByName(ChatColor.stripColor(Strings.removeLastWord(item.getItemMeta().getDisplayName()))).orNull();
            if (team != null) {
                player.openInventory(getTeleportMenu(player, team));
            }
        }
    } else if (event.getInventory().getName().equals(getTeleportMenuTitle(locale))) {
        if (item.isSimilar(getGoBackItem(locale))) {
            player.openInventory(getTeamsMenu(player));
        } else if (item.getType().equals(Material.SKULL_ITEM) && item.getItemMeta().hasDisplayName()) {
            Player teleport = Bukkit.getPlayer(((SkullMeta) item.getItemMeta()).getOwner());
            if (teleport != null) {
                player.teleport(teleport);
                player.closeInventory();
            }
        }
    } else if (event.getInventory().getName().equals(getEffectsMenuTitle(locale))) {
        if (item.isSimilar(getGoBackItem(locale))) {
            player.openInventory(getSpectatorMenu(player));
        } else if (item.isSimilar(getNightVisionItem(player.getLocale()))) {
            if (player.hasPotionEffect(PotionEffectType.NIGHT_VISION)) {
                player.removePotionEffect(PotionEffectType.NIGHT_VISION);
            } else {
                player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0, false, false));
            }
            player.closeInventory();
        } else if (item.getType().equals(Material.SUGAR) && item.getItemMeta().hasDisplayName()) {
            int value = event.getSlot();
            Setting setting = Settings.getSettingByName("Speed");
            Bukkit.dispatchCommand(player, "set speed " + setting.getValues().get(value).getValue());
            player.closeInventory();
        }
    }
}
 
Example 3
Source File: LocaleHelper.java    From LanguageUtils with MIT License 2 votes vote down vote up
/**
 * Return the language of the player
 *
 * @param player The player to be analyzed
 * @return the language of the player(in Java locale format)
 */
public static String getPlayerLanguage(Player player) {
    return player.getLocale();
}