so://phie

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy

blob: 3c405571c90d06226693ed58ccd19f22c0a6e8c1 (2663 bytes)[doc][blame][raw]

1package de.typable.minecrafthub.util;

2

3import org.bukkit.Bukkit;

4import org.bukkit.Material;

5import org.bukkit.block.BlockFace;

6import org.bukkit.entity.Player;

7import org.bukkit.inventory.Inventory;

8import org.bukkit.inventory.ItemStack;

9import org.bukkit.plugin.Plugin;

10

11import de.typable.minecrafthub.constant.DefaultConstants;

12import net.md_5.bungee.api.ChatColor;

13import net.md_5.bungee.api.ChatMessageType;

14import net.md_5.bungee.api.chat.TextComponent;

15

16

17public class Util

18{

19 public static boolean isEmpty(ItemStack item)

20 {

21 return item == null || item.getType() == Material.AIR;

22 }

23

24 public static boolean isType(ItemStack item, Material type)

25 {

26 return !isEmpty(item) && item.getType() == type;

27 }

28

29 public static boolean compare(ItemStack item, ItemStack item2)

30 {

31 if(item == null || item2 == null)

32 {

33 return false;

34 }

35

36 if(item.getType() != item2.getType())

37 {

38 return false;

39 }

40

41 return true;

42 }

43

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 }

52

53 if(result.isSimilar(item))

54 {

55 if(result.getAmount() + item.getAmount() <= item.getMaxStackSize())

56 {

57 return false;

58 }

59 }

60 }

61

62 return true;

63 }

64

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);

70

71 if(Util.compare(item, current))

72 {

73 amount -= current.getAmount();

74

75 if(amount <= 0)

76 {

77 return true;

78 }

79 }

80 }

81

82 return false;

83 }

84

85 public static void sendActionMessage(Player player, String message)

86 {

87 player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));

88 }

89

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;

95

96 @Override

97 public void run()

98 {

99 if(count == 0)

100 {

101 runnable.run();

102 return;

103 }

104

105 Bukkit.getServer().broadcastMessage(ChatColor.YELLOW + message + " " + count + " sec");

106

107 count--;

108 }

109 }, 0L, DefaultConstants.TICK);

110 }

111

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 }

127

128 return null;

129 }

130

131 public static boolean isAir(Material material)

132 {

133 return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;

134 }

135}