Stackables permission, block limits fixes, wildstacker level support

This commit is contained in:
Esophose 2019-06-22 19:54:42 -06:00
parent 9191f99f2d
commit 807cd45b60
9 changed files with 80 additions and 42 deletions

View File

@ -9,6 +9,7 @@ import me.goodandevil.skyblock.hologram.HologramManager;
import me.goodandevil.skyblock.hologram.HologramType; import me.goodandevil.skyblock.hologram.HologramType;
import me.goodandevil.skyblock.leaderboard.LeaderboardManager; import me.goodandevil.skyblock.leaderboard.LeaderboardManager;
import me.goodandevil.skyblock.levelling.LevellingManager; import me.goodandevil.skyblock.levelling.LevellingManager;
import me.goodandevil.skyblock.limit.LimitManager;
import me.goodandevil.skyblock.message.MessageManager; import me.goodandevil.skyblock.message.MessageManager;
import me.goodandevil.skyblock.scoreboard.ScoreboardManager; import me.goodandevil.skyblock.scoreboard.ScoreboardManager;
import me.goodandevil.skyblock.sound.SoundManager; import me.goodandevil.skyblock.sound.SoundManager;
@ -39,13 +40,14 @@ public class ReloadCommand extends SubCommand {
HologramManager hologramManager = skyblock.getHologramManager(); HologramManager hologramManager = skyblock.getHologramManager();
MessageManager messageManager = skyblock.getMessageManager(); MessageManager messageManager = skyblock.getMessageManager();
SoundManager soundManager = skyblock.getSoundManager(); SoundManager soundManager = skyblock.getSoundManager();
LimitManager limitManager = skyblock.getLimitManager();
FileManager fileManager = skyblock.getFileManager(); FileManager fileManager = skyblock.getFileManager();
messageManager.sendMessage(sender, "&cPlease note that this command is not supported and may " + messageManager.sendMessage(sender, "&cPlease note that this command is not supported and may " +
"cause issues that could put the plugin in an unstable state. " + "cause issues that could put the plugin in an unstable state. " +
"If you encounter any issues please stop your server, edit the configuration files, " + "If you encounter any issues please stop your server, edit the configuration files, " +
"and then start your server again. This command does NOT reload all the plugin files, only " + "and then start your server again. This command does NOT reload all the plugin files, only " +
"the config.yml, language.yml, generators.yml, and levelling.yml."); "the config.yml, language.yml, generators.yml, levelling.yml, and limits.yml.");
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
@ -94,6 +96,8 @@ public class ReloadCommand extends SubCommand {
hologramManager.resetHologram(); hologramManager.resetHologram();
limitManager.reload();
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Reload.Reloaded.Message")); messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Reload.Reloaded.Message"));
soundManager.playSound(sender, Sounds.ANVIL_USE.bukkitSound(), 1.0F, 1.0F); soundManager.playSound(sender, Sounds.ANVIL_USE.bukkitSound(), 1.0F, 1.0F);
} }

View File

@ -1226,18 +1226,18 @@ public class IslandManager {
if (isFlyUpgradeEnabled) { if (isFlyUpgradeEnabled) {
boolean upgradeEnabled = island != null && island.isUpgrade(Upgrade.Type.Fly); boolean upgradeEnabled = island != null && island.isUpgrade(Upgrade.Type.Fly);
setPlayerFlying = upgradeEnabled; setPlayerFlying = upgradeEnabled;
Bukkit.getServer().getScheduler().runTask(skyblock, () -> { Bukkit.getServer().getScheduler().runTask(skyblock, () -> player.setAllowFlight(upgradeEnabled));
player.setAllowFlight(upgradeEnabled);
});
} }
boolean hasFlyPermission = player.hasPermission("fabledskyblock.fly") || player.hasPermission("fabledskyblock.*"); if (island == null || setPlayerFlying)
if (hasFlyPermission && island != null && !setPlayerFlying) { return;
boolean hasGlobalFlyPermission = player.hasPermission("fabledskyblock.*") || player.hasPermission("fabledskyblock.fly.*");
boolean hasOwnIslandFlyPermission = player.hasPermission("fabledskyblock.fly") && island.getRole(player) != null && island.getRole(player) != IslandRole.Visitor;
if (hasGlobalFlyPermission || hasOwnIslandFlyPermission) {
WorldManager worldManager = skyblock.getWorldManager(); WorldManager worldManager = skyblock.getWorldManager();
boolean canFlyInWorld = worldManager.isIslandWorld(player.getWorld()); boolean canFlyInWorld = worldManager.isIslandWorld(player.getWorld());
Bukkit.getServer().getScheduler().runTask(skyblock, () -> { Bukkit.getServer().getScheduler().runTask(skyblock, () -> player.setAllowFlight(canFlyInWorld));
player.setAllowFlight(canFlyInWorld);
});
} }
} }

