fix issue template getter method

This commit is contained in:
Indyuce 2019-08-26 18:49:22 +02:00
parent 1c35076ded
commit daf8b244cb
2 changed files with 150 additions and 150 deletions

View File

@ -1,68 +1,68 @@
package net.Indyuce.mmoitems.api;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.MMOItem;
import net.Indyuce.mmoitems.stat.Upgrade_Stat.UpgradeData;
import net.Indyuce.mmoitems.stat.data.upgrade.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.Upgradable;
public class UpgradeTemplate {
private final String id;
private Map<ItemStat, UpgradeInfo> stats = new HashMap<>();
public UpgradeTemplate(ConfigurationSection config) {
Validate.notNull(config, "You must specify a config section.");
id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-");
for (String key : config.getKeys(false)) {
String statFormat = key.toUpperCase().replace("-", "_");
ItemStat stat = MMOItems.plugin.getStats().get(statFormat);
Validate.notNull(stat, "Could not read stat ID " + statFormat);
if (!(stat instanceof Upgradable)) {
log("Stat " + stat.getId() + " is not upgradable.");
continue;
}
try {
stats.put(stat, ((Upgradable) stat).loadUpgradeInfo(config.get(key)));
} catch (IllegalArgumentException exception) {
log("Could not load stat " + stat.getId() + ": " + exception.getMessage());
}
}
}
public void log(String... message) {
for (String line : message)
MMOItems.plugin.getLogger().log(Level.WARNING, "[Upgrade template] " + id + ": " + line);
}
public String getId() {
return id;
}
public Set<ItemStat> getKeys() {
return stats.keySet();
}
public UpgradeInfo getUpgradeInfo() {
return stats.get(stats);
}
public void upgrade(MMOItem mmoitem, UpgradeData upgrade) {
for (ItemStat stat : stats.keySet())
// if (mmoitem.hasData(stat))
((Upgradable) stat).apply(mmoitem, stats.get(stat));
}
}
package net.Indyuce.mmoitems.api;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.MMOItem;
import net.Indyuce.mmoitems.stat.Upgrade_Stat.UpgradeData;
import net.Indyuce.mmoitems.stat.data.upgrade.UpgradeInfo;
import net.Indyuce.mmoitems.stat.type.ItemStat;
import net.Indyuce.mmoitems.stat.type.Upgradable;
public class UpgradeTemplate {
private final String id;
private Map<ItemStat, UpgradeInfo> stats = new HashMap<>();
public UpgradeTemplate(ConfigurationSection config) {
Validate.notNull(config, "You must specify a config section.");
id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-");
for (String key : config.getKeys(false)) {
String statFormat = key.toUpperCase().replace("-", "_");
ItemStat stat = MMOItems.plugin.getStats().get(statFormat);
Validate.notNull(stat, "Could not read stat ID " + statFormat);
if (!(stat instanceof Upgradable)) {
log("Stat " + stat.getId() + " is not upgradable.");
continue;
}
try {
stats.put(stat, ((Upgradable) stat).loadUpgradeInfo(config.get(key)));
} catch (IllegalArgumentException exception) {
log("Could not load stat " + stat.getId() + ": " + exception.getMessage());
}
}
}
public void log(String... message) {
for (String line : message)
MMOItems.plugin.getLogger().log(Level.WARNING, "[Upgrade template] " + id + ": " + line);
}
public String getId() {
return id;
}
public Set<ItemStat> getKeys() {
return stats.keySet();
}
public UpgradeInfo getUpgradeInfo(ItemStat stat) {
return stats.get(stat);
}
public void upgrade(MMOItem mmoitem, UpgradeData upgrade) {
for (ItemStat stat : stats.keySet())
// if (mmoitem.hasData(stat))
((Upgradable) stat).apply(mmoitem, stats.get(stat));
}
}

View File

