BossShopPro
Item Comparison | 物品对比
字数统计: 2744字
如何接入API
首先你需要添加BossShopPro.jar 到你的Libraries里.
你可以使用下方方法来获取:
- import org.black_ixx.bossshop.BossShop;
- import org.black_ixx.bossshop.api.BossShopAPI;
- import org.bukkit.Bukkit;
- import org.bukkit.plugin.Plugin;
-
- public class BSPHook {
-
- private BossShop bs; //BossShopPro 插件实例
-
- public BSPHook(){
- Plugin plugin = Bukkit.getPluginManager().getPlugin("BossShopPro"); //获取BossShopPro 插件
-
- if(plugin==null){ //Not installed?
- System.out.print("[BSP Hook] BossShopPro was not found... you can download it here: https://www.spigotmc.org/resources/25699/");
- return;
- }
-
- bs = (BossShop) plugin; //Success :)
-
- }
-
-
- public BossShopAPI getBSPAPI(){
- return bs.getAPI(); //Returns BossShopPro API
- }
-
- }
打开一个商店
- public boolean openShop(Player p, String shop_name){
- BSShop shop = bs.getAPI().getShop(shop_name);
- if(shop==null){
- p.sendMessage(ChatColor.RED+"Shop "+shop_name+" not found...");
- return false;
- }
- bs.getAPI().openShop(p, shop);
- return true;
- }
检查一个物品是否属于BossShopPro
- //例子:物品事件
- if(bs.getAPI().isValidShop(event.getInventory())){
- //商店物品动作
- }else{
- //其余
- }
将一个商店物品添加到商店中
- //创建一个自定义BSBuy (商店物品)
- BSBuy buy = bs.getAPI().createBSBuy(BSRewardType.Shop, BSPriceType.Nothing, "item_shop", null, null, 1, "OpenShop.Item_Shop");
- //获取商店信息
- BSShop shop = bs.getAPI().getShop("menu");
- //将物品添加到商店
- ItemStack menu_item = [...]
- bs.getAPI().addItemToShop(menu_item, buy, shop);
注册一个自定义点数插件
你的插件必须要在BossShopPro之前载入
Plugin.yml
- loadbefore: [BossShop]
拓展BSPointsPlugin class
- [暂无]
然后onEnable,示例你的class,然后注册使用方法
- new Points().register();
如何创建一个附属插件
首先添加BossShopPro.jar 到你的libraries里。正常来说Bukkit插件的main class需要拓展org.bukkit.plugin.java.JavaPlugin,然而当你创建一个BossShopPro 附属插件时你需要导入以下的拓展之一:
· org.black_ixx.bossshop.api.BossShopAddon – 简易版附属
· org.black_ixx.bossshop.api.BossShopAddonConfigurable – 提供额外的对config文件的帮助,会在"plugins/BossShopPro/Addons/<名称>/" 中创建文件
- import org.black_ixx.bossshop.api.BSAddonStorage;
- import org.black_ixx.bossshop.api.BossShopAddon;
- import org.bukkit.command.CommandSender;
- public class BSPAddon extends BossShopAddon{
- @Override
- public String getAddonName() {
- return "ExampleAddon"; //在这里放你想要的附属插件名字
- }
- @Override
- public String getRequiredBossShopVersion() {
- return "1.1.7"; //这里放你的插件所支持的最老版本的BSP插件build版本(只需要数字和点;不需要"v"前缀)
- }
- @Override
- public void enableAddon() {
- //这个方法在附属插件加载后执行(会在BossShopPro被加载时执行;商店,商店物品,奖励类型等还暂时缺失)
- //使用的方法:创建自定义储存文件到附属插件文件夹内
- //这些储存文件类型暂时被限制到一组方法之中并无法直接获得Bukkit FileConfiguration 例子的权限,
- //因为在未来会有其他新的储存类型可能会被告知
- //下方的例子显示了你可以操作的部分。当然,储存class组不止是有下方例子的选项
- BSAddonStorage storage = this.createStorage(this, "StorageFileName"); //创建并装载一个储存文件
- storage.set("Number", 2); //设置一个整数数值
- storage.set("Text", "This is some text"); //设置一个字符数值
- int number = storage.getInt("Value", -1); //读取数值(如果没有找到数值, 基础数值“-1”会被返回)
- String text = storage.getString("Text", null); //读取数值,自失败的情况下返回无数值
- storage.save(); //储存文件
- storage.saveAsync(); //异步存储文件
- }
- @Override
- public void disableAddon() {
- //当附加插件被禁用时执行
- }
- @Override
- public void bossShopFinishedLoading() {
- //当BSP被完全执行时执行(包括但不限于商店,商品和奖励类型)
- }
- @Override
- public void bossShopReloaded(CommandSender sender) {
- //当BSP被手动重新装载之后执行("/bossshop reload")
- }
- }
- import org.black_ixx.bossshop.api.BSAddonConfig;
- import org.black_ixx.bossshop.api.BossShopAddonConfigurable;
- import org.black_ixx.bossshop.managers.config.FileHandler;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.file.FileConfiguration;
- public class BSPAddonConfigurable extends BossShopAddonConfigurable{
- @Override
- public String getAddonName() {
- return "ExampleAddonConfigurable"; //在这里选择附加插件的名字
- }
- @Override
- public String getRequiredBossShopVersion() {
- return "1.1.7"; //在这里放入最老能支持附加插件的BSP版本(只有数字和小数点; 没有"v" 前缀)
- }
- @Override
- public void enableAddon() {
- //当附加插件被允许时执行 当BSP核心被装载时发生, 商品,奖励类型和更多都处于缺失状态)
- //设置文件方法A:
- if(!getAddonConfig().getFile().exists()){
- new FileHandler().copyFromJar(this, "config.yml"); //这个文件处理器允许复制并完成addon.jar 文件里的设置文件
- }
- //设置文件方法B:
- getConfig().options().copyDefaults(true);
- getConfig().addDefault("PointsPlugin", "TokenEnchant");
- getConfig().addDefault("Message.NotEnoughPoints", "&cYou don't have enough Tokens!");
- getConfig().addDefault("Placeholder.DisplayPoints", "%points2% Tokens");
- getConfig().addDefault("PointsDisplay.Enabled", false);
- saveConfig(); //从v1.2.1. 开始运作,在使用"getAddonConfig().save();"之前
- //你可以访问文件设置,并为所欲为:
- FileConfiguration config = getConfig();
- //或者你可以访问 BSAddonConfig, 以提供更多的方法
- BSAddonConfig addonconfig = getAddonConfig();
- addonconfig.saveAsync(); //Saves file asynchronously
- addonconfig.deleteAll("Key"); //删除全部"Key."打头的设置访问记录
- }
- @Override
- public void disableAddon() {
- //当附加插件被禁用时执行
- }
- @Override
- public void bossShopFinishedLoading() {
- /当BSP被完全装载执行
- }
- @Override
- public void bossShopReloaded(CommandSender sender) {
- //当BSP被手动重新装载时执行("/bossshop reload")
- }
- @Override
- public boolean saveConfigOnDisable() {
- return false; //如果设置为真,设置文件每次附加文件被禁用会重新保存 }
- }
如何创建一个自定义奖励类型
首先你需要创建一个奖励class
- import java.util.List;
- import org.black_ixx.bossshop.core.BSBuy;
- import org.black_ixx.bossshop.core.rewards.BSRewardType;
- import org.black_ixx.bossshop.managers.ClassManager;
- import org.black_ixx.bossshop.managers.misc.InputReader;
- import org.black_ixx.bossshop.managers.misc.StringManipulationLib;
- import org.bukkit.entity.Player;
- import org.bukkit.event.inventory.ClickType;
- import net.milkbowl.vault.permission.Permission;
- public class BSRewardTypePermission extends BSRewardType{
- public Object createObject(Object o, boolean force_final_state){ //force_final_state 总会是真,除非用BossShopProConfigure 访问
- return InputReader.readStringList(o); //你可以把设置文件里的物品变成任何物品. 物品会被返回到这里.在以后会有用
- }
- public boolean validityCheck(String item_name, Object o){ //当"createObject" 被召唤之后执行. 在这里你可以查看物品的真实性.
- if(o!=null){
- return true;
- }
- ClassManager.manager.getBugFinder().severe("Was not able to create ShopItem "+item_name+"! The reward object needs to be a list of permissions (text lines).");
- return false;
- }
- public void enableType(){ //如果你的奖励类型有任何特殊性质,在这里开启
- ClassManager.manager.getSettings().setPermissionsEnabled(true);
- ClassManager.manager.getSettings().setVaultEnabled(true);
- }
- @Override
- public boolean canBuy(Player p, BSBuy buy, boolean message_if_no_success, Object reward, ClickType clickType) { //在这里同意、拒绝玩家购买商品
- for (String s : (List<String>) reward){
- if (!p.hasPermission(s)) {
- return true; //玩家缺少权限?可以买!
- }
- }
- if(message_if_no_success){
- ClassManager.manager.getMessageHandler().sendMessage("Main.AlreadyBought", p); //如果玩家有以下全部的权限可以禁止玩家购买
- }
- return false;
- }
- @Override
- public void giveReward(Player p, BSBuy buy, Object reward, ClickType clickType) { //如果所有都成功玩家在这里拿到奖励
- List<String> permissions = (List<String>) reward;
- Permission per = ClassManager.manager.getVaultHandler().getPermission();
- for (String s : permissions) {
- per.playerAdd(p, s);
- }
- }
- @Override
- public String getDisplayReward(Player p, BSBuy buy, Object reward, ClickType clickType) { //在这里定义"%reward%" 定位符怎么展示 List<String> permissions = (List<String>) reward;
- String permissions_formatted = StringManipulationLib.formatList(permissions);
- return ClassManager.manager.getMessageHandler().get("Display.Permission").replace("%permissions%", permissions_formatted);
- }
- @Override
- public String[] createNames() { //在这里定义引导奖励的所有名称, 第一个入口是主要名称.
- return new String[]{"permission", "permissions"};
- }
- @Override
- public boolean mightNeedShopUpdate() { //在这里决定物品被购买之后商店是否刷新
- return true;
- }
- //以下是可选择的:
- @Override
- public boolean logTransaction(){
- return false; //默认设置为真. 如果你不希望购买被记录,把这个设置为假
- }
- }
- import org.black_ixx.bossshop.core.BSBuy;
- import org.black_ixx.bossshop.core.rewards.BSRewardTypeNumber;
- import org.black_ixx.bossshop.managers.ClassManager;
- import org.black_ixx.bossshop.managers.misc.InputReader;
- import org.bukkit.entity.Player;
- import org.bukkit.event.inventory.ClickType;
- public class BSRewardTypeExp extends BSRewardTypeNumber{
- public Object createObject(Object o, boolean force_final_state){ //force_final_state 总会是真除非被BossShopProConfigure 工具访问
- return InputReader.getInt(o, -1); //尝试读取设置内奖励的数字; 失败返回-1
- }
- public boolean validityCheck(String item_name, Object o){ //这个方法当"createObject" 被召唤时执行. 这里你可以查看物品真实性.
- if((Integer)o!=-1){
- return true;
- }
- ClassManager.manager.getBugFinder().severe("Was not able to create ShopItem "+item_name+"! The reward object needs to be a valid Integer number. Example: '7' or '12'.");
- return false;
- }
- public void enableType(){ //你过你的奖励类型有任何特殊性质,在这里开启
- }
- @Override
- public boolean canBuy(Player p, BSBuy buy, boolean message_if_no_success, Object reward, ClickType clickType) { //这里你可以同意、拒绝玩家购买
- return true;
- }
- @Override
- public void giveReward(Player p, BSBuy buy, Object reward, ClickType clickType) { //如果全部过程顺利玩家在这里拿到奖励
- int exp = (int) ClassManager.manager.getMultiplierHandler().calculateRewardWithMultiplier(p, buy, clickType, ((Integer) reward), false); //如果你想要倍数被兼容的话,请使用倍数处理程序.重要: 在这种情况下你的pricetype必须和rewardtype一样
- p.setLevel(p.getLevel() + exp);
- }
- @Override
- public String getDisplayReward(Player p, BSBuy buy, Object reward, ClickType clickType) { //这里你决定了"%reward%" 占位符怎么展示这种奖励
- int exp = (int) ClassManager.manager.getMultiplierHandler().calculateRewardWithMultiplier(p, buy, clickType, ((Integer) reward), true);
- return ClassManager.manager.getMessageHandler().get("Display.Exp").replace("%levels%", String.valueOf(exp));
- }
- @Override
- public String[] createNames() { //这里你决定所有指向奖励的名称,第一个入口是主要名称.
- return new String[]{"exp", "xp", "level", "levels"};
- }
- @Override
- public boolean mightNeedShopUpdate() { //这里你决定在奖励被购买之后商店是否刷新
- return true;
- }
- @Override
- public boolean isIntegerValue() { //这里你决定奖励要么是integer价格要么是double价格
- return true;
- }
- }
自定义价格类型例子
- import org.black_ixx.bossshop.core.BSBuy;
- import org.black_ixx.bossshop.core.prices.BSPriceTypeNumber;
- import org.black_ixx.bossshop.managers.ClassManager;
- import org.black_ixx.bossshop.managers.misc.InputReader;
- import org.black_ixx.bossshop.misc.MathTools;
- import org.bukkit.entity.Player;
- import org.bukkit.event.inventory.ClickType;
- public class BSPriceTypeThirdCurrencyVariable extends BSPriceTypeNumber{
- private CustomPoints cp;
- public BSPriceTypeThirdCurrencyVariable(CustomPoints points){
- this.cp = points;
- updateNames(); //更新进入商店设置需要的名称从而使用这种价格类型: 现在自定义点数被设置为点数的名称(看#createNames())
- }
- /从设置接受价格物品并把它变成以后会用得到的物品
- public Object createObject(Object o, boolean force_final_state){
- return InputReader.getDouble(o, -1);
- }
- public boolean validityCheck(String item_name, Object o){ //验证价格物品
- if((Double)o!=-1){
- return true;
- }
- ClassManager.manager.getBugFinder().severe("Was not able to create ShopItem "+item_name+"! The price object needs to be a valid number. Example: '7' or '12'.");
- return false;
- }
- public void enableType(){ //当价格类型在商店被使用时当BSP开始时执行一次
- //可以被用来注册Vault的文件
- }
- @Override
- public boolean hasPrice(Player p, BSBuy buy, Object price, ClickType clickType, int multiplier, boolean messageOnFailure) {
- double points = ClassManager.manager.getMultiplierHandler().calculatePriceWithMultiplier(p, buy, clickType, (Double) price) * multiplier;
- if (cp.getPointsManager().getPoints(p) < points) {
- String message = cp.getMessageNotEnoughPoints();
- if(message != null && messageOnFailure){
- p.sendMessage(ClassManager.manager.getStringManager().transform(message, buy, buy.getShop(), null, p));
- }
- return false;
- }
- return true;
- }
- @Override
- public String takePrice(Player p, BSBuy buy, Object price, ClickType clickType, int multiplier) {
- double points = ClassManager.manager.getMultiplierHandler().calculatePriceWithMultiplier(p, buy, clickType, (Double) price) * multiplier;
- cp.getPointsManager().takePoints(p, points);
- return getDisplayBalance(p, buy, price, clickType);
- }
- @Override
- public String getDisplayBalance(Player p, BSBuy buy, Object price, ClickType clickType) {
- double balance_points = cp.getPointsManager().getPoints(p);
- return cp.getPlaceholderPoints().replace("%"+cp.getName()+"%", MathTools.displayNumber(balance_points, cp.getSpecialDisplayFormatting(), !cp.getPointsManager().usesDoubleValues()));
- }
- @Override
- public String getDisplayPrice(Player p, BSBuy buy, Object price, ClickType clickType) {
- return ClassManager.manager.getMultiplierHandler().calculatePriceDisplayWithMultiplier(p, buy, clickType, (Double) price, cp.getPlaceholderPoints().replace("%"+cp.getName()+"%", "%number%"), cp.getSpecialDisplayFormatting(), true);
- }
- @Override
- public String[] createNames() { //价格类型用户的名称可以被用于进入设置
- if(cp == null){
- return new String[]{"thirdcurrency", "points2", "point2"};
- }else{
- return new String[]{cp.getName()};
- }
- }
- public boolean supportsMultipliers(){
- return true; //makes RewardTypes like BuyAll possible
- }
- @Override
- public boolean mightNeedShopUpdate() {
- return true; //这个价格类型是否执行取决于是否更新(比如占位符的变化)
- }
- @Override
- public boolean isIntegerValue() {
- return false; //needs to be defined because the class extends BSPriceTypeNumber
- }
如何创建自己的物品数据(itemdata)部分
1. 伸展BossShopPro class "ItemDataPart"
2. 执行所有授予的方案all given methods
3. 创建一个监听器来监听"BSRegisterTypesEvent" 然后创建一个你的自定义ItemDataPart 的例子. 另外使用"register" 方法注册例子.
ItemDataPart例子
- public class ItemDataPartMaterial extends ItemDataPart{
- public ItemStack transform(ItemStack item, String used_name, String argument) {
- short durability = 0;
- Material m = Material.STONE;
- if (argument.contains(":")) {
- String[] parts = argument.split(":");
- if (parts.length > 1) {
- durability = (short)InputReader.getInt(parts[1].trim(), 0);
- }
- argument = parts[0].trim();
- }
- m = InputReader.readMaterial(argument);
- if (m == null) {
- ClassManager.manager.getBugFinder().severe("Mistake in Config: '" + argument + "' is not a valid '" + used_name + "'. Unable to find a fitting material.");
- return item;
- }
- item.setType(m);
- item.setDurability(durability);
- return item;
- }
- public int getPriority() {
- return PRIORITY_MOST_EARLY;
- }
- public boolean removeSpaces() {
- return true;
- }
- public String[] createNames() {
- return new String[] { "type", "id", "material" };
- }
- public List<String> read(ItemStack i, List<String> output) {
- output.add("type:" + i.getType().name());
- return output;
- }
- public boolean isSimilar(ItemStack shop_item, ItemStack player_item, BSBuy buy, Player p) {
- return shop_item.getType() == player_item.getType();
- }
- }
监听器例子
- @EventHandler
- public void onRegister(BSRegisterTypesEvent event) {
- new ItemDataPartMaterial().register();
- }