Created the language panel. It is currently not localized.

This commit is contained in:
Florian CUNY 2018-04-23 21:16:08 +02:00
parent 45101901bd
commit 5ebbc2e374
12 changed files with 163 additions and 18 deletions

View File

@ -10,6 +10,11 @@
#
# This translation is adapted to version : [alpha-1]
banner:
- "RED"
- "STRIPE_RIGHT:BLACK"
- "STRIPE_LEFT:YELLOW"
not-setup:
header: |-
Es werden weitere Einstellungen benötigt, bevor das Plugin genutzt werden kann...

View File

@ -9,6 +9,15 @@
#
# This translation is adapted to version : [alpha-1]
banner:
- "BLUE"
- "STRIPE_DOWNLEFT:WHITE"
- "STRIPE_DOWNRIGHT:WHITE"
- "STRIPE_CENTER:WHITE"
- "STRIPE_MIDDLE:WHITE"
- "STRAIGHT_CROSS:RED"
- "CROSS:RED"
not-setup:
header: |-
More set up is required before the plugin can start...

View File

@ -9,6 +9,12 @@
#
# This translation is adapted to version : [alpha-2]
banner:
- "WHITE"
- "STRIPE_SMALL:RED"
- "SQUARE_TOP_RIGHT:CYAN"
- "SQUARE_TOP_RIGHT:BLUE"
general:
deaths: "Deaths"
unlimited: "Unlimited"
@ -42,7 +48,6 @@ commands:
admin:
help:
description: "admin command"
parameters: ""
version:
description: "display %bsb_plugin_name% and addons versions"
setrange:
@ -161,7 +166,6 @@ commands:
description: "display island settings"
language:
description: "select language"
parameters: "<language>"
ranks:
owner: "Owner"

View File

@ -9,6 +9,11 @@
#
# Cette traduction est adaptée pour la version : [alpha-1]
banner:
- "WHITE"
- "STRIPE_BOTTOM:RED"
- "STRIPE_TOP:BLUE"
not-setup:
header: |-
Configuration nécessaire avant de pouvoir utiliser le plugin...

View File

@ -9,6 +9,15 @@
# DuckSoft: translator
# This translation is adapted to version : [alpha-1]
banner:
- "RED"
- "SQUARE_TOP_RIGHT:YELLOW"
- "CROSS:RED"
- "CURLY_BORDER:RED"
- "MOJANG:YELLOW"
- "HALF_HORIZONTAL_MIRROR:RED"
- "HALF_VERTICAL:RED"
not-setup:
header: |-
在此插件能正常运作之前, 您需要更多设置...

View File