@ -1,82 +1,82 @@
package net.Indyuce.mmoitems.comp;
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.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
public class MMOItemsRewardTypes extends BSRewardType {
/*
* the config gives the list of all the mmoitems that need to be given to
* the player
*/
@Override
public Object createObject(Object object, boolean force_final_state) {
return InputReader.readStringList(object);
}
public boolean validityCheck(String itemName, Object object) {
if (object != null || !(object instanceof List<?>))
return true;
ClassManager.manager.getBugFinder().severe("Couldn't load the MMOItems reward type" + itemName + ". The reward object needs to be a list of types & IDs (format: [ITEM_TYPE].[ITEM_ID]).");
return false;
}
/*
* since this is a buyable item, the player can always buy it so it should
* always return true.
*/
@Override
public boolean canBuy(Player player, BSBuy buy, boolean message_if_no_success, Object reward, ClickType clickType) {
return true;
}
@Override
@SuppressWarnings("unchecked")
public void giveReward(Player player, BSBuy buy, Object reward, ClickType clickType) {
for (String item : (List<String>) reward)
try {
String[] split = item.split("\\.");
Type type = MMOItems.plugin.getTypes().get(split[0].toUpperCase().replace("-", "_"));
for (ItemStack drop : player.getInventory().addItem(MMOItems.plugin.getItems().getItem(type, split[1])).values())
player.getWorld().dropItem(player.getLocation(), drop);
} catch (Exception e) {
ClassManager.manager.getBugFinder().severe("Couldn't load the MMOItems reward type" + item + ". Format: [ITEM_TYPE].[ITEM_ID]).");
}
}
@Override
public String getDisplayReward(Player p, BSBuy buy, Object reward, ClickType clickType) {
// List<String> permissions = (List<String>) reward;
// String permissions_formatted =
// StringManipulationLib.formatList(permissions);
// return
// ClassManager.manager.getMessageHandler().get("Display.Permission").replace("%permissions%",
// permissions_formatted);
return "";
}
@Override
public String[] createNames() {
return new String[] { "mmoitem", "mmoitems" };
}
@Override
public boolean mightNeedShopUpdate() {
return false;
}
@Override
public void enableType() {
}
}
package net.Indyuce.mmoitems.comp;
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.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
public class MMOItemsRewardTypes extends BSRewardType {
/*
* the config gives the list of all the mmoitems that need to be given to
* the player
*/
@Override
public Object createObject(Object object, boolean force_final_state) {
return InputReader.readStringList(object);
}
public boolean validityCheck(String itemName, Object object) {
if (object != null || !(object instanceof List<?>))
return true;
ClassManager.manager.getBugFinder().severe("Couldn't load the MMOItems reward type" + itemName + ". The reward object needs to be a list of types & IDs (format: [ITEM_TYPE].[ITEM_ID]).");
return false;
}
/*
* since this is a buyable item, the player can always buy it so it should
* always return true.
*/
@Override
public boolean canBuy(Player player, BSBuy buy, boolean message_if_no_success, Object reward, ClickType clickType) {
return true;
}
@Override
@SuppressWarnings("unchecked")
public void giveReward(Player player, BSBuy buy, Object reward, ClickType clickType) {
for (String item : (List<String>) reward)
try {
String[] split = item.split("\\.");
Type type = MMOItems.plugin.getTypes().get(split[0].toUpperCase().replace("-", "_"));
for (ItemStack drop : player.getInventory().addItem(MMOItems.plugin.getItems().getItem(type, split[1])).values())
player.getWorld().dropItem(player.getLocation(), drop);
} catch (Exception e) {
ClassManager.manager.getBugFinder().severe("Couldn't load the MMOItems reward type" + item + ". Format: [ITEM_TYPE].[ITEM_ID]).");
}
}
@Override
public String getDisplayReward(Player p, BSBuy buy, Object reward, ClickType clickType) {
// List<String> permissions = (List<String>) reward;
// String permissions_formatted =
// StringManipulationLib.formatList(permissions);
// return
// ClassManager.manager.getMessageHandler().get("Display.Permission").replace("%permissions%",
// permissions_formatted);
return "";
}
@Override
public String[] createNames() {
return new String[] { "mmoitem", "mmoitems" };
}
@Override
public boolean mightNeedShopUpdate() {
return false;
}
@Override
public void enableType() {
}
}