Misc island permission bug fixes, portal event bug fix

This commit is contained in:
Esophose 2019-05-25 23:55:07 -06:00
parent 4214c60fe3
commit 95e3eab883
5 changed files with 46 additions and 52 deletions

View File

@ -824,14 +824,6 @@ public class Island {
return unlocked;
}
public boolean isLocationWithinIsland(IslandWorld world, Location location) {
Location islandLocation = this.getLocation(world, IslandEnvironment.Island).clone().add(0.5, 0, 0.5);
double size = this.getRadius();
size += size % 2 == 0 ? 1 : 0;
return LocationUtil.isLocationAtLocationRadius(location, islandLocation, size);
}
public me.goodandevil.skyblock.api.island.Island getAPIWrapper() {
return apiWrapper;
}

View File

@ -1342,6 +1342,10 @@ public class IslandManager {
}
public boolean isLocationAtIsland(Island island, org.bukkit.Location location, IslandWorld world) {
return LocationUtil.isLocationAtLocationRadius(location, island.getLocation(world, IslandEnvironment.Island), island.getRadius());
Location islandLocation = island.getLocation(world, IslandEnvironment.Island).clone().add(0.5, 0, 0.5);
double size = island.getRadius();
size += size % 2 == 0 ? 1 : 0;
return LocationUtil.isLocationAtLocationRadius(location, islandLocation, size);
}
}

View File

