mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-02-04 03:31:02 +00:00
57 lines
1.9 KiB
Java
57 lines
1.9 KiB
Java
/*
|
|
* 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.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) {
|
|
continue;
|
|
}
|
|
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.toolStatsKeys.getTokenType())) {
|
|
event.getInventory().setResult(null);
|
|
}
|
|
}
|
|
}
|
|
}
|