SteamWar/BungeeCore
Archiviert
13
2

Update BauCommand
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-09-06 17:13:15 +02:00
Ursprung 2676f97cfb
Commit 4c44bc0a83
2 geänderte Dateien mit 150 neuen und 190 gelöschten Zeilen

Datei anzeigen

@ -26,6 +26,9 @@ import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import de.steamwar.messages.ChatSender;
import de.steamwar.network.packets.server.BaumemberUpdatePacket;
import net.md_5.bungee.api.CommandSender;
@ -33,78 +36,90 @@ import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
public class BauCommand extends BasicCommand {
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class BauCommand extends SWCommand {
public BauCommand(){
super("bau", null, "b", "build", "gs");
}
@Override
public void execute(CommandSender sender, String[] args) {
if(!(sender instanceof ProxiedPlayer)) {
return;
}
ProxiedPlayer p = (ProxiedPlayer) sender;
versionSelector(p, args, 0,
() -> new ServerStarter().build19(p.getUniqueId()).send(p).start(),
() -> new ServerStarter().build15(p.getUniqueId()).send(p).start(),
@Register
public void toBau(ProxiedPlayer p, @Mapper("version") @OptionalValue("") int version) {
versionSelector(version,
() -> new ServerStarter().build12(p.getUniqueId()).send(p).start(),
() -> {
switch (args[0].toLowerCase()) {
case "addmember":
addmember(p, args);
break;
case "tp":
case "teleport":
teleport(p, args);
break;
case "info":
Chat19.chat(p, "/bauinfo");
break;
case "togglewe":
togglewe(p, args);
break;
case "toggleworld":
toggleworld(p, args);
break;
case "delmember":
delmember(p, args);
break;
case "resetall":
case "delete":
delete(p, args);
break;
case "testarena":
case "test":
testarena(p, args);
break;
default:
HelpCommand.sendBauHelp(ChatSender.of(p));
}
}
() -> new ServerStarter().build15(p.getUniqueId()).send(p).start(),
() -> new ServerStarter().build19(p.getUniqueId()).send(p).start(),
() -> HelpCommand.sendBauHelp(ChatSender.of(p))
);
}
private static void addmember(ProxiedPlayer p, String[] args){
if (args.length == 1) {
Message.send("BAU_ADDMEMBER_USAGE", p);
return;
public void versionSelector(int version, Runnable r12, Runnable r15, Runnable r19, Runnable rDefault) {
switch (version) {
case 12:
r12.run();
break;
case 15:
r15.run();
break;
case 19:
r19.run();
break;
default:
rDefault.run();
break;
}
}
SteamwarUser target = SteamwarUser.get(args[1]);
if (target == null) {
Message.send("UNKNOWN_PLAYER", p);
return;
}else if(target.getUuid().equals(p.getUniqueId())) {
Message.send("BAU_ADDMEMBER_SELFADD", p);
return;
}else if (BauweltMember.getBauMember(p.getUniqueId(), target.getUuid()) != null) {
Message.send("BAU_ADDMEMBER_ISADDED", p);
return;
}
@Mapper(value = "version", local = true)
public TypeMapper<Integer> versionMapper() {
Map<String, Integer> versionMap = new HashMap<>();
versionMap.put("19", 19);
versionMap.put("1.19", 19);
versionMap.put("mwg", 19);
versionMap.put("miniwargear", 19);
versionMap.put("wg", 19);
versionMap.put("wargear", 19);
versionMap.put("ws", 15);
versionMap.put("15", 15);
versionMap.put("1.15", 15);
versionMap.put("warship", 15);
versionMap.put("as", 15);
versionMap.put("airship", 15);
versionMap.put("12", 12);
versionMap.put("1.12", 12);
return new TypeMapper<Integer>() {
@Override
public Integer map(CommandSender commandSender, String[] previousArguments, String s) {
if (commandSender == null) return null;
ProxiedPlayer player = (ProxiedPlayer) commandSender;
if (s.isEmpty()) {
int version = player.getPendingConnection().getVersion();
if (version > 578) { // Version > 1.15.2
return 19;
} else if (version > 340) { // Version > 1.12.2
return 15;
} else {
return 12;
}
}
return versionMap.get(s.toLowerCase());
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
return versionMap.keySet();
}
};
}
@Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE")
public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) {
new BauweltMember(p.getUniqueId(), target.getUuid(), false, false);
Message.send("BAU_ADDMEMBER_ADDED", p);
@ -113,71 +128,66 @@ public class BauCommand extends BasicCommand {
Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName());
}
private static void teleport(ProxiedPlayer p, String[] args){
if (args.length == 1) {
Message.send("BAU_TP_USAGE", p);
return;
}
@Validator(value = "addMemberTarget", local = true)
public TypeValidator<SteamwarUser> addMemberTargetValidator() {
return (sender, value, messageSender) -> {
if (value == null) {
messageSender.send("UNKNOWN_PLAYER");
return false;
}
if (((ProxiedPlayer) sender).getUniqueId().equals(value.getUuid())) {
messageSender.send("BAU_ADDMEMBER_SELFADD");
return false;
}
if (BauweltMember.getBauMember(((ProxiedPlayer) sender).getUniqueId(), value.getUuid()) != null) {
messageSender.send("BAU_ADDMEMBER_ISADDED");
return false;
}
return true;
};
}
SteamwarUser worldOwner = SteamwarUser.get(args[1]);
if (worldOwner == null) {
Message.send("UNKNOWN_PLAYER", p);
return;
}else if (!p.getUniqueId().equals(worldOwner.getUuid()) && BauweltMember.getBauMember(worldOwner.getUuid(), p.getUniqueId()) == null){
SubserverSystem.sendDeniedMessage(p, worldOwner.getUuid());
Message.send("BAU_TP_NOALLOWED", p);
return;
}
versionSelector(p, args, 2,
@Register(value = "tp", description = "BAU_TP_USAGE")
@Register("teleport")
public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue("") int version) {
versionSelector(version,
() -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build12(worldOwner.getUuid()).send(p).start(),
() -> HelpCommand.sendBauHelp(ChatSender.of(p)));
() -> HelpCommand.sendBauHelp(ChatSender.of(p))
);
}
private static void versionSelector(ProxiedPlayer p, String[] args, int pos, Runnable run19, Runnable run15, Runnable run12, Runnable runElse) {
if(args.length <= pos) {
int version = p.getPendingConnection().getVersion();
if(version > 578) { // Version > 1.15.2
run19.run();
} else if(version > 340) { // Version > 1.12.2
run15.run();
} else {
run12.run();
@Validator(value = "teleportTarget", local = true)
public TypeValidator<SteamwarUser> teleportTargetValidator() {
return (sender, value, messageSender) -> {
if (value == null) {
messageSender.send("UNKNOWN_PLAYER");
return false;
}
ProxiedPlayer p = (ProxiedPlayer) sender;
if (!p.getUniqueId().equals(value.getUuid()) && BauweltMember.getBauMember(value.getUuid(), p.getUniqueId()) == null) {
SubserverSystem.sendDeniedMessage(p, value.getUuid());
messageSender.send("BAU_TP_NOALLOWED");
return false;
}
return true;
};
}
@Register("info")
public void info(ProxiedPlayer p) {
Chat19.chat(p, "/bauinfo");
}
@Register("togglewe")
public void togglewe(ProxiedPlayer p, @AllowNull @OptionalValue("") SteamwarUser user) {
if (user == null) {
Message.send("BAU_MEMBER_TOGGLE_USAGE", p, "togglewe");
return;
}
switch (args[pos].toLowerCase()) {
case "19":
case "1.19":
case "mwg":
case "miniwargear":
run19.run();
break;
case "ws":
case "warship":
case "as":
case "airship":
case "wg":
case "wargear":
case "15":
case "1.15":
run15.run();
break;
case "12":
case "1.12":
run12.run();
break;
default:
runElse.run();
}
}
private static void togglewe(ProxiedPlayer p, String[] args){
BauweltMember target = toggle(p, args, "togglewe");
if(target == null)
BauweltMember target = member(p, user);
if (target == null)
return;
target.setWorldEdit(!target.isWorldEdit());
@ -185,9 +195,14 @@ public class BauCommand extends BasicCommand {
isAllowedTo(target.isWorldEdit(), p, target, "BAU_MEMBER_TOGGLE_WORLD_EDIT");
}
private static void toggleworld(ProxiedPlayer p, String[] args){
BauweltMember target = toggle(p, args, "toggleworld");
if(target == null)
@Register("toggleworld")
public void toggleworld(ProxiedPlayer p, @AllowNull @OptionalValue("") SteamwarUser user) {
if (user == null) {
Message.send("BAU_MEMBER_TOGGLE_USAGE", p, "toggleworld");
return;
}
BauweltMember target = member(p, user);
if (target == null)
return;
target.setWorld(!target.isWorld());
@ -205,14 +220,10 @@ public class BauCommand extends BasicCommand {
}
}
private static void delmember(ProxiedPlayer p, String[] args){
if (args.length == 1) {
Message.send("BAU_DELMEMBER_USAGE", p);
return;
}
BauweltMember target = member(p, SteamwarUser.get(args[1]));
if(target == null)
@Register(value = "delmember", description = "BAU_DELMEMBER_USAGE")
public void delmember(ProxiedPlayer p, SteamwarUser user) {
BauweltMember target = member(p, user);
if (target == null)
return;
if(SteamwarUser.get(target.getMemberID()).getUuid().equals(p.getUniqueId())) {
@ -232,13 +243,16 @@ public class BauCommand extends BasicCommand {
Message.send("BAU_DELMEMBER_DELETED", p);
}
private static void delete(ProxiedPlayer p, String[] args){
@Register("resetall")
@Register("delete")
public void delete(ProxiedPlayer p, @Mapper("version") @OptionalValue("") int version) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId());
versionSelector(p, args, 1,
versionSelector(version,
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS12_PATH + p.getUniqueId().toString())),
() -> HelpCommand.sendBauHelp(ChatSender.of(p)));
() -> HelpCommand.sendBauHelp(ChatSender.of(p))
);
}
private static void deleteConfirmation(ProxiedPlayer p, Runnable worldDeletion) {
@ -266,8 +280,12 @@ public class BauCommand extends BasicCommand {
});
}
private static void testarena(ProxiedPlayer p, String[] args){
FightCommand.createArena(p, "/bau testarena ", false, args, 1, false, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, map, p).start()));
@Register("test")
@Register("testarena")
public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) -> {
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, map, p).start());
});
}
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
@ -284,16 +302,6 @@ public class BauCommand extends BasicCommand {
return target;
}
private static BauweltMember toggle(ProxiedPlayer p, String[] args, String subcommand){
if (args.length == 1) {
Message.send("BAU_MEMBER_TOGGLE_USAGE", p, subcommand);
return null;
}
SteamwarUser member = SteamwarUser.get(args[1]);
return member(p, member);
}
private static void isAllowedTo(boolean permission, ProxiedPlayer p, BauweltMember target, String what){
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid());

Datei anzeigen

@ -157,54 +157,6 @@ public class FightCommand extends SWCommand {
}
}
static void createArena(CommandSender s, String precommand, boolean allowMerging, String[] args, int startArg, boolean historic, FightCallback callback){
if(!(s instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) s;
ChatSender sender = ChatSender.of(player);
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) {
return;
}
if(alreadyInArena(player))
return;
if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) {
sender.system("MODLOADER_DENIED");
return;
}
if(args.length < startArg+1){
getModes(sender, precommand, historic);
return;
}
ArenaMode mode = getMode(sender, args[startArg]);
if(mode == null)
return;
String map;
if(mode.getMaps().size() == 1){
map = mode.getRandomMap();
}else if(args.length < startArg+2){
getMaps(sender, precommand, mode);
return;
}else{
map = getMap(sender, mode, args[startArg+1]);
}
if(map == null)
return;
if(!allowMerging) {
callback.run(player, mode, map);
} else {
suggestMerging(player, mode, map, callback);
}
}
public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) {
Arenaserver mergable = null;
synchronized (Subserver.getServerList()) {