SteamWar/BungeeCore
Archiviert
13
2

Current state
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2022-04-19 20:32:02 +02:00
Ursprung 54932f6ebc
Commit c1048cfdbd
8 geänderte Dateien mit 135 neuen und 80 gelöschten Zeilen

Datei anzeigen

@ -19,9 +19,9 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.messages.ChatSender;
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;
@ -44,25 +44,25 @@ public class DevCommand extends BasicCommand {
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender s, String[] args) {
if (!(sender instanceof ProxiedPlayer)) if (!(s instanceof ProxiedPlayer))
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) s;
SteamwarUser steamwarUser = SteamwarUser.get(player); ChatSender sender = ChatSender.of(player);
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoDevServer)) { if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) {
return; return;
} }
updateDevServers(); updateDevServers();
if(devServers.isEmpty()) { if(devServers.isEmpty()) {
Message.send("DEV_NO_SERVER", sender); sender.system("DEV_NO_SERVER");
} else if (devServers.size() == 1) { } else if (devServers.size() == 1) {
player.connect(devServers.values().stream().findAny().get()); player.connect(devServers.values().stream().findAny().get());
} else if (args.length == 0) { } else if (args.length == 0) {
ServerInfo info = devServers.get(player.getName().toLowerCase()); ServerInfo info = devServers.get(player.getName().toLowerCase());
if (info == null) { if (info == null) {
Message.send("DEV_UNKNOWN_SERVER", player); sender.system("DEV_UNKNOWN_SERVER");
return; return;
} }
@ -70,7 +70,7 @@ public class DevCommand extends BasicCommand {
} else { } else {
ServerInfo info = devServers.get(args[0].toLowerCase()); ServerInfo info = devServers.get(args[0].toLowerCase());
if (info == null) { if (info == null) {
Message.send("DEV_NO_SERVER", player); sender.system("DEV_NO_SERVER");
return; return;
} }

Datei anzeigen

@ -22,13 +22,14 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker; import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.messages.ChatSender;
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.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
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;
import java.util.LinkedList; import java.util.LinkedList;
@ -47,27 +48,27 @@ public class FightCommand extends BasicCommand {
super("fight", "", "f"); super("fight", "", "f");
} }
static ArenaMode getMode(CommandSender sender, String arg){ private static ArenaMode getMode(ChatSender sender, String arg){
ArenaMode mode = ArenaMode.getByChat(arg); ArenaMode mode = ArenaMode.getByChat(arg);
if(mode != null) if(mode != null)
return mode; return mode;
Message.send("FIGHT_UNKNOWN_GAMEMODE", sender, arg); sender.system("FIGHT_UNKNOWN_GAMEMODE", arg);
return null; return null;
} }
static String getMap(CommandSender sender, ArenaMode mode, String arg){ private static String getMap(ChatSender sender, ArenaMode mode, String arg){
String realMap = mode.hasMap(arg.toLowerCase()); String realMap = mode.hasMap(arg.toLowerCase());
if(realMap != null) if(realMap != null)
return realMap; return realMap;
if(arg.equalsIgnoreCase("Random")) if(arg.equalsIgnoreCase("Random"))
return mode.getRandomMap(); return mode.getRandomMap();
Message.send("FIGHT_UNKNOWN_ARENA", sender); sender.system("FIGHT_UNKNOWN_ARENA");
return null; return null;
} }
private static void getModes(CommandSender sender, String precommand, boolean historic){ private static void getModes(ChatSender sender, String precommand, boolean historic){
TextComponent start = new TextComponent(); TextComponent start = new TextComponent();
TextComponent current = start; TextComponent current = start;
for(ArenaMode mode : ArenaMode.getAllModes()){ for(ArenaMode mode : ArenaMode.getAllModes()){
@ -77,25 +78,25 @@ public class FightCommand extends BasicCommand {
current.setBold(true); current.setBold(true);
current.setColor(ChatColor.GRAY); current.setColor(ChatColor.GRAY);
current.setText(mode.getChatName() + " "); current.setText(mode.getChatName() + " ");
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create())); current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
if(current != start) if(current != start)
start.addExtra(current); start.addExtra(current);
current = new TextComponent(); current = new TextComponent();
} }
sender.sendMessage(start); sender.sendMessage(ChatMessageType.SYSTEM, start);
} }
private static void getMaps(CommandSender sender, String precommand, ArenaMode mode){ private static void getMaps(ChatSender sender, String precommand, ArenaMode mode){
TextComponent start = new TextComponent(); TextComponent start = new TextComponent();
TextComponent current = start; TextComponent current = start;
if(mode.getMaps().size() > 1){ if(mode.getMaps().size() > 1){
String command = precommand + mode.getChatName() + " Random"; String command = precommand + mode.getChatName() + " Random";
start.setBold(true); start.setBold(true);
start.setColor(ChatColor.GRAY); start.setColor(ChatColor.GRAY);
start.setText(Message.parse("FIGHT_ARENA_RANDOM", sender) + " "); start.setText(sender.parseToLegacy("FIGHT_ARENA_RANDOM") + " ");
start.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create())); start.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
start.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); start.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
current = new TextComponent(); current = new TextComponent();
} }
@ -105,14 +106,14 @@ public class FightCommand extends BasicCommand {
current.setBold(true); current.setBold(true);
current.setColor(ChatColor.GRAY); current.setColor(ChatColor.GRAY);
current.setText(map + " "); current.setText(map + " ");
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create())); current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
if(current != start) if(current != start)
start.addExtra(current); start.addExtra(current);
current = new TextComponent(); current = new TextComponent();
} }
sender.sendMessage(start); sender.sendMessage(ChatMessageType.SYSTEM, start);
} }
private static boolean alreadyInArena(ProxiedPlayer player){ private static boolean alreadyInArena(ProxiedPlayer player){
@ -125,14 +126,14 @@ public class FightCommand extends BasicCommand {
return false; return false;
} }
static void createArena(CommandSender sender, String precommand, String[] args, int startArg, boolean historic, FightCallback callback){ static void createArena(CommandSender s, String precommand, String[] args, int startArg, boolean historic, FightCallback callback){
if(!(sender instanceof ProxiedPlayer)) if(!(s instanceof ProxiedPlayer))
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) s;
SteamwarUser steamwarUser = SteamwarUser.get(player); ChatSender sender = ChatSender.of(player);
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) {
return; return;
} }
@ -140,7 +141,7 @@ public class FightCommand extends BasicCommand {
return; return;
if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) { if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) {
Message.send("MODLOADER_DENIED", sender); sender.system("MODLOADER_DENIED");
return; return;
} }