@ -17,6 +17,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.EntityType;
@ -187,7 +188,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.WorldBorder.Block") && block.getType() == Material.DISPENSER) {
if (!island.isLocationWithinIsland(world, block.getLocation())) {
if (!islandManager.isLocationAtIsland(island, block.getLocation(), world)) {
event.setCancelled(true);
}
}
@ -268,7 +269,7 @@ public class Block implements Listener {
org.bukkit.block.Block block = event.getToBlock();
// Protect outside of border
if (!island.isLocationWithinIsland(world, block.getLocation())) {
if (!islandManager.isLocationAtIsland(island, block.getLocation(), world)) {
event.setCancelled(true);
return;
}
@ -291,7 +292,7 @@ public class Block implements Listener {
island.hasRole(IslandRole.Member, p.getUniqueId()) ||
island.hasRole(IslandRole.Coop, p.getUniqueId()) ||
island.hasRole(IslandRole.Operator, p.getUniqueId());
if (isMember && island.isLocationWithinIsland(world, p.getLocation())) {
if (isMember && islandManager.isLocationAtIsland(island, p.getLocation(), world)) {
possiblePlayers.add(p);
}
}
@ -334,7 +335,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration();
for (org.bukkit.block.Block block : event.getBlocks()) {
if (!island.isLocationWithinIsland(world, block.getLocation())) {
if (!islandManager.isLocationAtIsland(island, block.getLocation(), world)) {
event.setCancelled(true);
return;
}
@ -390,7 +391,7 @@ public class Block implements Listener {
FileConfiguration configLoad = config.getFileConfiguration();
for (org.bukkit.block.Block block : event.getBlocks()) {
if (!island.isLocationWithinIsland(world, block.getLocation())) {
if (!islandManager.isLocationAtIsland(island, block.getLocation(), world)) {
event.setCancelled(true);
return;
}
@ -466,7 +467,7 @@ public class Block implements Listener {
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
island.hasRole(IslandRole.Operator, player.getUniqueId());
if (isMember && island.isLocationWithinIsland(world, player.getLocation())) {
if (isMember && islandManager.isLocationAtIsland(island, player.getLocation(), world)) {
possiblePlayers.add(player);
}
}
@ -639,39 +640,28 @@ public class Block implements Listener {
IslandWorld world = worldManager.getIslandWorld(event.getBlocks().get(0).getWorld());
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
for (org.bukkit.block.Block block : event.getBlocks()) {
// PortalCreateEvent.getBlocks() changed from ArrayList<Block> to ArrayList<BlockState> in 1.14.1... why...
if (NMSUtil.getVersionNumber() > 13) {
for (BlockState block : event.getBlocks()) {
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
event.setCancelled(true);
return;
}
}
}
@EventHandler
public void onEntityCreatePortal(EntityCreatePortalEvent event) {
WorldManager worldManager = skyblock.getWorldManager();
IslandManager islandManager = skyblock.getIslandManager();
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection"))
return;
if (event.getBlocks().isEmpty())
return;
Island island = islandManager.getIslandAtLocation(event.getBlocks().get(0).getLocation());
if (island == null)
return;
// Check spawn block protection
IslandWorld world = worldManager.getIslandWorld(event.getBlocks().get(0).getWorld());
Location islandLocation = island.getLocation(world, IslandEnvironment.Main);
for (org.bukkit.block.BlockState block : event.getBlocks()) {
} else {
try {
@SuppressWarnings("unchecked")
ArrayList<org.bukkit.block.Block> blocks = (ArrayList<org.bukkit.block.Block>) event.getClass().getMethod("getBlocks").invoke(event);
for (org.bukkit.block.Block block : blocks) {
if (LocationUtil.isLocationAffectingLocation(block.getLocation(), islandLocation)) {
event.setCancelled(true);
return;
}
}
} catch (ReflectiveOperationException ex) {
ex.printStackTrace();
}
}
}
@EventHandler

View File

@ -101,7 +101,7 @@ public class Entity implements Listener {
}
}
// Fix a bug in spigot where arrows with flame still apply flame even if the event is cancelled
// Fix a bug in minecraft where arrows with flame still apply fire ticks even if the shot entity isn't damaged
if (preventFireTicks.contains(player.getUniqueId()) && event.getCause() == DamageCause.FIRE_TICK) {
player.setFireTicks(0);
event.setCancelled(true);
@ -157,8 +157,7 @@ public class Entity implements Listener {
return;
}
if (event.getDamager() instanceof Projectile
&& ((Projectile) event.getDamager()).getShooter() instanceof Player) {
if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player) {
Player player = (Player) ((Projectile) event.getDamager()).getShooter();
org.bukkit.entity.Entity entity = event.getEntity();
@ -167,6 +166,11 @@ public class Entity implements Listener {
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (entity.getType() == EntityType.ITEM_FRAME && !islandManager.hasPermission(player, entity.getLocation(), "HangingDestroy")) {
event.setCancelled(true);
return;
}
if (configLoad.getBoolean("Island.Settings.PvP.Enable")) {
if (!islandManager.hasSetting(entity.getLocation(), IslandRole.Owner, "PvP")) {
event.setCancelled(true);
@ -214,7 +218,7 @@ public class Entity implements Listener {
}
}
// Fix a bug in spigot where arrows with flame still apply flame even if the event is cancelled
// Fix a bug in minecraft where arrows with flame still apply fire ticks even if the shot entity isn't damaged
if (event.isCancelled() && event.getEntity() != null && event.getDamager() instanceof Arrow && ((Arrow)event.getDamager()).getShooter() instanceof Player) {
Arrow arrow = (Arrow) event.getDamager();
if (arrow.getFireTicks() != 0) {

View File

@ -258,7 +258,8 @@ public class Interact implements Listener {
|| block.getType() == Materials.BIRCH_BUTTON.parseMaterial()
|| block.getType() == Materials.JUNGLE_BUTTON.parseMaterial()
|| block.getType() == Materials.ACACIA_BUTTON.parseMaterial()
|| block.getType() == Materials.DARK_OAK_BUTTON.parseMaterial()) {
|| block.getType() == Materials.DARK_OAK_BUTTON.parseMaterial()
|| block.getType() == Materials.LEVER.parseMaterial()) {
if (!islandManager.hasPermission(player, block.getLocation(), "LeverButton")) {
event.setCancelled(true);
@ -468,6 +469,7 @@ public class Interact implements Listener {
}
}
} else if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
// Note: Cast is necessary as it is ambiguous without it in 1.8
if (player.getTargetBlock((Set<Material>) null, 5).getType() == Material.FIRE) {
if (!islandManager.hasPermission(player, block.getLocation(), "Fire")) {
event.setCancelled(true);
@ -479,7 +481,9 @@ public class Interact implements Listener {
}
}
} else if (event.getAction() == Action.PHYSICAL) {
if (block.getType() == Materials.FARMLAND.parseMaterial()) {
if (block.getType() == Materials.TURTLE_EGG.parseMaterial()) {
event.setCancelled(true);
} else if (block.getType() == Materials.FARMLAND.parseMaterial()) {
if (!islandManager.hasPermission(player, block.getLocation(), "Crop")) {
event.setCancelled(true);