mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2025-01-03 23:17:42 +01:00
Remove Deprecated Classes.
This commit is contained in:
parent
3b4a64bb39
commit
f9b941059e
2
pom.xml
2
pom.xml
@ -100,7 +100,7 @@
|
||||
<dependency>
|
||||
<groupId>world.bentobox</groupId>
|
||||
<artifactId>bentobox</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -1,170 +0,0 @@
|
||||
package world.bentobox.challenges;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
/**
|
||||
* Class that parses a string into an ItemStack
|
||||
* Used for converting config file entries to objects
|
||||
* @author tastybento
|
||||
*
|
||||
* @deprecated
|
||||
* @see world.bentobox.bentobox.util.ItemParser#parse(String)
|
||||
*/
|
||||
@Deprecated
|
||||
public class ParseItem {
|
||||
|
||||
private final ItemStack item;
|
||||
private ChallengesAddon addon;
|
||||
|
||||
public ParseItem(ChallengesAddon addon, String s) {
|
||||
this.addon = addon;
|
||||
item = parseItem(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string into an itemstack
|
||||
* @param s - input string
|
||||
* @return ItemStack or null if parsing failed
|
||||
*/
|
||||
private ItemStack parseItem(String s) {
|
||||
String[] part = s.split(":");
|
||||
if (part.length > 0 && (part[0].equalsIgnoreCase("POTION") || part[0].equalsIgnoreCase("TIPPED_ARROW"))) {
|
||||
return potion(s, part);
|
||||
}
|
||||
// Material:Qty
|
||||
if (part.length == 2) {
|
||||
return two(s, part);
|
||||
} else if (part.length == 3) {
|
||||
return three(s, part);
|
||||
}
|
||||
showError(s);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private ItemStack potion(String s, String[] part) {
|
||||
/*
|
||||
* # Format POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY
|
||||
# LEVEL, EXTENDED, SPLASH, LINGER are optional.
|
||||
# LEVEL is a number, 1 or 2
|
||||
# LINGER is for V1.9 servers and later
|
||||
# Examples:
|
||||
# POTION:STRENGTH:1:EXTENDED:SPLASH:1
|
||||
# POTION:INSTANT_DAMAGE:2::LINGER:2
|
||||
# POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1
|
||||
# POTION:WEAKNESS::::1 - any weakness potion
|
||||
*/
|
||||
|
||||
ItemStack result = new ItemStack(Material.POTION);
|
||||
if (part[0].equalsIgnoreCase("TIPPED_ARROW")) {
|
||||
result = new ItemStack(Material.TIPPED_ARROW);
|
||||
} else if (part[0].equalsIgnoreCase("SPLASH_POTION")) {
|
||||
result = new ItemStack(Material.SPLASH_POTION);
|
||||
} else if (part[0].equalsIgnoreCase("LINGERING_POTION")) {
|
||||
result = new ItemStack(Material.LINGERING_POTION);
|
||||
}
|
||||
int reqAmount = 0;
|
||||
String amount = "1";
|
||||
String level = "1";
|
||||
String ext = "";
|
||||
String splashLinger = "";
|
||||
switch (part.length) {
|
||||
case 3:
|
||||
amount = part[2];
|
||||
break;
|
||||
case 4:
|
||||
level = part[2];
|
||||
amount = part[3];
|
||||
break;
|
||||
case 5:
|
||||
level = part[2];
|
||||
ext = part[3];
|
||||
amount = part[4];
|
||||
break;
|
||||
case 6:
|
||||
level = part[2];
|
||||
ext = part[3];
|
||||
splashLinger = part[4];
|
||||
amount = part[5];
|
||||
break;
|
||||
|
||||
default:
|
||||
// Because I don't know!
|
||||
return null;
|
||||
}
|
||||
// Parse the quantity
|
||||
try {
|
||||
reqAmount = Integer.parseInt(amount);
|
||||
} catch (Exception e) {
|
||||
addon.getLogger().severe(() -> "Could not parse the quantity of the potion or tipped arrow " + s);
|
||||
return null;
|
||||
}
|
||||
result.setAmount(reqAmount);
|
||||
|
||||
// Parse the legacy splash / linger
|
||||
if (splashLinger.equalsIgnoreCase("SPLASH")) {
|
||||
result = new ItemStack(Material.SPLASH_POTION);
|
||||
} else if (splashLinger.equalsIgnoreCase("LINGER")) {
|
||||
result = new ItemStack(Material.LINGERING_POTION);
|
||||
}
|
||||
// Parse the type of potion
|
||||
PotionMeta potionMeta = (PotionMeta)(result.getItemMeta());
|
||||
PotionType type = PotionType.valueOf(part[1].toUpperCase());
|
||||
boolean isUpgraded = (level.isEmpty() || level.equalsIgnoreCase("1")) ? false: true;
|
||||
boolean isExtended = ext.equalsIgnoreCase("EXTENDED") ? true : false;
|
||||
PotionData data = new PotionData(type, isExtended, isUpgraded);
|
||||
potionMeta.setBasePotionData(data);
|
||||
result.setItemMeta(potionMeta);
|
||||
return result;
|
||||
}
|
||||
|
||||
private ItemStack three(String s, String[] part) {
|
||||
// Rearrange
|
||||
String[] twoer = {part[0], part[2]};
|
||||
ItemStack result = two(s, twoer);
|
||||
if (result == null) {
|
||||
showError(s);
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private void showError(String s) {
|
||||
addon.getLogger().severe(() -> "Problem with " + s + " in config.yml!");
|
||||
}
|
||||
|
||||
private ItemStack two(String s, String[] part) {
|
||||
int reqAmount = 0;
|
||||
try {
|
||||
reqAmount = Integer.parseInt(part[1]);
|
||||
} catch (Exception e) {
|
||||
showError(s);
|
||||
return null;
|
||||
}
|
||||
Material reqItem = Material.getMaterial(part[0].toUpperCase() + "_ITEM");
|
||||
if (reqItem == null) {
|
||||
// Try the item
|
||||
reqItem = Material.getMaterial(part[0].toUpperCase());
|
||||
}
|
||||
|
||||
if (reqItem == null) {
|
||||
showError(s);
|
||||
return null;
|
||||
}
|
||||
return new ItemStack(reqItem, reqAmount);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the item
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@Deprecated
|
||||
public class CompleteChallenge extends CompositeCommand {
|
||||
|
||||
private ChallengesManager manager;
|
||||
|
@ -1,52 +0,0 @@
|
||||
package world.bentobox.challenges.commands.admin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.panel.CreateChallengeListener;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Challenges can be creaded via GUI.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CreateChallenge extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Admin command to make challenges
|
||||
* @param parent
|
||||
*/
|
||||
public CreateChallenge(Addon addon, CompositeCommand parent) {
|
||||
super(addon, parent, "create");
|
||||
new CreateSurrounding(addon, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setOnlyPlayer(true);
|
||||
this.setPermission("admin.challenges");
|
||||
this.setParametersHelp("challenges.commands.admin.create.parameters");
|
||||
this.setDescription("challenges.commands.admin.create.description");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
user.sendMessage("challenges.errors.no-name");
|
||||
return false;
|
||||
}
|
||||
new PanelBuilder()
|
||||
.name(args.get(0))
|
||||
.size(49)
|
||||
.listener(new CreateChallengeListener((ChallengesAddon) getAddon(), user))
|
||||
.user(user)
|
||||
.build();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package world.bentobox.challenges.commands.admin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
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.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Command to create a surrounding type challenge
|
||||
* @author tastybento
|
||||
* @deprecated Required blocks can be added via GUI. Not necessary.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CreateSurrounding extends CompositeCommand implements Listener {
|
||||
|
||||
HashMap<UUID,SurroundChallengeBuilder> inProgress = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Admin command to make surrounding challenges
|
||||
* @param parent
|
||||
*/
|
||||
public CreateSurrounding(Addon addon, CompositeCommand parent) {
|
||||
super(addon, parent, "surrounding");
|
||||
addon.getServer().getPluginManager().registerEvents(this, addon.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
this.setOnlyPlayer(true);
|
||||
this.setPermission("admin.challenges");
|
||||
this.setParametersHelp("challenges.commands.admin.surrounding.parameters");
|
||||
this.setDescription("challenges.commands.admin.surrounding.description");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
user.sendMessage("challenges.errors.no-name");
|
||||
return false;
|
||||
}
|
||||
// Tell user to hit objects to add to the surrounding object requirements
|
||||
user.sendMessage("challenges.messages.admin.hit-things");
|
||||
inProgress.put(user.getUniqueId(), new SurroundChallengeBuilder((ChallengesAddon) getAddon()).owner(user).name(args.get(0)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
e.setCancelled(inProgress.containsKey(e.getPlayer().getUniqueId()) ? true : false);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
inProgress.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public boolean onPlayerInteract(PlayerInteractEvent e) {
|
||||
if (e.getAction().equals(Action.LEFT_CLICK_BLOCK) && inProgress.containsKey(e.getPlayer().getUniqueId())) {
|
||||
// Prevent damage
|
||||
e.setCancelled(true);
|
||||
inProgress.get(e.getPlayer().getUniqueId()).addBlock(e.getClickedBlock().getType());
|
||||
User.getInstance(e.getPlayer()).sendMessage("challenges.messages.admin.you-added", "[thing]", Util.prettifyText(e.getClickedBlock().getType().toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
return finished(e, e.getPlayer().getUniqueId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean finished(Cancellable e, UUID uuid) {
|
||||
if (inProgress.containsKey(uuid)) {
|
||||
e.setCancelled(true);
|
||||
boolean status = inProgress.get(uuid).build();
|
||||
if (status) {
|
||||
inProgress.get(uuid).getOwner().sendMessage("challenges.messages.admin.challenge-created", "[challenge]", inProgress.get(uuid).getName());
|
||||
}
|
||||
inProgress.remove(uuid);
|
||||
return status;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public boolean onPlayerInteract(PlayerInteractAtEntityEvent e) {
|
||||
return finished(e, e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public boolean onLeft(EntityDamageByEntityEvent e) {
|
||||
if (!(e.getDamager() instanceof Player)) {
|
||||
return false;
|
||||
}
|
||||
Player player = (Player)e.getDamager();
|
||||
if (inProgress.containsKey(player.getUniqueId())) {
|
||||
// Prevent damage
|
||||
e.setCancelled(true);
|
||||
inProgress.get(player.getUniqueId()).addEntity(e.getEntityType());
|
||||
User.getInstance(player).sendMessage("challenges.messages.admin.you-added", "[thing]", Util.prettifyText(e.getEntityType().toString()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package world.bentobox.challenges.commands.admin;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* Enables the state of a Surrounding Challenge to be stored as it is built
|
||||
* @author tastybento
|
||||
* @deprecated Levels and challenges can be created via GUI. Not necessary command.
|
||||
*/
|
||||
@Deprecated
|
||||
public class SurroundChallengeBuilder {
|
||||
private ChallengesAddon addon;
|
||||
private String name;
|
||||
private User owner;
|
||||
private Map<Material, Integer> reqBlocks = new EnumMap<>(Material.class);
|
||||
private Map<EntityType, Integer> reqEntities = new EnumMap<>(EntityType.class);
|
||||
|
||||
public SurroundChallengeBuilder(ChallengesAddon addon) {
|
||||
this.addon = addon;
|
||||
}
|
||||
|
||||
SurroundChallengeBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
SurroundChallengeBuilder owner(User user) {
|
||||
this.owner = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
SurroundChallengeBuilder addBlock(Material mat) {
|
||||
reqBlocks.computeIfPresent(mat, (material, amount) -> amount + 1);
|
||||
reqBlocks.putIfAbsent(mat, 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
SurroundChallengeBuilder addEntity(EntityType ent) {
|
||||
reqEntities.computeIfPresent(ent, (type, amount) -> amount + 1);
|
||||
reqEntities.putIfAbsent(ent, 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the owner
|
||||
*/
|
||||
public User getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reqBlocks
|
||||
*/
|
||||
public Map<Material, Integer> getReqBlocks() {
|
||||
return reqBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reqEntities
|
||||
*/
|
||||
public Map<EntityType, Integer> getReqEntities() {
|
||||
return reqEntities;
|
||||
}
|
||||
|
||||
public boolean build() {
|
||||
return false; //addon.getChallengesManager().createSurroundingChallenge(this);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AdminEditGUI implements ClickHandler {
|
||||
|
||||
private ChallengesAddon addon;
|
||||
private User requester;
|
||||
private Challenge challenge;
|
||||
private World world;
|
||||
private String permPrefix;
|
||||
private String label;
|
||||
private User target;
|
||||
|
||||
/**
|
||||
* Shows the admin panel for the challenge for a player
|
||||
* @param addon addon
|
||||
* @param requester admin user
|
||||
* @param target target of admin
|
||||
* @param challenge challenge
|
||||
* @param world world
|
||||
* @param permPrefix permission prefix for world
|
||||
* @param label command label
|
||||
*/
|
||||
public AdminEditGUI(ChallengesAddon addon, User requester, User target, Challenge challenge, World world,
|
||||
String permPrefix, String label) {
|
||||
super();
|
||||
this.addon = addon;
|
||||
this.requester = requester;
|
||||
this.target = target;
|
||||
this.challenge = challenge;
|
||||
this.world = world;
|
||||
this.permPrefix = permPrefix;
|
||||
this.label = label;
|
||||
|
||||
new PanelBuilder().size(27).user(requester).name(requester.getTranslation("challenges.admin.gui-title"))
|
||||
.item(new PanelItemBuilder().icon(challenge.getIcon()).name("Icon").build())
|
||||
.item(9, new PanelItemBuilder().icon(new ItemStack(Material.WHITE_BANNER)).name("Description").description(challenge.getDescription()).build())
|
||||
.item(18, new PanelItemBuilder().icon(new ItemStack(Material.GREEN_STAINED_GLASS_PANE)).name("Active").build())
|
||||
.item(27, new PanelItemBuilder().icon(new ItemStack(Material.BOOK)).name("Edit required items").clickHandler(this).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
if (slot == 27) {
|
||||
new RequiredPanel(challenge, user, panel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class AdminGUI implements ClickHandler {
|
||||
|
||||
private ChallengesAddon addon;
|
||||
private User player;
|
||||
private Challenge challenge;
|
||||
private World world;
|
||||
private String permPrefix;
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* Shows the admin panel for the challenge
|
||||
* @param addon
|
||||
* @param player
|
||||
* @param challenge
|
||||
* @param world
|
||||
* @param permPrefix
|
||||
* @param label
|
||||
*/
|
||||
public AdminGUI(ChallengesAddon addon, User player, Challenge challenge, World world,
|
||||
String permPrefix, String label) {
|
||||
super();
|
||||
this.addon = addon;
|
||||
this.player = player;
|
||||
this.challenge = challenge;
|
||||
this.world = world;
|
||||
this.permPrefix = permPrefix;
|
||||
this.label = label;
|
||||
|
||||
new PanelBuilder().size(27).user(player).name(player.getTranslation("challenges.admin.gui-title"))
|
||||
.item(new PanelItemBuilder().icon(challenge.getIcon()).name("Icon").build())
|
||||
.item(9, new PanelItemBuilder().icon(new ItemStack(Material.WHITE_BANNER)).name("Description").description(challenge.getDescription()).build())
|
||||
.item(18, new PanelItemBuilder().icon(new ItemStack(Material.GREEN_STAINED_GLASS_PANE)).name("Active").build())
|
||||
.item(27, new PanelItemBuilder().icon(new ItemStack(Material.BOOK)).name("Edit required items").clickHandler(this).build())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
if (slot == 27) {
|
||||
new RequiredPanel(challenge, user, panel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,248 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.ChallengesManager;
|
||||
import world.bentobox.challenges.database.object.ChallengeLevel;
|
||||
import world.bentobox.challenges.utils.GuiUtils;
|
||||
import world.bentobox.challenges.utils.LevelStatus;
|
||||
import world.bentobox.challenges.commands.ChallengesCommand;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.challenges.database.object.Challenge.ChallengeType;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ChallengesPanels {
|
||||
private ChallengesAddon addon;
|
||||
private ChallengesManager manager;
|
||||
private User user;
|
||||
private ChallengeLevel level;
|
||||
private World world;
|
||||
private String permPrefix;
|
||||
private String label;
|
||||
|
||||
public ChallengesPanels(ChallengesAddon addon, User user, String level, World world, String permPrefix, String label) {
|
||||
this.addon = addon;
|
||||
this.manager = addon.getChallengesManager();
|
||||
this.user = user;
|
||||
this.world = world;
|
||||
this.permPrefix = permPrefix;
|
||||
this.label = label;
|
||||
|
||||
if (manager.getAllChallenges(world).isEmpty()) {
|
||||
addon.getLogger().severe("There are no challenges set up!");
|
||||
user.sendMessage("general.errors.general");
|
||||
return;
|
||||
}
|
||||
if (level.isEmpty()) {
|
||||
level = manager.getLevels(world).iterator().next().getUniqueId();
|
||||
}
|
||||
this.level = this.manager.getLevel(level);
|
||||
// Check if level is valid
|
||||
if (!manager.isLevelUnlocked(user, this.level)) {
|
||||
return;
|
||||
}
|
||||
PanelBuilder panelBuilder = new PanelBuilder()
|
||||
.name(user.getTranslation("challenges.gui-title"));
|
||||
|
||||
addChallengeItems(panelBuilder);
|
||||
addNavigation(panelBuilder);
|
||||
addFreeChallanges(panelBuilder);
|
||||
|
||||
// Create the panel
|
||||
Panel panel = panelBuilder.build();
|
||||
panel.open(user);
|
||||
}
|
||||
|
||||
private void addChallengeItems(PanelBuilder panelBuilder) {
|
||||
List<Challenge> levelChallenges = manager.getLevelChallenges(level);
|
||||
// Only show a control panel for the level requested.
|
||||
for (Challenge challenge : levelChallenges) {
|
||||
createItem(panelBuilder, challenge);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFreeChallanges(PanelBuilder panelBuilder) {
|
||||
manager.getFreeChallenges(world).forEach(challenge -> createItem(panelBuilder, challenge));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a panel item for challenge if appropriate and adds it to panelBuilder
|
||||
* @param panelBuilder
|
||||
* @param challenge
|
||||
*/
|
||||
private void createItem(PanelBuilder panelBuilder, Challenge challenge) {
|
||||
// Check completion
|
||||
boolean completed = manager.isChallengeComplete(user, challenge);
|
||||
// If challenge is removed after completion, remove it
|
||||
if (completed && challenge.isRemoveWhenCompleted()) {
|
||||
return;
|
||||
}
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.icon(challenge.getIcon())
|
||||
.name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName())
|
||||
.description(challengeDescription(challenge))
|
||||
.glow(completed)
|
||||
.clickHandler((panel, player, c, s) -> {
|
||||
new TryToComplete(addon).user(player).manager(manager).challenge(challenge)
|
||||
.world(world).permPrefix(permPrefix).label(label).build();
|
||||
return true;
|
||||
})
|
||||
.build();
|
||||
if (challenge.getOrder() >= 0) {
|
||||
panelBuilder.item(challenge.getOrder(),item);
|
||||
} else {
|
||||
panelBuilder.item(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNavigation(PanelBuilder panelBuilder) {
|
||||
// TODO: This if fix for wrong getNumberOfChallengesStillToDo() issue. #23
|
||||
LevelStatus previousStatus = null;
|
||||
|
||||
// Add navigation to other levels
|
||||
for (LevelStatus status: manager.getChallengeLevelStatus(user, world)) {
|
||||
if (status.getLevel().getUniqueId().equals(level)) {
|
||||
// Skip if this is the current level
|
||||
previousStatus = status;
|
||||
continue;
|
||||
}
|
||||
// Create a nice name for the level
|
||||
String name = status.getLevel().getFriendlyName().isEmpty() ? status.getLevel().getUniqueId() : status.getLevel().getFriendlyName();
|
||||
|
||||
if (status.isUnlocked()) {
|
||||
// Clicking on this icon will open up this level's challenges
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.icon(new ItemStack(Material.ENCHANTED_BOOK))
|
||||
.name(name)
|
||||
.description(GuiUtils.stringSplit(
|
||||
user.getTranslation("challenges.navigation","[level]",name),
|
||||
this.addon.getChallengesSettings().getLoreLineLength()))
|
||||
.clickHandler((p, u, c, s) -> {
|
||||
u.closeInventory();
|
||||
u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId());
|
||||
return true;
|
||||
})
|
||||
.build();
|
||||
panelBuilder.item(item);
|
||||
} else {
|
||||
// Clicking on this icon will do nothing because the challenge is not unlocked yet
|
||||
String previousLevelName = status.getPreviousLevel().getFriendlyName().isEmpty() ? status.getPreviousLevel().getUniqueId() : status.getPreviousLevel().getFriendlyName();
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.icon(new ItemStack(Material.BOOK))
|
||||
.name(name)
|
||||
.description(GuiUtils.stringSplit(
|
||||
user.getTranslation("challenges.to-complete",
|
||||
"[challengesToDo]", String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""),
|
||||
"[thisLevel]", previousLevelName),
|
||||
this.addon.getChallengesSettings().getLoreLineLength()))
|
||||
.build();
|
||||
panelBuilder.item(item);
|
||||
}
|
||||
|
||||
previousStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the challenge description for the "item" in the inventory
|
||||
*
|
||||
* @param challenge
|
||||
* @return List of strings splitting challenge string into 25 chars long
|
||||
*/
|
||||
private List<String> challengeDescription(Challenge challenge) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
String level = challenge.getLevel();
|
||||
if (!level.isEmpty()) {
|
||||
result.addAll(splitTrans(user, "challenges.level", "[level]", level));
|
||||
}
|
||||
// Check if completed or not
|
||||
|
||||
boolean complete = addon.getChallengesManager().isChallengeComplete(user, challenge);
|
||||
int maxTimes = challenge.getMaxTimes();
|
||||
long doneTimes = addon.getChallengesManager().getChallengeTimes(user, challenge);
|
||||
if (complete) {
|
||||
result.add(user.getTranslation("challenges.complete"));
|
||||
}
|
||||
if (challenge.isRepeatable()) {
|
||||
if (maxTimes == 0) {
|
||||
|
||||
// Check if the player has maxed out the challenge
|
||||
if (doneTimes < maxTimes) {
|
||||
result.addAll(splitTrans(user, "challenges.completed-times","[donetimes]", String.valueOf(doneTimes),"[maxtimes]", String.valueOf(maxTimes)));
|
||||
} else {
|
||||
result.addAll(splitTrans(user, "challenges.maxed-reached","[donetimes]", String.valueOf(doneTimes),"[maxtimes]", String.valueOf(maxTimes)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!complete || (complete && challenge.isRepeatable())) {
|
||||
result.addAll(challenge.getDescription());
|
||||
if (challenge.getChallengeType().equals(ChallengeType.INVENTORY)) {
|
||||
if (challenge.isTakeItems()) {
|
||||
result.addAll(splitTrans(user, "challenges.item-take-warning"));
|
||||
}
|
||||
} else if (challenge.getChallengeType().equals(ChallengeType.ISLAND)) {
|
||||
result.addAll(splitTrans(user, "challenges.items-closeby"));
|
||||
}
|
||||
}
|
||||
if (complete && (!challenge.getChallengeType().equals(ChallengeType.INVENTORY) || !challenge.isRepeatable())) {
|
||||
result.addAll(splitTrans(user, "challenges.not-repeatable"));
|
||||
return result;
|
||||
}
|
||||
double moneyReward = 0;
|
||||
int expReward = 0;
|
||||
String rewardText = "";
|
||||
if (!complete) {
|
||||
// First time
|
||||
moneyReward = challenge.getRewardMoney();
|
||||
rewardText = challenge.getRewardText();
|
||||
expReward = challenge.getRewardExperience();
|
||||
if (!rewardText.isEmpty()) {
|
||||
result.addAll(splitTrans(user, "challenges.first-time-rewards"));
|
||||
}
|
||||
} else {
|
||||
// Repeat challenge
|
||||
moneyReward = challenge.getRepeatMoneyReward();
|
||||
rewardText = challenge.getRepeatRewardText();
|
||||
expReward = challenge.getRepeatExperienceReward();
|
||||
if (!rewardText.isEmpty()) {
|
||||
result.addAll(splitTrans(user, "challenges.repeat-rewards"));
|
||||
}
|
||||
|
||||
}
|
||||
if (!rewardText.isEmpty()) {
|
||||
result.addAll(splitTrans(user,rewardText));
|
||||
}
|
||||
if (expReward > 0) {
|
||||
result.addAll(splitTrans(user,"challenges.exp-reward", "[reward]", String.valueOf(expReward)));
|
||||
}
|
||||
if (addon.getPlugin().getSettings().isUseEconomy() && moneyReward > 0) {
|
||||
result.addAll(splitTrans(user,"challenges.money-reward", "[reward]", String.valueOf(moneyReward)));
|
||||
}
|
||||
// Final placeholder change for [label]
|
||||
result.replaceAll(x -> x.replace("[label]", label));
|
||||
return result;
|
||||
}
|
||||
|
||||
private Collection<? extends String> splitTrans(User user, String string, String...strings) {
|
||||
return GuiUtils.stringSplit(user.getTranslation(string, strings),
|
||||
this.addon.getChallengesSettings().getLoreLineLength());
|
||||
}
|
||||
}
|
@ -1,320 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.ChallengesManager;
|
||||
import world.bentobox.challenges.commands.ChallengesCommand;
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.challenges.database.object.Challenge.ChallengeType;
|
||||
import world.bentobox.challenges.database.object.ChallengeLevel;
|
||||
import world.bentobox.challenges.utils.GuiUtils;
|
||||
import world.bentobox.challenges.utils.LevelStatus;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class ChallengesPanels2 {
|
||||
|
||||
public enum Mode {
|
||||
ADMIN,
|
||||
EDIT,
|
||||
PLAYER
|
||||
}
|
||||
private ChallengesAddon addon;
|
||||
private ChallengesManager manager;
|
||||
private User requester;
|
||||
private ChallengeLevel level;
|
||||
private World world;
|
||||
private String permPrefix;
|
||||
private String label;
|
||||
private Mode mode;
|
||||
private User target;
|
||||
|
||||
public ChallengesPanels2(ChallengesAddon addon, User requester, User target, String level, World world, String permPrefix, String label, Mode mode) {
|
||||
this.addon = addon;
|
||||
this.manager = addon.getChallengesManager();
|
||||
this.requester = requester;
|
||||
this.target = target;
|
||||
this.world = world;
|
||||
this.permPrefix = permPrefix;
|
||||
this.label = label;
|
||||
this.mode = mode;
|
||||
|
||||
if (manager.getAllChallenges(world).isEmpty()) {
|
||||
addon.getLogger().severe("There are no challenges set up!");
|
||||
requester.sendMessage("general.errors.general");
|
||||
return;
|
||||
}
|
||||
if (level.isEmpty()) {
|
||||
// TODO: open the farthest challenge panel
|
||||
level = manager.getLevels(world).iterator().next().getUniqueId();
|
||||
}
|
||||
this.level = manager.getLevel(level);
|
||||
// Check if level is valid
|
||||
if (mode.equals(Mode.PLAYER) && !manager.isLevelUnlocked(requester, this.level)) {
|
||||
return;
|
||||
}
|
||||
PanelBuilder panelBuilder = new PanelBuilder();
|
||||
switch (mode) {
|
||||
case ADMIN:
|
||||
panelBuilder.name(requester.getTranslation("challenges.admin.gui-title"));
|
||||
break;
|
||||
case EDIT:
|
||||
panelBuilder.name(requester.getTranslation("challenges.admin.edit-gui-title"));
|
||||
break;
|
||||
case PLAYER:
|
||||
panelBuilder.name(requester.getTranslation("challenges.gui-title"));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
addChallengeItems(panelBuilder);
|
||||
addNavigation(panelBuilder);
|
||||
addFreeChallanges(panelBuilder);
|
||||
|
||||
// Create the panel
|
||||
Panel panel = panelBuilder.build();
|
||||
panel.open(requester);
|
||||
}
|
||||
|
||||
private void addChallengeItems(PanelBuilder panelBuilder) {
|
||||
// Only show a control panel for the level requested.
|
||||
for (Challenge challenge : manager.getLevelChallenges(level)) {
|
||||
createItem(panelBuilder, challenge);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFreeChallanges(PanelBuilder panelBuilder) {
|
||||
manager.getFreeChallenges(world).forEach(challenge -> createItem(panelBuilder, challenge));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a panel item for challenge if appropriate and adds it to panelBuilder
|
||||
* @param panelBuilder
|
||||
* @param challenge
|
||||
*/
|
||||
private void createItem(PanelBuilder panelBuilder, Challenge challenge) {
|
||||
// For admin, glow means activated. For user, glow means done
|
||||
boolean glow = false;
|
||||
switch (mode) {
|
||||
case ADMIN:
|
||||
glow = challenge.isDeployed();
|
||||
break;
|
||||
case EDIT:
|
||||
glow = manager.isChallengeComplete(requester, challenge);
|
||||
break;
|
||||
case PLAYER:
|
||||
glow = manager.isChallengeComplete(requester, challenge);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
// If not admin and challenge is removed after completion, remove it
|
||||
if (mode.equals(Mode.PLAYER) && glow && challenge.isRemoveWhenCompleted()) {
|
||||
return;
|
||||
}
|
||||
PanelItemBuilder itemBuilder = new PanelItemBuilder()
|
||||
.icon(challenge.getIcon())
|
||||
.name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName())
|
||||
.description(challengeDescription(challenge))
|
||||
.glow(glow);
|
||||
if (mode.equals(Mode.ADMIN)) {
|
||||
// Admin click
|
||||
itemBuilder.clickHandler((panel, player, c, s) -> {
|
||||
new AdminGUI(addon, player, challenge, world, permPrefix, label);
|
||||
return true;
|
||||
});
|
||||
|
||||
} else if (mode.equals(Mode.EDIT)) {
|
||||
// Admin edit click
|
||||
itemBuilder.clickHandler((panel, player, c, s) -> {
|
||||
new AdminEditGUI(addon, player, target, challenge, world, permPrefix, label);
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
// Player click
|
||||
itemBuilder.clickHandler((panel, player, c, s) -> {
|
||||
new TryToComplete(addon, player, challenge, world, label, permPrefix).build();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// If the challenge has a specific slot allocated, use it
|
||||
if (challenge.getOrder() >= 0) {
|
||||
panelBuilder.item(challenge.getOrder(),itemBuilder.build());
|
||||
} else {
|
||||
panelBuilder.item(itemBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
private void addNavigation(PanelBuilder panelBuilder) {
|
||||
// TODO: This if fix for wrong getNumberOfChallengesStillToDo() issue. #23
|
||||
LevelStatus previousStatus = null;
|
||||
|
||||
// Add navigation to other levels
|
||||
for (LevelStatus status: manager.getChallengeLevelStatus(requester, world)) {
|
||||
if (status.getLevel().getUniqueId().equalsIgnoreCase(level.getUniqueId())) {
|
||||
// Skip if this is the current level
|
||||
previousStatus = status;
|
||||
continue;
|
||||
}
|
||||
// Create a nice name for the level
|
||||
String name = status.getLevel().getFriendlyName().isEmpty() ? status.getLevel().getUniqueId() : status.getLevel().getFriendlyName();
|
||||
|
||||
if (mode.equals(Mode.ADMIN) || mode.equals(Mode.EDIT) || status.isUnlocked()) {
|
||||
// Clicking on this icon will open up this level's challenges
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.icon(new ItemStack(Material.ENCHANTED_BOOK))
|
||||
.name(name)
|
||||
.description(GuiUtils.stringSplit(
|
||||
requester.getTranslation("challenges.navigation","[level]",name),
|
||||
this.addon.getChallengesSettings().getLoreLineLength()))
|
||||
.clickHandler((p, u, c, s) -> {
|
||||
u.closeInventory();
|
||||
u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId());
|
||||
return true;
|
||||
})
|
||||
.build();
|
||||
panelBuilder.item(item);
|
||||
} else {
|
||||
// Clicking on this icon will do nothing because the challenge is not unlocked yet
|
||||
String previousLevelName = status.getPreviousLevel().getFriendlyName().isEmpty() ? status.getPreviousLevel().getUniqueId() : status.getPreviousLevel().getFriendlyName();
|
||||
PanelItem item = new PanelItemBuilder()
|
||||
.icon(new ItemStack(Material.BOOK))
|
||||
.name(name)
|
||||
.description(GuiUtils.stringSplit(requester.getTranslation("challenges.to-complete",
|
||||
"[challengesToDo]", String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""),
|
||||
"[thisLevel]", previousLevelName),
|
||||
this.addon.getChallengesSettings().getLoreLineLength()))
|
||||
.build();
|
||||
panelBuilder.item(item);
|
||||
}
|
||||
|
||||
previousStatus = status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the challenge description for the "item" in the inventory
|
||||
*
|
||||
* @param challenge
|
||||
* @return List of strings splitting challenge string into 25 chars long
|
||||
*/
|
||||
private List<String> challengeDescription(Challenge challenge) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
String level = challenge.getLevel();
|
||||
if (!level.isEmpty()) {
|
||||
result.addAll(splitTrans(requester, "challenges.level", "[level]", level));
|
||||
}
|
||||
|
||||
if (mode.equals(Mode.ADMIN)) {
|
||||
if ((!challenge.getChallengeType().equals(ChallengeType.INVENTORY) || !challenge.isRepeatable())) {
|
||||
result.addAll(splitTrans(requester, "challenges.not-repeatable"));
|
||||
} else {
|
||||
result.addAll(splitTrans(requester, "challenges.repeatable", "[maxtimes]", String.valueOf(challenge.getMaxTimes())));
|
||||
}
|
||||
if (challenge.getChallengeType().equals(ChallengeType.INVENTORY) && challenge.isTakeItems()) {
|
||||
result.addAll(splitTrans(requester, "challenges.item-take-warning"));
|
||||
}
|
||||
result.addAll(addRewards(challenge, true, true));
|
||||
} else {
|
||||
// Check if completed or not
|
||||
boolean complete = addon.getChallengesManager().isChallengeComplete(requester, challenge);
|
||||
int maxTimes = challenge.getMaxTimes();
|
||||
long doneTimes = addon.getChallengesManager().getChallengeTimes(requester, challenge);
|
||||
if (complete) {
|
||||
result.add(requester.getTranslation("challenges.complete"));
|
||||
}
|
||||
|
||||
if (challenge.isRepeatable()) {
|
||||
if (maxTimes == 0) {
|
||||
|
||||
// Check if the player has maxed out the challenge
|
||||
if (doneTimes < maxTimes) {
|
||||
result.addAll(splitTrans(requester, "challenges.completed-times","[donetimes]", String.valueOf(doneTimes),"[maxtimes]", String.valueOf(maxTimes)));
|
||||
} else {
|
||||
result.addAll(splitTrans(requester, "challenges.maxed-reached","[donetimes]", String.valueOf(doneTimes),"[maxtimes]", String.valueOf(maxTimes)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!complete || (complete && challenge.isRepeatable())) {
|
||||
result.addAll(challenge.getDescription());
|
||||
if (challenge.getChallengeType().equals(ChallengeType.INVENTORY)) {
|
||||
if (challenge.isTakeItems()) {
|
||||
result.addAll(splitTrans(requester, "challenges.item-take-warning"));
|
||||
}
|
||||
} else if (challenge.getChallengeType().equals(ChallengeType.ISLAND)) {
|
||||
result.addAll(splitTrans(requester, "challenges.items-closeby"));
|
||||
}
|
||||
}
|
||||
if (complete && (!challenge.getChallengeType().equals(ChallengeType.INVENTORY) || !challenge.isRepeatable())) {
|
||||
result.addAll(splitTrans(requester, "challenges.not-repeatable"));
|
||||
result.replaceAll(x -> x.replace("[label]", label));
|
||||
return result;
|
||||
}
|
||||
result.addAll(addRewards(challenge, complete, false));
|
||||
}
|
||||
// Final placeholder change for [label]
|
||||
result.replaceAll(x -> x.replace("[label]", label));
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> addRewards(Challenge challenge, boolean complete, boolean admin) {
|
||||
List<String> result = new ArrayList<>();
|
||||
double moneyReward = 0;
|
||||
int expReward = 0;
|
||||
String rewardText = "";
|
||||
if (admin || !complete) {
|
||||
// First time
|
||||
moneyReward = challenge.getRewardMoney();
|
||||
rewardText = challenge.getRewardText();
|
||||
expReward = challenge.getRewardExperience();
|
||||
if (!rewardText.isEmpty()) {
|
||||
result.addAll(splitTrans(requester, "challenges.first-time-rewards"));
|
||||
}
|
||||
}
|
||||
if (admin || complete){
|
||||
// Repeat challenge
|
||||
moneyReward = challenge.getRepeatMoneyReward();
|
||||
rewardText = challenge.getRepeatRewardText();
|
||||
expReward = challenge.getRepeatExperienceReward();
|
||||
if (!rewardText.isEmpty()) {
|
||||
result.addAll(splitTrans(requester, "challenges.repeat-rewards"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!rewardText.isEmpty()) {
|
||||
result.addAll(splitTrans(requester,rewardText));
|
||||
}
|
||||
if (expReward > 0) {
|
||||
result.addAll(splitTrans(requester,"challenges.exp-reward", "[reward]", String.valueOf(expReward)));
|
||||
}
|
||||
if (addon.getPlugin().getSettings().isUseEconomy() && moneyReward > 0) {
|
||||
result.addAll(splitTrans(requester,"challenges.money-reward", "[reward]", String.valueOf(moneyReward)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Collection<? extends String> splitTrans(User user, String string, String...strings) {
|
||||
return GuiUtils.stringSplit(user.getTranslation(string, strings),
|
||||
this.addon.getChallengesSettings().getLoreLineLength());
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.bentobox.api.panels.PanelListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CreateChallengeListener implements PanelListener {
|
||||
|
||||
private ChallengesAddon addon;
|
||||
private User user;
|
||||
|
||||
public CreateChallengeListener(ChallengesAddon addon, User user) {
|
||||
this.addon = addon;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
// Nothing to setup
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
addon.getChallengesManager().createChallenge("uniqueID");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryClick(User user, InventoryClickEvent event) {
|
||||
// Allow drag and drop
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class CreateChallengePanel {
|
||||
|
||||
public CreateChallengePanel(ChallengesAddon addon, User user) {
|
||||
new PanelBuilder().size(49).listener(new CreateChallengeListener(addon, user)).user(user).build();
|
||||
}
|
||||
|
||||
}
|
@ -1,165 +0,0 @@
|
||||
package world.bentobox.challenges.panel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import world.bentobox.challenges.database.object.Challenge;
|
||||
import world.bentobox.bentobox.api.panels.Panel;
|
||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||
import world.bentobox.bentobox.api.panels.PanelListener;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
/**
|
||||
* Handles the requirements for a challenge
|
||||
* Items, blocks, entities
|
||||
* @author tastybento
|
||||
* @deprecated All panels are reworked.
|
||||
*/
|
||||
@Deprecated
|
||||
public class RequiredPanel implements ClickHandler, PanelListener {
|
||||
private static final int CONTROL_NUMBER = 4;
|
||||
private Challenge challenge;
|
||||
private User user;
|
||||
private Panel panel;
|
||||
private Panel referringPanel;
|
||||
|
||||
/**
|
||||
* @param challenge
|
||||
* @param user
|
||||
*/
|
||||
public RequiredPanel(Challenge challenge, User user, Panel referringPanel) {
|
||||
this.challenge = challenge;
|
||||
this.user = user;
|
||||
this.panel = openPanel();
|
||||
this.referringPanel = referringPanel;
|
||||
}
|
||||
|
||||
private Panel openPanel() {
|
||||
PanelBuilder pb = new PanelBuilder().listener(this).name("Required Items").size(49);
|
||||
// Add the name and description icon
|
||||
pb.item(new PanelItemBuilder().icon(Material.BOOK).name(challenge.getFriendlyName()).description(challenge.getDescription()).clickHandler(this).build());
|
||||
// Add take all button
|
||||
pb.item(new PanelItemBuilder().icon(Material.BOOK).name("Take Items").description(challenge.isTakeItems() ? "Yes" : "No").clickHandler(this).build());
|
||||
// Add save button
|
||||
pb.item(new PanelItemBuilder().icon(Material.BOOK).name("Save").clickHandler(this).build());
|
||||
// Add cancel button
|
||||
pb.item(new PanelItemBuilder().icon(Material.BOOK).name("Cancel").clickHandler(this).build());
|
||||
|
||||
switch (challenge.getChallengeType()) {
|
||||
case INVENTORY:
|
||||
// Show the required items in the inventory
|
||||
challenge.getRequiredItems().stream().map(i -> new PanelItemBuilder().icon(i).clickHandler(this).build()).forEach(pb::item);
|
||||
return pb.user(user).build();
|
||||
case ISLAND:
|
||||
// Create the blocks required
|
||||
challenge.getRequiredBlocks().entrySet().stream().map(en -> new ItemStack(en.getKey(), en.getValue())).map(i -> new PanelItemBuilder().icon(i).clickHandler(this).build()).forEach(pb::item);
|
||||
// Create the entities required
|
||||
challenge.getRequiredEntities().entrySet().stream().map(this::toSpawnEgg).map(i -> new PanelItemBuilder()
|
||||
.icon(i)
|
||||
.name(Util.prettifyText(i.getType().toString()))
|
||||
.description("Entity")
|
||||
.clickHandler(this)
|
||||
.build()).forEach(pb::item);
|
||||
return pb.user(user).build();
|
||||
case OTHER:
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
private ItemStack toSpawnEgg(Entry<EntityType, Integer> en) {
|
||||
Material mat = Material.getMaterial(en.getKey().name() + "_SPAWN_EGG");
|
||||
if (mat != null) {
|
||||
return new ItemStack(mat, en.getValue());
|
||||
} else {
|
||||
return new ItemStack(Material.COW_SPAWN_EGG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onClick(Panel panel, User user, ClickType clickType, int slot) {
|
||||
Bukkit.getLogger().info("DEBUG: slot = " + slot);
|
||||
return slot < CONTROL_NUMBER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
// nothing to do
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onInventoryClick(User user, InventoryClickEvent event) {
|
||||
// Allow drag and drop
|
||||
event.setCancelled(event.getRawSlot() < CONTROL_NUMBER);
|
||||
|
||||
Bukkit.getLogger().info("DEBUG: inv slot = " + event.getSlot());
|
||||
Bukkit.getLogger().info("DEBUG: inv slot type = " + event.getSlotType());
|
||||
if (event.getSlot() == 1) {
|
||||
// Take items
|
||||
challenge.setTakeItems(!challenge.isTakeItems());
|
||||
// Update item
|
||||
event.getInventory().setItem(event.getSlot(), new PanelItemBuilder().icon(Material.BOOK).name("Take Items").description(challenge.isTakeItems() ? "Yes" : "No").build().getItem());
|
||||
return;
|
||||
}
|
||||
if (event.getSlot() == 3) {
|
||||
// Cancel
|
||||
referringPanel.open(user);
|
||||
return;
|
||||
// Return to previous panel
|
||||
}
|
||||
// Save
|
||||
if (event.getSlot() != 2) {
|
||||
return;
|
||||
}
|
||||
// Save changes
|
||||
switch (challenge.getChallengeType()) {
|
||||
case INVENTORY:
|
||||
List<ItemStack> reqItems = new ArrayList<>();
|
||||
// Skip first item
|
||||
for (int i = CONTROL_NUMBER; i < event.getInventory().getSize(); i++) {
|
||||
if (event.getInventory().getItem(i) != null) {
|
||||
reqItems.add(event.getInventory().getItem(i));
|
||||
}
|
||||
}
|
||||
challenge.setRequiredItems(reqItems);
|
||||
user.sendMessage("challenges.admin.saved");
|
||||
// TODO: save challenges
|
||||
event.getInventory().setItem(event.getSlot(), new PanelItemBuilder().icon(Material.BOOK).name("Save").description("Saved").build().getItem());
|
||||
break;
|
||||
case ISLAND:
|
||||
break;
|
||||
case OTHER:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
package world.bentobox.challenges;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.ItemFactory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.SpawnEggMeta;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import world.bentobox.challenges.ChallengesAddon;
|
||||
import world.bentobox.challenges.ParseItem;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@Deprecated
|
||||
public class ParseItemTest {
|
||||
|
||||
private static ChallengesAddon addon;
|
||||
private static ItemFactory itemFactory;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
addon = mock(ChallengesAddon.class);
|
||||
when(addon.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
Server server = mock(Server.class);
|
||||
World world = mock(World.class);
|
||||
when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
|
||||
when(server.getWorld("world")).thenReturn(world);
|
||||
when(server.getVersion()).thenReturn("BSB_Mocking");
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
when(server.getPluginManager()).thenReturn(pluginManager);
|
||||
|
||||
itemFactory = mock(ItemFactory.class);
|
||||
when(server.getItemFactory()).thenReturn(itemFactory);
|
||||
|
||||
Bukkit.setServer(server);
|
||||
|
||||
SpawnEggMeta itemMeta = mock(SpawnEggMeta.class);
|
||||
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
|
||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parseItemTest() {
|
||||
// Nothing test
|
||||
assertNull(new ParseItem(addon, "").getItem());
|
||||
// other
|
||||
assertNull(new ParseItem(addon, "::::::::::::::").getItem());
|
||||
// other
|
||||
assertNull(new ParseItem(addon, "anything:anything").getItem());
|
||||
// Bad material
|
||||
assertNull(new ParseItem(addon, "nosuchmaterial:2").getItem());
|
||||
|
||||
// Material
|
||||
for (Material mat : Material.values()) {
|
||||
ItemStack test = new ParseItem(addon, mat.name() + ":5").getItem();
|
||||
if (test != null) {
|
||||
if (test.getType().toString().endsWith("_ITEM") && !mat.toString().endsWith("_ITEM")) {
|
||||
assertEquals(mat.toString() + "_ITEM", test.getType().toString());
|
||||
} else {
|
||||
assertEquals(mat, test.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing amount
|
||||
ItemStack test = new ParseItem(addon, "STONE:").getItem();
|
||||
assertNull(test);
|
||||
|
||||
|
||||
// Test 3
|
||||
// Bad material
|
||||
assertNull(new ParseItem(addon, "nosuchmaterial:2:2").getItem());
|
||||
|
||||
// Bad amount
|
||||
assertNull(new ParseItem(addon, "STONE:1:sdfgsd").getItem());
|
||||
|
||||
// Missing amount = 1
|
||||
test = new ParseItem(addon, "STONE:1:").getItem();
|
||||
assertNotNull(test); // This is okay, it's just a 2
|
||||
|
||||
// Test Potions
|
||||
PotionMeta itemMeta = mock(PotionMeta.class);
|
||||
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
|
||||
when(Bukkit.getItemFactory()).thenReturn(itemFactory);
|
||||
|
||||
// Bad material
|
||||
assertNull(new ParseItem(addon, "nosuchmaterial:JUMP:2:NOTEXTENDED:NOSPLASH:2").getItem());
|
||||
// Bad amount
|
||||
assertNull(new ParseItem(addon, "POTION:JUMP:2:NOTEXTENDED:NOSPLASH:asfdas").getItem());
|
||||
test = new ParseItem(addon, "POTION:JUMP:2:NOTEXTENDED:NOSPLASH:").getItem();
|
||||
assertNull(test);
|
||||
|
||||
test = new ParseItem(addon, "POTION:JUMP:2:NOTEXTENDED:NOSPLASH:1").getItem();
|
||||
assertEquals(Material.POTION, test.getType());
|
||||
test = new ParseItem(addon, "POTION:JUMP:2").getItem();
|
||||
assertEquals(Material.POTION, test.getType());
|
||||
test = new ParseItem(addon, "POTION:STRENGTH:1:EXTENDED:SPLASH:1").getItem();
|
||||
assertEquals(Material.SPLASH_POTION, test.getType());
|
||||
test = new ParseItem(addon, "POTION:INSTANT_DAMAGE:2::LINGER:2").getItem();
|
||||
assertEquals(Material.LINGERING_POTION, test.getType());
|
||||
test = new ParseItem(addon, "TIPPED_ARROW:STRENGTH:1:::1").getItem();
|
||||
assertEquals(Material.TIPPED_ARROW, test.getType());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user