mirror of
https://github.com/EarthMC/QuickShop-Reremake.git
synced 2026-11-24 17:39:52 -05:00
Fix wg module bugs
Former-commit-id: 5f667b46c2c1d968f2a9cf615e56f04916720ac7
This commit is contained in:
1 parent
f7339cea6e
commit
8a3b4d35b7
3 files changed
+42
-38
No files matched your search
+29
-28
@@ -40,36 +40,38 @@ import org.maxgamer.quickshop.QuickShop;
|
||||
import org.maxgamer.quickshop.Util.Util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@IntegrationStage(loadStage = IntegrateStage.onLoadAfter)
|
||||
public class WorldGuardIntegration implements IntegratedPlugin {
|
||||
private List<WorldGuardFlags> createFlags;
|
||||
private List<WorldGuardFlags> tradeFlags;
|
||||
private StateFlag createFlag;
|
||||
private StateFlag tradeFlag;
|
||||
private StateFlag createFlag = new StateFlag("quickshop-create", false);
|
||||
private StateFlag tradeFlag = new StateFlag("quickshop-trade", true);
|
||||
private QuickShop plugin;
|
||||
public WorldGuardIntegration(QuickShop plugin){
|
||||
|
||||
public WorldGuardIntegration(QuickShop plugin) {
|
||||
this.plugin = plugin;
|
||||
createFlags = WorldGuardFlags.deserialize(plugin.getConfig().getStringList("integration.worldguard.create"));
|
||||
tradeFlags = WorldGuardFlags.deserialize(plugin.getConfig().getStringList("integration.worldguard.trade"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(){
|
||||
public void load() {
|
||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||
try {
|
||||
// create a flag with the name "my-custom-flag", defaulting to true
|
||||
this.createFlag = new StateFlag("quickshop-create", false);
|
||||
this.tradeFlag = new StateFlag("quickshop-trade", true);
|
||||
registry.register(this.createFlag);
|
||||
registry.register(this.tradeFlag);
|
||||
plugin.getLogger().info(ChatColor.GREEN+getName()+" flags register successfully.");
|
||||
Util.debugLog("Success register "+getName()+" flags.");
|
||||
plugin.getLogger().info(ChatColor.GREEN + getName() + " flags register successfully.");
|
||||
Util.debugLog("Success register " + getName() + " flags.");
|
||||
} catch (FlagConflictException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unload(){
|
||||
public void unload() {
|
||||
|
||||
}
|
||||
|
||||
@@ -83,32 +85,31 @@ public class WorldGuardIntegration implements IntegratedPlugin {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(location);
|
||||
boolean canBypass = WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(location.getWorld()));
|
||||
if(canBypass){
|
||||
Util.debugLog("Player "+player.getName()+" bypassing the protection checks, because player have bypass permission in WorldGuard");
|
||||
return true;
|
||||
}
|
||||
// if (canBypass) {
|
||||
// Util.debugLog("Player " + player.getName() + " bypassing the protection checks, because player have bypass permission in WorldGuard");
|
||||
// return true;
|
||||
// }
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
for (WorldGuardFlags flag: createFlags) {
|
||||
switch (flag){
|
||||
for (WorldGuardFlags flag : createFlags) {
|
||||
switch (flag) {
|
||||
case BUILD:
|
||||
if(!query.testState(wgLoc,localPlayer, Flags.BUILD)) {
|
||||
if (query.queryState(wgLoc, localPlayer, Flags.BUILD) == StateFlag.State.DENY) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case FLAG:
|
||||
if(!query.testState(wgLoc,localPlayer, this.createFlag)) {
|
||||
if (query.queryState(wgLoc, localPlayer, this.createFlag) == StateFlag.State.DENY) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case CHEST_ACCESS:
|
||||
if(!query.testState(wgLoc,localPlayer, Flags.CHEST_ACCESS)) {
|
||||
if (query.queryState(wgLoc, localPlayer, Flags.CHEST_ACCESS) == StateFlag.State.DENY) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case INTERACT:
|
||||
if(!query.testState(wgLoc,localPlayer, Flags.INTERACT)) {
|
||||
if (query.queryState(wgLoc, localPlayer, Flags.INTERACT) == StateFlag.State.DENY) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -122,32 +123,32 @@ public class WorldGuardIntegration implements IntegratedPlugin {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
com.sk89q.worldedit.util.Location wgLoc = BukkitAdapter.adapt(location);
|
||||
boolean canBypass = WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(location.getWorld()));
|
||||
if(canBypass){
|
||||
Util.debugLog("Player "+player.getName()+" bypassing the protection checks, because player have bypass permission in WorldGuard");
|
||||
if (canBypass) {
|
||||
Util.debugLog("Player " + player.getName() + " bypassing the protection checks, because player have bypass permission in WorldGuard");
|
||||
return true;
|
||||
}
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
for (WorldGuardFlags flag: createFlags) {
|
||||
switch (flag){
|
||||
for (WorldGuardFlags flag : createFlags) {
|
||||
switch (flag) {
|
||||
case BUILD:
|
||||
if(!query.testState(wgLoc,localPlayer, Flags.BUILD)) {
|
||||
if (!query.testState(wgLoc, localPlayer, Flags.BUILD)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
case FLAG:
|
||||
if(!query.testState(wgLoc,localPlayer, this.tradeFlag)) {
|
||||
if (!query.testState(wgLoc, localPlayer, this.tradeFlag)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case CHEST_ACCESS:
|
||||
if(!query.testState(wgLoc,localPlayer, Flags.CHEST_ACCESS)) {
|
||||
if (!query.testState(wgLoc, localPlayer, Flags.CHEST_ACCESS)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case INTERACT:
|
||||
if(!query.testState(wgLoc,localPlayer, Flags.INTERACT)) {
|
||||
if (!query.testState(wgLoc, localPlayer, Flags.INTERACT)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -320,6 +320,11 @@ public class ShopManager {
|
||||
shop.onUnload();
|
||||
return;
|
||||
}
|
||||
if(!plugin.getIntegrationHelper().callIntegrationsCanCreate(p,info.getLocation())){
|
||||
shop.onUnload();
|
||||
Util.debugLog("Cancelled by integrations");
|
||||
return;
|
||||
}
|
||||
/* The shop has hereforth been successfully created */
|
||||
createShop(shop, info);
|
||||
if (!plugin.getConfig().getBoolean("shop.lock")) {
|
||||
@@ -686,10 +691,6 @@ public class ShopManager {
|
||||
Util.debugLog("Cancelled by plugin");
|
||||
return;
|
||||
}
|
||||
if(!plugin.getIntegrationHelper().callIntegrationsCanCreate(player,info.getLocation())){
|
||||
Util.debugLog("Cancelled by integrations");
|
||||
return;
|
||||
}
|
||||
Location loc = shop.getLocation();
|
||||
try {
|
||||
// Write it to the database
|
||||
|
||||
@@ -66,14 +66,16 @@ public class IntegrationHelper {
|
||||
if (integratedPlugin.getClass().getDeclaredAnnotation(IntegrationStage.class).loadStage() == stage) {
|
||||
Util.debugLogHeavy("Calling for unload "+integratedPlugin.getName());
|
||||
integratedPlugin.unload();
|
||||
}else{
|
||||
Util.debugLogHeavy("Ignored calling because "+integratedPlugin.getName()+" stage is "+integratedPlugin.getClass().getDeclaredAnnotation(IntegrationStage.class).loadStage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean callIntegrationsCanCreate(@NotNull Player player, @NotNull Location location) {
|
||||
for (IntegratedPlugin integratedPlugin : integrations) {
|
||||
if (!integratedPlugin.canCreateShopHere(player, location)) {
|
||||
Util.debugLogHeavy("Integration " + integratedPlugin.getName() + " denied the player " + player.getName() + " at " + location + " shop creation.");
|
||||
for(IntegratedPlugin plugin : integrations){
|
||||
if (!plugin.canCreateShopHere(player,location)) {
|
||||
Util.debugLogHeavy("Cancelled by "+plugin.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -81,9 +83,9 @@ public class IntegrationHelper {
|
||||
}
|
||||
|
||||
public boolean callIntegrationsCanTrade(@NotNull Player player, @NotNull Location location) {
|
||||
for (IntegratedPlugin integratedPlugin : integrations) {
|
||||
if (!integratedPlugin.canTradeShopHere(player, location)) {
|
||||
Util.debugLogHeavy("Integration " + integratedPlugin.getName() + " denied the player " + player.getName() + " at " + location + " shop trading.");
|
||||
for(IntegratedPlugin plugin : integrations){
|
||||
if (!plugin.canTradeShopHere(player,location)) {
|
||||
Util.debugLogHeavy("Cancelled by "+plugin.getName());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user