mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-23 09:41:23 +01:00
Debug for all the experience source.
Added VanillaExperience & Resource ExperienceSource and added inCombat for Playing Experience Source.
This commit is contained in:
parent
b7e3959ae6
commit
2411dae631
@ -1,6 +1,7 @@
|
||||
package net.Indyuce.mmocore.api.load;
|
||||
|
||||
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
|
||||
import net.Indyuce.mmocore.experience.source.*;
|
||||
import net.Indyuce.mmocore.loot.droptable.condition.*;
|
||||
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.NoteDropItem;
|
||||
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.api.quest.objective.ClickonObjective;
|
||||
import net.Indyuce.mmocore.api.quest.objective.GoToObjective;
|
||||
@ -105,7 +97,7 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
if(config.getKey().equals("distance"))
|
||||
if (config.getKey().equals("distance"))
|
||||
return new DistanceCondition(config);
|
||||
|
||||
if (config.getKey().equals("world"))
|
||||
@ -125,8 +117,35 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
|
||||
if (config.getKey().equals("fishitem"))
|
||||
return new FishItemExperienceSource(dispenser, config);
|
||||
if (config.getKey().equals("resource"))
|
||||
return new ResourceExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("vanillaexperience"))
|
||||
return new VanillaExperienceExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("climb"))
|
||||
return new ClimbExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("damagedealt"))
|
||||
return new DamageDealtExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("damagetaken"))
|
||||
return new DamageTakenExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("move"))
|
||||
return new MoveExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("play"))
|
||||
return new PlayExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("projectile"))
|
||||
return new ProjectileExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("ride"))
|
||||
return new RideExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("tame"))
|
||||
return new TameExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("killmob"))
|
||||
return new KillMobExperienceSource(dispenser, config);
|
||||
|
@ -16,7 +16,7 @@ public class ProfessionExperienceDispenser implements ExperienceDispenser {
|
||||
@Override
|
||||
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;
|
||||
: hologramLocation;
|
||||
playerData.getCollectionSkills().giveExperience(profession, experience, EXPSource.SOURCE, hologramLocation);
|
||||
}
|
||||
|
||||
|
@ -6,16 +6,18 @@ 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.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
|
||||
//Can be Ladder,Vines,Twisting Vines,Weeping Vines.
|
||||
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)
|
||||
* The xp given depends on the vertical distance travelled, the random amount given correspond
|
||||
* to the xp when you climb, one block
|
||||
@ -27,9 +29,10 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
|
||||
type = null;
|
||||
else {
|
||||
String str = config.getString("type").toUpperCase().replace("-", "_");
|
||||
Validate.isTrue(str.equals("ladder") ||
|
||||
str.equals("vines") || str.equals("twisting-vines") || str.equals("weeping-vines"),
|
||||
"The type must be ladder, vine, twisted-vines or weeping-vines");
|
||||
Validate.isTrue(str.equals("LADDER") ||
|
||||
str.equals("VINE") || str.equals("TWISTING_VINES_PLANT") || str.equals("WEEPING_VINES"),
|
||||
"ClimbExperienceSource problem: The type must be ladder, vine, twisted-vines or weeping-vines");
|
||||
|
||||
type = Material.valueOf(str);
|
||||
}
|
||||
|
||||
@ -42,14 +45,14 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
|
||||
return new ExperienceSourceManager<ClimbExperienceSource>() {
|
||||
@EventHandler
|
||||
public void onClimb(PlayerMoveEvent e) {
|
||||
if(e.getPlayer().hasMetadata("NPC"))
|
||||
if (e.getPlayer().hasMetadata("NPC"))
|
||||
return;
|
||||
PlayerData playerData=PlayerData.get(e.getPlayer());
|
||||
double delta=e.getTo().getY()-e.getFrom().getY();
|
||||
if(delta>0) {
|
||||
for(ClimbExperienceSource source:getSources()) {
|
||||
if(source.matchesParameter(playerData,e.getTo().getBlock().getType()))
|
||||
source.giveExperience(playerData,delta,null);
|
||||
PlayerData playerData = PlayerData.get(e.getPlayer());
|
||||
double delta = e.getTo().getY() - e.getFrom().getY();
|
||||
if (delta > 0) {
|
||||
for (ClimbExperienceSource source : getSources()) {
|
||||
if (source.matchesParameter(playerData, e.getFrom().getBlock().getType()))
|
||||
source.giveExperience(playerData, delta, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,7 +63,13 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
|
||||
public boolean matchesParameter(PlayerData player, Material material) {
|
||||
if (type == null)
|
||||
return material.equals(Material.LADDER) || material.equals(Material.VINE) ||
|
||||
material.equals(Material.WEEPING_VINES) || material.equals(Material.TWISTING_VINES);
|
||||
return type.equals(material);
|
||||
material.equals(Material.WEEPING_VINES) || material.equals(Material.TWISTING_VINES) ||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
|
||||
|
||||
public DamageDealtExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser, config);
|
||||
if (!config.contains("damage-type"))
|
||||
if (!config.contains("type"))
|
||||
type = null;
|
||||
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
|
||||
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.");
|
||||
type = DamageType.valueOf(str);
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.Indyuce.mmocore.experience.source;
|
||||
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import io.lumine.mythic.lib.damage.DamageType;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
|
||||
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
|
||||
@ -11,6 +12,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
@ -20,18 +22,18 @@ public class DamageTakenExperienceSource extends SpecificExperienceSource<Entity
|
||||
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.
|
||||
*/
|
||||
public DamageTakenExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser, config);
|
||||
if(!config.contains("damage-cause"))
|
||||
cause=null;
|
||||
if (!config.contains("cause"))
|
||||
cause = null;
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -44,18 +46,26 @@ public class DamageTakenExperienceSource extends SpecificExperienceSource<Entity
|
||||
if (e.getEntity() instanceof Player && !e.getEntity().hasMetadata("NPC")) {
|
||||
double amount = e.getDamage();
|
||||
PlayerData playerData = PlayerData.get((OfflinePlayer) e.getEntity());
|
||||
//We wait 2 tick to check if the player is Dead
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (DamageTakenExperienceSource source : getSources()) {
|
||||
if(source.matchesParameter(playerData,e.getCause()))
|
||||
if (source.matchesParameter(playerData, e.getCause()))
|
||||
source.giveExperience(playerData, amount, null);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(MMOCore.plugin, 2);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesParameter(PlayerData player, EntityDamageEvent.DamageCause damageCause) {
|
||||
if(cause==null)
|
||||
if (player.getPlayer().isDead())
|
||||
return false;
|
||||
if (cause == null)
|
||||
return true;
|
||||
return damageCause.equals(cause);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ 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.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@ -25,13 +26,13 @@ public class MoveExperienceSource extends SpecificExperienceSource {
|
||||
|
||||
public MoveExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser, config);
|
||||
if (!config.contains("moving-type"))
|
||||
if (!config.contains("type"))
|
||||
type = null;
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -44,6 +45,7 @@ public class MoveExperienceSource extends SpecificExperienceSource {
|
||||
if(e.getPlayer().hasMetadata("NPC"))
|
||||
return;
|
||||
Player player=e.getPlayer();
|
||||
|
||||
PlayerData playerData =PlayerData.get(player);
|
||||
for(MoveExperienceSource source:getSources()) {
|
||||
if(source.matchesParameter(playerData,null)) {
|
||||
@ -60,11 +62,11 @@ public class MoveExperienceSource extends SpecificExperienceSource {
|
||||
}
|
||||
|
||||
public enum MovingType {
|
||||
SNEAKING(Player::isSneaking),
|
||||
FLYING(Player::isFlying),
|
||||
SWIMMING(Player::isSwimming),
|
||||
SPRINTING(Player::isSprinting),
|
||||
WALKING((p) -> !p.isSneaking() && !p.isSprinting() && !p.isFlying() && !p.isSwimming());
|
||||
SNEAK(Player::isSneaking),
|
||||
FLY((p)->p.isFlying()||p.isGliding()),
|
||||
SWIM((p)->p.getLocation().getBlock().isLiquid()),
|
||||
SPRINT(Player::isSprinting),
|
||||
WALK((p) -> !p.isSneaking() && !p.isSprinting() && !p.isFlying() && !p.getLocation().getBlock().isLiquid());
|
||||
|
||||
private final Function<Player, Boolean> matching;
|
||||
|
||||
@ -73,7 +75,7 @@ public class MoveExperienceSource extends SpecificExperienceSource {
|
||||
}
|
||||
|
||||
public boolean matches(Player player) {
|
||||
return matching.apply(player);
|
||||
return !player.isInsideVehicle()&&matching.apply(player);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package net.Indyuce.mmocore.experience.source;
|
||||
|
||||
import io.lumine.mythic.bukkit.BukkitAdapter;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
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.loot.chest.RegionBounds;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -14,17 +12,24 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class PlayingExperienceSource extends SpecificExperienceSource {
|
||||
public class PlayExperienceSource extends SpecificExperienceSource {
|
||||
|
||||
private final World world;
|
||||
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.
|
||||
*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);
|
||||
if (!config.contains("in-combat"))
|
||||
inCombat = false;
|
||||
else {
|
||||
inCombat = config.getBoolean("in-combat");
|
||||
}
|
||||
|
||||
if (!config.contains("world"))
|
||||
world = null;
|
||||
@ -49,13 +54,16 @@ public class PlayingExperienceSource extends SpecificExperienceSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceSourceManager<PlayingExperienceSource> newManager() {
|
||||
public ExperienceSourceManager<PlayExperienceSource> newManager() {
|
||||
return new PlayingExperienceSourceManager();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesParameter(PlayerData player, Object obj) {
|
||||
if (inCombat && !player.isInCombat())
|
||||
return false;
|
||||
|
||||
if (world == null)
|
||||
return true;
|
||||
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() {
|
||||
new BukkitRunnable() {
|
||||
@ -74,7 +82,7 @@ public class PlayingExperienceSource extends SpecificExperienceSource {
|
||||
Bukkit.getOnlinePlayers().forEach((player) -> {
|
||||
if (!player.hasMetadata("NPC")) {
|
||||
PlayerData playerData = PlayerData.get(player);
|
||||
for (PlayingExperienceSource source : getSources()) {
|
||||
for (PlayExperienceSource source : getSources()) {
|
||||
if (source.matchesParameter(playerData, null))
|
||||
giveExperience(playerData, 1, null);
|
||||
}
|
@ -10,6 +10,7 @@ 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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -17,18 +18,26 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ProjectileExperienceSource extends SpecificExperienceSource<Projectile> {
|
||||
|
||||
ProjectileType projectileType;
|
||||
private final ProjectileType projectileType;
|
||||
|
||||
public ProjectileExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser, config);
|
||||
Validate.isTrue(config.contains("type"));
|
||||
projectileType = ProjectileType.valueOf(config.getString("type").toUpperCase().replace("-", "_"));
|
||||
if(!config.contains("type"))
|
||||
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
|
||||
@ -39,8 +48,8 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
|
||||
|
||||
@EventHandler
|
||||
public void onHit(EntityDamageByEntityEvent e) {
|
||||
Entity entity = e.getDamager();
|
||||
if (e.getEntity() instanceof Projectile) {
|
||||
|
||||
if (e.getDamager() instanceof Projectile) {
|
||||
Projectile projectile = (Projectile) e.getDamager();
|
||||
if (projectile.getShooter() instanceof Player && !((Player) projectile.getShooter()).hasMetadata("NPC")) {
|
||||
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
|
||||
@EventHandler
|
||||
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();
|
||||
if (player.hasMetadata("NPC"))
|
||||
return;
|
||||
@ -85,29 +94,28 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
|
||||
|
||||
@Override
|
||||
public boolean matchesParameter(PlayerData player, Projectile projectile) {
|
||||
if(projectileType==null)
|
||||
return true;
|
||||
return projectileType.matches(projectile);
|
||||
}
|
||||
|
||||
|
||||
public enum ProjectileType {
|
||||
ARROW(Arrow.class),
|
||||
TRIDENT(Trident.class),
|
||||
FIREBALL(Fireball.class),
|
||||
FISH_HOOK(FishHook.class),
|
||||
ARROW((p)-> p instanceof Arrow),
|
||||
TRIDENT((p)-> p instanceof Trident),
|
||||
FIREBALL((p)-> p instanceof Fireball),
|
||||
FISH_HOOK((p)-> p instanceof FishHook),
|
||||
;
|
||||
|
||||
private final Class<? extends Projectile> clazz;
|
||||
private final Function<Projectile,Boolean> matching;
|
||||
|
||||
ProjectileType(Class<? extends Projectile> clazz) {
|
||||
this.clazz = clazz;
|
||||
ProjectileType(Function<Projectile,Boolean> matching) {
|
||||
this.matching=matching;
|
||||
}
|
||||
|
||||
public Class<? extends Projectile> getType() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public boolean matches(Projectile projectile) {
|
||||
return projectile.getClass().isAssignableFrom(getType());
|
||||
return matching.apply(projectile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ 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.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -25,12 +26,12 @@ public class RideExperienceSource extends SpecificExperienceSource<Class<? exten
|
||||
*/
|
||||
public RideExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser, config);
|
||||
if (!config.contains("entity-type"))
|
||||
if (!config.contains("type"))
|
||||
type = null;
|
||||
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),
|
||||
"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);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
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.api.util.MMOCoreUtils;
|
||||
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.entity.EntityDamageByEntityEvent;
|
||||
|
||||
import javax.swing.text.html.parser.Entity;
|
||||
|
||||
public class TamingExperienceSource extends SpecificExperienceSource {
|
||||
public class TameExperienceSource extends SpecificExperienceSource {
|
||||
|
||||
|
||||
public TamingExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
public TameExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceSourceManager<TamingExperienceSource> newManager() {
|
||||
return new ExperienceSourceManager<TamingExperienceSource>() {
|
||||
public ExperienceSourceManager<TameExperienceSource> newManager() {
|
||||
return new ExperienceSourceManager<TameExperienceSource>() {
|
||||
@EventHandler
|
||||
public void onWolfHit(EntityDamageByEntityEvent e) {
|
||||
if(e.getDamager() instanceof Wolf) {
|
||||
Wolf wolf= (Wolf) e.getDamager();
|
||||
if(wolf.getOwner() instanceof Player &&!((Player) wolf.getOwner()).hasMetadata("NPC")) {
|
||||
PlayerData playerData=PlayerData.get((OfflinePlayer) wolf.getOwner());
|
||||
for(TamingExperienceSource source:getSources()) {
|
||||
for(TameExperienceSource source:getSources()) {
|
||||
source.giveExperience(playerData,e.getDamage(), MMOCoreUtils.getCenterLocation(e.getEntity()));
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -5,11 +5,13 @@ 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.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
|
||||
private final RandomAmount amount;
|
||||
double counter = 0;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user