forked from Upstream/mmocore
Stash
This commit is contained in:
parent
a2e359d411
commit
9f3efaabf8
@ -49,6 +49,7 @@ import net.Indyuce.mmocore.script.mechanic.ManaMechanic;
|
|||||||
import net.Indyuce.mmocore.script.mechanic.StaminaMechanic;
|
import net.Indyuce.mmocore.script.mechanic.StaminaMechanic;
|
||||||
import net.Indyuce.mmocore.script.mechanic.StelliumMechanic;
|
import net.Indyuce.mmocore.script.mechanic.StelliumMechanic;
|
||||||
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPoint;
|
||||||
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;
|
||||||
@ -82,6 +83,8 @@ public class MMOCore extends JavaPlugin {
|
|||||||
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
|
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
|
||||||
|
|
||||||
public final SpawnPointManager spawnPointManager = new SpawnPointManager();
|
public final SpawnPointManager spawnPointManager = new SpawnPointManager();
|
||||||
|
|
||||||
|
public final PluginMessageManager pluginMessageManager = new PluginMessageManager();
|
||||||
public final StatManager statManager = new StatManager();
|
public final StatManager statManager = new StatManager();
|
||||||
public final GuildDataManager nativeGuildManager = new YAMLGuildDataManager();
|
public final GuildDataManager nativeGuildManager = new YAMLGuildDataManager();
|
||||||
public final PlayerDataManager playerDataManager = new PlayerDataManager(this);
|
public final PlayerDataManager playerDataManager = new PlayerDataManager(this);
|
||||||
@ -183,6 +186,10 @@ public class MMOCore extends JavaPlugin {
|
|||||||
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
|
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Registers plugin message channel to teleport players to other servers.
|
||||||
|
MMOCore.plugin.getServer().getMessenger().registerOutgoingPluginChannel(MMOCore.plugin, "BungeeCord");
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Resource regeneration. Must check if entity is dead otherwise regen
|
* Resource regeneration. Must check if entity is dead otherwise regen
|
||||||
* will make the 'respawn' button glitched plus HURT entity effect bug
|
* will make the 'respawn' button glitched plus HURT entity effect bug
|
||||||
@ -199,6 +206,21 @@ public class MMOCore extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}.runTaskTimer(MMOCore.plugin, 100, 20);
|
}.runTaskTimer(MMOCore.plugin, 100, 20);
|
||||||
|
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (PlayerData playerData : PlayerData.getAll()) {
|
||||||
|
for (SpawnPoint spawnPoint : spawnPointManager.getAll()) {
|
||||||
|
if (!playerData.hasUnlocked(spawnPoint) && spawnPoint.matchesCondition(playerData)) {
|
||||||
|
playerData.unlock(spawnPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskTimer(this, 5*20L, 5 * 20L);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For the sake of the lord, make sure they aren't using MMOItems Mana and
|
* For the sake of the lord, make sure they aren't using MMOItems Mana and
|
||||||
* Stamina Addon...This should prevent a couple error reports produced by people
|
* Stamina Addon...This should prevent a couple error reports produced by people
|
||||||
@ -331,6 +353,8 @@ public class MMOCore extends JavaPlugin {
|
|||||||
requestManager.initialize(clearBefore);
|
requestManager.initialize(clearBefore);
|
||||||
soundManager.initialize(clearBefore);
|
soundManager.initialize(clearBefore);
|
||||||
configItems.initialize(clearBefore);
|
configItems.initialize(clearBefore);
|
||||||
|
spawnPointManager.initialize(clearBefore);
|
||||||
|
pluginMessageManager.initialize(clearBefore);
|
||||||
//Needs to be loaded after the class manager.
|
//Needs to be loaded after the class manager.
|
||||||
InventoryManager.load();
|
InventoryManager.load();
|
||||||
|
|
||||||
|
@ -12,9 +12,8 @@ import net.Indyuce.mmocore.experience.source.*;
|
|||||||
import net.Indyuce.mmocore.loot.chest.condition.*;
|
import net.Indyuce.mmocore.loot.chest.condition.*;
|
||||||
import net.Indyuce.mmocore.loot.droptable.dropitem.*;
|
import net.Indyuce.mmocore.loot.droptable.dropitem.*;
|
||||||
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
||||||
import net.Indyuce.mmocore.spawnpoint.def.GlobalSpawnOption;
|
|
||||||
import net.Indyuce.mmocore.spawnpoint.def.LastSpawnOption;
|
import net.Indyuce.mmocore.spawnpoint.def.LastSpawnOption;
|
||||||
import net.Indyuce.mmocore.spawnpoint.def.LocationSpawnOption;
|
import net.Indyuce.mmocore.spawnpoint.def.SpawnPointOption;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class DefaultMMOLoader extends MMOLoader {
|
public class DefaultMMOLoader extends MMOLoader {
|
||||||
@ -211,12 +210,10 @@ public class DefaultMMOLoader extends MMOLoader {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DefaultSpawnOption loadDefaultSpawnOption(MMOLineConfig config) {
|
public DefaultSpawnOption loadDefaultSpawnOption(MMOLineConfig config) {
|
||||||
if (config.getKey().equals("global"))
|
|
||||||
return new GlobalSpawnOption();
|
|
||||||
if (config.getKey().equals("last"))
|
if (config.getKey().equals("last"))
|
||||||
return new LastSpawnOption();
|
return new LastSpawnOption(config);
|
||||||
if (config.getKey().equals("location"))
|
if (config.getKey().equals("spawnpoint"))
|
||||||
return new LocationSpawnOption(config);
|
return new SpawnPointOption(config);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,7 @@ import net.Indyuce.mmocore.skill.cast.SkillCastingMode;
|
|||||||
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
||||||
import net.Indyuce.mmocore.skilltree.SkillTreeStatus;
|
import net.Indyuce.mmocore.skilltree.SkillTreeStatus;
|
||||||
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
import net.Indyuce.mmocore.waypoint.Waypoint;
|
import net.Indyuce.mmocore.waypoint.Waypoint;
|
||||||
import net.Indyuce.mmocore.waypoint.WaypointOption;
|
import net.Indyuce.mmocore.waypoint.WaypointOption;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
@ -84,6 +85,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
*/
|
*/
|
||||||
private double health;
|
private double health;
|
||||||
private Guild guild;
|
private Guild guild;
|
||||||
|
|
||||||
|
private SpawnPointContext lastSpawnPointContext;
|
||||||
private SkillCastingInstance skillCasting;
|
private SkillCastingInstance skillCasting;
|
||||||
private final PlayerQuests questData;
|
private final PlayerQuests questData;
|
||||||
private final PlayerStats playerStats;
|
private final PlayerStats playerStats;
|
||||||
@ -128,6 +131,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
*/
|
*/
|
||||||
private final Map<String, Integer> tableItemClaims = new HashMap<>();
|
private final Map<String, Integer> tableItemClaims = new HashMap<>();
|
||||||
|
|
||||||
|
private boolean shouldTeleportWhenJoin;
|
||||||
|
|
||||||
// NON-FINAL player data stuff made public to facilitate field change
|
// NON-FINAL player data stuff made public to facilitate field change
|
||||||
public boolean noCooldown;
|
public boolean noCooldown;
|
||||||
|
|
||||||
@ -191,6 +196,21 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
node.getExperienceTable().claimRemovableTrigger(this, node);
|
node.getExperienceTable().claimRemovableTrigger(this, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is called when a player connects to a server and has shouldTeleportWhenJoin set to true.
|
||||||
|
* If the player is alive it means that he has been teleported to this server because of spawnpoints.
|
||||||
|
* If he is dead this will be done when he respawns.
|
||||||
|
*/
|
||||||
|
public void setupSpawnPoint() {
|
||||||
|
Validate.isTrue(MMOCore.plugin.spawnPointManager.isSpawnPoint(lastSpawnPointContext.getId()));
|
||||||
|
if (isOnline() && shouldTeleportWhenJoin && (lastSpawnPointContext.getServer().isEmpty() ||
|
||||||
|
lastSpawnPointContext.getServer().get().equalsIgnoreCase(MMOCore.plugin.pluginMessageManager.getServerName()))
|
||||||
|
&& !getPlayer().isDead()) {
|
||||||
|
MMOCore.plugin.spawnPointManager.getSpawnPoint(lastSpawnPointContext.getId()).whenRespawn(this);
|
||||||
|
shouldTeleportWhenJoin = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getPointSpent(SkillTree skillTree) {
|
public int getPointSpent(SkillTree skillTree) {
|
||||||
return pointSpent.getOrDefault(skillTree, 0);
|
return pointSpent.getOrDefault(skillTree, 0);
|
||||||
}
|
}
|
||||||
@ -351,7 +371,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the item is unlocked by the player
|
* @return If the item is unlocked by the player
|
||||||
* This is used for skills that can be locked & unlocked.
|
* This is used for skills that can be locked & unlocked.
|
||||||
*/
|
*/
|
||||||
public boolean hasUnlocked(Unlockable unlockable) {
|
public boolean hasUnlocked(Unlockable unlockable) {
|
||||||
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey());
|
return unlockable.isUnlockedByDefault() || unlockedItems.contains(unlockable.getUnlockNamespacedKey());
|
||||||
@ -366,7 +386,8 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
Validate.isTrue(!unlockable.isUnlockedByDefault(), "Cannot unlock an item unlocked by default");
|
Validate.isTrue(!unlockable.isUnlockedByDefault(), "Cannot unlock an item unlocked by default");
|
||||||
unlockable.whenUnlocked(this);
|
unlockable.whenUnlocked(this);
|
||||||
final boolean wasLocked = unlockedItems.add(unlockable.getUnlockNamespacedKey());
|
final boolean wasLocked = unlockedItems.add(unlockable.getUnlockNamespacedKey());
|
||||||
// Call the event synchronously
|
Bukkit.broadcastMessage("Unlocked " + unlockable.getUnlockNamespacedKey());
|
||||||
|
// Call the event synchronously
|
||||||
if (wasLocked)
|
if (wasLocked)
|
||||||
Bukkit.getScheduler().runTask(MythicLib.plugin, () -> Bukkit.getPluginManager().callEvent(new ItemUnlockedEvent(this, unlockable.getUnlockNamespacedKey())));
|
Bukkit.getScheduler().runTask(MythicLib.plugin, () -> Bukkit.getPluginManager().callEvent(new ItemUnlockedEvent(this, unlockable.getUnlockNamespacedKey())));
|
||||||
return wasLocked;
|
return wasLocked;
|
||||||
@ -454,6 +475,18 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
this.lastActivity.put(activity, timestamp);
|
this.lastActivity.put(activity, timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SpawnPointContext getLastSpawnPointContext() {
|
||||||
|
return lastSpawnPointContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastSpawnPointContext(SpawnPointContext lastSpawnPointContext) {
|
||||||
|
this.lastSpawnPointContext = lastSpawnPointContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShouldTeleportWhenJoin(boolean shouldTeleport) {
|
||||||
|
this.shouldTeleportWhenJoin = shouldTeleport;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLastLogin() {
|
public long getLastLogin() {
|
||||||
return getMMOPlayerData().getLastLogActivity();
|
return getMMOPlayerData().getLastLogActivity();
|
||||||
@ -1221,7 +1254,7 @@ public class PlayerData extends SynchronizedDataHolder implements OfflinePlayerD
|
|||||||
* checks if they could potentially upgrade to one of these
|
* checks if they could potentially upgrade to one of these
|
||||||
*
|
*
|
||||||
* @return If the player can change its current class to
|
* @return If the player can change its current class to
|
||||||
* a subclass
|
* a subclass
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean canChooseSubclass() {
|
public boolean canChooseSubclass() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.Indyuce.mmocore.api.player.attribute;
|
package net.Indyuce.mmocore.api.player.attribute;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import io.lumine.mythic.lib.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import io.lumine.mythic.lib.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
import io.lumine.mythic.lib.UtilityMethods;
|
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.modifier.Closeable;
|
import io.lumine.mythic.lib.player.modifier.Closeable;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.Indyuce.mmocore.api.quest;
|
package net.Indyuce.mmocore.api.quest;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import io.lumine.mythic.lib.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import io.lumine.mythic.lib.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
import io.lumine.mythic.lib.util.Closeable;
|
import io.lumine.mythic.lib.util.Closeable;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.Indyuce.mmocore.api.util;
|
package net.Indyuce.mmocore.api.util;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import io.lumine.mythic.lib.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.hologram.Hologram;
|
import io.lumine.mythic.lib.hologram.Hologram;
|
||||||
import io.lumine.mythic.lib.version.VersionMaterial;
|
import io.lumine.mythic.lib.version.VersionMaterial;
|
||||||
|
@ -30,6 +30,7 @@ public class AdminCommandTreeNode extends CommandTreeNode {
|
|||||||
addChild(new PointsCommandTreeNode("skill-realloc", this, PlayerData::setSkillReallocationPoints, PlayerData::giveSkillReallocationPoints, PlayerData::getSkillReallocationPoints));
|
addChild(new PointsCommandTreeNode("skill-realloc", this, PlayerData::setSkillReallocationPoints, PlayerData::giveSkillReallocationPoints, PlayerData::getSkillReallocationPoints));
|
||||||
addChild(new PointsCommandTreeNode("skill-tree-realloc", this, PlayerData::setSkillTreeReallocationPoints, PlayerData::giveSkillTreeReallocationPoints, PlayerData::getSkillTreeReallocationPoints));
|
addChild(new PointsCommandTreeNode("skill-tree-realloc", this, PlayerData::setSkillTreeReallocationPoints, PlayerData::giveSkillTreeReallocationPoints, PlayerData::getSkillTreeReallocationPoints));
|
||||||
addChild(new SkillTreePointsCommandTreeNode(this, (playerData, integer, s) -> playerData.setSkillTreePoints(s, integer), (playerData, integer, s) -> playerData.giveSkillTreePoints(s, integer), ((playerData, s) -> playerData.getSkillTreePoint(s))));
|
addChild(new SkillTreePointsCommandTreeNode(this, (playerData, integer, s) -> playerData.setSkillTreePoints(s, integer), (playerData, integer, s) -> playerData.giveSkillTreePoints(s, integer), ((playerData, s) -> playerData.getSkillTreePoint(s))));
|
||||||
|
addChild(new SpawnPointCommandTreeNode(this));
|
||||||
for (PlayerResource res : PlayerResource.values())
|
for (PlayerResource res : PlayerResource.values())
|
||||||
addChild(new ResourceCommandTreeNode(res.name().toLowerCase(), this, res));
|
addChild(new ResourceCommandTreeNode(res.name().toLowerCase(), this, res));
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class MMOCoreProfileDataModule implements ProfileDataModule, Listener {
|
|||||||
@Override
|
@Override
|
||||||
public void processPlaceholderRequest(PlaceholderRequest placeholderRequest) {
|
public void processPlaceholderRequest(PlaceholderRequest placeholderRequest) {
|
||||||
final PlayerData fictiveData = new PlayerData(new MMOPlayerData(placeholderRequest.getProfile().getUniqueId()));
|
final PlayerData fictiveData = new PlayerData(new MMOPlayerData(placeholderRequest.getProfile().getUniqueId()));
|
||||||
MMOCore.plugin.playerDataManager.getDataHandler().loadData(fictiveData).thenRun(() -> {
|
MMOCore.plugin.playerDataManager.loadData(fictiveData).thenRun(() -> {
|
||||||
placeholderRequest.addPlaceholder("class", fictiveData.getProfess().getName());
|
placeholderRequest.addPlaceholder("class", fictiveData.getProfess().getName());
|
||||||
placeholderRequest.addPlaceholder("level", fictiveData.getLevel());
|
placeholderRequest.addPlaceholder("level", fictiveData.getLevel());
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.Indyuce.mmocore.experience;
|
package net.Indyuce.mmocore.experience;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.UtilityMethods;
|
import io.lumine.mythic.lib.UtilityMethods;
|
||||||
|
import io.lumine.mythic.lib.gson.Gson;
|
||||||
|
import io.lumine.mythic.lib.gson.JsonElement;
|
||||||
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.ConfigMessage;
|
import net.Indyuce.mmocore.api.ConfigMessage;
|
||||||
import net.Indyuce.mmocore.api.SoundEvent;
|
import net.Indyuce.mmocore.api.SoundEvent;
|
||||||
|
@ -104,6 +104,7 @@ public class ConfigManager {
|
|||||||
loadDefaultFile("triggers.yml");
|
loadDefaultFile("triggers.yml");
|
||||||
loadDefaultFile("conditions.yml");
|
loadDefaultFile("conditions.yml");
|
||||||
loadDefaultFile("guilds.yml");
|
loadDefaultFile("guilds.yml");
|
||||||
|
loadDefaultFile("spawn-points.yml");
|
||||||
|
|
||||||
final ConfigurationSection config = MMOCore.plugin.getConfig();
|
final ConfigurationSection config = MMOCore.plugin.getConfig();
|
||||||
commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose"));
|
commandVerbose.reload(MMOCore.plugin.getConfig().getConfigurationSection("command-verbose"));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
import io.lumine.mythic.lib.gson.JsonParseException;
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
import net.Indyuce.mmocore.experience.source.type.ExperienceSource;
|
||||||
import net.Indyuce.mmocore.api.block.BlockType;
|
import net.Indyuce.mmocore.api.block.BlockType;
|
||||||
|
@ -1,55 +1,54 @@
|
|||||||
package net.Indyuce.mmocore.manager;
|
package net.Indyuce.mmocore.manager;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.UtilityMethods;
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import io.lumine.mythic.lib.util.ConfigFile;
|
import io.lumine.mythic.lib.util.ConfigFile;
|
||||||
import io.lumine.mythic.lib.util.configobject.ConfigSectionObject;
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.spawnpoint.SpawnPoint;
|
import net.Indyuce.mmocore.spawnpoint.SpawnPoint;
|
||||||
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
||||||
import org.bukkit.Location;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
import java.util.logging.Level;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SpawnPointManager implements MMOCoreManager {
|
public class SpawnPointManager implements MMOCoreManager {
|
||||||
/**
|
|
||||||
* Ordered by world for faster access time.
|
|
||||||
*/
|
|
||||||
private final Map<World, List<SpawnPoint>> spawnPoints = new HashMap<>();
|
|
||||||
|
|
||||||
private Location globalSpawn;
|
private final Map<String, SpawnPoint> spawnPoints = new HashMap<>();
|
||||||
|
|
||||||
private List<DefaultSpawnOption> defaultSpawnOptions = new ArrayList<>();
|
private List<DefaultSpawnOption> defaultSpawnOptions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public List<SpawnPoint> getSpawnPoints(World world) {
|
public SpawnPoint getSpawnPoint(String id) {
|
||||||
return spawnPoints.getOrDefault(world, new ArrayList<>());
|
return spawnPoints.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSpawnPoint(String id) {
|
||||||
|
return spawnPoints.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<SpawnPoint> getAll() {
|
||||||
|
return spawnPoints.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(boolean clearBefore) {
|
public void initialize(boolean clearBefore) {
|
||||||
FileConfiguration config = new ConfigFile(MMOCore.plugin, "", "spawn-points").getConfig();
|
FileConfiguration config = new ConfigFile(MMOCore.plugin, "", "spawn-points").getConfig();
|
||||||
|
Validate.isTrue(config.isConfigurationSection("spawn-points.default"), "You must specify a default spawn-point.");
|
||||||
if (config.isConfigurationSection("spawn-points"))
|
if (config.isConfigurationSection("spawn-points"))
|
||||||
for (String key : config.getConfigurationSection("spawn-points").getKeys(false)) {
|
for (String key : config.getConfigurationSection("spawn-points").getKeys(false)) {
|
||||||
SpawnPoint spawnPoint = new SpawnPoint(config.getConfigurationSection("spawn-points." + key));
|
try{
|
||||||
spawnPoints.putIfAbsent(spawnPoint.getLocation().getWorld(), new ArrayList<>());
|
SpawnPoint spawnPoint = new SpawnPoint(config.getConfigurationSection("spawn-points." + key));
|
||||||
spawnPoints.get(spawnPoint.getLocation().getWorld()).add(spawnPoint);
|
spawnPoints.put(spawnPoint.getId(), spawnPoint);
|
||||||
|
}catch (Exception e){
|
||||||
|
MMOCore.log(Level.WARNING,"An error occured while loading spawnpoint " + key + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
globalSpawn = UtilityMethods.readLocation(new ConfigSectionObject(config.getConfigurationSection("global-spawn")));
|
|
||||||
for (String defaultSpawnOption : config.getStringList("default-spawn")) {
|
for (String defaultSpawnOption : config.getStringList("default-spawn")) {
|
||||||
defaultSpawnOptions.add(MMOCore.plugin.loadManager.loadDefaultSpawnOption(new MMOLineConfig(defaultSpawnOption)));
|
defaultSpawnOptions.add(MMOCore.plugin.loadManager.loadDefaultSpawnOption(new MMOLineConfig(defaultSpawnOption)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getGlobalSpawn() {
|
|
||||||
return globalSpawn;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DefaultSpawnOption> getDefaultSpawnOptions() {
|
public List<DefaultSpawnOption> getDefaultSpawnOptions() {
|
||||||
return new ArrayList(defaultSpawnOptions);
|
return new ArrayList(defaultSpawnOptions);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import io.lumine.mythic.lib.data.sql.SQLDataSynchronizer;
|
|||||||
import io.lumine.mythic.lib.gson.JsonArray;
|
import io.lumine.mythic.lib.gson.JsonArray;
|
||||||
import io.lumine.mythic.lib.gson.JsonElement;
|
import io.lumine.mythic.lib.gson.JsonElement;
|
||||||
import io.lumine.mythic.lib.gson.JsonObject;
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
|
import io.lumine.mythic.lib.gson.JsonParser;
|
||||||
|
|
||||||
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.api.player.profess.PlayerClass;
|
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||||
@ -15,6 +17,7 @@ import net.Indyuce.mmocore.guild.provided.Guild;
|
|||||||
import net.Indyuce.mmocore.skill.ClassSkill;
|
import net.Indyuce.mmocore.skill.ClassSkill;
|
||||||
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
||||||
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -89,6 +92,11 @@ public class MMOCoreDataSynchronizer extends SQLDataSynchronizer<PlayerData> {
|
|||||||
getData().getWaypoints().addAll(MMOCoreUtils.jsonArrayToList(result.getString("waypoints")));
|
getData().getWaypoints().addAll(MMOCoreUtils.jsonArrayToList(result.getString("waypoints")));
|
||||||
if (!isEmpty(result.getString("friends")))
|
if (!isEmpty(result.getString("friends")))
|
||||||
MMOCoreUtils.jsonArrayToList(result.getString("friends")).forEach(str -> getData().getFriends().add(UUID.fromString(str)));
|
MMOCoreUtils.jsonArrayToList(result.getString("friends")).forEach(str -> getData().getFriends().add(UUID.fromString(str)));
|
||||||
|
if (!isEmpty(result.getString("last_spawn_point")))
|
||||||
|
getData().setLastSpawnPointContext(new SpawnPointContext(new JsonParser().parseString(result.getString("last_spawn_point")).getAsJsonObject()));
|
||||||
|
getData().setShouldTeleportWhenJoin(result.getBoolean("should_teleport_when_join"));
|
||||||
|
getData().setupSpawnPoint();
|
||||||
|
|
||||||
if (!isEmpty(result.getString("skills"))) {
|
if (!isEmpty(result.getString("skills"))) {
|
||||||
JsonObject object = MythicLib.plugin.getGson().fromJson(result.getString("skills"), JsonObject.class);
|
JsonObject object = MythicLib.plugin.getGson().fromJson(result.getString("skills"), JsonObject.class);
|
||||||
for (Map.Entry<String, JsonElement> entry : object.entrySet())
|
for (Map.Entry<String, JsonElement> entry : object.entrySet())
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.Indyuce.mmocore.manager.data.sql;
|
package net.Indyuce.mmocore.manager.data.sql;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import io.lumine.mythic.lib.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
import io.lumine.mythic.lib.data.sql.SQLDataSource;
|
import io.lumine.mythic.lib.data.sql.SQLDataSource;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
package net.Indyuce.mmocore.manager.data.sql;
|
package net.Indyuce.mmocore.manager.data.sql;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import io.lumine.mythic.lib.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import io.lumine.mythic.lib.gson.JsonObject;
|
||||||
import io.lumine.mythic.lib.UtilityMethods;
|
import io.lumine.mythic.lib.UtilityMethods;
|
||||||
import io.lumine.mythic.lib.data.sql.SQLDataSource;
|
import io.lumine.mythic.lib.data.sql.SQLDataSource;
|
||||||
import io.lumine.mythic.lib.data.sql.SQLSynchronizedDataHandler;
|
import io.lumine.mythic.lib.data.sql.SQLSynchronizedDataHandler;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
|
||||||
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
|
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
|
||||||
|
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, OfflinePlayerData, MMOCoreDataSynchronizer> {
|
public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, OfflinePlayerData> {
|
||||||
public SQLDataHandler(SQLDataSource dataSource) {
|
public SQLDataHandler(SQLDataSource dataSource) {
|
||||||
super(dataSource);
|
super(dataSource);
|
||||||
}
|
}
|
||||||
@ -34,7 +32,9 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
|||||||
"health", "FLOAT",
|
"health", "FLOAT",
|
||||||
"mana", "FLOAT",
|
"mana", "FLOAT",
|
||||||
"stamina", "FLOAT",
|
"stamina", "FLOAT",
|
||||||
"stellium", "FLOAT"};
|
"stellium", "FLOAT",
|
||||||
|
"last_spawn_point", "LONGTEXT",
|
||||||
|
"spawn_when_join", "TINYINT"};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@ -67,6 +67,8 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
|||||||
"stellium FLOAT," +
|
"stellium FLOAT," +
|
||||||
"unlocked_items LONGTEXT," +
|
"unlocked_items LONGTEXT," +
|
||||||
"class_info LONGTEXT," +
|
"class_info LONGTEXT," +
|
||||||
|
"last_spawn_point LONGTEXT," +
|
||||||
|
"spawn_when_join TINYINT," +
|
||||||
"is_saved TINYINT," +
|
"is_saved TINYINT," +
|
||||||
"PRIMARY KEY (uuid));");
|
"PRIMARY KEY (uuid));");
|
||||||
|
|
||||||
@ -122,6 +124,7 @@ public class SQLDataHandler extends SQLSynchronizedDataHandler<PlayerData, Offli
|
|||||||
updater.addData("professions", data.getCollectionSkills().toJsonString());
|
updater.addData("professions", data.getCollectionSkills().toJsonString());
|
||||||
updater.addData("quests", data.getQuestData().toJsonString());
|
updater.addData("quests", data.getQuestData().toJsonString());
|
||||||
updater.addData("class_info", createClassInfoData(data).toString());
|
updater.addData("class_info", createClassInfoData(data).toString());
|
||||||
|
updater.addData("last_spawn_point", data.getLastSpawnPointContext().toJson());
|
||||||
updater.addJSONArray("unlocked_items", data.getUnlockedItems());
|
updater.addJSONArray("unlocked_items", data.getUnlockedItems());
|
||||||
if (!autosave)
|
if (!autosave)
|
||||||
updater.addData("is_saved", 1);
|
updater.addData("is_saved", 1);
|
||||||
|
@ -10,6 +10,7 @@ import net.Indyuce.mmocore.guild.provided.Guild;
|
|||||||
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
import net.Indyuce.mmocore.manager.data.OfflinePlayerData;
|
||||||
import net.Indyuce.mmocore.skill.ClassSkill;
|
import net.Indyuce.mmocore.skill.ClassSkill;
|
||||||
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -17,6 +18,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -38,6 +40,7 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadFromSection(PlayerData data, ConfigurationSection config) {
|
public void loadFromSection(PlayerData data, ConfigurationSection config) {
|
||||||
|
MMOCore.log("LOAD");
|
||||||
|
|
||||||
// Reset stats linked to triggers.
|
// Reset stats linked to triggers.
|
||||||
data.resetTriggerStats();
|
data.resetTriggerStats();
|
||||||
@ -133,14 +136,17 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
|
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
|
||||||
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
|
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
|
||||||
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
|
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
|
||||||
|
data.setLastSpawnPointContext(new SpawnPointContext(config.getString("last-spawn-point.id"),
|
||||||
|
Optional.ofNullable(config.getString("last-spawn-point.server"))));
|
||||||
|
data.setShouldTeleportWhenJoin(config.getBoolean("should-teleport-when-join", false));
|
||||||
|
data.setupSpawnPoint();
|
||||||
if (data.isOnline() && !data.getPlayer().isDead())
|
if (data.isOnline() && !data.getPlayer().isDead())
|
||||||
data.getPlayer().setHealth(MMOCoreUtils.fixResource(config.getDouble("health"), data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
data.getPlayer().setHealth(MMOCoreUtils.fixResource(config.getDouble("health"), data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveInSection(PlayerData data, ConfigurationSection config) {
|
public void saveInSection(PlayerData data, ConfigurationSection config) {
|
||||||
|
MMOCore.log("SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVE");
|
||||||
config.set("class-points", data.getClassPoints());
|
config.set("class-points", data.getClassPoints());
|
||||||
config.set("skill-points", data.getSkillPoints());
|
config.set("skill-points", data.getSkillPoints());
|
||||||
config.set("skill-reallocation-points", data.getSkillReallocationPoints());
|
config.set("skill-reallocation-points", data.getSkillReallocationPoints());
|
||||||
@ -168,6 +174,7 @@ public class YAMLPlayerDataHandler extends YAMLSynchronizedDataHandler<PlayerDat
|
|||||||
|
|
||||||
config.set("bound-skills", null);
|
config.set("bound-skills", null);
|
||||||
data.mapBoundSkills().forEach((slot, skill) -> config.set("bound-skills." + slot, skill));
|
data.mapBoundSkills().forEach((slot, skill) -> config.set("bound-skills." + slot, skill));
|
||||||
|
MMOCore.log(data.getUnlockedItems().size()+" unlocked.");
|
||||||
config.set("unlocked-items", data.getUnlockedItems().stream().collect(Collectors.toList()));
|
config.set("unlocked-items", data.getUnlockedItems().stream().collect(Collectors.toList()));
|
||||||
config.set("attribute", null);
|
config.set("attribute", null);
|
||||||
config.createSection("attribute");
|
config.createSection("attribute");
|
||||||
|
@ -12,7 +12,7 @@ public record SkillTreePath(SkillTree tree, IntegerCoordinates coordinates, Skil
|
|||||||
SkillTreeStatus toStatus = playerData.getNodeStatus(to);
|
SkillTreeStatus toStatus = playerData.getNodeStatus(to);
|
||||||
if (fromStatus == SkillTreeStatus.UNLOCKED && toStatus == SkillTreeStatus.UNLOCKED)
|
if (fromStatus == SkillTreeStatus.UNLOCKED && toStatus == SkillTreeStatus.UNLOCKED)
|
||||||
return PathStatus.UNLOCKED;
|
return PathStatus.UNLOCKED;
|
||||||
if ((fromStatus == SkillTreeStatus.UNLOCKABLE && toStatus == SkillTreeStatus.LOCKED) || (fromStatus == SkillTreeStatus.LOCKED && toStatus == SkillTreeStatus.UNLOCKABLE))
|
if ((fromStatus == SkillTreeStatus.UNLOCKABLE && toStatus == SkillTreeStatus.UNLOCKED) || (fromStatus == SkillTreeStatus.UNLOCKED && toStatus == SkillTreeStatus.UNLOCKABLE))
|
||||||
return PathStatus.UNLOCKABLE;
|
return PathStatus.UNLOCKABLE;
|
||||||
if (fromStatus == SkillTreeStatus.FULLY_LOCKED || toStatus == SkillTreeStatus.FULLY_LOCKED)
|
if (fromStatus == SkillTreeStatus.FULLY_LOCKED || toStatus == SkillTreeStatus.FULLY_LOCKED)
|
||||||
return PathStatus.FULLY_LOCKED;
|
return PathStatus.FULLY_LOCKED;
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package net.Indyuce.mmocore.spawnpoint;
|
package net.Indyuce.mmocore.spawnpoint;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
|
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.script.Script;
|
import io.lumine.mythic.lib.script.Script;
|
||||||
import io.lumine.mythic.lib.script.condition.Condition;
|
import io.lumine.mythic.lib.script.condition.Condition;
|
||||||
import io.lumine.mythic.lib.skill.SimpleSkill;
|
import io.lumine.mythic.lib.skill.SimpleSkill;
|
||||||
import io.lumine.mythic.lib.skill.Skill;
|
import io.lumine.mythic.lib.skill.Skill;
|
||||||
|
import io.lumine.mythic.lib.skill.SkillMetadata;
|
||||||
import io.lumine.mythic.lib.skill.handler.MythicLibSkillHandler;
|
import io.lumine.mythic.lib.skill.handler.MythicLibSkillHandler;
|
||||||
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
|
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
|
||||||
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
import io.lumine.mythic.lib.skill.trigger.TriggerType;
|
||||||
@ -14,41 +16,53 @@ import io.lumine.mythic.lib.util.configobject.ConfigSectionObject;
|
|||||||
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.player.Unlockable;
|
import net.Indyuce.mmocore.player.Unlockable;
|
||||||
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class SpawnPoint implements Unlockable, SpawnProvider {
|
public class SpawnPoint implements Unlockable {
|
||||||
private final String id;
|
private final String id;
|
||||||
Location location;
|
private final Location location;
|
||||||
Condition unlockCondition;
|
private final Condition unlockCondition;
|
||||||
double strength;
|
private final double strength;
|
||||||
|
|
||||||
private Optional<Skill> unlockScript;
|
private final Optional<Skill> unlockScript;
|
||||||
private Optional<Skill> respawnScript;
|
private final Optional<Skill> respawnScript;
|
||||||
|
|
||||||
public SpawnPoint(ConfigurationSection section) {
|
public SpawnPoint(ConfigurationSection section) {
|
||||||
id = section.getName();
|
id = section.getName();
|
||||||
location = new Location(MMOCore.plugin.getServer().getWorld(section.getString("world")), section.getDouble("x"), section.getDouble("y"), section.getDouble("z"));
|
location = UtilityMethods.readLocation(new ConfigSectionObject(section.getConfigurationSection("location")));
|
||||||
|
Validate.isTrue(section.isConfigurationSection("unlock-condition"), "You must specify an unlock condition.");
|
||||||
unlockCondition = MythicLib.plugin.getSkills().loadCondition(
|
unlockCondition = MythicLib.plugin.getSkills().loadCondition(
|
||||||
new ConfigSectionObject(section.getConfigurationSection("unlock-condition")));
|
new ConfigSectionObject(section.getConfigurationSection("unlock-condition")));
|
||||||
strength = section.getDouble("strength");
|
|
||||||
if (section.isConfigurationSection("script.unlock"))
|
strength = section.getDouble("strength", 1);
|
||||||
|
Skill unlockScript = null;
|
||||||
|
if (section.isConfigurationSection("unlock-script"))
|
||||||
try {
|
try {
|
||||||
final Script script = MythicLib.plugin.getSkills().loadScript(section.getConfigurationSection("script.unlock"));
|
final Script script = MythicLib.plugin.getSkills().loadScript(section.getConfigurationSection("unlock-script"));
|
||||||
unlockScript = Optional.of(new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script)));
|
unlockScript = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script));
|
||||||
} catch (RuntimeException exception) {
|
} catch (RuntimeException exception) {
|
||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load unlock script: " + exception.getMessage());
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load unlock script: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
if (section.isConfigurationSection("script.respawn"))
|
this.unlockScript = Optional.ofNullable(unlockScript);
|
||||||
|
Skill respawnScript = null;
|
||||||
|
if (section.isConfigurationSection("respawn-script"))
|
||||||
try {
|
try {
|
||||||
final Script script = MythicLib.plugin.getSkills().loadScript(section.getConfigurationSection("script.respawn"));
|
final Script script = MythicLib.plugin.getSkills().loadScript(section.getConfigurationSection("respawn-script"));
|
||||||
respawnScript = Optional.of(new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script)));
|
respawnScript = new SimpleSkill(TriggerType.CAST, new MythicLibSkillHandler(script));
|
||||||
} catch (RuntimeException exception) {
|
} catch (RuntimeException exception) {
|
||||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load respawn script: " + exception.getMessage());
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load respawn script: " + exception.getMessage());
|
||||||
}
|
}
|
||||||
|
this.respawnScript = Optional.ofNullable(respawnScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
@ -75,19 +89,16 @@ public class SpawnPoint implements Unlockable, SpawnProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void whenUnlocked(PlayerData playerData) {
|
public void whenUnlocked(PlayerData playerData) {
|
||||||
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.OTHER);
|
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
|
||||||
unlockScript.ifPresent(skill -> skill.cast(new TriggerMetadata(caster)));
|
unlockScript.ifPresent(skill -> skill.cast(new TriggerMetadata(caster)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void whenRespawn(PlayerData playerData) {
|
public boolean matchesCondition(PlayerData playerData) {
|
||||||
|
return unlockCondition.isMet(new SkillMetadata(null, playerData.getMMOPlayerData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Support BungeeCord. Point compliqué car il faut executer le script sur le serveur dans lequel le joueur va etre tp.
|
public void whenRespawn(PlayerData playerData) {
|
||||||
@Override
|
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.MAIN_HAND);
|
||||||
public void respawn(PlayerData playerData) {
|
|
||||||
playerData.getPlayer().teleport(location);
|
|
||||||
PlayerMetadata caster = playerData.getMMOPlayerData().getStatMap().cache(EquipmentSlot.OTHER);
|
|
||||||
respawnScript.ifPresent(skill -> skill.cast(new TriggerMetadata(caster)));
|
respawnScript.ifPresent(skill -> skill.cast(new TriggerMetadata(caster)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package net.Indyuce.mmocore.spawnpoint;
|
|
||||||
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
|
||||||
|
|
||||||
public interface SpawnProvider {
|
|
||||||
void respawn(PlayerData playerData);
|
|
||||||
}
|
|
@ -2,7 +2,8 @@ package net.Indyuce.mmocore.spawnpoint.def;
|
|||||||
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import org.bukkit.Location;
|
import net.Indyuce.mmocore.spawnpoint.SpawnPoint;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@ -12,6 +13,10 @@ public abstract class DefaultSpawnOption {
|
|||||||
|
|
||||||
protected final String worldExpression;
|
protected final String worldExpression;
|
||||||
|
|
||||||
|
public DefaultSpawnOption() {
|
||||||
|
this.worldExpression = "true";
|
||||||
|
}
|
||||||
|
|
||||||
public DefaultSpawnOption(MMOLineConfig config) {
|
public DefaultSpawnOption(MMOLineConfig config) {
|
||||||
this.worldExpression = config.getString("world-expression");
|
this.worldExpression = config.getString("world-expression");
|
||||||
}
|
}
|
||||||
@ -23,8 +28,6 @@ public abstract class DefaultSpawnOption {
|
|||||||
return matcher.matches();
|
return matcher.matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Location getSpawnLocation(PlayerData playerData);
|
public abstract SpawnPointContext getSpawnPointContext(PlayerData playerData);
|
||||||
|
|
||||||
public abstract void whenRespawn(PlayerData playerData);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package net.Indyuce.mmocore.spawnpoint.def;
|
|
||||||
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
|
|
||||||
public class GlobalSpawnOption extends DefaultSpawnOption {
|
|
||||||
|
|
||||||
public GlobalSpawnOption(MMOLineConfig config) {
|
|
||||||
super(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getSpawnLocation(PlayerData playerData) {
|
|
||||||
return MMOCore.plugin.spawnPointManager.getGlobalSpawn();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void whenRespawn() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +1,19 @@
|
|||||||
package net.Indyuce.mmocore.spawnpoint.def;
|
package net.Indyuce.mmocore.spawnpoint.def;
|
||||||
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import org.bukkit.Location;
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
|
|
||||||
public class LastSpawnOption extends DefaultSpawnOption
|
public class LastSpawnOption extends DefaultSpawnOption {
|
||||||
{
|
|
||||||
|
|
||||||
public LastSpawnOption(MMOLineConfig config) {
|
public LastSpawnOption(MMOLineConfig config) {
|
||||||
super(config);
|
super(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
|
||||||
@Override
|
@Override
|
||||||
public Location getSpawnLocation(PlayerData playerData) {
|
public SpawnPointContext getSpawnPointContext(PlayerData playerData) {
|
||||||
return null;
|
return playerData.getLastSpawnPointContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void whenRespawn(PlayerData playerData) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package net.Indyuce.mmocore.spawnpoint.def;
|
|
||||||
|
|
||||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
|
||||||
import io.lumine.mythic.lib.util.configobject.ConfigObject;
|
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.World;
|
|
||||||
|
|
||||||
import javax.swing.text.html.Option;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class LocationSpawnOption extends DefaultSpawnOption {
|
|
||||||
private final double x, y, z;
|
|
||||||
private final Optional<World> world;
|
|
||||||
|
|
||||||
public LocationSpawnOption(MMOLineConfig config) {
|
|
||||||
super(config);
|
|
||||||
this.x = config.getDouble("spawn-x");
|
|
||||||
this.y = config.getDouble("spawn-y");
|
|
||||||
this.z = config.getDouble("spawn-z");
|
|
||||||
this.world = Optional.ofNullable(Bukkit.getWorld(config.getString("spawn-world")));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Location getSpawnLocation(PlayerData playerData) {
|
|
||||||
return new Location(world.orElseGet(() -> playerData.getPlayer().getWorld()), x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void whenRespawn(PlayerData playerData) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -45,6 +45,7 @@ public class MMOCoreBukkit {
|
|||||||
Bukkit.getPluginManager().registerEvents(new FishingListener(), plugin);
|
Bukkit.getPluginManager().registerEvents(new FishingListener(), plugin);
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), plugin);
|
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), plugin);
|
||||||
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), plugin);
|
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), plugin);
|
||||||
|
Bukkit.getPluginManager().registerEvents(new SpawnPointsListener(), plugin);
|
||||||
// Bukkit.getPluginManager().registerEvents(new ClassTriggers(), plugin);
|
// Bukkit.getPluginManager().registerEvents(new ClassTriggers(), plugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,33 +3,63 @@ package net.Indyuce.mmocore.listener;
|
|||||||
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.spawnpoint.SpawnPoint;
|
import net.Indyuce.mmocore.spawnpoint.SpawnPoint;
|
||||||
|
import net.Indyuce.mmocore.spawnpoint.SpawnPointContext;
|
||||||
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
import net.Indyuce.mmocore.spawnpoint.def.DefaultSpawnOption;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class SpawnPointsListener implements Listener {
|
public class SpawnPointsListener implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onTeleport(PlayerTeleportEvent event) {
|
public void onTeleport(PlayerTeleportEvent event) {
|
||||||
event.getFrom()
|
if (!event.getFrom().getWorld().equals(event.getTo().getWorld())) {
|
||||||
|
PlayerData playerData = PlayerData.get(event.getPlayer());
|
||||||
|
getLastSpawnPointContext(playerData).ifPresent(playerData::setLastSpawnPointContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeath(PlayerDeathEvent event) {
|
public void onDeath(PlayerDeathEvent event) {
|
||||||
//TODO Only when module enabled
|
|
||||||
PlayerData playerData = PlayerData.get(event.getEntity());
|
PlayerData playerData = PlayerData.get(event.getEntity());
|
||||||
|
//TODO: Only when module enabled
|
||||||
|
Optional<SpawnPointContext> context = getLastSpawnPointContext(playerData);
|
||||||
|
if (context.isPresent()) {
|
||||||
|
SpawnPointContext spawnPointContext = context.get();
|
||||||
|
playerData.setLastSpawnPointContext(spawnPointContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSpawn(PlayerRespawnEvent event) {
|
||||||
|
PlayerData playerData = PlayerData.get(event.getPlayer());
|
||||||
|
Optional<SpawnPointContext> context = getLastSpawnPointContext(playerData);
|
||||||
|
if (context.isPresent()) {
|
||||||
|
SpawnPointContext spawnPointContext = context.get();
|
||||||
|
if (!spawnPointContext.isOtherServer()){
|
||||||
|
event.setRespawnLocation(spawnPointContext.getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
spawnPointContext.whenRespawn(playerData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<SpawnPointContext> getLastSpawnPointContext(PlayerData playerData) {
|
||||||
World world = playerData.getPlayer().getWorld();
|
World world = playerData.getPlayer().getWorld();
|
||||||
List<SpawnPoint> reachableSpawnPoints = MMOCore.plugin.spawnPointManager.
|
List<SpawnPoint> reachableSpawnPoints = MMOCore.plugin.spawnPointManager.
|
||||||
getSpawnPoints(world)
|
getAll()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(spawnPoint -> playerData.hasUnlocked(spawnPoint))
|
.filter(spawnPoint -> spawnPoint.getLocation().getWorld().equals(world) && playerData.hasUnlocked(spawnPoint))
|
||||||
.toList();
|
.toList();
|
||||||
if (!reachableSpawnPoints.isEmpty()) {
|
if (!reachableSpawnPoints.isEmpty()) {
|
||||||
|
|
||||||
double minDistance = Double.MAX_VALUE;
|
double minDistance = Double.MAX_VALUE;
|
||||||
SpawnPoint closestSpawnPoint = null;
|
SpawnPoint closestSpawnPoint = null;
|
||||||
for (SpawnPoint spawnPoint : reachableSpawnPoints) {
|
for (SpawnPoint spawnPoint : reachableSpawnPoints) {
|
||||||
@ -40,14 +70,12 @@ public class SpawnPointsListener implements Listener {
|
|||||||
closestSpawnPoint = spawnPoint;
|
closestSpawnPoint = spawnPoint;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playerData.getPlayer().teleport(closestSpawnPoint.getLocation());
|
return Optional.of(new SpawnPointContext(closestSpawnPoint.getId()));
|
||||||
closestSpawnPoint.whenRespawn(playerData);
|
|
||||||
} else
|
} else
|
||||||
for (DefaultSpawnOption defaultSpawnOption : MMOCore.plugin.spawnPointManager.getDefaultSpawnOptions())
|
for (DefaultSpawnOption defaultSpawnOption : MMOCore.plugin.spawnPointManager.getDefaultSpawnOptions())
|
||||||
if (defaultSpawnOption.matches(world)) {
|
if (defaultSpawnOption.matches(world)) {
|
||||||
playerData.getPlayer().teleport(defaultSpawnOption.getSpawnLocation(playerData));
|
return Optional.of(defaultSpawnOption.getSpawnPointContext(playerData));
|
||||||
defaultSpawnOption.whenRespawn();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user