mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-26 10:29:48 -05:00
Added /qs create command
Also, minor fixes
This commit is contained in:
1 parent
b7faffe216
commit
c5ddc66b01
5 files changed
+307
-236
No files matched your search
@@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -17,16 +18,20 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Database.Database;
|
||||
import org.maxgamer.quickshop.Database.MySQLCore;
|
||||
import org.maxgamer.quickshop.Database.SQLiteCore;
|
||||
import org.maxgamer.quickshop.Shop.ContainerShop;
|
||||
import org.maxgamer.quickshop.Shop.Info;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopType;
|
||||
import org.maxgamer.quickshop.Shop.ShopAction;
|
||||
import org.maxgamer.quickshop.Shop.ShopChunk;
|
||||
import org.maxgamer.quickshop.Shop.ShopType;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class QS implements CommandExecutor {
|
||||
QuickShop plugin;
|
||||
@@ -269,6 +274,52 @@ public class QS implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private void create(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player) sender;
|
||||
ItemStack item = p.getItemInHand();
|
||||
if (item.getType()!=Material.AIR && (plugin.sneakCreate == false || p.isSneaking())) {
|
||||
if (sender.hasPermission("quickshop.create.sell")) {
|
||||
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
|
||||
|
||||
while (bIt.hasNext()) {
|
||||
Block b = bIt.next();
|
||||
|
||||
if (Util.canBeShop(b)) {
|
||||
if (!plugin.getShopManager().canBuildShop(p, b, Util.getYawFace(p.getLocation().getYaw()))) {
|
||||
// As of the new checking system, most plugins will tell the
|
||||
// player why they can't create a shop there.
|
||||
// So telling them a message would cause spam etc.
|
||||
return;
|
||||
}
|
||||
|
||||
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
||||
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
|
||||
return;
|
||||
}
|
||||
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getTypeId())) {
|
||||
p.sendMessage(MsgUtil.getMessage("blacklisted-item"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Send creation menu.
|
||||
Info info = new Info(b.getLocation(), ShopAction.CREATE, p.getItemInHand(), b.getRelative(Util.getYawFace(p.getLocation().getYaw())));
|
||||
plugin.getShopManager().getActions().put(p.getUniqueId(), info);
|
||||
p.sendMessage(MsgUtil.getMessage("how-much-to-trade-for", Util.getName(info.getItem())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(MsgUtil.getMessage("no-permission"));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(MsgUtil.getMessage("not-looking-at-shop"));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("This command can't be run by console");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private void setBuy(CommandSender sender) {
|
||||
if (sender instanceof Player && sender.hasPermission("quickshop.create.buy")) {
|
||||
BlockIterator bIt = new BlockIterator((LivingEntity) (Player) sender, 10);
|
||||
@@ -396,7 +447,7 @@ public class QS implements CommandExecutor {
|
||||
int i = 0;
|
||||
while (shIt.hasNext()) {
|
||||
Shop shop = shIt.next();
|
||||
|
||||
|
||||
try {
|
||||
if (shop.getLocation().getWorld() != null && shop.isSelling() && shop.getRemainingStock() == 0 && shop instanceof ContainerShop) {
|
||||
ContainerShop cs = (ContainerShop) shop;
|
||||
@@ -441,6 +492,9 @@ public class QS implements CommandExecutor {
|
||||
} else if (subArg.equals("find")) {
|
||||
find(sender, args);
|
||||
return true;
|
||||
} else if (subArg.startsWith("create")) {
|
||||
create(sender);
|
||||
return true;
|
||||
} else if (subArg.startsWith("buy")) {
|
||||
setBuy(sender);
|
||||
return true;
|
||||
@@ -558,8 +612,10 @@ public class QS implements CommandExecutor {
|
||||
s.sendMessage(ChatColor.GREEN + "/qs setowner <player>" + ChatColor.YELLOW + " - " + MsgUtil.getMessage("command.description.setowner"));
|
||||
if (s.hasPermission("quickshop.create.buy"))
|
||||
s.sendMessage(ChatColor.GREEN + "/qs buy" + ChatColor.YELLOW + " - " + MsgUtil.getMessage("command.description.buy"));
|
||||
if (s.hasPermission("quickshop.create.sell"))
|
||||
if (s.hasPermission("quickshop.create.sell")) {
|
||||
s.sendMessage(ChatColor.GREEN + "/qs sell" + ChatColor.YELLOW + " - " + MsgUtil.getMessage("command.description.sell"));
|
||||
s.sendMessage(ChatColor.GREEN + "/qs create" + ChatColor.YELLOW + " - " + MsgUtil.getMessage("command.description.create"));
|
||||
}
|
||||
if (s.hasPermission("quickshop.create.changeprice"))
|
||||
s.sendMessage(ChatColor.GREEN + "/qs price" + ChatColor.YELLOW + " - " + MsgUtil.getMessage("command.description.price"));
|
||||
if (s.hasPermission("quickshop.clean"))
|
||||
|
||||
@@ -1,217 +1,218 @@
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Info;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopAction;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private QuickShop plugin;
|
||||
|
||||
public PlayerListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Could be useful one day private LinkedList<String> getParents(Class<?>
|
||||
* clazz){ LinkedList<String> classes = new LinkedList<String>();
|
||||
*
|
||||
* while(clazz != null){ classes.add("Extends " + ChatColor.GREEN +
|
||||
* clazz.getCanonicalName()); for(Class<?> iface : clazz.getInterfaces()){
|
||||
* classes.add("Implements " + ChatColor.RED + iface.getCanonicalName());
|
||||
* classes.addAll(getParents(iface)); }
|
||||
*
|
||||
* clazz = clazz.getSuperclass(); } return classes; }
|
||||
*/
|
||||
/**
|
||||
* Handles players left clicking a chest. Left click a NORMAL chest with
|
||||
* item : Send creation menu Left click a SHOP chest : Send purchase menu
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
Block b = e.getClickedBlock();
|
||||
if (!Util.canBeShop(b) && b.getType() != Material.WALL_SIGN)
|
||||
return;
|
||||
Player p = e.getPlayer();
|
||||
if (plugin.sneak && !p.isSneaking()) {
|
||||
// Sneak only
|
||||
return;
|
||||
}
|
||||
Location loc = b.getLocation();
|
||||
ItemStack item = e.getItem();
|
||||
// Get the shop
|
||||
Shop shop = plugin.getShopManager().getShop(loc);
|
||||
// If that wasn't a shop, search nearby shops
|
||||
if (shop == null) {
|
||||
Block attached = null;
|
||||
|
||||
if (b.getType() == Material.WALL_SIGN) {
|
||||
attached = Util.getAttached(b);
|
||||
} else if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
|
||||
attached = Util.getSecondHalf(b);
|
||||
}
|
||||
|
||||
if (attached != null) {
|
||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
}
|
||||
}
|
||||
// Purchase handling
|
||||
if (shop != null && p.hasPermission("quickshop.use") && (plugin.sneakTrade == false || p.isSneaking())) {
|
||||
shop.onClick();
|
||||
// Text menu
|
||||
MsgUtil.sendShopInfo(p, shop);
|
||||
if (shop.isSelling()) {
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-buy"));
|
||||
} else {
|
||||
int items = Util.countItems(p.getInventory(), shop.getItem());
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-sell", "" + items));
|
||||
}
|
||||
// Add the new action
|
||||
HashMap<UUID, Info> actions = plugin.getShopManager().getActions();
|
||||
Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
|
||||
actions.put(p.getUniqueId(), info);
|
||||
return;
|
||||
}
|
||||
// Handles creating shops
|
||||
else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE && (plugin.sneakCreate == false || p.isSneaking())) {
|
||||
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
||||
// As of the new checking system, most plugins will tell the
|
||||
// player why they can't create a shop there.
|
||||
// So telling them a message would cause spam etc.
|
||||
return;
|
||||
}
|
||||
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
||||
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
|
||||
return;
|
||||
}
|
||||
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getTypeId())) {
|
||||
p.sendMessage(MsgUtil.getMessage("blacklisted-item"));
|
||||
return;
|
||||
}
|
||||
// Finds out where the sign should be placed for the shop
|
||||
Block last = null;
|
||||
Location from = p.getLocation().clone();
|
||||
from.setY(b.getY());
|
||||
from.setPitch(0);
|
||||
BlockIterator bIt = new BlockIterator(from, 0, 7);
|
||||
while (bIt.hasNext()) {
|
||||
Block n = bIt.next();
|
||||
if (n.equals(b))
|
||||
break;
|
||||
last = n;
|
||||
}
|
||||
// Send creation menu.
|
||||
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", Util.getName(info.getItem())));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
/**
|
||||
* Waits for a player to move too far from a shop, then cancels the menu.
|
||||
*/
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
if (e.isCancelled())
|
||||
return;
|
||||
Info info = plugin.getShopManager().getActions().get(e.getPlayer().getUniqueId());
|
||||
if (info != null) {
|
||||
Player p = e.getPlayer();
|
||||
Location loc1 = info.getLocation();
|
||||
Location loc2 = p.getLocation();
|
||||
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
||||
if (info.getAction() == ShopAction.CREATE) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-creation-cancelled"));
|
||||
} else if (info.getAction() == ShopAction.BUY) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-purchase-cancelled"));
|
||||
}
|
||||
plugin.getShopManager().getActions().remove(p.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
|
||||
onMove(me);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
// Notify the player any messages they were sent
|
||||
Bukkit.getScheduler().runTaskLater(QuickShop.instance, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MsgUtil.flush(e.getPlayer());
|
||||
}
|
||||
}, 60);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
// Remove them from the menu
|
||||
plugin.getShopManager().getActions().remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickup(PlayerPickupItemEvent e) {
|
||||
ItemStack stack = e.getItem().getItemStack();
|
||||
try {
|
||||
if (stack.getItemMeta().getDisplayName().startsWith(ChatColor.RED + "QuickShop ")) {
|
||||
e.setCancelled(true);
|
||||
// You shouldn't be able to pick up that...
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
} // if meta/displayname/stack is null. We don't really care in that
|
||||
// case.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
if (e.getInventory().getHolder() instanceof Block) {
|
||||
Block block = (Block) e.getInventory().getHolder();
|
||||
if (Util.canBeShop(block)) {
|
||||
Shop shop = plugin.getShopManager().getShop(block.getLocation());
|
||||
if (shop==null && (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST)) {
|
||||
Block attached = Util.getSecondHalf(block);
|
||||
if (attached!=null) {
|
||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
if (shop!=null) {
|
||||
shop.setSignText();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.maxgamer.quickshop.Listeners;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Shop.Info;
|
||||
import org.maxgamer.quickshop.Shop.Shop;
|
||||
import org.maxgamer.quickshop.Shop.ShopAction;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
public class PlayerListener implements Listener {
|
||||
private QuickShop plugin;
|
||||
|
||||
public PlayerListener(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Could be useful one day private LinkedList<String> getParents(Class<?>
|
||||
* clazz){ LinkedList<String> classes = new LinkedList<String>();
|
||||
*
|
||||
* while(clazz != null){ classes.add("Extends " + ChatColor.GREEN +
|
||||
* clazz.getCanonicalName()); for(Class<?> iface : clazz.getInterfaces()){
|
||||
* classes.add("Implements " + ChatColor.RED + iface.getCanonicalName());
|
||||
* classes.addAll(getParents(iface)); }
|
||||
*
|
||||
* clazz = clazz.getSuperclass(); } return classes; }
|
||||
*/
|
||||
/**
|
||||
* Handles players left clicking a chest. Left click a NORMAL chest with
|
||||
* item : Send creation menu Left click a SHOP chest : Send purchase menu
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onClick(PlayerInteractEvent e) {
|
||||
if (e.getAction() != Action.LEFT_CLICK_BLOCK)
|
||||
return;
|
||||
Block b = e.getClickedBlock();
|
||||
if (!Util.canBeShop(b) && b.getType() != Material.WALL_SIGN)
|
||||
return;
|
||||
Player p = e.getPlayer();
|
||||
if (plugin.sneak && !p.isSneaking()) {
|
||||
// Sneak only
|
||||
return;
|
||||
}
|
||||
Location loc = b.getLocation();
|
||||
ItemStack item = e.getItem();
|
||||
// Get the shop
|
||||
Shop shop = plugin.getShopManager().getShop(loc);
|
||||
// If that wasn't a shop, search nearby shops
|
||||
if (shop == null) {
|
||||
Block attached = null;
|
||||
|
||||
if (b.getType() == Material.WALL_SIGN) {
|
||||
attached = Util.getAttached(b);
|
||||
} else if (b.getType() == Material.CHEST || b.getType() == Material.TRAPPED_CHEST) {
|
||||
attached = Util.getSecondHalf(b);
|
||||
}
|
||||
|
||||
if (attached != null) {
|
||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
}
|
||||
}
|
||||
// Purchase handling
|
||||
if (shop != null && p.hasPermission("quickshop.use") && (plugin.sneakTrade == false || p.isSneaking())) {
|
||||
shop.onClick();
|
||||
// Text menu
|
||||
MsgUtil.sendShopInfo(p, shop);
|
||||
if (shop.isSelling()) {
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-buy"));
|
||||
} else {
|
||||
int items = Util.countItems(p.getInventory(), shop.getItem());
|
||||
p.sendMessage(MsgUtil.getMessage("how-many-sell", "" + items));
|
||||
}
|
||||
// Add the new action
|
||||
HashMap<UUID, Info> actions = plugin.getShopManager().getActions();
|
||||
Info info = new Info(shop.getLocation(), ShopAction.BUY, null, null, shop);
|
||||
actions.put(p.getUniqueId(), info);
|
||||
return;
|
||||
}
|
||||
// Handles creating shops
|
||||
else if (shop == null && item != null && item.getType() != Material.AIR && p.hasPermission("quickshop.create.sell") && Util.canBeShop(b) && p.getGameMode() != GameMode.CREATIVE && (plugin.sneakCreate == false || p.isSneaking())) {
|
||||
if (!plugin.getShopManager().canBuildShop(p, b, e.getBlockFace())) {
|
||||
// As of the new checking system, most plugins will tell the
|
||||
// player why they can't create a shop there.
|
||||
// So telling them a message would cause spam etc.
|
||||
return;
|
||||
}
|
||||
if (Util.getSecondHalf(b) != null && !p.hasPermission("quickshop.create.double")) {
|
||||
p.sendMessage(MsgUtil.getMessage("no-double-chests"));
|
||||
return;
|
||||
}
|
||||
if (Util.isBlacklisted(item.getType()) && !p.hasPermission("quickshop.bypass." + item.getTypeId())) {
|
||||
p.sendMessage(MsgUtil.getMessage("blacklisted-item"));
|
||||
return;
|
||||
}
|
||||
// Finds out where the sign should be placed for the shop
|
||||
Block last = null;
|
||||
Location from = p.getLocation().clone();
|
||||
from.setY(b.getY());
|
||||
from.setPitch(0);
|
||||
BlockIterator bIt = new BlockIterator(from, 0, 7);
|
||||
while (bIt.hasNext()) {
|
||||
Block n = bIt.next();
|
||||
if (n.equals(b))
|
||||
break;
|
||||
last = n;
|
||||
}
|
||||
// Send creation menu.
|
||||
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", Util.getName(info.getItem())));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
/**
|
||||
* Waits for a player to move too far from a shop, then cancels the menu.
|
||||
*/
|
||||
public void onMove(PlayerMoveEvent e) {
|
||||
if (e.isCancelled())
|
||||
return;
|
||||
Info info = plugin.getShopManager().getActions().get(e.getPlayer().getUniqueId());
|
||||
if (info != null) {
|
||||
Player p = e.getPlayer();
|
||||
Location loc1 = info.getLocation();
|
||||
Location loc2 = p.getLocation();
|
||||
if (loc1.getWorld() != loc2.getWorld() || loc1.distanceSquared(loc2) > 25) {
|
||||
if (info.getAction() == ShopAction.CREATE) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-creation-cancelled"));
|
||||
} else if (info.getAction() == ShopAction.BUY) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-purchase-cancelled"));
|
||||
}
|
||||
plugin.getShopManager().getActions().remove(p.getUniqueId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent e) {
|
||||
PlayerMoveEvent me = new PlayerMoveEvent(e.getPlayer(), e.getFrom(), e.getTo());
|
||||
onMove(me);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final PlayerJoinEvent e) {
|
||||
// Notify the player any messages they were sent
|
||||
Bukkit.getScheduler().runTaskLater(QuickShop.instance, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MsgUtil.flush(e.getPlayer());
|
||||
}
|
||||
}, 60);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
// Remove them from the menu
|
||||
plugin.getShopManager().getActions().remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerPickup(PlayerPickupItemEvent e) {
|
||||
ItemStack stack = e.getItem().getItemStack();
|
||||
try {
|
||||
if (stack.getItemMeta().getDisplayName().startsWith(ChatColor.RED + "QuickShop ")) {
|
||||
e.setCancelled(true);
|
||||
// You shouldn't be able to pick up that...
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
} // if meta/displayname/stack is null. We don't really care in that
|
||||
// case.
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
if (e.getInventory().getHolder() instanceof Block) {
|
||||
Block block = (Block) e.getInventory().getHolder();
|
||||
if (Util.canBeShop(block)) {
|
||||
Shop shop = plugin.getShopManager().getShop(block.getLocation());
|
||||
if (shop==null && (block.getType() == Material.CHEST || block.getType() == Material.TRAPPED_CHEST)) {
|
||||
Block attached = Util.getSecondHalf(block);
|
||||
if (attached!=null) {
|
||||
shop = plugin.getShopManager().getShop(attached.getLocation());
|
||||
}
|
||||
}
|
||||
|
||||
if (shop!=null) {
|
||||
shop.setSignText();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ public class ShopManager {
|
||||
private QuickShop plugin;
|
||||
private HashMap<UUID, Info> actions = new HashMap<UUID, Info>();
|
||||
private HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>> shops = new HashMap<String, HashMap<ShopChunk, HashMap<Location, Shop>>>();
|
||||
final private static ItemStack AIR = new ItemStack(Material.AIR);
|
||||
|
||||
public ShopManager(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
@@ -236,10 +237,10 @@ public class ShopManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), b, bf); // PIE = PlayerInteractEvent - What else?
|
||||
PlayerInteractEvent pie = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, AIR, b, bf); // PIE = PlayerInteractEvent - What else?
|
||||
Bukkit.getPluginManager().callEvent(pie);
|
||||
pie.getPlayer().closeInventory(); // If the player has chat open, this
|
||||
// will close their chat.
|
||||
// will close their chat.
|
||||
if (pie.isCancelled()) {
|
||||
return false;
|
||||
}
|
||||
@@ -305,7 +306,7 @@ public class ShopManager {
|
||||
p.sendMessage(ChatColor.RED+"Restricted prices for "+info.getItem().getType()+": min "+priceRestriction.getKey()+", max "+priceRestriction.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double tax = plugin.getConfig().getDouble("shop.cost");
|
||||
// Tax refers to the cost to create a shop. Not actual
|
||||
// tax, that would be silly
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Util {
|
||||
shoppables.clear();
|
||||
transparent.clear();
|
||||
restrictedPrices.clear();
|
||||
|
||||
|
||||
plugin = QuickShop.instance;
|
||||
for (String s : plugin.getConfig().getStringList("shop-blocks")) {
|
||||
Material mat = Material.getMaterial(s.toUpperCase());
|
||||
@@ -204,7 +204,7 @@ public class Util {
|
||||
addTransparentBlock(Material.BREWING_STAND);
|
||||
addTransparentBlock(Material.WOODEN_DOOR);
|
||||
addTransparentBlock(Material.WOOD_STEP);
|
||||
|
||||
|
||||
for (String s : plugin.getConfig().getStringList("price-restriction")) {
|
||||
String[] sp = s.split(";");
|
||||
if (sp.length==3) {
|
||||
@@ -213,7 +213,7 @@ public class Util {
|
||||
if (mat == null) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
|
||||
restrictedPrices.put(mat, new SimpleEntry<Double,Double>(Double.valueOf(sp[1]), Double.valueOf(sp[2])));
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().info("Invalid price restricted material: " + s);
|
||||
@@ -221,7 +221,7 @@ public class Util {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Return an entry with min and max prices, but null if there isn't a price restriction */
|
||||
public static Entry<Double,Double> getPriceRestriction(Material material) {
|
||||
return restrictedPrices.get(material);
|
||||
@@ -373,19 +373,19 @@ public class Util {
|
||||
if (nameParts.length==1) {
|
||||
return firstUppercase(ugly);
|
||||
}
|
||||
|
||||
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for (String part : nameParts) {
|
||||
sb.append(firstUppercase(part)+" ");
|
||||
}
|
||||
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
// Let's make very long names shorter for our sign
|
||||
public static String getNameForSign(ItemStack itemStack) {
|
||||
String name = getDataName(itemStack.getType(), itemStack.getDurability());
|
||||
|
||||
|
||||
String[] nameParts = name.split("_");
|
||||
if (nameParts.length==1) {
|
||||
return firstUppercase(nameParts[0]);
|
||||
@@ -399,12 +399,12 @@ public class Util {
|
||||
nameParts[i] = firstUppercase(nameParts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nameParts[nameParts.length-1] = firstUppercase(nameParts[nameParts.length-1]);
|
||||
|
||||
return StringUtils.join(nameParts);
|
||||
}
|
||||
|
||||
|
||||
public static String firstUppercase(String string) {
|
||||
if (string.length()>1) {
|
||||
return Character.toUpperCase(string.charAt(0))+string.substring(1).toLowerCase();
|
||||
@@ -412,7 +412,7 @@ public class Util {
|
||||
return string.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String toRomain(Integer value) {
|
||||
return toRoman(value.intValue());
|
||||
@@ -850,8 +850,8 @@ public class Util {
|
||||
if (book1 != book2)
|
||||
return false;// One has enchantment meta, the other does not.
|
||||
if (book1 == true) { // They are the same here (both true or both
|
||||
// false). So if one is true, the other is
|
||||
// true.
|
||||
// false). So if one is true, the other is
|
||||
// true.
|
||||
Map<Enchantment, Integer> ench1 = ((EnchantmentStorageMeta) stack1.getItemMeta()).getStoredEnchants();
|
||||
Map<Enchantment, Integer> ench2 = ((EnchantmentStorageMeta) stack2.getItemMeta()).getStoredEnchants();
|
||||
if (!ench1.equals(ench2))
|
||||
@@ -896,7 +896,7 @@ public class Util {
|
||||
public static Block getAttached(Block b) {
|
||||
try {
|
||||
Sign sign = (Sign) b.getState().getData(); // Throws a NPE
|
||||
// sometimes??
|
||||
// sometimes??
|
||||
BlockFace attached = sign.getAttachedFace();
|
||||
if (attached == null)
|
||||
return null;
|
||||
@@ -975,4 +975,16 @@ public class Util {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockFace getYawFace(float yaw) {
|
||||
if (yaw > 315 && yaw <= 45) {
|
||||
return BlockFace.NORTH;
|
||||
} else if (yaw > 45 && yaw <= 135) {
|
||||
return BlockFace.EAST;
|
||||
} else if (yaw > 135 && yaw <= 225) {
|
||||
return BlockFace.SOUTH;
|
||||
} else {
|
||||
return BlockFace.WEST;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user