Datei anzeigen

@ -27,6 +27,7 @@ import de.steamwar.bungeecore.sql.Fight;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SchematicType; import de.steamwar.bungeecore.sql.SchematicType;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -41,15 +42,14 @@ public class ReplayCommand extends BasicCommand {
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender s, String[] args) {
if(!(sender instanceof ProxiedPlayer)) if(!(s instanceof ProxiedPlayer))
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) s;
SteamwarUser steamwarUser = SteamwarUser.get(player); ChatSender sender = ChatSender.of(player);
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) { if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
return; return;
}
new SWStreamInv<>(player, Message.parse("REPLAY_TITLE", player), (click, fight) -> { new SWStreamInv<>(player, Message.parse("REPLAY_TITLE", player), (click, fight) -> {
SteamwarUser user = SteamwarUser.get(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId());
@ -59,24 +59,24 @@ public class ReplayCommand extends BasicCommand {
if (user.getUserGroup().isAdminGroup() && click.isShiftClick() && fight.replayExists()) { if (user.getUserGroup().isAdminGroup() && click.isShiftClick() && fight.replayExists()) {
starter.test(mode, mode.getRandomMap(), player).start(); starter.test(mode, mode.getRandomMap(), player).start();
} else if(!fight.replayAllowed()) { } else if(!fight.replayAllowed()) {
Message.send("REPLAY_UNAVAILABLE", player); sender.system("REPLAY_UNAVAILABLE");
} else { } else {
starter.arena(mode, mode.getRandomMap()).start(); starter.arena(mode, mode.getRandomMap()).start();
} }
}, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(player, fight), fight)).collect(Collectors.toList())).open(); }, page -> Fight.getPage(page, 45).stream().map(fight -> new SWListInv.SWListEntry<>(getFightItem(sender, fight), fight)).collect(Collectors.toList())).open();
} }
private SWItem getFightItem(ProxiedPlayer player, Fight fight) { private SWItem getFightItem(ChatSender sender, Fight fight) {
SchematicType type = fight.getSchemType(); SchematicType type = fight.getSchemType();
SWItem item = new SWItem(type != null ? type.getMaterial() : "BARRIER", parseLeader(player, fight.getBlueLeader(), fight.getBluePlayers().size(), fight.getWin() == 1)); SWItem item = new SWItem(type != null ? type.getMaterial() : "BARRIER", parseLeader(sender, fight.getBlueLeader(), fight.getBluePlayers().size(), fight.getWin() == 1));
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
lore.add(parseLeader(player, fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2)); lore.add(parseLeader(sender, fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2));
lore.add(Message.parse("REPLAY_TIME", player, fight.getStartTime())); lore.add(sender.parseToLegacy("REPLAY_TIME", fight.getStartTime()));
lore.add(""); lore.add("");
lore.add(Message.parse("REPLAY_SERVER", player, fight.getServer())); lore.add(sender.parseToLegacy("REPLAY_SERVER", fight.getServer()));
if(!fight.replayAllowed()) if(!fight.replayAllowed())
lore.add(Message.parse("REPLAY_UNAVAILABLE", player)); lore.add(sender.parseToLegacy("REPLAY_UNAVAILABLE"));
item.setLore(lore); item.setLore(lore);
if(fight.replayAllowed()) if(fight.replayAllowed())
@ -85,7 +85,7 @@ public class ReplayCommand extends BasicCommand {
return item; return item;
} }
private String parseLeader(ProxiedPlayer player, SteamwarUser leader, int players, boolean winner) { private String parseLeader(ChatSender sender, SteamwarUser leader, int players, boolean winner) {
return Message.parse(winner ? (players > 1 ? "REPLAY_WINNER" : "REPLAY_SOLO_WINNER") : (players > 1 ? "REPLAY_LOSER" : "REPLAY_SOLO_LOSER"), player, leader.getUserName(), players - 1); return sender.parseToLegacy(winner ? (players > 1 ? "REPLAY_WINNER" : "REPLAY_SOLO_WINNER") : (players > 1 ? "REPLAY_LOSER" : "REPLAY_SOLO_LOSER"), leader.getUserName(), players - 1);
} }
} }

