geforkt von SteamWar/BungeeCore
Rework arena and map selection in fight, challenge and testbau command
Dieser Commit ist enthalten in:
Ursprung
43809981fb
Commit
0f923f6564
@ -8,6 +8,7 @@ public class ArenaMode {
|
|||||||
|
|
||||||
private static Map<String, ArenaMode> byChat = new HashMap<>();
|
private static Map<String, ArenaMode> byChat = new HashMap<>();
|
||||||
private static Map<String, ArenaMode> byInternal = new HashMap<>();
|
private static Map<String, ArenaMode> byInternal = new HashMap<>();
|
||||||
|
private static List<ArenaMode> allModes = new LinkedList<>();
|
||||||
private static Random random = new Random();
|
private static Random random = new Random();
|
||||||
|
|
||||||
static void init(Configuration config){
|
static void init(Configuration config){
|
||||||
@ -32,6 +33,10 @@ public class ArenaMode {
|
|||||||
return chatNames;
|
return chatNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<ArenaMode> getAllModes(){
|
||||||
|
return allModes;
|
||||||
|
}
|
||||||
|
|
||||||
private final String internalName;
|
private final String internalName;
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
private final List<String> chatNames;
|
private final List<String> chatNames;
|
||||||
@ -45,6 +50,7 @@ public class ArenaMode {
|
|||||||
this.chatNames = config.getStringList("chatNames");
|
this.chatNames = config.getStringList("chatNames");
|
||||||
this.maps = config.getStringList("maps");
|
this.maps = config.getStringList("maps");
|
||||||
|
|
||||||
|
allModes.add(this);
|
||||||
byInternal.put(internalName, this);
|
byInternal.put(internalName, this);
|
||||||
for(String name : chatNames){
|
for(String name : chatNames){
|
||||||
byChat.put(name.toLowerCase(), this);
|
byChat.put(name.toLowerCase(), this);
|
||||||
|
@ -177,26 +177,15 @@ public class BauCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void testarena(ProxiedPlayer p, String[] command){
|
private static void testarena(ProxiedPlayer p, String[] command){
|
||||||
if (command.length == 2) {
|
FightCommand.createArena(p, "/bau testarena ", command, 2, (player, mode, map) -> ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||||
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(), () -> {
|
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
for (Subserver subserver : Subserver.getServerList()) {
|
||||||
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) {
|
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId())) {
|
||||||
subserver.stop();
|
subserver.stop();
|
||||||
break;
|
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){
|
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){
|
||||||
|
@ -18,68 +18,51 @@ public class ChallengeCommand extends BasicCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(args.length != 2){
|
if(args.length < 1){
|
||||||
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§8] §8[§7Spielmodus§8]");
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§8/§echallenge §8[§7Spieler§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.");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
ProxiedPlayer target = ProxyServer.getInstance().getPlayer(args[0]);
|
||||||
if(target == null){
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
subserver = Subserver.getSubserver(target);
|
Subserver subserver = Subserver.getSubserver(target);
|
||||||
if(subserver != null && subserver.getType() == Servertype.ARENA){
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArenaMode mode = ArenaMode.getByChat(args[1]);
|
FightCommand.createArena(sender, "/challenge " + target.getName() + " ", args, 1, (player, mode, map) -> {
|
||||||
if(mode == null){
|
if(challenges.containsKey(target) && challenges.get(target).contains(player)){
|
||||||
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + args[1]);
|
challenges.remove(target);
|
||||||
return;
|
challenges.remove(player);
|
||||||
}
|
|
||||||
|
|
||||||
String map = FightCommand.getMap(sender, mode, new String[0]);
|
Subserver arena = SubserverSystem.startArena(mode, map, 0, null, null, player.getUniqueId(), target.getUniqueId());
|
||||||
|
|
||||||
if(challenges.containsKey(target) && challenges.get(target).contains(player)){
|
arena.sendPlayer(player);
|
||||||
challenges.remove(target);
|
arena.sendPlayer(target);
|
||||||
challenges.remove(player);
|
|
||||||
|
|
||||||
Subserver arena = SubserverSystem.startArena(mode, map, 0, null, null, player.getUniqueId(), target.getUniqueId());
|
BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.getDisplayName() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(),
|
||||||
|
"§aZuschauen",
|
||||||
|
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
|
||||||
|
}else{
|
||||||
|
if(!challenges.containsKey(player)){
|
||||||
|
challenges.put(player, new LinkedList<>());
|
||||||
|
}
|
||||||
|
|
||||||
arena.sendPlayer(player);
|
challenges.get(player).add(target);
|
||||||
arena.sendPlayer(target);
|
|
||||||
|
|
||||||
BungeeCore.broadcast(BungeeCore.CHAT_PREFIX + "§e" + mode.getDisplayName() + "§7-§eDuell§7: " + player.getName() + " vs " + target.getName(),
|
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!");
|
||||||
"§aZuschauen",
|
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!");
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
|
|
||||||
}else{
|
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen",
|
||||||
if(!challenges.containsKey(player)){
|
"§aHerausforderung annehmen",
|
||||||
challenges.put(player, new LinkedList<>());
|
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName()));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
challenges.get(player).add(target);
|
|
||||||
|
|
||||||
BungeeCore.send(player, BungeeCore.CHAT_PREFIX + "§7Du hast §e" + target.getName() + " §7zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!");
|
|
||||||
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§e" + player.getName() + " §7 hat dich zu einem §e" + mode.getDisplayName() + "-Kampf §7herausgefordert!");
|
|
||||||
|
|
||||||
BungeeCore.send(target, BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um die Herausforderung anzunehmen",
|
|
||||||
"§aHerausforderung annehmen",
|
|
||||||
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/challenge " + player.getName() + " " + mode.getChatName()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void remove(ProxiedPlayer player){
|
public static void remove(ProxiedPlayer player){
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.*;
|
import de.steamwar.bungeecore.*;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.chat.ClickEvent;
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
@ -11,63 +12,125 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
|||||||
|
|
||||||
import java.util.LinkedList;
|
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 class FightCommand extends BasicCommand {
|
||||||
|
|
||||||
public FightCommand() {
|
public FightCommand() {
|
||||||
super("fight", "", "f");
|
super("fight", "", "f");
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getMap(CommandSender sender, ArenaMode mode, String[] args){
|
private static ArenaMode getMode(CommandSender sender, String arg){
|
||||||
if(args.length == 2){
|
ArenaMode mode = ArenaMode.getByChat(arg);
|
||||||
String realMap = mode.hasMap(args[1].toLowerCase());
|
if(mode != null)
|
||||||
if(realMap != null)
|
return mode;
|
||||||
return realMap;
|
|
||||||
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht.");
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cUnbekannter Spielmodus: " + arg);
|
||||||
return null;
|
return null;
|
||||||
}else{
|
}
|
||||||
|
|
||||||
|
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();
|
return mode.getRandomMap();
|
||||||
|
|
||||||
|
BungeeCore.send(sender, BungeeCore.CHAT_PREFIX + "§cDie gewünschte Arena gibt es nicht.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(args.length != 1 && args.length != 2){
|
createArena(sender, "/fight ", args, 0, (player, mode, map) -> {
|
||||||
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;
|
|
||||||
|
|
||||||
Subserver arena = SubserverSystem.startArena(mode, map, 0, null, null, player.getUniqueId(), null);
|
Subserver arena = SubserverSystem.startArena(mode, map, 0, null, null, player.getUniqueId(), null);
|
||||||
arena.sendPlayer(player);
|
arena.sendPlayer(player);
|
||||||
TextComponent tc = new TextComponent(BungeeCore.CHAT_PREFIX + "§7Klicke §ehier§7, um §e" + mode.getDisplayName() + " §7gegen §e" + player.getName() + " §7zu §7kämpfen!");
|
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.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()));
|
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()));
|
||||||
ProxyServer.getInstance().broadcast(tc);
|
ProxyServer.getInstance().broadcast(tc);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -82,4 +145,11 @@ public class FightCommand extends BasicCommand {
|
|||||||
}
|
}
|
||||||
return new LinkedList<>();
|
return new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is called when arena parameters are clear.
|
||||||
|
*/
|
||||||
|
interface FightCallback {
|
||||||
|
void run(ProxiedPlayer player, ArenaMode mode, String map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren