forked from Sefiraat/Networks
-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
6d7613e
commit d2d44c0
Showing
3 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/io/github/sefiraat/networks/listeners/BlockListener.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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.github.sefiraat.networks.listeners; | ||
|
||
import io.github.sefiraat.networks.NetworkStorage; | ||
import io.github.sefiraat.networks.network.NodeDefinition; | ||
import io.github.sefiraat.networks.network.NodeType; | ||
import io.github.sefiraat.networks.slimefun.network.NetworkController; | ||
import org.bukkit.Location; | ||
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; | ||
|
||
public class BlockListener implements Listener { | ||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) | ||
public void onBlockBreak(BlockBreakEvent e) { | ||
removeNetwork(e.getBlock().getLocation()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) | ||
public void onBlockPlace(BlockPlaceEvent e) { | ||
removeNetwork(e.getBlock().getLocation()); | ||
} | ||
|
||
private void removeNetwork(Location location) { | ||
NodeDefinition definition = NetworkStorage.getAllNetworkObjects().get(location); | ||
if (definition == null) return; | ||
if (definition.getNode() == null) return; | ||
NetworkStorage.removeNode(location); | ||
|
||
if (definition.getNode().getNodeType() == NodeType.CONTROLLER) { | ||
NetworkController.wipeNetwork(location); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/io/github/sefiraat/networks/managers/ListenerManager.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
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