Moved code to objects
This commit is contained in:
parent
884184006c
commit
b593a22568
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user