A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy
blob: 4e8bbae8d4af37d2b54a9ba0dd8c51d7c6f12ba2 (3689 bytes)[doc][blame][raw]
1
package de.typable.minecrafthub.util;3
import javax.swing.text.Position;5
import org.bukkit.Bukkit;6
import org.bukkit.Location;7
import org.bukkit.Material;8
import org.bukkit.block.Block;9
import org.bukkit.block.BlockFace;10
import org.bukkit.entity.Player;11
import org.bukkit.inventory.Inventory;12
import org.bukkit.inventory.ItemStack;13
import org.bukkit.plugin.Plugin;15
import de.typable.minecrafthub.constant.DefaultConstants;16
import net.md_5.bungee.api.ChatColor;17
import net.md_5.bungee.api.ChatMessageType;18
import net.md_5.bungee.api.chat.TextComponent;21
public class Util22
{23
public static boolean isEmpty(ItemStack item)24
{25
return item == null || item.getType() == Material.AIR;26
}28
public static boolean isType(ItemStack item, Material type)29
{30
return !isEmpty(item) && item.getType() == type;31
}33
public static boolean compare(ItemStack item, ItemStack item2)34
{35
if(item == null || item2 == null)36
{37
return false;38
}40
if(item.getType() != item2.getType())41
{42
return false;43
}45
return true;46
}48
public static boolean isInventoryFull(Inventory inventory, ItemStack result)49
{50
for(ItemStack item : inventory.getContents())51
{52
if(Util.isEmpty(item))53
{54
return false;55
}57
if(result.isSimilar(item))58
{59
if(result.getAmount() + item.getAmount() <= item.getMaxStackSize())60
{61
return false;62
}63
}64
}66
return true;67
}69
public static boolean containsAtLeast(Inventory inventory, ItemStack item, int amount)70
{71
for(int i = 0; i < inventory.getSize(); i++)72
{73
ItemStack current = inventory.getItem(i);75
if(Util.compare(item, current))76
{77
amount -= current.getAmount();79
if(amount <= 0)80
{81
return true;82
}83
}84
}86
return false;87
}89
public static void sendActionMessage(Player player, String message)90
{91
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));92
}94
public static void sendCountdown(Plugin plugin, final String message, final int time, Runnable runnable)95
{96
Bukkit.getScheduler().runTaskTimer(plugin, new Runnable()97
{98
int count = time;100
@Override101
public void run()102
{103
if(count == 0)104
{105
runnable.run();106
return;107
}109
Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + message + " " + count + " sec");111
count--;112
}113
}, 0L, DefaultConstants.TICK);114
}116
public static Float convertFacingToYaw(BlockFace face)117
{118
switch(face)119
{120
case NORTH:121
return 0F;122
case EAST:123
return 90F;124
case SOUTH:125
return 180F;126
case WEST:127
return -90F;128
default:129
break;130
}132
return null;133
}135
public static boolean isAir(Material material)136
{137
return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;138
}140
public static boolean isFarmable(Material material)141
{142
return material == Material.WHEAT || material == Material.CARROTS || material == Material.POTATOES || material == Material.BEETROOTS || material == Material.NETHER_WART || material == Material.COCOA;143
}145
public static boolean isStem(Material material)146
{147
return material == Material.ATTACHED_PUMPKIN_STEM || material == Material.ATTACHED_MELON_STEM;148
}150
public static boolean hasStem(Block block)151
{152
Location blockLocation = block.getLocation();153
Material blockNorth = blockLocation.clone().add(0, 0, -1).getBlock().getType();154
Material blockEast = blockLocation.clone().add(1, 0, 0).getBlock().getType();155
Material blockSouth = blockLocation.clone().add(0, 0, 1).getBlock().getType();156
Material blockWest = blockLocation.clone().add(-1, 0, 0).getBlock().getType();158
return isStem(blockNorth) || isStem(blockEast) || isStem(blockSouth) || isStem(blockWest);159
}160
}