geforkt von SteamWar/BungeeCore
Current state
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
54932f6ebc
Commit
c1048cfdbd
@ -19,9 +19,9 @@
|
||||
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -44,25 +44,25 @@ public class DevCommand extends BasicCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (!(sender instanceof ProxiedPlayer))
|
||||
public void execute(CommandSender s, String[] args) {
|
||||
if (!(s instanceof ProxiedPlayer))
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
ProxiedPlayer player = (ProxiedPlayer) s;
|
||||
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoDevServer)) {
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoDevServer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateDevServers();
|
||||
if(devServers.isEmpty()) {
|
||||
Message.send("DEV_NO_SERVER", sender);
|
||||
sender.system("DEV_NO_SERVER");
|
||||
} else if (devServers.size() == 1) {
|
||||
player.connect(devServers.values().stream().findAny().get());
|
||||
} else if (args.length == 0) {
|
||||
ServerInfo info = devServers.get(player.getName().toLowerCase());
|
||||
if (info == null) {
|
||||
Message.send("DEV_UNKNOWN_SERVER", player);
|
||||
sender.system("DEV_UNKNOWN_SERVER");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class DevCommand extends BasicCommand {
|
||||
} else {
|
||||
ServerInfo info = devServers.get(args[0].toLowerCase());
|
||||
if (info == null) {
|
||||
Message.send("DEV_NO_SERVER", player);
|
||||
sender.system("DEV_NO_SERVER");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,13 +22,14 @@ package de.steamwar.bungeecore.commands;
|
||||
import de.steamwar.bungeecore.*;
|
||||
import de.steamwar.bungeecore.listeners.mods.ModLoaderBlocker;
|
||||
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.ChatMessageType;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
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.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.util.LinkedList;
|
||||
@ -47,27 +48,27 @@ public class FightCommand extends BasicCommand {
|
||||
super("fight", "", "f");
|
||||
}
|
||||
|
||||
static ArenaMode getMode(CommandSender sender, String arg){
|
||||
private static ArenaMode getMode(ChatSender sender, String arg){
|
||||
ArenaMode mode = ArenaMode.getByChat(arg);
|
||||
if(mode != null)
|
||||
return mode;
|
||||
|
||||
Message.send("FIGHT_UNKNOWN_GAMEMODE", sender, arg);
|
||||
sender.system("FIGHT_UNKNOWN_GAMEMODE", arg);
|
||||
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());
|
||||
if(realMap != null)
|
||||
return realMap;
|
||||
if(arg.equalsIgnoreCase("Random"))
|
||||
return mode.getRandomMap();
|
||||
|
||||
Message.send("FIGHT_UNKNOWN_ARENA", sender);
|
||||
sender.system("FIGHT_UNKNOWN_ARENA");
|
||||
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 current = start;
|
||||
for(ArenaMode mode : ArenaMode.getAllModes()){
|
||||
@ -77,25 +78,25 @@ public class FightCommand extends BasicCommand {
|
||||
current.setBold(true);
|
||||
current.setColor(ChatColor.GRAY);
|
||||
current.setText(mode.getChatName() + " ");
|
||||
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create()));
|
||||
current.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
|
||||
current.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
if(current != start)
|
||||
start.addExtra(current);
|
||||
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 current = start;
|
||||
if(mode.getMaps().size() > 1){
|
||||
String command = precommand + mode.getChatName() + " Random";
|
||||
start.setBold(true);
|
||||
start.setColor(ChatColor.GRAY);
|
||||
start.setText(Message.parse("FIGHT_ARENA_RANDOM", sender) + " ");
|
||||
start.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§e" + command).create()));
|
||||
start.setText(sender.parseToLegacy("FIGHT_ARENA_RANDOM") + " ");
|
||||
start.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("§e" + command)));
|
||||
start.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
current = new TextComponent();
|
||||
}
|
||||
@ -105,14 +106,14 @@ public class FightCommand extends BasicCommand {
|
||||
current.setBold(true);
|
||||
current.setColor(ChatColor.GRAY);
|
||||
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));
|
||||
if(current != start)
|
||||
start.addExtra(current);
|
||||
current = new TextComponent();
|
||||
}
|
||||
|
||||
sender.sendMessage(start);
|
||||
sender.sendMessage(ChatMessageType.SYSTEM, start);
|
||||
}
|
||||
|
||||
private static boolean alreadyInArena(ProxiedPlayer player){
|
||||
@ -125,14 +126,14 @@ public class FightCommand extends BasicCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void createArena(CommandSender sender, String precommand, String[] args, int startArg, boolean historic, FightCallback callback){
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
static void createArena(CommandSender s, String precommand, String[] args, int startArg, boolean historic, FightCallback callback){
|
||||
if(!(s instanceof ProxiedPlayer))
|
||||
return;
|
||||
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
ProxiedPlayer player = (ProxiedPlayer) s;
|
||||
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,7 +141,7 @@ public class FightCommand extends BasicCommand {
|
||||
return;
|
||||
|
||||
if(ModLoaderBlocker.isFabric(player) && !precommand.equals("/bau testarena ")) {
|
||||
Message.send("MODLOADER_DENIED", sender);
|
||||
sender.system("MODLOADER_DENIED");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import de.steamwar.bungeecore.sql.Fight;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SchematicType;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
@ -41,15 +42,14 @@ public class ReplayCommand extends BasicCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
public void execute(CommandSender s, String[] args) {
|
||||
if(!(s instanceof ProxiedPlayer))
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
ProxiedPlayer player = (ProxiedPlayer) s;
|
||||
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player);
|
||||
if (steamwarUser.isPunishedWithMessage(player, Punishment.PunishmentType.NoFightServer)) {
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
if (sender.user().isPunishedWithMessage(sender, Punishment.PunishmentType.NoFightServer))
|
||||
return;
|
||||
}
|
||||
|
||||
new SWStreamInv<>(player, Message.parse("REPLAY_TITLE", player), (click, fight) -> {
|
||||
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||
@ -59,24 +59,24 @@ public class ReplayCommand extends BasicCommand {
|
||||
if (user.getUserGroup().isAdminGroup() && click.isShiftClick() && fight.replayExists()) {
|
||||
starter.test(mode, mode.getRandomMap(), player).start();
|
||||
} else if(!fight.replayAllowed()) {
|
||||
Message.send("REPLAY_UNAVAILABLE", player);
|
||||
sender.system("REPLAY_UNAVAILABLE");
|
||||
} else {
|
||||
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();
|
||||
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<>();
|
||||
lore.add(parseLeader(player, fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2));
|
||||
lore.add(Message.parse("REPLAY_TIME", player, fight.getStartTime()));
|
||||
lore.add(parseLeader(sender, fight.getRedLeader(), fight.getRedPlayers().size(), fight.getWin() == 2));
|
||||
lore.add(sender.parseToLegacy("REPLAY_TIME", fight.getStartTime()));
|
||||
lore.add("");
|
||||
lore.add(Message.parse("REPLAY_SERVER", player, fight.getServer()));
|
||||
lore.add(sender.parseToLegacy("REPLAY_SERVER", fight.getServer()));
|
||||
if(!fight.replayAllowed())
|
||||
lore.add(Message.parse("REPLAY_UNAVAILABLE", player));
|
||||
lore.add(sender.parseToLegacy("REPLAY_UNAVAILABLE"));
|
||||
item.setLore(lore);
|
||||
|
||||
if(fight.replayAllowed())
|
||||
@ -85,7 +85,7 @@ public class ReplayCommand extends BasicCommand {
|
||||
return item;
|
||||
}
|
||||
|
||||
private String parseLeader(ProxiedPlayer player, 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);
|
||||
private String parseLeader(ChatSender sender, SteamwarUser leader, int players, boolean winner) {
|
||||
return sender.parseToLegacy(winner ? (players > 1 ? "REPLAY_WINNER" : "REPLAY_SOLO_WINNER") : (players > 1 ? "REPLAY_LOSER" : "REPLAY_SOLO_LOSER"), leader.getUserName(), players - 1);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,11 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
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.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -35,16 +39,17 @@ public class TpCommand extends BasicCommand {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if(!(sender instanceof ProxiedPlayer))
|
||||
public void execute(CommandSender s, String[] args) {
|
||||
if(!(s instanceof ProxiedPlayer))
|
||||
return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
ProxiedPlayer player = (ProxiedPlayer) s;
|
||||
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
if(args.length == 0){
|
||||
if(Event.get() == null)
|
||||
Message.send("TP_USAGE", player);
|
||||
sender.system("TP_USAGE");
|
||||
else
|
||||
Message.send("TP_USAGE_EVENT", player);
|
||||
sender.system("TP_USAGE_EVENT");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -67,8 +72,9 @@ public class TpCommand extends BasicCommand {
|
||||
}
|
||||
|
||||
public static void teleport(ProxiedPlayer player, ServerInfo server){
|
||||
ChatSender sender = ChatSender.of(player);
|
||||
if(CheckCommand.isChecking(player)){
|
||||
Message.send("CHECK_CHECKING", player);
|
||||
sender.system("CHECK_CHECKING");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,7 +82,7 @@ public class TpCommand extends BasicCommand {
|
||||
Subserver subserver = Subserver.getSubserver(server);
|
||||
|
||||
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);
|
||||
|
||||
} else if(subserver instanceof Bauserver) {
|
||||
@ -85,15 +91,13 @@ public class TpCommand extends BasicCommand {
|
||||
SubserverSystem.sendPlayer(subserver, player);
|
||||
} else {
|
||||
SubserverSystem.sendDeniedMessage(player, bauserver.getOwner());
|
||||
Message.send("JOIN_PLAYER_BLOCK", player);
|
||||
sender.system("JOIN_PLAYER_BLOCK");
|
||||
}
|
||||
|
||||
} 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")) {
|
||||
Message.send("JOIN_PLAYER_BLOCK", player);
|
||||
|
||||
sender.system("JOIN_PLAYER_BLOCK");
|
||||
} else {
|
||||
player.connect(server);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.BannedUserIPs;
|
||||
import de.steamwar.bungeecore.sql.Punishment;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
@ -47,7 +48,7 @@ public class BanListener extends BasicListener {
|
||||
if (user.isPunished(Punishment.PunishmentType.Ban)) {
|
||||
user.updateBanIP(event.getConnection().getAddress().getAddress().getHostAddress());
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ import de.steamwar.bungeecore.BungeeCore;
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.commands.WebregisterCommand;
|
||||
import de.steamwar.bungeecore.listeners.ConnectionListener;
|
||||
import de.steamwar.messages.ChatSender;
|
||||
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.ProxiedPlayer;
|
||||
|
||||
@ -36,7 +36,6 @@ import java.net.UnknownHostException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
@ -293,11 +292,11 @@ public class SteamwarUser {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isPunishedWithMessage(ProxiedPlayer player, Punishment.PunishmentType punishment) {
|
||||
public boolean isPunishedWithMessage(ChatSender player, Punishment.PunishmentType punishment) {
|
||||
if (!isPunished(punishment)) {
|
||||
return false;
|
||||
}
|
||||
player.sendMessage(punishmentMessage(punishment, player));
|
||||
player.system(punishmentMessage(punishment));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -316,7 +315,7 @@ public class SteamwarUser {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if (player != null) {
|
||||
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())) {
|
||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
||||
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);
|
||||
if (currentPunishment.isPerma()) {
|
||||
return BungeeCore.stringToText(Message.parsePrefixed(punishment.getPlayerMessagePerma(), player, currentPunishment.getReason()));
|
||||
return new Message(punishment.getPlayerMessagePerma(), currentPunishment.getReason());
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
PREFIX=§eSteam§8War»
|
||||
SPACER=
|
||||
TIMEFORMAT=HH:mm dd.MM.yyyy
|
||||
TIMEFORMAT=dd.MM.yyyy HH:mm
|
||||
PLAIN_STRING={0}
|
||||
|
||||
UNKNOWN_COMMAND=§cUnbekannter Befehl.
|
||||
|
@ -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.hover.content.Text;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.LoginEvent;
|
||||
import net.md_5.bungee.command.ConsoleCommandSender;
|
||||
|
||||
import java.text.DateFormat;
|
||||
@ -41,6 +42,7 @@ import java.text.MessageFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -75,24 +77,28 @@ public interface ChatSender {
|
||||
send(false, ChatMessageType.CHAT, null, null, message);
|
||||
}
|
||||
|
||||
default void system(String message, Object... params) {
|
||||
send(true, ChatMessageType.SYSTEM, null, null, new Message(message, params));
|
||||
default void system(String format, Object... params) {
|
||||
system(new Message(format, params));
|
||||
}
|
||||
|
||||
default void system(String message, Message onHover, ClickEvent onClick, Object... params) {
|
||||
send(true, ChatMessageType.SYSTEM, onHover, onClick, new Message(message, params));
|
||||
default void system(Message message) {
|
||||
send(true, ChatMessageType.SYSTEM, null, null, message);
|
||||
}
|
||||
|
||||
default void prefixless(String message, Object... params) {
|
||||
send(false, ChatMessageType.SYSTEM, null, null, new Message(message, params));
|
||||
default void system(String format, Message onHover, ClickEvent onClick, Object... params) {
|
||||
send(true, ChatMessageType.SYSTEM, onHover, onClick, new Message(format, params));
|
||||
}
|
||||
|
||||
default void prefixless(String message, Message onHover, ClickEvent onClick, Object... params) {
|
||||
send(false, ChatMessageType.SYSTEM, onHover, onClick, new Message(message, params));
|
||||
default void prefixless(String format, Object... 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) {
|
||||
TextComponent msg = new TextComponent(parse(prefixed, message));
|
||||
TextComponent msg = parseToComponent(prefixed, message);
|
||||
if(onHover != null)
|
||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(parse(false, onHover))));
|
||||
if(onClick != null)
|
||||
@ -100,6 +106,18 @@ public interface ChatSender {
|
||||
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) {
|
||||
Locale locale = getLocale();
|
||||
ResourceBundle resourceBundle = SteamwarResourceBundle.getResourceBundle(locale);
|
||||
@ -112,7 +130,7 @@ public interface ChatSender {
|
||||
Object[] params = message.getParams();
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
if(params[i] instanceof Message) {
|
||||
params[i] = parse(false, (Message) params[i]);
|
||||
params[i] = parseToLegacy((Message) params[i]);
|
||||
} else if(params[i] instanceof Date) {
|
||||
params[i] = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format((Date) params[i]);
|
||||
} else if(params[i] instanceof SteamwarUser) {
|
||||
@ -126,7 +144,7 @@ public interface ChatSender {
|
||||
return TextComponent.fromLegacyText(format.format(params));
|
||||
}
|
||||
|
||||
static ChatSender of(ProxiedPlayer player) {
|
||||
static ChatSender ofProxiedPlayer(ProxiedPlayer player, BiConsumer<ChatMessageType, BaseComponent[]> sendMessage) {
|
||||
return new ChatSender() {
|
||||
@Override
|
||||
public SteamwarUser user() {
|
||||
@ -148,11 +166,19 @@ public interface ChatSender {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
if(sender instanceof ProxiedPlayer)
|
||||
return of((ProxiedPlayer) sender);
|
||||
@ -185,6 +211,30 @@ public interface ChatSender {
|
||||
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) {
|
||||
return new ChatSender() {
|
||||
@Override
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren