mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
Guild module
This commit is contained in:
parent
ba2691daf2
commit
88da562ebd
@ -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;
|
||||
|
||||
@ -216,8 +221,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 +230,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 +241,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 {
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
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.UltimateClansGuildModule;
|
||||
import net.Indyuce.mmocore.guild.provided.MMOCoreGuildModule;
|
||||
@ -9,7 +8,8 @@ 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),
|
||||
MMOCORE("MMOCore", MMOCoreGuildModule::new),
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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")))
|
||||
|
@ -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();
|
||||
|
@ -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"));
|
||||
|
@ -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."
|
||||
|
Loading…
Reference in New Issue
Block a user