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); fileManager = new FileManager(this);
worldManager = new WorldManager(this); worldManager = new WorldManager(this);
userCacheManager = new UserCacheManager(this); userCacheManager = new UserCacheManager(this);
economyManager = new EconomyManager();
visitManager = new VisitManager(this); visitManager = new VisitManager(this);
banManager = new BanManager(this); banManager = new BanManager(this);
islandManager = new IslandManager(this); islandManager = new IslandManager(this);
@ -126,7 +127,6 @@ public class SkyBlock extends JavaPlugin {
placeholderManager.registerPlaceholders(); placeholderManager.registerPlaceholders();
messageManager = new MessageManager(this); messageManager = new MessageManager(this);
economyManager = new EconomyManager();
hologramManager = new HologramManager(this); hologramManager = new HologramManager(this);
new PlaytimeTask(playerDataManager, islandManager).runTaskTimerAsynchronously(this, 0L, 20L); 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.Hologram;
import me.goodandevil.skyblock.hologram.HologramManager; 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.levelling.LevellingManager; import me.goodandevil.skyblock.levelling.LevellingManager;
import me.goodandevil.skyblock.message.MessageManager; import me.goodandevil.skyblock.message.MessageManager;
import me.goodandevil.skyblock.scoreboard.ScoreboardManager; import me.goodandevil.skyblock.scoreboard.ScoreboardManager;
@ -34,6 +35,7 @@ public class ReloadCommand extends SubCommand {
} }
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager();
HologramManager hologramManager = skyblock.getHologramManager(); HologramManager hologramManager = skyblock.getHologramManager();
MessageManager messageManager = skyblock.getMessageManager(); MessageManager messageManager = skyblock.getMessageManager();
SoundManager soundManager = skyblock.getSoundManager(); SoundManager soundManager = skyblock.getSoundManager();
@ -86,17 +88,11 @@ public class ReloadCommand extends SubCommand {
levellingManager.unregisterMaterials(); levellingManager.unregisterMaterials();
levellingManager.registerMaterials(); levellingManager.registerMaterials();
Bukkit.getServer().getScheduler().runTask(skyblock, () -> { leaderboardManager.clearLeaderboard();
for (HologramType hologramTypeList : HologramType.values()) { leaderboardManager.resetLeaderboard();
Hologram hologram = hologramManager.getHologram(hologramTypeList); leaderboardManager.setupLeaderHeads();
if (hologram != null) { hologramManager.resetHologram();
hologramManager.removeHologram(hologram);
}
hologramManager.spawnHologram(hologramTypeList);
}
});
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

@ -2,13 +2,16 @@ package me.goodandevil.skyblock.economy;
import me.goodandevil.skyblock.api.event.player.PlayerWithdrawMoneyEvent; import me.goodandevil.skyblock.api.event.player.PlayerWithdrawMoneyEvent;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
public class EconomyManager { public class EconomyManager {
private Economy economy; private Economy economy = null;
private Permission permission = null;
public EconomyManager() { public EconomyManager() {
setup(); setup();
@ -16,10 +19,14 @@ public class EconomyManager {
public void setup() { public void setup() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) { 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) if (economyRsp != null)
economy = registeredServiceProvider.getProvider(); 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)); 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() { 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(); removeWorldHolograms();
for (HologramType hologramTypeList : HologramType.values()) { for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) {
if (hologramTypeList == HologramType.Votes) { if (hologramTypeList == HologramType.Votes) {
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")) if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getBoolean("Island.Visitor.Vote")) { .getFileConfiguration().getBoolean("Island.Visitor.Vote")) {
@ -51,7 +50,6 @@ public class HologramManager {
spawnHologram(hologramTypeList); spawnHologram(hologramTypeList);
} }
}
}, 200L); }, 200L);
} }
@ -181,13 +179,11 @@ public class HologramManager {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
for (HologramType hologramTypeList : HologramType.values()) { for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) {
if (configLoad.getString("Location.Hologram.Leaderboard." + hologramTypeList.name()) != null) { if (configLoad.getString("Location.Hologram.Leaderboard." + hologramTypeList.name()) != null) {
locations.add(fileManager.getLocation(config, locations.add(fileManager.getLocation(config,
"Location.Hologram.Leaderboard." + hologramTypeList.name(), true)); "Location.Hologram.Leaderboard." + hologramTypeList.name(), true));
} }
} }
}
for (World worldList : Bukkit.getWorlds()) { for (World worldList : Bukkit.getWorlds()) {
List<Entity> entities = worldList.getEntities(); List<Entity> entities = worldList.getEntities();
@ -235,7 +231,6 @@ public class HologramManager {
.getFileConfiguration(); .getFileConfiguration();
for (HologramType hologramTypeList : HologramType.values()) { for (HologramType hologramTypeList : HologramType.values()) {
if (hologramTypeList == HologramType.Level || hologramTypeList == HologramType.Bank || hologramTypeList == HologramType.Votes) {
if (hologramTypeList == HologramType.Votes) { if (hologramTypeList == HologramType.Votes) {
if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Visitor.Vote")) { .getBoolean("Island.Visitor.Vote")) {
@ -313,4 +308,3 @@ public class HologramManager {
} }
} }
} }
}

View File

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

View File

@ -1,11 +1,14 @@
package me.goodandevil.skyblock.leaderboard; package me.goodandevil.skyblock.leaderboard;
import me.goodandevil.skyblock.SkyBlock; 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.TopBank;
import me.goodandevil.skyblock.leaderboard.leaderheads.TopLevel; import me.goodandevil.skyblock.leaderboard.leaderheads.TopLevel;
import me.goodandevil.skyblock.leaderboard.leaderheads.TopVotes; import me.goodandevil.skyblock.leaderboard.leaderheads.TopVotes;
import me.goodandevil.skyblock.visit.Visit; import me.goodandevil.skyblock.visit.Visit;
import me.goodandevil.skyblock.visit.VisitManager; import me.goodandevil.skyblock.visit.VisitManager;
import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -33,15 +36,28 @@ public class LeaderboardManager {
} }
public void resetLeaderboard() { public void resetLeaderboard() {
EconomyManager economyManager = skyblock.getEconomyManager();
VisitManager visitManager = skyblock.getVisitManager(); VisitManager visitManager = skyblock.getVisitManager();
WorldManager worldManager = skyblock.getWorldManager();
visitManager.loadIslands(); visitManager.loadIslands();
List<LeaderboardPlayer> islandLevels = new ArrayList<>(); List<LeaderboardPlayer> islandLevels = new ArrayList<>();
List<LeaderboardPlayer> islandBanks = new ArrayList<>(); List<LeaderboardPlayer> islandBanks = new ArrayList<>();
List<LeaderboardPlayer> islandVotes = 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++) { for (int i = 0; i < visitManager.getIslands().size(); i++) {
UUID ownerUUID = (UUID) visitManager.getIslands().keySet().toArray()[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); Visit visit = visitManager.getIslands().get(ownerUUID);
islandLevels.add(new LeaderboardPlayer(ownerUUID, visit.getLevel().getLevel())); islandLevels.add(new LeaderboardPlayer(ownerUUID, visit.getLevel().getLevel()));
islandBanks.add(new LeaderboardPlayer(ownerUUID, (long)visit.getBankBalance())); islandBanks.add(new LeaderboardPlayer(ownerUUID, (long)visit.getBankBalance()));

View File

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