forked from Upstream/mmocore
mmocoreManager code cleanup
This commit is contained in:
parent
c1f3829e63
commit
e92cb8e67a
@ -70,7 +70,6 @@ public class MMOCore extends LuminePlugin {
|
|||||||
public final SkillManager skillManager = new SkillManager();
|
public final SkillManager skillManager = new SkillManager();
|
||||||
public final ClassManager classManager = new ClassManager();
|
public final ClassManager classManager = new ClassManager();
|
||||||
public final DropTableManager dropTableManager = new DropTableManager();
|
public final DropTableManager dropTableManager = new DropTableManager();
|
||||||
public final CustomBlockManager mineManager = new CustomBlockManager();
|
|
||||||
public final BoosterManager boosterManager = new BoosterManager();
|
public final BoosterManager boosterManager = new BoosterManager();
|
||||||
public final AttributeManager attributeManager = new AttributeManager();
|
public final AttributeManager attributeManager = new AttributeManager();
|
||||||
public final PartyManager partyManager = new PartyManager();
|
public final PartyManager partyManager = new PartyManager();
|
||||||
@ -79,9 +78,8 @@ public class MMOCore extends LuminePlugin {
|
|||||||
public final net.Indyuce.mmocore.manager.ExperienceManager experience = new net.Indyuce.mmocore.manager.ExperienceManager();
|
public final net.Indyuce.mmocore.manager.ExperienceManager experience = new net.Indyuce.mmocore.manager.ExperienceManager();
|
||||||
public final LootChestManager lootChests = new LootChestManager();
|
public final LootChestManager lootChests = new LootChestManager();
|
||||||
|
|
||||||
/*
|
// Profession managers
|
||||||
* professions
|
public final net.Indyuce.mmocore.manager.profession.CustomBlockManager mineManager = new net.Indyuce.mmocore.manager.profession.CustomBlockManager();
|
||||||
*/
|
|
||||||
public final FishingManager fishingManager = new FishingManager();
|
public final FishingManager fishingManager = new FishingManager();
|
||||||
public final AlchemyManager alchemyManager = new AlchemyManager();
|
public final AlchemyManager alchemyManager = new AlchemyManager();
|
||||||
public final EnchantManager enchantManager = new EnchantManager();
|
public final EnchantManager enchantManager = new EnchantManager();
|
||||||
@ -206,7 +204,7 @@ public class MMOCore extends LuminePlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadPlugin();
|
initializePlugin(false);
|
||||||
|
|
||||||
if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
|
if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
|
||||||
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
|
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
|
||||||
@ -336,45 +334,39 @@ public class MMOCore extends LuminePlugin {
|
|||||||
lootChests.getActive().forEach(chest -> chest.unregister(false));
|
lootChests.getActive().forEach(chest -> chest.unregister(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadPlugin() {
|
/**
|
||||||
|
* Called either when the server starts when initializing the manager for
|
||||||
|
* the first time, or when issuing a plugin reload; in that case, stuff
|
||||||
|
* like listeners must all be cleared before.
|
||||||
|
*
|
||||||
|
* Also see {@link MMOCoreManager}
|
||||||
|
*
|
||||||
|
* @param clearBefore True when issuing a plugin reload
|
||||||
|
*/
|
||||||
|
public void initializePlugin(boolean clearBefore) {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
|
||||||
configManager = new ConfigManager();
|
configManager = new ConfigManager();
|
||||||
|
|
||||||
skillManager.reload();
|
skillManager.reload();
|
||||||
|
|
||||||
mineManager.clear();
|
mineManager.initialize(clearBefore);
|
||||||
mineManager.reload();
|
partyManager.initialize(clearBefore);
|
||||||
|
attributeManager.initialize(clearBefore);
|
||||||
|
|
||||||
fishingManager.clear();
|
// Experience must be loaded before professions and classes
|
||||||
alchemyManager.clear();
|
experience.initialize(clearBefore);
|
||||||
smithingManager.clear();
|
|
||||||
|
|
||||||
partyManager.clear();
|
// Drop tables must be loaded before professions
|
||||||
partyManager.reload();
|
dropTableManager.initialize(clearBefore);
|
||||||
|
|
||||||
attributeManager.clear();
|
professionManager.initialize(clearBefore);
|
||||||
attributeManager.reload();
|
classManager.initialize(clearBefore);
|
||||||
|
|
||||||
// experience must be loaded before professions and classes
|
|
||||||
experience.reload();
|
|
||||||
|
|
||||||
// drop tables must be loaded before professions
|
|
||||||
dropTableManager.clear();
|
|
||||||
dropTableManager.reload();
|
|
||||||
|
|
||||||
professionManager.clear();
|
|
||||||
professionManager.reload();
|
|
||||||
|
|
||||||
classManager.clear();
|
|
||||||
classManager.reload();
|
|
||||||
|
|
||||||
InventoryManager.load();
|
InventoryManager.load();
|
||||||
|
|
||||||
questManager.clear();
|
questManager.initialize(clearBefore);
|
||||||
questManager.reload();
|
lootChests.initialize(clearBefore);
|
||||||
|
|
||||||
lootChests.reload();
|
|
||||||
|
|
||||||
waypointManager = new WaypointManager(new ConfigFile("waypoints").getConfig());
|
waypointManager = new WaypointManager(new ConfigFile("waypoints").getConfig());
|
||||||
restrictionManager = new RestrictionManager(new ConfigFile("restrictions").getConfig());
|
restrictionManager = new RestrictionManager(new ConfigFile("restrictions").getConfig());
|
||||||
|
@ -91,20 +91,31 @@ public class PlayerData extends OfflinePlayerData implements Closable {
|
|||||||
*/
|
*/
|
||||||
private boolean fullyLoaded = false;
|
private boolean fullyLoaded = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the player data was loaded using temporary data.
|
||||||
|
* See {@link TemporaryPlayerData} for more info
|
||||||
|
*/
|
||||||
|
private final boolean usingTemporaryData;
|
||||||
|
|
||||||
public PlayerData(MMOPlayerData mmoData) {
|
public PlayerData(MMOPlayerData mmoData) {
|
||||||
|
this(mmoData, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerData(MMOPlayerData mmoData, TemporaryPlayerData tempData) {
|
||||||
|
this(mmoData, true);
|
||||||
|
|
||||||
|
mana = tempData.getDouble("mana");
|
||||||
|
stamina = tempData.getDouble("stamina");
|
||||||
|
stellium = tempData.getDouble("stellium");
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlayerData(MMOPlayerData mmoData, boolean usingTemporaryData) {
|
||||||
super(mmoData.getUniqueId());
|
super(mmoData.getUniqueId());
|
||||||
|
|
||||||
this.mmoData = mmoData;
|
this.mmoData = mmoData;
|
||||||
this.playerStats = new PlayerStats(this);
|
this.playerStats = new PlayerStats(this);
|
||||||
this.questData = new PlayerQuests(this);
|
this.questData = new PlayerQuests(this);
|
||||||
}
|
this.usingTemporaryData = usingTemporaryData;
|
||||||
|
|
||||||
public PlayerData(MMOPlayerData mmoData, TemporaryPlayerData tempData) {
|
|
||||||
this(mmoData);
|
|
||||||
|
|
||||||
mana = tempData.getDouble("mana");
|
|
||||||
stamina = tempData.getDouble("stamina");
|
|
||||||
stellium = tempData.getDouble("stellium");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -660,6 +671,10 @@ public class PlayerData extends OfflinePlayerData implements Closable {
|
|||||||
this.fullyLoaded = true;
|
this.fullyLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasUsedTemporaryData() {
|
||||||
|
return usingTemporaryData;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isCasting() {
|
public boolean isCasting() {
|
||||||
return skillCasting != null;
|
return skillCasting != null;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public class PlayerClass extends PostLoadObject {
|
|||||||
actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null;
|
actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null;
|
||||||
|
|
||||||
expCurve = config.contains("exp-curve")
|
expCurve = config.contains("exp-curve")
|
||||||
? MMOCore.plugin.experience.getOrThrow(
|
? MMOCore.plugin.experience.getCurveOrThrow(
|
||||||
config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
|
config.get("exp-curve").toString().toLowerCase().replace("_", "-").replace(" ", "-"))
|
||||||
: ExpCurve.DEFAULT;
|
: ExpCurve.DEFAULT;
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public class PlayerClass extends PostLoadObject {
|
|||||||
for (String key : config.getStringList("main-exp-sources"))
|
for (String key : config.getStringList("main-exp-sources"))
|
||||||
try {
|
try {
|
||||||
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser);
|
ExperienceSource<?> source = MMOCore.plugin.loadManager.loadExperienceSource(new MMOLineConfig(key), dispenser);
|
||||||
MMOCore.plugin.professionManager.registerExpSource(source);
|
MMOCore.plugin.experience.registerSource(source);
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '"
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp source '" + key + "' from class '"
|
||||||
+ id + "': " + exception.getMessage());
|
+ id + "': " + exception.getMessage());
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
package net.Indyuce.mmocore.api.player.profess.event;
|
package net.Indyuce.mmocore.api.player.profess.event;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||||
|
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
/**
|
||||||
|
* @deprecated Replaced by {@link ExperienceTable} and will
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
* be removed in 1.8.4
|
||||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
*/
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
@Deprecated
|
||||||
|
|
||||||
public class EventTrigger {
|
public class EventTrigger {
|
||||||
private final String event;
|
private final String event;
|
||||||
private final Set<Trigger> triggers = new LinkedHashSet<>();
|
private final Set<Trigger> triggers = new LinkedHashSet<>();
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
package net.Indyuce.mmocore.api.player.profess.event;
|
package net.Indyuce.mmocore.api.player.profess.event;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Replaced by {@link ExperienceTable} and will
|
||||||
|
* be removed in 1.8.4
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface EventTriggerHandler extends Listener {
|
public interface EventTriggerHandler extends Listener {
|
||||||
boolean handles(String event);
|
boolean handles(String event);
|
||||||
}
|
}
|
||||||
|
@ -62,13 +62,13 @@ public class Party {
|
|||||||
|
|
||||||
reopenInventories();
|
reopenInventories();
|
||||||
|
|
||||||
// disband the party if no member left
|
// Disband the party if no member left
|
||||||
if (members.count() < 1) {
|
if (members.count() < 1) {
|
||||||
MMOCore.plugin.partyManager.unregisterParty(this);
|
MMOCore.plugin.partyManager.unregisterParty(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// transfer ownership
|
// Transfer ownership
|
||||||
if (owner.equals(data)) {
|
if (owner.equals(data)) {
|
||||||
owner = members.get(0);
|
owner = members.get(0);
|
||||||
if (notify && owner.isOnline())
|
if (notify && owner.isOnline())
|
||||||
|
@ -19,7 +19,7 @@ public class ReloadCommandTreeNode extends CommandTreeNode {
|
|||||||
long ms = System.currentTimeMillis();
|
long ms = System.currentTimeMillis();
|
||||||
|
|
||||||
MMOCore.plugin.reloadConfig();
|
MMOCore.plugin.reloadConfig();
|
||||||
MMOCore.plugin.reloadPlugin();
|
MMOCore.plugin.initializePlugin(true);
|
||||||
|
|
||||||
PlayerData.getAll().forEach(PlayerData::update);
|
PlayerData.getAll().forEach(PlayerData::update);
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
|
||||||
public class ExpCurve {
|
public class ExpCurve {
|
||||||
@ -21,7 +22,9 @@ public class ExpCurve {
|
|||||||
/**
|
/**
|
||||||
* Purely arbitrary but MMOCore needs a default exp curve for everything
|
* Purely arbitrary but MMOCore needs a default exp curve for everything
|
||||||
* otherwise there might be divisions by 0 when trying to update the vanilla
|
* otherwise there might be divisions by 0 when trying to update the vanilla
|
||||||
* exp bar which requires a 0.0 -> 1.0 float as parameter
|
* exp bar which requires a 0.0 -> 1.0 float as parameter.
|
||||||
|
*
|
||||||
|
* See {@link PlayerData#refreshVanillaExp()}
|
||||||
*/
|
*/
|
||||||
public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500);
|
public static final ExpCurve DEFAULT = new ExpCurve("default", 100, 200, 300, 400, 500);
|
||||||
|
|
||||||
|
@ -22,7 +22,15 @@ public interface ExperienceDispenser {
|
|||||||
*/
|
*/
|
||||||
void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation);
|
void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation);
|
||||||
|
|
||||||
boolean matches(PlayerData playerData);
|
/**
|
||||||
|
* Experience sources handle both CLASS experience sources and PROFESSION
|
||||||
|
* experience sources. Professions have no problem because whatever
|
||||||
|
* class the player has chosen, he can get exp in that profession.
|
||||||
|
* <p>
|
||||||
|
* But class experience sources must first make sure that the player has
|
||||||
|
* the right class before giving exp to the player
|
||||||
|
*/
|
||||||
|
boolean shouldHandle(PlayerData playerData);
|
||||||
|
|
||||||
default Location getPlayerLocation(PlayerData player) {
|
default Location getPlayerLocation(PlayerData player) {
|
||||||
return player.isOnline() ? player.getPlayer().getLocation() : null;
|
return player.isOnline() ? player.getPlayer().getLocation() : null;
|
||||||
|
@ -23,7 +23,7 @@ public class MainExperienceDispenser implements ExperienceDispenser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(PlayerData playerData) {
|
public boolean shouldHandle(PlayerData playerData) {
|
||||||
return playerData.getProfess().equals(profess);
|
return playerData.getProfess().equals(profess);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class ProfessionExperienceDispenser implements ExperienceDispenser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(PlayerData playerData) {
|
public boolean shouldHandle(PlayerData playerData) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public abstract class ExperienceSource<T> {
|
|||||||
public abstract ExperienceSourceManager<?> newManager();
|
public abstract ExperienceSourceManager<?> newManager();
|
||||||
|
|
||||||
public boolean matches(PlayerData player, T obj) {
|
public boolean matches(PlayerData player, T obj) {
|
||||||
return getDispenser().matches(player) && matchesParameter(player, obj);
|
return getDispenser().shouldHandle(player) && matchesParameter(player, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean matchesParameter(PlayerData player, T obj);
|
public abstract boolean matchesParameter(PlayerData player, T obj);
|
||||||
|
@ -9,7 +9,7 @@ import net.Indyuce.mmocore.MMOCore;
|
|||||||
import net.Indyuce.mmocore.api.ConfigFile;
|
import net.Indyuce.mmocore.api.ConfigFile;
|
||||||
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
|
||||||
|
|
||||||
public class AttributeManager implements MMOManager {
|
public class AttributeManager implements MMOCoreManager {
|
||||||
private final Map<String, PlayerAttribute> map = new HashMap<>();
|
private final Map<String, PlayerAttribute> map = new HashMap<>();
|
||||||
|
|
||||||
public PlayerAttribute get(String id) {
|
public PlayerAttribute get(String id) {
|
||||||
@ -25,7 +25,9 @@ public class AttributeManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
map.clear();
|
||||||
|
|
||||||
ConfigFile config = new ConfigFile("attributes");
|
ConfigFile config = new ConfigFile("attributes");
|
||||||
for (String key : config.getConfig().getKeys(false))
|
for (String key : config.getConfig().getKeys(false))
|
||||||
@ -36,9 +38,4 @@ public class AttributeManager implements MMOManager {
|
|||||||
MMOCore.log(Level.WARNING, "Could not load attribute '" + key + "': " + exception.getMessage());
|
MMOCore.log(Level.WARNING, "Could not load attribute '" + key + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ import net.Indyuce.mmocore.api.player.profess.event.trigger.ClassChosenEventTrig
|
|||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger;
|
import net.Indyuce.mmocore.api.player.profess.event.trigger.LevelUpEventTrigger;
|
||||||
import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger;
|
import net.Indyuce.mmocore.api.player.profess.event.trigger.MultipleLevelUpEventTrigger;
|
||||||
|
|
||||||
public class ClassManager implements MMOManager {
|
public class ClassManager implements MMOCoreManager {
|
||||||
private final Map<String, PlayerClass> map = new HashMap<>();
|
private final Map<String, PlayerClass> map = new HashMap<>();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -84,7 +84,17 @@ public class ClassManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore) {
|
||||||
|
map.clear();
|
||||||
|
triggerHandlers.forEach(HandlerList::unregisterAll);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Do not clear the list of trigger listeners, since it's only setup
|
||||||
|
* once the server loads and it is never modified.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
for (File file : new File(MMOCore.plugin.getDataFolder() + "/classes").listFiles())
|
for (File file : new File(MMOCore.plugin.getDataFolder() + "/classes").listFiles())
|
||||||
try {
|
try {
|
||||||
String id = file.getName().substring(0, file.getName().length() - 4);
|
String id = file.getName().substring(0, file.getName().length() - 4);
|
||||||
@ -104,19 +114,8 @@ public class ClassManager implements MMOManager {
|
|||||||
.orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS));
|
.orElse(new PlayerClass("HUMAN", "Human", Material.LEATHER_BOOTS));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* register event triggers
|
* Register event triggers
|
||||||
*/
|
*/
|
||||||
triggerHandlers.forEach(handler -> Bukkit.getPluginManager().registerEvents(handler, MMOCore.plugin));
|
triggerHandlers.forEach(handler -> Bukkit.getPluginManager().registerEvents(handler, MMOCore.plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
map.clear();
|
|
||||||
triggerHandlers.forEach(HandlerList::unregisterAll);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* do not clear the list of trigger listeners, since it's only setup
|
|
||||||
* once the server loads and it is never modified.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
import net.Indyuce.mmocore.loot.droptable.DropTable;
|
||||||
|
|
||||||
public class DropTableManager implements MMOManager {
|
public class DropTableManager implements MMOCoreManager {
|
||||||
private final Map<String, DropTable> map = new HashMap<>();
|
private final Map<String, DropTable> map = new HashMap<>();
|
||||||
|
|
||||||
public void register(DropTable table) {
|
public void register(DropTable table) {
|
||||||
@ -59,7 +59,10 @@ public class DropTableManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
map.clear();
|
||||||
|
|
||||||
for (File file : new File(MMOCore.plugin.getDataFolder() + "/drop-tables").listFiles())
|
for (File file : new File(MMOCore.plugin.getDataFolder() + "/drop-tables").listFiles())
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -77,9 +80,4 @@ public class DropTableManager implements MMOManager {
|
|||||||
|
|
||||||
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> map.values().forEach(PostLoadObject::postLoad));
|
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> map.values().forEach(PostLoadObject::postLoad));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import net.Indyuce.mmocore.api.ConfigFile;
|
|||||||
import net.Indyuce.mmocore.loot.chest.LootChest;
|
import net.Indyuce.mmocore.loot.chest.LootChest;
|
||||||
import net.Indyuce.mmocore.loot.chest.LootChestRegion;
|
import net.Indyuce.mmocore.loot.chest.LootChestRegion;
|
||||||
|
|
||||||
public class LootChestManager {
|
public class LootChestManager implements MMOCoreManager {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* all active loot chests in the server
|
* all active loot chests in the server
|
||||||
@ -57,9 +57,12 @@ public class LootChestManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() {
|
@Override
|
||||||
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore) {
|
||||||
regions.values().forEach(region -> region.getRunnable().cancel());
|
regions.values().forEach(region -> region.getRunnable().cancel());
|
||||||
regions.clear();
|
regions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
FileConfiguration config = new ConfigFile("loot-chests").getConfig();
|
FileConfiguration config = new ConfigFile("loot-chests").getConfig();
|
||||||
for (String key : config.getKeys(false))
|
for (String key : config.getKeys(false))
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
|
||||||
|
|
||||||
public interface MMOManager {
|
|
||||||
void reload();
|
|
||||||
|
|
||||||
void clear();
|
|
||||||
}
|
|
@ -13,7 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.quest.Quest;
|
import net.Indyuce.mmocore.api.quest.Quest;
|
||||||
|
|
||||||
public class QuestManager implements MMOManager {
|
public class QuestManager implements MMOCoreManager {
|
||||||
private final Map<String, Quest> quests = new LinkedHashMap<>();
|
private final Map<String, Quest> quests = new LinkedHashMap<>();
|
||||||
|
|
||||||
public void load(File file) {
|
public void load(File file) {
|
||||||
@ -45,7 +45,10 @@ public class QuestManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
quests.clear();
|
||||||
|
|
||||||
load(new File(MMOCore.plugin.getDataFolder() + "/quests"));
|
load(new File(MMOCore.plugin.getDataFolder() + "/quests"));
|
||||||
for (Quest quest : quests.values())
|
for (Quest quest : quests.values())
|
||||||
try {
|
try {
|
||||||
@ -54,9 +57,4 @@ public class QuestManager implements MMOManager {
|
|||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load quest '" + quest.getId() + "': " + exception.getMessage());
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not post-load quest '" + quest.getId() + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
quests.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,32 @@ import net.Indyuce.mmocore.comp.mythicmobs.MythicSkill;
|
|||||||
public class SkillManager {
|
public class SkillManager {
|
||||||
private final Map<String, Skill> skills = new LinkedHashMap<>();
|
private final Map<String, Skill> skills = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public void register(Skill skill) {
|
||||||
|
skills.put(skill.getId().toUpperCase(), skill);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Skill get(String id) {
|
||||||
|
return skills.get(id.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean has(String id) {
|
||||||
|
return skills.containsKey(id.toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Skill> getAll() {
|
||||||
|
return skills.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Skill> getActive() {
|
||||||
|
return skills.values().stream().filter(skill -> !skill.isPassive()).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getKeys() {
|
||||||
|
return skills.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* skills are initialized when MMOCore enables but SkillManager must be
|
* Skills are initialized when MMOCore enables but SkillManager must be
|
||||||
* instanced when MMOCore loads so that extra plugins can register skills
|
* instanced when MMOCore loads so that extra plugins can register skills
|
||||||
* before CLASSES are loaded
|
* before CLASSES are loaded
|
||||||
*/
|
*/
|
||||||
@ -53,9 +77,7 @@ public class SkillManager {
|
|||||||
if (!mythicMobs.exists())
|
if (!mythicMobs.exists())
|
||||||
mythicMobs.mkdir();
|
mythicMobs.mkdir();
|
||||||
|
|
||||||
/*
|
// Load MythicMobs addon skills
|
||||||
* load MythicMobs addon skills
|
|
||||||
*/
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
|
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
|
||||||
for (File file : mythicMobs.listFiles()) {
|
for (File file : mythicMobs.listFiles()) {
|
||||||
try {
|
try {
|
||||||
@ -96,28 +118,4 @@ public class SkillManager {
|
|||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(Skill skill) {
|
|
||||||
skills.put(skill.getId().toUpperCase(), skill);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Skill get(String id) {
|
|
||||||
return skills.get(id.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean has(String id) {
|
|
||||||
return skills.containsKey(id.toUpperCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Skill> getAll() {
|
|
||||||
return skills.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Skill> getActive() {
|
|
||||||
return skills.values().stream().filter(skill -> !skill.isPassive()).collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getKeys() {
|
|
||||||
return skills.keySet();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,13 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
data.setAttributePoints(getDefaultData().getAttributePoints());
|
data.setAttributePoints(getDefaultData().getAttributePoints());
|
||||||
data.setAttributeReallocationPoints(getDefaultData().getAttrReallocPoints());
|
data.setAttributeReallocationPoints(getDefaultData().getAttrReallocPoints());
|
||||||
data.setExperience(0);
|
data.setExperience(0);
|
||||||
|
data.getQuestData().updateBossBar();
|
||||||
|
|
||||||
|
if (!data.hasUsedTemporaryData()) {
|
||||||
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
||||||
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
||||||
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
||||||
data.getQuestData().updateBossBar();
|
}
|
||||||
|
|
||||||
data.setFullyLoaded();
|
data.setFullyLoaded();
|
||||||
MMOCore.sqlDebug("Loaded DEFAULT data for: '" + data.getUniqueId() + "' as no saved data was found.");
|
MMOCore.sqlDebug("Loaded DEFAULT data for: '" + data.getUniqueId() + "' as no saved data was found.");
|
||||||
@ -62,9 +65,13 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
|||||||
data.setExperience(result.getInt("experience"));
|
data.setExperience(result.getInt("experience"));
|
||||||
if (!isEmpty(result.getString("class")))
|
if (!isEmpty(result.getString("class")))
|
||||||
data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
|
data.setClass(MMOCore.plugin.classManager.get(result.getString("class")));
|
||||||
|
|
||||||
|
if (!data.hasUsedTemporaryData()) {
|
||||||
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
||||||
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
||||||
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
||||||
|
}
|
||||||
|
|
||||||
if (!isEmpty(result.getString("guild")))
|
if (!isEmpty(result.getString("guild")))
|
||||||
data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), result.getString("guild")));
|
data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), result.getString("guild")));
|
||||||
if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes"));
|
if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes"));
|
||||||
|
@ -32,9 +32,13 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
data.setExperience(config.getInt("experience"));
|
data.setExperience(config.getInt("experience"));
|
||||||
if (config.contains("class"))
|
if (config.contains("class"))
|
||||||
data.setClass(MMOCore.plugin.classManager.get(config.getString("class")));
|
data.setClass(MMOCore.plugin.classManager.get(config.getString("class")));
|
||||||
|
|
||||||
|
if (!data.hasUsedTemporaryData()) {
|
||||||
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
data.setMana(data.getStats().getStat(StatType.MAX_MANA));
|
||||||
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
data.setStamina(data.getStats().getStat(StatType.MAX_STAMINA));
|
||||||
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
data.setStellium(data.getStats().getStat(StatType.MAX_STELLIUM));
|
||||||
|
}
|
||||||
|
|
||||||
if (config.contains("guild"))
|
if (config.contains("guild"))
|
||||||
data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), config.getString("guild")));
|
data.setGuild(MMOCore.plugin.dataProvider.getGuildManager().stillInGuild(data.getUniqueId(), config.getString("guild")));
|
||||||
if (config.contains("attribute"))
|
if (config.contains("attribute"))
|
||||||
@ -55,9 +59,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
if (data.getProfess().hasSkill(id))
|
if (data.getProfess().hasSkill(id))
|
||||||
data.getBoundSkills().add(data.getProfess().getSkill(id));
|
data.getBoundSkills().add(data.getProfess().getSkill(id));
|
||||||
|
|
||||||
/*
|
// Load class slots, use try so the player can log in.
|
||||||
* load class slots, use try so the player can log in.
|
|
||||||
*/
|
|
||||||
if (config.contains("class-info"))
|
if (config.contains("class-info"))
|
||||||
for (String key : config.getConfigurationSection("class-info").getKeys(false))
|
for (String key : config.getConfigurationSection("class-info").getKeys(false))
|
||||||
try {
|
try {
|
||||||
@ -67,6 +69,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
|||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOCore.log(Level.WARNING, "Could not load class info '" + key + "': " + exception.getMessage());
|
MMOCore.log(Level.WARNING, "Could not load class info '" + key + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setFullyLoaded();
|
data.setFullyLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,39 @@
|
|||||||
package net.Indyuce.mmocore.manager.profession;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.potion.PotionType;
|
public class AlchemyManager extends SpecificProfessionManager {
|
||||||
|
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
|
||||||
|
|
||||||
public class AlchemyManager implements MMOManager {
|
|
||||||
public double splash, lingering, upgrade, extend;
|
public double splash, lingering, upgrade, extend;
|
||||||
|
|
||||||
// private Map<PotionEffectType, Double> custom = new HashMap<>();
|
// private Map<PotionEffectType, Double> custom = new HashMap<>();
|
||||||
private final Map<PotionType, Double> base = new HashMap<>();
|
private final Map<PotionType, Double> base = new HashMap<>();
|
||||||
|
|
||||||
|
public AlchemyManager() {
|
||||||
|
super("alchemy-experience");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadProfessionConfiguration(ConfigurationSection config) {
|
||||||
|
splash = 1 + config.getDouble("special.splash") / 100;
|
||||||
|
lingering = 1 + config.getDouble("special.lingering") / 100;
|
||||||
|
extend = 1 + config.getDouble("special.extend") / 100;
|
||||||
|
upgrade = 1 + config.getDouble("special.upgrade") / 100;
|
||||||
|
|
||||||
|
for (String key : config.getConfigurationSection("effects").getKeys(false))
|
||||||
|
try {
|
||||||
|
PotionType type = PotionType.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||||
|
MMOCore.plugin.alchemyManager.registerBaseExperience(type, config.getDouble("effects." + key));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOCore.log(Level.WARNING, "Could not read potion type from " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// public double getWeight(PotionEffectType type) {
|
// public double getWeight(PotionEffectType type) {
|
||||||
// return custom.containsKey(type) ? custom.get(type) : 0;
|
// return custom.containsKey(type) ? custom.get(type) : 0;
|
||||||
// }
|
// }
|
||||||
@ -40,14 +61,10 @@ public class AlchemyManager implements MMOManager {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
// TODO Auto-generated method stub
|
if (clearBefore) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
splash = lingering = upgrade = extend = 1;
|
splash = lingering = upgrade = extend = 1;
|
||||||
base.clear();
|
base.clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
@ -11,6 +11,7 @@ import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
|||||||
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
||||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
import net.Indyuce.mmocore.manager.profession.SpecificProfessionManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -22,7 +23,7 @@ import java.util.*;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class CustomBlockManager implements MMOManager {
|
public class CustomBlockManager extends SpecificProfessionManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registered block infos
|
* Registered block infos
|
||||||
@ -49,6 +50,8 @@ public class CustomBlockManager implements MMOManager {
|
|||||||
private boolean protect;
|
private boolean protect;
|
||||||
|
|
||||||
public CustomBlockManager() {
|
public CustomBlockManager() {
|
||||||
|
super("on-mine");
|
||||||
|
|
||||||
registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? Optional.of(new SkullBlockType(block)) : Optional.empty());
|
registerBlockType(block -> MMOCoreUtils.isPlayerHead(block.getType()) ? Optional.of(new SkullBlockType(block)) : Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +163,8 @@ public class CustomBlockManager implements MMOManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadDropTables(ConfigurationSection config) {
|
@Override
|
||||||
|
public void loadProfessionConfiguration(ConfigurationSection config) {
|
||||||
for (String key : config.getKeys(false))
|
for (String key : config.getKeys(false))
|
||||||
try {
|
try {
|
||||||
register(new BlockInfo(config.getConfigurationSection(key)));
|
register(new BlockInfo(config.getConfigurationSection(key)));
|
||||||
@ -177,8 +181,11 @@ public class CustomBlockManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore) {
|
||||||
customMineConditions.clear();
|
customMineConditions.clear();
|
||||||
|
map.clear();
|
||||||
|
}
|
||||||
|
|
||||||
this.protect = MMOCore.plugin.getConfig().getBoolean("protect-custom-mine");
|
this.protect = MMOCore.plugin.getConfig().getBoolean("protect-custom-mine");
|
||||||
|
|
||||||
@ -189,9 +196,4 @@ public class CustomBlockManager implements MMOManager {
|
|||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage());
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load custom mining condition '" + key + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
map.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,15 +1,32 @@
|
|||||||
package net.Indyuce.mmocore.manager.profession;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
public class EnchantManager extends SpecificProfessionManager {
|
||||||
|
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
|
||||||
|
|
||||||
public class EnchantManager implements MMOManager {
|
|
||||||
private final Map<Enchantment, Double> base = new HashMap<>();
|
private final Map<Enchantment, Double> base = new HashMap<>();
|
||||||
|
|
||||||
|
public EnchantManager() {
|
||||||
|
super("base-enchant-exp");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadProfessionConfiguration(ConfigurationSection config) {
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
try {
|
||||||
|
Enchantment enchant = MythicLib.plugin.getVersion().getWrapper().getEnchantmentFromString(key.toLowerCase().replace("-", "_"));
|
||||||
|
MMOCore.plugin.enchantManager.registerBaseExperience(enchant, config.getDouble(key));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
MMOCore.log(Level.WARNING, "Could not find enchant with name '" + key + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void registerBaseExperience(Enchantment enchant, double value) {
|
public void registerBaseExperience(Enchantment enchant, double value) {
|
||||||
base.put(enchant, value);
|
base.put(enchant, value);
|
||||||
}
|
}
|
||||||
@ -19,13 +36,8 @@ public class EnchantManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
// TODO Auto-generated method stub
|
if (clearBefore)
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
base.clear();
|
base.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package net.Indyuce.mmocore.manager.profession;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class ExperienceSourceManager<T> implements Listener {
|
public abstract class ExperienceSourceManager<T extends ExperienceSource> implements Listener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of all active experience sources
|
* List of all active experience sources
|
||||||
@ -20,8 +21,6 @@ public abstract class ExperienceSourceManager<T> implements Listener {
|
|||||||
|
|
||||||
public void registerSource(T source) {
|
public void registerSource(T source) {
|
||||||
sources.add(source);
|
sources.add(source);
|
||||||
|
|
||||||
getSources();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<T> getSources() {
|
public Set<T> getSources() {
|
||||||
|
@ -1,30 +1,28 @@
|
|||||||
package net.Indyuce.mmocore.manager.profession;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
import net.Indyuce.mmocore.loot.droptable.condition.Condition;
|
||||||
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
import net.Indyuce.mmocore.loot.droptable.condition.ConditionInstance;
|
||||||
import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.fishing.FishingDropItem;
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
import org.apache.commons.lang.Validate;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
public class FishingManager implements MMOManager {
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class FishingManager extends SpecificProfessionManager {
|
||||||
private final Set<FishingDropTable> tables = new LinkedHashSet<>();
|
private final Set<FishingDropTable> tables = new LinkedHashSet<>();
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public void loadDropTables(ConfigurationSection config) {
|
public FishingManager() {
|
||||||
|
super("on-fish");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadProfessionConfiguration(ConfigurationSection config) {
|
||||||
for (String key : config.getKeys(false))
|
for (String key : config.getKeys(false))
|
||||||
try {
|
try {
|
||||||
tables.add(new FishingDropTable(config.getConfigurationSection(key)));
|
tables.add(new FishingDropTable(config.getConfigurationSection(key)));
|
||||||
@ -107,12 +105,8 @@ public class FishingManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
// TODO Auto-generated method stub
|
if (clearBefore)
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
tables.clear();
|
tables.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,41 @@
|
|||||||
package net.Indyuce.mmocore.manager.profession;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import io.lumine.mythic.lib.api.util.PostLoadObject;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.experience.Profession;
|
import net.Indyuce.mmocore.experience.Profession;
|
||||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ProfessionManager implements MMOManager {
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
public class ProfessionManager implements MMOCoreManager {
|
||||||
* Loaded professions.
|
|
||||||
*/
|
|
||||||
private final Map<String, Profession> professions = new HashMap<>();
|
private final Map<String, Profession> professions = new HashMap<>();
|
||||||
|
private final Set<SpecificProfessionManager> professionManagers = new HashSet<>();
|
||||||
/**
|
|
||||||
* Saves different experience sources based on experience source type.
|
|
||||||
*/
|
|
||||||
private final Map<Class<?>, ExperienceSourceManager<?>> managers = new HashMap<>();
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> ExperienceSourceManager<T> getManager(Class<T> t) {
|
|
||||||
return (ExperienceSourceManager<T>) managers.get(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T extends ExperienceSource<?>> void registerExpSource(T source) {
|
|
||||||
Class<T> path = (Class<T>) source.getClass();
|
|
||||||
|
|
||||||
if (!managers.containsKey(path))
|
|
||||||
managers.put(path, source.newManager());
|
|
||||||
getManager(path).registerSource(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(Profession profession) {
|
public void register(Profession profession) {
|
||||||
professions.put(profession.getId(), profession);
|
professions.put(profession.getId(), profession);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerProfessionManager(@NotNull SpecificProfessionManager professionManager) {
|
||||||
|
Validate.notNull(professionManager);
|
||||||
|
|
||||||
|
professionManagers.add(professionManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadProfessionConfigurations(ConfigurationSection config) {
|
||||||
|
for (SpecificProfessionManager manager : professionManagers)
|
||||||
|
if (config.contains(manager.getStringKey()))
|
||||||
|
try {
|
||||||
|
manager.loadProfessionConfiguration(config.getConfigurationSection(manager.getStringKey()));
|
||||||
|
} catch (RuntimeException exception) {
|
||||||
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession config '" + manager.getStringKey() + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Profession get(String id) {
|
public Profession get(String id) {
|
||||||
return professions.get(id);
|
return professions.get(id);
|
||||||
}
|
}
|
||||||
@ -58,7 +49,20 @@ public class ProfessionManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
professions.clear();
|
||||||
|
|
||||||
|
// Load default profession managers (can't be done on constructor because MMOCore.plugin is null)
|
||||||
|
if (professionManagers.isEmpty()) {
|
||||||
|
registerProfessionManager(MMOCore.plugin.alchemyManager);
|
||||||
|
registerProfessionManager(MMOCore.plugin.enchantManager);
|
||||||
|
registerProfessionManager(MMOCore.plugin.fishingManager);
|
||||||
|
registerProfessionManager(MMOCore.plugin.smithingManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
professionManagers.forEach(manager -> manager.initialize(clearBefore));
|
||||||
|
|
||||||
for (File file : new File(MMOCore.plugin.getDataFolder() + "/professions").listFiles())
|
for (File file : new File(MMOCore.plugin.getDataFolder() + "/professions").listFiles())
|
||||||
try {
|
try {
|
||||||
String id = file.getName().substring(0, file.getName().length() - 4);
|
String id = file.getName().substring(0, file.getName().length() - 4);
|
||||||
@ -66,14 +70,5 @@ public class ProfessionManager implements MMOManager {
|
|||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession " + file.getName() + ": " + exception.getMessage());
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load profession " + file.getName() + ": " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
getAll().forEach(PostLoadObject::postLoad);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
managers.values().forEach(HandlerList::unregisterAll);
|
|
||||||
managers.clear();
|
|
||||||
professions.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package net.Indyuce.mmocore.manager.profession;
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
public class SmithingManager extends SpecificProfessionManager {
|
||||||
|
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
|
||||||
|
|
||||||
public class SmithingManager implements MMOManager {
|
|
||||||
private final Map<Material, Double> base = new HashMap<>();
|
private final Map<Material, Double> base = new HashMap<>();
|
||||||
|
|
||||||
|
public SmithingManager() {
|
||||||
|
super("repair-exp");
|
||||||
|
}
|
||||||
|
|
||||||
public void registerBaseExperience(Material material, double value) {
|
public void registerBaseExperience(Material material, double value) {
|
||||||
base.put(material, value);
|
base.put(material, value);
|
||||||
}
|
}
|
||||||
@ -23,13 +26,19 @@ public class SmithingManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void loadProfessionConfiguration(ConfigurationSection config) {
|
||||||
// TODO Auto-generated method stub
|
for (String key : config.getKeys(false))
|
||||||
|
try {
|
||||||
|
Material material = Material.valueOf(key.toUpperCase().replace("-", "_").replace(" ", "_"));
|
||||||
|
registerBaseExperience(material, config.getDouble(key));
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
throw new RuntimeException("Could not read material from '" + key + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clear() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
base.clear();
|
base.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package net.Indyuce.mmocore.manager.profession;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
public abstract class SpecificProfessionManager implements MMOCoreManager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String key used to detect and load profession config in any
|
||||||
|
* profession.yml config
|
||||||
|
*/
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public SpecificProfessionManager(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void loadProfessionConfiguration(ConfigurationSection config);
|
||||||
|
}
|
@ -5,7 +5,7 @@ import net.Indyuce.mmocore.MMOCore;
|
|||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.social.Party;
|
import net.Indyuce.mmocore.api.player.social.Party;
|
||||||
import net.Indyuce.mmocore.api.player.stats.StatType;
|
import net.Indyuce.mmocore.api.player.stats.StatType;
|
||||||
import net.Indyuce.mmocore.manager.MMOManager;
|
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -14,8 +14,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class PartyManager implements MMOCoreManager {
|
||||||
public class PartyManager implements MMOManager {
|
|
||||||
private final Set<Party> parties = new HashSet<>();
|
private final Set<Party> parties = new HashSet<>();
|
||||||
private final Map<StatType, StatModifier> buffs = new HashMap<>();
|
private final Map<StatType, StatModifier> buffs = new HashMap<>();
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ public class PartyManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterParty(Party party) {
|
public void unregisterParty(Party party) {
|
||||||
// IMPORTANT: clears all party stats before unregistering the party
|
// IMPORTANT: clears all party members before unregistering the party
|
||||||
party.getMembers().forEach(party::removeMember);
|
party.getMembers().forEach(party::removeMember);
|
||||||
parties.remove(party);
|
parties.remove(party);
|
||||||
}
|
}
|
||||||
@ -52,7 +51,10 @@ public class PartyManager implements MMOManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reload() {
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
buffs.clear();
|
||||||
|
|
||||||
ConfigurationSection config = MMOCore.plugin.getConfig().getConfigurationSection("party.buff");
|
ConfigurationSection config = MMOCore.plugin.getConfig().getConfigurationSection("party.buff");
|
||||||
if (config != null)
|
if (config != null)
|
||||||
for (String key : config.getKeys(false))
|
for (String key : config.getKeys(false))
|
||||||
@ -63,9 +65,4 @@ public class PartyManager implements MMOManager {
|
|||||||
MMOCore.log(Level.WARNING, "Could not load party buff '" + key + "': " + exception.getMessage());
|
MMOCore.log(Level.WARNING, "Could not load party buff '" + key + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
buffs.clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user