SteamWar/BauSystem2.0
Archiviert
12
0
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
BauSystem2.0/BauSystem_API/src/de/steamwar/bausystem/SWUtils.java
yoyosource 06e4c5cf3f
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful
Add StopCommand
Add RestartCommand
Fix KillAllCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
2021-12-18 14:46:08 +01:00

82 Zeilen
2.8 KiB
Java

/*
* 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;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.UtilityClass;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import java.util.function.Function;
@UtilityClass
public class SWUtils {
@Getter
@Setter
private static Plugin bausystem;
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);
}
}
public static void sendToActionbar(Player p, String message) {
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
}
public static void actionBar(Function<Player, String> message) {
Bukkit.getOnlinePlayers().forEach(player -> {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message.apply(player)));
});
}
public static void message(Function<Player, String> message) {
Bukkit.getOnlinePlayers().forEach(player -> {
player.sendMessage(message.apply(player));
});
}
public static NamespacedKey getNamespaceKey(String name) {
return new NamespacedKey(getBausystem(), name);
}
}