SteamWar/BauSystem2.0
Archiviert
12
0

Remove last guard checks
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-08-18 20:27:05 +02:00
Ursprung 028c115731
Commit b722d9ab0f
12 geänderte Dateien mit 88 neuen und 166 gelöschten Zeilen

Datei anzeigen

@ -1204,6 +1204,7 @@ SELECT_NO_EXTENSION = §cThis region has no extension
SELECT_MESSAGE = §7WorldEdit selection set to {0}, {1}, {2} and {3}, {4}, {5} SELECT_MESSAGE = §7WorldEdit selection set to {0}, {1}, {2} and {3}, {4}, {5}
SKULL_HELP = §8/§eskull §8[§eplayer§8] §8-§7 Receive a player head SKULL_HELP = §8/§eskull §8[§eplayer§8] §8-§7 Receive a player head
SKULL_INVALID = §cInvalid player name
SKULL_ITEM = §e{0}§8s Head SKULL_ITEM = §e{0}§8s Head
SPEED_HELP = §8/§espeed §8[§71§8-§710§8|§edefault§8] §8-§7 Set your flight and walking speed. SPEED_HELP = §8/§espeed §8[§71§8-§710§8|§edefault§8] §8-§7 Set your flight and walking speed.

Datei anzeigen

@ -1184,6 +1184,7 @@ SELECT_NO_EXTENSION = §cDiese Region hat keine Ausfahrmaße
SELECT_MESSAGE = §7WorldEdit auswahl auf {0}, {1}, {2} und {3}, {4}, {5} gesetzt SELECT_MESSAGE = §7WorldEdit auswahl auf {0}, {1}, {2} und {3}, {4}, {5} gesetzt
SKULL_HELP = §8/§eskull §8[§eSpieler§8] §8-§7 Gibt einen SpielerKopf SKULL_HELP = §8/§eskull §8[§eSpieler§8] §8-§7 Gibt einen SpielerKopf
SKULL_INVALID = §cUngültiger Spieler
SKULL_ITEM = §e{0}§8s Kopf SKULL_ITEM = §e{0}§8s Kopf
SPEED_HELP = §8/§espeed §8[§71§8-§710§8|§edefault§8] §8-§7 Setzte deine Flug- und Laufgeschindigkeit. SPEED_HELP = §8/§espeed §8[§71§8-§710§8|§edefault§8] §8-§7 Setzte deine Flug- und Laufgeschindigkeit.

Datei anzeigen

