more things including island stuff.

This commit is contained in:
theone1000 2019-10-18 19:40:59 -06:00
parent 46308e328f
commit 38a2e83391
31 changed files with 1321 additions and 1138 deletions

View File

@ -15,7 +15,7 @@ import com.songoda.skyblock.invite.InviteManager;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.leaderboard.LeaderboardManager;
import com.songoda.skyblock.levelling.LevellingManager;
import com.songoda.skyblock.limit.LimitManager;
import com.songoda.skyblock.limit.LimitationInstanceHandler;
import com.songoda.skyblock.listeners.*;
import com.songoda.skyblock.menus.Rollback;
import com.songoda.skyblock.menus.admin.Creator;
@ -61,7 +61,6 @@ public class SkyBlock extends JavaPlugin {
private UpgradeManager upgradeManager;
private PlayerDataManager playerDataManager;
private CooldownManager cooldownManager;
private LimitManager limitManager;
private ScoreboardManager scoreboardManager;
private InviteManager inviteManager;
private BiomeManager biomeManager;
@ -76,6 +75,7 @@ public class SkyBlock extends JavaPlugin {
private MessageManager messageManager;
private EconomyManager economyManager;
private HologramManager hologramManager;
private LimitationInstanceHandler limitationHandler;
public static SkyBlock getInstance() {
return instance;
@ -101,7 +101,7 @@ public class SkyBlock extends JavaPlugin {
upgradeManager = new UpgradeManager(this);
playerDataManager = new PlayerDataManager(this);
cooldownManager = new CooldownManager(this);
limitManager = new LimitManager(this);
limitationHandler = new LimitationInstanceHandler();
if (fileManager.getConfig(new File(getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Scoreboard.Enable")) {
@ -261,10 +261,6 @@ public class SkyBlock extends JavaPlugin {
return cooldownManager;
}
public LimitManager getLimitManager() {
return limitManager;
}
public ScoreboardManager getScoreboardManager() {
return scoreboardManager;
}
@ -329,6 +325,10 @@ public class SkyBlock extends JavaPlugin {
return stackableManager;
}
public LimitationInstanceHandler getLimitationHandler() {
return limitationHandler;
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return new VoidGenerator();

View File

@ -31,8 +31,7 @@ public class BanManager {
public void onDisable() {
Map<UUID, Ban> banIslands = getIslands();
for (UUID banIslandList : banIslands.keySet()) {
Ban ban = banIslands.get(banIslandList);
for (Ban ban : banIslands.values()) {
ban.save();
}
}
@ -96,11 +95,7 @@ public class BanManager {
}
public Ban getIsland(UUID islandOwnerUUID) {
if (hasIsland(islandOwnerUUID)) {
return banStorage.get(islandOwnerUUID);
}
return null;
return banStorage.get(islandOwnerUUID);
}
public Map<UUID, Ban> getIslands() {
@ -116,9 +111,7 @@ public class BanManager {
}
public void removeIsland(UUID islandOwnerUUID) {
if (hasIsland(islandOwnerUUID)) {
banStorage.remove(islandOwnerUUID);
}
banStorage.remove(islandOwnerUUID);
}
public void unloadIsland(UUID islandOwnerUUID) {

View File

@ -11,8 +11,8 @@ import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
public class BiomeManager {
@ -23,7 +23,7 @@ public class BiomeManager {
}
public void setBiome(Island island, Biome biome) {
List<Chunk> chunks = new ArrayList<>();
Set<Chunk> chunks = new HashSet<>();
Location location = island.getLocation(IslandWorld.Normal, IslandEnvironment.Island);
int radius = (int) Math.ceil(island.getRadius());
@ -31,8 +31,7 @@ public class BiomeManager {
for (int z = location.getBlockZ() - radius; z < location.getBlockZ() + radius; z++) {
location.getWorld().setBiome(x, z, biome);
Chunk chunk = location.getWorld().getChunkAt(x >> 4, z >> 4);
if (!chunks.contains(chunk))
chunks.add(chunk);
chunks.add(chunk);
}
}

View File

@ -1,25 +1,25 @@
package com.songoda.skyblock.command.commands.admin;
import com.songoda.skyblock.command.SubCommand;
import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.config.FileManager.Config;
import com.songoda.skyblock.generator.GeneratorManager;
import com.songoda.skyblock.hologram.HologramManager;
import com.songoda.skyblock.leaderboard.LeaderboardManager;
import com.songoda.skyblock.levelling.LevellingManager;
import com.songoda.skyblock.limit.LimitManager;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.scoreboard.ScoreboardManager;
import com.songoda.skyblock.sound.SoundManager;
import com.songoda.skyblock.utils.version.Sounds;
import java.io.File;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.Map;
import com.songoda.skyblock.command.SubCommand;
import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.config.FileManager.Config;
import com.songoda.skyblock.generator.GeneratorManager;
import com.songoda.skyblock.leaderboard.LeaderboardManager;
import com.songoda.skyblock.levelling.LevellingManager;
import com.songoda.skyblock.limit.LimitationInstanceHandler;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.scoreboard.ScoreboardManager;
import com.songoda.skyblock.sound.SoundManager;
import com.songoda.skyblock.utils.version.Sounds;
public class ReloadCommand extends SubCommand {
@ -35,10 +35,9 @@ 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();
LimitManager limitManager = skyblock.getLimitManager();
LimitationInstanceHandler limitHandler = skyblock.getLimitationHandler();
FileManager fileManager = skyblock.getFileManager();
messageManager.sendMessage(sender, "&cPlease note that this command is not supported and may " +
@ -96,7 +95,7 @@ public class ReloadCommand extends SubCommand {
Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramManager().resetHologram());
});
limitManager.reload();
limitHandler.reloadAll();
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Reload.Reloaded.Message"));
soundManager.playSound(sender, Sounds.ANVIL_USE.bukkitSound(), 1.0F, 1.0F);

View File

@ -1,5 +1,14 @@
package com.songoda.skyblock.command.commands.admin;
import java.io.File;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import com.songoda.skyblock.command.SubCommand;
import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.config.FileManager.Config;
@ -10,16 +19,6 @@ import com.songoda.skyblock.playerdata.PlayerDataManager;
import com.songoda.skyblock.sound.SoundManager;
import com.songoda.skyblock.utils.player.OfflinePlayer;
import com.songoda.skyblock.utils.version.Sounds;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public class SetAlwaysLoadedCommand extends SubCommand {
@ -34,14 +33,21 @@ public class SetAlwaysLoadedCommand extends SubCommand {
}
public void onCommand(CommandSender sender, String[] args) {
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
MessageManager messageManager = skyblock.getMessageManager();
IslandManager islandManager = skyblock.getIslandManager();
SoundManager soundManager = skyblock.getSoundManager();
FileManager fileManager = skyblock.getFileManager();
FileManager fileManager = skyblock.getFileManager();
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
MessageManager messageManager = skyblock.getMessageManager();
if (args.length == 0) {
messageManager.sendMessage(sender,
configLoad.getString("Command.Island.Admin.SetAlwaysLoaded.No-Player-Input.Message"));
return;
}
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
IslandManager islandManager = skyblock.getIslandManager();
SoundManager soundManager = skyblock.getSoundManager();
if (args.length == 1) {
Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);

View File

@ -1,10 +1,9 @@
package com.songoda.skyblock.confirmation;
import org.bukkit.scheduler.BukkitRunnable;
import com.songoda.skyblock.playerdata.PlayerData;
import com.songoda.skyblock.playerdata.PlayerDataManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class ConfirmationTask extends BukkitRunnable {
@ -16,13 +15,9 @@ public class ConfirmationTask extends BukkitRunnable {
@Override
public void run() {
for (Player all : Bukkit.getOnlinePlayers()) {
if (playerDataManager.hasPlayerData(all)) {
PlayerData playerData = playerDataManager.getPlayerData(all);
if (playerData.getConfirmationTime() > 0) {
playerData.setConfirmationTime(playerData.getConfirmationTime() - 1);
}
for (PlayerData playerData : playerDataManager.getPlayerData().values()) {
if (playerData.getConfirmationTime() > 0) {
playerData.setConfirmationTime(playerData.getConfirmationTime() - 1);
}
}
}

View File

@ -13,7 +13,9 @@ import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -21,14 +23,14 @@ public class CooldownManager {
private final SkyBlock skyblock;
private Map<CooldownType, List<CooldownPlayer>> cooldownStorage = new HashMap<>();
private Map<CooldownType, List<CooldownPlayer>> cooldownStorage = new EnumMap<>(CooldownType.class);
public CooldownManager(SkyBlock skyblock) {
this.skyblock = skyblock;
IslandManager islandManager = skyblock.getIslandManager();
for (CooldownType cooldownTypeList : CooldownType.values()) {
for (CooldownType cooldownTypeList : CooldownType.getTypes()) {
List<CooldownPlayer> cooldownPlayers = new ArrayList<>();
for (Player all : Bukkit.getOnlinePlayers()) {
@ -60,7 +62,7 @@ public class CooldownManager {
}
public void onDisable() {
for (CooldownType cooldownTypeList : CooldownType.values()) {
for (CooldownType cooldownTypeList : CooldownType.getTypes()) {
setCooldownPlayer(cooldownTypeList);
saveCooldownPlayer(cooldownTypeList);
}
@ -69,23 +71,19 @@ public class CooldownManager {
public CooldownPlayer loadCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"));
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), player.getUniqueId().toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getString("Island." + cooldownType.name() + ".Cooldown") != null) {
return new CooldownPlayer(player.getUniqueId(),
new Cooldown(configLoad.getInt("Island." + cooldownType.name() + ".Cooldown")));
return new CooldownPlayer(player.getUniqueId(), new Cooldown(configLoad.getInt("Island." + cooldownType.name() + ".Cooldown")));
}
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml"));
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getString(cooldownType.name() + ".Cooldown") != null) {
return new CooldownPlayer(player.getUniqueId(),
new Cooldown(configLoad.getInt(cooldownType.name() + ".Cooldown")));
return new CooldownPlayer(player.getUniqueId(), new Cooldown(configLoad.getInt(cooldownType.name() + ".Cooldown")));
}
}
@ -95,79 +93,73 @@ public class CooldownManager {
public void createPlayer(CooldownType cooldownType, OfflinePlayer player) {
FileManager fileManager = skyblock.getFileManager();
if (cooldownStorage.containsKey(cooldownType)) {
int time = 0;
List<CooldownPlayer> cooldowns = cooldownStorage.get(cooldownType);
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
time = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
if (cooldowns == null) return;
Config config = fileManager
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();
int time = 0;
configLoad.set("Island." + cooldownType.name() + ".Cooldown", time);
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
time = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
try {
configLoad.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
time = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
Config config = fileManager
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), player.getUniqueId().toString() + ".yml"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();
Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();
configLoad.set("Island." + cooldownType.name() + ".Cooldown", time);
configLoad.set(cooldownType.name() + ".Cooldown", time);
try {
configLoad.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
try {
configLoad.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
time = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
cooldownStorage.get(cooldownType).add(new CooldownPlayer(player.getUniqueId(), new Cooldown(time)));
Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();
configLoad.set(cooldownType.name() + ".Cooldown", time);
try {
configLoad.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
cooldowns.add(new CooldownPlayer(player.getUniqueId(), new Cooldown(time)));
}
public void deletePlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set("Island." + cooldownType.name() + ".Cooldown", null);
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set(cooldownType.name() + ".Cooldown", null);
}
cooldownStorage.get(cooldownType).remove(cooldownPlayerList);
break;
for (Iterator<CooldownPlayer> it = getCooldownPlayersOrEmptyList(cooldownType).iterator(); it.hasNext();) {
if (it.next().getUUID().equals(player.getUniqueId())) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set("Island." + cooldownType.name() + ".Cooldown", null);
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set(cooldownType.name() + ".Cooldown", null);
}
it.remove();
break;
}
}
}
public boolean hasPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return true;
}
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return true;
}
}
@ -175,72 +167,55 @@ public class CooldownManager {
}
public void transferPlayer(CooldownType cooldownType, OfflinePlayer player1, OfflinePlayer player2) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player1.getUniqueId())) {
cooldownPlayerList.setUUID(player2.getUniqueId());
break;
}
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player1.getUniqueId())) {
cooldownPlayerList.setUUID(player2.getUniqueId());
break;
}
}
}
public void removeCooldownPlayer(CooldownType cooldownType, CooldownPlayer cooldownPlayer) {
if (cooldownStorage.containsKey(cooldownType)) {
cooldownStorage.get(cooldownType).remove(cooldownPlayer);
}
getCooldownPlayersOrEmptyList(cooldownType).remove(cooldownPlayer);
}
public void removeCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
cooldownStorage.get(cooldownType).remove(cooldownPlayerList);
break;
}
for (Iterator<CooldownPlayer> it = getCooldownPlayersOrEmptyList(cooldownType).iterator(); it.hasNext();) {
if (it.next().getUUID().equals(player.getUniqueId())) {
it.remove();
break;
}
}
}
public void setCooldownPlayer(CooldownType cooldownType) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
setCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
}
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
setCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
}
}
public void setCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set("Island." + cooldownType + ".Cooldown",
cooldownPlayerList.getCooldown().getTime());
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration()
.set(cooldownType.name() + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
}
break;
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set("Island." + cooldownType + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set(cooldownType.name() + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
}
break;
}
}
}
public void saveCooldownPlayer(CooldownType cooldownType) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
saveCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
}
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
saveCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
}
}
@ -249,12 +224,10 @@ public class CooldownManager {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml"));
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), player.getUniqueId().toString() + ".yml"));
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml"));
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"));
}
if (config != null) {
@ -267,19 +240,20 @@ public class CooldownManager {
}
public void addCooldownPlayer(CooldownType cooldownType, CooldownPlayer cooldownPlayer) {
if (cooldownType != null && cooldownPlayer != null) {
if (cooldownStorage.containsKey(cooldownType)) {
cooldownStorage.get(cooldownType).add(cooldownPlayer);
}
}
if (cooldownType == null || cooldownPlayer == null) return;
List<CooldownPlayer> cooldowns = cooldownStorage.get(cooldownType);
if (cooldowns == null) return;
cooldowns.add(cooldownPlayer);
}
public CooldownPlayer getCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return cooldownPlayerList;
}
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return cooldownPlayerList;
}
}
@ -287,14 +261,21 @@ public class CooldownManager {
}
public List<CooldownPlayer> getCooldownPlayers(CooldownType cooldownType) {
if (cooldownStorage.containsKey(cooldownType)) {
return cooldownStorage.get(cooldownType);
}
return cooldownStorage.get(cooldownType);
}
return null;
/**
* Convenience method. This method functions the same as
* {@link CooldownManager#getCooldownPlayers(CooldownType)} but returns a
* {@link Collections#emptyList()} when no value is present in the map under the
* key, cooldownType.
*/
public List<CooldownPlayer> getCooldownPlayersOrEmptyList(CooldownType cooldownType) {
return cooldownStorage.getOrDefault(cooldownType, Collections.emptyList());
}
public boolean hasCooldownType(CooldownType cooldownType) {
return cooldownStorage.containsKey(cooldownType);
}
}

View File

@ -15,22 +15,22 @@ public class CooldownTask extends BukkitRunnable {
@Override
public void run() {
for (CooldownType cooldownTypeList : CooldownType.values()) {
if (cooldownManager.hasCooldownType(cooldownTypeList)) {
List<CooldownPlayer> cooldownPlayers = cooldownManager.getCooldownPlayers(cooldownTypeList);
for (CooldownType cooldownType : CooldownType.getTypes()) {
List<CooldownPlayer> cooldownPlayers = cooldownManager.getCooldownPlayers(cooldownType);
for (int i = 0; i < cooldownPlayers.size(); i++) {
CooldownPlayer cooldownPlayer = cooldownPlayers.get(i);
Cooldown cooldown = cooldownPlayer.getCooldown();
if (cooldownPlayers == null) return;
cooldown.setTime(cooldown.getTime() - 1);
for (int i = 0; i < cooldownPlayers.size(); i++) {
CooldownPlayer cooldownPlayer = cooldownPlayers.get(i);
Cooldown cooldown = cooldownPlayer.getCooldown();
if (cooldown.getTime() <= 0) {
cooldownManager.deletePlayer(cooldownTypeList,
Bukkit.getServer().getOfflinePlayer(cooldownPlayer.getUUID()));
}
cooldown.setTime(cooldown.getTime() - 1);
if (cooldown.getTime() <= 0) {
cooldownManager.deletePlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayer.getUUID()));
}
}
}
}
}

View File

@ -1,7 +1,21 @@
package com.songoda.skyblock.cooldown;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum CooldownType {
Biome, Creation, Levelling, Ownership, Teleport
Biome,
Creation,
Levelling,
Ownership,
Teleport;
private static final Set<CooldownType> types = Collections.unmodifiableSet(EnumSet.allOf(CooldownType.class));
public static Set<CooldownType> getTypes() {
return types;
}
}

View File

@ -18,22 +18,17 @@ public class InviteManager {
public Invite createInvite(Player player, Player sender, UUID owner, int time) {
Invite invite = new Invite(player, sender, owner, time);
inviteStorage.put(player.getUniqueId(), invite);
return invite;
}
public void removeInvite(UUID uuid) {
if (hasInvite(uuid)) {
inviteStorage.remove(uuid);
}
inviteStorage.remove(uuid);
}
public void tranfer(UUID uuid1, UUID uuid2) {
Map<UUID, Invite> islandInvites = getInvites();
for (UUID islandInviteList : islandInvites.keySet()) {
Invite invite = islandInvites.get(islandInviteList);
for (Invite invite : islandInvites.values()) {
if (invite.getOwnerUUID().equals(uuid1)) {
invite.setOwnerUUID(uuid2);
}
@ -45,11 +40,7 @@ public class InviteManager {
}
public Invite getInvite(UUID uuid) {
if (hasInvite(uuid)) {
return inviteStorage.get(uuid);
}
return null;
return inviteStorage.get(uuid);
}
public boolean hasInvite(UUID uuid) {

View File

@ -27,6 +27,7 @@ import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
public class Island {
@ -104,7 +105,7 @@ public class Island {
if (playerDataConfigLoad.getString("Island.Owner") == null
|| !playerDataConfigLoad.getString("Island.Owner").equals(ownerUUID.toString())) {
members.remove(member);
members.remove(i);
}
}
@ -122,7 +123,7 @@ public class Island {
if (playerDataConfigLoad.getString("Island.Owner") == null
|| !playerDataConfigLoad.getString("Island.Owner").equals(ownerUUID.toString())) {
operators.remove(operator);
operators.remove(i);
}
}
@ -131,24 +132,21 @@ public class Island {
Config settingsDataConfig = null;
if (fileManager.isFileExist(new File(skyblock.getDataFolder().toString() + "/setting-data",
getOwnerUUID().toString() + ".yml"))) {
settingsDataConfig = fileManager.getConfig(new File(
skyblock.getDataFolder().toString() + "/setting-data", getOwnerUUID().toString() + ".yml"));
File settingDataFile = new File(skyblock.getDataFolder().toString() + "/setting-data", getOwnerUUID().toString() + ".yml");
if (fileManager.isFileExist(settingDataFile)) {
settingsDataConfig = fileManager.getConfig(settingDataFile);
}
for (IslandRole roleList : IslandRole.values()) {
for (IslandRole roleList : IslandRole.getRoles()) {
List<IslandSetting> settings = new ArrayList<>();
for (String settingList : defaultSettingsConfig.getFileConfiguration()
.getConfigurationSection("Settings." + roleList.name()).getKeys(false)) {
if (settingsDataConfig == null || settingsDataConfig.getFileConfiguration()
.getString("Settings." + roleList.name() + "." + settingList) == null) {
settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration()
.getBoolean("Settings." + roleList.name() + "." + settingList)));
for (String settingList : defaultSettingsConfig.getFileConfiguration().getConfigurationSection("Settings." + roleList.name()).getKeys(false)) {
if (settingsDataConfig == null || settingsDataConfig.getFileConfiguration().getString("Settings." + roleList.name() + "." + settingList) == null) {
settings.add(
new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList)));
} else {
settings.add(new IslandSetting(settingList, settingsDataConfig.getFileConfiguration()
.getBoolean("Settings." + roleList.name() + "." + settingList)));
settings.add(new IslandSetting(settingList, settingsDataConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList)));
}
}
@ -167,13 +165,13 @@ public class Island {
configLoad.set("Weather.Weather", mainConfigLoad.getString("Island.Weather.Default.Weather").toUpperCase());
configLoad.set("Ownership.Original", ownerUUID.toString());
for (IslandRole roleList : IslandRole.values()) {
List<IslandSetting> settings = new ArrayList<>();
for (IslandRole roleList : IslandRole.getRoles()) {
for (String settingList : defaultSettingsConfig.getFileConfiguration()
.getConfigurationSection("Settings." + roleList.name()).getKeys(false)) {
settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration()
.getBoolean("Settings." + roleList.name() + "." + settingList)));
Set<String> keys = defaultSettingsConfig.getFileConfiguration().getConfigurationSection("Settings." + roleList.name()).getKeys(false);
List<IslandSetting> settings = new ArrayList<>(keys.size());
for (String settingList : keys) {
settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList)));
}
islandSettings.put(roleList, settings);
@ -227,12 +225,8 @@ public class Island {
}
public UUID getOriginalOwnerUUID() {
return UUID
.fromString(
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
ownerUUID.toString() + ".yml"))
.getFileConfiguration().getString("Ownership.Original"));
return UUID.fromString(skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml"))
.getFileConfiguration().getString("Ownership.Original"));
}
public int getSize() {
@ -772,9 +766,9 @@ public class Island {
.getConfig(new File(skyblock.getDataFolder().toString() + "/setting-data", ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
for (IslandRole roleList : islandSettings.keySet()) {
for (IslandSetting settingList : islandSettings.get(roleList)) {
configLoad.set("Settings." + roleList + "." + settingList.getName(), settingList.getStatus());
for (Entry<IslandRole, List<IslandSetting>> entry : islandSettings.entrySet()) {
for (IslandSetting setting : entry.getValue()) {
configLoad.set("Settings." + entry.getKey() + "." + setting.getName(), setting.getStatus());
}
}
@ -790,7 +784,7 @@ public class Island {
.getConfig(new File(skyblock.getDataFolder().toString() + "/coop-data", ownerUUID.toString() + ".yml"));
configLoad = config.getFileConfiguration();
List<String> coopPlayersAsString = new ArrayList<>();
List<String> coopPlayersAsString = new ArrayList<>(coopPlayers.size());
for (Map.Entry<UUID, IslandCoop> entry : coopPlayers.entrySet()) {
if (entry.getValue() == IslandCoop.TEMP) continue;

View File

@ -2,12 +2,16 @@ package com.songoda.skyblock.island;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.config.FileManager.Config;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
public class IslandLevel {
@ -25,18 +29,25 @@ public class IslandLevel {
this.skyblock = skyblock;
this.ownerUUID = ownerUUID;
Config config = skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
Config config = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
Map<String, Long> materials = new HashMap<>();
Map<String, Long> materials;
if (configLoad.getString("Levelling.Materials") != null) {
for (String materialList : configLoad.getConfigurationSection("Levelling.Materials").getKeys(false)) {
if (configLoad.getString("Levelling.Materials." + materialList + ".Amount") != null) {
materials.put(materialList, configLoad.getLong("Levelling.Materials." + materialList + ".Amount"));
}
ConfigurationSection materialSection = configLoad.getConfigurationSection("Leveling.Materials");
if (materialSection != null) {
Set<String> keys = materialSection.getKeys(false);
materials = new HashMap<>(keys.size() * 2);
for (String material : materialSection.getKeys(false)) {
final ConfigurationSection current = materialSection.getConfigurationSection(material);
if (current.isSet("Amount")) materials.put(material, current.getLong("Amount"));
}
} else {
materials = new HashMap<>();
}
this.materials = materials;
@ -50,18 +61,18 @@ public class IslandLevel {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
ConfigurationSection materialSection = configLoad.getConfigurationSection("Materials");
if (materialSection == null) return 0;
long pointsEarned = 0;
for (String materialList : this.materials.keySet()) {
long materialAmount = this.materials.get(materialList);
for (Entry<String, Long> entry : this.materials.entrySet()) {
ConfigurationSection current = materialSection.getConfigurationSection(entry.getKey());
if (configLoad.getString("Materials." + materialList + ".Points") != null) {
long pointsRequired = config.getFileConfiguration().getLong("Materials." + materialList + ".Points");
long pointsRequired = current.getLong("Points", 0);
if (pointsRequired != 0) {
pointsEarned = pointsEarned + (materialAmount * pointsRequired);
}
}
if (pointsRequired != 0) pointsEarned = pointsEarned + (entry.getValue() * pointsRequired);
}
return pointsEarned;
@ -71,26 +82,25 @@ public class IslandLevel {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
long pointsEarned = 0;
ConfigurationSection materialSection = configLoad.getConfigurationSection("Materials");
if (this.materials.containsKey(material)) {
long materialAmount = this.materials.get(material);
if (materialSection == null) return 0;
if (configLoad.getString("Materials." + material + ".Points") != null) {
long pointsRequired = configLoad.getLong("Materials." + material + ".Points");
ConfigurationSection current = materialSection.getConfigurationSection(material);
if (pointsRequired != 0) {
pointsEarned = materialAmount * pointsRequired;
}
}
}
if (current == null) return 0;
return pointsEarned;
Long boxedAmount = this.materials.get(material);
if (boxedAmount == null) return 0;
long pointsRequired = current.getLong("Points");
return pointsRequired == 0 ? 0 : boxedAmount * pointsRequired;
}
public long getLevel() {
long division = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getLong("Island.Levelling.Division");
long division = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getLong("Island.Levelling.Division");
if (division == 0) {
division = 1;
@ -100,27 +110,19 @@ public class IslandLevel {
}
public void setMaterialAmount(String material, long amount) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"),
ownerUUID.toString() + ".yml"))
.getFileConfiguration().set("Levelling.Materials." + material + ".Amount", amount);
skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")).getFileConfiguration()
.set("Levelling.Materials." + material + ".Amount", amount);
this.materials.put(material, amount);
}
public long getMaterialAmount(String material) {
if (this.materials.containsKey(material)) {
return this.materials.get(material);
}
return 0;
return this.materials.getOrDefault(material, 0l);
}
public void removeMaterial(String material) {
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"),
ownerUUID.toString() + ".yml"))
.getFileConfiguration().set("Levelling.Materials." + material, null);
skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")).getFileConfiguration()
.set("Levelling.Materials." + material, null);
this.materials.remove(material);
}
@ -138,8 +140,7 @@ public class IslandLevel {
}
public void setMaterials(Map<String, Long> materials) {
Config config = skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
Config config = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration();
configLoad.set("Levelling.Materials", null);
@ -168,8 +169,7 @@ public class IslandLevel {
}
public void save() {
Config config = skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
Config config = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();

View File

@ -615,6 +615,7 @@ public class IslandManager {
if (island.isDeleted()) return;
island.save();
int islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1,
islandVisitors = getVisitorsAtIsland(island).size();
@ -627,7 +628,7 @@ public class IslandManager {
if (island.hasRole(IslandRole.Member, all.getUniqueId())
|| island.hasRole(IslandRole.Operator, all.getUniqueId())
|| island.hasRole(IslandRole.Owner, all.getUniqueId())) {
|| island.hasRole(IslandRole.Owner, all.getUniqueId()) || island.getCoopType(all.getUniqueId()) == IslandCoop.NORMAL) {
if (scoreboardManager != null) {
try {
if (islandMembers == 1 && islandVisitors == 0) {
@ -1291,7 +1292,9 @@ public class IslandManager {
for (UUID coopPlayerAtIslandList : getCoopPlayersAtIsland(island)) {
Player targetPlayer = Bukkit.getServer().getPlayer(coopPlayerAtIslandList);
if(island.getCoopType(coopPlayerAtIslandList) == IslandCoop.NORMAL) continue;
if (targetPlayer != null) {
LocationUtil.teleportPlayerToSpawn(targetPlayer);

View File

@ -1,7 +1,21 @@
package com.songoda.skyblock.island;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum IslandRole {
Coop, Visitor, Member, Operator, Owner
Coop,
Visitor,
Member,
Operator,
Owner;
private static final Set<IslandRole> roles = Collections.unmodifiableSet(EnumSet.allOf(IslandRole.class));
public static Set<IslandRole> getRoles() {
return roles;
}
}

View File

@ -27,9 +27,9 @@ public class TopBank extends DataCollector {
@Override
public List<Entry<?, Double>> requestAll() {
Map<UUID, Double> topLevels = new HashMap<>();
List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Bank);
Map<UUID, Double> topLevels = new HashMap<>(leaderboards.size());
for (Leaderboard leaderboard : leaderboards) {
Visit visit = leaderboard.getVisit();

View File

@ -26,9 +26,9 @@ public class TopLevel extends DataCollector {
@Override
public List<Entry<?, Double>> requestAll() {
Map<UUID, Double> topLevels = new HashMap<>();
List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Leaderboard.Type.Level);
Map<UUID, Double> topLevels = new HashMap<>(leaderboards.size());
for (int i = 0; i < leaderboards.size(); i++) {
Leaderboard leaderboard = leaderboards.get(i);

View File

@ -27,10 +27,10 @@ public class TopVotes extends DataCollector {
@Override
public List<Entry<?, Double>> requestAll() {
Map<UUID, Double> topLevels = new HashMap<>();
List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Votes);
Map<UUID, Double> topLevels = new HashMap<>(leaderboards.size());
for (int i = 0; i < leaderboards.size(); i++) {
Leaderboard leaderboard = leaderboards.get(i);
Visit visit = leaderboard.getVisit();

View File

@ -0,0 +1,77 @@
package com.songoda.skyblock.limit;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
public abstract class EnumLimitation<K extends Enum<K>> implements Limitation {
private long defaultLimit;
private final Class<K> type;
private final Map<K, Long> map;
public EnumLimitation(Class<K> type) {
this.defaultLimit = -1;
this.map = new EnumMap<>(type);
this.type = type;
}
public boolean isBeingTracked(Enum<K> type) {
return map.containsKey(type) || getDefault() >= 0;
}
protected Map<K, Long> getMap() {
return map;
}
public long getDefault() {
return defaultLimit;
}
public boolean hasTooMuch(long currentAmount, Enum<K> type) {
final long cached = map.getOrDefault(type, getDefault());
if (cached <= -1) return false;
return currentAmount > cached;
}
@Override
public void reload(ConfigurationSection loadFrom) {
unload();
if (loadFrom == null) return;
final Set<String> keys = loadFrom.getKeys(false);
removeAndLoadDefaultLimit(loadFrom, keys);
for (String key : keys) {
final String enumName = key.toUpperCase(Locale.ENGLISH);
try {
map.put(Enum.valueOf(type, enumName), loadFrom.getLong(key));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Incorrect enum constant '" + enumName + "' in " + loadFrom.getCurrentPath(), e);
}
}
}
@Override
public void unload() {
map.clear();
defaultLimit = -1;
}
protected void removeAndLoadDefaultLimit(ConfigurationSection loadFrom, Set<String> keys) {
keys.remove("DefaultLimit");
defaultLimit = loadFrom.getInt("DefaultLimit", -1);
}
}

View File

@ -1,115 +0,0 @@
package com.songoda.skyblock.limit;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.island.Island;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.utils.version.Materials;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class LimitManager {
private final SkyBlock skyblock;
private Map<Materials, Long> blockLimits;
public LimitManager(SkyBlock skyblock) {
this.skyblock = skyblock;
this.blockLimits = new HashMap<>();
this.reload();
}
public void reload() {
this.blockLimits.clear();
FileConfiguration limitsConfig = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "limits.yml")).getFileConfiguration();
ConfigurationSection blockLimitSection = limitsConfig.getConfigurationSection("block");
if (blockLimitSection != null) {
for (String materialString : blockLimitSection.getKeys(false)) {
Materials material = Materials.fromString(materialString);
if (material != null) {
long limit = blockLimitSection.getLong(materialString);
this.blockLimits.put(material, limit);
}
}
}
}
/**
* Gets the max number of a type of block a player can place
*
* @param player The player to check
* @param block The block to check
* @return The max number of the type of block the player can place
*/
public long getBlockLimit(Player player, Block block) {
if (player == null || block == null)
return -1;
if (player.hasPermission("fabledskyblock.limit.block.*"))
return -1;
Materials material = Materials.getMaterials(block.getType(), block.getData());
if (material == null)
return -1;
long limit = -1;
if (this.blockLimits.containsKey(material))
limit = Math.max(limit, this.blockLimits.get(material));
Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions()
.stream()
.filter(x -> x.getPermission().toLowerCase().startsWith("fabledskyblock.limit.block." + material.name().toLowerCase()))
.collect(Collectors.toSet());
for (PermissionAttachmentInfo permission : permissions) {
try {
String permString = permission.getPermission();
String numberString = permString.substring(permString.lastIndexOf(".") + 1);
if (numberString.equals("*"))
return -1;
limit = Math.max(limit, Integer.parseInt(numberString));
} catch (Exception ignored) {
}
}
return limit;
}
/**
* Checks if a player has exceeded the number of blocks they can place
*
* @param player The player to check
* @param block The block to check
* @return true if the player has exceeded the block limit, otherwise false
*/
public boolean isBlockLimitExceeded(Player player, Block block) {
IslandManager islandManager = this.skyblock.getIslandManager();
long limit = this.getBlockLimit(player, block);
if (limit == -1)
return false;
Island island = islandManager.getIslandAtLocation(block.getLocation());
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;
}
}

View File

@ -0,0 +1,13 @@
package com.songoda.skyblock.limit;
import org.bukkit.configuration.ConfigurationSection;
public interface Limitation {
void unload();
void reload(ConfigurationSection loadFrom);
String getSectionName();
}

View File

@ -0,0 +1,42 @@
package com.songoda.skyblock.limit;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.configuration.Configuration;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.limit.impl.BlockLimitation;
import com.songoda.skyblock.limit.impl.EntityLimitaton;
public final class LimitationInstanceHandler {
private final Map<Class<? extends Limitation>, Limitation> instances;
public LimitationInstanceHandler() {
this.instances = new HashMap<>();
registerInstance(new EntityLimitaton());
registerInstance(new BlockLimitation());
reloadAll();
}
public <T extends Limitation> T getInstance(Class<T> type) {
return type.cast(instances.get(type));
}
public void registerInstance(Limitation instance) {
instances.put(instance.getClass(), instance);
}
public void reloadAll() {
final SkyBlock instance = SkyBlock.getInstance();
final Configuration config = instance.getFileManager().getConfig(new File(instance.getDataFolder(), "limits.yml")).getFileConfiguration();
for (Limitation limit : instances.values()) {
limit.reload(config.getConfigurationSection(limit.getSectionName()));
}
}
}

View File

@ -0,0 +1,106 @@
package com.songoda.skyblock.limit.impl;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.island.Island;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.limit.EnumLimitation;
import com.songoda.skyblock.utils.version.Materials;
public final class BlockLimitation extends EnumLimitation<Materials> {
public BlockLimitation() {
super(Materials.class);
}
@Override
public String getSectionName() {
return "block";
}
@Override
public boolean hasTooMuch(long currentAmount, Enum<Materials> type) {
throw new UnsupportedOperationException("Not implemented. Use getBlockLimit and isBlockLimitExceeded instead.");
}
@Override
public void reload(ConfigurationSection loadFrom) {
unload();
if (loadFrom == null) return;
final Set<String> keys = loadFrom.getKeys(false);
removeAndLoadDefaultLimit(loadFrom, keys);
for (String key : keys) {
final String enumName = key.toUpperCase(Locale.ENGLISH);
final Materials type = Materials.fromString(enumName);
if (type == null) throw new IllegalArgumentException("Unable to parse Materials from '" + enumName + "' in " + loadFrom.getCurrentPath());
getMap().put(type, loadFrom.getLong(key));
}
}
@SuppressWarnings("deprecation")
public long getBlockLimit(Player player, Block block) {
if (player == null || block == null) return -1;
if (player.hasPermission("fabledskyblock.limit.block.*")) return -1;
final Materials material = Materials.getMaterials(block.getType(), block.getData());
if (material == null) return -1;
long limit = getMap().getOrDefault(material, getDefault());
final String name = material.name().toLowerCase();
Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions().stream()
.filter(x -> x.getPermission().toLowerCase().startsWith("fabledskyblock.limit.block." + name)).collect(Collectors.toSet());
for (PermissionAttachmentInfo permission : permissions) {
try {
String permString = permission.getPermission();
String numberString = permString.substring(permString.lastIndexOf(".") + 1);
if (numberString.equals("*")) return -1;
limit = Math.max(limit, Integer.parseInt(numberString));
} catch (Exception ignored) {
}
}
return limit;
}
@SuppressWarnings("deprecation")
public boolean isBlockLimitExceeded(Player player, Block block, long limit) {
if (limit == -1) return false;
final IslandManager islandManager = SkyBlock.getInstance().getIslandManager();
final Island island = islandManager.getIslandAtLocation(block.getLocation());
final 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;
}
}

View File

@ -0,0 +1,55 @@
package com.songoda.skyblock.limit.impl;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import com.songoda.skyblock.island.Island;
import com.songoda.skyblock.island.IslandEnvironment;
import com.songoda.skyblock.island.IslandWorld;
import com.songoda.skyblock.limit.EnumLimitation;
public final class EntityLimitaton extends EnumLimitation<EntityType> {
public EntityLimitaton() {
super(EntityType.class);
}
public long getEntityCount(Island island, IslandWorld islandWorld, EntityType type) {
final Location islandLocation = island.getLocation(islandWorld, IslandEnvironment.Island);
final World world = islandLocation.getWorld();
final Location minLocation = new Location(world, islandLocation.getBlockX() - island.getRadius(), 0,
islandLocation.getBlockZ() - island.getRadius());
final Location maxLocation = new Location(world, islandLocation.getBlockX() + island.getRadius(), world.getMaxHeight(),
islandLocation.getBlockZ() + island.getRadius());
final int minX = Math.min(maxLocation.getBlockX(), minLocation.getBlockX());
final int minZ = Math.min(maxLocation.getBlockZ(), minLocation.getBlockZ());
final int maxX = Math.max(maxLocation.getBlockX(), minLocation.getBlockX());
final int maxZ = Math.max(maxLocation.getBlockZ(), minLocation.getBlockZ());
int count = 0;
for (int x = minX; x < maxX + 16; x += 16) {
for (int z = minZ; z < maxZ + 16; z += 16) {
final Chunk chunk = world.getChunkAt(x >> 4, z >> 4);
for (Entity ent : chunk.getEntities()) {
if (ent.getType() == type) count++;
}
}
}
return count;
}
@Override
public String getSectionName() {
return "entity";
}
}

View File

@ -43,7 +43,7 @@ import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.island.IslandRole;
import com.songoda.skyblock.island.IslandWorld;
import com.songoda.skyblock.levelling.LevellingManager;
import com.songoda.skyblock.limit.LimitManager;
import com.songoda.skyblock.limit.impl.BlockLimitation;
import com.songoda.skyblock.stackable.Stackable;
import com.songoda.skyblock.stackable.StackableManager;
import com.songoda.skyblock.utils.NumberUtil;
@ -74,14 +74,17 @@ public class Block implements Listener {
if (!worldManager.isIslandWorld(block.getWorld())) return;
IslandWorld world = worldManager.getIslandWorld(block.getWorld());
Island island = islandManager.getIslandAtLocation(block.getLocation());
Location blockLocation = block.getLocation();
Island island = islandManager.getIslandAtLocation(blockLocation);
if (island == null) {
event.setCancelled(true);
return;
}
if (!islandManager.hasPermission(player, block.getLocation(), "Destroy")) {
if (!islandManager.hasPermission(player, blockLocation, "Destroy")) {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
@ -91,7 +94,7 @@ public class Block implements Listener {
}
if (stackableManager != null
&& stackableManager.isStacked(block.getLocation())) {
&& stackableManager.isStacked(blockLocation)) {
Stackable stackable = stackableManager.getStack(block.getLocation(), block.getType());
if (stackable != null) {
Material material = block.getType();
@ -99,7 +102,7 @@ public class Block implements Listener {
int droppedAmount = 0;
if (event.getPlayer().isSneaking()) {
Location dropLoc = event.getBlock().getLocation().add(0.5, 0.5, 0.5);
Location dropLoc = blockLocation.clone().add(0.5, 0.5, 0.5);
int count = stackable.getSize();
droppedAmount = count;
while (count > 64) {
@ -110,7 +113,7 @@ public class Block implements Listener {
block.setType(Material.AIR);
stackable.setSize(0);
} else {
block.getWorld().dropItemNaturally(block.getLocation().add(.5, 1, .5), new ItemStack(material, 1, data));
block.getWorld().dropItemNaturally(blockLocation.clone().add(.5, 1, .5), new ItemStack(material, 1, data));
stackable.takeOne();
droppedAmount = 1;
}
@ -247,15 +250,18 @@ public class Block implements Listener {
}
}
LimitManager limitManager = skyblock.getLimitManager();
if (limitManager.isBlockLimitExceeded(player, block)) {
BlockLimitation limits = skyblock.getLimitationHandler().getInstance(BlockLimitation.class);
long limit = limits.getBlockLimit(player, block);
if (limits.isBlockLimitExceeded(player, block, limit)) {
Materials material = Materials.getMaterials(block.getType(), block.getData());
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Limit.Block.Exceeded.Message")
.replace("%type", WordUtils.capitalizeFully(material.name().replace("_", " ")))
.replace("%limit", NumberUtil.formatNumber(limitManager.getBlockLimit(player, block))));
.replace("%limit", NumberUtil.formatNumber(limit)));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
event.setCancelled(true);

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ import com.songoda.skyblock.island.IslandLevel;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.island.IslandWorld;
import com.songoda.skyblock.levelling.LevellingManager;
import com.songoda.skyblock.limit.LimitManager;
import com.songoda.skyblock.limit.impl.BlockLimitation;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.sound.SoundManager;
import com.songoda.skyblock.stackable.Stackable;
@ -157,21 +157,24 @@ public class Interact implements Listener {
return;
}
LimitManager limitManager = skyblock.getLimitManager();
if (limitManager.isBlockLimitExceeded(player, block)) {
Materials material = Materials.getMaterials(block.getType(), block.getData());
BlockLimitation limits = skyblock.getLimitationHandler().getInstance(BlockLimitation.class);
long limit = limits.getBlockLimit(player, block);
if (limits.isBlockLimitExceeded(player, block, limit)) {
Materials material = Materials.getMaterials(block.getType(), block.getData());
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Limit.Block.Exceeded.Message")
.replace("%type", WordUtils.capitalizeFully(material.name().replace("_", " ")))
.replace("%limit", NumberUtil.formatNumber(limitManager.getBlockLimit(player, block))));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Limit.Block.Exceeded.Message")
.replace("%type", WordUtils.capitalizeFully(material.name().replace("_", " ")))
.replace("%limit", NumberUtil.formatNumber(limit)));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
event.setCancelled(true);
return;
event.setCancelled(true);
return;
}
Location location = event.getClickedBlock().getLocation();
if (stackableManager.isStacked(location)) {
Stackable stackable = stackableManager.getStack(location, event.getMaterial());

View File

@ -14,11 +14,7 @@ public class Area {
}
public Location getPosition(int position) {
if (positions.containsKey(position)) {
return positions.get(position);
}
return null;
return positions.get(position);
}
public void setPosition(int position, Location location) {

View File

@ -40,14 +40,14 @@ public class SchematicUtil {
// TODO: Cache this later
try {
Class<?> bukkitWorldClass = Class.forName("com.sk89q.worldedit.bukkit.BukkitWorld");
Constructor bukkitWorldConstructor = bukkitWorldClass.getConstructor(World.class);
Constructor<?> bukkitWorldConstructor = bukkitWorldClass.getConstructor(World.class);
Class<?> editSessionClass = Class.forName("com.sk89q.worldedit.EditSession");
Class<?> localWorldClass = Class.forName("com.sk89q.worldedit.LocalWorld");
Constructor editSessionConstructor = editSessionClass.getConstructor(localWorldClass, int.class);
Constructor<?> editSessionConstructor = editSessionClass.getConstructor(localWorldClass, int.class);
Class<?> cuboidClipboardClass = Class.forName("com.sk89q.worldedit.CuboidClipboard");
Method loadSchematicMethod = cuboidClipboardClass.getMethod("loadSchematic", File.class);
Class<?> vectorClass = Class.forName("com.sk89q.worldedit.Vector");
Constructor vectorConstructor = vectorClass.getConstructor(double.class, double.class, double.class);
Constructor<?> vectorConstructor = vectorClass.getConstructor(double.class, double.class, double.class);
Method pasteMethod = cuboidClipboardClass.getMethod("paste", editSessionClass, vectorClass, boolean.class);
Object editSessionObj = editSessionConstructor.newInstance(bukkitWorldConstructor.newInstance(location.getWorld()), 999999999);

View File

@ -6,7 +6,6 @@ import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.utils.Compression;
import com.songoda.skyblock.utils.version.NMSUtil;
import com.songoda.skyblock.utils.world.LocationUtil;
import com.songoda.skyblock.utils.world.block.BlockData;
@ -26,7 +25,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

View File

@ -242,6 +242,8 @@ Command:
Message: '&bSkyBlock &8| &aInfo&8: &eThis island will unload.'
Info:
Message: '&f&oKeeps an island from unloading.'
No-Player-Input:
Message: '&bSkyBlock &8| &cError&8: &ePlease input a player.'
Proxy:
IsOn:
Message: '&bSkyBlock &8| &aInfo&8: &eYou are now proxying %player.'

View File

@ -1,3 +1,6 @@
block:
BEDROCK: 0
END_PORTAL_FRAME: 12
DefaultLimit: -1
BEDROCK: 0
END_PORTAL_FRAME: 12
entity:
DefaultLimit: -1