Fix generators and armor stands in 1.8

This commit is contained in:
Esophose 2019-02-24 00:06:34 -07:00
parent 4c369b8962
commit e2bb8c6896
2 changed files with 57 additions and 7 deletions

View File

@ -118,7 +118,7 @@ public class Block implements Listener {
block.getWorld().dropItemNaturally(block.getLocation().clone().add(.5, 1, .5), new ItemStack(block.getType())); block.getWorld().dropItemNaturally(block.getLocation().clone().add(.5, 1, .5), new ItemStack(block.getType()));
} }
} }
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
@ -220,6 +220,7 @@ public class Block implements Listener {
public void onBlockFromTo(BlockFromToEvent event) { public void onBlockFromTo(BlockFromToEvent event) {
if (!skyblock.getWorldManager().isIslandWorld(event.getBlock().getWorld())) return; if (!skyblock.getWorldManager().isIslandWorld(event.getBlock().getWorld())) return;
GeneratorManager generatorManager = skyblock.getGeneratorManager();
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
WorldManager worldManager = skyblock.getWorldManager(); WorldManager worldManager = skyblock.getWorldManager();
@ -230,8 +231,43 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (island == null) return; if (island == null) return;
org.bukkit.block.Block block = event.getToBlock(); org.bukkit.block.Block block = event.getToBlock();
if (NMSUtil.getVersionNumber() < 12) {
if (generatorManager != null && generatorManager.getGenerators().size() > 0 && generatorManager.isGenerator(block)) {
List<Generator> generators = new ArrayList<>(generatorManager.getGenerators());
Collections.reverse(generators); // Use the highest generator available
// Filter players on the island
Set<Player> possiblePlayers = new HashSet<>();
for (Player p : Bukkit.getOnlinePlayers()) {
if (LocationUtil.isLocationAtLocationRadius(p.getLocation(), island.getLocation(world, IslandEnvironment.Island), island.getRadius())) {
possiblePlayers.add(p);
}
}
// Find highest generator available
for (Generator generator : generators) {
for (Player p : possiblePlayers) {
if (generator.isPermission()) {
if (!p.hasPermission(generator.getPermission())
&& !p.hasPermission("fabledskyblock.generator.*")
&& !p.hasPermission("fabledskyblock.*")) {
continue;
}
}
event.setCancelled(true);
generatorManager.generateBlock(generator, block);
return;
}
}
}
return;
}
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(), if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(),
island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 1.0D)) { island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 1.0D)) {
event.setCancelled(true); event.setCancelled(true);

View File

@ -7,6 +7,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
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;
@ -30,17 +31,15 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent; import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.hanging.HangingBreakEvent;
import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause;
import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerShearEntityEvent; import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -55,6 +54,7 @@ import me.goodandevil.skyblock.island.IslandRole;
import me.goodandevil.skyblock.island.IslandWorld; import me.goodandevil.skyblock.island.IslandWorld;
import me.goodandevil.skyblock.message.MessageManager; import me.goodandevil.skyblock.message.MessageManager;
import me.goodandevil.skyblock.sound.SoundManager; import me.goodandevil.skyblock.sound.SoundManager;
import me.goodandevil.skyblock.stackable.StackableManager;
import me.goodandevil.skyblock.upgrade.Upgrade; import me.goodandevil.skyblock.upgrade.Upgrade;
import me.goodandevil.skyblock.utils.version.Materials; import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.utils.version.NMSUtil; import me.goodandevil.skyblock.utils.version.NMSUtil;
@ -261,6 +261,22 @@ public class Entity implements Listener {
} }
} }
} }
@EventHandler
public void onStackableInteract(PlayerArmorStandManipulateEvent event) {
if (NMSUtil.getVersionNumber() != 8)
return;
StackableManager stackableManager = SkyBlock.getInstance().getStackableManager();
ArmorStand armorStand = event.getRightClicked();
for (Location stackLocation : stackableManager.getStacks().keySet()) {
if (stackLocation.getWorld().equals(armorStand.getWorld()) && armorStand.getLocation().distanceSquared(stackLocation) <= 1.5) {
event.setCancelled(true);
return;
}
}
}
@EventHandler @EventHandler
public void onHangingPlace(HangingPlaceEvent event) { public void onHangingPlace(HangingPlaceEvent event) {
@ -415,8 +431,6 @@ public class Entity implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
if (island == null) return;
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.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();