SteamWar/BungeeCore
Archiviert
13
2

WIP message deprecation
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2024-05-12 21:24:15 +02:00
Ursprung e1e1d66177
Commit 3b5be809dd
30 geänderte Dateien mit 598 neuen und 825 gelöschten Zeilen

Datei anzeigen

@ -61,6 +61,7 @@ public class BungeeCore extends Plugin {
public static boolean MAIN_SERVER; public static boolean MAIN_SERVER;
@Deprecated
public static String CHAT_PREFIX; public static String CHAT_PREFIX;
public static String LOBBY_SERVER; public static String LOBBY_SERVER;
public static boolean EVENT_MODE; public static boolean EVENT_MODE;
@ -214,21 +215,27 @@ public class BungeeCore extends Plugin {
return instance; return instance;
} }
@Deprecated
public static TextComponent stringToText(String msg){ public static TextComponent stringToText(String msg){
return new TextComponent(TextComponent.fromLegacyText(msg)); return new TextComponent(TextComponent.fromLegacyText(msg));
} }
@Deprecated
public static void send(ProxiedPlayer player, String msg){ public static void send(ProxiedPlayer player, String msg){
send(player, msg, null, null); send(player, msg, null, null);
} }
@Deprecated
public static void send(CommandSender sender, String msg){ public static void send(CommandSender sender, String msg){
sender.sendMessage(stringToText(msg)); sender.sendMessage(stringToText(msg));
} }
@Deprecated
public static void send(ProxiedPlayer player, ChatMessageType type, String msg){ public static void send(ProxiedPlayer player, ChatMessageType type, String msg){
send(player, type, msg, null, null); send(player, type, msg, null, null);
} }
@Deprecated
public static void send(ProxiedPlayer player, String msg, String onHover, ClickEvent onClick){ public static void send(ProxiedPlayer player, String msg, String onHover, ClickEvent onClick){
send(player, ChatMessageType.SYSTEM, msg, onHover, onClick); send(player, ChatMessageType.SYSTEM, msg, onHover, onClick);
} }
@Deprecated
public static void send(ProxiedPlayer player, ChatMessageType type, String msg, String onHover, ClickEvent onClick){ public static void send(ProxiedPlayer player, ChatMessageType type, String msg, String onHover, ClickEvent onClick){
if(type == ChatMessageType.CHAT && player.getChatMode() != ProxiedPlayer.ChatMode.SHOWN) if(type == ChatMessageType.CHAT && player.getChatMode() != ProxiedPlayer.ChatMode.SHOWN)
return; return;
@ -239,9 +246,11 @@ public class BungeeCore extends Plugin {
message.setClickEvent(onClick); message.setClickEvent(onClick);
player.sendMessage(type, message); player.sendMessage(type, message);
} }
@Deprecated
public static void broadcast(String msg){ public static void broadcast(String msg){
ProxyServer.getInstance().broadcast(stringToText(msg)); ProxyServer.getInstance().broadcast(stringToText(msg));
} }
@Deprecated
public static void broadcast(String msg, String onHover, ClickEvent onClick){ public static void broadcast(String msg, String onHover, ClickEvent onClick){
TextComponent message = stringToText(msg); TextComponent message = stringToText(msg);
if(onHover != null) if(onHover != null)
@ -251,18 +260,23 @@ public class BungeeCore extends Plugin {
ProxyServer.getInstance().broadcast(message); ProxyServer.getInstance().broadcast(message);
} }
@Deprecated
public static void log(final ServerInfo server, final String msg){ public static void log(final ServerInfo server, final String msg){
log(server.getName() + ": " + msg); log(server.getName() + ": " + msg);
} }
@Deprecated
public static void log(final ProxiedPlayer player, final String msg){ public static void log(final ProxiedPlayer player, final String msg){
log(player.getName() + ": " + msg); log(player.getName() + ": " + msg);
} }
@Deprecated
public static void log(final String msg){ public static void log(final String msg){
log(Level.INFO, msg); log(Level.INFO, msg);
} }
@Deprecated
public static void log(final Level logLevel, final String msg){ public static void log(final Level logLevel, final String msg){
get().getLogger().log(logLevel, msg); get().getLogger().log(logLevel, msg);
} }
@Deprecated
public static void log(final String msg, final Throwable e){ public static void log(final String msg, final Throwable e){
get().getLogger().log(Level.SEVERE, msg, e); get().getLogger().log(Level.SEVERE, msg, e);
} }

Datei anzeigen

@ -36,7 +36,7 @@ public abstract class Node {
"-XX:+EnableCRIUSupport", "-XX:-CRIURestoreNonPortableMode", "-XX:+EnableCRIUSupport", "-XX:-CRIURestoreNonPortableMode",
"-Xgc:excessiveGCratio=80", "-Xdisableexplicitgc", "-Xnoclassgc", "-Xmos128M", "-Xmns48M", "-XX:+ExitOnOutOfMemoryError", // initial heap half values of memory observed by 1.19 spectate server "-Xgc:excessiveGCratio=80", "-Xdisableexplicitgc", "-Xnoclassgc", "-Xmos128M", "-Xmns48M", "-XX:+ExitOnOutOfMemoryError", // initial heap half values of memory observed by 1.19 spectate server
"-Xsyslog:none", "-Xtrace:none", "-Xverify:none", "-Xdump:system:none", "-Xdump:jit:none", "-Xdump:snap:none", "-Xsyslog:none", "-Xtrace:none", "-Xverify:none", "-Xdump:system:none", "-Xdump:jit:none", "-Xdump:snap:none",
"-Dlog4j.configurationFile=log4j2.xml" "-XX:+EnableDynamicAgentLoading", "-Dlog4j.configurationFile=log4j2.xml"
); );
private static final Set<String> JAVA_8 = new HashSet<>(); private static final Set<String> JAVA_8 = new HashSet<>();
static { static {

Datei anzeigen

@ -2,7 +2,6 @@ package de.steamwar.bungeecore;
import de.steamwar.messages.Chatter; import de.steamwar.messages.Chatter;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import lombok.Getter;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -22,7 +21,7 @@ public class ServerStarter {
private static final Portrange BAU_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(10100, 20000) : new Portrange(2100, 2200); private static final Portrange BAU_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(10100, 20000) : new Portrange(2100, 2200);
private static final Portrange ARENA_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(3000, 3100) : (BungeeCore.EVENT_MODE ? new Portrange(4000, 5000) : BAU_PORTS); private static final Portrange ARENA_PORTS = BungeeCore.MAIN_SERVER ? new Portrange(3000, 3100) : (BungeeCore.EVENT_MODE ? new Portrange(4000, 5000) : BAU_PORTS);
private static final String SERVER_PATH = "/servers/"; public static final String SERVER_PATH = "/servers/";
private static final String USER_HOME = System.getProperty("user.home") + "/"; private static final String USER_HOME = System.getProperty("user.home") + "/";
private static final String EVENT_PATH = USER_HOME + "event/"; private static final String EVENT_PATH = USER_HOME + "event/";
public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/";
@ -114,11 +113,11 @@ public class ServerStarter {
return this; return this;
} }
public ServerStarter build(Version version, UUID owner) { public ServerStarter build(ServerVersion version, UUID owner) {
directory = version.getServerDirectory("Bau"); directory = version.getServerDirectory("Bau");
serverJar = version.getServerJar(); serverJar = version.getServerJar();
worldDir = version.getWorldFolder(WORLDS_BASE_PATH); worldDir = version.getWorldFolder(WORLDS_BASE_PATH);
worldName = version != Version.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); worldName = version != ServerVersion.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString();
checkpoint = true; checkpoint = true;
build(owner); build(owner);
@ -188,7 +187,7 @@ public class ServerStarter {
serverNameProvider = port -> bauServerName(SteamwarUser.get(owner)); serverNameProvider = port -> bauServerName(SteamwarUser.get(owner));
} }
public ServerStarter builder(Version version, String map, File generator) { public ServerStarter builder(ServerVersion version, String map, File generator) {
serverJar = version.getServerJar(); serverJar = version.getServerJar();
directory = version.getServerDirectory("Builder"); directory = version.getServerDirectory("Builder");
worldDir = version.getWorldFolder(BUILDER_BASE_PATH); worldDir = version.getWorldFolder(BUILDER_BASE_PATH);
@ -349,27 +348,4 @@ public class ServerStarter {
} }
} }
@Getter
public enum Version {
SPIGOT_12("spigot-1.12.2.jar", 12),
SPIGOT_15("spigot-1.15.2.jar", 15),
PAPER_19("paper-1.19.3.jar", 19),
PAPER_20("paper-1.20.1.jar", 20);
private final String serverJar;
private final int versionSuffix;
Version(String serverJar, int versionSuffix) {
this.serverJar = serverJar;
this.versionSuffix = versionSuffix;
}
public String getWorldFolder(String base) {
return base + versionSuffix + "/";
}
public File getServerDirectory(String base) {
return new File(SERVER_PATH, base + versionSuffix);
}
}
} }

Datei anzeigen

@ -0,0 +1,87 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore;
import lombok.Getter;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Getter
public enum ServerVersion {
SPIGOT_12("spigot-1.12.2.jar", 12),
SPIGOT_15("spigot-1.15.2.jar", 15),
PAPER_19("paper-1.19.3.jar", 19),
PAPER_20("paper-1.20.1.jar", 20);
private static final Map<String, ServerVersion> chatMap = new HashMap<>();
static {
chatMap.put("20", ServerVersion.PAPER_20);
chatMap.put("1.20", ServerVersion.PAPER_20);
chatMap.put("1.20.1", ServerVersion.PAPER_20);
chatMap.put("as", ServerVersion.PAPER_20);
chatMap.put("airship", ServerVersion.PAPER_20);
chatMap.put("wg", ServerVersion.PAPER_20);
chatMap.put("wargear", ServerVersion.PAPER_20);
chatMap.put("ws", ServerVersion.PAPER_20);
chatMap.put("warship", ServerVersion.PAPER_20);
chatMap.put("mwg", ServerVersion.PAPER_20);
chatMap.put("miniwargear", ServerVersion.PAPER_20);
chatMap.put("19", ServerVersion.PAPER_19);
chatMap.put("1.19", ServerVersion.PAPER_19);
chatMap.put("1.19.2", ServerVersion.PAPER_19);
chatMap.put("15", ServerVersion.SPIGOT_15);
chatMap.put("1.15", ServerVersion.SPIGOT_15);
chatMap.put("1.15.2", ServerVersion.SPIGOT_15);
chatMap.put("12", ServerVersion.SPIGOT_12);
chatMap.put("1.12", ServerVersion.SPIGOT_12);
chatMap.put("1.12.2", ServerVersion.SPIGOT_12);
}
public static ServerVersion get(String chat) {
return chatMap.get(chat.toLowerCase());
}
public static Set<String> chatVersions() {
return chatMap.keySet();
}
private final String serverJar;
private final int versionSuffix;
ServerVersion(String serverJar, int versionSuffix) {
this.serverJar = serverJar;
this.versionSuffix = versionSuffix;
}
public String getWorldFolder(String base) {
return base + versionSuffix + "/";
}
public File getServerDirectory(String base) {
return new File(ServerStarter.SERVER_PATH, base + versionSuffix);
}
}

Datei anzeigen

