use more core premission check protection

Former-commit-id: 133ff74c4d647b15c64df7efcce2fe8255f7800e
This commit is contained in:
Ghost_chu committed 2018-09-23 21:57:04 +08:00
1 parent ed772804f7
commit 328fe35030
2 files changed
+13 -18

No files matched your search

@@ -55,23 +55,6 @@ public class ShopManager {
public void createShop(Shop shop) {
Location loc = shop.getLocation();
ItemStack item = shop.getItem();
Player player = Bukkit.getPlayer(shop.getOwner());
if(player==null || !player.isOnline()) {
plugin.getLogger().info("Warning! Something wrong happed when createing shop,Canceling... (Code: Target player not online)");
return;
}
PlayerInteractEvent e = new PlayerInteractEvent(player, Action.LEFT_CLICK_BLOCK, item, shop.getLocation().getBlock(), BlockFace.UP);
Bukkit.getPluginManager().callEvent(e);
if (e.isCancelled()) {
e.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
return;
}
BlockBreakEvent be = new BlockBreakEvent(shop.getLocation().getBlock(),player);
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
be.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
return;
}
try {
// Write it to the database
String q = "INSERT INTO shops (owner, price, itemConfig, x, y, z, world, unlimited, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
@@ -186,6 +169,12 @@ public class ShopManager {
ShopChunk shopChunk = new ShopChunk(world, x, z);
HashMap<Location, Shop> inChunk = inWorld.get(shopChunk);
// That chunk data hasn't been created yet - Create it!
BlockBreakEvent be = new BlockBreakEvent(shop.getLocation().getBlock(),Bukkit.getPlayer(shop.getOwner()));
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
be.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
return;
}
if (inChunk == null) {
inChunk = new HashMap<Location, Shop>(1);
// Put it in the world
@@ -314,6 +303,12 @@ public class ShopManager {
if (info.getAction() == ShopAction.CREATE) {
try {
// Checking the shop can be created
BlockBreakEvent be = new BlockBreakEvent(info.getLocation().getBlock(),p);
Bukkit.getPluginManager().callEvent(be);
if (be.isCancelled()) {
be.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
return;
}
if (plugin.getShopManager().getShop(info.getLocation()) != null) {
p.sendMessage(MsgUtil.getMessage("shop-already-owned"));
return;