diff --git a/pom.xml b/pom.xml index de31e9b4..34cc0da3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.Indyuce MMOCore - 1.9.5 + 1.9.5-SNAPSHOT MMOCore Offer your players a brand new RPG experience!! @@ -92,7 +92,7 @@ phoenix - http://la-grange-evasion.pro.dns-orange.fr:8081/ + https://la-grange-evasion.pro.dns-orange.fr/repository/maven-public/ @@ -161,7 +161,7 @@ io.lumine MythicLib-dist - 1.3.4 + 1.3.4-SNAPSHOT provided diff --git a/src/main/java/net/Indyuce/mmocore/api/event/MMOCommandEvent.java b/src/main/java/net/Indyuce/mmocore/api/event/MMOCommandEvent.java index 2e6527cc..998a7de3 100644 --- a/src/main/java/net/Indyuce/mmocore/api/event/MMOCommandEvent.java +++ b/src/main/java/net/Indyuce/mmocore/api/event/MMOCommandEvent.java @@ -5,6 +5,10 @@ import org.bukkit.event.HandlerList; import net.Indyuce.mmocore.api.player.PlayerData; +/** + * @deprecated Use Bukkit event instead + */ +@Deprecated public class MMOCommandEvent extends PlayerDataEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; diff --git a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java index 82ed628c..77dbeeba 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java @@ -902,13 +902,16 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc } @Override - public int hashCode() { - return mmoData.hashCode(); + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PlayerData that = (PlayerData) o; + return getUniqueId().equals(that.mmoData.getUniqueId()); } @Override - public boolean equals(Object obj) { - return obj instanceof PlayerData && ((PlayerData) obj).getUniqueId().equals(getUniqueId()); + public int hashCode() { + return mmoData.hashCode(); } public static PlayerData get(OfflinePlayer player) { diff --git a/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java b/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java index ab7a6bef..d8caa653 100644 --- a/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java +++ b/src/main/java/net/Indyuce/mmocore/command/PartyCommand.java @@ -1,11 +1,13 @@ package net.Indyuce.mmocore.command; -import java.util.UUID; - import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.event.MMOCommandEvent; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.player.social.Request; import net.Indyuce.mmocore.manager.InventoryManager; import net.Indyuce.mmocore.party.provided.MMOCorePartyModule; +import net.Indyuce.mmocore.party.provided.PartyInvite; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; @@ -13,65 +15,65 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.party.provided.PartyInvite; -import net.Indyuce.mmocore.api.player.social.Request; +import java.util.UUID; public class PartyCommand extends BukkitCommand { - public PartyCommand(ConfigurationSection config) { - super(config.getString("main")); - - setAliases(config.getStringList("aliases")); - setDescription("Opens the party menu."); - } + public PartyCommand(ConfigurationSection config) { + super(config.getString("main")); - @Override - public boolean execute(CommandSender sender, String label, String[] args) { - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.RED + "This command is for players only."); - return true; - } + setAliases(config.getStringList("aliases")); + setDescription("Opens the party menu."); + } - PlayerData data = PlayerData.get((OfflinePlayer) sender); - MMOCommandEvent event = new MMOCommandEvent(data, "party"); - Bukkit.getServer().getPluginManager().callEvent(event); - if(event.isCancelled()) return true; - - if (args.length > 1) { - UUID uuid; - try { - uuid = UUID.fromString(args[1]); - } catch (Exception e) { - return true; - } + @Override + public boolean execute(CommandSender sender, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is for players only."); + return true; + } - Request request = MMOCore.plugin.requestManager.getRequest(uuid); - if (!(request instanceof PartyInvite)) - return true; + PlayerData data = PlayerData.get((OfflinePlayer) sender); + MMOCommandEvent event = new MMOCommandEvent(data, "party"); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) return true; - if (request.isTimedOut()) { - MMOCore.plugin.requestManager.unregisterRequest(uuid); - return true; - } + if (args.length > 0) { - if (!((MMOCorePartyModule) MMOCore.plugin.partyModule).isRegistered(((PartyInvite) request).getParty())) { - MMOCore.plugin.requestManager.unregisterRequest(uuid); - return true; - } + final @Nullable PartyInvite invite; + if (args.length > 1) - if (args[0].equalsIgnoreCase("accept")) - request.accept(); - if (args[0].equalsIgnoreCase("deny")) - request.deny(); - return true; - } + // Search by request ID + try { + final Request req = MMOCore.plugin.requestManager.getRequest(UUID.fromString(args[1])); + Validate.isTrue(req instanceof PartyInvite && !req.isTimedOut()); + invite = (PartyInvite) req; + Validate.isTrue(((MMOCorePartyModule) MMOCore.plugin.partyModule).isRegistered(invite.getParty())); + } catch (Exception exception) { + return true; + } - if (data.getParty() != null) - InventoryManager.PARTY_VIEW.newInventory(data).open(); - else - InventoryManager.PARTY_CREATION.newInventory(data).open(); - return true; - } + // Search by target player + else + invite = MMOCore.plugin.requestManager.findRequest(data, PartyInvite.class); + + // No invite found with given identifier/target player + if (invite == null) + return true; + + if (args[0].equalsIgnoreCase("accept")) + invite.accept(); + else if (args[0].equalsIgnoreCase("deny")) + invite.deny(); + return true; + } + + if (data.getParty() != null) + InventoryManager.PARTY_VIEW.newInventory(data).open(); + else + InventoryManager.PARTY_CREATION.newInventory(data).open(); + return true; + } } diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java index e33d778e..f46c0554 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/dropitem/DropItem.java @@ -1,17 +1,15 @@ package net.Indyuce.mmocore.loot.droptable.dropitem; -import java.util.Random; - -import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.loot.LootBuilder; import io.lumine.mythic.lib.api.MMOLineConfig; -import org.bukkit.Bukkit; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; +import net.Indyuce.mmocore.loot.LootBuilder; + +import java.util.Random; public abstract class DropItem { protected static final Random random = new Random(); - private static final double CHANCE_COEFFICIENT = 7. / 100; private final double chance, weight; private final RandomAmount amount; @@ -39,8 +37,6 @@ public abstract class DropItem { return amount.calculateInt(); } - - /** * CHANCE stat = 0 | tier chances are unchanged * CHANCE stat = +inf | uniform law for any drop item @@ -48,19 +44,9 @@ public abstract class DropItem { * * @return The real weight of an item considering the player's CHANCE stat. */ - /** - * CHANCE stat = 0 | tier chances are unchanged - * CHANCE stat = +inf | uniform law for any drop item - * CHANCE stat = 100 | all tier chances are taken their square root - * - * @return The real weight of an item considering the player's CHANCE stat. - */ - /** - * If the player chance is 0 the random value will remain the same. When he get lucks the chance gets closer to one. - */ public boolean rollChance(PlayerData player) { - double value=random.nextDouble(); - return value< Math.pow(chance, 1 / Math.pow(1 + CHANCE_COEFFICIENT * player.getStats().getStat("CHANCE"), 1.0 / 3.0)); + double value = random.nextDouble(); + return value < Math.pow(chance, 1 / Math.pow(1 + CHANCE_COEFFICIENT * player.getStats().getStat("CHANCE"), 1.0 / 3.0)); } public abstract void collect(LootBuilder builder); diff --git a/src/main/java/net/Indyuce/mmocore/manager/social/RequestManager.java b/src/main/java/net/Indyuce/mmocore/manager/social/RequestManager.java index d6b1a70b..5fdcb85c 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/social/RequestManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/social/RequestManager.java @@ -1,6 +1,7 @@ package net.Indyuce.mmocore.manager.social; import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.social.Request; import net.Indyuce.mmocore.manager.MMOCoreManager; import org.bukkit.Bukkit; @@ -14,6 +15,20 @@ public class RequestManager implements MMOCoreManager { private boolean ENABLED; + /** + * The request map is NOT cleared, whatever state of the clearBefore + * boolean as it's useless because they are guaranteed to disappear with time. + * + * @param clearBefore Useless here + */ + @Override + public void initialize(boolean clearBefore) { + if (!ENABLED) { + Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, this::flushRequests, 60 * 20, 60 * 20 * 5); + ENABLED = true; + } + } + @NotNull public Request getRequest(UUID uuid) { return Objects.requireNonNull(requests.get(uuid), "Could not find request with UUID '" + uuid.toString() + "'"); @@ -23,6 +38,19 @@ public class RequestManager implements MMOCoreManager { requests.put(request.getUniqueId(), request); } + /** + * @param Class extending {@link Request} + * @return Tries to find and return any non timed-out request + * with given target player and request type. + */ + @Nullable + public T findRequest(PlayerData target, Class givenClass) { + for (Request req : requests.values()) + if (!req.isTimedOut() && req.getTarget().equals(target) && req.getClass().equals(givenClass)) + return (T) req; + return null; + } + @Nullable public Request unregisterRequest(UUID uuid) { return requests.remove(uuid); @@ -38,18 +66,4 @@ public class RequestManager implements MMOCoreManager { iterator.remove(); } } - - /** - * The request map is NOT cleared, whatever state of the clearBefore - * boolean as it's useless because they are guaranteed to disappear with time. - * - * @param clearBefore Useless here - */ - @Override - public void initialize(boolean clearBefore) { - if (!ENABLED) { - Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, this::flushRequests, 60 * 20, 60 * 20 * 5); - ENABLED = true; - } - } } diff --git a/src/main/java/net/Indyuce/mmocore/player/playerclass/ClassTrigger.java b/src/main/java/net/Indyuce/mmocore/player/playerclass/ClassTrigger.java index 4d5183f2..73755651 100644 --- a/src/main/java/net/Indyuce/mmocore/player/playerclass/ClassTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/player/playerclass/ClassTrigger.java @@ -3,10 +3,10 @@ package net.Indyuce.mmocore.player.playerclass; import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.MMOLineConfig; +import io.lumine.mythic.lib.script.Script; +import io.lumine.mythic.lib.script.mechanic.Mechanic; import io.lumine.mythic.lib.skill.SimpleSkill; import io.lumine.mythic.lib.skill.Skill; -import io.lumine.mythic.lib.skill.custom.CustomSkill; -import io.lumine.mythic.lib.skill.custom.mechanic.Mechanic; import io.lumine.mythic.lib.skill.handler.MythicLibSkillHandler; import io.lumine.mythic.lib.skill.result.SkillResult; import io.lumine.mythic.lib.skill.trigger.TriggerMetadata; @@ -34,7 +34,7 @@ import java.util.List; @Deprecated public class ClassTrigger { private final ClassTriggerType type; - private final CustomSkill skill = new CustomSkill("classTrigger", false); + private final Script skill = new Script("classTrigger", false); private final Skill castableSkill = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(skill)); public ClassTrigger(String triggerTypeString, List mechanicStringList) { diff --git a/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java b/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java index 386cd07a..f8981f7a 100644 --- a/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java +++ b/src/main/java/net/Indyuce/mmocore/skill/ClassSkill.java @@ -4,7 +4,7 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot; import io.lumine.mythic.lib.player.cooldown.CooldownObject; import io.lumine.mythic.lib.player.modifier.ModifierSource; import io.lumine.mythic.lib.player.skill.PassiveSkill; -import io.lumine.mythic.lib.skill.custom.condition.Condition; +import io.lumine.mythic.lib.script.condition.Condition; import net.Indyuce.mmocore.api.util.math.formula.IntegerLinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.player.PlayerData; diff --git a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ExperienceMechanic.java b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ExperienceMechanic.java index 61ae176e..4e19420e 100644 --- a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ExperienceMechanic.java +++ b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ExperienceMechanic.java @@ -1,7 +1,7 @@ package net.Indyuce.mmocore.skill.custom.mechanic; +import io.lumine.mythic.lib.script.mechanic.type.TargetMechanic; import io.lumine.mythic.lib.skill.SkillMetadata; -import io.lumine.mythic.lib.skill.custom.mechanic.type.TargetMechanic; import io.lumine.mythic.lib.util.DoubleFormula; import io.lumine.mythic.lib.util.configobject.ConfigObject; import net.Indyuce.mmocore.MMOCore; diff --git a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ManaMechanic.java b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ManaMechanic.java index 49f93831..7a01335a 100644 --- a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ManaMechanic.java +++ b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/ManaMechanic.java @@ -2,7 +2,7 @@ package net.Indyuce.mmocore.skill.custom.mechanic; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.skill.SkillMetadata; -import io.lumine.mythic.lib.skill.custom.mechanic.type.TargetMechanic; +import io.lumine.mythic.lib.script.mechanic.type.TargetMechanic; import io.lumine.mythic.lib.util.DoubleFormula; import io.lumine.mythic.lib.util.configobject.ConfigObject; import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; diff --git a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StaminaMechanic.java b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StaminaMechanic.java index 88f28384..52a9b865 100644 --- a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StaminaMechanic.java +++ b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StaminaMechanic.java @@ -2,7 +2,7 @@ package net.Indyuce.mmocore.skill.custom.mechanic; import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.skill.SkillMetadata; -import io.lumine.mythic.lib.skill.custom.mechanic.type.TargetMechanic; +import io.lumine.mythic.lib.script.mechanic.type.TargetMechanic; import io.lumine.mythic.lib.util.DoubleFormula; import io.lumine.mythic.lib.util.configobject.ConfigObject; import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent; diff --git a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StelliumMechanic.java b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StelliumMechanic.java index e104bbcb..c9fa301f 100644 --- a/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StelliumMechanic.java +++ b/src/main/java/net/Indyuce/mmocore/skill/custom/mechanic/StelliumMechanic.java @@ -1,8 +1,8 @@ package net.Indyuce.mmocore.skill.custom.mechanic; import io.lumine.mythic.lib.UtilityMethods; +import io.lumine.mythic.lib.script.mechanic.type.TargetMechanic; import io.lumine.mythic.lib.skill.SkillMetadata; -import io.lumine.mythic.lib.skill.custom.mechanic.type.TargetMechanic; import io.lumine.mythic.lib.util.DoubleFormula; import io.lumine.mythic.lib.util.configobject.ConfigObject; import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;