mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-09 17:27:37 +01:00
Generators unlockLevel and update older versions to the new generator system
This commit is contained in:
parent
70fdd5ab88
commit
551af02570
@ -7,17 +7,19 @@ import java.util.List;
|
||||
|
||||
public class Generator {
|
||||
|
||||
private String name;
|
||||
private IslandWorld isWorld;
|
||||
private CompatibleMaterial materials;
|
||||
private List<GeneratorMaterial> generatorMaterials;
|
||||
private final String name;
|
||||
private final IslandWorld isWorld;
|
||||
private final CompatibleMaterial materials;
|
||||
private final List<GeneratorMaterial> generatorMaterials;
|
||||
private final long level;
|
||||
private boolean permission;
|
||||
|
||||
public Generator(String name, IslandWorld isWorld, CompatibleMaterial materials, List<GeneratorMaterial> generatorMaterials, boolean permission) {
|
||||
public Generator(String name, IslandWorld isWorld, CompatibleMaterial materials, List<GeneratorMaterial> generatorMaterials, long level, boolean permission) {
|
||||
this.name = name;
|
||||
this.isWorld = isWorld;
|
||||
this.materials = materials;
|
||||
this.generatorMaterials = generatorMaterials;
|
||||
this.level = level;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
@ -48,4 +50,8 @@ public class Generator {
|
||||
public void setPermission(boolean permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public long getLevel() {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import java.util.Random;
|
||||
public class GeneratorManager {
|
||||
|
||||
private final SkyBlock plugin;
|
||||
private List<Generator> generatorStorage = new ArrayList<>();
|
||||
private final List<Generator> generatorStorage = new ArrayList<>();
|
||||
|
||||
public GeneratorManager(SkyBlock plugin) {
|
||||
this.plugin = plugin;
|
||||
@ -62,6 +62,7 @@ public class GeneratorManager {
|
||||
generatorStorage.add(new Generator(configLoad.getString("Generators." + generatorList + ".Name"),
|
||||
IslandWorld.valueOf(configLoad.getString("Generators." + generatorList + ".World", "Normal")),
|
||||
icon, generatorMaterials,
|
||||
configLoad.getLong("Generators." + generatorList + ".UnlockLevel", 0L),
|
||||
configLoad.getBoolean("Generators." + generatorList + ".Permission")));
|
||||
}
|
||||
}
|
||||
@ -155,11 +156,11 @@ public class GeneratorManager {
|
||||
return CompatibleMaterial.COBBLESTONE;
|
||||
}
|
||||
|
||||
public void addGenerator(String name, IslandWorld isWorld, List<GeneratorMaterial> generatorMaterials, boolean permission) {
|
||||
public void addGenerator(String name, IslandWorld isWorld, List<GeneratorMaterial> generatorMaterials, int level, boolean permission) {
|
||||
CompatibleMaterial[] oreMaterials = new CompatibleMaterial[]{CompatibleMaterial.COAL, CompatibleMaterial.CHARCOAL, CompatibleMaterial.DIAMOND,
|
||||
CompatibleMaterial.IRON_INGOT, CompatibleMaterial.GOLD_INGOT, CompatibleMaterial.EMERALD};
|
||||
generatorStorage.add(new Generator(name, isWorld, oreMaterials[new Random().nextInt(oreMaterials.length)],
|
||||
generatorMaterials, permission));
|
||||
generatorMaterials, level, permission));
|
||||
}
|
||||
|
||||
public void removeGenerator(Generator generator) {
|
||||
|
@ -405,41 +405,98 @@ public class Block implements Listener {
|
||||
}
|
||||
|
||||
// Generators
|
||||
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 valid players on the island
|
||||
Set<Player> possiblePlayers = new HashSet<>();
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
boolean isMember = island.hasRole(IslandRole.Owner, p.getUniqueId()) || island.hasRole(IslandRole.Member, p.getUniqueId()) || island.hasRole(IslandRole.Coop, p.getUniqueId())
|
||||
|| island.hasRole(IslandRole.Operator, p.getUniqueId());
|
||||
if (isMember && islandManager.isLocationAtIsland(island, p.getLocation(), world)) {
|
||||
possiblePlayers.add(p);
|
||||
}
|
||||
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);
|
||||
|
||||
if(nearestPlayer){
|
||||
possiblePlayers.sort(Comparator.comparingDouble(a -> a.getLocation().distance(block.getLocation())));
|
||||
}
|
||||
|
||||
boolean onlyOwner = configLoad.getBoolean("Island.Generator.CheckOnlyOwnerPermissions", false);
|
||||
|
||||
double distance = possiblePlayers.get(0).getLocation().distance(block.getLocation());
|
||||
// Find highest generator available
|
||||
for (Generator generator : generators) {
|
||||
if(generator.getIsWorld().equals(world)){
|
||||
for (Player p : possiblePlayers) {
|
||||
|
||||
if (generator.isPermission() &&
|
||||
!p.hasPermission(generator.getPermission()) &&
|
||||
!p.hasPermission("fabledskyblock.generator.*") &&
|
||||
!p.hasPermission("fabledskyblock.*")) {
|
||||
continue;
|
||||
if(island.getLevel().getLevel() >= generator.getLevel()) {
|
||||
if(onlyOwner && plugin.getVaultPermission() != null) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||
event.setCancelled(true);
|
||||
org.bukkit.World finalWorld = event.getBlock().getWorld();
|
||||
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, () -> {
|
||||
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;
|
||||
}
|
||||
|
||||
org.bukkit.block.BlockState genState = generatorManager.generateBlock(generator, block);
|
||||
org.bukkit.block.BlockState toBlockState = event.getToBlock().getState();
|
||||
|
||||
toBlockState.setData(genState.getData());
|
||||
toBlockState.setType(genState.getType());
|
||||
toBlockState.update();
|
||||
islandLevelManager.updateLevel(island, genState.getLocation());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -624,6 +681,7 @@ public class Block implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
// Generators
|
||||
CompatibleMaterial material = CompatibleMaterial.getMaterial(block);
|
||||
if (material != CompatibleMaterial.WATER
|
||||
&& material != CompatibleMaterial.LAVA)
|
||||
@ -674,46 +732,48 @@ public class Block implements Listener {
|
||||
double distance = possiblePlayers.get(0).getLocation().distance(block.getLocation());
|
||||
// Find highest generator available
|
||||
for (Generator generator : generators) {
|
||||
if(onlyOwner && plugin.getVaultPermission() != null) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||
event.setCancelled(true);
|
||||
org.bukkit.World finalWorld = event.getBlock().getWorld();
|
||||
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, () -> {
|
||||
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);
|
||||
if(island.getLevel().getLevel() >= generator.getLevel()) {
|
||||
if(onlyOwner && plugin.getVaultPermission() != null) {
|
||||
OfflinePlayer owner = Bukkit.getServer().getOfflinePlayer(island.getOwnerUUID());
|
||||
event.setCancelled(true);
|
||||
org.bukkit.World finalWorld = event.getBlock().getWorld();
|
||||
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, () -> {
|
||||
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());
|
||||
}
|
||||
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;
|
||||
});
|
||||
} 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 (applyGenerator(event.getBlock().getWorld(), block, worldManager, islandLevelManager, island, state, generatorManager, generator))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ Generators:
|
||||
Name: Normal
|
||||
World: Normal
|
||||
Permission: false
|
||||
UnlockLevel: 0
|
||||
Materials:
|
||||
COBBLESTONE:
|
||||
Chance: 60
|
||||
@ -20,6 +21,7 @@ Generators:
|
||||
Name: Nether
|
||||
World: Nether
|
||||
Permission: false
|
||||
UnlockLevel: 0
|
||||
Materials:
|
||||
NETHERRACK:
|
||||
Chance: 80
|
||||
@ -31,6 +33,7 @@ Generators:
|
||||
Name: End
|
||||
World: End
|
||||
Permission: false
|
||||
UnlockLevel: 0
|
||||
Materials:
|
||||
END_STONE:
|
||||
Chance: 100.0
|
Loading…
Reference in New Issue
Block a user