Skip to content

Commit

Permalink
checks for folia w/ barrels
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsinco committed Aug 27, 2024
1 parent 621942b commit 02b6891
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
11 changes: 10 additions & 1 deletion src/main/java/com/dre/brewery/Barrel.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* A Multi Block Barrel with Inventory
Expand Down Expand Up @@ -477,7 +478,15 @@ public boolean isLarge() {
* is this a Small barrel?
*/
public boolean isSmall() {
return LegacyUtil.isSign(spigot.getType());
if (!BreweryPlugin.isFolia()) {
return LegacyUtil.isSign(spigot.getType());
}


AtomicBoolean type = new AtomicBoolean(false);
BreweryPlugin.getScheduler().runTask(spigot.getLocation(),
() -> type.set(LegacyUtil.isSign(spigot.getType())));
return type.get();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/dre/brewery/BreweryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class BreweryPlugin extends JavaPlugin {
private static BreweryPlugin breweryPlugin;
private static MinecraftVersion minecraftVersion;
private static DataManager dataManager;
private static boolean isFolia = false;
public static boolean debug;
public static boolean useNBT;

Expand All @@ -105,6 +106,11 @@ public void onLoad() {
@Override
public void onEnable() {
migrateBreweryDataFolder();
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
isFolia = true;
} catch (ClassNotFoundException ignored) {
}


// MC 1.13 uses a different NBT API than the newer versions.
Expand Down Expand Up @@ -380,6 +386,10 @@ public static DataManager getDataManager() {
return dataManager;
}

public static boolean isFolia() {
return isFolia;
}

// Utility

public void msg(CommandSender sender, String msg) {
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/com/dre/brewery/api/addons/AddonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public AddonManager(BreweryPlugin plugin) {

public void unloadAddons() {
for (BreweryAddon addon : addons) {
addon.onAddonDisable();
try {
addon.onAddonDisable();
} catch (Throwable t) {
plugin.errorLog("Failed to disable addon " + addon.getClass().getSimpleName(), t);
}
}
int loaded = addons.size();
if (loaded > 0) plugin.log("Disabled " + loaded + " addon(s)");
Expand All @@ -46,7 +50,11 @@ public void unloadAddons() {

public void reloadAddons() {
for (BreweryAddon addon : addons) {
addon.onBreweryReload();
try {
addon.onBreweryReload();
} catch (Throwable t) {
plugin.errorLog("Failed to reload addon " + addon.getClass().getSimpleName(), t);
}
}
int loaded = addons.size();
if (loaded > 0) plugin.log("Reloaded " + loaded + " addon(s)");
Expand Down Expand Up @@ -113,7 +121,11 @@ public void loadAddons() {
}

for (BreweryAddon addon : addons) {
addon.onAddonEnable();
try {
addon.onAddonEnable();
} catch (Throwable t) {
plugin.errorLog("Failed to enable addon " + addon.getClass().getSimpleName(), t);
}
}
int loaded = addons.size();
if (loaded > 0) plugin.log("Loaded " + loaded + " addon(s)");
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/com/dre/brewery/utility/LegacyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,15 @@ public static byte getWoodType(Block wood) throws NoSuchFieldError, NoClassDefFo
return 0;
}

switch (woodType) {
case GENERIC:
return 2;
case REDWOOD:
return 4;
case BIRCH:
return 1;
case JUNGLE:
return 3;
case ACACIA:
return 5;
case DARK_OAK:
return 6;
default:
return 0;
}
return switch (woodType) {
case GENERIC -> 2;
case REDWOOD -> 4;
case BIRCH -> 1;
case JUNGLE -> 3;
case ACACIA -> 5;
case DARK_OAK -> 6;
default -> 0;
};
}
}

Expand Down

0 comments on commit 02b6891

Please sign in to comment.