mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-29 06:05:13 +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.listeners.JoinLeaveListener;
|
||||
import us.tastybento.bskyblock.listeners.PanelListenerManager;
|
||||
import us.tastybento.bskyblock.lists.Flags;
|
||||
import us.tastybento.bskyblock.managers.AddonsManager;
|
||||
import us.tastybento.bskyblock.managers.CommandsManager;
|
||||
import us.tastybento.bskyblock.managers.FlagsManager;
|
||||
@ -99,6 +100,7 @@ public class BSkyBlock extends JavaPlugin {
|
||||
|
||||
// Load Flags
|
||||
flagsManager = new FlagsManager(plugin);
|
||||
new Flags();
|
||||
|
||||
// Load addons
|
||||
addonsManager = new AddonsManager(plugin);
|
||||
|
@ -30,7 +30,7 @@ public class Flag {
|
||||
}
|
||||
|
||||
public Optional<Listener> getListener() {
|
||||
return Optional.of(listener);
|
||||
return Optional.ofNullable(listener);
|
||||
}
|
||||
|
||||
public boolean isAllowed() {
|
||||
|
@ -101,7 +101,7 @@ public class IslandTeamInviteAcceptCommand extends AbstractIslandTeamCommand {
|
||||
}
|
||||
getIslands().save(false);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,8 @@ public class IslandCache {
|
||||
plugin.getLogger().info("DEBUG: owner = " + island.getOwner());
|
||||
islandsByUUID.put(island.getOwner(), island);
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: island has " + island.getMembers().size() + " members");
|
||||
for (UUID member: island.getMembers()) {
|
||||
plugin.getLogger().info("DEBUG: island has " + island.getMemberSet().size() + " members");
|
||||
for (UUID member: island.getMemberSet()) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: " + member);
|
||||
islandsByUUID.put(member, island);
|
||||
@ -288,7 +288,7 @@ public class IslandCache {
|
||||
public Set<UUID> getMembers(UUID playerUUID) {
|
||||
Island island = islandsByUUID.get(playerUUID);
|
||||
if (island != null)
|
||||
return new HashSet<UUID>(island.getMembers());
|
||||
return new HashSet<UUID>(island.getMemberSet());
|
||||
return new HashSet<UUID>(0);
|
||||
}
|
||||
|
||||
@ -336,10 +336,10 @@ public class IslandCache {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: player is the owner of this island");
|
||||
// Clear ownership and members
|
||||
island.getMembers().clear();
|
||||
island.getMemberSet().clear();
|
||||
island.setOwner(null);
|
||||
}
|
||||
island.getMembers().remove(playerUUID);
|
||||
island.getMemberSet().remove(playerUUID);
|
||||
}
|
||||
if (DEBUG)
|
||||
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: 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");
|
||||
// In a protected zone but is on the list of acceptable players
|
||||
return true;
|
||||
@ -972,7 +972,7 @@ public class IslandsManager {
|
||||
islandCache.addPlayer(playerUUID, teamIsland);
|
||||
if (DEBUG) {
|
||||
plugin.getLogger().info("DEBUG: new team member list:");
|
||||
plugin.getLogger().info(teamIsland.getMembers().toString());
|
||||
plugin.getLogger().info(teamIsland.getMemberSet().toString());
|
||||
}
|
||||
// Save the database
|
||||
save(false);
|
||||
|
@ -37,18 +37,6 @@ public class Island implements DataObject {
|
||||
|
||||
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 ////
|
||||
// The center of the island itself
|
||||
private Location center;
|
||||
@ -77,6 +65,7 @@ public class Island implements DataObject {
|
||||
|
||||
// Time parameters
|
||||
private long createdDate;
|
||||
|
||||
private long updatedDate;
|
||||
|
||||
//// Team ////
|
||||
@ -86,12 +75,11 @@ public class Island implements DataObject {
|
||||
//// State ////
|
||||
private boolean locked = false;
|
||||
private boolean spawn = false;
|
||||
|
||||
private boolean purgeProtected = false;
|
||||
//// Protection ////
|
||||
private HashMap<Flag, Integer> flags = new HashMap<>();
|
||||
|
||||
private int levelHandicap;
|
||||
|
||||
private Location spawnPoint;
|
||||
|
||||
public Island() {}
|
||||
@ -179,10 +167,31 @@ public class Island implements DataObject {
|
||||
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)
|
||||
*/
|
||||
public Set<UUID> getMembers(){
|
||||
public Set<UUID> getMemberSet(){
|
||||
Set<UUID> result = new HashSet<>();
|
||||
for (Entry<UUID, Integer> member: members.entrySet()) {
|
||||
if (member.getValue() >= RanksManager.MEMBER_RANK) {
|
||||
@ -249,6 +258,13 @@ public class Island implements DataObject {
|
||||
return protectionRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the island is protected from the Purge, otherwise false
|
||||
*/
|
||||
public boolean getPurgeProtected(){
|
||||
return purgeProtected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the island range
|
||||
*/
|
||||
@ -256,6 +272,85 @@ public class Island implements DataObject {
|
||||
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...)
|
||||
*/
|
||||
@ -302,6 +397,33 @@ public class Island implements DataObject {
|
||||
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
|
||||
* @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 true if the island is protected from the Purge, otherwise false
|
||||
* @return spawn
|
||||
*/
|
||||
public boolean getPurgeProtected(){
|
||||
return purgeProtected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the island is the spawn otherwise false
|
||||
*/
|
||||
public boolean getSpawn(){
|
||||
public boolean isSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
@ -360,6 +475,10 @@ public class Island implements DataObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeMember(UUID playerUUID) {
|
||||
members.remove(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param center the center to set
|
||||
*/
|
||||
@ -399,6 +518,13 @@ public class Island implements DataObject {
|
||||
}*/ //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
|
||||
* {@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
|
||||
*/
|
||||
@ -492,6 +625,22 @@ public class Island implements DataObject {
|
||||
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
|
||||
*/
|
||||
@ -508,6 +657,15 @@ public class Island implements DataObject {
|
||||
}*/ //TODO default flags
|
||||
}
|
||||
|
||||
public void setSpawnPoint(Location location) {
|
||||
spawnPoint = location;
|
||||
|
||||
}
|
||||
|
||||
public void setUniqueId(String uniqueId) {
|
||||
this.uniqueId = uniqueId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param updatedDate - the updatedDate to sets
|
||||
*/
|
||||
@ -521,148 +679,4 @@ public class Island implements DataObject {
|
||||
public void setWorld(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 (DEBUG)
|
||||
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)
|
||||
plugin.getLogger().info("DEBUG: No bypass - teleporting");
|
||||
user.sendMessage("locked.islandlocked");
|
||||
|
@ -22,7 +22,6 @@ import us.tastybento.bskyblock.listeners.flags.ShearingListener;
|
||||
import us.tastybento.bskyblock.listeners.flags.TeleportationListener;
|
||||
|
||||
public class Flags {
|
||||
|
||||
/*
|
||||
* Protection Flags
|
||||
*/
|
||||
|
@ -19,6 +19,7 @@ public class FlagsManager {
|
||||
|
||||
public void registerFlag(Flag flag) {
|
||||
//TODO all the security checks
|
||||
plugin.getLogger().info("DEBUG: registering flag " + flag.getID());
|
||||
flags.add(flag);
|
||||
// If there is a listener, register it into Bukkit.
|
||||
flag.getListener().ifPresent(l -> plugin.getServer().getPluginManager().registerEvents(l, plugin));
|
||||
|
@ -312,7 +312,7 @@ public class TestBSkyBlock {
|
||||
island.addMember(member2);
|
||||
island.addMember(member3);
|
||||
|
||||
Set<UUID> members = island.getMembers();
|
||||
Set<UUID> members = island.getMemberSet();
|
||||
assertTrue(members.contains(playerUUID));
|
||||
assertTrue(members.contains(member1));
|
||||
assertTrue(members.contains(member2));
|
||||
@ -320,7 +320,7 @@ public class TestBSkyBlock {
|
||||
|
||||
// Remove members
|
||||
island.removeMember(member3);
|
||||
members = island.getMembers();
|
||||
members = island.getMemberSet();
|
||||
assertTrue(members.contains(playerUUID));
|
||||
assertTrue(members.contains(member1));
|
||||
assertTrue(members.contains(member2));
|
||||
@ -328,7 +328,7 @@ public class TestBSkyBlock {
|
||||
|
||||
// Ban member
|
||||
island.addToBanList(member1);
|
||||
members = island.getMembers();
|
||||
members = island.getMemberSet();
|
||||
assertTrue(members.contains(playerUUID));
|
||||
assertFalse(members.contains(member1));
|
||||
assertTrue(members.contains(member2));
|
||||
|
Loading…
Reference in New Issue
Block a user