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.region.loader.Updater;
|
||||||
import de.steamwar.bausystem.utils.TickListener;
|
import de.steamwar.bausystem.utils.TickListener;
|
||||||
import de.steamwar.bausystem.worlddata.WorldData;
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
|
import de.steamwar.command.AbstractValidator;
|
||||||
import de.steamwar.command.SWCommandUtils;
|
import de.steamwar.command.SWCommandUtils;
|
||||||
import de.steamwar.message.Message;
|
import de.steamwar.message.Message;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -77,38 +78,27 @@ public class BauSystem extends JavaPlugin implements Listener {
|
|||||||
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
new Updater(PrototypeLoader.file, PrototypeLoader::load);
|
||||||
new Updater(RegionLoader.file, RegionLoader::load);
|
new Updater(RegionLoader.file, RegionLoader::load);
|
||||||
|
|
||||||
SWCommandUtils.addValidator(Player.class, (player, object, messageSender) -> {
|
SWCommandUtils.addValidator(Player.class, validator(Permission.BUILD));
|
||||||
if (Permission.BUILD.hasPermission(player)) {
|
SWCommandUtils.addValidator(CommandSender.class, validator(Permission.BUILD));
|
||||||
return true;
|
SWCommandUtils.addValidator("supervisor", validator(Permission.SUPERVISOR));
|
||||||
}
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
LinkageUtils.link();
|
LinkageUtils.link();
|
||||||
TickListener.impl.init();
|
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;
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
LinkageUtils.unlink();
|
LinkageUtils.unlink();
|
||||||
|
@ -49,9 +49,9 @@ public enum Permission {
|
|||||||
REAL_SPECTATOR(bauweltMember -> {
|
REAL_SPECTATOR(bauweltMember -> {
|
||||||
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
return !bauweltMember.isBuild() && !bauweltMember.isSupervisor();
|
||||||
}),
|
}),
|
||||||
SPECTATOR(bauweltMember -> {
|
/**
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Die Spectator-Permissions fallen etwas aus dem Muster, da es sich hier um die einzigen negativen Permissions handelt. Das macht auch die Permissonchecks unten sehr merkwürdig. Man sollte alle Anwendungen davon auf Die Spectator-Permissions fallen etwas aus dem Muster, da es sich hier um die einzigen negativen Permissions handelt. Das macht auch die Permissonchecks unten sehr merkwürdig. Man sollte alle Anwendungen davon auf `!BUILD` ändern.
|
|||||||
return !BUILD.permissionPredicate.test(bauweltMember);
|
* Primarily used for {@link de.steamwar.bausystem.linkage.specific.GuiItem}
|
||||||
}),
|
*/
|
||||||
MEMBER(bauweltMember -> {
|
MEMBER(bauweltMember -> {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Lixfel
hat
Wird das überhaupt noch benötigt? Jeder auf dem Server ist ja mindestens Member. Wird das überhaupt noch benötigt? Jeder auf dem Server ist ja mindestens Member.
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@ -87,10 +87,10 @@ public enum Permission {
|
|||||||
|
|
||||||
public boolean hasPermission(Player member) {
|
public boolean hasPermission(Player member) {
|
||||||
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
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());
|
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);
|
return permissionPredicate.test(bauweltMember);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -96,7 +96,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
calcCursor(event.getPlayer());
|
calcCursor(event.getPlayer());
|
||||||
}, 0);
|
}, 0);
|
||||||
@ -104,13 +104,13 @@ public class SimulatorCursor implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
calcCursor(event.getPlayer());
|
calcCursor(event.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
public void onPlayerItemHeld(PlayerItemHeldEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return;
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) return;
|
||||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
calcCursor(event.getPlayer());
|
calcCursor(event.getPlayer());
|
||||||
}, 1);
|
}, 1);
|
||||||
@ -159,7 +159,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
if (calculating.contains(player)) return;
|
if (calculating.contains(player)) return;
|
||||||
calculating.add(player);
|
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)) {
|
if (removeCursor(player) || SimulatorWatcher.show(null, player)) {
|
||||||
SWUtils.sendToActionbar(player, "");
|
SWUtils.sendToActionbar(player, "");
|
||||||
}
|
}
|
||||||
@ -344,7 +344,7 @@ public class SimulatorCursor implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
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")) {
|
if (!ItemUtils.isItem(event.getItem(), "simulator")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public class PistonCalculator implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
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.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||||
if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return;
|
if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return;
|
||||||
if (event.getClickedBlock() == null) return;
|
if (event.getClickedBlock() == null) return;
|
||||||
|
@ -35,7 +35,7 @@ public class TNTClickListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
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;
|
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||||
|
|
||||||
Entity entity = event.getRightClicked();
|
Entity entity = event.getRightClicked();
|
||||||
|
@ -85,7 +85,7 @@ public class BauMemberUpdate extends PacketHandler implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
SPECTATORS.add(event.getPlayer());
|
SPECTATORS.add(event.getPlayer());
|
||||||
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false));
|
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false));
|
||||||
showSpectatorNotice(event.getPlayer());
|
showSpectatorNotice(event.getPlayer());
|
||||||
|
@ -42,7 +42,7 @@ public class ItemFrameListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Permission.SPECTATOR.hasPermission((Player) event.getDamager())) return;
|
if(!Permission.BUILD.hasPermission((Player) event.getDamager())) return;
|
||||||
|
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
ItemFrame itemFrame = (ItemFrame) event.getEntity();
|
ItemFrame itemFrame = (ItemFrame) event.getEntity();
|
||||||
|
@ -82,7 +82,7 @@ public class SignEditFrom20 implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void edit(Player player, Block block) {
|
private void edit(Player player, Block block) {
|
||||||
if (Permission.SPECTATOR.hasPermission(player)) return;
|
if (!Permission.BUILD.hasPermission(player)) return;
|
||||||
Sign sign = (Sign) block.getState();
|
Sign sign = (Sign) block.getState();
|
||||||
Side side = signSide(player, block);
|
Side side = signSide(player, block);
|
||||||
SignSide signSide = sign.getSide(side);
|
SignSide signSide = sign.getSide(side);
|
||||||
|
@ -69,7 +69,7 @@ public class SignEditUntil19 implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void edit(Player player, Block block) {
|
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();
|
Sign sign = (org.bukkit.block.Sign) block.getState();
|
||||||
String[] lines = sign.getLines();
|
String[] lines = sign.getLines();
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
@ -176,7 +176,7 @@ public class SpectatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
|
public void onBlockMultiPlace(BlockMultiPlaceEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,56 +184,56 @@ public class SpectatorListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
public void onBlockCanBuild(BlockCanBuildEvent event) {
|
||||||
if (event.getPlayer() == null) return;
|
if (event.getPlayer() == null) return;
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setBuildable(false);
|
event.setBuildable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onBlockPlace(BlockPlaceEvent event) {
|
public void onBlockPlace(BlockPlaceEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockBreak(BlockBreakEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerBucketEntity(PlayerBucketEntityEvent event) {
|
public void onPlayerBucketEntity(PlayerBucketEntityEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ public class SpectatorListener implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
public void onEntityPickupItem(EntityPickupItemEvent event) {
|
||||||
if (!(event.getEntity() instanceof Player)) return;
|
if (!(event.getEntity() instanceof Player)) return;
|
||||||
if (Permission.SPECTATOR.hasPermission((Player) event.getEntity())) {
|
if (!Permission.BUILD.hasPermission((Player) event.getEntity())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class WorldEditListener implements Listener {
|
|||||||
if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return;
|
if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return;
|
||||||
|
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
if (Permission.SPECTATOR.hasPermission(e.getPlayer())) {
|
if (!Permission.BUILD.hasPermission(e.getPlayer())) {
|
||||||
BauSystem.MESSAGE.send("NO_PERMISSION", p);
|
BauSystem.MESSAGE.send("NO_PERMISSION", p);
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
e.setMessage("/");
|
e.setMessage("/");
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Die 3 Validator sind sehr gleich von der Codestruktur, evtl. Eine Extra-Methode daraus machen, mit Input CommandSender und Parameter, welche Permission.