Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/net/Indyuce/mmocore/MMOCore.java
#	src/main/java/net/Indyuce/mmocore/api/player/PlayerData.java
#	src/main/java/net/Indyuce/mmocore/manager/data/mysql/MySQLPlayerDataManager.java
This commit is contained in:
Ka0rX 2022-06-19 21:51:36 +02:00
commit be23a38e3d
36 changed files with 637 additions and 521 deletions

28
pom.xml
View File

@ -15,20 +15,6 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Lumine Releases</name>
<url>https://mvn.lumine.io/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Lumine Snapshots</name>
<url>https://mvn.lumine.io/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<finalName>${project.name}-${project.version}</finalName>
<resources>
@ -81,13 +67,13 @@
<repositories>
<repository>
<id>lumine</id>
<url>https://mvn.lumine.io/repository/maven/</url>
<id>nexus</id>
<url>https://mvn.lumine.io/repository/maven-public/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
<id>phoenix</id>
<url>http://la-grange-evasion.pro.dns-orange.fr:8081/repository/maven-public/</url>
</repository>
<repository>
@ -160,8 +146,8 @@
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.9.2</version>
<artifactId>PlaceholderAPI</artifactId>
<version>2.11.1</version>
<scope>provided</scope>
</dependency>
@ -182,7 +168,7 @@
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>Citizens</artifactId>
<version>2.0.25</version>
<version>2.0.30-b2571</version>
<scope>provided</scope>
</dependency>

View File

