Update Permission #220
@ -28,6 +28,7 @@ import de.steamwar.bausystem.region.loader.RegionLoader;
|
||||
import de.steamwar.bausystem.region.loader.Updater;
|
||||
import de.steamwar.bausystem.utils.TickListener;
|
||||
import de.steamwar.bausystem.worlddata.WorldData;
|
||||
import de.steamwar.command.AbstractValidator;
|
||||
import de.steamwar.command.SWCommandUtils;
|
||||
import de.steamwar.message.Message;
|
||||
import lombok.Getter;
|
||||
@ -77,38 +78,27 @@ public class BauSystem extends JavaPlugin implements Listener {
|
||||
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
||||
new Updater(RegionLoader.file, RegionLoader::load);
|
||||
|
||||
SWCommandUtils.addValidator(Player.class, (player, object, messageSender) -> {
|
||||
if (Permission.BUILD.hasPermission(player)) {
|
||||
return true;
|
||||
}
|
||||
messageSender.send("NO_PERMISSION");
|
||||
return false;
|
||||
});
|
||||
SWCommandUtils.addValidator(CommandSender.class, (commandSender, object, messageSender) -> {
|
||||
if (commandSender instanceof Player) {
|
||||
if (Permission.BUILD.hasPermission((Player) commandSender)) {
|
||||
return true;
|
||||
}
|
||||
messageSender.send("NO_PERMISSION");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
SWCommandUtils.addValidator("supervisor", (commandSender, object, messageSender) -> {
|
||||
if (commandSender instanceof Player) {
|
||||
if (Permission.SUPERVISOR.hasPermission((Player) commandSender)) {
|
||||
return true;
|
||||
}
|
||||
messageSender.send("NO_PERMISSION");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD));
|
||||
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));
|
||||
SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR));
|
||||
|
||||
LinkageUtils.link();
|
||||
TickListener.impl.init();
|
||||
}
|
||||
|
||||
private <T extends CommandSender> AbstractValidator<T, ?> validator(Permission permission) {
|
||||
return (commandSender, object, messageSender) -> {
|
||||
if (commandSender instanceof Player) {
|
||||
if (permission.hasPermission((Player) commandSender)) {
|
||||
return true;
|
||||
}
|
||||
messageSender.send("NO_PERMISSION");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
LinkageUtils.unlink();
|
||||
|
@ -49,9 +49,9 @@ public enum Permission {
|
||||
REAL_SPECTATOR(bauweltMember -> {
|
||||
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
||||
}),
|
||||
SPECTATOR(bauweltMember -> {
|
||||
return !BUILD.permissionPredicate.test(bauweltMember);
|
||||
}),
|
||||
/**
|
||||
* Primarily used for {@link de.steamwar.bausystem.linkage.specific.GuiItem}
|
||||
*/
|
||||
MEMBER(bauweltMember -> {
|
||||
YoyoNow markierte diese Unterhaltung als gelöst
|
||||
return true;
|
||||
});
|
||||
@ -87,10 +87,10 @@ public enum Permission {
|
||||
|
||||
public boolean hasPermission(Player member) {
|
||||
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
||||
return this != SPECTATOR && this != REAL_SPECTATOR;
|
||||
return this != REAL_SPECTATOR;
|
||||
}
|
||||
BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
|
||||
if (bauweltMember == null) return this == SPECTATOR || this == REAL_SPECTATOR;
|
||||
if (bauweltMember == null) return this == REAL_SPECTATOR;
|
||||
return permissionPredicate.test(bauweltMember);
|
||||
}
|
||||
}
|
@ -96,7 +96,7 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 0);
|
||||
@ -104,13 +104,13 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
calcCursor(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
calcCursor(event.getPlayer());
|
||||
}, 1);
|
||||
@ -159,7 +159,7 @@ public class SimulatorCursor implements Listener {
|
||||
if (calculating.contains(player)) return;
|
||||
calculating.add(player);
|
||||
}
|
||||
if (Permission.SPECTATOR.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
|
||||
if (!Permission.BUILD.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) {
|
||||
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||
SWUtils.sendToActionbar(player, "");
|
||||
}
|
||||
@ -344,7 +344,7 @@ public class SimulatorCursor implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||
return;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class PistonCalculator implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return;
|
||||
if (event.getClickedBlock() == null) return;
|
||||
|
@ -35,7 +35,7 @@ public class TNTClickListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||
|
||||
Entity entity = event.getRightClicked();
|
||||
|
@ -85,7 +85,7 @@ public class BauMemberUpdate extends PacketHandler implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
SPECTATORS.add(event.getPlayer());
|
||||
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false));
|
||||
showSpectatorNotice(event.getPlayer());
|
||||
|
@ -42,7 +42,7 @@ public class ItemFrameListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Permission.SPECTATOR.hasPermission((Player) event.getDamager())) return;
|
||||
if(!Permission.BUILD.hasPermission((Player) event.getDamager())) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
ItemFrame itemFrame = (ItemFrame) event.getEntity();
|
||||
|
@ -82,7 +82,7 @@ public class SignEditFrom20 implements Listener {
|
||||
}
|
||||
|
||||
private void edit(Player player, Block block) {
|
||||
if (Permission.SPECTATOR.hasPermission(player)) return;
|
||||
if (!Permission.BUILD.hasPermission(player)) return;
|
||||
Sign sign = (Sign) block.getState();
|
||||
Side side = signSide(player, block);
|
||||
SignSide signSide = sign.getSide(side);
|
||||
|
@ -69,7 +69,7 @@ public class SignEditUntil19 implements Listener {
|
||||
}
|
||||
|
||||
private void edit(Player player, Block block) {
|
||||
if (Permission.SPECTATOR.hasPermission(player)) return;
|
||||
if (!Permission.BUILD.hasPermission(player)) return;
|
||||
Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||
String[] lines = sign.getLines();
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
|
@ -176,7 +176,7 @@ public class SpectatorListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -184,56 +184,56 @@ public class SpectatorListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||
if (event.getPlayer() == null) return;
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setBuildable(false);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerBucketEntity(PlayerBucketEntityEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@ -241,7 +241,7 @@ public class SpectatorListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (Permission.SPECTATOR.hasPermission((Player) event.getEntity())) {
|
||||
if (!Permission.BUILD.hasPermission((Player) event.getEntity())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class WorldEditListener implements Listener {
|
||||
if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return;
|
||||
|
||||
Player p = e.getPlayer();
|
||||
if (Permission.SPECTATOR.hasPermission(e.getPlayer())) {
|
||||
if (!Permission.BUILD.hasPermission(e.getPlayer())) {
|
||||
BauSystem.MESSAGE.send("NO_PERMISSION", p);
|
||||
e.setCancelled(true);
|
||||
e.setMessage("/");
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Wird das überhaupt noch benötigt? Jeder auf dem Server ist ja mindestens Member.