mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
NMS Advanced item preview and new more event.
Former-commit-id: 7c47ee6f1ba3972b65eca2b88b1e3a48ddd39e94
This commit is contained in:
1 parent
43c8b13e0e
commit
6916b9f79f
16 files changed
+268
-99
No files matched your search
@@ -12,16 +12,13 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
@@ -280,7 +277,6 @@ public class QS implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void create(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
|
||||
@@ -33,14 +33,12 @@ public class Economy_Vault implements EconomyCore {
|
||||
@Deprecated
|
||||
public boolean deposit(String name, double amount) {
|
||||
boolean result = this.vault.depositPlayer(name, amount).transactionSuccess();
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug: Vault return Deprecated deposit result:"+result);}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean withdraw(String name, double amount) {
|
||||
boolean result = this.vault.withdrawPlayer(name, amount).transactionSuccess();
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug: Vault return Deprecated withdraw result:"+result);}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -50,16 +48,12 @@ public class Economy_Vault implements EconomyCore {
|
||||
if (this.vault.withdrawPlayer(from, amount).transactionSuccess()) {
|
||||
if (!this.vault.depositPlayer(to, amount).transactionSuccess()) {
|
||||
this.vault.depositPlayer(from, amount);
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer failed");}
|
||||
return false;
|
||||
}
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer success");}
|
||||
return true;
|
||||
}
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer failed");}
|
||||
return false;
|
||||
}
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer failed");}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -85,7 +79,6 @@ public class Economy_Vault implements EconomyCore {
|
||||
public boolean deposit(UUID name, double amount) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
||||
boolean result = this.vault.depositPlayer(p, amount).transactionSuccess();
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Vault report deposit "+result);}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -93,7 +86,6 @@ public class Economy_Vault implements EconomyCore {
|
||||
public boolean withdraw(UUID name, double amount) {
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(name);
|
||||
boolean result = this.vault.withdrawPlayer(p, amount).transactionSuccess();
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Vault report withdraw "+result);}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -105,16 +97,12 @@ public class Economy_Vault implements EconomyCore {
|
||||
if (this.vault.withdrawPlayer(pFrom, amount).transactionSuccess()) {
|
||||
if (!this.vault.depositPlayer(pTo, amount).transactionSuccess()) {
|
||||
this.vault.depositPlayer(pFrom, amount);
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer failed");}
|
||||
return false;
|
||||
}
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer success");}
|
||||
return true;
|
||||
}
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer failed");}
|
||||
return false;
|
||||
}
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Deprecated transfer failed");}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.maxgamer.quickshop.Nms;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_13_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import net.minecraft.server.v1_13_R1.NBTTagCompound;
|
||||
|
||||
public class v1_13_R1 {
|
||||
public String getNBTJson(ItemStack iStack) {
|
||||
if(iStack.getType().equals(Material.AIR)) {
|
||||
return null;
|
||||
}
|
||||
net.minecraft.server.v1_13_R1.ItemStack mcitem = CraftItemStack.asNMSCopy(iStack);
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
mcitem.save(nbt);
|
||||
return nbt.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.maxgamer.quickshop.Nms;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.minecraft.server.v1_13_R2.NBTTagCompound;
|
||||
|
||||
public class v1_13_R2 {
|
||||
public String getNBTJson(ItemStack iStack) {
|
||||
if(iStack.getType().equals(Material.AIR)) {
|
||||
return null;
|
||||
}
|
||||
net.minecraft.server.v1_13_R2.ItemStack mcitem = CraftItemStack.asNMSCopy(iStack);
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
mcitem.save(nbt);
|
||||
return nbt.toString();
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.maxgamer.quickshop.Command.QS;
|
||||
import org.maxgamer.quickshop.Database.Database;
|
||||
import org.maxgamer.quickshop.Database.Database.ConnectionException;
|
||||
@@ -71,6 +70,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class QuickShop extends JavaPlugin {
|
||||
/** The active instance of QuickShop */
|
||||
@@ -119,8 +119,6 @@ public class QuickShop extends JavaPlugin {
|
||||
/** Use SpoutPlugin to get item / block names */
|
||||
public boolean useSpout = false;
|
||||
// private Metrics metrics;
|
||||
/** Whether debug info should be shown in the console */
|
||||
public static boolean debug = false;
|
||||
|
||||
MultiverseCore mPlugin = null;
|
||||
|
||||
@@ -151,8 +149,6 @@ public class QuickShop extends JavaPlugin {
|
||||
reloadConfig(); // Reloads messages.yml too, aswell as config.yml and
|
||||
// others.
|
||||
getConfig().options().copyDefaults(true); // Load defaults.
|
||||
if (getConfig().contains("debug"))
|
||||
debug = true;
|
||||
if (loadEcon() == false)
|
||||
return;
|
||||
|
||||
@@ -526,9 +522,9 @@ public class QuickShop extends JavaPlugin {
|
||||
// Command handlers
|
||||
QS commandExecutor = new QS(this);
|
||||
getCommand("qs").setExecutor(commandExecutor);
|
||||
// if (getConfig().getInt("shop.find-distance") > 100) {
|
||||
// getLogger().severe("Shop.find-distance is too high! Pick a number under 100!");
|
||||
// }
|
||||
if (getConfig().getInt("shop.find-distance") > 100) {
|
||||
getLogger().severe("Shop.find-distance is too high! It may cause lag! Pick a number under 100!");
|
||||
}
|
||||
|
||||
if (display && displayItemCheckTicks > 0) {
|
||||
new BukkitRunnable() {
|
||||
@@ -820,19 +816,6 @@ public class QuickShop extends JavaPlugin {
|
||||
public Database getDB() {
|
||||
return this.database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints debug information if QuickShop is configured to do so.
|
||||
*
|
||||
* @param s
|
||||
* The string to print.
|
||||
*/
|
||||
public void debug(String s) {
|
||||
if (!debug)
|
||||
return;
|
||||
this.getLogger().info(ChatColor.YELLOW + "[Debug] " + s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ShopManager. This is used for fetching, adding and removing
|
||||
* shops.
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.maxgamer.quickshop.Shop;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -160,11 +161,14 @@ public class DisplayItem {
|
||||
if (!showFloatItem) {
|
||||
return;
|
||||
}
|
||||
//Call Event for QSAPI
|
||||
ShopDisplayItemSpawnEvent shopDisplayItemSpawnEvent = new ShopDisplayItemSpawnEvent(shop, iStack);
|
||||
Bukkit.getPluginManager().callEvent(shopDisplayItemSpawnEvent);
|
||||
if(shopDisplayItemSpawnEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
this.item = shop.getLocation().getWorld().dropItem(dispLoc, this.iStack);
|
||||
this.item.setVelocity(new Vector(0, 0.1, 0));
|
||||
if (QuickShop.debug) {
|
||||
plugin.getLogger().log(Level.WARNING, "Spawned item. Safeguarding.");
|
||||
}
|
||||
try {
|
||||
this.safeGuard(this.item);
|
||||
// NMS.safeGuard
|
||||
@@ -216,9 +220,6 @@ public class DisplayItem {
|
||||
if (this.shop.matches(near)) {
|
||||
e.remove();
|
||||
removed = true;
|
||||
if (QuickShop.debug) {
|
||||
plugin.getLogger().log(Level.WARNING, "Removed rogue item: " + near.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.maxgamer.quickshop.Shop;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ShopDisplayItemSpawnEvent extends Event implements Cancellable{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private Shop shop;
|
||||
private ItemStack iStack;
|
||||
/**
|
||||
* This event is called before the shop display item created
|
||||
*/
|
||||
|
||||
public ShopDisplayItemSpawnEvent(Shop shop, ItemStack iStack) {
|
||||
this.shop = shop;
|
||||
this.iStack = iStack;
|
||||
}
|
||||
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
public ItemStack getItemStack() {
|
||||
return iStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.maxgamer.quickshop.Shop;
|
||||
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ShopLoadEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
private Shop shop;
|
||||
/**Getting loading shops**/
|
||||
|
||||
public ShopLoadEvent(Shop shop) {
|
||||
this.shop = shop;
|
||||
}
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import org.maxgamer.quickshop.Database.Database;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Permissions;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class ShopManager {
|
||||
QuickShop plugin = QuickShop.instance;
|
||||
private HashMap<UUID, Info> actions = new HashMap<UUID, Info>();
|
||||
@@ -53,6 +52,8 @@ public class ShopManager {
|
||||
}
|
||||
|
||||
public void createShop(Shop shop) {
|
||||
ShopCreateEvent ssShopCreateEvent = new ShopCreateEvent(shop, Bukkit.getPlayer(shop.getOwner()));
|
||||
Bukkit.getPluginManager().callEvent(ssShopCreateEvent);
|
||||
Location loc = shop.getLocation();
|
||||
ItemStack item = shop.getItem();
|
||||
try {
|
||||
@@ -154,6 +155,12 @@ public class ShopManager {
|
||||
* The shop to add
|
||||
*/
|
||||
private void addShop(String world, Shop shop) {
|
||||
ShopLoadEvent shopLoadEvent = new ShopLoadEvent(shop);
|
||||
Bukkit.getPluginManager().callEvent(shopLoadEvent);
|
||||
if(shopLoadEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = this.getShops().get(world);
|
||||
// There's no world storage yet. We need to create that hashmap.
|
||||
if (inWorld == null) {
|
||||
@@ -186,6 +193,8 @@ public class ShopManager {
|
||||
* The shop to remove
|
||||
*/
|
||||
public void removeShop(Shop shop) {
|
||||
ShopUnloadEvent shopUnloadEvent = new ShopUnloadEvent(shop);
|
||||
Bukkit.getPluginManager().callEvent(shopUnloadEvent);
|
||||
Location loc = shop.getLocation();
|
||||
String world = loc.getWorld().getName();
|
||||
HashMap<ShopChunk, HashMap<Location, Shop>> inWorld = this.getShops().get(world);
|
||||
@@ -250,7 +259,8 @@ public class ShopManager {
|
||||
}
|
||||
int max = plugin.getShopLimit(p);
|
||||
if (owned + 1 > max) {
|
||||
p.sendMessage(ChatColor.RED + "You have already created a maximum of " + owned + "/" + max + " shops!");
|
||||
//p.sendMessage(ChatColor.RED + "You have already created a maximum of " + owned + "/" + max + " shops!");
|
||||
MsgUtil.getMessage("reached-maximum-can-create", String.valueOf(owned),String.valueOf(max));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -335,7 +345,8 @@ public class ShopManager {
|
||||
Entry<Double,Double> priceRestriction = Util.getPriceRestriction(info.getItem().getType());
|
||||
if (priceRestriction!=null) {
|
||||
if (price<priceRestriction.getKey() || price>priceRestriction.getValue()) {
|
||||
p.sendMessage(ChatColor.RED+"Restricted prices for "+info.getItem().getType()+": min "+priceRestriction.getKey()+", max "+priceRestriction.getValue());
|
||||
//p.sendMessage(ChatColor.RED+"Restricted prices for "+info.getItem().getType()+": min "+priceRestriction.getKey()+", max "+priceRestriction.getValue());
|
||||
p.sendMessage(MsgUtil.getMessage("restricted-prices",MsgUtil.getDisplayName(info.getItem()),String.valueOf(priceRestriction.getKey()),String.valueOf(priceRestriction.getValue())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,7 +389,7 @@ public class ShopManager {
|
||||
/* The shop has hereforth been successfully created */
|
||||
createShop(shop);
|
||||
Location loc = shop.getLocation();
|
||||
plugin.log(p.getName() + " created a " + MsgUtil.getDisplayName(shop.getItem(), shop.getDataName()) + " shop at (" + loc.getWorld().getName() + " - " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + ")");
|
||||
plugin.log(p.getName() + " created a " + MsgUtil.getDisplayName(shop.getItem()) + " shop at (" + loc.getWorld().getName() + " - " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + ")");
|
||||
if (!plugin.getConfig().getBoolean("shop.lock")) {
|
||||
// Warn them if they haven't been warned since
|
||||
// reboot
|
||||
@@ -448,7 +459,6 @@ public class ShopManager {
|
||||
|
||||
/* Purchase Handling */
|
||||
else if (info.getAction() == ShopAction.BUY) {
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Starting buy");}
|
||||
int amount = 0;
|
||||
try {
|
||||
amount = Integer.parseInt(message);
|
||||
@@ -470,7 +480,7 @@ public class ShopManager {
|
||||
if (shop.isSelling()) {
|
||||
int stock = shop.getRemainingStock();
|
||||
if (stock < amount) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-stock-too-low", String.valueOf(shop.getRemainingStock()), MsgUtil.getDisplayName(shop.getItem(), shop.getDataName())));
|
||||
p.sendMessage(MsgUtil.getMessage("shop-stock-too-low", String.valueOf(shop.getRemainingStock()), MsgUtil.getDisplayName(shop.getItem())));
|
||||
return;
|
||||
}
|
||||
if (amount == 0) {
|
||||
@@ -509,14 +519,15 @@ public class ShopManager {
|
||||
}
|
||||
|
||||
double total = amount * shop.getPrice();
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug: trade total: "+total);}
|
||||
if (!plugin.getEcon().withdraw(p.getUniqueId(), total)) {
|
||||
p.sendMessage(MsgUtil.getMessage("you-cant-afford-to-buy", format(amount * shop.getPrice()), format(plugin.getEcon().getBalance(p.getUniqueId()))));
|
||||
return;
|
||||
}
|
||||
if (!shop.isUnlimited() || plugin.getConfig().getBoolean("shop.pay-unlimited-shop-owners")) {
|
||||
boolean depositresult = plugin.getEcon().deposit(shop.getOwner(), total * (1 - tax));
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:deposit in shop manager result:"+depositresult);}
|
||||
if(!depositresult) {
|
||||
QuickShop.instance.getLogger().info("Can't deposit the money! Economy plugin issues?");
|
||||
}
|
||||
if (tax != 0) {
|
||||
try {
|
||||
for(OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||
@@ -532,12 +543,12 @@ 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.getDisplayName(shop.getItem(), shop.getDataName()), Util.format((tax * total)));
|
||||
String msg = MsgUtil.getMessage("player-bought-from-your-store-tax", p.getName(), "" + amount, MsgUtil.getDisplayName(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.getDisplayName(shop.getItem(), shop.getDataName()));
|
||||
msg += "\n" + MsgUtil.getMessage("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), MsgUtil.getDisplayName(shop.getItem()));
|
||||
MsgUtil.send(shop.getOwner(), msg);
|
||||
} else {
|
||||
String msg = MsgUtil.getMessage("player-bought-from-your-store", p.getName(), "" + amount, MsgUtil.getDisplayName(shop.getItem(), shop.getDataName()));
|
||||
String msg = MsgUtil.getMessage("player-bought-from-your-store", p.getName(), "" + amount, MsgUtil.getDisplayName(shop.getItem()));
|
||||
if (stock == amount)
|
||||
msg += "\n" + MsgUtil.getMessage("shop-out-of-stock", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ(), shop.getDataName());
|
||||
MsgUtil.send(shop.getOwner(), msg);
|
||||
@@ -546,18 +557,17 @@ public class ShopManager {
|
||||
// Transfers the item from A to B
|
||||
shop.sell(p, amount);
|
||||
MsgUtil.sendPurchaseSuccess(p, shop, amount);
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Trade purchase success completed.");}
|
||||
plugin.log(p.getName() + " bought " + amount + " for " + (shop.getPrice() * amount) + " from " + shop.toString());
|
||||
} else if (shop.isBuying()) {
|
||||
int space = shop.getRemainingSpace();
|
||||
if (space < amount) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-has-no-space", "" + space, MsgUtil.getDisplayName(shop.getItem(), shop.getDataName())));
|
||||
p.sendMessage(MsgUtil.getMessage("shop-has-no-space", "" + space, MsgUtil.getDisplayName(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.getDisplayName(shop.getItem(), shop.getDataName())));
|
||||
p.sendMessage(MsgUtil.getMessage("you-dont-have-that-many-items", "" + count, MsgUtil.getDisplayName(shop.getItem())));
|
||||
return;
|
||||
}
|
||||
if (amount == 0) {
|
||||
@@ -610,9 +620,11 @@ public class ShopManager {
|
||||
}
|
||||
// Give them the money after we know we succeeded
|
||||
boolean depositresult = plugin.getEcon().deposit(p.getUniqueId(), total * (1 - tax));
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:deposit2 in shopmanager result:"+depositresult);}
|
||||
if(!depositresult) {
|
||||
QuickShop.instance.getLogger().info("Can't deposit the money! Economy plugin issues?");
|
||||
}
|
||||
// Notify the owner of the purchase.
|
||||
String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, MsgUtil.getDisplayName(shop.getItem(), shop.getDataName()));
|
||||
String msg = MsgUtil.getMessage("player-sold-to-your-store", p.getName(), "" + amount, MsgUtil.getDisplayName(shop.getItem()));
|
||||
if (space == amount)
|
||||
msg += "\n" + MsgUtil.getMessage("shop-out-of-space", "" + shop.getLocation().getBlockX(), "" + shop.getLocation().getBlockY(), "" + shop.getLocation().getBlockZ());
|
||||
MsgUtil.send(shop.getOwner(), msg);
|
||||
@@ -624,7 +636,6 @@ public class ShopManager {
|
||||
}
|
||||
shop.buy(p, amount);
|
||||
MsgUtil.sendSellSuccess(p, shop, amount);
|
||||
if(QuickShop.debug) {plugin.getLogger().info("Economy debug:Trade sell success completed");}
|
||||
plugin.log(p.getName() + " sold " + amount + " for " + (shop.getPrice() * amount) + " to " + shop.toString());
|
||||
}
|
||||
shop.setSignText(); // Update the signs count
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.maxgamer.quickshop.Shop;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class ShopUnloadEvent extends Event{
|
||||
/**Getting the unloading shop, Can't cancel.**/
|
||||
public ShopUnloadEvent(Shop shop) {
|
||||
this.shop = shop;
|
||||
}
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private Shop shop;
|
||||
public Shop getShop() {
|
||||
return shop;
|
||||
}
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
public class ItemNMS {
|
||||
public String getItemJSON(ItemStack iStack) {
|
||||
ItemStack itemStack = iStack.clone();
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String version = name.substring(name.lastIndexOf('.') + 1);
|
||||
Class<?> nmsClass;
|
||||
try {
|
||||
nmsClass = Class.forName("org.maxgamer.quickshop.Nms." + version);
|
||||
} catch (ClassNotFoundException e2) {
|
||||
return null;
|
||||
}
|
||||
Object obj;
|
||||
try {
|
||||
obj = nmsClass.newInstance();
|
||||
} catch (InstantiationException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
return null;
|
||||
} catch (IllegalAccessException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Method method = nmsClass.getMethod("getNBTJson", ItemStack.class);
|
||||
String itemJSON = (String) method.invoke(obj, new Object[] { itemStack });
|
||||
return itemJSON;
|
||||
} catch (NoSuchMethodException | IllegalArgumentException | InvocationTargetException
|
||||
| IllegalAccessException e) {
|
||||
// do somethings
|
||||
QuickShop.instance.getLogger().info("A error happend:");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class MsgUtil {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.owner", shop.ownerName()));
|
||||
//p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item", MsgUtil.getItemi18n(shop.getDataName())));
|
||||
//Enabled
|
||||
Util.sendItemholochat(shop.getItem(),p,ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item", MsgUtil.getItemi18n(shop.getDataName())));
|
||||
Util.sendItemholochat(shop.getItem(),p,ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item", MsgUtil.getDisplayName(shop.getItem())));
|
||||
|
||||
// if (NMS.isPotion(items.getType())) {
|
||||
// String effects = CustomPotionsName.getEffects(items);
|
||||
@@ -352,7 +352,7 @@ public class MsgUtil {
|
||||
public static void sendPurchaseSuccess(Player p, Shop shop, int amount) {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.successful-purchase"));
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getItemi18n(shop.getDataName()), Util.format((amount * shop.getPrice()))));
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getDisplayName(shop.getItem()), Util.format((amount * shop.getPrice()))));
|
||||
Map<Enchantment, Integer> enchs = shop.getItem().getItemMeta().getEnchants();
|
||||
if (enchs != null && !enchs.isEmpty()) {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "+--------------------" + MsgUtil.getMessage("menu.enchants") + "-----------------------+");
|
||||
@@ -390,7 +390,7 @@ public class MsgUtil {
|
||||
public static void sendSellSuccess(Player p, Shop shop, int amount) {
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.successfully-sold"));
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getItemi18n(shop.getDataName()), Util.format((amount * shop.getPrice()))));
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "| " + MsgUtil.getMessage("menu.item-name-and-price", "" + amount, MsgUtil.getDisplayName(shop.getItem()), Util.format((amount * shop.getPrice()))));
|
||||
if (plugin.getConfig().getBoolean("show-tax")) {
|
||||
double tax = plugin.getConfig().getDouble("tax");
|
||||
double total = amount * shop.getPrice();
|
||||
@@ -428,13 +428,13 @@ public class MsgUtil {
|
||||
}
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "+---------------------------------------------------+");
|
||||
}
|
||||
public static String getDisplayName(ItemStack iStack, String DataName){
|
||||
public static String getDisplayName(ItemStack iStack){
|
||||
ItemStack is = iStack.clone();
|
||||
|
||||
if(is.hasItemMeta()&&is.getItemMeta().hasDisplayName()) {
|
||||
return is.getItemMeta().getDisplayName();
|
||||
}else {
|
||||
return MsgUtil.getItemi18n(DataName);
|
||||
return MsgUtil.getItemi18n(is.getType().name());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,12 +30,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.material.Sign;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
|
||||
|
||||
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@@ -265,35 +266,6 @@ public class Util {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string into an item from the database.
|
||||
*
|
||||
* @param itemString
|
||||
* The database string. Is the result of makeString(ItemStack
|
||||
* item).
|
||||
* @return A new itemstack, with the properties given in the string
|
||||
*/
|
||||
public static ItemStack makeItem(String itemString) {
|
||||
String[] itemInfo = itemString.split(":");
|
||||
ItemStack item = new ItemStack(Material.getMaterial(itemInfo[0]));
|
||||
MaterialData data = new MaterialData(Material.matchMaterial(itemInfo[1]));
|
||||
item.setData(data);
|
||||
item.setDurability(Short.parseShort(itemInfo[2]));
|
||||
item.setAmount(Integer.parseInt(itemInfo[3]));
|
||||
for (int i = 4; i < itemInfo.length; i = i + 2) {
|
||||
int level = Integer.parseInt(itemInfo[i + 1]);
|
||||
Enchantment ench = Enchantment.getByName(itemInfo[i]);
|
||||
if (ench == null)
|
||||
continue; // Invalid
|
||||
if (ench.canEnchantItem(item)) {
|
||||
if (level <= 0)
|
||||
continue;
|
||||
level = Math.min(ench.getMaxLevel(), level);
|
||||
item.addEnchantment(ench, level);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
public static String serialize(ItemStack iStack) {
|
||||
YamlConfiguration cfg = new YamlConfiguration();
|
||||
@@ -627,8 +599,26 @@ public class Util {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Use NMS
|
||||
public static void sendItemholochat(ItemStack itemStack, Player player, String normalText) {
|
||||
ItemNMS nms = new ItemNMS();
|
||||
String json = nms.getItemJSON(itemStack);
|
||||
if(json == null) {
|
||||
sendItemholochatAsNormaly(itemStack, player, normalText);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TextComponent normalmessage = new TextComponent(normalText+" "+MsgUtil.getMessage("menu.preview"));
|
||||
ComponentBuilder cBuilder = new ComponentBuilder(json);
|
||||
HoverEvent he = new HoverEvent(HoverEvent.Action.SHOW_ITEM, cBuilder.create());
|
||||
normalmessage.setHoverEvent(he);
|
||||
player.spigot().sendMessage(normalmessage);
|
||||
}catch (Exception e) {
|
||||
sendItemholochatAsNormaly(itemStack, player, normalText);
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendItemholochatAsNormaly(ItemStack itemStack, Player player, String normalText) {
|
||||
try {
|
||||
String Itemname = null;
|
||||
List<String> Itemlore = new ArrayList<>();
|
||||
@@ -659,7 +649,7 @@ public class Util {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Itemname = MsgUtil.getDisplayName(itemStack,MsgUtil.getItemi18n(itemStack.getType().name()));
|
||||
Itemname = MsgUtil.getDisplayName(itemStack);
|
||||
Itemlore = null;
|
||||
Itemenchs = null;
|
||||
}
|
||||
@@ -695,6 +685,7 @@ public class Util {
|
||||
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 SpigotFork.");
|
||||
}
|
||||
}
|
||||
private static String formatEnchLevel(Integer level) {
|
||||
|
||||
Reference in new issue
Block a user