forked from Upstream/mmocore
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3e28db8f35
@ -171,7 +171,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
<version>1.7</version>
|
||||
<version>1.7.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -9,6 +9,10 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Moved to MythicLib
|
||||
*/
|
||||
@Deprecated
|
||||
public class SoundObject {
|
||||
|
||||
@Nullable
|
||||
|
@ -801,7 +801,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
return false;
|
||||
|
||||
final double maxDis = MMOCore.plugin.configManager.partyMaxExpSplitRange;
|
||||
return maxDis <= 0 || pd.getPlayer().getLocation().distanceSquared(getPlayer().getLocation()) < maxDis * maxDis;
|
||||
return maxDis <= 0 || (pd.getPlayer().getWorld().equals(getPlayer().getWorld()) && pd.getPlayer().getLocation().distanceSquared(getPlayer().getLocation()) < maxDis * maxDis);
|
||||
}).collect(Collectors.toList());
|
||||
value /= (nearbyMembers.size() + 1);
|
||||
for (PlayerData member : nearbyMembers)
|
||||
|
@ -22,8 +22,9 @@ public class FromExperienceSource extends ExperienceSource {
|
||||
public FromExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser);
|
||||
|
||||
config.validateKeys("source");
|
||||
List<String> list = new ConfigFile("exp-sources").getConfig().getStringList(config.getString("source"));
|
||||
Validate.isTrue(list.size() != 0, "There is no source matching " + config.getString("key"));
|
||||
Validate.isTrue(list != null && !list.isEmpty(), "There is no source matching " + config.getString("source"));
|
||||
list.stream()
|
||||
.map(MMOLineConfig::new)
|
||||
.forEach(mmoLineConfig ->
|
||||
|
@ -3,9 +3,9 @@ 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.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.experience.EXPSource;
|
||||
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
|
||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -17,68 +17,70 @@ import org.bukkit.inventory.AnvilInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class RepairItemExperienceSource extends ExperienceSource<ItemStack> {
|
||||
@Nullable
|
||||
private final Material material;
|
||||
|
||||
public RepairItemExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
|
||||
super(dispenser);
|
||||
|
||||
/*
|
||||
* if material is null, the player can repair ANY material in order to
|
||||
* get experience.
|
||||
* If material is null, the player can repair
|
||||
* ANY material in order to get experience.
|
||||
*/
|
||||
material = config.contains("type") ? Material.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_")) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchesParameter(PlayerData player, ItemStack item) {
|
||||
return (material == null || item.getType() == material);
|
||||
return material == null || item.getType() == material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExperienceSourceManager<RepairItemExperienceSource> newManager() {
|
||||
return new ExperienceSourceManager<RepairItemExperienceSource>() {
|
||||
return new CustomExperienceManager();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void a(InventoryClickEvent event) {
|
||||
if (event.getInventory() != null && event.getInventory().getType() == InventoryType.ANVIL && event.getSlot() == 2) {
|
||||
private class CustomExperienceManager extends ExperienceSourceManager<RepairItemExperienceSource> {
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
PlayerData data = PlayerData.get((Player) event.getWhoClicked());
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void a(InventoryClickEvent event) {
|
||||
if (event.getInventory() == null || event.getInventory().getType() != InventoryType.ANVIL || event.getSlot() != 2)
|
||||
return;
|
||||
|
||||
for (RepairItemExperienceSource source : getSources())
|
||||
if (source.matches(data, item)) {
|
||||
// Check if there's exp associated to it
|
||||
final ItemStack item = event.getCurrentItem();
|
||||
if (!MMOCore.plugin.smithingManager.hasExperience(item.getType()))
|
||||
return;
|
||||
|
||||
if (!(event.getInventory() instanceof AnvilInventory))
|
||||
return;
|
||||
final PlayerData data = PlayerData.get((Player) event.getWhoClicked());
|
||||
for (RepairItemExperienceSource source : getSources())
|
||||
if (source.matches(data, item)) {
|
||||
|
||||
if (((AnvilInventory) event.getInventory()).getRepairCost() > ((Player) event.getWhoClicked()).getLevel())
|
||||
return;
|
||||
if (!(event.getInventory() instanceof AnvilInventory))
|
||||
return;
|
||||
|
||||
/*
|
||||
* make sure the items can actually be repaired
|
||||
* before getting the amount of durability repaired
|
||||
*/
|
||||
ItemStack old = event.getInventory().getItem(0);
|
||||
if (old == null || old.getType() == Material.AIR)
|
||||
return;
|
||||
if (old.getType().getMaxDurability() < 30 || item.getType().getMaxDurability() < 10)
|
||||
return;
|
||||
if (((AnvilInventory) event.getInventory()).getRepairCost() > ((Player) event.getWhoClicked()).getLevel())
|
||||
return;
|
||||
|
||||
if (!MMOCore.plugin.smithingManager.hasExperience(item.getType()))
|
||||
continue;
|
||||
/*
|
||||
* Make sure the items can actually be repaired
|
||||
* before getting the amount of durability repaired
|
||||
*/
|
||||
final ItemStack old = event.getInventory().getItem(0);
|
||||
if (old == null || old.getType() == Material.AIR || old.getType().getMaxDurability() < 30 || item.getType().getMaxDurability() < 10)
|
||||
return;
|
||||
|
||||
/*
|
||||
* calculate exp based on amount of durability which
|
||||
* was repaired, substract damage from old item
|
||||
* durability.
|
||||
*/
|
||||
double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType())
|
||||
* Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100;
|
||||
getDispenser().giveExperience(data, exp, data.getPlayer().getLocation(), EXPSource.SOURCE);
|
||||
}
|
||||
/*
|
||||
* Calculate exp based on amount of durability which was repaired,
|
||||
* substract damage from old item durability.
|
||||
*/
|
||||
final double exp = MMOCore.plugin.smithingManager.getBaseExperience(item.getType())
|
||||
* Math.max(0, ((Damageable) old.getItemMeta()).getDamage() - ((Damageable) item.getItemMeta()).getDamage()) / 100;
|
||||
getDispenser().giveExperience(data, exp, data.getPlayer().getLocation(), EXPSource.SOURCE);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,13 @@ public abstract class ExperienceSource<T> {
|
||||
return dispenser;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called ONCE per type of experience source.
|
||||
* This instanciates the manager for all of the exp sources
|
||||
* under that specific type.
|
||||
*
|
||||
* @return Instanciated experience source list
|
||||
*/
|
||||
public abstract ExperienceSourceManager<?> newManager();
|
||||
|
||||
public boolean matches(PlayerData player, T obj) {
|
||||
|
@ -1,44 +1,53 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.experience.ExpCurve;
|
||||
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ExperienceManager implements MMOCoreManager {
|
||||
private final Map<String, ExpCurve> expCurves = new HashMap<>();
|
||||
private final Map<String, ExperienceTable> expTables = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Experience sources from the exp-sources.yml config file where you can
|
||||
* input any exp source which can later be used along with the 'from'
|
||||
* exp source anywhere in the plugin.
|
||||
* <p>
|
||||
* TODO First needs to edit the exp-source current structure. This is going to break a lot of things
|
||||
*
|
||||
* @deprecated See TODO
|
||||
*/
|
||||
@Deprecated
|
||||
private final Map<String, List<ExperienceSource<?>>> publicExpSources = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Saves different experience sources based on experience source type.
|
||||
*/
|
||||
private final Map<Class<?>, ExperienceSourceManager<?>> managers = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public <T extends ExperienceSource> ExperienceSourceManager<T> getManager(Class<T> t) {
|
||||
return (ExperienceSourceManager<T>) managers.get(t);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ExperienceSource> void registerSource(T source) {
|
||||
Class<T> path = (Class<T>) source.getClass();
|
||||
|
||||
if (!managers.containsKey(path))
|
||||
managers.put(path, source.newManager());
|
||||
final Class<T> path = (Class<T>) source.getClass();
|
||||
managers.computeIfAbsent(path, unused -> source.newManager());
|
||||
getManager(path).registerSource(source);
|
||||
}
|
||||
|
||||
@ -51,6 +60,12 @@ public class ExperienceManager implements MMOCoreManager {
|
||||
return expCurves.get(id);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public List<ExperienceSource<?>> getExperienceSourceList(String key) {
|
||||
return publicExpSources.get(key);
|
||||
}
|
||||
|
||||
public boolean hasTable(String id) {
|
||||
return expTables.containsKey(id);
|
||||
}
|
||||
@ -88,7 +103,7 @@ public class ExperienceManager implements MMOCoreManager {
|
||||
managers.clear();
|
||||
}
|
||||
|
||||
expCurves.clear();
|
||||
// Exp curves
|
||||
for (File file : new File(MMOCore.plugin.getDataFolder() + "/expcurves").listFiles())
|
||||
try {
|
||||
ExpCurve curve = new ExpCurve(file);
|
||||
@ -97,7 +112,7 @@ public class ExperienceManager implements MMOCoreManager {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp curve '" + file.getName() + "': " + exception.getMessage());
|
||||
}
|
||||
|
||||
expTables.clear();
|
||||
// Exp tables
|
||||
FileConfiguration expTablesConfig = new ConfigFile("exp-tables").getConfig();
|
||||
for (String key : expTablesConfig.getKeys(false))
|
||||
try {
|
||||
|
@ -4,7 +4,6 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.OfflinePlayerData;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
@ -17,7 +16,6 @@ import net.Indyuce.mmocore.skill.ClassSkill;
|
||||
import net.Indyuce.mmocore.tree.SkillTreeNode;
|
||||
import net.Indyuce.mmocore.tree.skilltree.SkillTree;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -4,10 +4,10 @@ import io.lumine.mythic.lib.UtilityMethods;
|
||||
import io.lumine.mythic.lib.api.player.EquipmentSlot;
|
||||
import io.lumine.mythic.lib.player.PlayerMetadata;
|
||||
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
|
||||
import net.Indyuce.mmocore.api.SoundObject;
|
||||
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.skill.cast.PlayerKey;
|
||||
import net.Indyuce.mmocore.api.SoundObject;
|
||||
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
Loading…
Reference in New Issue
Block a user