don't bind meteoric

This commit is contained in:
okx-code
2024-11-17 22:12:05 +00:00
parent a65378e832
commit 388655ef86
4 changed files with 119 additions and 16 deletions

View File

@@ -0,0 +1,83 @@
package net.civmc.heliodor.meteoriciron;
import javax.annotation.Nullable;
import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.CustomRecipe;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
import net.minecraft.world.level.Level;
import org.bukkit.NamespacedKey;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import vg.civcraft.mc.civmodcore.inventory.CustomItem;
public class BindRecipe extends CustomRecipe {
private final static RecipeSerializer<BindRecipe> SERIALIZER = RecipeSerializer.register("crafting_special_allow_bind", new SimpleCraftingRecipeSerializer<>(BindRecipe::new));
public BindRecipe(CraftingBookCategory category) {
super(category);
}
@Nullable
private ItemStack getTool(CraftingInput input) {
ItemStack tool = null;
ItemStack nugget = null;
for (int i = 0; i < input.size(); i++) {
ItemStack test = input.getItem(i);
if (!test.isEmpty()) {
if (CustomItem.isCustomItem(test.getBukkitStack(), "meteoric_iron_nugget") && test.getCount() == 1) {
if (nugget == null) {
nugget = test;
} else {
return null;
}
} else if (test.getBukkitStack().getPersistentDataContainer().has(new NamespacedKey("simpleadminhacks", "no_bind")) &&
test.getBukkitStack().getPersistentDataContainer().has(new NamespacedKey("heliodor", "meteoric_unbindable"))) {
if (tool == null) {
tool = test;
} else {
return null;
}
} else {
return null;
}
}
}
return tool != null && nugget != null ? tool : null;
}
@Override
public boolean matches(CraftingInput input, Level world) {
return this.getTool(input) != null;
}
@Override
public ItemStack assemble(CraftingInput input, HolderLookup.Provider lookup) {
ItemStack tool = this.getTool(input);
if (tool == null) {
return ItemStack.EMPTY;
} else {
org.bukkit.inventory.ItemStack copy = tool.asBukkitCopy();
ItemMeta meta = copy.getItemMeta();
meta.getPersistentDataContainer().remove(new NamespacedKey("heliodor", "meteoric_unbindable"));
meta.getPersistentDataContainer().remove(new NamespacedKey("simpleadminhacks", "no_bind"));
copy.setItemMeta(meta);
return ((CraftItemStack) copy).handle;
}
}
@Override
public boolean canCraftInDimensions(int width, int height) {
return width * height >= 2;
}
@Override
public RecipeSerializer<?> getSerializer() {
return SERIALIZER;
}
}

View File

