Debug for all the experience source.

Added VanillaExperience & Resource ExperienceSource and added inCombat for Playing Experience Source.
This commit is contained in:
Guillaume 2022-05-08 11:14:58 +02:00
parent b7e3959ae6
commit 2411dae631
13 changed files with 332 additions and 172 deletions

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.api.load; package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.*;
import net.Indyuce.mmocore.loot.droptable.condition.*; import net.Indyuce.mmocore.loot.droptable.condition.*;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -12,15 +13,6 @@ import net.Indyuce.mmocore.loot.droptable.dropitem.DropTableDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.GoldDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.NoteDropItem;
import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem; import net.Indyuce.mmocore.loot.droptable.dropitem.VanillaDropItem;
import net.Indyuce.mmocore.experience.source.BrewPotionExperienceSource;
import net.Indyuce.mmocore.experience.source.CraftItemExperienceSource;
import net.Indyuce.mmocore.experience.source.EnchantItemExperienceSource;
import net.Indyuce.mmocore.experience.source.FishItemExperienceSource;
import net.Indyuce.mmocore.experience.source.KillMobExperienceSource;
import net.Indyuce.mmocore.experience.source.MineBlockExperienceSource;
import net.Indyuce.mmocore.experience.source.PlaceBlockExperienceSource;
import net.Indyuce.mmocore.experience.source.RepairItemExperienceSource;
import net.Indyuce.mmocore.experience.source.SmeltItemExperienceSource;
import net.Indyuce.mmocore.experience.source.type.ExperienceSource; import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
import net.Indyuce.mmocore.api.quest.objective.ClickonObjective; import net.Indyuce.mmocore.api.quest.objective.ClickonObjective;
import net.Indyuce.mmocore.api.quest.objective.GoToObjective; import net.Indyuce.mmocore.api.quest.objective.GoToObjective;
@ -40,130 +32,157 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
public class DefaultMMOLoader extends MMOLoader { public class DefaultMMOLoader extends MMOLoader {
@Override @Override
public Trigger loadTrigger(MMOLineConfig config) { public Trigger loadTrigger(MMOLineConfig config) {
if (config.getKey().equals("message")) if (config.getKey().equals("message"))
return new MessageTrigger(config); return new MessageTrigger(config);
if (config.getKey().equals("sound") || config.getKey().equals("playsound")) if (config.getKey().equals("sound") || config.getKey().equals("playsound"))
return new SoundTrigger(config); return new SoundTrigger(config);
if (config.getKey().equals("mana")) if (config.getKey().equals("mana"))
return new ManaTrigger(config); return new ManaTrigger(config);
if (config.getKey().equals("stamina")) if (config.getKey().equals("stamina"))
return new StaminaTrigger(config); return new StaminaTrigger(config);
if (config.getKey().equals("stellium"))
return new StelliumTrigger(config);
if (config.getKey().equals("command")) if (config.getKey().equals("stellium"))
return new CommandTrigger(config); return new StelliumTrigger(config);
if (config.getKey().equals("item") || config.getKey().equals("vanilla")) if (config.getKey().equals("command"))
return new ItemTrigger(config); return new CommandTrigger(config);
if (config.getKey().equals("exp") || config.getKey().equals("experience")) if (config.getKey().equals("item") || config.getKey().equals("vanilla"))
return new ExperienceTrigger(config); return new ItemTrigger(config);
return null; if (config.getKey().equals("exp") || config.getKey().equals("experience"))
} return new ExperienceTrigger(config);
@Override return null;
public DropItem loadDropItem(MMOLineConfig config) { }
if (config.getKey().equals("droptable"))
return new DropTableDropItem(config);
if (config.getKey().equals("vanilla")) @Override
return new VanillaDropItem(config); public DropItem loadDropItem(MMOLineConfig config) {
if (config.getKey().equals("droptable"))
return new DropTableDropItem(config);
if (config.getKey().equals("note")) if (config.getKey().equals("vanilla"))
return new NoteDropItem(config); return new VanillaDropItem(config);
if (config.getKey().equals("gold") || config.getKey().equals("coin")) if (config.getKey().equals("note"))
return new GoldDropItem(config); return new NoteDropItem(config);
return null; if (config.getKey().equals("gold") || config.getKey().equals("coin"))
} return new GoldDropItem(config);
@Override return null;
public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) { }
if (config.getKey().equals("goto"))
return new GoToObjective(section, config);
if (config.getKey().equals("mineblock")) @Override
return new MineBlockObjective(section, config); public Objective loadObjective(MMOLineConfig config, ConfigurationSection section) {
if (config.getKey().equals("goto"))
return new GoToObjective(section, config);
if (config.getKey().equals("killmob")) if (config.getKey().equals("mineblock"))
return new KillMobObjective(section, config); return new MineBlockObjective(section, config);
if (config.getKey().equals("clickon")) if (config.getKey().equals("killmob"))
return new ClickonObjective(section, config); return new KillMobObjective(section, config);
return null; if (config.getKey().equals("clickon"))
} return new ClickonObjective(section, config);
@Override return null;
public Condition loadCondition(MMOLineConfig config) { }
if(config.getKey().equals("distance"))
return new DistanceCondition(config);
if (config.getKey().equals("world")) @Override
return new WorldCondition(config); public Condition loadCondition(MMOLineConfig config) {
if (config.getKey().equals("distance"))
return new DistanceCondition(config);
if (config.getKey().equals("biome")) if (config.getKey().equals("world"))
return new BiomeCondition(config); return new WorldCondition(config);
if (config.getKey().equals("level")) if (config.getKey().equals("biome"))
return new LevelCondition(config); return new BiomeCondition(config);
if (config.getKey().equals("permission"))
return new PermissionCondition(config);
return null; if (config.getKey().equals("level"))
} return new LevelCondition(config);
@Override if (config.getKey().equals("permission"))
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) { return new PermissionCondition(config);
if (config.getKey().equals("fishitem"))
return new FishItemExperienceSource(dispenser, config);
if (config.getKey().equals("killmob")) return null;
return new KillMobExperienceSource(dispenser, config); }
if (config.getKey().equals("mineblock")) @Override
return new MineBlockExperienceSource(dispenser, config); public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
if (config.getKey().equals("resource"))
return new ResourceExperienceSource(dispenser, config);
if (config.getKey().equals("placeblock")) if (config.getKey().equals("vanillaexperience"))
return new PlaceBlockExperienceSource(dispenser, config); return new VanillaExperienceExperienceSource(dispenser, config);
if (config.getKey().equals("brewpotion")) if (config.getKey().equals("climb"))
return new BrewPotionExperienceSource(dispenser, config); return new ClimbExperienceSource(dispenser, config);
if (config.getKey().equals("smeltitem")) if (config.getKey().equals("damagedealt"))
return new SmeltItemExperienceSource(dispenser, config); return new DamageDealtExperienceSource(dispenser, config);
if (config.getKey().equals("enchantitem")) if (config.getKey().equals("damagetaken"))
return new EnchantItemExperienceSource(dispenser, config); return new DamageTakenExperienceSource(dispenser, config);
if (config.getKey().equals("repairitem")) if (config.getKey().equals("move"))
return new RepairItemExperienceSource(dispenser, config); return new MoveExperienceSource(dispenser, config);
if (config.getKey().equals("craftitem")) if (config.getKey().equals("play"))
return new CraftItemExperienceSource(dispenser, config); return new PlayExperienceSource(dispenser, config);
return null; if (config.getKey().equals("projectile"))
} return new ProjectileExperienceSource(dispenser, config);
@Override if (config.getKey().equals("ride"))
public BlockType loadBlockType(MMOLineConfig config) { return new RideExperienceSource(dispenser, config);
if (config.getKey().equalsIgnoreCase("vanilla")) if (config.getKey().equals("tame"))
return new VanillaBlockType(config); return new TameExperienceSource(dispenser, config);
if (config.getKey().equalsIgnoreCase("skull") || config.getKey().equals("head") || config.getKey().equals("playerhead"))
return new SkullBlockType(config);
return null; if (config.getKey().equals("killmob"))
} return new KillMobExperienceSource(dispenser, config);
if (config.getKey().equals("mineblock"))
return new MineBlockExperienceSource(dispenser, config);
if (config.getKey().equals("placeblock"))
return new PlaceBlockExperienceSource(dispenser, config);
if (config.getKey().equals("brewpotion"))
return new BrewPotionExperienceSource(dispenser, config);
if (config.getKey().equals("smeltitem"))
return new SmeltItemExperienceSource(dispenser, config);
if (config.getKey().equals("enchantitem"))
return new EnchantItemExperienceSource(dispenser, config);
if (config.getKey().equals("repairitem"))
return new RepairItemExperienceSource(dispenser, config);
if (config.getKey().equals("craftitem"))
return new CraftItemExperienceSource(dispenser, config);
return null;
}
@Override
public BlockType loadBlockType(MMOLineConfig config) {
if (config.getKey().equalsIgnoreCase("vanilla"))
return new VanillaBlockType(config);
if (config.getKey().equalsIgnoreCase("skull") || config.getKey().equals("head") || config.getKey().equals("playerhead"))
return new SkullBlockType(config);
return null;
}
} }