@ -26,7 +26,9 @@ import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.ItemUtils;
import de.steamwar.command.*; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -41,13 +43,13 @@ public class SimulatorCommand extends SWCommand {
} }
@Register(description = "SIMULATOR_HELP") @Register(description = "SIMULATOR_HELP")
public void genericCommand(@Guard Player p) { public void genericCommand(@Validator Player p) {
SimulatorCursor.hide(p, null); SimulatorCursor.hide(p, null);
SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p)); SWUtils.giveItemToPlayer(p, SimulatorStorage.getWand(p));
} }
@Register(value = "change", description = "SIMULATOR_CHANGE_HELP") @Register(value = "change", description = "SIMULATOR_CHANGE_HELP")
public void change(@Guard Player p) { public void change(@Validator Player p) {
ItemStack itemStack = p.getInventory().getItemInMainHand(); ItemStack itemStack = p.getInventory().getItemInMainHand();
if (!ItemUtils.isItem(itemStack, "simulator")) { if (!ItemUtils.isItem(itemStack, "simulator")) {
BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p); BauSystem.MESSAGE.send("SIMULATOR_NO_SIM_IN_HAND", p);
@ -57,7 +59,7 @@ public class SimulatorCommand extends SWCommand {
} }
@Register(value = "create", description = "SIMULATOR_CREATE_HELP") @Register(value = "create", description = "SIMULATOR_CREATE_HELP")
public void create(@Guard Player p, String name) { public void create(@Validator Player p, String name) {
createSimulator(p, name); createSimulator(p, name);
} }
@ -76,7 +78,7 @@ public class SimulatorCommand extends SWCommand {
} }
@Register(value = "delete", description = "SIMULATOR_DELETE_HELP") @Register(value = "delete", description = "SIMULATOR_DELETE_HELP")
public void delete(@Guard Player p, @Mapper("simulators") String name) { public void delete(@Validator Player p, @Mapper("simulators") String name) {
if (!SimulatorStorage.getSimulatorNames().contains(name)) { if (!SimulatorStorage.getSimulatorNames().contains(name)) {
BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p);
return; return;
@ -86,7 +88,7 @@ public class SimulatorCommand extends SWCommand {
} }
@Register(value = "start", description = "SIMULATOR_START_HELP") @Register(value = "start", description = "SIMULATOR_START_HELP")
public void start(@Guard Player p, @Mapper("simulators") String name) { public void start(@Validator Player p, @Mapper("simulators") String name) {
TNTSimulator tntSimulator = SimulatorStorage.getSimulator(name); TNTSimulator tntSimulator = SimulatorStorage.getSimulator(name);
if (tntSimulator == null) { if (tntSimulator == null) {
BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p); BauSystem.MESSAGE.send("SIMULATOR_NOT_EXISTS", p);
@ -114,17 +116,10 @@ public class SimulatorCommand extends SWCommand {
}; };
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker guardChecker() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "SIMULATOR_NO_PERMS");
if (Permission.hasPermission(player, Permission.WORLD)) {
return GuardResult.ALLOWED;
}
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
}
return GuardResult.DENIED;
}; };
} }
} }

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -39,19 +40,8 @@ public class LaufbauCommand extends SWCommand {
super("laufbau", "laufsklave"); super("laufbau", "laufsklave");
} }
private boolean permissionCheck(Player player, Permission permission) {
if (Permission.hasPermission(player, permission)) {
return true;
}
BauSystem.MESSAGE.send("LAUFBAU_NO_PERM", player);
return false;
}
@Register(description = {"LAUFBAU_HELP", "LAUFBAU_PREPARE1", "LAUFBAU_PREPARE2"}) @Register(description = {"LAUFBAU_HELP", "LAUFBAU_PREPARE1", "LAUFBAU_PREPARE2"})
public void laufbauSelection(Player player, @StaticValue(value = {"smallest", "blastresistant"}, allowISE = true) boolean preferingBlastResistance) { public void laufbauSelection(@Validator Player player, @StaticValue(value = {"smallest", "blastresistant"}, allowISE = true) boolean preferingBlastResistance) {
if (!permissionCheck(player, Permission.WORLDEDIT)) {
return;
}
Pair<Location, Location> selection = WorldEditUtils.getSelection(player); Pair<Location, Location> selection = WorldEditUtils.getSelection(player);
if (selection == null) { if (selection == null) {
BauSystem.MESSAGE.send("LAUFBAU_NO_WORLDEDIT", player); BauSystem.MESSAGE.send("LAUFBAU_NO_WORLDEDIT", player);
@ -84,10 +74,14 @@ public class LaufbauCommand extends SWCommand {
} }
@Register(value = "settings", description = "LAUFBAU_HELP_SETTINGS") @Register(value = "settings", description = "LAUFBAU_HELP_SETTINGS")
public void laufbauSettings(Player player) { public void laufbauSettings(@Validator Player player) {
if (!permissionCheck(player, Permission.WORLDEDIT)) {
return;
}
new LaufbauSettings(player); new LaufbauSettings(player);
} }
@ClassValidator(value = Player.class, local = true)
public TypeValidator<Player> validator() {
return (commandSender, player, messageSender) -> {
return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "LAUFBAU_NO_PERM");
};
}
} }

Datei anzeigen

@ -26,7 +26,9 @@ import de.steamwar.bausystem.features.slaves.WorldEditUtils;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.command.*; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -52,7 +54,7 @@ public class PanzernCommand extends SWCommand {
} }
@Register @Register
public void panzerSelection(@Guard Player player, @Mapper("block") Material blockMaterial, @Mapper("slab") Material slabMaterial) { public void panzerSelection(@Validator Player player, @Mapper("block") Material blockMaterial, @Mapper("slab") Material slabMaterial) {
Pair<Location, Location> selection = WorldEditUtils.getSelection(player); Pair<Location, Location> selection = WorldEditUtils.getSelection(player);
if (selection == null) { if (selection == null) {
BauSystem.MESSAGE.send("PANZERN_NO_WORLDEDIT", player); BauSystem.MESSAGE.send("PANZERN_NO_WORLDEDIT", player);
@ -88,17 +90,10 @@ public class PanzernCommand extends SWCommand {
}.runTaskTimer(BauSystem.getInstance(), 1, 1); }.runTaskTimer(BauSystem.getInstance(), 1, 1);
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker guardChecker() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "PANZERN_NO_PERM");
if (Permission.hasPermission(player, Permission.WORLDEDIT)) {
return GuardResult.ALLOWED;
}
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("PANZERN_NO_PERM", player);
}
return GuardResult.DENIED;
}; };
} }

