Update to BentoBox 1.14-SNAPSHOT API.

Implement new API features.
Replace deprecated methods.

Add compatibility layer with Minecraft 1.16 version.
This commit is contained in:
BONNe 2020-07-07 11:58:09 +03:00 committed by BONNe1704
parent e85b687e36
commit ce14c20126
8 changed files with 115 additions and 51 deletions

View File

@ -36,7 +36,7 @@
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.15.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.13.1</bentobox.version>
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
<level.version>1.6.0</level.version>
<vault.version>1.7</vault.version>
<!-- Revision variable removes warning about dynamic version -->

View File

@ -549,7 +549,7 @@ public class ChallengesManager
{
// Create the player data
ChallengesPlayerData pd = new ChallengesPlayerData(uniqueID);
this.playersDatabase.saveObject(pd);
this.playersDatabase.saveObjectAsync(pd);
// Add to cache
this.playerCacheData.put(uniqueID, pd);
}
@ -696,7 +696,7 @@ public class ChallengesManager
challengesID.forEach(challenge ->
level.getChallenges().add(addonName + challenge.substring(world.getName().length())));
this.levelDatabase.saveObject(level);
this.levelDatabase.saveObjectAsync(level);
this.levelCacheData.put(level.getUniqueId(), level);
updated = true;
@ -740,7 +740,7 @@ public class ChallengesManager
updated = true;
this.challengeDatabase.saveObject(challenge);
this.challengeDatabase.saveObjectAsync(challenge);
this.challengeCacheData.put(challenge.getUniqueId(), challenge);
}
@ -783,7 +783,7 @@ public class ChallengesManager
// This save should not involve any upgrades in other parts.
this.challengeDatabase.saveObject(challenge);
this.challengeDatabase.saveObjectAsync(challenge);
this.challengeCacheData.put(challenge.getUniqueId(), challenge);
}
}
@ -834,7 +834,7 @@ public class ChallengesManager
}
});
this.playersDatabase.saveObject(playerData);
this.playersDatabase.saveObjectAsync(playerData);
});
}

View File

