mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-25 20:25:16 +01:00
Fixed bugs with start up and flag registration.
Protection does not work yet. Still need more debugging.
This commit is contained in:
parent
72c99656cc
commit
0d645600fc
@ -11,6 +11,7 @@ import us.tastybento.bskyblock.database.managers.island.IslandsManager;
|
|||||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||||
import us.tastybento.bskyblock.listeners.JoinLeaveListener;
|
import us.tastybento.bskyblock.listeners.JoinLeaveListener;
|
||||||
import us.tastybento.bskyblock.listeners.PanelListenerManager;
|
import us.tastybento.bskyblock.listeners.PanelListenerManager;
|
||||||
|
import us.tastybento.bskyblock.lists.Flags;
|
||||||
import us.tastybento.bskyblock.managers.AddonsManager;
|
import us.tastybento.bskyblock.managers.AddonsManager;
|
||||||
import us.tastybento.bskyblock.managers.CommandsManager;
|
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||||
import us.tastybento.bskyblock.managers.FlagsManager;
|
import us.tastybento.bskyblock.managers.FlagsManager;
|
||||||
@ -99,6 +100,7 @@ public class BSkyBlock extends JavaPlugin {
|
|||||||
|
|
||||||
// Load Flags
|
// Load Flags
|
||||||
flagsManager = new FlagsManager(plugin);
|
flagsManager = new FlagsManager(plugin);
|
||||||
|
new Flags();
|
||||||
|
|
||||||
// Load addons
|
// Load addons
|
||||||
addonsManager = new AddonsManager(plugin);
|
addonsManager = new AddonsManager(plugin);
|
||||||
|
@ -30,7 +30,7 @@ public class Flag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Listener> getListener() {
|
public Optional<Listener> getListener() {
|
||||||
return Optional.of(listener);
|
return Optional.ofNullable(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAllowed() {
|
public boolean isAllowed() {
|
||||||
|
@ -101,7 +101,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
|||||||
}
|
}
|
||||||
getIslands().save(false);
|
getIslands().save(false);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
getPlugin().getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMembers().toString());
|
getPlugin().getLogger().info("DEBUG: After save " + getIslands().getIsland(prospectiveTeamLeaderUUID).getMemberSet().toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ public class IslandCache {
|
|||||||
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
|
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
|
||||||
islandsByUUID.put(island.getOwner(), island);
|
islandsByUUID.put(island.getOwner(), island);
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: island has " + island.getMembers().size() + " members");
|
plugin.getLogger().info("DEBUG: island has " + island.getMemberSet().size() + " members");
|
||||||
for (UUID member: island.getMembers()) {
|
for (UUID member: island.getMemberSet()) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: " + member);
|
plugin.getLogger().info("DEBUG: " + member);
|
||||||
islandsByUUID.put(member, island);
|
islandsByUUID.put(member, island);
|
||||||
@ -288,7 +288,7 @@ public class IslandCache {
|
|||||||
public Set<UUID> getMembers(UUID playerUUID) {
|
public Set<UUID> getMembers(UUID playerUUID) {
|
||||||
Island island = islandsByUUID.get(playerUUID);
|
Island island = islandsByUUID.get(playerUUID);
|
||||||
if (island != null)
|
if (island != null)
|
||||||
return new HashSet<UUID>(island.getMembers());
|
return new HashSet<UUID>(island.getMemberSet());
|
||||||
return new HashSet<UUID>(0);
|
return new HashSet<UUID>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,10 +336,10 @@ public class IslandCache {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: player is the owner of this island");
|
plugin.getLogger().info("DEBUG: player is the owner of this island");
|
||||||
// Clear ownership and members
|
// Clear ownership and members
|
||||||
island.getMembers().clear();
|
island.getMemberSet().clear();
|
||||||
island.setOwner(null);
|
island.setOwner(null);
|
||||||
}
|
}
|
||||||
island.getMembers().remove(playerUUID);
|
island.getMemberSet().remove(playerUUID);
|
||||||
}
|
}
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: removing reference to island by UUID");
|
plugin.getLogger().info("DEBUG: removing reference to island by UUID");
|
||||||
|
@ -785,7 +785,7 @@ public class IslandsManager {
|
|||||||
//plugin.getLogger().info("DEBUG: members = " + island.getMembers());
|
//plugin.getLogger().info("DEBUG: members = " + island.getMembers());
|
||||||
//plugin.getLogger().info("DEBUG: player UUID = " + player.getUniqueId());
|
//plugin.getLogger().info("DEBUG: player UUID = " + player.getUniqueId());
|
||||||
|
|
||||||
if (island.get().onIsland(loc) && island.get().getMembers().contains(player.getUniqueId())) {
|
if (island.get().onIsland(loc) && island.get().getMemberSet().contains(player.getUniqueId())) {
|
||||||
//plugin.getLogger().info("DEBUG: allowed");
|
//plugin.getLogger().info("DEBUG: allowed");
|
||||||
// In a protected zone but is on the list of acceptable players
|
// In a protected zone but is on the list of acceptable players
|
||||||
return true;
|
return true;
|
||||||
@ -972,7 +972,7 @@ public class IslandsManager {
|
|||||||
islandCache.addPlayer(playerUUID, teamIsland);
|
islandCache.addPlayer(playerUUID, teamIsland);
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
plugin.getLogger().info("DEBUG: new team member list:");
|
plugin.getLogger().info("DEBUG: new team member list:");
|
||||||
plugin.getLogger().info(teamIsland.getMembers().toString());
|
plugin.getLogger().info(teamIsland.getMemberSet().toString());
|
||||||
}
|
}
|
||||||
// Save the database
|
// Save the database
|
||||||
save(false);
|
save(false);
|
||||||
|
@ -37,18 +37,6 @@ public class Island implements DataObject {
|
|||||||
|
|
||||||
private String uniqueId = "";
|
private String uniqueId = "";
|
||||||
|
|
||||||
public String getUniqueId() {
|
|
||||||
// Island's have UUID's that are randomly assigned if they do not exist
|
|
||||||
if (uniqueId.isEmpty()) {
|
|
||||||
uniqueId = UUID.randomUUID().toString();
|
|
||||||
}
|
|
||||||
return uniqueId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUniqueId(String uniqueId) {
|
|
||||||
this.uniqueId = uniqueId;
|
|
||||||
}
|
|
||||||
|
|
||||||
//// Island ////
|
//// Island ////
|
||||||
// The center of the island itself
|
// The center of the island itself
|
||||||
private Location center;
|
private Location center;
|
||||||
@ -77,25 +65,25 @@ public class Island implements DataObject {
|
|||||||
|
|
||||||
// Time parameters
|
// Time parameters
|
||||||
private long createdDate;
|
private long createdDate;
|
||||||
|
|
||||||
private long updatedDate;
|
private long updatedDate;
|
||||||
|
|
||||||
//// Team ////
|
//// Team ////
|
||||||
private UUID owner;
|
private UUID owner;
|
||||||
private HashMap<UUID, Integer> members = new HashMap<>();
|
private HashMap<UUID, Integer> members = new HashMap<>();
|
||||||
|
|
||||||
//// State ////
|
//// State ////
|
||||||
private boolean locked = false;
|
private boolean locked = false;
|
||||||
private boolean spawn = false;
|
private boolean spawn = false;
|
||||||
|
|
||||||
private boolean purgeProtected = false;
|
private boolean purgeProtected = false;
|
||||||
//// Protection ////
|
//// Protection ////
|
||||||
private HashMap<Flag, Integer> flags = new HashMap<>();
|
private HashMap<Flag, Integer> flags = new HashMap<>();
|
||||||
|
|
||||||
private int levelHandicap;
|
private int levelHandicap;
|
||||||
|
|
||||||
private Location spawnPoint;
|
private Location spawnPoint;
|
||||||
|
|
||||||
public Island() {}
|
public Island() {}
|
||||||
|
|
||||||
public Island(Location location, UUID owner, int protectionRange) {
|
public Island(Location location, UUID owner, int protectionRange) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.members.put(owner, RanksManager.OWNER_RANK);
|
this.members.put(owner, RanksManager.OWNER_RANK);
|
||||||
@ -118,7 +106,7 @@ public class Island implements DataObject {
|
|||||||
public void addMember(UUID playerUUID) {
|
public void addMember(UUID playerUUID) {
|
||||||
members.put(playerUUID, RanksManager.MEMBER_RANK);
|
members.put(playerUUID, RanksManager.MEMBER_RANK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds target to a list of banned players for this island. May be blocked by the event being cancelled.
|
* 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.
|
* If the player is a member, coop or trustee, they will be removed from those lists.
|
||||||
@ -179,10 +167,31 @@ public class Island implements DataObject {
|
|||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the levelHandicap
|
||||||
|
*/
|
||||||
|
public int getLevelHandicap() {
|
||||||
|
return levelHandicap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the island is locked, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean getLocked(){
|
||||||
|
return locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the members
|
||||||
|
*/
|
||||||
|
public HashMap<UUID, Integer> getMembers() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the members of the island (owner included)
|
* @return the members of the island (owner included)
|
||||||
*/
|
*/
|
||||||
public Set<UUID> getMembers(){
|
public Set<UUID> getMemberSet(){
|
||||||
Set<UUID> result = new HashSet<>();
|
Set<UUID> result = new HashSet<>();
|
||||||
for (Entry<UUID, Integer> member: members.entrySet()) {
|
for (Entry<UUID, Integer> member: members.entrySet()) {
|
||||||
if (member.getValue() >= RanksManager.MEMBER_RANK) {
|
if (member.getValue() >= RanksManager.MEMBER_RANK) {
|
||||||
@ -249,6 +258,13 @@ public class Island implements DataObject {
|
|||||||
return protectionRange;
|
return protectionRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the island is protected from the Purge, otherwise false
|
||||||
|
*/
|
||||||
|
public boolean getPurgeProtected(){
|
||||||
|
return purgeProtected;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the island range
|
* @return the island range
|
||||||
*/
|
*/
|
||||||
@ -256,6 +272,85 @@ public class Island implements DataObject {
|
|||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the rank of user for this island
|
||||||
|
* @param user
|
||||||
|
* @return rank integer
|
||||||
|
*/
|
||||||
|
public int getRank(User user) {
|
||||||
|
return members.containsKey(user.getUniqueId()) ? members.get(user.getUniqueId()) : RanksManager.VISITOR_RANK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the ranks
|
||||||
|
*/
|
||||||
|
public HashMap<UUID, Integer> getRanks() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the island is the spawn otherwise false
|
||||||
|
*/
|
||||||
|
public boolean getSpawn(){
|
||||||
|
return spawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getSpawnPoint() {
|
||||||
|
return spawnPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param material
|
||||||
|
* @return count of how many tile entities of type mat are on the island at last count. Counts are done when a player places
|
||||||
|
* a tile entity.
|
||||||
|
*/
|
||||||
|
public int getTileEntityCount(Material material, World world) {
|
||||||
|
int result = 0;
|
||||||
|
for (int x = getMinProtectedX() /16; x <= (getMinProtectedX() + getProtectionRange() - 1)/16; x++) {
|
||||||
|
for (int z = getMinProtectedZ() /16; z <= (getMinProtectedZ() + getProtectionRange() - 1)/16; z++) {
|
||||||
|
for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) {
|
||||||
|
//plugin.getLogger().info("DEBUG: tile entity: " + holder.getType());
|
||||||
|
if (onIsland(holder.getLocation())) {
|
||||||
|
if (holder.getType() == material) {
|
||||||
|
result++;
|
||||||
|
} else if (material.equals(Material.REDSTONE_COMPARATOR_OFF)) {
|
||||||
|
if (holder.getType().equals(Material.REDSTONE_COMPARATOR_ON)) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
} else if (material.equals(Material.FURNACE)) {
|
||||||
|
if (holder.getType().equals(Material.BURNING_FURNACE)) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
} else if (material.toString().endsWith("BANNER")) {
|
||||||
|
if (holder.getType().toString().endsWith("BANNER")) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
} else if (material.equals(Material.WALL_SIGN) || material.equals(Material.SIGN_POST)) {
|
||||||
|
if (holder.getType().equals(Material.WALL_SIGN) || holder.getType().equals(Material.SIGN_POST)) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Entity holder : world.getChunkAt(x, z).getEntities()) {
|
||||||
|
//plugin.getLogger().info("DEBUG: entity: " + holder.getType());
|
||||||
|
if (holder.getType().toString().equals(material.toString()) && onIsland(holder.getLocation())) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUniqueId() {
|
||||||
|
// Island's have UUID's that are randomly assigned if they do not exist
|
||||||
|
if (uniqueId.isEmpty()) {
|
||||||
|
uniqueId = UUID.randomUUID().toString();
|
||||||
|
}
|
||||||
|
return uniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the date when the island was updated (team member connection, etc...)
|
* @return the date when the island was updated (team member connection, etc...)
|
||||||
*/
|
*/
|
||||||
@ -302,6 +397,33 @@ public class Island implements DataObject {
|
|||||||
return (x >= minX && x < minX + range*2 && z >= minZ && z < minZ + range*2) ? true: false;
|
return (x >= minX && x < minX + range*2 && z >= minZ && z < minZ + range*2) ? true: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean inIslandSpace(Location location) {
|
||||||
|
if (Util.inWorld(location)) {
|
||||||
|
return inIslandSpace(location.getBlockX(), location.getBlockZ());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the flag is allowed or not
|
||||||
|
* For flags that are for the island in general and not related to rank
|
||||||
|
* @param flag
|
||||||
|
* @return true if allowed, false if not
|
||||||
|
*/
|
||||||
|
public boolean isAllowed(Flag flag) {
|
||||||
|
return this.getFlag(flag) >= 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user is allowed to bypass the flag or not
|
||||||
|
* @param user - user
|
||||||
|
* @param flag - flag
|
||||||
|
* @return true if allowed, false if not
|
||||||
|
*/
|
||||||
|
public boolean isAllowed(User user, Flag flag) {
|
||||||
|
return (this.getRank(user) >= this.getFlag(flag)) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if banned
|
* Check if banned
|
||||||
* @param targetUUID
|
* @param targetUUID
|
||||||
@ -312,23 +434,16 @@ public class Island implements DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the island is locked, otherwise false
|
* @return true if island is locked, false if not
|
||||||
*/
|
*/
|
||||||
public boolean getLocked(){
|
public boolean isLocked() {
|
||||||
return locked;
|
return locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the island is protected from the Purge, otherwise false
|
* @return spawn
|
||||||
*/
|
*/
|
||||||
public boolean getPurgeProtected(){
|
public boolean isSpawn() {
|
||||||
return purgeProtected;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if the island is the spawn otherwise false
|
|
||||||
*/
|
|
||||||
public boolean getSpawn(){
|
|
||||||
return spawn;
|
return spawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,6 +475,10 @@ public class Island implements DataObject {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeMember(UUID playerUUID) {
|
||||||
|
members.remove(playerUUID);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param center the center to set
|
* @param center the center to set
|
||||||
*/
|
*/
|
||||||
@ -399,6 +518,13 @@ public class Island implements DataObject {
|
|||||||
}*/ //TODO default flags
|
}*/ //TODO default flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param levelHandicap the levelHandicap to set
|
||||||
|
*/
|
||||||
|
public void setLevelHandicap(int levelHandicap) {
|
||||||
|
this.levelHandicap = levelHandicap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks/Unlocks the island. May be cancelled by
|
* Locks/Unlocks the island. May be cancelled by
|
||||||
* {@link IslandLockEvent} or {@link IslandUnlockEvent}.
|
* {@link IslandLockEvent} or {@link IslandUnlockEvent}.
|
||||||
@ -420,6 +546,13 @@ public class Island implements DataObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param members the members to set
|
||||||
|
*/
|
||||||
|
public void setMembers(HashMap<UUID, Integer> members) {
|
||||||
|
this.members = members;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param minProtectedX the minProtectedX to set
|
* @param minProtectedX the minProtectedX to set
|
||||||
*/
|
*/
|
||||||
@ -492,13 +625,29 @@ public class Island implements DataObject {
|
|||||||
this.range = range;
|
this.range = range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set user's rank to an arbitrary rank value
|
||||||
|
* @param user
|
||||||
|
* @param rank
|
||||||
|
*/
|
||||||
|
public void setRank(User user, int rank) {
|
||||||
|
members.put(user.getUniqueId(), rank);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ranks the ranks to set
|
||||||
|
*/
|
||||||
|
public void setRanks(HashMap<UUID, Integer> ranks) {
|
||||||
|
this.members = ranks;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param isSpawn - if the island is the spawn
|
* @param isSpawn - if the island is the spawn
|
||||||
*/
|
*/
|
||||||
public void setSpawn(boolean isSpawn){
|
public void setSpawn(boolean isSpawn){
|
||||||
this.spawn = isSpawn;
|
this.spawn = isSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the flags to their default as set in config.yml for the spawn
|
* Resets the flags to their default as set in config.yml for the spawn
|
||||||
*/
|
*/
|
||||||
@ -508,6 +657,15 @@ public class Island implements DataObject {
|
|||||||
}*/ //TODO default flags
|
}*/ //TODO default flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSpawnPoint(Location location) {
|
||||||
|
spawnPoint = location;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUniqueId(String uniqueId) {
|
||||||
|
this.uniqueId = uniqueId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param updatedDate - the updatedDate to sets
|
* @param updatedDate - the updatedDate to sets
|
||||||
*/
|
*/
|
||||||
@ -521,148 +679,4 @@ public class Island implements DataObject {
|
|||||||
public void setWorld(World world) {
|
public void setWorld(World world) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the levelHandicap
|
|
||||||
*/
|
|
||||||
public int getLevelHandicap() {
|
|
||||||
return levelHandicap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param levelHandicap the levelHandicap to set
|
|
||||||
*/
|
|
||||||
public void setLevelHandicap(int levelHandicap) {
|
|
||||||
this.levelHandicap = levelHandicap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if island is locked, false if not
|
|
||||||
*/
|
|
||||||
public boolean isLocked() {
|
|
||||||
return locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return spawn
|
|
||||||
*/
|
|
||||||
public boolean isSpawn() {
|
|
||||||
return spawn;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param material
|
|
||||||
* @return count of how many tile entities of type mat are on the island at last count. Counts are done when a player places
|
|
||||||
* a tile entity.
|
|
||||||
*/
|
|
||||||
public int getTileEntityCount(Material material, World world) {
|
|
||||||
int result = 0;
|
|
||||||
for (int x = getMinProtectedX() /16; x <= (getMinProtectedX() + getProtectionRange() - 1)/16; x++) {
|
|
||||||
for (int z = getMinProtectedZ() /16; z <= (getMinProtectedZ() + getProtectionRange() - 1)/16; z++) {
|
|
||||||
for (BlockState holder : world.getChunkAt(x, z).getTileEntities()) {
|
|
||||||
//plugin.getLogger().info("DEBUG: tile entity: " + holder.getType());
|
|
||||||
if (onIsland(holder.getLocation())) {
|
|
||||||
if (holder.getType() == material) {
|
|
||||||
result++;
|
|
||||||
} else if (material.equals(Material.REDSTONE_COMPARATOR_OFF)) {
|
|
||||||
if (holder.getType().equals(Material.REDSTONE_COMPARATOR_ON)) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
} else if (material.equals(Material.FURNACE)) {
|
|
||||||
if (holder.getType().equals(Material.BURNING_FURNACE)) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
} else if (material.toString().endsWith("BANNER")) {
|
|
||||||
if (holder.getType().toString().endsWith("BANNER")) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
} else if (material.equals(Material.WALL_SIGN) || material.equals(Material.SIGN_POST)) {
|
|
||||||
if (holder.getType().equals(Material.WALL_SIGN) || holder.getType().equals(Material.SIGN_POST)) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Entity holder : world.getChunkAt(x, z).getEntities()) {
|
|
||||||
//plugin.getLogger().info("DEBUG: entity: " + holder.getType());
|
|
||||||
if (holder.getType().toString().equals(material.toString()) && onIsland(holder.getLocation())) {
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean inIslandSpace(Location location) {
|
|
||||||
if (Util.inWorld(location)) {
|
|
||||||
return inIslandSpace(location.getBlockX(), location.getBlockZ());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpawnPoint(Location location) {
|
|
||||||
spawnPoint = location;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getSpawnPoint() {
|
|
||||||
return spawnPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeMember(UUID playerUUID) {
|
|
||||||
members.remove(playerUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the rank of user for this island
|
|
||||||
* @param user
|
|
||||||
* @return rank integer
|
|
||||||
*/
|
|
||||||
public int getRank(User user) {
|
|
||||||
return members.containsKey(user.getUniqueId()) ? members.get(user.getUniqueId()) : RanksManager.VISITOR_RANK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set user's rank to an arbitrary rank value
|
|
||||||
* @param user
|
|
||||||
* @param rank
|
|
||||||
*/
|
|
||||||
public void setRank(User user, int rank) {
|
|
||||||
members.put(user.getUniqueId(), rank);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the ranks
|
|
||||||
*/
|
|
||||||
public HashMap<UUID, Integer> getRanks() {
|
|
||||||
return members;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ranks the ranks to set
|
|
||||||
*/
|
|
||||||
public void setRanks(HashMap<UUID, Integer> ranks) {
|
|
||||||
this.members = ranks;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a user is allowed to bypass the flag or not
|
|
||||||
* @param user - user
|
|
||||||
* @param flag - flag
|
|
||||||
* @return true if allowed, false if not
|
|
||||||
*/
|
|
||||||
public boolean isAllowed(User user, Flag flag) {
|
|
||||||
return (this.getRank(user) >= this.getFlag(flag)) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the flag is allowed or not
|
|
||||||
* For flags that are for the island in general and not related to rank
|
|
||||||
* @param flag
|
|
||||||
* @return true if allowed, false if not
|
|
||||||
*/
|
|
||||||
public boolean isAllowed(Flag flag) {
|
|
||||||
return this.getFlag(flag) >= 0 ? true : false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -71,7 +71,7 @@ public class JoinLeaveListener implements Listener {
|
|||||||
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) {
|
if (currentIsland != null && (currentIsland.isLocked() || plugin.getPlayers().isBanned(currentIsland.getOwner(),user.getUniqueId()))) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
|
plugin.getLogger().info("DEBUG: Current island is locked, or player is banned");
|
||||||
if (!currentIsland.getMembers().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
|
if (!currentIsland.getMemberSet().contains(playerUUID) && !user.hasPermission(Constants.PERMPREFIX + "mod.bypassprotect")) {
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
||||||
user.sendMessage("locked.islandlocked");
|
user.sendMessage("locked.islandlocked");
|
||||||
|
@ -22,7 +22,6 @@ import us.tastybento.bskyblock.listeners.flags.ShearingListener;
|
|||||||
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
||||||
|
|
||||||
public class Flags {
|
public class Flags {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Protection Flags
|
* Protection Flags
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +19,7 @@ public class FlagsManager {
|
|||||||
|
|
||||||
public void registerFlag(Flag flag) {
|
public void registerFlag(Flag flag) {
|
||||||
//TODO all the security checks
|
//TODO all the security checks
|
||||||
|
plugin.getLogger().info("DEBUG: registering flag " + flag.getID());
|
||||||
flags.add(flag);
|
flags.add(flag);
|
||||||
// If there is a listener, register it into Bukkit.
|
// If there is a listener, register it into Bukkit.
|
||||||
flag.getListener().ifPresent(l -> plugin.getServer().getPluginManager().registerEvents(l, plugin));
|
flag.getListener().ifPresent(l -> plugin.getServer().getPluginManager().registerEvents(l, plugin));
|
||||||
|
@ -312,7 +312,7 @@ public class TestBSkyBlock {
|
|||||||
island.addMember(member2);
|
island.addMember(member2);
|
||||||
island.addMember(member3);
|
island.addMember(member3);
|
||||||
|
|
||||||
Set<UUID> members = island.getMembers();
|
Set<UUID> members = island.getMemberSet();
|
||||||
assertTrue(members.contains(playerUUID));
|
assertTrue(members.contains(playerUUID));
|
||||||
assertTrue(members.contains(member1));
|
assertTrue(members.contains(member1));
|
||||||
assertTrue(members.contains(member2));
|
assertTrue(members.contains(member2));
|
||||||
@ -320,7 +320,7 @@ public class TestBSkyBlock {
|
|||||||
|
|
||||||
// Remove members
|
// Remove members
|
||||||
island.removeMember(member3);
|
island.removeMember(member3);
|
||||||
members = island.getMembers();
|
members = island.getMemberSet();
|
||||||
assertTrue(members.contains(playerUUID));
|
assertTrue(members.contains(playerUUID));
|
||||||
assertTrue(members.contains(member1));
|
assertTrue(members.contains(member1));
|
||||||
assertTrue(members.contains(member2));
|
assertTrue(members.contains(member2));
|
||||||
@ -328,7 +328,7 @@ public class TestBSkyBlock {
|
|||||||
|
|
||||||
// Ban member
|
// Ban member
|
||||||
island.addToBanList(member1);
|
island.addToBanList(member1);
|
||||||
members = island.getMembers();
|
members = island.getMemberSet();
|
||||||
assertTrue(members.contains(playerUUID));
|
assertTrue(members.contains(playerUUID));
|
||||||
assertFalse(members.contains(member1));
|
assertFalse(members.contains(member1));
|
||||||
assertTrue(members.contains(member2));
|
assertTrue(members.contains(member2));
|
||||||
|
Loading…
Reference in New Issue
Block a user