Lang support perks + Component-ization
LAng supports multiline (ie with lore)
This commit is contained in:
1 parent
d1c931cff0
commit
6f9d4657ea
10 files changed
+169
-89
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package me.lifelessnerd.purekitpvp;
|
||||
|
||||
import me.lifelessnerd.purekitpvp.custommobs.CustomMobCommand;
|
||||
import me.lifelessnerd.purekitpvp.files.LanguageConfig;
|
||||
import me.lifelessnerd.purekitpvp.files.MobSpawnConfig;
|
||||
import me.lifelessnerd.purekitpvp.createKit.*;
|
||||
import me.lifelessnerd.purekitpvp.customitems.GetCustomItem;
|
||||
@@ -12,8 +13,9 @@ import me.lifelessnerd.purekitpvp.globalevents.GlobalEventManager;
|
||||
import me.lifelessnerd.purekitpvp.globalevents.events.AbstractEvent;
|
||||
import me.lifelessnerd.purekitpvp.kitCommand.ResetKit;
|
||||
import me.lifelessnerd.purekitpvp.noncombatstats.commands.GetKitStats;
|
||||
import me.lifelessnerd.purekitpvp.utils.ComponentUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@@ -57,17 +59,17 @@ public class AdminCommandManager implements TabExecutor {
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(Component.text("The console cannot perform these commands."));
|
||||
return false;
|
||||
return false; // TODO make this subcommand specific
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!(player.hasPermission("purekitpvp.admin.*"))) {
|
||||
player.sendMessage(Component.text("You do not have permission!").color(NamedTextColor.RED));
|
||||
player.sendMessage(LanguageConfig.lang.get("GENERIC_NO_PERMISSION"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
player.sendMessage(Component.text("Please specify what function to use."));
|
||||
player.sendMessage(LanguageConfig.lang.get("GENERIC_LACK_OF_ARGS"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -79,8 +81,8 @@ public class AdminCommandManager implements TabExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
player.sendMessage(args[0] + " is not a valid sub-command.");
|
||||
TextReplacementConfig config = ComponentUtils.replaceConfig("%ARG%", args[0]);
|
||||
player.sendMessage(LanguageConfig.lang.get("GENERIC_WRONG_ARGS").replaceText(config));
|
||||
return false;
|
||||
|
||||
}
|
||||
@@ -160,7 +162,7 @@ public class AdminCommandManager implements TabExecutor {
|
||||
key = key.toLowerCase();
|
||||
autoComplete.add(key);
|
||||
}
|
||||
;
|
||||
|
||||
return autoComplete;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package me.lifelessnerd.purekitpvp;
|
||||
|
||||
import me.lifelessnerd.purekitpvp.files.LanguageConfig;
|
||||
import me.lifelessnerd.purekitpvp.utils.ComponentUtils;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@@ -63,6 +65,9 @@ public class AdminHelpCommand extends Subcommand {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
|
||||
}
|
||||
|
||||
} else {
|
||||
TextReplacementConfig config = ComponentUtils.replaceConfig("%ARG%", args[1]);
|
||||
player.sendMessage(LanguageConfig.lang.get("GENERIC_WRONG_ARGS").replaceText(config));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import me.lifelessnerd.purekitpvp.noncombatstats.listeners.ArrowsShotStat;
|
||||
import me.lifelessnerd.purekitpvp.noncombatstats.listeners.ProjectilesThrownStat;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.commons.codec.language.bm.Lang;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
@@ -74,18 +75,10 @@ public final class PureKitPvP extends JavaPlugin {
|
||||
CosmeticsConfig.get().options().copyDefaults(true);
|
||||
CosmeticsConfig.save();
|
||||
|
||||
EventData.setup();
|
||||
EventData.get().options().copyDefaults(true);
|
||||
EventData.save();
|
||||
|
||||
File lang = new File(getDataFolder(), "lang");
|
||||
if(!lang.exists()) {
|
||||
lang.mkdirs();
|
||||
}
|
||||
//TODO Check what language is selected in config
|
||||
//Based on that load map from en_US.yml into a translation Map
|
||||
// Use this map everywhere to query text
|
||||
|
||||
LanguageConfig.setup();
|
||||
LanguageConfig.get().options().copyDefaults(true);
|
||||
LanguageConfig.save();
|
||||
LanguageConfig.loadLanguage();
|
||||
|
||||
TabManager tabManager = new TabManager(this);
|
||||
tabManager.addHeader(Component.text("Hello there!").color(NamedTextColor.RED));
|
||||
|
||||
@@ -3,12 +3,9 @@ package me.lifelessnerd.purekitpvp;
|
||||
import me.lifelessnerd.purekitpvp.files.*;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ReloadPlugin extends Subcommand {
|
||||
Plugin plugin;
|
||||
@@ -60,6 +57,10 @@ public class ReloadPlugin extends Subcommand {
|
||||
CosmeticsConfig.reload();
|
||||
CosmeticsConfig.save();
|
||||
|
||||
LanguageConfig.reload();
|
||||
LanguageConfig.loadLanguage();
|
||||
LanguageConfig.save();
|
||||
|
||||
plugin.reloadConfig();
|
||||
plugin.getConfig();
|
||||
plugin.saveConfig();
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package me.lifelessnerd.purekitpvp.files;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class EventData {
|
||||
|
||||
private static File file;
|
||||
private static FileConfiguration customFile;
|
||||
|
||||
public static void setup(){
|
||||
|
||||
file = new File(Bukkit.getServer().getPluginManager().getPlugin("PureKitPvP").getDataFolder(), "eventdata.yml");
|
||||
if (!(file.exists())){
|
||||
try{
|
||||
file.createNewFile();
|
||||
} catch (IOException e){
|
||||
//pain
|
||||
}
|
||||
}
|
||||
customFile = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static FileConfiguration get(){
|
||||
return customFile;
|
||||
}
|
||||
|
||||
public static void save(){
|
||||
try{
|
||||
customFile.save(file);
|
||||
} catch (IOException e){
|
||||
System.out.println("Cannot save!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void reload(){
|
||||
customFile = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package me.lifelessnerd.purekitpvp.files;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LanguageConfig {
|
||||
|
||||
private static File file;
|
||||
private static FileConfiguration customFile;
|
||||
|
||||
public static HashMap<String, Component> lang;
|
||||
|
||||
public static Map<String, Object> defaults;
|
||||
|
||||
public static void setup(){
|
||||
|
||||
defaults = new HashMap<>();
|
||||
lang = new HashMap<>();
|
||||
|
||||
file = new File(Bukkit.getServer().getPluginManager().getPlugin("PureKitPvP").getDataFolder(), "lang.yml");
|
||||
if (!(file.exists())){
|
||||
try{
|
||||
file.createNewFile();
|
||||
} catch (IOException e){
|
||||
//pain
|
||||
}
|
||||
}
|
||||
customFile = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// Language defaults
|
||||
defaults.put("GENERIC_NO_PERMISSION", "&cYou do not have permission!");
|
||||
defaults.put("GENERIC_LACK_OF_ARGS", "&cNot enough arguments!");
|
||||
defaults.put("GENERIC_WRONG_ARGS", "%ARG% &cis not a valid argument!");
|
||||
defaults.put("GENERIC_WRONG_WORLD", "&cYou can only use this menu in &7%WORLD%");
|
||||
defaults.put("PERKS_ALREADY_SELECTED", "&cYou can only change perks when you have no kit selected!");
|
||||
defaults.put("PERKS_GUI_TITLE", "&6Perks Menu");
|
||||
defaults.put("PERKS_GUI_INFO_TITLE", "&cPerks Info");
|
||||
defaults.put("PERKS_GUI_INFO_LORE", """
|
||||
&aYou can equip a total of &e5 &aperks total.
|
||||
&7Click on a perk slot to choose a perk for that slot.
|
||||
&7It will replace any perk currently in that slot.
|
||||
&7Perks are abilities that are always active.
|
||||
&7Duplicate perks do not stack.
|
||||
""");
|
||||
|
||||
defaults.put("KITS_GUI_TITLE", "Kitties");
|
||||
defaults.put("KITS_GUI_PREV", "Previous");
|
||||
defaults.put("KITS_GUI_NEXT", "Next");
|
||||
|
||||
|
||||
customFile.addDefaults(defaults);
|
||||
}
|
||||
|
||||
public static FileConfiguration get(){
|
||||
return customFile;
|
||||
}
|
||||
|
||||
public static void save(){
|
||||
try{
|
||||
customFile.save(file);
|
||||
} catch (IOException e){
|
||||
System.out.println("Cannot save!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void reload(){
|
||||
customFile = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static void loadLanguage(){
|
||||
// Take data out of file; store it in map
|
||||
LegacyComponentSerializer serializer = LegacyComponentSerializer.legacyAmpersand();
|
||||
for (String key : get().getKeys(false)) {
|
||||
lang.put(key, serializer.deserialize(get().getString(key)));
|
||||
// System.out.println(key + ": " + get().getString(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+2
-2
@@ -61,7 +61,7 @@ public class GlobalEventManager {
|
||||
}
|
||||
if (amount >= 1) {
|
||||
globalTimer++;
|
||||
System.out.println(1 + " - " + globalTimer);
|
||||
// System.out.println(1 + " - " + globalTimer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public class GlobalEventManager {
|
||||
}
|
||||
if (amount >= 1) {
|
||||
globalTimer++;
|
||||
System.out.println(2 + " - " + globalTimer);
|
||||
// System.out.println(2 + " - " + globalTimer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package me.lifelessnerd.purekitpvp.kitCommand;
|
||||
|
||||
import me.lifelessnerd.purekitpvp.Subcommand;
|
||||
import me.lifelessnerd.purekitpvp.files.LanguageConfig;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -37,8 +39,9 @@ public class ResetKit extends Subcommand {
|
||||
@Override
|
||||
public boolean perform(Player player, String[] args) {
|
||||
|
||||
|
||||
if(!(player.hasPermission("purekitpvp.admin.resetkit"))){
|
||||
player.sendMessage(ChatColor.RED + "You do not have permission!");
|
||||
player.sendMessage(LanguageConfig.lang.get("GENERIC_NO_PERMISSION"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+11
-16
@@ -1,6 +1,6 @@
|
||||
package me.lifelessnerd.purekitpvp.perks.perkCommand;
|
||||
|
||||
import me.lifelessnerd.purekitpvp.files.KitConfig;
|
||||
import me.lifelessnerd.purekitpvp.files.LanguageConfig;
|
||||
import me.lifelessnerd.purekitpvp.files.PerkData;
|
||||
import me.lifelessnerd.purekitpvp.kitCommand.GetKit;
|
||||
import me.lifelessnerd.purekitpvp.perks.perkfirehandler.PerkLib;
|
||||
@@ -8,7 +8,6 @@ import me.lifelessnerd.purekitpvp.utils.ComponentUtils;
|
||||
import me.lifelessnerd.purekitpvp.utils.MyStringUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -17,7 +16,6 @@ import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
@@ -28,7 +26,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PerkCommand implements CommandExecutor {
|
||||
@@ -47,29 +44,27 @@ public class PerkCommand implements CommandExecutor {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (!(player.getWorld().getName().equalsIgnoreCase(plugin.getConfig().getString("world")))){
|
||||
player.sendMessage(
|
||||
Component.text("You can only use this menu in ", NamedTextColor.RED).append(
|
||||
Component.text(plugin.getConfig().getString("world"), NamedTextColor.GRAY)));
|
||||
player.sendMessage(LanguageConfig.lang.get("GENERIC_WRONG_WORLD").
|
||||
replaceText(ComponentUtils.replaceConfig("%WORLD%",plugin.getConfig().getString("world"))));
|
||||
return true;
|
||||
}
|
||||
if (GetKit.hasKit.contains(player.getName())){
|
||||
player.sendMessage(ChatColor.RED + "You can only change perks when you have no kit selected!");
|
||||
player.sendMessage(LanguageConfig.lang.get("PERKS_ALREADY_SELECTED"));
|
||||
return true;
|
||||
}
|
||||
//Create inventory GUI
|
||||
TextComponent invTitle = Component.text("Perks Menu").color(TextColor.color(255, 150, 20));
|
||||
Component invTitle = LanguageConfig.lang.get("PERKS_GUI_TITLE");
|
||||
Inventory perksInventory = Bukkit.createInventory(null, 54, invTitle);
|
||||
|
||||
//Info item
|
||||
ItemStack infoItem = new ItemStack(Material.BOOK);
|
||||
TextComponent infoItemName = Component.text("Perks Info").color(TextColor.color(233, 67, 47)).decoration(TextDecoration.ITALIC, false);
|
||||
Component infoItemName = LanguageConfig.lang.get("PERKS_GUI_INFO_TITLE");
|
||||
ItemMeta infoMeta = infoItem.getItemMeta();
|
||||
infoMeta.displayName(infoItemName);
|
||||
infoMeta = ComponentUtils.setLore(infoMeta, "&aYou can equip a total of &e5 &aperks total.", 0);
|
||||
infoMeta = ComponentUtils.setLore(infoMeta, "&7Click on a perk slot to choose a perk for that slot.", 1);
|
||||
infoMeta = ComponentUtils.setLore(infoMeta, "&7It will replace any perk currently in that slot.", 2);
|
||||
infoMeta = ComponentUtils.setLore(infoMeta, "&7Perks are abilities that are always active.", 3);
|
||||
infoMeta = ComponentUtils.setLore(infoMeta, "&7Duplicate perks do not stack.", 4);
|
||||
|
||||
ArrayList<Component> infoLore = ComponentUtils.splitComponent(LanguageConfig.lang.get("PERKS_GUI_INFO_LORE"));
|
||||
|
||||
infoMeta.lore(infoLore);
|
||||
infoItem.setItemMeta(infoMeta);
|
||||
perksInventory.setItem(13, infoItem);
|
||||
|
||||
@@ -126,7 +121,7 @@ public class PerkCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
player.openInventory(perksInventory);
|
||||
System.out.println(PerkData.get().getString(player.getName()));
|
||||
// System.out.println(PerkData.get().getString(player.getName()));
|
||||
// Create perks config values if not present
|
||||
if (PerkData.get().getString(player.getName()) == null){
|
||||
Set<String> empty = new HashSet<>();
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package me.lifelessnerd.purekitpvp.utils;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import me.lifelessnerd.purekitpvp.PluginGetter;
|
||||
import net.kyori.adventure.text.*;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
@@ -121,4 +122,40 @@ public class ComponentUtils {
|
||||
String json = GsonComponentSerializer.gson().serialize(inputComponent);
|
||||
return net.minecraft.network.chat.Component.Serializer.fromJson(json);
|
||||
}
|
||||
|
||||
public static TextReplacementConfig replaceConfig(String find, String replace){
|
||||
return replaceConfig(find, replace, 1);
|
||||
}
|
||||
public static TextReplacementConfig replaceConfig(String find, String replace, int times){
|
||||
return TextReplacementConfig.builder().matchLiteral(find).replacement(replace).times(times).build();
|
||||
}
|
||||
public static ArrayList<Component> splitComponent(Component massiveComponent){
|
||||
ArrayList<Component> output = new ArrayList<>();
|
||||
// if (!(massiveComponent instanceof TextComponent)){
|
||||
// PluginGetter.Plugin().getLogger().warning("Cannot convert multiline Component!");
|
||||
// return output;
|
||||
// }
|
||||
Component prevChild = Component.text("");
|
||||
for (Component child : massiveComponent.iterable(ComponentIteratorType.DEPTH_FIRST, ComponentIteratorFlag.INCLUDE_HOVER_SHOW_ENTITY_NAME)){
|
||||
//TODO make better condition -> /n is not .newline ? not with equals anyways
|
||||
TextComponent tc = (TextComponent) child;
|
||||
System.out.println(child);
|
||||
if (child.equals(massiveComponent)){
|
||||
continue;
|
||||
}
|
||||
if (tc.content().endsWith("\n")){
|
||||
// TODO Trim \n
|
||||
prevChild = prevChild.append(child).decoration(TextDecoration.ITALIC, false);
|
||||
output.add(prevChild);
|
||||
prevChild = Component.text("");
|
||||
} else {
|
||||
prevChild = prevChild.append(child);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user