Add ItemUtils
Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
d56263fa15
Commit
340233b558
62
BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java
Normale Datei
62
BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java
Normale Datei
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
In neuem Issue referenzieren
Einen Benutzer sperren