!Item gen stage 3

This commit is contained in:
Indyuce 2020-04-08 14:18:53 +02:00
parent cddebd5919
commit 421f7b5b4b
27 changed files with 639 additions and 252 deletions

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>5.3.3</version>
<version>5.4</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>

View File

@ -75,29 +75,30 @@ import net.mmogroup.mmolib.version.SpigotPlugin;
public class MMOItems extends JavaPlugin {
public static MMOItems plugin;
private RecipeManager recipeManager;
private ConfigManager configManager;
private StatManager statManager;
private EntityManager entityManager;
private final PluginUpdateManager pluginUpdateManager = new PluginUpdateManager();
private final AbilityManager abilityManager = new AbilityManager();
private final EntityManager entityManager = new EntityManager();
private final TypeManager typeManager = new TypeManager();
private CraftingManager stationRecipeManager;
private DropTableManager dropTableManager;
private UpdaterManager itemUpdaterManager;
private TypeManager typeManager;
private WorldGenManager worldGenManager;
private UpgradeManager upgradeManager;
private UpdaterManager dynamicUpdater;
private ItemGenManager itemGenerator;
private ConfigManager configManager;
private RecipeManager recipeManager;
private BlockManager blockManager;
private TierManager tierManager;
private StatManager statManager;
private ItemManager itemManager;
private SetManager setManager;
private UpgradeManager upgradeManager;
private WorldGenManager worldGenManager;
private BlockManager blockManager;
private ItemGenManager itemGenerator;
private AbilityManager abilityManager = new AbilityManager();
private CraftingManager stationRecipeManager = new CraftingManager();
private PluginUpdateManager pluginUpdateManager = new PluginUpdateManager();
private RPGHandler rpgPlugin;
private PlaceholderParser placeholderParser = new DefaultParser();
private HologramSupport hologramSupport;
private FlagPlugin flagPlugin = new DefaultFlags();
private PlayerInventory inventory = new DefaultPlayerInventory();
private FlagPlugin flagPlugin = new DefaultFlags();
private HologramSupport hologramSupport;
private RPGHandler rpgPlugin;
public void onLoad() {
plugin = this;
@ -116,7 +117,7 @@ public class MMOItems extends JavaPlugin {
saveDefaultConfig();
statManager = new StatManager();
typeManager = new TypeManager();
typeManager.reload();
}
public void onEnable() {
@ -124,28 +125,26 @@ public class MMOItems extends JavaPlugin {
new MMOItemsMetrics();
if (!getDataFolder().exists())
getDataFolder().mkdir();
abilityManager.registerDefaultAbilities();
abilityManager.initialize();
configManager = new ConfigManager();
itemManager = new ItemManager(getConfig().getBoolean("use-item-caching"));
itemManager = new ItemManager();
tierManager = new TierManager();
setManager = new SetManager();
upgradeManager = new UpgradeManager();
itemGenerator = new ItemGenManager();
dropTableManager = new DropTableManager();
dynamicUpdater = new UpdaterManager();
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 12)) {
worldGenManager = new WorldGenManager();
blockManager = new BlockManager();
}
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
stationRecipeManager.reload();
stationRecipeManager = new CraftingManager();
Bukkit.getPluginManager().registerEvents(entityManager = new EntityManager(), this);
Bukkit.getPluginManager().registerEvents(dropTableManager = new DropTableManager(), this);
Bukkit.getPluginManager().registerEvents(itemUpdaterManager = new UpdaterManager(), this);
Bukkit.getPluginManager().registerEvents(entityManager, this);
Bukkit.getPluginManager().registerEvents(dropTableManager, this);
Bukkit.getPluginManager().registerEvents(dynamicUpdater, this);
Bukkit.getPluginManager().registerEvents(new ItemUse(), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getPluginManager().registerEvents(new CustomSoundListener(), this);
@ -257,7 +256,7 @@ public class MMOItems extends JavaPlugin {
// save item updater data
ConfigFile updater = new ConfigFile("/dynamic", "updater");
updater.getConfig().getKeys(false).forEach(key -> updater.getConfig().set(key, null));
itemUpdaterManager.getDatas().forEach(data -> data.save(updater.getConfig()));
dynamicUpdater.getDatas().forEach(data -> data.save(updater.getConfig()));
updater.save();
// drop abandonned soulbound items
@ -282,7 +281,7 @@ public class MMOItems extends JavaPlugin {
}
public UpdaterManager getUpdater() {
return itemUpdaterManager;
return dynamicUpdater;
}
public SetManager getSets() {

View File

@ -34,7 +34,7 @@ public class UpgradeTemplate {
stats.put(stat, ((Upgradable) stat).loadUpgradeInfo(config.get(key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING,
"An error occured loading stat '" + key + "' from upgrade template '" + id + "': " + exception.getMessage());
"An error occured while trying to load stat '" + key + "' from upgrade template '" + id + "': " + exception.getMessage());
}
}
}

View File

@ -1,14 +1,13 @@
package net.Indyuce.mmoitems.api.itemgen;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.MMOItem;
import net.Indyuce.mmoitems.api.itemgen.NameModifier.ModifierType;
import net.Indyuce.mmoitems.api.itemgen.tier.RolledTier;
import net.Indyuce.mmoitems.stat.data.StringData;
import net.Indyuce.mmoitems.stat.data.type.Mergeable;
import net.Indyuce.mmoitems.stat.data.type.StatData;
@ -17,12 +16,12 @@ import net.Indyuce.mmoitems.stat.type.ItemStat;
public class GeneratedItemBuilder {
private final int level;
private final MMOItem mmoitem;
private final RolledTier tier;
/*
* weight is not final because it is lowered as modifiers are applied to the
* MMOItem.
* capacity is not final because it is lowered as modifiers are applied
*/
private double weight;
private double capacity;
/*
* name modifiers which must be applied at the end of the item generation
@ -37,26 +36,29 @@ public class GeneratedItemBuilder {
*/
public GeneratedItemBuilder(GenerationTemplate template, int level, double spread) {
this.level = rollLevel(level, spread);
weight = template.calculateWeight(level);
mmoitem = new MMOItem(template.getType(), template.getId());
this.mmoitem = new MMOItem(template.getType(), template.getId());
// apply base item data
template.getBaseItemData().entrySet().forEach(entry -> applyData(entry.getKey(), entry.getValue().randomize(this)));
// calculate item tier and capacity
tier = MMOItems.plugin.getItemGenerator().rollTier(this);
capacity = tier.getCapacity();
if (!tier.isDefault())
mmoitem.setData(ItemStat.TIER, new StringData(tier.getTier().getId()));
// roll item gen modifiers
List<GenerationModifier> lookUpOrder = new ArrayList<>(template.getModifiers());
Collections.shuffle(lookUpOrder);
for (GenerationModifier modifier : lookUpOrder) {
for (GenerationModifier modifier : template.getModifiers()) {
// roll modifier change
if (!modifier.rollChance())
continue;
// only apply if enough item weight
if (modifier.getWeight() > weight)
if (modifier.getWeight() > capacity)
continue;
weight -= modifier.getWeight();
capacity -= modifier.getWeight();
if (modifier.hasNameModifier())
addModifier(modifier.getNameModifier());
modifier.getItemData().forEach((stat, data) -> applyData(stat, data.randomize(this)));
@ -84,8 +86,12 @@ public class GeneratedItemBuilder {
return level;
}
public double getWeight() {
return weight;
public double getRemainingCapacity() {
return capacity;
}
public RolledTier getTier() {
return tier;
}
public MMOItem build() {

View File

@ -10,6 +10,7 @@ import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.itemgen.NameModifier.ModifierType;
import net.Indyuce.mmoitems.manager.ItemGenManager;
import net.Indyuce.mmoitems.stat.type.ItemStat;
public class GenerationModifier {
@ -21,15 +22,36 @@ public class GenerationModifier {
private final String id;
private final double chance, weight;
private final Map<ItemStat, RandomStatData> data = new HashMap<>();
private final Map<ItemStat, RandomStatData> data;
private final NameModifier nameModifier;
private static final Random random = new Random();
public GenerationModifier(ConfigurationSection config) {
this(null, config);
}
public GenerationModifier(ItemGenManager manager, ConfigurationSection config) {
Validate.notNull(config, "Could not read config");
id = config.getName().toLowerCase().replace("_", "-");
/*
* when providing a non-null itemGenManager, it indicates that public
* modifiers were loaded and that the constructor can them
*/
if (manager != null && config.contains("parent")) {
String parentFormat = config.get("parent").toString().toLowerCase().replace("_", "-").replace(" ", "_");
Validate.isTrue(manager.hasModifier(parentFormat), "Could not find public modifier with ID '" + parentFormat + "'");
GenerationModifier parent = manager.getModifier(parentFormat);
chance = Math.max(Math.min(config.getDouble("chance", parent.chance), 1), 0);
weight = config.getDouble("weight", parent.weight);
nameModifier = parent.nameModifier;
data = parent.data;
return;
}
this.data = new HashMap<>();
this.chance = Math.max(Math.min(config.getDouble("chance", 1), 1), 0);
this.weight = config.getDouble("weight");
@ -46,10 +68,15 @@ public class GenerationModifier {
ItemStat stat = MMOItems.plugin.getStats().get(id);
data.put(stat, stat.whenInitializedGeneration(config.get("stats." + key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO, "An error occured loading item gen modifier " + id + ": " + exception.getMessage());
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured while trying to load item gen modifier " + id + ": " + exception.getMessage());
}
}
public String getId() {
return id;
}
public double getWeight() {
return weight;
}

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmoitems.api.itemgen;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
@ -17,28 +17,28 @@ public class GenerationTemplate {
private final String id;
private final Type type;
private final NumericStatFormula weight;
// base item data
private final Map<ItemStat, RandomStatData> base = new HashMap<>();
private final Set<GenerationModifier> modifiers = new HashSet<>();
private final Set<GenerationModifier> modifiers = new LinkedHashSet<>();
public GenerationTemplate(ConfigurationSection config) {
Validate.notNull(config, "Could not load item gen template config");
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
this.id = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
Validate.isTrue(config.contains("type"), "Could not find item gen type");
String typeFormat = config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_");
Validate.isTrue(MMOItems.plugin.getTypes().has(typeFormat));
type = MMOItems.plugin.getTypes().get(typeFormat);
Validate.notNull(config.getConfigurationSection("weight"), "Could not find item gen weight");
weight = new NumericStatFormula(config.getConfigurationSection("weight"));
for (String key : config.getConfigurationSection("modifiers").getKeys(false))
modifiers.add(new GenerationModifier(config.getConfigurationSection("modifiers." + key)));
try {
modifiers.add(new GenerationModifier(MMOItems.plugin.getItemGenerator(), config.getConfigurationSection("modifiers." + key)));
} catch(IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured while trying to load modifier '" + key + "' from item gen template '" + id + "': " + exception.getMessage());
}
Validate.notNull(config.getConfigurationSection("base"), "Could not find base item data");
for (String key : config.getConfigurationSection("base").getKeys(false))
@ -50,7 +50,7 @@ public class GenerationTemplate {
base.put(stat, stat.whenInitializedGeneration(config.get("base." + key)));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured loading base item data '" + key + "' from item gen template '" + id + "': " + exception.getMessage());
"An error occured while trying to load base item data '" + key + "' from item gen template '" + id + "': " + exception.getMessage());
}
}
@ -80,10 +80,6 @@ public class GenerationTemplate {
// ((ListStringData) base.get(ItemStat.REQUIRED_CLASS));
}
public double calculateWeight(int level) {
return weight.calculate(level);
}
public GeneratedItemBuilder newBuilder(int playerLevel, double sd) {
return new GeneratedItemBuilder(this, playerLevel, sd);
}

View File

@ -0,0 +1,62 @@
package net.Indyuce.mmoitems.api.itemgen.tier;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.itemgen.GeneratedItemBuilder;
import net.Indyuce.mmoitems.api.itemgen.NumericStatFormula;
public class RandomTierInfo {
private final ItemTier tier;
private final double chance;
private final NumericStatFormula capacity;
public RandomTierInfo(ConfigurationSection config) {
Validate.notNull(config, "Config cannot be null");
String tierFormat = config.getName().toUpperCase().replace("-", "_").replace(" ", "_");
Validate.isTrue(MMOItems.plugin.getTiers().has(tierFormat), "Could not find tier with ID '" + tierFormat + "'");
tier = MMOItems.plugin.getTiers().get(tierFormat);
chance = config.getDouble("chance");
Validate.isTrue(chance > 0 && chance < 1, "Chance must be stricly between 0 and 1");
capacity = new NumericStatFormula(config.get("capacity"));
}
/*
* constructor for the default tier: there is no need for chance or tier
* instance
*/
public RandomTierInfo(NumericStatFormula capacity) {
this(null, 0, capacity);
}
public RandomTierInfo(ItemTier tier, double chance, NumericStatFormula capacity) {
this.tier = tier;
this.chance = chance;
this.capacity = capacity;
}
public boolean isDefault() {
return tier == null;
}
public ItemTier getTier() {
return tier;
}
public NumericStatFormula getCapacity() {
return capacity;
}
public double getChance() {
return chance;
}
public RolledTier roll(GeneratedItemBuilder builder) {
return new RolledTier(this, builder);
}
}

View File

@ -0,0 +1,26 @@
package net.Indyuce.mmoitems.api.itemgen.tier;
import net.Indyuce.mmoitems.api.ItemTier;
import net.Indyuce.mmoitems.api.itemgen.GeneratedItemBuilder;
public class RolledTier {
private final ItemTier tier;
private final double capacity;
public RolledTier(RandomTierInfo info, GeneratedItemBuilder builder) {
this.tier = info.getTier();
this.capacity = info.getCapacity().calculate(builder.getLevel());
}
public boolean isDefault() {
return tier == null;
}
public ItemTier getTier() {
return tier;
}
public double getCapacity() {
return capacity;
}
}

View File

@ -83,22 +83,16 @@ public class MMOItemsCommand implements CommandExecutor {
}
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("generate")) {
Player player = (Player)sender;
GenerationTemplate template = MMOItems.plugin.getItemGenerator().getTemplate(args[1]);
ItemStack item = template.newBuilder(PlayerData.get(player).getRPG().getLevel(), 3).build().newBuilder().build();
player.getInventory().addItem(item);
Player player = (Player) sender;
for (int j = 0; j < Integer.valueOf(args[2]); j++) {
GenerationTemplate template = MMOItems.plugin.getItemGenerator().getTemplate(args[1]);
ItemStack item = template.newBuilder(PlayerData.get(player).getRPG().getLevel(), 3).build().newBuilder().build();
player.getInventory().addItem(item);
}
}
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("browse")) {
@ -129,9 +123,11 @@ public class MMOItemsCommand implements CommandExecutor {
else if (args[0].equalsIgnoreCase("update")) {
if (args.length < 2) {
sender.sendMessage("");
sender.sendMessage(ChatColor.GRAY + "Sometimes updates happen to break config files due to a change in data storage. Applying a plugin config update using /mi update allows to instantly fix these issues.");
sender.sendMessage(ChatColor.GRAY
+ "Sometimes updates happen to break config files due to a change in data storage. Applying a plugin config update using /mi update allows to instantly fix these issues.");
sender.sendMessage("");
sender.sendMessage(ChatColor.RED + "Make sure you only apply required updates! You may also consider backing up your data before applying any update.");
sender.sendMessage(ChatColor.RED
+ "Make sure you only apply required updates! You may also consider backing up your data before applying any update.");
sender.sendMessage("");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi update list" + ChatColor.WHITE + " lists available config updates.");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi update info <id>" + ChatColor.WHITE + " displays info about an update.");
@ -169,7 +165,8 @@ public class MMOItemsCommand implements CommandExecutor {
}
sender.sendMessage("");
sender.sendMessage(ChatColor.YELLOW + "Use " + ChatColor.GOLD + "/mi update apply " + update.getId() + ChatColor.YELLOW + " to apply this config update.");
sender.sendMessage(ChatColor.YELLOW + "Use " + ChatColor.GOLD + "/mi update apply " + update.getId() + ChatColor.YELLOW
+ " to apply this config update.");
}
if (args[1].equalsIgnoreCase("list")) {
@ -196,7 +193,8 @@ public class MMOItemsCommand implements CommandExecutor {
if (id != Integer.parseInt(args[3]))
throw new NumberFormatException();
} catch (NumberFormatException exception) {
sender.sendMessage(ChatColor.RED + "Update IDs do not match. Make sure you enter twice the same ID to confirm you want to apply this update.");
sender.sendMessage(ChatColor.RED
+ "Update IDs do not match. Make sure you enter twice the same ID to confirm you want to apply this update.");
return true;
}
@ -208,7 +206,8 @@ public class MMOItemsCommand implements CommandExecutor {
PluginUpdate update = MMOItems.plugin.getUpdates().get(id);
sender.sendMessage(ChatColor.YELLOW + "Applying config update " + id + "...");
update.apply(sender);
sender.sendMessage(ChatColor.YELLOW + "Config update " + id + " was successfully applied. Check the console for potential update error logs.");
sender.sendMessage(
ChatColor.YELLOW + "Config update " + id + " was successfully applied. Check the console for potential update error logs.");
}
}
// ==================================================================================================================================
@ -245,7 +244,8 @@ public class MMOItemsCommand implements CommandExecutor {
sender.sendMessage(ChatColor.AQUA + "Base Value = " + ChatColor.RESET + att.getBaseValue());
sender.sendMessage(ChatColor.AQUA + "Value = " + ChatColor.RESET + att.getValue());
for (AttributeModifier mod : att.getModifiers())
sender.sendMessage(mod.getName() + " " + new DecimalFormat("0.####").format(mod.getAmount()) + " " + mod.getOperation() + " " + mod.getSlot());
sender.sendMessage(mod.getName() + " " + new DecimalFormat("0.####").format(mod.getAmount()) + " " + mod.getOperation() + " "
+ mod.getSlot());
} catch (IllegalArgumentException exception) {
player.sendMessage("Couldn't find attribute.");
} catch (NoSuchMethodError error) {
@ -257,7 +257,8 @@ public class MMOItemsCommand implements CommandExecutor {
if (args.length < 2) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "--------------------------------------------------");
for (String s : MMOItems.plugin.getUpdater().getItemPaths())
sender.sendMessage(ChatColor.RED + s + ChatColor.WHITE + " - " + ChatColor.RED + MMOItems.plugin.getUpdater().getData(s).getUniqueId().toString());
sender.sendMessage(ChatColor.RED + s + ChatColor.WHITE + " - " + ChatColor.RED
+ MMOItems.plugin.getUpdater().getData(s).getUniqueId().toString());
return true;
}
try {
@ -297,9 +298,12 @@ public class MMOItemsCommand implements CommandExecutor {
NBTItem item = MMOLib.plugin.getNMS().getNBTItem(player.getInventory().getItemInMainHand());
player.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "--------------------------------------------------");
player.sendMessage(ChatColor.AQUA + "Boolean = " + ChatColor.RESET + item.getBoolean("MMOITEMS_" + args[1].toUpperCase().replace("-", "_")));
player.sendMessage(ChatColor.AQUA + "Double = " + ChatColor.RESET + item.getDouble("MMOITEMS_" + args[1].toUpperCase().replace("-", "_")));
player.sendMessage(ChatColor.AQUA + "String = " + ChatColor.RESET + item.getString("MMOITEMS_" + args[1].toUpperCase().replace("-", "_")));
player.sendMessage(
ChatColor.AQUA + "Boolean = " + ChatColor.RESET + item.getBoolean("MMOITEMS_" + args[1].toUpperCase().replace("-", "_")));
player.sendMessage(
ChatColor.AQUA + "Double = " + ChatColor.RESET + item.getDouble("MMOITEMS_" + args[1].toUpperCase().replace("-", "_")));
player.sendMessage(
ChatColor.AQUA + "String = " + ChatColor.RESET + item.getString("MMOITEMS_" + args[1].toUpperCase().replace("-", "_")));
}
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("settag")) {
@ -312,7 +316,8 @@ public class MMOItemsCommand implements CommandExecutor {
if (args.length < 3)
return true;
try {
player.getInventory().setItemInMainHand(MMOLib.plugin.getNMS().getNBTItem(player.getInventory().getItemInMainHand()).addTag(new ItemTag(args[1].toUpperCase().replace("-", "_"), args[2].replace("%%", " "))).toItem());
player.getInventory().setItemInMainHand(MMOLib.plugin.getNMS().getNBTItem(player.getInventory().getItemInMainHand())
.addTag(new ItemTag(args[1].toUpperCase().replace("-", "_"), args[2].replace("%%", " "))).toItem());
player.sendMessage("Successfully set tag.");
} catch (Exception e) {
@ -366,14 +371,16 @@ public class MMOItemsCommand implements CommandExecutor {
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("stations")) {
if (args.length < 2) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Crafting Stations " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE
+ " Crafting Stations " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi stations list" + ChatColor.WHITE + " shows available crafting stations.");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi stations open <station> (player)" + ChatColor.WHITE + " opens a station.");
return true;
}
if (args[1].equalsIgnoreCase("list")) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Crafting Stations " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE
+ " Crafting Stations " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
for (CraftingStation station : MMOItems.plugin.getCrafting().getAll())
sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + station.getId());
}
@ -407,7 +414,8 @@ public class MMOItemsCommand implements CommandExecutor {
}
RPGPlayer rpg = PlayerData.get(player).getRPG();
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Player Information " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE
+ " Player Information " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.WHITE + "Information about " + ChatColor.LIGHT_PURPLE + player.getName());
sender.sendMessage("");
sender.sendMessage(ChatColor.WHITE + "Player Class: " + ChatColor.LIGHT_PURPLE + rpg.getClassName());
@ -427,7 +435,8 @@ public class MMOItemsCommand implements CommandExecutor {
player.setFoodLevel(20);
player.setFireTicks(0);
player.setSaturation(12);
for (PotionEffectType pe : new PotionEffectType[] { PotionEffectType.POISON, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HUNGER, PotionEffectType.WEAKNESS, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING })
for (PotionEffectType pe : new PotionEffectType[] { PotionEffectType.POISON, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION,
PotionEffectType.HUNGER, PotionEffectType.WEAKNESS, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING })
player.removePotionEffect(pe);
}
// ==================================================================================================================================
@ -437,8 +446,10 @@ public class MMOItemsCommand implements CommandExecutor {
Bukkit.getScheduler().runTaskAsynchronously(MMOItems.plugin, () -> {
MMOItems.plugin.getCrafting().reload();
sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reloaded the crafting stations..");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getCrafting().getAll().size() + ChatColor.GRAY + " Crafting Stations");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getCrafting().countRecipes() + ChatColor.GRAY + " Recipes");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getCrafting().getAll().size()
+ ChatColor.GRAY + " Crafting Stations");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getCrafting().countRecipes()
+ ChatColor.GRAY + " Recipes");
});
}
@ -454,7 +465,8 @@ public class MMOItemsCommand implements CommandExecutor {
Bukkit.getOnlinePlayers().forEach(online -> online.discoverRecipes(MMOItems.plugin.getRecipes().getNamespacedKeys()));
sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully reloaded recipes.");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getRecipes().getLoadedRecipes().size() + ChatColor.GRAY + " Recipes");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED
+ MMOItems.plugin.getRecipes().getLoadedRecipes().size() + ChatColor.GRAY + " Recipes");
});
});
}
@ -471,10 +483,14 @@ public class MMOItemsCommand implements CommandExecutor {
if (MMOLib.plugin.getVersion().isStrictlyHigher(1, 12))
MMOItems.plugin.getCustomBlocks().reload();
MMOItems.plugin.getItems().reload();
sender.sendMessage(MMOItems.plugin.getPrefix() + MMOItems.plugin.getName() + " " + MMOItems.plugin.getDescription().getVersion() + " reloaded.");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getTypes().getAll().size() + ChatColor.GRAY + " Item Types");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getTiers().getAll().size() + ChatColor.GRAY + " Item Tiers");
sender.sendMessage(MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getSets().getAll().size() + ChatColor.GRAY + " Item Sets");
sender.sendMessage(
MMOItems.plugin.getPrefix() + MMOItems.plugin.getName() + " " + MMOItems.plugin.getDescription().getVersion() + " reloaded.");
sender.sendMessage(
MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getTypes().getAll().size() + ChatColor.GRAY + " Item Types");
sender.sendMessage(
MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getTiers().getAll().size() + ChatColor.GRAY + " Item Tiers");
sender.sendMessage(
MMOItems.plugin.getPrefix() + "- " + ChatColor.RED + MMOItems.plugin.getSets().getAll().size() + ChatColor.GRAY + " Item Sets");
}
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("copy")) {
@ -484,8 +500,10 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.GRAY + "to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called "
+ args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.GRAY
+ "to see all the available item types.");
return true;
}
@ -516,7 +534,12 @@ public class MMOItemsCommand implements CommandExecutor {
for (Type type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();
for (String s : config.getKeys(false))
sender.sendMessage("* " + ChatColor.GREEN + s + (config.getConfigurationSection(s).contains("name") ? " " + ChatColor.WHITE + "(" + ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name")) + ChatColor.WHITE + ")" : ""));
sender.sendMessage(
"* " + ChatColor.GREEN + s
+ (config.getConfigurationSection(s).contains("name")
? " " + ChatColor.WHITE + "(" + ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name"))
+ ChatColor.WHITE + ")"
: ""));
}
}
// ==================================================================================================================================
@ -527,8 +550,10 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_"));
sender.sendMessage(MMOItems.plugin.getPrefix() + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.GRAY + "to see all the available item types.");
sender.sendMessage(
MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_"));
sender.sendMessage(MMOItems.plugin.getPrefix() + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.GRAY
+ "to see all the available item types.");
return true;
}
@ -538,18 +563,29 @@ public class MMOItemsCommand implements CommandExecutor {
FileConfiguration config = type.getConfigFile().getConfig();
if (!(sender instanceof Player)) {
for (String s : config.getKeys(false))
sender.sendMessage("* " + ChatColor.GREEN + s + (config.getConfigurationSection(s).contains("name") ? " " + ChatColor.WHITE + "(" + ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name")) + ChatColor.WHITE + ")" : ""));
sender.sendMessage(
"* " + ChatColor.GREEN + s
+ (config.getConfigurationSection(s).contains("name")
? " " + ChatColor.WHITE + "(" + ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name"))
+ ChatColor.WHITE + ")"
: ""));
return true;
}
for (String s : config.getKeys(false)) {
String nameFormat = config.getConfigurationSection(s).contains("name") ? " " + ChatColor.WHITE + "(" + ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name")) + ChatColor.WHITE + ")" : "";
MMOLib.plugin.getNMS().sendJson((Player) sender, "{\"text\":\"* " + ChatColor.GREEN + s + nameFormat + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/mi edit " + type.getId() + " " + s + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Click to edit " + (nameFormat.equals("") ? s : ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name"))) + ChatColor.WHITE + ".\",\"color\":\"white\"}}}");
String nameFormat = config.getConfigurationSection(s).contains("name") ? " " + ChatColor.WHITE + "("
+ ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name")) + ChatColor.WHITE + ")" : "";
MMOLib.plugin.getNMS().sendJson((Player) sender,
"{\"text\":\"* " + ChatColor.GREEN + s + nameFormat + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/mi edit "
+ type.getId() + " " + s + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"Click to edit "
+ (nameFormat.equals("") ? s : ChatColor.translateAlternateColorCodes('&', config.getString(s + ".name")))
+ ChatColor.WHITE + ".\",\"color\":\"white\"}}}");
}
}
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("list")) {
if (args.length < 2) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " MMOItems: lists " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE
+ " MMOItems: lists " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list type " + ChatColor.WHITE + "shows all item types (sword, axe...)");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list spirit " + ChatColor.WHITE + "shows all available staff spirits");
sender.sendMessage(ChatColor.LIGHT_PURPLE + "/mi list lute " + ChatColor.WHITE + "shows all available lute attack effects");
@ -557,8 +593,24 @@ public class MMOItemsCommand implements CommandExecutor {
if (sender instanceof Player) {
sender.sendMessage("");
sender.sendMessage("Spigot Javadoc Links:");
MMOLib.plugin.getNMS().sendJson((Player) sender, "[{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN + "Materials/Blocks\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN + "Potion Effects\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN + "Sounds\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.GREEN + "Click to open webpage.\"}]}}}]");
MMOLib.plugin.getNMS().sendJson((Player) sender, "[{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN + "Entities/Mobs\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN + "Enchantments\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN + "Particles\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particles.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ChatColor.GREEN + "Click to open webpage.\"}]}}}]");
MMOLib.plugin.getNMS().sendJson((Player) sender, "[{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN
+ "Materials/Blocks\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\""
+ ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\""
+ ChatColor.UNDERLINE + ChatColor.GREEN
+ "Potion Effects\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/potion/PotionEffectType.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\""
+ ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\""
+ ChatColor.UNDERLINE + ChatColor.GREEN
+ "Sounds\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Sound.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\""
+ ChatColor.GREEN + "Click to open webpage.\"}]}}}]");
MMOLib.plugin.getNMS().sendJson((Player) sender, "[{\"text\":\"" + ChatColor.UNDERLINE + ChatColor.GREEN
+ "Entities/Mobs\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/EntityType.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\""
+ ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\""
+ ChatColor.UNDERLINE + ChatColor.GREEN
+ "Enchantments\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/enchantments/Enchantment.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\""
+ ChatColor.GREEN + "Click to open webpage.\"}]}}},{\"text\":\" " + ChatColor.LIGHT_PURPLE + "- \"},{\"text\":\""
+ ChatColor.UNDERLINE + ChatColor.GREEN
+ "Particles\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particles.html\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\""
+ ChatColor.GREEN + "Click to open webpage.\"}]}}}]");
}
return true;
@ -566,9 +618,11 @@ public class MMOItemsCommand implements CommandExecutor {
// ability list
if (args[1].equalsIgnoreCase("ability")) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Abilities " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Abilities "
+ ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.WHITE + "Here are all the abilities you can bind to items.");
sender.sendMessage(ChatColor.WHITE + "The values inside brackets are " + ChatColor.UNDERLINE + "modifiers" + ChatColor.WHITE + " which allow you to change the ability values (cooldown, damage...)");
sender.sendMessage(ChatColor.WHITE + "The values inside brackets are " + ChatColor.UNDERLINE + "modifiers" + ChatColor.WHITE
+ " which allow you to change the ability values (cooldown, damage...)");
for (Ability a : MMOItems.plugin.getAbilities().getAll()) {
String modFormat = ChatColor.GRAY + String.join(ChatColor.WHITE + ", " + ChatColor.GRAY, a.getModifiers());
modFormat = ChatColor.WHITE + "(" + modFormat + ChatColor.WHITE + ")";
@ -578,14 +632,16 @@ public class MMOItemsCommand implements CommandExecutor {
// item type list
if (args[1].equalsIgnoreCase("type")) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Item Types " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Item Types "
+ ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
for (Type t : MMOItems.plugin.getTypes().getAll())
sender.sendMessage("* " + ChatColor.LIGHT_PURPLE + t.getName());
}
// staff spirit list
if (args[1].equalsIgnoreCase("spirit")) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Staff Spirits " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE
+ " Staff Spirits " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
for (StaffSpirit ss : StaffSpirit.values()) {
String lore = !ss.hasLore() ? " " + ChatColor.WHITE + ">> " + ChatColor.GRAY + "" + ChatColor.ITALIC + ss.getLore() : "";
sender.sendMessage("* " + ChatColor.LIGHT_PURPLE + ss.getName() + lore);
@ -594,7 +650,8 @@ public class MMOItemsCommand implements CommandExecutor {
// lute attack effect list
if (args[1].equalsIgnoreCase("lute")) {
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE + " Lute Attack Effects " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
sender.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "-----------------[" + ChatColor.LIGHT_PURPLE
+ " Lute Attack Effects " + ChatColor.DARK_GRAY + "" + ChatColor.STRIKETHROUGH + "]-----------------");
for (LuteAttackEffect lae : LuteAttackEffect.values())
sender.sendMessage("* " + ChatColor.LIGHT_PURPLE + lae.getName());
}
@ -612,8 +669,10 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called "
+ args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED
+ " to see all the available item types.");
return true;
}
@ -652,7 +711,8 @@ public class MMOItemsCommand implements CommandExecutor {
if (MMOLib.plugin.getNMS().getNBTItem(item).getBoolean("Unbreakable"))
config.getConfig().set(name + ".unbreakable", true);
for (Enchantment enchant : item.getEnchantments().keySet())
config.getConfig().set(name + ".enchants." + MMOLib.plugin.getVersion().getWrapper().getName(enchant), item.getEnchantmentLevel(enchant));
config.getConfig().set(name + ".enchants." + MMOLib.plugin.getVersion().getWrapper().getName(enchant),
item.getEnchantmentLevel(enchant));
}
config.getConfig().set(name + ".material", args[0].equalsIgnoreCase("load") ? item.getType().name() : type.getItem().getType().name());
@ -664,13 +724,16 @@ public class MMOItemsCommand implements CommandExecutor {
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("drop")) {
if (args.length != 10) {
sender.sendMessage(MMOItems.plugin.getPrefix() + "Usage: /mi drop <type> <item-id> <world-name> <x> <y> <z> <drop-chance> <[min]-[max]> <unidentified-chance>");
sender.sendMessage(MMOItems.plugin.getPrefix()
+ "Usage: /mi drop <type> <item-id> <world-name> <x> <y> <z> <drop-chance> <[min]-[max]> <unidentified-chance>");
return true;
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.RED + "to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called "
+ args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.RED
+ "to see all the available item types.");
return true;
}
@ -749,7 +812,8 @@ public class MMOItemsCommand implements CommandExecutor {
ItemStack item = new DropItem(type, name, 0, dropChance / 100, unidentifiedChance / 100, min, max).getItem();
if (item == null || item.getType() == Material.AIR) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
sender.sendMessage(
MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
return true;
}
@ -764,8 +828,10 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called "
+ args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED
+ " to see all the available item types.");
return true;
}
@ -803,8 +869,10 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called "
+ args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED
+ " to see all the available item types.");
return true;
}
@ -818,7 +886,8 @@ public class MMOItemsCommand implements CommandExecutor {
ItemStack item = MMOItems.plugin.getItems().getItem(type, id);
if (item == null || item.getType() == Material.AIR) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + args[2].toUpperCase() + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called "
+ args[2].toUpperCase() + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
return true;
}
@ -826,7 +895,8 @@ public class MMOItemsCommand implements CommandExecutor {
long old = System.currentTimeMillis();
new ItemEdition((Player) sender, type, args[2], item).open();
long ms = System.currentTimeMillis() - old;
MMOLib.plugin.getNMS().sendActionBar((Player) sender, ChatColor.YELLOW + "Took " + ms + "ms (" + new DecimalFormat("#.##").format(ms / 50.) + "tick" + (ms > 99 ? "s" : "") + ") to open the menu.");
MMOLib.plugin.getNMS().sendActionBar((Player) sender, ChatColor.YELLOW + "Took " + ms + "ms ("
+ new DecimalFormat("#.##").format(ms / 50.) + "tick" + (ms > 99 ? "s" : "") + ") to open the menu.");
}
// ==================================================================================================================================
else if (args[0].equalsIgnoreCase("ability")) {
@ -836,7 +906,8 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (args.length < 2) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Usage: /mi ability <ability> (player) (modifier1) (value1) (modifier2) (value2)...");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED
+ "Usage: /mi ability <ability> (player) (modifier1) (value1) (modifier2) (value2)...");
return false;
}
@ -878,8 +949,10 @@ public class MMOItemsCommand implements CommandExecutor {
}
if (!Type.isValid(args[1])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.RED + "to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called "
+ args[1].toUpperCase().replace("-", "_") + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type " + ChatColor.RED
+ "to see all the available item types.");
return true;
}
@ -929,7 +1002,8 @@ public class MMOItemsCommand implements CommandExecutor {
ItemStack item = new DropItem(type, name, 0, 1, unidentifiedChance / 100, min, max).getItem();
if (item == null || item.getType() == Material.AIR) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
sender.sendMessage(
MMOItems.plugin.getPrefix() + ChatColor.RED + "An error occured while attempting to generate the item called " + name + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "See console for more information!");
return true;
}
@ -952,7 +1026,8 @@ public class MMOItemsCommand implements CommandExecutor {
// type
if (!Type.isValid(args[0])) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "There is no item type called " + args[0] + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED + " to see all the available item types.");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Type " + ChatColor.GREEN + "/mi list type" + ChatColor.RED
+ " to see all the available item types.");
return true;
}
@ -960,7 +1035,8 @@ public class MMOItemsCommand implements CommandExecutor {
Type type = Type.get(args[0]);
ItemStack item = MMOItems.plugin.getItems().getItem(type, args[1]);
if (item == null || item.getType() == Material.AIR) {
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Couldn't find/generate the item called " + args[1].toUpperCase() + ".");
sender.sendMessage(
MMOItems.plugin.getPrefix() + ChatColor.RED + "Couldn't find/generate the item called " + args[1].toUpperCase() + ".");
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.RED + "Check your console for potential item generation errors.");
return true;
}
@ -1014,8 +1090,11 @@ public class MMOItemsCommand implements CommandExecutor {
// message
if (sender != target)
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.YELLOW + "Successfully gave " + ChatColor.GOLD + MMOUtils.getDisplayName(item) + (item.getAmount() > 1 ? " x" + item.getAmount() : "") + ChatColor.YELLOW + " to " + ChatColor.GOLD + target.getName() + ChatColor.YELLOW + ".");
Message.RECEIVED_ITEM.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(item), "#amount#", (item.getAmount() > 1 ? " x" + item.getAmount() : "")).send(target);
sender.sendMessage(MMOItems.plugin.getPrefix() + ChatColor.YELLOW + "Successfully gave " + ChatColor.GOLD
+ MMOUtils.getDisplayName(item) + (item.getAmount() > 1 ? " x" + item.getAmount() : "") + ChatColor.YELLOW + " to "
+ ChatColor.GOLD + target.getName() + ChatColor.YELLOW + ".");
Message.RECEIVED_ITEM.format(ChatColor.YELLOW, "#item#", MMOUtils.getDisplayName(item), "#amount#",
(item.getAmount() > 1 ? " x" + item.getAmount() : "")).send(target);
// item
if (target.getInventory().firstEmpty() == -1) {

View File

@ -41,7 +41,8 @@ public class AbilityManager {
public void registerAbility(Ability ability) {
if (!registration) {
MMOItems.plugin.getLogger().log(Level.INFO, "Failed attempt to register ability " + ability.getID() + ". Make sure abilities are registered when MI is loading.");
MMOItems.plugin.getLogger().log(Level.INFO,
"Failed attempt to register ability " + ability.getID() + ". Make sure abilities are registered when MI is loading.");
return;
}
@ -55,7 +56,7 @@ public class AbilityManager {
abilities.put(ability.getID(), ability);
}
public void registerDefaultAbilities() {
public void initialize() {
try {
JarFile file = new JarFile(MMOItems.plugin.getJarFile());
for (Enumeration<JarEntry> enu = file.entries(); enu.hasMoreElements();) {
@ -82,7 +83,8 @@ public class AbilityManager {
int count = 0;
for (File file : mythicMobs.listFiles()) {
try {
registerAbility(new MythicMobsAbility(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file)));
registerAbility(new MythicMobsAbility(file.getName().substring(0, file.getName().length() - 4),
YamlConfiguration.loadConfiguration(file)));
count++;
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load ability from " + file.getName() + ": " + exception.getMessage());

View File

@ -39,22 +39,6 @@ public class BlockManager {
return customBlocks.get(mushroomStateValue.get(state.getUniqueId()));
}
public void reload() {
customBlocks.clear();
FileConfiguration config = new ConfigFile("custom-blocks").getConfig();
for (int id = 1; id < 161; id++)
if (id != 54 && config.contains("" + id))
try {
MushroomState state = new MushroomState(getType(id), upIds.contains(id), downIds.contains(id), westIds.contains(id), eastIds.contains(id), southIds.contains(id), northIds.contains(id));
customBlocks.put(id, new CustomBlock(id, state, config.getConfigurationSection("" + id)));
mushroomStateValue.put(state.getUniqueId(), id);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load custom block " + id + ": " + exception.getMessage());
}
}
public Collection<CustomBlock> getAll() {
return customBlocks.values();
}
@ -74,4 +58,21 @@ public class BlockManager {
public Material getType(int id) {
return id < 54 ? Material.BROWN_MUSHROOM_BLOCK : id > 99 ? Material.MUSHROOM_STEM : Material.RED_MUSHROOM_BLOCK;
}
public void reload() {
customBlocks.clear();
FileConfiguration config = new ConfigFile("custom-blocks").getConfig();
for (int id = 1; id < 161; id++)
if (id != 54 && config.contains("" + id))
try {
MushroomState state = new MushroomState(getType(id), upIds.contains(id), downIds.contains(id), westIds.contains(id),
eastIds.contains(id), southIds.contains(id), northIds.contains(id));
customBlocks.put(id, new CustomBlock(id, state, config.getConfigurationSection("" + id)));
mushroomStateValue.put(state.getUniqueId(), id);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load custom block " + id + ": " + exception.getMessage());
}
}
}

View File

@ -276,7 +276,8 @@ public class ConfigManager {
// item generator
EXAMPLE_GEN_TEMPLATES("generator/templates/example-templates.yml", "generator/templates", "example-templates.yml"),
EXAMPLE_GEN_MODIFIERS("generator/modifiers/example-modifiers.yml", "generator/modifiers", "example-modifiers.yml"),
ITEM_GEN_CONFIG("generator/config.yml", "generator", "config.yml"),
// default item config files -> /MMOItems/item
ARMOR("item/armor.yml", "item", "armor.yml"),
AXE("item/axe.yml", "item", "axe.yml"),

View File

@ -31,21 +31,20 @@ import net.Indyuce.mmoitems.listener.CustomBlockListener;
import net.mmogroup.mmolib.MMOLib;
public class DropTableManager implements Listener {
private Map<EntityType, DropTable> monsters = new HashMap<>();
private Map<Material, DropTable> blocks = new HashMap<>();
private Map<Integer, DropTable> customBlocks = new HashMap<>();
private final Map<EntityType, DropTable> monsters = new HashMap<>();
private final Map<Material, DropTable> blocks = new HashMap<>();
private final Map<Integer, DropTable> customBlocks = new HashMap<>();
public DropTableManager() {
reload();
}
public void reload() {
FileConfiguration config = new ConfigFile("drops").getConfig();
monsters.clear();
blocks.clear();
customBlocks.clear();
FileConfiguration config = new ConfigFile("drops").getConfig();
if (config.contains("monsters"))
for (String key : config.getConfigurationSection("monsters").getKeys(false))
try {
@ -63,7 +62,7 @@ public class DropTableManager implements Listener {
} catch (Exception e) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Couldn't read the drop table material " + key);
}
if (config.contains("customblocks"))
for (String key : config.getConfigurationSection("customblocks").getKeys(false))
try {
@ -94,21 +93,20 @@ public class DropTableManager implements Listener {
final Material type = block.getType();
CustomBlock custom = MMOLib.plugin.getVersion().isStrictlyHigher(1, 12) ? CustomBlock.getFromData(block.getBlockData()) : null;
if(custom != null) {
if (custom != null) {
if (customBlocks.containsKey(custom.getId()))
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
if(CustomBlockListener.getPickaxePower(player) >= custom.getRequiredPower())
for (ItemStack drop : customBlocks.get(custom.getId()).read(hasSilkTouchTool(player))) {
CustomBlockDropEvent called = new CustomBlockDropEvent(player, custom, drop);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
Item item = block.getWorld().dropItemNaturally(block.getLocation().add(.5, .1, .5), called.getDrop());
item.setVelocity(item.getVelocity().multiply(0.5f));
}
if (CustomBlockListener.getPickaxePower(player) >= custom.getRequiredPower())
for (ItemStack drop : customBlocks.get(custom.getId()).read(hasSilkTouchTool(player))) {
CustomBlockDropEvent called = new CustomBlockDropEvent(player, custom, drop);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
Item item = block.getWorld().dropItemNaturally(block.getLocation().add(.5, .1, .5), called.getDrop());
item.setVelocity(item.getVelocity().multiply(0.5f));
}
}, 2);
}
else {
} else {
if (blocks.containsKey(type))
Bukkit.getScheduler().runTaskLater(MMOItems.plugin, () -> {
for (ItemStack drop : blocks.get(type).read(hasSilkTouchTool(player))) {
@ -123,14 +121,14 @@ public class DropTableManager implements Listener {
final Material type = block.getType();
CustomBlock custom = MMOLib.plugin.getVersion().isStrictlyHigher(1, 12) ? CustomBlock.getFromData(block.getBlockData()) : null;
if(custom != null) {
if(customBlocks.containsKey(custom.getId())) {
if(CustomBlockListener.getPickaxePower(player) >= custom.getRequiredPower()) {
if (custom != null) {
if (customBlocks.containsKey(custom.getId())) {
if (CustomBlockListener.getPickaxePower(player) >= custom.getRequiredPower()) {
return customBlocks.get(custom.getId()).read(hasSilkTouchTool(player));
}
}
} else {
if(blocks.containsKey(type)) {
if (blocks.containsKey(type)) {
return blocks.get(type).read(hasSilkTouchTool(player));
}
}

View File

@ -3,36 +3,88 @@ package net.Indyuce.mmoitems.manager;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ConfigFile;
import net.Indyuce.mmoitems.api.itemgen.GeneratedItemBuilder;
import net.Indyuce.mmoitems.api.itemgen.GenerationModifier;
import net.Indyuce.mmoitems.api.itemgen.GenerationTemplate;
import net.Indyuce.mmoitems.api.itemgen.NumericStatFormula;
import net.Indyuce.mmoitems.api.itemgen.tier.RandomTierInfo;
import net.Indyuce.mmoitems.api.itemgen.tier.RolledTier;
public class ItemGenManager {
private final Map<String, GenerationTemplate> templates = new HashMap<>();
/*
* bank of item modifiers which can be used anywhere in generation templates
* to make item generation easier.
*/
private final Map<String, GenerationModifier> modifiers = new HashMap<>();
/*
* tiers which the item generator can use to determine how much modifier
* capacity an item has. plugin has a default capacity calculator in case
* none is specified by the user but it's best to configure it
*/
private final Set<RandomTierInfo> itemGenTiers = new LinkedHashSet<>();
private RandomTierInfo defaultTier;
private static final Random random = new Random();
public ItemGenManager() {
reload();
}
public Collection<GenerationTemplate> getTemplates() {
return templates.values();
}
public Collection<GenerationModifier> getModifiers() {
return modifiers.values();
}
public boolean hasTemplate(String id) {
return templates.containsKey(id);
}
public boolean hasModifier(String id) {
return modifiers.containsKey(id);
}
public GenerationTemplate getTemplate(String id) {
return templates.get(id);
}
public GenerationModifier getModifier(String id) {
return modifiers.get(id);
}
public void reload() {
templates.clear();
itemGenTiers.clear();
modifiers.clear();
for (File file : new File(MMOItems.plugin.getDataFolder() + "/generator/modifiers").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
for (String key : config.getKeys(false))
try {
GenerationModifier modifier = new GenerationModifier(config.getConfigurationSection(key));
modifiers.put(modifier.getId(), modifier);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured while trying to load item gen modifier '" + key + "': " + exception.getMessage());
}
}
for (File file : new File(MMOItems.plugin.getDataFolder() + "/generator/templates").listFiles()) {
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
for (String key : config.getKeys(false))
@ -41,8 +93,42 @@ public class ItemGenManager {
templates.put(template.getId(), template);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured loading item gen template '" + key + "': " + exception.getMessage());
"An error occured while trying to load item gen template '" + key + "': " + exception.getMessage());
}
}
FileConfiguration config = new ConfigFile("/generator", "config").getConfig();
for (String key : config.getConfigurationSection("tiers").getKeys(false))
if (!key.equalsIgnoreCase("default"))
try {
RandomTierInfo tier = new RandomTierInfo(config.getConfigurationSection("tiers." + key));
itemGenTiers.add(tier);
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured while trying to load item gen tier capacity formula which ID '" + key + "': " + exception.getMessage());
}
try {
defaultTier = new RandomTierInfo(new NumericStatFormula(config.getConfigurationSection("tiers.default.capacity")));
} catch (IllegalArgumentException exception) {
defaultTier = new RandomTierInfo(new NumericStatFormula(5, .05, .1, .3));
MMOItems.plugin.getLogger().log(Level.INFO,
"An error occured while trying to load default capacity formula for the item generator, using default: "
+ exception.getMessage());
}
}
public RolledTier rollTier(GeneratedItemBuilder builder) {
double s = 0;
for (RandomTierInfo tier : itemGenTiers) {
if (random.nextDouble() < tier.getChance() / (1 - s))
return tier.roll(builder);
s += tier.getChance();
}
// default tier
return defaultTier.roll(builder);
}
}

View File

@ -1,38 +1,34 @@
package net.Indyuce.mmoitems.manager;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.function.Predicate;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.MMOItem;
import net.Indyuce.mmoitems.stat.type.ItemStat;
public class ItemManager {
private final Map<Type, Map<String, LoadedItem>> map = new HashMap<>();
private final boolean useCache;
public class ItemManager extends BukkitRunnable {
private final Map<Type, CachedItems> cache = new HashMap<>();
public ItemManager(boolean useCache) {
if (this.useCache = useCache)
Bukkit.getScheduler().runTaskTimerAsynchronously(MMOItems.plugin, () -> clearCache(), 60 * 20, 2 * 60 * 20);
public ItemManager() {
runTaskTimerAsynchronously(MMOItems.plugin, 60 * 20, 2 * 60 * 20);
}
public MMOItem getMMOItem(Type type, String id) {
id = id.toUpperCase().replace("-", "_").replace(" ", "_");
if (useCache) {
LoadedItem cached = getCachedMMOItem(type, id);
if (cached != null) {
cached.refresh();
return cached.getItem();
}
LoadedItem cached = getCachedMMOItem(type, id);
if (cached != null) {
cached.refresh();
return cached.getItem();
}
FileConfiguration typeConfig = type.getConfigFile().getConfig();
@ -51,9 +47,7 @@ public class ItemManager {
"Error while loading " + type.getId() + "." + id + " (" + stat.getName() + "): " + exception.getMessage());
}
if (useCache)
cache(mmoitem);
cache(mmoitem);
return mmoitem;
}
@ -63,8 +57,8 @@ public class ItemManager {
}
public LoadedItem getCachedMMOItem(Type type, String id) {
Map<String, LoadedItem> map;
return this.map.containsKey(type) ? (map = this.map.get(type)).containsKey(id) ? map.get(id) : null : null;
CachedItems cached;
return this.cache.containsKey(type) ? (cached = cache.get(type)).isCached(id) ? cached.getCached(id) : null : null;
}
/*
@ -74,8 +68,8 @@ public class ItemManager {
public boolean hasMMOItem(Type type, String id) {
id = id.toUpperCase().replace("-", "_").replace(" ", "_");
// check map
if (map.containsKey(type) && map.containsKey(type) && map.get(type).containsKey(id))
// check cache
if (cache.containsKey(type) && cache.get(type).isCached(id))
return true;
// check type config file
@ -83,28 +77,46 @@ public class ItemManager {
}
public void uncache(Type type, String id) {
if (map.containsKey(type))
map.get(type).remove(id);
if (cache.containsKey(type))
cache.get(type).emptyCache(id);
}
private void cache(MMOItem item) {
if (!map.containsKey(item.getType()))
map.put(item.getType(), new HashMap<>());
map.get(item.getType()).put(item.getId(), new LoadedItem(item));
if (!cache.containsKey(item.getType()))
cache.put(item.getType(), new CachedItems());
cache.get(item.getType()).cache(item.getId(), item);
}
/*
* every two minutes, loops through any loaded item and uncaches any if they
* have not been generated for more than 5 minutes.
*/
private void clearCache() {
for (Type type : map.keySet()) {
Map<String, LoadedItem> map = this.map.get(type);
for (String id : new HashSet<>(map.keySet())) {
LoadedItem item = map.get(id);
if (item.isTimedOut())
map.remove(id);
}
@Override
public void run() {
cache.values().forEach(cached -> cached.removeIf(loaded -> loaded.isTimedOut()));
}
public class CachedItems {
private final Map<String, LoadedItem> cache = new HashMap<>();
public LoadedItem getCached(String id) {
return cache.get(id);
}
public boolean isCached(String id) {
return cache.containsKey(id);
}
public void emptyCache(String id) {
cache.remove(id);
}
public void cache(String id, MMOItem item) {
cache.put(id, new LoadedItem(item));
}
public void removeIf(Predicate<LoadedItem> filter) {
cache.values().removeIf(filter);
}
}
@ -131,6 +143,6 @@ public class ItemManager {
}
public void reload() {
map.clear();
cache.clear();
}
}

View File

@ -17,9 +17,9 @@ public class SetManager {
}
public void reload() {
ConfigFile config = new ConfigFile("item-sets");
itemSets.clear();
ConfigFile config = new ConfigFile("item-sets");
for (String id : config.getConfig().getKeys(false))
try {
itemSets.put(id, new ItemSet(config.getConfig().getConfigurationSection(id)));
@ -28,6 +28,14 @@ public class SetManager {
}
}
public void register(ItemSet set) {
itemSets.put(set.getId(), set);
}
public boolean has(String id) {
return itemSets.containsKey(id);
}
public Collection<ItemSet> getAll() {
return itemSets.values();
}

View File

@ -12,7 +12,7 @@ import net.Indyuce.mmoitems.api.item.MMOItem;
import net.Indyuce.mmoitems.stat.type.ItemStat;
public class TierManager {
private Map<String, ItemTier> tiers = new HashMap<>();
private final Map<String, ItemTier> tiers = new HashMap<>();
public TierManager() {
reload();

View File

@ -15,15 +15,11 @@ import net.Indyuce.mmoitems.manager.ConfigManager.DefaultFile;
public class TypeManager {
private final Map<String, Type> map = new LinkedHashMap<>();
public TypeManager() {
reload();
}
public void reload() {
map.clear();
addAll(Type.ACCESSORY, Type.ARMOR, Type.BOW, Type.CATALYST, Type.CONSUMABLE, Type.CROSSBOW, Type.DAGGER,
Type.GAUNTLET,Type.GEM_STONE, Type.SKIN, Type.HAMMER, Type.LUTE, Type.MISCELLANEOUS, Type.MUSKET, Type.OFF_CATALYST,
Type.ORNAMENT, Type.SPEAR, Type.STAFF, Type.SWORD, Type.TOOL, Type.WHIP);
addAll(Type.ACCESSORY, Type.ARMOR, Type.BOW, Type.CATALYST, Type.CONSUMABLE, Type.CROSSBOW, Type.DAGGER, Type.GAUNTLET, Type.GEM_STONE,
Type.SKIN, Type.HAMMER, Type.LUTE, Type.MISCELLANEOUS, Type.MUSKET, Type.OFF_CATALYST, Type.ORNAMENT, Type.SPEAR, Type.STAFF,
Type.SWORD, Type.TOOL, Type.WHIP);
/*
* register all other types. important: check if the map already

View File

@ -196,7 +196,8 @@ public class UpdaterManager implements Listener {
return new UpdaterData(path, config);
}
public UpdaterData newUpdaterData(String path, UUID uuid, boolean keepLore, boolean keepEnchants, boolean keepDurability, boolean keepName, boolean keepGems, boolean keepSoulbound) {
public UpdaterData newUpdaterData(String path, UUID uuid, boolean keepLore, boolean keepEnchants, boolean keepDurability, boolean keepName,
boolean keepGems, boolean keepSoulbound) {
return new UpdaterData(path, uuid, keepLore, keepEnchants, keepDurability, keepName, keepGems, keepSoulbound);
}
@ -215,14 +216,17 @@ public class UpdaterManager implements Listener {
private boolean keepLore, keepDurability, keepEnchants, keepName, keepGems, keepSoulbound;
public UpdaterData(String path, FileConfiguration config) {
this(path, UUID.fromString(config.getString(path + ".uuid")), config.getBoolean(path + ".lore"), config.getBoolean(path + ".enchants"), config.getBoolean(path + ".durability"), config.getBoolean(path + ".name"), config.getBoolean(path + ".gems"), config.getBoolean(path + ".soulbound"));
this(path, UUID.fromString(config.getString(path + ".uuid")), config.getBoolean(path + ".lore"), config.getBoolean(path + ".enchants"),
config.getBoolean(path + ".durability"), config.getBoolean(path + ".name"), config.getBoolean(path + ".gems"),
config.getBoolean(path + ".soulbound"));
}
public UpdaterData(String path, UUID uuid) {
this(path, uuid, false, false, false, false, false, false);
}
public UpdaterData(String path, UUID uuid, boolean keepLore, boolean keepEnchants, boolean keepDurability, boolean keepName, boolean keepGems, boolean keepSoulbound) {
public UpdaterData(String path, UUID uuid, boolean keepLore, boolean keepEnchants, boolean keepDurability, boolean keepName, boolean keepGems,
boolean keepSoulbound) {
this.uuid = uuid;
this.path = path;

View File

@ -17,7 +17,7 @@ public class UpgradeManager {
public UpgradeManager() {
reload();
}
public void reload() {
templates.clear();

View File

@ -28,12 +28,7 @@ public abstract class RecipeManager {
*/
private final Set<LoadedRecipe> loadedRecipes = new HashSet<>();
public RecipeManager() {
if (!MMOItems.plugin.getConfig().getBoolean("disable-craftings"))
load();
}
public abstract void load();
public abstract void reload();
public abstract void registerFurnaceRecipe(Type type, String id, BurningRecipeInformation info, String number);
@ -82,7 +77,7 @@ public abstract class RecipeManager {
}
loadedRecipes.clear();
load();
reload();
});
}

View File

@ -28,7 +28,7 @@ public class RecipeManagerDefault extends RecipeManager {
@Override
@SuppressWarnings("deprecation")
public void load() {
public void reload() {
for (Type type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();

View File

@ -23,7 +23,7 @@ public class RecipeManagerLegacy extends RecipeManager {
@Override
@SuppressWarnings("deprecation")
public void load() {
public void reload() {
for (Type type : MMOItems.plugin.getTypes().getAll()) {
FileConfiguration config = type.getConfigFile().getConfig();

View File

@ -9,12 +9,6 @@
# Requires /reload when changed.
update-notify: true
# The plugin takes a few milliseconds to read the item data from the item
# config and a few hundred MICROseconds to actually generate it. Caching the
# item allows to skip the first step which reduces ~6 times the delay needed
# to generate any mmoitem. Takes up more RAM.
use-item-caching: true
# Enable/disable the plugin iterating over the whole player inventory
# instead of just the players armor and held items.
# This option is required for the Ornament item type, however

View File

@ -0,0 +1,64 @@
# Item Generator Config
# Specify how rare certain tiers are and how much
# modifier capacity they should have.
tiers:
uncommon:
chance: 0.15
capacity:
base: 6
# Scales on the item level
scale: .1
spread: .1
max-spread: .3
rare:
chance: 0.06
capacity:
base: 9
scale: .15
spread: .1
max-spread: .3
legendary:
chance: 0.01
capacity:
base: 12
scale: .2
spread: .1
max-spread: .3
mythical:
chance: 0.003
capacity:
base: 15
scale: .3
spread: .1
max-spread: .3
default:
capacity:
base: 3
# Scales on the item level
scale: 0.06
spread: .1
max-spread: .3
# When generating an item, the item gen must
# choose an item level which coincides with
# the player's level (otherwise unplayable).
#
# The item level is modeled by a gaussian
# random variable which mean is the player level.
# You can edit the standard deviation here.
#
# Leave it like this if don't you know
# what it does, default value is fine.
item-level-spread: 2

View File

@ -1,2 +1,18 @@
sharp:
chance: 0.3
prefix: '&fSharp'
stats:
attack-damage: 3
lore:
- '&7Much sharper!'
fiery:
chance: 0.1
prefix:
format: '&cFiery'
priority: 1
stats:
ability:
on-hit:
type: burn
mode: on_hit

View File

@ -2,10 +2,9 @@
# Example item
LONG_SWORD:
# Basic item information
type: SWORD
material: IRON_SWORD
# The more weight a randomly generated item has,
# the more modifiers it will be able to roll
@ -17,18 +16,34 @@ LONG_SWORD:
# Base item data
base:
material: IRON_SWORD
name: '&fLong Sword'
max-durability: 300.0
attack-damage: 7
attack-speed: 1.6
attack-damage:
base: 6
scale: 1.2
relative-spread: .1
max-relative-spread: .3
required-level:
base: 0
scale: 1
# Modifiers which have a chance to be rolled
modifiers:
sharp:
chance: 0.3
prefix:
format: '&fSharp'
priority : 0
prefix: '&fSharp'
stats:
attack-damage: 3
lore:
- '&7Much sharper!'
fiery:
chance: 0.1
prefix:
format: '&cFiery'
priority: 1
stats:
ability:
on-hit:
type: burn
mode: on_hit