From 1aa7d96347c4f65c1cb4d8c0b922939c32c9f3f2 Mon Sep 17 00:00:00 2001 From: Jules Date: Sat, 18 Jun 2022 12:35:26 +0200 Subject: [PATCH] Option to prevent high party level difference --- .../gui/social/party/EditablePartyView.java | 7 +++++++ .../Indyuce/mmocore/manager/ConfigManager.java | 1 - .../net/Indyuce/mmocore/party/provided/Party.java | 13 +++++++++++++ src/main/resources/config.yml | 15 +++++++++++++-- src/main/resources/default/messages.yml | 1 + 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java index ce442cf2..aa93e292 100644 --- a/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java +++ b/src/main/java/net/Indyuce/mmocore/gui/social/party/EditablePartyView.java @@ -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); diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 2ecfc2ec..da56b890 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -99,7 +99,6 @@ 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); diff --git a/src/main/java/net/Indyuce/mmocore/party/provided/Party.java b/src/main/java/net/Indyuce/mmocore/party/provided/Party.java index 659906f1..218a830e 100644 --- a/src/main/java/net/Indyuce/mmocore/party/provided/Party.java +++ b/src/main/java/net/Indyuce/mmocore/party/provided/Party.java @@ -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(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index aadb32bf..e2fee491 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -143,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. diff --git a/src/main/resources/default/messages.yml b/src/main/resources/default/messages.yml index b311b6ba..8d1f7fb0 100644 --- a/src/main/resources/default/messages.yml +++ b/src/main/resources/default/messages.yml @@ -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}'