@ -0,0 +1,63 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.bot.util;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.messages.Chatter;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import java.awt.*;
import java.time.Instant;
@UtilityClass
public class DiscordAlert {
public static void send(Chatter player, Color color, Message title, Message description, boolean success) {
Long discordId = player.user().getDiscordId();
if(SteamwarDiscordBot.instance() == null || discordId == null)
return;
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(discordId).complete();
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
builder.setColor(color);
builder.setTitle(player.parseToPlain(title));
builder.setDescription(player.parseToPlain(description));
builder.setTimestamp(Instant.now());
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.setEmbeds(builder.build());
if(success)
messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
try {
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
} catch (Exception e) {
// Ignored
}
}
}

Datei anzeigen

@ -1,79 +0,0 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bungeecore.bot.util;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Emoji;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.interactions.components.ActionRow;
import net.dv8tion.jda.api.interactions.components.Button;
import java.awt.*;
import java.time.Instant;
@UtilityClass
public class DiscordSchemAlert {
public void sendDecline(SchematicNode schematic, SteamwarUser user, String reason) {
if(user.getDiscordId() != null) {
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
builder.setColor(Color.RED);
builder.setTitle("SteamWar-Schematic Info");
builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde abgelehnt. **Grund:** \n" + reason);
builder.setTimestamp(Instant.now());
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.setEmbeds(builder.build());
try {
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
} catch (Exception e) {
// Ignored
}
}
}
public void sendAccept(SchematicNode schematic, SteamwarUser user) {
if(user.getDiscordId() != null) {
User dcUser = SteamwarDiscordBot.instance().getJda().retrieveUserById(user.getDiscordId()).complete();
EmbedBuilder builder = new EmbedBuilder();
builder.setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png");
builder.setColor(Color.GREEN);
builder.setTitle("SteamWar-Schematic Info");
builder.setDescription("Deine Schematic **" + schematic.getName() + "** wurde angenommen.");
builder.setTimestamp(Instant.now());
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.setEmbeds(builder.build());
messageBuilder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389"))));
try {
dcUser.openPrivateChannel().complete().sendMessage(messageBuilder.build()).queue();
} catch (Exception e) {
// Ignored
}
}
}
}

Datei anzeigen

@ -21,6 +21,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.Subserver;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
@ -60,7 +61,7 @@ public class ArenaCommand extends SWCommand {
} }
@Override @Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) { public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
List<Subserver> subserverList = Subserver.getServerList(); List<Subserver> subserverList = Subserver.getServerList();
synchronized (subserverList) { synchronized (subserverList) {
return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList()); return subserverList.stream().filter(subserver -> subserver.getType() == Servertype.ARENA).map(subserver -> subserver.getServer().getName()).collect(Collectors.toList());

Datei anzeigen

@ -36,13 +36,10 @@ import de.steamwar.sql.BauweltMember;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
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.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.function.Consumer;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BauCommand extends SWCommand { public class BauCommand extends SWCommand {
@ -60,68 +57,15 @@ public class BauCommand extends SWCommand {
} }
@Register @Register
public void toBau(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) { public void toBau(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) {
new ServerStarter().build(version, p.getUniqueId()).send(p).start(); new ServerStarter().build(version, p.getUniqueId()).send(p).start();
} }
@Mapper(value = "version", local = true)
public TypeMapper<ServerStarter.Version> versionMapper() {
Map<String, ServerStarter.Version> versionMap = new HashMap<>();
versionMap.put("20", ServerStarter.Version.PAPER_20);
versionMap.put("1.20", ServerStarter.Version.PAPER_20);
versionMap.put("as", ServerStarter.Version.PAPER_20);
versionMap.put("airship", ServerStarter.Version.PAPER_20);
versionMap.put("wg", ServerStarter.Version.PAPER_20);
versionMap.put("wargear", ServerStarter.Version.PAPER_20);
versionMap.put("ws", ServerStarter.Version.PAPER_20);
versionMap.put("warship", ServerStarter.Version.PAPER_20);
versionMap.put("19", ServerStarter.Version.PAPER_19);
versionMap.put("1.19", ServerStarter.Version.PAPER_19);
versionMap.put("mwg", ServerStarter.Version.PAPER_19);
versionMap.put("miniwargear", ServerStarter.Version.PAPER_19);
versionMap.put("15", ServerStarter.Version.SPIGOT_15);
versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
versionMap.put("12", ServerStarter.Version.SPIGOT_12);
versionMap.put("1.12", ServerStarter.Version.SPIGOT_12);
return new TypeMapper<ServerStarter.Version>() {
@Override
public ServerStarter.Version 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 > 762) { // Version > 1.19.4
return ServerStarter.Version.PAPER_20;
} else if (version > 578) { // Version > 1.15.2
return ServerStarter.Version.PAPER_19;
} else if (version > 340) { // Version > 1.12.2
return ServerStarter.Version.SPIGOT_15;
} else {
return ServerStarter.Version.SPIGOT_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") @Register(value = "addmember", description = "BAU_ADDMEMBER_USAGE")
public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) { public void addmember(ProxiedPlayer p, @Validator("addMemberTarget") SteamwarUser target) {
BauweltMember.addMember(p.getUniqueId(), target.getUUID()); BauweltMember.addMember(p.getUniqueId(), target.getUUID());
Message.send("BAU_ADDMEMBER_ADDED", p); Chatter.of(p).system("BAU_ADDMEMBER_ADDED");
Chatter.of(target.getUUID()).system("BAU_ADDMEMBER_ADDED_TARGET", p);
ProxiedPlayer z = ProxyServer.getInstance().getPlayer(target.getUUID());
if(z != null)
Message.send("BAU_ADDMEMBER_ADDED_TARGET", z, p.getName());
} }
@Validator(value = "addMemberTarget", local = true) @Validator(value = "addMemberTarget", local = true)
@ -145,7 +89,7 @@ public class BauCommand extends SWCommand {
@Register(value = "tp", description = "BAU_TP_USAGE") @Register(value = "tp", description = "BAU_TP_USAGE")
@Register("teleport") @Register("teleport")
public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) { public void teleport(ProxiedPlayer p, @Validator("teleportTarget") SteamwarUser worldOwner, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) {
new ServerStarter().build(version, worldOwner.getUUID()).send(p).start(); new ServerStarter().build(version, worldOwner.getUUID()).send(p).start();
} }
@ -173,83 +117,64 @@ public class BauCommand extends SWCommand {
@Register("setspectator") @Register("setspectator")
public void setSpectator(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { public void setSpectator(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) {
if (user == null) { setPerms(p, user, "setspectator", "BAU_MEMBER_SET_SPECTATOR", member -> {
Message.send("BAU_MEMBER_SET_USAGE", p, "setspectator"); member.setBuild(false);
return; member.setSupervisor(false);
} });
BauweltMember target = member(p, user);
if (target == null)
return;
target.setBuild(false);
target.setSupervisor(false);
clearMembercache(p);
sendPermissionUpdate(p, target, "BAU_MEMBER_SET_SPECTATOR");
} }
@Register("setbuild") @Register("setbuild")
public void setBuild(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { public void setBuild(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) {
if (user == null) { setPerms(p, user, "setbuild", "BAU_MEMBER_SET_BUILDER", member -> {
Message.send("BAU_MEMBER_SET_USAGE", p, "setbuild"); member.setBuild(true);
return; member.setSupervisor(false);
} });
BauweltMember target = member(p, user);
if (target == null)
return;
target.setBuild(true);
target.setSupervisor(false);
clearMembercache(p);
sendPermissionUpdate(p, target, "BAU_MEMBER_SET_BUILDER");
} }
@Register("setsupervisor") @Register("setsupervisor")
public void setSupervisor(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) { public void setSupervisor(ProxiedPlayer p, @Mapper("addedUsers") @AllowNull @OptionalValue("") SteamwarUser user) {
setPerms(p, user, "setsupervisor", "BAU_MEMBER_SET_SUPERVISOR", member -> {
member.setBuild(true);
member.setSupervisor(true);
});
}
private void setPerms(ProxiedPlayer p, SteamwarUser user, String name, String permName, Consumer<BauweltMember> setter) {
Chatter owner = Chatter.of(p);
if (user == null) { if (user == null) {
Message.send("BAU_MEMBER_SET_USAGE", p, "setsupervisor"); owner.system("BAU_MEMBER_SET_USAGE", name);
return; return;
} }
BauweltMember target = member(p, user);
if (target == null)
return;
target.setBuild(true); withMember(owner, user, target -> {
target.setSupervisor(true); setter.accept(target);
clearMembercache(p);
sendPermissionUpdate(p, target, "BAU_MEMBER_SET_SUPERVISOR");
}
private static void clearMembercache(ProxiedPlayer p){ Bauserver bauserver = Bauserver.get(p.getUniqueId());
for(ServerInfo info : ProxyServer.getInstance().getServers().values()){ if(bauserver != null)
Subserver server = Subserver.getSubserver(info); bauserver.getServer().getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket()));
if(server != null && server.getType() == Servertype.BAUSERVER && ((Bauserver)server).getOwner().equals(p.getUniqueId())){
info.getPlayers().stream().findAny().ifPresent(player -> NetworkSender.send(player, new BaumemberUpdatePacket())); Chatter.of(user.getUUID()).system("BAU_MEMBER_SET_TARGET", p.getName(), new Message(permName));
break; owner.system("BAU_MEMBER_SET", new Message(permName));
} });
}
} }
@Register(value = "delmember", description = "BAU_DELMEMBER_USAGE") @Register(value = "delmember", description = "BAU_DELMEMBER_USAGE")
public void delmember(ProxiedPlayer p, @Mapper("addedUsers") SteamwarUser user) { public void delmember(ProxiedPlayer p, @Mapper("addedUsers") SteamwarUser user) {
BauweltMember target = member(p, user); Chatter owner = Chatter.of(p);
if (target == null) withMember(owner, user, target -> {
return;
if(SteamwarUser.get(target.getMemberID()).getUUID().equals(p.getUniqueId())) {
Message.send("BAU_DELMEMBER_SELFDEL", p);
return;
}
target.remove(); target.remove();
ProxiedPlayer toRemove = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
if(toRemove != null){ Chatter member = Chatter.of(user.getUUID());
Message.send("BAU_DELMEMBER_DELETED_TARGET", toRemove, p.getName()); member.system("BAU_DELMEMBER_DELETED_TARGET", p);
member.withPlayer(toRemove -> {
Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo()); Subserver currentServer = Subserver.getSubserver(toRemove.getServer().getInfo());
if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) { if (currentServer != null && currentServer.getType() == Servertype.BAUSERVER && ((Bauserver) currentServer).getOwner().equals(p.getUniqueId())) {
toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER)); toRemove.connect(ProxyServer.getInstance().getServerInfo(BungeeCore.LOBBY_SERVER));
} }
} });
Message.send("BAU_DELMEMBER_DELETED", p);
owner.system("BAU_DELMEMBER_DELETED");
});
} }
@Mapper(value = "addedUsers", local = true) @Mapper(value = "addedUsers", local = true)
@ -262,10 +187,8 @@ public class BauCommand extends SWCommand {
@Override @Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
if (!(sender instanceof ProxiedPlayer)) return Collections.emptyList(); return BauweltMember.getMembers(Chatter.of(sender).user().getId()).stream()
return BauweltMember.getMembers(((ProxiedPlayer) sender).getUniqueId()).stream() .map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()).getUserName())
.map(bauweltMember -> SteamwarUser.get(bauweltMember.getMemberID()))
.map(steamwarUser -> steamwarUser.getUserName())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
}; };
@ -273,39 +196,34 @@ public class BauCommand extends SWCommand {
@Register("resetall") @Register("resetall")
@Register("delete") @Register("delete")
public void delete(ProxiedPlayer p, @Mapper("version") @OptionalValue(value = "", onlyUINIG = true) ServerStarter.Version version) { public void delete(ProxiedPlayer p, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) {
deleteConfirmation(p, () -> deleteWorld(p, version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerStarter.Version.SPIGOT_12 ? SteamwarUser.get(p.getUniqueId()).getId() : p.getUniqueId().toString()))); Chatter player = Chatter.of(p);
}
private static void deleteConfirmation(ProxiedPlayer p, Runnable worldDeletion) { SWInventory inventory = new SWInventory(player, 9, new Message("BAU_DELETE_GUI_NAME"));
SWInventory inventory = new SWInventory(p, 9, Message.parse("BAU_DELETE_GUI_NAME", p)); inventory.addItem(0, new SWItem(new Message("BAU_DELETE_GUI_DELETE"), 10), click -> {
inventory.addItem(8, new SWItem(Message.parse("BAU_DELETE_GUI_CANCEL", p), 1), click -> String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? player.user().getId() : p.getUniqueId().toString());
inventory.close()
);
inventory.addItem(0, new SWItem(Message.parse("BAU_DELETE_GUI_DELETE", p), 10), click -> {
worldDeletion.run();
inventory.close();
});
inventory.open();
}
private static void deleteWorld(ProxiedPlayer player, String world) {
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
Bauserver subserver = Bauserver.get(player.getUniqueId()); Bauserver subserver = Bauserver.get(p.getUniqueId());
if(subserver != null) if(subserver != null)
subserver.stop(); subserver.stop();
SubserverSystem.deleteFolder(BungeeCore.local, world); SubserverSystem.deleteFolder(BungeeCore.local, world);
Message.send("BAU_DELETE_DELETED", player); player.system("BAU_DELETE_DELETED");
}); });
inventory.close();
});
inventory.addItem(8, new SWItem(new Message("BAU_DELETE_GUI_CANCEL"), 1), click -> inventory.close());
inventory.open();
} }
@Register("test") @Register("test")
@Register("testarena") @Register("testarena")
public void testarena(ProxiedPlayer p, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { 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) -> { FightCommand.createArena(p, "/bau testarena ", false, arenaMode, map, false, (player, mode, m) ->
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start()); ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> new ServerStarter().test(mode, m, p).start())
}); );
} }
@Register(value = "lock", description = "BAU_LOCKED_OPTIONS") @Register(value = "lock", description = "BAU_LOCKED_OPTIONS")
@ -318,24 +236,18 @@ public class BauCommand extends SWCommand {
BauLock.setLocked(p, BauLockState.OPEN); BauLock.setLocked(p, BauLockState.OPEN);
} }
private static BauweltMember member(ProxiedPlayer p, SteamwarUser member){ private static void withMember(Chatter owner, SteamwarUser member, Consumer<BauweltMember> function) {
if (member == null) { if (member == null) {
Message.send("UNKNOWN_PLAYER", p); owner.system("UNKNOWN_PLAYER");
return null; return;
} }
BauweltMember target = BauweltMember.getBauMember(p.getUniqueId(), member.getUUID()); BauweltMember target = BauweltMember.getBauMember(owner.user().getId(), member.getId());
if (target == null) { if (target == null) {
Message.send("BAU_MEMBER_NOMEMBER", p); owner.system("BAU_MEMBER_NOMEMBER");
return null; return;
}
return target;
} }
private static void sendPermissionUpdate(ProxiedPlayer p, BauweltMember target, String what){ function.accept(target);
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(SteamwarUser.get(target.getMemberID()).getUUID());
if(player != null)
Message.send("BAU_MEMBER_SET_TARGET", player, p.getName(), Message.parse(what, player));
Message.send("BAU_MEMBER_SET", p, Message.parse(what, p));
} }
} }

