forked from Upstream/mmocore
New register stuff
This commit is contained in:
parent
be22442a78
commit
9727f02051
@ -45,9 +45,6 @@ import net.Indyuce.mmocore.party.PartyModule;
|
|||||||
import net.Indyuce.mmocore.party.PartyModuleType;
|
import net.Indyuce.mmocore.party.PartyModuleType;
|
||||||
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
|
import net.Indyuce.mmocore.party.provided.MMOCorePartyModule;
|
||||||
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
||||||
import net.Indyuce.mmocore.skill.list.Ambers;
|
|
||||||
import net.Indyuce.mmocore.skill.list.Neptune_Gift;
|
|
||||||
import net.Indyuce.mmocore.skill.list.Sneaky_Picky;
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -65,7 +62,7 @@ public class MMOCore extends LuminePlugin {
|
|||||||
public static MMOCore plugin;
|
public static MMOCore plugin;
|
||||||
|
|
||||||
public ConfigManager configManager;
|
public ConfigManager configManager;
|
||||||
public WaypointManager waypointManager;
|
public final WaypointManager waypointManager = new WaypointManager();
|
||||||
public SoundManager soundManager;
|
public SoundManager soundManager;
|
||||||
public RequestManager requestManager;
|
public RequestManager requestManager;
|
||||||
public ConfigItemManager configItems;
|
public ConfigItemManager configItems;
|
||||||
@ -82,6 +79,8 @@ public class MMOCore extends LuminePlugin {
|
|||||||
public final LootChestManager lootChests = new LootChestManager();
|
public final LootChestManager lootChests = new LootChestManager();
|
||||||
public final MMOLoadManager loadManager = new MMOLoadManager();
|
public final MMOLoadManager loadManager = new MMOLoadManager();
|
||||||
public final RestrictionManager restrictionManager = new RestrictionManager();
|
public final RestrictionManager restrictionManager = new RestrictionManager();
|
||||||
|
@Deprecated
|
||||||
|
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
|
||||||
|
|
||||||
public VaultEconomy economy;
|
public VaultEconomy economy;
|
||||||
public RegionHandler regionHandler = new DefaultRegionHandler();
|
public RegionHandler regionHandler = new DefaultRegionHandler();
|
||||||
@ -408,8 +407,8 @@ public class MMOCore extends LuminePlugin {
|
|||||||
questManager.initialize(clearBefore);
|
questManager.initialize(clearBefore);
|
||||||
lootChests.initialize(clearBefore);
|
lootChests.initialize(clearBefore);
|
||||||
restrictionManager.initialize(clearBefore);
|
restrictionManager.initialize(clearBefore);
|
||||||
|
waypointManager.initialize(clearBefore);
|
||||||
|
|
||||||
waypointManager = new WaypointManager(new ConfigFile("waypoints").getConfig());
|
|
||||||
requestManager = new RequestManager();
|
requestManager = new RequestManager();
|
||||||
soundManager = new SoundManager(new ConfigFile("sounds").getConfig());
|
soundManager = new SoundManager(new ConfigFile("sounds").getConfig());
|
||||||
configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
|
configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.manager.registry.MMOCoreRegister;
|
||||||
|
import net.Indyuce.mmocore.tree.SkillTree;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public class SkillTreeManager extends MMOCoreRegister<SkillTree> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRegisteredObjectName() {
|
||||||
|
return "skill tree";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
registered.clear();
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +1,22 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.ConfigFile;
|
||||||
|
import net.Indyuce.mmocore.waypoint.Waypoint;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
public class WaypointManager implements MMOCoreManager {
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
|
||||||
import net.Indyuce.mmocore.waypoint.Waypoint;
|
|
||||||
|
|
||||||
public class WaypointManager {
|
|
||||||
private final Map<String, Waypoint> waypoints = new LinkedHashMap<>();
|
private final Map<String, Waypoint> waypoints = new LinkedHashMap<>();
|
||||||
|
|
||||||
public WaypointManager(FileConfiguration config) {
|
|
||||||
for (String key : config.getKeys(false))
|
|
||||||
try {
|
|
||||||
register(new Waypoint(config.getConfigurationSection(key)));
|
|
||||||
} catch (IllegalArgumentException exception) {
|
|
||||||
MMOCore.log(Level.WARNING, "Could not load waypoint '" + key + "': " + exception.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<Waypoint> getAll() {
|
public Collection<Waypoint> getAll() {
|
||||||
return waypoints.values();
|
return waypoints.values();
|
||||||
}
|
}
|
||||||
@ -36,13 +30,30 @@ public class WaypointManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void register(Waypoint waypoint) {
|
public void register(Waypoint waypoint) {
|
||||||
|
Validate.isTrue(!waypoints.containsKey(Objects.requireNonNull(waypoint, "Waypoint cannot be null").getId()), "There is already a waypoint with ID '" + waypoint.getId() + "'");
|
||||||
|
|
||||||
waypoints.put(waypoint.getId(), waypoint);
|
waypoints.put(waypoint.getId(), waypoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public Waypoint getCurrentWaypoint(Player player) {
|
public Waypoint getCurrentWaypoint(Player player) {
|
||||||
for (Waypoint waypoint : getAll())
|
for (Waypoint waypoint : getAll())
|
||||||
if (waypoint.isOnWaypoint(player))
|
if (waypoint.isOnWaypoint(player))
|
||||||
return waypoint;
|
return waypoint;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(boolean clearBefore) {
|
||||||
|
if (clearBefore)
|
||||||
|
waypoints.clear();
|
||||||
|
|
||||||
|
FileConfiguration config = new ConfigFile("waypoints").getConfig();
|
||||||
|
for (String key : config.getKeys(false))
|
||||||
|
try {
|
||||||
|
register(new Waypoint(config.getConfigurationSection(key)));
|
||||||
|
} catch (RuntimeException exception) {
|
||||||
|
MMOCore.log(Level.WARNING, "Could not load waypoint '" + key + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package net.Indyuce.mmocore.manager.registry;
|
||||||
|
|
||||||
|
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public abstract class MMOCoreRegister<T extends RegisterObject> implements MMOCoreManager {
|
||||||
|
protected final Map<String, T> registered = new HashMap<>();
|
||||||
|
|
||||||
|
public void register(T t) {
|
||||||
|
Validate.notNull(t, getRegisteredObjectName() + " cannot be null");
|
||||||
|
Validate.isTrue(!registered.containsKey(t.getId()), "There is already a " + getRegisteredObjectName() + " registered with ID '" + t.getId() + "'");
|
||||||
|
|
||||||
|
registered.put(t.getId(), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get(String id) {
|
||||||
|
return Objects.requireNonNull(registered.get(id), "Could not find " + getRegisteredObjectName() + " with ID '" + id + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<T> getAll() {
|
||||||
|
return registered.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getRegisteredObjectName();
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package net.Indyuce.mmocore.manager.registry;
|
||||||
|
|
||||||
|
public interface RegisterObject {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifier used to register an object
|
||||||
|
*/
|
||||||
|
public String getId();
|
||||||
|
}
|
@ -3,7 +3,12 @@ package net.Indyuce.mmocore.player;
|
|||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some item that can be unlocked
|
* Some item that can be unlocked. ALl unlockable are saved in the same list in
|
||||||
|
* the player data. This useful list can be used for:
|
||||||
|
* - waypoints
|
||||||
|
* - skill tree nodes
|
||||||
|
* - skills using skill books? TODO
|
||||||
|
* - external plugins that implement other unlockable items
|
||||||
*
|
*
|
||||||
* @see {@link PlayerData#unlock(Unlockable)} and {@link PlayerData#hasUnlocked(Unlockable)}
|
* @see {@link PlayerData#unlock(Unlockable)} and {@link PlayerData#hasUnlocked(Unlockable)}
|
||||||
*/
|
*/
|
||||||
@ -11,7 +16,7 @@ public interface Unlockable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Format being used is the minecraft's default
|
* Format being used is the minecraft's default
|
||||||
* namespaced key format, e.g skill_tree:strength_1_5
|
* namespaced key format, e.g "skill_tree:strength_1_5"
|
||||||
*/
|
*/
|
||||||
String getUnlockNamespacedKey();
|
String getUnlockNamespacedKey();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package net.Indyuce.mmocore.tree;
|
package net.Indyuce.mmocore.tree;
|
||||||
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.manager.registry.RegisterObject;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -25,7 +27,7 @@ import java.util.logging.Level;
|
|||||||
* @author jules
|
* @author jules
|
||||||
* @see {@link SkillTreeNode}
|
* @see {@link SkillTreeNode}
|
||||||
*/
|
*/
|
||||||
public class SkillTree {
|
public class SkillTree implements RegisterObject {
|
||||||
private final String id, name;
|
private final String id, name;
|
||||||
private final Map<IntegerCoordinates, SkillTreeNode> nodes = new HashMap<>();
|
private final Map<IntegerCoordinates, SkillTreeNode> nodes = new HashMap<>();
|
||||||
|
|
||||||
@ -44,6 +46,7 @@ public class SkillTree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -56,6 +59,11 @@ public class SkillTree {
|
|||||||
return nodes.values();
|
return nodes.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public SkillTreeNode getNode(IntegerCoordinates coords) {
|
||||||
|
return Objects.requireNonNull(nodes.get(coords), "Could not find node in tree '" + id + "' with coordinates '" + coords.toString() + "'");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
@ -3,9 +3,11 @@ package net.Indyuce.mmocore.tree;
|
|||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.player.modifier.PlayerModifier;
|
import io.lumine.mythic.lib.player.modifier.PlayerModifier;
|
||||||
import io.lumine.mythic.lib.util.configobject.ConfigSectionObject;
|
import io.lumine.mythic.lib.util.configobject.ConfigSectionObject;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.player.Unlockable;
|
import net.Indyuce.mmocore.player.Unlockable;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -50,6 +52,11 @@ public class SkillTreeNode implements Unlockable {
|
|||||||
return lore;
|
return lore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUnlockNamespacedKey() {
|
||||||
|
return "skill_tree:" + tree.getId() + "_" + coordinates.getX() + "_" + coordinates.getY();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
@ -63,8 +70,25 @@ public class SkillTreeNode implements Unlockable {
|
|||||||
return Objects.hash(tree, coordinates);
|
return Objects.hash(tree, coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public String getUnlockNamespacedKey() {
|
* @param namespacedKey Something like "skill_tree:tree_name_1_5"
|
||||||
return "skill_tree:" + tree.getId() + "_" + coordinates.getX() + "_" + coordinates.getY();
|
* @return The corresponding skill tree node
|
||||||
|
* @throws RuntimeException If the string cannot be parsed, if the specified
|
||||||
|
* skill tree does not exist or if the skill tree has no such node
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public static SkillTreeNode getFromNamespacedKey(String namespacedKey) {
|
||||||
|
String[] split = namespacedKey.substring(11).split("_");
|
||||||
|
int n = split.length;
|
||||||
|
|
||||||
|
IntegerCoordinates coords = new IntegerCoordinates(Integer.valueOf(split[n - 2]), Integer.valueOf(split[n - 1]));
|
||||||
|
StringBuilder treeIdBuilder = new StringBuilder();
|
||||||
|
for (int i = 0; i < n - 2; i++) {
|
||||||
|
if (i > 0)
|
||||||
|
treeIdBuilder.append("_");
|
||||||
|
treeIdBuilder.append(split[i]);
|
||||||
|
}
|
||||||
|
String treeId = treeIdBuilder.toString();
|
||||||
|
return MMOCore.plugin.skillTreeManager.get(treeId).getNode(coords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user