@ -19,6 +19,8 @@ import com.google.gson.annotations.Expose;
import com.google.gson.annotations.JsonAdapter;
import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;
import world.bentobox.challenges.database.object.adapters.EntityCompatibilityAdapter;
import world.bentobox.challenges.database.object.adapters.RequirementsAdapter;
import world.bentobox.challenges.database.object.requirements.Requirements;
@ -28,6 +30,7 @@ import world.bentobox.challenges.database.object.requirements.Requirements;
* @author tastybento
*
*/
@Table(name = "Challenge")
public class Challenge implements DataObject
{
/**
@ -156,6 +159,7 @@ public class Challenge implements DataObject
@Deprecated
@Expose
@JsonAdapter(EntityCompatibilityAdapter.class)
private Map<EntityType, Integer> requiredEntities = new EnumMap<>(EntityType.class);
@Deprecated

View File

@ -14,6 +14,7 @@ import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.api.configuration.ConfigComment;
import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;
import world.bentobox.challenges.ChallengesManager;
/**
@ -21,6 +22,7 @@ import world.bentobox.challenges.ChallengesManager;
* @author tastybento
*
*/
@Table(name = "ChallengeLevel")
public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
{
/**

View File

@ -14,6 +14,7 @@ import com.google.gson.annotations.Expose;
import world.bentobox.bentobox.api.logs.LogEntry;
import world.bentobox.bentobox.database.objects.DataObject;
import world.bentobox.bentobox.database.objects.Table;
import world.bentobox.bentobox.database.objects.adapters.Adapter;
import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
@ -23,6 +24,7 @@ import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
* @author tastybento
*
*/
@Table(name = "ChallengesPlayerData")
public class ChallengesPlayerData implements DataObject
{
/**

View File

@ -0,0 +1,92 @@
//
// Created by BONNe
// Copyright - 2020
//
package world.bentobox.challenges.database.object.adapters;
import com.google.gson.*;
import org.bukkit.entity.EntityType;
import java.lang.reflect.Type;
import java.util.EnumMap;
import java.util.Map;
import world.bentobox.bentobox.BentoBox;
/**
* This is compatibility class for dealing with Mojang renamed entities.
* Created for update 1.16.
*/
public class EntityCompatibilityAdapter implements
JsonSerializer<Map<EntityType, Integer>>, JsonDeserializer<Map<EntityType, Integer>>
{
/**
* This method serializes input map as String Key and Integer value.
* @param src EnumMap that contains EntityType as key and Integer as value.
* @return serialized JsonElement.
*/
@Override
public JsonElement serialize(Map<EntityType, Integer> src, Type typeOfSrc, JsonSerializationContext context)
{
JsonObject jsonArray = new JsonObject();
src.forEach((entity, number) ->
{
jsonArray.addProperty(entity.name(), number);
});
return jsonArray;
}
/**
* This method deserializes json object that stores Entity Name and amount as integer.
* @param json Json element that must be parsed.
* @return EnumMap that contains EntityType as key and Integer as value.
* @throws JsonParseException
*/
@Override
public Map<EntityType, Integer> deserialize(JsonElement json,
Type typeOfT,
JsonDeserializationContext context)
throws JsonParseException
{
Map<EntityType, Integer> map = new EnumMap<>(EntityType.class);
for (Map.Entry<String, JsonElement> entrySet : json.getAsJsonObject().entrySet())
{
try
{
EntityType entityType = EntityType.valueOf(entrySet.getKey());
map.put(entityType, entrySet.getValue().getAsInt());
}
catch (IllegalArgumentException e)
{
if (entrySet.getKey().equals("PIG_ZOMBIE"))
{
// Hacky way how to get new entity name.
map.put(EntityType.valueOf("ZOMBIFIED_PIGLIN"),
entrySet.getValue().getAsInt());
}
else if (entrySet.getKey().equals("ZOMBIFIED_PIGLIN"))
{
// Hacky way how to get new entity name.
map.put(EntityType.valueOf("PIG_ZOMBIE"),
entrySet.getValue().getAsInt());
}
else
{
// No replacement for new entities in older server.
BentoBox.getInstance().logWarning("[ChallengesAddon] Entity with name `" +
entrySet.getKey() + "` does not exist in your Minecraft server version." +
" It will be skipped!");
}
}
}
return map;
}
}

View File

@ -16,6 +16,9 @@ import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.JsonAdapter;
import world.bentobox.challenges.database.object.adapters.EntityCompatibilityAdapter;
/**
@ -193,6 +196,7 @@ public class IslandRequirements extends Requirements
* Map that contains which entities and how many is necessary around player to complete challenge.
*/
@Expose
@JsonAdapter(EntityCompatibilityAdapter.class)
private Map<EntityType, Integer> requiredEntities = new EnumMap<>(EntityType.class);
/**

View File

@ -1,7 +1,7 @@
name: Challenges
main: world.bentobox.challenges.ChallengesAddon
version: ${version}${build.number}
api-version: 1.13.1
api-version: 1.14
repository: 'BentoBoxWorld/Challenges'
metrics: true
@ -19,52 +19,12 @@ permissions:
description: Let the player use the '/challenges' command
default: true
bskyblock.challenges:
'[gamemode].challenges':
description: Let the player use the '/island challenges' command
default: true
bskyblock.challenges.multiple:
'[gamemode].challenges.multiple':
description: Let the player complete challenge multiple times
default: true
bskyblock.admin.challenges:
'[gamemode].admin.challenges':
description: Access challenge admin commands
default: op
acidisland.challenges:
description: Let the player use the '/ai challenges' command
default: true
acidisland.challenges.multiple:
description: Let the player complete challenge multiple times
default: true
acidisland.admin.challenges:
description: Access challenge admin commands
default: op
caveblock.challenges:
description: Let the player use the '/cave challenges' command
default: true
caveblock.challenges.multiple:
description: Let the player complete challenge multiple times
default: true
caveblock.admin.challenges:
description: Access challenge admin commands
default: op
skygrid.challenges:
description: Let the player use the '/skygrid challenges' command
default: true
skygrid.challenges.multiple:
description: Let the player complete challenge multiple times
default: true
skygrid.admin.challenges:
description: Access challenge admin commands
default: op
aoneblock.challenges:
description: Let the player use the '/aoneblock challenges' command
default: true
aoneblock.challenges.multiple:
description: Let the player complete challenge multiple times
default: true
aoneblock.admin.challenges:
description: Access challenge admin commands
default: op
default: op