Skip to content

Commit

Permalink
Fixed vehicles in void don't have their block removed from the block …
Browse files Browse the repository at this point in the history
…counts (#1790)
  • Loading branch information
OmerBenGera committed Jul 20, 2023
1 parent 0ef0615 commit 464343c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -49,6 +49,7 @@
import org.bukkit.material.Directional;
import org.bukkit.material.Dispenser;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
Expand Down Expand Up @@ -353,6 +354,7 @@ private void onMinecartBreak(VehicleDestroyEvent e) {
if (e.getVehicle() instanceof Minecart) {
Key blockKey = plugin.getNMSAlgorithms().getMinecartBlock((Minecart) e.getVehicle());
onBlockBreak(blockKey, e.getVehicle().getLocation(), 1, Flag.DIRTY_CHUNK, Flag.SAVE_BLOCK_COUNT);
e.getVehicle().setMetadata("SSB-VehicleDestory", new FixedMetadataValue(plugin, true));
}
}

Expand Down
Expand Up @@ -2,11 +2,15 @@

import com.bgsoftware.superiorskyblock.SuperiorSkyblockPlugin;
import com.bgsoftware.superiorskyblock.api.island.Island;
import com.bgsoftware.superiorskyblock.api.key.Key;
import com.bgsoftware.superiorskyblock.core.Singleton;
import com.bgsoftware.superiorskyblock.core.key.KeyImpl;
import com.bgsoftware.superiorskyblock.module.BuiltinModules;
import com.bgsoftware.superiorskyblock.module.upgrades.type.UpgradeTypeEntityLimits;
import com.bgsoftware.superiorskyblock.world.BukkitEntities;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand All @@ -19,9 +23,11 @@
public class EntityTrackingListener implements Listener {

private final SuperiorSkyblockPlugin plugin;
private final Singleton<BlockChangesListener> blockChangesListener;

public EntityTrackingListener(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
this.blockChangesListener = plugin.getListener(BlockChangesListener.class);
this.registerDeathListener();
}

Expand Down Expand Up @@ -68,6 +74,19 @@ public void onEntityDespawn(Entity entity) {
return;

island.getEntitiesTracker().untrackEntity(KeyImpl.of(entity), 1);

if (!(entity instanceof Vehicle))
return;

if (entity.hasMetadata("SSB-VehicleDestory")) {
entity.removeMetadata("SSB-VehicleDestory", plugin);
return;
}

// Vehicle was not registered by VehicleDestroyEvent; We want to register its block break
Key blockKey = plugin.getNMSAlgorithms().getMinecartBlock((Minecart) entity);
this.blockChangesListener.get().onBlockBreak(blockKey, entity.getLocation(), 1,
BlockChangesListener.Flag.DIRTY_CHUNK, BlockChangesListener.Flag.SAVE_BLOCK_COUNT);
}

/* INTERNAL */
Expand Down

0 comments on commit 464343c

Please sign in to comment.