mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-12-01 06:53:37 +01:00
Completely drop ability to import ASkyBlock challenges.
This option was not working properly and were used wrongly. To avoid that, importing challenges and player data will be handled by converter.
This commit is contained in:
parent
7fce1a1fd4
commit
ac79fa5d56
@ -9,208 +9,33 @@ import java.nio.file.Paths;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
import world.bentobox.bentobox.database.json.BentoboxTypeAdapterFactory;
|
import world.bentobox.bentobox.database.json.BentoboxTypeAdapterFactory;
|
||||||
import world.bentobox.bentobox.database.objects.DataObject;
|
import world.bentobox.bentobox.database.objects.DataObject;
|
||||||
import world.bentobox.bentobox.util.ItemParser;
|
|
||||||
import world.bentobox.challenges.database.object.ChallengeLevel;
|
import world.bentobox.challenges.database.object.ChallengeLevel;
|
||||||
import world.bentobox.challenges.database.object.Challenge;
|
import world.bentobox.challenges.database.object.Challenge;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.challenges.utils.GuiUtils;
|
|
||||||
import world.bentobox.challenges.utils.Utils;
|
import world.bentobox.challenges.utils.Utils;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports challenges
|
* Imports challenges
|
||||||
* @author tastybento
|
* @author BONNe1704
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ChallengesImportManager
|
public class ChallengesImportManager
|
||||||
{
|
{
|
||||||
|
|
||||||
private ChallengesAddon addon;
|
|
||||||
private YamlConfiguration chal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import challenges from challenges.yml
|
* Import challenges from challenges.yml
|
||||||
* @param challengesAddon
|
* @param challengesAddon
|
||||||
*/
|
*/
|
||||||
public ChallengesImportManager(ChallengesAddon challengesAddon) {
|
public ChallengesImportManager(ChallengesAddon challengesAddon)
|
||||||
|
{
|
||||||
this.addon = challengesAddon;
|
this.addon = challengesAddon;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Import challenges
|
|
||||||
* @param user - user
|
|
||||||
* @param world - world to import into
|
|
||||||
* @param overwrite - true if previous ones should be overwritten
|
|
||||||
* @return true if successful
|
|
||||||
*/
|
|
||||||
public boolean importChallenges(User user, World world, boolean overwrite) {
|
|
||||||
File challengeFile = new File(addon.getDataFolder(), "challenges.yml");
|
|
||||||
if (!challengeFile.exists()) {
|
|
||||||
user.sendMessage("challenges.errors.import-no-file");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
chal = new YamlConfiguration();
|
|
||||||
try {
|
|
||||||
chal.load(challengeFile);
|
|
||||||
} catch (IOException | InvalidConfigurationException e) {
|
|
||||||
user.sendMessage("challenges.errors.no-load","[message]", e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
makeLevels(user, world, overwrite);
|
|
||||||
makeChallenges(user, world, overwrite);
|
|
||||||
addon.getChallengesManager().save();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void makeLevels(User user, World world, boolean overwrite) {
|
|
||||||
// Parse the levels
|
|
||||||
String levels = chal.getString("challenges.levels", "");
|
|
||||||
if (!levels.isEmpty()) {
|
|
||||||
user.sendMessage("challenges.messages.import-levels");
|
|
||||||
String[] lvs = levels.split(" ");
|
|
||||||
int order = 0;
|
|
||||||
for (String level : lvs) {
|
|
||||||
ChallengeLevel challengeLevel = new ChallengeLevel();
|
|
||||||
challengeLevel.setFriendlyName(level);
|
|
||||||
challengeLevel.setUniqueId(Utils.getGameMode(world) + "_" + level);
|
|
||||||
challengeLevel.setOrder(order++);
|
|
||||||
challengeLevel.setWorld(Util.getWorld(world).getName());
|
|
||||||
challengeLevel.setWaiverAmount(chal.getInt("challenges.waiveramount"));
|
|
||||||
// Check if there is a level reward
|
|
||||||
ConfigurationSection unlock = chal.getConfigurationSection("challenges.levelUnlock." + level);
|
|
||||||
if (unlock != null) {
|
|
||||||
challengeLevel.setUnlockMessage(unlock.getString("message", ""));
|
|
||||||
challengeLevel.setRewardText(unlock.getString("rewardDesc",""));
|
|
||||||
challengeLevel.setRewardItems(parseItems(unlock.getString("itemReward","")));
|
|
||||||
challengeLevel.setRewardMoney(unlock.getInt("moneyReward"));
|
|
||||||
challengeLevel.setRewardExperience(unlock.getInt("expReward"));
|
|
||||||
challengeLevel.setRewardCommands(unlock.getStringList("commands"));
|
|
||||||
}
|
|
||||||
addon.getChallengesManager().loadLevel(challengeLevel, overwrite, user, false);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
user.sendMessage("challenges.messages.no-levels");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Imports challenges
|
|
||||||
* @param overwrite
|
|
||||||
*/
|
|
||||||
private void makeChallenges(User user, World world, boolean overwrite) {
|
|
||||||
int size = 0;
|
|
||||||
// Parse the challenge file
|
|
||||||
ConfigurationSection chals = chal.getConfigurationSection("challenges.challengeList");
|
|
||||||
user.sendMessage("challenges.messages.import-challenges");
|
|
||||||
|
|
||||||
for (String challenge : chals.getKeys(false)) {
|
|
||||||
Challenge newChallenge = new Challenge();
|
|
||||||
newChallenge.setUniqueId(Utils.getGameMode(world) + "_" + challenge);
|
|
||||||
newChallenge.setDeployed(true);
|
|
||||||
ConfigurationSection details = chals.getConfigurationSection(challenge);
|
|
||||||
newChallenge.setFriendlyName(details.getString("friendlyname", challenge));
|
|
||||||
newChallenge.setDescription(GuiUtils.stringSplit(
|
|
||||||
details.getString("description", ""),
|
|
||||||
this.addon.getChallengesSettings().getLoreLineLength()));
|
|
||||||
newChallenge.setIcon(ItemParser.parse(details.getString("icon", "") + ":1"));
|
|
||||||
|
|
||||||
if (details.getString("type", "").equalsIgnoreCase("level"))
|
|
||||||
{
|
|
||||||
// Fix for older version config
|
|
||||||
newChallenge.setChallengeType(Challenge.ChallengeType.OTHER);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase()));
|
|
||||||
}
|
|
||||||
|
|
||||||
newChallenge.setTakeItems(details.getBoolean("takeItems",true));
|
|
||||||
newChallenge.setRewardText(details.getString("rewardText", ""));
|
|
||||||
newChallenge.setRewardCommands(details.getStringList("rewardcommands"));
|
|
||||||
newChallenge.setRewardMoney(details.getInt("moneyReward",0));
|
|
||||||
newChallenge.setRewardExperience(details.getInt("expReward"));
|
|
||||||
newChallenge.setRepeatable(details.getBoolean("repeatable"));
|
|
||||||
newChallenge.setRepeatRewardText(details.getString("repeatRewardText",""));
|
|
||||||
newChallenge.setRepeatMoneyReward(details.getInt("repearMoneyReward"));
|
|
||||||
newChallenge.setRepeatExperienceReward(details.getInt("repeatExpReward"));
|
|
||||||
newChallenge.setRepeatRewardCommands(details.getStringList("repeatrewardcommands"));
|
|
||||||
newChallenge.setMaxTimes(details.getInt("maxtimes"));
|
|
||||||
// TODO reset allowed
|
|
||||||
newChallenge.setRequiredMoney(details.getInt("requiredMoney"));
|
|
||||||
newChallenge.setRequiredExperience(details.getInt("requiredExp"));
|
|
||||||
String reqItems = details.getString("requiredItems","");
|
|
||||||
if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) {
|
|
||||||
newChallenge.setRequiredItems(parseItems(reqItems));
|
|
||||||
} else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)) {
|
|
||||||
newChallenge.setRequiredIslandLevel(Long.parseLong(reqItems));
|
|
||||||
} else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) {
|
|
||||||
parseEntities(newChallenge, reqItems);
|
|
||||||
}
|
|
||||||
newChallenge.setRewardItems(parseItems(details.getString("itemReward", "")));
|
|
||||||
newChallenge.setRepeatItemReward(parseItems(details.getString("repeatItemReward", "")));
|
|
||||||
// Save
|
|
||||||
if (!details.getString("level", "").isEmpty())
|
|
||||||
{
|
|
||||||
this.addon.getChallengesManager().addChallengeToLevel(newChallenge,
|
|
||||||
addon.getChallengesManager().getLevel(
|
|
||||||
Utils.getGameMode(world) + "_" + details.getString("level", "")));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (addon.getChallengesManager().loadChallenge(newChallenge, overwrite, user, false)) {
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage("challenges.messages.import-number", "[number]", String.valueOf(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run through entity types and materials and try to match to the string given
|
|
||||||
* @param challenge - challenge to be adjusted
|
|
||||||
* @param string - string from YAML file
|
|
||||||
*/
|
|
||||||
private void parseEntities(Challenge challenge, String string) {
|
|
||||||
Map<EntityType, Integer> req = new EnumMap<>(EntityType.class);
|
|
||||||
Map<Material, Integer> blocks = new EnumMap<>(Material.class);
|
|
||||||
if (!string.isEmpty()) {
|
|
||||||
for (String s : string.split(" ")) {
|
|
||||||
String[] part = s.split(":");
|
|
||||||
try {
|
|
||||||
Arrays.asList(EntityType.values()).stream().filter(t -> t.name().equalsIgnoreCase(part[0])).forEach(t -> req.put(t, Integer.valueOf(part[1])));
|
|
||||||
Arrays.asList(Material.values()).stream().filter(t -> t.name().equalsIgnoreCase(part[0])).forEach(t -> blocks.put(t, Integer.valueOf(part[1])));
|
|
||||||
} catch (Exception e) {
|
|
||||||
addon.getLogger().severe("Cannot parse '" + s + "'. Skipping...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
challenge.setRequiredEntities(req);
|
|
||||||
challenge.setRequiredBlocks(blocks);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ItemStack> parseItems(String reqList) {
|
|
||||||
List<ItemStack> result = new ArrayList<>();
|
|
||||||
if (!reqList.isEmpty()) {
|
|
||||||
for (String s : reqList.split(" ")) {
|
|
||||||
ItemStack item = ItemParser.parse(s);
|
|
||||||
if (item != null) {
|
|
||||||
result.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Default Challenge Loader
|
// Section: Default Challenge Loader
|
||||||
@ -301,9 +126,9 @@ public class ChallengesImportManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Default generation
|
// Section: Default generation
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -424,9 +249,9 @@ public class ChallengesImportManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
// Section: Private classes for default challegnes
|
// Section: Private classes for default challenges
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -633,4 +458,12 @@ public class ChallengesImportManager
|
|||||||
@Expose
|
@Expose
|
||||||
private String version;
|
private String version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Section: Variables
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
private ChallengesAddon addon;
|
||||||
}
|
}
|
@ -33,8 +33,7 @@ public class Challenges extends CompositeCommand
|
|||||||
|
|
||||||
// This method reloads challenges addon
|
// This method reloads challenges addon
|
||||||
new ReloadChallenges(getAddon(), this);
|
new ReloadChallenges(getAddon(), this);
|
||||||
// Import ASkyBlock Challenges
|
|
||||||
new ImportCommand(getAddon(), this);
|
|
||||||
// Defaults processing command
|
// Defaults processing command
|
||||||
new DefaultsCommand(this.getAddon(), this);
|
new DefaultsCommand(this.getAddon(), this);
|
||||||
|
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
package world.bentobox.challenges.commands.admin;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import world.bentobox.challenges.ChallengesAddon;
|
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
|
||||||
import world.bentobox.bentobox.api.user.User;
|
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
|
|
||||||
public class ImportCommand extends CompositeCommand {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Import challenges
|
|
||||||
* @param addon
|
|
||||||
* @param cmd
|
|
||||||
*/
|
|
||||||
public ImportCommand(Addon addon, CompositeCommand cmd) {
|
|
||||||
super(addon, cmd, "import");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
|
||||||
return ((ChallengesAddon)getAddon()).getImportManager().importChallenges(user, getWorld(), !args.isEmpty() && args.get(0).equalsIgnoreCase("overwrite"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setup() {
|
|
||||||
this.setPermission("challenges.admin");
|
|
||||||
this.setParametersHelp("challenges.commands.admin.import.parameters");
|
|
||||||
this.setDescription("challenges.commands.admin.import.description");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
|
||||||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
|
||||||
return Optional.of(Util.tabLimit(Arrays.asList("overwrite"), lastArg));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -15,7 +15,6 @@ import world.bentobox.bentobox.api.panels.PanelItem;
|
|||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.util.Util;
|
|
||||||
import world.bentobox.challenges.ChallengesAddon;
|
import world.bentobox.challenges.ChallengesAddon;
|
||||||
import world.bentobox.challenges.panel.CommonGUI;
|
import world.bentobox.challenges.panel.CommonGUI;
|
||||||
import world.bentobox.challenges.panel.util.ConfirmationGUI;
|
import world.bentobox.challenges.panel.util.ConfirmationGUI;
|
||||||
@ -61,7 +60,6 @@ public class AdminGUI extends CommonGUI
|
|||||||
EDIT_LEVEL,
|
EDIT_LEVEL,
|
||||||
DELETE_CHALLENGE,
|
DELETE_CHALLENGE,
|
||||||
DELETE_LEVEL,
|
DELETE_LEVEL,
|
||||||
IMPORT_CHALLENGES,
|
|
||||||
EDIT_SETTINGS,
|
EDIT_SETTINGS,
|
||||||
DEFAULT_IMPORT_CHALLENGES,
|
DEFAULT_IMPORT_CHALLENGES,
|
||||||
DEFAULT_EXPORT_CHALLENGES,
|
DEFAULT_EXPORT_CHALLENGES,
|
||||||
@ -123,8 +121,7 @@ public class AdminGUI extends CommonGUI
|
|||||||
|
|
||||||
|
|
||||||
// Import Challenges
|
// Import Challenges
|
||||||
panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES));
|
panelBuilder.item(15, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES));
|
||||||
panelBuilder.item(24, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES));
|
|
||||||
// Not added as I do not think admins should use it. It still will be able via command.
|
// Not added as I do not think admins should use it. It still will be able via command.
|
||||||
// panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES));
|
// panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES));
|
||||||
|
|
||||||
@ -355,31 +352,6 @@ public class AdminGUI extends CommonGUI
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IMPORT_CHALLENGES:
|
|
||||||
{
|
|
||||||
permissionSuffix = IMPORT;
|
|
||||||
|
|
||||||
name = this.user.getTranslation("challenges.gui.buttons.admin.import");
|
|
||||||
description = this.user.getTranslation("challenges.gui.descriptions.admin.import");
|
|
||||||
icon = new ItemStack(Material.HOPPER);
|
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
|
||||||
if (clickType.isRightClick())
|
|
||||||
{
|
|
||||||
this.overwriteMode = !this.overwriteMode;
|
|
||||||
this.build();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Run import command.
|
|
||||||
this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + IMPORT +
|
|
||||||
(this.overwriteMode ? " overwrite" : ""));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
glow = this.overwriteMode;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DEFAULT_IMPORT_CHALLENGES:
|
case DEFAULT_IMPORT_CHALLENGES:
|
||||||
{
|
{
|
||||||
permissionSuffix = DEFAULT;
|
permissionSuffix = DEFAULT;
|
||||||
|
Loading…
Reference in New Issue
Block a user