A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy
blob: 55607cb88e3256b8442d02c03c23fe234fb0d7f1 (2925 bytes)[doc][blame][raw]
1
package de.typable.minecrafthub.util;3
import org.bukkit.Bukkit;4
import org.bukkit.Material;5
import org.bukkit.block.BlockFace;6
import org.bukkit.entity.Player;7
import org.bukkit.inventory.Inventory;8
import org.bukkit.inventory.ItemStack;9
import org.bukkit.plugin.Plugin;11
import de.typable.minecrafthub.constant.DefaultConstants;12
import net.md_5.bungee.api.ChatColor;13
import net.md_5.bungee.api.ChatMessageType;14
import net.md_5.bungee.api.chat.TextComponent;17
public class Util18
{19
public static boolean isEmpty(ItemStack item)20
{21
return item == null || item.getType() == Material.AIR;22
}24
public static boolean isType(ItemStack item, Material type)25
{26
return !isEmpty(item) && item.getType() == type;27
}29
public static boolean compare(ItemStack item, ItemStack item2)30
{31
if(item == null || item2 == null)32
{33
return false;34
}36
if(item.getType() != item2.getType())37
{38
return false;39
}41
return true;42
}44
public static boolean isInventoryFull(Inventory inventory, ItemStack result)45
{46
for(ItemStack item : inventory.getContents())47
{48
if(Util.isEmpty(item))49
{50
return false;51
}53
if(result.isSimilar(item))54
{55
if(result.getAmount() + item.getAmount() <= item.getMaxStackSize())56
{57
return false;58
}59
}60
}62
return true;63
}65
public static boolean containsAtLeast(Inventory inventory, ItemStack item, int amount)66
{67
for(int i = 0; i < inventory.getSize(); i++)68
{69
ItemStack current = inventory.getItem(i);71
if(Util.compare(item, current))72
{73
amount -= current.getAmount();75
if(amount <= 0)76
{77
return true;78
}79
}80
}82
return false;83
}85
public static void sendActionMessage(Player player, String message)86
{87
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));88
}90
public static void sendCountdown(Plugin plugin, final String message, final int time, Runnable runnable)91
{92
Bukkit.getScheduler().runTaskTimer(plugin, new Runnable()93
{94
int count = time;96
@Override97
public void run()98
{99
if(count == 0)100
{101
runnable.run();102
return;103
}105
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + message + " " + count + " sec");107
count--;108
}109
}, 0L, DefaultConstants.TICK);110
}112
public static Float convertFacingToYaw(BlockFace face)113
{114
switch(face)115
{116
case NORTH:117
return 0F;118
case EAST:119
return 90F;120
case SOUTH:121
return 180F;122
case WEST:123
return -90F;124
default:125
break;126
}128
return null;129
}131
public static boolean isAir(Material material)132
{133
return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;134
}136
public static boolean isFarmable(Material material)137
{138
return material == Material.WHEAT || material == Material.CARROTS || material == Material.POTATOES || material == Material.BEETROOTS || material == Material.NETHER_WART || material == Material.COCOA;139
}140
}