Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update use textComponents, since we rely on paper anyway #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<version>6.2.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>de.themoep</groupId>
<artifactId>minedown-adventure</artifactId>
<version>1.7.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<profiles>
Expand Down Expand Up @@ -134,6 +140,10 @@
<pattern>org.reactivestreams</pattern>
<shadedPattern>de.minebench.syncinv.lib.reactivestreams</shadedPattern>
</relocation>
<relocation>
<pattern>de.themoep.minedown</pattern>
<shadedPattern>de.minebench.syncinv.lib.minedown</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/de/minebench/syncinv/SyncInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import de.minebench.syncinv.messenger.PlayerDataQuery;
import de.minebench.syncinv.messenger.RedisMessenger;
import de.minebench.syncinv.messenger.ServerMessenger;
import de.themoep.minedown.adventure.MineDown;
import lombok.Getter;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -225,16 +226,15 @@ public void onEnable() {
if (query.getYoungestServer() == null) {
openInvCommand.onCommand(sender, command, label, args);
} else {
sender.sendMessage(ChatColor.RED + "Current server does not have newest player data! "
+ ChatColor.GRAY + "Connecting to server " + query.getYoungestServer() + " which has the newest data...");
sender.sendMessage(getLang("stale-player-data", "server", query.getYoungestServer()));
connectToServer(((Player) sender).getUniqueId(), query.getYoungestServer());
}
});
if (q == null) {
sender.sendMessage(ChatColor.RED + "Could not query information from other servers! Take a look at the log for more details.");
sender.sendMessage(getLang("query-error"));
}
} else {
sender.sendMessage(ChatColor.RED + "Player not found!");
sender.sendMessage(getLang("player-not-found"));
}
});
return true;
Expand Down Expand Up @@ -286,8 +286,11 @@ public void onDisable() {
}

public void loadConfig() {
saveDefaultConfig();
reloadConfig();
reloadConfig(); // load working config

// save newly added config options to disk
getConfig().options().copyDefaults(true);
saveConfig();

debug = getConfig().getBoolean("debug");

Expand Down Expand Up @@ -388,11 +391,11 @@ && getConfig().contains("sync-" + syncType.getKey(), true)) {
}
}

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
public boolean onCommand(CommandSender sender, Command cmd, String label, String [] args) {
if (args.length > 0) {
if ("reload".equalsIgnoreCase(args[0]) && sender.hasPermission("syncing.command.reload")) {
loadConfig();
sender.sendMessage(ChatColor.YELLOW + "Config reloaded!");
sender.sendMessage(getLang("config-reloaded"));
return true;
}
}
Expand All @@ -401,16 +404,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

/**
* Get a language message from the config and replace variables in it
* @param key The key of the message (lang.<key>)
* @param replacements An array of variables to be replaced with certain strings in the format [var,repl,var,repl,...]
* @param key The key of the message (lang.<key>)
* @param replacements An array of String to replace placeholders (uses the % character as placeholder indicators)
* in format of [placeholder, repl, placeholder,repl,...]
* @return The message string with colorcodes and variables replaced
*/
public String getLang(String key, String... replacements) {
String msg = ChatColor.translateAlternateColorCodes('&', getConfig().getString("lang." + key, getName() + ": &cMissing language key &6" + key));
for (int i = 0; i + 1 < replacements.length; i += 2) {
msg = msg.replace("%" + replacements[i] + "%", replacements[i+1]);
public Component getLang(String key, String... replacements) {
String rawMsg = getConfig().getString("lang." + key); // use default defined by config (values from the config in jar)

if (rawMsg == null) { // key is missing
return MineDown.parse(getName() + ": &cMissing language key &6" + key);
} else {
return MineDown.parse(rawMsg, replacements);
}
return msg;
}

/**
Expand Down Expand Up @@ -1132,7 +1138,7 @@ public void kick(UUID playerId, String key) {
runSync(() -> {
Player player = getServer().getPlayer(playerId);
if (player != null) {
player.kickPlayer(getLang(key));
player.kick(getLang(key));
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ lang:
cant-drop-items: "&cYou can only drop items once your player data is loaded!"
cant-move: "&cYou can only move once your player data is loaded!"
wait-for-loading: "&cPlease wait until your player data is loaded!"
cant-load-data: "&cSorry but the server wasn't able to load your latest player data.\nPlease contact an administrator if this happens often!"
cant-load-data: "&cSorry but the server wasn't able to load your latest player data.\nPlease contact an administrator if this happens often!"
config-reloaded: "&eConfig reloaded!"
player-not-found: "&cPlayer not found!"
query-error : "Could not query information from other servers! Take a look at the log for more details."
stale-player-data : "&cCurrent server does not have newest player data! &7Connecting to server %server% which has the newest data..."