Skip to content

Commit

Permalink
Add separate language config
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Nov 5, 2018
1 parent 05c8148 commit a7422d4
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 99 deletions.
8 changes: 7 additions & 1 deletion bukkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@
<groupId>de.themoep.resourcepacksplugin</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.themoep.utils</groupId>
<artifactId>lang-bukkit</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>us.myles</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
*/
public class UsePackCommand implements CommandExecutor {

ResourcepacksPlugin plugin;
private final ResourcepacksPlugin plugin;
private final UsePackCommandExecutor usepackCommand;

public UsePackCommand(WorldResourcepacks plugin) {
this.plugin = plugin;
usepackCommand = new UsePackCommandExecutor(plugin);
}

@Override
Expand All @@ -43,6 +45,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(sender instanceof Player) {
s = plugin.getPlayer(((Player) sender).getUniqueId());
}
return new UsePackCommandExecutor(plugin).execute(s, args);
if(!usepackCommand.execute(s, args)) {
plugin.sendMessage(s, "command.usepack.usage");
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import de.themoep.resourcepacksplugin.core.UserManager;
import de.themoep.resourcepacksplugin.core.events.IResourcePackSelectEvent;
import de.themoep.resourcepacksplugin.core.events.IResourcePackSendEvent;
import de.themoep.utils.lang.bukkit.LanguageManager;
import fr.xephi.authme.api.v3.AuthMeApi;
import fr.xephi.authme.events.LoginEvent;
import org.bukkit.ChatColor;
Expand Down Expand Up @@ -66,6 +67,8 @@ public class WorldResourcepacks extends JavaPlugin implements ResourcepacksPlugi

private UserManager um;

private LanguageManager lm;

private Level loglevel = Level.INFO;

private int serverPackFormat = Integer.MAX_VALUE;
Expand All @@ -80,6 +83,7 @@ public class WorldResourcepacks extends JavaPlugin implements ResourcepacksPlugi
public void onEnable() {
storedPacks = new ConfigAccessor(this, "players.yml");
if (loadConfig()) {
lm = new LanguageManager(this, getConfig().getString("default-language"));
getServer().getPluginManager().registerEvents(new DisconnectListener(this), this);
getServer().getPluginManager().registerEvents(new WorldSwitchListener(this), this);

Expand Down Expand Up @@ -420,22 +424,16 @@ public UserManager getUserManager() {
return um;
}

public String getMessage(String key) {
String msg = getConfig().getString("messages." + key);
if(msg == null || msg.isEmpty()) {
msg = "&cUnknown message key: &6messages." + key;
}
return ChatColor.translateAlternateColorCodes('&', msg);
}

public String getMessage(String key, Map<String, String> replacements) {
String msg = getMessage(key);
if (replacements != null) {
for(Map.Entry<String, String> repl : replacements.entrySet()) {
msg = msg.replace("%" + repl.getKey() + "%", repl.getValue());
@Override
public String getMessage(ResourcepacksPlayer sender, String key, String... replacements) {
if (lm != null) {
Player player = null;
if (sender != null) {
player = getServer().getPlayer(sender.getUniqueId());
}
return lm.getConfig(player).get(key, replacements);
}
return msg;
return key;
}

public String getVersion() {
Expand Down Expand Up @@ -465,12 +463,13 @@ public ResourcepacksPlayer getPlayer(String playerName) {
}

@Override
public boolean sendMessage(ResourcepacksPlayer player, String message) {
return sendMessage(player, Level.INFO, message);
public boolean sendMessage(ResourcepacksPlayer player, String key, String... replacements) {
return sendMessage(player, Level.INFO, key, replacements);
}

@Override
public boolean sendMessage(ResourcepacksPlayer packPlayer, Level level, String message) {
public boolean sendMessage(ResourcepacksPlayer packPlayer, Level level, String key, String... replacements) {
String message = getMessage(packPlayer, key, replacements);
if(packPlayer != null) {
Player player = getServer().getPlayer(packPlayer.getUniqueId());
if(player != null) {
Expand All @@ -483,8 +482,6 @@ public boolean sendMessage(ResourcepacksPlayer packPlayer, Level level, String m
return false;
}



@Override
public boolean checkPermission(ResourcepacksPlayer player, String perm) {
// Console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
*/
public class WorldResourcepacksCommand implements CommandExecutor {

ResourcepacksPlugin plugin;
private final ResourcepacksPlugin plugin;
private final ResourcepacksPluginCommandExecutor resourcepacksCommand;

public WorldResourcepacksCommand(WorldResourcepacks plugin) {
this.plugin = plugin;
resourcepacksCommand = new ResourcepacksPluginCommandExecutor(plugin);
}

@Override
Expand All @@ -43,6 +45,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if(sender instanceof Player) {
s = plugin.getPlayer(((Player) sender).getUniqueId());
}
return new ResourcepacksPluginCommandExecutor(plugin).execute(s, args);
resourcepacksCommand.execute(s, args);
return true;
}
}
6 changes: 2 additions & 4 deletions bukkit/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
debug: true
# Default language
default-language: en
# Whether or not resourcepack file hashes should be generated on startup:
autogeneratehashes: true
# Whether /usepack should apply packs temporary or permanent when run without any argument:
usepack-is-temporary: true
# When manually setting a permanent pack then it will be reset if the user disconnects in under x amount of seconds.
# 0 or anything below will disable this functionality
permanent-pack-remove-time: 30
messages:
usepack: You now use the pack %pack%!
packlisthead: "Packs available to you:"
nopacks: No packs found!
packs:
lobbypack:
# The url the client should download the resourcepack from.
Expand Down
10 changes: 10 additions & 0 deletions bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.themoep.utils</groupId>
<artifactId>lang-bungee</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.minecrell.mcstats</groupId>
<artifactId>statslite-bungee</artifactId>
Expand Down Expand Up @@ -102,6 +108,10 @@
<pattern>org.bstats</pattern>
<shadedPattern>de.themoep.resourcepacksplugin.bungee.libs.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>de.themoep.utils.lang</pattern>
<shadedPattern>de.themoep.resourcepacksplugin.bungee.libs.lang</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import de.themoep.resourcepacksplugin.core.UserManager;
import de.themoep.resourcepacksplugin.core.events.IResourcePackSelectEvent;
import de.themoep.resourcepacksplugin.core.events.IResourcePackSendEvent;
import de.themoep.utils.lang.bungee.LanguageManager;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class BungeeResourcepacks extends Plugin implements ResourcepacksPlugin {
private PackManager pm = new PackManager(this);

private UserManager um;

private LanguageManager lm;

private Level loglevel = Level.INFO;

Expand Down Expand Up @@ -165,6 +168,10 @@ public void onEnable() {
return;
}

setEnabled(loadConfig());

lm = new LanguageManager(this, getConfig().getString("default-language"));

getProxy().getPluginManager().registerCommand(BungeeResourcepacks.getInstance(), new BungeeResourcepacksCommand(this, getDescription().getName().toLowerCase().charAt(0) + "rp", getDescription().getName().toLowerCase() + ".command", new String[]{getDescription().getName().toLowerCase()}));
getProxy().getPluginManager().registerCommand(BungeeResourcepacks.getInstance(), new UsePackCommand(this, "usepack", getDescription().getName().toLowerCase() + ".command.usepack", new String[] {}));

Expand All @@ -174,8 +181,6 @@ public void onEnable() {
getLogger().log(Level.INFO, "Detected ViaVersion " + viaApi.getVersion());
}

setEnabled(loadConfig());

if (isEnabled() && getConfig().getBoolean("autogeneratehashes", true)) {
getPackManager().generateHashes(null);
}
Expand Down Expand Up @@ -237,6 +242,8 @@ public boolean loadConfig() {
getLogger().log(getLogLevel(), "Use backend auth: " + getConfig().getBoolean("useauth"));
}

lm.setDefaultLocale(getConfig().getString("default-language"));

getPackManager().init();
if (getConfig().isSet("packs", true) && getConfig().isSection("packs")) {
getLogger().log(Level.INFO, "Loading packs:");
Expand Down Expand Up @@ -552,22 +559,16 @@ public boolean hasBackend(UUID playerId) {
return backendPackedPlayers.containsKey(playerId);
}

public String getMessage(String key) {
String msg = getConfig().getString("messages." + key, getConfig().getDefaults().getString("messages." + key));
if(msg == null || msg.isEmpty()) {
msg = "&cUnknown message key: &6messages." + key;
}
return ChatColor.translateAlternateColorCodes('&', msg);
}

public String getMessage(String key, Map<String, String> replacements) {
String msg = getMessage(key);
if (replacements != null) {
for(Map.Entry<String, String> repl : replacements.entrySet()) {
msg = msg.replace("%" + repl.getKey() + "%", repl.getValue());
@Override
public String getMessage(ResourcepacksPlayer sender, String key, String... replacements) {
if (lm != null) {
ProxiedPlayer player = null;
if (sender != null) {
player = getProxy().getPlayer(sender.getUniqueId());
}
return lm.getConfig(player).get(key, replacements);
}
return msg;
return key;
}

public String getName() {
Expand Down Expand Up @@ -601,12 +602,13 @@ public ResourcepacksPlayer getPlayer(String playerName) {
}

@Override
public boolean sendMessage(ResourcepacksPlayer player, String message) {
return sendMessage(player, Level.INFO, message);
public boolean sendMessage(ResourcepacksPlayer player, String key, String... replacements) {
return sendMessage(player, Level.INFO, key, replacements);
}

@Override
public boolean sendMessage(ResourcepacksPlayer player, Level level, String message) {
public boolean sendMessage(ResourcepacksPlayer player, Level level, String key, String... replacements) {
String message = getMessage(player, key, replacements);
if(player != null) {
ProxiedPlayer proxyPlayer = getProxy().getPlayer(player.getUniqueId());
if(proxyPlayer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
*/
public class BungeeResourcepacksCommand extends Command {

ResourcepacksPlugin plugin;
private final ResourcepacksPlugin plugin;
private final ResourcepacksPluginCommandExecutor resourcepacksCommand;

public BungeeResourcepacksCommand(BungeeResourcepacks plugin, String name, String permission, String... aliases) {
super(name, permission, aliases);
this.plugin = plugin;
resourcepacksCommand = new ResourcepacksPluginCommandExecutor(plugin);
}

@Override
Expand All @@ -43,8 +45,6 @@ public void execute(CommandSender sender, String[] args) {
if(sender instanceof ProxiedPlayer) {
s = plugin.getPlayer(((ProxiedPlayer) sender).getUniqueId());
}
if(!new ResourcepacksPluginCommandExecutor(plugin).execute(s, args)) {
sender.sendMessage("Usage: /frp [reload [resend]|version]");
}
resourcepacksCommand.execute(s, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
*/
public class UsePackCommand extends Command {

ResourcepacksPlugin plugin;
private final ResourcepacksPlugin plugin;
private final UsePackCommandExecutor usepackCommand;

public UsePackCommand(BungeeResourcepacks plugin, String name, String permission, String... aliases) {
super(name, permission, aliases);
this.plugin = plugin;
usepackCommand = new UsePackCommandExecutor(plugin);
}

@Override
Expand All @@ -43,8 +45,6 @@ public void execute(CommandSender sender, String[] args) {
if(sender instanceof ProxiedPlayer) {
s = plugin.getPlayer(((ProxiedPlayer) sender).getUniqueId());
}
if(!new UsePackCommandExecutor(plugin).execute(s, args)) {
sender.sendMessage("Usage: /usepack <packname> [<playername>] [<temp>]");
}
usepackCommand.execute(s, args);
}
}
6 changes: 2 additions & 4 deletions bungee/src/main/resources/bungee-config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
debug: true
# Default language
default-language: en
# Whether or not resourcepack file hashes should be generated on startup:
autogeneratehashes: true
# Whether /usepack should apply packs temporary or permanent when run without any argument:
usepack-is-temporary: true
# When manually setting a permanent pack then it will be reset if the user disconnects in under x amount of seconds.
# 0 or anything below will disable this functionality
permanent-pack-remove-time: 30
messages:
usepack: You now use the pack %pack%!
packlisthead: "Packs available to you:"
nopacks: No packs found!
packs:
lobbypack:
# The url the client should download the resourcepack from.
Expand Down
Loading

0 comments on commit a7422d4

Please sign in to comment.