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