mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Added Custom Items Name (supports 1.9.4 potions!)
This commit is contained in:
1 parent
21dbdc1fe8
commit
ec1fe83f18
4 files changed
+154
-2
No files matched your search
@@ -10,12 +10,14 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -23,6 +25,8 @@ 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.PotionType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.maxgamer.quickshop.Command.QS;
|
||||
import org.maxgamer.quickshop.Database.Database;
|
||||
@@ -45,12 +49,14 @@ import org.maxgamer.quickshop.Shop.ContainerShop;
|
||||
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.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
import org.maxgamer.quickshop.Watcher.ItemWatcher;
|
||||
import org.maxgamer.quickshop.Watcher.LogWatcher;
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class QuickShop extends JavaPlugin {
|
||||
/** The active instance of QuickShop */
|
||||
public static QuickShop instance;
|
||||
@@ -96,6 +102,8 @@ public class QuickShop extends JavaPlugin {
|
||||
// private Metrics metrics;
|
||||
/** Whether debug info should be shown in the console */
|
||||
public static boolean debug = false;
|
||||
|
||||
private Map<ItemStack,CustomItemName> customItemNames = new HashMap<ItemStack,CustomItemName>();
|
||||
|
||||
/** The plugin metrics from Hidendra */
|
||||
// public Metrics getMetrics(){ return metrics; }
|
||||
@@ -140,6 +148,51 @@ public class QuickShop extends JavaPlugin {
|
||||
LockListener ll = new LockListener(this);
|
||||
getServer().getPluginManager().registerEvents(ll, this);
|
||||
}
|
||||
|
||||
if (this.getConfig().isSet("custom-names")) {
|
||||
for (String s : this.getConfig().getStringList("custom-names")) {
|
||||
try {
|
||||
String[] mainVal = s.split("[;]");
|
||||
if (mainVal.length!=3) {
|
||||
throw new Exception("Invalid format (main args length must be 3)");
|
||||
}
|
||||
|
||||
String[] matVal = mainVal[0].split("[:]");
|
||||
Material material = Material.matchMaterial(matVal[0]);
|
||||
if (material==null) {
|
||||
throw new Exception("Invalid material: "+matVal[0]);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
is = new ItemStack(material, 1, (short) 0);
|
||||
}
|
||||
|
||||
if (mainVal[1].length()>16) {
|
||||
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]));
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning("Invalid custom item name definition {"+s+"} Error: "+e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits");
|
||||
if (limitCfg != null) {
|
||||
getLogger().info("Limit cfg found...");
|
||||
@@ -215,7 +268,6 @@ public class QuickShop extends JavaPlugin {
|
||||
ownerUUID = UUID.fromString(owner);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// This could be old data to be converted... check if it's a player
|
||||
@SuppressWarnings("deprecation")
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
|
||||
if (player.hasPlayedBefore()) {
|
||||
ownerUUID = player.getUniqueId();
|
||||
@@ -414,4 +466,8 @@ public class QuickShop extends JavaPlugin {
|
||||
public ShopManager getShopManager() {
|
||||
return this.shopManager;
|
||||
}
|
||||
|
||||
public Map<ItemStack, CustomItemName> getCustomItemNames() {
|
||||
return customItemNames;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class CustomItemName {
|
||||
private ItemStack itemStack;
|
||||
private String signName, fullName;
|
||||
|
||||
public CustomItemName(ItemStack itemStack, String signName, String fullName) {
|
||||
this.itemStack = itemStack;
|
||||
this.signName = signName;
|
||||
this.fullName = fullName;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack() {
|
||||
return itemStack;
|
||||
}
|
||||
public String getSignName() {
|
||||
return signName;
|
||||
}
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((fullName == null) ? 0 : fullName.hashCode());
|
||||
result = prime * result + ((itemStack == null) ? 0 : itemStack.getType().hashCode());
|
||||
result = prime * result + ((signName == null) ? 0 : signName.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof CustomItemName)) {
|
||||
return false;
|
||||
}
|
||||
CustomItemName other = (CustomItemName) obj;
|
||||
if (fullName == null) {
|
||||
if (other.fullName != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!fullName.equals(other.fullName)) {
|
||||
return false;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
if (other.itemStack != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!itemStack.isSimilar(other.itemStack)) {
|
||||
return false;
|
||||
}
|
||||
if (signName == null) {
|
||||
if (other.signName != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!signName.equals(other.signName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CustomItemName [itemStack=" + itemStack + ", signName=" + signName + ", fullName=" + fullName + "]";
|
||||
}
|
||||
}
|
||||
@@ -368,6 +368,13 @@ public class Util {
|
||||
* @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);
|
||||
if (customItemName!=null) {
|
||||
return customItemName.getFullName();
|
||||
}
|
||||
|
||||
String vanillaName = getDataName(i.getType(), i.getDurability());
|
||||
return prettifyText(vanillaName);
|
||||
}
|
||||
@@ -396,6 +403,13 @@ public class Util {
|
||||
|
||||
// Let's make very long names shorter for our sign
|
||||
public static String getNameForSign(ItemStack itemStack) {
|
||||
ItemStack is = itemStack.clone();
|
||||
is.setAmount(1);
|
||||
CustomItemName customItemName = QuickShop.instance.getCustomItemNames().get(is);
|
||||
if (customItemName!=null) {
|
||||
return customItemName.getSignName();
|
||||
}
|
||||
|
||||
String name = getDataName(itemStack.getType(), itemStack.getDurability());
|
||||
|
||||
String[] nameParts = name.split("_");
|
||||
|
||||
Reference in new issue
Block a user