Skip to content

Commit f6151a3

Browse files
committed
Code clean
1 parent 7696e5c commit f6151a3

10 files changed

Lines changed: 117 additions & 138 deletions

File tree

src/main/java/de/minebench/syncinv/PlayerData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ public class PlayerData implements Serializable {
7575
private final float fallDistance;
7676
private final Vector velocity;
7777
private final int heldItemSlot;
78-
private byte[] persistentData = null;
7978
private final Map<String, Map<String, Long>> advancementProgress = new HashMap<>();
8079
private final Table<Statistic, String, Integer> statistics = HashBasedTable.create();
8180
private final long lastSeen;
81+
private byte[] persistentData = null;
8282

8383
PlayerData(Player player, long lastSeen) {
8484
this.dataVersion = player.getServer().getUnsafe().getDataVersion();

src/main/java/de/minebench/syncinv/SyncInv.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public final class SyncInv extends JavaPlugin {
111111
* Sync data with all servers in a group when a player logs out
112112
*/
113113
private boolean syncWithGroupOnLogout;
114-
114+
115115
/**
116116
* Store player data even if the player never joined the server
117117
*/
@@ -160,7 +160,7 @@ public final class SyncInv extends JavaPlugin {
160160
*/
161161
@Getter
162162
private int newestMap = 0;
163-
163+
164164
// Unknown player storing
165165
private Method methodGetOfflinePlayer = null;
166166
private Method methodGetHandle = null;
@@ -184,7 +184,7 @@ public final class SyncInv extends JavaPlugin {
184184
public void onEnable() {
185185
// Plugin startup logic
186186
loadConfig();
187-
187+
188188
playerDataFolder = new File(getServer().getWorlds().get(0).getWorldFolder(), "playerdata");
189189
try {
190190
methodGetOfflinePlayer = getServer().getClass().getMethod("getOfflinePlayer", GameProfile.class);
@@ -303,7 +303,7 @@ public void loadConfig() {
303303
syncWithGroupOnLogout = getConfig().getBoolean("sync-with-group-on-logout");
304304

305305
storeUnknownPlayers = getConfig().getBoolean("store-unknown-players");
306-
306+
307307
queryTimeout = getConfig().getInt("query-timeout");
308308
applyTimedOutQueries = getConfig().getBoolean("apply-timed-out-queries");
309309

@@ -424,14 +424,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
424424

425425
/**
426426
* Get a language message from the config and replace variables in it
427-
* @param key The key of the message (lang.<key>)
427+
* @param key The key of the message (lang.<key>)
428428
* @param replacements An array of variables to be replaced with certain strings in the format [var,repl,var,repl,...]
429429
* @return The message string with colorcodes and variables replaced
430430
*/
431431
public String getLang(String key, String... replacements) {
432432
String msg = ChatColor.translateAlternateColorCodes('&', getConfig().getString("lang." + key, getName() + ": &cMissing language key &6" + key));
433433
for (int i = 0; i + 1 < replacements.length; i += 2) {
434-
msg = msg.replace("%" + replacements[i] + "%", replacements[i+1]);
434+
msg = msg.replace("%" + replacements[i] + "%", replacements[i + 1]);
435435
}
436436
return msg;
437437
}
@@ -535,7 +535,7 @@ public boolean applyTimedOutQueries() {
535535
/**
536536
* Connect a player to a bungee server
537537
* @param playerId The UUID of the player
538-
* @param server The name of the server
538+
* @param server The name of the server
539539
*/
540540
public void connectToServer(UUID playerId, String server) {
541541
Player player = getServer().getPlayer(playerId);
@@ -549,7 +549,7 @@ public void connectToServer(UUID playerId, String server) {
549549

550550
/**
551551
* Apply a PlayerData object to its player
552-
* @param data The data to apply
552+
* @param data The data to apply
553553
*/
554554
public void applyData(PlayerData data, Runnable finished) {
555555
if (data == null)
@@ -934,20 +934,13 @@ private void forceRender(MapView map) {
934934
map.addRenderer(new EmptyRenderer());
935935
}
936936

937-
private static class EmptyRenderer extends MapRenderer {
938-
@Override
939-
public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Player player) {
940-
941-
}
942-
}
943-
944937
private void cacheData(PlayerData data, Runnable finished) {
945938
playerDataCache.put(data.getPlayerId(), new AbstractMap.SimpleEntry<>(data, finished));
946939
}
947940

948941
/**
949942
* Get data that was cached which should be applied on a player's login
950-
* @param player The player to get the data for
943+
* @param player The player to get the data for
951944
* @return A cache entry containing the PlayerData and the notification Runnable when applied successfully
952945
*/
953946
public Map.Entry<PlayerData, Runnable> getCachedData(Player player) {
@@ -1104,7 +1097,7 @@ public PlayerData getData(Player player) {
11041097

11051098
/**
11061099
* The sound to play when a player gets unlocked, should match the vanilla levelup
1107-
* @param playerId The uuid of the Player to play the sound to
1100+
* @param playerId The uuid of the Player to play the sound to
11081101
*/
11091102
public void playLoadSound(UUID playerId) {
11101103
Player player = getServer().getPlayer(playerId);
@@ -1115,7 +1108,7 @@ public void playLoadSound(UUID playerId) {
11151108

11161109
/**
11171110
* The sound to play when a player gets unlocked, should match the vanilla levelup
1118-
* @param player The Player to play the sound to
1111+
* @param player The Player to play the sound to
11191112
*/
11201113
public void playLoadSound(Player player) {
11211114
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.7f, 1);
@@ -1142,7 +1135,7 @@ public void checkMap(int id) {
11421135
* Make sure that a task runs on the primary thread
11431136
*/
11441137
public void runSync(Runnable run) {
1145-
if(getServer().isPrimaryThread() || disabling) {
1138+
if (getServer().isPrimaryThread() || disabling) {
11461139
run.run();
11471140
} else {
11481141
getServer().getScheduler().runTask(this, run);
@@ -1153,7 +1146,7 @@ public void runSync(Runnable run) {
11531146
* Make sure that a task does not run on the primary thread
11541147
*/
11551148
public void runAsync(Runnable run) {
1156-
if(!getServer().isPrimaryThread() && !disabling) {
1149+
if (!getServer().isPrimaryThread() && !disabling) {
11571150
getServer().getScheduler().runTaskAsynchronously(this, run);
11581151
} else {
11591152
run.run();
@@ -1211,6 +1204,11 @@ public UUID getWorldId(MapView map) {
12111204
return null;
12121205
}
12131206

1207+
private static class EmptyRenderer extends MapRenderer {
1208+
@Override
1209+
public void render(@NotNull MapView map, @NotNull MapCanvas canvas, @NotNull Player player) {}
1210+
}
1211+
12141212
private enum FilterMode {
12151213
DENY,
12161214
ALLOW

src/main/java/de/minebench/syncinv/listeners/PlayerFreezeListener.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ public PlayerFreezeListener(SyncInv plugin) {
4646

4747
@EventHandler(ignoreCancelled = true)
4848
public void onDropItem(PlayerDropItemEvent e) {
49-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
49+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
5050
e.setCancelled(true);
5151
e.getPlayer().sendMessage(plugin.getLang("cant-drop-items"));
5252
}
5353
}
5454

5555
@EventHandler(ignoreCancelled = true)
5656
public void onPlayerMove(PlayerMoveEvent e) {
57-
if(!sameBlock(e.getFrom(), e.getTo()) && plugin.isLocked(e.getPlayer().getUniqueId())) {
57+
if (!sameBlock(e.getFrom(), e.getTo()) && plugin.isLocked(e.getPlayer().getUniqueId())) {
5858
e.setCancelled(true);
5959
if (e.getFrom().getBlockY() == e.getTo().getBlockY()) {
6060
e.getPlayer().sendMessage(plugin.getLang("cant-move"));
@@ -70,86 +70,86 @@ private boolean sameBlock(Location from, Location to) {
7070

7171
@EventHandler(ignoreCancelled = true)
7272
public void onPlayerPickupItem(PlayerPickupItemEvent e) {
73-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
73+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
7474
e.setCancelled(true);
7575
e.getPlayer().sendMessage(plugin.getLang("cant-pickup-items"));
7676
}
7777
}
7878

7979
@EventHandler(ignoreCancelled = true)
8080
public void onPlayerPickupExp(PlayerExpChangeEvent e) {
81-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
81+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
8282
e.setAmount(0);
8383
e.getPlayer().sendMessage(plugin.getLang("cant-pickup-exp"));
8484
}
8585
}
8686

8787
@EventHandler(ignoreCancelled = true)
8888
public void onPlayerDamage(EntityDamageEvent e) {
89-
if(e.getEntity() instanceof Player && plugin.isLocked(e.getEntity().getUniqueId())) {
89+
if (e.getEntity() instanceof Player && plugin.isLocked(e.getEntity().getUniqueId())) {
9090
e.setCancelled(true);
9191
}
9292
}
9393

9494
@EventHandler(ignoreCancelled = true)
9595
public void onInventoryInteraction(InventoryClickEvent e) {
96-
if(plugin.isLocked(e.getWhoClicked().getUniqueId())) {
96+
if (plugin.isLocked(e.getWhoClicked().getUniqueId())) {
9797
e.setCancelled(true);
9898
e.getWhoClicked().sendMessage(plugin.getLang("wait-for-loading"));
9999
}
100100
}
101101

102102
@EventHandler(ignoreCancelled = true)
103103
public void onInventoryInteraction(InventoryDragEvent e) {
104-
if(plugin.isLocked(e.getWhoClicked().getUniqueId())) {
104+
if (plugin.isLocked(e.getWhoClicked().getUniqueId())) {
105105
e.setCancelled(true);
106106
e.getWhoClicked().sendMessage(plugin.getLang("wait-for-loading"));
107107
}
108108
}
109109

110110
@EventHandler(ignoreCancelled = true)
111111
public void onInventoryInteraction(InventoryOpenEvent e) {
112-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
112+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
113113
e.setCancelled(true);
114114
e.getPlayer().sendMessage(plugin.getLang("wait-for-loading"));
115115
}
116116
}
117117

118118
@EventHandler(ignoreCancelled = true)
119119
public void onInteraction(PlayerInteractEvent e) {
120-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
120+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
121121
e.setCancelled(true);
122122
e.getPlayer().sendMessage(plugin.getLang("wait-for-loading"));
123123
}
124124
}
125125

126126
@EventHandler(ignoreCancelled = true)
127127
public void onDamageEntity(EntityDamageByEntityEvent e) {
128-
if(e.getDamager() instanceof Player && plugin.isLocked(e.getDamager().getUniqueId())) {
128+
if (e.getDamager() instanceof Player && plugin.isLocked(e.getDamager().getUniqueId())) {
129129
e.setCancelled(true);
130130
e.getDamager().sendMessage(plugin.getLang("wait-for-loading"));
131131
}
132132
}
133133

134134
@EventHandler(ignoreCancelled = true)
135135
public void onBlockDamage(BlockDamageEvent e) {
136-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
136+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
137137
e.setCancelled(true);
138138
e.getPlayer().sendMessage(plugin.getLang("wait-for-loading"));
139139
}
140140
}
141141

142142
@EventHandler(ignoreCancelled = true)
143143
public void onChat(AsyncPlayerChatEvent e) {
144-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
144+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
145145
e.setCancelled(true);
146146
e.getPlayer().sendMessage(plugin.getLang("wait-for-loading"));
147147
}
148148
}
149149

150150
@EventHandler(ignoreCancelled = true)
151151
public void onChat(PlayerCommandPreprocessEvent e) {
152-
if(plugin.isLocked(e.getPlayer().getUniqueId())) {
152+
if (plugin.isLocked(e.getPlayer().getUniqueId())) {
153153
e.setCancelled(true);
154154
e.getPlayer().sendMessage(plugin.getLang("wait-for-loading"));
155155
}

src/main/java/de/minebench/syncinv/listeners/PlayerQuitListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.bukkit.event.player.PlayerQuitEvent;
1111

1212
import java.util.Set;
13-
import java.util.UUID;
1413

1514
/*
1615
* SyncInv
@@ -44,7 +43,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
4443
}
4544
PlayerDataQuery query = plugin.getMessenger().removeQuery(event.getPlayer().getUniqueId());
4645
if (query != null) {
47-
// The player is gone although he had a query...
46+
// The player is gone, although he had a query...
4847
// We have to make sure now that the time of the data file matches the old one
4948
// and not send our data to all the other servers as it might be outdated
5049
plugin.runLater(() -> {
@@ -68,5 +67,4 @@ public void onPlayerQuit(PlayerQuitEvent event) {
6867
// Update last seen
6968
plugin.runLater(() -> plugin.setLastSeen(event.getPlayer().getUniqueId(), System.currentTimeMillis()), 1);
7069
}
71-
7270
}

src/main/java/de/minebench/syncinv/messenger/Message.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class Message {
4343

4444
/**
4545
* A Message of a certain type. Optionally with some data
46-
* @param type The type of the message
47-
* @param objects The data, in the order that it should be send
46+
* @param type The type of the message
47+
* @param objects The data, in the order that it should be send
4848
* @throws IllegalArgumentException when the amount of Objects given didn't match the MessageType requirements
4949
*/
5050
public Message(String sender, MessageType type, Object... objects) {
@@ -68,10 +68,10 @@ public Object read() {
6868

6969
/**
7070
* Generate a byte array out of the data of this message
71-
* @return The generated byte array (starts with the sender
72-
* then the type ordinal, then the amount
73-
* of data being send and each data object);
74-
* an empty one if an error occurred
71+
* @return The generated byte array (starts with the sender
72+
* then the type ordinal, then the amount
73+
* of data being send and each data object);
74+
* an empty one if an error occurred
7575
*/
7676
public byte[] toByteArray() {
7777
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -117,5 +117,4 @@ public static Message fromByteArray(byte[] bytes) throws IOException, IllegalArg
117117
return new Message(sender, type, data);
118118
}
119119
}
120-
121120
}

src/main/java/de/minebench/syncinv/messenger/PlayerDataQuery.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.minebench.syncinv.messenger;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
35
import org.bukkit.scheduler.BukkitTask;
46

57
import java.util.Map;
@@ -27,35 +29,27 @@
2729

2830
public class PlayerDataQuery {
2931
private final long timestamp = System.currentTimeMillis();
32+
@Getter
3033
private final UUID playerId;
34+
@Getter
3135
private final long localLastSeen;
3236
private final Consumer<PlayerDataQuery> onComplete;
37+
@Setter
3338
private BukkitTask timeoutTask;
3439
private boolean completed = false;
3540

36-
private Map<String, Long> servers = new ConcurrentHashMap<>();
41+
@Getter
42+
private final Map<String, Long> servers = new ConcurrentHashMap<>();
3743

3844
public PlayerDataQuery(UUID playerId, long localLastSeen, Consumer<PlayerDataQuery> onComplete) {
3945
this.playerId = playerId;
4046
this.localLastSeen = localLastSeen;
4147
this.onComplete = onComplete;
4248
}
4349

44-
public UUID getPlayerId() {
45-
return playerId;
46-
}
47-
48-
public long getLocalLastSeen() {
49-
return localLastSeen;
50-
}
51-
52-
public Map<String, Long> getServers() {
53-
return servers;
54-
}
55-
5650
/**
5751
* Add a new response to this query
58-
* @param server The name of the server
52+
* @param server The name of the server
5953
* @param lastSeen When the user was last seen on that server
6054
*/
6155
public void addResponse(String server, long lastSeen) {
@@ -86,10 +80,6 @@ public long getTimestamp() {
8680
return timestamp;
8781
}
8882

89-
public void setTimeoutTask(BukkitTask timeoutTask) {
90-
this.timeoutTask = timeoutTask;
91-
}
92-
9383
public void stopTimeout() {
9484
if (timeoutTask != null) {
9585
timeoutTask.cancel();

0 commit comments

Comments
 (0)