Datei anzeigen

@ -20,7 +20,11 @@
package de.steamwar.bungeecore.commands; package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.*; import de.steamwar.bungeecore.*;
import de.steamwar.bungeecore.sql.*; import de.steamwar.bungeecore.sql.BauweltMember;
import de.steamwar.bungeecore.sql.Event;
import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.Team;
import de.steamwar.messages.ChatSender;
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;
@ -35,16 +39,17 @@ public class TpCommand extends BasicCommand {
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender s, String[] args) {
if(!(sender instanceof ProxiedPlayer)) if(!(s instanceof ProxiedPlayer))
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) s;
ChatSender sender = ChatSender.of(player);
if(args.length == 0){ if(args.length == 0){
if(Event.get() == null) if(Event.get() == null)
Message.send("TP_USAGE", player); sender.system("TP_USAGE");
else else
Message.send("TP_USAGE_EVENT", player); sender.system("TP_USAGE_EVENT");
return; return;
} }
@ -67,8 +72,9 @@ public class TpCommand extends BasicCommand {
} }
public static void teleport(ProxiedPlayer player, ServerInfo server){ public static void teleport(ProxiedPlayer player, ServerInfo server){
ChatSender sender = ChatSender.of(player);
if(CheckCommand.isChecking(player)){ if(CheckCommand.isChecking(player)){
Message.send("CHECK_CHECKING", player); sender.system("CHECK_CHECKING");
return; return;
} }
@ -76,7 +82,7 @@ public class TpCommand extends BasicCommand {
Subserver subserver = Subserver.getSubserver(server); Subserver subserver = Subserver.getSubserver(server);
if (subserver instanceof Arenaserver) { if (subserver instanceof Arenaserver) {
if (!SteamwarUser.get(player).isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) if (!sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
SubserverSystem.sendPlayer(subserver, player); SubserverSystem.sendPlayer(subserver, player);
} else if(subserver instanceof Bauserver) { } else if(subserver instanceof Bauserver) {
@ -85,15 +91,13 @@ public class TpCommand extends BasicCommand {
SubserverSystem.sendPlayer(subserver, player); SubserverSystem.sendPlayer(subserver, player);
} else { } else {
SubserverSystem.sendDeniedMessage(player, bauserver.getOwner()); SubserverSystem.sendDeniedMessage(player, bauserver.getOwner());
Message.send("JOIN_PLAYER_BLOCK", player); sender.system("JOIN_PLAYER_BLOCK");
} }
} else if (serverPerm != null && !player.hasPermission(serverPerm)) { } else if (serverPerm != null && !player.hasPermission(serverPerm)) {
Message.send("JOIN_PLAYER_BLOCK", player); sender.system("JOIN_PLAYER_BLOCK");
} else if (serverPerm == null && !player.getGroups().contains("team")) { } else if (serverPerm == null && !player.getGroups().contains("team")) {
Message.send("JOIN_PLAYER_BLOCK", player); sender.system("JOIN_PLAYER_BLOCK");
} else { } else {
player.connect(server); player.connect(server);
} }

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.BannedUserIPs; import de.steamwar.bungeecore.sql.BannedUserIPs;
import de.steamwar.bungeecore.sql.Punishment; import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
@ -47,7 +48,7 @@ public class BanListener extends BasicListener {
if (user.isPunished(Punishment.PunishmentType.Ban)) { if (user.isPunished(Punishment.PunishmentType.Ban)) {
user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress()); user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress());
event.setCancelled(true); event.setCancelled(true);
event.setCancelReason(user.punishmentMessage(Punishment.PunishmentType.Ban, ProxyServer.getInstance().getPlayer(event.getConnection().getUniqueId()))); ChatSender.of(event).system(user.punishmentMessage(Punishment.PunishmentType.Ban));
return; return;
} }

Datei anzeigen

@ -24,8 +24,8 @@ import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.WebregisterCommand; import de.steamwar.bungeecore.commands.WebregisterCommand;
import de.steamwar.bungeecore.listeners.ConnectionListener; import de.steamwar.bungeecore.listeners.ConnectionListener;
import de.steamwar.messages.ChatSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -36,7 +36,6 @@ import java.net.UnknownHostException;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -293,11 +292,11 @@ public class SteamwarUser {
return true; return true;
} }
public boolean isPunishedWithMessage(ProxiedPlayer player, Punishment.PunishmentType punishment) { public boolean isPunishedWithMessage(ChatSender player, Punishment.PunishmentType punishment) {
if (!isPunished(punishment)) { if (!isPunished(punishment)) {
return false; return false;
} }
player.sendMessage(punishmentMessage(punishment, player)); player.system(punishmentMessage(punishment));
return true; return true;
} }
@ -316,7 +315,7 @@ public class SteamwarUser {
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid); ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
if (player != null) { if (player != null) {
updateBanIP(player.getAddress().getAddress().getHostAddress()); updateBanIP(player.getAddress().getAddress().getHostAddress());
player.disconnect(punishmentMessage(punishment, player)); ChatSender.disconnect(player).system(punishmentMessage(punishment));
for (BannedUserIPs banned : BannedUserIPs.get(player.getAddress().getAddress().getHostAddress())) { for (BannedUserIPs banned : BannedUserIPs.get(player.getAddress().getAddress().getHostAddress())) {
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID()); SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
if (isPunished(punishment) && bannedUser.getPunishment(punishment).getEndTime().before(time)) { if (isPunished(punishment) && bannedUser.getPunishment(punishment).getEndTime().before(time)) {
@ -328,12 +327,12 @@ public class SteamwarUser {
} }
} }
public TextComponent punishmentMessage(Punishment.PunishmentType punishment, ProxiedPlayer player) { public Message punishmentMessage(Punishment.PunishmentType punishment) {
Punishment currentPunishment = punishments.get(punishment); Punishment currentPunishment = punishments.get(punishment);
if (currentPunishment.isPerma()) { if (currentPunishment.isPerma()) {
return BungeeCore.stringToText(Message.parsePrefixed(punishment.getPlayerMessagePerma(), player, currentPunishment.getReason())); return new Message(punishment.getPlayerMessagePerma(), currentPunishment.getReason());
} else { } else {
return BungeeCore.stringToText(Message.parsePrefixed(punishment.getPlayerMessageUntil(), player, currentPunishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))), currentPunishment.getReason())); return new Message(punishment.getPlayerMessageUntil(), currentPunishment.getEndTime(), currentPunishment.getReason());
} }
} }