Datei anzeigen

@ -34,7 +34,9 @@ import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.bausystem.shared.ShowMode;
import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.bausystem.utils.ListChatView;
import de.steamwar.command.*; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
@ -104,13 +106,13 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = {"gui"}, description = "TRACE_COMMAND_HELP_GUI") @Register(value = {"gui"}, description = "TRACE_COMMAND_HELP_GUI")
public void guiCommand(@Guard Player p) { public void guiCommand(@Validator Player p) {
TraceGui.openGui(p); TraceGui.openGui(p);
} }
@Register(value = {"record", "list"}) @Register(value = {"record", "list"})
@Register(value = {"list"}, description = "TRACE_COMMAND_HELP_LIST") @Register(value = {"list"}, description = "TRACE_COMMAND_HELP_LIST")
public void listCommand(@Guard Player player, @OptionalValue("0") int page) { public void listCommand(@Validator Player player, @OptionalValue("0") int page) {
ListChatView.chatView(player, StoredRecords.getRecords(), page, record -> { ListChatView.chatView(player, StoredRecords.getRecords(), page, record -> {
TextComponent component = new TextComponent(); TextComponent component = new TextComponent();
component.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT", player, record.size())); component.setText(BauSystem.MESSAGE.parse("TRACE_RECORD_LIST_ELEMENT", player, record.size()));
@ -133,13 +135,13 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = {"record", "delete"}, noTabComplete = true) @Register(value = {"record", "delete"}, noTabComplete = true)
public void recordDelete(@Guard Player p, int id) { public void recordDelete(@Validator Player p, int id) {
StoredRecords.remove(id); StoredRecords.remove(id);
BauSystem.MESSAGE.send("TRACE_RECORD_DELETE", p); BauSystem.MESSAGE.send("TRACE_RECORD_DELETE", p);
} }
@Register(value = "record", noTabComplete = true) @Register(value = "record", noTabComplete = true)
public void recordList(@Guard Player player, int recordID, @OptionalValue("0") int page) { public void recordList(@Validator Player player, int recordID, @OptionalValue("0") int page) {
Record traceRecord = StoredRecords.get(recordID); Record traceRecord = StoredRecords.get(recordID);
if (traceRecord == null) { if (traceRecord == null) {
BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player);
@ -167,7 +169,7 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = {"record", "tnt", "delete"}, noTabComplete = true) @Register(value = {"record", "tnt", "delete"}, noTabComplete = true)
public void deleteRecordTNT(@Guard Player player, int recordID, int tntID) { public void deleteRecordTNT(@Validator Player player, int recordID, int tntID) {
Record record = StoredRecords.get(recordID); Record record = StoredRecords.get(recordID);
if (record == null) { if (record == null) {
BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player);
@ -178,7 +180,7 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = "record", noTabComplete = true) @Register(value = "record", noTabComplete = true)
public void recordTNTPositions(@Guard Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @OptionalValue("0") int page) { public void recordTNTPositions(@Validator Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @OptionalValue("0") int page) {
Record record = StoredRecords.get(recordID); Record record = StoredRecords.get(recordID);
if (record == null) { if (record == null) {
BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player);
@ -205,7 +207,7 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = "record", noTabComplete = true) @Register(value = "record", noTabComplete = true)
public void recordTNTPositions(@Guard Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @StaticValue("fuse") String fuse, int fuseTicks) { public void recordTNTPositions(@Validator Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @StaticValue("fuse") String fuse, int fuseTicks) {
Record record = StoredRecords.get(recordID); Record record = StoredRecords.get(recordID);
if (record == null) { if (record == null) {
BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player); BauSystem.MESSAGE.send("TRACE_RECORD_NOT_FOUND", player);
@ -229,39 +231,39 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = {"start"}, description = "TRACE_COMMAND_HELP_START") @Register(value = {"start"}, description = "TRACE_COMMAND_HELP_START")
public void startCommand(@Guard Player p) { public void startCommand(@Validator Player p) {
RecordStateMachine.commandStart(); RecordStateMachine.commandStart();
BauSystem.MESSAGE.send("TRACE_MESSAGE_START", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_START", p);
} }
@Register(value = {"single"}, description = "TRACE_COMMAND_HELP_SINGLE") @Register(value = {"single"}, description = "TRACE_COMMAND_HELP_SINGLE")
public void singleCommand(@Guard Player p) { public void singleCommand(@Validator Player p) {
RecordStateMachine.commandSingle(); RecordStateMachine.commandSingle();
BauSystem.MESSAGE.send("TRACE_MESSAGE_SINGLE", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_SINGLE", p);
} }
@Register(value = {"stop"}, description = "TRACE_COMMAND_HELP_STOP") @Register(value = {"stop"}, description = "TRACE_COMMAND_HELP_STOP")
public void stopCommand(@Guard Player p) { public void stopCommand(@Validator Player p) {
RecordStateMachine.commandStop(); RecordStateMachine.commandStop();
BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", p);
} }
@Register(value = {"auto"}, description = "TRACE_COMMAND_HELP_AUTO") @Register(value = {"auto"}, description = "TRACE_COMMAND_HELP_AUTO")
@Register({"toggleauto"}) @Register({"toggleauto"})
public void autoCommand(@Guard Player p) { public void autoCommand(@Validator Player p) {
RecordStateMachine.commandAuto(); RecordStateMachine.commandAuto();
BauSystem.MESSAGE.send(RecordStateMachine.getRecordStatus().getAutoMessage(), p); BauSystem.MESSAGE.send(RecordStateMachine.getRecordStatus().getAutoMessage(), p);
} }
@Register(value = {"delete"}, description = "TRACE_COMMAND_HELP_DELETE") @Register(value = {"delete"}, description = "TRACE_COMMAND_HELP_DELETE")
@Register({"clear"}) @Register({"clear"})
public void deleteCommand(@Guard Player p) { public void deleteCommand(@Validator Player p) {
StoredRecords.clear(); StoredRecords.clear();
BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_DELETE", p);
} }
@Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW") @Register(value = {"show"}, description = "TRACE_COMMAND_HELP_SHOW")
public void showCommand(@Guard Player p, @OptionalValue("entity") ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) { public void showCommand(@Validator Player p, @OptionalValue("entity") ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) {
ShowModeParameter showModeParameter = new ShowModeParameter(); ShowModeParameter showModeParameter = new ShowModeParameter();
for (ShowModeParameterType showModeParameterType : showModeParameterTypes) { for (ShowModeParameterType showModeParameterType : showModeParameterTypes) {
showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter); showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter);
@ -282,27 +284,20 @@ public class TraceCommand extends SWCommand {
} }
@Register(value = {"show", "gui"}, description = "TRACE_COMMAND_HELP_SHOW_GUI") @Register(value = {"show", "gui"}, description = "TRACE_COMMAND_HELP_SHOW_GUI")
public void showGuiCommand(@Guard Player p) { public void showGuiCommand(@Validator Player p) {
TraceShowGui.openGui(p); TraceShowGui.openGui(p);
} }
@Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE") @Register(value = {"hide"}, description = "TRACE_COMMAND_HELP_HIDE")
public void hideCommand(@Guard Player p) { public void hideCommand(@Validator Player p) {
TraceShowManager.hide(p); TraceShowManager.hide(p);
BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p); BauSystem.MESSAGE.send("TRACE_MESSAGE_HIDE", p);
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker guardChecker() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "TRACE_MESSAGE_DISALLOWED");
if (Permission.hasPermission(player, Permission.WORLD)) {
return GuardResult.ALLOWED;
}
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("TRACE_MESSAGE_DISALLOWED", player);
}
return GuardResult.DENIED;
}; };
} }
} }

Datei anzeigen

@ -23,10 +23,8 @@ import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.GuardCheckType;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -45,23 +43,16 @@ public class ClearCommand extends SWCommand {
} }
@Register(description = "OTHER_CLEAR_HELP_PLAYER") @Register(description = "OTHER_CLEAR_HELP_PLAYER")
public void clearPlayerCommand(@Guard Player p, Player target) { public void clearPlayerCommand(@Validator Player p, Player target) {
clear(target); clear(target);
BauSystem.MESSAGE.send("OTHER_CLEAR_FROM", target, p.getName()); BauSystem.MESSAGE.send("OTHER_CLEAR_FROM", target, p.getName());
BauSystem.MESSAGE.send("OTHER_CLEAR_TO", p, target.getName()); BauSystem.MESSAGE.send("OTHER_CLEAR_TO", p, target.getName());
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker loaderGuard() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "OTHER_CLEAR_NO_PERMS");
if (!Permission.hasPermission(player, Permission.WORLD)) {
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("OTHER_CLEAR_NO_PERMS", player);
}
return GuardResult.DENIED;
}
return GuardResult.ALLOWED;
}; };
} }

Datei anzeigen

@ -9,10 +9,8 @@ import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.command.GuardCheckType;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@Linked(LinkageType.COMMAND) @Linked(LinkageType.COMMAND)
@ -23,7 +21,7 @@ public class SelectCommand extends SWCommand {
} }
@Register(description = {"SELECT_HELP", "SELECT_EXTENSION_HELP"}) @Register(description = {"SELECT_HELP", "SELECT_EXTENSION_HELP"})
public void baurahmenCommand(@Guard Player p, RegionType regionType, @OptionalValue("NORMAL") RegionExtensionType regionExtensionType) { public void baurahmenCommand(@Validator Player p, RegionType regionType, @OptionalValue("NORMAL") RegionExtensionType regionExtensionType) {
Region region = Region.getRegion(p.getLocation()); Region region = Region.getRegion(p.getLocation());
if (region.isGlobal()) { if (region.isGlobal()) {
@ -43,17 +41,10 @@ public class SelectCommand extends SWCommand {
setSelection(regionType, regionExtensionType, region, p); setSelection(regionType, regionExtensionType, region, p);
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker guardChecker() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLDEDIT), "SELECT_NO_PERMS");
if (Permission.hasPermission(player, Permission.WORLDEDIT)) {
return GuardResult.ALLOWED;
}
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("SELECT_NO_PERMS", player);
}
return GuardResult.DENIED;
}; };
} }

Datei anzeigen

@ -43,8 +43,7 @@ public class SkullCommand extends SWCommand {
} }
@Register(description = "SKULL_HELP") @Register(description = "SKULL_HELP")
public void giveCommand(Player p, @Mapper("player") String skull) { public void giveCommand(Player p, @Mapper("player") @ErrorMessage("SKULL_INVALID") String skull) {
// TODO: Add message to invalid Skulls!
ItemStack is = SWItem.getPlayerSkull(skull).getItemStack(); ItemStack is = SWItem.getPlayerSkull(skull).getItemStack();
SkullMeta sm = (SkullMeta) is.getItemMeta(); SkullMeta sm = (SkullMeta) is.getItemMeta();
assert sm != null; assert sm != null;

Datei anzeigen

@ -40,32 +40,14 @@ public class TimeCommand extends SWCommand {
addDefaultHelpMessage("OTHER_TIME_HELP"); addDefaultHelpMessage("OTHER_TIME_HELP");
} }
// TODO: Add set as OptionalValue
@Register @Register
public void genericCommand(@Guard Player p, Time time) { public void genericCommand(@Validator Player p, @OptionalValue("") @StaticValue({"set", ""}) String set, Time time) {
Bukkit.getWorlds().get(0).setTime(time.getValue()); Bukkit.getWorlds().get(0).setTime(time.getValue());
BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p); BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p);
} }
@Register @Register
public void genericCommand(@Guard Player p, @StaticValue(value = "set") String set, Time time) { public void genericCommand(@Validator Player p, @OptionalValue("") @StaticValue({"set", ""}) String set, int time) {
Bukkit.getWorlds().get(0).setTime(time.getValue());
BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p);
}
// TODO: Add set as OptionalValue
@Register
public void genericCommand(@Guard Player p, int time) {
if (time < 0 || time > 24000) {
BauSystem.MESSAGE.send("OTHER_TIME_INVALID", p);
return;
}
Bukkit.getWorlds().get(0).setTime(time);
BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p);
}
@Register
public void genericCommand(@Guard Player p, @StaticValue(value = "set") String set, int time) {
if (time < 0 || time > 24000) { if (time < 0 || time > 24000) {
BauSystem.MESSAGE.send("OTHER_TIME_INVALID", p); BauSystem.MESSAGE.send("OTHER_TIME_INVALID", p);
return; return;
@ -85,17 +67,10 @@ public class TimeCommand extends SWCommand {
}, s -> tabCompletions); }, s -> tabCompletions);
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker loaderGuard() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "OTHER_TIME_NO_PERM");
if (!Permission.hasPermission(player, Permission.WORLD)) {
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("OTHER_TIME_NO_PERM", player);
}
return GuardResult.DENIED;
}
return GuardResult.ALLOWED;
}; };
} }