@ -27,7 +27,6 @@ import net.Indyuce.mmocore.comp.vault.VaultEconomy;
import net.Indyuce.mmocore.comp.vault.VaultMMOLoader;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.listener.*;
import net.Indyuce.mmocore.listener.bungee.GetMMOCorePlayerListener;
import net.Indyuce.mmocore.listener.event.PlayerPressKeyListener;
import net.Indyuce.mmocore.listener.option.*;
import net.Indyuce.mmocore.listener.profession.FishingListener;
@ -52,129 +51,130 @@ import org.bukkit.command.CommandMap;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import org.spigotmc.SpigotConfig;
import java.io.File;
import java.lang.reflect.Field;
import java.util.logging.Level;
public class MMOCore extends LuminePlugin {
public static MMOCore plugin;
public static MMOCore plugin;
public final WaypointManager waypointManager = new WaypointManager();
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 SkillManager skillManager = new SkillManager();
public final ClassManager classManager = new ClassManager();
public final DropTableManager dropTableManager = new DropTableManager();
public final BoosterManager boosterManager = new BoosterManager();
public final AttributeManager attributeManager = new AttributeManager();
public final PartyManager partyManager = new PartyManager();
public final QuestManager questManager = new QuestManager();
public final ProfessionManager professionManager = new ProfessionManager();
public final ExperienceManager experience = new ExperienceManager();
public final LootChestManager lootChests = new LootChestManager();
public final MMOLoadManager loadManager = new MMOLoadManager();
public final RestrictionManager restrictionManager = new RestrictionManager();
public final StatManager statManager = new StatManager();
@Deprecated
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
public final WaypointManager waypointManager = new WaypointManager();
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 SkillManager skillManager = new SkillManager();
public final ClassManager classManager = new ClassManager();
public final DropTableManager dropTableManager = new DropTableManager();
public final BoosterManager boosterManager = new BoosterManager();
public final AttributeManager attributeManager = new AttributeManager();
public final PartyManager partyManager = new PartyManager();
public final QuestManager questManager = new QuestManager();
public final ProfessionManager professionManager = new ProfessionManager();
public final ExperienceManager experience = new ExperienceManager();
public final LootChestManager lootChests = new LootChestManager();
public final MMOLoadManager loadManager = new MMOLoadManager();
public final RestrictionManager restrictionManager = new RestrictionManager();
public final StatManager statManager = new StatManager();
@Deprecated
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
// Profession managers
public final CustomBlockManager mineManager = new CustomBlockManager();
public final FishingManager fishingManager = new FishingManager();
public final AlchemyManager alchemyManager = new AlchemyManager();
public final EnchantManager enchantManager = new EnchantManager();
public final SmithingManager smithingManager = new SmithingManager();
// Profession managers
public final CustomBlockManager mineManager = new CustomBlockManager();
public final FishingManager fishingManager = new FishingManager();
public final AlchemyManager alchemyManager = new AlchemyManager();
public final EnchantManager enchantManager = new EnchantManager();
public final SmithingManager smithingManager = new SmithingManager();
@NotNull
public ConfigManager configManager;
public VaultEconomy economy;
public RegionHandler regionHandler = new DefaultRegionHandler();
public PlaceholderParser placeholderParser = new DefaultParser();
public DataProvider dataProvider = new YAMLDataProvider();
@NotNull
public ConfigManager configManager;
public VaultEconomy economy;
public RegionHandler regionHandler = new DefaultRegionHandler();
public PlaceholderParser placeholderParser = new DefaultParser();
public DataProvider dataProvider = new YAMLDataProvider();
// Modules
@NotNull
public PartyModule partyModule;
// Modules
@NotNull
public PartyModule partyModule;
@NotNull
public GuildModule guildModule;
public boolean shouldDebugSQL = false;
public boolean hasBungee=false;
private static final int MYTHICLIB_COMPATIBILITY_INDEX = 7;
public MMOCore() {
plugin = this;
}
public MMOCore() {
plugin = this;
}
public void load() {
public void load() {
// Check if the ML build matches
if (MYTHICLIB_COMPATIBILITY_INDEX != MythicLib.MMOCORE_COMPATIBILITY_INDEX) {
getLogger().log(Level.WARNING, "Your versions of MythicLib and MMOCore do not match. Make sure you are using the latest builds of both plugins");
disable();
return;
}
// Check if the ML build matches
if (MYTHICLIB_COMPATIBILITY_INDEX != MythicLib.MMOCORE_COMPATIBILITY_INDEX) {
getLogger().log(Level.WARNING, "Your versions of MythicLib and MMOCore do not match. Make sure you are using the latest builds of both plugins");
disable();
return;
}
// Register MMOCore-specific objects
MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction());
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
// Register MMOCore-specific objects
MythicLib.plugin.getEntities().registerRestriction(new MMOCoreTargetRestriction());
MythicLib.plugin.getModifiers().registerModifierType("attribute", configObject -> new AttributeModifier(configObject));
// Register extra objective, drop items...
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null)
loadManager.registerLoader(new WorldGuardMMOLoader());
if (Bukkit.getPluginManager().getPlugin("Citizens") != null)
loadManager.registerLoader(new CitizensMMOLoader());
if (Bukkit.getPluginManager().getPlugin("Citizens") != null)
loadManager.registerLoader(new CitizensMMOLoader());
if (Bukkit.getPluginManager().getPlugin("Vault") != null) loadManager.registerLoader(new VaultMMOLoader());
if (Bukkit.getPluginManager().getPlugin("Vault") != null) loadManager.registerLoader(new VaultMMOLoader());
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
loadManager.registerLoader(new MythicMobsMMOLoader());
}
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null)
loadManager.registerLoader(new MythicMobsMMOLoader());
}
public void enable() {
new SpigotPlugin(70575, this).checkForUpdate();
new Metrics(this);
saveDefaultConfig();
public void enable() {
new SpigotPlugin(70575, this).checkForUpdate();
new Metrics(this);
saveDefaultConfig();
final int configVersion = getConfig().contains("config-version", true) ? getConfig().getInt("config-version") : -1;
final int defConfigVersion = getConfig().getDefaults().getInt("config-version");
if (configVersion != defConfigVersion) {
getLogger().warning("You may be using an outdated config.yml!");
getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" + defConfigVersion + "')");
}
final int configVersion = getConfig().contains("config-version", true) ? getConfig().getInt("config-version") : -1;
final int defConfigVersion = getConfig().getDefaults().getInt("config-version");
if (configVersion != defConfigVersion) {
getLogger().warning("You may be using an outdated config.yml!");
getLogger().warning("(Your config version: '" + configVersion + "' | Expected config version: '" + defConfigVersion + "')");
}
if (getConfig().isConfigurationSection("mysql") && getConfig().getBoolean("mysql.enabled"))
dataProvider = new MySQLDataProvider(getConfig());
shouldDebugSQL = getConfig().getBoolean("mysql.debug");
if (getConfig().isConfigurationSection("mysql") && getConfig().getBoolean("mysql.enabled"))
dataProvider = new MySQLDataProvider(getConfig());
shouldDebugSQL = getConfig().getBoolean("mysql.debug");
if (getConfig().isConfigurationSection("default-playerdata"))
dataProvider.getDataManager().loadDefaultData(getConfig().getConfigurationSection("default-playerdata"));
if (getConfig().isConfigurationSection("default-playerdata"))
dataProvider.getDataManager().loadDefaultData(getConfig().getConfigurationSection("default-playerdata"));
if (Bukkit.getPluginManager().getPlugin("Vault") != null) economy = new VaultEconomy();
if (Bukkit.getPluginManager().getPlugin("Vault") != null) economy = new VaultEconomy();
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
placeholderParser = new PlaceholderAPIParser();
getLogger().log(Level.INFO, "Hooked onto PlaceholderAPI");
}
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
placeholderParser = new PlaceholderAPIParser();
getLogger().log(Level.INFO, "Hooked onto PlaceholderAPI");
}
if (Bukkit.getPluginManager().getPlugin("Citizens") != null) {
Bukkit.getPluginManager().registerEvents(new CitizenInteractEventListener(), this);
getLogger().log(Level.INFO, "Hooked onto Citizens");
}
if (Bukkit.getPluginManager().getPlugin("Citizens") != null) {
Bukkit.getPluginManager().registerEvents(new CitizenInteractEventListener(), this);
getLogger().log(Level.INFO, "Hooked onto Citizens");
}
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
regionHandler = new WorldGuardRegionHandler();
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
}
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
regionHandler = new WorldGuardRegionHandler();
getLogger().log(Level.INFO, "Hooked onto WorldGuard");
}
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
Bukkit.getServer().getPluginManager().registerEvents(new MythicHook(), this);
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
}
if (Bukkit.getPluginManager().getPlugin("MythicMobs") != null) {
Bukkit.getServer().getPluginManager().registerEvents(new MythicHook(), this);
MMOCore.plugin.getLogger().log(Level.INFO, "Hooked onto MythicMobs");
}
//Checks if the server runs with bungee
boolean bungee = SpigotConfig.bungee;
@ -208,29 +208,29 @@ public class MMOCore extends LuminePlugin {
}
}.runTaskTimer(MMOCore.plugin, 100, 20);
/*
* 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
* not reading the installation guide...
*/
if (Bukkit.getPluginManager().getPlugin("MMOMana") != null) {
getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "MMOCore is not meant to be used with MMOItems ManaAndStamina");
getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "Please read the installation guide!");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with MMOItems ManaAndStamina");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!");
return;
}
/*
* 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
* not reading the installation guide...
*/
if (Bukkit.getPluginManager().getPlugin("MMOMana") != null) {
getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "MMOCore is not meant to be used with MMOItems ManaAndStamina");
getLogger().log(Level.SEVERE, ChatColor.DARK_RED + "Please read the installation guide!");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] MMOCore is not meant to be used with MMOItems ManaAndStamina");
Bukkit.broadcastMessage(ChatColor.DARK_RED + "[MMOCore] Please read the installation guide!");
return;
}
initializePlugin(false);
initializePlugin(false);
if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
if (getConfig().getBoolean("vanilla-exp-redirection.enabled"))
Bukkit.getPluginManager().registerEvents(new RedirectVanillaExp(getConfig().getDouble("vanilla-exp-redirection.ratio")), this);
// Enable debug mode for extra debug tools
if (getConfig().contains("debug")) {
DebugMode.setLevel(getConfig().getInt("debug", 0));
DebugMode.enableActionBar();
}
// Enable debug mode for extra debug tools
if (getConfig().contains("debug")) {
DebugMode.setLevel(getConfig().getInt("debug", 0));
DebugMode.enableActionBar();
}
// Load quest module
try {
@ -255,214 +255,224 @@ public class MMOCore extends LuminePlugin {
partyModule = new MMOCorePartyModule();
}
// Load guild module
try {
String pluginName = UtilityMethods.enumName(getConfig().getString("guild-plugin"));
GuildModuleType moduleType = GuildModuleType.valueOf(pluginName);
Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed");
guildModule = moduleType.provideModule();
} catch (RuntimeException exception) {
getLogger().log(Level.WARNING, "Could not initialize guild module: " + exception.getMessage());
guildModule = new MMOCoreGuildModule();
}
// Skill casting
try {
SkillCastingMode mode = SkillCastingMode.valueOf(UtilityMethods.enumName(getConfig().getString("skill-casting.mode")));
Bukkit.getPluginManager().registerEvents(mode.loadFromConfig(getConfig().getConfigurationSection("skill-casting")), this);
} catch (RuntimeException exception) {
getLogger().log(Level.WARNING, "Could not load skill casting: " + exception.getMessage());
}
// Skill casting
try {
SkillCastingMode mode = SkillCastingMode.valueOf(UtilityMethods.enumName(getConfig().getString("skill-casting.mode")));
Bukkit.getPluginManager().registerEvents(mode.loadFromConfig(getConfig().getConfigurationSection("skill-casting")), this);
} catch (RuntimeException exception) {
getLogger().log(Level.WARNING, "Could not load skill casting: " + exception.getMessage());
}
if (configManager.overrideVanillaExp = getConfig().getBoolean("override-vanilla-exp"))
Bukkit.getPluginManager().registerEvents(new VanillaExperienceOverride(), this);
if (configManager.overrideVanillaExp = getConfig().getBoolean("override-vanilla-exp"))
Bukkit.getPluginManager().registerEvents(new VanillaExperienceOverride(), this);
if (getConfig().getBoolean("hotbar-swapping.enabled"))
try {
Bukkit.getPluginManager().registerEvents(new HotbarSwap(getConfig().getConfigurationSection("hotbar-swapping")), this);
} catch (RuntimeException exception) {
getLogger().log(Level.WARNING, "Could not load hotbar swapping: " + exception.getMessage());
}
if (getConfig().getBoolean("hotbar-swapping.enabled"))
try {
Bukkit.getPluginManager().registerEvents(new HotbarSwap(getConfig().getConfigurationSection("hotbar-swapping")), this);
} catch (RuntimeException exception) {
getLogger().log(Level.WARNING, "Could not load hotbar swapping: " + exception.getMessage());
}
if (getConfig().getBoolean("prevent-spawner-xp"))
Bukkit.getPluginManager().registerEvents(new NoSpawnerEXP(), this);
if (getConfig().getBoolean("prevent-spawner-xp"))
Bukkit.getPluginManager().registerEvents(new NoSpawnerEXP(), this);
if (getConfig().getBoolean("death-exp-loss.enabled"))
Bukkit.getPluginManager().registerEvents(new DeathExperienceLoss(), this);
if (getConfig().getBoolean("death-exp-loss.enabled"))
Bukkit.getPluginManager().registerEvents(new DeathExperienceLoss(), this);
if (getConfig().getBoolean("shift-click-player-profile-check"))
Bukkit.getPluginManager().registerEvents(new PlayerProfileCheck(), this);
if (getConfig().getBoolean("shift-click-player-profile-check"))
Bukkit.getPluginManager().registerEvents(new PlayerProfileCheck(), this);
Bukkit.getPluginManager().registerEvents(new WaypointsListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getPluginManager().registerEvents(new GoldPouchesListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockListener(), this);
Bukkit.getPluginManager().registerEvents(new LootableChestsListener(), this);
Bukkit.getPluginManager().registerEvents(new GuildListener(), this);
Bukkit.getPluginManager().registerEvents(new FishingListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), this);
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), this);
// Bukkit.getPluginManager().registerEvents(new ClassTriggers(), this);
Bukkit.getPluginManager().registerEvents(new WaypointsListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
Bukkit.getPluginManager().registerEvents(new GoldPouchesListener(), this);
Bukkit.getPluginManager().registerEvents(new BlockListener(), this);
Bukkit.getPluginManager().registerEvents(new LootableChestsListener(), this);
Bukkit.getPluginManager().registerEvents(new GuildListener(), this);
Bukkit.getPluginManager().registerEvents(new FishingListener(), this);
Bukkit.getPluginManager().registerEvents(new PlayerCollectStats(), this);
Bukkit.getPluginManager().registerEvents(new PlayerPressKeyListener(), this);
// Bukkit.getPluginManager().registerEvents(new ClassTriggers(), this);
/*
* Initialize player data from all online players. This is very important to do
* that after registering all the professses otherwise the player datas can't
* recognize what profess the player has and professes will be lost
*/
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player.getUniqueId()));
/*
* Initialize player data from all online players. This is very important to do
* that after registering all the professses otherwise the player datas can't
* recognize what profess the player has and professes will be lost
*/
Bukkit.getOnlinePlayers().forEach(player -> dataProvider.getDataManager().setup(player.getUniqueId()));
// load guild data after loading player data
dataProvider.getGuildManager().load();
// load guild data after loading player data
dataProvider.getGuildManager().load();
// Command
try {
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
// Command
try {
final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
bukkitCommandMap.setAccessible(true);
CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());
FileConfiguration config = new ConfigFile("commands").getConfig();
FileConfiguration config = new ConfigFile("commands").getConfig();
if (config.contains("player"))
commandMap.register("mmocore", new PlayerStatsCommand(config.getConfigurationSection("player")));
if (config.contains("attributes"))
commandMap.register("mmocore", new AttributesCommand(config.getConfigurationSection("attributes")));
if (config.contains("class"))
commandMap.register("mmocore", new ClassCommand(config.getConfigurationSection("class")));
if (config.contains("waypoints"))
commandMap.register("mmocore", new WaypointsCommand(config.getConfigurationSection("waypoints")));
if (config.contains("quests"))
commandMap.register("mmocore", new QuestsCommand(config.getConfigurationSection("quests")));
if (config.contains("skills"))
commandMap.register("mmocore", new SkillsCommand(config.getConfigurationSection("skills")));
if (config.contains("friends"))
commandMap.register("mmocore", new FriendsCommand(config.getConfigurationSection("friends")));
if (config.contains("party"))
commandMap.register("mmocore", new PartyCommand(config.getConfigurationSection("party")));
if (config.contains("guild"))
commandMap.register("mmocore", new GuildCommand(config.getConfigurationSection("guild")));
if (config.contains("player"))
commandMap.register("mmocore", new PlayerStatsCommand(config.getConfigurationSection("player")));
if (config.contains("attributes"))
commandMap.register("mmocore", new AttributesCommand(config.getConfigurationSection("attributes")));
if (config.contains("class"))
commandMap.register("mmocore", new ClassCommand(config.getConfigurationSection("class")));
if (config.contains("waypoints"))
commandMap.register("mmocore", new WaypointsCommand(config.getConfigurationSection("waypoints")));
if (config.contains("quests"))
commandMap.register("mmocore", new QuestsCommand(config.getConfigurationSection("quests")));
if (config.contains("skills"))
commandMap.register("mmocore", new SkillsCommand(config.getConfigurationSection("skills")));
if (config.contains("friends"))
commandMap.register("mmocore", new FriendsCommand(config.getConfigurationSection("friends")));
if (config.contains("party"))
commandMap.register("mmocore", new PartyCommand(config.getConfigurationSection("party")));
if (config.contains("guild"))
commandMap.register("mmocore", new GuildCommand(config.getConfigurationSection("guild")));
if (hasEconomy() && economy.isValid()) {
if (config.contains("withdraw"))
commandMap.register("mmocore", new WithdrawCommand(config.getConfigurationSection("withdraw")));
if (config.contains("deposit"))
commandMap.register("mmocore", new DepositCommand(config.getConfigurationSection("deposit")));
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
ex.printStackTrace();
}
if (hasEconomy() && economy.isValid()) {
if (config.contains("withdraw"))
commandMap.register("mmocore", new WithdrawCommand(config.getConfigurationSection("withdraw")));
if (config.contains("deposit"))
commandMap.register("mmocore", new DepositCommand(config.getConfigurationSection("deposit")));
}
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
ex.printStackTrace();
}
MMOCoreCommandTreeRoot mmoCoreCommand = new MMOCoreCommandTreeRoot();
getCommand("mmocore").setExecutor(mmoCoreCommand);
getCommand("mmocore").setTabCompleter(mmoCoreCommand);
MMOCoreCommandTreeRoot mmoCoreCommand = new MMOCoreCommandTreeRoot();
getCommand("mmocore").setExecutor(mmoCoreCommand);
getCommand("mmocore").setTabCompleter(mmoCoreCommand);
if (getConfig().getBoolean("auto-save.enabled")) {
int autosave = getConfig().getInt("auto-save.interval") * 20;
new BukkitRunnable() {
public void run() {
if (getConfig().getBoolean("auto-save.enabled")) {
int autosave = getConfig().getInt("auto-save.interval") * 20;
new BukkitRunnable() {
public void run() {
// Save player data
for (PlayerData data : PlayerData.getAll())
if (data.isFullyLoaded())
dataProvider.getDataManager().saveData(data);
// Save player data
for (PlayerData data : PlayerData.getAll())
if (data.isFullyLoaded())
dataProvider.getDataManager().saveData(data);
// Save guild info
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
}
}.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave);
}
}
// Save guild info
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
}
}.runTaskTimerAsynchronously(MMOCore.plugin, autosave, autosave);
}
}
public void disable() {
public void disable() {
// Save player data
for (PlayerData data : PlayerData.getAll())
if (data.isFullyLoaded()) {
data.close();
dataProvider.getDataManager().saveData(data);
}
// Save player data
for (PlayerData data : PlayerData.getAll())
if (data.isFullyLoaded()) {
data.close();
dataProvider.getDataManager().saveData(data);
}
// Save guild info
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
// Save guild info
for (Guild guild : dataProvider.getGuildManager().getAll())
dataProvider.getGuildManager().save(guild);
// Close MySQL data provider (memory leaks)
if (dataProvider instanceof MySQLDataProvider)
((MySQLDataProvider) dataProvider).close();
// Close MySQL data provider (memory leaks)
if (dataProvider instanceof MySQLDataProvider)
((MySQLDataProvider) dataProvider).close();
// Reset active blocks
mineManager.resetRemainingBlocks();
// Reset active blocks
mineManager.resetRemainingBlocks();
// Clear spawned loot chests
lootChests.getActive().forEach(chest -> chest.expire(false));
}
// Clear spawned loot chests
lootChests.getActive().forEach(chest -> chest.expire(false));
}
/**
* Called either when the server starts when initializing the manager for
* the first time, or when issuing a plugin reload; in that case, stuff
* like listeners must all be cleared before.
* <p>
* Also see {@link MMOCoreManager}
*
* @param clearBefore True when issuing a plugin reload
*/
public void initializePlugin(boolean clearBefore) {
if (clearBefore)
reloadConfig();
/**
* Called either when the server starts when initializing the manager for
* the first time, or when issuing a plugin reload; in that case, stuff
* like listeners must all be cleared before.
*
* Also see {@link MMOCoreManager}
*
* @param clearBefore True when issuing a plugin reload
*/
public void initializePlugin(boolean clearBefore) {
if (clearBefore)
reloadConfig();
configManager = new ConfigManager();
configManager = new ConfigManager();
statManager.initialize(clearBefore);
if (clearBefore)
MythicLib.plugin.getSkills().initialize(true);
skillManager.initialize(clearBefore);
mineManager.initialize(clearBefore);
partyManager.initialize(clearBefore);
attributeManager.initialize(clearBefore);
statManager.initialize(clearBefore);
if (clearBefore)
MythicLib.plugin.getSkills().initialize(true);
skillManager.initialize(clearBefore);
mineManager.initialize(clearBefore);
partyManager.initialize(clearBefore);
attributeManager.initialize(clearBefore);
// Experience must be loaded before professions and classes
experience.initialize(clearBefore);
// Experience must be loaded before professions and classes
experience.initialize(clearBefore);
// Drop tables must be loaded before professions
dropTableManager.initialize(clearBefore);
// Drop tables must be loaded before professions
dropTableManager.initialize(clearBefore);
professionManager.initialize(clearBefore);
classManager.initialize(clearBefore);
professionManager.initialize(clearBefore);
classManager.initialize(clearBefore);
InventoryManager.load();
InventoryManager.load();
questManager.initialize(clearBefore);
lootChests.initialize(clearBefore);
restrictionManager.initialize(clearBefore);
waypointManager.initialize(clearBefore);
requestManager.initialize(clearBefore);
soundManager.initialize(clearBefore);
configItems.initialize(clearBefore);
questManager.initialize(clearBefore);
lootChests.initialize(clearBefore);
restrictionManager.initialize(clearBefore);
waypointManager.initialize(clearBefore);
requestManager.initialize(clearBefore);
soundManager.initialize(clearBefore);
configItems.initialize(clearBefore);
if (getConfig().isConfigurationSection("action-bar"))
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
if (getConfig().isConfigurationSection("action-bar"))
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
if (clearBefore)
PlayerData.getAll().forEach(PlayerData::update);
}
if (clearBefore)
PlayerData.getAll().forEach(PlayerData::update);
}
public static void log(String message) {
log(Level.INFO, message);
}
public static void log(String message) {
log(Level.INFO, message);
}
public static void debug(int value, String message) {
debug(value, Level.INFO, message);
}
public static void debug(int value, String message) {
debug(value, Level.INFO, message);
}
public static void log(Level level, String message) {
plugin.getLogger().log(level, message);
}
public static void log(Level level, String message) {
plugin.getLogger().log(level, message);
}
public static void debug(int value, Level level, String message) {
if (DebugMode.level > (value - 1)) plugin.getLogger().log(level, message);
}
public static void debug(int value, Level level, String message) {
if (DebugMode.level > (value - 1)) plugin.getLogger().log(level, message);
}
public File getJarFile() {
return getFile();
}
public File getJarFile() {
return getFile();
}
public boolean hasEconomy() {
return economy != null && economy.isValid();
}
public boolean hasEconomy() {
return economy != null && economy.isValid();
}
public static void sqlDebug(String s) {
if (!MMOCore.plugin.shouldDebugSQL) return;
MMOCore.plugin.getLogger().warning("- [SQL Debug] " + s);
}
public static void sqlDebug(String s) {
if(!MMOCore.plugin.shouldDebugSQL) return;
MMOCore.plugin.getLogger().warning("- [SQL Debug] " + s);
}
}

View File

@ -49,7 +49,7 @@ public class PlayerActionBar extends BukkitRunnable {
.replace("{stellium}", digit.format(data.getStellium()))
.replace("{max_stellium}", StatInfo.valueOf("MAX_STELLIUM").format(data.getStats().getStat("MAX_STELLIUM")))
.replace("{class}", data.getProfess().getName())
.replace("{xp}", "" + data.getExperience())
.replace("{xp}", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()))
.replace("{armor}", StatInfo.valueOf("ARMOR").format(data.getPlayer().getAttribute(Attribute.GENERIC_ARMOR).getValue()))
.replace("{level}", "" + data.getLevel())
.replace("{name}", data.getPlayer().getDisplayName())))));

View File

@ -4,11 +4,12 @@ import org.bukkit.event.HandlerList;
import net.Indyuce.mmocore.experience.Profession;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.jetbrains.annotations.Nullable;
public class PlayerLevelUpEvent extends PlayerDataEvent {
private static final HandlerList handlers = new HandlerList();
// if null, this is main level
// If null, this is main level
private final Profession profession;
private final int oldLevel, newLevel;
@ -36,6 +37,7 @@ public class PlayerLevelUpEvent extends PlayerDataEvent {
return profession != null;
}
@Nullable
public Profession getProfession() {
return profession;
}

View File

@ -1,6 +1,5 @@
package net.Indyuce.mmocore.api.player;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.api.player.MMOPlayerData;
import io.lumine.mythic.lib.player.TemporaryPlayerData;
import io.lumine.mythic.lib.player.cooldown.CooldownMap;
@ -29,7 +28,6 @@ import net.Indyuce.mmocore.experience.droptable.ExperienceItem;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import net.Indyuce.mmocore.manager.data.mysql.MySQLTableEditor;
import net.Indyuce.mmocore.party.AbstractParty;
import net.Indyuce.mmocore.party.provided.Party;
import net.Indyuce.mmocore.player.Unlockable;
@ -52,7 +50,6 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class PlayerData extends OfflinePlayerData implements Closable, ExperienceTableClaimer {
@ -601,18 +598,19 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
return;
}
value = MMOCore.plugin.boosterManager.calculateExp(null, value);
value *= 1 + getStats().getStat("ADDITIONAL_EXPERIENCE") / 100;
// Splitting exp through party members
AbstractParty party = getParty();
if (splitExp && party != null) {
List<PlayerData> onlineMembers = getParty().getOnlineMembers();
AbstractParty party;
if (splitExp && (party = getParty()) != null) {
List<PlayerData> onlineMembers = party.getOnlineMembers();
value /= onlineMembers.size();
for (PlayerData member : onlineMembers)
member.giveExperience(value, EXPSource.PARTY_SHARING, null, false);
if (!equals(member))
member.giveExperience(value, source, null, false);
}
// Apply buffs AFTER splitting exp
value *= (1 + getStats().getStat("ADDITIONAL_EXPERIENCE") / 100) * MMOCore.plugin.boosterManager.getMultiplier(null);
PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(this, value, source);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
@ -620,7 +618,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
// Experience hologram
if (hologramLocation != null && isOnline())
MMOCoreUtils.displayIndicator(hologramLocation, MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", String.valueOf(event.getExperience())).message());
MMOCoreUtils.displayIndicator(hologramLocation, MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", MythicLib.plugin.getMMOConfig().decimal.format(event.getExperience())).message());
experience = Math.max(0, experience + event.getExperience());

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.command.rpg.admin;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.command.api.CommandTreeNode;
import io.lumine.mythic.lib.command.api.Parameter;
import net.Indyuce.mmocore.MMOCore;
@ -23,9 +24,9 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
addChild(new ActionCommandTreeNode(this, "set", PlayerData::setExperience, PlayerProfessions::setExperience));
addChild(new ActionCommandTreeNode(this, "give", (data, value) -> data.giveExperience(value, EXPSource.COMMAND), (professions, profession,
value) -> professions.giveExperience(profession, value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
value) -> professions.giveExperience(profession, value, EXPSource.COMMAND)));
addChild(new ActionCommandTreeNode(this, "take", (data, value) -> data.giveExperience(-value, EXPSource.COMMAND), (professions, profession,
value) -> professions.giveExperience(profession, -value, EXPSource.COMMAND, professions.getPlayerData().getPlayer().getLocation())));
value) -> professions.giveExperience(profession, -value, EXPSource.COMMAND)));
}
public static class ActionCommandTreeNode extends CommandTreeNode {
@ -68,7 +69,7 @@ public class ExperienceCommandTreeNode extends CommandTreeNode {
if (args[4].equalsIgnoreCase("main")) {
main.accept(data, amount);
CommandVerbose.verbose(sender, CommandVerbose.CommandType.EXPERIENCE, ChatColor.GOLD + player.getName() + ChatColor.YELLOW
+ " now has " + ChatColor.GOLD + data.getExperience() + ChatColor.YELLOW + " EXP.");
+ " now has " + ChatColor.GOLD + MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()) + ChatColor.YELLOW + " EXP.");
return CommandResult.SUCCESS;
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.command.rpg.admin;
import io.lumine.mythic.lib.MythicLib;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -33,7 +34,7 @@ public class InfoCommandTreeNode extends CommandTreeNode {
sender.sendMessage(ChatColor.YELLOW + "----------------------------------------------------");
sender.sendMessage(ChatColor.YELLOW + "Class: " + ChatColor.GOLD + playerData.getProfess().getName());
sender.sendMessage(ChatColor.YELLOW + "Level: " + ChatColor.GOLD + playerData.getLevel());
sender.sendMessage(ChatColor.YELLOW + "Experience: " + ChatColor.GOLD + playerData.getExperience() + ChatColor.YELLOW + " / " + ChatColor.GOLD
sender.sendMessage(ChatColor.YELLOW + "Experience: " + ChatColor.GOLD + MythicLib.plugin.getMMOConfig().decimal.format(playerData.getExperience()) + ChatColor.YELLOW + " / " + ChatColor.GOLD
+ playerData.getLevelUpExperience());
sender.sendMessage(ChatColor.YELLOW + "Class Points: " + ChatColor.GOLD + playerData.getClassPoints());
sender.sendMessage(ChatColor.YELLOW + "Quests: " + ChatColor.GOLD + playerData.getQuestData().getFinishedQuests().size() + ChatColor.YELLOW

View File

@ -128,7 +128,7 @@ public class RPGPlaceholders extends PlaceholderExpansion {
.valueOf(playerData.getCollectionSkills().getLevel(identifier.substring(11).replace(" ", "-").replace("_", "-").toLowerCase()));
else if (identifier.equals("experience"))
return String.valueOf(playerData.getExperience());
return MythicLib.plugin.getMMOConfig().decimal.format(playerData.getExperience());
else if (identifier.equals("next_level"))
return String.valueOf(playerData.getLevelUpExperience());
@ -226,9 +226,9 @@ public class RPGPlaceholders extends PlaceholderExpansion {
else if (placeholder.equalsIgnoreCase("leader"))
return Bukkit.getOfflinePlayer(playerData.getGuild().getOwner()).getName();
else if (placeholder.equalsIgnoreCase("members"))
return "" + playerData.getGuild().getMembers().count();
return String.valueOf(playerData.getGuild().countMembers());
else if (placeholder.equalsIgnoreCase("online_members"))
return "" + playerData.getGuild().getMembers().countOnline();
return String.valueOf(playerData.getGuild().countOnlineMembers());
}
return null;

View File

@ -19,7 +19,10 @@ public enum EXPSource {
/**
* When party members share exp
*
* @deprecated Not used anymore
*/
@Deprecated
PARTY_SHARING,
/**

View File

@ -13,6 +13,7 @@ import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.loot.chest.particle.SmallParticleEffect;
import net.Indyuce.mmocore.party.AbstractParty;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -22,6 +23,7 @@ import org.bukkit.configuration.ConfigurationSection;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -147,15 +149,15 @@ public class PlayerProfessions {
giveExperience(profession, total, source);
}
public void giveExperience(Profession profession, double value, EXPSource source) {
giveExperience(profession, value, source, null);
}
public boolean hasReachedMaxLevel(Profession profession) {
return profession.hasMaxLevel() && getLevel(profession) >= profession.getMaxLevel();
}
public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation) {
public void giveExperience(Profession profession, double value, EXPSource source) {
giveExperience(profession, value, source, null, true);
}
public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation, boolean splitExp) {
Validate.isTrue(playerData.isOnline(), "Cannot give experience to offline player");
if (value <= 0)
return;
@ -165,23 +167,31 @@ public class PlayerProfessions {
return;
}
value = MMOCore.plugin.boosterManager.calculateExp(profession, value);
// Splitting exp through party members
AbstractParty party;
if (splitExp && (party = playerData.getParty()) != null) {
List<PlayerData> onlineMembers = party.getOnlineMembers();
value /= onlineMembers.size();
for (PlayerData member : onlineMembers)
if (!member.equals(playerData))
member.getCollectionSkills().giveExperience(profession, value, source, null, false);
}
// Adds functionality for additional experience per profession.
value *= 1 + playerData.getStats().getInstance("ADDITIONAL_EXPERIENCE_" + UtilityMethods.enumName(profession.getId())).getTotal() / 100;
// Display hologram
if (hologramLocation != null)
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", "" + value).message());
// Apply buffs AFTER splitting exp
value *= (1 + playerData.getStats().getStat("ADDITIONAL_EXPERIENCE_" + UtilityMethods.enumName(profession.getId())) / 100) * MMOCore.plugin.boosterManager.getMultiplier(profession);
PlayerExperienceGainEvent event = new PlayerExperienceGainEvent(playerData, profession, value, source);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
return;
// Display hologram
if (hologramLocation != null)
MMOCoreUtils.displayIndicator(hologramLocation.add(.5, 1.5, .5), MMOCore.plugin.configManager.getSimpleMessage("exp-hologram", "exp", MythicLib.plugin.getMMOConfig().decimal.format(event.getExperience())).message());
exp.put(profession.getId(), Math.max(0, exp.getOrDefault(profession.getId(), 0.) + event.getExperience()));
int level, oldLevel = getLevel(profession);
double needed,exp;
double needed, exp;
/*
* Loop for exp overload when leveling up, will continue

View File

@ -127,7 +127,7 @@ public class Profession extends PostLoadObject implements ExperienceObject {
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, EXPSource source) {
hologramLocation = !getOption(Profession.ProfessionOption.EXP_HOLOGRAMS) ? null
: hologramLocation;
playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation);
playerData.getCollectionSkills().giveExperience(this, experience, EXPSource.SOURCE, hologramLocation, true);
}
@Override

View File

@ -11,6 +11,8 @@ import org.jetbrains.annotations.Nullable;
* Used to differenciate between the main class experience and
* experience given in a specific profession. Also being used to
* monitor EXP holograms.
*
* @deprecated Merged with {@link net.Indyuce.mmocore.experience.ExperienceObject}
*/
@Deprecated
public interface ExperienceDispenser {

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.gui;
import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
import io.lumine.mythic.lib.version.VersionMaterial;
@ -243,7 +244,7 @@ public class PlayerStats extends EditableInventory {
bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|");
holders.register("percent", decimal.format(ratio * 100));
holders.register("exp", "" + data.getExperience());
holders.register("exp", MythicLib.plugin.getMMOConfig().decimal.format(data.getExperience()));
holders.register("level", "" + data.getLevel());
holders.register("class_points", "" + data.getClassPoints());
holders.register("skill_points", "" + data.getSkillPoints());

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmocore.gui.social.guild;
import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.input.PlayerInput.InputType;
@ -25,6 +23,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.List;
import java.util.UUID;
public class EditableGuildAdmin extends EditableInventory {
@ -43,7 +42,7 @@ public class EditableGuildAdmin extends EditableInventory {
return new GuildViewInventory(data, this);
}
public static class MemberDisplayItem extends InventoryItem {
public static class MemberDisplayItem extends InventoryItem<GuildViewInventory> {
public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) {
super(memberItem, config);
}
@ -54,8 +53,8 @@ public class EditableGuildAdmin extends EditableInventory {
}
@Override
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
PlayerData member = PlayerData.get(inv.getPlayerData().getGuild().getMembers().get(n));
public Placeholders getPlaceholders(GuildViewInventory inv, int n) {
PlayerData member = PlayerData.get(inv.members.get(n));
Placeholders holders = new Placeholders();
@ -68,8 +67,8 @@ public class EditableGuildAdmin extends EditableInventory {
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n);
public ItemStack display(GuildViewInventory inv, int n) {
UUID uuid = inv.members.get(n);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
ItemStack disp = super.display(inv, n);
@ -87,7 +86,7 @@ public class EditableGuildAdmin extends EditableInventory {
}
}
public static class MemberItem extends SimplePlaceholderItem {
public static class MemberItem extends SimplePlaceholderItem<GuildViewInventory> {
private final InventoryItem empty;
private final MemberDisplayItem member;
@ -102,8 +101,8 @@ public class EditableGuildAdmin extends EditableInventory {
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
return inv.getPlayerData().getGuild().getMembers().count() > n ? member.display(inv, n) : empty.display(inv, n);
public ItemStack display(GuildViewInventory inv, int n) {
return inv.getPlayerData().getGuild().countMembers() > n ? member.display(inv, n) : empty.display(inv, n);
}
@Override
@ -115,15 +114,23 @@ public class EditableGuildAdmin extends EditableInventory {
public class GuildViewInventory extends GeneratedInventory {
private final int max;
private List<UUID> members;
public GuildViewInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
max = editable.getByFunction("member").getSlots().size();
}
@Override
public void open() {
members = playerData.getGuild().listMembers();
super.open();
}
@Override
public String calculateName() {
return getName().replace("{max}", "" + max).replace("{players}", "" + getPlayerData().getGuild().getMembers().count());
return getName().replace("{max}", "" + max).replace("{players}", "" + getPlayerData().getGuild().countMembers());
}
@Override
@ -138,7 +145,7 @@ public class EditableGuildAdmin extends EditableInventory {
if (item.getFunction().equals("invite")) {
if (playerData.getGuild().getMembers().count() >= max) {
if (playerData.getGuild().countMembers() >= max) {
MMOCore.plugin.configManager.getSimpleMessage("guild-is-full").send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
return;
@ -162,7 +169,7 @@ public class EditableGuildAdmin extends EditableInventory {
}
PlayerData targetData = PlayerData.get(target);
if (playerData.getGuild().getMembers().has(target.getUniqueId())) {
if (playerData.getGuild().hasMember(target.getUniqueId())) {
MMOCore.plugin.configManager.getSimpleMessage("already-in-guild", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();

View File

@ -21,6 +21,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import java.util.List;
import java.util.UUID;
public class EditableGuildView extends EditableInventory {
@ -35,7 +36,7 @@ public class EditableGuildView extends EditableInventory {
return function.equals("member") ? new MemberItem(config) : (function.equals("next") || function.equals("previous") || function.equals("disband") || function.equals("invite")) ? new ConditionalItem(function, config) : new SimplePlaceholderItem(config);
}
public static class MemberDisplayItem extends InventoryItem {
public static class MemberDisplayItem extends InventoryItem<GuildViewInventory> {
public MemberDisplayItem(MemberItem memberItem, ConfigurationSection config) {
super(memberItem, config);
}
@ -46,8 +47,8 @@ public class EditableGuildView extends EditableInventory {
}
@Override
public Placeholders getPlaceholders(GeneratedInventory inv, int n) {
UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n);
public Placeholders getPlaceholders(GuildViewInventory inv, int n) {
UUID uuid = inv.members.get(n);
Placeholders holders = new Placeholders();
/*
* Will never be null since a players name will always be recorded
@ -64,8 +65,8 @@ public class EditableGuildView extends EditableInventory {
}
@Override
public ItemStack display(GeneratedInventory inv, int n) {
UUID uuid = inv.getPlayerData().getGuild().getMembers().get(n);
public ItemStack display(GuildViewInventory inv, int n) {
UUID uuid = inv.members.get(n);
ItemStack disp = super.display(inv, n);
ItemMeta meta = disp.getItemMeta();
@ -99,7 +100,7 @@ public class EditableGuildView extends EditableInventory {
@Override
public ItemStack display(GuildViewInventory inv, int n) {
int index = n * inv.getPage();
return inv.getPlayerData().getGuild().getMembers().count() > index ? member.display(inv, index) : empty.display(inv, index);
return inv.getPlayerData().getGuild().countMembers() > index ? member.display(inv, index) : empty.display(inv, index);
}
@Override
@ -120,7 +121,7 @@ public class EditableGuildView extends EditableInventory {
public ItemStack display(GuildViewInventory inv, int n) {
if (function.equals("next"))
if (inv.getPage() == (inv.getPlayerData().getGuild().getMembers().count() + 20)
if (inv.getPage() == (inv.getPlayerData().getGuild().countMembers() + 20)
/ inv.getByFunction("member").getSlots().size())
return null;
if (function.equals("previous") && inv.getPage() == 1)
@ -136,19 +137,26 @@ public class EditableGuildView extends EditableInventory {
}
public class GuildViewInventory extends GeneratedInventory {
private int page = 1;
private final int maxpages;
private int page = 1;
private List<UUID> members;
public GuildViewInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
maxpages = (playerData.getGuild().getMembers().count() + 20)
/ editable.getByFunction("member").getSlots().size();
maxpages = (playerData.getGuild().countMembers() + 20) / editable.getByFunction("member").getSlots().size();
}
@Override
public void open() {
members = playerData.getGuild().listMembers();
super.open();
}
@Override
public String calculateName() {
return getName().replace("{online_players}", "" + getPlayerData().getGuild().getMembers().countOnline()).replace("{page}", "" + page).replace("{maxpages}", "" + maxpages).replace("{players}", "" + getPlayerData().getGuild().getMembers().count()).replace("{tag}", getPlayerData().getGuild().getTag()).replace("{name}", getPlayerData().getGuild().getName());
return getName().replace("{online_players}", "" + getPlayerData().getGuild().countOnlineMembers()).replace("{page}", "" + page).replace("{maxpages}", "" + maxpages).replace("{players}", String.valueOf(getPlayerData().getGuild().countMembers())).replace("{tag}", getPlayerData().getGuild().getTag()).replace("{name}", getPlayerData().getGuild().getName());
}
@Override
@ -209,7 +217,7 @@ public class EditableGuildView extends EditableInventory {
}
PlayerData targetData = PlayerData.get(target);
if (playerData.getGuild().getMembers().has(targetData.getUniqueId())) {
if (playerData.getGuild().hasMember(targetData.getUniqueId())) {
MMOCore.plugin.configManager.getSimpleMessage("already-in-guild", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();

View File

@ -172,6 +172,13 @@ public class EditablePartyView extends EditableInventory {
return;
}
if (Math.abs(targetData.getLevel() - party.getLevel()) > MMOCore.plugin.configManager.maxPartyLevelDifference) {
MMOCore.plugin.configManager.getSimpleMessage("high-level-difference", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_NO, 1, 1);
open();
return;
}
party.sendInvite(playerData, targetData);
MMOCore.plugin.configManager.getSimpleMessage("sent-party-invite", "player", target.getName()).send(player);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);

View File

@ -1,4 +1,11 @@
package net.Indyuce.mmocore.guild;
import org.bukkit.entity.Player;
public interface AbstractGuild {
/**
* @return If given player is in that party
*/
boolean hasMember(Player player);
}

View File

@ -1,7 +1,7 @@
package net.Indyuce.mmocore.guild;
import net.Indyuce.mmocore.guild.compat.FactionsGuildModule;
import net.Indyuce.mmocore.guild.compat.GuildsGuildModule;
import net.Indyuce.mmocore.guild.compat.KingdomsXGuildModule;
import net.Indyuce.mmocore.guild.compat.UltimateClansGuildModule;
import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule;
import org.bukkit.Bukkit;
@ -9,9 +9,10 @@ import org.bukkit.Bukkit;
import javax.inject.Provider;
public enum GuildModuleType {
FACTIONS("Factions", FactionsGuildModule::new),
// Useless since MythicLib already supports FactionBridge
// FACTIONS("Factions", FactionsGuildModule::new),
GUILDS("Guilds", GuildsGuildModule::new),
KINGDOMSX("Guilds", GuildsGuildModule::new),
KINGDOMSX("KingdomsX", KingdomsXGuildModule::new),
MMOCORE("MMOCore", MMOCoreGuildModule::new),
ULTIMATE_CLANS("UltimateClans", UltimateClansGuildModule::new),
;

View File

@ -6,13 +6,20 @@ import com.massivecraft.factions.Faction;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.guild.AbstractGuild;
import net.Indyuce.mmocore.guild.GuildModule;
import org.apache.commons.lang.NotImplementedException;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class FactionsGuildModule implements GuildModule {
@Override
public AbstractGuild getGuild(PlayerData playerData) {
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(playerData.getPlayer());
if (fPlayer == null)
return null;
return fPlayer.hasFaction() ? new CustomGuild(fPlayer.getFaction()) : null;
}
@ -22,7 +29,12 @@ public class FactionsGuildModule implements GuildModule {
private final Faction faction;
CustomGuild(Faction faction) {
this.faction = faction;
this.faction = Objects.requireNonNull(faction);
}
@Override
public boolean hasMember(Player player) {
throw new NotImplementedException();
}
}
}

View File

@ -5,8 +5,11 @@ import me.glaremasters.guilds.guild.Guild;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.guild.AbstractGuild;
import net.Indyuce.mmocore.guild.GuildModule;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class GuildsGuildModule implements GuildModule {
@Override
@ -21,7 +24,12 @@ public class GuildsGuildModule implements GuildModule {
private final Guild guild;
CustomGuild(Guild guild) {
this.guild = guild;
this.guild = Objects.requireNonNull(guild);
}
@Override
public boolean hasMember(Player player) {
return guild.getMember(player.getUniqueId()) != null;
}
}
}

View File

@ -3,18 +3,23 @@ package net.Indyuce.mmocore.guild.compat;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.guild.AbstractGuild;
import net.Indyuce.mmocore.guild.GuildModule;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kingdoms.constants.kingdom.Kingdom;
import org.kingdoms.constants.player.KingdomPlayer;
import org.kingdoms.main.Kingdoms;
import java.util.Objects;
public class KingdomsXGuildModule implements GuildModule {
@Override
public AbstractGuild getGuild(PlayerData playerData) {
KingdomPlayer kPlayer = Kingdoms.get().getDataHandlers().getKingdomPlayerManager().getData(playerData.getUniqueId());
Kingdom kingdom = kPlayer == null ? null : kPlayer.getKingdom();
if (kPlayer == null)
return null;
Kingdom kingdom = kPlayer.getKingdom();
return kingdom == null ? null : new CustomGuild(kingdom);
}
@ -24,7 +29,12 @@ public class KingdomsXGuildModule implements GuildModule {
private final Kingdom kingdom;
CustomGuild(Kingdom kingdom) {
this.kingdom = kingdom;
this.kingdom = Objects.requireNonNull(kingdom);
}
@Override
public boolean hasMember(Player player) {
return kingdom.isMember(player);
}
}
}

View File

@ -6,8 +6,11 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.guild.AbstractGuild;
import net.Indyuce.mmocore.guild.GuildModule;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class UltimateClansGuildModule implements GuildModule {
private static final UClans API = (UClans) Bukkit.getPluginManager().getPlugin("UltimateCLans");
@ -22,7 +25,13 @@ public class UltimateClansGuildModule implements GuildModule {
private final ClanData clan;
CustomGuild(ClanData clan) {
this.clan = clan;
this.clan = Objects.requireNonNull(clan);
}
@Override
public boolean hasMember(Player player) {
// List implementation. Pretty bad
return clan.getMembers().contains(player);
}
}
}

View File

@ -1,164 +1,148 @@
package net.Indyuce.mmocore.guild.provided;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import net.Indyuce.mmocore.guild.AbstractGuild;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.ConfigMessage;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.social.Request;
import net.Indyuce.mmocore.gui.api.PluginInventory;
import net.Indyuce.mmocore.gui.social.guild.EditableGuildView.GuildViewInventory;
import net.Indyuce.mmocore.guild.AbstractGuild;
import net.Indyuce.mmocore.manager.InventoryManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.function.Consumer;
public class Guild implements AbstractGuild {
private final GuildMembers members = new GuildMembers();
private final Map<UUID, Long> invites = new HashMap<>();
private final String guildId, guildName, guildTag;
private final Map<UUID, Long> invites = new HashMap<>();
private final String guildId, guildName, guildTag;
/**
* Owner changes when the old owner leaves guild
*/
private UUID owner;
private final Set<UUID> members = new HashSet<>();
public Guild(UUID owner, String name, String tag) {
this.owner = owner;
this.guildId = tag.toLowerCase();
this.guildName = name;
this.guildTag = tag;
}
/**
* Owner changes when the old owner leaves guild
*/
private UUID owner;
public UUID getOwner() {
return owner;
}
public String getName() {
return guildName;
}
public Guild(UUID owner, String name, String tag) {
this.owner = owner;
this.guildId = tag.toLowerCase();
this.guildName = name;
this.guildTag = tag;
}
public String getId() {
return guildId;
}
public String getTag() {
return guildTag;
}
public UUID getOwner() {
return owner;
}
public GuildMembers getMembers() {
return members;
}
public String getName() {
return guildName;
}
public long getLastInvite(Player player) {
return invites.containsKey(player.getUniqueId()) ? invites.get(player.getUniqueId()) : 0;
}
public String getId() {
return guildId;
}
public void removeLastInvite(Player player) {
invites.remove(player.getUniqueId());
}
public void removeMember(UUID uuid)
{ removeMember(uuid, false); }
// Disband boolean is to prevent co-modification exception when disbanding a guild
public void removeMember(UUID uuid, boolean disband) {
PlayerData data = PlayerData.get(uuid);
if (data != null && data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory)
InventoryManager.GUILD_CREATION.newInventory(data).open();
public String getTag() {
return guildTag;
}
if(!disband) members.remove(uuid);
if(data != null) data.setGuild(null);
reopenInventories();
public long getLastInvite(Player player) {
return invites.containsKey(player.getUniqueId()) ? invites.get(player.getUniqueId()) : 0;
}
//if(!disband) {
public void removeLastInvite(Player player) {
invites.remove(player.getUniqueId());
}
// disband the guild if no member left
if (members.count() < 1) {
MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(this);
return;
}
public void removeMember(UUID uuid) {
removeMember(uuid, false);
}
// transfer ownership
if (owner.equals(uuid)) {
owner = members.get(0);
MMOCore.plugin.configManager.getSimpleMessage("transfer-guild-ownership").send(Bukkit.getPlayer(owner));
}
//}
}
// Disband boolean is to prevent co-modification exception when disbanding a guild
public void removeMember(UUID uuid, boolean disband) {
PlayerData data = PlayerData.get(uuid);
if (data != null && data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory)
InventoryManager.GUILD_CREATION.newInventory(data).open();
public void addMember(UUID uuid) {
PlayerData data = PlayerData.get(uuid);
if (data.inGuild())
data.getGuild().removeMember(uuid);
if (!disband)
members.remove(uuid);
if (data != null)
data.setGuild(null);
reopenInventories();
data.setGuild(this);
members.add(uuid);
// Disband the guild if no member left
if (members.size() < 1) {
MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(this);
return;
}
reopenInventories();
}
public void registerMember(UUID uuid) {
members.add(uuid);
}
// Transfer ownership
if (owner.equals(uuid)) {
owner = members.stream().findAny().get();
MMOCore.plugin.configManager.getSimpleMessage("transfer-guild-ownership").send(Bukkit.getPlayer(owner));
}
}
public void reopenInventories() {
for (UUID uuid : members.members) {
PlayerData member = PlayerData.get(uuid);
if (member != null && member.isOnline() && member.getPlayer().getOpenInventory() != null && member.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory)
((PluginInventory) member.getPlayer().getOpenInventory().getTopInventory().getHolder()).open();
}
}
public void addMember(UUID uuid) {
PlayerData data = PlayerData.get(uuid);
if (data.inGuild())
data.getGuild().removeMember(uuid);
public void sendGuildInvite(PlayerData inviter, PlayerData target) {
invites.put(target.getUniqueId(), System.currentTimeMillis());
Request request = new GuildInvite(this, inviter, target);
new ConfigMessage("guild-invite").addPlaceholders("player", inviter.getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer());
MMOCore.plugin.requestManager.registerRequest(request);
}
public static class GuildMembers {
private final List<UUID> members = new ArrayList<>();
data.setGuild(this);
members.add(uuid);
public UUID get(int count) {
return members.get(count);
}
reopenInventories();
}
public boolean has(UUID player) {
return members.contains(player);
}
public void registerMember(UUID uuid) {
members.add(uuid);
}
public void add(UUID player) {
members.add(player);
}
public void reopenInventories() {
for (UUID uuid : members) {
PlayerData member = PlayerData.get(uuid);
if (member != null && member.isOnline() && member.getPlayer().getOpenInventory() != null && member.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory)
((PluginInventory) member.getPlayer().getOpenInventory().getTopInventory().getHolder()).open();
}
}
public void remove(UUID player) {
members.remove(player);
}
public void sendGuildInvite(PlayerData inviter, PlayerData target) {
invites.put(target.getUniqueId(), System.currentTimeMillis());
Request request = new GuildInvite(this, inviter, target);
new ConfigMessage("guild-invite").addPlaceholders("player", inviter.getPlayer().getName(), "uuid", request.getUniqueId().toString()).sendAsJSon(target.getPlayer());
MMOCore.plugin.requestManager.registerRequest(request);
}
public void forEach(Consumer<? super UUID> action) {
members.forEach(action);
}
@Override
public boolean hasMember(Player player) {
return hasMember(player.getUniqueId());
}
public int countOnline() {
int online = 0;
for(UUID member : members)
if(Bukkit.getOfflinePlayer(member).isOnline())
online += 1;
return online;
}
public boolean hasMember(UUID player) {
return members.contains(player);
}
public int count()
{ return members.size(); }
public void clear()
{ members.clear(); }
}
public List<UUID> listMembers() {
return new ArrayList<>(members);
}
public void forEachMember(Consumer<? super UUID> action) {
members.forEach(action);
}
public int countOnlineMembers() {
int online = 0;
for (UUID member : members)
if (Bukkit.getOfflinePlayer(member).isOnline())
online++;
return online;
}
public int countMembers() {
return members.size();
}
}

View File

@ -27,7 +27,7 @@ public class GuildInvite extends Request {
@Override
public void whenAccepted() {
guild.removeLastInvite(getCreator().getPlayer());
guild.getMembers().forEach(member -> {
guild.forEachMember(member -> {
if (Bukkit.getPlayer(member) != null) {
MMOCore.plugin.configManager.getSimpleMessage("guild-joined-other", "player",
getTarget().getPlayer().getName()).send(Bukkit.getPlayer(member));

View File

@ -32,7 +32,7 @@ public class GuildListener implements Listener {
GuildChatEvent called = new GuildChatEvent(data, format.message());
Bukkit.getPluginManager().callEvent(called);
if (!called.isCancelled())
data.getGuild().getMembers().forEach(member -> {
data.getGuild().forEachMember(member -> {
Player p = Bukkit.getPlayer(member);
if (p != null)
format.send(p);

View File

@ -197,7 +197,7 @@ public class FishingListener implements Listener {
location.getWorld().spawnParticle(Particle.FIREWORKS_SPARK, location, 0, 4 * (RANDOM.nextDouble() - .5), RANDOM.nextDouble() + 1, 4 * (RANDOM.nextDouble() - .5), .08);
if (MMOCore.plugin.fishingManager.hasLinkedProfession())
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location);
playerData.getCollectionSkills().giveExperience(MMOCore.plugin.fishingManager.getLinkedProfession(), experienceDropped, EXPSource.FISHING, location, true);
}
}
}

View File

@ -23,11 +23,12 @@ import java.util.logging.Level;
public class ConfigManager {
public final CommandVerbose commandVerbose = new CommandVerbose();
public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo;
public boolean overrideVanillaExp, canCreativeCast, cobbleGeneratorXP, saveDefaultClassInfo, attributesAsClassInfo;
public String partyChatPrefix, noSkillBoundPlaceholder;
public ChatColor staminaFull, staminaHalf, staminaEmpty;
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown;
public double lootChestsChanceWeight;
public int maxPartyLevelDifference;
private final FileConfiguration messages;
private final boolean chatInput;
@ -99,6 +100,7 @@ public class ConfigManager {
globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50;
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests");
maxPartyLevelDifference = MMOCore.plugin.getConfig().getInt("party.max-level-difference");
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);

View File

@ -41,6 +41,7 @@ public class MMOLoadManager {
return load(Objective.class, config, loader -> loader.loadObjective(config, section));
}
@Deprecated
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
return load(ExperienceSource.class, config, loader -> loader.loadExperienceSource(config, dispenser));
}

View File

@ -33,7 +33,7 @@ public abstract class GuildDataManager {
}
public void unregisterGuild(Guild guild) {
guild.getMembers().forEach(member -> guild.removeMember(member, true));
guild.forEachMember(member -> guild.removeMember(member, true));
// guild.getMembers().clear();
guilds.remove(guild.getId());
delete(guild);

View File

@ -22,7 +22,7 @@ public class YAMLGuildDataManager extends GuildDataManager {
config.getConfig().set("owner", guild.getOwner().toString());
List<String> memberList = new ArrayList<>();
guild.getMembers().forEach(uuid -> memberList.add(uuid.toString()));
guild.forEachMember(uuid -> memberList.add(uuid.toString()));
config.getConfig().set("members", memberList);
config.save();

View File

@ -47,7 +47,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
if (config.contains("guild")) {
Guild guild = provider.getGuildManager().getGuild(config.getString("guild"));
data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null);
data.setGuild(guild.hasMember(data.getUniqueId()) ? guild : null);
}
if (config.contains("attribute"))
data.getAttributes().load(config.getConfigurationSection("attribute"));

View File

@ -2,6 +2,7 @@ package net.Indyuce.mmocore.manager.social;
import net.Indyuce.mmocore.experience.Booster;
import net.Indyuce.mmocore.experience.Profession;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
@ -48,7 +49,7 @@ public class BoosterManager {
/**
* @return Sums all current experience boosters values
*/
public double getMultiplier(Profession profession) {
public double getMultiplier(@Nullable Profession profession) {
double d = 1;
for (Booster booster : map)
@ -58,10 +59,6 @@ public class BoosterManager {
return d;
}
public double calculateExp(Profession profession, double exp) {
return (exp * getMultiplier(profession));
}
/**
* @return Collection of currently registered boosters. Some of them can be
* expired but are not unregistered yet!

View File

@ -4,6 +4,7 @@ import io.lumine.mythic.lib.comp.target.InteractionType;
import io.lumine.mythic.lib.comp.target.TargetRestriction;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.guild.AbstractGuild;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -11,11 +12,21 @@ public class MMOCoreTargetRestriction implements TargetRestriction {
@Override
public boolean canTarget(Player player, LivingEntity livingEntity, InteractionType interactionType) {
if (!interactionType.isOffense() || !(livingEntity instanceof Player) || livingEntity.hasMetadata("NPC"))
if (!interactionType.isOffense() || !(livingEntity instanceof Player))
return true;
AbstractParty party = MMOCore.plugin.partyModule.getParty(PlayerData.get(player));
// TODO check for guild
return party == null || !party.hasMember((Player) livingEntity);
PlayerData data = PlayerData.get(player);
// Check for party
AbstractParty party = MMOCore.plugin.partyModule.getParty(data);
if (party != null && party.hasMember((Player) livingEntity))
return false;
// Check for guild
AbstractGuild guild = MMOCore.plugin.guildModule.getGuild(data);
if (guild != null && guild.hasMember((Player) livingEntity))
return false;
return true;
}
}

View File

@ -9,6 +9,7 @@ import net.Indyuce.mmocore.gui.social.party.EditablePartyView.PartyViewInventory
import net.Indyuce.mmocore.manager.InventoryManager;
import net.Indyuce.mmocore.party.AbstractParty;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.function.Consumer;
@ -25,13 +26,21 @@ public class Party implements AbstractParty {
/**
* Owner has to change when previous owner leaves party
*/
@NotNull
private PlayerData owner;
/**
* If the difference between a player level and the party
* level is too high then players cannot join the party.
*/
private final int partyLevel;
private final MMOCorePartyModule module;
public Party(MMOCorePartyModule module, PlayerData owner) {
this.owner = owner;
this.module = module;
this.partyLevel = owner.getLevel();
addMember(owner);
}
@ -59,6 +68,10 @@ public class Party implements AbstractParty {
return online;
}
public int getLevel() {
return partyLevel;
}
@Override
public int countMembers() {
return members.size();

View File

@ -59,14 +59,22 @@ protect-custom-mine: false
# - mcmmo
party-plugin: mmocore
## Edit the plugin handling parties here.
## Supported values (just copy and paste):
## - mmocore
## - beauty_quest
## - quest_creator
## - quests
# Edit the plugin handling parties here.
# Supported values (just copy and paste):
# - mmocore
# - beauty_quest
# - quest_creator
# - quests
quest-plugin: mmocore
# Edit the plugin handling guilds here.
# Supported values (just copy and paste):
# - mmocore
# - guilds
# - kingdomsx
# - ultimate_clans
guild-plugin: mmocore
# MythicLib introduces a CHANCE stat that is used in
# several different systems in MMOCore. By changing these
# weights you can define how much the Chance stat impacts
@ -135,10 +143,21 @@ party:
# to talk in the party chat.
chat-prefix: '@'
# The max players that can be in
# any given party. Between 2-8.
# The max amount of players in a party
# Has to be higher than 2
max-players: 8
# If the difference between a player's level and the
# initial party owner's level is higher that this
# value, then that player can't join the party.
#
# This prevents low level players from joining
# high level players and earning tons of EXP.
#
# Set to the max level possible if you want to disable
# that feature.
max-level-difference: 3
# Redirects vanilla experience obtained to MMOCore
# class experience. You can define the % of the vanilla
# experience that is being transfered as MMOCore exp.
@ -206,6 +225,11 @@ resource-bar-colors:
stamina-half: 'DARK_GREEN'
stamina-empty: 'WHITE'
# When set to true, attributes are saved and
# reset when a player changes their class.
# Not implemented yet.
# attributes-as-class-info: true
# Whether or not the admin commands should display
# the result of the command when ran.
# For Example: "Players Level is now 10."

View File

@ -118,6 +118,7 @@ party-joined-other: '&6{player}&e joined your party!'
transfer-party-ownership: '&eYou were transfered the party ownership.'
kick-from-party: '&eYou successfully kicked &6{player}&e.'
party-invite-cooldown: '&cPlease wait {cooldown} before inviting {player}.'
high-level-difference: '&cYou cannot invite {player} as the level difference is too high.'
# Guilds
guild-chat: '&a[{tag}] {player}: {message}'