From 48eb14b37763eeebb29f0d928775347a785d0b6c Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 28 Jan 2019 16:28:25 +0200 Subject: [PATCH 1/4] Restore original Challenges and ChallengeLevels objects. (For backward compatibility) --- .../database/object/ChallengeLevels.java | 226 +++++++ .../database/object/Challenges.java | 634 ++++++++++++++++++ 2 files changed, 860 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java create mode 100644 src/main/java/world/bentobox/challenges/database/object/Challenges.java diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java new file mode 100644 index 0000000..cba2d32 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java @@ -0,0 +1,226 @@ +package world.bentobox.challenges.database.object; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.inventory.ItemStack; + +import world.bentobox.challenges.ChallengesManager; +import world.bentobox.bentobox.api.configuration.ConfigComment; +import world.bentobox.bentobox.database.objects.DataObject; + +/** + * Represent a challenge level + * @author tastybento + * + */ +@Deprecated +public class ChallengeLevels implements DataObject, Comparable { + + public ChallengeLevels() {} + + @ConfigComment("A friendly name for the level. If blank, level name is used.") + private String friendlyName = ""; + + @ConfigComment("Worlds that this level applies in. String list.") + private List worlds = new ArrayList<>(); + + @ConfigComment("Commands to run when this level is completed") + private List rewardCommands = new ArrayList<>(); + + @ConfigComment("Level name") + private String uniqueId = ChallengesManager.FREE; + + @ConfigComment("The number of undone challenges that can be left on this level before unlocking next level") + private int waiveramount = 1; + + @ConfigComment("The ordering of the levels, lowest to highest") + private int order = 0; + + @ConfigComment("The message shown when unlocking this level") + private String unlockMessage = ""; + + @ConfigComment("Unlock reward description") + private String rewardDescription = ""; + + @ConfigComment("List of reward itemstacks") + private List rewardItems; + + @ConfigComment("Unlock experience reward") + private int expReward; + + @ConfigComment("Unlock money reward") + private int moneyReward; + + public String getFriendlyName() { + return friendlyName; + } + + public List getRewardCommands() { + return rewardCommands = new ArrayList<>(); + } + + @Override + public String getUniqueId() { + return uniqueId; + } + + /** + * Get the number of undone tasks that can be left on a level before unlocking next level + * @return + */ + public int getWaiveramount() { + return waiveramount; + } + + public void setFriendlyName(String friendlyName) { + this.friendlyName = friendlyName; + } + + public void setRewardCommands(List rewardCommands) { + this.rewardCommands = rewardCommands; + } + + @Override + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + public void setWaiveramount(int waiveramount) { + this.waiveramount = waiveramount; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } + + @Override + public int compareTo(ChallengeLevels o) { + return Integer.compare(this.order, o.order); + } + + /** + * @return the rewardDescription + */ + public String getRewardDescription() { + return rewardDescription; + } + + /** + * @param rewardDescription the rewardDescription to set + */ + public void setRewardDescription(String rewardDescription) { + this.rewardDescription = rewardDescription; + } + + /** + * @return the rewardItems + */ + public List getRewardItems() { + return rewardItems; + } + + /** + * @param rewardItems the rewardItems to set + */ + public void setRewardItems(List rewardItems) { + this.rewardItems = rewardItems; + } + + /** + * @return the expReward + */ + public int getExpReward() { + return expReward; + } + + /** + * @param expReward the expReward to set + */ + public void setExpReward(int expReward) { + this.expReward = expReward; + } + + /** + * @return the moneyReward + */ + public int getMoneyReward() { + return moneyReward; + } + + /** + * @param moneyReward the moneyReward to set + */ + public void setMoneyReward(int moneyReward) { + this.moneyReward = moneyReward; + } + + /** + * @return the unlockMessage + */ + public String getUnlockMessage() { + return unlockMessage; + } + + /** + * @param unlockMessage the unlockMessage to set + */ + public void setUnlockMessage(String unlockMessage) { + this.unlockMessage = unlockMessage; + } + + /** + * @return the worlds + */ + public List getWorlds() { + return worlds; + } + + /** + * @param worlds the worlds to set + */ + public void setWorlds(List worlds) { + this.worlds = worlds; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof ChallengeLevels)) { + return false; + } + ChallengeLevels other = (ChallengeLevels) obj; + if (uniqueId == null) { + if (other.uniqueId != null) { + return false; + } + } else if (!uniqueId.equals(other.uniqueId)) { + return false; + } + return true; + } + +} diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenges.java b/src/main/java/world/bentobox/challenges/database/object/Challenges.java new file mode 100644 index 0000000..d78500a --- /dev/null +++ b/src/main/java/world/bentobox/challenges/database/object/Challenges.java @@ -0,0 +1,634 @@ +package world.bentobox.challenges.database.object; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +import world.bentobox.challenges.ChallengesManager; +import world.bentobox.bentobox.api.configuration.ConfigComment; +import world.bentobox.bentobox.database.objects.DataObject; + +/** + * Data object for challenges + * @author tastybento + * + */ +@Deprecated +public class Challenges implements DataObject { + + public Challenges() {} + + public enum ChallengeType { + /** + * This challenge only shows and icon in the GUI and doesn't do anything. + */ + ICON, + /** + * The player must have the items on them. + */ + INVENTORY, + /** + * The island level has to be equal or over this amount. Only works if there's an island level plugin installed. + */ + LEVEL, + /** + * Items or required entities have to be within x blocks of the player. + */ + ISLAND + } + + // The order of the fields is the order shown in the YML files + @ConfigComment("Whether this challenge is deployed or not") + private boolean deployed; + + // Description + @ConfigComment("Name of the icon and challenge. May include color codes. Single line.") + private String friendlyName = ""; + @ConfigComment("Description of the challenge. Will become the lore on the icon. Can include & color codes. String List.") + private List description = new ArrayList<>(); + @ConfigComment("The icon in the GUI for this challenge. ItemStack.") + private ItemStack icon = new ItemStack(Material.PAPER); + @ConfigComment("Icon slot where this challenge should be placed. 0 to 49. A negative value means any slot") + private int slot = -1; + + // Definition + @ConfigComment("Challenge level. Default is Free") + private String level = ChallengesManager.FREE; + @ConfigComment("Challenge type can be ICON, INVENTORY, LEVEL or ISLAND.") + private ChallengeType challengeType = ChallengeType.INVENTORY; + @ConfigComment("World where this challenge operates. List only overworld. Nether and end are automatically covered.") + private String world = ""; + @ConfigComment("List of environments where this challenge will occur: NETHER, NORMAL, THE_END. Leave blank for all.") + private List environment = new ArrayList<>(); + @ConfigComment("The required permissions to see this challenge. String list.") + private Set reqPerms = new HashSet<>(); + @ConfigComment("The number of blocks around the player to search for items on an island") + private int searchRadius = 10; + @ConfigComment("If true, the challenge will disappear from the GUI when completed") + private boolean removeWhenCompleted; + @ConfigComment("Take the required items from the player") + private boolean takeItems = true; + @ConfigComment("Take the money from the player") + private boolean takeMoney = false; + + // Requirements + @ConfigComment("This is a map of the blocks required in a ISLAND challenge. Material, Integer") + private Map requiredBlocks = new EnumMap<>(Material.class); + @ConfigComment("The items that must be in the inventory to complete the challenge. ItemStack List.") + private List requiredItems = new ArrayList<>(); + @ConfigComment("Any entities that must be in the area for ISLAND type challenges. Map EntityType, Number") + private Map requiredEntities = new EnumMap<>(EntityType.class); + @ConfigComment("Required experience") + private int reqExp; + @ConfigComment("Required island level for this challenge. Only works if Level Addon is being used.") + private long reqIslandlevel; + @ConfigComment("Required money") + private int reqMoney; + + // Rewards + @ConfigComment("List of items the player will receive first time. ItemStack List.") + private List rewardItems = new ArrayList<>(); + @ConfigComment("If this is blank, the reward text will be auto-generated, otherwise this will be used.") + private String rewardText = ""; + @ConfigComment("Experience point reward") + private int rewardExp; + @ConfigComment("Money reward") + private int rewardMoney; + @ConfigComment("Commands to run when the player completes the challenge for the first time. String List") + private List rewardCommands = new ArrayList<>(); + + // Repeatable + @ConfigComment("True if the challenge is repeatable") + private boolean repeatable; + @ConfigComment("Maximum number of times the challenge can be repeated") + private int maxTimes = 1; + @ConfigComment("Repeat exp award") + private int repeatExpReward; + @ConfigComment("Reward items for repeating the challenge. List of ItemStacks.") + private List repeatItemReward = new ArrayList<>(); + @ConfigComment("Repeat money award") + private int repeatMoneyReward; + @ConfigComment("Commands to run when challenge is repeated. String List.") + private List repeatRewardCommands = new ArrayList<>(); + @ConfigComment("Description of the repeat rewards. If blank, it will be autogenerated.") + private String repeatRewardText = ""; + + + @ConfigComment("Unique name of the challenge") + private String uniqueId = ""; + + /* + * END OF SETTINGS + */ + + /** + * @return the challengeType + */ + public ChallengeType getChallengeType() { + return challengeType; + } + + /** + * @param challengeType the challengeType to set + */ + public void setChallengeType(ChallengeType challengeType) { + this.challengeType = challengeType; + } + + /** + * @return the deployed + */ + public boolean isDeployed() { + return deployed; + } + + /** + * @param deployed the deployed to set + */ + public void setDeployed(boolean deployed) { + this.deployed = deployed; + } + + /** + * @return the description + */ + public List getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(List description) { + this.description = description; + } + + /** + * @return the expReward + */ + public int getRewardExp() { + return rewardExp; + } + + /** + * @param expReward the expReward to set + */ + public void setRewardExp(int expReward) { + this.rewardExp = expReward; + } + + /** + * @return the friendlyName + */ + public String getFriendlyName() { + return friendlyName; + } + + /** + * @param friendlyName the friendlyName to set + */ + public void setFriendlyName(String friendlyName) { + this.friendlyName = friendlyName; + } + + /** + * @return the icon + */ + public ItemStack getIcon() { + return icon != null ? icon.clone() : new ItemStack(Material.MAP); + } + + /** + * @param icon the icon to set + */ + public void setIcon(ItemStack icon) { + this.icon = icon; + } + + /** + * @return the level + */ + public String getLevel() { + return level; + } + + /** + * @param level the level to set + */ + public void setLevel(String level) { + if (level.isEmpty()) { + level = ChallengesManager.FREE; + } + this.level = level; + } + + /** + * @return the maxTimes + */ + public int getMaxTimes() { + return maxTimes; + } + + /** + * @param maxTimes the maxTimes to set + */ + public void setMaxTimes(int maxTimes) { + this.maxTimes = maxTimes; + } + + /** + * @return the moneyReward + */ + public int getRewardMoney() { + return rewardMoney; + } + + /** + * @param moneyReward the moneyReward to set + */ + public void setRewardMoney(int moneyReward) { + this.rewardMoney = moneyReward; + } + + /** + * @return the removeWhenCompleted + */ + public boolean isRemoveWhenCompleted() { + return removeWhenCompleted; + } + + /** + * @param removeWhenCompleted the removeWhenCompleted to set + */ + public void setRemoveWhenCompleted(boolean removeWhenCompleted) { + this.removeWhenCompleted = removeWhenCompleted; + } + + /** + * @return the repeatable + */ + public boolean isRepeatable() { + return repeatable; + } + + /** + * @param repeatable the repeatable to set + */ + public void setRepeatable(boolean repeatable) { + this.repeatable = repeatable; + } + + /** + * @return the repeatExpReward + */ + public int getRepeatExpReward() { + return repeatExpReward; + } + + /** + * @param repeatExpReward the repeatExpReward to set + */ + public void setRepeatExpReward(int repeatExpReward) { + this.repeatExpReward = repeatExpReward; + } + + /** + * @return the repeatItemReward + */ + public List getRepeatItemReward() { + return repeatItemReward; + } + + /** + * @param repeatItemReward the repeatItemReward to set + */ + public void setRepeatItemReward(List repeatItemReward) { + this.repeatItemReward = repeatItemReward; + } + + /** + * @return the repeatMoneyReward + */ + public int getRepeatMoneyReward() { + return repeatMoneyReward; + } + + /** + * @param repeatMoneyReward the repeatMoneyReward to set + */ + public void setRepeatMoneyReward(int repeatMoneyReward) { + this.repeatMoneyReward = repeatMoneyReward; + } + + /** + * @return the repeatRewardCommands + */ + public List getRepeatRewardCommands() { + return repeatRewardCommands; + } + + /** + * @param repeatRewardCommands the repeatRewardCommands to set + */ + public void setRepeatRewardCommands(List repeatRewardCommands) { + this.repeatRewardCommands = repeatRewardCommands; + } + + /** + * @return the repeatRewardText + */ + public String getRepeatRewardText() { + return repeatRewardText; + } + + /** + * @param repeatRewardText the repeatRewardText to set + */ + public void setRepeatRewardText(String repeatRewardText) { + this.repeatRewardText = repeatRewardText; + } + + /** + * @return the reqExp + */ + public int getReqExp() { + return reqExp; + } + + /** + * @param reqExp the reqExp to set + */ + public void setReqExp(int reqExp) { + this.reqExp = reqExp; + } + + /** + * @return the reqIslandlevel + */ + public long getReqIslandlevel() { + return reqIslandlevel; + } + + /** + * @param reqIslandlevel the reqIslandlevel to set + */ + public void setReqIslandlevel(long reqIslandlevel) { + this.reqIslandlevel = reqIslandlevel; + } + + /** + * @return the reqMoney + */ + public int getReqMoney() { + return reqMoney; + } + + /** + * @param reqMoney the reqMoney to set + */ + public void setReqMoney(int reqMoney) { + this.reqMoney = reqMoney; + } + + /** + * @return the reqPerms + */ + public Set getReqPerms() { + return reqPerms; + } + + /** + * @param reqPerms the reqPerms to set + */ + public void setReqPerms(Set reqPerms) { + this.reqPerms = reqPerms; + } + + /** + * @return the requiredItems + */ + public List getRequiredItems() { + return requiredItems; + } + + /** + * @param requiredItems the requiredItems to set + */ + public void setRequiredItems(List requiredItems) { + this.requiredItems = requiredItems; + } + + /** + * @return requiredEntities + */ + public Map getRequiredEntities() { + return requiredEntities; + } + + /** + * @param requiredEntities the requiredEntities to set + */ + public void setRequiredEntities(Map requiredEntities) { + this.requiredEntities = requiredEntities; + } + + /** + * @return the requiredBlocks + */ + public Map getRequiredBlocks() { + return requiredBlocks; + } + + /** + * @param map the requiredBlocks to set + */ + public void setRequiredBlocks(Map map) { + this.requiredBlocks = map; + } + + /** + * @return the rewardCommands + */ + public List getRewardCommands() { + return rewardCommands; + } + + /** + * @param rewardCommands the rewardCommands to set + */ + public void setRewardCommands(List rewardCommands) { + this.rewardCommands = rewardCommands; + } + + /** + * @return the itemReward + */ + public List getRewardItems() { + return rewardItems; + } + + /** + * @param itemReward the itemReward to set + */ + public void setRewardItems(List itemReward) { + this.rewardItems = itemReward; + } + + /** + * @return the rewardText + */ + public String getRewardText() { + return rewardText; + } + + /** + * @param rewardText the rewardText to set + */ + public void setRewardText(String rewardText) { + this.rewardText = rewardText; + } + + /** + * @return the searchRadius + */ + public int getSearchRadius() { + return searchRadius; + } + + /** + * @param searchRadius the searchRadius to set + */ + public void setSearchRadius(int searchRadius) { + this.searchRadius = searchRadius; + } + + /** + * @return the slot + */ + public int getSlot() { + return slot; + } + + /** + * @param slot the slot to set + */ + public void setSlot(int slot) { + this.slot = slot; + } + + /** + * @return the takeItems + */ + public boolean isTakeItems() { + return takeItems; + } + + /** + * @param takeItems the takeItems to set + */ + public void setTakeItems(boolean takeItems) { + this.takeItems = takeItems; + } + + /** + * @return the takeMoney + */ + public boolean isTakeMoney() { + return takeMoney; + } + + /** + * @param takeMoney the takeMoney to set + */ + public void setTakeMoney(boolean takeMoney) { + this.takeMoney = takeMoney; + } + + /** + * @return the environment + */ + public List getEnvironment() { + return environment; + } + + /** + * @param environment the environment to set + */ + public void setEnvironment(List environment) { + this.environment = environment; + } + + /** + * @return the worlds + */ + public String getWorld() { + return world; + } + + /** + * @param worlds the worlds to set + */ + public void setWorld(String world) { + this.world = world; + } + + /** + * @return the uniqueId + */ + @Override + public String getUniqueId() { + return uniqueId; + } + + /** + * @param uniqueId the uniqueId to set + */ + @Override + public void setUniqueId(String uniqueId) { + this.uniqueId = uniqueId; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof Challenges)) { + return false; + } + Challenges other = (Challenges) obj; + if (uniqueId == null) { + if (other.uniqueId != null) { + return false; + } + } else if (!uniqueId.equals(other.uniqueId)) { + return false; + } + return true; + } +} From abfe81c5e66893e0eeaf7238e4282edad04702cd Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 28 Jan 2019 17:53:23 +0200 Subject: [PATCH 2/4] Add GuiButton that allows to load 0.3 challenges. Add Necessary methods in ImportManager. --- .../challenges/ChallengesImportManager.java | 166 +++++++++++++++++- .../challenges/panel/admin/AdminGUI.java | 19 ++ 2 files changed, 180 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index c16ab32..abe5d65 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -2,11 +2,7 @@ package world.bentobox.challenges; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.bukkit.Material; import org.bukkit.World; @@ -16,9 +12,12 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenges; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.Util; import world.bentobox.challenges.utils.GuiUtils; @@ -202,4 +201,161 @@ public class ChallengesImportManager } return result; } + + +// --------------------------------------------------------------------- +// Section: Backward compatibility +// --------------------------------------------------------------------- + + + /** + * This method imports challenges form 0.3 and below version. + * @param user - user + * @param world - world to import into + * @param overwrite - true if previous ones should be overwritten + * @return true if successful + */ + public boolean importPreviousChallenges(User user, World world, boolean overwrite) + { + ChallengesManager manager = this.addon.getChallengesManager(); + + List challenges = + new Config<>(this.addon, Challenges.class).loadConfigObjects(); + + if (!challenges.isEmpty()) + { + List levels = + new Config<>(this.addon, ChallengeLevels.class).loadConfigObjects(); + + for (ChallengeLevels level : levels) + { + manager.loadLevel(this.createLevel(level, world), overwrite, user, false); + } + + for (Challenges challenge : challenges) + { + Challenge newChallenge = this.createChallenge(challenge, world); + manager.loadChallenge(newChallenge, overwrite, user, false); + + if (challenge.getLevel().isEmpty() || challenge.getLevel().equals("FREE")) + { + newChallenge.setLevel(ChallengesManager.FREE); + } + else + { + String levelName = Util.getWorld(world).getName() + "_" + challenge.getLevel(); + + if (this.addon.getChallengesManager().containsLevel(levelName)) + { + manager.addChallengeToLevel(newChallenge, + this.addon.getChallengesManager().getLevel(levelName)); + } + } + } + } + + return true; + } + + + /** + * This method creates new ChallengeLevel based on old level settings. + * @param level Old level object. + * @param world World where new challenge will operate. + * @return New level or null, if old level does not operate in this world. + */ + private ChallengeLevel createLevel(ChallengeLevels level, World world) + { + if (!level.getWorlds().isEmpty() || + !level.getWorlds().contains(Util.getWorld(world).getName())) + { + return null; + } + + ChallengeLevel newLevel = new ChallengeLevel(); + newLevel.setUniqueId(Util.getWorld(world).getName() + "_" + level.getUniqueId()); + newLevel.setFriendlyName(level.getFriendlyName()); + newLevel.setOrder(level.getOrder()); + newLevel.setWorld(Util.getWorld(world).getName()); + + newLevel.setUnlockMessage(level.getUnlockMessage()); + newLevel.setWaiverAmount(level.getWaiveramount()); + + newLevel.setRewardText(level.getRewardDescription()); + newLevel.setRewardMoney(level.getMoneyReward()); + newLevel.setRewardExperience(level.getExpReward()); + newLevel.setRewardItems(level.getRewardItems()); + newLevel.setRewardCommands(level.getRewardCommands()); + + return newLevel; + } + + + /** + * This method creates new Challenge based on old challenges settings. + * @param challenge Old challenges object. + * @param world World where new challenge will operate. + * @return New Challenge or null, if old challenge does not operate in this world. + */ + private Challenge createChallenge(Challenges challenge, World world) + { + if (!challenge.getWorld().equals(Util.getWorld(world).getName())) + { + // Does not operate in given world. + return null; + } + + Challenge newChallenge = new Challenge(); + newChallenge.setUniqueId(challenge.getUniqueId()); + newChallenge.setFriendlyName(challenge.getFriendlyName()); + newChallenge.setRemoveWhenCompleted(challenge.isRemoveWhenCompleted()); + newChallenge.setDeployed(challenge.isDeployed()); + + newChallenge.setEnvironment(new HashSet<>(challenge.getEnvironment())); + + switch (challenge.getChallengeType()) + { + case INVENTORY: + newChallenge.setChallengeType(Challenge.ChallengeType.INVENTORY); + break; + case ISLAND: + newChallenge.setChallengeType(Challenge.ChallengeType.ISLAND); + break; + default: + newChallenge.setChallengeType(Challenge.ChallengeType.OTHER); + break; + } + + newChallenge.setOrder(challenge.getSlot()); + newChallenge.setDescription(challenge.getDescription()); + + newChallenge.setRequiredEntities(challenge.getRequiredEntities()); + newChallenge.setRequiredItems(challenge.getRequiredItems()); + newChallenge.setRequiredBlocks(challenge.getRequiredBlocks()); + newChallenge.setRequiredMoney(challenge.getReqMoney()); + newChallenge.setRequiredExperience(challenge.getReqExp()); + newChallenge.setRequiredIslandLevel(challenge.getReqIslandlevel()); + newChallenge.setRequiredPermissions(challenge.getReqPerms()); + + newChallenge.setTakeMoney(challenge.isTakeMoney()); + newChallenge.setTakeItems(challenge.isTakeItems()); + newChallenge.setSearchRadius(challenge.getSearchRadius()); + + newChallenge.setRewardText(challenge.getRewardText()); + newChallenge.setRewardItems(challenge.getRewardItems()); + newChallenge.setRewardMoney(challenge.getRewardMoney()); + newChallenge.setRewardExperience(challenge.getRewardExp()); + newChallenge.setRewardCommands(challenge.getRewardCommands()); + + newChallenge.setRepeatable(challenge.isRepeatable()); + newChallenge.setMaxTimes(challenge.getMaxTimes()); + + newChallenge.setRepeatRewardText(challenge.getRepeatRewardText()); + newChallenge.setRepeatItemReward(challenge.getRepeatItemReward()); + newChallenge.setRepeatMoneyReward(challenge.getRepeatMoneyReward()); + newChallenge.setRepeatExperienceReward(challenge.getRepeatExpReward()); + newChallenge.setRepeatRewardCommands(challenge.getRepeatRewardCommands()); + + return newChallenge; + } } \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 644e0d0..c5d3ca8 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -56,6 +56,7 @@ public class AdminGUI extends CommonGUI DELETE_CHALLENGE, DELETE_LEVEL, IMPORT_CHALLENGES, + BACKWARD_CHALLENGES, EDIT_SETTINGS } @@ -111,6 +112,7 @@ public class AdminGUI extends CommonGUI // Import Challenges panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES)); + panelBuilder.item(24, this.createButton(Button.BACKWARD_CHALLENGES)); // Edit Addon Settings panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS)); @@ -371,6 +373,23 @@ public class AdminGUI extends CommonGUI break; } + case BACKWARD_CHALLENGES: + { + permissionSuffix = IMPORT; + + name = this.user.getTranslation("challenges.gui.admin.buttons.backward"); + description = Collections.emptyList(); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.addon.getImportManager(). + importPreviousChallenges(this.user, this.world, false); + + return true; + }; + glow = false; + + break; + } case EDIT_SETTINGS: { permissionSuffix = SETTINGS; From 78fccc996e0c92992c00cef34414d6c71f00a788 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 28 Jan 2019 18:15:43 +0200 Subject: [PATCH 3/4] Fix some issues in ImportManager. --- .../challenges/ChallengesImportManager.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index abe5d65..47b86f4 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -229,12 +229,23 @@ public class ChallengesImportManager for (ChallengeLevels level : levels) { - manager.loadLevel(this.createLevel(level, world), overwrite, user, false); + ChallengeLevel newlevel = this.createLevel(level, world); + + if (newlevel != null) + { + manager.loadLevel(newlevel, overwrite, user, false); + } } for (Challenges challenge : challenges) { Challenge newChallenge = this.createChallenge(challenge, world); + + if (newChallenge == null) + { + continue; + } + manager.loadChallenge(newChallenge, overwrite, user, false); if (challenge.getLevel().isEmpty() || challenge.getLevel().equals("FREE")) @@ -266,7 +277,7 @@ public class ChallengesImportManager */ private ChallengeLevel createLevel(ChallengeLevels level, World world) { - if (!level.getWorlds().isEmpty() || + if (!level.getWorlds().isEmpty() && !level.getWorlds().contains(Util.getWorld(world).getName())) { return null; @@ -310,6 +321,7 @@ public class ChallengesImportManager newChallenge.setFriendlyName(challenge.getFriendlyName()); newChallenge.setRemoveWhenCompleted(challenge.isRemoveWhenCompleted()); newChallenge.setDeployed(challenge.isDeployed()); + newChallenge.setIcon(challenge.getIcon()); newChallenge.setEnvironment(new HashSet<>(challenge.getEnvironment())); From 739b1dc2bea58b47424af7c300ec2e4103f7de5a Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 28 Jan 2019 18:17:57 +0200 Subject: [PATCH 4/4] Update Lang file. - Improve import message. - Add backward string. --- src/main/resources/locales/en-US.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index fff97b6..261809b 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -136,7 +136,8 @@ challenges: toggle-users: Choose players type: 'Challenge Type: [value]' waiver-amount: Waiver Amount - import: Import + import: Import from ASkyBlock Challenges + backward: Import from Older ChallengesAddon choose-challenge-title: Challenges List choose-level-title: Levels List choose-user-title: Users List