geforkt von SteamWar/BungeeCore
Add Some Refactoring and enabling Doublelayer Messages
Dieser Commit ist enthalten in:
Ursprung
fec517f5a1
Commit
e76c79c8d8
@ -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.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.text.ChoiceFormat;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
public class Message {
|
public class Message {
|
||||||
private Message(){}
|
private Message(){}
|
||||||
|
|
||||||
public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){
|
public static TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, int[] useFormatter, Object... params){
|
||||||
return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, 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){
|
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){
|
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;
|
Locale locale;
|
||||||
if(sender instanceof ProxiedPlayer)
|
if(sender instanceof ProxiedPlayer)
|
||||||
locale = ((ProxiedPlayer)sender).getLocale();
|
locale = ((ProxiedPlayer)sender).getLocale();
|
||||||
@ -61,7 +70,11 @@ public class Message {
|
|||||||
pattern = resourceBundle.getObject("PREFIX") + " ";
|
pattern = resourceBundle.getObject("PREFIX") + " ";
|
||||||
pattern += (String)resourceBundle.getObject(message);
|
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){
|
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);
|
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){
|
public static void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
|
||||||
send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, 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);
|
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)
|
if(type == ChatMessageType.CHAT && sender instanceof ProxiedPlayer && ((ProxiedPlayer)sender).getChatMode() != ProxiedPlayer.ChatMode.SHOWN)
|
||||||
return;
|
return;
|
||||||
TextComponent msg = parseToComponent(message, prefixed, sender, params);
|
TextComponent msg = parseToComponent(message, prefixed, sender, useFormatter, params);
|
||||||
if(onHover != null)
|
if(onHover != null)
|
||||||
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
|
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
|
||||||
if(onClick != null)
|
if(onClick != null)
|
||||||
@ -102,9 +119,13 @@ public class Message {
|
|||||||
sender.sendMessage(msg);
|
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){
|
public static void broadcast(String message, String onHover, ClickEvent onClick, Object... params){
|
||||||
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers())
|
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){
|
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){
|
public static void team(String message, Object... params){
|
||||||
team(message, ChatMessageType.SYSTEM, 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()){
|
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
|
||||||
if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) {
|
if(player.getGroups().contains(ConnectionListener.TEAM_GROUP)) {
|
||||||
Object[] objects = new Object[params.length];
|
sendPrefixless(message, player, type, useFormatter, params);
|
||||||
for (int i = 0; i < params.length; i++) {
|
|
||||||
objects[i] = params[i].apply(player);
|
|
||||||
}
|
|
||||||
sendPrefixless(message, player, type, objects);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ import java.sql.Timestamp;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class BanCommand extends BasicCommand {
|
public class BanCommand extends BasicCommand {
|
||||||
@ -57,8 +56,7 @@ public class BanCommand extends BasicCommand {
|
|||||||
}
|
}
|
||||||
String msg = banReason.toString();
|
String msg = banReason.toString();
|
||||||
target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
|
target.ban(banTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
|
||||||
Message.team("BAN_TEAM_BANNED", target.getUserName(), sender.getName(),
|
Message.team("BAN_TEAM_BANNED", new int[]{2}, target.getUserName(), sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, banTime);
|
||||||
(args[1].equalsIgnoreCase("perma")?Message.parse("BAN_PERMA", sender):Message.parse("BAN_UNTIL", sender) + banTime.toLocalDateTime().format(DateTimeFormatter.ofPattern(Message.parse("TIMEFORMAT", sender)))), msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Timestamp parseTime(CommandSender sender, String arg){
|
public static Timestamp parseTime(CommandSender sender, String arg){
|
||||||
|
@ -24,7 +24,6 @@ import de.steamwar.bungeecore.sql.SteamwarUser;
|
|||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
public class MuteCommand extends BasicCommand {
|
public class MuteCommand extends BasicCommand {
|
||||||
|
|
||||||
@ -53,7 +52,6 @@ public class MuteCommand extends BasicCommand {
|
|||||||
}
|
}
|
||||||
String msg = muteReason.toString();
|
String msg = muteReason.toString();
|
||||||
target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
|
target.mute(muteTime, msg, SteamwarUser.get(sender.getName()).getId(), args[1].equalsIgnoreCase("perma"));
|
||||||
Message.team("MUTE_TEAM_MUTED", player -> target.getUserName(), player -> sender.getName(),
|
Message.team("MUTE_TEAM_MUTED", target.getUserName(), new int[]{2}, sender.getName(), (args[1].equalsIgnoreCase("perma")?"BAN_PERMA":"BAN_UNTIL"), msg, muteTime);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.bungeecore.commands;
|
package de.steamwar.bungeecore.commands;
|
||||||
|
|
||||||
import de.steamwar.bungeecore.BungeeCore;
|
import de.steamwar.bungeecore.BungeeCore;
|
||||||
|
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.bungeecore.sql.Team;
|
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 net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class WhoisCommand extends BasicCommand {
|
public class WhoisCommand extends BasicCommand {
|
||||||
public WhoisCommand(){
|
public WhoisCommand(){
|
||||||
@ -74,7 +76,7 @@ public class WhoisCommand extends BasicCommand {
|
|||||||
BungeeCore.send(player, "§7Strafen: ");
|
BungeeCore.send(player, "§7Strafen: ");
|
||||||
for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) {
|
for (Punishment punishment : Punishment.getAllPunishmentsOfPlayer(user.getId())) {
|
||||||
BungeeCore.send(player, "§7" + SteamwarUser.get(punishment.getPunisher()).getUserName() + "§8» §f§l" + punishment.getType().name() + ": §e"
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public class BanListener extends BasicListener {
|
|||||||
for(BannedUserIPs banned : ips) {
|
for(BannedUserIPs banned : ips) {
|
||||||
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
SteamwarUser bannedUser = SteamwarUser.get(banned.getUserID());
|
||||||
potentialBan.append(Message.parse("BAN_AVOIDING_LIST", target, bannedUser.getUserName(),
|
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());
|
TextComponent msg = new TextComponent(potentialBan.toString());
|
||||||
|
@ -134,11 +134,11 @@ public class Punishment {
|
|||||||
this.endTime = newUpdate;
|
this.endTime = newUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBantime(Timestamp endTime, boolean perma, ProxiedPlayer player) {
|
public String getBantime(Timestamp endTime, boolean perma) {
|
||||||
if(perma)
|
if(perma)
|
||||||
return Message.parse("BAN_PERMA", player);
|
return "Permanent";
|
||||||
else
|
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 {
|
public enum PunishmentType {
|
||||||
|
@ -96,7 +96,7 @@ USAGE_IGNORE=§8/§7ignore §8[§eSpieler§8]
|
|||||||
#Various commands
|
#Various commands
|
||||||
ALERT=§f{0}
|
ALERT=§f{0}
|
||||||
|
|
||||||
BAN_TEAM_BANNED=§c {0} wurde von {1} {2} gebannt. §f§lGrund: §f{3}
|
BAN_TEAM_BANNED=§c{0} wurde von {1} {2} gebannt. §f§lGrund: §f{3}
|
||||||
BANNED_MESSAGE_PERMA=§cDu bist permanent gebannt. §r§lGrund§r: §c{0}
|
BANNED_MESSAGE_PERMA=§cDu bist permanent gebannt. §r§lGrund§r: §c{0}
|
||||||
BANNED_MESSAGE_UNTIL=Du bist bis zum {0} gebannt. §r§lGrund§r: §c{1}
|
BANNED_MESSAGE_UNTIL=Du bist bis zum {0} gebannt. §r§lGrund§r: §c{1}
|
||||||
MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3}
|
MUTE_TEAM_MUTED=§c {0} wurde von {1} {2} gemuted. §f§lGrund: §f{3}
|
||||||
@ -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_CHANGED={0} verändert von {1} von {2} auf {3} wegen {4}
|
||||||
BAN_INVALID_TIME=§cUngültige Zeitangabe.
|
BAN_INVALID_TIME=§cUngültige Zeitangabe.
|
||||||
BAN_PERMA=Permanent
|
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_ALERT=§cMögliche Bannumgehung durch §r{0}§c: §c
|
||||||
BAN_AVOIDING_LIST={0} §e{1} §c
|
BAN_AVOIDING_LIST={0} §e{1} §c
|
||||||
BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung
|
BAN_AVOIDING_BAN_HOVER=§cBanne Spieler wegen Bannumgehung
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren