11package ru .meloncode .xmas ;
22
3- import net .minecraft .server .v1_14_R1 .BlockPosition ;
4- import net .minecraft .server .v1_14_R1 .TileEntitySkull ;
53import org .bukkit .Location ;
64import org .bukkit .Material ;
5+ import org .bukkit .World ;
76import org .bukkit .block .Block ;
87import org .bukkit .block .Skull ;
9- import org .bukkit .craftbukkit .v1_14_R1 .CraftWorld ;
108import org .bukkit .entity .Player ;
119import org .bukkit .inventory .ItemStack ;
1210import ru .meloncode .xmas .utils .TextUtils ;
1715import java .util .UUID ;
1816import java .util .concurrent .ConcurrentHashMap ;
1917
18+ import static ru .meloncode .xmas .Main .RANDOM ;
19+
2020class XMas {
2121
2222 private static final ConcurrentHashMap <UUID , MagicTree > trees = new ConcurrentHashMap <>();
@@ -42,26 +42,27 @@ public static void removeTree(MagicTree tree) {
4242 TreeSerializer .removeTree (tree );
4343 trees .remove (tree .getTreeUID ());
4444 }
45+
4546 public static void processPresent (Block block , Player player ) {
4647 if (block .getType () == Material .PLAYER_HEAD ) {
4748 Skull skull = (Skull ) block .getState ();
48- TileEntitySkull skullTile = (TileEntitySkull ) ((CraftWorld )skull .getWorld ()).getHandle ().getTileEntity (new BlockPosition (skull .getX (), skull .getY (), skull .getZ ()));
49- if (skullTile != null && skullTile .gameProfile != null ) {
50- if (Main .getHeads ().contains (skullTile .gameProfile .getName ())) {
49+
50+ if (Main .getHeads ().contains (skull .getOwner ())) {
5151 Location loc = block .getLocation ();
52- if ((Main .RANDOM .nextFloat ()) < Main .LUCK_CHANCE || !Main .LUCK_CHANCE_ENABLED ) {
53- loc .getWorld ().dropItemNaturally (loc ,
54- new ItemStack (Main .gifts .get (Main .RANDOM .nextInt (Main .gifts .size ()))));
55- Effects .TREE_SWAG .playEffect (loc );
56- TextUtils .sendMessage (player , LocaleManager .GIFT_LUCK );
57- } else {
58- Effects .SMOKE .playEffect (loc );
59- loc .getWorld ().dropItemNaturally (loc , new ItemStack (Material .COAL ));
60- TextUtils .sendMessage (player , LocaleManager .GIFT_FAIL );
52+ World world = loc .getWorld ();
53+ if (world != null ) {
54+ if (RANDOM .nextFloat () < Main .LUCK_CHANCE || !Main .LUCK_CHANCE_ENABLED ) {
55+ world .dropItemNaturally (loc , new ItemStack (Main .gifts .get (RANDOM .nextInt (Main .gifts .size ()))));
56+ Effects .TREE_SWAG .playEffect (loc );
57+ TextUtils .sendMessage (player , LocaleManager .GIFT_LUCK );
58+ } else {
59+ Effects .SMOKE .playEffect (loc );
60+ world .dropItemNaturally (loc , new ItemStack (Material .COAL ));
61+ TextUtils .sendMessage (player , LocaleManager .GIFT_FAIL );
62+ }
6163 }
6264 block .setType (Material .AIR );
6365 }
64- }
6566 }
6667 }
6768
0 commit comments