Git is weird and didnt let me commit lol

This commit is contained in:
TopchetoEU 2022-01-17 12:03:54 +02:00
parent a0ab822476
commit 0514b53270
24 changed files with 293 additions and 382 deletions

BIN
deps/bukkit.jar vendored

Binary file not shown.

19
pom.xml
View File

@ -22,21 +22,18 @@
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>spigot</groupId>
<artifactId>api</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/deps/bukkit.jar</systemPath>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>spigot</groupId>

View File

@ -11,7 +11,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import me.topchetoeu.bedwars.commandUtility.Command;
import me.topchetoeu.bedwars.commands.Command;
import me.topchetoeu.bedwars.engine.BedwarsPlayer;
import me.topchetoeu.bedwars.engine.Config;
import me.topchetoeu.bedwars.engine.Game;

View File

@ -17,8 +17,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import me.topchetoeu.bedwars.commandUtility.Command;
import me.topchetoeu.bedwars.commandUtility.CommandExecutors;
import me.topchetoeu.bedwars.commands.Command;
import me.topchetoeu.bedwars.commands.CommandExecutors;
import me.topchetoeu.bedwars.engine.AttackCooldownEradicator;
import me.topchetoeu.bedwars.engine.Config;
import me.topchetoeu.bedwars.engine.Game;
@ -38,8 +38,6 @@ import me.topchetoeu.bedwars.engine.trader.upgrades.ProtectionTeamUpgrade;
import me.topchetoeu.bedwars.engine.trader.upgrades.SharpnessTeamUpgrade;
import me.topchetoeu.bedwars.messaging.MessageUtility;
// TODO add permissions
public class Main extends JavaPlugin implements Listener {
@ -145,12 +143,12 @@ public class Main extends JavaPlugin implements Listener {
if (!conf.exists())
conf.createNewFile();
Config.load(conf);
File defaultFavs = new File(getDataFolder(), "default-favourites.yml");
File defaultFavourites = new File(getDataFolder(), "default-favourites.yml");
MessageUtility.load(new File(getDataFolder(), "messages.yml"));
if (!defaultFavs.exists())
defaultFavs.createNewFile();
if (!defaultFavourites.exists())
defaultFavourites.createNewFile();
File favsDir = new File(getDataFolder(), "favourites");
@ -177,7 +175,7 @@ public class Main extends JavaPlugin implements Listener {
EnforcedRankedDealType.init();
RankedUpgradeDealType.init();
Sections.init(new File(getDataFolder(), "sections.yml"));
Favourites.instance = new Favourites(favsDir, defaultFavs);
Favourites.instance = new Favourites(favsDir, defaultFavourites);
updateTimer();
@ -185,33 +183,34 @@ public class Main extends JavaPlugin implements Listener {
v.setAI(false);
});
Command cmd = Command.createLiteral("bedwars", "bw");
Command cmd = Command.createLiteral("bedwars", "bw").permission("bedwars");
cmd.literal("help").setExecutor(CommandExecutors.help()).string("args", false).setRecursive(true).setExecutor(CommandExecutors.help());
Commands.start(cmd.literal("start"));
Commands.stop(cmd.literal("stop"));
cmd.literal("help").permission("bedwars.help").setExecutor(CommandExecutors.help()).string("args", false).setRecursive(true).setExecutor(CommandExecutors.help());
Commands.start(cmd.literal("start")).permission("bedwars.control.start");
Commands.stop(cmd.literal("stop")).permission("bedwars.control.stop");
Commands.kill(cmd.literal("kill"));
Commands.revive(cmd.literal("revive"));
Commands.kill(cmd.literal("kill")).permission("bedwars.cheat.kill");
Commands.revive(cmd.literal("revive")).permission("bedwars.cheat.revive");
Command config = cmd.literal("configuration", "config", "conf");
Command base = config.literal("base");
Command generator = config.literal("generator", "gen");
Command config = cmd.literal("configuration", "config", "conf").permission("bedwars.conf");
Command base = config.literal("base").permission("bedwars.conf.bases");
Command generator = config.literal("generator", "gen").permission("bedwars.conf.generators");
Commands.baseAdd(base.literal("add"));
Commands.baseRemove(base.literal("remove"));
Commands.baseSetSpawn(base.literal("setspawn", "spawn"));
Commands.baseSetGenerator(base.literal("setgenerator", "generator", "gen"));
Commands.baseSetBed(base.literal("setbed", "bed"));
Commands.baseList(base.literal("list", "l"));
Commands.baseAdd(base.literal("add")).permission("bedwars.config.bases.add");
Commands.baseRemove(base.literal("remove")).permission("bedwars.config.bases.remove");
Commands.baseSetSpawn(base.literal("setspawn", "spawn")).permission("bedwars.config.bases.setspawn");
Commands.baseSetGenerator(base.literal("setgenerator", "generator", "gen")).permission("bedwars.config.bases.setgenerator");
Commands.baseSetBed(base.literal("setbed", "bed")).permission("bedwars.config.bases.setbed");
Commands.baseList(base.literal("list", "l")).permission("bedwars.config.bases.list");
Commands.createDiamondGen(generator.literal("diamond"));
Commands.createEmeraldGen(generator.literal("emerald", "em"));
Commands.clearGens(generator.literal("clear"));
Commands.createDiamondGen(generator.literal("diamond")).permission("bedwars.config.generators.diamond");
Commands.createEmeraldGen(generator.literal("emerald", "em")).permission("bedwars.config.generators.emerald");
Commands.clearGens(generator.literal("clear")).permission("bedwars.config.generators.clear");
Commands.breakBed(cmd.literal("breakbed", "cheat", "bedishonest", "abusepowers"));
Commands.breakBed(cmd.literal("breakbed", "cheat", "bedishonest", "abusepowers")).permission("bedwars.config.cheat.breakbed");
cmd.literal("villagertools", "villagers", "traders")
.setHelpMessage("Gives you tools to manage traders")
.permission("bedwars.villagertools")
.setExecutor((sender, _cmd, args) -> {
if (sender instanceof Player) {
Player p = (Player)sender;
@ -225,10 +224,10 @@ public class Main extends JavaPlugin implements Listener {
// .attachCommand(new Command("respawn", "revive")
// .setExecutor(Commands.revive)
// .setHelpMessage("Respawns a spectator, if he has a bed, he is immediatly respawned"))
// .setHelpMessage("Respawns a spectator, if he has a bed, he is immediately respawned"))
// .attachCommand(new Command("breakbed", "eliminateteam")
// .setExecutor(Commands.breakBed)
// .setHelpMessage("Destoys the bed of a team")
// .setHelpMessage("Destroys the bed of a team")
// )
// .attachCommand(new Command("eliminate")
// .setHelpMessage("Eliminates a player")

View File

@ -1,323 +0,0 @@
package me.topchetoeu.bedwars.commandUtility;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import me.topchetoeu.bedwars.commandUtility.args.ArgParser;
import me.topchetoeu.bedwars.commandUtility.args.ArgParserRes;
import me.topchetoeu.bedwars.commandUtility.args.CollectionArgParser;
import me.topchetoeu.bedwars.commandUtility.args.CollectionProvider;
import me.topchetoeu.bedwars.commandUtility.args.EnumArgParser;
import me.topchetoeu.bedwars.commandUtility.args.IntArgParser;
import me.topchetoeu.bedwars.commandUtility.args.LiteralArgParser;
import me.topchetoeu.bedwars.commandUtility.args.LocationArgParser;
import me.topchetoeu.bedwars.commandUtility.args.PlayerArgParser;
import me.topchetoeu.bedwars.commandUtility.args.StringArgParser;
import me.topchetoeu.bedwars.commandUtility.args.Suggestions;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
public class Command {
private String name;
private String helpMessage;
private CommandExecutor executor;
private HashSet<Command> children = new HashSet<>();
private ArgParser parser;
private boolean recursive = false;
private Set<JavaPlugin> parents = new HashSet<>();
public String getName() {
return name;
}
public boolean attachedToAnyPlugin() {
return parents.size() > 0;
}
public Set<JavaPlugin> getParentPlugins() {
return Collections.unmodifiableSet(parents);
}
public ArgParser getParser() {
return parser;
}
public String getHelpMessage() {
return helpMessage;
}
public Command setHelpMessage(String val) {
helpMessage = val;
return this;
}
public CommandExecutor getExecutor() {
return executor;
}
public Command setExecutor(CommandExecutor val) {
executor = val;
return this;
}
public Command addChild(Command cmd) {
if (cmd == null) throw new RuntimeException("cmd is null");
children.add(cmd);
return cmd;
}
public Command removeChild(Command cmd) {
if (cmd == null) throw new RuntimeException("cmd is null");
children.remove(cmd);
return this;
}
public boolean hasChild(Command cmd) {
if (cmd == null) return false;
return children.contains(cmd);
}
public Set<Command> getChildren() {
return Collections.unmodifiableSet(children);
}
public Command setRecursive(boolean val) {
recursive = val;
return this;
}
public boolean isRecursive() {
return recursive;
}
@SuppressWarnings("unchecked")
public void execute(CommandSender sender, String[] _args) {
Command toExecute = this;
Hashtable<String, Object> newArgs = new Hashtable<>();
List<String> args = new ArrayList<>();
Collections.addAll(args, _args);
String err = null;
while (args.size() > 0) {
Command newCmd = null;
Set<Command> children = toExecute.getChildren();
if (toExecute.isRecursive()) children = Collections.singleton(toExecute);
for (Command cmd : children) {
ArgParser parser = cmd.getParser();
ArgParserRes res = parser.parse(sender, args);
if (res.hasError()) err = res.getError();
else if (res.hasSucceeded()) {
for (int i = 0; i < res.getTakenCount(); i++) {
if (args.size() == 0) break;
args.remove(0);
}
if (res.hasResult()) {
if (cmd.recursive) {
if (!newArgs.containsKey(cmd.name)) newArgs.put(cmd.name, new ArrayList<>());
((List<Object>)newArgs.get(cmd.name)).add(res.getResult());
}
else newArgs.put(cmd.name, res.getResult());
}
newCmd = cmd;
break;
}
}
if (newCmd == null) {
toExecute = null;
break;
}
toExecute = newCmd;
}
if (toExecute == null) err = "Invalid command syntax.";
else if (toExecute.getExecutor() == null) err = "Incomplete command.";
if (err != null) sender.spigot().sendMessage(new ComponentBuilder()
.append("Error: ")
.color(ChatColor.DARK_RED)
.append(err)
.color(ChatColor.RED)
.create()
);
else {
if (toExecute.isRecursive() && !newArgs.containsKey(toExecute.name)) newArgs.put(toExecute.name, new ArrayList<>());
BaseComponent[] _err = toExecute.getExecutor().execute(sender, this, newArgs);
if (_err != null && _err.length > 0) sender.spigot().sendMessage(new ComponentBuilder()
.append("Error: ")
.color(ChatColor.DARK_RED)
.append(err)
.reset()
.create()
);
}
}
public List<String> tabComplete(CommandSender sender, String[] _args) {
Command toComplete = this;
List<String> args = new ArrayList<>();
Collections.addAll(args, _args);
int index = 1;
while (args.size() > 0) {
boolean found = false;
index++;
for (Command cmd : toComplete.children) {
ArgParser parser = cmd.getParser();
ArgParserRes res = parser.parse(sender, args);
if (res.hasSucceeded()) {
for (int i = 0; i < res.getTakenCount(); i++) {
if (args.size() == 0) break;
args.remove(0);
}
toComplete = cmd;
found = true;
break;
}
}
if (!found) break;
}
if (args.size() == 0) return null;
Suggestions suggestions = new Suggestions();
for (Command cmd : toComplete.children) {
cmd.getParser().addCompleteSuggestions(sender, args, suggestions);
}
if (suggestions.hasError() && !suggestions.getSuggestions().contains(args.get(0))) {
sender.spigot().sendMessage(new ComponentBuilder()
.append("Error (argument %d): ".formatted(index + 1))
.color(ChatColor.DARK_RED)
.append(suggestions.getError())
.color(ChatColor.RED)
.create()
);
return null;
}
else {
List<String> _suggestions = new ArrayList<>(suggestions.getSuggestions());
return _suggestions;
}
}
public Command register(JavaPlugin pl) {
if (!(parser instanceof LiteralArgParser))
throw new IllegalArgumentException("Only a command with a literal parser may be registered.");
if (parents.contains(pl)) throw new IllegalArgumentException("The command is already attached to the given plugin");
if (pl == null) throw new RuntimeException("pl is null");
parents.add(pl);
LiteralArgParser parser = (LiteralArgParser)this.parser;
String name = parser.getLiteral();
pl.getCommand(name).setAliases(parser.getAliases());
pl.getCommand(name).setExecutor((sender, cmd, alias, args) -> {
execute(sender, args);
return true;
});
pl.getCommand(name).setTabCompleter((sender, cmd, alias, args) -> {
return tabComplete(sender, args);
});
return this;
}
public Command(String name, ArgParser parser) {
this.name = name;
this.parser = parser;
}
public Command literal(String name) {
Command cmd = createLiteral(name);
addChild(cmd);
return cmd;
}
public Command literal(String name, String ...aliases) {
Command cmd = createLiteral(name, aliases);
addChild(cmd);
return cmd;
}
public Command location(String name) {
Command cmd = createLocation(name);
addChild(cmd);
return cmd;
}
public Command _enum(String name, Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
Command cmd = createEnum(name, enumType, caseInsensitive);
addChild(cmd);
return cmd;
}
public Command player(String name, boolean caseInsensitive) {
Command cmd = createPlayer(name, caseInsensitive);
addChild(cmd);
return cmd;
}
public Command string(String name, boolean greedy) {
Command cmd = createString(name, greedy);
addChild(cmd);
return cmd;
}
public Command _int(String name) {
Command cmd = createInt(name);
addChild(cmd);
return cmd;
}
public Command collection(String name, SimpleCollectionQuery query, boolean caseInsensitive) {
Command cmd = createCollection(name, query, caseInsensitive);
addChild(cmd);
return cmd;
}
public Command collection(String name, CollectionProvider provider, boolean caseInsensitive) {
Command cmd = createCollection(name, provider, caseInsensitive);
addChild(cmd);
return cmd;
}
public static Command createCollection(String name, SimpleCollectionQuery query, boolean caseInsensitive) {
return new Command(name, new CollectionArgParser(
() -> query.get().stream().collect(Collectors.toMap(v->v, v->v)),
caseInsensitive)
);
}
public static Command createCollection(String name, CollectionProvider provider, boolean caseInsensitive) {
return new Command(name, new CollectionArgParser(provider, caseInsensitive));
}
public static Command createPlayer(String name, boolean caseInsensitive) {
return new Command(name, new PlayerArgParser(caseInsensitive));
}
public static Command createEnum(String name, Class<? extends Enum<?>> enumType, boolean caseInsensitive) {
return new Command(name, new EnumArgParser(enumType, caseInsensitive));
}
public static Command createString(String name, boolean greedy) {
return new Command(name, new StringArgParser(greedy));
}
public static Command createInt(String name) {
return new Command(name, new IntArgParser());
}
public static Command createLocation(String name) {
return new Command(name, new LocationArgParser());
}
public static Command createLiteral(String lit) {
return new Command(lit, new LiteralArgParser(lit));
}
public static Command createLiteral(String lit, String ...aliases) {
return new Command(lit, new LiteralArgParser(lit, aliases));
}
public interface SimpleCollectionQuery {
Collection<String> get();
}
}

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility;
package me.topchetoeu.bedwars.commands;
import java.util.Map;

View File

@ -1,10 +1,9 @@
package me.topchetoeu.bedwars.commandUtility;
package me.topchetoeu.bedwars.commands;
import java.util.ArrayList;
import java.util.List;
import me.topchetoeu.bedwars.commandUtility.args.LiteralArgParser;
import me.topchetoeu.bedwars.commands.args.LiteralArgParser;
import net.md_5.bungee.api.chat.ComponentBuilder;
public class CommandExecutors {

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.List;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
public class ArgParserRes {
private int takenCount;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.List;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.Hashtable;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.List;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.List;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.stream.Collectors;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.Collections;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.List;

View File

@ -1,4 +1,4 @@
package me.topchetoeu.bedwars.commandUtility.args;
package me.topchetoeu.bedwars.commands.args;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -17,7 +17,7 @@ public class HoverLabel {
private Location loc;
private ArmorStand generateArmorStand(Location loc, BaseComponent[] name) {
if (name == null || name.equals("")) return null;
if (name == null || name.length == 0) return null;
ArmorStand as = (ArmorStand)loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
as.setGravity(false);
@ -59,7 +59,7 @@ public class HoverLabel {
for (int i = 0; i < n; i++) {
BaseComponent[] line = data.get(i);
if (line == null || line.equals("")) {
if (line == null || line.length == 0) {
if (armorStands.get(i) != null) armorStands.get(i).remove();
armorStands.set(i, null);
}

View File

@ -0,0 +1,78 @@
package me.topchetoeu.bedwars.permissions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class PermissionSegmentWildcard {
private String prefix;
private List<String> remaining;
public String getPrefix() {
return prefix;
}
public List<String> getRemainingSegments() {
return Collections.unmodifiableList(remaining);
}
public boolean isWildcard() {
return remaining != null;
}
public String toString() {
if (isWildcard()) return prefix + "*" + String.join("*", remaining);
else return prefix;
}
public boolean check(String segment) {
if (isWildcard()) {
for (int i = remaining.size() - 1; i >= 0; i--) {
String curr = remaining.get(i);
int index = segment.lastIndexOf(curr);
if (index == -1) return false;
segment = segment.substring(0, index);
}
return !segment.startsWith(prefix);
}
else return segment.equals(prefix);
}
public PermissionSegmentWildcard(String node, boolean isPrefix) {
this.prefix = node;
if (isPrefix) remaining = Collections.emptyList();
}
public PermissionSegmentWildcard(String prefix, String suffix) {
this.prefix = prefix;
this.remaining = Collections.singletonList(suffix);
}
public PermissionSegmentWildcard(String prefix, String ...remaining) {
this.prefix = prefix;
this.remaining = Arrays.asList(remaining);
}
public PermissionSegmentWildcard(String prefix, Collection<String> remaining) {
this.prefix = prefix;
this.remaining = new ArrayList<>(remaining);
}
public static PermissionSegmentWildcard parse(String str) {
if (str.contains("**")) throw new RuntimeException("Recursive wildcards not allowed.");
String[] segments = str.split("\\*");
if (segments.length == 0) return new PermissionSegmentWildcard("", true);
else if (segments.length == 1) return new PermissionSegmentWildcard(segments[0], false);
else {
List<String> remaining = new ArrayList<>();
Collections.addAll(remaining, segments);
remaining.remove(0);
if (remaining.size() == 0) return new PermissionSegmentWildcard(segments[0], true);
if (remaining.get(remaining.size() - 1).isEmpty())
remaining.remove(remaining.size() - 1);
return new PermissionSegmentWildcard(segments[0], remaining);
}
}
}

View File

@ -0,0 +1,84 @@
package me.topchetoeu.bedwars.permissions;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class PermissionWildcard {
private List<PermissionSegmentWildcard> prefix;
private List<PermissionSegmentWildcard> suffix;
public boolean hasRecursiveWildcard() {
return suffix != null;
}
public PermissionWildcard(boolean isPrefix, Collection<PermissionSegmentWildcard> segments) {
this.prefix = new ArrayList<>(segments);
if (isPrefix) suffix = Collections.emptyList();
}
public PermissionWildcard(boolean isPrefix, PermissionSegmentWildcard ...segments) {
this.prefix = Arrays.asList(segments);
if (isPrefix) suffix = Collections.emptyList();
}
public PermissionWildcard(Collection<PermissionSegmentWildcard> prefix, Collection<PermissionSegmentWildcard> suffix) {
this.prefix = new ArrayList<>(prefix);
this.suffix = new ArrayList<>(suffix);
}
public boolean check(String perm) {
String[] segments = perm.split(".");
if (segments.length < prefix.size()) return false;
if (suffix != null && segments.length < suffix.size()) return false;
int i = 0;
for (; i < prefix.size(); i++) {
if (!prefix.get(i).check(segments[i])) return false;
}
if (hasRecursiveWildcard()) {
int j = 0;
for (i = suffix.size(), j = segments.length; i >= 0; i--, j--) {
if (!prefix.get(i).check(segments[j])) return false;
}
return true;
}
else return i == prefix.size();
}
public String toString() {
String res = String.join(".", prefix.toArray(String[]::new));
if (hasRecursiveWildcard()) {
res += ".**";
if (suffix != null) res += "." + String.join(".", suffix.toArray(String[]::new));
}
return res;
}
public static PermissionWildcard parse(String raw) {
String[] segments = raw.split("\\.");
ArrayList<PermissionSegmentWildcard> prefix = new ArrayList<>();
ArrayList<PermissionSegmentWildcard> suffix = null;
ArrayList<PermissionSegmentWildcard> currList = prefix;
for (String segment : segments) {
if (segment.isEmpty()) throw new RuntimeException("Empty permission segments are not allowed.");
if (segment.equals("**")) {
if (suffix == null) {
currList = suffix = new ArrayList<>();
}
else throw new RuntimeException("Multiple recursive wildcards are not allowed.");
}
else if (segment.contains("**")) throw new RuntimeException("Wildcards must be the only thing in a segment.");
else currList.add(PermissionSegmentWildcard.parse(segment));
}
if (suffix == null) return new PermissionWildcard(false, prefix);
else return new PermissionWildcard(prefix, suffix);
}
}

View File

@ -0,0 +1,32 @@
package me.topchetoeu.bedwars.permissions;
import java.util.Hashtable;
import org.bukkit.permissions.Permissible;
public class Permissions {
private static final Hashtable<String, PermissionWildcard> cache = new Hashtable<>();
private Permissions() {
}
public static void reset() {
cache.clear();
}
public static final PermissionWildcard getCachedOrParse(String rawWildcard) {
cache.clear();
return cache.containsKey(rawWildcard) ? cache.get(rawWildcard) : PermissionWildcard.parse(rawWildcard);
}
public static boolean hasPermission(Permissible permissible, String permission) {
if (permission == null || permission.isEmpty()) return true;
if (permissible == null) return false;
if (permissible.isOp()) return true;
if (permissible.hasPermission(permission)) return true;
return permissible.getEffectivePermissions().stream().anyMatch(v -> {
return getCachedOrParse(v.getPermission()).check(permission);
});
}
}

View File

@ -8,3 +8,48 @@ commands:
bedwars:
description: A command used to control the bedwars plugin
aliases: [ bw, bedwar ]
permissions:
bedwars:
description: Gives access to all bedwars-related commands
children:
bedwars.config: yes
bedwars.cheat: yes
bedwars.control: yes
bedwars.villagertools: yes
bedwars.config:
description: Gives access to all bedwars configuration commands
children:
bedwars.config.bases: yes
bedwars.config.generators: yes
bedwars.config.bases:
description: Gives access to all base-related commands
children:
bedwars.config.bases.add: yes
bedwars.config.bases.remove: yes
bedwars.config.bases.setspawn: yes
bedwars.config.bases.setgenerator: yes
bedwars.config.bases.setbed: yes
bedwars.config.bases.add:
description: Gives access to base add command
bedwars.config.bases.remove:
description: Gives access to base remove command
bedwars.config.bases.setspawn:
description: Gives access to base set spawn command
bedwars.config.bases.setgenerator:
description: Gives access to base set generator command
bedwars.config.bases.setbed:
description: Gives access to base set bed command
bedwars.cheat:
description: Gives access to all features that allow cheating (like killing, eliminating or breaking other's beds)
children:
bedwars.cheat.kill: yes
bedwars.cheat.revive: yes
bedwars.cheat.breakbed: yes
bedwars.cheat.kill:
description: Gives access to the command /bw kill [player]
bedwars.cheat.revive:
description: Gives access to the command /bw revive [player]
bedwars.cheat.breakbed:
description: Gives access to the command /bw breakbed [team]
bedwars.villagertools:
description: Gives access to the command /bw villagertools