Merge remote-tracking branch 'origin/master'

This commit is contained in:
Jules 2022-06-18 12:34:53 +02:00
commit 0b344e7704
28 changed files with 314 additions and 219 deletions

View File

@ -25,7 +25,10 @@ import net.Indyuce.mmocore.comp.region.WorldGuardMMOLoader;
import net.Indyuce.mmocore.comp.region.WorldGuardRegionHandler;
import net.Indyuce.mmocore.comp.vault.VaultEconomy;
import net.Indyuce.mmocore.comp.vault.VaultMMOLoader;
import net.Indyuce.mmocore.guild.GuildModule;
import net.Indyuce.mmocore.guild.GuildModuleType;
import net.Indyuce.mmocore.guild.provided.Guild;
import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule;
import net.Indyuce.mmocore.listener.*;
import net.Indyuce.mmocore.listener.event.PlayerPressKeyListener;
import net.Indyuce.mmocore.listener.option.*;
@ -97,6 +100,8 @@ public class MMOCore extends LuminePlugin {
// Modules
@NotNull
public PartyModule partyModule;
@NotNull
public GuildModule guildModule;
public boolean shouldDebugSQL = false;
@ -119,7 +124,6 @@ public class MMOCore extends LuminePlugin {
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());
@ -216,8 +220,8 @@ public class MMOCore extends LuminePlugin {
// Load quest module
try {
String questPluginName = UtilityMethods.enumName(getConfig().getString("quest-plugin"));
PartyModuleType moduleType = PartyModuleType.valueOf(questPluginName);
String pluginName = UtilityMethods.enumName(getConfig().getString("quest-plugin"));
PartyModuleType moduleType = PartyModuleType.valueOf(pluginName);
Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed");
partyModule = moduleType.provideModule();
} catch (RuntimeException exception) {
@ -225,12 +229,10 @@ public class MMOCore extends LuminePlugin {
partyModule = new MMOCorePartyModule();
}
// Load party module
try {
String partyPluginName = UtilityMethods.enumName(getConfig().getString("party-plugin"));
PartyModuleType moduleType = PartyModuleType.valueOf(partyPluginName);
String pluginName = UtilityMethods.enumName(getConfig().getString("party-plugin"));
PartyModuleType moduleType = PartyModuleType.valueOf(pluginName);
Validate.isTrue(moduleType.isValid(), "Plugin '" + moduleType.name() + "' is not installed");
partyModule = moduleType.provideModule();
} catch (RuntimeException exception) {
@ -238,6 +240,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 {

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

@ -540,18 +540,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())

View File

@ -23,9 +23,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 {

View File

@ -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", "" + value).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

@ -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

@ -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;
for (UUID member : members)
if (Bukkit.getOfflinePlayer(member).isOnline())
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,7 +23,7 @@ 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;
@ -99,6 +99,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");
attributesAsClassInfo = MMOCore.plugin.getConfig().getBoolean("attributes-as-class-info");
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);

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

@ -71,7 +71,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
if (!isEmpty(result.getString("guild"))) {
Guild guild = provider.getGuildManager().getGuild(result.getString("guild"));
data.setGuild(guild.getMembers().has(data.getUniqueId()) ? guild : null);
data.setGuild(guild.hasMember(data.getUniqueId()) ? guild : null);
}
if (!isEmpty(result.getString("attributes"))) data.getAttributes().load(result.getString("attributes"));
if (!isEmpty(result.getString("professions")))

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

@ -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
@ -206,6 +214,10 @@ 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.
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."