> MMOCore 1.6 - API Handling Rewrite

REQUIRES MMOLIB 1.7!!!
- Rewrote MMOLib compatibility API (MMOLib is still a dependency!)
- Lootsplosions are now a part of MMOItems.
This commit is contained in:
ASangarin 2020-12-06 17:46:29 +01:00
parent 7b53c18dd4
commit 30452a3cd8
30 changed files with 101 additions and 295 deletions

62
pom.xml
View File

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId> <groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId> <artifactId>MMOCore</artifactId>
<version>1.5</version> <version>1.6</version>
<name>MMOCore</name> <name>MMOCore</name>
<description>Offer your players a brand new RPG experience.</description> <description>Offer your players a brand new RPG experience.</description>
@ -40,6 +40,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
@ -57,6 +58,14 @@
<shadedPattern>net.indyuce.mmocore.shaded.paperlib</shadedPattern> <shadedPattern>net.indyuce.mmocore.shaded.paperlib</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>net/mmogroup/**</exclude>
</excludes>
</filter>
</filters>
</configuration> </configuration>
<executions> <executions>
<execution> <execution>
@ -67,32 +76,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>../build.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>${jar.path}</outputDirectory>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<repositories> <repositories>
@ -114,23 +97,6 @@
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<!-- MMOs -->
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>mmoitems</artifactId>
<version>6.1.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOItems.jar</systemPath>
</dependency>
<dependency>
<groupId>net.mmogroup</groupId>
<artifactId>MMOLib</artifactId>
<version>1.5</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOLib.jar</systemPath>
</dependency>
<!-- Minecraft --> <!-- Minecraft -->
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
@ -140,6 +106,14 @@
<systemPath>${basedir}/lib/spigot.jar</systemPath> <systemPath>${basedir}/lib/spigot.jar</systemPath>
</dependency> </dependency>
<!-- MMOs -->
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOLib</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
<!-- APIs --> <!-- APIs -->
<dependency> <dependency>
<groupId>org.jetbrains</groupId> <groupId>org.jetbrains</groupId>

View File

@ -306,7 +306,7 @@ public class MMOCore extends JavaPlugin {
* that after registering all the professses otherwise the player datas can't * that after registering all the professses otherwise the player datas can't
* recognize what profess the player has and professes will be lost * recognize what profess the player has and professes will be lost
*/ */
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player)); Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player.getUniqueId()));
/* /*
* load guild data after loading player data * load guild data after loading player data

View File

@ -21,7 +21,7 @@ public class PlayerActionBar extends BukkitRunnable {
public void reload(ConfigurationSection cfg) { public void reload(ConfigurationSection cfg) {
config = new ActionBarConfig(cfg); config = new ActionBarConfig(cfg);
digit = new DecimalFormat(config.digit, MMOCore.plugin.configManager.formatSymbols); digit = new DecimalFormat(config.digit, MMOLib.plugin.getMMOConfig().formatSymbols);
if(!initialized && config.enabled) { if(!initialized && config.enabled) {
runTaskTimer(MMOCore.plugin, 0, config.ticks); runTaskTimer(MMOCore.plugin, 0, config.ticks);

View File

@ -1,30 +1,29 @@
package net.Indyuce.mmocore.api.droptable.condition; package net.Indyuce.mmocore.api.droptable.condition;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.api.player.MMOPlayerData;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class LevelCondition extends Condition { public class LevelCondition extends Condition {
private final int amount; private final int amount;
private final String profession; private final String profession;
public LevelCondition(MMOLineConfig config) { public LevelCondition(MMOLineConfig config) {
super(config); super(config);
config.validate("amount"); config.validate("amount");
amount = config.getInt("amount"); amount = config.getInt("amount");
profession = config.contains("profession") ? config.getString("profession") : null; profession = config.contains("profession") ? config.getString("profession") : null;
} }
@Override @Override
public boolean isMet(ConditionInstance entity) { public boolean isMet(ConditionInstance entity) {
if (entity.getEntity() instanceof Player) { if (entity.getEntity() instanceof Player) {
int level = (profession != null) ? MMOPlayerData.get((Player) entity.getEntity()).getMMOCore().getCollectionSkills().getLevel(profession) int level = (profession != null) ? PlayerData.get(entity.getEntity().getUniqueId()).getCollectionSkills().getLevel(profession) : PlayerData.get(entity.getEntity().getUniqueId()).getLevel();
: MMOPlayerData.get((Player) entity.getEntity()).getMMOCore().getLevel(); return level >= amount;
return level >= amount; }
} return false;
return false; }
}
} }

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import net.mmogroup.mmolib.MMOLib;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -184,6 +185,6 @@ public class PlayerProfessions {
bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|"); bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|");
if(playerData.isOnline()) if(playerData.isOnline())
MMOCore.plugin.configManager.getSimpleMessage("exp-notification", "profession", profession.getName(), "progress", bar.toString(), "ratio", MMOCore.plugin.configManager.getSimpleMessage("exp-notification", "profession", profession.getName(), "progress", bar.toString(), "ratio",
MMOCore.plugin.configManager.decimal.format((double) exp / needed * 100)).send(playerData.getPlayer()); MMOLib.plugin.getMMOConfig().decimal.format((double) exp / needed * 100)).send(playerData.getPlayer());
} }
} }

View File

@ -99,7 +99,6 @@ public class PlayerData extends OfflinePlayerData {
public PlayerData(MMOPlayerData mmoData) { public PlayerData(MMOPlayerData mmoData) {
super(mmoData.getUniqueId()); super(mmoData.getUniqueId());
mmoData.setMMOCore(this);
this.mmoData = mmoData; this.mmoData = mmoData;
this.playerStats = new PlayerStats(this); this.playerStats = new PlayerStats(this);
@ -116,8 +115,6 @@ public class PlayerData extends OfflinePlayerData {
super(UUID.randomUUID()); super(UUID.randomUUID());
mmoData = new MMOPlayerData(null, null); mmoData = new MMOPlayerData(null, null);
mmoData.setMMOCore(this);
playerStats = new PlayerStats(this); playerStats = new PlayerStats(this);
questData = new PlayerQuests(this, null); questData = new PlayerQuests(this, null);
} }

View File

@ -18,7 +18,7 @@ public class AttackEventTrigger implements EventTriggerHandler {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void a(PlayerAttackEvent event) { public void a(PlayerAttackEvent event) {
PlayerData player = event.getData().getMMOCore(); PlayerData player = PlayerData.get(event.getData().getUniqueId());
PlayerClass profess = player.getProfess(); PlayerClass profess = player.getProfess();
for (DamageType type : event.getAttack().getTypes()) { for (DamageType type : event.getAttack().getTypes()) {

View File

@ -1,13 +1,13 @@
package net.Indyuce.mmocore.api.player.stats; package net.Indyuce.mmocore.api.player.stats;
import java.text.DecimalFormat;
import org.bukkit.configuration.file.FileConfiguration;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigFile; import net.Indyuce.mmocore.api.ConfigFile;
import net.Indyuce.mmocore.api.experience.Profession; import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.mmogroup.mmolib.MMOLib;
import org.bukkit.configuration.file.FileConfiguration;
import java.text.DecimalFormat;
public enum StatType { public enum StatType {
@ -124,7 +124,7 @@ public enum StatType {
FileConfiguration config = new ConfigFile("stats").getConfig(); FileConfiguration config = new ConfigFile("stats").getConfig();
for (StatType stat : values()) { for (StatType stat : values()) {
stat.defaultInfo = config.contains("default." + stat.name()) ? new LinearValue(config.getConfigurationSection("default." + stat.name())) : new LinearValue(0, 0); stat.defaultInfo = config.contains("default." + stat.name()) ? new LinearValue(config.getConfigurationSection("default." + stat.name())) : new LinearValue(0, 0);
stat.format = MMOCore.plugin.configManager.newFormat(config.contains("decimal-format." + stat.name()) ? config.getString("decimal-format." + stat.name()) : "0.#"); stat.format = MMOLib.plugin.getMMOConfig().newFormat(config.contains("decimal-format." + stat.name()) ? config.getString("decimal-format." + stat.name()) : "0.#");
} }
} }
} }

View File

@ -1,9 +1,8 @@
package net.Indyuce.mmocore.api.util.math.formula; package net.Indyuce.mmocore.api.util.math.formula;
import net.mmogroup.mmolib.MMOLib;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.MMOCore;
public class LinearValue { public class LinearValue {
private final double base, perLevel, min, max; private final double base, perLevel, min, max;
private final boolean hasmin, hasmax; private final boolean hasmin, hasmax;
@ -75,17 +74,15 @@ public class LinearValue {
} }
public String getDisplay(int level) { public String getDisplay(int level) {
return MMOCore.plugin.configManager.decimals.format(calculate(level)); return MMOLib.plugin.getMMOConfig().decimals.format(calculate(level));
} }
public double calculate(int level) { public double calculate(int level) {
double value = base + perLevel * (level - 1); double value = base + perLevel * (level - 1);
if (hasmin) if (hasmin) value = Math.max(min, value);
value = Math.max(min, value);
if (hasmax) if (hasmax) value = Math.min(max, value);
value = Math.min(max, value);
return value; return value;
} }

View File

@ -24,7 +24,7 @@ public class ListCommandTreeNode extends CommandTreeNode {
for (Booster booster : MMOCore.plugin.boosterManager.getBoosters()) for (Booster booster : MMOCore.plugin.boosterManager.getBoosters())
if (!booster.isTimedOut()) if (!booster.isTimedOut())
MMOLib.plugin.getVersion().getWrapper().sendJson((Player) sender, "{\"text\":\"" + ChatColor.YELLOW + "- " + ChatColor.GOLD MMOLib.plugin.getVersion().getWrapper().sendJson((Player) sender, "{\"text\":\"" + ChatColor.YELLOW + "- " + ChatColor.GOLD
+ MMOCore.plugin.configManager.decimal.format((1 + booster.getExtra())) + "x" + ChatColor.YELLOW + " Booster - " + MMOLib.plugin.getMMOConfig().decimal.format((1 + booster.getExtra())) + "x" + ChatColor.YELLOW + " Booster - "
+ ChatColor.GOLD + (!booster.hasProfession() ? "ExploreAttributesCommand" : booster.getProfession().getName()) + ChatColor.GOLD + (!booster.hasProfession() ? "ExploreAttributesCommand" : booster.getProfession().getName())
+ ChatColor.YELLOW + " - " + ChatColor.GOLD + ChatColor.YELLOW + " - " + ChatColor.GOLD
+ new DelayFormat().format(booster.getCreationDate() + booster.getLength() - System.currentTimeMillis()) + new DelayFormat().format(booster.getCreationDate() + booster.getLength() - System.currentTimeMillis())

View File

@ -1,32 +0,0 @@
package net.Indyuce.mmocore.comp.mythicmobs;
import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.entity.Item;
import org.bukkit.scheduler.BukkitRunnable;
import net.Indyuce.mmocore.MMOCore;
public class LootColor extends BukkitRunnable {
private final Item item;
private final Color color;
private int j = 0;
public LootColor(Item item, Color color) {
this.item = item;
this.color = color;
runTaskTimer(MMOCore.plugin, 0, 1);
}
@Override
public void run() {
if (j++ > 100 || item.isDead() || item.isOnGround()) {
cancel();
return;
}
item.getWorld().spawnParticle(Particle.REDSTONE, item.getLocation(), 1, new Particle.DustOptions(color, 1.3f));
}
}

View File

@ -1,89 +0,0 @@
package net.Indyuce.mmocore.comp.mythicmobs;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.bukkit.Bukkit;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.ItemTier;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.item.NBTItem;
public class Lootsplosion implements Listener {
private static final Random random = new Random();
private final boolean colored;
public Lootsplosion() {
colored = Bukkit.getPluginManager().getPlugin("MMOItems") != null && MMOCore.plugin.getConfig().getBoolean("lootsplosion.mmoitems-color");
}
@EventHandler(priority = EventPriority.HIGH)
public void b(MythicMobDeathEvent event) {
if (event.getMob().getVariables().has("Lootsplosion"))
new LootsplosionHandler(event);
}
public class LootsplosionHandler implements Listener {
private final List<ItemStack> drops;
/*
* Y coordinate offset so the velocity is not directly negated when the
* item spawns on the ground
*/
private final double offset;
public LootsplosionHandler(MythicMobDeathEvent event) {
offset = event.getEntity().getHeight() / 2;
drops = new ArrayList<>(event.getDrops());
Bukkit.getPluginManager().registerEvents(this, MMOCore.plugin);
}
private void close() {
ItemSpawnEvent.getHandlerList().unregister(this);
}
@EventHandler
public void a(ItemSpawnEvent event) {
Item item = event.getEntity();
if (!drops.contains(item.getItemStack())) {
close();
return;
}
drops.remove(item.getItemStack());
item.teleport(item.getLocation().add(0, offset, 0));
item.setVelocity(randomVector());
if (colored)
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> {
NBTItem nbt = MMOLib.plugin.getVersion().getWrapper().getNBTItem(item.getItemStack());
if (nbt.hasTag("MMOITEMS_TIER")) {
ItemTier tier = MMOItems.plugin.getTiers().get(nbt.getString("MMOITEMS_TIER"));
if (tier.hasColor())
new LootColor(item, tier.getColor().toBukkit());
}
});
}
}
private Vector randomVector() {
double offset = MMOCore.plugin.getConfig().getDouble("lootsplosion.offset"),
height = MMOCore.plugin.getConfig().getDouble("lootsplosion.height");
return new Vector(Math.cos(random.nextDouble() * Math.PI * 2) * offset, height, Math.sin(random.nextDouble() * Math.PI * 2) * offset);
}
}