Datei anzeigen

@ -3,7 +3,9 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.ServerStarter; import de.steamwar.bungeecore.ServerStarter;
import de.steamwar.bungeecore.ServerVersion;
import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.command.PreviousArguments;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import de.steamwar.messages.Chatter; import de.steamwar.messages.Chatter;
@ -19,30 +21,18 @@ import java.util.stream.Collectors;
public class BuilderCloudCommand extends SWCommand { public class BuilderCloudCommand extends SWCommand {
private final Map<String, ServerStarter.Version> versionMap = new HashMap<>();
public BuilderCloudCommand() { public BuilderCloudCommand() {
super("buildercloud", ConnectionListener.BUILDERCLOUD_PERMISSION, "builder"); super("buildercloud", ConnectionListener.BUILDERCLOUD_PERMISSION, "builder");
versionMap.put("15", ServerStarter.Version.SPIGOT_15);
versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
versionMap.put("1.15.2", ServerStarter.Version.SPIGOT_15);
versionMap.put("19", ServerStarter.Version.PAPER_19);
versionMap.put("1.19", ServerStarter.Version.PAPER_19);
versionMap.put("1.19.2", ServerStarter.Version.PAPER_19);
versionMap.put("20", ServerStarter.Version.PAPER_20);
versionMap.put("1.20", ServerStarter.Version.PAPER_20);
versionMap.put("1.20.1", ServerStarter.Version.PAPER_20);
} }
@Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE") @Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE")
public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) {
mapFile(version, map).mkdir(); mapFile(version, map).mkdir();
new ServerStarter().builder(version, map, generator).send(player).start(); new ServerStarter().builder(version, map, generator).send(player).start();
} }
@Register(description = "BUILDERCLOUD_USAGE") @Register(description = "BUILDERCLOUD_USAGE")
public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) {
if(!mapFile(version, map).exists()) { if(!mapFile(version, map).exists()) {
Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP");
return; return;
@ -52,7 +42,7 @@ public class BuilderCloudCommand extends SWCommand {
} }
@Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE") @Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE")
public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String oldName, String newName) { public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String oldName, String newName) {
File oldMap = mapFile(version, oldName); File oldMap = mapFile(version, oldName);
if(!oldMap.exists()) { if(!oldMap.exists()) {
Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP");
@ -75,7 +65,7 @@ public class BuilderCloudCommand extends SWCommand {
} }
@Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE")
public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerVersion version, @Mapper("map") String map) {
if(!mapFile(version, map).exists()) { if(!mapFile(version, map).exists()) {
Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); Chatter.of(player).system("BUILDERCLOUD_UNKNOWN_MAP");
return; return;
@ -88,21 +78,6 @@ public class BuilderCloudCommand extends SWCommand {
}); });
} }
@ClassMapper(value = ServerStarter.Version.class, local = true)
private TypeMapper<ServerStarter.Version> versionTypeMapper() {
return new TypeMapper<ServerStarter.Version>() {
@Override
public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) {
return versionMap.get(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
return versionMap.keySet();
}
};
}
@Cached(global = true) @Cached(global = true)
@Mapper(value = "map", local = true) @Mapper(value = "map", local = true)
private TypeMapper<String> mapTypeMapper() { private TypeMapper<String> mapTypeMapper() {
@ -114,8 +89,8 @@ public class BuilderCloudCommand extends SWCommand {
} }
@Override @Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) { public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
File folder = getWorldFolder(previousArguments, 1); File folder = getWorldFolder(previousArguments.userArgs, 1);
String[] files; String[] files;
if(folder == null || (files = folder.list()) == null) if(folder == null || (files = folder.list()) == null)
@ -133,7 +108,7 @@ public class BuilderCloudCommand extends SWCommand {
return new TypeMapper<File>() { return new TypeMapper<File>() {
@Override @Override
public File map(CommandSender commandSender, String[] previousArguments, String s) { public File map(CommandSender commandSender, String[] previousArguments, String s) {
if(s.equals("")) if(s.isEmpty())
return null; return null;
File folder = getWorldFolder(previousArguments, 2); File folder = getWorldFolder(previousArguments, 2);
@ -149,8 +124,8 @@ public class BuilderCloudCommand extends SWCommand {
} }
@Override @Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) { public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
File folder = getWorldFolder(previousArguments, 2); File folder = getWorldFolder(previousArguments.userArgs, 2);
String[] files; String[] files;
if(folder == null || (files = folder.list()) == null) if(folder == null || (files = folder.list()) == null)
@ -161,12 +136,12 @@ public class BuilderCloudCommand extends SWCommand {
}; };
} }
private File mapFile(ServerStarter.Version version, String map) { private File mapFile(ServerVersion version, String map) {
return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map); return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map);
} }
private File getWorldFolder(String[] previousArguments, int offset) { private File getWorldFolder(String[] previousArguments, int offset) {
ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]); ServerVersion v = ServerVersion.get(previousArguments[previousArguments.length - offset]);
if(v == null) if(v == null)
return null; return null;
return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH)); return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH));

Datei anzeigen