Datei anzeigen

@ -58,7 +58,7 @@ public class WarpCommand extends SWCommand implements Disable, Enable {
@Register(value = "add", description = "WARP_HELP_ADD") @Register(value = "add", description = "WARP_HELP_ADD")
@Register("create") @Register("create")
public void addWarp(@Guard Player player, String name) { public void addWarp(@Validator Player player, String name) {
for (String forbiddenName : FORBIDDEN_NAMES) { for (String forbiddenName : FORBIDDEN_NAMES) {
if (name.equalsIgnoreCase(forbiddenName)) { if (name.equalsIgnoreCase(forbiddenName)) {
BauSystem.MESSAGE.send("WARP_NAME_RESERVED", player, name); BauSystem.MESSAGE.send("WARP_NAME_RESERVED", player, name);
@ -79,7 +79,7 @@ public class WarpCommand extends SWCommand implements Disable, Enable {
} }
@Register(value = "delete", description = "WARP_HELP_DELETE") @Register(value = "delete", description = "WARP_HELP_DELETE")
public void deleteWarp(@Guard Player player, Warp warp) { public void deleteWarp(@Validator Player player, Warp warp) {
warp.delete(); warp.delete();
BauSystem.MESSAGE.send("WARP_DELETED", player, warp.getName()); BauSystem.MESSAGE.send("WARP_DELETED", player, warp.getName());
} }
@ -122,17 +122,10 @@ public class WarpCommand extends SWCommand implements Disable, Enable {
BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation())); BauSystem.MESSAGE.sendPrefixless("WARP_GUI_DISTANCE", player, warp.getLocation().distance(player.getLocation()));
} }
@ClassGuard(value = Player.class, local = true) @ClassValidator(value = Player.class, local = true)
public GuardChecker commandGuard() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
Player player = (Player) commandSender; return !messageSender.send(!Permission.hasPermission(player, Permission.WORLD), "WARP_DISALLOWED");
if (!Permission.hasPermission(player, Permission.WORLD)) {
if (guardCheckType != GuardCheckType.TAB_COMPLETE) {
BauSystem.MESSAGE.send("WARP_DISALLOWED", player);
}
return GuardResult.DENIED;
}
return GuardResult.ALLOWED;
}; };
} }

