forked from Sefiraat/Networks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
13 deletions.
There are no files selected for viewing
36 changes: 27 additions & 9 deletions
36
src/main/java/io/github/sefiraat/networks/listeners/SyncListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,42 @@ | ||
package io.github.sefiraat.networks.listeners; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import io.github.sefiraat.networks.NetworkStorage; | ||
import io.github.sefiraat.networks.Networks; | ||
import io.github.sefiraat.networks.utils.NetworkUtils; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.bukkit.event.block.BlockPlaceEvent; | ||
import org.bukkit.event.world.ChunkUnloadEvent; | ||
|
||
import io.github.sefiraat.networks.utils.NetworkUtils; | ||
import java.text.MessageFormat; | ||
|
||
/* | ||
* Fix https://github.com/Sefiraat/Networks/issues/188 | ||
* Fix https://github.com/Sefiraat/Networks/issues/192 | ||
* Fix https://github.com/ytdd9527/NetworksExpansion/issues/119 | ||
*/ | ||
public class SyncListener implements Listener { | ||
private static final String S1 = "Listened BlockBreakEvent at {0}"; | ||
private static final String S2 = "Listened BlockPlaceEvent at {0}"; | ||
private static final String S3 = "Listened ChunkUnloadEvent at world: {0}, x: {1}, z: {2}"; | ||
|
||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) | ||
public void onBlockBreak(BlockBreakEvent e) { | ||
Networks.getInstance().debug(MessageFormat.format(S1, e.getBlock().getLocation())); | ||
NetworkUtils.clearNetwork(e.getBlock().getLocation()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||
public void onBlockBreak(@Nonnull BlockBreakEvent event) { | ||
NetworkUtils.clearNetwork(event.getBlock().getLocation()); | ||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) | ||
public void onBlockPlace(BlockPlaceEvent e) { | ||
Networks.getInstance().debug(MessageFormat.format(S2, e.getBlock().getLocation())); | ||
NetworkUtils.clearNetwork(e.getBlock().getLocation()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void onBlockPlace(@Nonnull BlockPlaceEvent event) { | ||
NetworkUtils.clearNetwork(event.getBlock().getLocation()); | ||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) | ||
public void onChunkUnload(ChunkUnloadEvent e) { | ||
Networks.getInstance().debug(MessageFormat.format(S3, e.getWorld().getName(), e.getChunk().getX(), e.getChunk().getZ())); | ||
NetworkStorage.unregisterChunk(e.getChunk()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters