SteamWar/BungeeCore
Archiviert
13
2

Add Some Refactoring and enabling Doublelayer Messages

Dieser Commit ist enthalten in:
Chaoscaot 2021-01-15 19:29:44 +01:00
Ursprung fec517f5a1
Commit e76c79c8d8
7 geänderte Dateien mit 50 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -28,27 +28,36 @@ import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.text.ChoiceFormat;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.function.Function;
public class Message {
private Message(){}
public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){
return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, params)));
public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){
return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, useFormatter, params)));
}
public static String parsePrefixed(String message, CommandSender sender, int[] useFormatter, Object... params){
return parse(message, true, sender, useFormatter, params);
}
public static String parsePrefixed(String message, CommandSender sender, Object... params){
return parse(message, true, sender, params);
return parse(message, true, sender, new int[0], params);
}
public static String parse(String message, CommandSender sender, int[] useFormatter, Object... params){
return parse(message, false, sender, useFormatter, params);
}
public static String parse(String message, CommandSender sender, Object... params){
return parse(message, false, sender, params);
return parse(message, false, sender, new int[0], params);
}
private static String parse(String message, boolean prefixed, CommandSender sender,Object... params){
private static String parse(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){
Locale locale;
if(sender instanceof ProxiedPlayer)
locale = ((ProxiedPlayer)sender).getLocale();
@ -61,7 +70,11 @@ public class Message {
pattern = resourceBundle.getObject("PREFIX") + " ";
pattern += (String)resourceBundle.getObject(message);
return new MessageFormat(pattern, locale).format(params);
MessageFormat format = new MessageFormat(pattern, locale);
for (int i : useFormatter) {
params[i] = new MessageFormat((String) resourceBundle.getObject((String) params[i]), locale).format(params);
}
return format.format(params);
}
public static void send(String message, CommandSender sender, Object... params){
@ -80,6 +93,10 @@ public class Message {
send(message, false, sender, type, null, null, params);
}
public static void sendPrefixless(String message, CommandSender sender, ChatMessageType type, int[] useFormatter, Object... params) {
send(message, false, sender, type, null, null, useFormatter, params);
}
public static void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
}
@ -88,10 +105,10 @@ public class Message {
send(message, false, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
}
public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){
public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, int[] useFormatter, Object... params){
if(type == ChatMessageType.CHAT && sender instanceof ProxiedPlayer && ((ProxiedPlayer)sender).getChatMode() != ProxiedPlayer.ChatMode.SHOWN)
return;
TextComponent msg = parseToComponent(message, prefixed, sender, params);
TextComponent msg = parseToComponent(message, prefixed, sender, useFormatter, params);
if(onHover != null)
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
if(onClick != null)
@ -102,9 +119,13 @@ public class Message {
sender.sendMessage(msg);
}
public static void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){
send(message, prefixed, sender, type, onHover, onClick, new int[0], params);
}
public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params){
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers())
send(message, player, parse(onHover, false, player), onClick, params);
send(message, player, parse(onHover, false, player, new int[0]), onClick, params);
}
public static void broadcast(String message, Object... params){
@ -120,18 +141,18 @@ public class Message {
}
}
public static void team(String message, Function<ProxiedPlayer, Object>... params){
team(message, ChatMessageType.SYSTEM, params);
public static void team(String message, Object... params){
team(message, ChatMessageType.SYSTEM, new int[0], params);
}
public static void team(String message, ChatMessageType type, Function<ProxiedPlayer, Object>... params){
public static void team(String message, int[] useChoice, Object... params){
team(message, ChatMessageType.SYSTEM, useChoice, params);
}
public static void team(String message, ChatMessageType type, int[] useFormatter, Object... params){
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) {
Object[] objects = new Object[params.length];
for (int i = 0; i < params.length; i++) {
objects[i] = params[i].apply(player);
}
sendPrefixless(message, player, type, objects);
sendPrefixless(message, player, type, useFormatter, params);
}
}
}

Datei anzeigen

@ -27,7 +27,6 @@ import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Date;
public class BanCommand extends BasicCommand {
@ -57,8 +56,7 @@ public class BanCommand extends BasicCommand {
}
String msg = banReason.toString();
target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(),
(args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + banTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", sender)))), msg);
Message.team("BAN_TEAM_BANNED", new int[]{2}, target.getUserName(), sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, banTime);
}
public static Timestamp parseTime(CommandSender sender, String arg){

Datei anzeigen

@ -24,7 +24,6 @@ import de.steamwar.bungeecore.sql.SteamwarUser;
import net.md_5.bungee.api.CommandSender;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
public class MuteCommand extends BasicCommand {
@ -53,7 +52,6 @@ public class MuteCommand extends BasicCommand {
}
String msg = muteReason.toString();
target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
Message.team("MUTE_TEAM_MUTED", player -> target.getUserName(), player -> sender.getName(),
player -> (args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", player):Message.parse("BAN_UNTIL", player) + muteTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)))), player -> msg);
Message.team("MUTE_TEAM_MUTED", target.getUserName(), new int[]{2}, sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, muteTime);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.sql.Punishment;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Team;
@ -28,6 +29,7 @@ import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.text.DecimalFormat;
import java.time.format.DateTimeFormatter;
public class WhoisCommand extends BasicCommand {
public WhoisCommand(){
@ -74,7 +76,7 @@ public class WhoisCommand extends BasicCommand {
BungeeCore.send(player, "§7Strafen: ");
for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) {
BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e"
+ punishment.getStartTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(BungeeCore.DATE_FORMAT)) + " §c" + punishment.getReason());
+ punishment.getStartTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player))) + " - " + (punishment.isPerma()?"Perma":punishment.getEndTime().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)))) + " §c" + punishment.getReason());
}
}
}

Datei anzeigen

@ -70,7 +70,7 @@ public class BanListener extends BasicListener {
for(BannedUserIPs banned : ips) {
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getUserName(),
banned.getTimestamp().toLocalDateTime().format(BungeeCore.DATE_FORMAT)));
banned.getTimestamp().toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", target)))));
}
TextComponent msg = new TextComponent(potentialBan.toString());

Datei anzeigen

@ -134,11 +134,11 @@ public class Punishment {
this.endTime = newUpdate;
}
public String getBantime(Timestamp endTime, boolean perma, ProxiedPlayer player) {
public String getBantime(Timestamp endTime, boolean perma) {
if(perma)
return Message.parse("BAN_PERMA", player);
return "Permanent";
else
return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", player)));
return endTime.toLocalDateTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm"));
}
public enum PunishmentType {

Datei anzeigen

@ -105,7 +105,7 @@ MUTED_MESSAGE_UNTIL=Du bist bis zum {0} gemuted. §r§lGrund§r: §c{1}
BAN_CHANGED={0} verändert von {1} von {2} auf {3} wegen {4}
BAN_INVALID_TIME=§cUngültige Zeitangabe.
BAN_PERMA=Permanent
BAN_UNTIL=bis zum
BAN_UNTIL=bis zum {4}
BAN_AVOIDING_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c
BAN_AVOIDING_LIST={0} §e{1} §c
BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung