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,13 +95,9 @@ public class BanManager {
}
public Ban getIsland(UUID islandOwnerUUID) {
if (hasIsland(islandOwnerUUID)) {
return banStorage.get(islandOwnerUUID);
}
return null;
}
public Map<UUID, Ban> getIslands() {
return banStorage;
}
@ -116,10 +111,8 @@ public class BanManager {
}
public void removeIsland(UUID islandOwnerUUID) {
if (hasIsland(islandOwnerUUID)) {
banStorage.remove(islandOwnerUUID);
}
}
public void unloadIsland(UUID islandOwnerUUID) {
if (hasIsland(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,7 +31,6 @@ 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);
}
}

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,14 +15,10 @@ public class ConfirmationTask extends BukkitRunnable {
@Override
public void run() {
for (Player all : Bukkit.getOnlinePlayers()) {
if (playerDataManager.hasPlayerData(all)) {
PlayerData playerData = playerDataManager.getPlayerData(all);
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,7 +93,10 @@ public class CooldownManager {
public void createPlayer(CooldownType cooldownType, OfflinePlayer player) {
FileManager fileManager = skyblock.getFileManager();
if (cooldownStorage.containsKey(cooldownType)) {
List<CooldownPlayer> cooldowns = cooldownStorage.get(cooldownType);
if (cooldowns == null) return;
int time = 0;
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
@ -103,8 +104,7 @@ public class CooldownManager {
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
Config config = fileManager
.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"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();
@ -120,8 +120,7 @@ public class CooldownManager {
.getInt("Island." + cooldownType.name() + ".Cooldown.Time");
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"));
File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration();
@ -134,127 +133,101 @@ public class CooldownManager {
}
}
cooldownStorage.get(cooldownType).add(new CooldownPlayer(player.getUniqueId(), new Cooldown(time)));
}
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())) {
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"))
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);
it.remove();
break;
}
}
}
}
public boolean hasPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return true;
}
}
}
return false;
}
public void transferPlayer(CooldownType cooldownType, OfflinePlayer player1, OfflinePlayer player2) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
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);
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)) {
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)) {
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());
.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());
.getFileConfiguration().set(cooldownType.name() + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
}
break;
}
}
}
}
public void saveCooldownPlayer(CooldownType cooldownType) {
if (cooldownStorage.containsKey(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
saveCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
}
}
}
public void saveCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
Config config = null;
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,34 +240,42 @@ 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)) {
for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return cooldownPlayerList;
}
}
}
return null;
}
public List<CooldownPlayer> getCooldownPlayers(CooldownType cooldownType) {
if (cooldownStorage.containsKey(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,9 +15,10 @@ 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);
if (cooldownPlayers == null) return;
for (int i = 0; i < cooldownPlayers.size(); i++) {
CooldownPlayer cooldownPlayer = cooldownPlayers.get(i);
@ -26,11 +27,10 @@ public class CooldownTask extends BukkitRunnable {
cooldown.setTime(cooldown.getTime() - 1);
if (cooldown.getTime() <= 0) {
cooldownManager.deletePlayer(cooldownTypeList,
Bukkit.getServer().getOfflinePlayer(cooldownPlayer.getUUID()));
}
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);
}
}
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,13 +40,9 @@ public class InviteManager {
}
public Invite getInvite(UUID uuid) {
if (hasInvite(uuid)) {
return inviteStorage.get(uuid);
}
return null;
}
public boolean hasInvite(UUID uuid) {
return inviteStorage.containsKey(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,11 +225,7 @@ public class Island {
}
public UUID getOriginalOwnerUUID() {
return UUID
.fromString(
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
ownerUUID.toString() + ".yml"))
return UUID.fromString(skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml"))
.getFileConfiguration().getString("Ownership.Original"));
}
@ -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

@ -616,6 +616,7 @@ public class IslandManager {
island.save();
int islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1,
islandVisitors = getVisitorsAtIsland(island).size();
boolean unloadIsland = true;
@ -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) {
@ -1292,6 +1293,8 @@ 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,9 +27,9 @@ 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);

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);

View File

@ -3,6 +3,7 @@ package com.songoda.skyblock.listeners;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -55,7 +56,6 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.collect.Sets;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.config.FileManager.Config;
@ -65,6 +65,7 @@ import com.songoda.skyblock.island.IslandLevel;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.island.IslandRole;
import com.songoda.skyblock.island.IslandWorld;
import com.songoda.skyblock.limit.impl.EntityLimitaton;
import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.sound.SoundManager;
import com.songoda.skyblock.stackable.StackableManager;
@ -102,8 +103,7 @@ public class Entity implements Listener {
} else if (event.getCause() == DamageCause.ENTITY_ATTACK) {
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event;
if (entityDamageByEntityEvent.getDamager() != null
&& entityDamageByEntityEvent.getDamager() instanceof Player) {
if (entityDamageByEntityEvent.getDamager() != null && entityDamageByEntityEvent.getDamager() instanceof Player) {
return;
}
} else {
@ -111,8 +111,7 @@ public class Entity implements Listener {
if (event.getCause() == DamageCause.valueOf("ENTITY_SWEEP_ATTACK")) {
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) event;
if (entityDamageByEntityEvent.getDamager() != null
&& entityDamageByEntityEvent.getDamager() instanceof Player) {
if (entityDamageByEntityEvent.getDamager() != null && entityDamageByEntityEvent.getDamager() instanceof Player) {
return;
}
}
@ -132,7 +131,8 @@ public class Entity implements Listener {
}
}
// Fix a bug in minecraft where arrows with flame still apply fire ticks even if the shot entity isn't damaged
// Fix a bug in minecraft where arrows with flame still apply fire ticks even if
// the shot entity isn't damaged
if (preventFireTicks.contains(player.getUniqueId()) && event.getCause() == DamageCause.FIRE_TICK) {
player.setFireTicks(0);
event.setCancelled(true);
@ -166,8 +166,7 @@ public class Entity implements Listener {
if (!islandManager.hasPermission(player, entity.getLocation(), "Destroy")) {
event.setCancelled(true);
messageManager.sendMessage(player,
fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
@ -175,8 +174,7 @@ public class Entity implements Listener {
if (!islandManager.hasPermission(player, entity.getLocation(), "MobHurting")) {
event.setCancelled(true);
messageManager.sendMessage(player,
fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
@ -213,8 +211,7 @@ public class Entity implements Listener {
if (!islandManager.hasPermission(player, entity.getLocation(), "MobHurting")) {
event.setCancelled(true);
messageManager.sendMessage(player,
fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
messageManager.sendMessage(player, fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
soundManager.playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
@ -230,9 +227,8 @@ public class Entity implements Listener {
FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.Settings.Damage.Enable")) {
if (!islandManager.hasSetting(player.getLocation(), IslandRole.Owner, "Damage")
|| (event.getDamager() instanceof TNTPrimed && !islandManager
.hasSetting(player.getLocation(), IslandRole.Owner, "Explosions"))) {
if (!islandManager.hasSetting(player.getLocation(), IslandRole.Owner, "Damage") || (event.getDamager() instanceof TNTPrimed
&& !islandManager.hasSetting(player.getLocation(), IslandRole.Owner, "Explosions"))) {
event.setCancelled(true);
}
} else if (!configLoad.getBoolean("Island.Damage.Enable")) {
@ -249,8 +245,10 @@ public class Entity implements Listener {
}
}
// Fix a bug in minecraft where arrows with flame still apply fire ticks even if the shot entity isn't damaged
if (event.isCancelled() && event.getEntity() != null && event.getDamager() instanceof Arrow && ((Arrow) event.getDamager()).getShooter() instanceof Player) {
// Fix a bug in minecraft where arrows with flame still apply fire ticks even if
// the shot entity isn't damaged
if (event.isCancelled() && event.getEntity() != null && event.getDamager() instanceof Arrow
&& ((Arrow) event.getDamager()).getShooter() instanceof Player) {
Arrow arrow = (Arrow) event.getDamager();
if (arrow.getFireTicks() != 0) {
preventFireTicks.add(event.getEntity().getUniqueId());
@ -272,8 +270,8 @@ public class Entity implements Listener {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration()
.getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
@ -281,26 +279,24 @@ public class Entity implements Listener {
/**
* Checks that an entity is not targeting another entity on different islands.
*
* @author LimeGlass
*/
@EventHandler
public void onEntityTarget(EntityTargetEvent event) {
org.bukkit.entity.Entity entity = event.getEntity();
WorldManager worldManager = skyblock.getWorldManager();
if (!worldManager.isIslandWorld(entity.getWorld()))
return;
if (!worldManager.isIslandWorld(entity.getWorld())) return;
org.bukkit.entity.Entity target = event.getTarget();
// Somehow the target can be null, thanks Spigot.
if (target == null)
return;
if (target == null) return;
IslandManager islandManager = skyblock.getIslandManager();
Island entityIsland = islandManager.getIslandAtLocation(entity.getLocation());
Island targetIsland = islandManager.getIslandAtLocation(target.getLocation());
// Event not related to Skyblock islands.
if (entityIsland == null && targetIsland == null)
return;
if (entityIsland == null && targetIsland == null) return;
// One entity is on an island, and the other isn't.
if (entityIsland == null || targetIsland == null) {
event.setCancelled(true);
@ -319,18 +315,15 @@ public class Entity implements Listener {
if (!skyblock.getIslandManager().hasPermission(player, event.getRightClicked().getLocation(), "ArmorStandUse")) {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
skyblock.getMessageManager().sendMessage(player, skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
if (NMSUtil.getVersionNumber() != 8)
return;
if (NMSUtil.getVersionNumber() != 8) return;
StackableManager stackableManager = SkyBlock.getInstance().getStackableManager();
if (stackableManager == null)
return;
if (stackableManager == null) return;
ArmorStand armorStand = event.getRightClicked();
for (Location stackLocation : stackableManager.getStacks().keySet()) {
@ -346,13 +339,12 @@ public class Entity implements Listener {
Player player = event.getPlayer();
if (skyblock.getWorldManager().isIslandWorld(player.getWorld())) {
if (!skyblock.getIslandManager().hasPermission(player, event.getEntity().getLocation(),
"EntityPlacement")) {
if (!skyblock.getIslandManager().hasPermission(player, event.getEntity().getLocation(), "EntityPlacement")) {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration()
.getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
@ -388,8 +380,8 @@ public class Entity implements Listener {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration()
.getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
@ -409,8 +401,8 @@ public class Entity implements Listener {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration()
.getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
@ -430,8 +422,8 @@ public class Entity implements Listener {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration()
.getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
@ -450,8 +442,8 @@ public class Entity implements Listener {
event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Settings.Permission.Message"));
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")).getFileConfiguration()
.getString("Island.Settings.Permission.Message"));
skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
}
}
@ -482,22 +474,25 @@ public class Entity implements Listener {
org.bukkit.block.Block block = event.getBlock();
// Check spawn block falling, this can be a bit glitchy, but it's better than nothing
// Check spawn block falling, this can be a bit glitchy, but it's better than
// nothing
if ((LocationUtil.isLocationLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Main).clone().subtract(0, 1, 0))
|| LocationUtil.isLocationLocation(block.getLocation(), island.getLocation(world, IslandEnvironment.Visitor).clone().subtract(0, 1, 0))) &&
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
|| LocationUtil.isLocationLocation(block.getLocation(),
island.getLocation(world, IslandEnvironment.Visitor).clone().subtract(0, 1, 0)))
&& skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Spawn.Protection")) {
event.setCancelled(true);
return;
}
if ((event.getEntityType() == EntityType.FALLING_BLOCK) && LocationUtil.isLocationLocation(event.getBlock().getLocation(),
island.getLocation(world, IslandEnvironment.Main)
.clone())
if ((event.getEntityType() == EntityType.FALLING_BLOCK)
&& LocationUtil.isLocationLocation(event.getBlock().getLocation(), island.getLocation(world, IslandEnvironment.Main).clone())
&& configLoad.getBoolean("Island.Spawn.Protection")) {
FallingBlock fallingBlock = (FallingBlock) event.getEntity();
if (fallingBlock.getDropItem()) {
if (NMSUtil.getVersionNumber() > 12) {
fallingBlock.getWorld().dropItemNaturally(fallingBlock.getLocation(), new ItemStack(fallingBlock.getBlockData().getMaterial(), 1));
fallingBlock.getWorld().dropItemNaturally(fallingBlock.getLocation(),
new ItemStack(fallingBlock.getBlockData().getMaterial(), 1));
} else {
try {
Method getBlockDataMethod = FallingBlock.class.getMethod("getBlockData");
@ -513,12 +508,11 @@ public class Entity implements Listener {
event.setCancelled(true);
}
if (entity instanceof FallingBlock)
return;
if (entity instanceof FallingBlock) return;
// Check entities interacting with spawn
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) &&
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
if (LocationUtil.isLocationAffectingIslandSpawn(block.getLocation(), island, world) && skyblock.getFileManager()
.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
event.setCancelled(true);
return;
}
@ -527,8 +521,9 @@ public class Entity implements Listener {
event.setCancelled(true);
}
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getBoolean("Island.Block.Level.Enable")) return;
if (!skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Block.Level.Enable"))
return;
Materials materials = Materials.getMaterials(block.getType(), block.getData());
@ -553,10 +548,9 @@ public class Entity implements Listener {
materials = Materials.fromString(event.getTo().name());
} else {
try {
materials = Materials.requestMaterials(event.getTo().name(),
(byte) event.getClass().getMethod("getData").invoke(event));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e) {
materials = Materials.requestMaterials(event.getTo().name(), (byte) event.getClass().getMethod("getData").invoke(event));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
e.printStackTrace();
}
}
@ -591,8 +585,8 @@ public class Entity implements Listener {
Island island = islandManager.getIslandAtLocation(entity.getLocation());
if (island != null) {
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"))
.getFileConfiguration().getBoolean("Island.Block.Level.Enable")) {
if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Block.Level.Enable")) {
for (org.bukkit.block.Block blockList : event.blockList()) {
@SuppressWarnings("deprecation")
Materials materials = Materials.getMaterials(blockList.getType(), blockList.getData());
@ -613,13 +607,12 @@ public class Entity implements Listener {
}
}
if (SkyBlock.getInstance().getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Spawn.Protection")) {
if (SkyBlock.getInstance().getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration()
.getBoolean("Island.Spawn.Protection")) {
IslandWorld world = worldManager.getIslandWorld(event.getEntity().getWorld());
for (org.bukkit.block.Block block : event.blockList()) {
if (LocationUtil.isLocationLocation(block.getLocation(),
island.getLocation(world, IslandEnvironment.Main)
.clone()
.subtract(0.0D, 1.0D, 0.0D))) {
island.getLocation(world, IslandEnvironment.Main).clone().subtract(0.0D, 1.0D, 0.0D))) {
event.blockList().remove(block);
break;
}
@ -635,29 +628,23 @@ public class Entity implements Listener {
LivingEntity livingEntity = event.getEntity();
// Certain entities shouldn't drop twice the amount
if (livingEntity instanceof Player
|| livingEntity instanceof ArmorStand
|| livingEntity instanceof Horse) {
if (livingEntity instanceof Player || livingEntity instanceof ArmorStand || livingEntity instanceof Horse) {
return;
}
if (NMSUtil.getVersionNumber() > 9) {
if (livingEntity instanceof Donkey || livingEntity instanceof Mule || livingEntity instanceof ElderGuardian)
return;
if (livingEntity instanceof Donkey || livingEntity instanceof Mule || livingEntity instanceof ElderGuardian) return;
}
if (NMSUtil.getVersionNumber() > 10) {
if (livingEntity instanceof Evoker)
return;
if (livingEntity instanceof Evoker) return;
}
if (NMSUtil.getVersionNumber() > 13) {
if (livingEntity instanceof Ravager || livingEntity instanceof Illager)
return;
if (livingEntity instanceof Ravager || livingEntity instanceof Illager) return;
}
if (livingEntity.hasMetadata("SkyBlock"))
return;
if (livingEntity.hasMetadata("SkyBlock")) return;
IslandManager islandManager = skyblock.getIslandManager();
@ -674,12 +661,9 @@ public class Entity implements Listener {
EntityEquipment equipment = livingEntity.getEquipment();
if (equipment != null) {
for (ItemStack item : event.getDrops()) {
if (item.equals(equipment.getHelmet())
|| item.equals(equipment.getChestplate())
|| item.equals(equipment.getLeggings())
|| item.equals(equipment.getBoots())
|| item.equals(equipment.getItemInMainHand())
|| item.equals(equipment.getItemInOffHand())) {
if (item.equals(equipment.getHelmet()) || item.equals(equipment.getChestplate())
|| item.equals(equipment.getLeggings()) || item.equals(equipment.getBoots())
|| item.equals(equipment.getItemInMainHand()) || item.equals(equipment.getItemInOffHand())) {
dontMultiply.add(item);
}
}
@ -687,14 +671,12 @@ public class Entity implements Listener {
if (livingEntity instanceof Pig) {
Pig pig = (Pig) livingEntity;
if (pig.hasSaddle())
dontMultiply.add(new ItemStack(Material.SADDLE, 1));
if (pig.hasSaddle()) dontMultiply.add(new ItemStack(Material.SADDLE, 1));
}
}
for (ItemStack is : event.getDrops())
if (!dontMultiply.contains(is))
livingEntity.getWorld().dropItemNaturally(livingEntity.getLocation(), is);
if (!dontMultiply.contains(is)) livingEntity.getWorld().dropItemNaturally(livingEntity.getLocation(), is);
}
}
}
@ -720,26 +702,53 @@ public class Entity implements Listener {
}
}
private static final Set<SpawnReason> CHECKED_REASONS;
static {
CHECKED_REASONS = EnumSet.of(SpawnReason.NATURAL, SpawnReason.JOCKEY, SpawnReason.MOUNT);
final SpawnReason raid = getSpawnReason("RAID");
final SpawnReason patrol = getSpawnReason("PATROL");
if (patrol != null) CHECKED_REASONS.add(patrol);
if (raid != null) CHECKED_REASONS.add(raid);
}
@SuppressWarnings("deprecation")
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
LivingEntity entity = event.getEntity();
if (entity instanceof ArmorStand)
return;
if (entity.hasMetadata("SkyBlock"))
return;
if (entity instanceof ArmorStand) return;
if (entity.hasMetadata("SkyBlock")) return;
SpawnReason reason = event.getSpawnReason();
Set<SpawnReason> reasons = Sets.newHashSet(SpawnReason.NATURAL, SpawnReason.JOCKEY, SpawnReason.MOUNT, getSpawnReason("RAID"), getSpawnReason("PATROL"));
// Check that the reason of this event is not any of these above.
if (!reasons.stream().filter(r -> r != null).anyMatch(r -> r == reason))
return;
Location entityLocation = entity.getLocation();
if (!skyblock.getWorldManager().isIslandWorld(entity.getWorld()))
Island island = skyblock.getIslandManager().getIslandAtLocation(entityLocation);
if (island == null) return;
EntityLimitaton limits = skyblock.getLimitationHandler().getInstance(EntityLimitaton.class);
EntityType type = entity.getType();
if (limits.isBeingTracked(type)) {
long count = limits.getEntityCount(island, skyblock.getWorldManager().getIslandWorld(entityLocation.getWorld()), type);
if (limits.hasTooMuch(count + 1, type)) {
entity.remove();
event.setCancelled(true);
return;
if (skyblock.getIslandManager().hasSetting(entity.getLocation(), IslandRole.Owner, "NaturalMobSpawning"))
return;
if (event.getSpawnReason() != SpawnReason.JOCKEY && event.getSpawnReason() != SpawnReason.MOUNT) {
}
}
SpawnReason spawnReason = event.getSpawnReason();
if (!CHECKED_REASONS.contains(spawnReason)) return;
if (!skyblock.getWorldManager().isIslandWorld(entity.getWorld())) return;
if (skyblock.getIslandManager().hasSetting(entityLocation, IslandRole.Owner, "NaturalMobSpawning")) return;
if (spawnReason != SpawnReason.JOCKEY && spawnReason != SpawnReason.MOUNT) {
entity.remove(); // Older versions ignore the event being cancelled, so this fixes that issue.
return;
}
@ -748,15 +757,14 @@ public class Entity implements Listener {
for (org.bukkit.entity.Entity passenger : entity.getPassengers())
passenger.remove();
} else {
if (entity.getPassenger() != null)
entity.getPassenger().remove();
if (entity.getPassenger() != null) entity.getPassenger().remove();
}
entity.remove();
});
event.setCancelled(true); // For other plugin API reasons.
}
private SpawnReason getSpawnReason(String reason) {
private static SpawnReason getSpawnReason(String reason) {
try {
return SpawnReason.valueOf(reason);
} catch (Exception e) {

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,15 +157,18 @@ public class Interact implements Listener {
return;
}
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);

View File

@ -14,13 +14,9 @@ public class Area {
}
public Location getPosition(int position) {
if (positions.containsKey(position)) {
return positions.get(position);
}
return null;
}
public void setPosition(int position, Location location) {
positions.put(position, 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:
DefaultLimit: -1
BEDROCK: 0
END_PORTAL_FRAME: 12
entity:
DefaultLimit: -1