Skip to content

Commit

Permalink
fix: 部分网络幽灵方块产生 (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
JWJUN233233 authored May 3, 2024
1 parent 6d7613e commit d2d44c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.github.sefiraat.networks.managers;

import io.github.sefiraat.networks.Networks;
import io.github.sefiraat.networks.listeners.BlockListener;
import io.github.sefiraat.networks.listeners.ExplosiveToolListener;
import org.bukkit.event.Listener;

public class ListenerManager {

public ListenerManager() {
addListener(new ExplosiveToolListener());
addListener(new BlockListener());
}

private void addListener(Listener listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ protected void onBreak(@Nonnull BlockBreakEvent event) {
blockMenu.dropItems(location, i);
}
}
NetworkStorage.removeNode(location);

if (this.nodeType == NodeType.CONTROLLER) {
NetworkController.wipeNetwork(location);
}

Slimefun.getDatabaseManager().getBlockDataController().removeBlock(location);
}
Expand Down

0 comments on commit d2d44c0

Please sign in to comment.