Fix AutoCrafting in Spigot 1.12.2

Back in the ol' days... There were no such thing as `Material.BIRCH_PLANKS`. And that caused a NoSuchMethodError. As simple as that ^^
This commit is contained in:
Christian Koop 2020-05-23 21:30:37 +02:00 committed by Brianna
parent c8cec714b7
commit 8d360eb886
3 changed files with 36 additions and 23 deletions

View File

@ -324,7 +324,7 @@ public class ModuleAutoCrafting extends Module {
}
public void addRecipes(Collection<Recipe> recipes) {
recipes.forEach(recipe -> this.addRecipe(recipe));
recipes.forEach(this::addRecipe);
}
public boolean hasRecipes() {
@ -347,7 +347,12 @@ public class ModuleAutoCrafting extends Module {
for (int i = 0; i < recipe.getIngredientList().size(); i++) {
ItemStack item = recipe.getIngredientList().get(i);
RecipeChoice rChoice = recipe.getChoiceList().get(i);
RecipeChoice rChoice = null;
try {
rChoice = recipe.getChoiceList().get(i);
} catch (NoSuchMethodError ignore) { // Method missing in Spigot 1.12.2
}
processIngredient(ingredients, item, rChoice);
}
@ -362,7 +367,12 @@ public class ModuleAutoCrafting extends Module {
for (Map.Entry<Character, ItemStack> entry : recipe.getIngredientMap().entrySet()) {
ItemStack item = entry.getValue();
RecipeChoice rChoice = recipe.getChoiceMap().get(entry.getKey());
RecipeChoice rChoice = null;
try {
rChoice = recipe.getChoiceMap().get(entry.getKey());
} catch (NoSuchMethodError ignore) { // Method missing in Spigot 1.12.2
}
if (item == null) continue;

View File

@ -62,7 +62,6 @@ public class HopTask extends BukkitRunnable {
public void run() {
Set<Location> toRemove = new HashSet<>();
main:
for (final com.songoda.epichoppers.hopper.Hopper hopper : plugin.getHopperManager().getHoppers().values()) {
try {
@ -108,13 +107,17 @@ public class HopTask extends BukkitRunnable {
hopper.getLevel().getRegisteredModules().stream()
.filter(Objects::nonNull)
.forEach(module -> {
// Run Module
module.run(hopper, hopperCache);
try {
// Run Module
module.run(hopper, hopperCache);
// Add banned materials to list.
List<Material> materials = module.getBlockedItems(hopper);
if (materials != null && !materials.isEmpty())
blockedMaterials.addAll(materials);
// Add banned materials to list.
List<Material> materials = module.getBlockedItems(hopper);
if (materials != null && !materials.isEmpty())
blockedMaterials.addAll(materials);
} catch (Throwable th) {
th.printStackTrace();
}
});
// Process extra hopper pull

View File

@ -2,15 +2,12 @@ package com.songoda.epichoppers.utils;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.epichoppers.EpicHoppers;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -30,7 +27,9 @@ public class Methods {
private static final Map<String, Location> serializeCache = new HashMap<>();
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ||
is1.getDurability() == Short.MAX_VALUE || is2.getDurability() == Short.MAX_VALUE) {
// Durability of Short.MAX_VALUE is used in recipes if the durability should be ignored
return is1.getType() == is2.getType();
} else {
return is1.getType() == is2.getType() && (is1.getDurability() == -1 || is2.getDurability() == -1 || is1.getDurability() == is2.getDurability());
@ -102,20 +101,20 @@ public class Methods {
}
public static String formatName(int level) {
EpicHoppers instance = EpicHoppers.getInstance();
String name = instance.getLocale().getMessage("general.nametag.nameformat")
.processPlaceholder("level", level).getMessage();
EpicHoppers instance = EpicHoppers.getInstance();
String name = instance.getLocale().getMessage("general.nametag.nameformat")
.processPlaceholder("level", level).getMessage();
return Methods.formatText(name);
return Methods.formatText(name);
}
public static void doParticles(Entity entity, Location location) {
EpicHoppers instance = EpicHoppers.getInstance();
location.setX(location.getX() + .5);
location.setY(location.getY() + .5);
location.setZ(location.getZ() + .5);
entity.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
EpicHoppers instance = EpicHoppers.getInstance();
location.setX(location.getX() + .5);
location.setY(location.getY() + .5);
location.setZ(location.getZ() + .5);
entity.getWorld().spawnParticle(org.bukkit.Particle.valueOf(instance.getConfig().getString("Main.Upgrade Particle Type")), location, 200, .5, .5, .5);
}
/**
@ -170,6 +169,7 @@ public class Methods {
serializeCache.put(cacheKey, location.clone());
return location;
}
public static String convertToInvisibleString(String s) {
if (s == null || s.equals(""))
return "";