mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2025-01-02 14:29:01 +01:00
Added surrounding challenge support.
Still a WIP.
This commit is contained in:
parent
51422108c6
commit
22389824a7
@ -1,5 +1,5 @@
|
||||
name: BSkyBlock-Challenges
|
||||
main: bskyblock.addon.challenges.Challenges
|
||||
main: bskyblock.addon.challenges.ChallengesAddon
|
||||
version: 0.1
|
||||
|
||||
authors: [tastybento]
|
||||
|
@ -28,12 +28,13 @@ challenges:
|
||||
completechallenge:
|
||||
challange-completed: "Challenge: [challengename] has been completed for [name]"
|
||||
error:
|
||||
island-level: "Your island must be level [level] to complete this challenge!"
|
||||
items-not-there: "All required items must be close to you on your island!"
|
||||
not-close-enough: "You must be standing within [number] blocks of all required items."
|
||||
island-level: "&cYour island must be level [level] to complete this challenge!"
|
||||
items-not-there: "&cAll required items must be close to you on your island!"
|
||||
not-close-enough: "&cYou must be standing within [number] blocks of all required items."
|
||||
not-enough-items: "&cYou do not have enough [items] to complete this challenge!"
|
||||
not-on-island: "You must be on your island to do that!"
|
||||
reward-problem: "There was a problem giving your reward. Ask Admin to check log!"
|
||||
not-on-island: "&cYou must be on your island to do that!"
|
||||
reward-problem: "&cThere was a problem giving your reward. Ask Admin to check log!"
|
||||
you-still-need: "&cYou still need [amount] x [item]"
|
||||
help:
|
||||
command: "/challenges: &fshow challenges"
|
||||
config-reloaded: "Configuration reloaded from file."
|
||||
|
@ -12,7 +12,7 @@ import us.tastybento.bskyblock.api.addons.Addon;
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class Challenges extends Addon {
|
||||
public class ChallengesAddon extends Addon {
|
||||
|
||||
private ChallengesManager challengesManager;
|
||||
|
@ -18,9 +18,9 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import bskyblock.addon.challenges.database.object.ChallengesData;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesData.ChallengeType;
|
||||
import bskyblock.addon.challenges.database.object.LevelsDO;
|
||||
import bskyblock.addon.challenges.database.object.ChallengeLevels;
|
||||
import bskyblock.addon.challenges.database.object.Challenges;
|
||||
import bskyblock.addon.challenges.database.object.Challenges.ChallengeType;
|
||||
import bskyblock.addon.challenges.panel.ChallengesPanels;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
@ -30,20 +30,23 @@ import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||
public class ChallengesManager {
|
||||
|
||||
//private static final boolean DEBUG = false;
|
||||
private Challenges addon;
|
||||
private LinkedHashMap<LevelsDO, List<ChallengesData>> challengeList;
|
||||
public static final String FREE = "Free";
|
||||
|
||||
private AbstractDatabaseHandler<ChallengesData> chHandler;
|
||||
private AbstractDatabaseHandler<LevelsDO> lvHandler;
|
||||
private ChallengesAddon addon;
|
||||
private LinkedHashMap<ChallengeLevels, List<Challenges>> challengeList;
|
||||
|
||||
private AbstractDatabaseHandler<Challenges> chHandler;
|
||||
private AbstractDatabaseHandler<ChallengeLevels> lvHandler;
|
||||
|
||||
|
||||
private ChallengesPanels challengesPanels;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChallengesManager(Challenges plugin) {
|
||||
public ChallengesManager(ChallengesAddon plugin) {
|
||||
this.addon = plugin;
|
||||
// Set up the database handler to store and retrieve Challenges
|
||||
chHandler = (AbstractDatabaseHandler<ChallengesData>) new FlatFileDatabase().getHandler(ChallengesData.class);
|
||||
lvHandler = (AbstractDatabaseHandler<LevelsDO>) new FlatFileDatabase().getHandler(LevelsDO.class);
|
||||
chHandler = (AbstractDatabaseHandler<Challenges>) new FlatFileDatabase().getHandler(Challenges.class);
|
||||
lvHandler = (AbstractDatabaseHandler<ChallengeLevels>) new FlatFileDatabase().getHandler(ChallengeLevels.class);
|
||||
challengeList = new LinkedHashMap<>();
|
||||
// Start panels
|
||||
challengesPanels = new ChallengesPanels(plugin, this);
|
||||
@ -57,7 +60,7 @@ public class ChallengesManager {
|
||||
return challengesPanels;
|
||||
}
|
||||
|
||||
public AbstractDatabaseHandler<ChallengesData> getHandler() {
|
||||
public AbstractDatabaseHandler<Challenges> getHandler() {
|
||||
return chHandler;
|
||||
}
|
||||
|
||||
@ -68,10 +71,10 @@ public class ChallengesManager {
|
||||
// Load the challenges
|
||||
challengeList.clear();
|
||||
try {
|
||||
for (ChallengesData challenge : chHandler.loadObjects()) {
|
||||
for (Challenges challenge : chHandler.loadObjects()) {
|
||||
Bukkit.getLogger().info("DEBUG: Loading challenge " + challenge.getFriendlyName() + " level " + challenge.getLevel());
|
||||
// See if we have this level already
|
||||
LevelsDO level;
|
||||
ChallengeLevels level;
|
||||
if (lvHandler.objectExists(challenge.getLevel())) {
|
||||
Bukkit.getLogger().info("DEBUG: Level contains level " + challenge.getLevel());
|
||||
// Get it from the database
|
||||
@ -79,7 +82,7 @@ public class ChallengesManager {
|
||||
} else {
|
||||
Bukkit.getLogger().info("DEBUG: Level does not contains level " + challenge.getLevel());
|
||||
// Make it
|
||||
level = new LevelsDO();
|
||||
level = new ChallengeLevels();
|
||||
level.setUniqueId(challenge.getLevel());
|
||||
Bukkit.getLogger().info("DEBUG: Level unique Id set to " + level.getUniqueId());
|
||||
lvHandler.saveObject(level);
|
||||
@ -90,7 +93,7 @@ public class ChallengesManager {
|
||||
} else {
|
||||
Bukkit.getLogger().info("DEBUG: No key found");
|
||||
// First challenge of this level type
|
||||
List<ChallengesData> challenges = new ArrayList<>();
|
||||
List<Challenges> challenges = new ArrayList<>();
|
||||
challenges.add(challenge);
|
||||
challengeList.put(level, challenges);
|
||||
}
|
||||
@ -117,7 +120,7 @@ public class ChallengesManager {
|
||||
public void save(boolean async){
|
||||
if(async){
|
||||
Runnable save = () -> {
|
||||
for (Entry<LevelsDO, List<ChallengesData>> en : challengeList.entrySet()) {
|
||||
for (Entry<ChallengeLevels, List<Challenges>> en : challengeList.entrySet()) {
|
||||
try {
|
||||
lvHandler.saveObject(en.getKey());
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
@ -126,7 +129,7 @@ public class ChallengesManager {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (ChallengesData challenge : en.getValue()) {
|
||||
for (Challenges challenge : en.getValue()) {
|
||||
try {
|
||||
chHandler.saveObject(challenge);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
@ -140,7 +143,7 @@ public class ChallengesManager {
|
||||
};
|
||||
BSkyBlock.getInstance().getServer().getScheduler().runTaskAsynchronously(BSkyBlock.getInstance(), save);
|
||||
} else {
|
||||
for (Entry<LevelsDO, List<ChallengesData>> en : challengeList.entrySet()) {
|
||||
for (Entry<ChallengeLevels, List<Challenges>> en : challengeList.entrySet()) {
|
||||
try {
|
||||
lvHandler.saveObject(en.getKey());
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
@ -149,7 +152,7 @@ public class ChallengesManager {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (ChallengesData challenge : en.getValue()) {
|
||||
for (Challenges challenge : en.getValue()) {
|
||||
try {
|
||||
chHandler.saveObject(challenge);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
@ -199,7 +202,7 @@ public class ChallengesManager {
|
||||
meta.setDisplayName(name);
|
||||
meta.setLore(lore);
|
||||
icon.setItemMeta(meta);
|
||||
ChallengesData newChallenge = new ChallengesData();
|
||||
Challenges newChallenge = new Challenges();
|
||||
newChallenge.setRequiredItems(contents);
|
||||
newChallenge.setUniqueId(name);
|
||||
newChallenge.setIcon(icon);
|
||||
@ -226,8 +229,8 @@ public class ChallengesManager {
|
||||
* @param level - the level required
|
||||
* @return the list of challenges for this level, or the first set of challenges if level is blank, or a blank list if there are no challenges
|
||||
*/
|
||||
public List<ChallengesData> getChallenges(String level) {
|
||||
return challengeList.getOrDefault(level, challengeList.isEmpty() ? new ArrayList<ChallengesData>() : challengeList.values().iterator().next());
|
||||
public List<Challenges> getChallenges(String level) {
|
||||
return challengeList.getOrDefault(level, challengeList.isEmpty() ? new ArrayList<Challenges>() : challengeList.values().iterator().next());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,15 +244,15 @@ public class ChallengesManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLevelComplete(User user, LevelsDO otherLevel) {
|
||||
public boolean isLevelComplete(User user, ChallengeLevels otherLevel) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
public LevelsDO getPreviousLevel(LevelsDO otherLevel) {
|
||||
LevelsDO result = null;
|
||||
public ChallengeLevels getPreviousLevel(ChallengeLevels otherLevel) {
|
||||
ChallengeLevels result = null;
|
||||
|
||||
for (LevelsDO level : challengeList.keySet()) {
|
||||
for (ChallengeLevels level : challengeList.keySet()) {
|
||||
if (level.equals(otherLevel)) {
|
||||
return result;
|
||||
}
|
||||
@ -265,8 +268,8 @@ public class ChallengesManager {
|
||||
*/
|
||||
public List<LevelStatus> getChallengeLevelStatus(User user) {
|
||||
List<LevelStatus> result = new ArrayList<>();
|
||||
LevelsDO previousLevel = null;
|
||||
for (Entry<LevelsDO, List<ChallengesData>> en : challengeList.entrySet()) {
|
||||
ChallengeLevels previousLevel = null;
|
||||
for (Entry<ChallengeLevels, List<Challenges>> en : challengeList.entrySet()) {
|
||||
int challsToDo = 0; // TODO - calculate how many challenges still to do for this player
|
||||
boolean complete = false; // TODO
|
||||
result.add(new LevelStatus(en.getKey(), previousLevel, challsToDo, complete));
|
||||
@ -275,12 +278,12 @@ public class ChallengesManager {
|
||||
}
|
||||
|
||||
public class LevelStatus {
|
||||
private final LevelsDO level;
|
||||
private final LevelsDO previousLevel;
|
||||
private final ChallengeLevels level;
|
||||
private final ChallengeLevels previousLevel;
|
||||
private final int numberOfChallengesStillToDo;
|
||||
private final boolean complete;
|
||||
|
||||
public LevelStatus(LevelsDO level, LevelsDO previousLevel, int numberOfChallengesStillToDo, boolean complete) {
|
||||
public LevelStatus(ChallengeLevels level, ChallengeLevels previousLevel, int numberOfChallengesStillToDo, boolean complete) {
|
||||
super();
|
||||
this.level = level;
|
||||
this.previousLevel = previousLevel;
|
||||
@ -290,13 +293,13 @@ public class ChallengesManager {
|
||||
/**
|
||||
* @return the level
|
||||
*/
|
||||
public LevelsDO getLevel() {
|
||||
public ChallengeLevels getLevel() {
|
||||
return level;
|
||||
}
|
||||
/**
|
||||
* @return the previousLevel
|
||||
*/
|
||||
public LevelsDO getPreviousLevel() {
|
||||
public ChallengeLevels getPreviousLevel() {
|
||||
return previousLevel;
|
||||
}
|
||||
/**
|
||||
@ -324,7 +327,7 @@ public class ChallengesManager {
|
||||
if (inventory.getContents().length == 0) {
|
||||
return;
|
||||
}
|
||||
ChallengesData newChallenge = new ChallengesData();
|
||||
Challenges newChallenge = new Challenges();
|
||||
newChallenge.setChallengeType(ChallengeType.INVENTORY);
|
||||
newChallenge.setFriendlyName(inventory.getTitle());
|
||||
newChallenge.setDeployed(false);
|
||||
@ -339,7 +342,7 @@ public class ChallengesManager {
|
||||
newChallenge.setUniqueId(inventory.getTitle());
|
||||
newChallenge.setIcon(new ItemStack(Material.EMPTY_MAP));
|
||||
newChallenge.setFreeChallenge(true);
|
||||
newChallenge.setLevel("");
|
||||
newChallenge.setLevel(FREE);
|
||||
|
||||
// Move all the items back to the player's inventory
|
||||
inventory.forEach(item -> {
|
||||
@ -371,13 +374,48 @@ public class ChallengesManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
public long checkChallengeTimes(User user, ChallengesData challenge) {
|
||||
public long checkChallengeTimes(User user, Challenges challenge) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Challenges getAddon() {
|
||||
public ChallengesAddon getAddon() {
|
||||
return addon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the challenge as complete and increments the number of times it has been completed
|
||||
* @param user
|
||||
* @param uniqueId
|
||||
*/
|
||||
public void setChallengeComplete(User user, String uniqueId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void createSurroundingChallenge(String string, Map<Material, Integer> map) {
|
||||
if (map.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Challenges newChallenge = new Challenges();
|
||||
newChallenge.setChallengeType(ChallengeType.SURROUNDING);
|
||||
newChallenge.setFriendlyName(string);
|
||||
newChallenge.setDeployed(true);
|
||||
newChallenge.setRequiredBlocks(map);
|
||||
newChallenge.setUniqueId(string);
|
||||
newChallenge.setIcon(new ItemStack(Material.ARMOR_STAND));
|
||||
newChallenge.setFreeChallenge(true);
|
||||
newChallenge.setLevel(FREE);
|
||||
|
||||
// Save the challenge
|
||||
try {
|
||||
chHandler.saveObject(newChallenge);
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
|
||||
| InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,16 +2,16 @@ package bskyblock.addon.challenges.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
public class ChallengesCommand extends CompositeCommand {
|
||||
private static final String CHALLENGE_COMMAND = "challenges";
|
||||
private Challenges addon;
|
||||
private ChallengesAddon addon;
|
||||
|
||||
public ChallengesCommand(Challenges addon) {
|
||||
public ChallengesCommand(ChallengesAddon addon) {
|
||||
super(CHALLENGE_COMMAND, "c", "challenge");
|
||||
this.addon = addon;
|
||||
// Set up commands
|
||||
|
@ -2,16 +2,16 @@ package bskyblock.addon.challenges.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
public class ChallengesAdminCommand extends CompositeCommand {
|
||||
private static final String CHALLENGE_ADMIN_COMMAND = "cadmin";
|
||||
private Challenges addon;
|
||||
private ChallengesAddon addon;
|
||||
|
||||
public ChallengesAdminCommand(Challenges addon) {
|
||||
public ChallengesAdminCommand(ChallengesAddon addon) {
|
||||
super(CHALLENGE_ADMIN_COMMAND);
|
||||
this.addon = addon;
|
||||
// Set up create command
|
||||
@ -37,5 +37,4 @@ public class ChallengesAdminCommand extends CompositeCommand {
|
||||
this.setOnlyPlayer(true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package bskyblock.addon.challenges.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import bskyblock.addon.challenges.panel.CreateChallengeListener;
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
@ -12,15 +12,17 @@ import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||
public class CreateChallenge extends CompositeCommand {
|
||||
|
||||
|
||||
private Challenges addon;
|
||||
private ChallengesAddon addon;
|
||||
|
||||
/**
|
||||
* Admin command to make challenges
|
||||
* @param parent
|
||||
*/
|
||||
public CreateChallenge(Challenges addon, CompositeCommand parent) {
|
||||
public CreateChallenge(ChallengesAddon addon, CompositeCommand parent) {
|
||||
super(parent, "create");
|
||||
this.addon = addon;
|
||||
new CreateSurrounding(addon, this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,6 +31,7 @@ public class CreateChallenge extends CompositeCommand {
|
||||
this.setPermission(Constants.PERMPREFIX + "admin.challenges");
|
||||
this.setParameters("challaneges.admin.create.parameters");
|
||||
this.setDescription("challenges.admin.create.description");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,99 @@
|
||||
package bskyblock.addon.challenges.commands.admin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
public class CreateSurrounding extends CompositeCommand implements Listener {
|
||||
|
||||
|
||||
private ChallengesAddon addon;
|
||||
private Map<UUID, Map<Material, Integer>> blocks = new HashMap<>();
|
||||
private Map<UUID, String> name = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Admin command to make surrounding challenges
|
||||
* @param parent
|
||||
*/
|
||||
public CreateSurrounding(ChallengesAddon addon, CompositeCommand parent) {
|
||||
super(parent, "surrounding");
|
||||
this.addon = addon;
|
||||
addon.getServer().getPluginManager().registerEvents(this, addon.getBSkyBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setOnlyPlayer(true);
|
||||
this.setPermission(Constants.PERMPREFIX + "admin.challenges");
|
||||
this.setParameters("challaneges.admin.create.surrounding.parameters");
|
||||
this.setDescription("challenges.admin.create.surrounding.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
user.sendRawMessage("not enough args");
|
||||
return false;
|
||||
}
|
||||
// Tell user to hit objects to add to the surrounding object requirements
|
||||
user.sendRawMessage("Hit things to add them to the list of things required. Right click when done");
|
||||
blocks.computeIfAbsent(user.getUniqueId(), k -> new HashMap<>());
|
||||
name.put(user.getUniqueId(), args.get(0));
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
if (blocks.containsKey(e.getPlayer().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
blocks.remove(e.getPlayer().getUniqueId());
|
||||
name.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
|
||||
addon.getLogger().info("DEBUG: left click");
|
||||
if (blocks.containsKey(e.getPlayer().getUniqueId())) {
|
||||
// Prevent damage
|
||||
e.setCancelled(true);
|
||||
Map<Material, Integer> blockMap = blocks.get(e.getPlayer().getUniqueId());
|
||||
blockMap.computeIfPresent(e.getClickedBlock().getType(), (state, amount) -> amount++);
|
||||
blockMap.putIfAbsent(e.getClickedBlock().getType(), 1);
|
||||
blocks.put(e.getPlayer().getUniqueId(), blockMap);
|
||||
User.getInstance(e.getPlayer()).sendRawMessage("You added one " + e.getClickedBlock().getType());
|
||||
return;
|
||||
};
|
||||
}
|
||||
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
addon.getLogger().info("DEBUG: right click");
|
||||
if (blocks.containsKey(e.getPlayer().getUniqueId())) {
|
||||
e.setCancelled(true);
|
||||
User.getInstance(e.getPlayer()).sendRawMessage("Finished!");
|
||||
addon.getChallengesManager().createSurroundingChallenge(name.get(e.getPlayer().getUniqueId()), blocks.get(e.getPlayer().getUniqueId()));
|
||||
blocks.remove(e.getPlayer().getUniqueId());
|
||||
name.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package bskyblock.addon.challenges.config;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
|
||||
public class PluginConfig {
|
||||
|
||||
/**
|
||||
* Loads the various settings from the config.yml file into the plugin
|
||||
*/
|
||||
public PluginConfig(Challenges plugin) {
|
||||
public PluginConfig(ChallengesAddon plugin) {
|
||||
plugin.saveDefaultConfig();
|
||||
|
||||
// Settings
|
||||
|
@ -3,9 +3,10 @@ package bskyblock.addon.challenges.database.object;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import bskyblock.addon.challenges.ChallengesManager;
|
||||
import us.tastybento.bskyblock.database.objects.DataObject;
|
||||
|
||||
public class LevelsDO implements DataObject, Comparable<LevelsDO> {
|
||||
public class ChallengeLevels implements DataObject, Comparable<ChallengeLevels> {
|
||||
|
||||
/**
|
||||
* A friendly name for the level. If blank, level name is used.
|
||||
@ -18,7 +19,7 @@ public class LevelsDO implements DataObject, Comparable<LevelsDO> {
|
||||
/**
|
||||
* Level name
|
||||
*/
|
||||
private String uniqueId = "Free";
|
||||
private String uniqueId = ChallengesManager.FREE;
|
||||
/**
|
||||
* The number of undone challenges that can be left on this level before unlocking next level
|
||||
*/
|
||||
@ -72,7 +73,7 @@ public class LevelsDO implements DataObject, Comparable<LevelsDO> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(LevelsDO o) {
|
||||
public int compareTo(ChallengeLevels o) {
|
||||
return Integer.compare(this.order, o.order);
|
||||
}
|
||||
|
||||
@ -98,10 +99,10 @@ public class LevelsDO implements DataObject, Comparable<LevelsDO> {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof LevelsDO)) {
|
||||
if (!(obj instanceof ChallengeLevels)) {
|
||||
return false;
|
||||
}
|
||||
LevelsDO other = (LevelsDO) obj;
|
||||
ChallengeLevels other = (ChallengeLevels) obj;
|
||||
if (uniqueId == null) {
|
||||
if (other.uniqueId != null) {
|
||||
return false;
|
@ -1,16 +1,20 @@
|
||||
package bskyblock.addon.challenges.database.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bskyblock.addon.challenges.ChallengesManager;
|
||||
import us.tastybento.bskyblock.database.objects.DataObject;
|
||||
|
||||
public class ChallengesData implements DataObject {
|
||||
public class Challenges implements DataObject {
|
||||
|
||||
public enum ChallengeType {
|
||||
/**
|
||||
@ -31,6 +35,11 @@ public class ChallengesData implements DataObject {
|
||||
SURROUNDING
|
||||
}
|
||||
|
||||
/**
|
||||
* Required blocks for SURROUNDING challenges
|
||||
*/
|
||||
private Map<Material, Integer> requiredBlocks;
|
||||
|
||||
/**
|
||||
* Type of challenge
|
||||
*/
|
||||
@ -62,7 +71,7 @@ public class ChallengesData implements DataObject {
|
||||
/**
|
||||
* The challenge level. Default is Free
|
||||
*/
|
||||
private String level = "Free";
|
||||
private String level = ChallengesManager.FREE;
|
||||
/**
|
||||
* Maximum number of times the challenge can be repeated
|
||||
*/
|
||||
@ -118,7 +127,11 @@ public class ChallengesData implements DataObject {
|
||||
/**
|
||||
* The items that must be in the inventory to complete the challenge.
|
||||
*/
|
||||
private List<ItemStack> requiredItems = new ArrayList<>();
|
||||
private List<ItemStack> requiredItems = new ArrayList<>();
|
||||
/**
|
||||
* Any entities that must be in the area for SURROUNDING type challenges
|
||||
*/
|
||||
private Map<EntityType, Integer> requiredEntities = new HashMap<>();
|
||||
/**
|
||||
* Commands to run when the player completes the challenge for the first time
|
||||
*/
|
||||
@ -263,6 +276,9 @@ public class ChallengesData implements DataObject {
|
||||
* @param level the level to set
|
||||
*/
|
||||
public void setLevel(String level) {
|
||||
if (level.isEmpty()) {
|
||||
level = ChallengesManager.FREE;
|
||||
}
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@ -462,6 +478,34 @@ public class ChallengesData implements DataObject {
|
||||
this.requiredItems = requiredItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return requiredEntities
|
||||
*/
|
||||
public Map<EntityType, Integer> getRequiredEntities() {
|
||||
return requiredEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param requiredEntities the requiredEntities to set
|
||||
*/
|
||||
public void setRequiredEntities(Map<EntityType, Integer> requiredEntities) {
|
||||
this.requiredEntities = requiredEntities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the requiredBlocks
|
||||
*/
|
||||
public Map<Material, Integer> getRequiredBlocks() {
|
||||
return requiredBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param map the requiredBlocks to set
|
||||
*/
|
||||
public void setRequiredBlocks(Map<Material, Integer> map) {
|
||||
this.requiredBlocks = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rewardCommands
|
||||
*/
|
@ -7,11 +7,11 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import bskyblock.addon.challenges.ChallengesManager;
|
||||
import bskyblock.addon.challenges.ChallengesManager.LevelStatus;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesData;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesData.ChallengeType;
|
||||
import bskyblock.addon.challenges.database.object.Challenges;
|
||||
import bskyblock.addon.challenges.database.object.Challenges.ChallengeType;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.panels.ClickType;
|
||||
import us.tastybento.bskyblock.api.panels.Panel;
|
||||
@ -22,10 +22,10 @@ import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
|
||||
public class ChallengesPanels {
|
||||
private static final boolean DEBUG = true;
|
||||
private Challenges addon;
|
||||
private ChallengesAddon addon;
|
||||
private ChallengesManager manager;
|
||||
|
||||
public ChallengesPanels(Challenges plugin, ChallengesManager manager){
|
||||
public ChallengesPanels(ChallengesAddon plugin, ChallengesManager manager){
|
||||
this.addon = plugin;
|
||||
this.manager = manager;
|
||||
}
|
||||
@ -73,13 +73,13 @@ public class ChallengesPanels {
|
||||
|
||||
private void addChallengeItems(PanelBuilder panelBuilder, User user, String level) {
|
||||
|
||||
List<ChallengesData> levelChallenges = manager.getChallenges(level);
|
||||
List<Challenges> levelChallenges = manager.getChallenges(level);
|
||||
// Do some checking
|
||||
if (DEBUG)
|
||||
addon.getLogger().info("DEBUG: Opening level " + level + " with " + levelChallenges.size() + " challenges");
|
||||
|
||||
// Only show a control panel for the level requested.
|
||||
for (ChallengesData challenge : levelChallenges) {
|
||||
for (Challenges challenge : levelChallenges) {
|
||||
addon.getLogger().info("DEBUG: Adding challenge " + challenge.getUniqueId());
|
||||
// Check completion
|
||||
boolean completed = manager.isChallengeComplete(user, challenge.getUniqueId());
|
||||
|
@ -4,16 +4,16 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.panels.PanelListener;
|
||||
|
||||
public class CreateChallengeListener implements PanelListener {
|
||||
|
||||
private Challenges addon;
|
||||
private ChallengesAddon addon;
|
||||
private User user;
|
||||
|
||||
public CreateChallengeListener(Challenges addon, User user) {
|
||||
public CreateChallengeListener(ChallengesAddon addon, User user) {
|
||||
this.addon = addon;
|
||||
this.user = user;
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
package bskyblock.addon.challenges.panel;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||
|
||||
public class CreateChallengePanel {
|
||||
|
||||
public CreateChallengePanel(Challenges addon, User user) {
|
||||
public CreateChallengePanel(ChallengesAddon addon, User user) {
|
||||
new PanelBuilder().setSize(49).setListener(new CreateChallengeListener(addon, user)).setUser(user).build();
|
||||
}
|
||||
|
||||
|
@ -4,15 +4,21 @@
|
||||
package bskyblock.addon.challenges.panel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesAddon;
|
||||
import bskyblock.addon.challenges.ChallengesManager;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesData;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesData.ChallengeType;
|
||||
import bskyblock.addon.challenges.database.object.Challenges;
|
||||
import bskyblock.addon.challenges.database.object.Challenges.ChallengeType;
|
||||
import bskyblock.addon.level.Level;
|
||||
import us.tastybento.bskyblock.Constants;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
@ -25,9 +31,9 @@ import us.tastybento.bskyblock.util.Util;
|
||||
*/
|
||||
public class TryToComplete {
|
||||
|
||||
private Challenges addon;
|
||||
private ChallengesAddon addon;
|
||||
|
||||
public TryToComplete(Challenges addon, User user, ChallengesManager manager, ChallengesData challenge) {
|
||||
public TryToComplete(ChallengesAddon addon, User user, ChallengesManager manager, Challenges challenge) {
|
||||
this.addon = addon;
|
||||
Bukkit.getLogger().info("DEBUG: try to complete");
|
||||
// Check if user is in the worlds
|
||||
@ -68,13 +74,14 @@ public class TryToComplete {
|
||||
runCommands(user, challenge.getRepeatRewardCommands());
|
||||
user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName());
|
||||
}
|
||||
|
||||
// Market as complete
|
||||
manager.setChallengeComplete(user, challenge.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a challenge can be completed or not
|
||||
*/
|
||||
private ChallengeResult checkIfCanCompleteChallenge(User user, ChallengesManager manager, ChallengesData challenge) {
|
||||
private ChallengeResult checkIfCanCompleteChallenge(User user, ChallengesManager manager, Challenges challenge) {
|
||||
// Check if user has the
|
||||
if (!challenge.isFreeChallenge() && !manager.isLevelAvailable(user, challenge.getLevel())) {
|
||||
user.sendMessage("challenges.errors.challenge-level-not-available");
|
||||
@ -109,7 +116,7 @@ public class TryToComplete {
|
||||
}
|
||||
}
|
||||
|
||||
private ChallengeResult checkInventory(User user, ChallengesManager manager, ChallengesData challenge) {
|
||||
private ChallengeResult checkInventory(User user, ChallengesManager manager, Challenges challenge) {
|
||||
Bukkit.getLogger().info("DEBUG: Checking inventory");
|
||||
// Run through inventory
|
||||
List<ItemStack> required = new ArrayList<>(challenge.getRequiredItems());
|
||||
@ -131,19 +138,71 @@ public class TryToComplete {
|
||||
return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge.getUniqueId()));
|
||||
}
|
||||
|
||||
private ChallengeResult checkLevel(User user, ChallengesManager manager, ChallengesData challenge) {
|
||||
private ChallengeResult checkLevel(User user, ChallengesManager manager, Challenges challenge) {
|
||||
// Check if the level addon is installed or not
|
||||
return addon.getAddonByName("BSkyBlock-Level").map(l -> {
|
||||
return ((Level)l).getIslandLevel(user.getUniqueId()) >= challenge.getReqIslandlevel() ?
|
||||
new ChallengeResult().setMeetsRequirements() : new ChallengeResult();
|
||||
new ChallengeResult().setMeetsRequirements() : new ChallengeResult();
|
||||
}).orElse(new ChallengeResult());
|
||||
}
|
||||
|
||||
private ChallengeResult checkSurrounding(User user, ChallengesManager manager, ChallengesData challenge) {
|
||||
// TODO Auto-generated method stub
|
||||
private ChallengeResult checkSurrounding(User user, ChallengesManager manager, Challenges challenge) {
|
||||
if (!addon.getIslands().playerIsOnIsland(user)) {
|
||||
// Player is not on island
|
||||
user.sendMessage("challenges.error.not-on-island");
|
||||
return new ChallengeResult();
|
||||
}
|
||||
// Check for items or entities in the area
|
||||
ChallengeResult result = searchForEntities(user, challenge.getRequiredEntities(), challenge.getSearchRadius());
|
||||
if (result.meetsRequirements) {
|
||||
// Search for items only if entities found
|
||||
result = searchForBlocks(user, challenge.getRequiredBlocks(), challenge.getSearchRadius());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ChallengeResult searchForBlocks(User user, Map<Material, Integer> map, int searchRadius) {
|
||||
Map<Material, Integer> blocks = new HashMap<>(map);
|
||||
addon.getLogger().info("Size of blocks = " + blocks.size());
|
||||
for (int x = -searchRadius; x <= searchRadius; x++) {
|
||||
for (int y = -searchRadius; y <= searchRadius; y++) {
|
||||
for (int z = -searchRadius; z <= searchRadius; z++) {
|
||||
Material mat = user.getWorld().getBlockAt(user.getLocation().add(new Vector(x,y,z))).getType();
|
||||
// Remove one
|
||||
blocks.computeIfPresent(mat, (b, amount) -> amount-1);
|
||||
// Remove any that have an amount of 0
|
||||
blocks.entrySet().removeIf(en -> en.getValue() <= 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (blocks.isEmpty()) {
|
||||
return new ChallengeResult().setMeetsRequirements();
|
||||
}
|
||||
user.sendMessage("challenges.error.not-close-enough", "[number]", String.valueOf(searchRadius));
|
||||
blocks.forEach((k,v) -> user.sendMessage("challenges.error.you-still-need",
|
||||
"[amount]", String.valueOf(v),
|
||||
"[item]", Util.prettifyText(k.toString())));
|
||||
|
||||
return new ChallengeResult();
|
||||
}
|
||||
|
||||
private ChallengeResult searchForEntities(User user, Map<EntityType, Integer> map, int searchRadius) {
|
||||
Map<EntityType, Integer> entities = new HashMap<>(map);
|
||||
user.getPlayer().getNearbyEntities(searchRadius, searchRadius, searchRadius).forEach(entity -> {
|
||||
// Look through all the nearby Entities, filtering by type
|
||||
entities.computeIfPresent(entity.getType(), (reqEntity, amount) -> amount--);
|
||||
entities.entrySet().removeIf(e -> e.getValue() == 0);
|
||||
});
|
||||
if (entities.isEmpty()) {
|
||||
return new ChallengeResult().setMeetsRequirements();
|
||||
}
|
||||
entities.forEach((reqEnt, amount) -> user.sendMessage("challenges.error.you-still-need",
|
||||
"[amount]", String.valueOf(amount),
|
||||
"[item]", Util.prettifyText(reqEnt.toString())));
|
||||
return new ChallengeResult();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contains flags on completion of challenge
|
||||
* @author tastybento
|
||||
|
Loading…
Reference in New Issue
Block a user