SteamWar/BauSystem
Archiviert
13
0

Update BauSystem to new CommandFramework #217

Manuell gemergt
YoyoNow hat 63 Commits von CommandFramework nach master 2021-04-02 18:08:26 +02:00 zusammengeführt
4 geänderte Dateien mit 89 neuen und 93 gelöschten Zeilen
Nur Änderungen aus Commit 7116fed5b2 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -96,8 +96,7 @@ public class BauSystem extends JavaPlugin implements Listener {
new CommandGills();
new CommandDetonator();
new CommandScript();
getCommand("scriptvars").setExecutor(new CommandScriptVars());
getCommand("scriptvars").setTabCompleter(new CommandScriptVarsTabCompleter());
new CommandScriptVars();
new CommandSimulator();
new CommandRedstoneTester();
new CommandGUI();

Datei anzeigen

@ -2,67 +2,99 @@ package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.world.ScriptListener;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class CommandScriptVars implements CommandExecutor {
public class CommandScriptVars extends SWCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (!(sender instanceof Player)) {
return false;
}
Player player = (Player) sender;
if (args.length == 0) {
Map<String, Integer> globalVariables = ScriptListener.GLOBAL_VARIABLES.get(player);
if (globalVariables == null) {
player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
return false;
}
int i = 0;
player.sendMessage(BauSystem.PREFIX + globalVariables.size() + " Variable(n)");
for (Map.Entry<String, Integer> var : globalVariables.entrySet()) {
if (i++ >= 40) break;
player.sendMessage("- " + var.getKey() + "=" + var.getValue());
}
return false;
}
String varName = args[0];
if (args.length == 1) {
Map<String, Integer> globalVariables = ScriptListener.GLOBAL_VARIABLES.get(player);
if (globalVariables == null) {
player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
return false;
}
if (!globalVariables.containsKey(varName)) {
player.sendMessage(BauSystem.PREFIX + "§cUnbekannte Variable");
return false;
}
player.sendMessage(BauSystem.PREFIX + varName + "=" + globalVariables.get(varName));
return false;
}
switch (args[1].toLowerCase()) {
case "delete":
case "clear":
case "remove":
if (!ScriptListener.GLOBAL_VARIABLES.containsKey(player)) {
player.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
break;
}
ScriptListener.GLOBAL_VARIABLES.get(player).remove(varName);
player.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht");
break;
default:
int value = ScriptListener.parseValue(args[1]);
ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(player, p -> new HashMap<>()).put(varName, value);
player.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt");
}
return false;
public CommandScriptVars() {
super("scripvars");
}
@Register
public void genericCommand(Player p) {
Map<String, Integer> globalVariables = ScriptListener.GLOBAL_VARIABLES.get(p);
if (globalVariables == null) {
p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
return;
}
int i = 0;
p.sendMessage(BauSystem.PREFIX + globalVariables.size() + " Variable(n)");
for (Map.Entry<String, Integer> var : globalVariables.entrySet()) {
if (i++ >= 40) break;
p.sendMessage("- " + var.getKey() + "=" + var.getValue());
}
}
@Register
public void removeCommand(Player p, String varName) {
Map<String, Integer> globalVariables = ScriptListener.GLOBAL_VARIABLES.get(p);
if (globalVariables == null) {
p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
return;
}
if (!globalVariables.containsKey(varName)) {
p.sendMessage(BauSystem.PREFIX + "§cUnbekannte Variable");
return;
}
p.sendMessage(BauSystem.PREFIX + varName + "=" + globalVariables.get(varName));
}
@Register
public void booleanValueCommand(Player p, String varName, @Mapper(value = "BooleanString") int value) {
valueCommand(p, varName, value);
}
@Register
public void valueCommand(Player p, String varName, int value) {
ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(p, player -> new HashMap<>()).put(varName, value);
p.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt");
}
@Register
public void removeCommand(Player p, String varName, @Mapper(value = "ClearString") String remove) {
if (!ScriptListener.GLOBAL_VARIABLES.containsKey(p)) {
p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert");
return;
}
ScriptListener.GLOBAL_VARIABLES.get(p).remove(varName);
p.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht");
}
@ClassMapper(value = String.class, local = true)
public TypeMapper<String> stringTypeMapper() {
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> {
if (commandSender instanceof Player) {
Player player = (Player) commandSender;
return new ArrayList<>(ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).keySet());
}
return null;
});
}
@Mapper(value = "ClearString", local = true)
public TypeMapper<String> clearStringTypeMapper() {
List<String> tabCompletes = Arrays.asList("delete", "clear", "remove");
return SWCommandUtils.createMapper(s -> s, s -> tabCompletes);
}
@Mapper(value = "BooleanString", local = true)
public TypeMapper<Object> booleanStringTypeMapper() {
List<String> tabCompletes = Arrays.asList("yes", "no", "true", "false");
return SWCommandUtils.createMapper(s -> {
if (s.equalsIgnoreCase("yes") || s.equals("true")) {
return 1;
}
if (s.equalsIgnoreCase("no") || s.equals("false")) {
return 0;
}
return null;
}, s -> tabCompletes);
}
}

Datei anzeigen

@ -1,34 +0,0 @@
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.world.ScriptListener;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class CommandScriptVarsTabCompleter implements TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String s, String[] args) {
if (!(sender instanceof Player)) {
return new ArrayList<>();
}
Player player = (Player) sender;
if (args.length == 1) {
List<String> variables = new ArrayList<>(ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).keySet());
return SWUtils.manageList(variables, args);
}
if (args.length != 2) {
return new ArrayList<>();
}
int value = ScriptListener.GLOBAL_VARIABLES.getOrDefault(player, new HashMap<>()).getOrDefault(args[0], 0);
return SWUtils.manageList(Arrays.asList(value + "", "true", "false", "yes", "no", "delete", "clear", "remove"), args);
}
}

Datei anzeigen

@ -13,4 +13,3 @@ commands:
freeze:
aliases: stoplag
lockschem:
scriptvars: