Merge remote-tracking branch 'origin/master'

# Conflicts:
#	pom.xml
This commit is contained in:
Jules 2022-03-22 19:59:27 +01:00
commit d8517eb94e
131 changed files with 2212 additions and 1746 deletions

18
MMOCore (1).iml Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="MavenCustomPomFilePath">
<option name="mavenPomFileUrl" value="file://$MODULE_DIR$/dependency-reduced-pom.xml" />
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$/src/main/java">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
</content>
<content url="file://$MODULE_DIR$/src/main/resources">
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.9.1</version>
<version>1.9.2</version>
<name>MMOCore</name>
<description>Offer your players a brand new RPG experience!!</description>
@ -140,14 +140,14 @@
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicLib-dist</artifactId>
<version>1.3</version>
<version>1.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.lumine</groupId>
<artifactId>MythicMobs-Dist</artifactId>
<version>5.0.0-SNAPSHOT</version>
<artifactId>Mythic-Dist</artifactId>
<version>5.0.1</version>
<scope>provided</scope>
</dependency>

View File

@ -45,9 +45,6 @@ import net.Indyuce.mmocore.party.PartyModule;
import net.Indyuce.mmocore.party.PartyModuleType;
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
import net.Indyuce.mmocore.skill.list.Ambers;
import net.Indyuce.mmocore.skill.list.Neptune_Gift;
import net.Indyuce.mmocore.skill.list.Sneaky_Picky;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -64,11 +61,10 @@ import java.util.logging.Level;
public class MMOCore extends LuminePlugin {
public static MMOCore plugin;
public ConfigManager configManager;
public WaypointManager waypointManager;
public SoundManager soundManager;
public RequestManager requestManager;
public ConfigItemManager configItems;
public final WaypointManager waypointManager = new WaypointManager();
public final SoundManager soundManager = new SoundManager();
public final RequestManager requestManager = new RequestManager();
public final ConfigItemManager configItems = new ConfigItemManager();
public final PlayerActionBar actionBarManager = new PlayerActionBar();
public final SkillManager skillManager = new SkillManager();
public final ClassManager classManager = new ClassManager();
@ -82,7 +78,18 @@ public class MMOCore extends LuminePlugin {
public final LootChestManager lootChests = new LootChestManager();
public final MMOLoadManager loadManager = new MMOLoadManager();
public final RestrictionManager restrictionManager = new RestrictionManager();
@Deprecated
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
// Profession managers
public final CustomBlockManager mineManager = new CustomBlockManager();
public final FishingManager fishingManager = new FishingManager();
public final AlchemyManager alchemyManager = new AlchemyManager();
public final EnchantManager enchantManager = new EnchantManager();
public final SmithingManager smithingManager = new SmithingManager();
@NotNull
public ConfigManager configManager;
public VaultEconomy economy;
public RegionHandler regionHandler = new DefaultRegionHandler();
public PlaceholderParser placeholderParser = new DefaultParser();
@ -92,13 +99,6 @@ public class MMOCore extends LuminePlugin {
@NotNull
public PartyModule partyModule;
// Profession managers
public final CustomBlockManager mineManager = new CustomBlockManager();
public final FishingManager fishingManager = new FishingManager();
public final AlchemyManager alchemyManager = new AlchemyManager();
public final EnchantManager enchantManager = new EnchantManager();
public final SmithingManager smithingManager = new SmithingManager();
public boolean shouldDebugSQL = false;
private static final int MYTHICLIB_COMPATIBILITY_INDEX = 7;
@ -130,11 +130,6 @@ public class MMOCore extends LuminePlugin {
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
loadManager.registerLoader(new MythicMobsMMOLoader());
// Register MMOCore specific skills
MythicLib.plugin.getSkills().registerSkillHandler(new Ambers());
MythicLib.plugin.getSkills().registerSkillHandler(new Neptune_Gift());
MythicLib.plugin.getSkills().registerSkillHandler(new Sneaky_Picky());
}
public void enable() {
@ -388,7 +383,8 @@ public class MMOCore extends LuminePlugin {
* @param clearBefore True when issuing a plugin reload
*/
public void initializePlugin(boolean clearBefore) {
reloadConfig();
if (clearBefore)
reloadConfig();
configManager = new ConfigManager();
@ -413,16 +409,18 @@ public class MMOCore extends LuminePlugin {
questManager.initialize(clearBefore);
lootChests.initialize(clearBefore);
restrictionManager.initialize(clearBefore);
waypointManager = new WaypointManager(new ConfigFile("waypoints").getConfig());
requestManager = new RequestManager();
soundManager = new SoundManager(new ConfigFile("sounds").getConfig());
configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
waypointManager.initialize(clearBefore);
requestManager.initialize(clearBefore);
soundManager.initialize(clearBefore);
configItems.initialize(clearBefore);
if (getConfig().isConfigurationSection("action-bar"))
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
StatType.load();
if (clearBefore)
PlayerData.getAll().forEach(PlayerData::update);
}
public static void log(String message) {

View File

@ -2,12 +2,9 @@ package net.Indyuce.mmocore.api;
import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.PlayerMetadata;
import io.lumine.mythic.lib.skill.SimpleSkill;
import io.lumine.mythic.lib.skill.Skill;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import io.lumine.mythic.lib.skill.result.SkillResult;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.party.AbstractParty;
@ -18,6 +15,8 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public class MMOCoreAPI {
private final JavaPlugin plugin;
@ -87,7 +86,7 @@ public class MMOCoreAPI {
public SkillResult cast(PlayerData playerData, RegisteredSkill skill, int level) {
PlayerMetadata casterMeta = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
TriggerMetadata triggerMeta = new TriggerMetadata(casterMeta, null, null);
return new CastableSkill(new ClassSkill(skill, 0), level).cast(triggerMeta);
return new CastableSkill(new ClassSkill(skill, 0, 0), level).cast(triggerMeta);
}
/**
@ -110,8 +109,7 @@ public class MMOCoreAPI {
public SkillResult cast(PlayerData playerData, SkillHandler<?> skill, int level) {
PlayerMetadata casterMeta = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
TriggerMetadata triggerMeta = new TriggerMetadata(casterMeta, null, null);
RegisteredSkill registered = MMOCore.plugin.skillManager.getSkill(skill.getId());
Skill cast = registered == null ? new SimpleSkill(TriggerType.CAST, skill) : new CastableSkill(new ClassSkill(registered, 0), level);
return cast.cast(triggerMeta);
RegisteredSkill registered = Objects.requireNonNull(MMOCore.plugin.skillManager.getSkill(skill.getId()), "Could not find registered skill with such handler");
return new CastableSkill(new ClassSkill(registered, 0, 0), level).cast(triggerMeta);
}
}

View File

@ -1,91 +0,0 @@
package net.Indyuce.mmocore.api;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class Waypoint {
private final String id, name;
private final Location loc;
private final double radiusSquared, stellium;
private final boolean def, sneak, dynamic;
public Waypoint(ConfigurationSection section) {
Validate.notNull(section, "Could not load config section");
id = section.getName();
name = section.getString("name");
Validate.notNull(name, "Could not load waypoint name");
String format = section.getString("location");
Validate.notNull(format, "Could not read location");
loc = readLocation(format);
stellium = section.getDouble("stellium");
radiusSquared = Math.pow(section.getDouble("radius"), 2);
def = section.getBoolean("default");
sneak = !section.contains("sneak") || section.getBoolean("sneak");
dynamic = section.getBoolean("dynamic");
}
public Location getLocation() {
return loc;
}
public String getName() {
return name;
}
public double getStelliumCost() {
return stellium;
}
public boolean hasSneakEnabled() {
return sneak;
}
public String getId() {
return id;
}
public boolean isDefault() {
return def;
}
public boolean isDynamic() {
return dynamic;
}
public boolean isOnWaypoint(Player player) {
return player.getWorld().equals(loc.getWorld()) && player.getLocation().distanceSquared(loc) < radiusSquared;
}
@Override
public String toString() {
return id;
}
@Override
public boolean equals(Object object) {
return object instanceof Waypoint && ((Waypoint) object).id.equals(id);
}
private Location readLocation(String string) {
String[] split = string.split(" ");
World world = Bukkit.getWorld(split[0]);
Validate.notNull(world, "Could not find world with name '" + split[0]+"'");
double x = Double.parseDouble(split[1]);
double y = Double.parseDouble(split[2]);
double z = Double.parseDouble(split[3]);
float yaw = split.length > 4 ? (float) Double.parseDouble(split[4]) : 0;
float pitch = split.length > 5 ? (float) Double.parseDouble(split[5]) : 0;
return new Location(world, x, y, z, yaw, pitch);
}
}

View File

@ -17,7 +17,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
import net.Indyuce.mmocore.util.item.CurrencyItemBuilder;
import io.lumine.mythic.lib.api.util.SmartGive;
public class Withdraw implements Listener {
@ -101,9 +101,9 @@ public class Withdraw implements Listener {
SmartGive smart = new SmartGive(player);
if (note > 0)
smart.give(new CurrencyItem("NOTE", note).build());
smart.give(new CurrencyItemBuilder("NOTE", note).build());
ItemStack coinsItem = new CurrencyItem("GOLD_COIN", 1).build();
ItemStack coinsItem = new CurrencyItemBuilder("GOLD_COIN", 1).build();
coinsItem.setAmount(coins);
smart.give(coinsItem);
}

View File

@ -97,6 +97,11 @@ public class PlayerResourceUpdateEvent extends PlayerDataEvent implements Cancel
*/
SKILL_COST,
/**
* When consuming stellium to use a waypoint
*/
USE_WAYPOINT,
/**
* Used by quests triggers
* - {@link net.Indyuce.mmocore.api.quest.trigger.ManaTrigger}

View File

@ -1,6 +1,6 @@
package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.block.BlockType;
@ -14,7 +14,6 @@ import net.Indyuce.mmocore.loot.droptable.condition.WorldCondition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.MMDropTableDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem;
import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource;
@ -88,9 +87,6 @@ public class DefaultMMOLoader extends MMOLoader {
if (config.getKey().equals("gold") || config.getKey().equals("coin"))
return new GoldDropItem(config);
if (config.getKey().equals("mmdroptable"))
return new MMDropTableDropItem(config);
return null;
}

View File

@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.block.BlockType;
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;

View File

@ -1,12 +1,15 @@
package net.Indyuce.mmocore.api.player;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.player.MMOPlayerData;
import io.lumine.mythic.lib.player.TemporaryPlayerData;
import io.lumine.mythic.lib.player.cooldown.CooldownMap;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.player.Unlockable;
import net.Indyuce.mmocore.waypoint.CostType;
import net.Indyuce.mmocore.waypoint.Waypoint;
import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
@ -22,7 +25,7 @@ import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.Indyuce.mmocore.api.util.Closable;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.ExperienceTableClaimer;
@ -35,6 +38,7 @@ import net.Indyuce.mmocore.party.provided.Party;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
import net.Indyuce.mmocore.waypoint.WaypointOption;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.Validate;
@ -382,7 +386,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
}
public boolean hasWaypoint(Waypoint waypoint) {
return waypoint.isDefault() || waypoints.contains(waypoint.getId());
return waypoint.hasOption(WaypointOption.DEFAULT) || waypoints.contains(waypoint.getId());
}
public void unlockWaypoint(Waypoint waypoint) {
@ -455,9 +459,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
*
* @param waypoint Target waypoint
*/
public void warp(Waypoint waypoint) {
if (!isOnline())
return;
public void warp(Waypoint waypoint, CostType costType) {
/*
* This cooldown is only used internally to make sure the player is not
@ -466,7 +468,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
*/
setLastActivity(PlayerActivity.USE_WAYPOINT);
giveStellium(-waypoint.getStelliumCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_COST);
final double cost = waypoint.getCost(costType);
giveStellium(-cost, PlayerResourceUpdateEvent.UpdateReason.USE_WAYPOINT);
new BukkitRunnable() {
final int x = getPlayer().getLocation().getBlockX();
@ -481,7 +484,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|| getPlayer().getLocation().getBlockZ() != z) {
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_CANCELLED).playTo(getPlayer());
MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(getPlayer());
giveStellium(waypoint.getStelliumCost(), PlayerResourceUpdateEvent.UpdateReason.SKILL_REGENERATION);
giveStellium(cost, PlayerResourceUpdateEvent.UpdateReason.USE_WAYPOINT);
cancel();
return;
}
@ -534,10 +537,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return;
}
// Experience hologram
if (hologramLocation != null && isOnline())
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message());
value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat(StatType.ADDITIONAL_EXPERIENCE) / 100;
@ -555,6 +554,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
if (event.isCancelled())
return;
// Experience hologram
if (hologramLocation != null && isOnline())
MMOCoreUtils.displayIndicator(hologramLocation, MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", String.valueOf(event.getExperience())).message());
experience = Math.max(0, experience + event.getExperience());
// Calculate the player's next level

View File

@ -1,15 +0,0 @@
package net.Indyuce.mmocore.api.player;
/**
* Some item that can be unlocked
*
* @see {@link PlayerData#unlock(Unlockable)} and {@link PlayerData#hasUnlocked(Unlockable)}
*/
public interface Unlockable {
/**
* Format being used is the minecraft's default
* namespaced key format, e.g skill_tree:strength_1_5
*/
String getUnlockNamespacedKey();
}

View File

@ -14,12 +14,12 @@ import net.Indyuce.mmocore.api.player.profess.resource.ResourceRegeneration;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.api.util.math.particle.CastingParticle;
import net.Indyuce.mmocore.loot.chest.particle.CastingParticle;
import net.Indyuce.mmocore.experience.ExpCurve;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.provider.MainExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ClassExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.player.playerclass.ClassTrigger;
import net.Indyuce.mmocore.player.playerclass.ClassTriggerType;
@ -155,7 +155,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
}
if (config.contains("main-exp-sources")) {
ExperienceDispenser dispenser = new MainExperienceDispenser(this);
ExperienceDispenser dispenser = new ClassExperienceDispenser(this);
for (String key : config.getStringList("main-exp-sources"))
try {
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser);
@ -375,6 +375,7 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
return found == null ? Optional.empty() : Optional.of(found);
}
@Nullable
public ClassSkill getSkill(String id) {
return skills.get(id);
}

View File

@ -12,6 +12,10 @@ public class ManaDisplayOptions {
private final String name, icon;
private final char barCharacter;
public ChatColor getFull() { return full; }
public ChatColor getHalf() { return half; }
public ChatColor getEmpty() { return empty; }
public static final ManaDisplayOptions DEFAULT = new ManaDisplayOptions(ChatColor.AQUA, ChatColor.BLUE, ChatColor.WHITE, "Mana",
AltChar.listSquare.charAt(0), ChatColor.BLUE + AltChar.star2);

View File

@ -68,6 +68,7 @@ public enum StatType {
PROJECTILE_DAMAGE,
WEAPON_DAMAGE,
SKILL_DAMAGE,
UNARMED_DAMAGE,
UNDEAD_DAMAGE,
// Misc damage stats

View File

@ -1,19 +1,24 @@
package net.Indyuce.mmocore.api.quest.trigger;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.SimpleExperienceDispenser;
import org.apache.commons.lang.Validate;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.ExperienceInfo;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import io.lumine.mythic.lib.api.MMOLineConfig;
import org.jetbrains.annotations.NotNull;
public class ExperienceTrigger extends Trigger {
@NotNull
private final RandomAmount amount;
private final Profession profession;
@NotNull
private final EXPSource source;
@NotNull
private final ExperienceDispenser dispenser;
public ExperienceTrigger(MMOLineConfig config) {
super(config);
@ -23,26 +28,15 @@ public class ExperienceTrigger extends Trigger {
if (config.contains("profession")) {
String id = config.getString("profession").toLowerCase().replace("_", "-");
Validate.isTrue(MMOCore.plugin.professionManager.has(id), "Could not find profession");
profession = MMOCore.plugin.professionManager.get(id);
dispenser = new ProfessionExperienceDispenser(MMOCore.plugin.professionManager.get(id));
} else
profession = null;
dispenser = new SimpleExperienceDispenser();
amount = new RandomAmount(config.getString("amount"));
source = config.contains("source") ? EXPSource.valueOf(config.getString("source").toUpperCase()) : EXPSource.QUEST;
}
@Override
public void apply(PlayerData player) {
if (profession == null)
player.giveExperience(amount.calculateInt(), source);
else
player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), source);
}
/*
* experience must be accessible from the custom mine event. this method
* allows to generate an experience info instance for easy manipulations
*/
public ExperienceInfo newInfo() {
return new ExperienceInfo(amount.calculateInt(), profession);
dispenser.giveExperience(player, amount.calculateInt(), null, source);
}
}

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmocore.api.util;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
import io.lumine.mythic.utils.holograms.Hologram;
import io.lumine.mythic.utils.serialize.Position;
@ -66,6 +65,7 @@ public class MMOCoreUtils {
*/
public static void displayIndicator(Location loc, String message) {
Hologram holo = Hologram.create(Position.of(loc), Arrays.asList(message));
holo.spawn();
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> holo.despawn(), 20);
}
@ -184,8 +184,11 @@ public class MMOCoreUtils {
/**
* Method used when mining a custom block or fishing, as the corresponding
* interaction event is cancelled durability is not handled. This method is
* needed and actually calls a damage event so that MMOItems can listen to
* it
* needed and actually calls a damage event so that MMOItems can listen to it.
* <p>
* This method only supports item types which DO have a durability bar like
* fishing rods or pickaxes. This shouldn't cause any issue because you can
* only use fishing rods to fish and pickaxes to mine stuff.
*
* @param player Player holding the item with durability
* @param slot The slot of the item with durability
@ -193,26 +196,28 @@ public class MMOCoreUtils {
*/
public static void decreaseDurability(Player player, EquipmentSlot slot, int damage) {
ItemStack item = player.getInventory().getItem(slot);
NBTItem nbt = NBTItem.get(item);
if (!nbt.hasTag("MMOITEMS_MAX_DURABILITY")) {
if (!item.hasItemMeta() || !(item.getItemMeta() instanceof Damageable) || item.getItemMeta().isUnbreakable())
return;
}
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
if (!nbt.getBoolean("Unbreakable") && item.getItemMeta() instanceof Damageable) {
ItemMeta meta = item.getItemMeta();
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + damage);
ItemMeta meta = item.getItemMeta();
if (event.getDamage() + ((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
player.getInventory().setItem(slot, null);
} else {
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + event.getDamage());
item.setItemMeta(meta);
if (((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
player.getInventory().setItem(slot, null);
}
}
}
/**
* @return Center location of an entity using its bounding box
*/
public static Location getCenterLocation(Entity entity) {
return entity.getBoundingBox().getCenter().toLocation(entity.getWorld());
}
}

View File

@ -1,144 +0,0 @@
package net.Indyuce.mmocore.api.util.item;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmocore.MMOCore;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial;
public class ConfigItem {
private final String name, id, texture;
private final ItemStack item;
private final List<String> lore;
private final int damage, modeldata;
private boolean unbreakable;
private final Map<String, String> placeholders = new HashMap<>();
public ConfigItem(ConfigurationSection config) {
id = config.getName();
name = config.getString("name");
lore = config.getStringList("lore");
item = new ItemStack(Material.valueOf(config.getString("item")));
Validate.notNull(name, "Name cannot be null");
Validate.notNull(lore, "Lore can be empty but not null");
/*
* extra options
*/
damage = config.getInt("damage");
texture = config.getString("texture");
modeldata = config.getInt("custom-model-data");
}
public ConfigItem(String id) {
this(MMOCore.plugin.configItems.get(id));
}
public ConfigItem(ConfigItem cache) {
this.id = cache.id;
name = cache.name;
lore = cache.lore;
item = cache.item;
damage = cache.damage;
texture = cache.texture;
modeldata = cache.modeldata;
unbreakable = cache.unbreakable;
}
public ItemStack getItem(int amount) {
ItemStack item = this.item.clone();
item.setAmount(amount);
return item;
}
public List<String> getLore() {
return lore;
}
public String getName() {
return name;
}
public int getModelData() {
return modeldata;
}
public String getId() {
return id;
}
public ConfigItem setUnbreakable() {
unbreakable = true;
return this;
}
public ConfigItem addPlaceholders(String... placeholders) {
for (int j = 0; j < placeholders.length - 1; j += 2)
this.placeholders.put(placeholders[j], placeholders[j + 1]);
return this;
}
public ItemStack build() {
return build(1);
}
public ItemStack build(int amount) {
ItemStack item = getItem(amount);
ItemMeta meta = item.getItemMeta();
if (meta instanceof Damageable)
((Damageable) meta).setDamage(damage);
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(modeldata);
if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && texture != null)
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", texture));
profileField.set(meta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.log(Level.WARNING, "Could not load config item texture of " + id);
}
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(format(name));
List<String> lore = new ArrayList<>();
getLore().forEach(line -> lore.add(format(line)));
meta.setLore(lore);
item.setItemMeta(meta);
return unbreakable ? NBTItem.get(item).addTag(new ItemTag("Unbreakable", true)).toItem() : item;
}
protected String format(String string) {
for (String placeholder : placeholders.keySet())
if (string.contains("{" + placeholder + "}"))
string = string.replace("{" + placeholder + "}", "" + placeholders.get(placeholder));
return MythicLib.plugin.parseColors(string);
}
}

View File

@ -1,45 +0,0 @@
package net.Indyuce.mmocore.api.util.item;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
public class CurrencyItem extends ConfigItem {
private final int worth, amount;
public CurrencyItem(String key, int worth) {
this(key, worth, 1);
}
public CurrencyItem(String key, int worth, int amount) {
super(key);
addPlaceholders("worth", "" + (this.worth = worth));
this.amount = amount;
}
@Override
public ItemStack build() {
ItemStack item = getItem(amount);
ItemMeta meta = item.getItemMeta();
meta.addItemFlags(ItemFlag.values());
meta.setDisplayName(format(getName()));
List<String> lore = new ArrayList<>();
getLore().forEach(line -> lore.add(format(line)));
meta.setLore(lore);
if(MythicLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(getModelData());
item.setItemMeta(meta);
return NBTItem.get(item).addTag(new ItemTag("RpgWorth", worth)).toItem();
}
}

View File

@ -1,17 +0,0 @@
package net.Indyuce.mmocore.api.util.item;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import io.lumine.mythic.lib.MythicLib;
public class NamedItemStack extends ItemStack {
public NamedItemStack(Material material, String name) {
super(material);
ItemMeta meta = getItemMeta();
meta.setDisplayName(MythicLib.plugin.parseColors(name));
setItemMeta(meta);
}
}

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.command;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeRoot;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeRoot;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.command.rpg.CoinsCommandTreeNode;
import net.Indyuce.mmocore.command.rpg.NoteCommandTreeNode;

View File

@ -1,44 +1,47 @@
package net.Indyuce.mmocore.command.rpg;
import io.lumine.mythic.lib.api.util.SmartGive;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.util.item.CurrencyItemBuilder;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class CoinsCommandTreeNode extends CommandTreeNode {
public CoinsCommandTreeNode(CommandTreeNode parent) {
super(parent, "coins");
public CoinsCommandTreeNode(CommandTreeNode parent) {
super(parent, "coins");
addParameter(Parameter.PLAYER);
addParameter(Parameter.AMOUNT);
}
addParameter(Parameter.PLAYER);
addParameter(Parameter.AMOUNT);
}
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 3)
return CommandResult.THROW_USAGE;
@Override
public CommandResult execute(CommandSender sender, String[] args) {
if (args.length < 3)
return CommandResult.THROW_USAGE;
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[1] + ".");
return CommandResult.FAILURE;
}
Player player = Bukkit.getPlayer(args[1]);
if (player == null) {
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[1] + ".");
return CommandResult.FAILURE;
}
int amount;
try {
amount = Integer.parseInt(args[2]);
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number.");
return CommandResult.FAILURE;
}
int amount;
try {
amount = Integer.parseInt(args[2]);
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + args[2] + " is not a valid number.");
return CommandResult.FAILURE;
}
new SmartGive(player).give(new CurrencyItem("GOLD_COIN", 1, amount).build());
return CommandResult.SUCCESS;
}
ItemStack coins = new CurrencyItemBuilder("GOLD_COIN", 1).build();
coins.setAmount(amount);
new SmartGive(player).give(coins);
return CommandResult.SUCCESS;
}
}

View File

@ -7,10 +7,10 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
import net.Indyuce.mmocore.util.item.CurrencyItemBuilder;
import io.lumine.mythic.lib.api.util.SmartGive;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class NoteCommandTreeNode extends CommandTreeNode {
public NoteCommandTreeNode(CommandTreeNode parent) {
@ -40,7 +40,7 @@ public class NoteCommandTreeNode extends CommandTreeNode {
return CommandResult.FAILURE;
}
new SmartGive(player).give(new CurrencyItem("NOTE", worth).build());
new SmartGive(player).give(new CurrencyItemBuilder("NOTE", worth).build());
return CommandResult.SUCCESS;
}
}

View File

@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
public class ReloadCommandTreeNode extends CommandTreeNode {
public ReloadCommandTreeNode(CommandTreeNode parent) {
@ -18,15 +18,11 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
sender.sendMessage(ChatColor.YELLOW + "Reloading " + MMOCore.plugin.getName() + " " + MMOCore.plugin.getDescription().getVersion() + "...");
long ms = System.currentTimeMillis();
MMOCore.plugin.reloadConfig();
MMOCore.plugin.initializePlugin(true);
PlayerData.getAll().forEach(PlayerData::update);
ms = System.currentTimeMillis() - ms;
sender.sendMessage(ChatColor.YELLOW + MMOCore.plugin.getName() + " " + MMOCore.plugin.getDescription().getVersion() + " successfully reloaded.");
sender.sendMessage(ChatColor.YELLOW + "Time Taken: " + ChatColor.GOLD + ms + ChatColor.YELLOW + "ms (" + ChatColor.GOLD + (double) ms / 50 + ChatColor.YELLOW + " ticks)");
return CommandResult.SUCCESS;
}
}

View File

@ -1,6 +1,6 @@
package net.Indyuce.mmocore.command.rpg.admin;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import org.bukkit.command.CommandSender;

View File

@ -10,8 +10,8 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes.AttributeInstance;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class AttributeCommandTreeNode extends CommandTreeNode {
public AttributeCommandTreeNode(CommandTreeNode parent) {

View File

@ -12,8 +12,8 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.command.CommandVerbose;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class ClassCommandTreeNode extends CommandTreeNode {
public ClassCommandTreeNode(CommandTreeNode parent) {

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.command.rpg.admin;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.CommandVerbose;

View File

@ -9,8 +9,8 @@ import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class ForceClassCommandTreeNode extends CommandTreeNode {
public ForceClassCommandTreeNode(CommandTreeNode parent) {

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.command.rpg.admin;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Bukkit;

View File

@ -8,8 +8,8 @@ import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class InfoCommandTreeNode extends CommandTreeNode {
public InfoCommandTreeNode(CommandTreeNode parent) {

View File

@ -14,8 +14,8 @@ import net.Indyuce.mmocore.experience.PlayerProfessions;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class LevelCommandTreeNode extends CommandTreeNode {
public LevelCommandTreeNode(CommandTreeNode parent) {

View File

@ -7,8 +7,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class NoCooldownCommandTreeNode extends CommandTreeNode {
public NoCooldownCommandTreeNode(CommandTreeNode parent) {

View File

@ -10,8 +10,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class PointsCommandTreeNode extends CommandTreeNode {
private final String type;

View File

@ -10,8 +10,8 @@ import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes.AttributeInstance;
import net.Indyuce.mmocore.command.CommandVerbose;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class ResetCommandTreeNode extends CommandTreeNode {
public ResetCommandTreeNode(CommandTreeNode parent) {

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.command.rpg.admin;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.api.quest.trigger.ManaTrigger;

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.command.rpg.booster;
import org.bukkit.command.CommandSender;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
public class BoosterCommandTreeNode extends CommandTreeNode {
public BoosterCommandTreeNode(CommandTreeNode parent) {

View File

@ -12,8 +12,8 @@ import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.experience.Booster;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class CreateCommandTreeNode extends CommandTreeNode {
public CreateCommandTreeNode(CommandTreeNode parent) {

View File

@ -8,7 +8,7 @@ import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.Booster;
import net.Indyuce.mmocore.api.util.math.format.DelayFormat;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
public class ListCommandTreeNode extends CommandTreeNode {
public ListCommandTreeNode(CommandTreeNode parent) {

View File

@ -8,8 +8,8 @@ import org.bukkit.command.CommandSender;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.Booster;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class RemoveCommandTreeNode extends CommandTreeNode {
public RemoveCommandTreeNode(CommandTreeNode parent) {

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.command.rpg.debug;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
public class DebugCommandTreeNode extends CommandTreeNode {
public static final String commandPrefix = ChatColor.YELLOW + "[" + ChatColor.RED + "DEBUG" + ChatColor.GOLD + "] " + ChatColor.RESET;

View File

@ -2,8 +2,8 @@ package net.Indyuce.mmocore.command.rpg.debug;
import io.lumine.mythic.lib.api.stat.StatInstance;
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import org.bukkit.ChatColor;

View File

@ -6,8 +6,8 @@ import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class StatValueCommandTreeNode extends CommandTreeNode {
public StatValueCommandTreeNode(CommandTreeNode parent) {

View File

@ -7,8 +7,8 @@ import org.bukkit.entity.Player;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class CancelCommandTreeNode extends CommandTreeNode {
public CancelCommandTreeNode(CommandTreeNode parent) {

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.command.rpg.quest;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import org.bukkit.Bukkit;

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.command.rpg.quest;
import org.bukkit.command.CommandSender;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
public class QuestCommandTreeNode extends CommandTreeNode {

View File

@ -10,8 +10,8 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.Indyuce.mmocore.api.quest.Quest;
import net.Indyuce.mmocore.command.MMOCoreCommandTreeRoot;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class StartCommandTreeNode extends CommandTreeNode {
public StartCommandTreeNode(CommandTreeNode parent) {

View File

@ -6,8 +6,8 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.manager.InventoryManager;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class OpenCommandTreeNode extends CommandTreeNode {
public OpenCommandTreeNode(CommandTreeNode parent) {

View File

@ -1,9 +1,9 @@
package net.Indyuce.mmocore.command.rpg.waypoint;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.waypoint.Waypoint;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;

View File

@ -6,10 +6,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.waypoint.Waypoint;
import net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.commands.mmolib.api.Parameter;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
public class UnlockCommandTreeNode extends CommandTreeNode {
public UnlockCommandTreeNode(CommandTreeNode parent) {

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.command.rpg.waypoint;
import org.bukkit.command.CommandSender;
import io.lumine.mythic.lib.commands.mmolib.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
public class WaypointsCommandTreeNode extends CommandTreeNode {
public WaypointsCommandTreeNode(CommandTreeNode parent) {

View File

@ -1,24 +1,19 @@
package net.Indyuce.mmocore.comp.mythicmobs;
import io.lumine.xikage.mythicmobs.MythicMobs;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicReloadedEvent;
import io.lumine.xikage.mythicmobs.skills.placeholders.Placeholder;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.bukkit.events.MythicDropLoadEvent;
import io.lumine.mythic.bukkit.events.MythicReloadedEvent;
import io.lumine.mythic.core.skills.placeholders.Placeholder;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.comp.mythicmobs.load.CurrencyItemDrop;
import net.Indyuce.mmocore.comp.mythicmobs.load.GoldPouchDrop;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import org.apache.commons.lang.Validate;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import java.util.Optional;
import java.util.logging.Level;
public class MythicHook implements Listener {
public MythicHook() {
registerPlaceholders();
@ -46,25 +41,25 @@ public class MythicHook implements Listener {
// When MM is reloaded, reload placeholders because they are no longer registered
registerPlaceholders();
// Reload skills
MMOCore.plugin.skillManager.initialize(true);
// Reload every god damn thing
MMOCore.plugin.initializePlugin(true);
}
private void registerPlaceholders() {
// Resource
MythicMobs.inst().getPlaceholderManager().register("mana", Placeholder.meta((metadata, arg) -> {
MythicBukkit.inst().getPlaceholderManager().register("mana", Placeholder.meta((metadata, arg) -> {
return String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getMana());
}));
MythicMobs.inst().getPlaceholderManager().register("stamina", Placeholder.meta((metadata, arg) -> {
MythicBukkit.inst().getPlaceholderManager().register("stamina", Placeholder.meta((metadata, arg) -> {
return String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getStamina());
}));
MythicMobs.inst().getPlaceholderManager().register("stellium", Placeholder.meta((metadata, arg) -> {
MythicBukkit.inst().getPlaceholderManager().register("stellium", Placeholder.meta((metadata, arg) -> {
return String.valueOf((int) PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getStellium());
}));
// Attributes
MythicMobs.inst().getPlaceholderManager().register("attribute", Placeholder.meta((metadata, arg) -> {
MythicBukkit.inst().getPlaceholderManager().register("attribute", Placeholder.meta((metadata, arg) -> {
PlayerAttributes attributes = PlayerData.get(metadata.getCaster().getEntity().getUniqueId()).getAttributes();
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(arg);
return String.valueOf(attributes.getAttribute(attribute));

View File

@ -1,49 +1,54 @@
package net.Indyuce.mmocore.comp.mythicmobs;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.load.MMOLoader;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicFactionExperienceSource;
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicFactionObjective;
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicMobExperienceSource;
import net.Indyuce.mmocore.comp.mythicmobs.load.KillMythicMobObjective;
import net.Indyuce.mmocore.comp.mythicmobs.load.MythicSkillTrigger;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.comp.mythicmobs.load.*;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import org.bukkit.configuration.ConfigurationSection;
public class MythicMobsMMOLoader extends MMOLoader {
@Override
public Trigger loadTrigger(MMOLineConfig config) {
@Override
public Trigger loadTrigger(MMOLineConfig config) {
if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill"))
return new MythicSkillTrigger(config);
if (config.getKey().equalsIgnoreCase("mmskill") || config.getKey().equalsIgnoreCase("mythicmobskill"))
return new MythicSkillTrigger(config);
return null;
}
return null;
}
@Override
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
@Override
public DropItem loadDropItem(MMOLineConfig config) {
if (config.getKey().equalsIgnoreCase("killmythicmob"))
return new KillMythicMobObjective(section, config);
if (config.getKey().equalsIgnoreCase("killmythicfaction"))
return new KillMythicFactionObjective(section, config);
if (config.getKey().equals("mmdroptable"))
return new MMDropTableDropItem(config);
return null;
}
return null;
}
@Override
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
@Override
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
if (config.getKey().equalsIgnoreCase("killmythicmob"))
return new KillMythicMobExperienceSource(dispenser, config);
if (config.getKey().equalsIgnoreCase("killmythicfaction"))
return new KillMythicFactionExperienceSource(dispenser, config);
if (config.getKey().equalsIgnoreCase("killmythicmob"))
return new KillMythicMobObjective(section, config);
if (config.getKey().equalsIgnoreCase("killmythicfaction"))
return new KillMythicFactionObjective(section, config);
return null;
}
return null;
}
@Override
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
if (config.getKey().equalsIgnoreCase("killmythicmob"))
return new KillMythicMobExperienceSource(dispenser, config);
if (config.getKey().equalsIgnoreCase("killmythicfaction"))
return new KillMythicFactionExperienceSource(dispenser, config);
return null;
}
}

View File

@ -1,40 +1,40 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.api.config.MythicLineConfig;
import io.lumine.mythic.api.drops.DropMetadata;
import io.lumine.mythic.api.drops.IMultiDrop;
import io.lumine.mythic.bukkit.adapters.BukkitItemStack;
import io.lumine.mythic.core.drops.Drop;
import io.lumine.mythic.core.drops.LootBag;
import io.lumine.mythic.core.drops.droppables.ItemDrop;
import net.Indyuce.mmocore.util.item.CurrencyItemBuilder;
import java.util.Random;
import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitItemStack;
import io.lumine.xikage.mythicmobs.drops.Drop;
import io.lumine.xikage.mythicmobs.drops.DropMetadata;
import io.lumine.xikage.mythicmobs.drops.IMultiDrop;
import io.lumine.xikage.mythicmobs.drops.LootBag;
import io.lumine.xikage.mythicmobs.drops.droppables.ItemDrop;
import io.lumine.xikage.mythicmobs.io.MythicLineConfig;
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
public class CurrencyItemDrop extends Drop implements IMultiDrop {
private final String key;
private final int minw;
private final int maxw;
private final String key;
private final int minw;
private final int maxw;
private static final Random random = new Random();
private static final Random random = new Random();
public CurrencyItemDrop(String key, MythicLineConfig config) {
super(config.getLine(), config);
this.key = key;
minw = config.getInteger("minw", 1);
maxw = config.getInteger("maxw", 1);
}
public CurrencyItemDrop(String key, MythicLineConfig config) {
super(config.getLine(), config);
@SuppressWarnings("deprecation")
@Override
public LootBag get(DropMetadata metadata) {
LootBag loot = new LootBag(metadata);
loot.add(new ItemDrop(this.getLine(), (MythicLineConfig) this.getConfig(), new BukkitItemStack(new CurrencyItem(key, random(minw, maxw)).build())));
return loot;
}
this.key = key;
minw = config.getInteger("minw", 1);
maxw = config.getInteger("maxw", 1);
}
private int random(int a, int b) {
return random.nextInt(b - a + 1) + a;
}
@SuppressWarnings("deprecation")
@Override
public LootBag get(DropMetadata metadata) {
LootBag loot = new LootBag(metadata);
loot.add(new ItemDrop(this.getLine(), this.getConfig(), new BukkitItemStack(new CurrencyItemBuilder(key, random(minw, maxw)).build())));
return loot;
}
private int random(int a, int b) {
return random.nextInt(b - a + 1) + a;
}
}

View File

@ -1,66 +1,70 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import java.util.Random;
import io.lumine.mythic.api.config.MythicLineConfig;
import io.lumine.mythic.api.drops.DropMetadata;
import io.lumine.mythic.api.drops.IMultiDrop;
import io.lumine.mythic.bukkit.adapters.BukkitItemStack;
import io.lumine.mythic.core.drops.Drop;
import io.lumine.mythic.core.drops.LootBag;
import io.lumine.mythic.core.drops.droppables.ItemDrop;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.util.item.CurrencyItemBuilder;
import net.Indyuce.mmocore.util.item.SimpleItemBuilder;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitItemStack;
import io.lumine.xikage.mythicmobs.drops.Drop;
import io.lumine.xikage.mythicmobs.drops.DropMetadata;
import io.lumine.xikage.mythicmobs.drops.IMultiDrop;
import io.lumine.xikage.mythicmobs.drops.LootBag;
import io.lumine.xikage.mythicmobs.drops.droppables.ItemDrop;
import io.lumine.xikage.mythicmobs.io.MythicLineConfig;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.item.ConfigItem;
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import java.util.Random;
public class GoldPouchDrop extends Drop implements IMultiDrop {
private final int min;
private final int max;
private final int min;
private final int max;
private static final Random random = new Random();
private static final Random random = new Random();
public GoldPouchDrop(MythicLineConfig config) {
super(config.getLine(), config);
public GoldPouchDrop(MythicLineConfig config) {
super(config.getLine(), config);
min = config.getInteger("min", 1);
max = config.getInteger("max", 10);
}
min = config.getInteger("min", 1);
max = config.getInteger("max", 10);
}
@SuppressWarnings("deprecation")
@Override
public LootBag get(DropMetadata metadata) {
LootBag loot = new LootBag(metadata);
NBTItem nbt = NBTItem.get(new ConfigItem("MOB_GOLD_POUCH").build());
@SuppressWarnings("deprecation")
@Override
public LootBag get(DropMetadata metadata) {
LootBag loot = new LootBag(metadata);
NBTItem nbt = NBTItem.get(new SimpleItemBuilder("MOB_GOLD_POUCH").build());
ItemStack[] content = new ItemStack[18];
int money = random.nextInt(max - min + 1) + min;
ItemStack[] content = new ItemStack[18];
int money = random.nextInt(max - min + 1) + min;
for (int j = 0; j < 7 && money > 0; j++) {
int a = j == 6 ? money : Math.max(1, (int) ((.12 + random.nextDouble() * .4) * (double) money));
money -= a;
for (int j = 0; j < 7 && money > 0; j++) {
int a = j == 6 ? money : Math.max(1, (int) ((.12 + random.nextDouble() * .4) * (double) money));
money -= a;
if (a < 30 && random.nextDouble() < .3) {
content[getAvailableSlot(content)] = new CurrencyItem("GOLD_COIN", 1, a).build();
continue;
}
if (a < 30 && random.nextDouble() < .3) {
content[getAvailableSlot(content)] = setAmount(new CurrencyItemBuilder("GOLD_COIN", 1).build(), a);
continue;
}
content[getAvailableSlot(content)] = new CurrencyItem("NOTE", a, 1).build();
}
content[getAvailableSlot(content)] = new CurrencyItemBuilder("NOTE", a).build();
}
nbt.addTag(new ItemTag("RpgPouchSize", 18), new ItemTag("RpgPouchMob", true), new ItemTag("RpgPouchInventory", MMOCoreUtils.toBase64(content)));
loot.add(new ItemDrop(this.getLine(), (MythicLineConfig) this.getConfig(), new BukkitItemStack(nbt.toItem())));
return loot;
}
nbt.addTag(new ItemTag("RpgPouchSize", 18), new ItemTag("RpgPouchMob", true), new ItemTag("RpgPouchInventory", MMOCoreUtils.toBase64(content)));
loot.add(new ItemDrop(this.getLine(), this.getConfig(), new BukkitItemStack(nbt.toItem())));
return loot;
}
private int getAvailableSlot(ItemStack[] content) {
int slot;
while (content[slot = random.nextInt(content.length)] != null)
if(content[slot].getType() == Material.AIR) break;
return slot;
}
private ItemStack setAmount(ItemStack item, int amount) {
item.setAmount(amount);
return item;
}
private int getAvailableSlot(ItemStack[] content) {
int slot;
while (content[slot = random.nextInt(content.length)] != null)
if (content[slot].getType() == Material.AIR) break;
return slot;
}
}

View File

@ -1,10 +1,10 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Bukkit;

View File

@ -1,57 +1,56 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
import net.Indyuce.mmocore.api.quest.QuestProgress;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
import net.Indyuce.mmocore.api.quest.QuestProgress;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class KillMythicFactionObjective extends Objective {
private final String factionName;
private final int required;
private final String factionName;
private final int required;
public KillMythicFactionObjective(ConfigurationSection section, MMOLineConfig config) {
super(section);
public KillMythicFactionObjective(ConfigurationSection section, MMOLineConfig config) {
super(section);
config.validate("amount", "name");
config.validate("amount", "name");
factionName = config.getString("name");
required = config.getInt("amount");
}
factionName = config.getString("name");
required = config.getInt("amount");
}
@Override
public ObjectiveProgress newProgress(QuestProgress questProgress) {
return new KillFactionProgress(questProgress, this);
}
@Override
public ObjectiveProgress newProgress(QuestProgress questProgress) {
return new KillFactionProgress(questProgress, this);
}
public class KillFactionProgress extends ObjectiveProgress implements Listener {
private int count;
public class KillFactionProgress extends ObjectiveProgress implements Listener {
private int count;
public KillFactionProgress(QuestProgress questProgress, Objective objective) {
super(questProgress, objective);
}
public KillFactionProgress(QuestProgress questProgress, Objective objective) {
super(questProgress, objective);
}
@EventHandler
public void a(MythicMobDeathEvent event) {
if(!getQuestProgress().getPlayer().isOnline()) return;
if (event.getKiller() instanceof Player
&& event.getKiller().equals(getQuestProgress().getPlayer().getPlayer())
&& event.getMob().hasFaction() && event.getMob().getFaction().equals(factionName)) {
count++;
getQuestProgress().getPlayer().getQuestData().updateBossBar();
if (count >= required)
getQuestProgress().completeObjective();
}
}
@EventHandler
public void a(MythicMobDeathEvent event) {
if (!getQuestProgress().getPlayer().isOnline()) return;
if (event.getKiller() instanceof Player
&& event.getKiller().equals(getQuestProgress().getPlayer().getPlayer())
&& event.getMob().hasFaction() && event.getMob().getFaction().equals(factionName)) {
count++;
getQuestProgress().getPlayer().getQuestData().updateBossBar();
if (count >= required)
getQuestProgress().completeObjective();
}
}
@Override
public String formatLore(String lore) {
return lore.replace("{left}", "" + (required - count));
}
}
@Override
public String formatLore(String lore) {
return lore.replace("{left}", "" + (required - count));
}
}
}

View File

@ -1,10 +1,10 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Bukkit;

View File

@ -1,55 +1,54 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.bukkit.events.MythicMobDeathEvent;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
import net.Indyuce.mmocore.api.quest.QuestProgress;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
import net.Indyuce.mmocore.api.quest.QuestProgress;
import net.Indyuce.mmocore.api.quest.objective.Objective;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class KillMythicMobObjective extends Objective {
private final String internalName;
private final int required;
private final String internalName;
private final int required;
public KillMythicMobObjective(ConfigurationSection section, MMOLineConfig config) {
super(section);
public KillMythicMobObjective(ConfigurationSection section, MMOLineConfig config) {
super(section);
config.validate("amount", "name");
config.validate("amount", "name");
internalName = config.getString("name");
required = config.getInt("amount");
}
internalName = config.getString("name");
required = config.getInt("amount");
}
@Override
public ObjectiveProgress newProgress(QuestProgress questProgress) {
return new KillMobProgress(questProgress, this);
}
@Override
public ObjectiveProgress newProgress(QuestProgress questProgress) {
return new KillMobProgress(questProgress, this);
}
public class KillMobProgress extends ObjectiveProgress implements Listener {
private int count;
public class KillMobProgress extends ObjectiveProgress implements Listener {
private int count;
public KillMobProgress(QuestProgress questProgress, Objective objective) {
super(questProgress, objective);
}
public KillMobProgress(QuestProgress questProgress, Objective objective) {
super(questProgress, objective);
}
@EventHandler
public void a(MythicMobDeathEvent event) {
if(!getQuestProgress().getPlayer().isOnline()) return;
if (event.getKiller() instanceof Player && event.getKiller().equals(getQuestProgress().getPlayer().getPlayer()) && event.getMob().getType().getInternalName().equals(internalName)) {
count++;
getQuestProgress().getPlayer().getQuestData().updateBossBar();
if (count >= required)
getQuestProgress().completeObjective();
}
}
@EventHandler
public void a(MythicMobDeathEvent event) {
if (!getQuestProgress().getPlayer().isOnline()) return;
if (event.getKiller() instanceof Player && event.getKiller().equals(getQuestProgress().getPlayer().getPlayer()) && event.getMob().getType().getInternalName().equals(internalName)) {
count++;
getQuestProgress().getPlayer().getQuestData().updateBossBar();
if (count >= required)
getQuestProgress().completeObjective();
}
}
@Override
public String formatLore(String lore) {
return lore.replace("{left}", "" + (required - count));
}
}
@Override
public String formatLore(String lore) {
return lore.replace("{left}", "" + (required - count));
}
}
}

View File

@ -0,0 +1,42 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.api.drops.DropMetadata;
import io.lumine.mythic.api.drops.IItemDrop;
import io.lumine.mythic.bukkit.BukkitAdapter;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.core.drops.Drop;
import io.lumine.mythic.core.drops.DropMetadataImpl;
import io.lumine.mythic.core.drops.DropTable;
import io.lumine.mythic.core.drops.LootBag;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.loot.LootBuilder;
import net.Indyuce.mmocore.loot.droptable.dropitem.DropItem;
import java.util.NoSuchElementException;
public class MMDropTableDropItem extends DropItem {
private final DropTable dropTable;
private static final DropMetadata DROP_METADATA = new DropMetadataImpl(null, null);
public MMDropTableDropItem(MMOLineConfig config) {
super(config);
config.validate("id");
String id = config.getString("id");
try {
dropTable = MythicBukkit.inst().getDropManager().getDropTable(id).orElse(null);
} catch (NoSuchElementException exception) {
throw new IllegalArgumentException("Could not find MM drop table with ID '" + id + "'");
}
}
@Override
public void collect(LootBuilder builder) {
LootBag lootBag = dropTable.generate(DROP_METADATA);
for (Drop type : lootBag.getDrops())
if (type instanceof IItemDrop)
builder.addLoot(BukkitAdapter.adapt(((IItemDrop) type).getDrop(DROP_METADATA, 1)));
}
}

View File

@ -1,18 +1,21 @@
package net.Indyuce.mmocore.comp.mythicmobs.load;
import io.lumine.mythic.api.adapters.AbstractPlayer;
import io.lumine.mythic.api.mobs.GenericCaster;
import io.lumine.mythic.api.skills.Skill;
import io.lumine.mythic.api.skills.SkillCaster;
import io.lumine.mythic.api.skills.SkillMetadata;
import io.lumine.mythic.api.skills.SkillTrigger;
import io.lumine.mythic.bukkit.BukkitAdapter;
import io.lumine.mythic.bukkit.MythicBukkit;
import io.lumine.mythic.core.skills.SkillMetadataImpl;
import io.lumine.mythic.core.skills.SkillTriggers;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.xikage.mythicmobs.MythicMobs;
import io.lumine.xikage.mythicmobs.adapters.AbstractPlayer;
import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter;
import io.lumine.xikage.mythicmobs.mobs.GenericCaster;
import io.lumine.xikage.mythicmobs.skills.Skill;
import io.lumine.xikage.mythicmobs.skills.SkillCaster;
import io.lumine.xikage.mythicmobs.skills.SkillMetadata;
import io.lumine.xikage.mythicmobs.skills.SkillTrigger;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import org.apache.commons.lang.Validate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional;
@ -24,7 +27,7 @@ public class MythicSkillTrigger extends Trigger {
config.validate("id");
String id = config.getString("id");
Optional<io.lumine.xikage.mythicmobs.skills.Skill> opt = MythicMobs.inst().getSkillManager().getSkill(id);
Optional<io.lumine.mythic.api.skills.Skill> opt = MythicBukkit.inst().getSkillManager().getSkill(id);
Validate.isTrue(opt.isPresent(), "Could not find MM skill " + id);
skill = opt.get();
}
@ -35,8 +38,8 @@ public class MythicSkillTrigger extends Trigger {
AbstractPlayer trigger = BukkitAdapter.adapt(player.getPlayer());
SkillCaster caster = new GenericCaster(trigger);
SkillMetadata skillMeta = new SkillMetadata(SkillTrigger.API, caster, trigger, BukkitAdapter.adapt(player.getPlayer().getLocation()), new HashSet<>(), null, 1);
if (skill.usable(skillMeta, SkillTrigger.API))
SkillMetadata skillMeta = new SkillMetadataImpl(SkillTriggers.API, caster, trigger, BukkitAdapter.adapt(player.getPlayer().getLocation()), new HashSet<>(), null, 1);
if (skill.isUsable(skillMeta))
skill.execute(skillMeta);
}
}

View File

@ -1,19 +0,0 @@
package net.Indyuce.mmocore.experience;
public class ExperienceInfo {
private final Profession profess;
private final int value;
public ExperienceInfo(int value, Profession profess) {
this.value = value;
this.profess = profess;
}
public Profession getProfession() {
return profess;
}
public int getValue() {
return value;
}
}

View File

@ -12,7 +12,7 @@ import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

View File

@ -5,8 +5,8 @@ import io.lumine.mythic.lib.api.util.PostLoadObject;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.provider.ProfessionExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ProfessionExperienceDispenser;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.experience.provider;
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -7,18 +7,18 @@ import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class MainExperienceDispenser implements ExperienceDispenser {
public class ClassExperienceDispenser implements ExperienceDispenser {
private final PlayerClass profess;
public MainExperienceDispenser(PlayerClass profess) {
public ClassExperienceDispenser(PlayerClass profess) {
this.profess = profess;
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation) {
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation;
playerData.giveExperience(experience, EXPSource.SOURCE, hologramLocation, true);
playerData.giveExperience(experience, source, hologramLocation, true);
}
@Override

View File

@ -1,12 +1,16 @@
package net.Indyuce.mmocore.experience.provider;
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Used to differenciate between the main class experience
* and experience given in a specific profession
* Used to differenciate between the main class experience and
* experience given in a specific profession. Also being used to
* monitor EXP holograms.
*/
public interface ExperienceDispenser {
@ -17,10 +21,12 @@ public interface ExperienceDispenser {
* @param experience Experience gained. Note that it is a double
* because it gets converted to an integer at
* the very last moment in MMOCore
* @param hologramLocation Location of displayed hologram, nothing
* is displayed if it's null
* @param hologramLocation Location of displayed hologram. When set to null
* and if exp holograms are enabled it will take the
* player's location instead.
* @param source Why the EXP was gained
*/
void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation);
void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, @NotNull EXPSource source);
/**
* Experience sources handle both CLASS experience sources and PROFESSION
@ -32,7 +38,8 @@ public interface ExperienceDispenser {
*/
boolean shouldHandle(PlayerData playerData);
@Nullable
default Location getPlayerLocation(PlayerData player) {
return player.isOnline() ? player.getPlayer().getLocation() : null;
return player.isOnline() ? MMOCoreUtils.getCenterLocation(player.getPlayer()) : null;
}
}

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.experience.provider;
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.Profession;
@ -14,7 +14,7 @@ public class ProfessionExperienceDispenser implements ExperienceDispenser {
}
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation) {
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation;
playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation);

View File

@ -0,0 +1,22 @@
package net.Indyuce.mmocore.experience.dispenser;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.EXPSource;
import org.bukkit.Location;
import org.jetbrains.annotations.Nullable;
public class SimpleExperienceDispenser implements ExperienceDispenser {
@Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !MMOCore.plugin.getConfig().getBoolean("display-main-class-exp-holograms") ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation;
playerData.giveExperience(experience, source, hologramLocation, true);
}
@Override
public boolean shouldHandle(PlayerData playerData) {
return true;
}
}

View File

@ -2,7 +2,8 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
@ -167,7 +168,7 @@ public class BrewPotionExperienceSource extends ExperienceSource<PotionMeta> {
*/
// exp += getTotal(mapEffectDurations());
getDispenser().giveExperience(PlayerData.get(player), (int) exp * multiplier, null);
getDispenser().giveExperience(PlayerData.get(player), (int) exp * multiplier, null, EXPSource.SOURCE);
}
}
}

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate;

View File

@ -4,7 +4,8 @@ import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.enchantments.Enchantment;
@ -59,7 +60,7 @@ public class EnchantItemExperienceSource extends ExperienceSource<Void> {
double exp = 0;
for (Entry<Enchantment, Integer> entry : applicableEnchants.entrySet())
exp += MMOCore.plugin.enchantManager.getBaseExperience(entry.getKey()) * entry.getValue();
getDispenser().giveExperience(player, (int) exp, event.getEnchantBlock().getLocation());
getDispenser().giveExperience(player, (int) exp, event.getEnchantBlock().getLocation(), EXPSource.SOURCE);
}
}
};

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;

View File

@ -4,7 +4,8 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Bukkit;
@ -34,7 +35,7 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
for (KillMobExperienceSource source : getSources())
if (source.matches(data, event.getTarget()))
source.giveExperience(data, 1, event.getTarget().getLocation());
source.giveExperience(data, 1, MMOCoreUtils.getCenterLocation(event.getTarget()));
}
}, 2);
}

View File

@ -3,7 +3,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.GameMode;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;

View File

@ -2,7 +2,8 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
@ -74,7 +75,7 @@ public class RepairItemExperienceSource extends ExperienceSource<ItemStack> {
*/
double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType())
* Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100;
getDispenser().giveExperience(data, (int) exp, null);
getDispenser().giveExperience(data, (int) exp, null, EXPSource.SOURCE);
}
}
}

View File

@ -2,7 +2,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Location;

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.experience.source.type;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
public abstract class ExperienceSource<T> {

View File

@ -1,7 +1,8 @@
package net.Indyuce.mmocore.experience.source.type;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.experience.provider.ExperienceDispenser;
import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import org.bukkit.Location;
@ -41,6 +42,6 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
* @param hologramLocation Location used to display the exp hologram
*/
public void giveExperience(PlayerData player, double multiplier, @Nullable Location hologramLocation) {
getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation);
getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation, EXPSource.SOURCE);
}
}

View File

@ -200,13 +200,15 @@ public class PlayerStats extends EditableInventory {
@Override
public ItemStack display(GeneratedInventory inv, int n) {
ItemStack item = super.display(inv, n);
if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
SkullMeta meta = (SkullMeta) item.getItemMeta();
meta.setOwningPlayer(inv.getPlayer());
item.setItemMeta(meta);
ItemStack disp = super.display(inv, n);
if (disp.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
SkullMeta meta = (SkullMeta) disp.getItemMeta();
inv.dynamicallyUpdateItem(this, n, disp, current -> {
meta.setOwningPlayer(inv.getPlayer());
current.setItemMeta(meta);
});
}
return item;
return disp;
}
@Override

View File

@ -3,7 +3,6 @@ package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.EditableInventory;
@ -11,6 +10,9 @@ import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.waypoint.CostType;
import net.Indyuce.mmocore.waypoint.Waypoint;
import net.Indyuce.mmocore.waypoint.WaypointOption;
import org.apache.commons.lang.Validate;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
@ -19,177 +21,208 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class WaypointViewer extends EditableInventory {
public WaypointViewer() {
super("waypoints");
}
public WaypointViewer() {
super("waypoints");
}
@Override
public InventoryItem load(String function, ConfigurationSection config) {
@Override
public InventoryItem load(String function, ConfigurationSection config) {
if (function.equals("waypoint"))
return new WaypointItem(config);
if (function.equals("waypoint"))
return new WaypointItem(config);
if (function.equals("previous"))
return new SimplePlaceholderItem<WaypointViewerInventory>(config) {
if (function.equals("previous"))
return new SimplePlaceholderItem<WaypointViewerInventory>(config) {
@Override
public boolean canDisplay(WaypointViewerInventory inv) {
return inv.page > 0;
}
};
@Override
public boolean canDisplay(WaypointViewerInventory inv) {
return inv.page > 0;
}
};
if (function.equals("next"))
return new SimplePlaceholderItem<WaypointViewerInventory>(config) {
if (function.equals("next"))
return new SimplePlaceholderItem<WaypointViewerInventory>(config) {
@Override
public boolean canDisplay(WaypointViewerInventory inv) {
return inv.getEditable().getByFunction("waypoint").getSlots().size() * (inv.page + 1) < inv.waypoints.size();
}
};
@Override
public boolean canDisplay(WaypointViewerInventory inv) {
return inv.getEditable().getByFunction("waypoint").getSlots().size() * (inv.page + 1) < inv.waypoints.size();
}
};
return new SimplePlaceholderItem(config);
}
return new SimplePlaceholderItem(config);
}
public GeneratedInventory newInventory(PlayerData data) {
return newInventory(data, null);
}
public GeneratedInventory newInventory(PlayerData data) {
return newInventory(data, null);
}
public GeneratedInventory newInventory(PlayerData data, Waypoint waypoint) {
return new WaypointViewerInventory(data, this, waypoint);
}
public GeneratedInventory newInventory(PlayerData data, Waypoint waypoint) {
return new WaypointViewerInventory(data, this, waypoint);
}
public class WaypointDisplayItem extends InventoryItem<WaypointViewerInventory> {
private final Material notReady;
public class WaypointItem extends SimplePlaceholderItem<WaypointViewerInventory> {
private final SimplePlaceholderItem noWaypoint, locked;
private final WaypointItemHandler availWaypoint, notLinked, notDynamic, noStellium;
public WaypointDisplayItem(ConfigurationSection config) {
super(config);
public WaypointItem(ConfigurationSection config) {
super(Material.BARRIER, config);
Validate.isTrue(config.contains("not-ready"), "Could not read 'not-ready' material");
notReady = Material.valueOf(config.getString("not-ready"));
}
Validate.notNull(config.getConfigurationSection("no-waypoint"), "Could not load 'no-waypoint' config");
Validate.notNull(config.getConfigurationSection("locked"), "Could not load 'locked' config");
Validate.notNull(config.getConfigurationSection("not-a-destination"), "Could not load 'not-a-destination' config");
Validate.notNull(config.getConfigurationSection("not-dynamic"), "Could not load 'not-dynamic' config");
Validate.notNull(config.getConfigurationSection("not-enough-stellium"), "Could not load 'not-enough-stellium' config");
Validate.notNull(config.getConfigurationSection("display"), "Could not load 'display' config");
@Override
public ItemStack display(WaypointViewerInventory inv, int n) {
ItemStack disp = super.display(inv, n);
noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint"));
locked = new SimplePlaceholderItem(config.getConfigurationSection("locked"));
notLinked = new WaypointItemHandler(config.getConfigurationSection("not-a-destination"));
notDynamic = new WaypointItemHandler(config.getConfigurationSection("not-dynamic"));
noStellium = new WaypointItemHandler(config.getConfigurationSection("not-enough-stellium"));
availWaypoint = new WaypointItemHandler(config.getConfigurationSection("display"));
}
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n);
if (inv.getPlayerData().getStellium() < waypoint.getStelliumCost() || (inv.current == null && !waypoint.isDynamic()))
disp.setType(notReady);
@Override
public boolean hasDifferentDisplay() {
return true;
}
return NBTItem.get(disp).addTag(new ItemTag("waypointId", waypoint.getId())).toItem();
}
@Override
public ItemStack display(WaypointViewerInventory inv, int n) {
@Override
public Placeholders getPlaceholders(WaypointViewerInventory inv, int n) {
Placeholders holders = new Placeholders();
int index = inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n;
if (index >= inv.waypoints.size())
return noWaypoint.display(inv, n);
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n);
holders.register("name", waypoint.getName());
holders.register("stellium", decimal.format(waypoint.getStelliumCost()));
// Locked waypoint?
Waypoint waypoint = inv.waypoints.get(index);
if (!inv.getPlayerData().hasWaypoint(waypoint))
return locked.display(inv, n);
return holders;
}
}
// Waypoints are not linked
if (inv.current != null && !inv.current.hasDestination(waypoint))
return notLinked.display(inv, n);
public class WaypointItem extends SimplePlaceholderItem<WaypointViewerInventory> {
private final SimplePlaceholderItem noWaypoint, locked;
private final WaypointDisplayItem availWaypoint;
// Not dynamic waypoint
if (inv.current == null && !waypoint.hasOption(WaypointOption.DYNAMIC))
return notDynamic.display(inv, n);
public WaypointItem(ConfigurationSection config) {
super(Material.BARRIER, config);
// Stellium cost
if (waypoint.getCost(inv.current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE) > inv.getPlayerData().getStellium())
return noStellium.display(inv, n);
Validate.notNull(config.getConfigurationSection("no-waypoint"), "Could not load 'no-waypoint' config");
Validate.notNull(config.getConfigurationSection("locked"), "Could not load 'locked' config");
Validate.notNull(config.getConfigurationSection("display"), "Could not load 'display' config");
return availWaypoint.display(inv, n);
}
}
noWaypoint = new SimplePlaceholderItem(config.getConfigurationSection("no-waypoint"));
locked = new SimplePlaceholderItem(config.getConfigurationSection("locked"));
availWaypoint = new WaypointDisplayItem(config.getConfigurationSection("display"));
}
public class WaypointItemHandler extends InventoryItem<WaypointViewerInventory> {
public WaypointItemHandler(ConfigurationSection config) {
super(config);
}
@Override
public boolean hasDifferentDisplay() {
return true;
}
@Override
public ItemStack display(WaypointViewerInventory inv, int n) {
ItemStack disp = super.display(inv, n);
@Override
public ItemStack display(WaypointViewerInventory inv, int n) {
// If a player can teleport to another waypoint given his location
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n);
return NBTItem.get(disp).addTag(new ItemTag("waypointId", waypoint.getId())).toItem();
}
int index = inv.page * inv.getEditable().getByFunction("waypoint").getSlots().size() + n;
if (index >= inv.waypoints.size())
return noWaypoint.display(inv, n);
@Override
public Placeholders getPlaceholders(WaypointViewerInventory inv, int n) {
Placeholders holders = new Placeholders();
Waypoint waypoint = inv.waypoints.get(index);
return inv.getPlayerData().hasWaypoint(waypoint) ? availWaypoint.display(inv, n) : locked.display(inv);
}
}
Waypoint waypoint = inv.waypoints.get(inv.page * inv.getByFunction("waypoint").getSlots().size() + n);
holders.register("name", waypoint.getName());
holders.register("current_cost", decimal.format(waypoint.getCost(inv.waypointCostType)));
holders.register("normal_cost", decimal.format(waypoint.getCost(CostType.NORMAL_USE)));
holders.register("dynamic_cost", decimal.format(waypoint.getCost(CostType.DYNAMIC_USE)));
public class WaypointViewerInventory extends GeneratedInventory {
private final List<Waypoint> waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll());
private final Waypoint current;
return holders;
}
}
private int page;
public class WaypointViewerInventory extends GeneratedInventory {
private final List<Waypoint> waypoints = new ArrayList<>(MMOCore.plugin.waypointManager.getAll());
private final Waypoint current;
private final CostType waypointCostType;
public WaypointViewerInventory(PlayerData playerData, EditableInventory editable, Waypoint current) {
super(playerData, editable);
private int page;
this.current = current;
}
public WaypointViewerInventory(PlayerData playerData, EditableInventory editable, Waypoint current) {
super(playerData, editable);
@Override
public String calculateName() {
return getName();
}
this.current = current;
this.waypointCostType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE;
}
@Override
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
if (item.getFunction().equals("next")) {
page++;
open();
return;
}
@Override
public String calculateName() {
return getName();
}
if (item.getFunction().equals("previous")) {
page--;
open();
return;
}
@Override
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
if (item.getFunction().equals("next")) {
page++;
open();
return;
}
if (item.getFunction().equals("waypoint")) {
String tag = NBTItem.get(event.getCurrentItem()).getString("waypointId");
if (tag.equals(""))
return;
if (item.getFunction().equals("previous")) {
page--;
open();
return;
}
Waypoint waypoint = MMOCore.plugin.waypointManager.get(tag);
if (!playerData.hasWaypoint(waypoint)) {
MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-waypoint").send(player);
return;
}
if (item.getFunction().equals("waypoint")) {
String tag = NBTItem.get(event.getCurrentItem()).getString("waypointId");
if (tag.equals(""))
return;
if (waypoint.equals(current)) {
MMOCore.plugin.configManager.getSimpleMessage("standing-on-waypoint").send(player);
return;
}
// Locked waypoint?
Waypoint waypoint = MMOCore.plugin.waypointManager.get(tag);
if (!playerData.hasWaypoint(waypoint)) {
MMOCore.plugin.configManager.getSimpleMessage("not-unlocked-waypoint").send(player);
return;
}
if (current == null && !waypoint.isDynamic()) {
MMOCore.plugin.configManager.getSimpleMessage("not-dynamic-waypoint").send(player);
return;
}
// Cannot teleport to current waypoint
if (waypoint.equals(current)) {
MMOCore.plugin.configManager.getSimpleMessage("standing-on-waypoint").send(player);
return;
}
double left = waypoint.getStelliumCost() - playerData.getStellium();
if (left > 0) {
MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player);
return;
}
// Waypoint does not have target as destination
if (current != null && !current.hasDestination(waypoint)) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-teleport-to").send(player);
return;
}
if (playerData.getActivityTimeOut(PlayerActivity.USE_WAYPOINT) > 0)
return;
// Not dynamic waypoint
if (current == null && !waypoint.hasOption(WaypointOption.DYNAMIC)) {
MMOCore.plugin.configManager.getSimpleMessage("not-dynamic-waypoint").send(player);
return;
}
player.closeInventory();
playerData.warp(waypoint);
}
}
}
// Stellium cost
CostType costType = current == null ? CostType.DYNAMIC_USE : CostType.NORMAL_USE;
double left = waypoint.getCost(costType) - playerData.getStellium();
if (left > 0) {
MMOCore.plugin.configManager.getSimpleMessage("not-enough-stellium", "more", decimal.format(left)).send(player);
return;
}
if (playerData.getActivityTimeOut(PlayerActivity.USE_WAYPOINT) > 0)
return;
player.closeInventory();
playerData.warp(waypoint, costType);
}
}
}
}

View File

@ -1,95 +1,112 @@
package net.Indyuce.mmocore.gui.api;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.TriggerItem;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public abstract class GeneratedInventory extends PluginInventory {
private final EditableInventory editable;
private final List<InventoryItem> loaded = new ArrayList<>();
private final EditableInventory editable;
private final List<InventoryItem> loaded = new ArrayList<>();
public GeneratedInventory(PlayerData playerData, EditableInventory editable) {
super(playerData);
private Inventory open;
this.editable = editable;
}
public GeneratedInventory(PlayerData playerData, EditableInventory editable) {
super(playerData);
public List<InventoryItem> getLoaded() {
return loaded;
}
this.editable = editable;
}
public EditableInventory getEditable() {
return editable;
}
public List<InventoryItem> getLoaded() {
return loaded;
}
public InventoryItem getByFunction(String function) {
for (InventoryItem item : loaded)
if (item.getFunction().equals(function))
return item;
return null;
}
public EditableInventory getEditable() {
return editable;
}
public InventoryItem getBySlot(int slot) {
for (InventoryItem item : loaded)
if (item.getSlots().contains(slot))
return item;
return null;
}
public InventoryItem getByFunction(String function) {
for (InventoryItem item : loaded)
if (item.getFunction().equals(function))
return item;
return null;
}
/**
* This method must use an ordered collection because
* of GUI items overriding possibilities. Hence the use
* of an array list instead of a set
*/
public void addLoaded(InventoryItem item) {
loaded.add(0, item);
}
public InventoryItem getBySlot(int slot) {
for (InventoryItem item : loaded)
if (item.getSlots().contains(slot))
return item;
return null;
}
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, editable.getSlots(), MythicLib.plugin.parseColors(calculateName()));
/**
* This method must use an ordered collection because
* of GUI items overriding possibilities. Hence the use
* of an array list instead of a set
*/
public void addLoaded(InventoryItem item) {
loaded.add(0, item);
}
for (InventoryItem item : editable.getItems())
if (item.canDisplay(this))
item.setDisplayed(inv, this);
@Override
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, editable.getSlots(), MythicLib.plugin.parseColors(calculateName()));
return inv;
}
for (InventoryItem item : editable.getItems())
if (item.canDisplay(this))
item.setDisplayed(inv, this);
public void open() {
return inv;
}
/*
* Very important, in order to prevent ghost items, the loaded items map
* must be cleared when the inventory is updated or open at least twice
*/
loaded.clear();
public void open() {
getPlayer().openInventory(getInventory());
}
/*
* Very important, in order to prevent ghost items, the loaded items map
* must be cleared when the inventory is updated or open at least twice
*/
loaded.clear();
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
getPlayer().openInventory(open = getInventory());
}
if (event.getClickedInventory() != null && event.getClickedInventory().equals(event.getInventory())) {
InventoryItem item = getBySlot(event.getSlot());
if (item == null)
return;
/**
* @deprecated Not a fan of that implementation.
* Better work with {@link InventoryItem#setDisplayed(Inventory, GeneratedInventory)}
*/
@Deprecated
public void dynamicallyUpdateItem(InventoryItem<?> item, int n, ItemStack placed, Consumer<ItemStack> update) {
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
update.accept(placed);
open.setItem(item.getSlots().get(n), placed);
});
}
if (item instanceof TriggerItem)
((TriggerItem) item).getTrigger().apply(getPlayerData());
else
whenClicked(event, item);
}
}
public void whenClicked(InventoryClickEvent event) {
event.setCancelled(true);
public abstract String calculateName();
if (event.getClickedInventory() != null && event.getClickedInventory().equals(event.getInventory())) {
InventoryItem item = getBySlot(event.getSlot());
if (item == null)
return;
public abstract void whenClicked(InventoryClickEvent event, InventoryItem item);
if (item instanceof TriggerItem)
((TriggerItem) item).getTrigger().apply(getPlayerData());
else
whenClicked(event, item);
}
}
public abstract String calculateName();
public abstract void whenClicked(InventoryClickEvent event, InventoryItem item);
}

View File

@ -13,6 +13,8 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -21,147 +23,160 @@ import java.util.UUID;
import java.util.logging.Level;
public abstract class InventoryItem<T extends GeneratedInventory> {
private final String id, function;
private final List<Integer> slots = new ArrayList<>();
private final String id, function;
private final List<Integer> slots = new ArrayList<>();
private final Material material;
private final String name, texture;
private final List<String> lore;
private final int modelData;
private final boolean placeholders, hideFlags;
@Nullable
private final InventoryItem<?> parent;
public InventoryItem(ConfigurationSection config) {
this(Material.valueOf(config.getString("item", "").toUpperCase().replace(" ", "_").replace("-", "_")), config);
}
private final Material material;
private final String name, texture;
private final List<String> lore;
private final int modelData;
private final boolean hideFlags;
public InventoryItem(Material material, ConfigurationSection config) {
this.id = config.getName();
this.function = config.getString("function", "");
public InventoryItem(ConfigurationSection config) {
this((InventoryItem) null, config);
}
this.material = material;
this.name = config.getString("name");
this.lore = config.getStringList("lore");
this.hideFlags = config.getBoolean("hide-flags");
this.texture = config.getString("texture");
this.placeholders = config.getBoolean("placeholders");
this.modelData = config.getInt("custom-model-data");
public InventoryItem(@Nullable InventoryItem<?> parent, ConfigurationSection config) {
this(parent, Material.valueOf(config.getString("item", "").toUpperCase().replace(" ", "_").replace("-", "_")), config);
}
config.getStringList("slots").forEach(str -> slots.add(Integer.parseInt(str)));
}
public InventoryItem(@NotNull Material material, ConfigurationSection config) {
this(null, material, config);
}
public String getId() {
return id;
}
public InventoryItem(InventoryItem parent, Material material, ConfigurationSection config) {
this.id = config.getName();
this.function = config.getString("function", "");
this.parent = parent;
public String getFunction() {
return function;
}
this.material = material;
this.name = config.getString("name");
this.lore = config.getStringList("lore");
this.hideFlags = config.getBoolean("hide-flags");
this.texture = config.getString("texture");
this.modelData = config.getInt("custom-model-data");
public boolean hasFunction() {
return !function.isEmpty();
}
config.getStringList("slots").forEach(str -> slots.add(Integer.parseInt(str)));
}
public List<Integer> getSlots() {
return slots;
}
public String getId() {
return id;
}
public Material getMaterial() {
return material;
}
@NotNull
public String getFunction() {
return parent == null ? function : parent.function;
}
public boolean hideFlags() {
return hideFlags;
}
public boolean hasFunction() {
return !getFunction().isEmpty();
}
public boolean hasName() {
return name != null;
}
@NotNull
public List<Integer> getSlots() {
return parent == null ? slots : parent.slots;
}
public String getName() {
return name;
}
public Material getMaterial() {
return material;
}
public boolean hasLore() {
return lore != null && !lore.isEmpty();
}
public boolean hideFlags() {
return hideFlags;
}
public List<String> getLore() {
return lore;
}
public boolean hasName() {
return name != null;
}
public int getModelData() {
return modelData;
}
public String getName() {
return name;
}
public void setDisplayed(Inventory inv, T generated) {
generated.addLoaded(this);
public boolean hasLore() {
return lore != null && !lore.isEmpty();
}
if (!hasDifferentDisplay()) {
ItemStack display = display(generated);
for (int slot : getSlots())
inv.setItem(slot, display);
} else
for (int j = 0; j < slots.size(); j++)
inv.setItem(slots.get(j), display(generated, j));
public List<String> getLore() {
return lore;
}
}
public int getModelData() {
return modelData;
}
public boolean hasDifferentDisplay() {
return false;
}
public void setDisplayed(Inventory inv, T generated) {
generated.addLoaded(this);
public boolean canDisplay(T inv) {
return true;
}
if (!hasDifferentDisplay()) {
ItemStack display = display(generated);
for (int slot : getSlots())
inv.setItem(slot, display);
} else
for (int j = 0; j < slots.size(); j++)
inv.setItem(slots.get(j), display(generated, j));
public ItemStack display(T inv) {
return display(inv, 0);
}
}
public ItemStack display(T inv, int n) {
public boolean hasDifferentDisplay() {
return false;
}
Placeholders placeholders = getPlaceholders(inv, n);
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
public boolean canDisplay(T inv) {
return true;
}
if (texture != null && meta instanceof SkullMeta)
applyTexture(texture, (SkullMeta) meta);
public ItemStack display(T inv) {
return display(inv, 0);
}
if (hasName())
meta.setDisplayName(placeholders.apply(inv.getPlayer(), getName()));
public ItemStack display(T inv, int n) {
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
Placeholders placeholders = getPlaceholders(inv, n);
ItemStack item = new ItemStack(material);
ItemMeta meta = item.getItemMeta();
if (hasLore()) {
List<String> lore = new ArrayList<>();
getLore().forEach(line -> lore.add(ChatColor.GRAY + placeholders.apply(inv.getPlayer(), line)));
meta.setLore(lore);
}
if (texture != null && meta instanceof SkullMeta)
applyTexture(texture, (SkullMeta) meta);
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(getModelData());
if (hasName())
meta.setDisplayName(placeholders.apply(inv.getPlayer(), getName()));
item.setItemMeta(meta);
return item;
}
if (hideFlags())
meta.addItemFlags(ItemFlag.values());
private void applyTexture(String value, SkullMeta meta) {
try {
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", value));
if (hasLore()) {
List<String> lore = new ArrayList<>();
getLore().forEach(line -> lore.add(ChatColor.GRAY + placeholders.apply(inv.getPlayer(), line)));
meta.setLore(lore);
}
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.log(Level.WARNING, "Could not apply item texture value of " + getId());
}
}
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(getModelData());
public Placeholders getPlaceholders(T inv) {
return getPlaceholders(inv, 0);
}
item.setItemMeta(meta);
return item;
}
public abstract Placeholders getPlaceholders(T inv, int n);
private void applyTexture(String value, SkullMeta meta) {
try {
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", value));
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.log(Level.WARNING, "Could not apply item texture value of " + getId());
}
}
public Placeholders getPlaceholders(T inv) {
return getPlaceholders(inv, 0);
}
public abstract Placeholders getPlaceholders(T inv, int n);
}

View File

@ -7,28 +7,25 @@ import java.util.HashMap;
import java.util.Map;
public class Placeholders {
private final Map<String, String> placeholders = new HashMap<>();
private final Map<String, String> placeholders = new HashMap<>();
public void register(String path, Object obj) {
placeholders.put(path, obj.toString());
}
public void register(String path, Object obj) {
placeholders.put(path, obj.toString());
}
public String apply(Player player, String str) {
public String apply(Player player, String str) {
/*
* Remove potential conditions, apply color codes
* and external placeholders if needed.
*/
str = MMOCore.plugin.placeholderParser.parse(player, removeCondition(str));
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
// Internal placeholders
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
str = str.replace("{" + holder + "}", placeholders.getOrDefault(holder, "Error"));
}
return str;
}
private String removeCondition(String str) {
return str.startsWith("{") && str.contains("}") ? str.substring(str.indexOf("}") + 1) : str;
}
// External placeholders
return MMOCore.plugin.placeholderParser.parse(player, removeCondition(str));
}
private String removeCondition(String str) {
return str.startsWith("{") && str.contains("}") ? str.substring(str.indexOf("}") + 1) : str;
}
}

View File

@ -5,6 +5,10 @@ import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
public class SimplePlaceholderItem<T extends GeneratedInventory> extends InventoryItem<T> {
public SimplePlaceholderItem(InventoryItem<?> parent, ConfigurationSection config) {
super(parent, config);
}
public SimplePlaceholderItem(ConfigurationSection config) {
super(config);
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.gui.eco;
import net.Indyuce.mmocore.util.item.SimpleItemBuilder;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -13,7 +14,6 @@ import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.item.ConfigItem;
import net.Indyuce.mmocore.gui.api.PluginInventory;
import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.api.util.SmartGive;
@ -30,7 +30,7 @@ public class DepositMenu extends PluginInventory {
public Inventory getInventory() {
Inventory inv = Bukkit.createInventory(this, 27, "Deposit");
inv.setItem(26, depositItem = new ConfigItem("DEPOSIT_ITEM").addPlaceholders("worth", "0").build());
inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "0").build());
new BukkitRunnable() {
@ -115,6 +115,6 @@ public class DepositMenu extends PluginInventory {
private void updateDeposit(Inventory inv) {
deposit = MMOCoreUtils.getWorth(inv.getContents());
inv.setItem(26, depositItem = new ConfigItem("DEPOSIT_ITEM").addPlaceholders("worth", "" + deposit).build());
inv.setItem(26, depositItem = new SimpleItemBuilder("DEPOSIT_ITEM").addPlaceholders("worth", "" + deposit).build());
}
}

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmocore.gui.social.friend;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -15,6 +13,7 @@ import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.manager.InventoryManager;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
@ -24,10 +23,13 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.UUID;
public class EditableFriendList extends EditableInventory {
private static final NamespacedKey UUID_NAMESPACEDKEY = new NamespacedKey(MMOCore.plugin, "Uuid");
public EditableFriendList() {
super("friend-list");
}
@ -64,8 +66,8 @@ public class EditableFriendList extends EditableInventory {
}
public static class OfflineFriendItem extends InventoryItem {
public OfflineFriendItem(ConfigurationSection config) {
super(config);
public OfflineFriendItem(FriendItem parent, ConfigurationSection config) {
super(parent, config);
}
@Override
@ -82,27 +84,11 @@ public class EditableFriendList extends EditableInventory {
holders.register("last_seen", new DelayFormat(2).format(System.currentTimeMillis() - friend.getLastPlayed()));
return holders;
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
OfflinePlayer friend = Bukkit.getOfflinePlayer(inv.getPlayerData().getFriends().get(n));
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
if (meta instanceof SkullMeta)
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
((SkullMeta) meta).setOwningPlayer(friend);
disp.setItemMeta(meta);
});
return NBTItem.get(disp).addTag(new ItemTag("uuid", friend.getUniqueId().toString())).toItem();
}
}
public static class OnlineFriendItem extends SimplePlaceholderItem {
public OnlineFriendItem(ConfigurationSection config) {
super(config);
public OnlineFriendItem(FriendItem parent, ConfigurationSection config) {
super(parent, config);
}
@Override
@ -123,22 +109,6 @@ public class EditableFriendList extends EditableInventory {
holders.register("online_since", new DelayFormat(2).format(System.currentTimeMillis() - data.getLastLogin()));
return holders;
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
Player friend = Bukkit.getPlayer(inv.getPlayerData().getFriends().get(n));
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
if (meta instanceof SkullMeta)
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
((SkullMeta) meta).setOwningPlayer(friend);
disp.setItemMeta(meta);
});
return NBTItem.get(disp).addTag(new ItemTag("uuid", friend.getUniqueId().toString())).toItem();
}
}
public static class FriendItem extends SimplePlaceholderItem {
@ -151,14 +121,28 @@ public class EditableFriendList extends EditableInventory {
Validate.notNull(config.contains("online"), "Could not load online config");
Validate.notNull(config.contains("offline"), "Could not load offline config");
online = new OnlineFriendItem(config.getConfigurationSection("online"));
offline = new OfflineFriendItem(config.getConfigurationSection("offline"));
online = new OnlineFriendItem(this, config.getConfigurationSection("online"));
offline = new OfflineFriendItem(this, config.getConfigurationSection("offline"));
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
return inv.getPlayerData().getFriends().size() <= n ? super.display(inv, n)
: Bukkit.getOfflinePlayer(inv.getPlayerData().getFriends().get(n)).isOnline() ? online.display(inv, n) : offline.display(inv, n);
if (inv.getPlayerData().getFriends().size() <= n)
return super.display(inv, n);
ItemStack disp = Bukkit.getOfflinePlayer(inv.getPlayerData().getFriends().get(n)).isOnline() ? online.display(inv, n) : offline.display(inv, n);
Player friend = Bukkit.getPlayer(inv.getPlayerData().getFriends().get(n));
ItemMeta meta = disp.getItemMeta();
meta.getPersistentDataContainer().set(UUID_NAMESPACEDKEY, PersistentDataType.STRING, friend.getUniqueId().toString());
if (meta instanceof SkullMeta)
inv.dynamicallyUpdateItem(this, n, disp, current -> {
((SkullMeta) meta).setOwningPlayer(friend);
current.setItemMeta(meta);
});
disp.setItemMeta(meta);
return disp;
}
@Override
@ -238,7 +222,7 @@ public class EditableFriendList extends EditableInventory {
}
if (item.getFunction().equals("friend") && event.getAction() == InventoryAction.PICKUP_HALF) {
String tag = NBTItem.get(event.getCurrentItem()).getString("uuid");
String tag = event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
if (tag == null || tag.isEmpty())
return;

View File

@ -13,6 +13,7 @@ import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.configuration.ConfigurationSection;
@ -22,10 +23,13 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.UUID;
public class EditableGuildAdmin extends EditableInventory {
private static final NamespacedKey UUID_NAMESPACEDKEY = new NamespacedKey(MMOCore.plugin, "Uuid");
public EditableGuildAdmin() {
super("guild-admin");
}
@ -40,8 +44,8 @@ public class EditableGuildAdmin extends EditableInventory {
}
public static class MemberDisplayItem extends InventoryItem {
public MemberDisplayItem(ConfigurationSection config) {
super(config);
public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) {
super(memberItem, config);
}
@Override
@ -65,19 +69,21 @@ public class EditableGuildAdmin extends EditableInventory {
@Override
public ItemStack display(GeneratedInventory inv, int n) {
PlayerData member = PlayerData.get(inv.getPlayerData().getGuild().getMembers().get(n));
UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
meta.getPersistentDataContainer().set(UUID_NAMESPACEDKEY, PersistentDataType.STRING, uuid.toString());
if (meta instanceof SkullMeta)
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
if (!member.isOnline()) return;
((SkullMeta) meta).setOwningPlayer(member.getPlayer());
disp.setItemMeta(meta);
if (meta instanceof SkullMeta && offlinePlayer != null)
inv.dynamicallyUpdateItem(this, n, disp, current -> {
((SkullMeta) meta).setOwningPlayer(offlinePlayer);
current.setItemMeta(meta);
});
return NBTItem.get(disp).addTag(new ItemTag("uuid", member.getUniqueId().toString())).toItem();
disp.setItemMeta(meta);
return disp;
}
}
@ -92,7 +98,7 @@ public class EditableGuildAdmin extends EditableInventory {
Validate.notNull(config.contains("member"), "Could not load member config");
empty = new SimplePlaceholderItem(config.getConfigurationSection("empty"));
member = new MemberDisplayItem(config.getConfigurationSection("member"));
member = new MemberDisplayItem(this, config.getConfigurationSection("member"));
}
@Override
@ -174,7 +180,7 @@ public class EditableGuildAdmin extends EditableInventory {
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
return;
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(NBTItem.get(event.getCurrentItem()).getString("uuid")));
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
if (target.equals(player))
return;

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmocore.gui.social.guild;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
import net.Indyuce.mmocore.api.player.PlayerData;
@ -13,10 +11,7 @@ import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
@ -24,10 +19,13 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.UUID;
public class EditableGuildView extends EditableInventory {
private static final NamespacedKey UUID_NAMESPACEDKEY = new NamespacedKey(MMOCore.plugin, "Uuid");
public EditableGuildView() {
super("guild-view");
}
@ -38,8 +36,8 @@ public class EditableGuildView extends EditableInventory {
}
public static class MemberDisplayItem extends InventoryItem {
public MemberDisplayItem(ConfigurationSection config) {
super(config);
public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) {
super(memberItem, config);
}
@Override
@ -71,14 +69,16 @@ public class EditableGuildView extends EditableInventory {
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
meta.getPersistentDataContainer().set(UUID_NAMESPACEDKEY, PersistentDataType.STRING, uuid.toString());
if (meta instanceof SkullMeta)
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
inv.dynamicallyUpdateItem(this, n, disp, current -> {
((SkullMeta) meta).setOwningPlayer(Bukkit.getOfflinePlayer(uuid));
disp.setItemMeta(meta);
current.setItemMeta(meta);
});
return NBTItem.get(disp).addTag(new ItemTag("uuid", uuid.toString())).toItem();
disp.setItemMeta(meta);
return disp;
}
}
@ -93,7 +93,7 @@ public class EditableGuildView extends EditableInventory {
Validate.notNull(config.contains("member"), "Could not load member config");
empty = new SimplePlaceholderItem(config.getConfigurationSection("empty"));
member = new MemberDisplayItem(config.getConfigurationSection("member"));
member = new MemberDisplayItem(this, config.getConfigurationSection("member"));
}
@Override
@ -223,11 +223,15 @@ public class EditableGuildView extends EditableInventory {
});
}
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF && !NBTItem.get(event.getCurrentItem()).getString("uuid").isEmpty()) {
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF) {
if (!playerData.getGuild().getOwner().equals(playerData.getUniqueId()))
return;
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(NBTItem.get(event.getCurrentItem()).getString("uuid")));
String tag = event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING);
if (tag == null || tag.isEmpty())
return;
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(tag));
if (target.equals(player))
return;

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmocore.gui.social.party;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType;
@ -13,10 +11,7 @@ import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.party.provided.Party;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
@ -24,178 +19,178 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.UUID;
public class EditablePartyView extends EditableInventory {
public EditablePartyView() {
super("party-view");
}
private static final NamespacedKey UUID_NAMESPACEDKEY = new NamespacedKey(MMOCore.plugin, "Uuid");
@Override
public InventoryItem load(String function, ConfigurationSection config) {
return function.equals("member") ? new MemberItem(config) : new SimplePlaceholderItem(config);
}
public EditablePartyView() {
super("party-view");
}
public static class MemberDisplayItem extends InventoryItem {
public MemberDisplayItem(ConfigurationSection config) {
super(config);
}
@Override
public InventoryItem load(String function, ConfigurationSection config) {
return function.equals("member") ? new MemberItem(config) : new SimplePlaceholderItem(config);
}
@Override
public boolean hasDifferentDisplay() {
return true;
}
public static class MemberDisplayItem extends InventoryItem {
public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) {
super(memberItem, config);
}
@Override
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
Party party = (Party) inv.getPlayerData().getParty();
PlayerData member = party.getMembers().get(n);
@Override
public boolean hasDifferentDisplay() {
return true;
}
Placeholders holders = new Placeholders();
if (member.isOnline())
holders.register("name", member.getPlayer().getName());
holders.register("class", member.getProfess().getName());
holders.register("level", "" + member.getLevel());
holders.register("since", new DelayFormat(2).format(System.currentTimeMillis() - member.getLastLogin()));
return holders;
}
@Override
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
Party party = (Party) inv.getPlayerData().getParty();
PlayerData member = party.getMembers().get(n);
@Override
public ItemStack display(GeneratedInventory inv, int n) {
Party party = (Party) inv.getPlayerData().getParty();
PlayerData member = party.getMembers().get(n);
Placeholders holders = new Placeholders();
if (member.isOnline())
holders.register("name", member.getPlayer().getName());
holders.register("class", member.getProfess().getName());
holders.register("level", "" + member.getLevel());
holders.register("since", new DelayFormat(2).format(System.currentTimeMillis() - member.getLastLogin()));
return holders;
}
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
@Override
public ItemStack display(GeneratedInventory inv, int n) {
Party party = (Party) inv.getPlayerData().getParty();
PlayerData member = party.getMembers().get(n);
/*
* run async to save performance
*/
if (meta instanceof SkullMeta)
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
if (!member.isOnline()) return;
((SkullMeta) meta).setOwningPlayer(member.getPlayer());
disp.setItemMeta(meta);
});
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
meta.getPersistentDataContainer().set(UUID_NAMESPACEDKEY, PersistentDataType.STRING, member.getUniqueId().toString());
return NBTItem.get(disp).addTag(new ItemTag("uuid", member.getUniqueId().toString())).toItem();
}
}
if (meta instanceof SkullMeta)
inv.dynamicallyUpdateItem(this, n, disp, current -> {
((SkullMeta) meta).setOwningPlayer(member.getPlayer());
current.setItemMeta(meta);
});
public static class MemberItem extends SimplePlaceholderItem {
private final InventoryItem empty;
private final MemberDisplayItem member;
disp.setItemMeta(meta);
return disp;
}
}
public MemberItem(ConfigurationSection config) {
super(Material.BARRIER, config);
public static class MemberItem extends SimplePlaceholderItem {
private final InventoryItem empty;
private final MemberDisplayItem member;
Validate.notNull(config.contains("empty"), "Could not load empty config");
Validate.notNull(config.contains("member"), "Could not load member config");
public MemberItem(ConfigurationSection config) {
super(Material.BARRIER, config);
empty = new SimplePlaceholderItem(config.getConfigurationSection("empty"));
member = new MemberDisplayItem(config.getConfigurationSection("member"));
}
Validate.notNull(config.contains("empty"), "Could not load empty config");
Validate.notNull(config.contains("member"), "Could not load member config");
@Override
public ItemStack display(GeneratedInventory inv, int n) {
Party party = (Party) inv.getPlayerData().getParty();
return party.getMembers().size() > n ? member.display(inv, n) : empty.display(inv, n);
}
empty = new SimplePlaceholderItem(config.getConfigurationSection("empty"));
member = new MemberDisplayItem(this, config.getConfigurationSection("member"));
}
@Override
public boolean hasDifferentDisplay() {
return true;
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
Party party = (Party) inv.getPlayerData().getParty();
return party.getMembers().size() > n ? member.display(inv, n) : empty.display(inv, n);
}
@Override
public boolean canDisplay(GeneratedInventory inv) {
return true;
}
}
@Override
public boolean hasDifferentDisplay() {
return true;
}
public GeneratedInventory newInventory(PlayerData data) {
return new PartyViewInventory(data, this);
}
@Override
public boolean canDisplay(GeneratedInventory inv) {
return true;
}
}
public class PartyViewInventory extends GeneratedInventory {
private final int max;
public GeneratedInventory newInventory(PlayerData data) {
return new PartyViewInventory(data, this);
}
public PartyViewInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
public class PartyViewInventory extends GeneratedInventory {
private final int max;
max = editable.getByFunction("member").getSlots().size();
}
public PartyViewInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
@Override
public String calculateName() {
Party party = (Party) getPlayerData().getParty();
return getName().replace("{max}", "" + max).replace("{players}", "" + party.getMembers().size());
}
max = editable.getByFunction("member").getSlots().size();
}
@Override
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
Party party = (Party) playerData.getParty();
@Override
public String calculateName() {
Party party = (Party) getPlayerData().getParty();
return getName().replace("{max}", "" + max).replace("{players}", "" + party.getMembers().size());
}
if (item.getFunction().equals("leave")) {
party.removeMember(playerData);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
player.closeInventory();
return;
}
@Override
public void whenClicked(InventoryClickEvent event, InventoryItem item) {
Party party = (Party) playerData.getParty();
if (item.getFunction().equals("invite")) {
if (item.getFunction().equals("leave")) {
party.removeMember(playerData);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
player.closeInventory();
return;
}
if (party.getMembers().size() >= max) {
MMOCore.plugin.configManager.getSimpleMessage("party-is-full").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
}
if (item.getFunction().equals("invite")) {
MMOCore.plugin.configManager.newPlayerInput(player, InputType.PARTY_INVITE, (input) -> {
Player target = Bukkit.getPlayer(input);
if (target == null) {
MMOCore.plugin.configManager.getSimpleMessage("not-online-player", "player", input).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();
return;
}
if (party.getMembers().size() >= max) {
MMOCore.plugin.configManager.getSimpleMessage("party-is-full").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
}
long remaining = party.getLastInvite(target) + 60 * 2 * 1000 - System.currentTimeMillis();
if (remaining > 0) {
MMOCore.plugin.configManager.getSimpleMessage("party-invite-cooldown", "player", target.getName(), "cooldown", new DelayFormat().format(remaining)).send(player);
open();
return;
}
MMOCore.plugin.configManager.newPlayerInput(player, InputType.PARTY_INVITE, (input) -> {
Player target = Bukkit.getPlayer(input);
if (target == null) {
MMOCore.plugin.configManager.getSimpleMessage("not-online-player", "player", input).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();
return;
}
PlayerData targetData = PlayerData.get(target);
if (party.hasMember(target)) {
MMOCore.plugin.configManager.getSimpleMessage("already-in-party", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();
return;
}
long remaining = party.getLastInvite(target) + 60 * 2 * 1000 - System.currentTimeMillis();
if (remaining > 0) {
MMOCore.plugin.configManager.getSimpleMessage("party-invite-cooldown", "player", target.getName(), "cooldown", new DelayFormat().format(remaining)).send(player);
open();
return;
}
party.sendInvite(playerData, targetData);
MMOCore.plugin.configManager.getSimpleMessage("sent-party-invite", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
open();
});
}
PlayerData targetData = PlayerData.get(target);
if (party.hasMember(target)) {
MMOCore.plugin.configManager.getSimpleMessage("already-in-party", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();
return;
}
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF) {
if (!party.getOwner().equals(playerData))
return;
party.sendInvite(playerData, targetData);
MMOCore.plugin.configManager.getSimpleMessage("sent-party-invite", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
open();
});
}
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(NBTItem.get(event.getCurrentItem()).getString("uuid")));
if (target.equals(player))
return;
if (item.getFunction().equals("member") && event.getAction() == InventoryAction.PICKUP_HALF) {
if (!party.getOwner().equals(playerData))
return;
party.removeMember(PlayerData.get(target));
MMOCore.plugin.configManager.getSimpleMessage("kick-from-party", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
}
}
}
OfflinePlayer target = Bukkit.getOfflinePlayer(UUID.fromString(event.getCurrentItem().getItemMeta().getPersistentDataContainer().get(UUID_NAMESPACEDKEY, PersistentDataType.STRING)));
if (target.equals(player))
return;
party.removeMember(PlayerData.get(target));
MMOCore.plugin.configManager.getSimpleMessage("kick-from-party", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
}
}
}
}

View File

@ -1,40 +1,58 @@
package net.Indyuce.mmocore.listener;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.manager.SoundManager;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.waypoint.Waypoint;
import net.Indyuce.mmocore.waypoint.WaypointOption;
import org.bukkit.Particle;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.manager.InventoryManager;
import java.util.Objects;
public class WaypointsListener implements Listener {
@EventHandler
public void a(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (!event.isSneaking())
return;
Waypoint waypoint = MMOCore.plugin.waypointManager.getCurrentWaypoint(player);
if (waypoint == null || !waypoint.hasSneakEnabled())
return;
@EventHandler
public void interactWithWaypoint(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
if (!event.isSneaking())
return;
PlayerData data = PlayerData.get(player);
if (!data.hasWaypoint(waypoint)) {
data.unlockWaypoint(waypoint);
new SmallParticleEffect(player, Particle.SPELL_WITCH);
MMOCore.plugin.configManager.getSimpleMessage("new-waypoint", "waypoint", waypoint.getName()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_UNLOCK).playTo(player);
return;
}
Waypoint waypoint = MMOCore.plugin.waypointManager.getCurrentWaypoint(player);
if (waypoint == null)
return;
player.setSneaking(false);
InventoryManager.WAYPOINTS.newInventory(data, waypoint).open();
}
PlayerData data = PlayerData.get(player);
if (waypoint.hasOption(WaypointOption.UNLOCKABLE) && !data.hasWaypoint(waypoint)) {
data.unlockWaypoint(waypoint);
new SmallParticleEffect(player, Particle.SPELL_WITCH);
MMOCore.plugin.configManager.getSimpleMessage("new-waypoint", "waypoint", waypoint.getName()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_UNLOCK).playTo(player);
return;
}
if (waypoint.hasOption(WaypointOption.ENABLE_MENU)) {
player.setSneaking(false);
InventoryManager.WAYPOINTS.newInventory(data, waypoint).open();
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void waypointBook(PlayerInteractEvent event) {
if (!event.hasItem() || (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK))
return;
NBTItem nbtItem = NBTItem.get(event.getItem());
if (Objects.equals(nbtItem.getString("MMOCoreItemId"), "WAYPOINT_BOOK"))
InventoryManager.WAYPOINTS.newInventory(PlayerData.get(event.getPlayer())).open();
}
}

View File

@ -36,7 +36,7 @@ import java.util.UUID;
public class FishingListener implements Listener {
private final Set<UUID> fishing = new HashSet<>();
private static final Random random = new Random();
private static final Random RANDOM = new Random();
@EventHandler(priority = EventPriority.LOW)
public void a(PlayerFishEvent event) {
@ -65,9 +65,9 @@ public class FishingListener implements Listener {
private final Player player;
private final FishHook hook;
private final int total, exp;
private final int fishStrength, experienceDropped;
private int pulls;
private int currentPulls;
/**
* Used to track the last time the player swung the fishing rod.
@ -84,16 +84,20 @@ public class FishingListener implements Listener {
this.playerData = PlayerData.get(this.player = player);
this.hook = hook;
this.total = (int) (caught.rollTugs() * (1 - PlayerData.get(player).getStats().getStat(StatType.FISHING_STRENGTH) / 100));
this.exp = caught.rollExperience();
this.fishStrength = (int) Math.floor(caught.rollTugs() * (1 - PlayerData.get(player).getStats().getStat(StatType.FISHING_STRENGTH) / 100));
this.experienceDropped = caught.rollExperience();
fishing.add(player.getUniqueId());
runTaskTimer(MMOCore.plugin, 0, 2);
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin);
// Check for instant loot
if (fishStrength == 0)
lootFish();
}
public void criticalFish() {
pulls = total + 2;
public void setCriticalFish() {
currentPulls = fishStrength + 2;
}
public boolean isTimedOut() {
@ -103,16 +107,17 @@ public class FishingListener implements Listener {
/**
* @return If the fish is weak enough to be looted by the player.
*/
public boolean pull() {
public boolean pullOnce() {
last = System.currentTimeMillis();
return pulls++ > total;
currentPulls++;
return currentPulls >= fishStrength;
}
/**
* Critical fish's means you catch the fish on the very first try
*/
public boolean isCrit() {
return pulls > total + 1;
public boolean isCriticalFish() {
return currentPulls > fishStrength + 1;
}
private void close() {
@ -128,7 +133,7 @@ public class FishingListener implements Listener {
if (isTimedOut())
close();
location.getWorld().spawnParticle(Particle.CRIT, location, 0, 2 * (random.nextDouble() - .5), 3, 2 * (random.nextDouble() - .5), .6);
location.getWorld().spawnParticle(Particle.CRIT, location, 0, 2 * (RANDOM.nextDouble() - .5), 3, 2 * (RANDOM.nextDouble() - .5), .6);
}
@EventHandler
@ -143,54 +148,57 @@ public class FishingListener implements Listener {
return;
}
if (pulls == 0 && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
criticalFish();
if (currentPulls == 0 && RANDOM.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_CHANCE) / 100)
setCriticalFish();
// Check if enough pulls; if not, wait till the next fish event
if (!pull())
return;
// The fish is successfully looted from here
close();
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
MMOCoreUtils.decreaseDurability(player,
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
if (!isCrit() && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
return;
}
ItemStack collect = caught.collect(new LootBuilder(playerData, 0));
if (collect == null) {
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
return;
}
CustomPlayerFishEvent called = new CustomPlayerFishEvent(playerData, collect);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
// Calculate yeet velocity
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCrit() ? "-crit" : "")).message());
Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();
vec.setY(vec.getY() * .031 + vec.length() * .05);
vec.setX(vec.getX() * .08);
vec.setZ(vec.getZ() * .08);
item.setVelocity(vec);
player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0);
for (int j = 0; j < 16; j++)
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2,
4 * (random.nextDouble() - .5), .05);
if (MMOCore.plugin.fishingManager.hasLinkedProfession())
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), exp, EXPSource.FISHING, location);
if (pullOnce())
lootFish();
}
}
public void lootFish() {
close();
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
MMOCoreUtils.decreaseDurability(player,
(mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
// Critical fishing failure
if (!isCriticalFish() && RANDOM.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
return;
}
// Find looted item
ItemStack collect = caught.collect(new LootBuilder(playerData, 0));
if (collect == null) {
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
return;
}
// Call Bukkit event
CustomPlayerFishEvent called = new CustomPlayerFishEvent(playerData, collect);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
return;
// Calculate yeet velocity
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
MMOCore.plugin.configManager.getSimpleMessage("fish-out-water" + (isCriticalFish() ? "-crit" : "")).message());
Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();
vec.setY(vec.getY() * .031 + vec.length() * .05);
vec.setX(vec.getX() * .08);
vec.setZ(vec.getZ() * .08);
item.setVelocity(vec);
player.getWorld().playSound(player.getLocation(), VersionSound.BLOCK_NOTE_BLOCK_HAT.toSound(), 1, 0);
for (int j = 0; j < 8; j++)
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (RANDOM.nextDouble() - .5), RANDOM.nextDouble() + 1, 4 * (RANDOM.nextDouble() - .5), .08);
if (MMOCore.plugin.fishingManager.hasLinkedProfession())
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location);
}
}
}

View File

@ -13,7 +13,7 @@ import org.bukkit.potion.PotionEffectType;
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import io.lumine.mythic.lib.MythicLib;
public class PlayerCollectStats implements Listener {

View File

@ -7,7 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.util.math.particle.ChestParticleEffect;
import net.Indyuce.mmocore.loot.chest.particle.ChestParticleEffect;
public class TierEffect {
private final ChestParticleEffect type;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.api.util.math.particle;
package net.Indyuce.mmocore.loot.chest.particle;
import java.util.function.Consumer;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.api.util.math.particle;
package net.Indyuce.mmocore.loot.chest.particle;
import java.util.function.BiConsumer;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.api.util.math.particle;
package net.Indyuce.mmocore.loot.chest.particle;
import java.util.function.Consumer;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.api.util.math.particle;
package net.Indyuce.mmocore.loot.chest.particle;
import org.bukkit.Color;
import org.bukkit.Particle;

View File

@ -1,4 +1,4 @@
package net.Indyuce.mmocore.api.util.math.particle;
package net.Indyuce.mmocore.loot.chest.particle;
import org.bukkit.Location;
import org.bukkit.Particle;

View File

@ -1,16 +1,19 @@
package net.Indyuce.mmocore.loot.droptable.dropitem;
import net.Indyuce.mmocore.loot.LootBuilder;
import net.Indyuce.mmocore.api.util.item.CurrencyItem;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.util.item.CurrencyItemBuilder;
import net.Indyuce.mmocore.loot.LootBuilder;
import org.bukkit.inventory.ItemStack;
public class GoldDropItem extends DropItem {
public GoldDropItem(MMOLineConfig config) {
super(config);
}
public GoldDropItem(MMOLineConfig config) {
super(config);
}
@Override
public void collect(LootBuilder builder) {
builder.addLoot(new CurrencyItem("GOLD_COIN", 1, rollAmount()).build());
}
@Override
public void collect(LootBuilder builder) {
ItemStack item = new CurrencyItemBuilder("GOLD_COIN", 1).build();
item.setAmount(rollAmount());
builder.addLoot(item);
}
}

View File

@ -1,40 +0,0 @@
package net.Indyuce.mmocore.loot.droptable.dropitem;
import java.util.NoSuchElementException;
import io.lumine.xikage.mythicmobs.MythicMobs;
import io.lumine.xikage.mythicmobs.adapters.bukkit.BukkitAdapter;
import io.lumine.xikage.mythicmobs.drops.Drop;
import io.lumine.xikage.mythicmobs.drops.DropMetadata;
import io.lumine.xikage.mythicmobs.drops.DropTable;
import io.lumine.xikage.mythicmobs.drops.IItemDrop;
import io.lumine.xikage.mythicmobs.drops.LootBag;
import net.Indyuce.mmocore.loot.LootBuilder;
import io.lumine.mythic.lib.api.MMOLineConfig;
public class MMDropTableDropItem extends DropItem {
private final DropTable dropTable;
private static final DropMetadata metadata = new DropMetadata(null, null);
public MMDropTableDropItem(MMOLineConfig config) {
super(config);
config.validate("id");
String id = config.getString("id");
try {
dropTable = MythicMobs.inst().getDropManager().getDropTable(id).orElse(null);
} catch (NoSuchElementException exception) {
throw new IllegalArgumentException("Could not find MM drop table with ID '" + id + "'");
}
}
@Override
public void collect(LootBuilder builder) {
LootBag lootBag = dropTable.generate(metadata);
for (Drop type : lootBag.getDrops())
if (type instanceof IItemDrop)
builder.addLoot(BukkitAdapter.adapt(((IItemDrop) type).getDrop(metadata)));
}
}

Some files were not shown because too many files have changed in this diff Show More