Skip to content

Commit

Permalink
update use textComponents, since we rely on paper anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
FireInstall committed May 8, 2024
1 parent 752c4e4 commit e3d7337
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
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
33 changes: 16 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,7 +286,8 @@ public void onDisable() {
}

public void loadConfig() {
saveDefaultConfig();
getConfig().options().copyDefaults(true); // save newly added config options to disk
saveConfig();
reloadConfig();

debug = getConfig().getBoolean("debug");
Expand Down Expand Up @@ -388,11 +389,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 +402,14 @@ 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]);
}
return msg;
public Component getLang(String key, String... replacements) {
String rawMsg = getConfig().getString("lang." + key, getName() + ": &cMissing language key &6" + key);
return MineDown.parse(rawMsg, replacements);
}

/**
Expand Down Expand Up @@ -1132,7 +1131,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..."

0 comments on commit e3d7337

Please sign in to comment.