mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Fix a / zero bug, Add new PermissionChecker
Former-commit-id: 71cebbdd68358496373975238e3e269a935de4a1 [formerly 7c9f01129f21bd08eee5fb0a9c1fff23382bfa0a] Former-commit-id: 9762ffce9ecd36ce3136a3a2ddeedde17c0185bf
This commit is contained in:
1 parent
6f63552c9d
commit
8a21877add
6 files changed
+88
-19
No files matched your search
@@ -29,6 +29,7 @@ import org.maxgamer.quickshop.Listeners.*;
|
||||
import org.maxgamer.quickshop.Shop.*;
|
||||
import org.maxgamer.quickshop.Util.Compatibility;
|
||||
import org.maxgamer.quickshop.Util.MsgUtil;
|
||||
import org.maxgamer.quickshop.Util.PermissionChecker;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
import org.maxgamer.quickshop.Watcher.ItemWatcher;
|
||||
import org.maxgamer.quickshop.Watcher.LogWatcher;
|
||||
@@ -98,6 +99,7 @@ public class QuickShop extends JavaPlugin {
|
||||
private ShopLoader shopLoader;
|
||||
private DatabaseHelper databaseHelper;
|
||||
private DatabaseManager databaseManager;
|
||||
private PermissionChecker permissionChecker;
|
||||
//private LWCPlugin lwcPlugin;
|
||||
|
||||
/**
|
||||
@@ -211,6 +213,7 @@ public class QuickShop extends JavaPlugin {
|
||||
this.shopManager = new ShopManager(this);
|
||||
this.queuedShopManager = new QueuedShopManager(this);
|
||||
this.databaseManager = new DatabaseManager(this, database);
|
||||
this.permissionChecker = new PermissionChecker(this);
|
||||
|
||||
if (this.display) {
|
||||
// Display item handler thread
|
||||
@@ -670,6 +673,14 @@ public class QuickShop extends JavaPlugin {
|
||||
reloadConfig();
|
||||
|
||||
}
|
||||
if (selectedVersion == 29) {
|
||||
getConfig().set("plugin.Multiverse-Core", null);
|
||||
getConfig().set("shop.protection-checking", true);
|
||||
getConfig().set("config-version", 30);
|
||||
selectedVersion = 30;
|
||||
saveConfig();
|
||||
reloadConfig();
|
||||
}
|
||||
}
|
||||
|
||||
/** Reloads QuickShops config */
|
||||
|
||||
@@ -236,6 +236,8 @@ public class ShopLoader {
|
||||
for (Long aM : m) {
|
||||
sum += aM;
|
||||
}
|
||||
if (m.length == 0)
|
||||
return sum;
|
||||
return sum / m.length;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,7 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredListener;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
@@ -313,13 +310,8 @@ public class ShopManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
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.
|
||||
if (pie.useInteractedBlock() == Result.DENY) {
|
||||
if (!plugin.getPermissionChecker().canBuild(p, b, true))
|
||||
return false;
|
||||
}
|
||||
ShopPreCreateEvent spce = new ShopPreCreateEvent(p, b.getLocation());
|
||||
Bukkit.getPluginManager().callEvent(spce);
|
||||
if (spce.isCancelled()) {
|
||||
@@ -582,14 +574,8 @@ public class ShopManager {
|
||||
|
||||
plugin.getCompatibilityTool().toggleInteractListeners(false);
|
||||
|
||||
PlayerInteractEvent be = new PlayerInteractEvent(p, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), info
|
||||
.getLocation().getBlock(), BlockFace.SELF);
|
||||
Bukkit.getPluginManager().callEvent(be);
|
||||
|
||||
plugin.getCompatibilityTool().toggleInteractListeners(true);
|
||||
|
||||
if (be.isCancelled()) {
|
||||
be.getPlayer().sendMessage(MsgUtil.getMessage("no-permission"));
|
||||
if (!plugin.getPermissionChecker().canBuild(p, info.getLocation(), true)) {
|
||||
p.sendMessage(MsgUtil.getMessage("no-permission") + ": BUILD CHECK");
|
||||
Util.debugLog("Failed to create shop: Protection check failed:");
|
||||
for (RegisteredListener belisteners : BlockBreakEvent.getHandlerList().getRegisteredListeners()) {
|
||||
Util.debugLog(belisteners.getPlugin().getName());
|
||||
@@ -597,6 +583,8 @@ public class ShopManager {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getCompatibilityTool().toggleInteractListeners(true);
|
||||
|
||||
if (plugin.getShopManager().getShop(info.getLocation()) != null) {
|
||||
p.sendMessage(MsgUtil.getMessage("shop-already-owned"));
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.maxgamer.quickshop.Util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.maxgamer.quickshop.QuickShop;
|
||||
|
||||
public class PermissionChecker {
|
||||
private QuickShop plugin;
|
||||
private boolean usePermissionChecker;
|
||||
|
||||
public PermissionChecker(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
usePermissionChecker = this.plugin.getConfig().getBoolean("shop.protection-checking");
|
||||
}
|
||||
|
||||
public boolean canBuild(Player player, Location location, boolean place) {
|
||||
if (!usePermissionChecker) {
|
||||
return true;
|
||||
} else {
|
||||
return canBuild(player, location.getBlock(), place);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canBuild(Player player, Block block, boolean place) {
|
||||
if (!usePermissionChecker)
|
||||
return true;
|
||||
BlockEvent beMainHand;
|
||||
BlockEvent beOffHand;
|
||||
if (place) {
|
||||
beMainHand = new BlockPlaceEvent(block, block.getState(), block.getRelative(0, -1, 0), player.getInventory()
|
||||
.getItemInMainHand(), player, true, EquipmentSlot.HAND);
|
||||
beOffHand = new BlockPlaceEvent(block, block.getState(), block.getRelative(0, -1, 0), player.getInventory()
|
||||
.getItemInOffHand(), player, true, EquipmentSlot.OFF_HAND);
|
||||
} else {
|
||||
beMainHand = new BlockBreakEvent(block, player);
|
||||
beOffHand = new BlockBreakEvent(block, player);
|
||||
}
|
||||
Bukkit.getPluginManager().callEvent(beMainHand);
|
||||
Bukkit.getPluginManager().callEvent(beOffHand);
|
||||
|
||||
if (((Cancellable) beMainHand).isCancelled())
|
||||
return false;
|
||||
if (((Cancellable) beOffHand).isCancelled())
|
||||
return false;
|
||||
|
||||
if (beMainHand instanceof BlockPlaceEvent)
|
||||
if (!((BlockPlaceEvent) beMainHand).canBuild())
|
||||
return false;
|
||||
|
||||
if (beOffHand instanceof BlockPlaceEvent)
|
||||
if (!((BlockPlaceEvent) beOffHand).canBuild())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#Default config: https://github.com/Ghost-chu/QuickShop-Reremake/blob/master/src/main/resources/config.yml
|
||||
|
||||
#Do not touch if you not clear know about this
|
||||
config-version: 29
|
||||
config-version: 30
|
||||
|
||||
#Select language you want use, (e.g de), use other exist language to override it.
|
||||
#After you use new language override it, you need delete `messages.yml` to let plugin regen your language file.
|
||||
@@ -173,6 +173,9 @@ shop:
|
||||
#Check itemstack more strict!
|
||||
strict-matches-check: false
|
||||
|
||||
#Protection check
|
||||
protection-checking: true
|
||||
|
||||
#ShopQueue can help low-performance server load shops one by one not all in same time.
|
||||
#This feature can help solve server laggy when load huge numbers shops or dead-lock threads.
|
||||
queue:
|
||||
@@ -207,4 +210,5 @@ plugin:
|
||||
#If you have Multiverse-Core, QSRR will try load world when shop's world not exist and throw out exception auto repair the shop.
|
||||
Multiverse-Core: true
|
||||
#If you have OpenInv, QSRR will enable EnderChest feature.
|
||||
OpenInv: true
|
||||
OpenInv: true
|
||||
#
|
||||
Reference in new issue
Block a user