Skip to content

Commit

Permalink
Merge pull request #193 from dniym/fix/1.20.6-support
Browse files Browse the repository at this point in the history
Added 1.20.6 support.
  • Loading branch information
dniym authored Jun 5, 2024
2 parents 57c0609 + f35b00a commit a3b1767
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 42 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ dependencies {
compileOnly("com.elmakers.mine.bukkit:MagicAPI:10.2")
compileOnly("de.tr7zw:item-nbt-api-plugin:2.8.0")
compileOnly("com.github.TheBusyBiscuit:Slimefun4:RC-30") { isTransitive = false }
compileOnly("io.netty:netty-all:4.1.82.Final") {
compileOnly("io.netty:netty-all:4.1.110.Final") {
because("The version aligns with the version used by Minecraft itself." +
"The minecraft server ships netty as well, so we don't need to include it in the jar.")
}
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.217") { isTransitive = false }
compileOnly("fr.minuskube.inv:smart-invs:1.2.7")
compileOnly("com.github.CraftingStore:MinecraftPlugin:master-SNAPSHOT")
//compileOnly("com.github.CraftingStore.MinecraftPlugin:core:master-e366d322f8-1")
compileOnly("com.github.brcdev-minecraft:shopgui-api:3.0.0")
}

Expand All @@ -66,7 +66,7 @@ tasks.compileJava.configure {
options.release.set(8)
}

version = "2.9.10-SNAPSHOT-02"
version = "2.9.11-SNAPSHOT-01"

tasks.named<Copy>("processResources") {
filesMatching("plugin.yml") {
Expand Down
64 changes: 61 additions & 3 deletions src/main/java/main/java/me/dniym/IllegalStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import main.java.me.dniym.commands.IllegalStackCommand;
import main.java.me.dniym.enums.Msg;
import main.java.me.dniym.enums.Protections;
import main.java.me.dniym.enums.ServerVersion;
import main.java.me.dniym.listeners.Listener113;
import main.java.me.dniym.listeners.Listener114;
import main.java.me.dniym.listeners.Listener116;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class IllegalStack extends JavaPlugin {
private static IllegalStack plugin;
private static Plugin ProCosmetics = null;
private static boolean isHybridEnvironment = false;
private static boolean isPaperServer = false;
private static boolean hasProtocolLib = false;
private static boolean hasAttribAPI = false;
private static boolean nbtAPI = false;
Expand Down Expand Up @@ -75,6 +77,8 @@ public class IllegalStack extends JavaPlugin {
private Scheduler.ScheduledTask syncTimer = null;
// private static NMSEntityVillager nmsTrader= null;

private ServerVersion serverVersion;

public static IllegalStack getPlugin() {
return plugin;
}
Expand All @@ -87,6 +91,10 @@ public static boolean isIsHybridEnvironment() {
return isHybridEnvironment;
}

public static boolean isPaperServer() {
return isPaperServer;
}

public static boolean isSpigot() {
return Spigot;
}
Expand Down Expand Up @@ -145,9 +153,21 @@ private static void checkForHybridEnvironment() {
}
}

private static void checkForPaperServer() {
try {
Class.forName("com.destroystokyo.paper.utils.PaperPluginLogger");
isPaperServer = true;
LOGGER.info("Server is a Paper server, enabling Paper features.");
} catch (ClassNotFoundException e) {
isPaperServer = false;
LOGGER.info("Server is NOT a Paper server, continuing as normal.");
}
}

private static void StartupPlugin() {

checkForHybridEnvironment();
checkForPaperServer();

try {
Class.forName("org.spigotmc.SpigotConfig");
Expand Down Expand Up @@ -177,6 +197,7 @@ private static void StartupPlugin() {
}
}

Protections.runReflectionChecks();

if (fListener.getInstance() == null) {
plugin.getServer().getPluginManager().registerEvents(new fListener(plugin), plugin);
Expand Down Expand Up @@ -402,6 +423,7 @@ public void onEnable() {
updateConfig();
loadMsgs();
checkForHybridEnvironment();
checkForPaperServer();
IllegalStackCommand illegalStackCommand = new IllegalStackCommand();
this.getCommand("istack").setExecutor(illegalStackCommand);
this.getCommand("istack").setTabCompleter(illegalStackCommand);
Expand Down Expand Up @@ -1083,10 +1105,28 @@ private void writeConfig() {

private void setVersion() {

String version = getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
String version;

try {
version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
} catch (ArrayIndexOutOfBoundsException e) {
version = null;
}

if (version != null) {
version = getString(version);
IllegalStack.version = version;
} else {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String bukkitVersion = Bukkit.getServer().getBukkitVersion();
if (bukkitVersion.contains("1.20.5") || bukkitVersion.contains("1.20.6")) {
serverVersion = ServerVersion.v1_20_R4;
} else {
serverVersion = ServerVersion.valueOf(packageName.replace("org.bukkit.craftbukkit.", ""));
}

version = getString(version);
IllegalStack.version = version;
IllegalStack.version = serverVersion.getServerVersionName();
}
}

public static Material getLbBlock() {
Expand All @@ -1097,4 +1137,22 @@ public static void setLbBlock(Material lbBlock) {
IllegalStack.lbBlock = lbBlock;
}

public ServerVersion getServerVersion() {
return serverVersion;
}

public static int getMajorServerVersion() {
int version;

try {
version = Integer.parseInt(getVersion().split("_")[1]);
} catch (NumberFormatException e) {
LOGGER.error("Unable to process server version!");
LOGGER.error("Some features may break unexpectedly!");
LOGGER.error("Report any issues to the developer!");
return 0;
}
return version;
}

}
77 changes: 46 additions & 31 deletions src/main/java/main/java/me/dniym/enums/Protections.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main.java.me.dniym.enums;


import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
Expand All @@ -26,6 +27,7 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.BlockInventoryHolder;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand All @@ -37,7 +39,6 @@
//import me.jet315.minions.MinionAPI;
//import me.jet315.minions.minions.Minion;
import net.brcdev.shopgui.gui.gui.OpenGui;
import net.craftingstore.bukkit.inventory.CraftingStoreInventoryHolder;

public enum Protections {

Expand Down Expand Up @@ -1294,7 +1295,6 @@ public enum Protections {
false
)
;

private static final Logger LOGGER = LogManager.getLogger("IllegalStack/" + Protections.class.getSimpleName());
///OPTIONS///
private Object defaultValue = null;
Expand All @@ -1314,6 +1314,7 @@ public enum Protections {
private boolean isList = false;
private int catId = 0;
private boolean relevant = false;
private static Class<?> craftingStoreInventoryHolder = null;

Protections(
int id,
Expand Down Expand Up @@ -1692,34 +1693,33 @@ public void setEnabled(boolean enabled) {
}

private String getServerVersion() {
if (serverVersion == "") {
String version = IllegalStack
.getPlugin()
.getServer()
.getClass()
.getPackage()
.getName()
.replace(".", ",")
.split(",")[3];


version = IllegalStack.getString(version);
if (version.equalsIgnoreCase("v1_15_R1")) {

version = IllegalStack.getPlugin().getServer().getVersion().split(" ")[2];
if (version.contains(" ")) {
version = version.replace(")", "");
version = version.replace(".", "_");
String[] ver = version.split("_");
version = "v" + ver[0] + "_" + ver[1] + "_R" + ver[2];
}

}

serverVersion = version;

}
return serverVersion;
// if (serverVersion.equalsIgnoreCase("")) {
// String version = IllegalStack
// .getPlugin()
// .getServer()
// .getClass()
// .getPackage()
// .getName()
// .replace(".", ",")
// .split(",")[3];
//
//
// version = IllegalStack.getString(version);
// if (version.equalsIgnoreCase("v1_15_R1")) {
//
// version = IllegalStack.getPlugin().getServer().getVersion().split(" ")[2];
// if (version.contains(" ")) {
// version = version.replace(")", "");
// version = version.replace(".", "_");
// String[] ver = version.split("_");
// version = "v" + ver[0] + "_" + ver[1] + "_R" + ver[2];
// }
//
// }
//
// serverVersion = version;
// }
return IllegalStack.getVersion();
}

public boolean notifyOnly() {
Expand Down Expand Up @@ -2442,11 +2442,26 @@ public boolean isWhitelisted(ItemStack is) {
return false;
}

public static void runReflectionChecks() {
try {
craftingStoreInventoryHolder = Class.forName("net.craftingstore.bukkit.inventory.CraftingStoreInventoryHolder");
LOGGER.info("CraftingStore plugin detected! IllegalStack will now be able to detect and handle CraftingStore inventories.");
} catch (ClassNotFoundException e) {
craftingStoreInventoryHolder = null;
}
}

public boolean isThirdPartyInventory(InventoryView inv) {

if (IllegalStack.getPlugin().getServer().getPluginManager().getPlugin("CraftingStore") != null) {
if (inv.getTopInventory().getHolder() instanceof CraftingStoreInventoryHolder) {
if (craftingStoreInventoryHolder == null) {
return false;
}
InventoryHolder holder = inv.getTopInventory().getHolder();
if (holder == null) {
return false;
}
if (inv.getTopInventory().getHolder().getClass() == craftingStoreInventoryHolder) {
return true;
}

Expand Down
59 changes: 59 additions & 0 deletions src/main/java/main/java/me/dniym/enums/ServerVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package main.java.me.dniym.enums;

public enum ServerVersion {

v1_8_R1,
v1_8_R2,
v1_8_R3,
v1_9_R1,
v1_9_R2,
v1_10_R1,
v1_11_R1,
v1_12_R1,
v1_13_R1,
v1_13_R2,
v1_14_R1,
v1_15_R1,
v1_16_R1,
v1_16_R2,
v1_16_R3,
v1_17_R1,
v1_18_R1,
v1_18_R2,
v1_19_R1,
v1_19_R2,
v1_19_R3,
v1_20_R1,
v1_20_R2,
v1_20_R3,
v1_20_R4;

public boolean serverVersionEqual(ServerVersion version) {
return this.equals(version);
}

public boolean serverVersionGreaterThanOrEqual(ServerVersion version) {
return this.ordinal() >= version.ordinal();
}


public boolean serverVersionGreaterThan(ServerVersion version1, ServerVersion version2) {
return version1.ordinal() > version2.ordinal();
}

public boolean serverVersionLessThan(ServerVersion version1, ServerVersion version2) {
return version1.ordinal() < version2.ordinal();
}

public String getServerVersionName() {
return this.name();
}

public int getOrdinalServerVersionNumber() {
return this.ordinal();
}

public int getServerMajorVersionNumber() {
return Integer.parseInt(this.name().split("_")[1]);
}
}
7 changes: 4 additions & 3 deletions src/main/java/main/java/me/dniym/timers/fTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import main.java.me.dniym.checks.BadPotionCheck;
import main.java.me.dniym.enums.Msg;
import main.java.me.dniym.enums.Protections;
import main.java.me.dniym.enums.ServerVersion;
import main.java.me.dniym.listeners.fListener;
import main.java.me.dniym.listeners.mcMMOListener;
import main.java.me.dniym.util.TrackedProjectile;
Expand Down Expand Up @@ -81,8 +82,7 @@ public fTimer(IllegalStack illegalStack) {
}


String version = plugin.getServer().getClass().getPackage().getName().replace(".", ",")
.split(",")[3];
String version = IllegalStack.getVersion();
is1_8 = version.equalsIgnoreCase("v1_8_R3") || version.contains("v1_8");

if (is1_8) {
Expand Down Expand Up @@ -123,7 +123,8 @@ public static void setPunish(HashMap<Player, Entity> punish) {
@Override
public void run() {

if (!IllegalStack.isIsHybridEnvironment()) {
if (!IllegalStack.isIsHybridEnvironment() && IllegalStack.isPaperServer()
&& IllegalStack.getMajorServerVersion() >= 16) {
if (IllegalStack.isDisable() || Bukkit.getServer().isStopping()) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/main/java/me/dniym/timers/sTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import main.java.me.dniym.IllegalStack;
import main.java.me.dniym.enums.Msg;
import main.java.me.dniym.enums.Protections;
import main.java.me.dniym.enums.ServerVersion;
import main.java.me.dniym.listeners.fListener;
import main.java.me.dniym.utils.Scheduler;
import net.md_5.bungee.api.ChatColor;
Expand Down Expand Up @@ -65,7 +66,8 @@ public static void checkChunk(String chunkID, BlockState[] tileEntities) {
@Override
public void run() {

if (!IllegalStack.isIsHybridEnvironment()) {
if (!IllegalStack.isIsHybridEnvironment() && IllegalStack.isPaperServer()
&& IllegalStack.getMajorServerVersion() >= 16) {
if (IllegalStack.isDisable() || Bukkit.getServer().isStopping()) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/main/java/me/dniym/timers/syncTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public syncTimer(IllegalStack illegalStack) {
@Override
public void run() {

if (!IllegalStack.isIsHybridEnvironment()) {
if (!IllegalStack.isIsHybridEnvironment() && IllegalStack.isPaperServer()
&& IllegalStack.getMajorServerVersion() >= 16) {
if (IllegalStack.isDisable() || Bukkit.getServer().isStopping()) {
return;
}
Expand Down

0 comments on commit a3b1767

Please sign in to comment.