Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/miner android cleanup #4233

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -75,87 +76,97 @@ public AndroidType getAndroidType() {
protected void dig(Block b, BlockMenu menu, Block block) {
Collection<ItemStack> drops = block.getDrops(effectivePickaxe);

if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) {
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));
if (!canBreakBlock(block, b)) {
return;
}

if (Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) {
AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
Bukkit.getPluginManager().callEvent(event);
AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
Bukkit.getPluginManager().callEvent(event);

if (event.isCancelled()) {
return;
}
if (event.isCancelled()) {
return;
}

// We only want to break non-Slimefun blocks
if (!BlockStorage.hasBlockInfo(block)) {
breakBlock(menu, drops, block);
}
}
// We only want to break non-Slimefun blocks
if (!BlockStorage.hasBlockInfo(block)) {
breakBlock(menu, drops, block);
}
}

@ParametersAreNonnullByDefault
protected boolean canBreakBlock(Block block, Block b) {
Collection<ItemStack> drops = block.getDrops(effectivePickaxe);
if (SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) || drops.isEmpty()) {
return false;
}

String ownerName = BlockStorage.getLocationInfo(b.getLocation(), "owner");
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(ownerName));
if (!Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) {
return false;
}

return true;
}

@Override
@ParametersAreNonnullByDefault
protected void moveAndDig(Block b, BlockMenu menu, BlockFace face, Block block) {
Collection<ItemStack> drops = block.getDrops(effectivePickaxe);

if (!SlimefunTag.UNBREAKABLE_MATERIALS.isTagged(block.getType()) && !drops.isEmpty()) {
OfflinePlayer owner = Bukkit.getOfflinePlayer(UUID.fromString(BlockStorage.getLocationInfo(b.getLocation(), "owner")));

if (Slimefun.getProtectionManager().hasPermission(owner, block.getLocation(), Interaction.BREAK_BLOCK)) {
AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
Bukkit.getPluginManager().callEvent(event);

if (event.isCancelled()) {
return;
}

// We only want to break non-Slimefun blocks
if (!BlockStorage.hasBlockInfo(block)) {
breakBlock(menu, drops, block);
move(b, face, block);
}
} else {
move(b, face, block);
}
} else {
if (!canBreakBlock(block, b)) {
move(b, face, block);
return;
}

AndroidMineEvent event = new AndroidMineEvent(block, new AndroidInstance(this, b));
Bukkit.getPluginManager().callEvent(event);

if (event.isCancelled()) {
return;
}

// We only want to break non-Slimefun blocks
if (!BlockStorage.hasBlockInfo(block)) {
breakBlock(menu, drops, block);
move(b, face, block);
}
}

@ParametersAreNonnullByDefault
private void breakBlock(BlockMenu menu, Collection<ItemStack> drops, Block block) {

if (!block.getWorld().getWorldBorder().isInside(block.getLocation())) {
World world = block.getWorld();
if (!world.getWorldBorder().isInside(block.getLocation())) {
return;
}

block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
world.playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());

// Push our drops to the inventory
for (ItemStack drop : drops) {
menu.pushItem(drop, getOutputSlots());
}

// Check if Block Generator optimizations should be applied.
if (applyOptimizations.getValue()) {
InfiniteBlockGenerator generator = InfiniteBlockGenerator.findAt(block);

// If we found a generator, continue.
if (generator != null) {
if (firesEvent.getValue()) {
generator.callEvent(block);
}

// "poof" a "new" block was generated
SoundEffect.MINER_ANDROID_BLOCK_GENERATION_SOUND.playAt(block);
block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, block.getX() + 0.5, block.getY() + 1.25, block.getZ() + 0.5, 8, 0.5, 0.5, 0.5, 0.015);
} else {
block.setType(Material.AIR);
}
} else {
if (!applyOptimizations.getValue()) {
block.setType(Material.AIR);
return;
}

// If we didn't find a generator ignore the block.
InfiniteBlockGenerator generator = InfiniteBlockGenerator.findAt(block);
if (generator == null) {
block.setType(Material.AIR);
return;
}

if (firesEvent.getValue()) {
generator.callEvent(block);
}

// "poof" a "new" block was generated
SoundEffect.MINER_ANDROID_BLOCK_GENERATION_SOUND.playAt(block);
world.spawnParticle(Particle.SMOKE_NORMAL, block.getX() + 0.5, block.getY() + 1.25, block.getZ() + 0.5, 8, 0.5, 0.5, 0.5, 0.015);
}

}
Loading