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,16 +41,14 @@ 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")) { continue;
continue;
}
} }
spawnHologram(hologramTypeList);
} }
spawnHologram(hologramTypeList);
} }
}, 200L); }, 200L);
} }
@ -181,11 +179,9 @@ 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));
}
} }
} }
@ -235,79 +231,77 @@ 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")) {
continue;
}
}
Hologram hologram;
if (hasHologram(hologramTypeList)) {
hologram = getHologram(hologramTypeList);
} else {
continue; continue;
} }
}
Leaderboard.Type leaderboardType = null; Hologram hologram;
switch (hologramTypeList) { if (hasHologram(hologramTypeList)) {
case Level: hologram = getHologram(hologramTypeList);
leaderboardType = Leaderboard.Type.Level; } else {
break; continue;
case Bank: }
leaderboardType = Leaderboard.Type.Bank;
break;
case Votes:
leaderboardType = Leaderboard.Type.Votes;
break;
}
for (int i = 0; i < 10; i++) { Leaderboard.Type leaderboardType = null;
Leaderboard leaderboard = leaderboardManager.getLeaderboardFromPosition(leaderboardType, i);
int hologramLine = 10 - i;
if (leaderboard == null) { switch (hologramTypeList) {
hologram.setLine(hologramLine, messageManager.replaceMessage(null, case Level:
configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Unclaimed") leaderboardType = Leaderboard.Type.Level;
.replace("%position", "" + (i + 1)))); break;
case Bank:
leaderboardType = Leaderboard.Type.Bank;
break;
case Votes:
leaderboardType = Leaderboard.Type.Votes;
break;
}
for (int i = 0; i < 10; i++) {
Leaderboard leaderboard = leaderboardManager.getLeaderboardFromPosition(leaderboardType, i);
int hologramLine = 10 - i;
if (leaderboard == null) {
hologram.setLine(hologramLine, messageManager.replaceMessage(null,
configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Unclaimed")
.replace("%position", "" + (i + 1))));
} else {
Visit visit = leaderboard.getVisit();
Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID());
String islandOwnerName;
if (targetPlayer == null) {
islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName();
} else { } else {
Visit visit = leaderboard.getVisit(); islandOwnerName = targetPlayer.getName();
}
Player targetPlayer = Bukkit.getServer().getPlayer(visit.getOwnerUUID()); if (hologramTypeList == HologramType.Level) {
String islandOwnerName; IslandLevel level = visit.getLevel();
hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&',
if (targetPlayer == null) { configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed")
islandOwnerName = new OfflinePlayer(visit.getOwnerUUID()).getName(); .replace("%position", "" + (i + 1))
} else { .replace("%player", islandOwnerName)
islandOwnerName = targetPlayer.getName(); .replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel()))
} .replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints()))));
} else if (hologramTypeList == HologramType.Bank) {
if (hologramTypeList == HologramType.Level) { hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&',
IslandLevel level = visit.getLevel(); configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed")
hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', .replace("%position", "" + (i + 1))
configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") .replace("%player", islandOwnerName)
.replace("%position", "" + (i + 1)) .replace("%balance",
.replace("%player", islandOwnerName) "" + NumberUtil.formatNumberByDecimal(visit.getBankBalance()))));
.replace("%level", NumberUtil.formatNumberByDecimal(level.getLevel())) } else if (hologramTypeList == HologramType.Votes) {
.replace("%points", NumberUtil.formatNumberByDecimal(level.getPoints())))); hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&',
} else if (hologramTypeList == HologramType.Bank) { configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed")
hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&', .replace("%position", "" + (i + 1))
configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed") .replace("%player", islandOwnerName)
.replace("%position", "" + (i + 1)) .replace("%votes",
.replace("%player", islandOwnerName) "" + NumberUtil.formatNumberByDecimal(visit.getVoters().size()))));
.replace("%balance",
"" + NumberUtil.formatNumberByDecimal(visit.getBankBalance()))));
} else if (hologramTypeList == HologramType.Votes) {
hologram.setLine(hologramLine, ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Hologram.Leaderboard." + hologramTypeList.name() + ".Claimed")
.replace("%position", "" + (i + 1))
.replace("%player", islandOwnerName)
.replace("%votes",
"" + NumberUtil.formatNumberByDecimal(visit.getVoters().size()))));
}
} }
} }
} }

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