Use Util.getItemStackName(ItemStack)

Former-commit-id: 192df400ccebff82e51c638724f63d58c0ae9197 [formerly 660ea812390eff26cc3b00964c98645d61310d95]
Former-commit-id: 281fd6311c62485dc042f9dafbc430f17c058a67
This commit is contained in:
Ghost_chu committed 2019-06-18 15:49:05 +08:00
1 parent 4f1a290b3c
commit b91ed80fcc
10 files changed
+160 -328

No files matched your search

@@ -254,8 +254,7 @@ public class QS implements CommandExecutor {
for (int i = 2; i < args.length; i++) {
sb.append(" " + args[i]);
}
String lookFor = sb.toString();
lookFor = lookFor.toLowerCase();
String lookFor = sb.toString().toLowerCase();
Player p = (Player) sender;
Location loc = p.getEyeLocation().clone();
double minDistance = plugin.getConfig().getInt("shop.find-distance");
@@ -270,11 +269,13 @@ public class QS implements CommandExecutor {
if (inChunk == null)
continue;
for (Shop shop : inChunk.values()) {
if (MsgUtil.getItemi18n(shop.getDataName()).toLowerCase().contains(lookFor)
&& shop.getLocation().distanceSquared(loc) < minDistanceSquared) {
closest = shop;
minDistanceSquared = shop.getLocation().distanceSquared(loc);
}
if (!Util.getItemStackName(shop.getItem()).toLowerCase().contains(lookFor))
continue;
if (!(shop.getLocation().distanceSquared(loc) < minDistanceSquared))
continue;
closest = shop;
minDistanceSquared = shop.getLocation().distanceSquared(loc);
}
}
}
@@ -343,8 +344,7 @@ public class QS implements CommandExecutor {
b.getRelative(p.getFacing().getOppositeFace()));
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
p.sendMessage(
MsgUtil.getMessage("how-much-to-trade-for", MsgUtil
.getItemi18n(info.getItem().getType().name())));
MsgUtil.getMessage("how-much-to-trade-for", Util.getItemStackName(item)));
} else {
plugin.getShopManager().handleChat(p, args[1]);
}
@@ -392,7 +392,7 @@ public class QS implements CommandExecutor {
shop.update();
MsgUtil.sendControlPanelInfo(sender, shop);
sender.sendMessage(MsgUtil
.getMessage("command.now-buying", MsgUtil.getItemi18n(shop.getItem().getType().name())));
.getMessage("command.now-buying", Util.getItemStackName(shop.getItem())));
return;
}
}
@@ -411,7 +411,7 @@ public class QS implements CommandExecutor {
//shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil
.getMessage("command.now-buying", MsgUtil.getItemi18n(shop.getItem().getType().name())));
.getMessage("command.now-buying", Util.getItemStackName(shop.getItem())));
return;
}
}
@@ -432,7 +432,7 @@ public class QS implements CommandExecutor {
shop.update();
MsgUtil.sendControlPanelInfo(sender, shop);
sender.sendMessage(MsgUtil
.getMessage("command.now-selling", MsgUtil.getItemi18n(shop.getItem().getType().name())));
.getMessage("command.now-selling", Util.getItemStackName(shop.getItem())));
return;
}
@@ -452,7 +452,7 @@ public class QS implements CommandExecutor {
//shop.setSignText();
shop.update();
sender.sendMessage(MsgUtil
.getMessage("command.now-selling", MsgUtil.getItemi18n(shop.getItem().getType().name())));
.getMessage("command.now-selling", Util.getItemStackName(shop.getItem())));
return;
}
}
@@ -156,7 +156,7 @@ public class PlayerListener implements Listener {
Info info = new Info(b.getLocation(), ShopAction.CREATE, e.getItem(), last);
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
p.sendMessage(
MsgUtil.getMessage("how-much-to-trade-for", MsgUtil.getItemi18n(info.getItem().getType().name())));
MsgUtil.getMessage("how-much-to-trade-for", Util.getItemStackName(shop.getItem())));
}
} else if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
&& Util.isWallSign(e.getClickedBlock().getType())) {
@@ -58,6 +58,7 @@ public class QuickShop extends JavaPlugin {
private LogWatcher logWatcher;
private ItemMatcher itemMatcher;
private DisplayBugFixListener displayBugFixListener;
private LockListener lockListener;
// /** Whether players are required to sneak to create/buy from a shop */
// public boolean sneak;
// /** Whether players are required to sneak to create a shop */
@@ -190,8 +191,10 @@ public class QuickShop extends JavaPlugin {
Timer enableTimer = new Timer(true);
/* PreInit for BootError feature */
commandExecutor = new QS(this);
//noinspection ConstantConditions
getCommand("qs").setExecutor(commandExecutor);
commandTabCompleter = new Tab(this);
//noinspection ConstantConditions
getCommand("qs").setTabCompleter(commandTabCompleter);
getLogger().info("Quickshop Reremake");
@@ -220,6 +223,9 @@ public class QuickShop extends JavaPlugin {
/* Process Metrics and Sentry error reporter. */
metrics = new Metrics(this);
/* It will generate a new UUID above updateConfig */
//noinspection ConstantConditions
serverUniqueID = UUID.fromString(getConfig().getString("server-uuid"));
sentryErrorReporter = new SentryErrorReporter(this);
@@ -236,36 +242,21 @@ public class QuickShop extends JavaPlugin {
itemMatcher = new ItemMatcher(this);
Util.initialize();
setupDBonEnableding = true;
setupDatabase(); //Load the database
setupDBonEnableding = false;
MsgUtil.loadItemi18n();
MsgUtil.loadEnchi18n();
MsgUtil.loadPotioni18n();
setupDBonEnableding = true;
setupDatabase(); //Load the database
setupDBonEnableding = false;
/* Initalize the tools */
// Create the shop manager.
this.shopManager = new ShopManager(this);
this.databaseManager = new DatabaseManager(this, database);
this.permissionChecker = new PermissionChecker(this);
//if (this.display) {
// Display item handler thread
// getLogger().info("Starting item scheduler");
// ShopVaildWatcher itemWatcher = new ShopVaildWatcher(this);
// shopVaildWatchTask = Bukkit.getScheduler().runTaskTimer(this, itemWatcher, 600, 600);
//}
if (this.getConfig().getBoolean("log-actions")) {
// Logger Handler
this.logWatcher = new LogWatcher(this, new File(this.getDataFolder(), "qs.log"));
logWatcher.task = Bukkit.getScheduler().runTaskTimerAsynchronously(this, this.logWatcher, 150, 150);
}
if (getConfig().getBoolean("shop.lock")) {
LockListener ll = new LockListener(this);
getServer().getPluginManager().registerEvents(ll, this);
}
getServer().getPluginManager().registerEvents(new UpdateWatcher(), this);
ConfigurationSection limitCfg = this.getConfig().getConfigurationSection("limits");
if (limitCfg != null) {
getLogger().info("Limit cfg found...");
@@ -280,17 +271,16 @@ public class QuickShop extends JavaPlugin {
if (getConfig().getInt("shop.find-distance") > 100) {
getLogger().severe("Shop.find-distance is too high! It may cause lag! Pick a number under 100!");
}
/* Load all shops. */
shopLoader = new ShopLoader(this);
shopLoader.loadShops();
getLogger().info("Registering Listeners...");
// Register events
if (getConfig().getBoolean("shop.lock")) {
LockListener lockListener = new LockListener(this);
Bukkit.getServer().getPluginManager().registerEvents(lockListener, this);
}
getLogger().info("Registering Listeners");
// Register events
blockListener = new BlockListener(this);
playerListener = new PlayerListener(this);
worldListener = new WorldListener(this);
@@ -445,7 +445,7 @@ public class ContainerShop implements Shop {
// This should not happen.
if (amount > 0) {
plugin.getLogger().log(Level.WARNING, "Could not take all items from a players inventory on purchase! " + p
.getName() + ", missing: " + amount + ", item: " + this.getDataName() + "!");
.getName() + ", missing: " + amount + ", item: " + Util.getItemStackName(this.getItem()) + "!");
}
} else {
ItemStack[] playerContents = p.getInventory().getContents();
@@ -628,16 +628,6 @@ public class ContainerShop implements Shop {
return this.getLocation().getBlock().equals(Util.getAttached(b));
}
/**
* Convenience method. Equivilant to
* org.maxgamer.quickshop.Util.getName(shop.getItem()).
*
* @return The name of this shops item
*/
public String getDataName() {
return Util.getName(this.getItem());
}
/**
* Deletes the shop from the list of shops and queues it for database
*/
@@ -107,7 +107,8 @@ public class RealDisplayItem implements DisplayItem {
continue;
Item eItem = (Item) entity;
if (!DisplayItem.checkIsGuardItemStack(eItem.getItemStack())) {
Util.debugLog(Util.getName(eItem.getItemStack()) + " not a shop displayItem: Failed check guardedItemStack");
Util.debugLog(Util
.getItemStackName(eItem.getItemStack()) + " not a shop displayItem: Failed check guardedItemStack");
continue;
}
if (!eItem.getUniqueId().equals(this.item.getUniqueId())) {
@@ -117,7 +118,8 @@ public class RealDisplayItem implements DisplayItem {
entity.remove();
removed = true;
} else {
Util.debugLog(Util.getName(eItem.getItemStack()) + " not a shop displayItem: Failed check shop display.");
Util.debugLog(Util
.getItemStackName(eItem.getItemStack()) + " not a shop displayItem: Failed check shop display.");
}
}
}
@@ -178,13 +178,6 @@ public abstract interface Shop {
*/
public abstract boolean isAttached(Block paramBlock);
/**
* Get item will show on the sign
*
* @return The text will show on the sign
*/
public abstract String getDataName();
/**
* Delete shop from ram, and database.
*/
@@ -404,14 +404,13 @@ public class ShopManager {
space = 10000;
if (space < amount) {
p.sendMessage(MsgUtil
.getMessage("shop-has-no-space", "" + space, MsgUtil.getItemi18n(shop.getItem().getType().name())));
.getMessage("shop-has-no-space", "" + space, Util.getItemStackName(shop.getItem())));
return;
}
int count = Util.countItems(p.getInventory(), shop.getItem());
// Not enough items
if (amount > count) {
p.sendMessage(MsgUtil.getMessage("you-dont-have-that-many-items", "" + count, MsgUtil
.getItemi18n(shop.getItem().getType().name())));
p.sendMessage(MsgUtil.getMessage("you-dont-have-that-many-items", "" + count, Util.getItemStackName(shop.getItem())));
return;
}
if (amount == 0) {
@@ -462,8 +461,8 @@ public class ShopManager {
// Give them the money after we know we succeeded
plugin.getEcon().deposit(p.getUniqueId(), total * (1 - tax));
// Notify the owner of the purchase.
String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, MsgUtil
.getItemi18n(shop.getItem().getType().name()));
String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, Util
.getItemStackName(shop.getItem()));
if (space == amount)
msg += "\n" + MsgUtil.getMessage("shop-out-of-space", "" + shop.getLocation().getBlockX(), "" + shop.getLocation()
.getBlockY(), "" + shop.getLocation().getBlockZ());
@@ -493,8 +492,8 @@ public class ShopManager {
if (stock == -1)
stock = 10000;
if (stock < amount) {
p.sendMessage(MsgUtil.getMessage("shop-stock-too-low", "" + shop.getRemainingStock(), MsgUtil
.getItemi18n(shop.getItem().getType().name())));
p.sendMessage(MsgUtil
.getMessage("shop-stock-too-low", "" + shop.getRemainingStock(), Util.getItemStackName(shop.getItem())));
return;
}
if (amount == 0) {
@@ -548,20 +547,20 @@ public class ShopManager {
}
// Notify the shop owner
if (plugin.getConfig().getBoolean("show-tax")) {
String msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p.getName(), "" + amount, MsgUtil
.getItemi18n(shop.getItem().getType().name()), Util.format((tax * total)));
String msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p.getName(), "" + amount, Util
.getItemStackName(shop.getItem()), Util.format((tax * total)));
if (stock == amount)
msg += "\n" + MsgUtil.getMessage("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop
.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), MsgUtil
.getItemi18n(shop.getItem().getType().name()));
.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), Util
.getItemStackName(shop.getItem()));
MsgUtil.send(shop.getOwner(), msg, shop.isUnlimited());
} else {
String msg = MsgUtil.getMessage("player-bought-from-your-store", p.getName(), "" + amount, MsgUtil
.getItemi18n(shop.getItem().getType().name()));
String msg = MsgUtil.getMessage("player-bought-from-your-store", p.getName(), "" + amount, Util
.getItemStackName(shop.getItem()));
if (stock == amount)
msg += "\n" + MsgUtil.getMessage("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop
.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), MsgUtil
.getItemi18n(shop.getItem().getType().name()));
.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), Util
.getItemStackName(shop.getItem()));
MsgUtil.send(shop.getOwner(), msg, shop.isUnlimited());
}
// Transfers the item from A to B
@@ -6,6 +6,7 @@ public class IncompatibleChecker {
private final ArrayList<String> incompatibleVersionList = new ArrayList<>();
public IncompatibleChecker() {
incompatibleVersionList.clear();
mc1_5();
mc1_6();
mc1_7();
@@ -26,7 +26,6 @@ import org.bukkit.entity.Tameable;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.*;
import org.maxgamer.quickshop.QuickShop;
@@ -653,7 +652,7 @@ public class MsgUtil {
//Enabled
sendItemholochat(shop, shop.getItem(), p, ChatColor.DARK_PURPLE + MsgUtil
.getMessage("tableformat.left_begin") + " " + MsgUtil
.getMessage("menu.item", MsgUtil.getDisplayName(shop.getItem())));
.getMessage("menu.item", Util.getItemStackName(shop.getItem())));
if (Util.isTool(items.getType())) {
chatSheetPrinter.printLine(MsgUtil.getMessage("menu.damage-percent-remaining", Util.getToolPercentage(items)));
}
@@ -671,7 +670,7 @@ public class MsgUtil {
}
}
chatSheetPrinter.printLine(MsgUtil
.getMessage("menu.price-per", MsgUtil.getDisplayName(shop.getItem()), Util.format(shop.getPrice())));
.getMessage("menu.price-per", Util.getItemStackName(shop.getItem()), Util.format(shop.getPrice())));
if (shop.isBuying()) {
chatSheetPrinter.printLine(MsgUtil.getMessage("menu.this-shop-is-buying"));
} else {
@@ -714,7 +713,7 @@ public class MsgUtil {
chatSheetPrinter.printHeader();
chatSheetPrinter.printLine(MsgUtil.getMessage("menu.successful-purchase"));
chatSheetPrinter.printLine(MsgUtil
.getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getDisplayName(shop.getItem()), Util
.getMessage("menu.item-name-and-price", "" + amount, Util.getItemStackName(shop.getItem()), Util
.format((amount * shop.getPrice()))));
Map<Enchantment, Integer> enchs = new HashMap<>();
if (shop.getItem().hasItemMeta() && shop.getItem().getItemMeta().hasEnchants())
@@ -751,7 +750,7 @@ public class MsgUtil {
chatSheetPrinter.printHeader();
chatSheetPrinter.printLine(MsgUtil.getMessage("menu.successfully-sold"));
chatSheetPrinter.printLine(MsgUtil
.getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getDisplayName(shop.getItem()), Util
.getMessage("menu.item-name-and-price", "" + amount, Util.getItemStackName(shop.getItem()), Util
.format((amount * shop.getPrice()))));
if (plugin.getConfig().getBoolean("show-tax")) {
double tax = plugin.getConfig().getDouble("tax");
@@ -787,21 +786,6 @@ public class MsgUtil {
chatSheetPrinter.printFooter();
}
/**
* Get item's displayname.
* @param iStack stack
* @return itemDisplayName
*/
public static String getDisplayName(@NotNull ItemStack iStack) {
ItemStack is = iStack.clone();
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
return is.getItemMeta().getDisplayName();
} else {
return MsgUtil.getItemi18n(is.getType().name());
}
}
/**
* getMessage in messages.yml
*
@@ -904,91 +888,91 @@ public class MsgUtil {
normalmessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, cBuilder.create()));
player.spigot().sendMessage(normalmessage);
} catch (Throwable t) {
sendItemholochatAsNormaly(itemStack, player, normalText);
t.printStackTrace();
}
}
/**
* Send the ItemPreview chat msg by Bukkit API.
* More worst than NMS mode.
* *STILL WIP*
*
* @param itemStack Target ItemStack
* @param player Target player
* @param normalText The text you will see
*/
// Without NMS
private static void sendItemholochatAsNormaly(@NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) {
try {
String Itemname = null;
List<String> Itemlore = new ArrayList<>();
String finalItemdata = null;
Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
Map<String, Integer> Itemenchs = new HashMap<String, Integer>();
if (itemStack.hasItemMeta()) {
ItemMeta iMeta = itemStack.getItemMeta();
if (iMeta.hasDisplayName()) {
Itemname = iMeta.getDisplayName();
} else {
Itemname = MsgUtil.getItemi18n(itemStack.getType().name());
}
if (iMeta.hasLore()) {
Itemlore = iMeta.getLore();
} else {
Itemlore = new ArrayList<String>();
}
if (iMeta.hasEnchants()) {
enchs = iMeta.getEnchants();
for (Entry<Enchantment, Integer> entries : enchs.entrySet()) {
String i18n = MsgUtil.getEnchi18n(entries.getKey());
if (i18n != null) {
Itemenchs.put(i18n, entries.getValue());
} else {
Itemenchs = null;
}
}
}
} else {
Itemname = MsgUtil.getDisplayName(itemStack);
Itemlore = null;
Itemenchs = null;
}
if (Itemname != MsgUtil.getItemi18n(itemStack.getType().name())) {
finalItemdata = Itemname + " " + ChatColor.GRAY + "(" + MsgUtil.getItemi18n(itemStack.getType()
.name()) + ChatColor.GRAY + ")";
} else {
finalItemdata = Itemname;
}
finalItemdata += "\n";
List<String> a = new ArrayList<>();
List<Integer> b = new ArrayList<>();
a.addAll(Itemenchs.keySet());
b.addAll(Itemenchs.values());
for (int i = 0; i < a.size(); i++) {
finalItemdata += ChatColor.GRAY + a.get(i) + " " + RomanNumber.toRoman(b.get(i)) + "\n";
}
String potionResult = Util.getPotiondata(itemStack);
if (potionResult != null) {
finalItemdata += potionResult;
}
if (Itemlore != null) {
for (String string : Itemlore) {
finalItemdata += ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC + string + "\n";
}
}
TextComponent normalmessage = new TextComponent(normalText + " " + MsgUtil.getMessage("menu.preview"));
ComponentBuilder cBuilder = new ComponentBuilder(finalItemdata);
HoverEvent he = new HoverEvent(HoverEvent.Action.SHOW_TEXT, cBuilder.create());
normalmessage.setHoverEvent(he);
player.spigot().sendMessage(normalmessage);
} catch (Exception e) {
player.sendMessage(normalText);
QuickShop.instance.getLogger()
.severe("QuickShop cannot send Advanced chat message, Are you using CraftBukkit? Please use Spigot or a Spigot fork.");
}
}
// /**
// * Send the ItemPreview chat msg by Bukkit API.
// * More worst than NMS mode.
// * *STILL WIP*
// *
// * @param itemStack Target ItemStack
// * @param player Target player
// * @param normalText The text you will see
// */
// // Without NMS
// private static void sendItemholochatAsNormaly(@NotNull ItemStack itemStack, @NotNull Player player, @NotNull String normalText) {
// try {
// String Itemname = null;
// List<String> Itemlore = new ArrayList<>();
// String finalItemdata = null;
// Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
// Map<String, Integer> Itemenchs = new HashMap<String, Integer>();
// if (itemStack.hasItemMeta()) {
// ItemMeta iMeta = itemStack.getItemMeta();
// if (iMeta.hasDisplayName()) {
// Itemname = iMeta.getDisplayName();
// } else {
// Itemname = Util.getItemStackName(itemStack);
// }
// if (iMeta.hasLore()) {
// Itemlore = iMeta.getLore();
// } else {
// Itemlore = new ArrayList<String>();
// }
// if (iMeta.hasEnchants()) {
// enchs = iMeta.getEnchants();
// for (Entry<Enchantment, Integer> entries : enchs.entrySet()) {
// String i18n = MsgUtil.getEnchi18n(entries.getKey());
// if (i18n != null) {
// Itemenchs.put(i18n, entries.getValue());
// } else {
// Itemenchs = null;
// }
// }
// }
// } else {
// Itemname =Util.getItemStackName(itemStack);
// Itemlore = null;
// Itemenchs = null;
// }
// if (Itemname != MsgUtil.getItemi18n(itemStack.getType().name())) {
// finalItemdata = Itemname + " " + ChatColor.GRAY + "(" + MsgUtil.getItemi18n(itemStack.getType()
// .name()) + ChatColor.GRAY + ")";
// } else {
// finalItemdata = Itemname;
// }
//
// finalItemdata += "\n";
// List<String> a = new ArrayList<>();
// List<Integer> b = new ArrayList<>();
// a.addAll(Itemenchs.keySet());
// b.addAll(Itemenchs.values());
// for (int i = 0; i < a.size(); i++) {
// finalItemdata += ChatColor.GRAY + a.get(i) + " " + RomanNumber.toRoman(b.get(i)) + "\n";
// }
//
// String potionResult = Util.getPotiondata(itemStack);
// if (potionResult != null) {
// finalItemdata += potionResult;
// }
//
// if (Itemlore != null) {
// for (String string : Itemlore) {
// finalItemdata += ChatColor.DARK_PURPLE + "" + ChatColor.ITALIC + string + "\n";
// }
// }
// TextComponent normalmessage = new TextComponent(normalText + " " + MsgUtil.getMessage("menu.preview"));
// ComponentBuilder cBuilder = new ComponentBuilder(finalItemdata);
// HoverEvent he = new HoverEvent(HoverEvent.Action.SHOW_TEXT, cBuilder.create());
// normalmessage.setHoverEvent(he);
// player.spigot().sendMessage(normalmessage);
// } catch (Exception e) {
// player.sendMessage(normalText);
// QuickShop.instance.getLogger()
// .severe("QuickShop cannot send Advanced chat message, Are you using CraftBukkit? Please use Spigot or a Spigot fork.");
// }
// }
}
@@ -10,7 +10,6 @@ import java.util.Map.Entry;
import com.google.common.io.Files;
import lombok.*;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.*;
import org.bukkit.block.data.Directional;
@@ -37,7 +36,7 @@ import org.maxgamer.quickshop.Shop.Shop;
public class Util {
private static EnumSet<Material> blacklist = EnumSet.noneOf(Material.class);
private static EnumSet<Material> shoppables = EnumSet.noneOf(Material.class);
private static EnumMap<Material, Entry<Double, Double>> restrictedPrices = new EnumMap<Material, Entry<Double, Double>>(Material.class);
private static EnumMap<Material, Entry<Double, Double>> restrictedPrices = new EnumMap<>(Material.class);
private static List<String> worldBlacklist = new ArrayList<>();
@Getter private static List<String> debugLogs = new ArrayList<>();
private static QuickShop plugin;
@@ -88,7 +87,7 @@ public class Util {
.warning("Material " + sp[0] + " in config.yml can't match with a valid Materials, check your config.yml!");
continue;
}
restrictedPrices.put(mat, new SimpleEntry<Double, Double>(Double.valueOf(sp[1]), Double.valueOf(sp[2])));
restrictedPrices.put(mat, new SimpleEntry<>(Double.valueOf(sp[1]), Double.valueOf(sp[2])));
} catch (Exception e) {
plugin.getLogger().warning("Invalid price restricted material: " + s);
}
@@ -157,6 +156,8 @@ public class Util {
Set<String> keys = config.getKeys(true);
for (String key : keys) {
String filtered = config.getString(key);
if (filtered == null)
continue;
if (filtered.startsWith("MemorySection")) {
continue;
}
@@ -194,6 +195,7 @@ public class Util {
}
if (!isShoppables(b.getType()))
return false;
//noinspection RedundantIfStatement
if (isBlacklistWorld(b.getWorld()))
return false;
return true;
@@ -291,27 +293,6 @@ public class Util {
.getBlockZ()) && (b1.getWorld().getName().equals(b2.getWorld().getName()));
}
/**
* Check two location is or not equals for the BlockPosition on 2D
*
* @param loc1 location 1
* @param loc2 location 2
* @return Equals or not.
*/
public static boolean location3DEqual(@NotNull Location loc1, @NotNull Location loc2) {
if (loc1.equals(loc2))
return true;
if (!loc1.getWorld().getName().equals(loc2.getWorld().getName()))
return false;
if (loc1.getBlockX() != loc2.getBlockX())
return false;
if (loc1.getBlockY() != loc2.getBlockY())
return false;
if (loc1.getBlockZ() != loc2.getBlockZ())
return false;
return true;
}
/**
* Checks whether someone else's shop is within reach of a hopper being placed by a player.
*
@@ -368,21 +349,6 @@ public class Util {
return cfg.getItemStack("item");
}
/**
* Fetches an ItemStack's name - For example, converting INK_SAC:11 to
* Dandellion Yellow, or WOOL:14 to Red Wool
*
* @param itemStack The itemstack to fetch the name of
* @return The human readable item name.
*/
public static String getName(@NotNull ItemStack itemStack) {
// if (NMS.isPotion(itemStack.getType())) {
// return CustomPotionsName.getFullName(itemStack);
// }
String vanillaName = itemStack.getType().name();
return prettifyText(vanillaName);
}
/**
* Converts a name like IRON_INGOT into Iron Ingot to improve readability
*
@@ -394,20 +360,13 @@ public class Util {
if (nameParts.length == 1) {
return firstUppercase(ugly);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nameParts.length; i++) {
sb.append(firstUppercase(nameParts[i]));
if (i + 1 != nameParts.length)
sb.append(" ");
}
// for (String part : nameParts) {
// sb.append(firstUppercase(part) + " ");
// }
return sb.toString();
}
@@ -426,47 +385,6 @@ public class Util {
return itemMeta.getLocalizedName();
}
/**
* Get item's sign name for display on the sign.
*
* @param itemStack target itemStack
* @return String ItemOnSignName
*/
// Let's make very long names shorter for our sign
public static String getNameForSign(@NotNull ItemStack itemStack) {
// if (NMS.isPotion(itemStack.getType())) {
// return CustomPotionsName.getSignName(itemStack);
// }
ItemStack is = itemStack.clone();
is.setAmount(1);
if (is.hasItemMeta()) {
if (is.getItemMeta().hasDisplayName()) {
return is.getItemMeta().getDisplayName();
}
}
String name = MsgUtil.getItemi18n(itemStack.getType().name()).trim();
String[] nameParts = name.split("_");
if (nameParts.length == 1) {
return firstUppercase(nameParts[0]);
}
for (int i = 0; i < nameParts.length - 1; i++) {
int length = StringUtils.join(nameParts).length();
if (length > 16) {
nameParts[i] = nameParts[i].substring(0, 1) + ".";
} else {
nameParts[i] = firstUppercase(nameParts[i]);
}
}
nameParts[nameParts.length - 1] = firstUppercase(nameParts[nameParts.length - 1]);
return StringUtils.join(nameParts);
}
/**
* First uppercase for every words the first char for a text.
*
@@ -490,24 +408,6 @@ public class Util {
return !(mat.getMaxDurability() == 0);
}
// /**
// * Sort the HashMap
// * @param map map
// * @return Sorted HashMap
// */
// public static Map sortHashMap(Map map) {
// List<Map.Entry<String, String>> list = new ArrayList<Map.Entry<String, String>>(map.entrySet());
// Collections.sort(list, new Comparator<Map.Entry<String, String>>() {
//
// public int compare(Entry<String, String> o1,
// Entry<String, String> o2) {
// return o1.getValue().compareTo(o2.getValue());
// }
//
// });
// return map;
// }
/**
* Formats the given number according to how vault would like it. E.g. $50 or 5
* dollars.
@@ -530,7 +430,6 @@ public class Util {
Util.debugLog("format", e.getMessage());
Util.debugLog("format", "Use alternate-currency-symbol to formatting, Cause NumberFormatException");
return plugin.getConfig().getString("shop.alternate-currency-symbol") + n;
// return "$" + n;
}
}
@@ -618,16 +517,6 @@ public class Util {
* @return is or not a wall_sign
*/
public static boolean isWallSign(@NotNull Material material) {
// try {
// if (Tag.WALL_SIGNS.isTagged(material))
// return true;
// } catch (Throwable e) {
// if (material.name().endsWith("WALL_SIGN") || material.name().equals("WALL_SIGN"))
// return true;
// }
//if (material.name().endsWith("WALL_SIGN") || material.name().equals("WALL_SIGN"))
// return true;
return Tag.WALL_SIGNS.isTagged(material);
}
@@ -696,33 +585,6 @@ public class Util {
}
}
//Use NMS
// /**
// * Format ench level.
// *
// * @param level level
// * @return formated level
// */
// private static String formatEnchLevel(@NotNull Integer level) {
// switch (level) {
// case 1:
// return "I";
// case 2:
// return "II";
// case 3:
// return "III";
// case 4:
// return "IV";
// case 5:
// return "V";
// default:
// return String.valueOf(level);
//
// }
// }
/**
* @param iStack itemstack
* @return potion data, readable
@@ -781,13 +643,13 @@ public class Util {
*/
public static boolean isDevEdition() {
String version = QuickShop.instance.getDescription().getVersion().toLowerCase();
if (version.contains("dev") || version.contains("develop") || version.contains("alpha") || version
.contains("beta") || version
.contains("test") || version.contains("snapshot") || version.contains("preview")) {
return true;
} else {
return false;
}
return (version.contains("dev") ||
version.contains("develop") ||
version.contains("alpha") ||
version.contains("beta") ||
version.contains("test") ||
version.contains("snapshot") ||
version.contains("preview"));
}
/**
@@ -798,17 +660,28 @@ public class Util {
if (inv == null)
return;
try {
for (int i = 0; i < inv.getSize(); i++)
if (DisplayItem.checkIsGuardItemStack(inv.getItem(i))) {
for (int i = 0; i < inv.getSize(); i++) {
ItemStack itemStack = inv.getItem(i);
if (itemStack == null)
continue;
if (DisplayItem.checkIsGuardItemStack(itemStack)) {
// Found Item and remove it.
inv.setItem(i, new ItemStack(Material.AIR, 0));
Util.debugLog("Found a displayitem in an inventory, it has been removed.");
}
}
} catch (Throwable t) {
//Ignore
}
}
public static String getItemStackName(@NotNull ItemStack itemStack) {
if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName())
return itemStack.getItemMeta().getDisplayName();
return MsgUtil.getItemi18n(itemStack.getType().name());
}
private static Object serverInstance;
private static Field tpsField;