Skip to content

Commit

Permalink
Update to BentoBox 1.14-SNAPSHOT API.
Browse files Browse the repository at this point in the history
Implement new API features.
Replace deprecated methods.

Add compatibility layer with Minecraft 1.16 version.
  • Loading branch information
BONNe committed Jul 7, 2020
1 parent e85b687 commit ce14c20
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 51 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private void addPlayerData(@NonNull String uniqueID)
{
// 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);
}
Expand Down Expand Up @@ -696,7 +696,7 @@ private boolean migrateLevels(World world)
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;
Expand Down Expand Up @@ -740,7 +740,7 @@ private boolean migrateChallenges(World world)

updated = true;

this.challengeDatabase.saveObject(challenge);
this.challengeDatabase.saveObjectAsync(challenge);
this.challengeCacheData.put(challenge.getUniqueId(), challenge);
}

Expand Down Expand Up @@ -783,7 +783,7 @@ private boolean migrateChallenges(World world)

// This save should not involve any upgrades in other parts.

this.challengeDatabase.saveObject(challenge);
this.challengeDatabase.saveObjectAsync(challenge);
this.challengeCacheData.put(challenge.getUniqueId(), challenge);
}
}
Expand Down Expand Up @@ -834,7 +834,7 @@ private void migratePlayers(World world)
}
});

this.playersDatabase.saveObject(playerData);
this.playersDatabase.saveObjectAsync(playerData);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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;

Expand All @@ -28,6 +30,7 @@
* @author tastybento
*
*/
@Table(name = "Challenge")
public class Challenge implements DataObject
{
/**
Expand Down Expand Up @@ -156,6 +159,7 @@ public enum ChallengeType

@Deprecated
@Expose
@JsonAdapter(EntityCompatibilityAdapter.class)
private Map<EntityType, Integer> requiredEntities = new EnumMap<>(EntityType.class);

@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

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;

/**
* Represent a challenge level
* @author tastybento
*
*/
@Table(name = "ChallengeLevel")
public class ChallengeLevel implements DataObject, Comparable<ChallengeLevel>
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

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;

Expand All @@ -23,6 +24,7 @@
* @author tastybento
*
*/
@Table(name = "ChallengesPlayerData")
public class ChallengesPlayerData implements DataObject
{
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
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;


/**
Expand Down Expand Up @@ -193,6 +196,7 @@ public Requirements clone()
* 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);

/**
Expand Down
50 changes: 5 additions & 45 deletions src/main/resources/addon.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

0 comments on commit ce14c20

Please sign in to comment.