Island top exemption setting and permission

This commit is contained in:
Esophose 2019-04-11 00:41:27 -06:00
parent da8c162344
commit c2f670e127
7 changed files with 121 additions and 95 deletions

View File

@ -86,6 +86,7 @@ public class SkyBlock extends JavaPlugin {
fileManager = new FileManager(this);
worldManager = new WorldManager(this);
userCacheManager = new UserCacheManager(this);
economyManager = new EconomyManager();
visitManager = new VisitManager(this);
banManager = new BanManager(this);
islandManager = new IslandManager(this);
@ -126,7 +127,6 @@ public class SkyBlock extends JavaPlugin {
placeholderManager.registerPlaceholders();
messageManager = new MessageManager(this);
economyManager = new EconomyManager();
hologramManager = new HologramManager(this);
new PlaytimeTask(playerDataManager, islandManager).runTaskTimerAsynchronously(this, 0L, 20L);

View File

@ -7,6 +7,7 @@ import me.goodandevil.skyblock.generator.GeneratorManager;
import me.goodandevil.skyblock.hologram.Hologram;
import me.goodandevil.skyblock.hologram.HologramManager;
import me.goodandevil.skyblock.hologram.HologramType;
import me.goodandevil.skyblock.leaderboard.LeaderboardManager;
import me.goodandevil.skyblock.levelling.LevellingManager;
import me.goodandevil.skyblock.message.MessageManager;
import me.goodandevil.skyblock.scoreboard.ScoreboardManager;
@ -34,6 +35,7 @@ public class ReloadCommand extends SubCommand {
}
public void onCommand(CommandSender sender, String[] args) {
LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager();
HologramManager hologramManager = skyblock.getHologramManager();
MessageManager messageManager = skyblock.getMessageManager();
SoundManager soundManager = skyblock.getSoundManager();
@ -86,17 +88,11 @@ public class ReloadCommand extends SubCommand {
levellingManager.unregisterMaterials();
levellingManager.registerMaterials();
Bukkit.getServer().getScheduler().runTask(skyblock, () -> {
for (HologramType hologramTypeList : HologramType.values()) {
Hologram hologram = hologramManager.getHologram(hologramTypeList);
leaderboardManager.clearLeaderboard();
leaderboardManager.resetLeaderboard();
leaderboardManager.setupLeaderHeads();
if (hologram != null) {
hologramManager.removeHologram(hologram);
}
hologramManager.spawnHologram(hologramTypeList);
}
});
hologramManager.resetHologram();
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Reload.Reloaded.Message"));
soundManager.playSound(sender, Sounds.ANVIL_USE.bukkitSound(), 1.0F, 1.0F);

View File

@ -2,13 +2,16 @@ package me.goodandevil.skyblock.economy;
import me.goodandevil.skyblock.api.event.player.PlayerWithdrawMoneyEvent;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider;
public class EconomyManager {
private Economy economy;
private Economy economy = null;
private Permission permission = null;
public EconomyManager() {
setup();
@ -16,10 +19,14 @@ public class EconomyManager {
public void setup() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
RegisteredServiceProvider<Economy> registeredServiceProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
RegisteredServiceProvider<Economy> economyRsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (registeredServiceProvider != null)
economy = registeredServiceProvider.getProvider();
if (economyRsp != null)
economy = economyRsp.getProvider();
RegisteredServiceProvider<Permission> permissionRsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
if (permissionRsp != null)
permission = permissionRsp.getProvider();
}
}
@ -46,7 +53,17 @@ public class EconomyManager {
Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money));
}
public boolean hasPermission(String world, OfflinePlayer player, String perm) {
if (permission != null)
return permission.playerHas(world, player, perm);
return false;
}
public boolean isEconomy() {
return Bukkit.getServer().getPluginManager().getPlugin("Vault") != null;
return economy != null;
}
public boolean isPermission() {
return permission != null;
}
}

View File

@ -41,7 +41,6 @@ public class HologramManager {
removeWorldHolograms();
for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) {
if (hologramTypeList == HologramType.Votes) {
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getBoolean("Island.Visitor.Vote")) {
@ -51,7 +50,6 @@ public class HologramManager {
spawnHologram(hologramTypeList);
}
}
}, 200L);
}
@ -181,13 +179,11 @@ public class HologramManager {
FileConfiguration configLoad = config.getFileConfiguration();
for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) {
if (configLoad.getString("Location.Hologram.Leaderboard." + hologramTypeList.name()) != null) {
locations.add(fileManager.getLocation(config,
"Location.Hologram.Leaderboard." + hologramTypeList.name(), true));
}
}
}
for (World worldList : Bukkit.getWorlds()) {
List<Entity> entities = worldList.getEntities();
@ -235,7 +231,6 @@ public class HologramManager {
.getFileConfiguration();
for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) {
if (hologramTypeList == HologramType.Votes) {
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Visitor.Vote")) {
@ -312,5 +307,4 @@ public class HologramManager {
}
}
}
}
}

View File

@ -2,6 +2,6 @@ package me.goodandevil.skyblock.hologram;
public enum HologramType {
Level, Bank, Votes, Stackable;
Level, Bank, Votes
}

View File

@ -1,11 +1,14 @@
package me.goodandevil.skyblock.leaderboard;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.economy.EconomyManager;
import me.goodandevil.skyblock.island.IslandWorld;
import me.goodandevil.skyblock.leaderboard.leaderheads.TopBank;
import me.goodandevil.skyblock.leaderboard.leaderheads.TopLevel;
import me.goodandevil.skyblock.leaderboard.leaderheads.TopVotes;
import me.goodandevil.skyblock.visit.Visit;
import me.goodandevil.skyblock.visit.VisitManager;
import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -33,15 +36,28 @@ public class LeaderboardManager {
}
public void resetLeaderboard() {
EconomyManager economyManager = skyblock.getEconomyManager();
VisitManager visitManager = skyblock.getVisitManager();
WorldManager worldManager = skyblock.getWorldManager();
visitManager.loadIslands();
List<LeaderboardPlayer> islandLevels = new ArrayList<>();
List<LeaderboardPlayer> islandBanks = new ArrayList<>();
List<LeaderboardPlayer> islandVotes = new ArrayList<>();
boolean enableExemptions = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getBoolean("Island.Leaderboard.Exemptions.Enable");
for (int i = 0; i < visitManager.getIslands().size(); i++) {
UUID ownerUUID = (UUID) visitManager.getIslands().keySet().toArray()[i];
if (enableExemptions && economyManager.hasPermission(
worldManager.getWorld(IslandWorld.Normal).getName(),
Bukkit.getOfflinePlayer(ownerUUID),
"fabledskyblock.island.top.exempt"))
continue;
Visit visit = visitManager.getIslands().get(ownerUUID);
islandLevels.add(new LeaderboardPlayer(ownerUUID, visit.getLevel().getLevel()));
islandBanks.add(new LeaderboardPlayer(ownerUUID, (long)visit.getBankBalance()));

View File

@ -83,6 +83,9 @@ Island:
Reset:
# Time until Leaderboard resets
Time: 300
# If users with the permission should be exempt from /is leaderboard
Exemptions:
Enable: false
Invite:
# Time until Island invite expires
Time: 300