Skip to content

Commit d7c2c23

Browse files
committed
[update] BlockPlaceListenerの機能強化
1 parent a059711 commit d7c2c23

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
package com.github.elic0de.thejpspit.spigot.listener;
22

33
import com.github.elic0de.thejpspit.spigot.TheJpsPit;
4-
import java.util.HashSet;
5-
import java.util.Set;
64
import org.bukkit.Bukkit;
7-
import org.bukkit.Effect;
85
import org.bukkit.GameMode;
9-
import org.bukkit.Location;
10-
import org.bukkit.Material;
11-
import org.bukkit.block.Block;
6+
import org.bukkit.block.BlockState;
127
import org.bukkit.entity.Player;
138
import org.bukkit.event.EventHandler;
149
import org.bukkit.event.Listener;
1510
import org.bukkit.event.block.BlockPlaceEvent;
1611

12+
import java.util.HashSet;
13+
import java.util.Set;
14+
1715
public class BlockPlaceListener implements Listener {
1816

1917
private final TheJpsPit pit;
2018

21-
private static final Set<Location> water = new HashSet<>();
22-
private static final Set<Location> blocksPlaced = new HashSet<>();
19+
private static final Set<BlockState> replacedStates = new HashSet<>();
2320

2421
public BlockPlaceListener() {
2522
this.pit = TheJpsPit.getInstance();
@@ -30,29 +27,19 @@ public BlockPlaceListener() {
3027
public void on(BlockPlaceEvent event) {
3128
final Player player = event.getPlayer();
3229
if (player.getGameMode() == GameMode.CREATIVE) return;
33-
final Block placedBlock = event.getBlockPlaced();
34-
final Location placedBlockLocation = placedBlock.getLocation();
35-
36-
if(event.getBlockReplacedState().getType() == Material.WATER) water.add(placedBlock.getLocation());
30+
final BlockState replacedState = event.getBlockReplacedState();
3731

38-
blocksPlaced.add(placedBlockLocation);
32+
replacedStates.add(replacedState);
3933

4034
pit.getServer().getScheduler().runTaskLater(pit, runnable -> {
41-
if (water.contains(placedBlockLocation)) {
42-
placedBlock.setType(Material.WATER);
43-
} else {
44-
placedBlock.setType(Material.AIR);
35+
if (replacedStates.contains(replacedState)) {
36+
replacedState.update();
37+
replacedStates.remove(replacedState);
4538
}
46-
blocksPlaced.remove(placedBlockLocation);
4739
}, (15 * 20));
4840
}
4941

50-
public static void removeBlocks() {
51-
for (Location location : blocksPlaced) {
52-
location.getBlock().setType(Material.AIR);
53-
}
54-
for (Location location : water) {
55-
location.getBlock().setType(Material.WATER);
56-
}
42+
public static void restoreBlocks() {
43+
replacedStates.forEach(BlockState::update);
5744
}
5845
}

0 commit comments

Comments
 (0)