mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 05:25:21 +01:00
A good start(tm). It compiles and registers commands.
Now for the hard work to begin.
This commit is contained in:
parent
3b74b17283
commit
a9707b2925
@ -1,18 +1,9 @@
|
||||
name: BSkyBlock-Challenges
|
||||
main: bskyblock.addin.challenges.Challenges
|
||||
main: bskyblock.addon.challenges.Challenges
|
||||
version: 0.1
|
||||
|
||||
authors: [tastybento]
|
||||
|
||||
depend: [BSkyBlock]
|
||||
|
||||
commands:
|
||||
challenges:
|
||||
description: Game challenges
|
||||
aliases: [c, challenge]
|
||||
usage: |
|
||||
/challenges
|
||||
|
||||
permissions:
|
||||
bskyblock.island.challenges:
|
||||
description: Let the player use the /challenges command
|
313
config.yml
313
config.yml
@ -1,305 +1,16 @@
|
||||
# This file lists the values for various blocks that are used to calculate the
|
||||
# island level. Level = total of all blocks in island boundary / 100.
|
||||
# Players with the permission askyblock.island.multiplier.# will have their blocks
|
||||
# multiplied in value by that amount.
|
||||
# Challenges Config
|
||||
|
||||
# Underwater block multiplier
|
||||
# If blocks are below sea-level, they can have a higher value. e.g. 2x
|
||||
# Promotes under-water development if there is a sea. Value can be fractional.
|
||||
underwater: 1.0
|
||||
# Reset Challenges - if this is true, player's challenges will reset when they
|
||||
# reset an island or if they are kicked or leave a team. Prevents exploiting the
|
||||
# challenges by doing them repeatedly.
|
||||
resetchallenges: false
|
||||
|
||||
# Value of one island level. Default 100. Minimum value is 1.
|
||||
levelcost: 100
|
||||
# Broadcast 1st time challenge completion messages to all players.
|
||||
# Change to false if the spam becomes too much.
|
||||
broadcastmessages: true
|
||||
|
||||
# Cooldown between level requests in seconds
|
||||
levelwait: 60
|
||||
|
||||
# Death penalty
|
||||
# How many block values a player will lose per death.
|
||||
# Default value of 100 means that for every death, the player will lose 1 level (if levelcost is 100)
|
||||
# Set to zero to not use this feature
|
||||
deathpenalty: 100
|
||||
# Sum team deaths - if true, all the teams deaths are summed
|
||||
# If false, only the leader's deaths counts
|
||||
sumteamdeaths: false
|
||||
# Max deaths
|
||||
# If player dies more than this, it doesn't count anymore
|
||||
# Stops players from getting into an impossible situation
|
||||
maxdeaths: 10
|
||||
# Reset deaths on island reset
|
||||
islandresetdeathreset: true
|
||||
# Reset deaths on team join
|
||||
teamjoindeathreset: true
|
||||
|
||||
|
||||
# This section lists the limits for any particular block. Blocks over this amount
|
||||
# are not counted.
|
||||
# Format:
|
||||
# MATERIAL: limit or MATERIAL:DATA: limit.
|
||||
# If DATA is used, there MUST be a corresponding block:data value in the blocks list.
|
||||
# For example, if you limit Jungle Logs LOG:3, then there must be a value for LOG:3
|
||||
# in the blocks section. If there is not, then LOG:3 would have no value.
|
||||
limits:
|
||||
COBBLESTONE: 10000
|
||||
NETHERRACK: 1000
|
||||
#LOG:3: 10
|
||||
|
||||
# This section lists the value of a block. Value must be an integer.
|
||||
# Any blocks not listed will have a value of zero.
|
||||
# Format is MATERIAL: value or MATERIAL:DATA: value.
|
||||
|
||||
blocks:
|
||||
ACACIA_DOOR: 1
|
||||
ACACIA_STAIRS: 1
|
||||
ACACIA_FENCE: 1
|
||||
ACACIA_FENCE_GATE: 1
|
||||
ACACIA_STAIRS: 2
|
||||
ACTIVATOR_RAIL: 10
|
||||
AIR: 0
|
||||
ANVIL: 10
|
||||
ARMOR_STAND: 2
|
||||
BANNER: 2
|
||||
BEACON: 100
|
||||
BED_BLOCK: 1
|
||||
BEDROCK: 0
|
||||
BEETROOT_BLOCK: 1
|
||||
BIRCH_DOOR: 1
|
||||
BIRCH_FENCE: 1
|
||||
BIRCH_FENCE_GATE: 1
|
||||
BIRCH_WOOD_STAIRS: 1
|
||||
BLACK_GLAZED_TERRACOTTA: 1
|
||||
BLACK_SHULKER_BOX: 1
|
||||
BLUE_GLAZED_TERRACOTTA: 1
|
||||
BLUE_SHULKER_BOX: 1
|
||||
BOAT: 2
|
||||
BOAT_ACACIA: 2
|
||||
BOAT_BIRCH: 2
|
||||
BOAT_DARK_OAK: 2
|
||||
BOAT_JUNGLE: 2
|
||||
BOAT_SPRUCE: 2
|
||||
BONE_BLOCK: 1
|
||||
BOOKSHELF: 5
|
||||
BREWING_STAND: 20
|
||||
BRICK: 5
|
||||
BRICK_STAIRS: 5
|
||||
BROWN_GLAZED_TERRACOTTA: 1
|
||||
BROWN_SHULKER_BOX: 1
|
||||
BURNING_FURNACE: 10
|
||||
CACTUS: 1
|
||||
CAKE_BLOCK: 1
|
||||
CARPET: 1
|
||||
CAULDRON: 10
|
||||
CHEST: 2
|
||||
CHORUS_FLOWER: 1
|
||||
CHORUS_PLANT: 1
|
||||
CLAY: 2
|
||||
COAL_BLOCK: 9
|
||||
COAL_ORE: 0
|
||||
COBBLE_WALL: 1
|
||||
COBBLESTONE: 1
|
||||
COBBLESTONE_STAIRS: 1
|
||||
COCOA: 1
|
||||
CONCRETE: 1
|
||||
CONCRETE_POWDER: 1
|
||||
CYAN_GLAZED_TERRACOTTA: 1
|
||||
CYAN_SHULKER_BOX: 1
|
||||
DARK_OAK_DOOR: 1
|
||||
DARK_OAK_FENCE: 1
|
||||
DARK_OAK_FENCE_GATE: 1
|
||||
DARK_OAK_STAIRS: 1
|
||||
DAYLIGHT_DETECTOR: 10
|
||||
DAYLIGHT_DETECTOR_INVERTED: 10
|
||||
DEAD_BUSH: 1
|
||||
DETECTOR_RAIL: 10
|
||||
DIAMOND_BLOCK: 300
|
||||
DIODE: 5
|
||||
DIODE_BLOCK_OFF: 5
|
||||
DIODE_BLOCK_ON: 5
|
||||
DIRT: 2
|
||||
DISPENSER: 5
|
||||
DOUBLE_PLANT: 2
|
||||
DOUBLE_STEP: 1
|
||||
DOUBLE_STONE_SLAB2: 1
|
||||
DRAGON_EGG: 150
|
||||
DROPPER: 5
|
||||
EMERALD_BLOCK: 150
|
||||
EMERALD_ORE: 0
|
||||
ENCHANTMENT_TABLE: 150
|
||||
END_BRICKS: 2
|
||||
ENDER_CHEST: 150
|
||||
ENDER_PORTAL_FRAME: 0
|
||||
ENDER_PORTAL: 0
|
||||
ENDER_STONE: 2
|
||||
EXPLOSIVE_MINECART: 10
|
||||
FENCE: 1
|
||||
FENCE_GATE: 1
|
||||
FIRE: 0
|
||||
FLOWER_POT: 5
|
||||
FROSTED_ICE: 1
|
||||
FURNACE: 10
|
||||
GLASS: 2
|
||||
GLOWSTONE: 1
|
||||
GOLD_BLOCK: 150
|
||||
GOLD_ORE: 0
|
||||
GRASS: 5
|
||||
GRASS_PATH: 5
|
||||
GRAY_GLAZED_TERRACOTTA: 1
|
||||
GRAY_SHULKER_BOX: 1
|
||||
GRAVEL: 1
|
||||
GREEN_GLAZED_TERRACOTTA: 1
|
||||
GREEN_SHULKER_BOX: 1
|
||||
HARD_CLAY: 2
|
||||
HAY_BLOCK: 2
|
||||
HOPPER: 10
|
||||
HOPPER_MINECART: 20
|
||||
HUGE_MUSHROOM_1: 1
|
||||
HUGE_MUSHROOM_2: 1
|
||||
ICE: 5
|
||||
IRON_BLOCK: 10
|
||||
IRON_DOOR_BLOCK: 5
|
||||
IRON_FENCE: 5
|
||||
IRON_ORE: 0
|
||||
IRON_PLATE: 5
|
||||
IRON_TRAPDOOR: 1
|
||||
ITEM_FRAME: 2
|
||||
JACK_O_LANTERN: 1
|
||||
JUKEBOX: 10
|
||||
JUNGLE_DOOR: 1
|
||||
JUNGLE_FENCE: 1
|
||||
JUNGLE_FENCE_GATE: 1
|
||||
JUNGLE_WOOD_STAIRS: 1
|
||||
LADDER: 1
|
||||
LAPIS_BLOCK: 10
|
||||
LAPIS_ORE: 0
|
||||
LAVA: 0
|
||||
LEAVES_2: 1
|
||||
LEAVES: 1
|
||||
LEVER: 1
|
||||
LIGHT_BLUE_GLAZED_TERRACOTTA: 1
|
||||
LIGHT_BLUE_SHULKER_BOX: 1
|
||||
LIME_GLAZED_TERRACOTTA: 1
|
||||
LIME_SHULKER_BOX: 1
|
||||
LOG: 1
|
||||
#Other log types - examples
|
||||
#LOG:3: 2
|
||||
LOG_2: 1
|
||||
LONG_GRASS: 1
|
||||
MAGENTA_GLAZED_TERRACOTTA: 1
|
||||
MAGENTA_SHULKER_BOX: 1
|
||||
MAGMA: 1
|
||||
MELON_BLOCK: 1
|
||||
MELON_STEM: 1
|
||||
MINECART: 10
|
||||
MOB_SPAWNER: 0
|
||||
MOSSY_COBBLESTONE: 2
|
||||
MYCEL: 5
|
||||
NETHER_BRICK: 2
|
||||
NETHER_BRICK_STAIRS: 2
|
||||
NETHER_FENCE: 2
|
||||
NETHER_STALK: 1
|
||||
NETHER_WART_BLOCK: 2
|
||||
NETHERRACK: 1
|
||||
NOTE_BLOCK: 10
|
||||
OBSERVER: 1
|
||||
OBSIDIAN: 10
|
||||
ORANGE_GLAZED_TERRACOTTA: 1
|
||||
ORANGE_SHULKER_BOX: 1
|
||||
PACKED_ICE: 5
|
||||
PAINTING: 2
|
||||
PINK_GLAZED_TERRACOTTA: 1
|
||||
PINK_SHULKER_BOX: 1
|
||||
PISTON_BASE: 2
|
||||
PISTON_STICKY_BASE: 2
|
||||
PORTAL: 0
|
||||
POWERED_MINECART: 10
|
||||
POWERED_RAIL: 10
|
||||
PRISMARINE: 10
|
||||
PUMPKIN_STEM: 1
|
||||
PUMPKIN: 1
|
||||
PURPLE_GLAZED_TERRACOTTA: 1
|
||||
PURPLE_SHULKER_BOX: 1
|
||||
PURPUR_BLOCK: 1
|
||||
PURPUR_DOUBLE_SLAB: 1
|
||||
PURPUR_PILLAR: 1
|
||||
PURPUR_SLAB: 1
|
||||
PURPUR_STAIRS: 1
|
||||
QUARTZ_BLOCK: 1
|
||||
QUARTZ_ORE: 0
|
||||
QUARTZ_STAIRS: 1
|
||||
QUARTZ: 1
|
||||
RAILS: 1
|
||||
RED_GLAZED_TERRACOTTA: 1
|
||||
RED_MUSHROOM: 1
|
||||
RED_NETHER_BRICK: 2
|
||||
RED_ROSE: 1
|
||||
RED_SANDSTONE: 1
|
||||
RED_SANDSTONE_STAIRS: 1
|
||||
RED_SHULKER_BOX: 1
|
||||
REDSTONE_BLOCK: 10
|
||||
REDSTONE_COMPARATOR_OFF: 10
|
||||
REDSTONE_COMPARATOR_ON: 10
|
||||
REDSTONE_COMPARATOR: 10
|
||||
REDSTONE_LAMP_OFF: 10
|
||||
REDSTONE_LAMP_ON: 10
|
||||
REDSTONE_ORE: 0
|
||||
REDSTONE_TORCH_OFF: 5
|
||||
REDSTONE_TORCH_ON: 5
|
||||
REDSTONE_WIRE: 1
|
||||
SAND: 1
|
||||
SANDSTONE: 1
|
||||
SANDSTONE_STAIRS: 1
|
||||
SEA_LANTERN: 1
|
||||
SIGN_POST: 1
|
||||
SILVER_GLAZED_TERRACOTTA: 1
|
||||
SILVER_SHULKER_BOX: 1
|
||||
SKULL: 10
|
||||
SLIME_BLOCK: 10
|
||||
SMOOTH_BRICK: 2
|
||||
SMOOTH_STAIRS: 2
|
||||
SNOW_BLOCK: 1
|
||||
SOIL: 2
|
||||
SOUL_SAND: 2
|
||||
SPONGE: 10
|
||||
SPRUCE_DOOR: 1
|
||||
SPRUCE_FENCE: 1
|
||||
SPRUCE_FENCE_GATE: 1
|
||||
SPRUCE_WOOD_STAIRS: 1
|
||||
STAINED_CLAY: 2
|
||||
STAINED_GLASS: 2
|
||||
STAINED_GLASS_PANE: 1
|
||||
STATIONARY_LAVA: 0
|
||||
STATIONARY_WATER: 0
|
||||
STEP: 1
|
||||
STONE: 1
|
||||
STONE_BUTTON: 1
|
||||
STONE_PLATE: 2
|
||||
STORAGE_MINECART: 10
|
||||
SUGAR_CANE_BLOCK: 1
|
||||
THIN_GLASS: 1
|
||||
TNT: 5
|
||||
TORCH: 2
|
||||
TRAP_DOOR: 5
|
||||
TRAPPED_CHEST: 10
|
||||
TRIPWIRE_HOOK: 2
|
||||
TRIPWIRE: 2
|
||||
VINE: 1
|
||||
WALL_SIGN: 1
|
||||
WATER_LILY: 5
|
||||
WEB: 10
|
||||
WHEAT: 1
|
||||
WHITE_GLAZED_TERRACOTTA: 1
|
||||
WHITE_SHULKER_BOX: 1
|
||||
WOOD: 1
|
||||
WOOD_BUTTON: 1
|
||||
WOOD_DOOR: 1
|
||||
WOOD_DOUBLE_STEP: 1
|
||||
WOOD_PLATE: 1
|
||||
WOOD_STAIRS: 1
|
||||
WOOD_STEP: 1
|
||||
WOODEN_DOOR: 1
|
||||
WOOL: 1
|
||||
WORKBENCH: 1
|
||||
YELLOW_FLOWER: 1
|
||||
YELLOW_GLAZED_TERRACOTTA: 1
|
||||
YELLOW_SHULKER_BOX: 1
|
||||
# Remove non-repeatable challenges from the challenge GUI when complete
|
||||
removecompleteonetimechallenges: false
|
||||
|
||||
# Add enchanted glow to completed challenges
|
||||
addcompletedglow: true
|
||||
|
@ -1,36 +0,0 @@
|
||||
package bskyblock.addin.challenges;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
/**
|
||||
* Makes code look nicer
|
||||
* @author ben
|
||||
*
|
||||
*/
|
||||
public abstract class AddonHelper {
|
||||
protected final Challenges plugin;
|
||||
protected final BSkyBlock bSkyBlock;
|
||||
|
||||
public AddonHelper(Challenges plugin) {
|
||||
this.plugin = plugin;
|
||||
this.bSkyBlock = BSkyBlock.getPlugin();
|
||||
}
|
||||
|
||||
public final Logger getLogger() {
|
||||
return plugin.getLogger();
|
||||
}
|
||||
|
||||
public final void sendMessage(CommandSender sender, String message) {
|
||||
Util.sendMessage(sender, message);
|
||||
}
|
||||
|
||||
public final BSBLocale getLocale(CommandSender sender) {
|
||||
return plugin.getLocale(sender);
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package bskyblock.addin.challenges;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import bskyblock.addin.challenges.commands.ChallengesCommand;
|
||||
import bskyblock.addin.challenges.config.LocaleManager;
|
||||
import bskyblock.addin.challenges.config.PluginConfig;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
|
||||
/**
|
||||
* Addin to BSkyBlock that enables challenges
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class Challenges extends JavaPlugin {
|
||||
|
||||
// The BSkyBlock plugin instance.
|
||||
private BSkyBlock bSkyBlock;
|
||||
|
||||
// Locale manager for this plugin
|
||||
private LocaleManager localeManager;
|
||||
|
||||
private ChallengesManager manager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Load the plugin's config
|
||||
new PluginConfig(this);
|
||||
// Get the BSkyBlock plugin. This will be available because this plugin depends on it in plugin.yml.
|
||||
bSkyBlock = BSkyBlock.getPlugin();
|
||||
// Check if it is enabled - it might be loaded, but not enabled.
|
||||
if (bSkyBlock == null || !bSkyBlock.isEnabled()) {
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Local locales
|
||||
localeManager = new LocaleManager(this);
|
||||
|
||||
// Challenges Manager
|
||||
manager = new ChallengesManager(this);
|
||||
// Register commands
|
||||
new ChallengesCommand(this);
|
||||
// Register Listener
|
||||
getServer().getPluginManager().registerEvents(manager.getChallengesPanels(), this);
|
||||
// Done
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
if (manager != null)
|
||||
manager.save(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the locale for this player
|
||||
* @param sender
|
||||
* @return Locale object for sender
|
||||
*/
|
||||
public BSBLocale getLocale(CommandSender sender) {
|
||||
return localeManager.getLocale(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locale for this UUID
|
||||
* @param uuid
|
||||
* @return Locale object for UUID
|
||||
*/
|
||||
public BSBLocale getLocale(UUID uuid) {
|
||||
return localeManager.getLocale(uuid);
|
||||
}
|
||||
|
||||
public ChallengesManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package bskyblock.addin.challenges.commands;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import bskyblock.addin.challenges.Challenges;
|
||||
import us.tastybento.bskyblock.api.commands.AbstractCommand;
|
||||
import us.tastybento.bskyblock.api.commands.ArgumentHandler;
|
||||
import us.tastybento.bskyblock.api.commands.CanUseResp;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.VaultHelper;
|
||||
|
||||
public class ChallengesCommand extends AbstractCommand implements Listener {
|
||||
private static final String CHALLENGE_COMMAND = "challenges";
|
||||
private Challenges plugin;
|
||||
|
||||
public ChallengesCommand(Challenges plugin) {
|
||||
super(CHALLENGE_COMMAND, new String[]{"c", "challenge"}, true);
|
||||
plugin.getCommand(CHALLENGE_COMMAND).setExecutor(this);
|
||||
plugin.getCommand(CHALLENGE_COMMAND).setTabCompleter(this);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CanUseResp canUse(CommandSender sender) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return new CanUseResp(getLocale(sender).get("general.errors.use-in-game"));
|
||||
}
|
||||
|
||||
// Basic permission check to use /challenges
|
||||
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.challenges")) {
|
||||
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
|
||||
}
|
||||
|
||||
return new CanUseResp(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// Open up the challenges GUI
|
||||
if (isPlayer) {
|
||||
player.openInventory(plugin.getManager().getChallengesPanels().getChallenges(player));
|
||||
} else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
addArgument(new ArgumentHandler(label) {
|
||||
|
||||
@Override
|
||||
public CanUseResp canUse(CommandSender sender) {
|
||||
return new CanUseResp(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
// Create a copy of items in the player's main inventory
|
||||
Player player = (Player)sender;
|
||||
String name = UUID.randomUUID().toString();
|
||||
if (args.length > 0) {
|
||||
name = args[0];
|
||||
}
|
||||
plugin.getManager().createChallenge(player, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] usage(CommandSender sender) {
|
||||
return new String[] {null, "Make a challenge from the items in your inventory"};
|
||||
}
|
||||
}.alias("make"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package bskyblock.addin.challenges.config;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import bskyblock.addin.challenges.Challenges;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.config.AbstractLocaleManager;
|
||||
import us.tastybento.bskyblock.config.BSBLocale;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
public class LocaleManager extends AbstractLocaleManager {
|
||||
|
||||
public LocaleManager(Challenges plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BSBLocale getLocale(UUID player) {
|
||||
//getLogger().info("DEBUG: " + player);
|
||||
//getLogger().info("DEBUG: " + getPlayers() == null ? "Players is null":"Players in not null");
|
||||
//getLogger().info("DEBUG: " + getPlayers().getPlayer(player));
|
||||
//getLogger().info("DEBUG: " + getPlayers().getPlayer(player).getLocale());
|
||||
String locale = BSkyBlock.getPlugin().getPlayers().getPlayer(player).getLocale();
|
||||
if(locale.isEmpty() || !getLocales().containsKey(locale)) return getLocales().get(Settings.defaultLanguage);
|
||||
|
||||
return getLocales().get(locale);
|
||||
}
|
||||
}
|
49
src/bskyblock/addon/challenges/Challenges.java
Normal file
49
src/bskyblock/addon/challenges/Challenges.java
Normal file
@ -0,0 +1,49 @@
|
||||
package bskyblock.addon.challenges;
|
||||
|
||||
import bskyblock.addon.challenges.commands.ChallengesCommand;
|
||||
import bskyblock.addon.challenges.config.PluginConfig;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.addons.Addon;
|
||||
|
||||
/**
|
||||
* Addin to BSkyBlock that enables challenges
|
||||
* @author tastybento
|
||||
*
|
||||
*/
|
||||
public class Challenges extends Addon {
|
||||
|
||||
// The BSkyBlock plugin instance.
|
||||
private BSkyBlock bSkyBlock;
|
||||
|
||||
private ChallengesManager manager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Load the plugin's config
|
||||
new PluginConfig(this);
|
||||
// Get the BSkyBlock plugin. This will be available because this plugin depends on it in plugin.yml.
|
||||
bSkyBlock = BSkyBlock.getInstance();
|
||||
// Check if it is enabled - it might be loaded, but not enabled.
|
||||
if (bSkyBlock == null || !bSkyBlock.isEnabled()) {
|
||||
this.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Challenges Manager
|
||||
manager = new ChallengesManager(this);
|
||||
// Register commands
|
||||
new ChallengesCommand(this);
|
||||
// Done
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
if (manager != null)
|
||||
manager.save(false);
|
||||
}
|
||||
|
||||
public ChallengesManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package bskyblock.addin.challenges;
|
||||
package bskyblock.addon.challenges;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -14,16 +14,16 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import bskyblock.addin.challenges.database.object.ChallengesDO;
|
||||
import bskyblock.addin.challenges.database.object.LevelsDO;
|
||||
import bskyblock.addin.challenges.panel.ChallengesPanels;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesDO;
|
||||
import bskyblock.addon.challenges.database.object.LevelsDO;
|
||||
import bskyblock.addon.challenges.panel.ChallengesPanels;
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.database.flatfile.FlatFileDatabase;
|
||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
public class ChallengesManager {
|
||||
|
||||
@ -40,8 +40,8 @@ public class ChallengesManager {
|
||||
public ChallengesManager(Challenges plugin) {
|
||||
this.plugin = plugin;
|
||||
// Set up the database handler to store and retrieve Challenges
|
||||
chHandler = (AbstractDatabaseHandler<ChallengesDO>) new FlatFileDatabase().getHandler(plugin, ChallengesDO.class);
|
||||
lvHandler = (AbstractDatabaseHandler<LevelsDO>) new FlatFileDatabase().getHandler(plugin, LevelsDO.class);
|
||||
chHandler = (AbstractDatabaseHandler<ChallengesDO>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), ChallengesDO.class);
|
||||
lvHandler = (AbstractDatabaseHandler<LevelsDO>) new FlatFileDatabase().getHandler(BSkyBlock.getInstance(), LevelsDO.class);
|
||||
challengeList = new LinkedHashMap<>();
|
||||
// Start panels
|
||||
challengesPanels = new ChallengesPanels(plugin, this);
|
||||
@ -68,12 +68,13 @@ public class ChallengesManager {
|
||||
try {
|
||||
for (ChallengesDO challenge : chHandler.loadObjects()) {
|
||||
// See if we have this level already
|
||||
LevelsDO level = new LevelsDO();
|
||||
LevelsDO level;
|
||||
if (lvHandler.objectExits(challenge.getLevel())) {
|
||||
// Get it from the database
|
||||
level = lvHandler.loadObject(challenge.getLevel());
|
||||
} else {
|
||||
// Make it
|
||||
level = new LevelsDO();
|
||||
level.setUniqueId(challenge.getLevel());
|
||||
lvHandler.saveObject(level);
|
||||
}
|
||||
@ -127,7 +128,7 @@ public class ChallengesManager {
|
||||
}
|
||||
}
|
||||
};
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save);
|
||||
BSkyBlock.getInstance().getServer().getScheduler().runTaskAsynchronously(BSkyBlock.getInstance(), save);
|
||||
} else {
|
||||
for (Entry<LevelsDO, List<ChallengesDO>> en : challengeList.entrySet()) {
|
||||
try {
|
||||
@ -161,11 +162,11 @@ public class ChallengesManager {
|
||||
* Create a challenge from the inventory contents
|
||||
* @param contents
|
||||
*/
|
||||
public void createChallenge(Player player, String name) {
|
||||
public void createChallenge(User user, String name) {
|
||||
// Get the main icon
|
||||
ItemStack icon = player.getInventory().getItemInOffHand();
|
||||
ItemStack icon = user.getInventory().getItemInOffHand();
|
||||
if (icon == null || icon.getType().equals(Material.AIR)) {
|
||||
Util.sendMessage(player, "Icon will be paper");
|
||||
user.sendLegacyMessage("Icon will be paper");
|
||||
icon = new ItemStack(Material.PAPER);
|
||||
}
|
||||
icon.setAmount(1);
|
||||
@ -174,7 +175,7 @@ public class ChallengesManager {
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("Required items:");
|
||||
|
||||
List<ItemStack> inv = Arrays.asList(player.getInventory().getStorageContents());
|
||||
List<ItemStack> inv = Arrays.asList(user.getInventory().getStorageContents());
|
||||
List<ItemStack> contents = new ArrayList<>();
|
||||
for (ItemStack item : inv) {
|
||||
if (item != null && !item.getType().equals(Material.AIR)) {
|
||||
@ -193,7 +194,7 @@ public class ChallengesManager {
|
||||
newChallenge.setUniqueId(name);
|
||||
newChallenge.setIcon(icon);
|
||||
if (chHandler.objectExits(name)) {
|
||||
Util.sendMessage(player, ChatColor.RED + "Challenge already exists! Use /c replace <name>");
|
||||
user.sendLegacyMessage(ChatColor.RED + "Challenge already exists! Use /c replace <name>");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@ -202,10 +203,10 @@ public class ChallengesManager {
|
||||
| InstantiationException | NoSuchMethodException | IntrospectionException | SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
Util.sendMessage(player, ChatColor.RED + "Challenge creation failed! " + e.getMessage());
|
||||
user.sendLegacyMessage(ChatColor.RED + "Challenge creation failed! " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
Util.sendMessage(player, "Challenge accepted!");
|
||||
user.sendLegacyMessage("Challenge accepted!");
|
||||
// TODO ADD CHALLENGE
|
||||
//challenges.put(newChallenge.getUniqueId(), newChallenge);
|
||||
}
|
||||
@ -249,10 +250,10 @@ public class ChallengesManager {
|
||||
|
||||
/**
|
||||
* Get the status on every level
|
||||
* @param player
|
||||
* @param user
|
||||
* @return Level name, how many challenges still to do on which level
|
||||
*/
|
||||
public List<LevelStatus> getChallengeLevelStatus(Player player) {
|
||||
public List<LevelStatus> getChallengeLevelStatus(User user) {
|
||||
List<LevelStatus> result = new ArrayList<>();
|
||||
LevelsDO previousLevel = null;
|
||||
for (Entry<LevelsDO, List<ChallengesDO>> en : challengeList.entrySet()) {
|
@ -0,0 +1,41 @@
|
||||
package bskyblock.addon.challenges.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
public class ChallengesCommand extends CompositeCommand {
|
||||
private static final String CHALLENGE_COMMAND = "challenges";
|
||||
private Challenges plugin;
|
||||
|
||||
public ChallengesCommand(Challenges plugin) {
|
||||
super(CHALLENGE_COMMAND, "c", "challenge");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// Open up the challenges GUI
|
||||
if (user.isPlayer()) {
|
||||
plugin.getManager().getChallengesPanels().getChallenges(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setOnlyPlayer(true);
|
||||
this.setPermission(Settings.PERMPREFIX + "challenges");
|
||||
this.setDescription("addon.challenges.help");
|
||||
this.setUsage("addon.challenges.usage");
|
||||
|
||||
// Set up create command
|
||||
new CreateChallenge(plugin, this);
|
||||
}
|
||||
|
||||
|
||||
}
|
40
src/bskyblock/addon/challenges/commands/CreateChallenge.java
Normal file
40
src/bskyblock/addon/challenges/commands/CreateChallenge.java
Normal file
@ -0,0 +1,40 @@
|
||||
package bskyblock.addon.challenges.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import us.tastybento.bskyblock.api.commands.CompositeCommand;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
public class CreateChallenge extends CompositeCommand {
|
||||
|
||||
|
||||
private Challenges plugin;
|
||||
|
||||
public CreateChallenge(Challenges plugin, ChallengesCommand parent) {
|
||||
super(parent, "create");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setOnlyPlayer(true);
|
||||
this.setPermission(Settings.PERMPREFIX + "challenges");
|
||||
this.setDescription("addon.challenges.create.description");
|
||||
this.setUsage("addon.challenges.create.usage");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, List<String> args) {
|
||||
// Create a copy of items in the player's main inventory
|
||||
String name = UUID.randomUUID().toString();
|
||||
if (args.size() > 0) {
|
||||
name = args.get(0);
|
||||
}
|
||||
plugin.getManager().createChallenge(user, name);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package bskyblock.addin.challenges.config;
|
||||
package bskyblock.addon.challenges.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -6,7 +6,7 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import bskyblock.addin.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
|
||||
public class PluginConfig {
|
||||
private static final boolean DEBUG = false;
|
@ -1,4 +1,4 @@
|
||||
package bskyblock.addin.challenges.config;
|
||||
package bskyblock.addon.challenges.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package bskyblock.addin.challenges.database.object;
|
||||
package bskyblock.addon.challenges.database.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
@ -1,4 +1,4 @@
|
||||
package bskyblock.addin.challenges.database.object;
|
||||
package bskyblock.addon.challenges.database.object;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
@ -1,63 +1,54 @@
|
||||
package bskyblock.addin.challenges.panel;
|
||||
package bskyblock.addon.challenges.panel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import bskyblock.addin.challenges.Challenges;
|
||||
import bskyblock.addin.challenges.ChallengesManager;
|
||||
import bskyblock.addin.challenges.ChallengesManager.LevelStatus;
|
||||
import bskyblock.addin.challenges.database.object.ChallengesDO;
|
||||
import bskyblock.addin.challenges.panel.Panel.PanelBuilder;
|
||||
import bskyblock.addin.challenges.panel.Panel.PanelItem;
|
||||
import bskyblock.addon.challenges.Challenges;
|
||||
import bskyblock.addon.challenges.ChallengesManager;
|
||||
import bskyblock.addon.challenges.ChallengesManager.LevelStatus;
|
||||
import bskyblock.addon.challenges.database.object.ChallengesDO;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.panels.ClickType;
|
||||
import us.tastybento.bskyblock.api.panels.Panel;
|
||||
import us.tastybento.bskyblock.api.panels.PanelItem;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelBuilder;
|
||||
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
|
||||
|
||||
public class ChallengesPanels implements Listener {
|
||||
|
||||
public class ChallengesPanels {
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String CHALLENGE_COMMAND = "challenges";
|
||||
//private static final String CHALLENGE_COMMAND = "challenges";
|
||||
private Challenges plugin;
|
||||
private HashMap<UUID, Panel> challengePanels;
|
||||
private ChallengesManager manager;
|
||||
|
||||
public ChallengesPanels(Challenges plugin, ChallengesManager manager){
|
||||
this.plugin = plugin;
|
||||
this.manager = manager;
|
||||
challengePanels = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public Inventory getChallenges(Player player) {
|
||||
return getChallenges(player, "");
|
||||
public void getChallenges(User user) {
|
||||
getChallenges(user, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically creates an inventory of challenges for the player showing the
|
||||
* level
|
||||
*
|
||||
* @param player
|
||||
* @param level
|
||||
* @param user
|
||||
* @return inventory
|
||||
*/
|
||||
public Inventory getChallenges(Player player, String level) {
|
||||
public void getChallenges(User user, String level) {
|
||||
plugin.getLogger().info("DEBUG: level requested = " + level);
|
||||
PanelBuilder panelBuilder = Panel.builder(plugin)
|
||||
.name(plugin.getLocale(player).get("challenges.guiTitle"));
|
||||
PanelBuilder panelBuilder = new PanelBuilder()
|
||||
.setName(user.getTranslation("challenges.guiTitle"));
|
||||
List<ChallengesDO> levelChallenges = manager.getChallenges(level);
|
||||
// Do some checking
|
||||
if (DEBUG)
|
||||
@ -65,39 +56,52 @@ public class ChallengesPanels implements Listener {
|
||||
// Only show a control panel for the level requested.
|
||||
for (ChallengesDO challenge : levelChallenges) {
|
||||
plugin.getLogger().info("Adding challenge " + challenge.getUniqueId());
|
||||
boolean completed = manager.isChallengeComplete(player.getUniqueId(), challenge.getUniqueId());
|
||||
boolean completed = manager.isChallengeComplete(user.getUniqueId(), challenge.getUniqueId());
|
||||
if (completed && challenge.isRemoveWhenCompleted())
|
||||
continue;
|
||||
PanelItem item = Panel.panelItemBuilder()
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.setIcon(challenge.getIcon())
|
||||
.setName(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName())
|
||||
.setDescription(challenge.getDescription())
|
||||
.setSlot(challenge.getSlot())
|
||||
.setGlow(completed)
|
||||
.setCommand(CHALLENGE_COMMAND + " c " + challenge.getUniqueId())
|
||||
.setClickHandler(new PanelItem.ClickHandler() {
|
||||
@Override
|
||||
public boolean onClick(Player player, ClickType click) {
|
||||
player.sendMessage("Hi!");
|
||||
return false;
|
||||
}
|
||||
})
|
||||
//.setCommand(CHALLENGE_COMMAND + " c " + challenge.getUniqueId())
|
||||
.build();
|
||||
plugin.getLogger().info("requested slot" + item.getSlot());
|
||||
panelBuilder.addItem(item);
|
||||
plugin.getLogger().info("requested slot" + challenge.getSlot());
|
||||
panelBuilder.addItem(challenge.getSlot(),item);
|
||||
}
|
||||
// Add navigation to other levels
|
||||
for (LevelStatus status: manager.getChallengeLevelStatus(player)) {
|
||||
for (LevelStatus status: manager.getChallengeLevelStatus(user)) {
|
||||
String name = ChatColor.GOLD + (status.getLevel().getFriendlyName().isEmpty() ? status.getLevel().getUniqueId() : status.getLevel().getFriendlyName());
|
||||
if (status.isComplete() || status.getPreviousLevel() == null) {
|
||||
// Clicking on this icon will open up this level's challenges
|
||||
PanelItem item = Panel.panelItemBuilder()
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.setIcon(new ItemStack(Material.BOOK_AND_QUILL))
|
||||
.setName(name)
|
||||
.setDescription(plugin.getLocale(player).get("challenges.navigation").replace("[level]",name))
|
||||
.setCommand(CHALLENGE_COMMAND + " c " + status.getLevel().getUniqueId())
|
||||
.setDescription(user.getTranslation("challenges.navigation","[level]",name))
|
||||
.setClickHandler(new PanelItem.ClickHandler() {
|
||||
@Override
|
||||
public boolean onClick(Player player, ClickType click) {
|
||||
player.sendMessage("Hi!");
|
||||
return false;
|
||||
}
|
||||
})
|
||||
//.setCommand(CHALLENGE_COMMAND + " c " + status.getLevel().getUniqueId())
|
||||
.build();
|
||||
panelBuilder.addItem(item);
|
||||
} else {
|
||||
// Clicking on this icon will do nothing because the challenge is not unlocked yet
|
||||
String previousLevelName = ChatColor.GOLD + (status.getPreviousLevel().getFriendlyName().isEmpty() ? status.getPreviousLevel().getUniqueId() : status.getPreviousLevel().getFriendlyName());
|
||||
PanelItem item = Panel.panelItemBuilder()
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.setIcon(new ItemStack(Material.BOOK))
|
||||
.setName(name)
|
||||
.setDescription((plugin.getLocale(player).get("challenges.toComplete").replace("[challengesToDo]",String.valueOf(status.getNumberOfChallengesStillToDo()))).replace("[thisLevel]", previousLevelName))
|
||||
.setDescription((user.getTranslation("challenges.toComplete", "[challengesToDo]",String.valueOf(status.getNumberOfChallengesStillToDo()), "[thisLevel]", previousLevelName)))
|
||||
.build();
|
||||
panelBuilder.addItem(item);
|
||||
}
|
||||
@ -114,10 +118,10 @@ public class ChallengesPanels implements Listener {
|
||||
}*/
|
||||
// Create the panel
|
||||
Panel panel = panelBuilder.build();
|
||||
challengePanels.put(player.getUniqueId(), panel);
|
||||
return panel.getPanel();
|
||||
panel.open(user);
|
||||
}
|
||||
|
||||
/*
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked(); // The player that
|
||||
@ -156,6 +160,7 @@ public class ChallengesPanels implements Listener {
|
||||
* Clean up the hashmap should the player open up another inventory
|
||||
* @param event
|
||||
*/
|
||||
/*
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
@ -172,5 +177,5 @@ public class ChallengesPanels implements Listener {
|
||||
challengePanels.remove(event.getPlayer().getUniqueId());
|
||||
plugin.getLogger().info("DEBUG: removing inv " + challengePanels.size());
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package bskyblock.addin.challenges.panel;
|
||||
package bskyblock.addon.challenges.panel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
Loading…
Reference in New Issue
Block a user