Skip to content

Commit ab97121

Browse files
committed
Kicking Outdated Clients; Refactor to tf.tuff, 1.1.1
1 parent 7c4be29 commit ab97121

File tree

11 files changed

+335
-317
lines changed

11 files changed

+335
-317
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+

.idea/jarRepositories.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
1-
package net.potato.tuff;
2-
3-
import com.comphenix.protocol.PacketType;
4-
import com.comphenix.protocol.ProtocolLibrary;
5-
import com.comphenix.protocol.ProtocolManager;
6-
import com.comphenix.protocol.events.PacketAdapter;
7-
import com.comphenix.protocol.events.PacketEvent;
8-
import org.bukkit.Chunk;
9-
import org.bukkit.World;
10-
import org.bukkit.entity.Player;
11-
import net.potato.tuff.TuffX;
12-
13-
public class ChunkPacketListener {
14-
15-
private static boolean initialized = false;
16-
17-
public static void initialize(TuffX plugin) {
18-
if (initialized) {
19-
return;
20-
}
21-
22-
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
23-
if (protocolManager == null) {
24-
plugin.getLogger().severe("Could not initialize ChunkPacketListener because ProtocolManager is null!");
25-
return;
26-
}
27-
28-
protocolManager.addPacketListener(
29-
new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
30-
@Override
31-
public void onPacketSending(PacketEvent event) {
32-
Player player = event.getPlayer();
33-
34-
if (!((TuffX) this.plugin).isPlayerReady(player)) {
35-
return;
36-
}
37-
38-
World world = player.getWorld();
39-
int chunkX = event.getPacket().getIntegers().read(0);
40-
int chunkZ = event.getPacket().getIntegers().read(1);
41-
42-
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
43-
if (player.isOnline() && world.isChunkLoaded(chunkX, chunkZ)) {
44-
Chunk chunk = world.getChunkAt(chunkX, chunkZ);
45-
((TuffX) this.plugin).processAndSendChunk(player, chunk);
46-
}
47-
});
48-
}
49-
}
50-
);
51-
52-
plugin.getLogger().info("ProtocolLib listener for chunks registered successfully.");
53-
initialized = true;
54-
}
1+
package tf.tuff;
2+
3+
import com.comphenix.protocol.PacketType;
4+
import com.comphenix.protocol.ProtocolLibrary;
5+
import com.comphenix.protocol.ProtocolManager;
6+
import com.comphenix.protocol.events.PacketAdapter;
7+
import com.comphenix.protocol.events.PacketEvent;
8+
import org.bukkit.Chunk;
9+
import org.bukkit.World;
10+
import org.bukkit.entity.Player;
11+
12+
public class ChunkPacketListener {
13+
14+
private static boolean initialized = false;
15+
16+
public static void initialize(TuffX plugin) {
17+
if (initialized) {
18+
return;
19+
}
20+
21+
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
22+
if (protocolManager == null) {
23+
plugin.getLogger().severe("Could not initialize ChunkPacketListener because ProtocolManager is null!");
24+
return;
25+
}
26+
27+
protocolManager.addPacketListener(
28+
new PacketAdapter(plugin, PacketType.Play.Server.MAP_CHUNK) {
29+
@Override
30+
public void onPacketSending(PacketEvent event) {
31+
Player player = event.getPlayer();
32+
33+
if (!((TuffX) this.plugin).isPlayerReady(player)) {
34+
return;
35+
}
36+
37+
World world = player.getWorld();
38+
int chunkX = event.getPacket().getIntegers().read(0);
39+
int chunkZ = event.getPacket().getIntegers().read(1);
40+
41+
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
42+
if (player.isOnline() && world.isChunkLoaded(chunkX, chunkZ)) {
43+
Chunk chunk = world.getChunkAt(chunkX, chunkZ);
44+
((TuffX) this.plugin).processAndSendChunk(player, chunk);
45+
}
46+
});
47+
}
48+
}
49+
);
50+
51+
plugin.getLogger().info("ProtocolLib listener for chunks registered successfully.");
52+
initialized = true;
53+
}
5554
}

src/main/java/net/potato/tuff/ChunkSectionKey.java renamed to src/main/java/tf/tuff/ChunkSectionKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.potato.tuff;
1+
package tf.tuff;
22

33
import java.util.Objects;
44
import java.util.UUID;

src/main/java/net/potato/tuff/LegacyBlockIdManager.java renamed to src/main/java/tf/tuff/LegacyBlockIdManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.potato.tuff;
1+
package tf.tuff;
22

33
import org.bukkit.Material;
44
import org.bukkit.plugin.Plugin;

src/main/java/net/potato/tuff/LegacyBlockIds.java renamed to src/main/java/tf/tuff/LegacyBlockIds.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.potato.tuff;
1+
package tf.tuff;
22

33
import java.util.Map;
44
import java.util.HashMap;

src/main/java/net/potato/tuff/TuffX.java renamed to src/main/java/tf/tuff/TuffX.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package net.potato.tuff;
1+
package tf.tuff;
22

33
import org.bukkit.Chunk;
44
import org.bukkit.ChunkSnapshot;
@@ -191,7 +191,9 @@ public void run() {
191191
}.runTask(this);
192192
break;
193193
case "ready":
194-
p.kickPlayer("§cYour client is not compatible with the version of §6TuffX §cthe server has installed!\n§7Please update your client.");
194+
if (getConfig().getBoolean("kick-outdated-clients", true)){
195+
p.kickPlayer("§cYour client is not compatible with the version of §6TuffX §cthe server has installed!\n§7Please update your client.");
196+
}
195197
}
196198
}
197199

0 commit comments

Comments
 (0)