View File

@ -72,7 +72,7 @@ public class Chunk {
} }
public void prepareNextChunkSnapshots() { public void prepareNextChunkSnapshots() {
boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker") && false; // TODO: Disabled for now until we figure out why it isn't working properly boolean isWildStackerEnabled = Bukkit.getPluginManager().isPluginEnabled("WildStacker");
Bukkit.getScheduler().runTask(this.skyblock, () -> { Bukkit.getScheduler().runTask(this.skyblock, () -> {
this.chunkSnapshots.clear(); this.chunkSnapshots.clear();

View File

@ -41,6 +41,7 @@ public class LevellingManager {
private final SkyBlock skyblock; private final SkyBlock skyblock;
private Set<Island> activeIslandScans = new HashSet<>();
private List<LevellingMaterial> materialStorage = new ArrayList<>(); private List<LevellingMaterial> materialStorage = new ArrayList<>();
private Method getBlockTypeMethod = null; private Method getBlockTypeMethod = null;
@ -67,6 +68,8 @@ public class LevellingManager {
return; return;
} }
this.activeIslandScans.add(island);
Chunk chunk = new Chunk(skyblock, island); Chunk chunk = new Chunk(skyblock, island);
chunk.prepareInitial(); chunk.prepareInitial();
@ -180,7 +183,7 @@ public class LevellingManager {
if (snapshot.isStackedSpawner(location)) { if (snapshot.isStackedSpawner(location)) {
Map.Entry<Integer, EntityType> spawnerData = snapshot.getStackedSpawner(location); Map.Entry<Integer, EntityType> spawnerData = snapshot.getStackedSpawner(location);
amount = spawnerData.getKey(); amount = spawnerData.getKey();
blockData = 0; spawnerType = spawnerData.getValue();
} }
} }
@ -304,6 +307,8 @@ public class LevellingManager {
me.goodandevil.skyblock.menus.Levelling.getInstance().open(player); me.goodandevil.skyblock.menus.Levelling.getInstance().open(player);
} }
} }
this.activeIslandScans.remove(island);
} }
public void registerMaterials() { public void registerMaterials() {
@ -321,12 +326,16 @@ public class LevellingManager {
} }
} catch (Exception e) { } catch (Exception e) {
Bukkit.getServer().getLogger().log(Level.WARNING, "SkyBlock | Error: The material '" + materialKey Bukkit.getServer().getLogger().log(Level.WARNING, "SkyBlock | Error: The material '" + materialKey
+ "' is not a Material type. Make sure the material name is a 1.13 material name. Please correct this in the 'levelling.yml' file."); + "' is not a Material type. Make sure the material name is a 1.14 material name. Please correct this in the 'levelling.yml' file.");
} }
} }
} }
} }
public boolean isIslandLevelBeingScanned(Island island) {
return this.activeIslandScans.contains(island);
}
public void unregisterMaterials() { public void unregisterMaterials() {
materialStorage.clear(); materialStorage.clear();
} }

View File