@ -20,11 +20,11 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.bot.util.DiscordSchemAlert; import de.steamwar.bungeecore.bot.util.DiscordAlert;
import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter; import de.steamwar.messages.Chatter;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
@ -33,24 +33,23 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import java.awt.*;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.List;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
public class CheckCommand extends SWCommand { public class CheckCommand extends SWCommand {
private static final Map<SchematicType, SchematicType> fightTypes = new HashMap<>(); private static final Map<SchematicType, SchematicType> fightTypes = new HashMap<>();
private static Map<SchematicType, List<String>> checkQuestions = new HashMap<>(); private static final Map<SchematicType, List<String>> checkQuestions = new HashMap<>();
private static Map<SchematicType, List<String>> ranks = new HashMap<>();
private static Map<UUID, CheckSession> currentCheckers = new HashMap<>(); private static final Map<UUID, CheckSession> currentCheckers = new HashMap<>();
private static Map<Integer, CheckSession> currentSchems = new HashMap<>(); private static final Map<Integer, CheckSession> currentSchems = new HashMap<>();
public static void setCheckQuestions(SchematicType checkType, Configuration config) { public static void setCheckQuestions(SchematicType checkType, Configuration config) {
checkQuestions.put(checkType, config.getStringList("CheckQuestions")); checkQuestions.put(checkType, config.getStringList("CheckQuestions"));
if(!config.getStringList("Ranks").isEmpty())
ranks.put(checkType, config.getStringList("Ranks"));
} }
public static void addFightType(SchematicType checkType, SchematicType fightType) { public static void addFightType(SchematicType checkType, SchematicType fightType) {
@ -102,9 +101,9 @@ public class CheckCommand extends SWCommand {
} else { } else {
chatter.prefixless("CHECK_LIST_CHECKING", chatter.prefixless("CHECK_LIST_CHECKING",
new Message("CHECK_LIST_CHECKING_HOVER"), new Message("CHECK_LIST_CHECKING_HOVER"),
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.getName()), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + current.checker.user().getUserName()),
waitTime, waitTime,
schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.getName()); schematic.getSchemtype().getKuerzel(), SteamwarUser.get(schematic.getOwner()).getUserName(), schematic.getName(), current.checker.user().getUserName());
} }
} }
} }
@ -120,7 +119,7 @@ public class CheckCommand extends SWCommand {
SteamwarUser checkingUser = SteamwarUser.get(player.getUniqueId()); SteamwarUser checkingUser = SteamwarUser.get(player.getUniqueId());
SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID)); SchematicNode schem = SchematicNode.getSchematicNode(Integer.parseInt(schemID));
if(!schem.getSchemtype().check()){ if(!schem.getSchemtype().check()){
ProxyServer.getInstance().getLogger().log(Level.SEVERE, player.getName() + " tried to check an uncheckable schematic!"); ProxyServer.getInstance().getLogger().log(Level.SEVERE, () -> player.getName() + " tried to check an uncheckable schematic!");
return; return;
}else if(schem.getOwner() == checkingUser.getId()) { }else if(schem.getOwner() == checkingUser.getId()) {
chatter.system("CHECK_SCHEMATIC_OWN"); chatter.system("CHECK_SCHEMATIC_OWN");
@ -151,16 +150,15 @@ public class CheckCommand extends SWCommand {
@Register(value = "next", description = "CHECK_HELP_NEXT") @Register(value = "next", description = "CHECK_HELP_NEXT")
public void next(ProxiedPlayer player) { public void next(ProxiedPlayer player) {
next(player, new String[0]); if(notChecking(player))
return;
currentCheckers.get(player.getUniqueId()).next();
} }
@Register(value = "accept") @Register(value = "accept")
public void accept(ProxiedPlayer player, @OptionalValue("") String rank) { public void accept(ProxiedPlayer player, @OptionalValue("") String rank) {
if (rank.equals("")) { next(player);
next(player, new String[0]);
} else {
next(player, new String[]{rank});
}
} }
@Register(value = "decline", description = "CHECK_HELP_DECLINE") @Register(value = "decline", description = "CHECK_HELP_DECLINE")
@ -176,14 +174,14 @@ public class CheckCommand extends SWCommand {
for (SchematicType type : SchematicType.values()) { for (SchematicType type : SchematicType.values()) {
if (type.check()) if (type.check())
schematicList.addAll(SchematicNode.getAllSchematicsOfType(type.toDB())); schematicList.addAll(SchematicNode.getAllSchematicsOfType(type));
} }
return schematicList; return schematicList;
} }
public static String getChecker(SchematicNode schematic) { public static String getChecker(SchematicNode schematic) {
if (currentSchems.get(schematic.getId()) == null) return null; if (currentSchems.get(schematic.getId()) == null) return null;
return currentSchems.get(schematic.getId()).checker.getName(); return currentSchems.get(schematic.getId()).checker.user().getUserName();
} }
private static boolean notChecking(ProxiedPlayer player){ private static boolean notChecking(ProxiedPlayer player){
@ -194,23 +192,6 @@ public class CheckCommand extends SWCommand {
return false; return false;
} }
private void next(ProxiedPlayer player, String[] args){
if(notChecking(player))
return;
int rank = 0;
if(args.length > 0){
try{
rank = Integer.parseInt(args[0]);
}catch(NumberFormatException e){
Chatter.of(player).system("CHECK_INVALID_RANK");
return;
}
}
currentCheckers.get(player.getUniqueId()).next(rank);
}
private static class CheckSession{ private static class CheckSession{
private final Chatter checker; private final Chatter checker;
private final SchematicNode schematic; private final SchematicNode schematic;
@ -234,13 +215,13 @@ public class CheckCommand extends SWCommand {
currentSchems.put(schematic.getId(), this); currentSchems.put(schematic.getId(), this);
for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic)) for(CheckedSchematic previous : CheckedSchematic.previousChecks(schematic))
checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason()); checker.prefixless("CHECK_SCHEMATIC_PREVIOUS", previous.getEndTime(), SteamwarUser.get(previous.getValidator()).getUserName(), previous.getDeclineReason());
next(0); next();
})); }));
} }
private void next(int rank) { private void next() {
if(!checkList.hasNext()){ if(!checkList.hasNext()){
accept(rank); accept();
return; return;
} }
@ -249,95 +230,67 @@ public class CheckCommand extends SWCommand {
TextComponent next = new TextComponent(); TextComponent next = new TextComponent();
next.setColor(ChatColor.GREEN); next.setColor(ChatColor.GREEN);
if(checkList.hasNext()){ if(checkList.hasNext()){
next.setText(Message.parse("CHECK_NEXT", checker)); next.setText(checker.parseToPlain("CHECK_NEXT"));
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next")); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check next"));
}else if(ranks.containsKey(schematic.getSchemtype())){
List<String> r = ranks.get(schematic.getSchemtype());
for(int i = 0; i < r.size(); i++){
Message.sendPrefixless("CHECK_RANK", checker,
Message.parse("CHECK_RANK_HOVER", checker),
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept " + (i+1)),
i+1, r.get(i));
Message.sendPrefixless("SPACER", checker);
}
}else{ }else{
next.setText(Message.parse("CHECK_ACCEPT", checker)); next.setText(checker.parseToPlain("CHECK_ACCEPT"));
next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept")); next.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/check accept"));
} }
TextComponent decline = new TextComponent(" " + Message.parse("CHECK_DECLINE", checker)); TextComponent decline = new TextComponent(" " + checker.parseToPlain("CHECK_DECLINE"));
decline.setColor(ChatColor.RED); decline.setColor(ChatColor.RED);
decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline ")); decline.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/check decline "));
next.addExtra(decline); next.addExtra(decline);
checker.sendMessage(next); checker.sendMessage(ChatMessageType.SYSTEM, next);
} }
private void accept(int rank){ private void accept(){
if(createLog("freigegeben")) { if(concludeCheckSession("freigegeben", fightTypes.get(schematic.getSchemtype()))) {
if(ranks.containsKey(schematic.getSchemtype())){ Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
if(rank <= 0 || ranks.get(schematic.getSchemtype()).size() < rank){ owner.withPlayerOrDiscord(
checker.system("CHECK_INVALID_RANK"); player -> owner.system("CHECK_ACCEPTED", schematic.getSchemtype().name(), schematic.getName()),
return; user -> DiscordAlert.send(owner, Color.GREEN, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_ACCEPT", schematic.getName()), true)
);
Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), owner.user().getUserName());
} }
schematic.setRank(rank);
}
schematic.setType(fightTypes.get(schematic.getSchemtype()).toDB());
SteamwarUser user = SteamwarUser.get(schematic.getOwner());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID());
if(player != null) {
Message.send("CHECK_ACCEPTED", player, schematic.getSchemtype().name(), schematic.getName());
} else {
DiscordSchemAlert.sendAccept(schematic, user);
}
Chatter.serverteam().system("CHECK_ACCEPTED_TEAM", schematic.getName(), user.getUserName());
}
stop();
} }
private void decline(String reason){ private void decline(String reason){
if(createLog(reason)) { if(concludeCheckSession(reason, SchematicType.Normal)) {
SteamwarUser user = SteamwarUser.get(schematic.getOwner()); Chatter owner = Chatter.of(SteamwarUser.get(schematic.getOwner()).getUUID());
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(user.getUUID()); owner.withPlayerOrDiscord(
if(player != null) { player -> owner.system("CHECK_DECLINED", schematic.getSchemtype().name(), schematic.getName(), reason),
Message.send("CHECK_DECLINED", player, schematic.getSchemtype().name(), schematic.getName(), reason); user -> DiscordAlert.send(owner, Color.RED, new Message("DC_TITLE_SCHEMINFO"), new Message("DC_SCHEM_DECLINE", schematic.getName(), reason), false)
} else { );
DiscordSchemAlert.sendDecline(schematic, user, reason); Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), owner.user().getUserName(), reason);
} }
Chatter.serverteam().system("CHECK_DECLINED_TEAM", schematic.getName(), user.getUserName(), reason);
schematic.setType(SchematicType.Normal.toDB());
}
stop();
} }
private void abort(){ private void abort(){
createLog("Prüfvorgang abgebrochen"); concludeCheckSession("Prüfvorgang abgebrochen", null);
stop();
} }
private void stop(){ private boolean concludeCheckSession(String reason, SchematicType type) {
currentCheckers.remove(checker.getUniqueId());
currentSchems.remove(schematic.getId());
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
Bauserver subserver = Bauserver.get(checker.getUniqueId());
if(subserver != null)
subserver.stop();
});
}
private void remove() {
currentCheckers.remove(checker.getUniqueId());
currentSchems.remove(schematic.getId());
}
private boolean createLog(String reason) {
if(SchematicNode.getSchematicNode(schematic.getId()) == null) // Schematic was deleted if(SchematicNode.getSchematicNode(schematic.getId()) == null) // Schematic was deleted
return false; return false;
CheckedSchematic.create(schematic, SteamwarUser.get(checker.getUniqueId()).getId(), startTime, Timestamp.from(Instant.now()), reason); CheckedSchematic.create(schematic, checker.user().getId(), startTime, Timestamp.from(Instant.now()), reason);
if(type != null)
schematic.setSchemtype(type);
remove();
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
Bauserver subserver = Bauserver.get(checker.user().getUUID());
if(subserver != null)
subserver.stop();
});
return true; return true;
} }
private void remove() {
currentCheckers.remove(checker.user().getUUID());
currentSchems.remove(schematic.getId());
}
} }
} }

Datei anzeigen

