Merge remote-tracking branch 'origin/master'

# Conflicts:
#	MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java
#	MMOCore-API/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java
This commit is contained in:
Ka0rX 2022-08-21 13:47:52 +02:00
commit f01391c6ab
22 changed files with 245 additions and 198 deletions

View File

@ -6,7 +6,7 @@ import io.lumine.mythic.lib.version.SpigotPlugin;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.social.PartyManager;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.PlayerActionBar;
import net.Indyuce.mmocore.manager.ActionBarManager;
import net.Indyuce.mmocore.api.player.attribute.AttributeModifier;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.command.*;
@ -64,7 +64,7 @@ public class MMOCore extends JavaPlugin {
public final SoundManager soundManager = new SoundManager();
public final RequestManager requestManager = new RequestManager();
public final ConfigItemManager configItems = new ConfigItemManager();
public final PlayerActionBar actionBarManager = new PlayerActionBar();
public final ActionBarManager actionBarManager = new ActionBarManager();
public final SkillManager skillManager = new SkillManager();
public final ClassManager classManager = new ClassManager();
public final DropTableManager dropTableManager = new DropTableManager();
@ -111,11 +111,11 @@ public class MMOCore extends JavaPlugin {
MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction());
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
// Skill creation
// Custom scripts
MythicLib.plugin.getSkills().registerMechanic("mana", config -> new ManaMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("stamina", config -> new StaminaMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("stellium", config -> new StelliumMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("experience", config -> new ExperienceMechanic(config));
MythicLib.plugin.getSkills().registerMechanic("mmocore_experience", config -> new ExperienceMechanic(config));
// Register extra objective, drop items...
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)

View File

@ -1,81 +0,0 @@
package net.Indyuce.mmocore.api;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.manager.StatManager;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.scheduler.BukkitRunnable;
import java.text.DecimalFormat;
public class PlayerActionBar extends BukkitRunnable {
boolean initialized = false;
private ActionBarConfig config;
private DecimalFormat digit;
public void reload(ConfigurationSection cfg) {
config = new ActionBarConfig(cfg);
digit = MythicLib.plugin.getMMOConfig().newDecimalFormat(config.digit);
if (!initialized && config.enabled) {
runTaskTimer(MMOCore.plugin, 0, config.ticks);
initialized = true;
}
}
public long getTimeOut() {
return config.timeout;
}
@Override
public void run() {
for (PlayerData data : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.getActivityTimeOut(PlayerActivity.ACTION_BAR_MESSAGE) == 0) {
Placeholders holders=getActionBarPlaceholder(data);
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(
holders.apply(data.getPlayer(), data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : config.format)));
}
}
public Placeholders getActionBarPlaceholder(PlayerData data) {
Placeholders holders= new Placeholders();
holders.register("health", digit.format(data.getPlayer().getHealth()));
holders.register("max_health", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
holders.register("mana_icon", data.getProfess().getManaDisplay().getIcon());
holders.register("mana", digit.format(data.getMana()));
holders.register("max_mana", StatManager.format("MAX_MANA", data.getStats().getStat("MAX_MANA")));
holders.register("stamina", digit.format(data.getStamina()));
holders.register("max_stamina", StatManager.format("MAX_STAMINA", data.getStats().getStat("MAX_STAMINA")));
holders.register("stellium", digit.format(data.getStellium()));
holders.register("max_stellium", StatManager.format("MAX_STELLIUM", data.getStats().getStat("MAX_STELLIUM")));
holders.register("class", data.getProfess().getName());
holders.register("xp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()));
holders.register("armor", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()));
holders.register("level", "" + data.getLevel());
holders.register("name", data.getPlayer().getDisplayName());
return holders;
}
private static class ActionBarConfig {
private final boolean enabled;
private final int ticks, timeout;
private final String digit, format;
private ActionBarConfig(ConfigurationSection config) {
enabled = config.getBoolean("enabled", false);
timeout = config.getInt("", 60);
digit = config.getString("decimal", "0.#");
ticks = config.getInt("ticks-to-update", 5);
format = config.getString("format", "please format me :c");
}
}
}

View File

@ -656,12 +656,12 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
final int x = getPlayer().getLocation().getBlockX();
final int y = getPlayer().getLocation().getBlockY();
final int z = getPlayer().getLocation().getBlockZ();
final int warpTime = target.getWarpTime();
int t;
public void run() {
if (!isOnline())
return;
if (getPlayer().getLocation().getBlockX() != x || getPlayer().getLocation().getBlockY() != y
if (!isOnline() || getPlayer().getLocation().getBlockX() != x
|| getPlayer().getLocation().getBlockY() != y
|| getPlayer().getLocation().getBlockZ() != z) {
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_CANCELLED).playTo(getPlayer());
MMOCore.plugin.configManager.getSimpleMessage("warping-canceled").send(getPlayer());
@ -670,8 +670,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return;
}
MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", "" + ((MMOCore.plugin.configManager.waypointWarpTime + 20 - t) / 20)).send(getPlayer());
if (t++ >= MMOCore.plugin.configManager.waypointWarpTime) {
MMOCore.plugin.configManager.getSimpleMessage("warping-comencing", "left", String.valueOf((warpTime - t) / 20)).send(getPlayer());
if (t++ >= warpTime) {
getPlayer().teleport(target.getLocation());
getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 20, 1, false, false));
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_TELEPORT).playTo(getPlayer());
@ -679,12 +679,14 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return;
}
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_CHARGE).playTo(getPlayer(), 1, (float) (t / Math.PI * 1.5 / MMOCore.plugin.configManager.waypointWarpTime + .5));
double r = Math.sin((double) t / MMOCore.plugin.configManager.waypointWarpTime * Math.PI);
MMOCore.plugin.soundManager.getSound(SoundEvent.WARP_CHARGE).playTo(getPlayer(), 1, (float) (.5 + t * 1.5 / warpTime));
final double r = Math.sin((double) t / warpTime * Math.PI);
for (double j = 0; j < Math.PI * 2; j += Math.PI / 4)
getPlayer().getLocation().getWorld().spawnParticle(Particle.REDSTONE,
getPlayer().getLocation().add(Math.cos((double) 5 * t / MMOCore.plugin.configManager.waypointWarpTime + j) * r, (double) 2 * t / MMOCore.plugin.configManager.waypointWarpTime, Math.sin((double) 5 * t / MMOCore.plugin.configManager.waypointWarpTime + j) * r), 1,
new Particle.DustOptions(Color.PURPLE, 1.25f));
getPlayer().getLocation().getWorld().spawnParticle(Particle.REDSTONE, getPlayer().getLocation().add(
Math.cos((double) 5 * t / warpTime + j) * r,
(double) 2 * t / warpTime,
Math.sin((double) 5 * t / warpTime + j) * r),
1, new Particle.DustOptions(Color.PURPLE, 1.25f));
}
}.runTaskTimer(MMOCore.plugin, 0, 1);
}

