Added a gameMode field to islands for convenience usage

#631
This commit is contained in:
Florian CUNY 2019-04-13 14:44:31 +02:00
parent 9386e8aa71
commit 141e1d388d
2 changed files with 32 additions and 1 deletions

View File

@ -77,6 +77,13 @@ public class Island implements DataObject {
@Expose
private World world;
/**
* Name of the {@link world.bentobox.bentobox.api.addons.GameModeAddon GameModeAddon} this island is handled by.
* @since 1.5.0
*/
@Expose
private String gameMode;
// Display name
@Expose
@Nullable
@ -915,4 +922,22 @@ public class Island implements DataObject {
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
/**
* Returns the name of the {@link world.bentobox.bentobox.api.addons.GameModeAddon GameModeAddon} this island is handled by.
* @return the name of the {@link world.bentobox.bentobox.api.addons.GameModeAddon GameModeAddon} this island is handled by.
* @since 1.5.0
*/
public String getGameMode() {
return gameMode;
}
/**
* Sets the name of the {@link world.bentobox.bentobox.api.addons.GameModeAddon GameModeAddon} this island is handled by.
* Note this has no effect over the actual location of the island, however this may cause issues with addons using this data.
* @since 1.5.0
*/
public void setGameMode(String gameMode) {
this.gameMode = gameMode;
}
}

View File

@ -254,6 +254,7 @@ public class IslandsManager {
Island island = new Island(location, owner, plugin.getIWM().getIslandProtectionRange(location.getWorld()));
// Game the gamemode name and prefix the uniqueId
String gmName = plugin.getIWM().getAddon(location.getWorld()).map(gm -> gm.getDescription().getName()).orElse("");
island.setGameMode(gmName);
island.setUniqueId(gmName + island.getUniqueId());
while (handler.objectExists(island.getUniqueId())) {
// This should never happen, so although this is a potential infinite loop I'm going to leave it here because
@ -406,7 +407,7 @@ public class IslandsManager {
/**
* Returns a set of island member UUID's for the island of playerUUID.
* Only includes players of rank {@link RanksManager.MEMBER_RANK} and above.
* Only includes players of rank {@link RanksManager#MEMBER_RANK} and above.
* This includes the owner of the island. If there is no island, this set will be empty.
*
* @param world - world to check
@ -764,6 +765,11 @@ public class IslandsManager {
this.setSpawn(island);
}
}
// Update some of their fields
if (island.getGameMode() == null) {
island.setGameMode(plugin.getIWM().getAddon(island.getWorld()).map(gm -> gm.getDescription().getName()).orElse(""));
}
});
if (!toQuarantine.isEmpty()) {
plugin.logError(toQuarantine.size() + " islands could not be loaded successfully; moving to trash bin.");