Debug Experience Sources

This commit is contained in:
Ka0rX 2022-07-26 16:48:23 +02:00
parent 2e5cb2b725
commit 2d05bd770b
8 changed files with 31 additions and 13 deletions

View File

@ -124,6 +124,10 @@ public class DefaultMMOLoader extends MMOLoader {
if (config.getKey().equals("climb"))
return new ClimbExperienceSource(dispenser, config);
if (config.getKey().equals("eat")) {
return new EatExperienceSource(dispenser, config);
}
if (config.getKey().equals("damagedealt"))
return new DamageDealtExperienceSource(dispenser, config);

View File

@ -338,7 +338,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
public void refreshVanillaExp() {
if (!isOnline() || !MMOCore.plugin.configManager.overrideVanillaExp)
return;
getPlayer().sendExperienceChange(0.01f);
getPlayer().setLevel(getLevel());
getPlayer().setExp(Math.max(0, Math.min(1, (float) experience / (float) getLevelUpExperience())));
}

View File

@ -27,6 +27,7 @@ import net.Indyuce.mmocore.player.stats.StatInfo;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;

View File

@ -4,15 +4,18 @@ import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.event.PlayerAttackEvent;
import io.lumine.mythic.lib.damage.DamagePacket;
import io.lumine.mythic.lib.damage.DamageType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import java.util.Arrays;
import java.util.Objects;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class DamageDealtExperienceSource extends SpecificExperienceSource<DamageType> {
@ -43,6 +46,7 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
return new ExperienceSourceManager<DamageDealtExperienceSource>() {
@EventHandler
public void onDamageDealt(PlayerAttackEvent e) {
PlayerData playerData = PlayerData.get(e.getPlayer());
for (DamageDealtExperienceSource source : getSources()) {
double value = 0;
@ -62,10 +66,13 @@ public class DamageDealtExperienceSource extends SpecificExperienceSource<Damage
@Override
public boolean matchesParameter(PlayerData player, DamageType damageType) {
if (type == null)
if (type == null) {
return true;
else
}
else {
return type.equals(damageType);
}
}
}

View File

@ -11,6 +11,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
public class EatExperienceSource extends SpecificExperienceSource<ItemStack> {
@ -36,13 +37,13 @@ public class EatExperienceSource extends SpecificExperienceSource<ItemStack> {
return new ExperienceSourceManager<EatExperienceSource>() {
@EventHandler
public void a(FoodLevelChangeEvent e) {
if (!(e.getEntity() instanceof Player) || e.getEntity().hasMetadata("NPC"))
return;
PlayerData playerData = PlayerData.get((OfflinePlayer) e.getEntity());
for (EatExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, e.getItem()))
source.giveExperience(playerData, e.getFoodLevel(), null);
public void a(PlayerItemConsumeEvent e) {
if(!e.getPlayer().hasMetadata("NPC")) {
PlayerData playerData = PlayerData.get(e.getPlayer());
for (EatExperienceSource source : getSources()) {
if (source.matchesParameter(playerData, e.getItem()))
source.giveExperience(playerData, 1, null);
}
}
}
};

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.manager.profession.ExperienceSourceManager;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -39,7 +40,8 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
@Override
public ExperienceSourceManager<MineBlockExperienceSource> newManager() {
return new ExperienceSourceManager<MineBlockExperienceSource>() {
return
new ExperienceSourceManager<MineBlockExperienceSource>() {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void a(BlockBreakEvent event) {
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL)
@ -63,11 +65,13 @@ public class MineBlockExperienceSource extends SpecificExperienceSource<Material
}
private boolean hasSilkTouch(ItemStack item) {
return item != null && item.hasItemMeta() && item.getItemMeta().hasEnchant(Enchantment.SILK_TOUCH);
}
@Override
public boolean matchesParameter(PlayerData player, Material obj) {
return material == obj;
}
}

View File

@ -6,6 +6,7 @@ import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import net.Indyuce.mmocore.api.player.PlayerData;
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;
@ -39,7 +40,8 @@ public class MoveExperienceSource extends SpecificExperienceSource {
double deltax = e.getTo().getBlockX() - e.getFrom().getBlockX();
double deltay = e.getTo().getBlockY() - e.getFrom().getBlockY();
double deltaz = e.getTo().getBlockZ() - e.getFrom().getBlockZ();
if (deltax != 0 && deltay != 0 && deltaz != 0) {
if (deltax != 0 || deltay != 0 || deltaz != 0) {
double delta = Math.sqrt(deltax * deltax + deltay * deltay + deltaz * deltaz);
if (e.getPlayer().hasMetadata("NPC"))
return;

View File

@ -126,7 +126,6 @@ public class PlayerStats extends EditableInventory {
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
String replaced;
if (holder.endsWith("_base")) {
StatInfo info = StatInfo.valueOf(UtilityMethods.enumName(holder.substring(0, holder.length() - 5)));
replaced = info.format(stats.getBase(info.name));