Debug experience sources EventHandler annotation.

This commit is contained in:
Ka0rX 2022-08-27 16:09:21 +02:00
parent 4d793e721b
commit dfcb97d3c8
9 changed files with 32 additions and 11 deletions

View File

@ -10,6 +10,9 @@ 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 static org.bukkit.event.EventPriority.HIGHEST;
import static org.bukkit.event.EventPriority.MONITOR;
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;
@ -41,7 +44,7 @@ public class ClimbExperienceSource extends SpecificExperienceSource<Material> {
@Override @Override
public ExperienceSourceManager<ClimbExperienceSource> newManager() { public ExperienceSourceManager<ClimbExperienceSource> newManager() {
return new ExperienceSourceManager<ClimbExperienceSource>() { return new ExperienceSourceManager<ClimbExperienceSource>() {
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
public void onClimb(PlayerMoveEvent e) { public void onClimb(PlayerMoveEvent e) {
double delta=e.getTo().getBlockY()-e.getFrom().getBlockY(); double delta=e.getTo().getBlockY()-e.getFrom().getBlockY();
if (delta > 0) { if (delta > 0) {

View File

@ -10,11 +10,14 @@ 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.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.bukkit.event.EventPriority.MONITOR;
public class DamageDealtExperienceSource extends SpecificExperienceSource<DamageType> { public class DamageDealtExperienceSource extends SpecificExperienceSource<DamageType> {
private final DamageType type; private final DamageType type;
@ -41,9 +44,9 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
@Override @Override
public ExperienceSourceManager<DamageDealtExperienceSource> newManager() { public ExperienceSourceManager<DamageDealtExperienceSource> newManager() {
return new ExperienceSourceManager<DamageDealtExperienceSource>() { return new ExperienceSourceManager<DamageDealtExperienceSource>() {
@EventHandler //It isn't triggered when the PlayerAttackEvent gets cancelled
@EventHandler(priority = MONITOR,ignoreCancelled = true)
public void onDamageDealt(PlayerAttackEvent e) { public void onDamageDealt(PlayerAttackEvent e) {
PlayerData playerData = PlayerData.get(e.getPlayer()); PlayerData playerData = PlayerData.get(e.getPlayer());
for (DamageDealtExperienceSource source : getSources()) { for (DamageDealtExperienceSource source : getSources()) {
double value = 0; double value = 0;

View File

@ -17,6 +17,8 @@ import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.bukkit.event.EventPriority.HIGHEST;
public class DamageTakenExperienceSource extends SpecificExperienceSource<EntityDamageEvent.DamageCause> { public class DamageTakenExperienceSource extends SpecificExperienceSource<EntityDamageEvent.DamageCause> {
private final EntityDamageEvent.DamageCause cause; private final EntityDamageEvent.DamageCause cause;
@ -40,7 +42,8 @@ public class DamageTakenExperienceSource extends SpecificExperienceSource<Entity
@Override @Override
public ExperienceSourceManager<DamageTakenExperienceSource> newManager() { public ExperienceSourceManager<DamageTakenExperienceSource> newManager() {
return new ExperienceSourceManager<DamageTakenExperienceSource>() { return new ExperienceSourceManager<DamageTakenExperienceSource>() {
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
public void onDamageTaken(EntityDamageEvent e) { public void onDamageTaken(EntityDamageEvent e) {
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();

View File

@ -11,6 +11,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import static org.bukkit.event.EventPriority.MONITOR;
public class EatExperienceSource extends SpecificExperienceSource<ItemStack> { public class EatExperienceSource extends SpecificExperienceSource<ItemStack> {
private final Material type; private final Material type;
@ -33,7 +35,7 @@ public class EatExperienceSource extends SpecificExperienceSource<ItemStack> {
public ExperienceSourceManager<EatExperienceSource> newManager() { public ExperienceSourceManager<EatExperienceSource> newManager() {
return new ExperienceSourceManager<EatExperienceSource>() { return new ExperienceSourceManager<EatExperienceSource>() {
@EventHandler @EventHandler(priority = MONITOR,ignoreCancelled = true)
public void a(PlayerItemConsumeEvent e) { public void a(PlayerItemConsumeEvent e) {
if(!e.getPlayer().hasMetadata("NPC")) { if(!e.getPlayer().hasMetadata("NPC")) {
PlayerData playerData = PlayerData.get(e.getPlayer()); PlayerData playerData = PlayerData.get(e.getPlayer());

View File

@ -15,6 +15,8 @@ import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.bukkit.event.EventPriority.MONITOR;
public class MoveExperienceSource extends SpecificExperienceSource { public class MoveExperienceSource extends SpecificExperienceSource {
private final MovingType type; private final MovingType type;
@ -34,7 +36,7 @@ public class MoveExperienceSource extends SpecificExperienceSource {
@Override @Override
public ExperienceSourceManager<MoveExperienceSource> newManager() { public ExperienceSourceManager<MoveExperienceSource> newManager() {
return new ExperienceSourceManager<MoveExperienceSource>() { return new ExperienceSourceManager<MoveExperienceSource>() {
@EventHandler @EventHandler(priority = MONITOR,ignoreCancelled = true)
public void onMove(PlayerMoveEvent e) { public void onMove(PlayerMoveEvent e) {
double deltax = e.getTo().getBlockX() - e.getFrom().getBlockX(); double deltax = e.getTo().getBlockX() - e.getFrom().getBlockX();
double deltay = e.getTo().getBlockY() - e.getFrom().getBlockY(); double deltay = e.getTo().getBlockY() - e.getFrom().getBlockY();

View File

@ -23,6 +23,8 @@ import java.util.HashMap;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.bukkit.event.EventPriority.HIGHEST;
public class ProjectileExperienceSource extends SpecificExperienceSource<Projectile> { public class ProjectileExperienceSource extends SpecificExperienceSource<Projectile> {
private final ProjectileType projectileType; private final ProjectileType projectileType;
@ -43,14 +45,14 @@ public class ProjectileExperienceSource extends SpecificExperienceSource<Project
return new ExperienceSourceManager<ProjectileExperienceSource>() { return new ExperienceSourceManager<ProjectileExperienceSource>() {
HashMap<Projectile, Location> projectiles = new HashMap<>(); HashMap<Projectile, Location> projectiles = new HashMap<>();
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
public void onHit(ProjectileHitEvent e) { public void onHit(ProjectileHitEvent e) {
if (e.getHitBlock() != null && projectiles.containsKey(e.getEntity())) if (e.getHitBlock() != null && projectiles.containsKey(e.getEntity()))
projectiles.remove(e.getEntity()); projectiles.remove(e.getEntity());
} }
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
public void onDamage(EntityDamageByEntityEvent e) { public void onDamage(EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Projectile) { if (e.getEntity() instanceof Projectile) {

View File

@ -10,6 +10,8 @@ import net.Indyuce.mmocore.api.event.PlayerResourceUpdateEvent;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import static org.bukkit.event.EventPriority.HIGHEST;
public class ResourceExperienceSource extends SpecificExperienceSource<PlayerResource> { public class ResourceExperienceSource extends SpecificExperienceSource<PlayerResource> {
private final PlayerResource resource; private final PlayerResource resource;
@ -34,7 +36,7 @@ public class ResourceExperienceSource extends SpecificExperienceSource<PlayerRes
@Override @Override
public ExperienceSourceManager<ResourceExperienceSource> newManager() { public ExperienceSourceManager<ResourceExperienceSource> newManager() {
return new ExperienceSourceManager<ResourceExperienceSource>() { return new ExperienceSourceManager<ResourceExperienceSource>() {
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
public void onResource(PlayerResourceUpdateEvent e) { public void onResource(PlayerResourceUpdateEvent e) {
if (e.getPlayer().hasMetadata("NPC")) if (e.getPlayer().hasMetadata("NPC"))
return; return;

View File

@ -15,6 +15,8 @@ import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.bukkit.event.EventPriority.HIGHEST;
public class RideExperienceSource extends SpecificExperienceSource<EntityType> { public class RideExperienceSource extends SpecificExperienceSource<EntityType> {
private final EntityType type; private final EntityType type;
@ -39,7 +41,7 @@ public class RideExperienceSource extends SpecificExperienceSource<EntityType> {
@Override @Override
public ExperienceSourceManager<RideExperienceSource> newManager() { public ExperienceSourceManager<RideExperienceSource> newManager() {
return new ExperienceSourceManager<RideExperienceSource>() { return new ExperienceSourceManager<RideExperienceSource>() {
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
public void onRide(PlayerMoveEvent e) { public void onRide(PlayerMoveEvent e) {
if (e.getPlayer().isInsideVehicle()) { if (e.getPlayer().isInsideVehicle()) {

View File

@ -12,6 +12,8 @@ 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 static org.bukkit.event.EventPriority.HIGHEST;
public class TameExperienceSource extends SpecificExperienceSource { public class TameExperienceSource extends SpecificExperienceSource {
public TameExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) { public TameExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config); super(dispenser, config);
@ -21,7 +23,7 @@ public class TameExperienceSource extends SpecificExperienceSource {
public ExperienceSourceManager<TameExperienceSource> newManager() { public ExperienceSourceManager<TameExperienceSource> newManager() {
return new ExperienceSourceManager<TameExperienceSource>() { return new ExperienceSourceManager<TameExperienceSource>() {
@EventHandler @EventHandler(priority = HIGHEST,ignoreCancelled = true)
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();