Merge pull request #20 from DmitryRendov/loc
Introduce messages.yml for further localization
This commit is contained in:
commit
bb92624332
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
|||||||
.classpath
|
.classpath
|
||||||
.project
|
.project
|
||||||
|
.idea
|
||||||
.settings/*
|
.settings/*
|
||||||
bin/*
|
bin/*
|
||||||
target/*
|
target/*
|
||||||
|
|||||||
4
pom.xml
4
pom.xml
@ -34,7 +34,7 @@
|
|||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.2.1</version>
|
<version>3.2.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>co.aikar.commands</pattern>
|
<pattern>co.aikar.commands</pattern>
|
||||||
@ -64,7 +64,7 @@
|
|||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>bungeecord-repo</id>
|
<id>bungeecord-repo</id>
|
||||||
<url>https://()oss.sonatype.org/content/repositories/snapshots</url>
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
|
|||||||
84
src/me/EtienneDx/RealEstate/Messages.java
Normal file
84
src/me/EtienneDx/RealEstate/Messages.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
|
import me.EtienneDx.AnnotationConfig.AnnotationConfig;
|
||||||
|
import me.EtienneDx.AnnotationConfig.ConfigField;
|
||||||
|
import me.EtienneDx.AnnotationConfig.ConfigFile;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ConfigFile(header = "Use a YAML editor like NotepadPlusPlus to edit this file. \nAfter editing, back up your changes before reloading the server in case you made a syntax error. \nUse dollar signs ($) for formatting codes, which are documented here: http://minecraft.gamepedia.com/Formatting_codes")
|
||||||
|
public class Messages extends AnnotationConfig
|
||||||
|
{
|
||||||
|
public PluginDescriptionFile pdf;
|
||||||
|
|
||||||
|
@ConfigField(name="RealEstate.NoTransactionFound")
|
||||||
|
public String msgNoTransactionFound = "$cNo transaction found at your location!";
|
||||||
|
|
||||||
|
@ConfigField(name="RealEstate.PageMustBePositive")
|
||||||
|
public String msgPageMustBePositive = "$cPage must be a positive option";
|
||||||
|
|
||||||
|
@ConfigField(name="RealEstate.PageNotExists")
|
||||||
|
public String msgPageNotExists = "$cThis page does not exist!";
|
||||||
|
|
||||||
|
@ConfigField(name="RealEstate.RenewRentNow", comment = "0: enabled/disabled; 1: type of claim")
|
||||||
|
public String msgRenewRentNow = "$bAutomatic renew is now $a{0} $bfor this {1}";
|
||||||
|
|
||||||
|
@ConfigField(name="RealEstate.RenewRentCurrently", comment = "0: enabled/disabled; 1: type of claim")
|
||||||
|
public String msgRenewRentCurrently = "$bAutomatic renew is currently $a{0} $bfor this {1}";
|
||||||
|
|
||||||
|
public Messages()
|
||||||
|
{
|
||||||
|
this.pdf = RealEstate.instance.getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadConfig()
|
||||||
|
{
|
||||||
|
this.loadConfig(RealEstate.messagesFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized public String getMessage(String msgTemplate, String... args) {
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
String param = args[i];
|
||||||
|
msgTemplate = msgTemplate.replace("{" + i + "}", param);
|
||||||
|
}
|
||||||
|
|
||||||
|
return msgTemplate.replace('$', (char) 0x00A7);
|
||||||
|
}
|
||||||
|
//sends a color-coded message to a player
|
||||||
|
public static void sendMessage(Player player, String msgTemplate, String... args) {
|
||||||
|
sendMessage(player, msgTemplate, 0, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sends a color-coded message to a player
|
||||||
|
public static void sendMessage(Player player, String msgTemplate, long delayInTicks, String... args) {
|
||||||
|
String message = RealEstate.instance.messages.getMessage(msgTemplate, args);
|
||||||
|
sendMessage(player, message, delayInTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sends a color-coded message to a player
|
||||||
|
public static void sendMessage(Player player, String message) {
|
||||||
|
if (message == null || message.length() == 0) return;
|
||||||
|
|
||||||
|
if (player == null) {
|
||||||
|
RealEstate.instance.log.info(message);
|
||||||
|
} else {
|
||||||
|
player.sendMessage(RealEstate.instance.config.chatPrefix + message.replace('$', (char) 0x00A7));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendMessage(Player player, String message, long delayInTicks) {
|
||||||
|
SendPlayerMessageTask task = new SendPlayerMessageTask(player, message);
|
||||||
|
|
||||||
|
if (delayInTicks > 0) {
|
||||||
|
RealEstate.instance.getServer().getScheduler().runTaskLater(RealEstate.instance, task, delayInTicks);
|
||||||
|
} else {
|
||||||
|
task.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,8 +1,6 @@
|
|||||||
package me.EtienneDx.RealEstate;
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -50,19 +48,24 @@ public class RECommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction found at your location!");
|
Messages.sendMessage(player, RealEstate.instance.messages.msgNoTransactionFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subcommand("list")
|
@Subcommand("list")
|
||||||
@Description("Displays the list of all real estate offers currently existing")
|
@Description("Displays the list of all real estate offers currently existing")
|
||||||
@CommandCompletion("all|sell|rent|lease")
|
@CommandCompletion("all|sell|rent|lease")
|
||||||
@Syntax("[all|sell|rent|lease] <page>")
|
@Syntax("[all|sell|rent|lease] <page>")
|
||||||
public static void list(CommandSender player, @Optional String type, @Default("1") int page)
|
public static void list(CommandSender sender, @Optional String type, @Default("1") int page)
|
||||||
{
|
{
|
||||||
|
Player player = null;
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
player = (Player) sender;
|
||||||
|
}
|
||||||
if(page <= 0)
|
if(page <= 0)
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Page must be a positive option!");
|
Messages.sendMessage(player, RealEstate.instance.messages.msgPageMustBePositive);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -91,12 +94,12 @@ public class RECommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Invalid option provided!");
|
sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Invalid option provided!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(count == 0)
|
if(count == 0)
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction have been found!");
|
sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction have been found!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -123,22 +126,22 @@ public class RECommand extends BaseCommand
|
|||||||
int max = Math.min(start + RealEstate.instance.config.cfgPageSize, count);
|
int max = Math.min(start + RealEstate.instance.config.cfgPageSize, count);
|
||||||
if(start <= max)
|
if(start <= max)
|
||||||
{
|
{
|
||||||
player.sendMessage(ChatColor.DARK_BLUE + "----= " + ChatColor.WHITE + "[ " + ChatColor.GOLD + typeMsg + " page " + ChatColor.DARK_GREEN + " " +
|
sender.sendMessage(ChatColor.DARK_BLUE + "----= " + ChatColor.WHITE + "[ " + ChatColor.GOLD + typeMsg + " page " + ChatColor.DARK_GREEN + " " +
|
||||||
page + ChatColor.GOLD + " / " + ChatColor.DARK_GREEN + (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize) +
|
page + ChatColor.GOLD + " / " + ChatColor.DARK_GREEN + (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize) +
|
||||||
ChatColor.WHITE + " ]" + ChatColor.DARK_BLUE + " =----");
|
ChatColor.WHITE + " ]" + ChatColor.DARK_BLUE + " =----");
|
||||||
for(int i = start; i < max; i++)
|
for(int i = start; i < max; i++)
|
||||||
{
|
{
|
||||||
RealEstate.instance.log.info("transaction " + i);
|
RealEstate.instance.log.info("transaction " + i);
|
||||||
transactions.get(i).msgInfo(player);
|
transactions.get(i).msgInfo(sender);
|
||||||
}
|
}
|
||||||
if(page < (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize))
|
if(page < (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize))
|
||||||
{
|
{
|
||||||
player.sendMessage(ChatColor.GOLD + "To see the next page, type " + ChatColor.GREEN + "/re list " + (type != null ? type : "all") + " " + (page + 1));
|
sender.sendMessage(ChatColor.GOLD + "To see the next page, type " + ChatColor.GREEN + "/re list " + (type != null ? type : "all") + " " + (page + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This page does not exist!");
|
Messages.sendMessage(player, RealEstate.instance.messages.msgPageNotExists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,8 +164,7 @@ public class RECommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
if(newStatus == null)
|
if(newStatus == null)
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is currently " +
|
Messages.sendMessage(player, RealEstate.instance.messages.msgRenewRentCurrently, cr.autoRenew ? "enabled" : "disabled", claimType);
|
||||||
ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!");
|
|
||||||
}
|
}
|
||||||
else if(!newStatus.equalsIgnoreCase("enable") && !newStatus.equalsIgnoreCase("disable"))
|
else if(!newStatus.equalsIgnoreCase("enable") && !newStatus.equalsIgnoreCase("disable"))
|
||||||
{
|
{
|
||||||
@ -172,8 +174,7 @@ public class RECommand extends BaseCommand
|
|||||||
{
|
{
|
||||||
cr.autoRenew = newStatus.equalsIgnoreCase("enable");
|
cr.autoRenew = newStatus.equalsIgnoreCase("enable");
|
||||||
RealEstate.transactionsStore.saveData();
|
RealEstate.transactionsStore.saveData();
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is now " +
|
Messages.sendMessage(player, RealEstate.instance.messages.msgRenewRentNow, cr.autoRenew ? "enabled" : "disabled", claimType);
|
||||||
ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -30,8 +30,10 @@ public class RealEstate extends JavaPlugin
|
|||||||
{
|
{
|
||||||
public Logger log;
|
public Logger log;
|
||||||
public Config config;
|
public Config config;
|
||||||
|
public Messages messages;
|
||||||
BukkitCommandManager manager;
|
BukkitCommandManager manager;
|
||||||
public final static String pluginDirPath = "plugins" + File.separator + "RealEstate" + File.separator;
|
public final static String pluginDirPath = "plugins" + File.separator + "RealEstate" + File.separator;
|
||||||
|
final static String messagesFilePath = RealEstate.pluginDirPath + "messages.yml";
|
||||||
public static boolean vaultPresent = false;
|
public static boolean vaultPresent = false;
|
||||||
public static Economy econ = null;
|
public static Economy econ = null;
|
||||||
public static Permission perms = null;
|
public static Permission perms = null;
|
||||||
@ -81,6 +83,11 @@ public class RealEstate extends JavaPlugin
|
|||||||
this.config.loadConfig();// loads config or default
|
this.config.loadConfig();// loads config or default
|
||||||
this.config.saveConfig();// save eventual default
|
this.config.saveConfig();// save eventual default
|
||||||
|
|
||||||
|
this.messages = new Messages();
|
||||||
|
this.messages.loadConfig(this.messagesFilePath);// loads customizable messages or defaults
|
||||||
|
this.messages.saveConfig(this.messagesFilePath);// save eventual default
|
||||||
|
this.log.info("Customizable messages loaded.");
|
||||||
|
|
||||||
ConfigurationSerialization.registerClass(ClaimSell.class);
|
ConfigurationSerialization.registerClass(ClaimSell.class);
|
||||||
ConfigurationSerialization.registerClass(ClaimRent.class);
|
ConfigurationSerialization.registerClass(ClaimRent.class);
|
||||||
ConfigurationSerialization.registerClass(ClaimLease.class);
|
ConfigurationSerialization.registerClass(ClaimLease.class);
|
||||||
|
|||||||
27
src/me/EtienneDx/RealEstate/SendPlayerMessageTask.java
Normal file
27
src/me/EtienneDx/RealEstate/SendPlayerMessageTask.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
class SendPlayerMessageTask implements Runnable
|
||||||
|
{
|
||||||
|
private Player player;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
|
||||||
|
public SendPlayerMessageTask(Player player, String message)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if(player == null)
|
||||||
|
{
|
||||||
|
RealEstate.instance.log.info(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Messages.sendMessage(this.player, this.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user