A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy
blob: 2b1c9391b18586dc2ac7e0b45205fb5640dbce0f (2224 bytes)[doc][blame][raw]
1
package de.typable.minecrafthub.util;3
import org.bukkit.Bukkit;4
import org.bukkit.Material;5
import org.bukkit.entity.Player;6
import org.bukkit.inventory.Inventory;7
import org.bukkit.inventory.ItemStack;8
import org.bukkit.plugin.Plugin;10
import de.typable.minecrafthub.constant.DefaultConstants;11
import net.md_5.bungee.api.ChatColor;12
import net.md_5.bungee.api.ChatMessageType;13
import net.md_5.bungee.api.chat.TextComponent;16
public class Util17
{18
public static boolean isEmpty(ItemStack item)19
{20
return item == null || item.getType() == Material.AIR;21
}23
public static boolean isType(ItemStack item, Material type)24
{25
return !isEmpty(item) && item.getType() == type;26
}28
public static boolean compare(ItemStack item, ItemStack item2)29
{30
if(item == null || item2 == null)31
{32
return false;33
}35
if(item.getType() != item2.getType())36
{37
return false;38
}40
return true;41
}43
public static boolean isInventoryFull(Inventory inventory, ItemStack result)44
{45
for(ItemStack item : inventory.getContents())46
{47
if(Util.isEmpty(item))48
{49
return false;50
}52
if(result.isSimilar(item))53
{54
if(result.getAmount() + item.getAmount() <= item.getMaxStackSize())55
{56
return false;57
}58
}59
}61
return true;62
}64
public static boolean containsAtLeast(Inventory inventory, ItemStack item, int amount)65
{66
for(int i = 0; i < inventory.getSize(); i++)67
{68
ItemStack current = inventory.getItem(i);70
if(Util.compare(item, current))71
{72
amount -= current.getAmount();74
if(amount <= 0)75
{76
return true;77
}78
}79
}81
return false;82
}84
public static void sendActionMessage(Player player, String message)85
{86
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));87
}89
public static void sendCountdown(Plugin plugin, final String message, final int time, Runnable runnable)90
{91
Bukkit.getScheduler().runTaskTimer(plugin, new Runnable()92
{93
int count = time;95
@Override96
public void run()97
{98
if(count == 0)99
{100
runnable.run();101
return;102
}104
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + message + " " + count + " sec");106
count--;107
}108
}, 0L, DefaultConstants.TICK);109
}110
}