diff --git a/.gitignore b/.gitignore
index e1425cb..4938411 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
build/
.gradle/
-bin/
\ No newline at end of file
+bin/
+.idea/
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..90a6016
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..7d3b3e8
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..1fcfd5c
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..8a911c2
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,70 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a25b6db
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..c4e1060
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/TuffXPlus.main.iml b/.idea/modules/TuffXPlus.main.iml
new file mode 100644
index 0000000..ad42100
--- /dev/null
+++ b/.idea/modules/TuffXPlus.main.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+ SPIGOT
+ ADVENTURE
+
+ 1
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/TuffXPlus.test.iml b/.idea/modules/TuffXPlus.test.iml
new file mode 100644
index 0000000..a376b96
--- /dev/null
+++ b/.idea/modules/TuffXPlus.test.iml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ ADVENTURE
+
+ 1
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index fe10c6e..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,82 +0,0 @@
-plugins {
- id 'java'
- id 'com.gradleup.shadow' version '8.3.0'
-}
-
-group = 'tf.tuff'
-version = '1.0.0'
-
-java {
- sourceCompatibility = JavaVersion.VERSION_17
- targetCompatibility = JavaVersion.VERSION_17
-}
-
-tasks.withType(JavaCompile).configureEach {
- options.encoding = "UTF-8"
-}
-
-repositories {
- mavenCentral()
- maven { url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' }
- maven { url = 'https://repo.papermc.io/repository/maven-public/' }
- maven { url = 'https://repo.viaversion.com/everything/' }
- maven { url = 'https://repo.codemc.io/repository/maven-releases/' }
- maven { url = 'https://repo.codemc.io/repository/maven-snapshots/' }
- maven { url = 'https://jitpack.io' }
- maven { url = 'https://repo.dmulloy2.net/repository/public/' }
-}
-
-dependencies {
- compileOnly 'org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT'
-
- implementation 'com.github.retrooper:packetevents-spigot:2.11.1'
-
- compileOnly 'com.viaversion:viabackwards:5.3.2'
- compileOnly 'com.viaversion:viaversion:5.4.1'
-
- compileOnly 'it.unimi.dsi:fastutil:8.5.16'
-
- implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
-
- compileOnly 'io.netty:netty-all:4.1.97.Final'
-
- implementation 'org.java-websocket:Java-WebSocket:1.5.4'
-
- compileOnly 'org.projectlombok:lombok:1.18.30'
- annotationProcessor 'org.projectlombok:lombok:1.18.30'
-}
-
-processResources {
- filesMatching('plugin.yml') {
- expand(
- 'version': project.version,
- 'name': project.name
- )
- }
-}
-
-shadowJar {
- archiveClassifier.set('')
- archiveFileName.set("${project.name}-${project.version}.jar")
-
- relocate 'com.github.retrooper.packetevents', 'tf.tuff.packetevents'
- relocate 'io.github.retrooper.packetevents', 'tf.tuff.packetevents'
- relocate 'com.fasterxml.jackson', 'tf.tuff.jackson'
- relocate 'org.java_websocket', 'tf.tuff.websocket'
-
- exclude 'META-INF/*.SF'
- exclude 'META-INF/*.DSA'
- exclude 'META-INF/*.RSA'
- exclude 'META-INF/LICENSE'
- exclude 'META-INF/NOTICE'
- exclude 'META-INF/versions/**'
- exclude 'module-info.class'
-}
-
-tasks.named('jar') {
- enabled = false
-}
-
-tasks.named('build') {
- dependsOn shadowJar
-}
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..5f29b14
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,85 @@
+import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
+
+plugins {
+ java
+ id("com.gradleup.shadow") version "8.3.0"
+ id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
+}
+
+group = "tf.tuff"
+version = "1.0.0"
+
+
+repositories {
+ mavenCentral()
+ maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
+ maven("https://repo.papermc.io/repository/maven-public/")
+ maven("https://repo.viaversion.com/everything/")
+ maven("https://repo.codemc.io/repository/maven-releases/")
+ maven("https://repo.codemc.io/repository/maven-snapshots/")
+ maven("https://jitpack.io")
+ maven("https://repo.dmulloy2.net/repository/public/")
+ maven("https://repo.codemc.io/repository/maven-releases/")
+}
+
+dependencies {
+ paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT")
+
+ implementation(libs.packetevents.spigot)
+ compileOnly(libs.viabackwards)
+ compileOnly(libs.viaversion)
+ compileOnly(libs.fastutil)
+ implementation(libs.jackson.databind)
+ compileOnly(libs.netty.all)
+ implementation(libs.java.websocket)
+
+ compileOnly(libs.lombok)
+ annotationProcessor(libs.lombok)
+}
+
+
+java {
+ sourceCompatibility = JavaVersion.VERSION_21
+ targetCompatibility = JavaVersion.VERSION_21
+}
+
+tasks {
+ withType().configureEach {
+ options.encoding = "UTF-8"
+ }
+
+ processResources {
+ filesMatching("plugin.yml") {
+ expand(
+ "version" to project.version,
+ "name" to project.name
+ )
+ }
+ }
+
+ named("shadowJar") {
+ archiveClassifier.set("")
+ archiveFileName.set("${project.name}-${project.version}.jar")
+
+ relocate("com.github.retrooper.packetevents", "tf.tuff.packetevents")
+ relocate("io.github.retrooper.packetevents", "tf.tuff.packetevents")
+ relocate("com.fasterxml.jackson", "tf.tuff.jackson")
+ relocate("org.java_websocket", "tf.tuff.websocket")
+
+ exclude("META-INF/*.SF")
+ exclude("META-INF/*.DSA")
+ exclude("META-INF/*.RSA")
+ exclude("META-INF/LICENSE")
+ exclude("META-INF/NOTICE")
+ exclude("META-INF/versions/**")
+ exclude("module-info.class")
+ }
+
+ withType {
+ enabled = false
+ }
+
+ named("build") {
+ dependsOn(shadowJar)
+ }
+}
\ No newline at end of file
diff --git a/gradle/gradle-wrapper-shared-8.5.jar b/gradle/gradle-wrapper-shared-8.5.jar
deleted file mode 100644
index 54bc2d6..0000000
Binary files a/gradle/gradle-wrapper-shared-8.5.jar and /dev/null differ
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
new file mode 100644
index 0000000..e6503f4
--- /dev/null
+++ b/gradle/libs.versions.toml
@@ -0,0 +1,21 @@
+[versions]
+
+packetevents = "2.11.1"
+viabackwards = "5.3.2"
+viaversion = "5.4.1"
+fastutil = "8.5.16"
+jackson = "2.15.2"
+netty = "4.1.97.Final"
+websocket = "1.5.4"
+lombok = "1.18.30"
+
+[libraries]
+
+packetevents-spigot = { module = "com.github.retrooper:packetevents-spigot", version.ref = "packetevents" }
+viabackwards = { module = "com.viaversion:viabackwards", version.ref = "viabackwards" }
+viaversion = { module = "com.viaversion:viaversion", version.ref = "viaversion" }
+fastutil = { module = "it.unimi.dsi:fastutil", version.ref = "fastutil" }
+jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
+netty-all = { module = "io.netty:netty-all", version.ref = "netty" }
+java-websocket = { module = "org.java-websocket:Java-WebSocket", version.ref = "websocket" }
+lombok = { module = "org.projectlombok:lombok", version.ref = "lombok" }
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 1af9e09..37f78a6 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
diff --git a/settings.gradle b/settings.gradle
deleted file mode 100644
index e4ea97e..0000000
--- a/settings.gradle
+++ /dev/null
@@ -1 +0,0 @@
-rootProject.name = 'TuffXPlus'
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..873b2d7
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1 @@
+rootProject.name = "TuffXPlus"
diff --git a/src/main/java/tf/tuff/NetworkListener.java b/src/main/java/tf/tuff/NetworkListener.java
index 9e99e48..57b7019 100644
--- a/src/main/java/tf/tuff/NetworkListener.java
+++ b/src/main/java/tf/tuff/NetworkListener.java
@@ -4,7 +4,6 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChunkData;
-import org.bukkit.World;
import org.bukkit.entity.Player;
public class NetworkListener implements PacketListener {
@@ -17,16 +16,18 @@ public NetworkListener(TuffX plugin) {
@Override
public void onPacketSend(PacketSendEvent event) {
- if (event.getPacketType() == PacketType.Play.Server.CHUNK_DATA) {
- Player player = (Player) event.getPlayer();
- if (player == null) return;
+ if (event.getPacketType() != PacketType.Play.Server.CHUNK_DATA) return;
- WrapperPlayServerChunkData wrapper = new WrapperPlayServerChunkData(event);
- int chunkX = wrapper.getColumn().getX();
- int chunkZ = wrapper.getColumn().getZ();
+ Player player = event.getPlayer();
+ WrapperPlayServerChunkData wrapper = new WrapperPlayServerChunkData(event);
+
+ plugin.getY0Plugin().cpl
+ .handleChunk(plugin,
+ player,
+ player.getWorld(),
+ wrapper.getColumn().getX(),
+ wrapper.getColumn().getZ()
+ );
- World world = player.getWorld();
- plugin.y0Plugin.cpl.handleChunk(plugin, player, world, chunkX, chunkZ);
- }
}
}
diff --git a/src/main/java/tf/tuff/ServerRegistry.java b/src/main/java/tf/tuff/ServerRegistry.java
index a561a59..ebf57ed 100644
--- a/src/main/java/tf/tuff/ServerRegistry.java
+++ b/src/main/java/tf/tuff/ServerRegistry.java
@@ -23,44 +23,35 @@ public void connect() {
}
private void doConnect() {
- if (!running)
- return;
+ if (!running) return;
try {
- client = new WebSocketClient(new URI(wsUrl)) {
+ client = new WebSocketClient(
+ new URI(wsUrl)
+ ) {
@Override
public void onOpen(ServerHandshake h) {
send("{\"type\":\"register\",\"server\":\"" + server + "\"}");
}
-
@Override
- public void onMessage(String msg) {
- }
+ public void onMessage(String msg) {}
@Override
public void onClose(int code, String reason, boolean remote) {
- if (running) {
- p.getServer().getScheduler().runTaskLaterAsynchronously(p, () -> doConnect(), 100L);
- }
+ if (running) p.getServer().getScheduler().runTaskLaterAsynchronously(p, () -> doConnect(), 100L);
}
-
@Override
- public void onError(Exception e) {
- }
+ public void onError(Exception e) {}
};
client.setConnectionLostTimeout(30);
client.connect();
} catch (Exception e) {
- if (running) {
- p.getServer().getScheduler().runTaskLaterAsynchronously(p, () -> doConnect(), 100L);
- }
+ if (running) p.getServer().getScheduler().runTaskLaterAsynchronously(p, this::doConnect, 100L);
}
}
public void disconnect() {
running = false;
- if (client != null) {
- client.close();
- }
+ if (client != null) client.close();
}
}
diff --git a/src/main/java/tf/tuff/TuffX.java b/src/main/java/tf/tuff/TuffX.java
index 92e14ab..9ed99c0 100644
--- a/src/main/java/tf/tuff/TuffX.java
+++ b/src/main/java/tf/tuff/TuffX.java
@@ -1,45 +1,42 @@
package tf.tuff;
+import com.github.retrooper.packetevents.PacketEvents;
+import com.github.retrooper.packetevents.event.PacketListenerPriority;
+import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
+import lombok.Getter;
+import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.EventPriority;
-import org.bukkit.event.Listener;
-import org.bukkit.event.block.*;
-import org.bukkit.event.entity.EntityToggleGlideEvent;
-import org.bukkit.event.entity.EntityToggleSwimEvent;
-import org.bukkit.event.inventory.InventoryClickEvent;
-import org.bukkit.event.player.PlayerChangedWorldEvent;
-import org.bukkit.event.player.PlayerJoinEvent;
-import org.bukkit.event.player.PlayerQuitEvent;
-import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageListener;
-
-import com.github.retrooper.packetevents.PacketEvents;
-import com.github.retrooper.packetevents.event.PacketListenerPriority;
-
-import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
+import org.jetbrains.annotations.NotNull;
+import tf.tuff.listeners.BlockListener;
+import tf.tuff.listeners.PlayerListener;
import tf.tuff.netty.ChunkInjector;
import tf.tuff.tuffactions.TuffActions;
import tf.tuff.viablocks.ViaBlocksPlugin;
import tf.tuff.viaentities.ViaEntitiesPlugin;
import tf.tuff.y0.Y0Plugin;
-public class TuffX extends JavaPlugin implements Listener, PluginMessageListener {
+import java.util.List;
- public ServerRegistry serverRegistry;
+public final class TuffX extends JavaPlugin implements PluginMessageListener {
- public Y0Plugin y0Plugin;
- public ViaBlocksPlugin viaBlocksPlugin;
- public TuffActions tuffActions;
- public ViaEntitiesPlugin viaEntitiesPlugin;
- private ChunkInjector chunkInjector;
+ private ServerRegistry serverRegistry;
+ @Getter private static TuffX instance;
+ @Getter private Y0Plugin y0Plugin;
+ @Getter private ViaBlocksPlugin viaBlocksPlugin;
+ @Getter private TuffActions tuffActions;
+ @Getter private ViaEntitiesPlugin viaEntitiesPlugin;
+
+ public TuffX() {
+ instance = this;
+ }
@Override
public void onLoad() {
- this.y0Plugin = new Y0Plugin(this);
+ y0Plugin = new Y0Plugin(this);
this.viaBlocksPlugin = new ViaBlocksPlugin(this);
this.tuffActions = new TuffActions(this);
this.viaEntitiesPlugin = new ViaEntitiesPlugin(this);
@@ -55,24 +52,43 @@ public void onEnable() {
PacketEvents.getAPI().init();
y0Plugin.onTuffXEnable();
- tuffActions.onTuffXEnable();
+ tuffActions.load();
viaBlocksPlugin.onTuffXEnable();
viaEntitiesPlugin.onTuffXEnable();
- chunkInjector = new ChunkInjector(viaBlocksPlugin.blockListener, y0Plugin);
+ ChunkInjector chunkInjector = new ChunkInjector(viaBlocksPlugin.blockListener, y0Plugin);
viaBlocksPlugin.blockListener.setChunkInjector(chunkInjector);
y0Plugin.setChunkInjector(chunkInjector);
saveDefaultConfig();
-
PacketEvents.getAPI().getEventManager().registerListener(
new NetworkListener(this), PacketListenerPriority.NORMAL
);
- getServer().getPluginManager().registerEvents(this, this);
-
+ Bukkit.getPluginManager().registerEvents(new BlockListener(), this);
+ Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
setupRegistry();
- lfe();
+ List.of(
+ "████████╗██╗ ██╗███████╗ ███████╗ ██╗ ██╗",
+ "╚══██╔══╝██║ ██║██╔════╝ ██╔════╝ ╚██╗██╔╝",
+ " ██║ ██║ ██║██████╗ ██████╗ ╚███╔╝ ",
+ " ██║ ██║ ██║██╔═══╝ ██╔═══╝ ██╔██╗ ",
+ " ██║ ╚██████╔╝██║ ██║ ██╔╝╚██╗",
+ " ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝",
+ "",
+ "CREDITS",
+ "Y0 support:",
+ "• Below y0 (client + plugin) programmed by Potato (@justatypicalpotato)",
+ "• llucasandersen - plugin optimizations",
+ "• ViaBlocks partial plugin and client rewrite by Potato",
+ "• llucasandersen (Complex client models and texture fixes,",
+ " optimizations, PacketEvents migration and async safety fixes)",
+ "• coleis1op, if ts is driving me crazy, im taking credit",
+ "• Swimming and creative items programmed by Potato (@justatypicalpotato)",
+ "• shaded build, 1.14+ support (before merge) - llucasandersen",
+ "• Restrictions - UplandJacob",
+ "• Overall plugin merges by Potato"
+ ).forEach(Bukkit.getConsoleSender()::sendMessage);
}
private void setupRegistry() {
@@ -101,6 +117,20 @@ public void onDisable() {
PacketEvents.getAPI().terminate();
}
+ @Override
+ public void onPluginMessageReceived(@NotNull String channel, Player player, byte[] message) {
+ if (!player.isOnline()) return;
+
+ switch (channel) {
+ case "eagler:below_y0" -> y0Plugin.handlePacket(player, message);
+ case "viablocks:handshake" -> viaBlocksPlugin.handlePacket(player, message);
+ case "eagler:tuffactions" -> tuffActions.handlePacket(player, message);
+ case "entities:handshake" -> viaEntitiesPlugin.handlePacket(player, message);
+ default ->
+ getLogger().warning("Received plugin message on unknown channel '%s' from %s".formatted(channel, player.getName()));
+ }
+ }
+
public void reloadTuffX(){
reloadConfig();
saveDefaultConfig();
@@ -111,22 +141,19 @@ public void reloadTuffX(){
}
setupRegistry();
-
viaBlocksPlugin.onTuffXReload();
y0Plugin.onTuffXReload();
tuffActions.onTuffXReload();
viaEntitiesPlugin.onTuffXReload();
-
getLogger().info("TuffX reloaded.");
}
public boolean TuffXCommand(CommandSender sender, Command command, String label, String[] args){
if (args.length > 0) {
if (args[0].equalsIgnoreCase("reload")) {
- if (!(sender instanceof Player)) {
+ if (!(sender instanceof Player player)) {
reloadTuffX();
} else {
- Player player = (Player) sender;
if (!player.hasPermission("tuffx.reload")) {
player.sendMessage("§cYou do not have permission to use this command.");
return false;
@@ -140,138 +167,10 @@ public boolean TuffXCommand(CommandSender sender, Command command, String label,
}
@Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
+ public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNull String label, String @NotNull [] args) {
if (command.getName().equalsIgnoreCase("tuffx")) return TuffXCommand(sender, command, label, args);
if (command.getName().equalsIgnoreCase("viablocks")) return viaBlocksPlugin.onTuffXCommand(sender, command, label, args);
if (command.getName().equalsIgnoreCase("restrictions")) return tuffActions.onTuffXCommand(sender, command, label, args);
return true;
}
-
- @Override
- public void onPluginMessageReceived(String channel, Player player, byte[] message) {
- if (!player.isOnline()) return;
-
- if (channel.equals("eagler:below_y0")) y0Plugin.handlePacket(player,message);
- else if (channel.equals("viablocks:handshake")) viaBlocksPlugin.handlePacket(player,message);
- else if (channel.equals("eagler:tuffactions")) tuffActions.handlePacket(player,message);
- else if (channel.equals("entities:handshake")) viaEntitiesPlugin.handlePacket(player,message);
- else getLogger().warning("Received plugin message on unknown channel '%s' from %s".formatted(channel, player.getName()));
- }
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void onPlayerChangeWorld(PlayerChangedWorldEvent e) {
- y0Plugin.handlePlayerChangeWorld(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockForm(BlockFormEvent e) {
- viaBlocksPlugin.blockListener.handleBlockForm(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockFade(BlockFadeEvent e) {
- viaBlocksPlugin.blockListener.handleBlockFade(e);
- }
-
- @EventHandler(priority = EventPriority.MONITOR)
- public void onPlayerJoin(PlayerJoinEvent e) {
- y0Plugin.handlePlayerJoin(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockGrow(BlockGrowEvent e) {
- viaBlocksPlugin.blockListener.handleBlockGrow(e);
- }
-
- @EventHandler
- public void onPlayerQuit(PlayerQuitEvent e) {
- y0Plugin.handlePlayerQuit(e);
- tuffActions.handlePlayerQuit(e);
- viaBlocksPlugin.blockListener.handlePlayerQuit(e);
- viaEntitiesPlugin.handlePlayerQuit(e);
- }
-
- @EventHandler
- public void onToggleSwim(EntityToggleSwimEvent e) {
- tuffActions.handleToggleSwim(e);
- }
-
- @EventHandler
- public void onToggleGlide(EntityToggleGlideEvent e) {
- tuffActions.handleToggleGlide(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockSpread(BlockSpreadEvent e) {
- viaBlocksPlugin.blockListener.handleBlockSpread(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockBreak(BlockBreakEvent e) {
- viaBlocksPlugin.blockListener.handleBlockBreak(e);
- y0Plugin.handleBlockBreak(e);
- }
-
- @EventHandler
- public void onPlayerInventoryClick(InventoryClickEvent e) {
- tuffActions.handlePlayerInventoryClick(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockPlace(BlockPlaceEvent e) {
- viaBlocksPlugin.blockListener.handleBlockPlace(e);
- y0Plugin.handleBlockPlace(e);
- }
-
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onBlockPhysics(BlockPhysicsEvent e) {
- y0Plugin.handleBlockPhysics(e);
- viaBlocksPlugin.blockListener.handleBlockPhysics(e);
- }
-
- @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onChunkLoad(ChunkLoadEvent e) {
- y0Plugin.handleChunkLoad(e);
- viaBlocksPlugin.blockListener.handleChunkLoad(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockExplode(BlockExplodeEvent e) {
- viaBlocksPlugin.blockListener.handleBlockExplode(e);
- y0Plugin.handleBlockExplode(e);
- }
-
- @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
- public void onBlockFromTo(BlockFromToEvent e) {
- viaBlocksPlugin.blockListener.handleBlockFromTo(e);
- y0Plugin.handleBlockFromTo(e);
- }
-
- private void lfe() {
- getLogger().info("");
- getLogger().info("████████╗██╗ ██╗███████╗ ███████╗ ██╗ ██╗");
- getLogger().info("╚══██╔══╝██║ ██║██╔════╝ ██╔════╝ ╚██╗██╔╝");
- getLogger().info(" ██║ ██║ ██║██████╗ ██████╗ ╚███╔╝ ");
- getLogger().info(" ██║ ██║ ██║██╔═══╝ ██╔═══╝ ██╔██╗ ");
- getLogger().info(" ██║ ╚██████╔╝██║ ██║ ██╔╝╚██╗");
- getLogger().info(" ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝");
- getLogger().info("");
- getLogger().info("CREDITS");
- getLogger().info("");
- getLogger().info("Y0 support:");
- getLogger().info("• Below y0 (client + plugin) programmed by Potato (@justatypicalpotato)");
- getLogger().info("• llucasandersen - plugin optimizations");
- getLogger().info("");
- getLogger().info("ViaBlocks:");
- getLogger().info("• ViaBlocks partial plugin and client rewrite by Potato");
- getLogger().info("• llucasandersen (Complex client models and texture fixes,");
- getLogger().info(" optimizations, PacketEvents migration and async safety fixes)");
- getLogger().info("• coleis1op, if ts is driving me crazy, im taking credit");
- getLogger().info("");
- getLogger().info("Other:");
- getLogger().info("• Swimming and creative items programmed by Potato (@justatypicalpotato)");
- getLogger().info("• shaded build, 1.14+ support (before merge) - llucasandersen");
- getLogger().info("• Restrictions - UplandJacob");
- getLogger().info("• Overall plugin merges by Potato");
- }
}
diff --git a/src/main/java/tf/tuff/listeners/BlockListener.java b/src/main/java/tf/tuff/listeners/BlockListener.java
new file mode 100644
index 0000000..f9c90a6
--- /dev/null
+++ b/src/main/java/tf/tuff/listeners/BlockListener.java
@@ -0,0 +1,64 @@
+package tf.tuff.listeners;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.*;
+
+public class BlockListener extends ListenerBase implements Listener {
+
+ public BlockListener() {
+ super();
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockForm(BlockFormEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockForm(e);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockFade(BlockFadeEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockFade(e);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockSpread(BlockSpreadEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockSpread(e);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockBreak(BlockBreakEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockBreak(e);
+ y0Plugin.handleBlockBreak(e);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockGrow(BlockGrowEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockGrow(e);
+ }
+
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockPlace(BlockPlaceEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockPlace(e);
+ y0Plugin.handleBlockPlace(e);
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onBlockPhysics(BlockPhysicsEvent e) {
+ y0Plugin.handleBlockPhysics(e);
+ viaBlocksPlugin.blockListener.handleBlockPhysics(e);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockExplode(BlockExplodeEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockExplode(e);
+ y0Plugin.handleBlockExplode(e);
+ }
+
+ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
+ public void onBlockFromTo(BlockFromToEvent e) {
+ viaBlocksPlugin.blockListener.handleBlockFromTo(e);
+ y0Plugin.handleBlockFromTo(e);
+ }
+}
diff --git a/src/main/java/tf/tuff/listeners/ListenerBase.java b/src/main/java/tf/tuff/listeners/ListenerBase.java
new file mode 100644
index 0000000..678a752
--- /dev/null
+++ b/src/main/java/tf/tuff/listeners/ListenerBase.java
@@ -0,0 +1,21 @@
+package tf.tuff.listeners;
+
+import tf.tuff.TuffX;
+import tf.tuff.tuffactions.TuffActions;
+import tf.tuff.viablocks.ViaBlocksPlugin;
+import tf.tuff.viaentities.ViaEntitiesPlugin;
+import tf.tuff.y0.Y0Plugin;
+
+public abstract class ListenerBase {
+ protected final ViaBlocksPlugin viaBlocksPlugin;
+ protected final TuffActions tuffActions;
+ protected final ViaEntitiesPlugin viaEntitiesPlugin;
+ protected final Y0Plugin y0Plugin;
+
+ public ListenerBase() {
+ viaBlocksPlugin = TuffX.getInstance().getViaBlocksPlugin();
+ tuffActions = TuffX.getInstance().getTuffActions();
+ viaEntitiesPlugin = TuffX.getInstance().getViaEntitiesPlugin();
+ y0Plugin = TuffX.getInstance().getY0Plugin();
+ }
+}
diff --git a/src/main/java/tf/tuff/listeners/PlayerListener.java b/src/main/java/tf/tuff/listeners/PlayerListener.java
new file mode 100644
index 0000000..c6cba48
--- /dev/null
+++ b/src/main/java/tf/tuff/listeners/PlayerListener.java
@@ -0,0 +1,60 @@
+package tf.tuff.listeners;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.*;
+import org.bukkit.event.entity.EntityToggleGlideEvent;
+import org.bukkit.event.entity.EntityToggleSwimEvent;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.world.ChunkLoadEvent;
+
+public class PlayerListener extends ListenerBase implements Listener {
+
+ public PlayerListener() {
+ super();
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPlayerChangeWorld(PlayerChangedWorldEvent e) {
+ y0Plugin.handlePlayerChangeWorld(e);
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onPlayerJoin(PlayerJoinEvent e) {
+ y0Plugin.handlePlayerJoin(e);
+ }
+
+ @EventHandler
+ public void onPlayerQuit(PlayerQuitEvent e) {
+ y0Plugin.handlePlayerQuit(e);
+ tuffActions.handlePlayerQuit(e);
+ viaBlocksPlugin.blockListener.handlePlayerQuit(e);
+ viaEntitiesPlugin.handlePlayerQuit(e);
+ }
+
+ @EventHandler
+ public void onPlayerInventoryClick(InventoryClickEvent e) {
+ tuffActions.handlePlayerInventoryClick(e);
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onChunkLoad(ChunkLoadEvent e) {
+ y0Plugin.handleChunkLoad(e);
+ viaBlocksPlugin.blockListener.handleChunkLoad(e);
+ }
+
+ @EventHandler
+ public void onToggleSwim(EntityToggleSwimEvent e) {
+ tuffActions.handleToggleSwim(e);
+ }
+
+ @EventHandler
+ public void onToggleGlide(EntityToggleGlideEvent e) {
+ tuffActions.handleToggleGlide(e);
+ }
+
+}
diff --git a/src/main/java/tf/tuff/netty/BaseInjector.java b/src/main/java/tf/tuff/netty/BaseInjector.java
index b2e521b..dc77096 100644
--- a/src/main/java/tf/tuff/netty/BaseInjector.java
+++ b/src/main/java/tf/tuff/netty/BaseInjector.java
@@ -1,6 +1,7 @@
package tf.tuff.netty;
import com.viaversion.viaversion.api.Via;
+import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import org.bukkit.entity.Player;
@@ -22,7 +23,7 @@ protected void onPostInject(Player player) {
public void inject(Player player) {
UUID uuid = player.getUniqueId();
- var viaConnection = Via.getAPI().getConnection(uuid);
+ UserConnection viaConnection = Via.getAPI().getConnection(uuid);
if (viaConnection == null) return;
Channel channel = viaConnection.getChannel();
@@ -36,12 +37,12 @@ public void inject(Player player) {
String targetHandler = null;
String[] anchors = {"packet_handler", "encoder", "via-encoder"};
- for (int i = 0; i < anchors.length; ++i) {
- if (channel.pipeline().get(anchors[i]) != null) {
- targetHandler = anchors[i];
- break;
- }
- }
+ for (String anchor : anchors) {
+ if (channel.pipeline().get(anchor) != null) {
+ targetHandler = anchor;
+ break;
+ }
+ }
ChannelHandler handler = createHandler(player);
if (targetHandler != null) {
@@ -58,19 +59,15 @@ public void inject(Player player) {
}
public void eject(Player player) {
- UUID uuid = player.getUniqueId();
- var viaConnection = Via.getAPI().getConnection(uuid);
- if (viaConnection == null) return;
-
- Channel channel = viaConnection.getChannel();
+ UserConnection viaConnection = Via.getAPI().getConnection(player.getUniqueId());
+ Channel channel = viaConnection != null ? viaConnection.getChannel() : null;
if (channel != null && channel.isOpen()) {
channel.eventLoop().submit(() -> {
try {
if (channel.pipeline().get(handlerName) != null) {
channel.pipeline().remove(handlerName);
}
- } catch (Exception e) {
- }
+ } catch (Exception ignored) {}
});
}
}
diff --git a/src/main/java/tf/tuff/tuffactions/TuffActions.java b/src/main/java/tf/tuff/tuffactions/TuffActions.java
index bf90b04..23a5a40 100644
--- a/src/main/java/tf/tuff/tuffactions/TuffActions.java
+++ b/src/main/java/tf/tuff/tuffactions/TuffActions.java
@@ -1,14 +1,7 @@
package tf.tuff.tuffactions;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-
+import com.github.retrooper.packetevents.PacketEvents;
+import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPluginMessage;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -17,15 +10,20 @@
import org.bukkit.event.entity.EntityToggleSwimEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
-
-import com.github.retrooper.packetevents.PacketEvents;
-import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerPluginMessage;
-
import tf.tuff.TuffX;
import tf.tuff.tuffactions.creative.CreativeMenu;
import tf.tuff.tuffactions.restrictions.Restrictions;
import tf.tuff.tuffactions.swimming.Swimming;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+
public class TuffActions {
public static final String CHANNEL = "eagler:tuffactions";
@@ -37,12 +35,12 @@ public class TuffActions {
public static boolean swimmingEnabled = false;
public static boolean creativeEnabled = false;
public static boolean restrictionsEnabled = false;
-
+
public final TuffX plugin;
public static final Set tuffPlayers = ConcurrentHashMap.newKeySet();
- public TuffActions(TuffX plugin){
+ public TuffActions(TuffX plugin) {
this.plugin = plugin;
}
@@ -67,7 +65,7 @@ public void onTuffXReload() {
info("Misc features reloaded.");
}
- public void onTuffXEnable() {
+ public void load() {
loadConfig();
PacketEvents.getAPI().init();
@@ -75,13 +73,11 @@ public void onTuffXEnable() {
this.creativeManager = new CreativeMenu(this);
this.restrictions = new Restrictions(this);
info("Finished enabling features.");
-
- plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "eagler:tuffactions");
- plugin.getServer().getMessenger().registerIncomingPluginChannel(plugin, "eagler:tuffactions", plugin);
}
public boolean onTuffXCommand(CommandSender sender, Command command, String label, String[] args) {
- if (command.getName().equalsIgnoreCase("restrictions")) return this.restrictions.onTuffXCommand(sender, command, label, args);
+ if (command.getName().equalsIgnoreCase("restrictions"))
+ return this.restrictions.onTuffXCommand(sender, command, label, args);
return true;
}
@@ -103,43 +99,59 @@ public void handlePacket(Player player, byte[] message) {
tuffPlayers.add(player.getUniqueId());
- if ("swimming_state".equals(action) && swimmingEnabled) {
- swimmingManager.handleSwimState(player, in.readBoolean());
- } else if ("elytra_state".equals(action) && swimmingEnabled) {
- swimmingManager.handleElytraState(player, in.readBoolean());
- } else if ("creative_ready".equals(action) && creativeEnabled){
- creativeManager.handleCreativeReady(player);
- } else if ("swim_ready".equals(action) && swimmingEnabled){
- swimmingManager.handleSwimReady(player);
- } else if ("give_creative_item".equals(action) && creativeEnabled){
- if (player.getGameMode() != GameMode.CREATIVE) {
- return;
+ switch (action.toLowerCase()) {
+ case "swimming_state" -> {
+ if (swimmingEnabled) {
+ swimmingManager.handleSwimState(player, in.readBoolean());
+ break;
+ }
+ }
+ case "elytra_state" -> {
+ if (swimmingEnabled) {
+ swimmingManager.handleElytraState(player, in.readBoolean());
+ break;
+ }
}
- int itemLength = in.readUnsignedByte();
- if (in.available() < itemLength + Integer.BYTES) {
- return;
+ case "creative-ready" -> {
+ if (creativeEnabled) {
+ creativeManager.handleCreativeReady(player);
+ }
}
- byte[] itemBytes = new byte[itemLength];
- in.readFully(itemBytes);
- String item = new String(itemBytes, StandardCharsets.UTF_8);
- int amount = in.readInt();
- creativeManager.handlePlaceholderTaken(player, item, amount);
- } else if ("pick_viablock".equals(action) && creativeEnabled){
- if (player.getGameMode() != GameMode.CREATIVE) {
- return;
+ case "swim_ready" -> {
+ if (swimmingEnabled) {
+ swimmingManager.handleSwimReady(player);
+ }
+ }
+ case "give_creative_item" -> {
+ if (creativeEnabled) {
+ if (player.getGameMode() != GameMode.CREATIVE) return;
+ int itemLength = in.readUnsignedByte();
+ if (in.available() < itemLength + Integer.BYTES) {
+ return;
+ }
+ byte[] itemBytes = new byte[itemLength];
+ in.readFully(itemBytes);
+ String item = new String(itemBytes, StandardCharsets.UTF_8);
+ int amount = in.readInt();
+ creativeManager.handlePlaceholderTaken(player, item, amount);
+ }
}
- int blockLength = in.readUnsignedByte();
- if (in.available() < blockLength + 1) {
- return;
+ case "pick_viablock" -> {
+ if (creativeEnabled) {
+ if (player.getGameMode() != GameMode.CREATIVE) return;
+ int blockLength = in.readUnsignedByte();
+ if (in.available() < blockLength + 1) return;
+ byte[] blockBytes = new byte[blockLength];
+ in.readFully(blockBytes);
+ String blockName = new String(blockBytes, StandardCharsets.UTF_8);
+ int hotbarSlot = in.readUnsignedByte();
+ creativeManager.handlePickViablock(player, blockName, hotbarSlot);
+ }
}
- byte[] blockBytes = new byte[blockLength];
- in.readFully(blockBytes);
- String blockName = new String(blockBytes, StandardCharsets.UTF_8);
- int hotbarSlot = in.readUnsignedByte();
- creativeManager.handlePickViablock(player, blockName, hotbarSlot);
- } else if ("restrictions_ready".equals(action)) {
- restrictions.handleRestrictionsReady(player);
+ case "restrictions_ready" ->
+ restrictions.handleRestrictionsReady(player);
}
+
} catch (IOException e) {
log(Level.WARNING, "Failed to read a plugin message from " + player.getName(), e);
}
@@ -150,44 +162,41 @@ public void sendPluginMessage(Player player, byte[] payload) {
}
public void sendPluginMessage(Player player, String channel, byte[] payload) {
- if (player == null || payload == null || !player.isOnline() || !PacketEvents.getAPI().isInitialized()) {
+ if (player == null || payload == null ||
+ !player.isOnline() || !PacketEvents.getAPI().isInitialized()
+ ) {
return;
}
+
WrapperPlayServerPluginMessage packet = new WrapperPlayServerPluginMessage(channel, payload);
PacketEvents.getAPI().getPlayerManager().sendPacket(player, packet);
}
public void handlePlayerQuit(PlayerQuitEvent event) {
- if (swimmingEnabled) {
- swimmingManager.handleSwimQuit(event);
- }
+ if (swimmingEnabled) swimmingManager.handleSwimQuit(event);
tuffPlayers.remove(event.getPlayer().getUniqueId());
}
public void handleToggleSwim(EntityToggleSwimEvent event) {
- if (swimmingEnabled) {
- swimmingManager.handleToggleSwim(event);
- }
+ if (swimmingEnabled) swimmingManager.handleToggleSwim(event);
}
public void handleToggleGlide(EntityToggleGlideEvent event) {
- if (swimmingEnabled) {
- swimmingManager.handleToggleGlide(event);
- }
+ if (swimmingEnabled) swimmingManager.handleToggleGlide(event);
}
public void handlePlayerInventoryClick(InventoryClickEvent event) {
- if (creativeEnabled) {
- creativeManager.onPlayerInventoryClick(event);
- }
+ if (creativeEnabled) creativeManager.onPlayerInventoryClick(event);
}
public void log(Level level, String msg, Throwable e) {
- plugin.getLogger().log(level, "[TuffActions] "+msg, e);
+ plugin.getLogger().log(level, "[TuffActions] ".formatted(msg), e);
}
+
public void log(Level level, String msg) {
- plugin.getLogger().log(level, "[TuffActions] "+msg);
+ plugin.getLogger().log(level, "[TuffActions] %s".formatted(msg));
}
+
public void info(String msg) {
log(Level.INFO, msg);
}
diff --git a/src/main/java/tf/tuff/tuffactions/creative/CreativeMenu.java b/src/main/java/tf/tuff/tuffactions/creative/CreativeMenu.java
index 221f84b..af74561 100644
--- a/src/main/java/tf/tuff/tuffactions/creative/CreativeMenu.java
+++ b/src/main/java/tf/tuff/tuffactions/creative/CreativeMenu.java
@@ -1,17 +1,17 @@
package tf.tuff.tuffactions.creative;
-import tf.tuff.tuffactions.TuffActions;
-
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
+import tf.tuff.tuffactions.TuffActions;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -20,7 +20,7 @@
import java.util.logging.Level;
public class CreativeMenu {
- private final TuffActions plugin;
+ private final TuffActions plugin;
private final Set itemMapping = ConcurrentHashMap.newKeySet();
private final Map playerHoldingPlaceholder = new ConcurrentHashMap<>();
@@ -29,18 +29,13 @@ public class CreativeMenu {
public CreativeMenu(TuffActions plugin) {
this.plugin = plugin;
this.tabUtil = new TabUtil(plugin);
-
- if (TuffActions.creativeEnabled) {
- initializeMappings();
- }
+ if (TuffActions.creativeEnabled) initializeMappings();
}
public void initializeMappings() {
- for (Material m : Material.values()){
- if (m.isItem()){
- itemMapping.add(m.name());
- }
- }
+ Arrays.stream(Material.values()).toList().forEach(m -> {
+ if (m.isItem()) itemMapping.add(m.name());
+ });
}
public void handleCreativeReady(Player player) {
@@ -73,10 +68,7 @@ public void handlePickViablock(Player player, String blockName, int hotbarSlot)
if (material == null || !material.isItem()) {
return;
}
- if (hotbarSlot < 0 || hotbarSlot > 8) {
- hotbarSlot = 0;
- }
- player.getInventory().setItem(hotbarSlot, new ItemStack(material, 1));
+ player.getInventory().setItem(hotbarSlot > 8 || hotbarSlot < 0 ? 0 : hotbarSlot, new ItemStack(material, 1));
}
public void onPlayerInventoryClick(InventoryClickEvent event) {
@@ -87,7 +79,7 @@ public void onPlayerInventoryClick(InventoryClickEvent event) {
InventoryAction action = event.getAction();
if (action == InventoryAction.PLACE_ALL || action == InventoryAction.PLACE_ONE || action == InventoryAction.SWAP_WITH_CURSOR) {
- Bukkit.getScheduler().runTaskLater(this.plugin.plugin, () -> {
+ Bukkit.getScheduler().runTaskLater(this.plugin.getPlugin(), () -> {
ItemStack realItemStack = playerHoldingPlaceholder.get(playerUUID);
if (realItemStack != null && event.getClickedInventory() != null) {
diff --git a/src/main/java/tf/tuff/tuffactions/creative/TabUtil.java b/src/main/java/tf/tuff/tuffactions/creative/TabUtil.java
index 428990c..c6ff551 100644
--- a/src/main/java/tf/tuff/tuffactions/creative/TabUtil.java
+++ b/src/main/java/tf/tuff/tuffactions/creative/TabUtil.java
@@ -1,16 +1,16 @@
package tf.tuff.tuffactions.creative;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.jetbrains.annotations.NotNull;
+import tf.tuff.tuffactions.TuffActions;
+
+import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
import java.util.logging.Level;
-import javax.annotation.Nullable;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-import tf.tuff.tuffactions.TuffActions;
public class TabUtil {
private final TuffActions plugin;
@@ -20,9 +20,7 @@ public class TabUtil {
public TabUtil(TuffActions plugin) {
this.plugin = plugin;
this.mappingFile = new File(plugin.plugin.getDataFolder(), "tab-mapping.json");
-
setupMappingFile();
-
loadMapping();
}
@@ -34,14 +32,13 @@ private void setupMappingFile() {
}
private void loadMapping() {
+
+ ObjectMapper mapper = new ObjectMapper();
+ TypeReference