View File

@ -16,7 +16,7 @@ public class ProfessionExperienceDispenser implements ExperienceDispenser {
@Override @Override
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) { public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null hologramLocation = !profession.getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null
: hologramLocation == null ? getPlayerLocation(playerData) : hologramLocation; : hologramLocation;
playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation); playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation);
} }

View File

@ -6,16 +6,18 @@ import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;
public class ClimbExperienceSource extends SpecificExperienceSource<Material> { public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
//Can be Ladder,Vines,Twisting Vines,Weeping Vines. //Can be Ladder,Vines,Twisting Vines,Weeping Vines.
private final Material type; private final Material type;
/** /**
*Gives Experience when a player climbs on a ladder, a vine, a twisting vine or a weeping vine depending * Gives Experience when a player climbs on a ladder, a vine, a twisting vine or a weeping vine depending
* on the type precised (if no type is precised it will give xp for the 4) * on the type precised (if no type is precised it will give xp for the 4)
* The xp given depends on the vertical distance travelled, the random amount given correspond * The xp given depends on the vertical distance travelled, the random amount given correspond
* to the xp when you climb, one block * to the xp when you climb, one block
@ -27,9 +29,10 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
type = null; type = null;
else { else {
String str = config.getString("type").toUpperCase().replace("-", "_"); String str = config.getString("type").toUpperCase().replace("-", "_");
Validate.isTrue(str.equals("ladder") || Validate.isTrue(str.equals("LADDER") ||
str.equals("vines") || str.equals("twisting-vines") || str.equals("weeping-vines"), str.equals("VINE") || str.equals("TWISTING_VINES_PLANT") || str.equals("WEEPING_VINES"),
"The type must be ladder, vine, twisted-vines or weeping-vines"); "ClimbExperienceSource problem: The type must be ladder, vine, twisted-vines or weeping-vines");
type = Material.valueOf(str); type = Material.valueOf(str);
} }
@ -42,14 +45,14 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
return new ExperienceSourceManager<ClimbExperienceSource>() { return new ExperienceSourceManager<ClimbExperienceSource>() {
@EventHandler @EventHandler
public void onClimb(PlayerMoveEvent e) { public void onClimb(PlayerMoveEvent e) {
if(e.getPlayer().hasMetadata("NPC")) if (e.getPlayer().hasMetadata("NPC"))
return; return;
PlayerData playerData=PlayerData.get(e.getPlayer()); PlayerData playerData = PlayerData.get(e.getPlayer());
double delta=e.getTo().getY()-e.getFrom().getY(); double delta = e.getTo().getY() - e.getFrom().getY();
if(delta>0) { if (delta > 0) {
for(ClimbExperienceSource source:getSources()) { for (ClimbExperienceSource source : getSources()) {
if(source.matchesParameter(playerData,e.getTo().getBlock().getType())) if (source.matchesParameter(playerData, e.getFrom().getBlock().getType()))
source.giveExperience(playerData,delta,null); source.giveExperience(playerData, delta, null);
} }
} }
} }
@ -60,7 +63,13 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
public boolean matchesParameter(PlayerData player, Material material) { public boolean matchesParameter(PlayerData player, Material material) {
if (type == null) if (type == null)
return material.equals(Material.LADDER) || material.equals(Material.VINE) || return material.equals(Material.LADDER) || material.equals(Material.VINE) ||
material.equals(Material.WEEPING_VINES) || material.equals(Material.TWISTING_VINES); material.equals(Material.WEEPING_VINES) || material.equals(Material.TWISTING_VINES) ||
return type.equals(material); material.equals(Material.WEEPING_VINES_PLANT) || material.equals(Material.TWISTING_VINES_PLANT);
if (type.equals(Material.WEEPING_VINES))
return material.equals(Material.WEEPING_VINES) || material.equals(Material.WEEPING_VINES_PLANT);
if (type.equals(Material.TWISTING_VINES))
return material.equals(Material.TWISTING_VINES) || material.equals(Material.TWISTING_VINES_PLANT);
return material.equals(type);
} }
} }

View File

@ -26,13 +26,13 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
public DamageDealtExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public DamageDealtExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
if (!config.contains("damage-type")) if (!config.contains("type"))
type = null; type = null;
else { else {
String str = config.getString("damage-type").toUpperCase().replace("-", "_"); String str = config.getString("type").toUpperCase().replace("-", "_");
//Checks if the damage type correspond to a value of the damage type enum //Checks if the damage type correspond to a value of the damage type enum
Validate.isTrue(Arrays.stream(DamageType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str), Validate.isTrue(Arrays.stream(DamageType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str),
"damage-type value not allowed. Damage type value allowed: magic, physical, weapon, skill, projectile," + "Type value not allowed. Type value allowed: magic, physical, weapon, skill, projectile," +
" unarmed, on-hit, minion, dot."); " unarmed, on-hit, minion, dot.");
type = DamageType.valueOf(str); type = DamageType.valueOf(str);

View File

@ -2,6 +2,7 @@ package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.damage.DamageType; import io.lumine.mythic.lib.damage.DamageType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
@ -11,6 +12,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
@ -20,18 +22,18 @@ public class DamageTakenExperienceSource extends SpecificExperienceSource<Entity
private final EntityDamageEvent.DamageCause cause; private final EntityDamageEvent.DamageCause cause;
/** /**
*Gives experience when a player takes damage from a certain cause. If no cause is given it will give xp for all * Gives experience when a player takes damage from a certain cause. If no cause is given it will give xp for all
* the damage causes. The random value you give correspond to the xp you get per damage taken. * the damage causes. The random value you give correspond to the xp you get per damage taken.
*/ */
public DamageTakenExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public DamageTakenExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
if(!config.contains("damage-cause")) if (!config.contains("cause"))
cause=null; cause = null;
else { else {
String str = config.getString("damage-cause").toUpperCase().replace("-", "_"); String str = config.getString("cause").toUpperCase().replace("-", "_");
//Checks if the damage type correspond to a value of the damage type enum //Checks if the damage type correspond to a value of the damage type enum
Validate.isTrue(Arrays.stream(EntityDamageEvent.DamageCause.values()).map(Objects::toString).collect(Collectors.toList()).contains(str), Validate.isTrue(Arrays.stream(EntityDamageEvent.DamageCause.values()).map(Objects::toString).collect(Collectors.toList()).contains(str),
"damage-type value not allowed. Go check at all the Damage Causes in EntityDamageEvent.DamageCause enum."); "Cause not allowed. Go check at all the Damage Causes in EntityDamageEvent.DamageCause enum.");
cause = EntityDamageEvent.DamageCause.valueOf(str); cause = EntityDamageEvent.DamageCause.valueOf(str);
} }
} }
@ -44,10 +46,16 @@ public class DamageTakenExperienceSource extends SpecificExperienceSource<Entity
if (e.getEntity() instanceof Player && !e.getEntity().hasMetadata("NPC")) { if (e.getEntity() instanceof Player && !e.getEntity().hasMetadata("NPC")) {
double amount = e.getDamage(); double amount = e.getDamage();
PlayerData playerData = PlayerData.get((OfflinePlayer) e.getEntity()); PlayerData playerData = PlayerData.get((OfflinePlayer) e.getEntity());
for (DamageTakenExperienceSource source : getSources()) { //We wait 2 tick to check if the player is Dead
if(source.matchesParameter(playerData,e.getCause())) new BukkitRunnable() {
source.giveExperience(playerData, amount, null); @Override
} public void run() {
for (DamageTakenExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, e.getCause()))
source.giveExperience(playerData, amount, null);
}
}
}.runTaskLater(MMOCore.plugin, 2);
} }
} }
}; };
@ -55,7 +63,9 @@ public class DamageTakenExperienceSource extends SpecificExperienceSource<Entity
@Override @Override
public boolean matchesParameter(PlayerData player, EntityDamageEvent.DamageCause damageCause) { public boolean matchesParameter(PlayerData player, EntityDamageEvent.DamageCause damageCause) {
if(cause==null) if (player.getPlayer().isDead())
return false;
if (cause == null)
return true; return true;
return damageCause.equals(cause); return damageCause.equals(cause);
} }

View File

@ -8,6 +8,7 @@ import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
@ -25,13 +26,13 @@ public class MoveExperienceSource extends SpecificExperienceSource {
public MoveExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public MoveExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
if (!config.contains("moving-type")) if (!config.contains("type"))
type = null; type = null;
else { else {
String str = config.getString("moving-type").toUpperCase().replace("-", "_"); String str = config.getString("type").toUpperCase().replace("-", "_");
//Checks if the damage type correspond to a value of the damage type enum //Checks if the damage type correspond to a value of the damage type enum
Validate.isTrue(Arrays.stream(MoveExperienceSource.MovingType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str), Validate.isTrue(Arrays.stream(MoveExperienceSource.MovingType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str),
"moving-type value not allowed. Moving type values allowed: sneaking, flying, swimming, sprinting, walking."); "moving-type value not allowed. Moving type values allowed: sneak, fly, swim, sprint, walk.");
type = MovingType.valueOf(str); type = MovingType.valueOf(str);
} }
} }
@ -44,6 +45,7 @@ public class MoveExperienceSource extends SpecificExperienceSource {
if(e.getPlayer().hasMetadata("NPC")) if(e.getPlayer().hasMetadata("NPC"))
return; return;
Player player=e.getPlayer(); Player player=e.getPlayer();
PlayerData playerData =PlayerData.get(player); PlayerData playerData =PlayerData.get(player);
for(MoveExperienceSource source:getSources()) { for(MoveExperienceSource source:getSources()) {
if(source.matchesParameter(playerData,null)) { if(source.matchesParameter(playerData,null)) {
@ -60,11 +62,11 @@ public class MoveExperienceSource extends SpecificExperienceSource {
} }
public enum MovingType { public enum MovingType {
SNEAKING(Player::isSneaking), SNEAK(Player::isSneaking),
FLYING(Player::isFlying), FLY((p)->p.isFlying()||p.isGliding()),
SWIMMING(Player::isSwimming), SWIM((p)->p.getLocation().getBlock().isLiquid()),
SPRINTING(Player::isSprinting), SPRINT(Player::isSprinting),
WALKING((p) -> !p.isSneaking() && !p.isSprinting() && !p.isFlying() && !p.isSwimming()); WALK((p) -> !p.isSneaking() && !p.isSprinting() && !p.isFlying() && !p.getLocation().getBlock().isLiquid());
private final Function<Player, Boolean> matching; private final Function<Player, Boolean> matching;
@ -73,7 +75,7 @@ public class MoveExperienceSource extends SpecificExperienceSource {
} }
public boolean matches(Player player) { public boolean matches(Player player) {
return matching.apply(player); return !player.isInsideVehicle()&&matching.apply(player);
} }
} }

View File

@ -1,12 +1,10 @@
package net.Indyuce.mmocore.experience.source; package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.bukkit.BukkitAdapter;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.loot.chest.RegionBounds;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -14,17 +12,24 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class PlayingExperienceSource extends SpecificExperienceSource { public class PlayExperienceSource extends SpecificExperienceSource {
private final World world; private final World world;
private final double x1, x2, z1, z2; private final double x1, x2, z1, z2;
private final boolean inCombat;
/** /**
* Experience source giving the specified amount of xp to all the players online each second in certain world bounds. * Experience source giving the specified amount of xp to all the players online each second in certain world bounds.
*If no bounds are given, it will give the xp to every player online. * If no bounds are given, it will give the xp to every player online. You can also specifiy if the player
* has to be inCombat or not to get the xp.
*/ */
public PlayingExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public PlayExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
if (!config.contains("in-combat"))
inCombat = false;
else {
inCombat = config.getBoolean("in-combat");
}
if (!config.contains("world")) if (!config.contains("world"))
world = null; world = null;
@ -49,13 +54,16 @@ public class PlayingExperienceSource extends SpecificExperienceSource {
} }
@Override @Override
public ExperienceSourceManager<PlayingExperienceSource> newManager() { public ExperienceSourceManager<PlayExperienceSource> newManager() {
return new PlayingExperienceSourceManager(); return new PlayingExperienceSourceManager();
} }
@Override @Override
public boolean matchesParameter(PlayerData player, Object obj) { public boolean matchesParameter(PlayerData player, Object obj) {
if (inCombat && !player.isInCombat())
return false;
if (world == null) if (world == null)
return true; return true;
Location location = player.getPlayer().getLocation(); Location location = player.getPlayer().getLocation();
@ -64,7 +72,7 @@ public class PlayingExperienceSource extends SpecificExperienceSource {
} }
private class PlayingExperienceSourceManager extends ExperienceSourceManager<PlayingExperienceSource> { private class PlayingExperienceSourceManager extends ExperienceSourceManager<PlayExperienceSource> {
public PlayingExperienceSourceManager() { public PlayingExperienceSourceManager() {
new BukkitRunnable() { new BukkitRunnable() {
@ -74,7 +82,7 @@ public class PlayingExperienceSource extends SpecificExperienceSource {
Bukkit.getOnlinePlayers().forEach((player) -> { Bukkit.getOnlinePlayers().forEach((player) -> {
if (!player.hasMetadata("NPC")) { if (!player.hasMetadata("NPC")) {
PlayerData playerData = PlayerData.get(player); PlayerData playerData = PlayerData.get(player);
for (PlayingExperienceSource source : getSources()) { for (PlayExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, null)) if (source.matchesParameter(playerData, null))
giveExperience(playerData, 1, null); giveExperience(playerData, 1, null);
} }

View File

@ -10,6 +10,7 @@ import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -17,18 +18,26 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ProjectileExperienceSource extends SpecificExperienceSource<Projectile> { public class ProjectileExperienceSource extends SpecificExperienceSource<Projectile> {
ProjectileType projectileType; private final ProjectileType projectileType;
public ProjectileExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public ProjectileExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
Validate.isTrue(config.contains("type")); if(!config.contains("type"))
projectileType = ProjectileType.valueOf(config.getString("type").toUpperCase().replace("-", "_")); projectileType=null;
else {
String str=config.getString("type").toUpperCase().replace("-", "_");
Validate.isTrue(Arrays.stream(ProjectileType.values()).map(ProjectileType::toString).collect(Collectors.toList()).contains(str));
projectileType = ProjectileType.valueOf(str);
}
} }
@Override @Override
@ -39,8 +48,8 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
@EventHandler @EventHandler
public void onHit(EntityDamageByEntityEvent e) { public void onHit(EntityDamageByEntityEvent e) {
Entity entity = e.getDamager();
if (e.getEntity() instanceof Projectile) { if (e.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) e.getDamager(); Projectile projectile = (Projectile) e.getDamager();
if (projectile.getShooter() instanceof Player && !((Player) projectile.getShooter()).hasMetadata("NPC")) { if (projectile.getShooter() instanceof Player && !((Player) projectile.getShooter()).hasMetadata("NPC")) {
Player player = (Player) projectile.getShooter(); Player player = (Player) projectile.getShooter();
@ -61,7 +70,7 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
//Mark every arrow with the the location at which it was shot to calculate the distance //Mark every arrow with the the location at which it was shot to calculate the distance
@EventHandler @EventHandler
public void onLaunch(ProjectileLaunchEvent e) { public void onLaunch(ProjectileLaunchEvent e) {
if (e.getEntity().getShooter() instanceof Player && e.getEntity() instanceof Arrow) { if (e.getEntity().getShooter() instanceof Player) {
Player player = (Player) e.getEntity().getShooter(); Player player = (Player) e.getEntity().getShooter();
if (player.hasMetadata("NPC")) if (player.hasMetadata("NPC"))
return; return;
@ -85,29 +94,28 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
@Override @Override
public boolean matchesParameter(PlayerData player, Projectile projectile) { public boolean matchesParameter(PlayerData player, Projectile projectile) {
if(projectileType==null)
return true;
return projectileType.matches(projectile); return projectileType.matches(projectile);
} }
public enum ProjectileType { public enum ProjectileType {
ARROW(Arrow.class), ARROW((p)-> p instanceof Arrow),
TRIDENT(Trident.class), TRIDENT((p)-> p instanceof Trident),
FIREBALL(Fireball.class), FIREBALL((p)-> p instanceof Fireball),
FISH_HOOK(FishHook.class), FISH_HOOK((p)-> p instanceof FishHook),
; ;
private final Class<? extends Projectile> clazz; private final Function<Projectile,Boolean> matching;
ProjectileType(Class<? extends Projectile> clazz) { ProjectileType(Function<Projectile,Boolean> matching) {
this.clazz = clazz; this.matching=matching;
} }
public Class<? extends Projectile> getType() {
return clazz;
}
public boolean matches(Projectile projectile) { public boolean matches(Projectile projectile) {
return projectile.getClass().isAssignableFrom(getType()); return matching.apply(projectile);
} }
} }

View File

@ -0,0 +1,63 @@
package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
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;
import org.bukkit.event.EventHandler;
import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;
public class ResourceExperienceSource extends SpecificExperienceSource<PlayerResource> {
private final PlayerResource resource;
/**
* Gives experience when the player uses a specific resoure. If no resource is precised it will trigger for
* mana, stamina and stellium. The amount specified si the xp given per resource consummed.
*/
public ResourceExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config);
if (!config.contains("resource"))
resource = null;
else {
String str = config.getString("resource").toUpperCase().replace("-", "_");
Validate.isTrue(str.equals("MANA") || str.equals("STELLIUM") || str.equals("STAMINA"),
"ResourceExperienceSource problem: The resource can only be mana, stamina or STELLIUM");
resource = PlayerResource.valueOf(str);
}
}
@Override
public ExperienceSourceManager<ResourceExperienceSource> newManager() {
return new ExperienceSourceManager<ResourceExperienceSource>() {
@EventHandler
public void onResource(PlayerResourceUpdateEvent e) {
if (e.getPlayer().hasMetadata("NPC"))
return;
PlayerData playerData = PlayerData.get(e.getPlayer());
if(e.getAmount()<0)
for (ResourceExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, e.getResource()))
source.giveExperience(playerData, -e.getAmount(), null);
}
}
};
}
@Override
public boolean matchesParameter(PlayerData player, PlayerResource obj) {
if (resource == null)
return !obj.equals(PlayerResource.HEALTH);
return resource.equals(obj);
}
}

View File

@ -6,6 +6,7 @@ import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -25,12 +26,12 @@ public class RideExperienceSource extends SpecificExperienceSource<Class<? exten
*/ */
public RideExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public RideExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
if (!config.contains("entity-type")) if (!config.contains("type"))
type = null; type = null;
else { else {
String str = config.getString("entity-type").toUpperCase().replace("-", "_"); String str = config.getString("type").toUpperCase().replace("-", "_");
Validate.isTrue(Arrays.stream(EntityType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str), Validate.isTrue(Arrays.stream(EntityType.values()).map(Objects::toString).collect(Collectors.toList()).contains(str),
"The entity-type must correspond to an entity that exist in the game."); "The type must correspond to an entity that exist in the game.");
type=EntityType.valueOf(str); type=EntityType.valueOf(str);
} }

View File

@ -1,7 +1,6 @@
package net.Indyuce.mmocore.experience.source; package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
@ -13,25 +12,23 @@ import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import javax.swing.text.html.parser.Entity; public class TameExperienceSource extends SpecificExperienceSource {
public class TamingExperienceSource extends SpecificExperienceSource {
public TamingExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public TameExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
} }
@Override @Override
public ExperienceSourceManager<TamingExperienceSource> newManager() { public ExperienceSourceManager<TameExperienceSource> newManager() {
return new ExperienceSourceManager<TamingExperienceSource>() { return new ExperienceSourceManager<TameExperienceSource>() {
@EventHandler @EventHandler
public void onWolfHit(EntityDamageByEntityEvent e) { public void onWolfHit(EntityDamageByEntityEvent e) {
if(e.getDamager() instanceof Wolf) { if(e.getDamager() instanceof Wolf) {
Wolf wolf= (Wolf) e.getDamager(); Wolf wolf= (Wolf) e.getDamager();
if(wolf.getOwner() instanceof Player &&!((Player) wolf.getOwner()).hasMetadata("NPC")) { if(wolf.getOwner() instanceof Player &&!((Player) wolf.getOwner()).hasMetadata("NPC")) {
PlayerData playerData=PlayerData.get((OfflinePlayer) wolf.getOwner()); PlayerData playerData=PlayerData.get((OfflinePlayer) wolf.getOwner());
for(TamingExperienceSource source:getSources()) { for(TameExperienceSource source:getSources()) {
source.giveExperience(playerData,e.getDamage(), MMOCoreUtils.getCenterLocation(e.getEntity())); source.giveExperience(playerData,e.getDamage(), MMOCoreUtils.getCenterLocation(e.getEntity()));
} }
} }

View File

@ -0,0 +1,39 @@
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.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.apache.commons.lang.Validate;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerExpChangeEvent;
public class VanillaExperienceExperienceSource extends SpecificExperienceSource {
public VanillaExperienceExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config);
}
@Override
public ExperienceSourceManager<VanillaExperienceExperienceSource> newManager() {
return new ExperienceSourceManager<VanillaExperienceExperienceSource>() {
@EventHandler
public void onExp(PlayerExpChangeEvent e) {
if(e.getPlayer().hasMetadata("NPC"))
return;
PlayerData playerData=PlayerData.get(e.getPlayer());
for(VanillaExperienceExperienceSource source:getSources()) {
if(source.matchesParameter(playerData,null))
giveExperience(playerData,e.getAmount(),null);
}
}
};
}
@Override
public boolean matchesParameter(PlayerData player, Object obj) {
return true;
}
}

View File

@ -5,11 +5,13 @@ import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser; import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> { public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
private final RandomAmount amount; private final RandomAmount amount;
double counter = 0;
/** /**
* Used to register experience sources with SPECIFIC experience outputs. * Used to register experience sources with SPECIFIC experience outputs.
@ -42,6 +44,8 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
* @param hologramLocation Location used to display the exp hologram * @param hologramLocation Location used to display the exp hologram
*/ */
public void giveExperience(PlayerData player, double multiplier, @Nullable Location hologramLocation) { public void giveExperience(PlayerData player, double multiplier, @Nullable Location hologramLocation) {
counter+=rollAmount() * multiplier;
Bukkit.broadcastMessage("Gave xp " + counter+ " from " + this.getClass().getSimpleName());
getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation, EXPSource.SOURCE); getDispenser().giveExperience(player, rollAmount() * multiplier, hologramLocation, EXPSource.SOURCE);
} }
} }