@ -4,6 +4,7 @@ import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.island.Island; import me.goodandevil.skyblock.island.Island;
import me.goodandevil.skyblock.island.IslandManager; import me.goodandevil.skyblock.island.IslandManager;
import me.goodandevil.skyblock.utils.version.Materials; import me.goodandevil.skyblock.utils.version.Materials;
import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.CreatureSpawner; import org.bukkit.block.CreatureSpawner;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -26,6 +27,12 @@ public class LimitManager {
this.skyblock = skyblock; this.skyblock = skyblock;
this.blockLimits = new HashMap<>(); this.blockLimits = new HashMap<>();
this.reload();
}
public void reload() {
this.blockLimits.clear();
FileConfiguration limitsConfig = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "limits.yml")).getFileConfiguration(); FileConfiguration limitsConfig = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "limits.yml")).getFileConfiguration();
ConfigurationSection blockLimitSection = limitsConfig.getConfigurationSection("block"); ConfigurationSection blockLimitSection = limitsConfig.getConfigurationSection("block");
@ -51,22 +58,14 @@ public class LimitManager {
return -1; return -1;
long limit = -1; long limit = -1;
Materials material; Materials material = Materials.getMaterials(block.getType(), block.getData());
if (block.getType() == Materials.SPAWNER.parseMaterial()) {
material = Materials.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType());
if (this.blockLimits.containsKey(Materials.SPAWNER))
limit = Math.max(limit, this.blockLimits.get(Materials.SPAWNER));
} else {
material = Materials.getMaterials(block.getType(), block.getData());
}
if (this.blockLimits.containsKey(material)) if (this.blockLimits.containsKey(material))
limit = Math.max(limit, this.blockLimits.get(material)); limit = Math.max(limit, this.blockLimits.get(material));
Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions() Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions()
.stream() .stream()
.filter(x -> x.getPermission().toLowerCase().startsWith("fabledskyblock.limit.block." + material.name().toLowerCase()) .filter(x -> x.getPermission().toLowerCase().startsWith("fabledskyblock.limit.block." + material.name().toLowerCase()))
|| (block.getType() == Materials.SPAWNER.parseMaterial() && x.getPermission().toLowerCase().startsWith("fabledskyblock.limit.block.spawner")))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
for (PermissionAttachmentInfo permission : permissions) { for (PermissionAttachmentInfo permission : permissions) {
@ -97,7 +96,12 @@ public class LimitManager {
return false; return false;
Island island = islandManager.getIslandAtLocation(block.getLocation()); Island island = islandManager.getIslandAtLocation(block.getLocation());
long totalPlaced = island.getLevel().getMaterialAmount(Materials.getMaterials(block.getType(), block.getData()).name()); long totalPlaced;
if (block.getType() == Materials.SPAWNER.parseMaterial()) {
totalPlaced = island.getLevel().getMaterials().entrySet().stream().filter(x -> x.getKey().contains("SPAWNER")).mapToLong(Map.Entry::getValue).sum();
} else {
totalPlaced = island.getLevel().getMaterialAmount(Materials.getMaterials(block.getType(), block.getData()).name());
}
return limit < totalPlaced + 1; return limit < totalPlaced + 1;
} }

View File

@ -5,6 +5,7 @@ import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.generator.Generator; import me.goodandevil.skyblock.generator.Generator;
import me.goodandevil.skyblock.generator.GeneratorManager; import me.goodandevil.skyblock.generator.GeneratorManager;
import me.goodandevil.skyblock.island.*; import me.goodandevil.skyblock.island.*;
import me.goodandevil.skyblock.levelling.LevellingManager;
import me.goodandevil.skyblock.limit.LimitManager; import me.goodandevil.skyblock.limit.LimitManager;
import me.goodandevil.skyblock.stackable.Stackable; import me.goodandevil.skyblock.stackable.Stackable;
import me.goodandevil.skyblock.stackable.StackableManager; import me.goodandevil.skyblock.stackable.StackableManager;
@ -170,6 +171,7 @@ public class Block implements Listener {
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
WorldManager worldManager = skyblock.getWorldManager(); WorldManager worldManager = skyblock.getWorldManager();
LevellingManager levellingManager = skyblock.getLevellingManager();
if (!worldManager.isIslandWorld(block.getWorld())) return; if (!worldManager.isIslandWorld(block.getWorld())) return;
IslandWorld world = worldManager.getIslandWorld(block.getWorld()); IslandWorld world = worldManager.getIslandWorld(block.getWorld());
@ -180,6 +182,14 @@ public class Block implements Listener {
return; return;
} }
if (levellingManager.isIslandLevelBeingScanned(island)) {
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Command.Island.Level.Scanning.BlockPlacing.Message"));
event.setCancelled(true);
return;
}
if (!islandManager.hasPermission(player, block.getLocation(), "Place")) { if (!islandManager.hasPermission(player, block.getLocation(), "Place")) {
event.setCancelled(true); event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player, skyblock.getMessageManager().sendMessage(player,
@ -226,12 +236,7 @@ public class Block implements Listener {
LimitManager limitManager = skyblock.getLimitManager(); LimitManager limitManager = skyblock.getLimitManager();
if (limitManager.isBlockLimitExceeded(player, block)) { if (limitManager.isBlockLimitExceeded(player, block)) {
Materials material; Materials material = Materials.getMaterials(block.getType(), block.getData());
if (block.getType() == Materials.SPAWNER.parseMaterial()) {
material = Materials.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType());
} else {
material = Materials.getMaterials(block.getType(), block.getData());
}
skyblock.getMessageManager().sendMessage(player, skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))

View File

@ -3,6 +3,7 @@ package me.goodandevil.skyblock.listeners;
import java.io.File; import java.io.File;
import java.util.Set; import java.util.Set;
import me.goodandevil.skyblock.levelling.LevellingManager;
import me.goodandevil.skyblock.limit.LimitManager; import me.goodandevil.skyblock.limit.LimitManager;
import me.goodandevil.skyblock.utils.NumberUtil; import me.goodandevil.skyblock.utils.NumberUtil;
import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.text.WordUtils;
@ -68,6 +69,13 @@ public class Interact implements Listener {
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
SoundManager soundManager = skyblock.getSoundManager(); SoundManager soundManager = skyblock.getSoundManager();
StackableManager stackableManager = skyblock.getStackableManager(); StackableManager stackableManager = skyblock.getStackableManager();
LevellingManager levellingManager = skyblock.getLevellingManager();
Island island = islandManager.getIslandAtLocation(player.getLocation());
if (island == null) {
event.setCancelled(true);
return;
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.LEFT_CLICK_BLOCK) {
if (block.getType() == Material.DRAGON_EGG) { if (block.getType() == Material.DRAGON_EGG) {
@ -123,19 +131,23 @@ public class Interact implements Listener {
if (stackableManager != null if (stackableManager != null
&& stackableManager.getStackableMaterials().contains(event.getMaterial()) && stackableManager.getStackableMaterials().contains(event.getMaterial())
&& event.getClickedBlock().getType() == event.getMaterial() && event.getClickedBlock().getType() == event.getMaterial()
&& !player.isSneaking() && islandManager.hasPermission(player, block.getLocation(), "Place")) { && !player.isSneaking() && islandManager.hasPermission(player, block.getLocation(), "Place")
&& (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Stackable.RequirePermission") || player.hasPermission("fabledskyblock.stackable"))) {
if (NMSUtil.getVersionNumber() > 8) { if (NMSUtil.getVersionNumber() > 8) {
if (event.getHand() == EquipmentSlot.OFF_HAND) return; if (event.getHand() == EquipmentSlot.OFF_HAND) return;
} }
if (levellingManager.isIslandLevelBeingScanned(island)) {
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Command.Island.Level.Scanning.BlockPlacing.Message"));
event.setCancelled(true);
return;
}
LimitManager limitManager = skyblock.getLimitManager(); LimitManager limitManager = skyblock.getLimitManager();
if (limitManager.isBlockLimitExceeded(player, block)) { if (limitManager.isBlockLimitExceeded(player, block)) {
Materials material; Materials material = Materials.getMaterials(block.getType(), block.getData());
if (block.getType() == Materials.SPAWNER.parseMaterial()) {
material = Materials.getSpawner(((CreatureSpawner) block.getState()).getSpawnedType());
} else {
material = Materials.getMaterials(block.getType(), block.getData());
}
skyblock.getMessageManager().sendMessage(player, skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
@ -162,8 +174,6 @@ public class Interact implements Listener {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (!configLoad.getBoolean("Island.Block.Level.Enable")) return; if (!configLoad.getBoolean("Island.Block.Level.Enable")) return;
Island island = islandManager.getIslandAtLocation(block.getLocation());
Materials materials = Materials.getMaterials(block.getType(), block.getData()); Materials materials = Materials.getMaterials(block.getType(), block.getData());
if (materials == null) return; if (materials == null) return;

View File

@ -14,9 +14,9 @@ Island:
# The size of an Island when created. # The size of an Island when created.
# [!] Do not go over the maximum. # [!] Do not go over the maximum.
# [!] Even numbers WILL create world border issues. # [!] Even numbers WILL create world border issues.
Minimum: 101 Minimum: 100
# The maximum size of an Island based on the permission node 'skyblock.size.<size>'. # The maximum size of an Island based on the permission node 'skyblock.size.<size>'.
Maximum: 201 Maximum: 200
Creation: Creation:
# Rather than opening the 'Island Creator' menu. Create an island # Rather than opening the 'Island Creator' menu. Create an island
# as soon as a player performs the '/island' or '/island create' # as soon as a player performs the '/island' or '/island create'
@ -38,7 +38,7 @@ Island:
# Delete the Island world when changing the liquid option. # Delete the Island world when changing the liquid option.
# If lava disabled, the world will be a water world. # If lava disabled, the world will be a water world.
# -1 to disable Nether and End unlock prices. # -1 to disable Nether and End unlock prices.
# Valid Enrivonments: NORMAL, NETHER, THE_END # Valid Environments: NORMAL, NETHER, THE_END
Normal: Normal:
Name: "island_normal_world" Name: "island_normal_world"
IslandSpawnHeight: 72 IslandSpawnHeight: 72
@ -285,3 +285,5 @@ Island:
Enable: true Enable: true
Stackable: Stackable:
Enable: true Enable: true
# fabledskyblock.stackables
RequirePermission: false

View File

@ -82,6 +82,8 @@ Command:
Message: '&eScanning Island level: &b%percent%' Message: '&eScanning Island level: &b%percent%'
NotOnIsland: NotOnIsland:
Message: '&bSkyBlock &8| &cError&8: &eYou cannot initiate an Island level scan without being on your Island.' Message: '&bSkyBlock &8| &cError&8: &eYou cannot initiate an Island level scan without being on your Island.'
BlockPlacing:
Message: '&bSkyBlock &8 | &cError:&8: &eYou cannot place blocks during an Island level scan. Please wait for the scan to finish.'
Cooldown: Cooldown:
Word: Word:
Minute: minute(s) Minute: minute(s)
@ -2062,7 +2064,9 @@ Menu:
- '' - ''
- '&cWarning: You must wait a' - '&cWarning: You must wait a'
- '&chour after a rescan to' - '&chour after a rescan to'
- '&cperform another one!' - '&cperform another one! You'
- '&cwill also not be able to'
- '&cplace blocks during the scan!'
Displayname: '&aRescan Island Materials' Displayname: '&aRescan Island Materials'
Material: Material:
Displayname: '&7%material &8(&e+%points Points&8)' Displayname: '&7%material &8(&e+%points Points&8)'