@ -1,21 +1,51 @@
package us.tastybento.bskyblock.api.localization;
import java.io.File;
import java.util.List;
import java.util.Locale;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta;
/**
* @author Poslovitch, Tastybento
* @author Poslovitch, tastybento
*/
public class BSBLocale {
private Locale locale;
private YamlConfiguration config;
private ItemStack banner;
public BSBLocale(Locale locale, File file) {
this.locale = locale;
config = YamlConfiguration.loadConfiguration(file);
// Load the banner from the configuration
List<String> bannerLayers = config.getStringList("banner");
if (bannerLayers != null && !bannerLayers.isEmpty()) {
banner = new ItemStack(Material.BANNER, 1);
BannerMeta meta = (BannerMeta) banner.getItemMeta();
meta.setBaseColor(DyeColor.valueOf(bannerLayers.get(0)));
bannerLayers.remove(0);
for (String s : bannerLayers) {
String[] pattern = s.split(":");
meta.addPattern(new Pattern(DyeColor.valueOf(pattern[1]), PatternType.valueOf(pattern[0])));
}
banner.setItemMeta(meta);
} else {
banner = new ItemStack(Material.BANNER, 1);
BannerMeta meta = (BannerMeta) banner.getItemMeta();
meta.setBaseColor(DyeColor.WHITE);
banner.setItemMeta(meta);
}
}
/**
@ -62,6 +92,14 @@ public class BSBLocale {
return locale.toLanguageTag();
}
/**
* Returns the banner ItemStack representing this locale
* @return the banner ItemStack
*/
public ItemStack getBanner() {
return banner;
}
/**
* Merges a language YAML file to this locale
* @param language

View File

@ -44,6 +44,7 @@ public class PanelItem {
meta.addItemFlags(ItemFlag.HIDE_DESTROYS);
meta.addItemFlags(ItemFlag.HIDE_PLACED_ON);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
icon.setItemMeta(meta);
}

View File

@ -6,14 +6,7 @@ import java.util.List;
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.island.IslandAboutCommand;
import us.tastybento.bskyblock.commands.island.IslandCreateCommand;
import us.tastybento.bskyblock.commands.island.IslandGoCommand;
import us.tastybento.bskyblock.commands.island.IslandResetCommand;
import us.tastybento.bskyblock.commands.island.IslandResetnameCommand;
import us.tastybento.bskyblock.commands.island.IslandSethomeCommand;
import us.tastybento.bskyblock.commands.island.IslandSetnameCommand;
import us.tastybento.bskyblock.commands.island.IslandSettingsCommand;
import us.tastybento.bskyblock.commands.island.*;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
public class IslandCommand extends CompositeCommand {
@ -40,6 +33,7 @@ public class IslandCommand extends CompositeCommand {
new IslandResetnameCommand(this);
new IslandSethomeCommand(this);
new IslandSettingsCommand(this);
new IslandLanguageCommand(this);
// Team commands
new IslandTeamCommand(this);
}

View File

@ -1,4 +1,38 @@
package us.tastybento.bskyblock.commands.island;
public class IslandLanguageCommand {
}
import us.tastybento.bskyblock.Constants;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.panels.LanguagePanel;
import java.util.List;
/**
* @author Poslovitch
*/
public class IslandLanguageCommand extends CompositeCommand {
public IslandLanguageCommand(IslandCommand islandCommand) {
super(islandCommand, "language", "lang");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CompositeCommand#setup()
*/
@Override
public void setup() {
setPermission(Constants.PERMPREFIX + "island.language");
setOnlyPlayer(true);
setDescription("commands.island.language.description");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public boolean execute(User user, List<String> args) {
LanguagePanel.openPanel(user);
return true;
}
}

View File

@ -53,7 +53,6 @@ public class IslandBuilder {
world = island.getWorld();
}
/**
* @param type the type to set
*/
@ -77,7 +76,6 @@ public class IslandBuilder {
return this;
}
/**
* @param player - the player the player to set
*/
@ -87,7 +85,6 @@ public class IslandBuilder {
return this;
}
/**
* @param list the default chestItems to set
*/
@ -96,7 +93,6 @@ public class IslandBuilder {
return this;
}
public void build() {
// Switch on island type
if (type == IslandType.ISLAND) {

View File

@ -6,6 +6,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.localization.BSBLocale;
@ -13,7 +15,7 @@ import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.util.FileLister;
/**
* @author Tastybento, Poslovitch
* @author tastybento, Poslovitch
*/
public class LocalesManager {
@ -101,7 +103,13 @@ public class LocalesManager {
} catch (IOException e) {
plugin.getLogger().severe("Could not copy locale files from jar " + e.getMessage());
}
}
public Set<Locale> getAvailableLocales() {
return languages.keySet();
}
public Map<Locale, BSBLocale> getLanguages() {
return this.languages;
}
}

View File

@ -0,0 +1,42 @@
package us.tastybento.bskyblock.panels;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
import us.tastybento.bskyblock.api.user.User;
import java.util.Locale;
/**
* @author Poslovitch
*/
public class LanguagePanel {
/**
* Dynamically creates the panel.
* @param user the User to show the panel to
*/
public static void openPanel(User user) {
PanelBuilder panelBuilder = new PanelBuilder()
.name(user.getTranslation("languages.panel.title"));
for (Locale locale : BSkyBlock.getInstance().getLocalesManager().getAvailableLocales()) {
PanelItemBuilder localeIcon = new PanelItemBuilder().icon(BSkyBlock.getInstance().getLocalesManager().getLanguages().get(locale).getBanner())
.name("languages." + locale.toLanguageTag() + ".name")
.clickHandler((u, click) -> {
BSkyBlock.getInstance().getPlayers().setLocale(u.getUniqueId(), locale.toLanguageTag());
u.sendMessage("language.changed");
u.closeInventory();
return true;
});
if (user.getLocale().toLanguageTag().equals(locale.toLanguageTag())) {
localeIcon.description("language.already-selected");
}
panelBuilder.item(localeIcon.build());
}
panelBuilder.build().open(user);
}
}