View File

@ -3,6 +3,7 @@ package net.Indyuce.mmocore.api.player.attribute;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.player.modifier.Closeable;
import io.lumine.mythic.lib.player.modifier.ModifierSource;
@ -100,7 +101,12 @@ public class PlayerAttributes {
return getInstance(attribute.getId());
}
@Deprecated
public int countSkillPoints() {
return countPoints();
}
public int countPoints() {
int n = 0;
for (AttributeInstance ins : instances.values())
n += ins.getBase();
@ -110,11 +116,12 @@ public class PlayerAttributes {
public class AttributeInstance {
private int spent;
private final String id;
private final String id, enumName;
private final Map<String, AttributeModifier> map = new HashMap<>();
public AttributeInstance(String attribute) {
id = attribute;
public AttributeInstance(String id) {
this.id = id;
this.enumName = UtilityMethods.enumName(this.id);
}
public int getBase() {
@ -146,10 +153,14 @@ public class PlayerAttributes {
if (attr.getType() == ModifierType.FLAT)
d += attr.getValue();
d += data.getMMOPlayerData().getStatMap().getStat("ADDITIONAL_" + enumName);
for (AttributeModifier attr : map.values())
if (attr.getType() == ModifierType.RELATIVE)
d *= attr.getValue();
d *= 1 + data.getMMOPlayerData().getStatMap().getStat("ADDITIONAL_" + enumName + "_PERCENT") / 100;
// cast to int at the last moment
return (int) d;
}

View File

@ -1,17 +1,16 @@
package net.Indyuce.mmocore.comp.placeholder;
import io.lumine.mythic.lib.MythicLib;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.OfflinePlayer;
import me.clip.placeholderapi.PlaceholderAPI;
import io.lumine.mythic.lib.MythicLib;
public class PlaceholderAPIParser implements PlaceholderParser {
public PlaceholderAPIParser() {
new RPGPlaceholders().register();
}
public PlaceholderAPIParser() {
new RPGPlaceholders().register();
}
@Override
public String parse(OfflinePlayer player, String string) {
return MythicLib.plugin.parseColors(PlaceholderAPI.setPlaceholders(player, string.replace("%player%", player.getName())));
}
@Override
public String parse(OfflinePlayer player, String string) {
return MythicLib.plugin.parseColors(PlaceholderAPI.setPlaceholders(player, string));
}
}

View File

@ -109,7 +109,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
}
else if (identifier.startsWith("profession_experience_"))
return String.valueOf(
return MythicLib.plugin.getMMOConfig().decimal.format(
playerData.getCollectionSkills().getExperience(identifier.substring(22).replace(" ", "-").replace("_", "-").toLowerCase()));
else if (identifier.startsWith("profession_next_level_"))

View File

@ -1,12 +1,13 @@
package net.Indyuce.mmocore.experience.source;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.api.MMOLineConfig;
import io.lumine.mythic.lib.api.event.PlayerKillEntityEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.experience.dispenser.ExperienceDispenser;
import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource;
import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
@ -16,23 +17,30 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.persistence.PersistentDataType;
import javax.annotation.Nullable;
public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
public final EntityType type;
private final EntityType type;
@Nullable
private final String displayName;
public KillMobExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser, config);
config.validate("type");
config.validateKeys("type");
displayName = config.contains("name") ? MythicLib.plugin.parseColors(config.getString("name")) : null;
type = EntityType.valueOf(config.getString("type").toUpperCase().replace("-", "_").replace(" ", "_"));
}
@Override
public ExperienceSourceManager<KillMobExperienceSource> newManager() {
return new ExperienceSourceManager<KillMobExperienceSource>() {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerKillEntityEvent event) {
Bukkit.getScheduler().runTaskLater(MMOCore.plugin, () -> {
if (event.getTarget().isDead() && !event.getTarget().getPersistentDataContainer().has(new NamespacedKey(MMOCore.plugin,"spawner_spawned"),PersistentDataType.STRING)) {
if (event.getTarget().isDead() && !event.getTarget().getPersistentDataContainer().has(new NamespacedKey(MMOCore.plugin, "spawner_spawned"), PersistentDataType.STRING)) {
PlayerData data = PlayerData.get(event.getPlayer());
for (KillMobExperienceSource source : getSources())
@ -46,6 +54,6 @@ public class KillMobExperienceSource extends SpecificExperienceSource<Entity> {
@Override
public boolean matchesParameter(PlayerData player, Entity obj) {
return obj.getType() == type;
return obj.getType() == type && (displayName == null || displayName.equals(obj.getCustomName()));
}
}

View File

@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
private final RandomAmount amount;
double counter = 0;
/**
* Used to register experience sources with SPECIFIC experience outputs.
@ -20,20 +19,21 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
public SpecificExperienceSource(ExperienceDispenser dispenser, MMOLineConfig config) {
super(dispenser);
config.validate("amount");
config.validateKeys("amount");
amount = new RandomAmount(config.getString("amount"));
}
/**
* Used for FromExperienceSource
*
* @param dispenser
*/
public SpecificExperienceSource(ExperienceDispenser dispenser) {
super(dispenser);
amount=new RandomAmount(0,0);
}
amount = new RandomAmount(0, 0);
}
public RandomAmount getAmount() {
return amount;

View File

@ -31,7 +31,7 @@ public class AttributeView extends EditableInventory {
Placeholders holders = new Placeholders();
holders.register("attribute_points", inv.getPlayerData().getAttributePoints());
holders.register("points", inv.getPlayerData().getAttributeReallocationPoints());
holders.register("total", inv.getPlayerData().getAttributes().countSkillPoints());
holders.register("total", inv.getPlayerData().getAttributes().countPoints());
return holders;
}
};
@ -93,7 +93,7 @@ public class AttributeView extends EditableInventory {
public void whenClicked(InventoryClickContext context, InventoryItem item) {
if (item.getFunction().equalsIgnoreCase("reallocation")) {
int spent = playerData.getAttributes().countSkillPoints();
int spent = playerData.getAttributes().countPoints();
if (spent < 1) {
MMOCore.plugin.configManager.getSimpleMessage("no-attribute-points-spent").send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.NOT_ENOUGH_POINTS).playTo(getPlayer());

View File

@ -19,15 +19,30 @@ public class Placeholders {
// Remove conditions first
str = removeCondition(str);
/*
* For MMOCore not to loop on unparsable placeholders, it keeps
* track of the "last placeholder" parsed. The 'explored' string
* has NO parsed placeholder.
*/
String explored = str;
// Internal placeholders
while (str.contains("{") && str.substring(str.indexOf("{")).contains("}")) {
String holder = str.substring(str.indexOf("{") + 1, str.indexOf("}"));
while (explored.contains("{") && explored.substring(explored.indexOf("{")).contains("}")) {
final int begin = explored.indexOf("{"), end = explored.indexOf("}");
final String holder = explored.substring(begin + 1, end);
@Nullable String found = placeholders.get(holder);
/*
* Do NOT replace the placeholder unless a corresponding value has
* been found. This simple workaround fixes an issue with PAPI
* math expansions which interferes with MMOCore placeholders since
* it uses {....} as well.
*/
if (found != null)
str = str.replace("{" + holder + "}", found);
else
str = str.replace("{" + holder + "}", "PHE");
// Increase counter
explored = explored.substring(end + 1);
}
// External placeholders

View File

@ -0,0 +1,68 @@
package net.Indyuce.mmocore.manager;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.manager.StatManager;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerActivity;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.attribute.Attribute;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.scheduler.BukkitRunnable;
public class ActionBarManager extends BukkitRunnable {
private int updateTicks, timeOut;
private String barFormat;
private boolean enabled, scheduled;
public void reload(ConfigurationSection config) {
enabled = config.getBoolean("enabled", false);
timeOut = config.getInt("", 60);
updateTicks = config.getInt("ticks-to-update", 5);
barFormat = config.getString("format", "<No Action Bar Format Found>");
if (!scheduled && enabled) {
runTaskTimer(MMOCore.plugin, 0, updateTicks);
scheduled = true;
} else if (scheduled && !enabled) {
cancel();
scheduled = false;
}
}
public long getTimeOut() {
return timeOut;
}
@Override
public void run() {
for (PlayerData data : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.getActivityTimeOut(PlayerActivity.ACTION_BAR_MESSAGE) == 0) {
Placeholders holders = getActionBarPlaceholders(data);
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(
holders.apply(data.getPlayer(), data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : barFormat)));
}
}
public Placeholders getActionBarPlaceholders(PlayerData data) {
Placeholders holders = new Placeholders();
holders.register("health", StatManager.format("MAX_HEALTH", data.getPlayer().getHealth()));
holders.register("max_health", StatManager.format("MAX_HEALTH", data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()));
holders.register("mana_icon", data.getProfess().getManaDisplay().getIcon());
holders.register("mana", StatManager.format("MAX_MANA", data.getMana()));
holders.register("max_mana", StatManager.format("MAX_MANA", data.getStats().getStat("MAX_MANA")));
holders.register("stamina", StatManager.format("MAX_STAMINA", data.getStamina()));
holders.register("max_stamina", StatManager.format("MAX_STAMINA", data.getStats().getStat("MAX_STAMINA")));
holders.register("stellium", StatManager.format("MAX_STELLIUM", data.getStellium()));
holders.register("max_stellium", StatManager.format("MAX_STELLIUM", data.getStats().getStat("MAX_STELLIUM")));
holders.register("class", data.getProfess().getName());
holders.register("xp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()));
holders.register("armor", StatManager.format("ARMOR", data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()));
holders.register("level", String.valueOf(data.getLevel()));
holders.register("name", data.getPlayer().getDisplayName());
return holders;
}
}

View File

@ -8,10 +8,13 @@ import java.util.logging.Level;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.ConfigFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class AttributeManager implements MMOCoreManager {
private final Map<String, PlayerAttribute> map = new HashMap<>();
@Nullable
public PlayerAttribute get(String id) {
return map.get(id);
}
@ -20,6 +23,7 @@ public class AttributeManager implements MMOCoreManager {
return map.containsKey(id);
}
@NotNull
public Collection<PlayerAttribute> getAll() {
return map.values();
}

View File

@ -74,12 +74,13 @@ public class ConfigManager {
loadDefaultFile("expcurves", "levels.txt");
loadDefaultFile("expcurves", "mining.txt");
}
/*
if(!new File(MMOCore.plugin.getDataFolder()+"/skilltree").exists()) {
loadDefaultFile("skilltree","combat.yml");
loadDefaultFile("skilltree","autocombat.yml");
loadDefaultFile("skilltree","customcombat.yml");
}
*/
loadDefaultFile("attributes.yml");
loadDefaultFile("items.yml");
loadDefaultFile("messages.yml");
@ -117,8 +118,8 @@ public class ConfigManager {
canCreativeCast = MMOCore.plugin.getConfig().getBoolean("can-creative-cast");
cobbleGeneratorXP = MMOCore.plugin.getConfig().getBoolean("should-cobblestone-generators-give-exp");
saveDefaultClassInfo = MMOCore.plugin.getConfig().getBoolean("save-default-class-info");
maxBoundSkills= MMOCore.plugin.getConfig().getInt("max-bound-skills",6);
waypointWarpTime=MMOCore.plugin.getConfig().getInt("waypoint-warp-time",5);
maxBoundSkills = MMOCore.plugin.getConfig().getInt("max-bound-skills", 6);
overrideVanillaExp = MMOCore.plugin.getConfig().getBoolean("override-vanilla-exp");
}
private ChatColor getColorOrDefault(String key, ChatColor defaultColor) {

View File

@ -3,12 +3,12 @@ package net.Indyuce.mmocore.manager;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.skill.handler.SkillHandler;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.list.Sneaky_Picky;
import net.Indyuce.mmocore.api.ConfigFile;
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.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -83,8 +83,12 @@ public class SkillManager implements MMOCoreManager {
config.save();
}
RegisteredSkill skill = new RegisteredSkill(handler, config.getConfig());
this.skills.put(handler.getId(), skill);
try {
final RegisteredSkill skill = new RegisteredSkill(handler, config.getConfig());
this.skills.put(handler.getId(), skill);
} catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load skill '" + handler.getId() + "': " + exception.getMessage());
}
}
}
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.manager;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.SoundEvent;
import net.Indyuce.mmocore.api.SoundObject;
@ -9,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
public class SoundManager implements MMOCoreManager {
private final Map<SoundEvent, SoundObject> sounds = new HashMap<>();
@ -25,6 +27,10 @@ public class SoundManager implements MMOCoreManager {
FileConfiguration config = new ConfigFile("sounds").getConfig();
for (SoundEvent sound : SoundEvent.values())
sounds.put(sound, new SoundObject(config.getString(sound.name().replace("_", "-").toLowerCase())));
try {
sounds.put(sound, new SoundObject(config.getString(sound.name().replace("_", "-").toLowerCase())));
} catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load sound for '" + sound.name() + "': " + exception.getMessage());
}
}
}

View File

@ -24,12 +24,22 @@ public class MySQLDataProvider extends MMODataSource implements DataProvider {
executeUpdateAsync(
"CREATE TABLE IF NOT EXISTS mmocore_playerdata(uuid VARCHAR(36),class_points "
+ "INT(11) DEFAULT 0,skill_points INT(11) DEFAULT 0,attribute_points INT(11) "
+ "DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,level INT(11) DEFAULT 1,"
+ "DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,skill_reallocation_points INT(11) DEFAULT 0,level INT(11) DEFAULT 1,"
+ "experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,"
+ "attributes LONGTEXT,professions LONGTEXT,times_claimed LONGTEXT,quests LONGTEXT,"
+ "waypoints LONGTEXT,friends LONGTEXT,skills LONGTEXT,bound_skills LONGTEXT,"
+ "class_info LONGTEXT, is_saved TINYINT, PRIMARY KEY (uuid));");
// Add 'skill_reallocation_points' if it doesn't exist
getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'skill_reallocation_points'", result -> {
try {
if (!result.next())
executeUpdateAsync("ALTER TABLE mmocore_playerdata ADD COLUMN skill_reallocation_points INT(11) DEFAULT 0");
} catch (SQLException exception) {
exception.printStackTrace();
}
});
// Add 'times_claimed' if it doesn't exist
getResultAsync("SELECT * FROM information_schema.COLUMNS WHERE TABLE_NAME = 'mmocore_playerdata' AND COLUMN_NAME = 'times_claimed'", result -> {
try {

View File

@ -1,56 +1,55 @@
package net.Indyuce.mmocore.manager.data.mysql;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
public class MySQLTableEditor {
private final Table table;
private final UUID uuid;
private final Table table;
private final UUID uuid;
private final MySQLDataProvider provider;
private final MySQLDataProvider provider;
public MySQLTableEditor(Table table, UUID uuid, MySQLDataProvider provider) {
this.table = table;
this.uuid = uuid;
this.provider = provider;
}
public MySQLTableEditor(Table table, UUID uuid,MySQLDataProvider provider) {
this.table = table;
this.uuid = uuid;
this.provider=provider;
}
public void updateData(String key, Object value) {
provider.executeUpdate("INSERT INTO " + table + "(uuid, " + key
+ ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
}
public void updateData(String key, Object value) {
provider.executeUpdate("INSERT INTO " + table + "(uuid, " + key
+ ") VALUES('" + uuid + "', '" + value + "') ON DUPLICATE KEY UPDATE " + key + "='" + value + "';");
}
public void updateJSONArray(String key, Collection<String> collection) {
JsonArray json = new JsonArray();
for (String s : collection)
json.add(s);
updateData(key, json.toString());
}
public void updateJSONArray(String key, Collection<String> collection) {
JsonArray json = new JsonArray();
for (String s : collection)
json.add(s);
updateData(key, json.toString());
}
public void updateJSONObject(String key, Set<Entry<String, Integer>> collection) {
JsonObject json = new JsonObject();
for (Entry<String, Integer> entry : collection)
json.addProperty(entry.getKey(), entry.getValue());
updateData(key, json.toString());
}
public void updateJSONObject(String key, Set<Entry<String, Integer>> collection) {
JsonObject json = new JsonObject();
for (Entry<String, Integer> entry : collection)
json.addProperty(entry.getKey(), entry.getValue());
updateData(key, json.toString());
}
public enum Table {
PLAYERDATA("mmocore_playerdata"), GUILDDATA("mmocore_guilddata");
public enum Table {
PLAYERDATA("mmocore_playerdata"), GUILDDATA("mmocore_guilddata");
final String tableName;
final String tableName;
Table(String tN) {
tableName = tN;
}
Table(String tN) {
tableName = tN;
}
@Override
public String toString() {
return tableName;
}
}
@Override
public String toString() {
return tableName;
}
}
}

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmocore.skill.cast.listener;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.event.skill.PlayerCastSkillEvent;
import io.lumine.mythic.lib.api.player.EquipmentSlot;
@ -8,15 +7,14 @@ import io.lumine.mythic.lib.player.PlayerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerMetadata;
import io.lumine.mythic.lib.skill.trigger.TriggerType;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.SoundObject;
import net.Indyuce.mmocore.api.event.PlayerKeyPressEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.skill.cast.PlayerKey;
import net.Indyuce.mmocore.api.SoundObject;
import net.Indyuce.mmocore.skill.cast.KeyCombo;
import net.Indyuce.mmocore.skill.cast.PlayerKey;
import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -34,15 +32,18 @@ public class KeyCombos implements Listener {
* hash code method
*/
private final Map<KeyCombo, Integer> combos = new HashMap<>();
/**
* All the keys that are at the start of a combo.
*/
private final Set<PlayerKey> firstComboKeys = new HashSet<>();
/**
* Key players need to press to start a combo
* Key players need to press to start a combo. If it's set to
* null then the player can press any key which starts a combo.
* These "starting keys" are saved in {@link #firstComboKeys}
*/
private final boolean needsInitializerKey;
@Nullable
private final PlayerKey initializerKey;
private final int longestCombo;
@ -58,9 +59,8 @@ public class KeyCombos implements Listener {
public KeyCombos(ConfigurationSection config) {
int longestCombo = 0;
// Load different combos
int currentLongestCombo = 0;
for (String key : config.getConfigurationSection("combos").getKeys(false))
try {
int spellSlot = Integer.valueOf(key);
@ -72,12 +72,12 @@ public class KeyCombos implements Listener {
combos.put(combo, spellSlot);
firstComboKeys.add(combo.getAt(0));
longestCombo = Math.max(longestCombo, combo.countKeys());
currentLongestCombo = Math.max(currentLongestCombo, combo.countKeys());
} catch (RuntimeException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load key combo '" + key + "': " + exception.getMessage());
}
this.longestCombo = longestCombo;
this.longestCombo = currentLongestCombo;
// Load player key names
actionBarOptions = config.contains("action-bar") ? new ActionBarOptions(config.getConfigurationSection("action-bar")) : null;
@ -87,13 +87,9 @@ public class KeyCombos implements Listener {
comboClickSound = config.contains("sound.combo-key") ? new SoundObject(config.getConfigurationSection("sound.combo-key")) : null;
failComboSound = config.contains("sound.fail-combo") ? new SoundObject(config.getConfigurationSection("sound.fail-combo")) : null;
needsInitializerKey = config.getBoolean("needs-initializer-key", true);
// Find initializer key
initializerKey = needsInitializerKey ? PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(
initializerKey = config.contains("initializer-key") ? PlayerKey.valueOf(UtilityMethods.enumName(Objects.requireNonNull(
config.getString("initializer-key"), "Could not find initializer key"))) : null;
}
@EventHandler
@ -102,7 +98,7 @@ public class KeyCombos implements Listener {
Player player = playerData.getPlayer();
if (!event.getData().isCasting()) {
if (needsInitializerKey) {
if (initializerKey != null) {
if (event.getPressed() == initializerKey) {
// Always cancel event
@ -122,7 +118,7 @@ public class KeyCombos implements Listener {
event.setCancelled(true);
// Start combo
CustomSkillCastingHandler casting =new CustomSkillCastingHandler(playerData);
CustomSkillCastingHandler casting = new CustomSkillCastingHandler(playerData);
playerData.setSkillCasting(casting);
casting.current.registerKey(event.getPressed());
if (beginComboSound != null)
@ -132,7 +128,6 @@ public class KeyCombos implements Listener {
}
}
// Adding pressed key
CustomSkillCastingHandler casting = (CustomSkillCastingHandler) playerData.getSkillCasting();
casting.current.registerKey(event.getPressed());
@ -243,7 +238,7 @@ public class KeyCombos implements Listener {
public String format(CustomSkillCastingHandler casting) {
StringBuilder builder = new StringBuilder();
Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholder(casting.getCaster());
Placeholders holders = MMOCore.plugin.actionBarManager.getActionBarPlaceholders(casting.getCaster());
builder.append(prefix);
// Join all keys with separator

View File

@ -23,6 +23,7 @@ public class Waypoint extends PostLoadObject implements Unlockable {
private final Location loc;
private final List<String> lore;
private final double radiusSquared;
private final int warpTime;
/**
* Set that saves all the waypoints accessible when in this waypoint.
@ -48,6 +49,7 @@ public class Waypoint extends PostLoadObject implements Unlockable {
loc = readLocation(Objects.requireNonNull(config.getString("location"), "Could not read location"));
radiusSquared = Math.pow(config.getDouble("radius"), 2);
warpTime = config.getInt("warp-time", 100);
dynamicCost = config.getDouble("cost.dynamic-use");
normalCost = config.getDouble("cost.normal-use");
@ -95,10 +97,17 @@ public class Waypoint extends PostLoadObject implements Unlockable {
return loc;
}
public int getWarpTime() {
return warpTime;
}
public double getDynamicCost() {
return dynamicCost;
}
/**
* @deprecated Not implemented yet
*/
@Deprecated
public double getSetSpawnCost() {
return setSpawnCost;

View File

@ -16,7 +16,7 @@ public class MMOCoreBukkit {
* all the listeners required for MMOCore to run
*/
public MMOCoreBukkit(MMOCore plugin) {
if (plugin.configManager.overrideVanillaExp = plugin.getConfig().getBoolean("override-vanilla-exp"))
if (plugin.configManager.overrideVanillaExp)
Bukkit.getPluginManager().registerEvents(new VanillaExperienceOverride(), plugin);
if (plugin.getConfig().getBoolean("hotbar-swapping.enabled"))

View File

@ -114,11 +114,8 @@ action-bar:
# (This doesn't change any other action bars provided by MMOCore.)
enabled: true
# The decimal format for stats (not including stat formats in stats.yml)
decimal: "0.#"
# The amount of miliseconds the bar will be faded
#out when displaying other action bars.
# The amount of milliseconds the bar will be
# faded out when displaying other action bars.
time-out: 60
# The amount of ticks before updating the info

View File

@ -16,7 +16,7 @@
<description>Offer your players a brand new RPG experience!!</description>
<properties>
<revision>1.9.5-SNAPSHOT</revision>
<revision>1.10.1-SNAPSHOT</revision>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>