mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Several changes to the custom items name. Added potions name section.
This commit is contained in:
1 parent
3444b6451e
commit
b45cf07646
6 files changed
+121
-32
No files matched your search
@@ -6,10 +6,12 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
@@ -25,7 +27,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.maxgamer.quickshop.Command.QS;
|
||||
@@ -50,6 +52,7 @@ import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopManager;
|
||||
import org.maxgamer.quickshop.Shop.ShopType;
|
||||
import org.maxgamer.quickshop.Util.CustomItemName;
|
||||
import org.maxgamer.quickshop.Util.CustomPotionsName;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Permissions;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
@@ -104,7 +107,7 @@ public class QuickShop extends JavaPlugin {
|
||||
/** Whether debug info should be shown in the console */
|
||||
public static boolean debug = false;
|
||||
|
||||
private Map<ItemStack,CustomItemName> customItemNames = new HashMap<ItemStack,CustomItemName>();
|
||||
private Map<Material,List<CustomItemName>> customItemsName = new HashMap<Material,List<CustomItemName>>();
|
||||
|
||||
/** The plugin metrics from Hidendra */
|
||||
// public Metrics getMetrics(){ return metrics; }
|
||||
@@ -156,8 +159,8 @@ public class QuickShop extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(ll, this);
|
||||
}
|
||||
|
||||
if (this.getConfig().isSet("custom-names")) {
|
||||
for (String s : this.getConfig().getStringList("custom-names")) {
|
||||
if (this.getConfig().isSet("custom-items-name")) {
|
||||
for (String s : this.getConfig().getStringList("custom-items-name")) {
|
||||
try {
|
||||
String[] mainVal = s.split("[;]");
|
||||
if (mainVal.length!=3) {
|
||||
@@ -172,18 +175,10 @@ public class QuickShop extends JavaPlugin {
|
||||
|
||||
ItemStack is;
|
||||
if (matVal.length>1) {
|
||||
if (material==Material.POTION) {
|
||||
PotionType potionType = PotionType.valueOf(matVal[1].toUpperCase());
|
||||
if (potionType==null) {
|
||||
throw new Exception("Invalid PotionType: "+matVal[1]);
|
||||
}
|
||||
is = new Potion(potionType).toItemStack(1);
|
||||
} else {
|
||||
try {
|
||||
is = new ItemStack(material, 1, Short.valueOf(matVal[1]));
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Invalid data value: "+matVal[1]);
|
||||
}
|
||||
try {
|
||||
is = new ItemStack(material, 1, Short.valueOf(matVal[1]));
|
||||
} catch (Exception e) {
|
||||
throw new Exception("Invalid data value: "+matVal[1]);
|
||||
}
|
||||
} else {
|
||||
is = new ItemStack(material, 1, (short) 0);
|
||||
@@ -193,13 +188,66 @@ public class QuickShop extends JavaPlugin {
|
||||
Bukkit.getLogger().warning("Custom item name definition {"+s+"} sign name is longer than 16 characters. Only the first 16 characters will be shown.");
|
||||
}
|
||||
|
||||
customItemNames.put(is, new CustomItemName(is, mainVal[1], mainVal[2]));
|
||||
List<CustomItemName> cinList = customItemsName.get(material);
|
||||
if (cinList==null) {
|
||||
cinList = new ArrayList<CustomItemName>();
|
||||
customItemsName.put(material, cinList);
|
||||
}
|
||||
|
||||
cinList.add(new CustomItemName(is, mainVal[1], mainVal[2]));
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning("Invalid custom item name definition {"+s+"} Error: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationSection customPotionsName = this.getConfig().getConfigurationSection("custom-potions-name");
|
||||
if (customPotionsName!=null) {
|
||||
CustomPotionsName.setFullPotionFormat(customPotionsName.getString("format-full"));
|
||||
CustomPotionsName.setSignPotionFormat(customPotionsName.getString("format-sign"));
|
||||
CustomPotionsName.setSplashFull(customPotionsName.getString("splash-full"));
|
||||
CustomPotionsName.setSplashSign(customPotionsName.getString("splash-sign"));
|
||||
Map<PotionType,CustomPotionsName.Names> potionTypes = new HashMap<PotionType,CustomPotionsName.Names>();
|
||||
for (String s : customPotionsName.getStringList("types")) {
|
||||
try {
|
||||
String[] a = s.split("[;]");
|
||||
if (a.length!=3) {
|
||||
throw new Exception("Invalid format (main args length must be 3)");
|
||||
}
|
||||
|
||||
PotionType type = PotionType.valueOf(a[0].toUpperCase());
|
||||
if (type==null) {
|
||||
throw new Exception("Invalid PotionType "+a[0]);
|
||||
}
|
||||
|
||||
potionTypes.put(type, new CustomPotionsName.Names(a[1], a[2]));
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning("Invalid potion item name definition {"+s+"} Error: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
CustomPotionsName.setPotionTypes(potionTypes);
|
||||
|
||||
Map<PotionEffectType,String> potionEffects = new HashMap<PotionEffectType,String>();
|
||||
for (String s : customPotionsName.getStringList("effects")) {
|
||||
try {
|
||||
String[] a = s.split("[;]");
|
||||
if (a.length!=2) {
|
||||
throw new Exception("Invalid format (main args length must be 2)");
|
||||
}
|
||||
|
||||
PotionEffectType type = PotionEffectType.getByName(a[0]);
|
||||
if (type==null) {
|
||||
throw new Exception("Invalid PotionEffectType "+a[0]);
|
||||
}
|
||||
|
||||
potionEffects.put(type, a[1]);
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning("Invalid potion effect type name definition {"+s+"} Error: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
CustomPotionsName.setPotionEffects(potionEffects);
|
||||
}
|
||||
|
||||
ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits");
|
||||
if (limitCfg != null) {
|
||||
getLogger().info("Limit cfg found...");
|
||||
@@ -474,7 +522,18 @@ public class QuickShop extends JavaPlugin {
|
||||
return this.shopManager;
|
||||
}
|
||||
|
||||
public Map<ItemStack, CustomItemName> getCustomItemNames() {
|
||||
return customItemNames;
|
||||
public Map<Material, List<CustomItemName>> getCustomItemsNameMap() {
|
||||
return customItemsName;
|
||||
}
|
||||
|
||||
public CustomItemName getCustomItemNames(ItemStack is) {
|
||||
List<CustomItemName> list = customItemsName.get(is.getType());
|
||||
for (CustomItemName cin : list) {
|
||||
if (cin.matches(is)) {
|
||||
return cin;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,9 @@ public class CustomItemName {
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
public boolean matches(ItemStack otherItemStack) {
|
||||
return otherItemStack.getType()==this.itemStack.getType() && otherItemStack.getDurability()==this.itemStack.getDurability();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -51,7 +54,7 @@ public class CustomItemName {
|
||||
} else if (!fullName.equals(other.fullName)) {
|
||||
return false;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
if (itemStack.getItemMeta() == null) {
|
||||
if (other.itemStack != null) {
|
||||
return false;
|
||||
}
|
||||
@@ -72,4 +75,6 @@ public class CustomItemName {
|
||||
public String toString() {
|
||||
return "CustomItemName [itemStack=" + itemStack + ", signName=" + signName + ", fullName=" + fullName + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ 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.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -19,7 +20,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.ContainerShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -146,6 +146,9 @@ public class MsgUtil {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.shop-information"));
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", Bukkit.getOfflinePlayer(shop.getOwner()).getName()==null ? (shop.isUnlimited() ? "AdminShop" : "Unknown") : Bukkit.getOfflinePlayer(shop.getOwner()).getName()));
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item", shop.getDataName()));
|
||||
if (items.getType()==Material.POTION) {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.effects", CustomPotionsName.getEffects(items)));
|
||||
}
|
||||
if (Util.isTool(items.getType())) {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.damage-percent-remaining", Util.getToolPercentage(items)));
|
||||
}
|
||||
|
||||
@@ -363,19 +363,21 @@ public class Util {
|
||||
* Fetches an ItemStack's name - For example, converting INK_SAC:11 to
|
||||
* Dandellion Yellow, or WOOL:14 to Red Wool
|
||||
*
|
||||
* @param i
|
||||
* @param itemStack
|
||||
* The itemstack to fetch the name of
|
||||
* @return The human readable item name.
|
||||
*/
|
||||
public static String getName(ItemStack i) {
|
||||
ItemStack is = i.clone();
|
||||
is.setAmount(1);
|
||||
CustomItemName customItemName = QuickShop.instance.getCustomItemNames().get(is);
|
||||
public static String getName(ItemStack itemStack) {
|
||||
if (itemStack.getType()==Material.POTION) {
|
||||
return CustomPotionsName.getFullName(itemStack);
|
||||
}
|
||||
|
||||
CustomItemName customItemName = QuickShop.instance.getCustomItemNames(itemStack);
|
||||
if (customItemName!=null) {
|
||||
return customItemName.getFullName();
|
||||
}
|
||||
|
||||
String vanillaName = getDataName(i.getType(), i.getDurability());
|
||||
String vanillaName = getDataName(itemStack.getType(), itemStack.getDurability());
|
||||
return prettifyText(vanillaName);
|
||||
}
|
||||
|
||||
@@ -403,9 +405,13 @@ public class Util {
|
||||
|
||||
// Let's make very long names shorter for our sign
|
||||
public static String getNameForSign(ItemStack itemStack) {
|
||||
if (itemStack.getType()==Material.POTION) {
|
||||
return CustomPotionsName.getSignName(itemStack);
|
||||
}
|
||||
|
||||
ItemStack is = itemStack.clone();
|
||||
is.setAmount(1);
|
||||
CustomItemName customItemName = QuickShop.instance.getCustomItemNames().get(is);
|
||||
CustomItemName customItemName = QuickShop.instance.getCustomItemNames(is);
|
||||
if (customItemName!=null) {
|
||||
return customItemName.getSignName();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user