Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
8b97ea0383
Commit
6e56ecdc99
@ -20,12 +20,17 @@
|
|||||||
package de.steamwar.bausystem;
|
package de.steamwar.bausystem;
|
||||||
|
|
||||||
import de.steamwar.bausystem.config.BauServer;
|
import de.steamwar.bausystem.config.BauServer;
|
||||||
|
import de.steamwar.command.CommandMetaData;
|
||||||
|
import de.steamwar.command.TypeValidator;
|
||||||
import de.steamwar.sql.BauweltMember;
|
import de.steamwar.sql.BauweltMember;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -54,4 +59,33 @@ public enum Permission {
|
|||||||
public static boolean hasPermission(Player member, Permission permission) {
|
public static boolean hasPermission(Player member, Permission permission) {
|
||||||
return permission.hasPermission(member);
|
return permission.hasPermission(member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.PARAMETER)
|
||||||
|
@CommandMetaData.Parameter({Player.class})
|
||||||
|
@CommandMetaData.ImplicitValidator(handler = Perm.Handler.class, order = -10)
|
||||||
|
public @interface Perm {
|
||||||
|
Permission value();
|
||||||
|
String message() default "";
|
||||||
|
|
||||||
|
class Handler implements TypeValidator<Player> {
|
||||||
|
|
||||||
|
private Permission permission;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public Handler(Perm perm) {
|
||||||
|
this.permission = perm.value();
|
||||||
|
this.message = perm.message();
|
||||||
|
if (message != null && message.isEmpty()) message = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean validate(CommandSender commandSender, Player player, MessageSender messageSender) {
|
||||||
|
if (message == null) {
|
||||||
|
return permission.hasPermission(player);
|
||||||
|
}
|
||||||
|
return !messageSender.send(!permission.hasPermission((Player) commandSender), message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren