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 5, 2024
1 parent 752c4e4 commit 9a596a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 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
31 changes: 15 additions & 16 deletions src/main/java/de/minebench/syncinv/SyncInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
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 net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.GameRule;
import org.bukkit.Location;
import org.bukkit.Material;
Expand Down Expand Up @@ -225,16 +227,16 @@ 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(Component.text("Current server does not have newest player data! ", NamedTextColor.RED).
append(Component.text("Connecting to server " + query.getYoungestServer() + " which has the newest data...", NamedTextColor.GRAY)));
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(Component.text("Could not query information from other servers! Take a look at the log for more details.", NamedTextColor.RED));
}
} else {
sender.sendMessage(ChatColor.RED + "Player not found!");
sender.sendMessage(Component.text("Player not found!", NamedTextColor.RED));
}
});
return true;
Expand Down Expand Up @@ -388,11 +390,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(Component.text("Config reloaded!", NamedTextColor.YELLOW));
return true;
}
}
Expand All @@ -401,16 +403,13 @@ 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 (suffix and prefix))
* @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() + ": <red>Missing language key</red><gold> " + key+"</gold>");
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

0 comments on commit 9a596a5

Please sign in to comment.