Archiviert
1
0

Rework arena and map selection in fight, challenge and testbau command

Dieser Commit ist enthalten in:
Lixfel 2020-01-18 13:39:15 +01:00
Ursprung 43809981fb
Commit 0f923f6564
4 geänderte Dateien mit 145 neuen und 97 gelöschten Zeilen

Datei anzeigen

@ -8,6 +8,7 @@ public class ArenaMode {
private static Map<String, ArenaMode> byChat = new HashMap<>();
private static Map<String, ArenaMode> byInternal = new HashMap<>();
private static List<ArenaMode> allModes = new LinkedList<>();
private static Random random = new Random();
static void init(Configuration config){
@ -32,6 +33,10 @@ public class ArenaMode {
return chatNames;
}
public static List<ArenaMode> getAllModes(){
return allModes;
}
private final String internalName;
private final String displayName;
private final List<String> chatNames;
@ -45,6 +50,7 @@ public class ArenaMode {
this.chatNames = config.getStringList("chatNames");
this.maps = config.getStringList("maps");
allModes.add(this);
byInternal.put(internalName, this);
for(String name : chatNames){
byChat.put(name.toLowerCase(), this);

Datei anzeigen

@ -177,26 +177,15 @@ public class BauCommand {
}
private static void testarena(ProxiedPlayer p, String[] command){
if (command.length == 2) {
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "/bau testarena <Spielmodus>");
return;
}
ArenaMode mode = ArenaMode.getByChat(command[2]);
if(mode == null){
BungeeCore.send(p, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + command[2]);
return;
}
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
FightCommand.createArena(p, "/bau testarena ", command, 2, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) {
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) {
subserver.stop();
break;
}
}
SubserverSystem.sendToTestServer(p, mode, FightCommand.getMap(p, mode, new String[0]));
});
SubserverSystem.sendToTestServer(p, mode, map);
}));
}
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){

Datei anzeigen

@ -18,42 +18,24 @@ public class ChallengeCommand extends BasicCommand {
@Override
public void execute(CommandSender sender, String[] args) {
if(args.length != 2){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8] §8[§7Spielmodus§8]");
return;
}
if(!(sender instanceof ProxiedPlayer)){
return;
}
ProxiedPlayer player = (ProxiedPlayer) sender;
Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu befindest dich bereits in einer Arena.");
if(args.length < 1){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8]");
return;
}
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
if(target == null){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler ist nicht online.");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer gewünschte Spieler ist nicht online.");
return;
}
subserver = Subserver.getSubserver(target);
Subserver subserver = Subserver.getSubserver(target);
if(subserver != null && subserver.getType() == Servertype.ARENA){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDer Herausgeforderte ist bereits in einer Arena.");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDer Herausgeforderte ist bereits in einer Arena.");
return;
}
ArenaMode mode = ArenaMode.getByChat(args[1]);
if(mode == null){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]);
return;
}
String map = FightCommand.getMap(sender, mode, new String[0]);
FightCommand.createArena(sender, "/challenge " + target.getName() + " ", args, 1, (player, mode, map) -> {
if(challenges.containsKey(target) && challenges.get(target).contains(player)){
challenges.remove(target);
challenges.remove(player);
@ -80,6 +62,7 @@ public class ChallengeCommand extends BasicCommand {
"§aHerausforderung annehmen",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName()));
}
});
}
public static void remove(ProxiedPlayer player){

Datei anzeigen

@ -1,6 +1,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent;
@ -11,63 +12,125 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.LinkedList;
/**
* Jeder Fightcommand (auch bau testarena und challenge) haben folgende Optionskette:
*
* [ArenaMode] [Map]
*
* Sollte der ArenaMode fehlen, kann er mit getMode() bestimmt werden.
* Sollte die Map fehlen, kann sie mit getMap() bestimmt werden.
*/
public class FightCommand extends BasicCommand {
public FightCommand() {
super("fight", "", "f");
}
static String getMap(CommandSender sender, ArenaMode mode, String[] args){
if(args.length == 2){
String realMap = mode.hasMap(args[1].toLowerCase());
private static ArenaMode getMode(CommandSender sender, String arg){
ArenaMode mode = ArenaMode.getByChat(arg);
if(mode != null)
return mode;
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + arg);
return null;
}
private static String getMap(CommandSender sender, ArenaMode mode, String arg){
String realMap = mode.hasMap(arg.toLowerCase());
if(realMap != null)
return realMap;
if(arg.equals("Random"))
return mode.getRandomMap();
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht.");
return null;
}else{
return mode.getRandomMap();
}
private static void getModes(CommandSender sender, String precommand){
TextComponent start = new TextComponent();
TextComponent current = start;
for(ArenaMode mode : ArenaMode.getAllModes()){
String command = precommand + mode.getChatName();
current.setBold(true);
current.setColor(ChatColor.GRAY);
current.setText(mode.getChatName());
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create()));
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
if(current != start)
start.addExtra(current);
current = new TextComponent();
}
sender.sendMessage(start);
}
private static void getMaps(CommandSender sender, String precommand, ArenaMode mode){
TextComponent start = new TextComponent();
TextComponent current = start;
for(String map : mode.getMaps()){
String command = precommand + mode.getChatName() + " " + map;
current.setBold(true);
current.setColor(ChatColor.GRAY);
current.setText(mode.getChatName());
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create()));
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
if(current != start)
start.addExtra(current);
current = new TextComponent();
}
sender.sendMessage(start);
}
private static boolean alreadyInArena(ProxiedPlayer player){
Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cDu befindest dich bereits in einer Arena.");
return true;
}
return false;
}
static void createArena(CommandSender sender, String precommand, String[] args, int startArg, FightCallback callback){
if(!(sender instanceof ProxiedPlayer))
return;
ProxiedPlayer player = (ProxiedPlayer) sender;
if(alreadyInArena(player))
return;
if(args.length < startArg+1){
getModes(sender, precommand);
return;
}
ArenaMode mode = getMode(sender, args[startArg]);
if(mode == null)
return;
if(args.length < startArg+2){
getMaps(sender, precommand, mode);
return;
}
String map = getMap(sender, mode, args[startArg+1]);
if(map == null)
return;
callback.run(player, mode, map);
}
@Override
public void execute(CommandSender sender, String[] args) {
if(args.length != 1 && args.length != 2){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§7Mit §e/fight §7kannst du einen neuen Kampf starten!");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight §8[§7Spielmodus§8] <§7Arena§8>");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight AirShip §8- §7Starte einen §eAirShip§8-§7Kampf§8!");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight WarShip §8- §7Starte einen §eWarShip§8-§7Kampf§8!");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight WarGear §8- §7Starte einen §eWarGear§8-§7Kampf§8!");
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§efight MiniWarGear §8- §7Starte einen §eMiniWarGear§8-§7Kampf");
return;
}
if(sender instanceof ProxiedPlayer){
ProxiedPlayer player = (ProxiedPlayer) sender;
Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDu befindest dich bereits in einer Arena.");
return;
}
ArenaMode mode = ArenaMode.getByChat(args[0]);
if(mode == null){
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[0]);
return;
}
String map = getMap(sender, mode, args);
if(map == null)
return;
createArena(sender, "/fight ", args, 0, (player, mode, map) -> {
Subserver arena = SubserverSystem.startArena(mode, map, 0, null, null, player.getUniqueId(), null);
arena.sendPlayer(player);
TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.getDisplayName() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!");
tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§aGegen §7" + player.getName() + " §ekämpfen").create()));
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
ProxyServer.getInstance().broadcast(tc);
}
});
}
@Override
@ -82,4 +145,11 @@ public class FightCommand extends BasicCommand {
}
return new LinkedList<>();
}
/**
* Is called when arena parameters are clear.
*/
interface FightCallback {
void run(ProxiedPlayer player, ArenaMode mode, String map);
}
}