Datei anzeigen

@ -24,10 +24,8 @@ import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.Linked;
import de.steamwar.command.GuardCheckType;
import de.steamwar.command.GuardChecker;
import de.steamwar.command.GuardResult;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -41,29 +39,23 @@ public class StopCommand extends SWCommand {
} }
@Register(description = "STOP_HELP") @Register(description = "STOP_HELP")
public void genericCommand(@Guard CommandSender sender) { public void genericCommand(@Validator CommandSender sender) {
SWUtils.message(current -> BauSystem.MESSAGE.parsePrefixed("STOP_MESSAGE", current)); SWUtils.message(current -> BauSystem.MESSAGE.parsePrefixed("STOP_MESSAGE", current));
Bukkit.getServer().shutdown(); Bukkit.getServer().shutdown();
} }
@ClassGuard(value = CommandSender.class, local = true) @ClassMapper(value = Player.class, local = true)
public GuardChecker stopGuard() { public TypeValidator<Player> validator() {
return (commandSender, guardCheckType, strings, s) -> { return (commandSender, player, messageSender) -> {
if (!(commandSender instanceof Player)) {
return GuardResult.ALLOWED;
}
Player player = (Player) commandSender;
if (Permission.hasPermission(player, Permission.WORLD)) { if (Permission.hasPermission(player, Permission.WORLD)) {
return GuardResult.ALLOWED; return true;
} }
SteamwarUser steamwarUser = SteamwarUser.get(player); SteamwarUser steamwarUser = SteamwarUser.get(player);
if (steamwarUser.getUserGroup().isAdminGroup()) { if (steamwarUser.getUserGroup().isAdminGroup()) {
return GuardResult.ALLOWED; return true;
} }
if (guardCheckType != GuardCheckType.TAB_COMPLETE) { messageSender.send("STOP_NO_PERMS");
BauSystem.MESSAGE.send("STOP_NO_PERMS", player); return false;
}
return GuardResult.DENIED;
}; };
} }
} }