SteamWar/BauSystem2.0
Archiviert
12
0

Fix Permission
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-12-16 16:52:59 +01:00
Ursprung 3dddb48d0c
Commit 78f7e42629
5 geänderte Dateien mit 58 neuen und 45 gelöschten Zeilen

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bausystem;
import de.steamwar.bausystem.config.BauServer;
import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser;
import lombok.AllArgsConstructor;
import org.bukkit.entity.Player;
@ -29,11 +30,9 @@ import java.util.function.Predicate;
@AllArgsConstructor
public enum Permission {
OWNER(bauweltMember -> {
return bauweltMember.getBauweltID() == BauServer.getInstance().getOwnerID();
}),
OWNER(bauweltMember -> false),
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 -> {
return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember);
@ -47,9 +46,17 @@ public enum Permission {
private final Predicate<BauweltMember> permissionPredicate;
public boolean hasPermission(BauweltMember bauweltMember) {
if (bauweltMember == null) return false;
return permissionPredicate.test(bauweltMember);
}
public boolean hasPermission(Player member) {
if (SteamwarUser.get(member.getUniqueId()).getId() == BauServer.getInstance().getOwnerID()) {
return this != SPECTATOR;
}
BauweltMember bauweltMember = BauweltMember.getBauMember(BauServer.getInstance().getOwner(), member.getUniqueId());
if (bauweltMember == null) return this != SPECTATOR;
if (bauweltMember == null) return false;
return permissionPredicate.test(bauweltMember);
}
}

Datei anzeigen

@ -1,6 +1,7 @@
package de.steamwar.bausystem.features.bau;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.config.BauServer;
import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.flags.Flag;
@ -24,12 +25,7 @@ public class InfoCommand extends SWCommand {
super("bauinfo");
}
@Register(help = true)
public void genericHelp(Player p, String... args) {
BauSystem.MESSAGE.send("BAU_INFO_COMMAND_HELP", p);
}
@Register
@Register(description = "BAU_INFO_COMMAND_HELP")
public void genericCommand(Player p) {
sendBauInfo(p);
}
@ -52,11 +48,16 @@ public class InfoCommand extends SWCommand {
membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size()));
for (BauweltMember member : members) {
membermessage.append(BauSystem.MESSAGE.parse("BAU_INFO_MEMBER_INFO", p,
SteamwarUser.get(member.getMemberID()).getUserName(),
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 (!membermessage.isEmpty()) {
membermessage.append(", ");
}
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());

Datei anzeigen

@ -48,6 +48,6 @@ public class CountingwandGuiItem extends BauGuiItem {
@Override
public Permission permission() {
return Permission.WORLDEDIT;
return Permission.MEMBER;
}
}

Datei anzeigen

@ -108,26 +108,13 @@ public class BauGUI {
if (!permission.hasPermission(p)) {
List<String> lore = meta.getLore();
if (lore == null) {
lore = Collections.singletonList(BauSystem.MESSAGE.parse(permissionString(permission), p));
lore = Collections.singletonList(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
} else {
lore.add(BauSystem.MESSAGE.parse(permissionString(permission), p));
lore.add(BauSystem.MESSAGE.parse("NO_PERMISSION", p));
}
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
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";
}
}
}

Datei anzeigen

@ -19,11 +19,10 @@
package de.steamwar.bausystem.features.world;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.utils.NMSWrapper;
import de.steamwar.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -45,8 +44,13 @@ public class SpectatorListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
if (Permission.SUPERVISOR.hasPermission(event.getPlayer())) {
return;
}
if (!anySupervisorOnline(null)) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
event.getPlayer().kickPlayer("");
}, 1);
}
if (Permission.SPECTATOR.hasPermission(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)
public void onInventoryClick(InventoryClickEvent event) {
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)
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")) {
@ -138,7 +142,21 @@ public class SpectatorListener implements Listener {
}
@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())) {
event.setCancelled(true);
}