mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-25 08:51:33 +01:00
Added more config to Generator player permission check
This commit is contained in:
parent
8fedcb00c2
commit
642c64981a
@ -552,11 +552,13 @@ public class Block implements Listener {
|
|||||||
WorldManager worldManager = skyblock.getWorldManager();
|
WorldManager worldManager = skyblock.getWorldManager();
|
||||||
IslandLevelManager islandLevelManager = skyblock.getLevellingManager();
|
IslandLevelManager islandLevelManager = skyblock.getLevellingManager();
|
||||||
|
|
||||||
|
FileConfiguration config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration();
|
||||||
|
|
||||||
if (!worldManager.isIslandWorld(block.getWorld())) return;
|
if (!worldManager.isIslandWorld(block.getWorld())) return;
|
||||||
|
|
||||||
// Check ice/snow forming
|
// Check ice/snow forming
|
||||||
if (block.getType() == Material.ICE || block.getType() == Material.SNOW) {
|
if (block.getType() == Material.ICE || block.getType() == Material.SNOW) {
|
||||||
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Weather.IceAndSnow"))
|
if (!config.getBoolean("Island.Weather.IceAndSnow"))
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -594,37 +596,52 @@ public class Block implements Listener {
|
|||||||
|
|
||||||
Collections.reverse(generators); // Use the highest generator available
|
Collections.reverse(generators); // Use the highest generator available
|
||||||
|
|
||||||
|
boolean ignoreVisitors = config.getBoolean("Island.Generator.IgnoreVisitors", false);
|
||||||
|
|
||||||
// Filter valid players on the island.
|
// Filter valid players on the island.
|
||||||
Set<Player> possiblePlayers = new HashSet<>();
|
List<Player> possiblePlayers = new ArrayList<>();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
boolean isMember = island.hasRole(IslandRole.Owner, player.getUniqueId()) ||
|
boolean isMember = island.hasRole(IslandRole.Owner, player.getUniqueId()) ||
|
||||||
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
|
island.hasRole(IslandRole.Member, player.getUniqueId()) ||
|
||||||
island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
|
island.hasRole(IslandRole.Coop, player.getUniqueId()) ||
|
||||||
island.hasRole(IslandRole.Operator, player.getUniqueId()) ||
|
island.hasRole(IslandRole.Operator, player.getUniqueId()) ||
|
||||||
(island.getVisit().getVisitors().contains(player.getUniqueId()) &&
|
(island.getVisit().getVisitors().contains(player.getUniqueId()) &&
|
||||||
player.hasPermission("fabledskyblock.generator.anywhere"));
|
player.hasPermission("fabledskyblock.generator.anywhere") &&
|
||||||
|
!ignoreVisitors);
|
||||||
|
|
||||||
if (isMember && islandManager.isLocationAtIsland(island, player.getLocation(), world)) {
|
if (isMember && islandManager.isLocationAtIsland(island, player.getLocation(), world)) {
|
||||||
possiblePlayers.add(player);
|
possiblePlayers.add(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find highest generator available
|
if(!possiblePlayers.isEmpty()){
|
||||||
for (Generator generator : generators) {
|
boolean nearestPlayer = config.getBoolean("Island.Generator.CheckOnlyNearestPlayer", false);
|
||||||
for (Player player : possiblePlayers) {
|
|
||||||
if (generator.isPermission()) {
|
if(nearestPlayer){
|
||||||
if (!player.hasPermission(generator.getPermission()) && !player.hasPermission("fabledskyblock.generator.*") && !player.hasPermission("fabledskyblock.*")) {
|
possiblePlayers.sort(Comparator.comparingDouble(a -> a.getLocation().distance(block.getLocation())));
|
||||||
continue;
|
}
|
||||||
|
|
||||||
|
double distance = possiblePlayers.get(0).getLocation().distance(block.getLocation());
|
||||||
|
// Find highest generator available
|
||||||
|
for (Generator generator : generators) {
|
||||||
|
for (Player player : possiblePlayers) {
|
||||||
|
if(player.getLocation().distance(block.getLocation()) > distance){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (generator.isPermission()) {
|
||||||
|
if (!player.hasPermission(generator.getPermission()) && !player.hasPermission("fabledskyblock.generator.*") && !player.hasPermission("fabledskyblock.*")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(worldManager.getIslandWorld(event.getBlock().getWorld()).equals(generator.getIsWorld())){
|
||||||
|
org.bukkit.block.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;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(worldManager.getIslandWorld(event.getBlock().getWorld()).equals(generator.getIsWorld())){
|
|
||||||
org.bukkit.block.BlockState genState = generatorManager.generateBlock(generator, block);
|
|
||||||
state.setType(genState.getType());
|
|
||||||
|
|
||||||
if (NMSUtil.getVersionNumber() < 13) state.setData(genState.getData());
|
|
||||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,6 +319,11 @@ Island:
|
|||||||
Enable: true
|
Enable: true
|
||||||
Generator:
|
Generator:
|
||||||
Enable: true
|
Enable: true
|
||||||
|
# Check permissions of all the online player in the island or just
|
||||||
|
# the nearest player to the generator
|
||||||
|
CheckOnlyNearestPlayer: false
|
||||||
|
# Ignore visitors in permission check, also who has "fabledskyblock.generator.anywhere" permission
|
||||||
|
IgnoreVisitors: false
|
||||||
Stackable:
|
Stackable:
|
||||||
Enable: true
|
Enable: true
|
||||||
# fabledskyblock.stackables
|
# fabledskyblock.stackables
|
||||||
|
Loading…
Reference in New Issue
Block a user