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

View File

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

View File

@ -11,8 +11,8 @@ import org.bukkit.block.Biome;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.HashSet;
import java.util.List; import java.util.Set;
public class BiomeManager { public class BiomeManager {
@ -23,7 +23,7 @@ public class BiomeManager {
} }
public void setBiome(Island island, Biome biome) { 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); Location location = island.getLocation(IslandWorld.Normal, IslandEnvironment.Island);
int radius = (int) Math.ceil(island.getRadius()); 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++) { for (int z = location.getBlockZ() - radius; z < location.getBlockZ() + radius; z++) {
location.getWorld().setBiome(x, z, biome); location.getWorld().setBiome(x, z, biome);
Chunk chunk = location.getWorld().getChunkAt(x >> 4, z >> 4); 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; package com.songoda.skyblock.command.commands.admin;
import com.songoda.skyblock.command.SubCommand; import java.io.File;
import com.songoda.skyblock.config.FileManager; import java.util.Map;
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 org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import com.songoda.skyblock.command.SubCommand;
import java.util.Map; 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 { public class ReloadCommand extends SubCommand {
@ -35,10 +35,9 @@ public class ReloadCommand extends SubCommand {
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager(); LeaderboardManager leaderboardManager = skyblock.getLeaderboardManager();
HologramManager hologramManager = skyblock.getHologramManager();
MessageManager messageManager = skyblock.getMessageManager(); MessageManager messageManager = skyblock.getMessageManager();
SoundManager soundManager = skyblock.getSoundManager(); SoundManager soundManager = skyblock.getSoundManager();
LimitManager limitManager = skyblock.getLimitManager(); LimitationInstanceHandler limitHandler = skyblock.getLimitationHandler();
FileManager fileManager = skyblock.getFileManager(); FileManager fileManager = skyblock.getFileManager();
messageManager.sendMessage(sender, "&cPlease note that this command is not supported and may " + 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()); Bukkit.getScheduler().runTask(skyblock, () -> skyblock.getHologramManager().resetHologram());
}); });
limitManager.reload(); limitHandler.reloadAll();
messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Reload.Reloaded.Message")); messageManager.sendMessage(sender, configLoad.getString("Command.Island.Admin.Reload.Reloaded.Message"));
soundManager.playSound(sender, Sounds.ANVIL_USE.bukkitSound(), 1.0F, 1.0F); soundManager.playSound(sender, Sounds.ANVIL_USE.bukkitSound(), 1.0F, 1.0F);

View File

@ -1,5 +1,14 @@
package com.songoda.skyblock.command.commands.admin; 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.command.SubCommand;
import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.config.FileManager.Config; 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.sound.SoundManager;
import com.songoda.skyblock.utils.player.OfflinePlayer; import com.songoda.skyblock.utils.player.OfflinePlayer;
import com.songoda.skyblock.utils.version.Sounds; 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 { public class SetAlwaysLoadedCommand extends SubCommand {
@ -34,14 +33,21 @@ public class SetAlwaysLoadedCommand extends SubCommand {
} }
public void onCommand(CommandSender sender, String[] args) { 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")); Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); 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) { if (args.length == 1) {
Player targetPlayer = Bukkit.getServer().getPlayer(args[0]); Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);

View File

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

View File

@ -13,7 +13,9 @@ import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; 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.List;
import java.util.Map; import java.util.Map;
@ -21,14 +23,14 @@ public class CooldownManager {
private final SkyBlock skyblock; 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) { public CooldownManager(SkyBlock skyblock) {
this.skyblock = skyblock; this.skyblock = skyblock;
IslandManager islandManager = skyblock.getIslandManager(); IslandManager islandManager = skyblock.getIslandManager();
for (CooldownType cooldownTypeList : CooldownType.values()) { for (CooldownType cooldownTypeList : CooldownType.getTypes()) {
List<CooldownPlayer> cooldownPlayers = new ArrayList<>(); List<CooldownPlayer> cooldownPlayers = new ArrayList<>();
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
@ -60,7 +62,7 @@ public class CooldownManager {
} }
public void onDisable() { public void onDisable() {
for (CooldownType cooldownTypeList : CooldownType.values()) { for (CooldownType cooldownTypeList : CooldownType.getTypes()) {
setCooldownPlayer(cooldownTypeList); setCooldownPlayer(cooldownTypeList);
saveCooldownPlayer(cooldownTypeList); saveCooldownPlayer(cooldownTypeList);
} }
@ -69,23 +71,19 @@ public class CooldownManager {
public CooldownPlayer loadCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) { public CooldownPlayer loadCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) { if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
Config config = skyblock.getFileManager() Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), player.getUniqueId().toString() + ".yml"));
player.getUniqueId().toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getString("Island." + cooldownType.name() + ".Cooldown") != null) { if (configLoad.getString("Island." + cooldownType.name() + ".Cooldown") != null) {
return new CooldownPlayer(player.getUniqueId(), return new CooldownPlayer(player.getUniqueId(), new Cooldown(configLoad.getInt("Island." + cooldownType.name() + ".Cooldown")));
new Cooldown(configLoad.getInt("Island." + cooldownType.name() + ".Cooldown")));
} }
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) { } else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
Config config = skyblock.getFileManager() Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"));
player.getUniqueId().toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getString(cooldownType.name() + ".Cooldown") != null) { if (configLoad.getString(cooldownType.name() + ".Cooldown") != null) {
return new CooldownPlayer(player.getUniqueId(), return new CooldownPlayer(player.getUniqueId(), new Cooldown(configLoad.getInt(cooldownType.name() + ".Cooldown")));
new Cooldown(configLoad.getInt(cooldownType.name() + ".Cooldown")));
} }
} }
@ -95,7 +93,10 @@ public class CooldownManager {
public void createPlayer(CooldownType cooldownType, OfflinePlayer player) { public void createPlayer(CooldownType cooldownType, OfflinePlayer player) {
FileManager fileManager = skyblock.getFileManager(); FileManager fileManager = skyblock.getFileManager();
if (cooldownStorage.containsKey(cooldownType)) { List<CooldownPlayer> cooldowns = cooldownStorage.get(cooldownType);
if (cooldowns == null) return;
int time = 0; int time = 0;
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) { if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
@ -103,8 +104,7 @@ public class CooldownManager {
.getInt("Island." + cooldownType.name() + ".Cooldown.Time"); .getInt("Island." + cooldownType.name() + ".Cooldown.Time");
Config config = fileManager Config config = fileManager
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), player.getUniqueId().toString() + ".yml"));
player.getUniqueId().toString() + ".yml"));
File configFile = config.getFile(); File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
@ -120,8 +120,7 @@ public class CooldownManager {
.getInt("Island." + cooldownType.name() + ".Cooldown.Time"); .getInt("Island." + cooldownType.name() + ".Cooldown.Time");
Config config = skyblock.getFileManager() Config config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"));
player.getUniqueId().toString() + ".yml"));
File configFile = config.getFile(); File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration(); 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) { public void deletePlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) { for (Iterator<CooldownPlayer> it = getCooldownPlayersOrEmptyList(cooldownType).iterator(); it.hasNext();) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) { if (it.next().getUUID().equals(player.getUniqueId())) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) { if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
skyblock.getFileManager() skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml")) player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set("Island." + cooldownType.name() + ".Cooldown", null); .getFileConfiguration().set("Island." + cooldownType.name() + ".Cooldown", null);
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) { } else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
skyblock.getFileManager() skyblock.getFileManager().getConfig(
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"))
player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set(cooldownType.name() + ".Cooldown", null); .getFileConfiguration().set(cooldownType.name() + ".Cooldown", null);
} }
it.remove();
cooldownStorage.get(cooldownType).remove(cooldownPlayerList);
break; break;
} }
} }
} }
}
public boolean hasPlayer(CooldownType cooldownType, OfflinePlayer player) { 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())) { if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return true; return true;
} }
} }
}
return false; return false;
} }
public void transferPlayer(CooldownType cooldownType, OfflinePlayer player1, OfflinePlayer player2) { public void transferPlayer(CooldownType cooldownType, OfflinePlayer player1, OfflinePlayer player2) {
if (cooldownStorage.containsKey(cooldownType)) { for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player1.getUniqueId())) { if (cooldownPlayerList.getUUID().equals(player1.getUniqueId())) {
cooldownPlayerList.setUUID(player2.getUniqueId()); cooldownPlayerList.setUUID(player2.getUniqueId());
break; break;
} }
} }
} }
}
public void removeCooldownPlayer(CooldownType cooldownType, CooldownPlayer cooldownPlayer) { public void removeCooldownPlayer(CooldownType cooldownType, CooldownPlayer cooldownPlayer) {
if (cooldownStorage.containsKey(cooldownType)) { getCooldownPlayersOrEmptyList(cooldownType).remove(cooldownPlayer);
cooldownStorage.get(cooldownType).remove(cooldownPlayer);
}
} }
public void removeCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) { public void removeCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) { for (Iterator<CooldownPlayer> it = getCooldownPlayersOrEmptyList(cooldownType).iterator(); it.hasNext();) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) { if (it.next().getUUID().equals(player.getUniqueId())) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) { it.remove();
cooldownStorage.get(cooldownType).remove(cooldownPlayerList);
break; break;
} }
} }
} }
}
public void setCooldownPlayer(CooldownType cooldownType) { public void setCooldownPlayer(CooldownType cooldownType) {
if (cooldownStorage.containsKey(cooldownType)) { for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
setCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID())); setCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
} }
} }
}
public void setCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) { public void setCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) { for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) { if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) { if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
skyblock.getFileManager() skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"),
player.getUniqueId().toString() + ".yml")) player.getUniqueId().toString() + ".yml"))
.getFileConfiguration().set("Island." + cooldownType + ".Cooldown", .getFileConfiguration().set("Island." + cooldownType + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
cooldownPlayerList.getCooldown().getTime());
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) { } else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
skyblock.getFileManager() skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
player.getUniqueId().toString() + ".yml")) player.getUniqueId().toString() + ".yml"))
.getFileConfiguration() .getFileConfiguration().set(cooldownType.name() + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
.set(cooldownType.name() + ".Cooldown", cooldownPlayerList.getCooldown().getTime());
} }
break; break;
} }
} }
} }
}
public void saveCooldownPlayer(CooldownType cooldownType) { public void saveCooldownPlayer(CooldownType cooldownType) {
if (cooldownStorage.containsKey(cooldownType)) { for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
saveCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID())); saveCooldownPlayer(cooldownType, Bukkit.getServer().getOfflinePlayer(cooldownPlayerList.getUUID()));
} }
} }
}
public void saveCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) { public void saveCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
Config config = null; Config config = null;
if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) { if (cooldownType == CooldownType.Biome || cooldownType == CooldownType.Creation) {
config = skyblock.getFileManager() config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/player-data"), player.getUniqueId().toString() + ".yml"));
player.getUniqueId().toString() + ".yml"));
} else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) { } else if (cooldownType == CooldownType.Levelling || cooldownType == CooldownType.Ownership) {
config = skyblock.getFileManager() config = skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), .getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), player.getUniqueId().toString() + ".yml"));
player.getUniqueId().toString() + ".yml"));
} }
if (config != null) { if (config != null) {
@ -267,34 +240,42 @@ public class CooldownManager {
} }
public void addCooldownPlayer(CooldownType cooldownType, CooldownPlayer cooldownPlayer) { public void addCooldownPlayer(CooldownType cooldownType, CooldownPlayer cooldownPlayer) {
if (cooldownType != null && cooldownPlayer != null) {
if (cooldownStorage.containsKey(cooldownType)) { if (cooldownType == null || cooldownPlayer == null) return;
cooldownStorage.get(cooldownType).add(cooldownPlayer);
} List<CooldownPlayer> cooldowns = cooldownStorage.get(cooldownType);
}
if (cooldowns == null) return;
cooldowns.add(cooldownPlayer);
} }
public CooldownPlayer getCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) { public CooldownPlayer getCooldownPlayer(CooldownType cooldownType, OfflinePlayer player) {
if (cooldownStorage.containsKey(cooldownType)) { for (CooldownPlayer cooldownPlayerList : getCooldownPlayersOrEmptyList(cooldownType)) {
for (CooldownPlayer cooldownPlayerList : cooldownStorage.get(cooldownType)) {
if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) { if (cooldownPlayerList.getUUID().equals(player.getUniqueId())) {
return cooldownPlayerList; return cooldownPlayerList;
} }
} }
}
return null; return null;
} }
public List<CooldownPlayer> getCooldownPlayers(CooldownType cooldownType) { 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) { public boolean hasCooldownType(CooldownType cooldownType) {
return cooldownStorage.containsKey(cooldownType); return cooldownStorage.containsKey(cooldownType);
} }
} }

