SteamWar/BungeeCore
Archiviert
13
2

Merge pull request 'Update BauCommand' (#428) from BauCommand into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #428
Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2022-09-20 13:17:52 +02:00
Commit 93c96aea08
5 geänderte Dateien mit 175 neuen und 224 gelöschten Zeilen

@ -1 +1 @@
Subproject commit 9df92595b2f344585bd3e1639cedc761680b7761
Subproject commit 1dea71993d897354d3f52a705f6e0e1e0c8ec580

Datei anzeigen

@ -25,6 +25,9 @@ import de.steamwar.bungeecore.inventory.SWItem;
import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.sql.*;
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;
@ -32,89 +35,91 @@ 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;
}
@Register(help = true)
public void genericHelp(ProxiedPlayer p, String... args) {
HelpCommand.sendBauHelp(ChatSender.of(p));
}
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;
case "lock":
if(args.length < 2) {
Message.send("BAU_LOCKED_OPTIONS", p);
return;
}
BauLock.setLocked(p, args[1].toUpperCase());
break;
case "unlock":
BauLock.setLocked(p, "OPEN");
break;
default:
HelpCommand.sendBauHelp(ChatSender.of(p));
}
}
() -> new ServerStarter().build15(p.getUniqueId()).send(p).start(),
() -> new ServerStarter().build19(p.getUniqueId()).send(p).start()
);
}
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) {
switch (version) {
case 12:
r12.run();
break;
case 15:
r15.run();
break;
case 19:
r19.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);
@ -123,76 +128,69 @@ 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;
}
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;
}
if(BauLock.isLocked(worldOwner, SteamwarUser.get(p))) {
Message.send("BAU_LOCKED_NOALLOWED", p);
return;
}
versionSelector(p, args, 2,
() -> 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)));
}
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 = "addMemberTarget", local = true)
public TypeValidator<SteamwarUser> addMemberTargetValidator() {
return (sender, value, messageSender) -> {
if (value == null) {
messageSender.send("UNKNOWN_PLAYER");
return false;
}
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();
}
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;
};
}
private static void togglewe(ProxiedPlayer p, String[] args){
BauweltMember target = toggle(p, args, "togglewe");
if(target == null)
@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().build12(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build15(worldOwner.getUuid()).send(p).start(),
() -> new ServerStarter().build19(worldOwner.getUuid()).send(p).start()
);
}
@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;
}
if(BauLock.isLocked(value, SteamwarUser.get(p))) {
messageSender.send("BAU_LOCKED_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;
}
BauweltMember target = member(p, user);
if (target == null)
return;
target.setWorldEdit(!target.isWorldEdit());
@ -200,9 +198,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());
@ -220,14 +223,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())) {
@ -247,13 +246,15 @@ 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,
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())),
versionSelector(version,
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS12_PATH + p.getUniqueId().toString())),
() -> HelpCommand.sendBauHelp(ChatSender.of(p)));
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS15_PATH + user.getId())),
() -> deleteConfirmation(p, () -> deleteWorld(p, ServerStarter.WORLDS19_PATH + user.getId()))
);
}
private static void deleteConfirmation(ProxiedPlayer p, Runnable worldDeletion) {
@ -281,8 +282,22 @@ 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());
});
}
@Register(value = "lock", description = "BAU_LOCKED_OPTIONS")
public void lock(ProxiedPlayer p, BauLockState bauLockState) {
BauLock.setLocked(p, bauLockState);
}
@Register("unlock")
public void unlock(ProxiedPlayer p) {
BauLock.setLocked(p, BauLockState.OPEN);
}
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
@ -299,16 +314,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()) {

Datei anzeigen

@ -20,21 +20,15 @@
package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.Message;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@UtilityClass
public class BauLock {
private static final String BAU_LOCK_CONFIG_NAME = "baulockstate";
public static void setLocked(ProxiedPlayer p, String arg) {
public static void setLocked(ProxiedPlayer p, BauLockState state) {
SteamwarUser owner = SteamwarUser.get(p.getUniqueId());
BauLockState state;
try {
state = BauLockState.valueOf(arg);
} catch (IllegalArgumentException e) {
Message.send("BAU_LOCKED_OPTIONS", owner.getPlayer());
return;
}
UserConfig.updateUserConfig(owner.getId(), BAU_LOCK_CONFIG_NAME, state == BauLockState.OPEN ? null : state.name());
Message.send("BAU_LOCKED_" + state.name(), owner.getPlayer());
}

Datei anzeigen

@ -121,7 +121,7 @@ public class SWCommand extends AbstractSWCommand<CommandSender> {
}
@Register(help = true)
private void internalHelp(ProxiedPlayer p, String... args) {
public void internalHelp(ProxiedPlayer p, String... args) {
ChatSender chatSender = ChatSender.of(p);
try {
chatSender.prefixless("COMMAND_HELP_HEAD", command.getName());