Skip to content
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 @@ -59,6 +59,12 @@
<version>6.5.1.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 @@ -130,6 +136,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
36 changes: 21 additions & 15 deletions src/main/java/de/minebench/syncinv/SyncInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,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 org.apache.maven.artifact.versioning.ComparableVersion;
import org.bukkit.ChatColor;
import net.kyori.adventure.text.Component;
import org.bukkit.GameRule;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
Expand Down Expand Up @@ -288,16 +289,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 @@ -349,8 +349,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 @@ -451,7 +454,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
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 @@ -461,15 +464,18 @@ 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 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 @@ -1197,7 +1203,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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import de.minebench.syncinv.SyncInv;
import de.minebench.syncinv.SyncType;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -60,7 +59,7 @@ public void onMapScale(PrepareItemCraftEvent event) {
plugin.logDebug(event.getView().getPlayer().getName() + " is not on the world that map " + map.getId() + " is from! (" + mapId + ")");
event.getInventory().setResult(null);
for (HumanEntity viewer : event.getViewers()) {
viewer.sendMessage(ChatColor.RED + "Please switch to the world where this map was created to scale it!");
viewer.sendMessage(plugin.getLang("map-scale-wrong-world"));
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import de.minebench.syncinv.SyncInv;
import io.papermc.paper.connection.PlayerLoginConnection;
import io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -42,12 +40,12 @@ public void onPlayerLogin(PlayerConnectionValidateLoginEvent e) {
if (e.isAllowed() && e.getConnection() instanceof PlayerLoginConnection connection && connection.getUnsafeProfile() != null) {
// Sync login listener for sanity checking as we don't want to allow the player to exist twice
Entity entity = plugin.getServer().getEntity(connection.getUnsafeProfile().getUniqueId());
if (entity instanceof Player) {
e.kickMessage(Component.text("A player with your UUID already exists!").color(NamedTextColor.RED));
if (entity instanceof Player player) {
e.kickMessage(plugin.getLang("login_denied_duplicated_uuid"));
plugin.logDebug("A player object with the same UUID " + connection.getUnsafeProfile().getUniqueId() + " already exists on the server.");
// Kick player. This should do nothing if it's not a real one (e.g. one loaded by OpenInv)
// Removal of such players is up to OpenInv itself
((Player) entity).kickPlayer("Login from different location.");
player.kick(plugin.getLang("kick_duplicated_uuid"));
} else if (entity != null) {
// Well... this is weird. An entity with the same UUID as the player's exists?!? Removing it just to be sure...
plugin.getLogger().info("A " + entity + " with the same UUID " + connection.getUnsafeProfile().getUniqueId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import de.minebench.syncinv.PlayerData;
import de.minebench.syncinv.SyncInv;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down Expand Up @@ -41,12 +40,12 @@ public void onPlayerPreLogin(AsyncPlayerPreLoginEvent e) {
if (e.getLoginResult() == AsyncPlayerPreLoginEvent.Result.ALLOWED) {
if (plugin.getMessenger() == null) {
e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
e.setKickMessage(ChatColor.RED + plugin.getName() + " is not enabled! Please contact an administrator!");
e.kickMessage(plugin.getLang("login_denied_plugin_invalid_state", "plugin", plugin.getName()));
return;
}
if (plugin.getMessenger().queryData(e.getUniqueId()) == null && (!plugin.getMessenger().isAllowedToBeAlone() || !plugin.getMessenger().isAlone())) {
e.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
e.setKickMessage(ChatColor.RED + "Unable to query player data!");
e.kickMessage(plugin.getLang("login_denied_missing_data"));
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.minebench.syncinv.listeners;

import de.minebench.syncinv.SyncInv;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -40,13 +39,13 @@ public void onPlayerLogin(PlayerLoginEvent e) {
if (e.getResult() == PlayerLoginEvent.Result.ALLOWED) {
// Sync login listener for sanity checking as we don't want to allow the player to exist twice
Entity entity = plugin.getServer().getEntity(e.getPlayer().getUniqueId());
if (entity instanceof Player) {
if (entity instanceof Player player) {
e.setResult(PlayerLoginEvent.Result.KICK_OTHER);
e.setKickMessage(ChatColor.RED + "A player with your UUID already exists!");
e.kickMessage(plugin.getLang("login_denied_duplicated_uuid"));
plugin.logDebug("A player object with the same UUID " + e.getPlayer().getUniqueId() + " already exists on the server.");
// Kick player. This should do nothing if it's not a real one (e.g. one loaded by OpenInv)
// Removal of such players is up to OpenInv itself
((Player) entity).kickPlayer("Login from different location.");
player.kick(plugin.getLang("kick_duplicated_uuid"));
} else if (entity != null) {
// Well... this is weird. An entity with the same UUID as the player's exists?!? Removing it just to be sure...
plugin.getLogger().info("A " + entity + " with the same UUID " + e.getPlayer().getUniqueId()
Expand Down
11 changes: 10 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ 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..."
map-scale-wrong-world : "&cPlease switch to the world where this map was created to scale it!"
login_denied_duplicated_uuid : "&cA player with your UUID already exists!"
kick_duplicated_uuid : "Login from different location."
login_denied_missing_data : "&cUnable to query player data!"
login_denied_plugin_invalid_state : "&c %plugin% is not enabled! Please contact an administrator!"