tokens update

This commit is contained in:
hyperdefined
2025-01-25 16:56:03 -05:00
parent ff578e170e
commit 30b26533ef
21 changed files with 1705 additions and 531 deletions

View File

@@ -0,0 +1,61 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
public class PrepareCraft implements Listener {
private final ToolStats toolStats;
public PrepareCraft(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onCraft(PrepareItemCraftEvent event) {
// get the items in the crafting grid
ItemStack[] grid = event.getInventory().getMatrix();
for (ItemStack item : grid) {
if (item == null || item.getType() != Material.PAPER) {
continue;
}
toolStats.logger.info(item.getType().toString());
ItemMeta meta = item.getItemMeta();
if (meta == null) {
continue;
}
// if the paper item has our PDC, cancel it
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(toolStats.tokenType)) {
toolStats.logger.info("has PDC");
event.getInventory().setResult(null);
} else {
toolStats.logger.info("no PDC");
}
}
}
}