Merge pull request 'Implementing first multilingual framework' (#52) from multiLingualFramework into master
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
1b17b513d2
13
SpigotCore_12/src/de/steamwar/message/Message_12.java
Normale Datei
13
SpigotCore_12/src/de/steamwar/message/Message_12.java
Normale Datei
@ -0,0 +1,13 @@
|
|||||||
|
package de.steamwar.message;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
class Message_12 {
|
||||||
|
private Message_12(){}
|
||||||
|
|
||||||
|
static Locale getLocale(Player player){
|
||||||
|
return Locale.forLanguageTag(player.getLocale());
|
||||||
|
}
|
||||||
|
}
|
13
SpigotCore_8/src/de/steamwar/message/Message_8.java
Normale Datei
13
SpigotCore_8/src/de/steamwar/message/Message_8.java
Normale Datei
@ -0,0 +1,13 @@
|
|||||||
|
package de.steamwar.message;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
class Message_8 {
|
||||||
|
private Message_8(){}
|
||||||
|
|
||||||
|
static Locale getLocale(Player player){
|
||||||
|
return Locale.forLanguageTag(player.spigot().getLocale());
|
||||||
|
}
|
||||||
|
}
|
137
SpigotCore_Main/src/de/steamwar/message/Message.java
Normale Datei
137
SpigotCore_Main/src/de/steamwar/message/Message.java
Normale Datei
@ -0,0 +1,137 @@
|
|||||||
|
package de.steamwar.message;
|
||||||
|
|
||||||
|
import de.steamwar.core.Core;
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class Message {
|
||||||
|
|
||||||
|
private final String resourceBundleName;
|
||||||
|
|
||||||
|
public Message(String resourceBundleName){
|
||||||
|
this.resourceBundleName = resourceBundleName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parsing input to a message */
|
||||||
|
|
||||||
|
public TextComponent parseToComponent(String message, boolean prefixed, CommandSender sender, Object... params){
|
||||||
|
return new TextComponent(TextComponent.fromLegacyText(parse(message, prefixed, sender, params)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parsePrefixed(String message, CommandSender sender, Object... params){
|
||||||
|
return parse(message, true, sender, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String parse(String message, CommandSender sender, Object... params){
|
||||||
|
return parse(message, false, sender, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String parse(String message, boolean prefixed, CommandSender sender, Object... params){
|
||||||
|
Locale locale;
|
||||||
|
if(sender instanceof Player)
|
||||||
|
locale = getLocale((Player) sender);
|
||||||
|
else
|
||||||
|
locale = Locale.getDefault();
|
||||||
|
|
||||||
|
ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceBundleName, locale);
|
||||||
|
String pattern = "";
|
||||||
|
if(prefixed)
|
||||||
|
pattern = resourceBundle.getObject("PREFIX") + " ";
|
||||||
|
pattern += (String)resourceBundle.getObject(message);
|
||||||
|
|
||||||
|
return new MessageFormat(pattern, locale).format(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Locale getLocale(Player player){
|
||||||
|
switch(Core.getVersion()){
|
||||||
|
case 8:
|
||||||
|
case 9:
|
||||||
|
case 10:
|
||||||
|
return Message_8.getLocale(player);
|
||||||
|
case 12:
|
||||||
|
case 14:
|
||||||
|
case 15:
|
||||||
|
default:
|
||||||
|
return Message_12.getLocale(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send a message to one player */
|
||||||
|
|
||||||
|
public void send(String message, CommandSender sender, Object... params){
|
||||||
|
send(message, true, sender, ChatMessageType.SYSTEM, null, null, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPrefixless(String message, CommandSender sender, Object... params){
|
||||||
|
send(message, false, sender, ChatMessageType.SYSTEM, null, null, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(String message, CommandSender sender, ChatMessageType type, Object... params){
|
||||||
|
send(message, true, sender, type, null, null, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPrefixless(String message, CommandSender sender, ChatMessageType type, Object... params){
|
||||||
|
send(message, false, sender, type, null, null, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
|
||||||
|
send(message, true, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPrefixless(String message, CommandSender sender, String onHover, ClickEvent onClick, Object... params){
|
||||||
|
send(message, false, sender, ChatMessageType.SYSTEM, onHover, onClick, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void send(String message, boolean prefixed, CommandSender sender, ChatMessageType type, String onHover, ClickEvent onClick, Object... params){
|
||||||
|
TextComponent msg = parseToComponent(message, prefixed, sender, params);
|
||||||
|
if(onHover != null)
|
||||||
|
msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover)));
|
||||||
|
if(onClick != null)
|
||||||
|
msg.setClickEvent(onClick);
|
||||||
|
if(sender instanceof Player)
|
||||||
|
((Player)sender).spigot().sendMessage(type, msg);
|
||||||
|
else
|
||||||
|
sender.spigot().sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send message to all players */
|
||||||
|
|
||||||
|
public void broadcastPrefixless(String message, String onHover, ClickEvent onClick, Object... params){
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
sendPrefixless(message, player, parse(onHover, false, player), onClick, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcastPrefixless(String message, Object... params){
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
sendPrefixless(message, player, ChatMessageType.SYSTEM, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcastActionbar(String message, Object... params){
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
send(message, player, ChatMessageType.ACTION_BAR, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast(String message, String onHover, ClickEvent onClick, Object... params){
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
send(message, player, parse(onHover, false, player), onClick, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void broadcast(String message, Object... params){
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
send(message, player, ChatMessageType.SYSTEM, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void chat(String message, Object... params){
|
||||||
|
for(Player player : Bukkit.getOnlinePlayers())
|
||||||
|
sendPrefixless(message, player, ChatMessageType.CHAT, params);
|
||||||
|
}
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren