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,7 +51,6 @@ 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;
@ -99,6 +97,8 @@ public class MMOCore extends LuminePlugin {
// Modules
@NotNull
public PartyModule partyModule;
@NotNull
public GuildModule guildModule;
public boolean shouldDebugSQL = false;
public boolean hasBungee=false;
@ -255,6 +255,16 @@ 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 {
@ -392,7 +402,7 @@ public class MMOCore extends LuminePlugin {
* 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

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,20 +167,28 @@ 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;

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,29 +1,25 @@
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 Set<UUID> members = new HashSet<>();
/**
* Owner changes when the old owner leaves guild
*/
@ -52,10 +48,6 @@ public class Guild implements AbstractGuild {
return guildTag;
}
public GuildMembers getMembers() {
return members;
}
public long getLastInvite(Player player) {
return invites.containsKey(player.getUniqueId()) ? invites.get(player.getUniqueId()) : 0;
}
@ -64,8 +56,9 @@ public class Guild implements AbstractGuild {
invites.remove(player.getUniqueId());
}
public void removeMember(UUID uuid)
{ removeMember(uuid, false); }
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) {
@ -73,24 +66,23 @@ public class Guild implements AbstractGuild {
if (data != null && data.isOnline() && data.getPlayer().getOpenInventory() != null && data.getPlayer().getOpenInventory().getTopInventory().getHolder() instanceof GuildViewInventory)
InventoryManager.GUILD_CREATION.newInventory(data).open();
if(!disband) members.remove(uuid);
if(data != null) data.setGuild(null);
if (!disband)
members.remove(uuid);
if (data != null)
data.setGuild(null);
reopenInventories();
//if(!disband) {
// disband the guild if no member left
if (members.count() < 1) {
// Disband the guild if no member left
if (members.size() < 1) {
MMOCore.plugin.dataProvider.getGuildManager().unregisterGuild(this);
return;
}
// transfer ownership
// Transfer ownership
if (owner.equals(uuid)) {
owner = members.get(0);
owner = members.stream().findAny().get();
MMOCore.plugin.configManager.getSimpleMessage("transfer-guild-ownership").send(Bukkit.getPlayer(owner));
}
//}
}
public void addMember(UUID uuid) {
@ -109,7 +101,7 @@ public class Guild implements AbstractGuild {
}
public void reopenInventories() {
for (UUID uuid : members.members) {
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();
@ -123,42 +115,34 @@ public class Guild implements AbstractGuild {
MMOCore.plugin.requestManager.registerRequest(request);
}
public static class GuildMembers {
private final List<UUID> members = new ArrayList<>();
public UUID get(int count) {
return members.get(count);
@Override
public boolean hasMember(Player player) {
return hasMember(player.getUniqueId());
}
public boolean has(UUID player) {
public boolean hasMember(UUID player) {
return members.contains(player);
}
public void add(UUID player) {
members.add(player);
public List<UUID> listMembers() {
return new ArrayList<>(members);
}
public void remove(UUID player) {
members.remove(player);
}
public void forEach(Consumer<? super UUID> action) {
public void forEachMember(Consumer<? super UUID> action) {
members.forEach(action);
}
public int countOnline() {
public int countOnlineMembers() {
int online = 0;
for (UUID member : members)
if (Bukkit.getOfflinePlayer(member).isOnline())
online += 1;
online++;
return online;
}
public int count()
{ return members.size(); }
public void clear()
{ members.clear(); }
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}'