From 092664183937400b3515a54ae629e45fcad1cc45 Mon Sep 17 00:00:00 2001 From: ASangarin Date: Sat, 13 Jun 2020 21:31:25 +0200 Subject: [PATCH] !More minor API changes --- .../mmocore/api/experience/EXPSource.java | 3 ++- .../api/experience/PlayerProfessions.java | 17 ++++++++++++----- .../source/type/ExperienceSource.java | 2 +- .../mmocore/api/player/social/Party.java | 6 +++++- .../api/quest/trigger/ExperienceTrigger.java | 2 +- .../command/rpg/admin/ExperienceCommandMap.java | 2 +- .../command/rpg/admin/LevelCommandMap.java | 2 +- .../listener/profession/FishingListener.java | 3 ++- 8 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java index a0104eb8..df28b5f7 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/EXPSource.java @@ -1,9 +1,10 @@ package net.Indyuce.mmocore.api.experience; public enum EXPSource { + SOURCE, COMMAND, VANILLA, QUEST, - SOURCE, + FISHING, OTHER; } diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java index 81e4d533..a39ce73d 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/PlayerProfessions.java @@ -17,6 +17,7 @@ import com.google.gson.JsonObject; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.ConfigMessage; +import net.Indyuce.mmocore.api.event.PlayerExperienceGainEvent; import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.util.math.particle.SmallParticleEffect; @@ -102,28 +103,34 @@ public class PlayerProfessions { exp.put(profession.getId(), value); } - public void giveLevels(Profession profession, int value) { + public void giveLevels(Profession profession, int value, EXPSource source) { int total = 0, level = getLevel(profession); while (value-- > 0) total += profession.getExpCurve().getExperience(level + value + 1); - giveExperience(profession, total); + giveExperience(profession, total, source); } - public void giveExperience(Profession profession, int value) { - giveExperience(profession, value, null); + public void giveExperience(Profession profession, int value, EXPSource source) { + giveExperience(profession, value, null, source); } public boolean hasReachedMaxLevel(Profession profession) { return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel(); } - public void giveExperience(Profession profession, int value, Location loc) { + public void giveExperience(Profession profession, int value, Location loc, EXPSource source) { if(hasReachedMaxLevel(profession)) { setExperience(profession, 0); return; } value = MMOCore.plugin.boosterManager.calculateExp(profession, value); + + PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source); + Bukkit.getPluginManager().callEvent(event); + if (event.isCancelled()) + return; + exp.put(profession.getId(), exp.containsKey(profession.getId()) ? exp.get(profession.getId()) + value : value); // display hologram diff --git a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java index 5c86ed5c..39d1d93b 100644 --- a/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/api/experience/source/type/ExperienceSource.java @@ -47,7 +47,7 @@ public abstract class ExperienceSource { public void giveExperience(PlayerData player, int amount, Location location) { if (hasProfession()) - player.getCollectionSkills().giveExperience(profession, amount, location == null ? player.getPlayer().getLocation() : location); + player.getCollectionSkills().giveExperience(profession, amount, location == null ? player.getPlayer().getLocation() : location, EXPSource.SOURCE); else player.giveExperience(amount, location == null ? player.getPlayer().getLocation() : location, EXPSource.SOURCE); } diff --git a/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java b/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java index 6e99c540..1fa364cc 100644 --- a/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java +++ b/src/main/java/net/Indyuce/mmocore/api/player/social/Party.java @@ -54,6 +54,10 @@ public class Party { } public void removeMember(PlayerData data) { + removeMember(data, true); + } + + public void removeMember(PlayerData data, boolean notify) { if (data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof PartyViewInventory) InventoryManager.PARTY_CREATION.newInventory(data).open(); @@ -72,7 +76,7 @@ public class Party { // transfer ownership if (owner.equals(data)) { owner = members.get(0); - MMOCore.plugin.configManager.getSimpleMessage("transfer-party-ownership").send(owner.getPlayer()); + if(notify) MMOCore.plugin.configManager.getSimpleMessage("transfer-party-ownership").send(owner.getPlayer()); } } diff --git a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java index fd1654ec..ca0a87ad 100644 --- a/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java +++ b/src/main/java/net/Indyuce/mmocore/api/quest/trigger/ExperienceTrigger.java @@ -32,7 +32,7 @@ public class ExperienceTrigger extends Trigger { if (profession == null) player.giveExperience(amount.calculateInt(), EXPSource.QUEST); else - player.getCollectionSkills().giveExperience(profession, amount.calculateInt()); + player.getCollectionSkills().giveExperience(profession, amount.calculateInt(), EXPSource.QUEST); } /* diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandMap.java index f727f97f..14177d52 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandMap.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/ExperienceCommandMap.java @@ -21,7 +21,7 @@ public class ExperienceCommandMap extends CommandMap { super(parent, "exp"); addFloor(new ActionCommandMap(this, "set", (data, value) -> data.setExperience(value), (professions, profession, value) -> professions.setExperience(profession, value))); - addFloor(new ActionCommandMap(this, "give", (data, value) -> data.giveExperience(value, data.getPlayer().getLocation(), EXPSource.COMMAND), (professions, profession, value) -> professions.giveExperience(profession, value, professions.getPlayerData().getPlayer().getLocation()))); + addFloor(new ActionCommandMap(this, "give", (data, value) -> data.giveExperience(value, data.getPlayer().getLocation(), EXPSource.COMMAND), (professions, profession, value) -> professions.giveExperience(profession, value, professions.getPlayerData().getPlayer().getLocation(), EXPSource.COMMAND))); } public class ActionCommandMap extends CommandEnd { diff --git a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandMap.java b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandMap.java index 7162979f..c1550458 100644 --- a/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandMap.java +++ b/src/main/java/net/Indyuce/mmocore/command/rpg/admin/LevelCommandMap.java @@ -21,7 +21,7 @@ public class LevelCommandMap extends CommandMap { super(parent, "level"); addFloor(new ActionCommandMap(this, "set", (data, value) -> data.setLevel(value), (professions, profession, value) -> professions.setLevel(profession, value))); - addFloor(new ActionCommandMap(this, "give", (data, value) -> data.giveLevels(value, EXPSource.COMMAND), (professions, profession, value) -> professions.giveLevels(profession, value))); + addFloor(new ActionCommandMap(this, "give", (data, value) -> data.giveLevels(value, EXPSource.COMMAND), (professions, profession, value) -> professions.giveLevels(profession, value, EXPSource.COMMAND))); } public class ActionCommandMap extends CommandEnd { diff --git a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java index 374eb0fe..fbd078d4 100644 --- a/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java +++ b/src/main/java/net/Indyuce/mmocore/listener/profession/FishingListener.java @@ -24,6 +24,7 @@ import org.bukkit.util.Vector; import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.api.droptable.dropitem.fishing.FishingDropItem; import net.Indyuce.mmocore.api.event.CustomPlayerFishEvent; +import net.Indyuce.mmocore.api.experience.EXPSource; import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.manager.profession.FishingManager.FishingDropTable; @@ -176,7 +177,7 @@ public class FishingListener implements Listener { location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (random.nextDouble() - .5), 2, 4 * (random.nextDouble() - .5), .05); if (MMOCore.plugin.professionManager.has("fishing")) - playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, location); + playerData.getCollectionSkills().giveExperience(MMOCore.plugin.professionManager.get("fishing"), exp, location, EXPSource.FISHING); } } }