View File

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

View File

@ -1,7 +1,21 @@
package com.songoda.skyblock.cooldown; package com.songoda.skyblock.cooldown;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum CooldownType { 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) { public Invite createInvite(Player player, Player sender, UUID owner, int time) {
Invite invite = new Invite(player, sender, owner, time); Invite invite = new Invite(player, sender, owner, time);
inviteStorage.put(player.getUniqueId(), invite); inviteStorage.put(player.getUniqueId(), invite);
return invite; return invite;
} }
public void removeInvite(UUID uuid) { public void removeInvite(UUID uuid) {
if (hasInvite(uuid)) {
inviteStorage.remove(uuid); inviteStorage.remove(uuid);
} }
}
public void tranfer(UUID uuid1, UUID uuid2) { public void tranfer(UUID uuid1, UUID uuid2) {
Map<UUID, Invite> islandInvites = getInvites(); Map<UUID, Invite> islandInvites = getInvites();
for (UUID islandInviteList : islandInvites.keySet()) { for (Invite invite : islandInvites.values()) {
Invite invite = islandInvites.get(islandInviteList);
if (invite.getOwnerUUID().equals(uuid1)) { if (invite.getOwnerUUID().equals(uuid1)) {
invite.setOwnerUUID(uuid2); invite.setOwnerUUID(uuid2);
} }
@ -45,13 +40,9 @@ public class InviteManager {
} }
public Invite getInvite(UUID uuid) { public Invite getInvite(UUID uuid) {
if (hasInvite(uuid)) {
return inviteStorage.get(uuid); return inviteStorage.get(uuid);
} }
return null;
}
public boolean hasInvite(UUID uuid) { public boolean hasInvite(UUID uuid) {
return inviteStorage.containsKey(uuid); return inviteStorage.containsKey(uuid);
} }

View File

@ -27,6 +27,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.Map.Entry;
public class Island { public class Island {
@ -104,7 +105,7 @@ public class Island {
if (playerDataConfigLoad.getString("Island.Owner") == null if (playerDataConfigLoad.getString("Island.Owner") == null
|| !playerDataConfigLoad.getString("Island.Owner").equals(ownerUUID.toString())) { || !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 if (playerDataConfigLoad.getString("Island.Owner") == null
|| !playerDataConfigLoad.getString("Island.Owner").equals(ownerUUID.toString())) { || !playerDataConfigLoad.getString("Island.Owner").equals(ownerUUID.toString())) {
operators.remove(operator); operators.remove(i);
} }
} }
@ -131,24 +132,21 @@ public class Island {
Config settingsDataConfig = null; Config settingsDataConfig = null;
if (fileManager.isFileExist(new File(skyblock.getDataFolder().toString() + "/setting-data", File settingDataFile = new File(skyblock.getDataFolder().toString() + "/setting-data", getOwnerUUID().toString() + ".yml");
getOwnerUUID().toString() + ".yml"))) {
settingsDataConfig = fileManager.getConfig(new File( if (fileManager.isFileExist(settingDataFile)) {
skyblock.getDataFolder().toString() + "/setting-data", getOwnerUUID().toString() + ".yml")); settingsDataConfig = fileManager.getConfig(settingDataFile);
} }
for (IslandRole roleList : IslandRole.values()) { for (IslandRole roleList : IslandRole.getRoles()) {
List<IslandSetting> settings = new ArrayList<>(); List<IslandSetting> settings = new ArrayList<>();
for (String settingList : defaultSettingsConfig.getFileConfiguration() for (String settingList : defaultSettingsConfig.getFileConfiguration().getConfigurationSection("Settings." + roleList.name()).getKeys(false)) {
.getConfigurationSection("Settings." + roleList.name()).getKeys(false)) { if (settingsDataConfig == null || settingsDataConfig.getFileConfiguration().getString("Settings." + roleList.name() + "." + settingList) == null) {
if (settingsDataConfig == null || settingsDataConfig.getFileConfiguration() settings.add(
.getString("Settings." + roleList.name() + "." + settingList) == null) { new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList)));
settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration()
.getBoolean("Settings." + roleList.name() + "." + settingList)));
} else { } else {
settings.add(new IslandSetting(settingList, settingsDataConfig.getFileConfiguration() settings.add(new IslandSetting(settingList, settingsDataConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList)));
.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("Weather.Weather", mainConfigLoad.getString("Island.Weather.Default.Weather").toUpperCase());
configLoad.set("Ownership.Original", ownerUUID.toString()); configLoad.set("Ownership.Original", ownerUUID.toString());
for (IslandRole roleList : IslandRole.values()) { for (IslandRole roleList : IslandRole.getRoles()) {
List<IslandSetting> settings = new ArrayList<>();
for (String settingList : defaultSettingsConfig.getFileConfiguration() Set<String> keys = defaultSettingsConfig.getFileConfiguration().getConfigurationSection("Settings." + roleList.name()).getKeys(false);
.getConfigurationSection("Settings." + roleList.name()).getKeys(false)) { List<IslandSetting> settings = new ArrayList<>(keys.size());
settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration()
.getBoolean("Settings." + roleList.name() + "." + settingList))); for (String settingList : keys) {
settings.add(new IslandSetting(settingList, defaultSettingsConfig.getFileConfiguration().getBoolean("Settings." + roleList.name() + "." + settingList)));
} }
islandSettings.put(roleList, settings); islandSettings.put(roleList, settings);
@ -227,11 +225,7 @@ public class Island {
} }
public UUID getOriginalOwnerUUID() { public UUID getOriginalOwnerUUID() {
return UUID return UUID.fromString(skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml"))
.fromString(
skyblock.getFileManager()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/island-data"),
ownerUUID.toString() + ".yml"))
.getFileConfiguration().getString("Ownership.Original")); .getFileConfiguration().getString("Ownership.Original"));
} }
@ -772,9 +766,9 @@ public class Island {
.getConfig(new File(skyblock.getDataFolder().toString() + "/setting-data", ownerUUID.toString() + ".yml")); .getConfig(new File(skyblock.getDataFolder().toString() + "/setting-data", ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
for (IslandRole roleList : islandSettings.keySet()) { for (Entry<IslandRole, List<IslandSetting>> entry : islandSettings.entrySet()) {
for (IslandSetting settingList : islandSettings.get(roleList)) { for (IslandSetting setting : entry.getValue()) {
configLoad.set("Settings." + roleList + "." + settingList.getName(), settingList.getStatus()); 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")); .getConfig(new File(skyblock.getDataFolder().toString() + "/coop-data", ownerUUID.toString() + ".yml"));
configLoad = config.getFileConfiguration(); configLoad = config.getFileConfiguration();
List<String> coopPlayersAsString = new ArrayList<>(); List<String> coopPlayersAsString = new ArrayList<>(coopPlayers.size());
for (Map.Entry<UUID, IslandCoop> entry : coopPlayers.entrySet()) { for (Map.Entry<UUID, IslandCoop> entry : coopPlayers.entrySet()) {
if (entry.getValue() == IslandCoop.TEMP) continue; 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.SkyBlock;
import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.config.FileManager.Config;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class IslandLevel { public class IslandLevel {
@ -25,18 +29,25 @@ public class IslandLevel {
this.skyblock = skyblock; this.skyblock = skyblock;
this.ownerUUID = ownerUUID; this.ownerUUID = ownerUUID;
Config config = skyblock.getFileManager().getConfig( Config config = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
Map<String, Long> materials = new HashMap<>(); Map<String, Long> materials;
if (configLoad.getString("Levelling.Materials") != null) { ConfigurationSection materialSection = configLoad.getConfigurationSection("Leveling.Materials");
for (String materialList : configLoad.getConfigurationSection("Levelling.Materials").getKeys(false)) {
if (configLoad.getString("Levelling.Materials." + materialList + ".Amount") != null) { if (materialSection != null) {
materials.put(materialList, configLoad.getLong("Levelling.Materials." + materialList + ".Amount")); 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; this.materials = materials;
@ -50,18 +61,18 @@ public class IslandLevel {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml")); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
ConfigurationSection materialSection = configLoad.getConfigurationSection("Materials");
if (materialSection == null) return 0;
long pointsEarned = 0; long pointsEarned = 0;
for (String materialList : this.materials.keySet()) { for (Entry<String, Long> entry : this.materials.entrySet()) {
long materialAmount = this.materials.get(materialList); ConfigurationSection current = materialSection.getConfigurationSection(entry.getKey());
if (configLoad.getString("Materials." + materialList + ".Points") != null) { long pointsRequired = current.getLong("Points", 0);
long pointsRequired = config.getFileConfiguration().getLong("Materials." + materialList + ".Points");
if (pointsRequired != 0) { if (pointsRequired != 0) pointsEarned = pointsEarned + (entry.getValue() * pointsRequired);
pointsEarned = pointsEarned + (materialAmount * pointsRequired);
}
}
} }
return pointsEarned; return pointsEarned;
@ -71,26 +82,25 @@ public class IslandLevel {
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml")); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "levelling.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
long pointsEarned = 0; ConfigurationSection materialSection = configLoad.getConfigurationSection("Materials");
if (this.materials.containsKey(material)) { if (materialSection == null) return 0;
long materialAmount = this.materials.get(material);
if (configLoad.getString("Materials." + material + ".Points") != null) { ConfigurationSection current = materialSection.getConfigurationSection(material);
long pointsRequired = configLoad.getLong("Materials." + material + ".Points");
if (pointsRequired != 0) { if (current == null) return 0;
pointsEarned = materialAmount * pointsRequired;
}
}
}
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() { public long getLevel() {
long division = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")) long division = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getLong("Island.Levelling.Division");
.getFileConfiguration().getLong("Island.Levelling.Division");
if (division == 0) { if (division == 0) {
division = 1; division = 1;
@ -100,27 +110,19 @@ public class IslandLevel {
} }
public void setMaterialAmount(String material, long amount) { public void setMaterialAmount(String material, long amount) {
skyblock.getFileManager() skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")).getFileConfiguration()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), .set("Levelling.Materials." + material + ".Amount", amount);
ownerUUID.toString() + ".yml"))
.getFileConfiguration().set("Levelling.Materials." + material + ".Amount", amount);
this.materials.put(material, amount); this.materials.put(material, amount);
} }
public long getMaterialAmount(String material) { public long getMaterialAmount(String material) {
if (this.materials.containsKey(material)) { return this.materials.getOrDefault(material, 0l);
return this.materials.get(material);
}
return 0;
} }
public void removeMaterial(String material) { public void removeMaterial(String material) {
skyblock.getFileManager() skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")).getFileConfiguration()
.getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), .set("Levelling.Materials." + material, null);
ownerUUID.toString() + ".yml"))
.getFileConfiguration().set("Levelling.Materials." + material, null);
this.materials.remove(material); this.materials.remove(material);
} }
@ -138,8 +140,7 @@ public class IslandLevel {
} }
public void setMaterials(Map<String, Long> materials) { public void setMaterials(Map<String, Long> materials) {
Config config = skyblock.getFileManager().getConfig( Config config = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
configLoad.set("Levelling.Materials", null); configLoad.set("Levelling.Materials", null);
@ -168,8 +169,7 @@ public class IslandLevel {
} }
public void save() { public void save() {
Config config = skyblock.getFileManager().getConfig( Config config = skyblock.getFileManager().getConfig(new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
new File(new File(skyblock.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml"));
File configFile = config.getFile(); File configFile = config.getFile();
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();

View File

@ -616,6 +616,7 @@ public class IslandManager {
island.save(); island.save();
int islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1, int islandMembers = island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1,
islandVisitors = getVisitorsAtIsland(island).size(); islandVisitors = getVisitorsAtIsland(island).size();
boolean unloadIsland = true; boolean unloadIsland = true;
@ -627,7 +628,7 @@ public class IslandManager {
if (island.hasRole(IslandRole.Member, all.getUniqueId()) if (island.hasRole(IslandRole.Member, all.getUniqueId())
|| island.hasRole(IslandRole.Operator, 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) { if (scoreboardManager != null) {
try { try {
if (islandMembers == 1 && islandVisitors == 0) { if (islandMembers == 1 && islandVisitors == 0) {
@ -1292,6 +1293,8 @@ public class IslandManager {
for (UUID coopPlayerAtIslandList : getCoopPlayersAtIsland(island)) { for (UUID coopPlayerAtIslandList : getCoopPlayersAtIsland(island)) {
Player targetPlayer = Bukkit.getServer().getPlayer(coopPlayerAtIslandList); Player targetPlayer = Bukkit.getServer().getPlayer(coopPlayerAtIslandList);
if(island.getCoopType(coopPlayerAtIslandList) == IslandCoop.NORMAL) continue;
if (targetPlayer != null) { if (targetPlayer != null) {
LocationUtil.teleportPlayerToSpawn(targetPlayer); LocationUtil.teleportPlayerToSpawn(targetPlayer);

View File

@ -1,7 +1,21 @@
package com.songoda.skyblock.island; package com.songoda.skyblock.island;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
public enum IslandRole { 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 @Override
public List<Entry<?, Double>> requestAll() { public List<Entry<?, Double>> requestAll() {
Map<UUID, Double> topLevels = new HashMap<>();
List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Bank); List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Bank);
Map<UUID, Double> topLevels = new HashMap<>(leaderboards.size());
for (Leaderboard leaderboard : leaderboards) { for (Leaderboard leaderboard : leaderboards) {
Visit visit = leaderboard.getVisit(); Visit visit = leaderboard.getVisit();

View File

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

View File

@ -27,9 +27,9 @@ public class TopVotes extends DataCollector {
@Override @Override
public List<Entry<?, Double>> requestAll() { public List<Entry<?, Double>> requestAll() {
Map<UUID, Double> topLevels = new HashMap<>();
List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Votes); List<Leaderboard> leaderboards = skyblock.getLeaderboardManager().getLeaderboard(Type.Votes);
Map<UUID, Double> topLevels = new HashMap<>(leaderboards.size());
for (int i = 0; i < leaderboards.size(); i++) { for (int i = 0; i < leaderboards.size(); i++) {
Leaderboard leaderboard = leaderboards.get(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.IslandRole;
import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.island.IslandWorld;
import com.songoda.skyblock.levelling.LevellingManager; 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.Stackable;
import com.songoda.skyblock.stackable.StackableManager; import com.songoda.skyblock.stackable.StackableManager;
import com.songoda.skyblock.utils.NumberUtil; import com.songoda.skyblock.utils.NumberUtil;
@ -74,14 +74,17 @@ public class Block implements Listener {
if (!worldManager.isIslandWorld(block.getWorld())) return; if (!worldManager.isIslandWorld(block.getWorld())) return;
IslandWorld world = worldManager.getIslandWorld(block.getWorld()); IslandWorld world = worldManager.getIslandWorld(block.getWorld());
Island island = islandManager.getIslandAtLocation(block.getLocation());
Location blockLocation = block.getLocation();
Island island = islandManager.getIslandAtLocation(blockLocation);
if (island == null) { if (island == null) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!islandManager.hasPermission(player, block.getLocation(), "Destroy")) { if (!islandManager.hasPermission(player, blockLocation, "Destroy")) {
event.setCancelled(true); event.setCancelled(true);
skyblock.getMessageManager().sendMessage(player, skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
@ -91,7 +94,7 @@ public class Block implements Listener {
} }
if (stackableManager != null if (stackableManager != null
&& stackableManager.isStacked(block.getLocation())) { && stackableManager.isStacked(blockLocation)) {
Stackable stackable = stackableManager.getStack(block.getLocation(), block.getType()); Stackable stackable = stackableManager.getStack(block.getLocation(), block.getType());
if (stackable != null) { if (stackable != null) {
Material material = block.getType(); Material material = block.getType();
@ -99,7 +102,7 @@ public class Block implements Listener {
int droppedAmount = 0; int droppedAmount = 0;
if (event.getPlayer().isSneaking()) { 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(); int count = stackable.getSize();
droppedAmount = count; droppedAmount = count;
while (count > 64) { while (count > 64) {
@ -110,7 +113,7 @@ public class Block implements Listener {
block.setType(Material.AIR); block.setType(Material.AIR);
stackable.setSize(0); stackable.setSize(0);
} else { } 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(); stackable.takeOne();
droppedAmount = 1; droppedAmount = 1;
} }
@ -247,15 +250,18 @@ public class Block implements Listener {
} }
} }
LimitManager limitManager = skyblock.getLimitManager(); BlockLimitation limits = skyblock.getLimitationHandler().getInstance(BlockLimitation.class);
if (limitManager.isBlockLimitExceeded(player, block)) {
long limit = limits.getBlockLimit(player, block);
if (limits.isBlockLimitExceeded(player, block, limit)) {
Materials material = Materials.getMaterials(block.getType(), block.getData()); Materials material = Materials.getMaterials(block.getType(), block.getData());
skyblock.getMessageManager().sendMessage(player, skyblock.getMessageManager().sendMessage(player,
skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"))
.getFileConfiguration().getString("Island.Limit.Block.Exceeded.Message") .getFileConfiguration().getString("Island.Limit.Block.Exceeded.Message")
.replace("%type", WordUtils.capitalizeFully(material.name().replace("_", " "))) .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); skyblock.getSoundManager().playSound(player, Sounds.VILLAGER_NO.bukkitSound(), 1.0F, 1.0F);
event.setCancelled(true); event.setCancelled(true);

View File

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

View File

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

View File

@ -40,14 +40,14 @@ public class SchematicUtil {
// TODO: Cache this later // TODO: Cache this later
try { try {
Class<?> bukkitWorldClass = Class.forName("com.sk89q.worldedit.bukkit.BukkitWorld"); 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<?> editSessionClass = Class.forName("com.sk89q.worldedit.EditSession");
Class<?> localWorldClass = Class.forName("com.sk89q.worldedit.LocalWorld"); 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"); Class<?> cuboidClipboardClass = Class.forName("com.sk89q.worldedit.CuboidClipboard");
Method loadSchematicMethod = cuboidClipboardClass.getMethod("loadSchematic", File.class); Method loadSchematicMethod = cuboidClipboardClass.getMethod("loadSchematic", File.class);
Class<?> vectorClass = Class.forName("com.sk89q.worldedit.Vector"); 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); Method pasteMethod = cuboidClipboardClass.getMethod("paste", editSessionClass, vectorClass, boolean.class);
Object editSessionObj = editSessionConstructor.newInstance(bukkitWorldConstructor.newInstance(location.getWorld()), 999999999); 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.google.gson.reflect.TypeToken;
import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager;
import com.songoda.skyblock.utils.Compression;
import com.songoda.skyblock.utils.version.NMSUtil; import com.songoda.skyblock.utils.version.NMSUtil;
import com.songoda.skyblock.utils.world.LocationUtil; import com.songoda.skyblock.utils.world.LocationUtil;
import com.songoda.skyblock.utils.world.block.BlockData; import com.songoda.skyblock.utils.world.block.BlockData;
@ -26,7 +25,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;

View File

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

View File

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