@@ -12,10 +12,12 @@ import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.craftbukkit.inventory.CraftComplexRecipe;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemRarity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
@@ -30,7 +32,7 @@ public interface MeteoricIronArmour {
int CHESPLATE_DURABILITY = 9648;
static ItemStack createHelmet() {
static ItemStack createHelmet(boolean bind) {
ItemStack item = new ItemStack(Material.IRON_HELMET);
Damageable meta = (Damageable) item.getItemMeta();
@@ -45,12 +47,16 @@ public interface MeteoricIronArmour {
meta.setFireResistant(true);
setAttributes(meta, 3, 2, 0.03, "helmet", EquipmentSlotGroup.HEAD);
AnvilRepairListener.setNoCombine(meta);
if (bind) {
meta.getPersistentDataContainer().set(new NamespacedKey("simpleadminhacks", "no_bind"), PersistentDataType.BOOLEAN, true);
meta.getPersistentDataContainer().set(new NamespacedKey("heliodor", "meteoric_unbindable"), PersistentDataType.BOOLEAN, true);
}
item.setItemMeta(meta);
CustomItem.registerCustomItem("meteoric_iron_helmet", item);
CustomItem.registerCustomItem(bind ? "meteoric_iron_helmet_bound" : "meteoric_iron_helmet", item);
return item;
}
static ItemStack createChestplate() {
static ItemStack createChestplate(boolean bind) {
ItemStack item = new ItemStack(Material.IRON_CHESTPLATE);
Damageable meta = (Damageable) item.getItemMeta();
@@ -63,12 +69,16 @@ public interface MeteoricIronArmour {
meta.setFireResistant(true);
setAttributes(meta, 8, 2, 0.03, "chestplate", EquipmentSlotGroup.CHEST);
AnvilRepairListener.setNoCombine(meta);
if (bind) {
meta.getPersistentDataContainer().set(new NamespacedKey("simpleadminhacks", "no_bind"), PersistentDataType.BOOLEAN, true);
meta.getPersistentDataContainer().set(new NamespacedKey("heliodor", "meteoric_unbindable"), PersistentDataType.BOOLEAN, true);
}
item.setItemMeta(meta);
CustomItem.registerCustomItem("meteoric_iron_chestplate", item);
CustomItem.registerCustomItem(bind ? "meteoric_iron_chestplate_bound" : "meteoric_iron_chestplate", item);
return item;
}
static ItemStack createLeggings() {
static ItemStack createLeggings(boolean bind) {
ItemStack item = new ItemStack(Material.IRON_LEGGINGS);
Damageable meta = (Damageable) item.getItemMeta();
@@ -82,12 +92,16 @@ public interface MeteoricIronArmour {
meta.setFireResistant(true);
setAttributes(meta, 6, 2, 0.03, "leggings", EquipmentSlotGroup.LEGS);
AnvilRepairListener.setNoCombine(meta);
if (bind) {
meta.getPersistentDataContainer().set(new NamespacedKey("simpleadminhacks", "no_bind"), PersistentDataType.BOOLEAN, true);
meta.getPersistentDataContainer().set(new NamespacedKey("heliodor", "meteoric_unbindable"), PersistentDataType.BOOLEAN, true);
}
item.setItemMeta(meta);
CustomItem.registerCustomItem("meteoric_iron_leggings", item);
CustomItem.registerCustomItem(bind ? "meteoric_iron_leggings_bound" : "meteoric_iron_leggings", item);
return item;
}
static ItemStack createBoots() {
static ItemStack createBoots(boolean bind) {
ItemStack item = new ItemStack(Material.IRON_BOOTS);
Damageable meta = (Damageable) item.getItemMeta();
@@ -102,8 +116,12 @@ public interface MeteoricIronArmour {
meta.setFireResistant(true);
setAttributes(meta, 3, 2, 0.03, "boots", EquipmentSlotGroup.FEET);
AnvilRepairListener.setNoCombine(meta);
if (bind) {
meta.getPersistentDataContainer().set(new NamespacedKey("simpleadminhacks", "no_bind"), PersistentDataType.BOOLEAN, true);
meta.getPersistentDataContainer().set(new NamespacedKey("heliodor", "meteoric_unbindable"), PersistentDataType.BOOLEAN, true);
}
item.setItemMeta(meta);
CustomItem.registerCustomItem("meteoric_iron_boots", item);
CustomItem.registerCustomItem(bind ? "meteoric_iron_boots_bound" : "meteoric_iron_boots", item);
return item;
}
@@ -117,18 +135,18 @@ public interface MeteoricIronArmour {
meta.setAttributeModifiers(ams);
}
static List<ShapedRecipe> getRecipes(Plugin plugin) {
static List<Recipe> getRecipes(Plugin plugin) {
return List.of(
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_helmet"), MeteoricIronArmour.createHelmet())
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_helmet"), MeteoricIronArmour.createHelmet(false))
.shape("xxx", "x x")
.setIngredient('x', MeteoricIron.createIngot())),
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_chestplate"), MeteoricIronArmour.createChestplate())
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_chestplate"), MeteoricIronArmour.createChestplate(false))
.shape("x x", "xxx", "xxx")
.setIngredient('x', MeteoricIron.createIngot())),
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_leggings"), MeteoricIronArmour.createLeggings())
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_leggings"), MeteoricIronArmour.createLeggings(false))
.shape("xxx", "x x", "x x")
.setIngredient('x', MeteoricIron.createIngot())),
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_boots"), MeteoricIronArmour.createBoots())
categoryEquipment(new ShapedRecipe(new NamespacedKey(plugin, "meteoric_iron_boots"), MeteoricIronArmour.createBoots(false))
.shape("x x", "x x")
.setIngredient('x', MeteoricIron.createIngot())));
}

View File

@@ -31,7 +31,7 @@ public class SqlVeinDao implements VeinDao {
CREATE TABLE IF NOT EXISTS veins (
id INT NOT NULL AUTO_INCREMENT,
type VARCHAR(64) NOT NULL,
spawned_at TIMESTAMP NOT NULL,
spawned_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(),
world VARCHAR(64) NOT NULL,
radius INT NOT NULL,
x INT NOT NULL,

View File

@@ -31,6 +31,7 @@ public class ArmourBound extends BasicHack {
private SimpleAdminHacks plugin;
private NamespacedKey key;
private NamespacedKey noBindKey;
@AutoLoad
private List<String> whitelist;
@@ -38,6 +39,7 @@ public class ArmourBound extends BasicHack {
super(plugin, config);
this.plugin = plugin;
this.key = new NamespacedKey(plugin, "SAH_ArmourBound");
this.noBindKey = new NamespacedKey(plugin, "no_bind");
}
@EventHandler
@@ -56,7 +58,7 @@ public class ArmourBound extends BasicHack {
}
//From here, we take over from the copy, get the actual itemstack ourselves
newItem = player.getInventory().getItem(realSlot);
if (!whitelist.contains(newItem.getType().toString())) {
if (!whitelist.contains(newItem.getType().toString()) || newItem.getPersistentDataContainer().has(noBindKey)) {
return;
}
ItemMeta meta = newItem.getItemMeta();
@@ -92,7 +94,7 @@ public class ArmourBound extends BasicHack {
if (item == null) {
continue;
}
if (!whitelist.contains(item.getType().toString())) {
if (!whitelist.contains(item.getType().toString()) || item.getPersistentDataContainer().has(noBindKey)) {
continue;
}
meta = item.getItemMeta();