@ -19,19 +19,18 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.EventStarter;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.SubserverSystem;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.messages.Chatter; import de.steamwar.messages.Chatter;
import de.steamwar.sql.*; import de.steamwar.sql.*;
import de.steamwar.command.SWCommand; import net.md_5.bungee.api.CommandSender;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import de.steamwar.command.TypeValidator;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.time.Instant; import java.time.Instant;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -48,91 +47,75 @@ public class EventCommand extends SWCommand {
} }
@Register @Register
public void noCurrentEvent(@Validator("noEvent") ProxiedPlayer player){ public void noCurrentEvent(@Validator("noEvent") CommandSender sender) {
Message.send("EVENT_NO_CURRENT", player); Chatter player = Chatter.of(sender);
player.system("EVENT_NO_CURRENT");
List<Event> coming = Event.getComing(); List<Event> coming = Event.getComing();
if(coming.isEmpty())
return;
player.system("EVENT_COMING");
Instant now = Instant.now(); Instant now = Instant.now();
if(!coming.isEmpty()){ DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_DATE_FORMAT"));
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_DATE_FORMAT", player));
Message.send("EVENT_COMING", player);
for(Event e : coming){ for(Event e : coming){
Message.send("EVENT_COMING_EVENT", player, e.getStart().toLocalDateTime().format(dateFormat), e.getEnd().toLocalDateTime().format(dateFormat), e.getEventName()); player.prefixless("EVENT_COMING_EVENT", e.getStart().toLocalDateTime().format(format), e.getEnd().toLocalDateTime().format(format), e.getEventName());
Set<Team> teams = TeamTeilnahme.getTeams(e.getEventID());
if(now.isBefore(e.getDeadline().toInstant())) { if(now.isBefore(e.getDeadline().toInstant()))
Message.send("EVENT_COMING_DEADLINE", player, e.getDeadline()); player.prefixless("EVENT_COMING_DEADLINE", e.getDeadline());
}
SchematicType schemType = e.getSchematicType(); SchematicType schemType = e.getSchematicType();
if (schemType != null) { if (schemType != null && schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant()))
if (schemType.getDeadline() != null && now.isBefore(schemType.getDeadline().toInstant())) { player.prefixless("EVENT_COMING_SCHEM_DEADLINE", schemType.getDeadline());
Message.send("EVENT_COMING_SCHEM_DEADLINE", player, e.getDeadline());
} Set<Team> teams = TeamTeilnahme.getTeams(e.getEventID());
} if(!teams.isEmpty())
if(!teams.isEmpty()){ player.prefixless("EVENT_COMING_TEAMS", teams.stream().map(team -> player.parseToLegacy("EVENT_COMING_TEAM", team.getTeamColor(), team.getTeamKuerzel())).collect(Collectors.joining(" ")));
StringBuilder tline = new StringBuilder();
for(Team t : teams){
tline.append(' ').append(Message.parse("EVENT_COMING_TEAM", player, t.getTeamColor(), t.getTeamKuerzel()));
}
Message.send("EVENT_COMING_TEAMS", player, tline.toString());
}
}
} }
} }
@Register @Register
public void eventOverview(@Validator(value = "noEvent", invert = true) ProxiedPlayer player) { public void eventOverview(@Validator(value = "noEvent", invert = true) CommandSender sender) {
Chatter player = Chatter.of(sender);
player.system("EVENT_USAGE");
Event currentEvent = Event.get(); Event currentEvent = Event.get();
Message.send("EVENT_USAGE", player); player.system("EVENT_CURRENT_EVENT", currentEvent.getEventName());
List<EventFight> fights = EventFight.getEvent(currentEvent.getEventID()); DateTimeFormatter format = DateTimeFormatter.ofPattern(player.parseToPlain("EVENT_TIME_FORMAT"));
for(EventFight fight : EventFight.getEvent(currentEvent.getEventID())){
Message.send("EVENT_CURRENT_EVENT", player, currentEvent.getEventName());
DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern(Message.parse("EVENT_TIME_FORMAT", player));
for(EventFight fight : fights){
Team blue = Team.get(fight.getTeamBlue()); Team blue = Team.get(fight.getTeamBlue());
Team red = Team.get(fight.getTeamRed()); Team red = Team.get(fight.getTeamRed());
StringBuilder fline = new StringBuilder(Message.parse("EVENT_CURRENT_FIGHT", player, fight.getStartTime().toLocalDateTime().format(timeFormat), blue.getTeamColor(), blue.getTeamKuerzel(), StringBuilder fline = new StringBuilder(player.parseToLegacy("EVENT_CURRENT_FIGHT", fight.getStartTime().toLocalDateTime().format(format), blue.getTeamColor(), blue.getTeamKuerzel(), red.getTeamColor(), red.getTeamKuerzel()));
red.getTeamColor(), red.getTeamKuerzel()));
if(fight.hasFinished()){ if(fight.hasFinished()){
switch(fight.getErgebnis()){ switch(fight.getErgebnis()){
case 1: case 1:
fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, blue.getTeamColor(), blue.getTeamKuerzel())); fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", blue.getTeamColor(), blue.getTeamKuerzel()));
break; break;
case 2: case 2:
fline.append(Message.parse("EVENT_CURRENT_FIGHT_WIN", player, red.getTeamColor(), red.getTeamKuerzel())); fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_WIN", red.getTeamColor(), red.getTeamKuerzel()));
break; break;
default: default:
fline.append(Message.parse("EVENT_CURRENT_FIGHT_DRAW", player)); fline.append(player.parseToLegacy("EVENT_CURRENT_FIGHT_DRAW"));
} }
} }
BungeeCore.send(player, fline.toString()); player.prefixless("PLAIN_STRING", fline.toString());
} }
} }
@Register @Register
public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) { public void eventWithTeam(@Validator(value = "noEvent", invert = true) ProxiedPlayer player, @ErrorMessage("EVENT_NO_TEAM") Team team) {
Chatter sender = Chatter.of(player);
Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId()); Subserver eventArena = EventStarter.getEventServer().get(team.getTeamId());
if(eventArena == null || !Subserver.getServerList().contains(eventArena)){ if(eventArena == null || !Subserver.getServerList().contains(eventArena)){
Message.send("EVENT_NO_FIGHT_TEAM", player); sender.system("EVENT_NO_FIGHT_TEAM");
return; return;
} }
Chatter sender = Chatter.of(player);
if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) { if (!PunishmentCommand.isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) {
SubserverSystem.sendPlayer(eventArena, player); SubserverSystem.sendPlayer(eventArena, player);
} }
} }
@ClassMapper(Team.class)
@Cached(cacheDuration = 10, global = true)
public TypeMapper<Team> teamMapper() {
return SWCommandUtils.createMapper(Team::get, s -> EventStarter.getEventServer()
.keySet()
.stream()
.map(Team::get)
.map(t -> Arrays.asList(t.getTeamKuerzel(), t.getTeamColor()))
.flatMap(Collection::stream)
.collect(Collectors.toList()));
}
} }

Datei anzeigen

@ -19,23 +19,18 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.Event;
import de.steamwar.sql.EventFight; import de.steamwar.sql.EventFight;
import de.steamwar.sql.Team; import de.steamwar.sql.Team;
import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeMapper;
import de.steamwar.sql.Event;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class EventRescheduleCommand extends SWCommand { public class EventRescheduleCommand extends SWCommand {
@ -44,10 +39,12 @@ public class EventRescheduleCommand extends SWCommand {
} }
@Register @Register
public void reschedule(ProxiedPlayer player, Team teamBlue, Team teamRed) { public void reschedule(CommandSender sender, Team teamBlue, Team teamRed) {
Chatter player = Chatter.of(sender);
Event event = Event.get(); Event event = Event.get();
if(event == null){ if(event == null){
Message.send("EVENTRESCHEDULE_UNKNOWN_TEAM", player); player.system("EVENTRESCHEDULE_UNKNOWN_TEAM");
return; return;
} }
@ -60,31 +57,13 @@ public class EventRescheduleCommand extends SWCommand {
continue; continue;
if(fight.getTeamBlue() == teamBlue.getTeamId() && fight.getTeamRed() == teamRed.getTeamId()){ if(fight.getTeamBlue() == teamBlue.getTeamId() && fight.getTeamRed() == teamRed.getTeamId()){
Message.send("EVENTRESCHEDULE_STARTING", player); player.system("EVENTRESCHEDULE_STARTING");
fight.reschedule(); fight.reschedule();
EventFight.loadAllComingFights(); EventFight.loadAllComingFights();
return; return;
} }
} }
Message.send("EVENTRESCHEDULE_NO_FIGHT", player); player.system("EVENTRESCHEDULE_NO_FIGHT");
}
@ClassMapper(value = Team.class, local = true)
public TypeMapper<Team> teamTypeMapper() {
return new TypeMapper<Team>() {
@Override
public Team map(CommandSender commandSender, String[] previousArguments, String s) {
return Team.get(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
Event event = Event.get();
if (event == null) return null;
List<EventFight> fights = EventFight.getEvent(event.getEventID());
return fights.stream().flatMap(fight -> Stream.of(fight.getTeamBlue(), fight.getTeamRed())).map(Team::get).map(Team::getTeamKuerzel).distinct().collect(Collectors.toList());
}
};
} }
} }

Datei anzeigen

@ -32,41 +32,12 @@ import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.api.chat.hover.content.Text;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
/**
* 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 SWCommand { public class FightCommand extends SWCommand {
public FightCommand() { public FightCommand() {
super("fight", "", "f"); super("fight", "", "f");
} }
private static ArenaMode getMode(Chatter sender, String arg){
ArenaMode mode = ArenaMode.getByChat(arg);
if(mode != null)
return mode;
sender.system("FIGHT_UNKNOWN_GAMEMODE", arg);
return null;
}
private static String getMap(Chatter sender, ArenaMode mode, String arg){
String realMap = mode.hasMap(arg.toLowerCase());
if(realMap != null)
return realMap;
if(arg.equalsIgnoreCase("Random"))
return mode.getRandomMap();
sender.system("FIGHT_UNKNOWN_ARENA");
return null;
}
private static void getModes(Chatter sender, String precommand, boolean historic){ private static void getModes(Chatter sender, String precommand, boolean historic){
TextComponent start = new TextComponent(); TextComponent start = new TextComponent();
TextComponent current = start; TextComponent current = start;
@ -90,7 +61,7 @@ public class FightCommand extends SWCommand {
private static boolean alreadyInArena(ProxiedPlayer player){ private static boolean alreadyInArena(ProxiedPlayer player){
Subserver subserver = Subserver.getSubserver(player); Subserver subserver = Subserver.getSubserver(player);
if(subserver != null && subserver.getType() == Servertype.ARENA){ if(subserver != null && subserver.getType() == Servertype.ARENA){
Message.send("FIGHT_IN_ARENA", player); Chatter.of(player).system("FIGHT_IN_ARENA");
return true; return true;
} }
@ -137,20 +108,21 @@ public class FightCommand extends SWCommand {
return; return;
} }
SWInventory inventory = new SWInventory(player, 9, Message.parse("FIGHT_MERGE_TITLE", player)); Chatter chatter = Chatter.of(player);
inventory.addItem(0, new SWItem(Message.parse("FIGHT_MERGE_DECLINE", player), 1), click -> { SWInventory inventory = new SWInventory(chatter, 9, new Message("FIGHT_MERGE_TITLE"));
inventory.addItem(0, new SWItem(new Message("FIGHT_MERGE_DECLINE"), 1), click -> {
inventory.close(); inventory.close();
declineMerge.run(player, mode, map); declineMerge.run(player, mode, map);
}); });
Arenaserver finalMergable = mergable; Arenaserver finalMergable = mergable;
SWItem item = new SWItem(Message.parse("FIGHT_MERGE_INFO", player, mode.getDisplayName(), finalMergable.getMap()), 11); SWItem item = new SWItem(new Message("FIGHT_MERGE_INFO", mode.getDisplayName(), finalMergable.getMap()), 11);
item.addLore(Message.parse("FIGHT_MERGE_INFO_LORE_1", player, finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName())); item.addLore(new Message("FIGHT_MERGE_INFO_LORE_1", finalMergable.getServer().getPlayers().toArray(new ProxiedPlayer[1])[0].getName()));
inventory.addItem(4, item, click -> {}); inventory.addItem(4, item, click -> {});
inventory.addItem(8, new SWItem(Message.parse("FIGHT_MERGE_ACCEPT", player), 10), click -> { inventory.addItem(8, new SWItem(new Message("FIGHT_MERGE_ACCEPT"), 10), click -> {
if(Subserver.getServerList().contains(finalMergable)) { if(Subserver.getServerList().contains(finalMergable)) {
finalMergable.sendPlayer(player); finalMergable.sendPlayer(player);
} else { } else {
Message.send("FIGHT_MERGE_OFFLINE", player); chatter.system("FIGHT_MERGE_OFFLINE");
declineMerge.run(player, mode, map); declineMerge.run(player, mode, map);
} }
}); });
@ -166,10 +138,7 @@ public class FightCommand extends SWCommand {
); );
} }
/** public interface FightCallback {
* Is called when arena parameters are clear.
*/
interface FightCallback {
void run(ProxiedPlayer player, ArenaMode mode, String map); void run(ProxiedPlayer player, ArenaMode mode, String map);
} }
} }

Datei anzeigen

@ -33,10 +33,8 @@ public class HistoricCommand extends SWCommand {
@Register @Register
public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback(
new ServerStarter().arena(mode, m).blueLeader(p).callback(
arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()) arena -> Chatter.broadcast().system("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName())
).start(); ).start());
});
} }
} }

Datei anzeigen

@ -19,8 +19,8 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.IgnoreSystem; import de.steamwar.sql.IgnoreSystem;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -33,18 +33,19 @@ public class IgnoreCommand extends SWCommand {
@Register(description = "USAGE_IGNORE") @Register(description = "USAGE_IGNORE")
public void genericCommand(ProxiedPlayer p, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) { public void genericCommand(ProxiedPlayer p, @ErrorMessage("UNKNOWN_PLAYER") SteamwarUser target) {
SteamwarUser user = SteamwarUser.get(p.getUniqueId()); Chatter player = Chatter.of(p);
SteamwarUser user = player.user();
if(target.equals(user)){ if(target.equals(user)){
Message.send("IGNORE_YOURSELF", p); player.system("IGNORE_YOURSELF");
return; return;
} }
if(IgnoreSystem.isIgnored(user, target)){ if(IgnoreSystem.isIgnored(user, target)){
Message.send("IGNORE_ALREADY", p); player.system("IGNORE_ALREADY");
return; return;
} }
IgnoreSystem.ignore(user, target); IgnoreSystem.ignore(user, target);
Message.send("IGNORE_MESSAGE", p, target.getUserName()); player.system("IGNORE_MESSAGE", target);
} }
} }

Datei anzeigen

@ -19,51 +19,20 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator;
import de.steamwar.messages.Chatter; import de.steamwar.messages.Chatter;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class JoinmeCommand extends SWCommand { public class JoinmeCommand extends SWCommand {
public JoinmeCommand() { public JoinmeCommand() {
super("joinme"); super("joinme", ConnectionListener.TEAMCHAT_PERMISSION);
}
@Register(description = "JOINME_USAGE")
public void genericCommand(ProxiedPlayer player) {
if (!SteamwarUser.get(player.getUniqueId()).hasPerm(UserPerm.TEAM)) {
Message.send("JOINME_USAGE", player);
return;
}
Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player.getName(), player.getServer().getInfo().getName());
} }
@Register @Register
public void genericCommand(ProxiedPlayer player, @Validator ProxiedPlayer target) { public void genericCommand(ProxiedPlayer player) {
if (target.equals(player)){ Chatter.broadcast().system("JOINME_BROADCAST", "JOINME_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/join " + player.getName()), player, player.getServer().getInfo().getName());
Message.send("JOINME_PLAYER_SELF", player);
return;
}
Subserver subserver = Subserver.getSubserver(target);
TpCommand.teleport(player, subserver != null ? subserver.getServer() : target.getServer().getInfo());
}
@ClassValidator(ProxiedPlayer.class)
public TypeValidator<ProxiedPlayer> playerMapper() {
return (sender, value, messageSender) -> {
if (value == null || !value.isConnected()) {
messageSender.send("JOINME_PLAYER_OFFLINE", sender);
return false;
}
return true;
};
} }
} }

Datei anzeigen

@ -19,10 +19,10 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.Subserver;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
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.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
@ -62,14 +62,16 @@ public class ListCommand extends SWCommand {
} }
@Register @Register
public void genericCommand(CommandSender commandSender) { public void list(CommandSender sender) {
Chatter chatter = Chatter.of(sender);
TreeMap<String, List<ProxiedPlayer>> playerMap = getCustomTablist(); TreeMap<String, List<ProxiedPlayer>> playerMap = getCustomTablist();
for (String server : playerMap.navigableKeySet()) { for (String server : playerMap.navigableKeySet()) {
String serverName = server; String serverName = server;
if (server.equals("Bau")) { if (server.equals("Bau")) {
serverName = Message.parse("TABLIST_BAU", commandSender); serverName = chatter.parseToLegacy("TABLIST_BAU");
} }
Message.send("LIST_COMMAND", commandSender, serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); chatter.prefixless("LIST_COMMAND", serverName, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", ")));
} }
} }
} }

Datei anzeigen

@ -26,12 +26,14 @@ import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.Mod; import de.steamwar.sql.Mod;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class ModCommand extends SWCommand { public class ModCommand extends SWCommand {
@ -40,109 +42,83 @@ public class ModCommand extends SWCommand {
super("mod", ConnectionListener.MOD_PERMISSION, "mods"); super("mod", ConnectionListener.MOD_PERMISSION, "mods");
} }
public static final Map<ProxiedPlayer, Mod.ModType> playerFilterType = new HashMap<>(); public static final Map<UUID, Mod.ModType> playerFilterType = new HashMap<>();
@Register @Register
public void genericCommand(ProxiedPlayer p) { public void mods(ProxiedPlayer p) {
playerFilterType.putIfAbsent(p,Mod.ModType.UNKLASSIFIED); playerFilterType.putIfAbsent(p.getUniqueId(), Mod.ModType.UNKLASSIFIED);
openGui(p); openGui(Chatter.of(p));
} }
private void openGui(ProxiedPlayer p) { private void openGui(Chatter player) {
SWStreamInv<Mod> swStreamInv = new SWStreamInv<>(p,Message.parse("MOD_COMMAND_GUI_TITLE",p), (click, element) -> { SWStreamInv<Mod> swStreamInv = new SWStreamInv<>(player, new Message("MOD_COMMAND_GUI_TITLE"), (click, mod) -> openTypeGUI(player, "MOD_COMMAND_CLASSICIATION_GUI", type -> {
openClassificationGui(p,element); mod.setModType(type);
},page -> { SWInventory.close(player);
Mod.ModType filtertype = playerFilterType.get(p); openGui(player);
return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(getModItem(mod),mod)).collect(Collectors.toList()); }), page -> {
Mod.ModType filtertype = playerFilterType.get(player.user().getUUID());
return Mod.getAllModsFiltered(page,45, filtertype).stream().map(mod -> new SWListInv.SWListEntry<>(new SWItem("NAME_TAG", new Message("PLAIN_STRING", mod.getModName())).addLore(new Message("PLAIN_STRING", mod.getPlatform().name())), mod)).collect(Collectors.toList());
}); });
swStreamInv.addItem(52,new SWItem("NAME_TAG","Filter"), click -> { swStreamInv.addItem(52, new SWItem("NAME_TAG", new Message("MOD_TITLE_FILTER")), click -> {
swStreamInv.close(); swStreamInv.close();
openFilterGui(p); openTypeGUI(player, "MOD_TITLE_FILTER", type -> playerFilterType.replace(player.user().getUUID(), type));
}); });
swStreamInv.open(); swStreamInv.open();
} }
public void updateAndCloseGui(Mod.ModType modType, Mod mod, SWInventory toClose, ProxiedPlayer p) { private void openTypeGUI(Chatter player, String title, Consumer<Mod.ModType> function) {
mod.setModType(modType); SWInventory inv = new SWInventory(player, 9, new Message(title));
toClose.close();
openGui(p);
}
private void openFilterGui(ProxiedPlayer p) { inv.addItem(1, new SWItem(new Message("MOD_UNCLASSIFIED"), 8), click -> function.accept(Mod.ModType.UNKLASSIFIED));
SWInventory inv = new SWInventory(p, 9, "Filter"); inv.addItem(2, new SWItem(new Message("MOD_ALLOWED"), 2), click -> function.accept(Mod.ModType.GREEN));
inv.addItem(3, new SWItem(new Message("MOD_FORBIDDEN"), 11), click -> function.accept(Mod.ModType.YELLOW));
inv.addItem(4, new SWItem(new Message("MOD_AUTOBAN"), 1), click -> function.accept(Mod.ModType.RED));
inv.addItem(5, new SWItem(new Message("MOD_YT"), 13), click -> function.accept(Mod.ModType.YOUTUBER_ONLY));
inv.addItem(1, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), click -> playerFilterType.replace(p, Mod.ModType.UNKLASSIFIED)); inv.addItem(8, new SWItem("ARROW", new Message("MOD_ITEM_BACK")), click -> {
inv.addItem(2, new SWItem(Message.parse("MOD_ALLOWED",p),2), click -> playerFilterType.replace(p, Mod.ModType.GREEN));
inv.addItem(3, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), click -> playerFilterType.replace(p, Mod.ModType.YELLOW));
inv.addItem(4, new SWItem(Message.parse("MOD_AUTOBAN",p),1), click -> playerFilterType.replace(p, Mod.ModType.RED));
inv.addItem(5, new SWItem(Message.parse("MOD_YT",p),13), click -> playerFilterType.replace(p, Mod.ModType.YOUTUBER_ONLY));
inv.addItem(8, new SWItem("ARROW", Message.parse("MOD_ITEM_BACK",p)), click -> {
inv.close(); inv.close();
openGui(p); openGui(player);
}); });
inv.open(); inv.open();
} }
private void openClassificationGui(ProxiedPlayer p,Mod element) {
SWInventory swInventory = new SWInventory(p,9,Message.parse("MOD_COMMAND_CLASSICIATION_GUI",p));
swInventory.addItem(2, new SWItem(Message.parse("MOD_UNCLASSIFIED",p),8), (click1 -> updateAndCloseGui(Mod.ModType.UNKLASSIFIED,element,swInventory,p)));
swInventory.addItem(3, new SWItem(Message.parse("MOD_ALLOWED",p), 2), (click1 -> updateAndCloseGui(Mod.ModType.GREEN,element,swInventory,p)));
swInventory.addItem(4, new SWItem(Message.parse("MOD_FORBIDDEN",p), 11), (click1 -> updateAndCloseGui(Mod.ModType.YELLOW,element,swInventory,p)));
swInventory.addItem(5, new SWItem(Message.parse("MOD_AUTOBAN",p),1), (click1 -> updateAndCloseGui(Mod.ModType.RED,element,swInventory,p)));
swInventory.addItem(6, new SWItem(Message.parse("MOD_YT",p), 13), (click1 -> updateAndCloseGui(Mod.ModType.YOUTUBER_ONLY,element,swInventory,p)));
swInventory.addItem(8,new SWItem("ARROW",Message.parse("MOD_ITEM_BACK",p)), click1 -> {
swInventory.close();
openGui(p);
});
swInventory.open();
}
private SWItem getModItem(Mod modEntry) {
SWItem item = new SWItem("NAME_TAG", modEntry.getModName());
item.addLore(modEntry.getPlatform().name());
return item;
}
@Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE") @Register(value = {"set"},description = "MOD_COMMAND_SET_USAGE")
public void set(ProxiedPlayer p, String modName, Mod.Platform platform, Mod.ModType newModType) { public void set(ProxiedPlayer p, String modName, Mod.Platform platform, Mod.ModType newModType) {
Chatter player = Chatter.of(p);
Mod mod = Mod.get(modName, platform); Mod mod = Mod.get(modName, platform);
if(mod == null) { if(mod == null) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE",p,modName, platform.name()); player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name());
return; return;
} }
mod.setModType(newModType); mod.setModType(newModType);
Message.send("MOD_CHANGED_TYPE",p,modName,platform.name(),newModType.name()); player.system("MOD_CHANGED_TYPE", modName, platform.name(), newModType.name());
} }
@Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE") @Register(value = {"get"},description = "MOD_COMMAND_GET_USAGE")
public void get(ProxiedPlayer p, String modName, Mod.Platform platform) { public void get(ProxiedPlayer p, String modName, Mod.Platform platform) {
Chatter player = Chatter.of(p);
Mod mod = Mod.get(modName, platform); Mod mod = Mod.get(modName, platform);
if(mod == null) { if(mod == null) {
Message.send("MOD_COMMAND_NOT_FOUND_IN_DATABASE", p, modName, platform.name()); player.system("MOD_COMMAND_NOT_FOUND_IN_DATABASE", modName, platform.name());
return; return;
} }
Message.send("MOD_COMMAND_INFO", p, modName, platform.name(), mod.getModType().name()); player.system("MOD_COMMAND_INFO", modName, platform.name(), mod.getModType().name());
} }
@Register(value = {"next"}) @Register(value = {"next"})
public void next(ProxiedPlayer p) { public void next(ProxiedPlayer p) {
Chatter player = Chatter.of(p);
Mod mod = Mod.findFirstMod(); Mod mod = Mod.findFirstMod();
if(mod == null) { if(mod == null) {
Message.send("MOD_NO_MORE_UNCLASSIFIED_MODS",p); player.system("MOD_NO_MORE_UNCLASSIFIED_MODS");
return; return;
} }
Message.send("MOD_FOUND_NEXT_MOD",p,"MOD_OPEN_GUI",new ClickEvent(ClickEvent.Action.RUN_COMMAND,""),mod.getModName(),mod.getPlatform().name()); player.system("MOD_FOUND_NEXT_MOD", mod.getModName(), mod.getPlatform().name());
} }
} }

Datei anzeigen

@ -19,8 +19,8 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
public class PingCommand extends SWCommand { public class PingCommand extends SWCommand {
@ -31,6 +31,6 @@ public class PingCommand extends SWCommand {
@Register @Register
public void genericCommand(ProxiedPlayer player) { public void genericCommand(ProxiedPlayer player) {
Message.send("PING_RESPONSE", player, player.getPing()); Chatter.of(player).system("PING_RESPONSE", player.getPing());
} }
} }

Datei anzeigen

@ -19,9 +19,9 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.SteamwarUser;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.text.NumberFormat; import java.text.NumberFormat;
@ -39,6 +39,6 @@ public class PlaytimeCommand extends SWCommand {
format.setMaximumFractionDigits(2); format.setMaximumFractionDigits(2);
String formattedText = format.format((user.getOnlinetime() / (double) 3600)); String formattedText = format.format((user.getOnlinetime() / (double) 3600));
Message.send("HOURS_PLAYED", player, formattedText); Chatter.of(player).system("HOURS_PLAYED", formattedText);
} }
} }

Datei anzeigen

@ -489,7 +489,7 @@ public class TeamCommand extends SWCommand {
} }
@Register("tp") @Register("tp")
public void tp(ProxiedPlayer player, @ErrorMessage("TEAM_TP_NO_TEAM") @Mapper("teamWithTeamServer") Team targetTeam) { public void tp(ProxiedPlayer player, @ErrorMessage("TEAM_TP_NO_TEAM") Team targetTeam) {
if (targetTeam.getAddress() == null || targetTeam.getAddress().isEmpty()) { if (targetTeam.getAddress() == null || targetTeam.getAddress().isEmpty()) {
Message.send("TEAM_NO_ADDRESS", player); Message.send("TEAM_NO_ADDRESS", player);
return; return;
@ -678,25 +678,6 @@ public class TeamCommand extends SWCommand {
}; };
} }
@Mapper(value = "teamWithTeamServer", local = true)
@Cached(global = true, cacheDuration = 60)
public TypeMapper<Team> teamWithTeamServer() {
return new TypeMapper<Team>() {
@Override
public Team map(CommandSender commandSender, String[] previousArguments, String s) {
return Team.get(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return Team.getAll().stream()
.filter(team -> team.getAddress() != null && !team.getAddress().isEmpty())
.flatMap(team -> Stream.of(team.getTeamName(), team.getTeamKuerzel()))
.collect(Collectors.toList());
}
};
}
private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){ private boolean checkTeamName(ProxiedPlayer player, Team team, String arg){
Team t = Team.get(arg); Team t = Team.get(arg);
if(t != null && t.getTeamId() != team.getTeamId()){ if(t != null && t.getTeamId() != team.getTeamId()){

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.util.Chat19; import de.steamwar.bungeecore.util.Chat19;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import de.steamwar.command.TypeValidator; import de.steamwar.command.TypeValidator;
import de.steamwar.messages.Chatter;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Tutorial; import de.steamwar.sql.Tutorial;
import de.steamwar.sql.UserPerm; import de.steamwar.sql.UserPerm;
@ -131,12 +132,12 @@ public class TutorialCommand extends SWCommand {
} }
private void rate(ProxiedPlayer player, Tutorial tutorial) { private void rate(ProxiedPlayer player, Tutorial tutorial) {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Chatter chatter = Chatter.of(player);
int[] rates = new int[]{1, 2, 3, 4, 5}; int[] rates = new int[]{1, 2, 3, 4, 5};
new SWListInv<>(player, Message.parse("TUTORIAL_RATE_TITLE", player), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", Message.parse("TUTORIAL_RATE", player, rate)), rate)).collect(Collectors.toList()), (click, rate) -> { new SWListInv<>(player, Message.parse("TUTORIAL_RATE_TITLE", player), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", Message.parse("TUTORIAL_RATE", player, rate)), rate)).collect(Collectors.toList()), (click, rate) -> {
tutorial.rate(user.getId(), rate); tutorial.rate(chatter.user().getId(), rate);
SWInventory.close(player); SWInventory.close(chatter);
}).open(); }).open();
} }

Datei anzeigen

