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.BauweltMember;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.util.Chat19; 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.messages.ChatSender;
import de.steamwar.network.packets.server.BaumemberUpdatePacket; import de.steamwar.network.packets.server.BaumemberUpdatePacket;
import net.md_5.bungee.api.CommandSender; 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.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; 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(){ public BauCommand(){
super("bau", null, "b", "build", "gs"); super("bau", null, "b", "build", "gs");
} }
@Override @Register
public void execute(CommandSender sender, String[] args) { public void toBau(ProxiedPlayer p, @Mapper("version") @OptionalValue("") int version) {
if(!(sender instanceof ProxiedPlayer)) { versionSelector(version,
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(),
() -> new ServerStarter().build12(p.getUniqueId()).send(p).start(), () -> new ServerStarter().build12(p.getUniqueId()).send(p).start(),
() -> { () -> new ServerStarter().build15(p.getUniqueId()).send(p).start(),
switch (args[0].toLowerCase()) { () -> new ServerStarter().build19(p.getUniqueId()).send(p).start(),
case "addmember": () -> HelpCommand.sendBauHelp(ChatSender.of(p))
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));
}
}
); );
} }
private static void addmember(ProxiedPlayer p, String[] args){ public void versionSelector(int version, Runnable r12, Runnable r15, Runnable r19, Runnable rDefault) {
if (args.length == 1) { switch (version) {
Message.send("BAU_ADDMEMBER_USAGE", p); case 12:
return; r12.run();
break;
case 15:
r15.run();
break;
case 19:
r19.run();
break;
default:
rDefault.run();
break;
}
} }
SteamwarUser target = SteamwarUser.get(args[1]); @Mapper(value = "version", local = true)
if (target == null) { public TypeMapper<Integer> versionMapper() {
Message.send("UNKNOWN_PLAYER", p); Map<String, Integer> versionMap = new HashMap<>();
return; versionMap.put("19", 19);
}else if(target.getUuid().equals(p.getUniqueId())) { versionMap.put("1.19", 19);
Message.send("BAU_ADDMEMBER_SELFADD", p); versionMap.put("mwg", 19);
return; versionMap.put("miniwargear", 19);
}else if (BauweltMember.getBauMember(p.getUniqueId(), target.getUuid()) != null) { versionMap.put("wg", 19);
Message.send("BAU_ADDMEMBER_ISADDED", p); versionMap.put("wargear", 19);
return; 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); new BauweltMember(p.getUniqueId(), target.getUuid(), false, false);
Message.send("BAU_ADDMEMBER_ADDED", p); Message.send("BAU_ADDMEMBER_ADDED", p);
@ -113,71 +128,66 @@ public class BauCommand extends BasicCommand {
Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName()); Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName());
} }
private static void teleport(ProxiedPlayer p, String[] args){ @Validator(value = "addMemberTarget", local = true)
if (args.length == 1) { public TypeValidator<SteamwarUser> addMemberTargetValidator() {
Message.send("BAU_TP_USAGE", p); return (sender, value, messageSender) -> {
return; 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]); @Register(value = "tp", description = "BAU_TP_USAGE")
if (worldOwner == null) { @Register("teleport")
Message.send("UNKNOWN_PLAYER", p); public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue("") int version) {
return; versionSelector(version,
}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,
() -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start(), () -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(), () -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build12(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) { @Validator(value = "teleportTarget", local = true)
if(args.length <= pos) { public TypeValidator<SteamwarUser> teleportTargetValidator() {
int version = p.getPendingConnection().getVersion(); return (sender, value, messageSender) -> {
if(version > 578) { // Version > 1.15.2 if (value == null) {
run19.run(); messageSender.send("UNKNOWN_PLAYER");
} else if(version > 340) { // Version > 1.12.2 return false;
run15.run();
} else {
run12.run();
} }
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; return;
} }
BauweltMember target = member(p, user);
switch (args[pos].toLowerCase()) { if (target == null)
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)
return; return;
target.setWorldEdit(!target.isWorldEdit()); target.setWorldEdit(!target.isWorldEdit());
@ -185,9 +195,14 @@ public class BauCommand extends BasicCommand {
isAllowedTo(target.isWorldEdit(), p, target, "BAU_MEMBER_TOGGLE_WORLD_EDIT"); isAllowedTo(target.isWorldEdit(), p, target, "BAU_MEMBER_TOGGLE_WORLD_EDIT");
} }
private static void toggleworld(ProxiedPlayer p, String[] args){ @Register("toggleworld")
BauweltMember target = toggle(p, args, "toggleworld"); public void toggleworld(ProxiedPlayer p, @AllowNull @OptionalValue("") SteamwarUser user) {
if(target == null) if (user == null) {
Message.send("BAU_MEMBER_TOGGLE_USAGE", p, "toggleworld");
return;
}
BauweltMember target = member(p, user);
if (target == null)
return; return;
target.setWorld(!target.isWorld()); target.setWorld(!target.isWorld());
@ -205,14 +220,10 @@ public class BauCommand extends BasicCommand {
} }
} }
private static void delmember(ProxiedPlayer p, String[] args){ @Register(value = "delmember", description = "BAU_DELMEMBER_USAGE")
if (args.length == 1) { public void delmember(ProxiedPlayer p, SteamwarUser user) {
Message.send("BAU_DELMEMBER_USAGE", p); BauweltMember target = member(p, user);
return; if (target == null)
}
BauweltMember target = member(p, SteamwarUser.get(args[1]));
if(target == null)
return; return;
if(SteamwarUser.get(target.getMemberID()).getUuid().equals(p.getUniqueId())) { if(SteamwarUser.get(target.getMemberID()).getUuid().equals(p.getUniqueId())) {
@ -232,13 +243,16 @@ public class BauCommand extends BasicCommand {
Message.send("BAU_DELMEMBER_DELETED", p); 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()); 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.WORLDS19_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())), () -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS12_PATH + p.getUniqueId().toString())), () -> 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) { 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){ @Register("test")
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("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){ private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
@ -284,16 +302,6 @@ public class BauCommand extends BasicCommand {
return target; 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){ private static void isAllowedTo(boolean permission, ProxiedPlayer p, BauweltMember target, String what){
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUuid()); 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) { public static void suggestMerging(ProxiedPlayer player, ArenaMode mode, String map, FightCallback declineMerge) {
Arenaserver mergable = null; Arenaserver mergable = null;
synchronized (Subserver.getServerList()) { synchronized (Subserver.getServerList()) {