mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-07 03:00:29 +01:00
Fix generators on 1.11.2-
This commit is contained in:
parent
d194f0a525
commit
016f7a0ec2
@ -5,10 +5,14 @@ import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.skyblock.SkyBlock;
|
||||
import com.songoda.skyblock.config.FileManager.Config;
|
||||
import com.songoda.skyblock.generator.Generator;
|
||||
import com.songoda.skyblock.generator.GeneratorManager;
|
||||
import com.songoda.skyblock.island.*;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandEnvironment;
|
||||
import com.songoda.skyblock.island.IslandLevel;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.island.IslandRole;
|
||||
import com.songoda.skyblock.island.IslandWorld;
|
||||
import com.songoda.skyblock.levelling.IslandLevelManager;
|
||||
import com.songoda.skyblock.limit.impl.BlockLimitation;
|
||||
import com.songoda.skyblock.permission.PermissionManager;
|
||||
@ -20,12 +24,16 @@ import com.songoda.skyblock.utils.version.NMSUtil;
|
||||
import com.songoda.skyblock.utils.world.LocationUtil;
|
||||
import com.songoda.skyblock.world.WorldManager;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Effect;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.block.Block;
|
||||
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.Entity;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -34,8 +42,15 @@ import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.world.PortalCreateEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BlockListeners implements Listener {
|
||||
|
||||
@ -433,109 +448,10 @@ public class BlockListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_12)) {
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
if (material != CompatibleMaterial.WATER
|
||||
&& material != CompatibleMaterial.LAVA)
|
||||
return;
|
||||
|
||||
BlockState state = event.getToBlock().getState();
|
||||
Material type = state.getType();
|
||||
|
||||
if (type != Material.COBBLESTONE && type != Material.STONE) return;
|
||||
|
||||
if (generatorManager == null) return;
|
||||
|
||||
List<Generator> generators = Lists.newArrayList(generatorManager.getGenerators());
|
||||
|
||||
if (generators.isEmpty()) return;
|
||||
|
||||
Collections.reverse(generators); // Use the highest generator available
|
||||
|
||||
boolean ignoreVisitors = configLoad.getBoolean("Island.Generator.IgnoreVisitors", false);
|
||||
|
||||
// Filter valid players on the island.
|
||||
List<Player> possiblePlayers = new ArrayList<>();
|
||||
Set<UUID> visitors = island.getVisit().getVisitors();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
boolean isMember = island.hasRole(IslandRole.Owner, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Operator, player.getUniqueId()) ||
|
||||
(!ignoreVisitors &&
|
||||
visitors.contains(player.getUniqueId()) &&
|
||||
player.hasPermission("fabledskyblock.generator.anywhere"));
|
||||
|
||||
if (isMember && islandManager.isLocationAtIsland(island, player.getLocation(), world)) {
|
||||
possiblePlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
if(!possiblePlayers.isEmpty()){
|
||||
boolean nearestPlayer = configLoad.getBoolean("Island.Generator.CheckOnlyNearestPlayer", false);
|
||||
double distance = possiblePlayers.get(0).getLocation().distance(block.getLocation());
|
||||
boolean onlyOwner = configLoad.getBoolean("Island.Generator.CheckOnlyOwnerPermissions", false);
|
||||
|
||||
if(nearestPlayer){
|
||||
possiblePlayers.sort(Comparator.comparingDouble(a -> a.getLocation().distance(block.getLocation())));
|
||||
}
|
||||
|
||||
// Find highest generator available
|
||||
for (Generator generator : generators) {
|
||||
if(island.getLevel().getLevel() >= generator.getLevel()) {
|
||||
if(onlyOwner && plugin.getVaultPermission() != null) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||
if(owner.isOnline()) {
|
||||
Player onlineOwner = (Player) owner;
|
||||
if(onlineOwner.hasPermission(generator.getPermission())) {
|
||||
applyGenerator(event.getBlock().getWorld(), block, worldManager, islandLevelManager, island, state, generatorManager, generator);
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
org.bukkit.World finalWorld = event.getBlock().getWorld();
|
||||
this.generatorWaitingLocs.add(LocationUtil.toBlockLocation(block.getLocation().clone()));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
if(plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, generator.getPermission())) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
this.generatorWaitingLocs.remove(LocationUtil.toBlockLocation(block.getLocation().clone()));
|
||||
if(worldManager.getIslandWorld(finalWorld).equals(generator.getIsWorld())){
|
||||
BlockState genState = generatorManager.generateBlock(generator, block);
|
||||
block.setType(genState.getType());
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
|
||||
BlockState tempState = block.getState();
|
||||
tempState.setData(genState.getData());
|
||||
tempState.update(true, true);
|
||||
}
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
block.setType(CompatibleMaterial.COBBLESTONE.getMaterial());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (Player player : possiblePlayers) {
|
||||
if(nearestPlayer && player.getLocation().distance(block.getLocation()) > distance){
|
||||
break;
|
||||
}
|
||||
if (generator.isPermission()) {
|
||||
if (!player.hasPermission(generator.getPermission()) && !player.hasPermission("fabledskyblock.generator.*") && !player.hasPermission("fabledskyblock.*")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (applyGenerator(event.getBlock().getWorld(), block, worldManager, islandLevelManager, island, state, generatorManager, generator))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_12))
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||
handleGeneration(block, island, event.getToBlock().getState());
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -686,7 +602,6 @@ public class BlockListeners implements Listener {
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
org.bukkit.block.Block block = event.getBlock();
|
||||
WorldManager worldManager = plugin.getWorldManager();
|
||||
IslandLevelManager islandLevelManager = plugin.getLevellingManager();
|
||||
|
||||
FileConfiguration config = this.plugin.getConfiguration();
|
||||
|
||||
@ -712,126 +627,8 @@ public class BlockListeners implements Listener {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Generators
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
if (material != CompatibleMaterial.WATER
|
||||
&& material != CompatibleMaterial.LAVA)
|
||||
return;
|
||||
|
||||
BlockState state = event.getNewState();
|
||||
Material type = state.getType();
|
||||
|
||||
if (type != Material.COBBLESTONE && type != Material.STONE) return;
|
||||
|
||||
GeneratorManager generatorManager = plugin.getGeneratorManager();
|
||||
if (generatorManager == null) return;
|
||||
|
||||
List<Generator> generators = Lists.newArrayList(generatorManager.getGenerators());
|
||||
|
||||
if (generators.isEmpty()) return;
|
||||
|
||||
Collections.reverse(generators); // Use the highest generator available
|
||||
|
||||
boolean ignoreVisitors = config.getBoolean("Island.Generator.IgnoreVisitors", false);
|
||||
|
||||
// Filter valid players on the island.
|
||||
List<Player> possiblePlayers = new ArrayList<>();
|
||||
Set<UUID> visitors = island.getVisit().getVisitors();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
boolean isMember = island.hasRole(IslandRole.Owner, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Operator, player.getUniqueId()) ||
|
||||
(!ignoreVisitors &&
|
||||
visitors.contains(player.getUniqueId()) &&
|
||||
player.hasPermission("fabledskyblock.generator.anywhere"));
|
||||
|
||||
if (isMember && islandManager.isLocationAtIsland(island, player.getLocation(), world)) {
|
||||
possiblePlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
if(!possiblePlayers.isEmpty()){
|
||||
boolean nearestPlayer = config.getBoolean("Island.Generator.CheckOnlyNearestPlayer", false);
|
||||
|
||||
if(nearestPlayer){
|
||||
possiblePlayers.sort(Comparator.comparingDouble(a -> a.getLocation().distance(block.getLocation())));
|
||||
}
|
||||
|
||||
boolean onlyOwner = config.getBoolean("Island.Generator.CheckOnlyOwnerPermissions", false);
|
||||
|
||||
double distance = possiblePlayers.get(0).getLocation().distance(block.getLocation());
|
||||
// Find highest generator available
|
||||
for (Generator generator : generators) {
|
||||
if(island.getLevel().getLevel() >= generator.getLevel()) {
|
||||
if(onlyOwner && plugin.getVaultPermission() != null) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||
if(owner.isOnline()) {
|
||||
Player onlineOwner = (Player) owner;
|
||||
if(onlineOwner.hasPermission(generator.getPermission())) {
|
||||
applyGenerator(event.getBlock().getWorld(), block, worldManager, islandLevelManager, island, state, generatorManager, generator);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (handleGeneration(block, island, event.getNewState()))
|
||||
event.setCancelled(true);
|
||||
org.bukkit.World finalWorld = event.getBlock().getWorld();
|
||||
this.generatorWaitingLocs.add(LocationUtil.toBlockLocation(block.getLocation().clone()));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
if (plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, generator.getPermission()) ||
|
||||
plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, "fabledskyblock.generator.*") ||
|
||||
plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, "fabledskyblock.*")) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
this.generatorWaitingLocs.remove(LocationUtil.toBlockLocation(block.getLocation().clone()));
|
||||
if (worldManager.getIslandWorld(finalWorld).equals(generator.getIsWorld())) {
|
||||
BlockState genState = generatorManager.generateBlock(generator, block);
|
||||
block.setType(genState.getType());
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
|
||||
BlockState tempState = block.getState();
|
||||
tempState.setData(genState.getData());
|
||||
tempState.update(true, true);
|
||||
}
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
block.setType(CompatibleMaterial.COBBLESTONE.getMaterial());
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (Player player : possiblePlayers) {
|
||||
if(nearestPlayer && player.getLocation().distance(block.getLocation()) > distance){
|
||||
break;
|
||||
}
|
||||
if (generator.isPermission()) {
|
||||
if (!player.hasPermission(generator.getPermission()) && !player.hasPermission("fabledskyblock.generator.*") && !player.hasPermission("fabledskyblock.*")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (applyGenerator(event.getBlock().getWorld(), block, worldManager, islandLevelManager, island, state, generatorManager, generator))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean applyGenerator(org.bukkit.World world, org.bukkit.block.Block block, WorldManager worldManager, IslandLevelManager islandLevelManager, Island island, BlockState state, GeneratorManager generatorManager, Generator generator) {
|
||||
if(worldManager.getIslandWorld(world).equals(generator.getIsWorld())){
|
||||
BlockState genState = generatorManager.generateBlock(generator, block);
|
||||
state.setType(genState.getType());
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) state.setData(genState.getData());
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
@ -972,4 +769,131 @@ public class BlockListeners implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleGeneration(Block block, Island island, BlockState state) {
|
||||
WorldManager worldManager = plugin.getWorldManager();
|
||||
IslandLevelManager islandLevelManager = plugin.getLevellingManager();
|
||||
FileConfiguration config = this.plugin.getConfiguration();
|
||||
IslandManager islandManager = plugin.getIslandManager();
|
||||
IslandWorld world = worldManager.getIslandWorld(block.getWorld());
|
||||
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)
|
||||
&& material != CompatibleMaterial.WATER
|
||||
&& material != CompatibleMaterial.LAVA)
|
||||
return false;
|
||||
|
||||
Material type = state.getType();
|
||||
|
||||
if (type != Material.COBBLESTONE && type != Material.STONE) return false;
|
||||
|
||||
GeneratorManager generatorManager = plugin.getGeneratorManager();
|
||||
if (generatorManager == null) return false;
|
||||
|
||||
List<Generator> generators = Lists.newArrayList(generatorManager.getGenerators());
|
||||
|
||||
if (generators.isEmpty()) return false;
|
||||
|
||||
Collections.reverse(generators); // Use the highest generator available
|
||||
|
||||
boolean ignoreVisitors = config.getBoolean("Island.Generator.IgnoreVisitors", false);
|
||||
|
||||
// Filter valid players on the island.
|
||||
List<Player> possiblePlayers = new ArrayList<>();
|
||||
Set<UUID> visitors = island.getVisit().getVisitors();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
boolean isMember = island.hasRole(IslandRole.Owner, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
|
||||
island.hasRole(IslandRole.Operator, player.getUniqueId()) ||
|
||||
(!ignoreVisitors &&
|
||||
visitors.contains(player.getUniqueId()) &&
|
||||
player.hasPermission("fabledskyblock.generator.anywhere"));
|
||||
|
||||
if (isMember && islandManager.isLocationAtIsland(island, player.getLocation(), world)) {
|
||||
possiblePlayers.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!possiblePlayers.isEmpty()) {
|
||||
boolean nearestPlayer = config.getBoolean("Island.Generator.CheckOnlyNearestPlayer", false);
|
||||
|
||||
if (nearestPlayer) {
|
||||
possiblePlayers.sort(Comparator.comparingDouble(a -> a.getLocation().distance(block.getLocation())));
|
||||
}
|
||||
|
||||
boolean onlyOwner = config.getBoolean("Island.Generator.CheckOnlyOwnerPermissions", false);
|
||||
|
||||
double distance = possiblePlayers.get(0).getLocation().distance(block.getLocation());
|
||||
// Find highest generator available
|
||||
for (Generator generator : generators) {
|
||||
if (island.getLevel().getLevel() < generator.getLevel()) continue;
|
||||
if (onlyOwner && plugin.getVaultPermission() != null) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||
if (owner.isOnline()) {
|
||||
Player onlineOwner = (Player) owner;
|
||||
if (onlineOwner.hasPermission(generator.getPermission())) {
|
||||
applyGenerator(block, worldManager, islandLevelManager, island, state, generatorManager, generator);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
org.bukkit.World finalWorld = block.getWorld();
|
||||
this.generatorWaitingLocs.add(LocationUtil.toBlockLocation(block.getLocation().clone()));
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
if (plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, generator.getPermission()) ||
|
||||
plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, "fabledskyblock.generator.*") ||
|
||||
plugin.getVaultPermission().playerHas(block.getWorld().getName(), owner, "fabledskyblock.*")) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
this.generatorWaitingLocs.remove(LocationUtil.toBlockLocation(block.getLocation().clone()));
|
||||
|
||||
if (!worldManager.getIslandWorld(finalWorld).equals(generator.getIsWorld()))
|
||||
return;
|
||||
|
||||
BlockState genState = generatorManager.generateBlock(generator, block);
|
||||
block.setType(genState.getType());
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
|
||||
BlockState tempState = block.getState();
|
||||
tempState.setData(genState.getData());
|
||||
tempState.update(true, true);
|
||||
}
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
});
|
||||
} else {
|
||||
Bukkit.getScheduler().runTask(plugin, () ->
|
||||
block.setType(CompatibleMaterial.COBBLESTONE.getMaterial()));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
for (Player player : possiblePlayers) {
|
||||
if (nearestPlayer && player.getLocation().distance(block.getLocation()) > distance) {
|
||||
break;
|
||||
}
|
||||
if (generator.isPermission()) {
|
||||
if (!player.hasPermission(generator.getPermission()) && !player.hasPermission("fabledskyblock.generator.*") && !player.hasPermission("fabledskyblock.*")) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (applyGenerator(block, worldManager, islandLevelManager, island, state, generatorManager, generator))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean applyGenerator(org.bukkit.block.Block block, WorldManager worldManager, IslandLevelManager islandLevelManager, Island island, BlockState state, GeneratorManager generatorManager, Generator generator) {
|
||||
if (worldManager.getIslandWorld(block.getWorld()).equals(generator.getIsWorld())) {
|
||||
BlockState genState = generatorManager.generateBlock(generator, block);
|
||||
state.setType(genState.getType());
|
||||
|
||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) state.setData(genState.getData());
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user