mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-03-02 10:31:23 +01:00
Fix falling blocks getting destroyed on island spawn, wording change
This commit is contained in:
parent
36e815f9f1
commit
4103552691
@ -2,20 +2,24 @@ package me.goodandevil.skyblock.listeners;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
|
import org.bukkit.entity.Donkey;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.ExperienceOrb;
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.entity.Hanging;
|
import org.bukkit.entity.Hanging;
|
||||||
|
import org.bukkit.entity.Horse;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
@ -395,6 +399,7 @@ public class Entity implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||||
org.bukkit.entity.Entity entity = event.getEntity();
|
org.bukkit.entity.Entity entity = event.getEntity();
|
||||||
|
|
||||||
@ -420,7 +425,22 @@ public class Entity implements Listener {
|
|||||||
island.getLocation(world, IslandEnvironment.Main)
|
island.getLocation(world, IslandEnvironment.Main)
|
||||||
.clone())
|
.clone())
|
||||||
&& configLoad.getBoolean("Island.Spawn.Protection")) {
|
&& configLoad.getBoolean("Island.Spawn.Protection")) {
|
||||||
event.getEntity().remove();
|
FallingBlock fallingBlock = (FallingBlock) event.getEntity();
|
||||||
|
if (fallingBlock.getDropItem()) {
|
||||||
|
if (NMSUtil.getVersionNumber() > 12) {
|
||||||
|
fallingBlock.getWorld().dropItemNaturally(fallingBlock.getLocation(), new ItemStack(fallingBlock.getBlockData().getMaterial(), 1));
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Method getBlockDataMethod = FallingBlock.class.getMethod("getBlockData");
|
||||||
|
byte data = (byte) getBlockDataMethod.invoke(fallingBlock);
|
||||||
|
if (fallingBlock.getMaterial().name().endsWith("ANVIL")) {
|
||||||
|
data = (byte) Math.ceil(data / 4);
|
||||||
|
}
|
||||||
|
Bukkit.broadcastMessage(((byte)getBlockDataMethod.invoke(fallingBlock)) + "");
|
||||||
|
fallingBlock.getWorld().dropItemNaturally(fallingBlock.getLocation(), new ItemStack(fallingBlock.getMaterial(), 1, (byte) data));
|
||||||
|
} catch (Exception ignored) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +455,6 @@ public class Entity implements Listener {
|
|||||||
.getFileConfiguration().getBoolean("Island.Block.Level.Enable")) return;
|
.getFileConfiguration().getBoolean("Island.Block.Level.Enable")) return;
|
||||||
org.bukkit.block.Block block = event.getBlock();
|
org.bukkit.block.Block block = event.getBlock();
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
Materials materials = Materials.getMaterials(block.getType(), block.getData());
|
Materials materials = Materials.getMaterials(block.getType(), block.getData());
|
||||||
|
|
||||||
if (materials != null) {
|
if (materials != null) {
|
||||||
@ -538,12 +557,16 @@ public class Entity implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
if (event.getEntity() instanceof Player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LivingEntity livingEntity = event.getEntity();
|
LivingEntity livingEntity = event.getEntity();
|
||||||
|
|
||||||
|
// Certain entities shouldn't drop twice the amount
|
||||||
|
if (livingEntity instanceof Player ||
|
||||||
|
livingEntity instanceof ArmorStand ||
|
||||||
|
livingEntity instanceof Horse ||
|
||||||
|
livingEntity instanceof Donkey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (livingEntity.hasMetadata("SkyBlock")) {
|
if (livingEntity.hasMetadata("SkyBlock")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1530,7 +1530,7 @@ Menu:
|
|||||||
Claimable:
|
Claimable:
|
||||||
Lore:
|
Lore:
|
||||||
- "&7Increases loot drops two times"
|
- "&7Increases loot drops two times"
|
||||||
- "&7the speed at your Island."
|
- "&7the amount at your Island."
|
||||||
- ""
|
- ""
|
||||||
- "&7Drops&8: &f2x"
|
- "&7Drops&8: &f2x"
|
||||||
- "&7Cost&8: &f$%cost"
|
- "&7Cost&8: &f$%cost"
|
||||||
@ -1541,7 +1541,7 @@ Menu:
|
|||||||
Unclaimable:
|
Unclaimable:
|
||||||
Lore:
|
Lore:
|
||||||
- "&7Increases loot drops two times"
|
- "&7Increases loot drops two times"
|
||||||
- "&7the speed at your Island."
|
- "&7the amount at your Island."
|
||||||
- ""
|
- ""
|
||||||
- "&7Drops&8: &f2x"
|
- "&7Drops&8: &f2x"
|
||||||
- "&7Cost&8: &f$%cost"
|
- "&7Cost&8: &f$%cost"
|
||||||
@ -1552,7 +1552,7 @@ Menu:
|
|||||||
Claimed:
|
Claimed:
|
||||||
Lore:
|
Lore:
|
||||||
- "&7Increases loot drops two times"
|
- "&7Increases loot drops two times"
|
||||||
- "&7the speed at your Island."
|
- "&7the amount at your Island."
|
||||||
- ""
|
- ""
|
||||||
- "&7Drops&8: &f2x"
|
- "&7Drops&8: &f2x"
|
||||||
- "&7Cost&8: &f$%cost"
|
- "&7Cost&8: &f$%cost"
|
||||||
|
Loading…
Reference in New Issue
Block a user