2525import com .volmit .adapt .util .J ;
2626import com .volmit .adapt .util .Localizer ;
2727import lombok .NoArgsConstructor ;
28- import org .bukkit .Location ;
2928import org .bukkit .Material ;
3029import org .bukkit .Particle ;
3130import org .bukkit .Sound ;
3736import org .bukkit .inventory .ItemStack ;
3837
3938import java .util .Collection ;
40- import java .util .HashMap ;
41- import java .util .Map ;
39+ import java .util .HashSet ;
40+ import java .util .Set ;
4241
4342public class AxeWoodVeinminer extends SimpleAdaptation <AxeWoodVeinminer .Config > {
4443 public AxeWoodVeinminer () {
@@ -89,8 +88,7 @@ public void on(BlockBreakEvent e) {
8988 if (isLog (new ItemStack (e .getBlock ().getType ()))) {
9089
9190 Block block = e .getBlock ();
92- Map <Location , Block > blockMap = new HashMap <>();
93- blockMap .put (block .getLocation (), block );
91+ Set <Block > blockMap = new HashSet <>();
9492 int blockCount = 0 ;
9593 for (int i = 0 ; i < getRadius (getLevel (p )); i ++) {
9694 for (int x = -i ; x <= i ; x ++) {
@@ -107,46 +105,31 @@ public void on(BlockBreakEvent e) {
107105 Adapt .verbose ("Block: " + b .getLocation () + " is too far away from " + block .getLocation () + " (" + getRadius (getLevel (p )) + ")" );
108106 continue ;
109107 }
110- blockMap .put ( b . getLocation (), b );
108+ blockMap .add ( b );
111109 }
112110 }
113111 }
114112 }
115113 }
116114
117115 J .s (() -> {
118- for (Location l : blockMap .keySet ()) {
119- Block b = e .getBlock ().getWorld ().getBlockAt (l );
120- xp (p , 2 );
121- if (getPlayer (p ).getData ().getSkillLines () != null
122- && getPlayer (p ).getData ().getSkillLines ().get ("axes" ).getAdaptations () != null
123- && getPlayer (p ).getData ().getSkillLines ().get ("axes" ).getAdaptations ().get ("axe-drop-to-inventory" ) != null
124- && getPlayer (p ).getData ().getSkillLines ().get ("axes" ).getAdaptations ().get ("axe-drop-to-inventory" ).getLevel () > 0 ) {
125- Collection <ItemStack > items = e .getBlock ().getDrops ();
126- if (!isLog (new ItemStack (b .getType ()))) {
127- for (ItemStack i : items ) {
128- p .playSound (p .getLocation (), Sound .BLOCK_CALCITE_HIT , 0.01f , 0.01f );
129- xp (p , 2 );
130- HashMap <Integer , ItemStack > extra = p .getInventory ().addItem (i );
131- if (!extra .isEmpty ()) {
132- p .getWorld ().dropItem (p .getLocation (), extra .get (0 ));
133- }
134- }
135- } else {
136- if (!p .getInventory ().addItem (new ItemStack (b .getType ())).isEmpty ()) {
137- p .getWorld ().dropItemNaturally (p .getLocation (), new ItemStack (b .getType ()));
138- }
116+ for (Block blocks : blockMap ) {
117+ if (getPlayer (p ).getData ().getSkillLines ().get ("axes" ).getAdaptations ().get ("axe-drop-to-inventory" ).getLevel () > 0 ) {
118+ Collection <ItemStack > items = blocks .getDrops ();
119+ for (ItemStack item : items ) {
120+ safeGiveItem (p , item );
121+ Adapt .verbose ("Giving item: " + item );
139122 }
140- p . breakBlock ( l . getBlock () );
123+ blocks . setType ( Material . AIR );
141124 } else {
142- b .breakNaturally (p .getItemInUse ());
143- e . getBlock () .getWorld ().playSound (e .getBlock ().getLocation (), Sound .BLOCK_FUNGUS_BREAK , 0.01f , 0.25f );
125+ blocks .breakNaturally (p .getItemInUse ());
126+ blocks .getWorld ().playSound (e .getBlock ().getLocation (), Sound .BLOCK_FUNGUS_BREAK , 0.01f , 0.25f );
144127 if (getConfig ().showParticles ) {
145- e . getBlock (). getWorld ().spawnParticle (Particle .ASH , e . getBlock () .getLocation ().add (0.5 , 0.5 , 0.5 ), 25 , 0.5 , 0.5 , 0.5 , 0.1 );
128+ blocks . getWorld ().spawnParticle (Particle .ASH , blocks .getLocation ().add (0.5 , 0.5 , 0.5 ), 25 , 0.5 , 0.5 , 0.5 , 0.1 );
146129 }
147130 }
148131 if (getConfig ().showParticles ) {
149- vfxSingleCubeOutlineR (b , Particle .ENCHANTMENT_TABLE );
132+ vfxSingleCubeOutlineR (blocks , Particle .ENCHANTMENT_TABLE );
150133 }
151134 }
152135 });
0 commit comments