mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 09:08:03 +01:00
Added methods to PlayerManager and IslandManager.
This commit is contained in:
parent
c74b6720e9
commit
679b511178
@ -45,11 +45,11 @@ public class BSkyBlock extends JavaPlugin{
|
||||
offlineHistoryMessages = new OfflineHistoryMessages(this);
|
||||
offlineHistoryMessages.load();
|
||||
|
||||
if (Settings.useEconomy && !VaultHelper.setupEconomy(this)) {
|
||||
if (Settings.useEconomy && !VaultHelper.setupEconomy()) {
|
||||
getLogger().warning("Could not set up economy! - Running without an economy.");
|
||||
Settings.useEconomy = false;
|
||||
}
|
||||
if (!VaultHelper.setupPermissions(this)) {
|
||||
if (!VaultHelper.setupPermissions()) {
|
||||
getLogger().severe("Cannot link with Vault for permissions! Disabling plugin!");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
|
@ -35,7 +35,7 @@ public class IslandCommand extends ASBCommand{
|
||||
|
||||
Player player = (Player) sender;
|
||||
// Basic permission check to even use /island
|
||||
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")){
|
||||
if(!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.create")){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
|
||||
return false;
|
||||
}
|
||||
@ -113,7 +113,7 @@ public class IslandCommand extends ASBCommand{
|
||||
@Override
|
||||
public String[] getHelp(CommandSender sender, String label){
|
||||
// TODO check if multiple homes
|
||||
if(VaultHelper.hasPerm((Player) sender, "todo")) return new String[] {"[1-x]", plugin.getLocale(sender).islandHelpGoHomes};
|
||||
if(VaultHelper.checkPerm((Player) sender, "todo")) return new String[] {"[1-x]", plugin.getLocale(sender).islandHelpGoHomes};
|
||||
return new String[] {null, plugin.getLocale(sender).islandHelpGo};
|
||||
}
|
||||
});
|
||||
@ -314,17 +314,17 @@ public class IslandCommand extends ASBCommand{
|
||||
public boolean canExecute(CommandSender sender, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){
|
||||
if(!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!plugin.getPlayers().getPlayer(player.getUniqueId()).hasIsland()){
|
||||
if(!plugin.getIslands().hasIsland(player.getUniqueId())){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoIsland);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!plugin.getPlayers().getPlayer(player.getUniqueId()).isOwner()){
|
||||
if(!plugin.getIslands().isOwner(player.getUniqueId())){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNotLeader);
|
||||
return false;
|
||||
}
|
||||
@ -359,8 +359,8 @@ public class IslandCommand extends ASBCommand{
|
||||
}
|
||||
|
||||
// Set the name
|
||||
if(VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name.format")) plugin.getPlayers().getPlayer(player.getUniqueId()).getIsland().setName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
else plugin.getPlayers().getPlayer(player.getUniqueId()).getIsland().setName(name);
|
||||
if(VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name.format")) plugin.getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
else plugin.getIslands().getIsland(player.getUniqueId()).setName(name);
|
||||
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).generalSuccess);
|
||||
}
|
||||
@ -383,17 +383,17 @@ public class IslandCommand extends ASBCommand{
|
||||
public boolean canExecute(CommandSender sender, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){
|
||||
if(!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!plugin.getPlayers().getPlayer(player.getUniqueId()).hasIsland()){
|
||||
if(!plugin.getIslands().hasIsland(player.getUniqueId())){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoIsland);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!plugin.getPlayers().getPlayer(player.getUniqueId()).isOwner()){
|
||||
if(!plugin.getIslands().isOwner(player.getUniqueId())){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNotLeader);
|
||||
return false;
|
||||
}
|
||||
@ -406,7 +406,7 @@ public class IslandCommand extends ASBCommand{
|
||||
Player player = (Player) sender;
|
||||
|
||||
// Resets the island name
|
||||
plugin.getPlayers().getPlayer(player.getUniqueId()).getIsland().setName(null);
|
||||
plugin.getIslands().getIsland(player.getUniqueId()).setName(null);
|
||||
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(player).generalSuccess);
|
||||
}
|
||||
|
||||
@ -1076,12 +1076,12 @@ public class IslandCommand extends ASBCommand{
|
||||
public boolean canExecute(CommandSender sender, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.lock")){
|
||||
if(!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lock")){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoPermission);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!plugin.getPlayers().getPlayer(player.getUniqueId()).hasIsland()){
|
||||
if(!plugin.getIslands().hasIsland(player.getUniqueId())){
|
||||
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).errorNoIsland);
|
||||
return false;
|
||||
}
|
||||
@ -1092,7 +1092,7 @@ public class IslandCommand extends ASBCommand{
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
Island island = plugin.getPlayers().getPlayer(player.getUniqueId()).getIsland();
|
||||
Island island = plugin.getIslands().getIsland(player.getUniqueId());
|
||||
|
||||
if(!island.isLocked()){
|
||||
// TODO: Expel all visitors
|
||||
|
@ -38,4 +38,12 @@ public class Settings {
|
||||
public static HashMap<SettingsFlag, Boolean> defaultSpawnSettings = new HashMap<SettingsFlag, Boolean>();
|
||||
|
||||
public static List<HistoryMessageType> historyMessagesTypes;
|
||||
|
||||
public static int inviteWait;
|
||||
|
||||
public static int maxDeaths;
|
||||
|
||||
public static int islandDistance;
|
||||
|
||||
public static int protectionRange;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
|
||||
import us.tastybento.bskyblock.database.mysql.MySQLDatabase;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.APlayer;
|
||||
import us.tastybento.bskyblock.database.objects.Players;
|
||||
import us.tastybento.bskyblock.database.sqlite.SQLiteDatabase;
|
||||
|
||||
public abstract class ASBDatabase {
|
||||
@ -20,8 +20,8 @@ public abstract class ASBDatabase {
|
||||
return DatabaseType.FLATFILE.database;
|
||||
}
|
||||
|
||||
public abstract APlayer loadPlayerData(UUID uuid);
|
||||
public abstract void savePlayerData(APlayer player);
|
||||
public abstract Players loadPlayerData(UUID uuid);
|
||||
public abstract void savePlayerData(Players player);
|
||||
|
||||
public abstract Island loadIslandData(String location);
|
||||
public abstract void saveIslandData(Island island);
|
||||
@ -40,4 +40,27 @@ public abstract class ASBDatabase {
|
||||
this.database = database;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks in database whether the player is known by the plugin or not
|
||||
* @param uniqueID
|
||||
* @return true or false
|
||||
*/
|
||||
public abstract boolean isPlayerKnown(UUID uniqueID);
|
||||
|
||||
/**
|
||||
* Gets the UUID for player with name. If adminCheck is true, the search will be more extensive
|
||||
* @param name
|
||||
* @param adminCheck
|
||||
* @return UUID of player with name, or null if it cannot be found
|
||||
*/
|
||||
public abstract UUID getUUID(String name, boolean adminCheck);
|
||||
|
||||
/**
|
||||
* Associates this name with the UUID
|
||||
* @param name
|
||||
* @param uuid
|
||||
*/
|
||||
public abstract void savePlayerName(String name, UUID uuid);
|
||||
|
||||
}
|
||||
|
@ -1,40 +1,49 @@
|
||||
package us.tastybento.bskyblock.database;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
|
||||
public class IslandsManager {
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private ASBDatabase database;
|
||||
|
||||
|
||||
private HashMap<Location, Island> islands;
|
||||
private Island spawn;
|
||||
private HashMap<UUID, Island> islandsByUUID;
|
||||
// 2D islandGrid of islands, x,z
|
||||
private TreeMap<Integer, TreeMap<Integer, Island>> islandGrid = new TreeMap<Integer, TreeMap<Integer, Island>>();
|
||||
|
||||
private Island spawn;
|
||||
|
||||
// Metrics data
|
||||
private int metrics_createdcount = 0;
|
||||
|
||||
|
||||
public IslandsManager(BSkyBlock plugin){
|
||||
this.plugin = plugin;
|
||||
database = ASBDatabase.getDatabase();
|
||||
islands = new HashMap<Location, Island>();
|
||||
islandsByUUID = new HashMap<UUID, Island>();
|
||||
spawn = null;
|
||||
}
|
||||
|
||||
|
||||
public void load(){
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
public void save(boolean async){
|
||||
if(async){
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(Entry<Location, Island> entry : islands.entrySet()){
|
||||
@ -48,47 +57,279 @@ public class IslandsManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void shutdown(){
|
||||
save(false);
|
||||
islands.clear();
|
||||
}
|
||||
|
||||
|
||||
public int getCount(){
|
||||
return islands.size();
|
||||
}
|
||||
|
||||
|
||||
public boolean isIsland(Location location){
|
||||
return islands.get(location) != null;
|
||||
}
|
||||
|
||||
|
||||
public Island getIsland(Location location){
|
||||
return islands.get(location);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the island for this player. If they are in a team, the team island is returned
|
||||
* @param uuid
|
||||
* @return
|
||||
*/
|
||||
public Island getIsland(UUID uuid){
|
||||
return plugin.getPlayers().getPlayer(uuid).getIsland();
|
||||
return islandsByUUID.get(uuid);
|
||||
}
|
||||
|
||||
public void createIsland(Location location){
|
||||
//TODO
|
||||
|
||||
/**
|
||||
* Create an island with no owner at location
|
||||
* @param location
|
||||
*/
|
||||
public Island createIsland(Location location){
|
||||
return createIsland(location, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an island with owner
|
||||
* @param location
|
||||
* @param owner UUID
|
||||
*/
|
||||
public Island createIsland(Location location, UUID owner){
|
||||
Island island = new Island(location, owner, Settings.protectionRange);
|
||||
islands.put(location, island);
|
||||
if (owner != null)
|
||||
islandsByUUID.put(owner, island);
|
||||
return island;
|
||||
}
|
||||
|
||||
public void deleteIsland(Location location){
|
||||
//TODO
|
||||
}
|
||||
|
||||
|
||||
public Island getSpawn(){
|
||||
return spawn;
|
||||
}
|
||||
|
||||
|
||||
// Metrics-related methods //
|
||||
|
||||
|
||||
public int metrics_getCreatedCount(){
|
||||
return metrics_createdcount;
|
||||
}
|
||||
|
||||
|
||||
public void metrics_setCreatedCount(int count){
|
||||
this.metrics_createdcount = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this player from any and all islands
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void removePlayer(UUID playerUUID) {
|
||||
Island island = islandsByUUID.get(playerUUID);
|
||||
if (island != null) {
|
||||
if (island.getOwner().equals(playerUUID)) {
|
||||
// Clear ownership and members
|
||||
island.getMembers().clear();
|
||||
island.setOwner(null);
|
||||
}
|
||||
island.getMembers().remove(playerUUID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the island level
|
||||
* @param playerUUID
|
||||
* @return Level of island, or null if unknown
|
||||
*/
|
||||
public Integer getIslandLevel(UUID playerUUID) {
|
||||
if (islandsByUUID.containsKey(playerUUID))
|
||||
return islandsByUUID.get(playerUUID).getLevel();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the island level for this player
|
||||
* @param playerUUID
|
||||
* @param islandLevel
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
public boolean setIslandLevel(UUID playerUUID, int islandLevel) {
|
||||
if (islandsByUUID.containsKey(playerUUID)) {
|
||||
islandsByUUID.get(playerUUID).setLevel(islandLevel);
|
||||
// TODO
|
||||
//plugin.getChatListener().setPlayerLevel(playerUUID, islandLevel);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts a player in a team. Removes them from their old island if required.
|
||||
* @param playerUUID
|
||||
* @param teamLeader
|
||||
* @param islandLocation
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
public boolean setJoinTeam(UUID playerUUID, UUID teamLeader) {
|
||||
Island teamIsland = islandsByUUID.get(teamLeader);
|
||||
if (teamIsland == null) {
|
||||
// Something odd here, team leader does not have an island!
|
||||
plugin.getLogger().severe("Team leader does not have an island!");
|
||||
return false;
|
||||
}
|
||||
if (teamIsland.getMembers().contains(playerUUID)) {
|
||||
// Player already on island
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Fire a join team event. If canceled, return false
|
||||
|
||||
if (!setLeaveTeam(playerUUID)) {
|
||||
// Player not allowed to leave team
|
||||
return false;
|
||||
}
|
||||
// Add player to new island
|
||||
teamIsland.addMember(playerUUID);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player leaves a team
|
||||
* @param playerUUID
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
public boolean setLeaveTeam(UUID playerUUID) {
|
||||
// Try to remove player from old island
|
||||
// TODO: Fire an event, if not cancelled, zero the player data
|
||||
plugin.getPlayers().zeroPlayerData(playerUUID);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of island member UUID's for the island of playerUUID
|
||||
*
|
||||
* @param playerUUID
|
||||
* @return Set of team UUIDs
|
||||
*/
|
||||
public Set<UUID> getMembers(UUID playerUUID) {
|
||||
Island island = islandsByUUID.get(playerUUID);
|
||||
if (island != null)
|
||||
return island.getMembers();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides UUID of this player's team leader or null if it does not exist
|
||||
* @param playerUUID
|
||||
* @return UUID of leader or null if player has no island
|
||||
*/
|
||||
public UUID getTeamLeader(UUID playerUUID) {
|
||||
if (islandsByUUID.containsKey(playerUUID))
|
||||
return islandsByUUID.get(playerUUID).getOwner();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the island at the location or null if there is none.
|
||||
* This includes the full island space, not just the protected area
|
||||
*
|
||||
* @param location
|
||||
* @return PlayerIsland object
|
||||
*/
|
||||
public Island getIslandAt(Location location) {
|
||||
if (location == null) {
|
||||
return null;
|
||||
}
|
||||
// World check
|
||||
if (!inWorld(location)) {
|
||||
return null;
|
||||
}
|
||||
// Check if it is spawn
|
||||
if (spawn != null && spawn.onIsland(location)) {
|
||||
return spawn;
|
||||
}
|
||||
return getIslandAt(location.getBlockX(), location.getBlockZ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the island at the x,z location or null if there is none.
|
||||
* This includes the full island space, not just the protected area.
|
||||
*
|
||||
* @param x
|
||||
* @param z
|
||||
* @return PlayerIsland or null
|
||||
*/
|
||||
public Island getIslandAt(int x, int z) {
|
||||
Entry<Integer, TreeMap<Integer, Island>> en = islandGrid.floorEntry(x);
|
||||
if (en != null) {
|
||||
Entry<Integer, Island> ent = en.getValue().floorEntry(z);
|
||||
if (ent != null) {
|
||||
// Check if in the island range
|
||||
Island island = ent.getValue();
|
||||
if (island.inIslandSpace(x, z)) {
|
||||
// plugin.getLogger().info("DEBUG: In island space");
|
||||
return island;
|
||||
}
|
||||
//plugin.getLogger().info("DEBUG: not in island space");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if a location is in the island world or not or
|
||||
* in the new nether if it is activated
|
||||
* @param loc
|
||||
* @return true if in the island world
|
||||
*/
|
||||
protected boolean inWorld(Location loc) {
|
||||
// TODO: determine if the world is correct
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUUID
|
||||
* @return ture if player has island
|
||||
*/
|
||||
public boolean hasIsland(UUID playerUUID) {
|
||||
return islandsByUUID.containsKey(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player's island location.
|
||||
* Returns an island location OR a team island location
|
||||
*
|
||||
* @param playerUUID
|
||||
* @return Location of player's island or null if one does not exist
|
||||
*/
|
||||
public Location getIslandLocation(UUID playerUUID) {
|
||||
if (hasIsland(playerUUID))
|
||||
return getIsland(playerUUID).getCenter();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUUID
|
||||
* @return ban list for player
|
||||
*/
|
||||
public Set<UUID> getBanList(UUID playerUUID) {
|
||||
// Get player's island
|
||||
Island island = getIsland(playerUUID);
|
||||
return island == null ? new HashSet<UUID>(): island.getBanned();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uniqueId
|
||||
* @return true if the player is the owner of their island, i.e., owner or team leader
|
||||
*/
|
||||
public boolean isOwner(UUID uniqueId) {
|
||||
if (hasIsland(uniqueId)) {
|
||||
return getIsland(uniqueId).getOwner().equals(uniqueId) ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,38 @@
|
||||
package us.tastybento.bskyblock.database;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.database.objects.APlayer;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.Players;
|
||||
import us.tastybento.bskyblock.util.VaultHelper;
|
||||
|
||||
public class PlayersManager{
|
||||
|
||||
private BSkyBlock plugin;
|
||||
private ASBDatabase database;
|
||||
|
||||
private HashMap<UUID, APlayer> players;
|
||||
private HashMap<UUID, Players> playerCache;
|
||||
|
||||
/**
|
||||
* Provides a memory cache of online player information
|
||||
* This is the one-stop-shop of player info
|
||||
* If the player is not cached, then a request is made to Players to obtain it
|
||||
*
|
||||
* @param plugin
|
||||
*/
|
||||
public PlayersManager(BSkyBlock plugin){
|
||||
this.plugin = plugin;
|
||||
database = ASBDatabase.getDatabase();
|
||||
players = new HashMap<UUID, APlayer>();
|
||||
playerCache = new HashMap<UUID, Players>();
|
||||
}
|
||||
|
||||
public void load(){
|
||||
@ -30,13 +45,13 @@ public class PlayersManager{
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for(Entry<UUID, APlayer> entry : players.entrySet()){
|
||||
for(Entry<UUID, Players> entry : playerCache.entrySet()){
|
||||
database.savePlayerData(entry.getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
for(Entry<UUID, APlayer> entry : players.entrySet()){
|
||||
for(Entry<UUID, Players> entry : playerCache.entrySet()){
|
||||
database.savePlayerData(entry.getValue());
|
||||
}
|
||||
}
|
||||
@ -44,10 +59,446 @@ public class PlayersManager{
|
||||
|
||||
public void shutdown(){
|
||||
save(false);
|
||||
players.clear();
|
||||
playerCache.clear();
|
||||
}
|
||||
|
||||
public APlayer getPlayer(UUID uuid){
|
||||
return players.get(uuid);
|
||||
public Players getPlayer(UUID uuid){
|
||||
return playerCache.get(uuid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Cache control methods
|
||||
*/
|
||||
|
||||
public Players addPlayer(final UUID playerUUID) {
|
||||
if (playerUUID == null)
|
||||
return null;
|
||||
//plugin.getLogger().info("DEBUG: added player " + playerUUID);
|
||||
if (!playerCache.containsKey(playerUUID)) {
|
||||
final Players player = new Players(playerUUID);
|
||||
playerCache.put(playerUUID, player);
|
||||
return player;
|
||||
} else {
|
||||
return playerCache.get(playerUUID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the player's info and removes the player from the cache
|
||||
*
|
||||
* @param player - UUID of player
|
||||
*
|
||||
*/
|
||||
public void removeOnlinePlayer(final UUID player) {
|
||||
if (playerCache.containsKey(player)) {
|
||||
database.savePlayerData(playerCache.get(player));
|
||||
playerCache.remove(player);
|
||||
// plugin.getLogger().info("Removing player from cache: " + player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all players on the server now from cache and saves their info
|
||||
*/
|
||||
public void removeAllPlayers() {
|
||||
for (UUID pl : playerCache.keySet()) {
|
||||
database.savePlayerData(playerCache.get(pl));
|
||||
}
|
||||
playerCache.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* Player info query methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if the player is known or not
|
||||
*
|
||||
* @param uniqueID
|
||||
* @return true if player is know, otherwise false
|
||||
*/
|
||||
public boolean isAKnownPlayer(final UUID uniqueID) {
|
||||
if (uniqueID == null) {
|
||||
return false;
|
||||
}
|
||||
// Try cache
|
||||
if (playerCache.containsKey(uniqueID)) {
|
||||
return true;
|
||||
} else {
|
||||
// Get from the database - do not add to cache yet
|
||||
return database.isPlayerKnown(uniqueID) ? true: false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player object for the named player
|
||||
*
|
||||
* @param playerUUID
|
||||
* - String name of player
|
||||
* @return - player object
|
||||
*/
|
||||
public Players get(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player has an island.
|
||||
*
|
||||
* @param playerUUID
|
||||
* - string name of player
|
||||
* @return true if player has island
|
||||
*/
|
||||
public boolean hasIsland(final UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return plugin.getIslands().hasIsland(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if player is in a Team from cache if available
|
||||
*
|
||||
* @param playerUUID
|
||||
* @return true if player in a team
|
||||
*/
|
||||
public boolean inTeam(final UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
Island island = plugin.getIslands().getIsland(playerUUID);
|
||||
if (island == null) {
|
||||
return false;
|
||||
}
|
||||
return island.getMembers().size() > 1 ? true: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any island associated with this player and generally cleans up
|
||||
* the player
|
||||
*
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void zeroPlayerData(UUID playerUUID) {
|
||||
Players player = addPlayer(playerUUID);
|
||||
player.clearHomeLocations();
|
||||
plugin.getIslands().removePlayer(playerUUID);
|
||||
/*
|
||||
* TODO
|
||||
playerCache.get(playerUUID).save(); // Needed?
|
||||
TopTen.topTenRemoveEntry(playerUUID);*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the home location for the player
|
||||
* @param playerUUID
|
||||
* @param location
|
||||
* @param number - 1 is default. Can be any number.
|
||||
*/
|
||||
public void setHomeLocation(UUID playerUUID, Location location, int number) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).setHomeLocation(location,number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default home location for player
|
||||
* @param playerUUID
|
||||
* @param location
|
||||
*/
|
||||
public void setHomeLocation(UUID playerUUID, Location location) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).setHomeLocation(location,1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears any home locations for player
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void clearHomeLocations(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).clearHomeLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the home location, or null if none
|
||||
*
|
||||
* @param playerUUID
|
||||
* @param number
|
||||
* @return Home location or null if none
|
||||
*/
|
||||
public Location getHomeLocation(UUID playerUUID, int number) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getHomeLocation(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default home location for player
|
||||
* @param playerUUID
|
||||
* @return Home location or null if none
|
||||
*/
|
||||
public Location getHomeLocation(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getHomeLocation(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides all home locations for player
|
||||
* @param playerUUID
|
||||
* @return List of home locations
|
||||
*/
|
||||
public HashMap<Integer, Location> getHomeLocations(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getHomeLocations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to return a UUID for a given player's name. Only uses online or cached information.
|
||||
* @param string
|
||||
* @return UUID of player or null if unknown
|
||||
*/
|
||||
public UUID getUUID(String string) {
|
||||
return getUUID(string, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to return a UUID for a given player's name
|
||||
* @param string
|
||||
* @param adminCheck - if made via an admin call, this will go out to the 'net and grab - may cause lag
|
||||
* @return UUID of player or null if unknown
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public UUID getUUID(String string, boolean adminCheck) {
|
||||
// Look in the database if it ready
|
||||
return database.getUUID(string, adminCheck);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player's name and updates the name>UUID database
|
||||
* @param uniqueId
|
||||
* @param name
|
||||
*/
|
||||
public void setPlayerName(UUID uniqueId, String name) {
|
||||
addPlayer(uniqueId);
|
||||
playerCache.get(uniqueId).setPlayerN(name);
|
||||
database.savePlayerName(name, uniqueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the name of the player from their UUID
|
||||
* Player must have logged into the game before
|
||||
*
|
||||
* @param playerUUID
|
||||
* @return String - playerName
|
||||
*/
|
||||
public String getName(UUID playerUUID) {
|
||||
if (playerUUID == null) {
|
||||
return "";
|
||||
}
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getPlayerName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse lookup - returns the owner of an island from the location
|
||||
*
|
||||
* @param loc
|
||||
* @return UUID of owner of island
|
||||
*/
|
||||
public UUID getPlayerFromIslandLocation(Location loc) {
|
||||
if (loc == null)
|
||||
return null;
|
||||
// Look in the grid
|
||||
Island island = plugin.getIslands().getIslandAt(loc);
|
||||
if (island != null) {
|
||||
return island.getOwner();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets how many island resets the player has left
|
||||
*
|
||||
* @param playerUUID
|
||||
* @return number of resets
|
||||
*/
|
||||
public int getResetsLeft(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getResetsLeft();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets how many resets the player has left
|
||||
*
|
||||
* @param playerUUID
|
||||
* @param resets
|
||||
*/
|
||||
public void setResetsLeft(UUID playerUUID, int resets) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).setResetsLeft(resets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how long the player must wait before they can be invited to an
|
||||
* island with the location
|
||||
*
|
||||
* @param playerUUID
|
||||
* @param location
|
||||
* @return time to wait in minutes/hours
|
||||
*/
|
||||
public long getInviteCoolDownTime(UUID playerUUID, Location location) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getInviteCoolDownTime(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the timer for the player for this location before which they can
|
||||
* be invited
|
||||
* Called when they are kicked from an island or leave.
|
||||
*
|
||||
* @param playerUUID
|
||||
* @param location
|
||||
*/
|
||||
public void startInviteCoolDownTimer(UUID playerUUID, Location location) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).startInviteCoolDownTimer(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale for this player. If missing, will return nothing
|
||||
* @param playerUUID
|
||||
* @return name of the locale this player uses
|
||||
*/
|
||||
public String getLocale(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
if (playerUUID == null) {
|
||||
return "";
|
||||
}
|
||||
return playerCache.get(playerUUID).getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the locale this player wants to use
|
||||
* @param playerUUID
|
||||
* @param localeName
|
||||
*/
|
||||
public void setLocale(UUID playerUUID, String localeName) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).setLocale(localeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ban target from a player's island. Ban may be blocked by event being cancelled.
|
||||
* @param playerUUID
|
||||
* @param targetUUID
|
||||
* @return true if banned, false if not
|
||||
*/
|
||||
public boolean ban(UUID playerUUID, UUID targetUUID) {
|
||||
addPlayer(playerUUID);
|
||||
addPlayer(targetUUID);
|
||||
Island island = plugin.getIslands().getIsland(playerUUID);
|
||||
if (island != null) {
|
||||
// Player has island
|
||||
return island.addToBanList(targetUUID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unban target from player's island
|
||||
* @param playerUUID
|
||||
* @param targetUUID
|
||||
* @return
|
||||
*/
|
||||
public boolean unBan(UUID playerUUID, UUID targetUUID) {
|
||||
addPlayer(playerUUID);
|
||||
addPlayer(targetUUID);
|
||||
Island island = plugin.getIslands().getIsland(playerUUID);
|
||||
if (island != null) {
|
||||
// Player has island
|
||||
return island.removeFromBanList(targetUUID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param playerUUID
|
||||
* @param targetUUID
|
||||
* @return true if target is banned from player's island
|
||||
*/
|
||||
public boolean isBanned(UUID playerUUID, UUID targetUUID) {
|
||||
if (playerUUID == null || targetUUID == null) {
|
||||
// If the island is unowned, then playerUUID could be null
|
||||
return false;
|
||||
}
|
||||
addPlayer(playerUUID);
|
||||
addPlayer(targetUUID);
|
||||
// Check if the target player has a permission bypass (admin.noban)
|
||||
Player target = plugin.getServer().getPlayer(targetUUID);
|
||||
if (target != null && VaultHelper.checkPerm(target, Settings.PERMPREFIX + "admin.noban")) {
|
||||
return false;
|
||||
}
|
||||
Island island = plugin.getIslands().getIsland(playerUUID);
|
||||
if (island != null) {
|
||||
// Player has island
|
||||
return island.isBanned(targetUUID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears resets for online players or players in the cache
|
||||
* @param resetLimit
|
||||
*/
|
||||
public void clearResets(int resetLimit) {
|
||||
for (Players player : playerCache.values()) {
|
||||
player.setResetsLeft(resetLimit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the player uses the control panel or not when doing /island
|
||||
* @param b
|
||||
*/
|
||||
public void setControlPanel(UUID playerUUID, boolean b) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).setControlPanel(b);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the player uses the control panel or not when doing /island
|
||||
* @param playerUUID
|
||||
* @return true if they use the control panel
|
||||
*/
|
||||
public boolean getControlPanel(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getControlPanel();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add death to player
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void addDeath(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).addDeath();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set death number for player
|
||||
* @param playerUUID
|
||||
* @param deaths
|
||||
*/
|
||||
public void setDeaths(UUID playerUUID, int deaths) {
|
||||
addPlayer(playerUUID);
|
||||
playerCache.get(playerUUID).setDeaths(deaths);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of times player has died in ASkyBlock worlds since counting began
|
||||
* @param playerUUID
|
||||
* @return
|
||||
*/
|
||||
public int getDeaths(UUID playerUUID) {
|
||||
addPlayer(playerUUID);
|
||||
return playerCache.get(playerUUID).getDeaths();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,20 +4,51 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import us.tastybento.bskyblock.database.ASBDatabase;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.APlayer;
|
||||
import us.tastybento.bskyblock.database.objects.Players;
|
||||
|
||||
public class FlatFileDatabase extends ASBDatabase{
|
||||
|
||||
@Override
|
||||
public APlayer loadPlayerData(UUID uuid) {
|
||||
public UUID getUUID(String name, boolean adminCheck) {
|
||||
/*
|
||||
if (plugin.getTinyDB() != null && plugin.getTinyDB().isDbReady()) {
|
||||
UUID result = plugin.getTinyDB().getPlayerUUID(string);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
// This goes after the database because it is possible for islands that have a duplicate name to be in
|
||||
// the cache. For example, Bill had an island but left. Bill changes his name to Bob. Then Alice changes
|
||||
// her name to Bill and logs into the game. There are now two islands with owner names called "Bill"
|
||||
// The name database will ensure the names are updated.
|
||||
for (UUID id : playerCache.keySet()) {
|
||||
String name = playerCache.get(id).getPlayerName();
|
||||
//plugin.getLogger().info("DEBUG: Testing name " + name);
|
||||
if (name != null && name.equalsIgnoreCase(string)) {
|
||||
//plugin.getLogger().info("DEBUG: found it! " + id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
*/
|
||||
// Try the server
|
||||
if (adminCheck) {
|
||||
return Bukkit.getServer().getOfflinePlayer(name).getUniqueId();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Players loadPlayerData(UUID uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePlayerData(APlayer player) {
|
||||
public void savePlayerData(Players player) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -45,4 +76,16 @@ public class FlatFileDatabase extends ASBDatabase{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerKnown(UUID uniqueID) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePlayerName(String name, UUID uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,18 +6,18 @@ import java.util.UUID;
|
||||
|
||||
import us.tastybento.bskyblock.database.ASBDatabase;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.APlayer;
|
||||
import us.tastybento.bskyblock.database.objects.Players;
|
||||
|
||||
public class MySQLDatabase extends ASBDatabase{
|
||||
|
||||
@Override
|
||||
public APlayer loadPlayerData(UUID uuid) {
|
||||
public Players loadPlayerData(UUID uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePlayerData(APlayer player) {
|
||||
public void savePlayerData(Players player) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -46,4 +46,22 @@ public class MySQLDatabase extends ASBDatabase{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerKnown(UUID uniqueID) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name, boolean adminCheck) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePlayerName(String name, UUID uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,166 +0,0 @@
|
||||
package us.tastybento.bskyblock.database.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
* Tracks info on the player, recognized by his UUID
|
||||
*
|
||||
* @author Tastybento
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class APlayer {
|
||||
private UUID uuid;
|
||||
|
||||
private String locale;
|
||||
private boolean useControlPanel;
|
||||
private Island island;
|
||||
private int deaths;
|
||||
private int resetsLeft;
|
||||
private HashMap<Integer, Location> homes;
|
||||
|
||||
/**
|
||||
* Constructor - initializes the variables
|
||||
* @param uuid - UUID of the player
|
||||
*/
|
||||
public APlayer(UUID uuid){
|
||||
this.uuid = uuid;
|
||||
|
||||
this.locale = "";
|
||||
this.useControlPanel = Settings.useControlPanel;
|
||||
this.island = null;
|
||||
this.deaths = 0;
|
||||
this.resetsLeft = Settings.defaultResetLimit;
|
||||
this.homes = new HashMap<Integer, Location>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return player UUID
|
||||
*/
|
||||
public UUID getUUID(){
|
||||
return uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player locale
|
||||
*/
|
||||
public String getLocale(){
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param localeID - the locale to set
|
||||
*/
|
||||
public void setLocale(String localeID){
|
||||
this.locale = localeID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player uses the control panel
|
||||
*/
|
||||
public boolean useControlPanel(){
|
||||
return useControlPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param useControlPanel - display the control panel to the player when /is or not
|
||||
*/
|
||||
public void setUseControlPanel(boolean useControlPanel){
|
||||
this.useControlPanel = useControlPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player island, or null if he don't have one
|
||||
*/
|
||||
public Island getIsland(){
|
||||
return island;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param island - the island to set
|
||||
*/
|
||||
public void setIsland(Island island){
|
||||
this.island = island;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player island location
|
||||
*/
|
||||
public Location getIslandLocation(){
|
||||
return island.getCenter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player has an island (solo or in team)
|
||||
*/
|
||||
public boolean hasIsland(){
|
||||
return island != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is the owner (team leader) of his island
|
||||
*/
|
||||
public boolean isOwner(){
|
||||
return island.getOwner().equals(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the player is in a team
|
||||
*/
|
||||
public boolean inTeam(){
|
||||
return island.getMembers().contains(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the island team leader
|
||||
*/
|
||||
public UUID getTeamLeader(){
|
||||
return island.getOwner();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player death count
|
||||
*/
|
||||
public int getDeathCount(){
|
||||
return deaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deaths - the death count to set
|
||||
*/
|
||||
public void setDeathCount(int deaths){
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player resets left
|
||||
*/
|
||||
public int getResetsLeft(){
|
||||
return resetsLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resetsLeft - the resets left to set
|
||||
*/
|
||||
public void setResetsLeft(int resetsLeft){
|
||||
this.resetsLeft = resetsLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player homes
|
||||
*/
|
||||
public HashMap<Integer, Location> getHomes(){
|
||||
return homes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param homes - the homes to set
|
||||
*/
|
||||
public void setHomes(HashMap<Integer, Location> homes){
|
||||
this.homes = homes;
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package us.tastybento.bskyblock.database.objects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandLockEvent;
|
||||
@ -14,101 +16,132 @@ import us.tastybento.bskyblock.config.Settings;
|
||||
/**
|
||||
* Stores all the info about an island
|
||||
* Managed by IslandsManager
|
||||
* Responsible for team information as well.
|
||||
*
|
||||
* @author Tastybento
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class Island {
|
||||
private BSkyBlock plugin;
|
||||
|
||||
|
||||
//// Island ////
|
||||
// The center of the island itself
|
||||
private Location center;
|
||||
// Island range
|
||||
private int range;
|
||||
|
||||
|
||||
// Coordinates of the island area
|
||||
private int minX;
|
||||
private int minZ;
|
||||
// Coordinates of minimum protected area
|
||||
private int minProtectedX;
|
||||
private int minProtectedZ;
|
||||
// Protection size
|
||||
private int protectionRange;
|
||||
// Height of island
|
||||
private int y;
|
||||
// World the island is in
|
||||
private World world;
|
||||
|
||||
// Display name
|
||||
private String name;
|
||||
|
||||
|
||||
// Time parameters
|
||||
private long createdDate;
|
||||
private long updatedDate;
|
||||
|
||||
|
||||
//// Team ////
|
||||
// Owner (Team Leader)
|
||||
private UUID owner;
|
||||
// Members
|
||||
private List<UUID> members;
|
||||
// Members (use set because each value must be unique)
|
||||
private Set<UUID> members;
|
||||
// Trustees
|
||||
private List<UUID> trustees;
|
||||
private Set<UUID> trustees;
|
||||
// Coops
|
||||
private List<UUID> coops;
|
||||
|
||||
private Set<UUID> coops;
|
||||
// Banned players
|
||||
private Set<UUID> banned;
|
||||
|
||||
//// State ////
|
||||
private boolean locked = false;
|
||||
private boolean isSpawn = false;
|
||||
private boolean purgeProtected = false;
|
||||
|
||||
|
||||
//// Rating ////
|
||||
private int level;
|
||||
private int levelHandicap;
|
||||
|
||||
|
||||
//// Protection ////
|
||||
private HashMap<SettingsFlag, Boolean> flags = new HashMap<SettingsFlag, Boolean>();
|
||||
|
||||
public Island(BSkyBlock plugin, int x, int z, UUID owner){
|
||||
|
||||
|
||||
public Island(Location location, UUID owner, int protectionRange) {
|
||||
this.members = new HashSet<UUID>();
|
||||
this.members.add(owner);
|
||||
this.owner = owner;
|
||||
this.coops = new HashSet<UUID>();
|
||||
this.trustees = new HashSet<UUID>();
|
||||
this.banned = new HashSet<UUID>();
|
||||
this.createdDate = System.currentTimeMillis();
|
||||
this.updatedDate = System.currentTimeMillis();
|
||||
this.name = "";
|
||||
this.world = location.getWorld();
|
||||
this.center = location;
|
||||
this.minX = center.getBlockX() - Settings.islandDistance;
|
||||
this.minZ = center.getBlockZ() - Settings.islandDistance;
|
||||
this.protectionRange = protectionRange;
|
||||
this.minProtectedX = center.getBlockX() - protectionRange;
|
||||
this.minProtectedZ = center.getBlockZ() - protectionRange;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the center Location
|
||||
*/
|
||||
public Location getCenter(){
|
||||
return center;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the x coordinate of the island center
|
||||
*/
|
||||
public int getX(){
|
||||
return center.getBlockX();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the y coordinate of the island center
|
||||
*/
|
||||
public int getY(){
|
||||
return center.getBlockY();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the z coordinate of the island center
|
||||
*/
|
||||
public int getZ(){
|
||||
return center.getBlockZ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the island range
|
||||
*/
|
||||
public int getRange(){
|
||||
return range;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param range - the range to set
|
||||
*/
|
||||
public void setRange(int range){
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the island display name or the owner's name if none is set
|
||||
*/
|
||||
public String getName(){
|
||||
return (name != null) ? name : plugin.getServer().getOfflinePlayer(owner).getName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name - the display name to set
|
||||
* Set to null to remove the display name
|
||||
@ -116,98 +149,100 @@ public class Island {
|
||||
public void setName(String name){
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the date when the island was created
|
||||
*/
|
||||
public long getCreatedDate(){
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param createdDate - the createdDate to sets
|
||||
*/
|
||||
public void setCreatedDate(long createdDate){
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the date when the island was updated (team member connection, etc...)
|
||||
*/
|
||||
public long getUpdatedDate(){
|
||||
return updatedDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param updatedDate - the updatedDate to sets
|
||||
*/
|
||||
public void setUptadedDate(long updatedDate){
|
||||
public void setUpdatedDate(long updatedDate){
|
||||
this.updatedDate = updatedDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the owner (team leader)
|
||||
*/
|
||||
public UUID getOwner(){
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the owner of the island. If the owner was previous banned, they are unbanned
|
||||
* @param owner - the owner/team leader to set
|
||||
*/
|
||||
public void setOwner(UUID owner){
|
||||
this.owner = owner;
|
||||
this.banned.remove(owner);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the members of the island (owner included)
|
||||
*/
|
||||
public List<UUID> getMembers(){
|
||||
public Set<UUID> getMembers(){
|
||||
return members;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param members - the members to set
|
||||
*/
|
||||
public void setMembers(List<UUID> members){
|
||||
public void setMembers(Set<UUID> members){
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the trustees players of the island
|
||||
*/
|
||||
public List<UUID> getTrustees(){
|
||||
public Set<UUID> getTrustees(){
|
||||
return trustees;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param trustees - the trustees to set
|
||||
*/
|
||||
public void setTrustees(List<UUID> trustees){
|
||||
public void setTrustees(Set<UUID> trustees){
|
||||
this.trustees = trustees;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the coop players of the island
|
||||
*/
|
||||
public List<UUID> getCoops(){
|
||||
public Set<UUID> getCoops(){
|
||||
return coops;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param coops - the coops to set
|
||||
*/
|
||||
public void setCoops(List<UUID> coops){
|
||||
public void setCoops(Set<UUID> coops){
|
||||
this.coops = coops;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the island is locked, otherwise false
|
||||
*/
|
||||
public boolean isLocked(){
|
||||
return locked;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Locks/Unlocks the island. May be cancelled by
|
||||
* {@link IslandLockEvent} or {@link IslandUnlockEvent}.
|
||||
@ -218,7 +253,7 @@ public class Island {
|
||||
// Lock the island
|
||||
IslandLockEvent event = new IslandLockEvent(this);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
|
||||
if(!event.isCancelled()){
|
||||
this.locked = locked;
|
||||
}
|
||||
@ -226,69 +261,69 @@ public class Island {
|
||||
// Unlock the island
|
||||
IslandUnlockEvent event = new IslandUnlockEvent(this);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
|
||||
if(!event.isCancelled()){
|
||||
this.locked = locked;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the island is the spawn otherwise false
|
||||
*/
|
||||
public boolean isSpawn(){
|
||||
return isSpawn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param isSpawn - if the island is the spawn
|
||||
*/
|
||||
public void setSpawn(boolean isSpawn){
|
||||
this.isSpawn = isSpawn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the island is protected from the Purge, otherwise false
|
||||
*/
|
||||
public boolean isPurgeProtected(){
|
||||
return purgeProtected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param purgeProtected - if the island is protected from the Purge
|
||||
*/
|
||||
public void setPurgeProtected(boolean purgeProtected){
|
||||
this.purgeProtected = purgeProtected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the island level
|
||||
*/
|
||||
public int getLevel(){
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param level - the island level to set
|
||||
*/
|
||||
public void setLevel(int level){
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the island level handicap
|
||||
*/
|
||||
public int getLevelHandicap(){
|
||||
return levelHandicap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param levelHandicap - the island level handicap to set
|
||||
*/
|
||||
public void setLevelHandicap(int levelHandicap){
|
||||
this.levelHandicap = levelHandicap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Island Guard Settings flags
|
||||
* Covers island, spawn and system settings
|
||||
@ -298,251 +333,251 @@ public class Island {
|
||||
public enum SettingsFlag{
|
||||
// Can use Anvil
|
||||
ANVIL,
|
||||
|
||||
|
||||
// Can interact with Armor Stand
|
||||
ARMOR_STAND,
|
||||
|
||||
|
||||
// Can interact with Beacon
|
||||
BEACON,
|
||||
|
||||
|
||||
// Can use bed
|
||||
BED,
|
||||
|
||||
|
||||
// Can break blocks
|
||||
BREAK_BLOCKS,
|
||||
|
||||
|
||||
// Can breed animals
|
||||
BREEDING,
|
||||
|
||||
|
||||
// Can use brewing stand
|
||||
BREWING,
|
||||
|
||||
|
||||
// Can use buttons
|
||||
BUTTON,
|
||||
|
||||
|
||||
// Can empty or fill buckets
|
||||
BUCKET,
|
||||
|
||||
|
||||
// Can collect lava (override BUCKET)
|
||||
COLLECT_LAVA,
|
||||
|
||||
|
||||
// Can collect water (override BUCKET)
|
||||
COLLECT_WATER,
|
||||
|
||||
|
||||
// Can eat and teleport with Chorus Fruit
|
||||
CHORUS_FRUIT,
|
||||
|
||||
|
||||
// Can use the workbench
|
||||
CRAFTING,
|
||||
|
||||
|
||||
// Allow creepers to hurt entities (but not to destroy blocks)
|
||||
CREEPER_HURT,
|
||||
|
||||
|
||||
// Allow creepers to destroy blocks
|
||||
CREEPER_GRIEFING,
|
||||
|
||||
|
||||
// Allow creepers to blow up chests (only if creeper_griefing is enabled)
|
||||
CREEPER_BLOW_UP_CHEST,
|
||||
|
||||
|
||||
// Allow creepers to blow up dispensers (only if creeper_griefing is enabled)
|
||||
CREEPER_BLOW_UP_DISPENSER,
|
||||
|
||||
|
||||
// Allow creepers to blow up droppers (only if creeper_griefing is enabled)
|
||||
CREEPER_BLOW_UP_DROPPER,
|
||||
|
||||
|
||||
// Allow creepers to blow up hoppers (only if creeper_griefing is enabled)
|
||||
CREEPER_BLOW_UP_HOPPER,
|
||||
|
||||
|
||||
// Allow creepers to blow up shulker boxes (only if creeper_griefing is enabled)
|
||||
CREEPER_BLOW_UP_SHULKER_BOX,
|
||||
|
||||
|
||||
// Can trample crops
|
||||
CROP_TRAMPLE,
|
||||
|
||||
|
||||
// Can open doors or trapdoors
|
||||
DOOR,
|
||||
|
||||
|
||||
// Can use Elytras
|
||||
ELYTRA,
|
||||
|
||||
|
||||
// Can use the enchanting table
|
||||
ENCHANTING,
|
||||
|
||||
|
||||
// Allow Enderman griefing
|
||||
ENDERMAN_GRIEFING,
|
||||
|
||||
|
||||
// Display enter/exit island messages
|
||||
ENTER_EXIT_MESSAGES,
|
||||
|
||||
|
||||
// Fire use/placement in general
|
||||
FIRE,
|
||||
|
||||
|
||||
// Can extinguish fires by punching them
|
||||
FIRE_EXTINGUISH,
|
||||
|
||||
|
||||
// Allow fire spread
|
||||
FIRE_SPREAD,
|
||||
|
||||
|
||||
// Can use fishing rod
|
||||
FISHING_ROD,
|
||||
|
||||
|
||||
// Can use furnaces
|
||||
FURNACE,
|
||||
|
||||
|
||||
// Can open gates
|
||||
GATE,
|
||||
|
||||
|
||||
// Can hurt animals (e.g. cows) - Villagers excluded
|
||||
HURT_ANIMALS,
|
||||
|
||||
|
||||
// Can hurt monsters
|
||||
HURT_MONSTERS,
|
||||
|
||||
|
||||
// Can hurt villagers
|
||||
HURT_VILLAGERS,
|
||||
|
||||
|
||||
// Can ignite creepers using flint and steel
|
||||
IGNITE_CREEPER,
|
||||
|
||||
|
||||
// Can ignite TNTs using flint and steel
|
||||
IGNITE_TNT,
|
||||
|
||||
|
||||
// Can interact with tamed animals
|
||||
INTERACT_TAMED,
|
||||
|
||||
|
||||
// Can drop items
|
||||
ITEM_DROP,
|
||||
|
||||
|
||||
// Can pickup items
|
||||
ITEM_PICKUP,
|
||||
|
||||
|
||||
// Can leash or unleash animals
|
||||
LEASH,
|
||||
|
||||
|
||||
// Can use levers
|
||||
LEVER,
|
||||
|
||||
|
||||
// Can milk cows
|
||||
MILKING,
|
||||
|
||||
|
||||
// Animals can spawn
|
||||
ANIMAL_SPAWN,
|
||||
|
||||
|
||||
// Monster projectiles can destroy item frames (skeleten arrows, shulker shots)
|
||||
MONSTER_DESTROY_ITEM_FRAMES,
|
||||
|
||||
|
||||
// Monsters can spawn
|
||||
MONSTER_SPAWN,
|
||||
|
||||
|
||||
// Can open horse or other animal inventories (llama)
|
||||
MOUNT_INVENTORY,
|
||||
|
||||
|
||||
// Can ride an animal
|
||||
MOUNT_RIDING,
|
||||
|
||||
|
||||
// Can operate jukeboxes, noteblocks
|
||||
MUSIC,
|
||||
|
||||
|
||||
// Can open chests
|
||||
OPEN_CHESTS,
|
||||
|
||||
|
||||
// Can open dispensers
|
||||
OPEN_DISPENSERS,
|
||||
|
||||
|
||||
// Can open droppers
|
||||
OPEN_DROPPERS,
|
||||
|
||||
|
||||
// Can open hoppers
|
||||
OPEN_HOPPERS,
|
||||
|
||||
|
||||
// Can open shulker boxes
|
||||
OPEN_SHULKER_BOXES,
|
||||
|
||||
|
||||
// Can place blocks
|
||||
PLACE_BLOCKS,
|
||||
|
||||
|
||||
// Can go through portals
|
||||
PORTAL,
|
||||
|
||||
|
||||
// Can activate pressure plates
|
||||
PRESSURE_PLATE,
|
||||
|
||||
|
||||
// Can do PvP in the overworld
|
||||
PVP_OVERWORLD,
|
||||
|
||||
|
||||
// Can do PvP in the nether
|
||||
PVP_NETHER,
|
||||
|
||||
|
||||
// Can interact with redstone items (repeaters, comparators)
|
||||
REDSTONE,
|
||||
|
||||
|
||||
// Can use spawn eggs
|
||||
SPAWN_EGGS,
|
||||
|
||||
|
||||
// Can shear sheeps
|
||||
SHEARING,
|
||||
|
||||
|
||||
// Can throw chicken eggs
|
||||
THROW_EGGS,
|
||||
|
||||
|
||||
// Can throw fireworks
|
||||
THROW_FIREWORKS,
|
||||
|
||||
|
||||
// Can throw enderpearls
|
||||
THROW_ENDERPEARLS,
|
||||
|
||||
|
||||
// Can throw snowballs
|
||||
THROW_SNOWBALLS,
|
||||
|
||||
|
||||
// Can throw splash potions
|
||||
THROW_SPLASH_POTIONS,
|
||||
|
||||
|
||||
// Allow TNT to hurt entities (but not to destroy blocks)
|
||||
TNT_HURT,
|
||||
|
||||
|
||||
// Allow TNT to destroy blocks
|
||||
TNT_GRIEFING,
|
||||
|
||||
|
||||
// Allow TNTs to blow up chests (only if TNT_griefing is enabled)
|
||||
TNT_BLOW_UP_CHEST,
|
||||
|
||||
|
||||
// Allow TNTs to blow up dispensers (only if TNT_griefing is enabled)
|
||||
TNT_BLOW_UP_DISPENSER,
|
||||
|
||||
|
||||
// Allow TNTs to blow up droppers (only if TNT_griefing is enabled)
|
||||
TNT_BLOW_UP_DROPPER,
|
||||
|
||||
|
||||
// Allow TNTs to blow up hoppers (only if TNT_griefing is enabled)
|
||||
TNT_BLOW_UP_HOPPER,
|
||||
|
||||
|
||||
// Allow TNTs to blow up shulker boxes (only if TNT_griefing is enabled)
|
||||
TNT_BLOW_UP_SHULKER_BOX,
|
||||
|
||||
|
||||
// Can trade with villagers
|
||||
VILLAGER_TRADING,
|
||||
|
||||
|
||||
// Allow Withers to hurt entities (but not to destroy blocks)
|
||||
WITHER_HURT,
|
||||
|
||||
|
||||
// Allow Wither to destroy blocks
|
||||
WITHER_GRIEFING,
|
||||
|
||||
|
||||
// Allow withers to blow up chests (only if wither_griefing is enabled)
|
||||
WITHER_BLOW_UP_CHEST,
|
||||
|
||||
|
||||
// Allow withers to blow up dispensers (only if wither_griefing is enabled)
|
||||
WITHER_BLOW_UP_DISPENSER,
|
||||
|
||||
|
||||
// Allow withers to blow up droppers (only if wither_griefing is enabled)
|
||||
WITHER_BLOW_UP_DROPPER,
|
||||
|
||||
|
||||
// Allow withers to blow up hoppers (only if wither_griefing is enabled)
|
||||
WITHER_BLOW_UP_HOPPER,
|
||||
|
||||
|
||||
// Allow withers to blow up shulker boxes (only if wither_griefing is enabled)
|
||||
WITHER_BLOW_UP_SHULKER_BOX
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the flags to their default as set in config.yml for this island
|
||||
*/
|
||||
@ -551,7 +586,7 @@ public class Island {
|
||||
this.flags.put(flag, Settings.defaultIslandSettings.get(flag));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the flags to their default as set in config.yml for the spawn
|
||||
*/
|
||||
@ -560,7 +595,7 @@ public class Island {
|
||||
this.flags.put(flag, Settings.defaultSpawnSettings.get(flag));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Island Guard flag status
|
||||
* @param flag
|
||||
@ -570,7 +605,7 @@ public class Island {
|
||||
if(flags.containsKey(flag)) return flags.get(flag);
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the Island Guard flag status
|
||||
* @param flag
|
||||
@ -579,7 +614,7 @@ public class Island {
|
||||
public void setFlag(SettingsFlag flag, boolean value){
|
||||
flags.put(flag, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Toggles the Island Guard flag status if it is in the list
|
||||
* @param flag
|
||||
@ -587,4 +622,101 @@ public class Island {
|
||||
public void toggleFlag(SettingsFlag flag){
|
||||
if(flags.containsKey(flag)) flags.put(flag, (flags.get(flag)) ? false : true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a team member. If player is on banned list, they will be removed from it.
|
||||
* @param playerUUID
|
||||
*/
|
||||
public void addMember(UUID playerUUID) {
|
||||
members.add(playerUUID);
|
||||
banned.remove(playerUUID);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a location is within this island's protected area
|
||||
*
|
||||
* @param target
|
||||
* @return true if it is, false if not
|
||||
*/
|
||||
public boolean onIsland(Location target) {
|
||||
if (center.getWorld() != null) {
|
||||
if (target.getBlockX() >= minProtectedX && target.getBlockX() < (minProtectedX + protectionRange)
|
||||
&& target.getBlockZ() >= minProtectedZ && target.getBlockZ() < (minProtectedZ + protectionRange)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean inIslandSpace(int x, int z) {
|
||||
if (x >= center.getBlockX() - Settings.islandDistance / 2 && x < center.getBlockX() + Settings.islandDistance / 2 && z >= center.getBlockZ() - Settings.islandDistance / 2
|
||||
&& z < center.getBlockZ() + Settings.islandDistance / 2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
|
||||
* If the player is a member, coop or trustee, they will be removed from those lists.
|
||||
* @param targetUUID
|
||||
* @return
|
||||
*/
|
||||
public boolean addToBanList(UUID targetUUID) {
|
||||
// TODO fire ban event
|
||||
if (members.contains(targetUUID)) {
|
||||
members.remove(targetUUID);
|
||||
}
|
||||
if (coops.contains(targetUUID)) {
|
||||
coops.remove(targetUUID);
|
||||
}
|
||||
if (trustees.contains(targetUUID)) {
|
||||
trustees.remove(targetUUID);
|
||||
}
|
||||
banned.add(targetUUID);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes target from the banned list. May be cancelled by unban event.
|
||||
* @param targetUUID
|
||||
* @return true if successful, otherwise false.
|
||||
*/
|
||||
public boolean removeFromBanList(UUID targetUUID) {
|
||||
// TODO fire unban event
|
||||
banned.remove(targetUUID);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if banned
|
||||
* @param targetUUID
|
||||
* @return Returns true if target is banned on this island
|
||||
*/
|
||||
public boolean isBanned(UUID targetUUID) {
|
||||
return banned.contains(targetUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the protectionRange
|
||||
*/
|
||||
public int getProtectionRange() {
|
||||
return protectionRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param protectionRange the protectionRange to set
|
||||
*/
|
||||
public void setProtectionRange(int protectionRange) {
|
||||
this.protectionRange = protectionRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the banned
|
||||
*/
|
||||
public Set<UUID> getBanned() {
|
||||
return banned;
|
||||
}
|
||||
}
|
||||
|
252
src/main/java/us/tastybento/bskyblock/database/objects/Players.java
Executable file
252
src/main/java/us/tastybento/bskyblock/database/objects/Players.java
Executable file
@ -0,0 +1,252 @@
|
||||
package us.tastybento.bskyblock.database.objects;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
* Tracks the following info on the player
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class Players {
|
||||
private HashMap<Integer, Location> homeLocations;
|
||||
private UUID uuid;
|
||||
private String playerName;
|
||||
private int resetsLeft;
|
||||
private String locale;
|
||||
private boolean useControlPanel;
|
||||
private int deaths;
|
||||
private HashMap<Location, Date> kickedList;
|
||||
|
||||
|
||||
/**
|
||||
* @param uuid
|
||||
* Constructor - initializes the state variables
|
||||
*
|
||||
*/
|
||||
public Players(final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.homeLocations = new HashMap<Integer,Location>();
|
||||
this.playerName = "";
|
||||
this.resetsLeft = Settings.defaultResetLimit;
|
||||
this.locale = "";
|
||||
this.useControlPanel = Settings.useControlPanel;
|
||||
this.kickedList = new HashMap<Location, Date>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default home location.
|
||||
* @return Location
|
||||
*/
|
||||
public Location getHomeLocation() {
|
||||
return getHomeLocation(1); // Default
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the home location by number.
|
||||
* @param number
|
||||
* @return Location of this home or null if not available
|
||||
*/
|
||||
public Location getHomeLocation(int number) {
|
||||
if (homeLocations.containsKey(number)) {
|
||||
return homeLocations.get(number);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a list of all home locations - used when searching for a safe spot to place someone
|
||||
* @return List of home locations
|
||||
*/
|
||||
public HashMap<Integer,Location> getHomeLocations() {
|
||||
HashMap<Integer,Location> result = new HashMap<Integer,Location>();
|
||||
for (int number : homeLocations.keySet()) {
|
||||
result.put(number, homeLocations.get(number));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return Bukkit.getPlayer(uuid);
|
||||
}
|
||||
|
||||
public UUID getPlayerUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public void setPlayerN(String playerName) {
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resetsLeft
|
||||
*/
|
||||
public int getResetsLeft() {
|
||||
return resetsLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resetsLeft
|
||||
* the resetsLeft to set
|
||||
*/
|
||||
public void setResetsLeft(int resetsLeft) {
|
||||
this.resetsLeft = resetsLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the home location of the player in a String format
|
||||
*
|
||||
* @param l
|
||||
* a Bukkit location
|
||||
*/
|
||||
public void setHomeLocation(final Location l) {
|
||||
setHomeLocation(l, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the numbered home location of the player. Numbering starts at 1.
|
||||
* @param location
|
||||
* @param number
|
||||
*/
|
||||
public void setHomeLocation(final Location location, int number) {
|
||||
if (location == null) {
|
||||
homeLocations.clear();
|
||||
} else {
|
||||
// Make the location x,y,z integer, but keep the yaw and pitch
|
||||
homeLocations.put(number, new Location(location.getWorld(),location.getBlockX(),location.getBlockY(),location.getBlockZ(),location.getYaw(), location.getPitch()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the uuid for this player object
|
||||
* @param uuid
|
||||
*/
|
||||
public void setPlayerUUID(final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all home Locations
|
||||
*/
|
||||
public void clearHomeLocations() {
|
||||
homeLocations.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the locale
|
||||
*/
|
||||
public String getLocale() {
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param locale the locale to set
|
||||
*/
|
||||
public void setLocale(String locale) {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether a player uses the control panel or not
|
||||
* @param b
|
||||
*/
|
||||
public void setControlPanel(boolean b) {
|
||||
useControlPanel = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return useControlPanel
|
||||
*/
|
||||
public boolean getControlPanel() {
|
||||
return useControlPanel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deaths
|
||||
*/
|
||||
public int getDeaths() {
|
||||
return deaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param deaths the deaths to set
|
||||
*/
|
||||
public void setDeaths(int deaths) {
|
||||
this.deaths = deaths;
|
||||
if (this.deaths > Settings.maxDeaths) {
|
||||
this.deaths = Settings.maxDeaths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add death
|
||||
*/
|
||||
public void addDeath() {
|
||||
this.deaths++;
|
||||
if (this.deaths > Settings.maxDeaths) {
|
||||
this.deaths = Settings.maxDeaths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can invite or still waiting for cool down to end
|
||||
*
|
||||
* @param location
|
||||
* to check
|
||||
* @return number of mins/hours left until cool down ends
|
||||
*/
|
||||
public long getInviteCoolDownTime(Location location) {
|
||||
// Check the hashmap
|
||||
if (location != null && kickedList.containsKey(location)) {
|
||||
// plugin.getLogger().info("DEBUG: Location is known");
|
||||
// The location is in the list
|
||||
// Check the date/time
|
||||
Date kickedDate = kickedList.get(location);
|
||||
// plugin.getLogger().info("DEBUG: kicked date = " + kickedDate);
|
||||
Calendar coolDownTime = Calendar.getInstance();
|
||||
coolDownTime.setTime(kickedDate);
|
||||
// coolDownTime.add(Calendar.HOUR_OF_DAY, Settings.inviteWait);
|
||||
coolDownTime.add(Calendar.MINUTE, Settings.inviteWait);
|
||||
// Add the invite cooldown period
|
||||
Calendar timeNow = Calendar.getInstance();
|
||||
// plugin.getLogger().info("DEBUG: date now = " + timeNow);
|
||||
if (coolDownTime.before(timeNow)) {
|
||||
// The time has expired
|
||||
kickedList.remove(location);
|
||||
return 0;
|
||||
} else {
|
||||
// Still not there yet
|
||||
// long hours = (coolDownTime.getTimeInMillis() -
|
||||
// timeNow.getTimeInMillis())/(1000 * 60 * 60);
|
||||
// Temp minutes
|
||||
long hours = (coolDownTime.getTimeInMillis() - timeNow.getTimeInMillis()) / (1000 * 60);
|
||||
return hours;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the invite cooldown timer for location. Location should be the center of an island.
|
||||
* @param location
|
||||
*/
|
||||
public void startInviteCoolDownTimer(Location location) {
|
||||
if (location != null) {
|
||||
kickedList.put(location, new Date());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,18 +6,18 @@ import java.util.UUID;
|
||||
|
||||
import us.tastybento.bskyblock.database.ASBDatabase;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
import us.tastybento.bskyblock.database.objects.APlayer;
|
||||
import us.tastybento.bskyblock.database.objects.Players;
|
||||
|
||||
public class SQLiteDatabase extends ASBDatabase{
|
||||
|
||||
@Override
|
||||
public APlayer loadPlayerData(UUID uuid) {
|
||||
public Players loadPlayerData(UUID uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePlayerData(APlayer player) {
|
||||
public void savePlayerData(Players player) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -46,4 +46,22 @@ public class SQLiteDatabase extends ASBDatabase{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPlayerKnown(UUID uniqueID) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUUID(String name, boolean adminCheck) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void savePlayerName(String name, UUID uuid) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,31 +1,28 @@
|
||||
package us.tastybento.bskyblock.util;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
||||
/**
|
||||
* Helper class for Vault Economy and Permissions
|
||||
*
|
||||
* @author Tastybento
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class VaultHelper {
|
||||
public static Economy econ = null;
|
||||
public static Permission permission = null;
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the economy instance
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public static boolean setupEconomy(BSkyBlock plugin) {
|
||||
RegisteredServiceProvider<Economy> economyProvider = plugin.getServer().getServicesManager()
|
||||
.getRegistration(Economy.class);
|
||||
public static boolean setupEconomy() {
|
||||
RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (economyProvider != null) {
|
||||
econ = economyProvider.getProvider();
|
||||
}
|
||||
@ -37,9 +34,9 @@ public class VaultHelper {
|
||||
*
|
||||
* @return true if successful
|
||||
*/
|
||||
public static boolean setupPermissions(BSkyBlock plugin) {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = plugin.getServer().getServicesManager()
|
||||
.getRegistration(Permission.class);
|
||||
public static boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.permission.Permission.class);
|
||||
if (permissionProvider != null) {
|
||||
permission = permissionProvider.getProvider();
|
||||
}
|
||||
@ -53,7 +50,7 @@ public class VaultHelper {
|
||||
* @param perm
|
||||
* @return true if the player has the perm
|
||||
*/
|
||||
public static boolean hasPerm(final Player player, final String perm) {
|
||||
public static boolean checkPerm(final Player player, final String perm) {
|
||||
return permission.has(player, perm);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user