mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Added ItemName i18n testing
Former-commit-id: 4f6e366ec1c96485910a49d0b62c7ab19271dbce
This commit is contained in:
1 parent
28b9d0acb5
commit
539fd2b3ff
6 files changed
+41
-24
No files matched your search
@@ -193,7 +193,7 @@ public class PlayerListener implements Listener {
|
||||
public void onPlayerPickup(EntityPickupItemEvent e) {
|
||||
ItemStack stack = e.getItem().getItemStack();
|
||||
try {
|
||||
if (stack.getItemMeta().getDisplayName().startsWith(ChatColor.RED + "QuickShop ")) {
|
||||
if (stack.getItemMeta().getDisplayName().equals("QuickShop")) {
|
||||
e.setCancelled(true);
|
||||
// You shouldn't be able to pick up that...
|
||||
}
|
||||
|
||||
@@ -392,6 +392,7 @@ public class QuickShop extends JavaPlugin {
|
||||
|
||||
getLogger().info("Loaded " + count + " shops.");
|
||||
MsgUtil.loadTransactionMessages();
|
||||
MsgUtil.loadItemi18n();
|
||||
MsgUtil.clean();
|
||||
// Register events
|
||||
getLogger().info("Registering Listeners");
|
||||
|
||||
@@ -12,7 +12,9 @@ import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -21,6 +23,8 @@ import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
|
||||
import net.minecraft.server.v1_13_R1.StatusChallengeUtils;
|
||||
|
||||
public class MsgUtil {
|
||||
private static QuickShop plugin;
|
||||
private static YamlConfiguration messages;
|
||||
@@ -64,13 +68,37 @@ public class MsgUtil {
|
||||
msgs = new LinkedList<String>();
|
||||
player_messages.put(owner, msgs);
|
||||
}
|
||||
msgs.add(message);
|
||||
}
|
||||
msgs.add(message);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Could not load transaction messages from database. Skipping.");
|
||||
}
|
||||
}
|
||||
public static void loadItemi18n() {
|
||||
plugin.getLogger().info("Starting loading Itemname i18n...");
|
||||
FileConfiguration config = plugin.getConfig();
|
||||
Material[] itemsi18n = Material.values();
|
||||
for (Material material : itemsi18n) {
|
||||
String itemname = config.getString("itemi18n."+material.name());
|
||||
if(itemname==null || itemname.equals("")) {
|
||||
plugin.getLogger().info("Found new items/blocks,add it in config...");
|
||||
config.set("itemi18n."+material.name(), material.name());
|
||||
}
|
||||
}
|
||||
plugin.getLogger().info("Complete to load Itemname i18n.");
|
||||
}
|
||||
public static String getItemi18n(String ItemBukkitName) {
|
||||
String Itemname_i18n = plugin.getConfig().getString("itemi18n."+ItemBukkitName);
|
||||
if(ItemBukkitName==null) {
|
||||
return "";
|
||||
}
|
||||
if(Itemname_i18n==null || Itemname_i18n.equals("")) {
|
||||
return Material.matchMaterial("ItemBukkitName").name();
|
||||
}else {
|
||||
return Itemname_i18n;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
|
||||
@@ -319,7 +319,7 @@ public class Util {
|
||||
return customItemName.getFullName();
|
||||
}
|
||||
|
||||
String vanillaName = getDataName(itemStack.getType(), itemStack.getDurability());
|
||||
String vanillaName = MsgUtil.getItemi18n(itemStack.getType().name());
|
||||
return prettifyText(vanillaName);
|
||||
}
|
||||
|
||||
@@ -358,7 +358,7 @@ public class Util {
|
||||
return customItemName.getSignName();
|
||||
}
|
||||
|
||||
String name = getDataName(itemStack.getType(), itemStack.getDurability());
|
||||
String name = MsgUtil.getItemi18n(itemStack.getType().name());
|
||||
|
||||
String[] nameParts = name.split("_");
|
||||
if (nameParts.length==1) {
|
||||
@@ -416,23 +416,6 @@ public class Util {
|
||||
}
|
||||
return roman;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a given material and data value into a format similar to
|
||||
* Material.<?>.toString(). Upper case, with underscores. Includes material
|
||||
* name in result.
|
||||
*
|
||||
* @param mat
|
||||
* The base material.
|
||||
* @param damage
|
||||
* The durability/damage of the item.
|
||||
* @return A string with the name of the item.
|
||||
*/
|
||||
private static String getDataName(Material mat, short damage) {
|
||||
return mat.name();
|
||||
//Not need in 1.13
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mat
|
||||
* The material to check
|
||||
|
||||
Reference in new issue
Block a user