From b593a22568b18d3693429960a60043bfbda1a580 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 10 May 2021 14:51:14 +0200 Subject: [PATCH] Moved code to objects --- .../LinkedBeaconTeleporterBlock.java | 22 +++++++++++++++++++ .../LinkedBeaconTeleporterItem.java | 9 ++++++++ .../listener/OnBlockBreak.java | 13 +---------- .../listener/OnBlockPlace.java | 3 +-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java index e89dcb1..ee34fcc 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterBlock.java @@ -1,8 +1,10 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.event.block.BlockBreakEvent; import java.util.List; @@ -21,6 +23,26 @@ public class LinkedBeaconTeleporterBlock extends LinkedBeaconTeleporter { } + public LinkedBeaconTeleporterItem break_(BlockBreakEvent e){ + // Dont drop anything + e.setDropItems(false); + e.setExpToDrop(0); + + LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.breakLbtBlock(this); + + Location loc = this.block().getLocation(); + + // Drop custom-item + if(e.getPlayer().getGameMode() != GameMode.CREATIVE) + loc.getWorld().dropItemNaturally( + loc.add(0.5, 0, 0.5), + lbtItem.item() + ); + + return lbtItem; + } + + // Conversion methods public static LinkedBeaconTeleporterBlock getFromLocation(Location loc){ return Main.lbtManager.getLbtBlockFromLocation(loc); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java index f57fe1c..fc856d6 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/LinkedBeaconTeleporterItem.java @@ -1,7 +1,10 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter; import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main; +import org.bukkit.GameMode; import org.bukkit.Material; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -35,6 +38,12 @@ public class LinkedBeaconTeleporterItem extends LinkedBeaconTeleporter { } + public LinkedBeaconTeleporterBlock place(BlockPlaceEvent e){ + LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.placeLbtItem(this, e.getBlock()); + return lbtBlock; + } + + // Conversion methods public static LinkedBeaconTeleporterItem getFromItemStack(ItemStack itemStack){ return Main.lbtManager.getLbtItemFromItemStack(itemStack); diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockBreak.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockBreak.java index 2018faa..de8cf34 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockBreak.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockBreak.java @@ -26,18 +26,7 @@ public class OnBlockBreak implements Listener { // Ignore if not found if(lbtBlock == null) return; - LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.breakLbtBlock(lbtBlock); - - // Dont drop anything - e.setDropItems(false); - e.setExpToDrop(0); - - // Drop custom-item - if(e.getPlayer().getGameMode() != GameMode.CREATIVE) - lbtBlock.block().getLocation().getWorld().dropItemNaturally( - lbtBlock.block().getLocation(), - lbtItem.item() - ); + LinkedBeaconTeleporterItem lbtItem = lbtBlock.break_(e); } } } diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockPlace.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockPlace.java index 11ea48e..dafe2c8 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockPlace.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnBlockPlace.java @@ -25,8 +25,7 @@ public class OnBlockPlace implements Listener { // Ignore if not found if(lbtItem == null) return; - Block block = e.getBlock(); - LinkedBeaconTeleporterBlock lbtBlock = Main.lbtManager.placeLbtItem(lbtItem, block); + LinkedBeaconTeleporterBlock lbtBlock = lbtItem.place(e); } } }