33import com .github .elic0de .thejpspit .spigot .TheJpsPit ;
44import org .bukkit .Bukkit ;
55import org .bukkit .GameMode ;
6+ import org .bukkit .Location ;
67import org .bukkit .block .BlockState ;
78import org .bukkit .entity .Player ;
89import org .bukkit .event .EventHandler ;
910import org .bukkit .event .Listener ;
1011import org .bukkit .event .block .BlockPlaceEvent ;
1112import org .bukkit .event .player .PlayerBucketEmptyEvent ;
1213
13- import java .util .HashSet ;
14- import java .util .Set ;
14+ import java .util .HashMap ;
1515
1616public class BlockPlaceListener implements Listener {
1717
1818 private final TheJpsPit pit ;
1919
20- private static final Set < BlockState > replacedStates = new HashSet <>();
20+ private static final HashMap < Location , BlockState > replacedStates = new HashMap <>();
2121
2222 public BlockPlaceListener () {
2323 this .pit = TheJpsPit .getInstance ();
@@ -30,12 +30,13 @@ public void on(BlockPlaceEvent event) {
3030 if (player .getGameMode () == GameMode .CREATIVE ) return ;
3131 final BlockState replacedState = event .getBlockReplacedState ();
3232
33- replacedStates .add (replacedState );
33+ if (replacedStates .containsKey (replacedState .getLocation ())) return ;
34+ replacedStates .put (replacedState .getLocation (), replacedState );
3435
3536 pit .getServer ().getScheduler ().runTaskLater (pit , runnable -> {
36- if (replacedStates .contains (replacedState )) {
37+ if (replacedStates .containsKey (replacedState . getLocation () )) {
3738 replacedState .update (true );
38- replacedStates .remove (replacedState );
39+ replacedStates .remove (replacedState . getLocation () );
3940 }
4041 }, (15 * 20 ));
4142 }
@@ -46,17 +47,18 @@ public void on(PlayerBucketEmptyEvent event) {
4647 if (player .getGameMode () == GameMode .CREATIVE ) return ;
4748 final BlockState replacedState = event .getBlock ().getState ();
4849
49- replacedStates .add (replacedState );
50+ if (replacedStates .containsKey (replacedState .getLocation ())) return ;
51+ replacedStates .put (replacedState .getLocation (), replacedState );
5052
5153 pit .getServer ().getScheduler ().runTaskLater (pit , runnable -> {
52- if (replacedStates .contains (replacedState )) {
54+ if (replacedStates .containsKey (replacedState . getLocation () )) {
5355 replacedState .update (true );
54- replacedStates .remove (replacedState );
56+ replacedStates .remove (replacedState . getLocation () );
5557 }
5658 }, (15 * 20 ));
5759 }
5860
5961 public static void restoreBlocks () {
60- replacedStates .forEach (b -> b .update (true ));
62+ replacedStates .values (). forEach (b -> b .update (true ));
6163 }
6264}
0 commit comments