Datei anzeigen

@ -1,6 +1,6 @@
PREFIX=§eSteam§8War» PREFIX=§eSteam§8War»
SPACER= SPACER=
TIMEFORMAT=HH:mm dd.MM.yyyy TIMEFORMAT=dd.MM.yyyy HH:mm
PLAIN_STRING={0} PLAIN_STRING={0}
UNKNOWN_COMMAND=§cUnbekannter Befehl. UNKNOWN_COMMAND=§cUnbekannter Befehl.

Datei anzeigen

@ -34,6 +34,7 @@ import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; 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;
import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.command.ConsoleCommandSender; import net.md_5.bungee.command.ConsoleCommandSender;
import java.text.DateFormat; import java.text.DateFormat;
@ -41,6 +42,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.function.BiConsumer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -75,24 +77,28 @@ public interface ChatSender {
send(false, ChatMessageType.CHAT, null, null, message); send(false, ChatMessageType.CHAT, null, null, message);
} }
default void system(String message, Object... params) { default void system(String format, Object... params) {
send(true, ChatMessageType.SYSTEM, null, null, new Message(message, params)); system(new Message(format, params));
} }
default void system(String message, Message onHover, ClickEvent onClick, Object... params) { default void system(Message message) {
send(true, ChatMessageType.SYSTEM, onHover, onClick, new Message(message, params)); send(true, ChatMessageType.SYSTEM, null, null, message);
} }
default void prefixless(String message, Object... params) { default void system(String format, Message onHover, ClickEvent onClick, Object... params) {
send(false, ChatMessageType.SYSTEM, null, null, new Message(message, params)); send(true, ChatMessageType.SYSTEM, onHover, onClick, new Message(format, params));
} }
default void prefixless(String message, Message onHover, ClickEvent onClick, Object... params) { default void prefixless(String format, Object... params) {
send(false, ChatMessageType.SYSTEM, onHover, onClick, new Message(message, params)); prefixless(format, null, null, params);
}
default void prefixless(String format, Message onHover, ClickEvent onClick, Object... params) {
send(false, ChatMessageType.SYSTEM, onHover, onClick, new Message(format, params));
} }
default void send(boolean prefixed, ChatMessageType type, Message onHover, ClickEvent onClick, Message message) { default void send(boolean prefixed, ChatMessageType type, Message onHover, ClickEvent onClick, Message message) {
TextComponent msg = new TextComponent(parse(prefixed, message)); TextComponent msg = parseToComponent(prefixed, message);
if(onHover != null) if(onHover != null)
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(parse(false, onHover)))); msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(parse(false, onHover))));
if(onClick != null) if(onClick != null)
@ -100,6 +106,18 @@ public interface ChatSender {
sendMessage(type, msg); sendMessage(type, msg);
} }
default TextComponent parseToComponent(boolean prefixed, Message message) {
return new TextComponent(parse(prefixed, message));
}
default String parseToLegacy(String format, Object... params) {
return parseToLegacy(new Message(format, params));
}
default String parseToLegacy(Message message) {
return parseToComponent(false, message).toLegacyText();
}
default BaseComponent[] parse(boolean prefixed, Message message) { default BaseComponent[] parse(boolean prefixed, Message message) {
Locale locale = getLocale(); Locale locale = getLocale();
ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale); ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale);
@ -112,7 +130,7 @@ public interface ChatSender {
Object[] params = message.getParams(); Object[] params = message.getParams();
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
if(params[i] instanceof Message) { if(params[i] instanceof Message) {
params[i] = parse(false, (Message) params[i]); params[i] = parseToLegacy((Message) params[i]);
} else if(params[i] instanceof Date) { } else if(params[i] instanceof Date) {
params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]); params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]);
} else if(params[i] instanceof SteamwarUser) { } else if(params[i] instanceof SteamwarUser) {
@ -126,7 +144,7 @@ public interface ChatSender {
return TextComponent.fromLegacyText(format.format(params)); return TextComponent.fromLegacyText(format.format(params));
} }
static ChatSender of(ProxiedPlayer player) { static ChatSender ofProxiedPlayer(ProxiedPlayer player, BiConsumer<ChatMessageType, BaseComponent[]> sendMessage) {
return new ChatSender() { return new ChatSender() {
@Override @Override
public SteamwarUser user() { public SteamwarUser user() {
@ -148,11 +166,19 @@ public interface ChatSender {
@Override @Override
public void sendMessage(ChatMessageType type, BaseComponent... msg) { public void sendMessage(ChatMessageType type, BaseComponent... msg) {
player.sendMessage(type, msg); sendMessage.accept(type, msg);
} }
}; };
} }
static ChatSender of(ProxiedPlayer player) {
return ofProxiedPlayer(player, player::sendMessage);
}
static ChatSender disconnect(ProxiedPlayer player) {
return ofProxiedPlayer(player, (type, msg) -> player.disconnect(msg));
}
static ChatSender of(CommandSender sender) { static ChatSender of(CommandSender sender) {
if(sender instanceof ProxiedPlayer) if(sender instanceof ProxiedPlayer)
return of((ProxiedPlayer) sender); return of((ProxiedPlayer) sender);
@ -185,6 +211,30 @@ public interface ChatSender {
return of(ConsoleCommandSender.getInstance()); return of(ConsoleCommandSender.getInstance());
} }
static ChatSender of(LoginEvent event) {
return new ChatSender() {
@Override
public SteamwarUser user() {
return SteamwarUser.get(event.getConnection().getUniqueId());
}
@Override
public Locale getLocale() {
return Locale.getDefault();
}
@Override
public boolean chatShown() {
return false;
}
@Override
public void sendMessage(ChatMessageType type, BaseComponent... msg) {
event.setCancelReason(msg);
}
};
}
static ChatSender discordChannel(DiscordChatListener channel) { static ChatSender discordChannel(DiscordChatListener channel) {
return new ChatSender() { return new ChatSender() {
@Override @Override