Add Migrator for EnumerationUtil addition.

This commit is contained in:
Olof Larsson 2017-03-24 15:53:20 +01:00
parent 94cffec16c
commit 59fad9b136
4 changed files with 89 additions and 14 deletions

View File

@ -49,6 +49,7 @@ import com.massivecraft.factions.entity.MConfColl;
import com.massivecraft.factions.entity.MFlagColl;
import com.massivecraft.factions.entity.MPermColl;
import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.factions.entity.migrator.MigratorMConf001EnumerationUtil;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.integration.V19.IntegrationV19;
import com.massivecraft.factions.integration.herochat.IntegrationHerochat;
@ -120,6 +121,8 @@ public class Factions extends MassivePlugin
// Initialize Database
this.databaseInitialized = false;
MigratorMConf001EnumerationUtil.get().setActive(true);
MFlagColl.get().setActive(true);
MPermColl.get().setActive(true);
MConfColl.get().setActive(true);

View File

@ -52,6 +52,12 @@ public class MConf extends Entity<MConf>
return this;
}
// -------------------------------------------- //
// VERSION
// -------------------------------------------- //
public int version = 1;
// -------------------------------------------- //
// COMMAND ALIASES
// -------------------------------------------- //

View File

@ -0,0 +1,67 @@
package com.massivecraft.factions.entity.migrator;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.util.EnumerationUtil;
import com.massivecraft.massivecore.store.migration.VersionMigratorRoot;
import com.massivecraft.massivecore.xlib.gson.JsonArray;
import com.massivecraft.massivecore.xlib.gson.JsonElement;
import com.massivecraft.massivecore.xlib.gson.JsonObject;
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
import java.util.Collection;
import java.util.Iterator;
public class MigratorMConf001EnumerationUtil extends VersionMigratorRoot
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MigratorMConf001EnumerationUtil i = new MigratorMConf001EnumerationUtil();
public static MigratorMConf001EnumerationUtil get() { return i; }
private MigratorMConf001EnumerationUtil()
{
super(MConf.class);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void migrateInner(JsonObject entity)
{
removeFromStringsField(entity, "materialsEditOnInteract", EnumerationUtil.MATERIALS_EDIT_ON_INTERACT.getStringSet());
removeFromStringsField(entity, "materialsEditTools", EnumerationUtil.MATERIALS_EDIT_TOOL.getStringSet());
removeFromStringsField(entity, "materialsDoor", EnumerationUtil.MATERIALS_DOOR.getStringSet());
removeFromStringsField(entity, "materialsContainer", EnumerationUtil.MATERIALS_CONTAINER.getStringSet());
removeFromStringsField(entity, "entityTypesEditOnInteract", EnumerationUtil.ENTITY_TYPES_EDIT_ON_INTERACT.getStringSet());
removeFromStringsField(entity, "entityTypesEditOnDamage", EnumerationUtil.ENTITY_TYPES_EDIT_ON_DAMAGE.getStringSet());
removeFromStringsField(entity, "entityTypesContainer", EnumerationUtil.ENTITY_TYPES_CONTAINER.getStringSet());
removeFromStringsField(entity, "entityTypesMonsters", EnumerationUtil.ENTITY_TYPES_MONSTER.getStringSet());
removeFromStringsField(entity, "entityTypesAnimals", EnumerationUtil.ENTITY_TYPES_ANIMAL.getStringSet());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
private void removeFromStringsField(JsonObject entity, String fieldName, Collection<String> removals)
{
JsonElement stringsElement = entity.get(fieldName);
if (!(stringsElement instanceof JsonArray)) return;
JsonArray strings = (JsonArray)stringsElement;
for (Iterator<JsonElement> iterator = strings.iterator(); iterator.hasNext();)
{
JsonElement stringElement = iterator.next();
if (!(stringElement instanceof JsonPrimitive)) continue;
JsonPrimitive string = (JsonPrimitive)stringElement;
if (!removals.contains(string.getAsString())) continue;
iterator.remove();
}
}
}

View File

@ -11,7 +11,7 @@ public class EnumerationUtil
// MATERIAL EDIT ON INTERACT
// -------------------------------------------- //
private static final BackstringSet<Material> MATERIALS_EDIT_ON_INTERACT = new BackstringSet<>(Material.class,
public static final BackstringSet<Material> MATERIALS_EDIT_ON_INTERACT = new BackstringSet<>(Material.class,
"DIODE_BLOCK_OFF", // Minecraft 1.?
"DIODE_BLOCK_ON", // Minecraft 1.?
"NOTE_BLOCK", // Minecraft 1.?
@ -32,7 +32,7 @@ public class EnumerationUtil
// MATERIAL EDIT TOOLS
// -------------------------------------------- //
private static final BackstringSet<Material> MATERIALS_EDIT_TOOLS = new BackstringSet<>(Material.class,
public static final BackstringSet<Material> MATERIALS_EDIT_TOOL = new BackstringSet<>(Material.class,
"FIREBALL", // Minecraft 1.?
"FLINT_AND_STEEL", // Minecraft 1.?
"BUCKET", // Minecraft 1.?
@ -53,7 +53,7 @@ public class EnumerationUtil
public static boolean isMaterialEditTool(Material material)
{
return MATERIALS_EDIT_TOOLS.contains(material) || MConf.get().materialsEditTools.contains(material);
return MATERIALS_EDIT_TOOL.contains(material) || MConf.get().materialsEditTools.contains(material);
}
// -------------------------------------------- //
@ -61,7 +61,7 @@ public class EnumerationUtil
// -------------------------------------------- //
// Interacting with these materials placed in the terrain results in door toggling.
private static final BackstringSet<Material> MATERIALS_DOOR = new BackstringSet<>(Material.class,
public static final BackstringSet<Material> MATERIALS_DOOR = new BackstringSet<>(Material.class,
"WOODEN_DOOR", // Minecraft 1.?
"ACACIA_DOOR", // Minecraft 1.8
"BIRCH_DOOR", // Minecraft 1.8
@ -86,7 +86,7 @@ public class EnumerationUtil
// MATERIAL CONTAINER
// -------------------------------------------- //
private static final BackstringSet<Material> MATERIALS_CONTAINER = new BackstringSet<>(Material.class,
public static final BackstringSet<Material> MATERIALS_CONTAINER = new BackstringSet<>(Material.class,
"DISPENSER", // Minecraft 1.?
"CHEST", // Minecraft 1.?
"FURNACE", // Minecraft 1.?
@ -129,7 +129,7 @@ public class EnumerationUtil
// -------------------------------------------- //
// Interacting with these entities results in an edit.
private static final BackstringSet<EntityType> ENTITY_TYPES_EDIT_ON_INTERACT = new BackstringSet<>(EntityType.class,
public static final BackstringSet<EntityType> ENTITY_TYPES_EDIT_ON_INTERACT = new BackstringSet<>(EntityType.class,
"ITEM_FRAME", // Minecraft 1.?
"ARMOR_STAND" // Minecraft 1.8
);
@ -144,7 +144,7 @@ public class EnumerationUtil
// -------------------------------------------- //
// Damaging these entities results in an edit.
private static final BackstringSet<EntityType> ENTITY_TYPES_EDIT_ON_DAMAGE = new BackstringSet<>(EntityType.class,
public static final BackstringSet<EntityType> ENTITY_TYPES_EDIT_ON_DAMAGE = new BackstringSet<>(EntityType.class,
"ITEM_FRAME", // Minecraft 1.?
"ARMOR_STAND", // Minecraft 1.8
"ENDER_CRYSTAL" // Minecraft 1.10
@ -159,21 +159,21 @@ public class EnumerationUtil
// ENTITY TYPE CONTAINER
// -------------------------------------------- //
private static final BackstringSet<EntityType> ENTITY_TYPE_CONTAINERS = new BackstringSet<>(EntityType.class,
public static final BackstringSet<EntityType> ENTITY_TYPES_CONTAINER = new BackstringSet<>(EntityType.class,
"MINECART_CHEST", // Minecraft 1.?
"MINECART_HOPPER" // Minecraft 1.?
);
public static boolean isEntityTypeContainer(EntityType entityType)
{
return ENTITY_TYPE_CONTAINERS.contains(entityType) || MConf.get().entityTypesContainer.contains(entityType);
return ENTITY_TYPES_CONTAINER.contains(entityType) || MConf.get().entityTypesContainer.contains(entityType);
}
// -------------------------------------------- //
// ENTITY TYPE MONSTER
// -------------------------------------------- //
private static final BackstringSet<EntityType> ENTITY_TYPE_MONSTERS = new BackstringSet<>(EntityType.class,
public static final BackstringSet<EntityType> ENTITY_TYPES_MONSTER = new BackstringSet<>(EntityType.class,
"BLAZE", // Minecraft 1.?
"CAVE_SPIDER", // Minecraft 1.?
"CREEPER", // Minecraft 1.?
@ -206,14 +206,14 @@ public class EnumerationUtil
public static boolean isEntityTypeMonster(EntityType entityType)
{
return ENTITY_TYPE_MONSTERS.contains(entityType) || MConf.get().entityTypesMonsters.contains(entityType);
return ENTITY_TYPES_MONSTER.contains(entityType) || MConf.get().entityTypesMonsters.contains(entityType);
}
// -------------------------------------------- //
// ENTITY TYPE ANIMAL
// -------------------------------------------- //
private static final BackstringSet<EntityType> ENTITY_TYPE_ANIMALS = new BackstringSet<>(EntityType.class,
public static final BackstringSet<EntityType> ENTITY_TYPES_ANIMAL = new BackstringSet<>(EntityType.class,
"BAT", // Minecraft 1.?
"CHICKEN", // Minecraft 1.?
"COW", // Minecraft 1.?
@ -234,8 +234,7 @@ public class EnumerationUtil
public static boolean isEntityTypeAnimal(EntityType entityType)
{
return ENTITY_TYPE_ANIMALS.contains(entityType) || MConf.get().entityTypesAnimals.contains(entityType);
return ENTITY_TYPES_ANIMAL.contains(entityType) || MConf.get().entityTypesAnimals.contains(entityType);
}
}