9
9
import com .gmail .nossr50 .util .player .UserManager ;
10
10
import com .gmail .nossr50 .util .skills .CombatUtils ;
11
11
import com .gmail .nossr50 .util .skills .SkillUtils ;
12
- import com .gmail .nossr50 .util .sounds .SoundManager ;
13
- import com .gmail .nossr50 .util .sounds .SoundType ;
14
12
import org .bukkit .ChatColor ;
15
13
import org .bukkit .Location ;
16
14
import org .bukkit .Material ;
25
23
import java .util .List ;
26
24
27
25
public final class ChimaeraWing {
28
- private static McMMOPlayer mcMMOPlayer ;
29
- private static Location location ;
30
-
31
26
private ChimaeraWing () {}
32
27
33
28
/**
@@ -40,7 +35,7 @@ public static void activationCheck(Player player) {
40
35
return ;
41
36
}
42
37
43
- ItemStack inHand = player .getInventory ().getItemInMainHand ();
38
+ final ItemStack inHand = player .getInventory ().getItemInMainHand ();
44
39
45
40
if (!ItemUtils .isChimaeraWing (inHand )) {
46
41
return ;
@@ -51,7 +46,7 @@ public static void activationCheck(Player player) {
51
46
return ;
52
47
}
53
48
54
- mcMMOPlayer = UserManager .getPlayer (player );
49
+ final McMMOPlayer mcMMOPlayer = UserManager .getPlayer (player );
55
50
56
51
//Not loaded
57
52
if (mcMMOPlayer == null )
@@ -61,10 +56,10 @@ public static void activationCheck(Player player) {
61
56
return ;
62
57
}
63
58
64
- int amount = inHand .getAmount ();
59
+ int amountInHand = inHand .getAmount ();
65
60
66
- if (amount < mcMMO .p .getGeneralConfig ().getChimaeraUseCost ()) {
67
- NotificationManager .sendPlayerInformation (player , NotificationType .REQUIREMENTS_NOT_MET , "Item.ChimaeraWing.NotEnough" ,String .valueOf (mcMMO .p .getGeneralConfig ().getChimaeraUseCost () - amount ), "Item.ChimaeraWing.Name" );
61
+ if (amountInHand < mcMMO .p .getGeneralConfig ().getChimaeraUseCost ()) {
62
+ NotificationManager .sendPlayerInformation (player , NotificationType .REQUIREMENTS_NOT_MET , "Item.ChimaeraWing.NotEnough" ,String .valueOf (mcMMO .p .getGeneralConfig ().getChimaeraUseCost () - amountInHand ), "Item.ChimaeraWing.Name" );
68
63
return ;
69
64
}
70
65
@@ -92,13 +87,13 @@ public static void activationCheck(Player player) {
92
87
}
93
88
}
94
89
95
- location = player .getLocation ();
90
+ final Location playerLocation = player .getLocation ();
96
91
97
92
if (mcMMO .p .getGeneralConfig ().getChimaeraPreventUseUnderground ()) {
98
- if (location .getY () < player .getWorld ().getHighestBlockYAt (location )) {
99
- player . getInventory (). setItemInMainHand ( new ItemStack ( getChimaeraWing ( amount - mcMMO . p . getGeneralConfig (). getChimaeraUseCost ())) );
100
- NotificationManager .sendPlayerInformation (player , NotificationType . REQUIREMENTS_NOT_MET , "Item.ChimaeraWing.Fail" );
101
- player . updateInventory ( );
93
+ if (playerLocation .getY () < player .getWorld ().getHighestBlockYAt (playerLocation )) {
94
+ expendChimaeraWing ( player , amountInHand , inHand );
95
+ NotificationManager .sendPlayerInformation (player ,
96
+ NotificationType . REQUIREMENTS_NOT_MET , "Item.ChimaeraWing.Fail" );
102
97
player .setVelocity (new Vector (0 , 0.5D , 0 ));
103
98
CombatUtils .dealDamage (player , Misc .getRandom ().nextInt ((int ) (player .getHealth () - 10 )));
104
99
mcMMOPlayer .actualizeChimeraWingLastUse ();
@@ -107,44 +102,23 @@ public static void activationCheck(Player player) {
107
102
}
108
103
109
104
mcMMOPlayer .actualizeTeleportCommenceLocation (player );
110
-
111
- long warmup = mcMMO .p .getGeneralConfig ().getChimaeraWarmup ();
112
-
113
- if (warmup > 0 ) {
114
- NotificationManager .sendPlayerInformation (player , NotificationType .ITEM_MESSAGE , "Teleport.Commencing" , String .valueOf (warmup ));
115
- mcMMO .p .getFoliaLib ().getScheduler ().runAtEntityLater (player , new ChimaeraWingWarmup (mcMMOPlayer ), 20 * warmup );
105
+ long teleportDelay = mcMMO .p .getGeneralConfig ().getChimaeraWarmup ();
106
+ if (teleportDelay > 0 ) {
107
+ NotificationManager .sendPlayerInformation (player , NotificationType .ITEM_MESSAGE , "Teleport.Commencing" , String .valueOf (teleportDelay ));
108
+ mcMMO .p .getFoliaLib ().getScheduler ().runAtEntityLater (player , new ChimaeraWingWarmup (mcMMOPlayer , playerLocation ), 20 * teleportDelay );
116
109
} else {
117
- chimaeraExecuteTeleport ( );
110
+ mcMMO . p . getFoliaLib (). getScheduler (). runAtEntityLater ( player , new ChimaeraWingWarmup ( mcMMOPlayer , playerLocation ), 0 );
118
111
}
119
112
}
120
113
121
- public static void chimaeraExecuteTeleport () {
122
- Player player = mcMMOPlayer .getPlayer ();
123
-
124
- if (mcMMO .p .getGeneralConfig ().getChimaeraUseBedSpawn () && player .getBedSpawnLocation () != null ) {
125
- // player.teleport(player.getBedSpawnLocation());
126
- mcMMO .p .getFoliaLib ().getScheduler ().teleportAsync (player , player .getBedSpawnLocation ());
114
+ public static void expendChimaeraWing (Player player , int amountInHand , ItemStack inHand ) {
115
+ int amountAfterUse = amountInHand - mcMMO .p .getGeneralConfig ().getChimaeraUseCost ();
116
+ if (amountAfterUse >= 1 ) {
117
+ inHand .setAmount (amountAfterUse );
118
+ player .getInventory ().setItemInMainHand (inHand );
127
119
} else {
128
- Location spawnLocation = player .getWorld ().getSpawnLocation ();
129
- if (spawnLocation .getBlock ().getType () == Material .AIR ) {
130
- // player.teleport(spawnLocation);
131
- mcMMO .p .getFoliaLib ().getScheduler ().teleportAsync (player , spawnLocation );
132
- } else {
133
- // player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
134
- mcMMO .p .getFoliaLib ().getScheduler ().teleportAsync (player , player .getWorld ().getHighestBlockAt (spawnLocation ).getLocation ());
135
- }
120
+ player .getInventory ().removeItem (inHand );
136
121
}
137
-
138
- player .getInventory ().setItemInMainHand (new ItemStack (getChimaeraWing (player .getInventory ().getItemInMainHand ().getAmount () - mcMMO .p .getGeneralConfig ().getChimaeraUseCost ())));
139
- player .updateInventory ();
140
- mcMMOPlayer .actualizeChimeraWingLastUse ();
141
- mcMMOPlayer .setTeleportCommenceLocation (null );
142
-
143
- if (mcMMO .p .getGeneralConfig ().getChimaeraSoundEnabled ()) {
144
- SoundManager .sendSound (player , location , SoundType .CHIMAERA_WING );
145
- }
146
-
147
- NotificationManager .sendPlayerInformation (player , NotificationType .ITEM_MESSAGE , "Item.ChimaeraWing.Pass" );
148
122
}
149
123
150
124
public static ItemStack getChimaeraWing (int amount ) {
0 commit comments