Skip to content
Open
10 changes: 7 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
maven("https://repo.thbn.me/releases/")
maven("https://repo.thbn.me/snapshots/")
maven("https://repo.tehbrian.dev/snapshots/")
maven("https://repo.codemc.io/repository/maven-public/")
maven("https://repo.broccol.ai/snapshots/")
}

dependencies {
Expand All @@ -34,7 +36,8 @@ dependencies {
implementation("com.google.inject:guice:7.0.0")
implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("dev.tehbrian:tehlib-paper:0.6.0")
implementation("dev.tehbrian.restrictionhelper:restrictionhelper-spigot:0.4.1")
implementation("dev.tehbrian:restrictionhelper-spigot:0.5.0")
implementation("de.tr7zw:item-nbt-api:2.15.0")
}

tasks {
Expand Down Expand Up @@ -67,7 +70,7 @@ tasks {
"love.broccolai.corn",
"cloud.commandframework",
"com.google",
"dev.tehbrian.restrictionhelper",
"dev.tehbrian.restrictionhelper-spigot",
"dev.tehbrian.tehlib",
"io.leangen",
"jakarta.inject",
Expand All @@ -77,6 +80,7 @@ tasks {
"org.checkerframework",
"org.spongepowered",
"org.yaml",
"de.tr7zw.changeme.nbtapi"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.google.inject.Inject;
import com.google.inject.name.Named;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
import dev.tehbrian.tehlib.configurate.AbstractConfig;
import org.bukkit.Material;
import org.bukkit.block.data.type.Light;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockDataMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.spongepowered.configurate.CommentedConfigurationNode;
Expand All @@ -15,7 +15,6 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public final class SpecialConfig extends AbstractConfig<YamlConfigurateWrapper> {

Expand Down Expand Up @@ -43,55 +42,48 @@ public void load() throws ConfigurateException {
}

for (final String dirtyItemName : itemNames) {
final var itemName = dirtyItemName.strip().toUpperCase(Locale.ROOT);

// special case for light levels.
if (itemName.startsWith("LIGHT") && !itemName.equals("LIGHT")) {
int level;
try {
level = Integer.parseInt(itemName.split("-")[1]);
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
this.logger.warn("Invalid light data {}.", itemName);
this.logger.warn("Skipping this item. Please check your {}", fileName);
this.logger.warn("Printing stack trace:", e);
continue;
}

if (level > 15) {
level = 15;
}
if (level < 0) {
level = 0;
}

// create a light item with that light level.
final ItemStack item = new ItemStack(Material.LIGHT);
final BlockDataMeta meta = (BlockDataMeta) item.getItemMeta();
final Light data = (Light) Material.LIGHT.createBlockData();
data.setLevel(level);
meta.setBlockData(data);
item.setItemMeta(meta);

final String configItem = dirtyItemName.strip();
ItemStack item = this.itemFromString(configItem, fileName);
if (item != null) {
this.items.add(item);
continue;
}

final Material itemMaterial;
try {
itemMaterial = Material.valueOf(itemName);
} catch (final IllegalArgumentException e) {
this.logger.warn("The material {} does not exist.", itemName);
this.logger.warn("Skipping this item. Please check your {}", fileName);
this.logger.warn("Printing stack trace:", e);
continue;
}

this.items.add(new ItemStack(itemMaterial));
}
}

public List<ItemStack> items() {
return this.items;
}

/**
* This method return the ItemStack object based on the configuration following
* the syntax '%Material name%, %JSON values%'.
* @param configItem The item string
* @param fileName The name of the configuration file for logging purposes
* @return The ItemStack object or null if the item is invalid
*/
private @Nullable ItemStack itemFromString(String configItem, String fileName) {
try {
String[] itemData = configItem.strip().split(", ", 2);
Material material = Material.valueOf(itemData[0].toUpperCase());
ItemStack item = new ItemStack(material);

if (itemData.length > 1 && !itemData[1].isBlank()) {
try {
ReadableNBT itemNBT = NBT.parseNBT(itemData[1]);
NBT.modifyComponents(item, nbt -> {
nbt.mergeCompound(itemNBT);
});
} catch (Exception e) {
this.logger.warn("Invalid NBT data for item {}: {}", material, itemData[1], e);
return null;
}
}
return item;
} catch (IllegalArgumentException e) {
this.logger.warn("The material {} does not exist.", configItem);
this.logger.warn("Skipping this item. Please check your {}", fileName);
this.logger.warn("Printing stack trace:", e);
return null;
}
}
}
Empty file.
35 changes: 19 additions & 16 deletions src/main/resources/special.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ items:
- STRUCTURE_VOID
- BARRIER
- DEBUG_STICK
- LIGHT-15
- LIGHT-14
- LIGHT-13
- LIGHT-12
- LIGHT-11
- LIGHT-10
- LIGHT-9
- LIGHT-8
- LIGHT-7
- LIGHT-6
- LIGHT-5
- LIGHT-4
- LIGHT-3
- LIGHT-2
- LIGHT-1
- LIGHT-0
- 'LIGHT, {"minecraft:block_state": {level: "15"}}'
- 'LIGHT, {"minecraft:block_state": {level: "14"}} '
- 'LIGHT, {"minecraft:block_state": {level: "13"}}'
- 'LIGHT, {"minecraft:block_state": {level: "12"}}'
- 'LIGHT, {"minecraft:block_state": {level: "11"}}'
- 'LIGHT, {"minecraft:block_state": {level: "10"}}'
- 'LIGHT, {"minecraft:block_state": {level: "9"}}'
- 'LIGHT, {"minecraft:block_state": {level: "8"}}'
- 'LIGHT, {"minecraft:block_state": {level: "7"}}'
- 'LIGHT, {"minecraft:block_state": {level: "6"}}'
- 'LIGHT, {"minecraft:block_state": {level: "5"}}'
- 'LIGHT, {"minecraft:block_state": {level: "4"}}'
- 'LIGHT, {"minecraft:block_state": {level: "3"}}'
- 'LIGHT, {"minecraft:block_state": {level: "2"}}'
- 'LIGHT, {"minecraft:block_state": {level: "1"}}'
- 'LIGHT, {"minecraft:block_state": {level: "0"}}'

# Items below are not in the operator items menu.
- KNOWLEDGE_BOOK
Expand All @@ -45,5 +45,8 @@ items:
- TIPPED_ARROW
- PETRIFIED_OAK_SLAB

# Normal items with special NBT
- 'ITEM_FRAME, {"minecraft:entity_data": {id: "minecraft:item_frame", Invisible: 1b}, "minecraft:item_name":''{text:"Invisible Item Frame"}''}'

# No touch!
version: 1
Copy link
Copy Markdown

@RedstoneFuture RedstoneFuture Jun 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the version need to be incremented? (Tbd.)