SteamWar/BauSystem2.0
Archiviert
12
0
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-05-24 11:20:08 +02:00
Ursprung d56263fa15
Commit 340233b558
2 geänderte Dateien mit 62 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,62 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.utils;
import de.steamwar.bausystem.SWUtils;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
@UtilityClass
public class ItemUtils {
private final NamespacedKey ITEM_KEY = SWUtils.getNamespaceKey("bau_item");
public boolean isItem(ItemStack itemStack, String tag) {
if (itemStack == null) {
return false;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return false;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
if (!container.has(ITEM_KEY, PersistentDataType.STRING)) {
return false;
}
return tag.equals(container.get(ITEM_KEY, PersistentDataType.STRING));
}
public void setItem(ItemStack itemStack, String tag) {
if (itemStack == null) {
return;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return;
}
meta.getPersistentDataContainer().set(ITEM_KEY, PersistentDataType.STRING, tag);
itemStack.setItemMeta(meta);
}
}