Update Permission #220
@ -21,6 +21,7 @@ package de.steamwar.bausystem;
|
|||||||
|
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
import de.steamwar.sql.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -29,11 +30,9 @@ import java.util.function.Predicate;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum Permission {
|
public enum Permission {
|
||||||
|
|
||||||
OWNER(bauweltMember -> {
|
OWNER(bauweltMember -> false),
|
||||||
return bauweltMember.getBauweltID() == BauServer.getInstance().getOwnerID();
|
|
||||||
}),
|
|
||||||
SUPERVISOR(bauweltMember -> {
|
SUPERVISOR(bauweltMember -> {
|
||||||
return OWNER.permissionPredicate.test(bauweltMember); // TODO: Needs to be changed later on
|
return false; // TODO: Needs to be changed later on
|
||||||
}),
|
}),
|
||||||
BUILD(bauweltMember -> {
|
BUILD(bauweltMember -> {
|
||||||
return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember);
|
return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember);
|
||||||
@ -47,9 +46,17 @@ public enum Permission {
|
|||||||
|
|
||||||
private final Predicate<BauweltMember> permissionPredicate;
|
private final Predicate<BauweltMember> permissionPredicate;
|
||||||
|
|
||||||
|
public boolean hasPermission(BauweltMember bauweltMember) {
|
||||||
|
if (bauweltMember == null) return false;
|
||||||
|
return permissionPredicate.test(bauweltMember);
|
||||||
|
}
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
|
||||||
public boolean hasPermission(Player member) {
|
public boolean hasPermission(Player member) {
|
||||||
|
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
|
||||||
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 this != 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;
|
if (bauweltMember == null) return false;
|
||||||
return permissionPredicate.test(bauweltMember);
|
return permissionPredicate.test(bauweltMember);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package de.steamwar.bausystem.features.bau;
|
package de.steamwar.bausystem.features.bau;
|
||||||
|
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
@ -24,12 +25,7 @@ public class InfoCommand extends SWCommand {
|
|||||||
super("bauinfo");
|
super("bauinfo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register(help = true)
|
@Register(description = "BAU_INFO_COMMAND_HELP")
|
||||||
public void genericHelp(Player p, String... args) {
|
|
||||||
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_HELP", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Register
|
|
||||||
public void genericCommand(Player p) {
|
public void genericCommand(Player p) {
|
||||||
sendBauInfo(p);
|
sendBauInfo(p);
|
||||||
}
|
}
|
||||||
@ -52,11 +48,16 @@ public class InfoCommand extends SWCommand {
|
|||||||
membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size()));
|
membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size()));
|
||||||
|
|
||||||
for (BauweltMember member : members) {
|
for (BauweltMember member : members) {
|
||||||
membermessage.append(BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_INFO", p,
|
if (!membermessage.isEmpty()) {
|
||||||
SteamwarUser.get(member.getMemberID()).getUserName(),
|
membermessage.append(", ");
|
||||||
member.isWorldEdit() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WE_DISALLOW", p),
|
}
|
||||||
member.isWorld() ? BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_ALLOW", p) : BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_WORLD_DISALLOW", p)
|
if (Permission.SUPERVISOR.hasPermission(member)) {
|
||||||
));
|
membermessage.append("§c").append(SteamwarUser.get(member.getMemberID()).getUserName());
|
||||||
|
} else if (Permission.BUILD.hasPermission(member)) {
|
||||||
|
membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName());
|
||||||
|
} else {
|
||||||
|
membermessage.append("§7").append(SteamwarUser.get(member.getMemberID()).getUserName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.sendMessage(membermessage.toString());
|
p.sendMessage(membermessage.toString());
|
||||||
|
|
||||||
|
@ -48,6 +48,6 @@ public class CountingwandGuiItem extends BauGuiItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Permission permission() {
|
public Permission permission() {
|
||||||
return Permission.WORLDEDIT;
|
return Permission.MEMBER;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -108,26 +108,13 @@ public class BauGUI {
|
|||||||
if (!permission.hasPermission(p)) {
|
if (!permission.hasPermission(p)) {
|
||||||
List<String> lore = meta.getLore();
|
List<String> lore = meta.getLore();
|
||||||
if (lore == null) {
|
if (lore == null) {
|
||||||
lore = Collections.singletonList(BauSystem.MESSAGE.parse(permissionString(permission), p));
|
lore = Collections.singletonList(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
|
||||||
} else {
|
} else {
|
||||||
lore.add(BauSystem.MESSAGE.parse(permissionString(permission), p));
|
lore.add(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
|
||||||
}
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
itemStack.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String permissionString(Permission permission) {
|
|
||||||
switch (permission) {
|
|
||||||
case OWNER:
|
|
||||||
return "GUI_NO_OWNER";
|
|
||||||
case WORLD:
|
|
||||||
return "GUI_NO_WORLD";
|
|
||||||
case WORLDEDIT:
|
|
||||||
return "GUI_NO_WORLDEDIT";
|
|
||||||
default:
|
|
||||||
return "GUI_NO_MEMBER";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,10 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.features.world;
|
package de.steamwar.bausystem.features.world;
|
||||||
|
|
||||||
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.bausystem.utils.NMSWrapper;
|
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@ -45,8 +44,13 @@ public class SpectatorListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
if (Permission.SUPERVISOR.hasPermission(event.getPlayer())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!anySupervisorOnline(null)) {
|
if (!anySupervisorOnline(null)) {
|
||||||
event.getPlayer().kickPlayer("");
|
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||||
|
event.getPlayer().kickPlayer("");
|
||||||
|
}, 1);
|
||||||
}
|
}
|
||||||
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||||
Player p = event.getPlayer();
|
Player p = event.getPlayer();
|
||||||
@ -60,6 +64,15 @@ public class SpectatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
if (!anySupervisorOnline(event.getPlayer())) {
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
player.kickPlayer("");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
ItemStack itemStack = event.getCurrentItem();
|
ItemStack itemStack = event.getCurrentItem();
|
||||||
@ -82,15 +95,6 @@ public class SpectatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
|
||||||
if (!anySupervisorOnline(event.getPlayer())) {
|
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
|
||||||
player.kickPlayer("");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||||
if (event.getMessage().startsWith("/schem save") || event.getMessage().startsWith("//schem save") || event.getMessage().startsWith("/schematic save") || event.getMessage().startsWith("//schematic save")) {
|
if (event.getMessage().startsWith("/schem save") || event.getMessage().startsWith("//schem save") || event.getMessage().startsWith("/schematic save") || event.getMessage().startsWith("//schematic save")) {
|
||||||
@ -138,7 +142,21 @@ public class SpectatorListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPlayerBucket(PlayerBucketEvent event) {
|
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
|
||||||
|
if (Permission.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerBucketEntity(PlayerBucketEntityEvent event) {
|
||||||
|
if (Permission.SPECTATOR.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.SPECTATOR.hasPermission(event.getPlayer())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
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.