View File

@ -1,22 +1,17 @@
package net.Indyuce.mmocore.comp.mythicmobs; package net.Indyuce.mmocore.comp.mythicmobs;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import io.lumine.xikage.mythicmobs.MythicMobs; import io.lumine.xikage.mythicmobs.MythicMobs;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent; import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicDropLoadEvent;
import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicReloadedEvent; import io.lumine.xikage.mythicmobs.api.bukkit.events.MythicReloadedEvent;
import io.lumine.xikage.mythicmobs.skills.placeholders.Placeholder; import io.lumine.xikage.mythicmobs.skills.placeholders.Placeholder;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.comp.mythicmobs.load.CurrencyItemDrop; import net.Indyuce.mmocore.comp.mythicmobs.load.CurrencyItemDrop;
import net.Indyuce.mmocore.comp.mythicmobs.load.GoldPouchDrop; import net.Indyuce.mmocore.comp.mythicmobs.load.GoldPouchDrop;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class MythicMobsDrops implements Listener { public class MythicMobsDrops implements Listener {
public MythicMobsDrops() { public MythicMobsDrops() {
if (MMOCore.plugin.getConfig().getBoolean("lootsplosion.enabled"))
Bukkit.getPluginManager().registerEvents(new Lootsplosion(), MMOCore.plugin);
registerPlaceholders(); registerPlaceholders();
} }

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill;
@ -17,6 +18,6 @@ public class PlayerAttackSkillHandler extends PassiveMythicMobSkillHandler {
@EventHandler @EventHandler
private void event(PlayerAttackEvent e) { private void event(PlayerAttackEvent e) {
castSkill(e.getData().getMMOCore(), e.getEntity()); castSkill(PlayerData.get(e.getData().getUniqueId()), e.getEntity());
} }
} }

View File

@ -7,6 +7,7 @@ import net.Indyuce.mmocore.api.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.stats.StatType; import net.Indyuce.mmocore.api.player.stats.StatType;
import net.Indyuce.mmocore.api.quest.PlayerQuests; import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.mmogroup.mmolib.MMOLib;
import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.api.util.AltChar;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -55,7 +56,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
else if (identifier.equals("level_percent")) { else if (identifier.equals("level_percent")) {
PlayerData playerData = PlayerData.get(player); PlayerData playerData = PlayerData.get(player);
double current = playerData.getExperience(), next = playerData.getLevelUpExperience(); double current = playerData.getExperience(), next = playerData.getLevelUpExperience();
return MMOCore.plugin.configManager.decimal.format(current / next * 100); return MMOLib.plugin.getMMOConfig().decimal.format(current / next * 100);
} }
else if (identifier.equals("combat")) else if (identifier.equals("combat"))
@ -86,7 +87,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
String name = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase(); String name = identifier.substring(19).replace(" ", "-").replace("_", "-").toLowerCase();
Profession profession = MMOCore.plugin.professionManager.get(name); Profession profession = MMOCore.plugin.professionManager.get(name);
double current = professions.getExperience(profession), next = professions.getLevelUpExperience(profession); double current = professions.getExperience(profession), next = professions.getLevelUpExperience(profession);
return MMOCore.plugin.configManager.decimal.format(current / next * 100); return MMOLib.plugin.getMMOConfig().decimal.format(current / next * 100);
} }
else if (identifier.startsWith("bound_")) { else if (identifier.startsWith("bound_")) {
@ -131,7 +132,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
.getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-")))); .getAttribute(MMOCore.plugin.attributeManager.get(identifier.substring(10).toLowerCase().replace("_", "-"))));
else if (identifier.equals("mana")) else if (identifier.equals("mana"))
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getMana()); return MMOLib.plugin.getMMOConfig().decimal.format(PlayerData.get(player).getMana());
else if (identifier.equals("mana_bar")) { else if (identifier.equals("mana_bar")) {
PlayerData data = PlayerData.get(player); PlayerData data = PlayerData.get(player);
@ -141,17 +142,17 @@ public class RPGPlaceholders extends PlaceholderExpansion {
else if (identifier.startsWith("exp_multiplier_")) { else if (identifier.startsWith("exp_multiplier_")) {
String format = identifier.substring(15).toLowerCase().replace("_", "-").replace(" ", "-"); String format = identifier.substring(15).toLowerCase().replace("_", "-").replace(" ", "-");
Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format); Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format);
return MMOCore.plugin.configManager.decimal.format(MMOCore.plugin.boosterManager.getMultiplier(profession) * 100); return MMOLib.plugin.getMMOConfig().decimal.format(MMOCore.plugin.boosterManager.getMultiplier(profession) * 100);
} }
else if (identifier.startsWith("exp_boost_")) { else if (identifier.startsWith("exp_boost_")) {
String format = identifier.substring(10).toLowerCase().replace("_", "-").replace(" ", "-"); String format = identifier.substring(10).toLowerCase().replace("_", "-").replace(" ", "-");
Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format); Profession profession = format.equals("main") ? null : MMOCore.plugin.professionManager.get(format);
return MMOCore.plugin.configManager.decimal.format((MMOCore.plugin.boosterManager.getMultiplier(profession) - 1) * 100); return MMOLib.plugin.getMMOConfig().decimal.format((MMOCore.plugin.boosterManager.getMultiplier(profession) - 1) * 100);
} }
else if (identifier.equals("stamina")) else if (identifier.equals("stamina"))
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getStamina()); return MMOLib.plugin.getMMOConfig().decimal.format(PlayerData.get(player).getStamina());
else if (identifier.equals("stamina_bar")) { else if (identifier.equals("stamina_bar")) {
StringBuilder format = new StringBuilder(); StringBuilder format = new StringBuilder();
@ -168,7 +169,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
} }
else if (identifier.equals("stellium")) else if (identifier.equals("stellium"))
return MMOCore.plugin.configManager.decimal.format(PlayerData.get(player).getStellium()); return MMOLib.plugin.getMMOConfig().decimal.format(PlayerData.get(player).getStellium());
else if (identifier.equals("stellium_bar")) { else if (identifier.equals("stellium_bar")) {
StringBuilder format = new StringBuilder(); StringBuilder format = new StringBuilder();
@ -187,7 +188,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
else if (identifier.equals("quest_progress")) { else if (identifier.equals("quest_progress")) {
PlayerQuests data = PlayerData.get(player).getQuestData(); PlayerQuests data = PlayerData.get(player).getQuestData();
return data.hasCurrent() return data.hasCurrent()
? MMOCore.plugin.configManager.decimal ? MMOLib.plugin.getMMOConfig().decimal
.format((int) (double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100) .format((int) (double) data.getCurrent().getObjectiveNumber() / data.getCurrent().getQuest().getObjectives().size() * 100)
: "0"; : "0";
} }

View File

@ -5,6 +5,7 @@ import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import net.mmogroup.mmolib.MMOLib;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@ -25,7 +26,7 @@ public abstract class EditableInventory {
*/ */
private final Set<InventoryItem> items = new LinkedHashSet<>(); private final Set<InventoryItem> items = new LinkedHashSet<>();
protected static final DecimalFormat decimal = MMOCore.plugin.configManager.decimal; protected static final DecimalFormat decimal = MMOLib.plugin.getMMOConfig().decimal;
public EditableInventory(String id) { public EditableInventory(String id) {
this.id = id; this.id = id;

View File

@ -51,7 +51,7 @@ public class PartyListener implements Listener {
LivingEntity entity = event.getEntity(); LivingEntity entity = event.getEntity();
if (entity instanceof Player && !entity.hasMetadata("NPC")) { if (entity instanceof Player && !entity.hasMetadata("NPC")) {
PlayerData targetData = PlayerData.get((Player) event.getEntity()); PlayerData targetData = PlayerData.get((Player) event.getEntity());
if (targetData.hasParty() && targetData.getParty().getMembers().has(event.getData().getMMOCore())) if (targetData.hasParty() && targetData.getParty().getMembers().has(PlayerData.get(event.getData().getUniqueId())))
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -28,7 +28,7 @@ public class PlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void a(PlayerJoinEvent event) { public void a(PlayerJoinEvent event) {
MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer()); MMOCore.plugin.dataProvider.getDataManager().setup(event.getPlayer().getUniqueId());
} }
/* /*

View File

@ -17,8 +17,6 @@ import org.bukkit.util.Consumer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
@ -31,9 +29,6 @@ public class ConfigManager {
public ChatColor staminaFull, staminaHalf, staminaEmpty; public ChatColor staminaFull, staminaHalf, staminaEmpty;
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown;
public final DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols();
public final DecimalFormat decimal = new DecimalFormat("0.#", formatSymbols), decimals = new DecimalFormat("0.##", formatSymbols);
private final FileConfiguration messages; private final FileConfiguration messages;
private final boolean chatInput; private final boolean chatInput;
@ -97,7 +92,6 @@ public class ConfigManager {
hotbarSwap = MMOCore.plugin.getConfig().getBoolean("hotbar-swap"); hotbarSwap = MMOCore.plugin.getConfig().getBoolean("hotbar-swap");
chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input"); chatInput = MMOCore.plugin.getConfig().getBoolean("use-chat-input");
partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix"); partyChatPrefix = MMOCore.plugin.getConfig().getString("party.chat-prefix");
formatSymbols.setDecimalSeparator(getFirstChar(MMOCore.plugin.getConfig().getString("number-format.decimal-separator")));
combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000; combatLogTimer = MMOCore.plugin.getConfig().getInt("combat-log.timer") * 1000;
lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000; lootChestExpireTime = Math.max(MMOCore.plugin.getConfig().getInt("loot-chests.chest-expire-time"), 1) * 1000;
lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000; lootChestPlayerCooldown = MMOCore.plugin.getConfig().getInt("player-cooldown") * 1000;
@ -117,14 +111,6 @@ public class ConfigManager {
} }
} }
public DecimalFormat newFormat(String pattern) {
return new DecimalFormat(pattern, formatSymbols);
}
private char getFirstChar(String str) {
return str == null || str.isEmpty() ? ',' : str.charAt(0);
}
public PlayerInput newPlayerInput(Player player, InputType type, Consumer<String> output) { public PlayerInput newPlayerInput(Player player, InputType type, Consumer<String> output) {
return chatInput ? new ChatInput(player, type, output) : new AnvilGUI(player, type, output); return chatInput ? new ChatInput(player, type, output) : new AnvilGUI(player, type, output);
} }

View File

@ -11,7 +11,6 @@ import org.apache.commons.lang.Validate;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.experience.ExpCurve; import net.Indyuce.mmocore.api.experience.ExpCurve;
import net.Indyuce.mmoitems.MMOItems;
public class ExperienceManager { public class ExperienceManager {
private final Map<String, ExpCurve> expCurves = new HashMap<>(); private final Map<String, ExpCurve> expCurves = new HashMap<>();
@ -40,7 +39,7 @@ public class ExperienceManager {
ExpCurve curve = new ExpCurve(file); ExpCurve curve = new ExpCurve(file);
expCurves.put(curve.getId(), curve); expCurves.put(curve.getId(), curve);
} catch (IllegalArgumentException | IOException exception) { } catch (IllegalArgumentException | IOException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load exp curve '" + file.getName() + "': " + exception.getMessage()); MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp curve '" + file.getName() + "': " + exception.getMessage());
} }
} }
} }

View File

@ -1,21 +1,21 @@
package net.Indyuce.mmocore.manager.data; package net.Indyuce.mmocore.manager.data;
import java.util.Collection;
import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore; import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent; import net.Indyuce.mmocore.api.event.PlayerDataLoadEvent;
import net.Indyuce.mmocore.api.player.OfflinePlayerData; import net.Indyuce.mmocore.api.player.OfflinePlayerData;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.mmogroup.mmolib.api.player.MMOPlayerData; import net.mmogroup.mmolib.api.player.MMOPlayerData;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public abstract class PlayerDataManager { public abstract class PlayerDataManager {
private final static Map<UUID, PlayerData> data = new HashMap<>();
private DefaultPlayerData defaultData = new DefaultPlayerData(); private DefaultPlayerData defaultData = new DefaultPlayerData();
public PlayerData get(OfflinePlayer player) { public PlayerData get(OfflinePlayer player) {
@ -23,37 +23,36 @@ public abstract class PlayerDataManager {
} }
public PlayerData get(UUID uuid) { public PlayerData get(UUID uuid) {
PlayerData found = MMOPlayerData.get(uuid).getMMOCore(); return data.getOrDefault(uuid, setup(uuid));
return found == null ? PlayerData.NOT_LOADED : found;
} }
public void remove(UUID uuid) { public void remove(UUID uuid) {
if (MMOPlayerData.isLoaded(uuid)) data.remove(uuid);
MMOPlayerData.get(uuid).setMMOCore(null);
} }
public abstract OfflinePlayerData getOffline(UUID uuid); public abstract OfflinePlayerData getOffline(UUID uuid);
public void setup(Player player) { public PlayerData setup(UUID uuid) {
/* /*
* Setup playerData based on loadData method to support both MySQL and * Setup playerData based on loadData method to support both MySQL and
* YAML data storage * YAML data storage
*/ */
MMOPlayerData mmoData = MMOPlayerData.get(player); PlayerData playerData = data.get(uuid);
if (mmoData.getMMOCore() == null) { if (playerData == null) {
PlayerData generated = new PlayerData(mmoData); playerData = data.put(uuid, new PlayerData(MMOPlayerData.get(uuid)));
/* /*
* Loads player data and ONLY THEN refresh the player statistics and * Loads player data and ONLY THEN refresh the player statistics and
* calls the load event on the MAIN thread * calls the load event on the MAIN thread
*/ */
Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> { Bukkit.getScheduler().runTaskAsynchronously(MMOCore.plugin, () -> {
loadData(generated); PlayerData loaded = PlayerData.get(uuid);
Bukkit.getScheduler().runTask(MMOCore.plugin, () -> Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(generated))); loadData(loaded);
generated.getStats().updateStats(); Bukkit.getScheduler().runTask(MMOCore.plugin, () -> Bukkit.getPluginManager().callEvent(new PlayerDataLoadEvent(loaded)));
loaded.getStats().updateStats();
}); });
} }
return playerData;
} }
public DefaultPlayerData getDefaultData() { public DefaultPlayerData getDefaultData() {
@ -65,12 +64,11 @@ public abstract class PlayerDataManager {
} }
public boolean isLoaded(UUID uuid) { public boolean isLoaded(UUID uuid) {
return MMOPlayerData.isLoaded(uuid) && MMOPlayerData.get(uuid).getMMOCore() != null; return data.containsKey(uuid);
} }
public Collection<PlayerData> getLoaded() { public Collection<PlayerData> getLoaded() {
return MMOPlayerData.getLoaded().stream().filter(data -> data.getMMOCore() != null).map(MMOPlayerData::getMMOCore) return data.values();
.collect(Collectors.toSet());
} }
public abstract void loadData(PlayerData data); public abstract void loadData(PlayerData data);

View File

@ -22,7 +22,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
@Override @Override
public void loadData(PlayerData data) { public void loadData(PlayerData data) {
FileConfiguration config = new ConfigFile(data.getPlayer()).getConfig(); FileConfiguration config = new ConfigFile(data.getUniqueId()).getConfig();
data.setClassPoints(config.getInt("class-points", getDefaultData().getClassPoints())); data.setClassPoints(config.getInt("class-points", getDefaultData().getClassPoints()));
data.setSkillPoints(config.getInt("skill-points", getDefaultData().getSkillPoints())); data.setSkillPoints(config.getInt("skill-points", getDefaultData().getSkillPoints()));

View File

@ -37,7 +37,7 @@ public class Ambers extends Skill implements Listener {
@EventHandler @EventHandler
public void a(PlayerAttackEvent event) { public void a(PlayerAttackEvent event) {
PlayerData data = event.getData().getMMOCore(); PlayerData data = PlayerData.get(event.getData().getUniqueId());
if (!event.getAttack().hasType(DamageType.SKILL) || !data.getProfess().hasSkill(this)) if (!event.getAttack().hasType(DamageType.SKILL) || !data.getProfess().hasSkill(this))
return; return;

View File

@ -32,7 +32,7 @@ public class Backstab extends Skill implements Listener {
@EventHandler @EventHandler
public void a(PlayerAttackEvent event) { public void a(PlayerAttackEvent event) {
PlayerData data = event.getData().getMMOCore(); PlayerData data = PlayerData.get(event.getData().getUniqueId());
LivingEntity target = event.getEntity(); LivingEntity target = event.getEntity();
if (data.isInCombat() || !event.getAttack().hasType(DamageType.WEAPON) if (data.isInCombat() || !event.getAttack().hasType(DamageType.WEAPON)
|| event.getPlayer().getEyeLocation().getDirection().angle(target.getEyeLocation().getDirection()) > Math.PI / 6 || event.getPlayer().getEyeLocation().getDirection().angle(target.getEyeLocation().getDirection()) > Math.PI / 6

View File

@ -69,7 +69,7 @@ public class Evade extends Skill {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void b(PlayerAttackEvent event) { public void b(PlayerAttackEvent event) {
if (event.getAttack().hasType(DamageType.WEAPON) && !event.isCancelled() && event.getData().getMMOCore().equals(data)) if (event.getAttack().hasType(DamageType.WEAPON) && !event.isCancelled() && PlayerData.get(event.getData().getUniqueId()).equals(data))
close(); close();
} }

View File

@ -30,7 +30,7 @@ public class Fire_Berserker extends Skill implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void a(PlayerAttackEvent event) { public void a(PlayerAttackEvent event) {
PlayerData data = event.getData().getMMOCore(); PlayerData data = PlayerData.get(event.getData().getUniqueId());
if (event.getPlayer().getFireTicks() > 0) { if (event.getPlayer().getFireTicks() > 0) {
Optional<SkillInfo> skill = data.getProfess().findSkill(this); Optional<SkillInfo> skill = data.getProfess().findSkill(this);
skill.ifPresent(skillInfo -> event.getAttack().multiplyDamage(1 + skillInfo.getModifier("extra", data.getSkillLevel(this)) / 100)); skill.ifPresent(skillInfo -> event.getAttack().multiplyDamage(1 + skillInfo.getModifier("extra", data.getSkillLevel(this)) / 100));

View File

@ -46,7 +46,7 @@ public class Power_Mark extends Skill implements Listener {
@EventHandler @EventHandler
public void a(PlayerAttackEvent event) { public void a(PlayerAttackEvent event) {
PlayerData data = event.getData().getMMOCore(); PlayerData data = PlayerData.get(event.getData().getUniqueId());
if (!event.getAttack().hasType(DamageType.WEAPON) || !data.getProfess().hasSkill(this)) if (!event.getAttack().hasType(DamageType.WEAPON) || !data.getProfess().hasSkill(this))
return; return;
@ -89,7 +89,7 @@ public class Power_Mark extends Skill implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void stackDamage(PlayerAttackEvent event) { public void stackDamage(PlayerAttackEvent event) {
if (!event.isCancelled() && j < 20 * (duration - 2) && radiusCheck(event.getEntity().getLocation()) && event.getData().getMMOCore().equals(data)) { if (!event.isCancelled() && j < 20 * (duration - 2) && radiusCheck(event.getEntity().getLocation()) && PlayerData.get(event.getData().getUniqueId()).equals(data)) {
accumulate += event.getAttack().getDamage() * ratio; accumulate += event.getAttack().getDamage() * ratio;
new ParabolicProjectile(event.getEntity().getLocation().add(0, event.getEntity().getHeight() / 2, 0), loc, () -> loc.getWorld().playSound(loc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1), Color.PURPLE); new ParabolicProjectile(event.getEntity().getLocation().add(0, event.getEntity().getHeight() / 2, 0), loc, () -> loc.getWorld().playSound(loc, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1), Color.PURPLE);
} }

View File

@ -32,7 +32,7 @@ public class Sneaky_Picky extends Skill implements Listener {
@EventHandler @EventHandler
public void a(PlayerAttackEvent event) { public void a(PlayerAttackEvent event) {
PlayerData data = event.getData().getMMOCore(); PlayerData data = PlayerData.get(event.getData().getUniqueId());
if (!event.getAttack().hasType(DamageType.WEAPON) || data.isInCombat() || !data.getProfess().hasSkill(this)) if (!event.getAttack().hasType(DamageType.WEAPON) || data.isInCombat() || !data.getProfess().hasSkill(this))
return; return;

View File

@ -8,7 +8,7 @@
# a Spigot Plugin by Team Requiem # a Spigot Plugin by Team Requiem
# DO NOT TOUCH # DO NOT TOUCH
config-version: 2 config-version: 3
# Auto-Save feature automatically saves playerdata # Auto-Save feature automatically saves playerdata
# (class, level, etc.) and guild data # (class, level, etc.) and guild data
@ -55,18 +55,7 @@ custom-mine-conditions:
# broken when custom mining conditions are met # broken when custom mining conditions are met
protect-custom-mine: false protect-custom-mine: false
# Offset is the distance traveled on X and Y coordinates
# Height is the Y velocity coordinate. Lootsplosions
# only trigger with MythicMobs monsters.
# Requires a SERVER reload when changed.
lootsplosion:
enabled: true
mmoitems-color: true
offset: .2
height: .6
loot-chests: loot-chests:
# Time in seconds it takes for a loot chest to # Time in seconds it takes for a loot chest to
# expire after it was spawned. 600 is 10 minutes. # expire after it was spawned. 600 is 10 minutes.
chest-expire-time: 600 chest-expire-time: 600
@ -127,17 +116,6 @@ death-exp-loss:
# Percentage of current EXP you lose when dying. # Percentage of current EXP you lose when dying.
percent: 30 percent: 30
# Edit general plugin number formatting here.
number-format:
decimal-separator: .
# Allows to scale health up/down to a specific
# amount so extra health does not fill up the screen.
# Requires a SERVER reload when changed.
health-scale:
enabled: true
scale: 20
# Allows to toggle exp hologram from gaining experience # Allows to toggle exp hologram from gaining experience
display-exp-holograms: true display-exp-holograms: true

View File

@ -107,7 +107,7 @@ attributes:
base: 24 base: 24
per-level: 0.5 per-level: 0.5
movement-speed: movement-speed:
base: .905 base: .12
per-level: 0 per-level: 0
attack-damage: attack-damage:
base: 2 base: 2