Skip to content

Commit

Permalink
Drop an ES System when the block gets broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanOMik committed Jul 8, 2020
1 parent 2e67719 commit 77a426a
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.seanomik.energeticstorage.files.PlayersFile;
import net.seanomik.energeticstorage.objects.ESDrive;
import net.seanomik.energeticstorage.objects.ESSystem;
import net.seanomik.energeticstorage.utils.ItemConstructor;
import net.seanomik.energeticstorage.utils.PermissionChecks;
import net.seanomik.energeticstorage.utils.Reference;
import net.seanomik.energeticstorage.utils.Utils;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void onBlockBreakListener(BlockBreakEvent event) {
if (esSystem != null) {
if (esSystem.isPlayerTrusted(player) || esSystem.getOwner().equals(player.getUniqueId()) || PermissionChecks.canDestroyUntrustedSystems(player)) {
for (ESDrive drive : esSystem.getESDrives()) {
block.getLocation().getWorld().dropItem(block.getLocation(), drive.getDriveItem());
block.getLocation().getWorld().dropItemNaturally(block.getLocation(), drive.getDriveItem());
}

// Remove the system from cache and storage
Expand All @@ -43,6 +44,10 @@ public void onBlockBreakListener(BlockBreakEvent event) {
List<ESSystem> systems = new LinkedList<>(Reference.ES_SYSTEMS.get(player.getUniqueId()));
systems.removeIf(esSystem::equals);
Reference.ES_SYSTEMS.replace(player.getUniqueId(), systems);

// Drop an ES System
event.setDropItems(false);
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), ItemConstructor.createSystemBlock());
} else {
event.setCancelled(true);
player.sendMessage(Reference.PREFIX + ChatColor.RED + "You are not trusted to this system!");
Expand Down

0 comments on commit 77a426a

Please sign in to comment.