2021-04-17 15:21:40 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2021-04-18 13:58:02 +02:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2021-04-17 15:21:40 +02:00
|
|
|
import lombok.experimental.UtilityClass;
|
2021-04-17 15:53:07 +02:00
|
|
|
import net.md_5.bungee.api.ChatMessageType;
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
2021-04-17 15:21:40 +02:00
|
|
|
import org.bukkit.Material;
|
2021-04-18 13:58:02 +02:00
|
|
|
import org.bukkit.NamespacedKey;
|
2021-04-17 15:21:40 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2021-04-18 13:58:02 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2021-04-17 15:21:40 +02:00
|
|
|
|
|
|
|
@UtilityClass
|
|
|
|
public class SWUtils {
|
|
|
|
|
2021-04-18 13:58:02 +02:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private static Plugin bausystem;
|
|
|
|
|
2021-04-17 15:21:40 +02:00
|
|
|
public static void giveItemToPlayer(Player player, ItemStack itemStack) {
|
|
|
|
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < player.getInventory().getSize(); i++) {
|
|
|
|
ItemStack current = player.getInventory().getItem(i);
|
|
|
|
if (current != null && current.isSimilar(itemStack)) {
|
|
|
|
player.getInventory().setItem(i, null);
|
|
|
|
itemStack = current;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ItemStack current = player.getInventory().getItemInMainHand();
|
|
|
|
player.getInventory().setItemInMainHand(itemStack);
|
|
|
|
if (current.getType() != Material.AIR) {
|
|
|
|
player.getInventory().addItem(current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 15:53:07 +02:00
|
|
|
public static void sendToActionbar(Player p, String message) {
|
|
|
|
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
|
|
|
|
}
|
2021-04-18 13:58:02 +02:00
|
|
|
|
|
|
|
public static NamespacedKey getNamespaceKey(String name) {
|
|
|
|
return new NamespacedKey(getBausystem(), name);
|
|
|
|
}
|
2021-04-17 15:21:40 +02:00
|
|
|
}
|