Added default island flags and settings to config.yml

These are specified per-world so go in the world section.
This commit is contained in:
tastybento 2018-07-05 21:10:47 -07:00
parent 2b5664c7ff
commit a72a49975f
7 changed files with 171 additions and 29 deletions

View File

@ -70,6 +70,9 @@ public class BSkyBlock extends JavaPlugin {
saveDefaultConfig();
setInstance(this);
// Load Flags
flagsManager = new FlagsManager(instance);
// Load settings from config.yml. This will check if there are any issues with it too.
settings = new BSBConfig<>(this, Settings.class).loadConfigObject("");
// Start Database managers
@ -120,9 +123,6 @@ public class BSkyBlock extends JavaPlugin {
addonsManager.enableAddons();
getServer().getScheduler().runTask(instance, () -> {
// Load Flags
flagsManager = new FlagsManager(instance);
// Register Listeners
registerListeners();

View File

@ -21,6 +21,9 @@ import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.database.BSBDbSetup.DatabaseType;
import us.tastybento.bskyblock.database.objects.DataObject;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.FlagSerializer;
import us.tastybento.bskyblock.database.objects.adapters.FlagSerializer2;
/**
* All the plugin settings are here
@ -246,6 +249,22 @@ public class Settings implements DataObject, WorldSettings {
@ConfigEntry(path = "world.flags")
private Map<String, Boolean> worldFlags = new HashMap<>();
@ConfigComment("These are the default protection settings for new islands.")
@ConfigComment("The value is the minimum island rank required allowed to do the action")
@ConfigComment("Ranks are: Visitor = 0, Member = 900, Owner = 1000")
@ConfigEntry(path = "world.default-island-flags")
@Adapter(FlagSerializer.class)
private Map<Flag, Integer> defaultIslandFlags = new HashMap<>();
@ConfigComment("These are the default settings for new islands")
@ConfigEntry(path = "world.default-island-settings")
@Adapter(FlagSerializer2.class)
private Map<Flag, Integer> defaultIslandSettings = new HashMap<>();
@ConfigComment("These are the settings visible to users.")
@ConfigEntry(path = "world.visible-settings")
private List<String> visibleSettings = new ArrayList<>();
// ---------------------------------------------
/* ISLAND */
@ -377,8 +396,6 @@ public class Settings implements DataObject, WorldSettings {
private int togglePvPCooldown;
private Map<Flag, Boolean> defaultFlags = new HashMap<>();
//TODO transform these options below into flags
private boolean allowEndermanGriefing;
private boolean endermanDeathDrop;
@ -394,8 +411,6 @@ public class Settings implements DataObject, WorldSettings {
@ConfigEntry(path = "protection.invincible-visitors")
private List<String> ivSettings = new ArrayList<>();
//TODO flags
// ---------------------------------------------
@ -567,12 +582,6 @@ public class Settings implements DataObject, WorldSettings {
public int getDeathsMax() {
return deathsMax;
}
/**
* @return the defaultFlags
*/
public Map<Flag, Boolean> getDefaultFlags() {
return defaultFlags;
}
/**
* @return the defaultLanguage
*/
@ -1069,12 +1078,6 @@ public class Settings implements DataObject, WorldSettings {
public void setDeathsSumTeam(boolean deathsSumTeam) {
this.deathsSumTeam = deathsSumTeam;
}
/**
* @param defaultFlags the defaultFlags to set
*/
public void setDefaultFlags(Map<Flag, Boolean> defaultFlags) {
this.defaultFlags = defaultFlags;
}
/**
* @param defaultLanguage the defaultLanguage to set
*/
@ -1570,6 +1573,44 @@ public class Settings implements DataObject, WorldSettings {
// This is a plugin, not an addon
return Optional.empty();
}
/**
* @return the defaultIslandProtection
*/
@Override
public Map<Flag, Integer> getDefaultIslandFlags() {
return defaultIslandFlags;
}
/**
* @return the visibleSettings
*/
@Override
public List<String> getVisibleSettings() {
return visibleSettings;
}
/**
*/
public void setDefaultIslandFlags(Map<Flag, Integer> defaultIslandFlags) {
this.defaultIslandFlags = defaultIslandFlags;
}
/**
* @param visibleSettings the visibleSettings to set
*/
public void setVisibleSettings(List<String> visibleSettings) {
this.visibleSettings = visibleSettings;
}
/**
* @return the defaultIslandSettings
*/
@Override
public Map<Flag, Integer> getDefaultIslandSettings() {
return defaultIslandSettings;
}
/**
* @param defaultIslandSettings the defaultIslandSettings to set
*/
public void setDefaultIslandSettings(Map<Flag, Integer> defaultIslandSettings) {
this.defaultIslandSettings = defaultIslandSettings;
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.GameMode;
import org.bukkit.entity.EntityType;
import us.tastybento.bskyblock.api.addons.Addon;
import us.tastybento.bskyblock.api.flags.Flag;
/**
* Contains world-specific settings. Only getters are required, but you may need setters for your own class.
@ -158,36 +159,49 @@ public interface WorldSettings {
/**
* @return the onJoinResetMoney
*/
public boolean isOnJoinResetMoney();
boolean isOnJoinResetMoney();
/**
* @return the onJoinResetInventory
*/
public boolean isOnJoinResetInventory();
boolean isOnJoinResetInventory();
/**
* @return the onJoinResetEnderChest
*/
public boolean isOnJoinResetEnderChest();
boolean isOnJoinResetEnderChest();
/**
* @return the onLeaveResetMoney
*/
public boolean isOnLeaveResetMoney();
boolean isOnLeaveResetMoney();
/**
* @return the onLeaveResetInventory
*/
public boolean isOnLeaveResetInventory();
boolean isOnLeaveResetInventory();
/**
* @return the onLeaveResetEnderChest
*/
public boolean isOnLeaveResetEnderChest();
boolean isOnLeaveResetEnderChest();
/**
* @return the Addon that registered this world
*/
public Optional<Addon> getAddon();
Optional<Addon> getAddon();
/**
* @return default rank settings for new islands
*/
Map<Flag, Integer> getDefaultIslandFlags();
/**
* @return visible settings for player
*/
List<String> getVisibleSettings();
Map<Flag, Integer> getDefaultIslandSettings();
}

View File

@ -25,6 +25,7 @@ import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.database.objects.adapters.Adapter;
import us.tastybento.bskyblock.database.objects.adapters.FlagSerializer;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.managers.RanksManager;
import us.tastybento.bskyblock.util.Pair;
import us.tastybento.bskyblock.util.Util;
@ -490,10 +491,16 @@ public class Island implements DataObject {
}
/**
* Resets the flags to their default as set in config.yml for this island
* Resets the flags to their default as set in config.yml for this island.
* If flags are missing from the config, the default hard-coded value is used and set
*/
public void setFlagsDefaults(){
//TODO default flags
public void setFlagsDefaults() {
Map<Flag, Integer> result = new HashMap<>();
Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.PROTECTION))
.forEach(f -> result.put(f, BSkyBlock.getInstance().getIWM().getDefaultIslandFlags(world).getOrDefault(f, f.getDefaultRank())));
Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.SETTING))
.forEach(f -> result.put(f, BSkyBlock.getInstance().getIWM().getDefaultIslandSettings(world).getOrDefault(f, f.getDefaultRank())));
this.setFlags(result);
}
/**

View File

@ -0,0 +1,52 @@
package us.tastybento.bskyblock.database.objects.adapters;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.MemorySection;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.flags.Flag;
/**
* @author tastybento
*
*/
public class FlagSerializer2 implements AdapterInterface<Map<Flag, Integer>, Map<String, Boolean>> {
@SuppressWarnings("unchecked")
@Override
public Map<Flag, Integer> deserialize(Object object) {
Map<Flag, Integer> result = new HashMap<>();
if (object == null) {
return result;
}
// For YAML
if (object instanceof MemorySection) {
MemorySection section = (MemorySection) object;
for (String key : section.getKeys(false)) {
result.put(BSkyBlock.getInstance().getFlagsManager().getFlagByID(key), section.getBoolean(key) ? 0 : -1);
}
} else {
for (Entry<String, Boolean> en : ((Map<String, Boolean>)object).entrySet()) {
result.put(BSkyBlock.getInstance().getFlagsManager().getFlagByID(en.getKey()), en.getValue() ? 0 : -1);
}
}
return result;
}
@SuppressWarnings("unchecked")
@Override
public Map<String, Boolean> serialize(Object object) {
Map<String, Boolean> result = new HashMap<>();
if (object == null) {
return result;
}
Map<Flag, Integer> flags = (Map<Flag, Integer>)object;
for (Entry<Flag, Integer> en: flags.entrySet()) {
result.put(en.getKey().getID(), en.getValue() < 0 ? false : true);
}
return result;
}
}

View File

@ -23,6 +23,7 @@ import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.flags.Flag;
import us.tastybento.bskyblock.api.user.User;
import us.tastybento.bskyblock.generators.ChunkGeneratorWorld;
import us.tastybento.bskyblock.lists.Flags;
import us.tastybento.bskyblock.util.Util;
/**
@ -186,6 +187,9 @@ public class IslandWorldManager {
worlds.put(world, friendlyName);
worldSettings.put(world, settings);
multiverseReg(world);
// Set default island settings
Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.PROTECTION)).forEach(f -> settings.getDefaultIslandFlags().putIfAbsent(f, f.getDefaultRank()));
Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.SETTING)).forEach(f -> settings.getDefaultIslandSettings().putIfAbsent(f, f.getDefaultRank()));
}
/**
@ -558,4 +562,25 @@ public class IslandWorldManager {
return worldSettings.get(Util.getWorld(world)).getAddon();
}
/**
* Get default island flag settings for this world.
* @param world - world
* @return default rank settings for new islands.
*/
public Map<Flag, Integer> getDefaultIslandFlags(World world) {
return worldSettings.get(Util.getWorld(world)).getDefaultIslandFlags();
}
public List<String> getVisibleSettings(World world) {
return worldSettings.get(Util.getWorld(world)).getVisibleSettings();
}
/**
* Return island setting defaults for world
* @param world - world
* @return default settings for new islands
*/
public Map<Flag, Integer> getDefaultIslandSettings(World world) {
return worldSettings.get(Util.getWorld(world)).getDefaultIslandSettings();
}
}

View File

@ -154,6 +154,9 @@ public class NewIsland {
plugin.getSchemsManager().paste(plugin.getIWM().getEndWorld(world), island);
}
// Set default settings
island.setFlagsDefaults();
// Fire exit event
Reason reasonDone = Reason.CREATED;
switch (reason) {