@ -19,11 +19,14 @@
package de.steamwar.bungeecore.inventory; package de.steamwar.bungeecore.inventory;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.network.NetworkSender; import de.steamwar.bungeecore.network.NetworkSender;
import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler; import de.steamwar.bungeecore.network.handlers.InventoryCallbackHandler;
import de.steamwar.sql.SteamwarUser; import de.steamwar.messages.Chatter;
import de.steamwar.network.packets.server.CloseInventoryPacket; import de.steamwar.network.packets.server.CloseInventoryPacket;
import de.steamwar.network.packets.server.InventoryPacket; import de.steamwar.network.packets.server.InventoryPacket;
import lombok.Getter;
import lombok.Setter;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.ArrayList; import java.util.ArrayList;
@ -35,22 +38,28 @@ import java.util.function.BiFunction;
public class SWInventory { public class SWInventory {
private final Map<Integer, SWItem> itemMap; private final Map<Integer, SWItem> itemMap = new HashMap<>();
private final Chatter player;
private final int size;
private final Message title;
@Setter
private InvCallback close; private InvCallback close;
private ProxiedPlayer player; @Getter
private int size; @Setter
private String title; private boolean next = false;
private boolean next;
private final AtomicBoolean processingClick = new AtomicBoolean(); private final AtomicBoolean processingClick = new AtomicBoolean();
@Deprecated
public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) { public SWInventory(ProxiedPlayer proxiedPlayer, int size, String title) {
itemMap = new HashMap<>(); this(Chatter.of(proxiedPlayer), size, new Message("PLAIN_STRING", title));
InventoryCallbackHandler.inventoryHashMap.put(SteamwarUser.get(proxiedPlayer.getUniqueId()).getId(), this); }
this.player = proxiedPlayer;
public SWInventory(Chatter player, int size, Message title) {
InventoryCallbackHandler.inventoryHashMap.put(player.user().getId(), this);
this.player = player;
this.size = size; this.size = size;
this.title = title; this.title = title;
next = false;
} }
public void addItem(int pos, SWItem item, InvCallback callback) { public void addItem(int pos, SWItem item, InvCallback callback) {
@ -67,44 +76,10 @@ public class SWInventory {
itemMap.put(pos, item); itemMap.put(pos, item);
} }
public void addItem(int pos, SWItem item, String name, InvCallback callback) {
item.setName(name);
item.setCallback(callback);
itemMap.put(pos, item);
}
public void removeItem(int position) {
itemMap.remove(position);
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public void setTitle(String title) {
this.title = title;
}
public void setCallback(int pos, InvCallback callback) { public void setCallback(int pos, InvCallback callback) {
itemMap.get(pos).setCallback(callback); itemMap.get(pos).setCallback(callback);
} }
public void setNext(boolean next) {
this.next = next;
}
public boolean isNext() {
return next;
}
public Map<Integer, SWItem> getItems() {
return itemMap;
}
public void handleCallback(InvCallback.ClickType type, int pos) { public void handleCallback(InvCallback.ClickType type, int pos) {
if(processingClick.compareAndSet(false, true)) { if(processingClick.compareAndSet(false, true)) {
itemMap.get(pos).getCallback().clicked(type); itemMap.get(pos).getCallback().clicked(type);
@ -114,7 +89,7 @@ public class SWInventory {
public void handleClose() { public void handleClose() {
if(processingClick.compareAndSet(false, true)) { if(processingClick.compareAndSet(false, true)) {
InventoryCallbackHandler.inventoryHashMap.remove(SteamwarUser.get(player.getUniqueId()).getId(), this); InventoryCallbackHandler.inventoryHashMap.remove(player.user().getId(), this);
if(close != null) if(close != null)
close.clicked(null); close.clicked(null);
processingClick.set(false); processingClick.set(false);
@ -122,8 +97,8 @@ public class SWInventory {
} }
public void open() { public void open() {
InventoryPacket inv = new InventoryPacket(title, SteamwarUser.get(player.getUniqueId()).getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(integer).toString())); InventoryPacket inv = new InventoryPacket(player.parseToLegacy(title), player.user().getId(), size, map(itemMap, (integer, swItem) -> swItem.writeToString(player, integer).toString()));
NetworkSender.send(player, inv); player.withPlayer(p -> NetworkSender.send(p, inv));
} }
private static <T, K, J> Map<T, J> map(Map<T, K> map, BiFunction<T, K, J> function) { private static <T, K, J> Map<T, J> map(Map<T, K> map, BiFunction<T, K, J> function) {
@ -136,23 +111,7 @@ public class SWInventory {
close(player); close(player);
} }
public static void close(ProxiedPlayer player) { public static void close(Chatter player) {
NetworkSender.send(player, new CloseInventoryPacket(SteamwarUser.get(player.getUniqueId()).getId())); player.withPlayer(p -> NetworkSender.send(p, new CloseInventoryPacket(player.user().getId())));
}
public void setClose(InvCallback close) {
this.close = close;
}
public ProxiedPlayer getPlayer() {
return player;
}
public void setPlayer(ProxiedPlayer player) {
this.player = player;
}
public String getTitle() {
return title;
} }
} }

Datei anzeigen

@ -21,28 +21,44 @@ package de.steamwar.bungeecore.inventory;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import de.steamwar.bungeecore.Message;
import de.steamwar.messages.Chatter;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Setter
public class SWItem { public class SWItem {
private String material, title, skullOwner; @Getter
private boolean enchanted, hideAttributes; private String material = "DYE";
private List<String> lore; private Message title;
private String skullOwner;
private boolean enchanted;
private boolean hideAttributes;
private List<Message> lore = new ArrayList<>();
@Getter
private InvCallback callback; private InvCallback callback;
private int color; private int color = 0;
@Deprecated
public SWItem(String material, String title) { public SWItem(String material, String title) {
this.material = material.toUpperCase(); this(material, new Message("PLAIN_STRING", title));
lore = new ArrayList<>();
this.title = title;
color = 0;
} }
public SWItem(String material, Message title) {
this.material = material.toUpperCase();
this.title = title;
}
@Deprecated
public SWItem(String title, int color) { public SWItem(String title, int color) {
this.material = "DYE"; this(new Message("PLAIN_STRING", title), color);
lore = new ArrayList<>(); }
public SWItem(Message title, int color) {
this.title = title; this.title = title;
this.color = color; this.color = color;
} }
@ -53,68 +69,27 @@ public class SWItem {
return item; return item;
} }
public void setCallback(InvCallback callback) { @Deprecated
this.callback = callback;
}
public void setColor(int color) {
this.color = color;
}
public InvCallback getCallback() {
return callback;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material.toUpperCase();
}
public String getSkullOwner() {
return skullOwner;
}
public void setSkullOwner(String skullOwner) {
this.skullOwner = skullOwner;
}
public boolean isEnchanted() {
return enchanted;
}
public void setEnchanted(boolean enchanted) {
this.enchanted = enchanted;
}
public boolean isHideAttributes() {
return hideAttributes;
}
public void setHideAttributes(boolean hideAttributes) {
this.hideAttributes = hideAttributes;
}
public SWItem setName(String name) { public SWItem setName(String name) {
title = name; title = new Message("PLAIN_STRING", name);
return this; return this;
} }
public String getTitle() { @Deprecated
return title;
}
public void addLore(String lore) { public void addLore(String lore) {
this.lore.add(lore); addLore(new Message("PLAIN_STRING", lore));
} }
public JsonObject writeToString(int position) { public SWItem addLore(Message lore) {
this.lore.add(lore);
return this;
}
public JsonObject writeToString(Chatter player, int position) {
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
object.addProperty("material", material); object.addProperty("material", material);
object.addProperty("position", position); object.addProperty("position", position);
object.addProperty("title", title); object.addProperty("title", player.parseToLegacy(title));
if(skullOwner != null) if(skullOwner != null)
object.addProperty("skullOwner", skullOwner); object.addProperty("skullOwner", skullOwner);
if(enchanted) if(enchanted)
@ -125,9 +100,8 @@ public class SWItem {
object.addProperty("color", color); object.addProperty("color", color);
if(lore != null) { if(lore != null) {
JsonArray array = new JsonArray(); JsonArray array = new JsonArray();
for (String lores: for (Message lores : lore) {
lore) { array.add(player.parseToLegacy(lores));
array.add(lores);
} }
object.add("lore", array); object.add("lore", array);
} }
@ -153,10 +127,6 @@ public class SWItem {
return true; return true;
} }
public void setLore(List<String> lore) {
this.lore = lore;
}
public SWItem clone() { public SWItem clone() {
SWItem item; SWItem item;
if(color != 0) { if(color != 0) {

Datei anzeigen

@ -47,7 +47,7 @@ public class SWListInv<T> extends SWInventory {
else else
addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {}); addItem(45, new SWItem("§7Seite zurück", 8), (InvCallback.ClickType click) -> {});
if(page < elements.size()/45) if(page < elements.size()/45)
addItem(53, new SWItem("§eSeite vor", 10), "§eSeite vor", (InvCallback.ClickType click) -> { addItem(53, new SWItem("§eSeite vor", 10), (InvCallback.ClickType click) -> {
page++; page++;
open(); open();
}); });

Datei anzeigen

@ -1,5 +1,7 @@
package de.steamwar.bungeecore.inventory; package de.steamwar.bungeecore.inventory;
import de.steamwar.bungeecore.Message;
import de.steamwar.messages.Chatter;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.List; import java.util.List;
@ -10,6 +12,14 @@ public class SWStreamInv<T> extends SWInventory {
private final Function<Integer, List<SWListInv.SWListEntry<T>>> constructor; private final Function<Integer, List<SWListInv.SWListEntry<T>>> constructor;
private int page; private int page;
public SWStreamInv(Chatter chatter, Message title, SWListInv.ListCallback<T> callback, Function<Integer, List<SWListInv.SWListEntry<T>>> constructor) {
super(chatter, 54, title);
this.callback = callback;
this.constructor = constructor;
page = 0;
}
@Deprecated
public SWStreamInv(ProxiedPlayer proxiedPlayer, String title, SWListInv.ListCallback<T> callback, Function<Integer, List<SWListInv.SWListEntry<T>>> constructor) { public SWStreamInv(ProxiedPlayer proxiedPlayer, String title, SWListInv.ListCallback<T> callback, Function<Integer, List<SWListInv.SWListEntry<T>>> constructor) {
super(proxiedPlayer, 54, title); super(proxiedPlayer, 54, title);
this.callback = callback; this.callback = callback;

Datei anzeigen

@ -19,20 +19,54 @@
package de.steamwar.command; package de.steamwar.command;
import de.steamwar.bungeecore.ServerVersion;
import de.steamwar.bungeecore.commands.TypeMappers; import de.steamwar.bungeecore.commands.TypeMappers;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.Team;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.util.Collection;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
@UtilityClass @UtilityClass
public class TypeUtils { public class TypeUtils {
static void init() { static void init() {
SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, (s) -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(ProxiedPlayer.class, SWCommandUtils.createMapper(BungeeCord.getInstance()::getPlayer, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList()))); SWCommandUtils.addMapper(SteamwarUser.class, SWCommandUtils.createMapper(SteamwarUser::get, s -> BungeeCord.getInstance().getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList())));
SWCommandUtils.addMapper(ServerVersion.class, new TypeMapper<ServerVersion>() {
@Override
public ServerVersion map(CommandSender sender, String[] previousArguments, String s) {
if (sender instanceof ProxiedPlayer && s.isEmpty()) {
int version = ((ProxiedPlayer) sender).getPendingConnection().getVersion();
if (version > 762) { // Version > 1.19.4
return ServerVersion.PAPER_20;
} else if (version > 578) { // Version > 1.15.2
return ServerVersion.PAPER_19;
} else if (version > 340) { // Version > 1.12.2
return ServerVersion.SPIGOT_15;
} else {
return ServerVersion.SPIGOT_12;
}
}
return ServerVersion.get(s);
}
@Override
public Collection<String> tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) {
return ServerVersion.chatVersions();
}
});
AbstractTypeMapper<Object, Team> teamMapper = SWCommandUtils.createMapper(Team::get, s -> Team.getAll().stream().flatMap(team -> Stream.of(team.getTeamKuerzel(), team.getTeamName())).collect(Collectors.toList()));
TabCompletionCache.add(teamMapper, true, 10, TimeUnit.SECONDS);
SWCommandUtils.addMapper(Team.class, teamMapper);
TypeMappers.init(); TypeMappers.init();
} }

Datei anzeigen

@ -691,9 +691,15 @@ MOD_COMMAND_INFO=§7The mod {0} on platform {1} is of the type {2}.
MOD_COMMAND_GUI_TITLE=Unclassified Mods MOD_COMMAND_GUI_TITLE=Unclassified Mods
MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer MOD_COMMAND_CLASSICIATION_GUI=Mod Type Changer
MOD_OPEN_GUI=§7Open Gui MOD_OPEN_GUI=§7Open Gui
MOD_TITLE_FILTER=Filter
MOD_UNCLASSIFIED=§7Unclassified MOD_UNCLASSIFIED=§7Unclassified
MOD_ALLOWED=§aAllowed MOD_ALLOWED=§aAllowed
MOD_FORBIDDEN=§eForbidden MOD_FORBIDDEN=§eForbidden
MOD_AUTOBAN=§cAutoban MOD_AUTOBAN=§cAutoban
MOD_YT=§5YT Only MOD_YT=§5YT Only
MOD_ITEM_BACK=§7Back MOD_ITEM_BACK=§7Back
#Discord
DC_TITLE_SCHEMINFO=Schematic Info
DC_SCHEM_ACCEPT=Your schematic **{0}** has been accepted.
DC_SCHEM_DECLINE=Your schematic **{0}** has been declined.\n**Reason:**{1}

Datei anzeigen

@ -651,3 +651,8 @@ ADVENT_CALENDAR_DAY=§7Tag§8: §e{0}
ADVENT_CALENDAR_MESSAGE=§eHast du heute schon dein Geschenk geholt? ADVENT_CALENDAR_MESSAGE=§eHast du heute schon dein Geschenk geholt?
ADVENT_CALENDAR_MESSAGE_HOVER=§eKlicken zum öffnen! ADVENT_CALENDAR_MESSAGE_HOVER=§eKlicken zum öffnen!
ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten! ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten!
#Discord
DC_TITLE_SCHEMINFO=Schematicinfo
DC_SCHEM_ACCEPT=Deine Schematic **{0}** wurde angenommen.
DC_SCHEM_DECLINE=Deine Schematic **{0}** wurde abgelehnt. **Grund:** \n{1}

Datei anzeigen

@ -43,6 +43,7 @@ import java.text.MessageFormat;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
@ -78,7 +79,11 @@ public interface Chatter {
Locale getLocale(); Locale getLocale();
boolean chatShown(); boolean chatShown();
void sendMessage(ChatMessageType type, BaseComponent... msg); void sendMessage(ChatMessageType type, BaseComponent... msg);
void withPlayer(Consumer<ProxiedPlayer> function); void withPlayerOrDiscord(Consumer<ProxiedPlayer> withPlayer, Consumer<SteamwarUser> withDiscord);
default void withPlayer(Consumer<ProxiedPlayer> function) {
withPlayerOrDiscord(function, user -> {});
}
default void chat(Message message) { default void chat(Message message) {
send(false, ChatMessageType.CHAT, null, null, message); send(false, ChatMessageType.CHAT, null, null, message);
@ -182,8 +187,8 @@ public interface Chatter {
} }
@Override @Override
public void withPlayer(Consumer<ProxiedPlayer> function) { public void withPlayerOrDiscord(Consumer<ProxiedPlayer> withPlayer, Consumer<SteamwarUser> withDiscord) {
function.accept(player); withPlayer.accept(player);
} }
}; };
} }
@ -219,6 +224,29 @@ public interface Chatter {
}; };
} }
static Chatter of(UUID uuid) {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
if(player != null)
return Chatter.of(player);
return new PlayerlessChatter() {
@Override
public SteamwarUser user() {
return SteamwarUser.get(uuid);
}
@Override
public boolean chatShown() {
return false;
}
@Override
public void sendMessage(ChatMessageType type, BaseComponent... msg) {
// Nowhere to send
}
};
}
static Chatter console() { static Chatter console() {
return of(ConsoleCommandSender.getInstance()); return of(ConsoleCommandSender.getInstance());
} }
@ -295,8 +323,8 @@ public interface Chatter {
} }
@Override @Override
public void withPlayer(Consumer<ProxiedPlayer> function) { public void withPlayerOrDiscord(Consumer<ProxiedPlayer> withPlayer, Consumer<SteamwarUser> withDiscord) {
//Not a player withDiscord.accept(user());
} }
} }
} }