> MMOItems 6.5 - API Handling Rewrite

REQUIRES MMOLIB 1.7!!!
- Rewrote MMOLib compatibility API (MMOLib is still a dependency!)
- Lootsplosions are now a part of MMOItems.
This commit is contained in:
ASangarin 2020-12-06 17:47:13 +01:00
parent 502563bbc0
commit 7402b572ab
32 changed files with 741 additions and 688 deletions

59
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOItems</artifactId>
<version>6.4</version>
<version>6.5</version>
<name>MMOItems</name>
<description>A great item solution for your RPG server.</description>
@ -47,32 +47,6 @@
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>../build.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${jar.path}</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
@ -94,23 +68,6 @@
</repository>
</repositories>
<dependencies>
<!-- MMOs -->
<dependency>
<groupId>net.mmogroup</groupId>
<artifactId>MMOLib</artifactId>
<version>1.0.9</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOLib.jar</systemPath>
</dependency>
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>mmocore</artifactId>
<version>1.4.12</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOCore.jar</systemPath>
</dependency>
<!-- Minecraft -->
<dependency>
<groupId>com.mojang</groupId>
@ -125,6 +82,20 @@
<systemPath>${basedir}/lib/spigot.jar</systemPath>
</dependency>
<!-- MMOs -->
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOLib</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
<!-- APIs -->
<dependency>
<groupId>org.jetbrains</groupId>

View File

@ -50,6 +50,7 @@ import net.Indyuce.mmoitems.listener.DurabilityListener;
import net.Indyuce.mmoitems.listener.ElementListener;
import net.Indyuce.mmoitems.listener.ItemListener;
import net.Indyuce.mmoitems.listener.ItemUse;
import net.Indyuce.mmoitems.listener.LootsplosionListener;
import net.Indyuce.mmoitems.listener.PlayerListener;
import net.Indyuce.mmoitems.manager.AbilityManager;
import net.Indyuce.mmoitems.manager.BlockManager;
@ -69,7 +70,6 @@ import net.Indyuce.mmoitems.manager.TierManager;
import net.Indyuce.mmoitems.manager.TypeManager;
import net.Indyuce.mmoitems.manager.UpgradeManager;
import net.Indyuce.mmoitems.manager.WorldGenManager;
import net.mmogroup.mmolib.api.player.MMOPlayerData;
import net.mmogroup.mmolib.version.SpigotPlugin;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
@ -120,21 +120,19 @@ public class MMOItems extends JavaPlugin {
public void onLoad() {
plugin = this;
if (getServer().getPluginManager().getPlugin("WorldGuard") != null)
try {
flagPlugin = new WorldGuardFlags();
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldGuard 7: " + exception.getMessage());
}
if (getServer().getPluginManager().getPlugin("WorldGuard") != null) try {
flagPlugin = new WorldGuardFlags();
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldGuard 7: " + exception.getMessage());
}
if (getServer().getPluginManager().getPlugin("WorldEdit") != null)
try {
new WorldEditSupport();
getLogger().log(Level.INFO, "Hooked onto WorldEdit");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldEdit 7: " + exception.getMessage());
}
if (getServer().getPluginManager().getPlugin("WorldEdit") != null) try {
new WorldEditSupport();
getLogger().log(Level.INFO, "Hooked onto WorldEdit");
} catch (Exception exception) {
getLogger().log(Level.WARNING, "Could not initialize support with WorldEdit 7: " + exception.getMessage());
}
saveDefaultConfig();
@ -146,15 +144,14 @@ public class MMOItems extends JavaPlugin {
typeManager.reload();
templateManager.preloadTemplates();
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null)
new MMOCoreMMOLoader();
if (Bukkit.getPluginManager().getPlugin("MMOCore") != null) new MMOCoreMMOLoader();
}
public void onEnable() {
new SpigotPlugin(39267, this).checkForUpdate();
final int configVersion = getConfig().contains("config-version", true) ? getConfig().getInt("config-version") : -1;
final int defConfigVersion = getConfig().getDefaults().getInt("config-version");
if(configVersion != defConfigVersion) {
if (configVersion != defConfigVersion) {
getLogger().warning("You may be using an outdated config.yml!");
getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" + defConfigVersion + "')");
}
@ -191,8 +188,7 @@ public class MMOItems extends JavaPlugin {
worldGenManager = new WorldGenManager();
blockManager = new BlockManager();
if (Bukkit.getPluginManager().getPlugin("Vault") != null)
vaultSupport = new VaultSupport();
if (Bukkit.getPluginManager().getPlugin("Vault") != null) vaultSupport = new VaultSupport();
getLogger().log(Level.INFO, "Loading crafting stations, please wait..");
layoutManager.reload();
@ -209,6 +205,8 @@ public class MMOItems extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(new GuiListener(), this);
Bukkit.getPluginManager().registerEvents(new ElementListener(), this);
Bukkit.getPluginManager().registerEvents(new CustomBlockListener(), this);
if (getConfig().getBoolean("lootsplosion.enabled"))
Bukkit.getPluginManager().registerEvents(new LootsplosionListener(), this);
/*
* this class implements the Listener, if the option
@ -272,8 +270,7 @@ public class MMOItems extends JavaPlugin {
if (Bukkit.getPluginManager().getPlugin("GlowAPI") != null && Bukkit.getPluginManager().getPlugin("PacketListenerApi") != null) {
Bukkit.getPluginManager().registerEvents(new ItemGlowListener(), this);
getLogger().log(Level.INFO, "Hooked onto GlowAPI (Item Glow)");
} else
Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
} else Bukkit.getPluginManager().registerEvents(new NoGlowListener(), this);
}
if (Bukkit.getPluginManager().getPlugin("RealDualWield") != null) {
@ -292,7 +289,7 @@ public class MMOItems extends JavaPlugin {
boolean book = getConfig().getBoolean("recipes.use-recipe-book");
boolean amounts = getConfig().getBoolean("recipes.recipe-amounts");
if(book && amounts) {
if (book && amounts) {
getLogger().warning("Tried to enable recipe book while amounts are active!");
getLogger().warning("Please use only ONE of these options!");
getLogger().warning("Disabling both options for now...");
@ -301,8 +298,7 @@ public class MMOItems extends JavaPlugin {
}
recipeManager.load(book, amounts);
if(amounts)
Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
if (amounts) Bukkit.getPluginManager().registerEvents(new CraftingListener(), this);
// amount and bukkit recipes
getLogger().log(Level.INFO, "Loading recipes, please wait...");
@ -321,7 +317,7 @@ public class MMOItems extends JavaPlugin {
public void onDisable() {
// save player data
MMOPlayerData.getLoaded().stream().filter(data -> data.getMMOItems() != null).forEach(data -> data.getMMOItems().save());
PlayerData.getLoaded().forEach(PlayerData::save);
// save item updater data
ConfigFile updater = new ConfigFile("/dynamic", "updater");
@ -374,8 +370,7 @@ public class MMOItems extends JavaPlugin {
* player level, class, resources like mana and stamina for item or skill
* costs, item restrictions, etc.
*
* @param handler
* Your RPGHandler instance
* @param handler Your RPGHandler instance
*/
public void setRPG(RPGHandler handler) {
Validate.notNull(handler, "RPGHandler cannot be null");
@ -403,11 +398,10 @@ public class MMOItems extends JavaPlugin {
* checks held items + armor slots. However other plugins like MMOInv do
* implement custom slots and therefore must register a custom
* PlayerInventory instance.
*
* <p>
* Default instance is DefaultPlayerInventory in comp.inventory
*
* @param value
* The player inventory subclass
* @param value The player inventory subclass
*/
public void setPlayerInventory(PlayerInventory value) {
inventory = value;
@ -494,8 +488,7 @@ public class MMOItems extends JavaPlugin {
}
public void findRpgPlugin() {
if (rpgPlugin != null)
return;
if (rpgPlugin != null) return;
for (RPGHandler.PluginEnum plugin : RPGHandler.PluginEnum.values())
if (Bukkit.getPluginManager().getPlugin(plugin.getName()) != null) {
@ -509,9 +502,9 @@ public class MMOItems extends JavaPlugin {
/**
* @return Generates an item given an item template. The item level will
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
* scale according to the player RPG level if the template has the
* 'level-item' option. The item will pick a random tier if the
* template has the 'tiered' option
*/
public MMOItem getMMOItem(Type type, String id, PlayerData player) {
return templateManager.getTemplate(type, id).newBuilder(player.getRPG()).build();
@ -522,12 +515,10 @@ public class MMOItems extends JavaPlugin {
}
/**
* @param itemLevel
* The desired item level
* @param itemTier
* The desired item tier, can be null
* @param itemLevel The desired item level
* @param itemTier The desired item tier, can be null
* @return Generates an item given an item template with a specific item
* level and item tier
* level and item tier
*/
public MMOItem getMMOItem(Type type, String id, int itemLevel, @Nullable ItemTier itemTier) {
return templateManager.getTemplate(type, id).newBuilder(itemLevel, itemTier).build();
@ -539,8 +530,8 @@ public class MMOItems extends JavaPlugin {
/**
* @return Generates an item given an item template. The item level will be
* 0 and the item will have no item tier unless one is specified in
* the base item data.
* 0 and the item will have no item tier unless one is specified in
* the base item data.
*/
public MMOItem getMMOItem(Type type, String id) {
return templateManager.getTemplate(type, id).newBuilder(0, null).build();

View File

@ -230,7 +230,7 @@ public class Type {
*/
@Deprecated
public static Type get(ItemStack item) {
return MMOLib.plugin.getVersion().getWrapper().getNBTItem(item).getType();
return Type.get(MMOLib.plugin.getVersion().getWrapper().getNBTItem(item).getType());
}
/**
@ -241,7 +241,7 @@ public class Type {
* @return The type or NPE if it couldn't be found
*/
public static Type get(String id) {
return MMOItems.plugin.getTypes().get(id.toUpperCase().replace("-", "_").replace(" ", "_"));
return isValid(id) ? MMOItems.plugin.getTypes().get(id.toUpperCase().replace("-", "_").replace(" ", "_")) : null;
}
/**
@ -252,7 +252,7 @@ public class Type {
* @return If a registered type with this ID could be found
*/
public static boolean isValid(String id) {
return MMOItems.plugin.getTypes().has(id.toUpperCase().replace("-", "_").replace(" ", "_"));
return id != null && MMOItems.plugin.getTypes().has(id.toUpperCase().replace("-", "_").replace(" ", "_"));
}
public enum EquipmentSlot {

View File

@ -72,7 +72,7 @@ public class Consumable extends UseItem {
* Unidentified items do not have any type, so you must check if the
* item has a type first.
*/
Type targetType = target.getType();
Type targetType = Type.get(target.getType());
if (targetType == null) {
if (getNBTItem().getBoolean("MMOITEMS_CAN_IDENTIFY") && target.hasTag("MMOITEMS_UNIDENTIFIED_ITEM")) {
@ -177,7 +177,7 @@ public class Consumable extends UseItem {
* applying a soulbound onto an item. it does not work if the item
* already has a soulbound, and it has a chance to successfully apply.
*/
double soulbindingChance = getNBTItem().getStat(ItemStats.SOULBINDING_CHANCE);
double soulbindingChance = getNBTItem().getStat(ItemStats.SOULBINDING_CHANCE.getId());
if (soulbindingChance > 0) {
if (target.getItem().getAmount() > 1) {
Message.CANT_BIND_STACKED.format(ChatColor.RED).send(player, "soulbound");
@ -198,7 +198,7 @@ public class Consumable extends UseItem {
if (called.isCancelled())
return false;
int soulboundLevel = (int) Math.max(1, getNBTItem().getStat(ItemStats.SOULBOUND_LEVEL));
int soulboundLevel = (int) Math.max(1, getNBTItem().getStat(ItemStats.SOULBOUND_LEVEL.getId()));
(targetMMO = new LiveMMOItem(target)).setData(ItemStats.SOULBOUND,
((Soulbound) ItemStats.SOULBOUND).newSoulboundData(player.getUniqueId(), player.getName(), soulboundLevel));
target.getItem().setItemMeta(targetMMO.newBuilder().build().getItemMeta());
@ -220,7 +220,7 @@ public class Consumable extends UseItem {
* have at least the soulbound's level to be able to break the item
* soulbound.
*/
double soulboundBreakChance = getNBTItem().getStat(ItemStats.SOULBOUND_BREAK_CHANCE);
double soulboundBreakChance = getNBTItem().getStat(ItemStats.SOULBOUND_BREAK_CHANCE.getId());
if (soulboundBreakChance > 0) {
MMOItem targetMMO = new VolatileMMOItem(target);
if (!targetMMO.hasData(ItemStats.SOULBOUND)) {
@ -232,7 +232,7 @@ public class Consumable extends UseItem {
SoulboundData soulbound = (SoulboundData) targetMMO.getData(ItemStats.SOULBOUND);
// check for soulbound level
if (Math.max(1, getNBTItem().getStat(ItemStats.SOULBOUND_LEVEL)) < soulbound.getLevel()) {
if (Math.max(1, getNBTItem().getStat(ItemStats.SOULBOUND_LEVEL.getId())) < soulbound.getLevel()) {
Message.LOW_SOULBOUND_LEVEL.format(ChatColor.RED, "#level#", MMOUtils.intToRoman(soulbound.getLevel())).send(player, "soulbound");
return false;
}
@ -261,7 +261,7 @@ public class Consumable extends UseItem {
* Item repairing, does not apply if there's no repair power or if the
* item still has all its uses left
*/
int repairPower = (int) getNBTItem().getStat(ItemStats.REPAIR);
int repairPower = (int) getNBTItem().getStat(ItemStats.REPAIR.getId());
if (repairPower > 0) {
// custom durability

View File

@ -52,7 +52,7 @@ public class GemStone extends UseItem {
return new ApplyResult(ResultType.NONE);
// check for success rate
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE);
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
if (successRate != 0 && random.nextDouble() > successRate / 100) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
Message.GEM_STONE_BROKE

View File

@ -54,7 +54,7 @@ public class ItemSkin extends UseItem {
}
// check for success rate
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE);
double successRate = getNBTItem().getStat(ItemStats.SUCCESS_RATE.getId());
if (successRate != 0)
if (random.nextDouble() < 1 - successRate / 100) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);

View File

@ -95,6 +95,10 @@ public class UseItem {
Bukkit.dispatchCommand(player, parsed);
}
public static UseItem getItem(Player player, NBTItem item, String type) {
return getItem(player, item, Type.get(type));
}
public static UseItem getItem(Player player, NBTItem item, Type type) {
if (type.corresponds(Type.CONSUMABLE))
return new Consumable(player, item);

View File

@ -43,7 +43,7 @@ public class Weapon extends UseItem {
if (!isSwing && getPlayerData().isOnCooldown(cooldown))
return false;
double manaCost = getNBTItem().getStat(ItemStats.MANA_COST), staminaCost = getNBTItem().getStat(ItemStats.STAMINA_COST);
double manaCost = getNBTItem().getStat(ItemStats.MANA_COST.getId()), staminaCost = getNBTItem().getStat(ItemStats.STAMINA_COST.getId());
if (manaCost > 0 && playerData.getRPG().getMana() < manaCost) {
Message.NOT_ENOUGH_MANA.format(ChatColor.RED).send(getPlayer(), "not-enough-mana");
@ -69,7 +69,7 @@ public class Weapon extends UseItem {
@SuppressWarnings("UnusedReturnValue")
public ItemAttackResult targetedAttack(CachedStats stats, LivingEntity target, ItemAttackResult result) {
// cooldown
double attackSpeed = getNBTItem().getStat(ItemStats.ATTACK_SPEED);
double attackSpeed = getNBTItem().getStat(ItemStats.ATTACK_SPEED.getId());
attackSpeed = attackSpeed == 0 ? 1.493 : 1 / attackSpeed;
if (!hasEnoughResources(attackSpeed, CooldownType.ATTACK, true))
return result.setSuccessful(false);

View File

@ -42,7 +42,7 @@ public class Crossbow extends UntargetedWeapon {
getPlayer().getWorld().playSound(getPlayer().getLocation(), Sound.ENTITY_ARROW_SHOOT, 1, 1);
Arrow arrow = getPlayer().launchProjectile(Arrow.class);
arrow.setVelocity(getPlayer().getEyeLocation().getDirection().multiply(3 * getValue(getNBTItem().getStat(ItemStats.ARROW_VELOCITY), 1)));
arrow.setVelocity(getPlayer().getEyeLocation().getDirection().multiply(3 * getValue(getNBTItem().getStat(ItemStats.ARROW_VELOCITY.getId()), 1)));
getPlayer().setVelocity(getPlayer().getVelocity().setX(0).setZ(0));
MMOItems.plugin.getEntities().registerCustomProjectile(getNBTItem(), stats.newTemporary(), arrow, true);

View File

@ -42,8 +42,8 @@ public class Lute extends UntargetedWeapon {
durItem.decreaseDurability(1).update();
double attackDamage = getValue(stats.getStat(ItemStats.ATTACK_DAMAGE), 1);
double range = getValue(getNBTItem().getStat(ItemStats.RANGE), MMOItems.plugin.getConfig().getDouble("default.range"));
Vector weight = new Vector(0, -.003 * getNBTItem().getStat(ItemStats.NOTE_WEIGHT), 0);
double range = getValue(getNBTItem().getStat(ItemStats.RANGE.getId()), MMOItems.plugin.getConfig().getDouble("default.range"));
Vector weight = new Vector(0, -.003 * getNBTItem().getStat(ItemStats.NOTE_WEIGHT.getId()), 0);
LuteAttackEffect effect = LuteAttackEffect.get(getNBTItem());
Sound sound = new SoundReader(getNBTItem().getString("MMOITEMS_LUTE_ATTACK_SOUND"), VersionSound.BLOCK_NOTE_BLOCK_BELL.toSound()).getSound();

View File

@ -35,11 +35,11 @@ public class Musket extends UntargetedWeapon {
durItem.decreaseDurability(1).update();
double attackDamage = stats.getStat(ItemStats.ATTACK_DAMAGE);
double range = getValue(getNBTItem().getStat(ItemStats.RANGE), MMOItems.plugin.getConfig().getDouble("default.range"));
double recoil = getValue(getNBTItem().getStat(ItemStats.RECOIL), MMOItems.plugin.getConfig().getDouble("default.recoil"));
double range = getValue(getNBTItem().getStat(ItemStats.RANGE.getId()), MMOItems.plugin.getConfig().getDouble("default.range"));
double recoil = getValue(getNBTItem().getStat(ItemStats.RECOIL.getId()), MMOItems.plugin.getConfig().getDouble("default.recoil"));
// knockback
double knockback = getNBTItem().getStat(ItemStats.KNOCKBACK);
double knockback = getNBTItem().getStat(ItemStats.KNOCKBACK.getId());
if (knockback > 0)
getPlayer().setVelocity(getPlayer().getVelocity().add(getPlayer().getEyeLocation().getDirection().setY(0).normalize().multiply(-1 * knockback).setY(-.2)));

View File

@ -40,7 +40,7 @@ public class Staff extends UntargetedWeapon {
durItem.decreaseDurability(1).update();
double attackDamage = getValue(stats.getStat(ItemStats.ATTACK_DAMAGE), 1);
double range = getValue(getNBTItem().getStat(ItemStats.RANGE), MMOItems.plugin.getConfig().getDouble("default.range"));
double range = getValue(getNBTItem().getStat(ItemStats.RANGE.getId()), MMOItems.plugin.getConfig().getDouble("default.range"));
StaffSpirit spirit = StaffSpirit.get(getNBTItem());
if (spirit != null) {

View File

@ -36,7 +36,7 @@ public class Whip extends UntargetedWeapon {
durItem.decreaseDurability(1).update();
double attackDamage = getValue(stats.getStat(ItemStats.ATTACK_DAMAGE), 1);
double range = getValue(getNBTItem().getStat(ItemStats.RANGE), MMOItems.plugin.getConfig().getDouble("default.range"));
double range = getValue(getNBTItem().getStat(ItemStats.RANGE.getId()), MMOItems.plugin.getConfig().getDouble("default.range"));
double a = Math.toRadians(getPlayer().getEyeLocation().getYaw() + 160);
Location loc = getPlayer().getEyeLocation().add(new Vector(Math.cos(a), 0, Math.sin(a)).multiply(.5));

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.api.item.mmoitem;
import net.Indyuce.mmoitems.api.Type;
import net.mmogroup.mmolib.api.item.NBTItem;
public abstract class ReadMMOItem extends MMOItem {
@ -13,7 +14,7 @@ public abstract class ReadMMOItem extends MMOItem {
* The NBTItem being read to generate an MMOItem
*/
public ReadMMOItem(NBTItem item) {
super(item.getType(), item.getString("MMOITEMS_ITEM_ID"));
super(Type.get(item.getType()), item.getString("MMOITEMS_ITEM_ID"));
this.item = item;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
package net.Indyuce.mmoitems.api.util.message;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmoitems.MMOItems;
import net.mmogroup.mmolib.MMOLib;

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmoitems.command.item;
import net.Indyuce.mmoitems.api.Type;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -33,7 +34,7 @@ public class UnidentifyCommandTreeNode extends CommandTreeNode {
return CommandResult.FAILURE;
}
player.getInventory().setItemInMainHand(item.getType().getUnidentifiedTemplate().newBuilder(item).build());
player.getInventory().setItemInMainHand(Type.get(item.getType()).getUnidentifiedTemplate().newBuilder(item).build());
sender.sendMessage(MMOItems.plugin.getPrefix() + "Successfully unidentified the item you are holding.");
return CommandResult.SUCCESS;
}

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.comp.inventory;
import java.util.ArrayList;
import java.util.List;
import net.Indyuce.mmoitems.api.Type;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
@ -34,7 +35,7 @@ public class OrnamentPlayerInventory implements PlayerInventory, Listener {
for (ItemStack item : player.getInventory().getContents()) {
NBTItem nbtItem;
if (item != null && (nbtItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item)).hasType() && nbtItem.getType().getEquipmentType() == EquipmentSlot.ANY)
if (item != null && (nbtItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item)).hasType() && Type.get(nbtItem.getType()).getEquipmentType() == EquipmentSlot.ANY)
list.add(new EquippedItem(nbtItem, EquipmentSlot.ANY));
}
@ -45,7 +46,7 @@ public class OrnamentPlayerInventory implements PlayerInventory, Listener {
public void a(EntityPickupItemEvent event) {
if (event.getEntityType() == EntityType.PLAYER) {
NBTItem nbt = NBTItem.get(event.getItem().getItemStack());
if (nbt.hasType() && nbt.getType().getEquipmentType() == EquipmentSlot.ANY)
if (nbt.hasType() && Type.get(nbt.getType()).getEquipmentType() == EquipmentSlot.ANY)
PlayerData.get((Player) event.getEntity()).updateInventory();
}
}
@ -53,7 +54,7 @@ public class OrnamentPlayerInventory implements PlayerInventory, Listener {
@EventHandler(ignoreCancelled = true)
public void b(PlayerDropItemEvent event) {
NBTItem nbt = NBTItem.get(event.getItemDrop().getItemStack());
if (nbt.hasType() && nbt.getType().getEquipmentType() == EquipmentSlot.ANY)
if (nbt.hasType() && Type.get(nbt.getType()).getEquipmentType() == EquipmentSlot.ANY)
PlayerData.get(event.getPlayer()).updateInventory();
}
}

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.comp.inventory;
import java.util.ArrayList;
import java.util.List;
import net.Indyuce.mmoitems.api.Type;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -48,7 +49,7 @@ public class RPGInventoryHook implements PlayerInventory, Listener {
if (ornaments)
for (ItemStack item : player.getInventory().getContents()) {
NBTItem nbtItem;
if (item != null && (nbtItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item)).hasType() && nbtItem.getType().getEquipmentType() == EquipmentSlot.ANY)
if (item != null && (nbtItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item)).hasType() && Type.get(nbtItem.getType()).getEquipmentType() == EquipmentSlot.ANY)
list.add(new EquippedItem(nbtItem, EquipmentSlot.ANY));
}

View File

@ -17,12 +17,8 @@ import net.Indyuce.mmoitems.comp.mmocore.stat.Required_Attribute;
import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
public class MMOCoreHook implements RPGHandler, Listener {
/*
* called when MMOItems enables
*/
/* called when MMOItems enables */
public MMOCoreHook() {
/*
* only works when the server is reloaded. needs /reload when changing
* attributes or professions to refresh MMOItems stats
@ -63,7 +59,7 @@ public class MMOCoreHook implements RPGHandler, Listener {
public MMOCoreRPGPlayer(net.Indyuce.mmoitems.api.player.PlayerData playerData) {
super(playerData);
data = playerData.getMMOPlayerData().getMMOCore();
data = PlayerData.get(playerData.getUniqueId());
}
public PlayerData getData() {

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmoitems.comp.mmocore.load;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.player.PlayerData;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
@ -32,7 +33,7 @@ public class ItemTemplateDropItem extends ItemGenerationDropItem {
@Override
public void collect(LootBuilder builder) {
RPGPlayer rpgPlayer = builder.getEntity().getMMOPlayerData().getMMOItems().getRPG();
RPGPlayer rpgPlayer = PlayerData.get(builder.getEntity().getUniqueId()).getRPG();
MMOItem mmoitem = rollMMOItem(template, rpgPlayer);
if (rollSoulbound())

View File

@ -1,8 +1,5 @@
package net.Indyuce.mmoitems.comp.mmocore.load;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmoitems.MMOItems;
@ -10,6 +7,8 @@ import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.api.util.SmartGive;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
public class MMOItemTrigger extends Trigger {
private final MMOItemTemplate template;
@ -33,7 +32,7 @@ public class MMOItemTrigger extends Trigger {
@Override
public void apply(PlayerData player) {
ItemStack item = template.newBuilder(player.getMMOPlayerData().getMMOItems().getRPG()).build().newBuilder().build();
ItemStack item = template.newBuilder(net.Indyuce.mmoitems.api.player.PlayerData.get(player.getUniqueId()).getRPG()).build().newBuilder().build();
item.setAmount(amount);
new SmartGive(player.getPlayer()).give(item);
}

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmoitems.comp.mmocore.load;
import java.util.Optional;
import net.Indyuce.mmoitems.ItemStats;
import net.Indyuce.mmoitems.api.player.PlayerData;
import org.apache.commons.lang.Validate;
import org.bukkit.inventory.ItemStack;
@ -41,7 +42,7 @@ public class RandomItemDropItem extends ItemGenerationDropItem {
@Override
public void collect(LootBuilder builder) {
RPGPlayer rpgPlayer = builder.getEntity().getMMOPlayerData().getMMOItems().getRPG();
RPGPlayer rpgPlayer = PlayerData.get(builder.getEntity().getUniqueId()).getRPG();
TemplateExplorer explorer = new TemplateExplorer();
if (matchClass)

View File

@ -24,7 +24,7 @@ public class Required_Attribute extends DoubleStat implements ItemRestriction, G
@Override
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
MMOCoreRPGPlayer mmocore = (MMOCoreRPGPlayer) player;
if (mmocore.getData().getAttributes().getAttribute(attribute) < item.getStat(this)) {
if (mmocore.getData().getAttributes().getAttribute(attribute) < item.getStat(getId())) {
if (message) {
new AddonMessage("not-enough-attribute").format(ChatColor.RED, "#attribute#", attribute.getName()).send(player.getPlayer(), "cant-use-item");
player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f);

View File

@ -24,7 +24,7 @@ public class Required_Profession extends DoubleStat implements ItemRestriction,
@Override
public boolean canUse(RPGPlayer player, NBTItem item, boolean message) {
MMOCoreHook.MMOCoreRPGPlayer mmocore = (MMOCoreHook.MMOCoreRPGPlayer) player;
if (mmocore.getData().getCollectionSkills().getLevel(this.profession) < item.getStat(this)) {
if (mmocore.getData().getCollectionSkills().getLevel(this.profession) < item.getStat(getId())) {
if (message) {
new AddonMessage("not-enough-profession").format(ChatColor.RED, "#profession#", profession.getName()).send(player.getPlayer(), "cant-use-item");
player.getPlayer().playSound(player.getPlayer().getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1.5f);

View File

@ -131,7 +131,7 @@ public class ItemUse implements Listener {
NBTItem offhandItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(player.getInventory().getItemInOffHand());
ItemAttackResult result = new ItemAttackResult(event.getDamage(), DamageType.WEAPON, DamageType.PHYSICAL);
if (item.hasType() && item.getType() != Type.BLOCK) {
if (item.hasType() && Type.get(item.getType()) != Type.BLOCK) {
Weapon weapon = new Weapon(playerData, item);
if (weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) {
@ -150,7 +150,7 @@ public class ItemUse implements Listener {
return;
}
}
if (offhandItem.hasType() && item.getType() != Type.BLOCK) {
if (offhandItem.hasType() && Type.get(item.getType()) != Type.BLOCK) {
Weapon weapon = new Weapon(playerData, offhandItem);
if (weapon.getMMOItem().getType().getItemSet() == TypeSet.RANGE) {
@ -239,7 +239,7 @@ public class ItemUse implements Listener {
if (!picked.hasType())
return;
ItemSkin.ApplyResult result = ((ItemSkin) useItem).applyOntoItem(picked, picked.getType());
ItemSkin.ApplyResult result = ((ItemSkin) useItem).applyOntoItem(picked, Type.get(picked.getType()));
if (result.getType() == ItemSkin.ResultType.NONE)
return;
@ -257,7 +257,7 @@ public class ItemUse implements Listener {
if (!picked.hasType())
return;
GemStone.ApplyResult result = ((GemStone) useItem).applyOntoItem(picked, picked.getType());
GemStone.ApplyResult result = ((GemStone) useItem).applyOntoItem(picked, Type.get(picked.getType()));
if (result.getType() == GemStone.ResultType.NONE)
return;
@ -283,7 +283,7 @@ public class ItemUse implements Listener {
return;
NBTItem item = MMOLib.plugin.getVersion().getWrapper().getNBTItem(event.getBow());
Type type = item.getType();
Type type = Type.get(item.getType());
PlayerData playerData = PlayerData.get((Player) event.getEntity());
if (type != null)
@ -293,8 +293,8 @@ public class ItemUse implements Listener {
}
Arrow arrow = (Arrow) event.getProjectile();
if (!(item.getStat(ItemStats.ARROW_VELOCITY) <= 0))
arrow.setVelocity(arrow.getVelocity().multiply(1 + (item.getStat(ItemStats.ARROW_VELOCITY) / 2)));
if (!(item.getStat(ItemStats.ARROW_VELOCITY.getId()) <= 0))
arrow.setVelocity(arrow.getVelocity().multiply(1 + (item.getStat(ItemStats.ARROW_VELOCITY.getId()) / 2)));
MMOItems.plugin.getEntities().registerCustomProjectile(item, playerData.getStats().newTemporary(), event.getProjectile(),
type != null, event.getForce());
}
@ -324,7 +324,7 @@ public class ItemUse implements Listener {
return;
}
useItem.getPlayerData().applyItemCooldown(useItem.getMMOItem().getId(), useItem.getNBTItem().getStat(ItemStats.ITEM_COOLDOWN));
useItem.getPlayerData().applyItemCooldown(useItem.getMMOItem().getId(), useItem.getNBTItem().getStat(ItemStats.ITEM_COOLDOWN.getId()));
useItem.executeCommands();
}
}

View File

@ -0,0 +1,115 @@
package net.Indyuce.mmoitems.listener;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
public class LootsplosionListener implements Listener {
private static final Random random = new Random();
private final boolean colored;
public LootsplosionListener() {
colored = Bukkit.getPluginManager().getPlugin("MMOItems") != null
&& MMOItems.plugin.getConfig().getBoolean("lootsplosion.show-color");
}
@EventHandler(priority = EventPriority.HIGH)
public void b(MythicMobDeathEvent event) {
if (event.getMob().getVariables().has("Lootsplosion"))
new LootsplosionHandler(event);
}
public class LootsplosionHandler implements Listener {
private final List<ItemStack> drops;
/*
* Y coordinate offset so the velocity is not directly negated when the
* item spawns on the ground
*/
private final double offset;
public LootsplosionHandler(MythicMobDeathEvent event) {
offset = event.getEntity().getHeight() / 2;
drops = new ArrayList<>(event.getDrops());
Bukkit.getPluginManager().registerEvents(this, MMOItems.plugin);
}
private void close() {
ItemSpawnEvent.getHandlerList().unregister(this);
}
@EventHandler
public void a(ItemSpawnEvent event) {
Item item = event.getEntity();
if (!drops.contains(item.getItemStack())) {
close();
return;
}
drops.remove(item.getItemStack());
item.teleport(item.getLocation().add(0, offset, 0));
item.setVelocity(randomVector());
if (colored)
Bukkit.getScheduler().runTask(MMOItems.plugin, () -> {
NBTItem nbt = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item.getItemStack());
if (nbt.hasTag("MMOITEMS_TIER")) {
ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER"));
if (tier.hasColor())
new LootColor(item, tier.getColor().toBukkit());
}
});
}
}
private Vector randomVector() {
double offset = MMOItems.plugin.getConfig().getDouble("lootsplosion.offset"),
height = MMOItems.plugin.getConfig().getDouble("lootsplosion.height");
return new Vector(Math.cos(random.nextDouble() * Math.PI * 2) * offset, height, Math.sin(random.nextDouble() * Math.PI * 2) * offset);
}
public static class LootColor extends BukkitRunnable {
private final Item item;
private final Color color;
private int j = 0;
public LootColor(Item item, Color color) {
this.item = item;
this.color = color;
runTaskTimer(MMOItems.plugin, 0, 1);
}
@Override
public void run() {
if (j++ > 100 || item.isDead() || item.isOnGround()) {
cancel();
return;
}
item.getWorld().spawnParticle(Particle.REDSTONE, item.getLocation(), 1, new Particle.DustOptions(color, 1.3f));
}
}
}

View File

@ -120,7 +120,7 @@ public class PlayerListener implements Listener {
return;
NBTItem nbtItem = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item.getItem());
Type type = nbtItem.getType();
Type type = Type.get(nbtItem.getType());
PlayerData playerData = PlayerData.get((Player) event.getEntity().getShooter());
if (type != null && !new Weapon(playerData, nbtItem).canBeUsed()) {

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmoitems.manager;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ConfigFile;
@ -270,7 +269,7 @@ public class ConfigManager implements Reloadable {
File folder = new File(MMOItems.plugin.getDataFolder() + "/" + path);
if (!folder.exists())
if(!folder.mkdir())
MMOCore.log(Level.WARNING, "Could not create directory!");
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not create directory!");
}
/*

View File

@ -39,7 +39,7 @@ public class TemplateManager implements Reloadable {
}
public boolean hasTemplate(NBTItem nbt) {
return hasTemplate(nbt.getType(), nbt.getString("MMOITEMS_ITEM_ID"));
return hasTemplate(Type.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID"));
}
public MMOItemTemplate getTemplate(Type type, String id) {
@ -47,7 +47,7 @@ public class TemplateManager implements Reloadable {
}
public MMOItemTemplate getTemplate(NBTItem nbt) {
return getTemplate(nbt.getType(), nbt.getString("MMOITEMS_ITEM_ID"));
return getTemplate(Type.get(nbt.getType()), nbt.getString("MMOITEMS_ITEM_ID"));
}
/**

View File

@ -3,7 +3,6 @@ package net.Indyuce.mmoitems.manager;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate;
import net.Indyuce.mmoitems.api.player.PlayerData;
import net.mmogroup.mmolib.MMOLib;
@ -44,12 +43,10 @@ public class UpdaterManager implements Listener {
@EventHandler
public void updateOnClick(InventoryClickEvent event) {
ItemStack item = event.getCurrentItem();
if (item == null || item.getType() == Material.AIR)
return;
if (item == null || item.getType() == Material.AIR) return;
ItemStack newItem = getUpdated(item, (Player) event.getWhoClicked());
if (!newItem.equals(item))
event.setCurrentItem(newItem);
if (!newItem.equals(item)) event.setCurrentItem(newItem);
}
/**
@ -79,9 +76,8 @@ public class UpdaterManager implements Listener {
* If the item type is null, then it is not an mmoitem and it does not
* need to be updated
*/
Type type = item.getType();
if (type == null)
return item.getItem();
Type type = Type.get(item.getType());
if (type == null) return item.getItem();
/*
* check the internal UUID of the item, if it does not make the one
@ -100,7 +96,7 @@ public class UpdaterManager implements Listener {
* apply older gem stones, using a light MMOItem so the item does not
* calculate every stat data from the older item.
*/
MMOItem volatileItem = new VolatileMMOItem(item);
//MMOItem volatileItem = new VolatileMMOItem(item);
/*if (did.hasOption(KeepOption.KEEP_GEMS) && volatileItem.hasData(ItemStats.GEM_SOCKETS))
newMMOItem.replaceData(ItemStats.GEM_SOCKETS, volatileItem.getData(ItemStats.GEM_SOCKETS));
@ -122,19 +118,18 @@ public class UpdaterManager implements Listener {
* removed!
*/
//if (did.hasOption(KeepOption.KEEP_ENCHANTS))
item.getItem().getItemMeta().getEnchants().forEach((enchant, level) -> newItemMeta.addEnchant(enchant, level, true));
item.getItem().getItemMeta().getEnchants().forEach((enchant, level) -> newItemMeta.addEnchant(enchant, level, true));
/*
* keepLore is used to save enchants from custom enchants plugins that
* only use lore to save enchant data
*/
//if (did.hasOption(KeepOption.KEEP_LORE)) {
int n = 0;
for (String s : item.getItem().getItemMeta().getLore()) {
if (!s.startsWith(ChatColor.GRAY + ""))
break;
lore.add(n++, s);
}
int n = 0;
for (String s : item.getItem().getItemMeta().getLore()) {
if (!s.startsWith(ChatColor.GRAY + "")) break;
lore.add(n++, s);
}
//}
/*
@ -142,14 +137,14 @@ public class UpdaterManager implements Listener {
* users do not get extra durability when the item is updated
*/
//if (did.hasOption(KeepOption.KEEP_DURABILITY) && item.getItem().getItemMeta() instanceof Damageable && newItemMeta instanceof Damageable)
((Damageable) newItemMeta).setDamage(((Damageable) item.getItem().getItemMeta()).getDamage());
((Damageable) newItemMeta).setDamage(((Damageable) item.getItem().getItemMeta()).getDamage());
/*
* keep name so players who renamed the item in the anvil does not have
* to rename it again
*/
//if (did.hasOption(KeepOption.KEEP_NAME) && item.getItem().getItemMeta().hasDisplayName())
newItemMeta.setDisplayName(item.getItem().getItemMeta().getDisplayName());
newItemMeta.setDisplayName(item.getItem().getItemMeta().getDisplayName());
newItemMeta.setLore(lore);
newItem.setItemMeta(newItemMeta);
@ -157,8 +152,7 @@ public class UpdaterManager implements Listener {
}
public enum KeepOption {
KEEP_LORE("Any lore line starting with '&7' will be", "kept when updating your item.", "", "This option is supposed to keep",
"the item custom enchants.", ChatColor.RED + "May not support every enchant plugin."),
KEEP_LORE("Any lore line starting with '&7' will be", "kept when updating your item.", "", "This option is supposed to keep", "the item custom enchants.", ChatColor.RED + "May not support every enchant plugin."),
KEEP_ENCHANTS("The item keeps its old enchantments."),
KEEP_DURABILITY("The item keeps its durability.", "Don't use this option if you", "are using texture-by-durability!"),
KEEP_NAME("The item keeps its display name."),

View File

@ -8,7 +8,7 @@
# a Spigot Plugin by Team Requiem
# DO NOT TOUCH
config-version: 4
config-version: 5
# Notifies players with the 'mmoitems.update-notify' perm node when
# they join the server if a new update is available for download.
@ -275,6 +275,15 @@ item-revision:
click: false
join: false
# Offset is the distance traveled on X and Y coordinates
# Height is the Y velocity coordinate. Lootsplosions
# only trigger with MythicMobs monsters.
# Requires a SERVER reload when changed.
lootsplosion:
enabled: true
color: true
offset: .2
height: .6
# When I was a kid, I saw the Mona Lisa in my school art book...
# The fist time I saw her, with her hands on her knee... how do I say this...