1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Added permission checks for the GEO Scanner and GPS Control Panel

This commit is contained in:
NCBPFluffyBear 2020-10-06 19:46:22 -05:00
parent a843e99dbf
commit 37f0715156
2 changed files with 38 additions and 4 deletions

View File

@ -1,6 +1,9 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.geo;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
@ -19,10 +22,22 @@ public class GEOScanner extends SimpleSlimefunItem<BlockUseHandler> {
@Override
public BlockUseHandler getItemHandler() {
return e -> {
Block b = e.getClickedBlock().get();
e.cancel();
SlimefunPlugin.getGPSNetwork().getResourceManager().scan(e.getPlayer(), b, 0);
Block b = e.getClickedBlock().get();
Player p = e.getPlayer();
if (p.hasPermission("slimefun.inventory.bypass")
|| (SlimefunPlugin.getProtectionManager().hasPermission(
p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES))
&& Slimefun.hasUnlocked(e.getPlayer(), item, false)
) {
SlimefunPlugin.getGPSNetwork().getResourceManager().scan(p, b, 0);
} else {
SlimefunPlugin.getLocalization().sendMessage(p, "inventory.no-access", true);
}
};
}
}

View File

@ -1,5 +1,8 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.gps;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
@ -17,6 +20,22 @@ public class GPSControlPanel extends SimpleSlimefunItem<BlockUseHandler> {
@Override
public BlockUseHandler getItemHandler() {
return e -> SlimefunPlugin.getGPSNetwork().openTransmitterControlPanel(e.getPlayer());
return e -> {
e.cancel();
Player p = e.getPlayer();
if (p.hasPermission("slimefun.inventory.bypass")
|| (SlimefunPlugin.getProtectionManager().hasPermission(
p, e.getClickedBlock().get().getLocation(), ProtectableAction.ACCESS_INVENTORIES))
&& Slimefun.hasUnlocked(p, item, false)
) {
SlimefunPlugin.getGPSNetwork().openTransmitterControlPanel(p);
} else {
SlimefunPlugin.getLocalization().sendMessage(p, "inventory.no-access", true);
}
};
}
}