Skip to content

Commit

Permalink
[U] 删除对 PlotSquared 的直接权限检查
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jun 17, 2020
1 parent 918b99b commit 5b7bb3d
Showing 1 changed file with 23 additions and 42 deletions.
65 changes: 23 additions & 42 deletions src/main/java/io/github/starwishsama/extra/ProtectionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.plotsquared.core.plot.Plot;
import io.github.thebusybiscuit.slimefun4.api.events.AndroidMineEvent;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
Expand All @@ -27,7 +26,6 @@
*/
public class ProtectionChecker implements Listener {
private static boolean resInstalled = false;
private static boolean plotInstalled = false;

@EventHandler
public void onAndroidMine(AndroidMineEvent e) {
Expand All @@ -42,24 +40,18 @@ public void onAndroidMine(AndroidMineEvent e) {
}

public ProtectionChecker(SlimefunPlugin plugin) {
checkInstallStatus(plugin);
resInstalled = plugin.getServer().getPluginManager().getPlugin("Residence") != null;

if (!resInstalled && !plotInstalled) {
plugin.getLogger().log(Level.WARNING, "未检测到领地/地皮插件, 相关功能将自动关闭");
if (!resInstalled) {
plugin.getLogger().log(Level.WARNING, "未检测到领地插件, 相关功能将自动关闭");
return;
}

if (resInstalled) plugin.getLogger().log(Level.INFO, "检测到领地插件, 相关功能已开启");
if (plotInstalled) plugin.getLogger().log(Level.INFO, "检测到地皮插件, 相关功能已开启");
plugin.getLogger().log(Level.INFO, "检测到领地插件, 相关功能已开启");

plugin.getServer().getPluginManager().registerEvents(this, plugin);
}

public static void checkInstallStatus(SlimefunPlugin plugin) {
resInstalled = plugin.getServer().getPluginManager().getPlugin("Residence") != null;
plotInstalled = plugin.getServer().getPluginManager().getPlugin("PlotSquared") != null;
}

/**
* 检查是否可以在领地/地皮内破坏/交互方块
*
Expand All @@ -69,42 +61,31 @@ public static void checkInstallStatus(SlimefunPlugin plugin) {
* @return 是否可以破坏
*/
public static boolean canInteract(Player p, Block block, InteractType type) {
if (p != null && block != null) {
if (p != null && block != null && resInstalled) {
if (p.isOp()) {
return true;
}
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(block.getLocation());
if (res != null) {
ResidencePermissions perms = res.getPermissions();

if (resInstalled) {
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(block.getLocation());
if (res != null) {
ResidencePermissions perms = res.getPermissions();

if (res.getOwnerUUID() == p.getUniqueId()) {
return true;
}

switch (type) {
case DESTROY:
return perms.playerHas(p, Flags.destroy, true) || perms.playerHas(p, Flags.build, true);
case PLACE:
case MOVE:
return perms.playerHas(p, Flags.place, true) || perms.playerHas(p, Flags.build, true);
case INTERACT:
if (!perms.playerHas(p, Flags.use, true)) {
SlimefunPlugin.getLocal().sendMessage(p, "inventory.no-access");
return false;
} else {
return true;
}
}
if (res.getOwnerUUID() == p.getUniqueId()) {
return true;
}
}

if (plotInstalled) {
Plot plot = Plot.getPlot(new com.plotsquared.core.location.Location(block.getWorld().getName(), block.getX(), block.getY(), block.getZ()));

if (plot != null) {
return plot.isOwner(p.getUniqueId()) || plot.isAdded(p.getUniqueId());
switch (type) {
case DESTROY:
return perms.playerHas(p, Flags.destroy, true) || perms.playerHas(p, Flags.build, true);
case PLACE:
case MOVE:
return perms.playerHas(p, Flags.place, true) || perms.playerHas(p, Flags.build, true);
case INTERACT:
if (!perms.playerHas(p, Flags.use, true)) {
SlimefunPlugin.getLocal().sendMessage(p, "inventory.no-access");
return false;
} else {
return true;
}
}
}
}
Expand Down

0 comments on commit 5b7bb3d

Please sign in to comment.