Skip to content

Commit

Permalink
Merge pull request #189 from dniym/fix/hybrid-environment-checks
Browse files Browse the repository at this point in the history
Added startup checks to look for Hybrid server environment
  • Loading branch information
dniym authored Mar 17, 2024
2 parents 9a9f190 + 0317ba5 commit 119ce00
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 142 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repositories {
}

dependencies {
compileOnly("dev.folia:folia-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT")
compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0")
compileOnly("com.elmakers.mine.bukkit:MagicAPI:10.2")
compileOnly("de.tr7zw:item-nbt-api-plugin:2.8.0")
Expand All @@ -66,7 +66,7 @@ tasks.compileJava.configure {
options.release.set(8)
}

version = "2.9.9"
version = "2.9.10-SNAPSHOT-01"

tasks.named<Copy>("processResources") {
filesMatching("plugin.yml") {
Expand Down
150 changes: 103 additions & 47 deletions src/main/java/main/java/me/dniym/IllegalStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class IllegalStack extends JavaPlugin {

private static IllegalStack plugin;
private static Plugin ProCosmetics = null;
private static boolean isHybridEnvironment = false;
private static boolean hasProtocolLib = false;
private static boolean hasAttribAPI = false;
private static boolean nbtAPI = false;
Expand Down Expand Up @@ -82,6 +83,10 @@ public void setPlugin(IllegalStack plugin) {
IllegalStack.plugin = plugin;
}

public static boolean isIsHybridEnvironment() {
return isHybridEnvironment;
}

public static boolean isSpigot() {
return Spigot;
}
Expand All @@ -106,7 +111,44 @@ public static void ReloadConfig(Boolean wasCommand) {

}

private static void checkForHybridEnvironment() {
try {
Class.forName("io.izzel.arclight.i18n.ArclightConfig");
isHybridEnvironment = true;
LOGGER.info("Server is an ArcLight hybrid environment, enabling hybrid scheduler checks.");
} catch (ClassNotFoundException e) {
isHybridEnvironment = false;
LOGGER.info("Server is NOT an ArcLight hybrid environment, continuing as normal.");
}

if (!isIsHybridEnvironment()) {
try {
Class.forName("net.minecraftforge.fml.ModList");
isHybridEnvironment = true;
LOGGER.info("Server is a Forge hybrid environment, enabling hybrid scheduler checks.");

} catch (ClassNotFoundException e) {
isHybridEnvironment = false;
LOGGER.info("Server is NOT a Forge hybrid environment, continuing as normal.");
}
}

if (!isIsHybridEnvironment()) {
try {
Class.forName("net.fabricmc.loader.api.FabricLoader");
isHybridEnvironment = true;
LOGGER.info("Server is a Fabric hybrid environment, enabling hybrid scheduler checks.");
} catch (ClassNotFoundException e) {
isHybridEnvironment = false;
LOGGER.info("Server is NOT a Fabric hybrid environment, continuing as normal.");
}
}
}

private static void StartupPlugin() {

checkForHybridEnvironment();

try {
Class.forName("org.spigotmc.SpigotConfig");
Spigot = true;
Expand All @@ -116,13 +158,13 @@ private static void StartupPlugin() {
}

if (plugin.getServer().getPluginManager().getPlugin("Logblock") != null) {
File conf = new File(Bukkit.getPluginManager().getPlugin("Logblock").getDataFolder(), "config.yml");
final FileConfiguration lbconfig = YamlConfiguration.loadConfiguration(conf);
if(lbconfig != null) {
setLbBlock(Material.matchMaterial(lbconfig.getString("tools.toolblock.item")));
LOGGER.info("Logblock plugin found, if blacklisted the toolblock item: " + getLbBlock().name() + " will not be removed.");
}
File conf = new File(Bukkit.getPluginManager().getPlugin("Logblock").getDataFolder(), "config.yml");
final FileConfiguration lbconfig = YamlConfiguration.loadConfiguration(conf);

if (lbconfig != null) {
setLbBlock(Material.matchMaterial(lbconfig.getString("tools.toolblock.item")));
LOGGER.info("Logblock plugin found, if blacklisted the toolblock item: " + getLbBlock().name() + " will not be removed.");
}
}
if (plugin.getServer().getPluginManager().getPlugin("CMI") != null) {
CMI = true;
Expand All @@ -149,8 +191,9 @@ private static void StartupPlugin() {
if (plugin.ScanTimer != null) {
plugin.ScanTimer.cancel();
}
if (plugin.syncTimer != null)
plugin.syncTimer.cancel();
if (plugin.syncTimer != null) {
plugin.syncTimer.cancel();
}
}


Expand Down Expand Up @@ -322,8 +365,9 @@ public static boolean hasIds() {
}

public static boolean hasAsyncScheduler() {
return hasAsyncScheduler;
return hasAsyncScheduler;
}

public static boolean hasShulkers() {
return hasShulkers;
}
Expand Down Expand Up @@ -357,14 +401,15 @@ public void onEnable() {
loadConfig();
updateConfig();
loadMsgs();
checkForHybridEnvironment();
IllegalStackCommand illegalStackCommand = new IllegalStackCommand();
this.getCommand("istack").setExecutor(illegalStackCommand);
this.getCommand("istack").setTabCompleter(illegalStackCommand);


ProCosmetics = this.getServer().getPluginManager().getPlugin("ProCosmetics");


if (this.getServer().getPluginManager().getPlugin("EpicRename") != null) {
EpicRename = true;
}
Expand Down Expand Up @@ -437,13 +482,13 @@ public void onEnable() {
}

if (plugin.getServer().getPluginManager().getPlugin("Logblock") != null) {
File conf = new File(Bukkit.getPluginManager().getPlugin("Logblock").getDataFolder(), "config.yml");
final FileConfiguration lbconfig = YamlConfiguration.loadConfiguration(conf);
if(lbconfig != null) {
setLbBlock(Material.matchMaterial(lbconfig.getString("tools.toolblock.item")));
LOGGER.info("Logblock plugin found, if blacklisted the toolblock item: " + getLbBlock().name() + " will not be removed.");
}
File conf = new File(Bukkit.getPluginManager().getPlugin("Logblock").getDataFolder(), "config.yml");
final FileConfiguration lbconfig = YamlConfiguration.loadConfiguration(conf);

if (lbconfig != null) {
setLbBlock(Material.matchMaterial(lbconfig.getString("tools.toolblock.item")));
LOGGER.info("Logblock plugin found, if blacklisted the toolblock item: " + getLbBlock().name() + " will not be removed.");
}
}

if (this.getServer().getPluginManager().getPlugin("CMI") != null) {
Expand Down Expand Up @@ -490,7 +535,7 @@ public void onEnable() {
Protections.ItemScanTimer.getIntValue()
);
syncTimer = Scheduler.runTaskTimer(this, new syncTimer(this), 10, 10);

}

if (Protections.RemoveBooksNotMatchingCharset.isEnabled() && !fListener.getInstance().is113() && !fListener.is18()) {
Expand Down Expand Up @@ -599,13 +644,14 @@ private void setHasContainers() {
}

private void setHasAsyncScheduler() {
try {
Class.forName("org.bukkit.Server.getAsyncScheduler");
hasAsyncScheduler = true;
} catch (ClassNotFoundException ignored) {
}
try {
Class.forName("org.bukkit.Server.getAsyncScheduler");
hasAsyncScheduler = true;
} catch (ClassNotFoundException ignored) {

}
}

private void setHasChestedAnimals() {

try {
Expand Down Expand Up @@ -728,7 +774,11 @@ private void loadMsgs() {
boolean update = false;
for (Msg m : Msg.values()) {
if (fc.getString(m.name()) == null) {
LOGGER.info(" {} Was missing from messages.yml, adding it with the default value {}", m.name(), m.getConfigVal());
LOGGER.info(
" {} Was missing from messages.yml, adding it with the default value {}",
m.name(),
m.getConfigVal()
);
fc.set(m.name(), m.getConfigVal());
update = true;

Expand Down Expand Up @@ -830,7 +880,10 @@ private void loadConfig() {
}

if (whitelisted.length() > 0) {
LOGGER.warn("WARNING: IllegalStack will NOT block but instead, will notify for the following exploits: {}", whitelisted);
LOGGER.warn(
"WARNING: IllegalStack will NOT block but instead, will notify for the following exploits: {}",
whitelisted
);
}

whitelisted = new StringBuilder();
Expand Down Expand Up @@ -932,18 +985,18 @@ private void loadConfig() {
}
}

private static boolean disable=false;
private static boolean disable = false;

public static boolean isDisable() {
return disable;
}

@Override
public void onDisable() {
disable=true;
if(hasAsyncScheduler) {
disable = true;
if (hasAsyncScheduler) {
getServer().getAsyncScheduler().cancelTasks(this);
}else {
} else {
Bukkit.getScheduler().cancelTasks(this);
}

Expand All @@ -969,14 +1022,17 @@ private void writeConfig() {
if (relevant.get(p)) //relevant to this version, check if it exists.
{
if (config.getString(p.getConfigPath()) == null) {

if(p == Protections.RemoveOverstackedItems && this.getServer().getPluginManager().getPlugin("StackableItems") != null) {
config.set(p.getConfigPath(), false);
LOGGER.warn("The StackableItems plugin has been detected on your server, The protection RemoveOverstackedItems has been automatically disabled to prevent item loss, enabling this protection will most definitely remove items as this plugin is known to break the vanilla stack limits.");
p.setEnabled(false);
} else
config.set(p.getConfigPath(), p.getDefaultValue());


if (p == Protections.RemoveOverstackedItems && this.getServer().getPluginManager().getPlugin(
"StackableItems") != null) {
config.set(p.getConfigPath(), false);
LOGGER.warn(
"The StackableItems plugin has been detected on your server, The protection RemoveOverstackedItems has been automatically disabled to prevent item loss, enabling this protection will most definitely remove items as this plugin is known to break the vanilla stack limits.");
p.setEnabled(false);
} else {
config.set(p.getConfigPath(), p.getDefaultValue());
}

LOGGER.warn(
"Found a missing protection from your configuration: {} it has been added with a default value of: {}",
p.name(),
Expand Down Expand Up @@ -1033,12 +1089,12 @@ private void setVersion() {
IllegalStack.version = version;
}

public static Material getLbBlock() {
return lbBlock;
}
public static Material getLbBlock() {
return lbBlock;
}

public static void setLbBlock(Material lbBlock) {
IllegalStack.lbBlock = lbBlock;
}
public static void setLbBlock(Material lbBlock) {
IllegalStack.lbBlock = lbBlock;
}

}
Loading

0 comments on commit 119ce00

Please sign in to comment.