formatting applied to most of the source code to tidy things up, and misc refactors

This commit is contained in:
nossr50
2025-07-03 14:03:43 -07:00
parent f322d05159
commit e52371aeb3
440 changed files with 11762 additions and 7365 deletions

View File

@@ -3252,7 +3252,7 @@ Version 1.5.01
= Fixed bug where pistons would mess with the block tracking
= Fixed bug where the Updater was running on the main thread.
= Fixed bug when players would use /ptp without being in a party
= Fixed bug where player didn't have a mcMMOPlayer object in AsyncPlayerChatEvent
= Fixed bug where player didn't have a mmoPlayer object in AsyncPlayerChatEvent
= Fixed bug where dodge would check the wrong player skill level
= Fixed bug which causes /party teleport to stop working
= Fixed bug where SaveTimerTask would produce an IndexOutOfBoundsException

View File

@@ -14,7 +14,7 @@
<properties>
<!-- <spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>-->
<spigot.version>1.21.6-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.21.7-R0.1-SNAPSHOT</spigot.version>
<kyori.adventure.version>4.23.0</kyori.adventure.version>
<kyori.adventure.platform.version>4.4.1-SNAPSHOT</kyori.adventure.platform.version>
<kyori.option.version>1.1.0</kyori.option.version>
@@ -100,13 +100,11 @@
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<junitArtifactName>org.junit.jupiter:junit-jupiter</junitArtifactName>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>

View File

@@ -8,7 +8,8 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
public final class AbilityAPI {
private AbilityAPI() {}
private AbilityAPI() {
}
public static boolean berserkEnabled(Player player) {
return UserManager.getPlayer(player).getAbilityMode(SuperAbilityType.BERSERK);
@@ -39,10 +40,10 @@ public final class AbilityAPI {
}
public static boolean isAnyAbilityEnabled(Player player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
for (SuperAbilityType ability : SuperAbilityType.values()) {
if (mcMMOPlayer.getAbilityMode(ability)) {
if (mmoPlayer.getAbilityMode(ability)) {
return true;
}
}
@@ -84,9 +85,7 @@ public final class AbilityAPI {
public static boolean isBleeding(LivingEntity entity) {
if (entity.isValid()) {
if (entity.hasMetadata(MetadataConstants.METADATA_KEY_RUPTURE)) {
return true;
}
return entity.hasMetadata(MetadataConstants.METADATA_KEY_RUPTURE);
}
return false;

View File

@@ -6,63 +6,8 @@ import com.gmail.nossr50.util.player.UserManager;
import org.bukkit.entity.Player;
public final class ChatAPI {
private ChatAPI() {}
// /**
// * Send a message to all members of a party
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender
// * @param displayName The display name of the sender
// * @param party The name of the party to send to
// * @param message The message to send
// */
// public static void sendPartyChat(Plugin plugin, String sender, String displayName, String party, String message) {
// getPartyChatManager(plugin, party).handleChat(sender, displayName, message);
// }
//
// /**
// * Send a message to all members of a party
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender to display in the chat
// * @param party The name of the party to send to
// * @param message The message to send
// */
// public static void sendPartyChat(Plugin plugin, String sender, String party, String message) {
// getPartyChatManager(plugin, party).handleChat(sender, message);
// }
//
// /**
// * Send a message to administrators
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender
// * @param displayName The display name of the sender
// * @param message The message to send
// */
// public static void sendAdminChat(Plugin plugin, String sender, String displayName, String message) {
// ChatManagerFactory.getChatManager(plugin, ChatChannel.ADMIN).handleChat(sender, displayName, message);
// }
//
// /**
// * Send a message to administrators
// * </br>
// * This function is designed for API usage.
// *
// * @param plugin The plugin sending the message
// * @param sender The name of the sender to display in the chat
// * @param message The message to send
// */
// public static void sendAdminChat(Plugin plugin, String sender, String message) {
// ChatManagerFactory.getChatManager(plugin, ChatChannel.ADMIN).handleChat(sender, message);
// }
private ChatAPI() {
}
/**
* Check if a player is currently talking in party chat.
@@ -110,7 +55,8 @@ public final class ChatAPI {
* @param player The player to toggle party chat on.
*/
public static void togglePartyChat(Player player) {
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(player), ChatChannel.PARTY);
mcMMO.p.getChatManager()
.setOrToggleChatChannel(UserManager.getPlayer(player), ChatChannel.PARTY);
}
/**
@@ -119,7 +65,8 @@ public final class ChatAPI {
* @param playerName The name of the player to toggle party chat on.
*/
public static void togglePartyChat(String playerName) {
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(playerName), ChatChannel.PARTY);
mcMMO.p.getChatManager()
.setOrToggleChatChannel(UserManager.getPlayer(playerName), ChatChannel.PARTY);
}
/**
@@ -128,7 +75,8 @@ public final class ChatAPI {
* @param player The player to toggle admin chat on.
*/
public static void toggleAdminChat(Player player) {
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(player), ChatChannel.ADMIN);
mcMMO.p.getChatManager()
.setOrToggleChatChannel(UserManager.getPlayer(player), ChatChannel.ADMIN);
}
/**
@@ -137,6 +85,7 @@ public final class ChatAPI {
* @param playerName The name of the player to toggle party chat on.
*/
public static void toggleAdminChat(String playerName) {
mcMMO.p.getChatManager().setOrToggleChatChannel(UserManager.getPlayer(playerName), ChatChannel.ADMIN);
mcMMO.p.getChatManager()
.setOrToggleChatChannel(UserManager.getPlayer(playerName), ChatChannel.ADMIN);
}
}

View File

@@ -2,15 +2,17 @@ package com.gmail.nossr50.api;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.mcMMO;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class DatabaseAPI {
private DatabaseAPI() {
}
/**
* Checks if a player exists in the mcMMO Database
*
* @param offlinePlayer target player
* @return true if the player exists in the DB, false if they do not
*/
@@ -22,6 +24,7 @@ public class DatabaseAPI {
/**
* Checks if a player exists in the mcMMO Database
*
* @param uuid target player
* @return true if the player exists in the DB, false if they do not
*/
@@ -38,6 +41,7 @@ public class DatabaseAPI {
/**
* Checks if a player exists in the mcMMO Database
*
* @param playerName target player
* @return true if the player exists in the DB, false if they do not
*/

View File

@@ -1,10 +1,17 @@
package com.gmail.nossr50.api;
import com.gmail.nossr50.api.exceptions.*;
import static com.gmail.nossr50.datatypes.experience.XPGainReason.PVE;
import static com.gmail.nossr50.datatypes.experience.XPGainSource.CUSTOM;
import static com.gmail.nossr50.datatypes.experience.XPGainSource.SELF;
import com.gmail.nossr50.api.exceptions.InvalidFormulaTypeException;
import com.gmail.nossr50.api.exceptions.InvalidPlayerException;
import com.gmail.nossr50.api.exceptions.InvalidSkillException;
import com.gmail.nossr50.api.exceptions.InvalidXPGainReasonException;
import com.gmail.nossr50.api.exceptions.McMMOPlayerNotFoundException;
import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.experience.XPGainReason;
import com.gmail.nossr50.datatypes.experience.XPGainSource;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
@@ -12,21 +19,21 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillTools;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.UUID;
public final class ExperienceAPI {
private ExperienceAPI() {}
private ExperienceAPI() {
}
/**
* Returns whether given string is a valid type of skill suitable for the
* other API calls in this class.
* Returns whether given string is a valid type of skill suitable for the other API calls in
* this class.
* </br>
* This function is designed for API usage.
*
@@ -38,38 +45,40 @@ public final class ExperienceAPI {
}
/**
* Start the task that gives combat XP.
* Processes combat XP like mcMMO normally would, so mcMMO will check whether the entity should reward XP when giving out the XP
* Start the task that gives combat XP. Processes combat XP like mcMMO normally would, so mcMMO
* will check whether the entity should reward XP when giving out the XP
*
* @param mcMMOPlayer The attacking player
* @param mmoPlayer The attacking player
* @param target The defending entity
* @param primarySkillType The skill being used
* @param multiplier final XP result will be multiplied by this
* @deprecated Draft API
*/
@Deprecated
public static void addCombatXP(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType, double multiplier) {
CombatUtils.processCombatXP(mcMMOPlayer, target, primarySkillType, multiplier);
public static void addCombatXP(McMMOPlayer mmoPlayer, LivingEntity target,
PrimarySkillType primarySkillType,
double multiplier) {
CombatUtils.processCombatXP(mmoPlayer, target, primarySkillType, multiplier);
}
/**
* Start the task that gives combat XP.
* Processes combat XP like mcMMO normally would, so mcMMO will check whether the entity should reward XP when giving out the XP
* Start the task that gives combat XP. Processes combat XP like mcMMO normally would, so mcMMO
* will check whether the entity should reward XP when giving out the XP
*
* @param mcMMOPlayer The attacking player
* @param mmoPlayer The attacking player
* @param target The defending entity
* @param primarySkillType The skill being used
* @deprecated Draft API
*/
@Deprecated
public static void addCombatXP(McMMOPlayer mcMMOPlayer, LivingEntity target, PrimarySkillType primarySkillType) {
CombatUtils.processCombatXP(mcMMOPlayer, target, primarySkillType);
public static void addCombatXP(McMMOPlayer mmoPlayer, LivingEntity target,
PrimarySkillType primarySkillType) {
CombatUtils.processCombatXP(mmoPlayer, target, primarySkillType);
}
/**
* Returns whether the given skill type string is both valid and not a
* child skill. (Child skills have no XP of their own, and their level is
* derived from the parent(s).)
* Returns whether the given skill type string is both valid and not a child skill. (Child
* skills have no XP of their own, and their level is derived from the parent(s).)
* </br>
* This function is designed for API usage.
*
@@ -77,7 +86,7 @@ public final class ExperienceAPI {
* @return true if this is a valid, non-child mcMMO skill
*/
public static boolean isNonChildSkill(String skillType) {
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
final PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
return skill != null && !SkillTools.isChildSkill(skill);
}
@@ -95,7 +104,6 @@ public final class ExperienceAPI {
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
*/
@Deprecated
@@ -112,7 +120,6 @@ public final class ExperienceAPI {
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
@@ -130,17 +137,19 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason, boolean isUnshared) {
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason,
boolean isUnshared) {
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP,
getXPGainReason(xpGainReason), CUSTOM);
return;
}
getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason),
CUSTOM);
}
/**
@@ -148,8 +157,8 @@ public final class ExperienceAPI {
* </br>
* This function is designed for API usage.
*
* @deprecated We're using float for our XP values now
* replaced by {@link #addRawXPOffline(String playerName, String skillType, float XP)}
* @deprecated We're using float for our XP values now replaced by
* {@link #addRawXPOffline(String playerName, String skillType, float XP)}
*/
@Deprecated
public static void addRawXPOffline(String playerName, String skillType, int XP) {
@@ -161,15 +170,13 @@ public final class ExperienceAPI {
* </br>
* This function is designed for API usage.
*
* @deprecated We're using uuids to get an offline player
* replaced by {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
*
* @param playerName The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @deprecated We're using uuids to get an offline player replaced by
* {@link #addRawXPOffline(UUID uuid, String skillType, float XP)}
*/
@Deprecated
public static void addRawXPOffline(String playerName, String skillType, float XP) {
@@ -184,7 +191,6 @@ public final class ExperienceAPI {
* @param uuid The UUID of player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@@ -200,7 +206,6 @@ public final class ExperienceAPI {
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
*/
@Deprecated
@@ -217,12 +222,15 @@ public final class ExperienceAPI {
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addMultipliedXP(Player player, String skillType, int XP, String xpGainReason) {
getPlayer(player).applyXpGain(getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
public static void addMultipliedXP(Player player, String skillType, int XP,
String xpGainReason) {
getPlayer(player).applyXpGain(
getSkillType(skillType),
(int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()),
getXPGainReason(xpGainReason), CUSTOM);
}
/**
@@ -233,13 +241,14 @@ public final class ExperienceAPI {
* @param playerName The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static void addMultipliedXPOffline(String playerName, String skillType, int XP) {
addOfflineXP(playerName, getSkillType(skillType), (int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
addOfflineXP(
playerName, getSkillType(skillType),
(int) (XP * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
}
/**
@@ -250,7 +259,6 @@ public final class ExperienceAPI {
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
*/
@Deprecated
@@ -267,7 +275,6 @@ public final class ExperienceAPI {
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
@@ -285,20 +292,26 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
PrimarySkillType skill = getSkillType(skillType);
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason,
boolean isUnshared) {
final PrimarySkillType skill = getSkillType(skillType);
final ExperienceConfig expConf = ExperienceConfig.getInstance();
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(skill,
(int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginUnsharedXpGain(
skill, (int) (XP / expConf.getFormulaSkillModifier(
skill) * expConf.getExperienceGainsGlobalMultiplier()),
getXPGainReason(xpGainReason), CUSTOM);
return;
}
getPlayer(player).applyXpGain(skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).applyXpGain(
skill, (int) (XP / expConf.getFormulaSkillModifier(
skill) * expConf.getExperienceGainsGlobalMultiplier()),
getXPGainReason(xpGainReason), CUSTOM);
}
/**
@@ -309,27 +322,29 @@ public final class ExperienceAPI {
* @param playerName The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static void addModifiedXPOffline(String playerName, String skillType, int XP) {
PrimarySkillType skill = getSkillType(skillType);
final PrimarySkillType skill = getSkillType(skillType);
addOfflineXP(playerName, skill, (int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(skill) * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()));
addOfflineXP(
playerName, skill,
(int) (XP / ExperienceConfig.getInstance().getFormulaSkillModifier(
skill) * ExperienceConfig.getInstance()
.getExperienceGainsGlobalMultiplier()));
}
/**
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
* and party sharing.
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills, and
* party sharing.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
*
* @throws InvalidSkillException if the given skill is not valid
*/
@Deprecated
@@ -338,8 +353,8 @@ public final class ExperienceAPI {
}
/**
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
* and party sharing.
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills, and
* party sharing.
* </br>
* This function is designed for API usage.
*
@@ -347,7 +362,6 @@ public final class ExperienceAPI {
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
@@ -356,8 +370,8 @@ public final class ExperienceAPI {
}
/**
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
* and party sharing.
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills, and
* party sharing.
* </br>
* This function is designed for API usage.
*
@@ -366,17 +380,19 @@ public final class ExperienceAPI {
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
public static void addXP(Player player, String skillType, int XP, String xpGainReason,
boolean isUnshared) {
if (isUnshared) {
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP,
getXPGainReason(xpGainReason), CUSTOM);
return;
}
getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason), XPGainSource.CUSTOM);
getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason),
CUSTOM);
}
/**
@@ -387,7 +403,6 @@ public final class ExperienceAPI {
* @param player The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws UnsupportedOperationException if the given skill is a child skill
*/
@@ -403,7 +418,6 @@ public final class ExperienceAPI {
* @param playerName The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -421,7 +435,6 @@ public final class ExperienceAPI {
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -438,12 +451,12 @@ public final class ExperienceAPI {
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXP(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType) throws InvalidPlayerException {
public static int getOfflineXP(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType)
throws InvalidPlayerException {
return getOfflineProfile(offlinePlayer).getSkillXpLevel(getNonChildSkillType(skillType));
}
@@ -455,7 +468,6 @@ public final class ExperienceAPI {
* @param player The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws UnsupportedOperationException if the given skill is a child skill
*/
@@ -471,7 +483,6 @@ public final class ExperienceAPI {
* @param playerName The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -489,7 +500,6 @@ public final class ExperienceAPI {
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -506,18 +516,22 @@ public final class ExperienceAPI {
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP in a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRaw(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType) throws InvalidPlayerException, UnsupportedOperationException, InvalidSkillException {
public static float getOfflineXPRaw(@NotNull OfflinePlayer offlinePlayer,
@NotNull String skillType)
throws InvalidPlayerException, UnsupportedOperationException, InvalidSkillException {
return getOfflineProfile(offlinePlayer).getSkillXpLevelRaw(getNonChildSkillType(skillType));
}
public static float getOfflineXPRaw(@NotNull OfflinePlayer offlinePlayer, @NotNull PrimarySkillType skillType) throws InvalidPlayerException, UnsupportedOperationException {
if (SkillTools.isChildSkill(skillType))
public static float getOfflineXPRaw(@NotNull OfflinePlayer offlinePlayer,
@NotNull PrimarySkillType skillType)
throws InvalidPlayerException, UnsupportedOperationException {
if (SkillTools.isChildSkill(skillType)) {
throw new UnsupportedOperationException();
}
return getOfflineProfile(offlinePlayer).getSkillXpLevelRaw(skillType);
}
@@ -530,7 +544,6 @@ public final class ExperienceAPI {
* @param player The player to get the XP amount for
* @param skillType The skill to get the XP amount for
* @return the total amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws UnsupportedOperationException if the given skill is a child skill
*/
@@ -546,7 +559,6 @@ public final class ExperienceAPI {
* @param playerName The player to get XP for
* @param skillType The skill to get XP for
* @return the total amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -564,7 +576,6 @@ public final class ExperienceAPI {
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the total amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -581,12 +592,13 @@ public final class ExperienceAPI {
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the total amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getOfflineXPToNextLevel(@NotNull OfflinePlayer offlinePlayer, @NotNull String skillType) throws UnsupportedOperationException, InvalidSkillException, InvalidPlayerException {
public static int getOfflineXPToNextLevel(@NotNull OfflinePlayer offlinePlayer,
@NotNull String skillType)
throws UnsupportedOperationException, InvalidSkillException, InvalidPlayerException {
return getOfflineProfile(offlinePlayer).getXpToLevel(getNonChildSkillType(skillType));
}
@@ -598,14 +610,13 @@ public final class ExperienceAPI {
* @param player The player to get the XP amount for
* @param skillType The skill to get the XP amount for
* @return the amount of XP remaining until the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static int getXPRemaining(Player player, String skillType) {
PrimarySkillType skill = getNonChildSkillType(skillType);
final PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getPlayer(player).getProfile();
final PlayerProfile profile = getPlayer(player).getProfile();
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
}
@@ -618,15 +629,14 @@ public final class ExperienceAPI {
* @param playerName The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
@Deprecated
public static int getOfflineXPRemaining(String playerName, String skillType) {
PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(playerName);
final PrimarySkillType skill = getNonChildSkillType(skillType);
final PlayerProfile profile = getOfflineProfile(playerName);
return profile.getXpToLevel(skill) - profile.getSkillXpLevel(skill);
}
@@ -639,14 +649,13 @@ public final class ExperienceAPI {
* @param uuid The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRemaining(UUID uuid, String skillType) {
PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(uuid);
final PrimarySkillType skill = getNonChildSkillType(skillType);
final PlayerProfile profile = getOfflineProfile(uuid);
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
}
@@ -659,14 +668,14 @@ public final class ExperienceAPI {
* @param offlinePlayer The player to get XP for
* @param skillType The skill to get XP for
* @return the amount of XP needed to reach the next level
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*/
public static float getOfflineXPRemaining(OfflinePlayer offlinePlayer, String skillType) throws InvalidSkillException, InvalidPlayerException, UnsupportedOperationException {
PrimarySkillType skill = getNonChildSkillType(skillType);
PlayerProfile profile = getOfflineProfile(offlinePlayer);
public static float getOfflineXPRemaining(OfflinePlayer offlinePlayer, String skillType)
throws InvalidSkillException, InvalidPlayerException, UnsupportedOperationException {
final PrimarySkillType skill = getNonChildSkillType(skillType);
final PlayerProfile profile = getOfflineProfile(offlinePlayer);
return profile.getXpToLevel(skill) - profile.getSkillXpLevelRaw(skill);
}
@@ -679,7 +688,6 @@ public final class ExperienceAPI {
* @param player The player to add levels to
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add
*
* @throws InvalidSkillException if the given skill is not valid
*/
public static void addLevel(Player player, String skillType, int levels) {
@@ -694,14 +702,13 @@ public final class ExperienceAPI {
* @param playerName The player to add levels to
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static void addLevelOffline(String playerName, String skillType, int levels) {
PlayerProfile profile = getOfflineProfile(playerName);
PrimarySkillType skill = getSkillType(skillType);
final PlayerProfile profile = getOfflineProfile(playerName);
final PrimarySkillType skill = getSkillType(skillType);
if (SkillTools.isChildSkill(skill)) {
var parentSkills = mcMMO.p.getSkillTools().getChildSkillParents(skill);
@@ -726,13 +733,12 @@ public final class ExperienceAPI {
* @param uuid The player to add levels to
* @param skillType Type of skill to add levels to
* @param levels Number of levels to add
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static void addLevelOffline(UUID uuid, String skillType, int levels) {
PlayerProfile profile = getOfflineProfile(uuid);
PrimarySkillType skill = getSkillType(skillType);
final PlayerProfile profile = getOfflineProfile(uuid);
final PrimarySkillType skill = getSkillType(skillType);
if (SkillTools.isChildSkill(skill)) {
var parentSkills = mcMMO.p.getSkillTools().getChildSkillParents(skill);
@@ -757,7 +763,6 @@ public final class ExperienceAPI {
* @param player The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @deprecated Use getLevel(Player player, PrimarySkillType skillType) instead
*/
@@ -774,7 +779,6 @@ public final class ExperienceAPI {
* @param player The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
*
* @throws InvalidSkillException if the given skill is not valid
*/
public static int getLevel(Player player, PrimarySkillType skillType) {
@@ -789,7 +793,6 @@ public final class ExperienceAPI {
* @param playerName The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@@ -805,7 +808,6 @@ public final class ExperienceAPI {
* @param uuid The player to get the level for
* @param skillType The skill to get the level for
* @return the level of a given skill
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@@ -832,13 +834,12 @@ public final class ExperienceAPI {
*
* @param playerName The player to get the power level for
* @return the power level of the player
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static int getPowerLevelOffline(String playerName) {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(playerName);
final PlayerProfile profile = getOfflineProfile(playerName);
for (PrimarySkillType type : SkillTools.NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
@@ -854,12 +855,11 @@ public final class ExperienceAPI {
*
* @param uuid The player to get the power level for
* @return the power level of the player
*
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static int getPowerLevelOffline(UUID uuid) {
int powerLevel = 0;
PlayerProfile profile = getOfflineProfile(uuid);
final PlayerProfile profile = getOfflineProfile(uuid);
for (PrimarySkillType type : SkillTools.NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(type);
@@ -875,7 +875,6 @@ public final class ExperienceAPI {
*
* @param skillType The skill to get the level cap for
* @return the level cap of a given skill
*
* @throws InvalidSkillException if the given skill is not valid
*/
public static int getLevelCap(String skillType) {
@@ -900,16 +899,16 @@ public final class ExperienceAPI {
*
* @param playerName The name of the player to check
* @param skillType The skill to check
*
* @return the position on the leaderboard
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*
* @return the position on the leaderboard
*/
@Deprecated
public static int getPlayerRankSkill(String playerName, String skillType) {
return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(getNonChildSkillType(skillType));
return mcMMO.getDatabaseManager()
.readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(
getNonChildSkillType(skillType));
}
/**
@@ -919,15 +918,15 @@ public final class ExperienceAPI {
*
* @param uuid The name of the player to check
* @param skillType The skill to check
*
* @return the position on the leaderboard
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
*
* @return the position on the leaderboard
*/
public static int getPlayerRankSkill(UUID uuid, String skillType) {
return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(getNonChildSkillType(skillType));
return mcMMO.getDatabaseManager()
.readRank(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(
getNonChildSkillType(skillType));
}
/**
@@ -936,14 +935,14 @@ public final class ExperienceAPI {
* This function is designed for API usage.
*
* @param playerName The name of the player to check
*
* @throws InvalidPlayerException if the given player does not exist in the database
*
* @return the position on the power level leaderboard
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@Deprecated
public static int getPlayerRankOverall(String playerName) {
return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(null);
return mcMMO.getDatabaseManager()
.readRank(mcMMO.p.getServer().getOfflinePlayer(playerName).getName()).get(
null);
}
/**
@@ -952,13 +951,12 @@ public final class ExperienceAPI {
* This function is designed for API usage.
*
* @param uuid The name of the player to check
*
* @throws InvalidPlayerException if the given player does not exist in the database
*
* @return the position on the power level leaderboard
* @throws InvalidPlayerException if the given player does not exist in the database
*/
public static int getPlayerRankOverall(UUID uuid) {
return mcMMO.getDatabaseManager().readRank(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(null);
return mcMMO.getDatabaseManager()
.readRank(mcMMO.p.getServer().getOfflinePlayer(uuid).getName()).get(null);
}
/**
@@ -969,7 +967,6 @@ public final class ExperienceAPI {
* @param player The player to set the level of
* @param skillType The skill to set the level for
* @param skillLevel The value to set the level to
*
* @throws InvalidSkillException if the given skill is not valid
*/
public static void setLevel(Player player, String skillType, int skillLevel) {
@@ -984,7 +981,6 @@ public final class ExperienceAPI {
* @param playerName The player to set the level of
* @param skillType The skill to set the level for
* @param skillLevel The value to set the level to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@@ -1001,7 +997,6 @@ public final class ExperienceAPI {
* @param uuid The player to set the level of
* @param skillType The skill to set the level for
* @param skillLevel The value to set the level to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
*/
@@ -1017,7 +1012,6 @@ public final class ExperienceAPI {
* @param player The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws UnsupportedOperationException if the given skill is a child skill
*/
@@ -1033,7 +1027,6 @@ public final class ExperienceAPI {
* @param playerName The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -1051,7 +1044,6 @@ public final class ExperienceAPI {
* @param uuid The player to set the XP of
* @param skillType The skill to set the XP for
* @param newValue The value to set the XP to
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -1068,7 +1060,6 @@ public final class ExperienceAPI {
* @param player The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*
* @throws InvalidSkillException if the given skill is not valid
* @throws UnsupportedOperationException if the given skill is a child skill
*/
@@ -1084,7 +1075,6 @@ public final class ExperienceAPI {
* @param playerName The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -1102,7 +1092,6 @@ public final class ExperienceAPI {
* @param uuid The player to change the XP of
* @param skillType The skill to change the XP for
* @param xp The amount of XP to remove
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidPlayerException if the given player does not exist in the database
* @throws UnsupportedOperationException if the given skill is a child skill
@@ -1117,11 +1106,11 @@ public final class ExperienceAPI {
* This function is designed for API usage.
*
* @param level The level to get the amount of XP for
*
* @throws InvalidFormulaTypeException if the given formulaType is not valid
*/
public static int getXpNeededToLevel(int level) {
return mcMMO.getFormulaManager().getXPtoNextLevel(level, ExperienceConfig.getInstance().getFormulaType());
return mcMMO.getFormulaManager()
.getXPtoNextLevel(level, ExperienceConfig.getInstance().getFormulaType());
}
/**
@@ -1131,7 +1120,6 @@ public final class ExperienceAPI {
*
* @param level The level to get the amount of XP for
* @param formulaType The formula type to get the amount of XP for
*
* @throws InvalidFormulaTypeException if the given formulaType is not valid
*/
public static int getXpNeededToLevel(int level, String formulaType) {
@@ -1139,82 +1127,102 @@ public final class ExperienceAPI {
}
/**
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
* Will add the appropriate type of XP from the block to the player based on the material of the
* blocks given
*
* @param blockStates the blocks to reward XP for
* @param mcMMOPlayer the target player
* @param mmoPlayer the target player
*/
public static void addXpFromBlocks(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer) {
for(BlockState bs : blockStates) {
for(PrimarySkillType skillType : PrimarySkillType.values()) {
public static void addXpFromBlocks(ArrayList<BlockState> blockStates, McMMOPlayer mmoPlayer) {
for (BlockState bs : blockStates) {
for (PrimarySkillType skillType : PrimarySkillType.values()) {
if (ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()), XPGainReason.PVE, XPGainSource.SELF);
mmoPlayer.applyXpGain(
skillType,
ExperienceConfig.getInstance().getXp(skillType, bs.getType()), PVE,
SELF);
}
}
}
}
/**
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
* if it matches the given skillType
* Will add the appropriate type of XP from the block to the player based on the material of the
* blocks given if it matches the given skillType
*
* @param blockStates the blocks to reward XP for
* @param mcMMOPlayer the target player
* @param mmoPlayer the target player
* @param skillType target primary skill
*/
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates, McMMOPlayer mcMMOPlayer,
PrimarySkillType skillType) {
for(BlockState bs : blockStates) {
public static void addXpFromBlocksBySkill(ArrayList<BlockState> blockStates,
McMMOPlayer mmoPlayer,
PrimarySkillType skillType) {
for (BlockState bs : blockStates) {
if (ExperienceConfig.getInstance().getXp(skillType, bs.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType,
ExperienceConfig.getInstance().getXp(skillType, bs.getType()),
XPGainReason.PVE, XPGainSource.SELF);
mmoPlayer.applyXpGain(
skillType, ExperienceConfig.getInstance().getXp(skillType, bs.getType()),
PVE,
SELF);
}
}
}
/**
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given
* Will add the appropriate type of XP from the block to the player based on the material of the
* blocks given
*
* @param blockState The target blockstate
* @param mcMMOPlayer The target player
* @param mmoPlayer The target player
*/
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mcMMOPlayer) {
for(PrimarySkillType skillType : PrimarySkillType.values()) {
public static void addXpFromBlock(BlockState blockState, McMMOPlayer mmoPlayer) {
for (PrimarySkillType skillType : PrimarySkillType.values()) {
if (ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(
skillType, blockState.getType()), XPGainReason.PVE, XPGainSource.SELF);
mmoPlayer.applyXpGain(
skillType,
ExperienceConfig.getInstance().getXp(skillType, blockState.getType()),
PVE, SELF);
}
}
}
/**
* Will add the appropriate type of XP from the block to the player based on the material of the blocks given if it matches the given skillType
* Will add the appropriate type of XP from the block to the player based on the material of the
* blocks given if it matches the given skillType
*
* @param blockState The target blockstate
* @param mcMMOPlayer The target player
* @param mmoPlayer The target player
* @param skillType target primary skill
*/
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mcMMOPlayer, PrimarySkillType skillType) {
public static void addXpFromBlockBySkill(BlockState blockState, McMMOPlayer mmoPlayer,
PrimarySkillType skillType) {
if (ExperienceConfig.getInstance().getXp(skillType, blockState.getType()) > 0) {
mcMMOPlayer.applyXpGain(skillType, ExperienceConfig.getInstance().getXp(skillType, blockState.getType()),
XPGainReason.PVE, XPGainSource.SELF);
mmoPlayer.applyXpGain(
skillType,
ExperienceConfig.getInstance().getXp(skillType, blockState.getType()), PVE,
SELF);
}
}
// Utility methods follow.
private static void addOfflineXP(@NotNull UUID playerUniqueId, @NotNull PrimarySkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerUniqueId);
private static void addOfflineXP(@NotNull UUID playerUniqueId, @NotNull PrimarySkillType skill,
int XP) {
final PlayerProfile profile = getOfflineProfile(playerUniqueId);
profile.addXp(skill, XP);
profile.save(true);
}
private static void addOfflineXP(@NotNull String playerName, @NotNull PrimarySkillType skill, int XP) {
PlayerProfile profile = getOfflineProfile(playerName);
private static void addOfflineXP(@NotNull String playerName, @NotNull PrimarySkillType skill,
int XP) {
final PlayerProfile profile = getOfflineProfile(playerName);
profile.addXp(skill, XP);
profile.scheduleAsyncSave();
}
private static @NotNull PlayerProfile getOfflineProfile(@NotNull UUID uuid) throws InvalidPlayerException {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
private static @NotNull PlayerProfile getOfflineProfile(@NotNull UUID uuid)
throws InvalidPlayerException {
final PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(uuid);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
@@ -1223,8 +1231,9 @@ public final class ExperienceAPI {
return profile;
}
private static @NotNull PlayerProfile getOfflineProfile(@NotNull OfflinePlayer offlinePlayer) throws InvalidPlayerException {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(offlinePlayer);
private static @NotNull PlayerProfile getOfflineProfile(@NotNull OfflinePlayer offlinePlayer)
throws InvalidPlayerException {
final PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(offlinePlayer);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
@@ -1233,8 +1242,9 @@ public final class ExperienceAPI {
return profile;
}
private static @NotNull PlayerProfile getOfflineProfile(@NotNull String playerName) throws InvalidPlayerException {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
private static @NotNull PlayerProfile getOfflineProfile(@NotNull String playerName)
throws InvalidPlayerException {
final PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
if (!profile.isLoaded()) {
throw new InvalidPlayerException();
@@ -1244,7 +1254,7 @@ public final class ExperienceAPI {
}
private static PrimarySkillType getSkillType(String skillType) throws InvalidSkillException {
PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
final PrimarySkillType skill = mcMMO.p.getSkillTools().matchSkill(skillType);
if (skill == null) {
throw new InvalidSkillException();
@@ -1253,8 +1263,9 @@ public final class ExperienceAPI {
return skill;
}
private static PrimarySkillType getNonChildSkillType(String skillType) throws InvalidSkillException, UnsupportedOperationException {
PrimarySkillType skill = getSkillType(skillType);
private static PrimarySkillType getNonChildSkillType(String skillType)
throws InvalidSkillException, UnsupportedOperationException {
final PrimarySkillType skill = getSkillType(skillType);
if (SkillTools.isChildSkill(skill)) {
throw new UnsupportedOperationException("Child skills do not have XP");
@@ -1274,7 +1285,7 @@ public final class ExperienceAPI {
}
private static FormulaType getFormulaType(String formula) throws InvalidFormulaTypeException {
FormulaType formulaType = FormulaType.getFormulaType(formula);
final FormulaType formulaType = FormulaType.getFormulaType(formula);
if (formulaType == null) {
throw new InvalidFormulaTypeException();
@@ -1284,12 +1295,12 @@ public final class ExperienceAPI {
}
/**
* @deprecated Use UserManager::getPlayer(Player player) instead
* @param player target player
* @return McMMOPlayer for that player if the profile is loaded, otherwise null
* @throws McMMOPlayerNotFoundException
* @deprecated Use UserManager::getPlayer(Player player) instead
*/
@Deprecated
@Deprecated(forRemoval = true)
private static McMMOPlayer getPlayer(Player player) throws McMMOPlayerNotFoundException {
if (!UserManager.hasPlayerDataKey(player)) {
throw new McMMOPlayerNotFoundException(player);

View File

@@ -1,6 +1,5 @@
package com.gmail.nossr50.api;
public enum FakeBlockBreakEventType {
FAKE,
TREE_FELLER
FAKE, TREE_FELLER
}

View File

@@ -12,6 +12,5 @@ public enum ItemSpawnReason {
UNARMED_DISARMED_ITEM, //When you disarm an opponent and they drop their weapon
SALVAGE_ENCHANTMENT_BOOK, //When you salvage an enchanted item and get the enchantment back in book form
SALVAGE_MATERIALS, //When you salvage an item and get materials back
TREE_FELLER_DISPLACED_BLOCK,
BONUS_DROPS, //Can be from Mining, Woodcutting, Herbalism, etc
TREE_FELLER_DISPLACED_BLOCK, BONUS_DROPS, //Can be from Mining, Woodcutting, Herbalism, etc
}

View File

@@ -7,14 +7,18 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.*;
public final class PartyAPI {
private PartyAPI() {}
private PartyAPI() {
}
/**
* Get the name of the party a player is in.
@@ -50,8 +54,9 @@ public final class PartyAPI {
* @return true if the player is in a party, false otherwise
*/
public static boolean inParty(Player player) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled() || UserManager.getPlayer(player) == null)
if (!mcMMO.p.getPartyConfig().isPartyEnabled() || UserManager.getPlayer(player) == null) {
return false;
}
return UserManager.getPlayer(player).inParty();
}
@@ -66,8 +71,9 @@ public final class PartyAPI {
* @return true if the two players are in the same party, false otherwise
*/
public static boolean inSameParty(Player playerA, Player playerB) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled())
if (!mcMMO.p.getPartyConfig().isPartyEnabled()) {
return false;
}
return mcMMO.p.getPartyManager().inSameParty(playerA, playerB);
}
@@ -101,8 +107,9 @@ public final class PartyAPI {
//Check if player profile is loaded
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (mmoPlayer == null)
if (mmoPlayer == null) {
return;
}
Party party = mcMMO.p.getPartyManager().getParty(partyName);
@@ -110,7 +117,9 @@ public final class PartyAPI {
party = new Party(new PartyLeader(player.getUniqueId(), player.getName()), partyName);
} else {
if (mcMMO.p.getPartyManager().isPartyFull(player, party)) {
NotificationManager.sendPlayerInformation(player, NotificationType.PARTY_MESSAGE, "Commands.Party.PartyFull", party.toString());
NotificationManager.sendPlayerInformation(
player, NotificationType.PARTY_MESSAGE,
"Commands.Party.PartyFull", party.toString());
return;
}
}
@@ -119,8 +128,8 @@ public final class PartyAPI {
}
/**
* The max party size of the server
* 0 or less for no size limit
* The max party size of the server 0 or less for no size limit
*
* @return the max party size on this server
*/
public static int getMaxPartySize() {
@@ -138,8 +147,9 @@ public final class PartyAPI {
*/
public static void addToParty(Player player, String partyName, boolean bypassLimit) {
//Check if player profile is loaded
if (!mcMMO.p.getPartyConfig().isPartyEnabled() || UserManager.getPlayer(player) == null)
if (!mcMMO.p.getPartyConfig().isPartyEnabled() || UserManager.getPlayer(player) == null) {
return;
}
Party party = mcMMO.p.getPartyManager().getParty(partyName);
@@ -159,8 +169,9 @@ public final class PartyAPI {
*/
public static void removeFromParty(Player player) {
//Check if player profile is loaded
if (!mcMMO.p.getPartyConfig().isPartyEnabled() || UserManager.getPlayer(player) == null)
if (!mcMMO.p.getPartyConfig().isPartyEnabled() || UserManager.getPlayer(player) == null) {
return;
}
mcMMO.p.getPartyManager().removeFromParty(UserManager.getPlayer(player));
}
@@ -174,8 +185,9 @@ public final class PartyAPI {
* @return the leader of the party
*/
public static @Nullable String getPartyLeader(String partyName) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled())
if (!mcMMO.p.getPartyConfig().isPartyEnabled()) {
return null;
}
return mcMMO.p.getPartyManager().getPartyLeaderName(partyName);
}
@@ -190,10 +202,13 @@ public final class PartyAPI {
*/
@Deprecated
public static void setPartyLeader(String partyName, String playerName) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled())
if (!mcMMO.p.getPartyConfig().isPartyEnabled()) {
return;
}
mcMMO.p.getPartyManager().setPartyLeader(mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId(), mcMMO.p.getPartyManager().getParty(partyName));
mcMMO.p.getPartyManager().setPartyLeader(
mcMMO.p.getServer().getOfflinePlayer(playerName).getUniqueId(),
mcMMO.p.getPartyManager().getParty(partyName));
}
/**
@@ -210,7 +225,7 @@ public final class PartyAPI {
return null;
}
List<OfflinePlayer> members = new ArrayList<>();
final List<OfflinePlayer> members = new ArrayList<>();
for (UUID memberUniqueId : mcMMO.p.getPartyManager().getAllMembers(player).keySet()) {
OfflinePlayer member = mcMMO.p.getServer().getOfflinePlayer(memberUniqueId);
members.add(member);
@@ -228,8 +243,9 @@ public final class PartyAPI {
*/
@Deprecated
public static LinkedHashSet<String> getMembers(Player player) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled())
if (!mcMMO.p.getPartyConfig().isPartyEnabled()) {
return null;
}
return (LinkedHashSet<String>) mcMMO.p.getPartyManager().getAllMembers(player).values();
}
@@ -243,8 +259,9 @@ public final class PartyAPI {
* @return all the player names and uuids in the player's party
*/
public static LinkedHashMap<UUID, String> getMembersMap(Player player) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled())
if (!mcMMO.p.getPartyConfig().isPartyEnabled()) {
return null;
}
return mcMMO.p.getPartyManager().getAllMembers(player);
}
@@ -258,8 +275,9 @@ public final class PartyAPI {
* @return all online players in this party
*/
public static List<Player> getOnlineMembers(String partyName) {
if (!mcMMO.p.getPartyConfig().isPartyEnabled())
if (!mcMMO.p.getPartyConfig().isPartyEnabled()) {
return null;
}
return mcMMO.p.getPartyManager().getOnlineMembers(partyName);
}

View File

@@ -3,17 +3,16 @@ package com.gmail.nossr50.api;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.skills.SkillTools;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public final class SkillAPI {
private SkillAPI() {}
private SkillAPI() {
}
/**
* Returns a list of strings with mcMMO's skills
* This includes parent and child skills
* Returns a list of strings with mcMMO's skills This includes parent and child skills
* </br>
* This function is designed for API usage.
*
@@ -24,8 +23,7 @@ public final class SkillAPI {
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes parent skills
* Returns a list of strings with mcMMO's skills This only includes parent skills
* </br>
* This function is designed for API usage.
*
@@ -36,8 +34,7 @@ public final class SkillAPI {
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes child skills
* Returns a list of strings with mcMMO's skills This only includes child skills
* </br>
* This function is designed for API usage.
*
@@ -48,8 +45,7 @@ public final class SkillAPI {
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes combat skills
* Returns a list of strings with mcMMO's skills This only includes combat skills
* </br>
* This function is designed for API usage.
*
@@ -60,8 +56,7 @@ public final class SkillAPI {
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes gathering skills
* Returns a list of strings with mcMMO's skills This only includes gathering skills
* </br>
* This function is designed for API usage.
*
@@ -72,8 +67,7 @@ public final class SkillAPI {
}
/**
* Returns a list of strings with mcMMO's skills
* This only includes misc skills
* Returns a list of strings with mcMMO's skills This only includes misc skills
* </br>
* This function is designed for API usage.
*

View File

@@ -1,8 +1,10 @@
package com.gmail.nossr50.api.exceptions;
import java.io.Serial;
import org.jetbrains.annotations.NotNull;
public class IncompleteNamespacedKeyRegister extends RuntimeException {
@Serial
private static final long serialVersionUID = -6905157273569301219L;
public IncompleteNamespacedKeyRegister(@NotNull String message) {

View File

@@ -1,6 +1,9 @@
package com.gmail.nossr50.api.exceptions;
import java.io.Serial;
public class InvalidFormulaTypeException extends RuntimeException {
@Serial
private static final long serialVersionUID = 3368670229490121886L;
public InvalidFormulaTypeException() {

View File

@@ -1,6 +1,9 @@
package com.gmail.nossr50.api.exceptions;
import java.io.Serial;
public class InvalidPlayerException extends RuntimeException {
@Serial
private static final long serialVersionUID = 907213002618581385L;
public InvalidPlayerException() {

View File

@@ -1,6 +1,9 @@
package com.gmail.nossr50.api.exceptions;
import java.io.Serial;
public class InvalidSkillException extends RuntimeException {
@Serial
private static final long serialVersionUID = 942705284195791157L;
public InvalidSkillException() {

View File

@@ -1,6 +1,9 @@
package com.gmail.nossr50.api.exceptions;
import java.io.Serial;
public class InvalidXPGainReasonException extends RuntimeException {
@Serial
private static final long serialVersionUID = 4427052841957931157L;
public InvalidXPGainReasonException() {

View File

@@ -1,12 +1,15 @@
package com.gmail.nossr50.api.exceptions;
import java.io.Serial;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class McMMOPlayerNotFoundException extends RuntimeException {
@Serial
private static final long serialVersionUID = 761917904993202836L;
public McMMOPlayerNotFoundException(@NotNull Player player) {
super("McMMOPlayer object was not found for [NOTE: This can mean the profile is not loaded yet! : " + player.getName() + " " + player.getUniqueId());
super("McMMOPlayer object was not found for [NOTE: This can mean the profile is not loaded yet! : "
+ player.getName() + " " + player.getUniqueId());
}
}

View File

@@ -1,9 +0,0 @@
package com.gmail.nossr50.api.exceptions;
import org.jetbrains.annotations.NotNull;
public class ValueOutOfBoundsException extends RuntimeException {
public ValueOutOfBoundsException(@NotNull String message) {
super(message);
}
}

View File

@@ -23,7 +23,6 @@ public class ChatManager {
private final @NotNull AdminChatMailer adminChatMailer;
private final @NotNull PartyChatMailer partyChatMailer;
private final @NotNull ConsoleAuthor consoleAuthor;
private final @NotNull Audience consoleAudience;
@@ -34,7 +33,8 @@ public class ChatManager {
partyChatMailer = new PartyChatMailer(pluginRef);
this.consoleAuthor = new ConsoleAuthor(LocaleLoader.getString("Chat.Identity.Console"));
this.consoleAudience = mcMMO.getAudiences().filter((cs) -> cs instanceof ConsoleCommandSender);
this.consoleAudience = mcMMO.getAudiences()
.filter((cs) -> cs instanceof ConsoleCommandSender);
this.isChatEnabled = ChatConfig.getInstance().isChatEnabled();
}
@@ -45,7 +45,8 @@ public class ChatManager {
* @param rawMessage the raw message from the player as it was typed
* @param isAsync whether this is getting processed via async
*/
public void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull String rawMessage, boolean isAsync) {
public void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull String rawMessage,
boolean isAsync) {
processPlayerMessage(mmoPlayer, mmoPlayer.getChatChannel(), rawMessage, isAsync);
}
@@ -56,7 +57,8 @@ public class ChatManager {
* @param args the raw command arguments from the player
* @param chatChannel target channel
*/
public void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull String[] args, @NotNull ChatChannel chatChannel) {
public void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull String[] args,
@NotNull ChatChannel chatChannel) {
String chatMessageWithoutCommand = buildChatMessage(args);
//Commands are never async
@@ -71,13 +73,20 @@ public class ChatManager {
* @param rawMessage raw chat message as it was typed
* @param isAsync whether this is getting processed via async
*/
private void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull ChatChannel chatChannel, @NotNull String rawMessage, boolean isAsync) {
private void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer,
@NotNull ChatChannel chatChannel,
@NotNull String rawMessage, boolean isAsync) {
switch (chatChannel) {
case ADMIN:
adminChatMailer.processChatMessage(mmoPlayer.getPlayerAuthor(), rawMessage, isAsync, Permissions.colorChat(mmoPlayer.getPlayer()));
adminChatMailer.processChatMessage(
mmoPlayer.getPlayerAuthor(), rawMessage, isAsync,
Permissions.colorChat(mmoPlayer.getPlayer()));
break;
case PARTY:
partyChatMailer.processChatMessage(mmoPlayer.getPlayerAuthor(), rawMessage, mmoPlayer.getParty(), isAsync, Permissions.colorChat(mmoPlayer.getPlayer()), Misc.isPartyLeader(mmoPlayer));
partyChatMailer.processChatMessage(
mmoPlayer.getPlayerAuthor(), rawMessage, mmoPlayer.getParty(),
isAsync, Permissions.colorChat(mmoPlayer.getPlayer()),
Misc.isPartyLeader(mmoPlayer));
break;
case PARTY_OFFICER:
case NONE:
@@ -87,6 +96,7 @@ public class ChatManager {
/**
* Handles console messaging to admins
*
* @param rawMessage raw message from the console
*/
public void processConsoleMessage(@NotNull String rawMessage) {
@@ -95,6 +105,7 @@ public class ChatManager {
/**
* Handles console messaging to admins
*
* @param args raw command args from the console
*/
public void processConsoleMessage(@NotNull String[] args) {
@@ -103,15 +114,18 @@ public class ChatManager {
/**
* Handles console messaging to a specific party
*
* @param rawMessage raw message from the console
* @param party target party
*/
public void processConsoleMessage(@NotNull String rawMessage, @NotNull Party party) {
partyChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, party, false, true, false);
partyChatMailer.processChatMessage(getConsoleAuthor(), rawMessage, party, false, true,
false);
}
/**
* Gets a console author
*
* @return a {@link ConsoleAuthor}
*/
private @NotNull Author getConsoleAuthor() {
@@ -119,31 +133,38 @@ public class ChatManager {
}
/**
* Change the chat channel of a {@link McMMOPlayer}
* Targeting the channel a player is already in will remove that player from the chat channel
* Change the chat channel of a {@link McMMOPlayer} Targeting the channel a player is already in
* will remove that player from the chat channel
*
* @param mmoPlayer target player
* @param targetChatChannel target chat channel
*/
public void setOrToggleChatChannel(@NotNull McMMOPlayer mmoPlayer, @NotNull ChatChannel targetChatChannel) {
public void setOrToggleChatChannel(@NotNull McMMOPlayer mmoPlayer,
@NotNull ChatChannel targetChatChannel) {
if (targetChatChannel == mmoPlayer.getChatChannel()) {
//Disabled message
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Chat.Channel.Off", StringUtils.getCapitalized(targetChatChannel.toString())));
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString(
"Chat.Channel.Off",
StringUtils.getCapitalized(targetChatChannel.toString())));
mmoPlayer.setChatMode(ChatChannel.NONE);
} else {
mmoPlayer.setChatMode(targetChatChannel);
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Chat.Channel.On", StringUtils.getCapitalized(targetChatChannel.toString())));
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString(
"Chat.Channel.On",
StringUtils.getCapitalized(targetChatChannel.toString())));
}
}
/**
* Create a chat message from an array of {@link String}
*
* @param args array of {@link String}
* @return a String built from the array
*/
private @NotNull String buildChatMessage(@NotNull String[] args) {
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < args.length; i++) {
for (int i = 0; i < args.length; i++) {
if (i + 1 >= args.length) {
stringBuilder.append(args[i]);
} else {
@@ -156,6 +177,7 @@ public class ChatManager {
/**
* Whether the player is allowed to send a message to the chat channel they are targeting
*
* @param mmoPlayer target player
* @return true if the player can send messages to that chat channel
*/
@@ -181,6 +203,7 @@ public class ChatManager {
/**
* Sends just the console a message
*
* @param author author of the message
* @param message message contents in component form
*/
@@ -190,6 +213,7 @@ public class ChatManager {
/**
* Whether the mcMMO chat system which handles party and admin chat is enabled or disabled
*
* @return true if mcMMO chat processing (for party/admin chat) is enabled
*/
public boolean isChatEnabled() {
@@ -197,11 +221,11 @@ public class ChatManager {
}
/**
* Whether a specific chat channel is enabled
* ChatChannels are enabled/disabled via user config
* Whether a specific chat channel is enabled ChatChannels are enabled/disabled via user config
* <p>
* If chat is disabled, this always returns false If NONE is passed as a {@link ChatChannel} it
* will return true
*
* If chat is disabled, this always returns false
* If NONE is passed as a {@link ChatChannel} it will return true
* @param chatChannel target chat channel
* @return true if the chat channel is enabled
*/
@@ -209,16 +233,11 @@ public class ChatManager {
if (!isChatEnabled) {
return false;
} else {
switch(chatChannel) {
case ADMIN:
case PARTY:
case PARTY_OFFICER:
return ChatConfig.getInstance().isChatChannelEnabled(chatChannel);
case NONE:
return true;
default:
return false;
}
return switch (chatChannel) {
case ADMIN, PARTY, PARTY_OFFICER ->
ChatConfig.getInstance().isChatChannelEnabled(chatChannel);
case NONE -> true;
};
}
}

View File

@@ -3,12 +3,11 @@ package com.gmail.nossr50.chat;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.player.UserManager;
import java.util.function.Predicate;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import java.util.function.Predicate;
public class SamePartyPredicate<T extends CommandSender> implements Predicate<T> {
final Party party;
@@ -21,12 +20,14 @@ public class SamePartyPredicate<T extends CommandSender> implements Predicate<T>
public boolean test(T t) {
//Include the console in the audience
if (t instanceof ConsoleCommandSender) {
return false; //Party audiences are special, we exclude console from them to avoid double messaging since we send a more verbose version to consoles
//Party audiences are special, we exclude console from them to avoid double
// messaging since we send a more verbose version to consoles
return false;
} else {
if (t instanceof Player player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (mcMMOPlayer != null) {
return mcMMOPlayer.getParty() == party;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (mmoPlayer != null) {
return mmoPlayer.getParty() == party;
}
}
}

View File

@@ -3,17 +3,17 @@ package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.util.text.TextUtils;
import com.google.common.base.Objects;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.UUID;
public abstract class AbstractPlayerAuthor implements Author {
private final @NotNull Player player;
private final @NotNull Map<ChatChannel, String> sanitizedNameCache;
private @NotNull String lastKnownDisplayName;
private final @NotNull HashMap<ChatChannel, String> sanitizedNameCache;
public AbstractPlayerAuthor(@NotNull Player player) {
this.player = player;
@@ -31,22 +31,24 @@ public abstract class AbstractPlayerAuthor implements Author {
}
/**
* Player display names can change and this method will update the last known display name of this player
* Player display names can change and this method will update the last known display name of
* this player
*/
private void updateLastKnownDisplayName() {
lastKnownDisplayName = player.getDisplayName();
}
/**
* Gets a sanitized name for a channel
* Sanitized names are names that are friendly to the {@link net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer}
* Sanitized names for authors are cached by channel and are only created as needed
* Sanitized names will update if a players display name has updated
* Gets a sanitized name for a channel Sanitized names are names that are friendly to the
* {@link net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer} Sanitized names
* for authors are cached by channel and are only created as needed Sanitized names will update
* if a players display name has updated
*
* @param chatChannel target chat channel
* @return the sanitized name for a player
*/
protected @NotNull String getSanitizedName(@NotNull ChatChannel chatChannel, boolean useDisplayName) {
protected @NotNull String getSanitizedName(@NotNull ChatChannel chatChannel,
boolean useDisplayName) {
//Already in cache
if (sanitizedNameCache.containsKey(chatChannel)) {
//Update cache
@@ -68,16 +70,18 @@ public abstract class AbstractPlayerAuthor implements Author {
}
/**
* Update the sanitized name cache
* This will add entries if one didn't exit
* Sanitized names are associated with a {@link ChatChannel} as different chat channels have different chat name settings
* Update the sanitized name cache This will add entries if one didn't exit Sanitized names are
* associated with a {@link ChatChannel} as different chat channels have different chat name
* settings
*
* @param chatChannel target chat channel
* @param useDisplayName whether to use this authors display name
*/
private void updateSanitizedNameCache(@NotNull ChatChannel chatChannel, boolean useDisplayName) {
private void updateSanitizedNameCache(@NotNull ChatChannel chatChannel,
boolean useDisplayName) {
if (useDisplayName) {
sanitizedNameCache.put(chatChannel, TextUtils.sanitizeForSerializer(player.getDisplayName()));
sanitizedNameCache.put(chatChannel,
TextUtils.sanitizeForSerializer(player.getDisplayName()));
} else {
//No need to sanitize a basic String
sanitizedNameCache.put(chatChannel, player.getName());
@@ -105,12 +109,17 @@ public abstract class AbstractPlayerAuthor implements Author {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AbstractPlayerAuthor that = (AbstractPlayerAuthor) o;
return Objects.equal(player, that.player) &&
Objects.equal(lastKnownDisplayName, that.lastKnownDisplayName) &&
Objects.equal(sanitizedNameCache, that.sanitizedNameCache);
return Objects.equal(player, that.player) && Objects.equal(
lastKnownDisplayName,
that.lastKnownDisplayName) && Objects.equal(
sanitizedNameCache, that.sanitizedNameCache);
}
@Override

View File

@@ -7,9 +7,9 @@ import org.jetbrains.annotations.NotNull;
public interface Author extends Identity {
/**
* The name of this author as used in mcMMO chat
* This is the {@link String} representation of the users current chat username
* This can either be the player's display name or the player's official registered nickname with Mojang it depends on the servers chat settings for mcMMO
* The name of this author as used in mcMMO chat This is the {@link String} representation of
* the users current chat username This can either be the player's display name or the player's
* official registered nickname with Mojang it depends on the servers chat settings for mcMMO
*
* @param chatChannel which chat channel this is going to
* @return The name of this author as used in mcMMO chat
@@ -25,6 +25,7 @@ public interface Author extends Identity {
/**
* Whether this author is a {@link org.bukkit.entity.Player}
*
* @return true if this author is a player
*/
boolean isPlayer();

View File

@@ -2,11 +2,10 @@ package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.util.text.TextUtils;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class ConsoleAuthor implements Author {
private final UUID uuid;
private final @NotNull String name;

View File

@@ -10,6 +10,7 @@ import com.gmail.nossr50.events.chat.McMMOChatEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.text.TextUtils;
import java.util.function.Predicate;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
@@ -18,16 +19,14 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.function.Predicate;
public class AdminChatMailer extends AbstractChatMailer {
public static final @NotNull String MCMMO_CHAT_ADMINCHAT_PERMISSION = "mcmmo.chat.adminchat";
public AdminChatMailer(Plugin pluginRef) {
super(pluginRef);
}
public static final @NotNull String MCMMO_CHAT_ADMINCHAT_PERMISSION = "mcmmo.chat.adminchat";
/**
* Constructs an audience of admins
*
@@ -43,9 +42,10 @@ public class AdminChatMailer extends AbstractChatMailer {
* @return admin chat audience predicate
*/
public @NotNull Predicate<CommandSender> predicate() {
return (commandSender) -> commandSender.isOp()
|| commandSender.hasPermission(MCMMO_CHAT_ADMINCHAT_PERMISSION)
|| (ChatConfig.getInstance().isConsoleIncludedInAudience(ChatChannel.ADMIN) && commandSender instanceof ConsoleCommandSender);
return (commandSender) -> commandSender.isOp() || commandSender.hasPermission(
MCMMO_CHAT_ADMINCHAT_PERMISSION) || (
ChatConfig.getInstance().isConsoleIncludedInAudience(
ChatChannel.ADMIN) && commandSender instanceof ConsoleCommandSender);
}
/**
@@ -56,11 +56,16 @@ public class AdminChatMailer extends AbstractChatMailer {
* @param canColor whether to replace colors codes with colors in the raw message
* @return the styled string, based on a locale entry
*/
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message, boolean canColor) {
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message,
boolean canColor) {
if (canColor) {
return LocaleLoader.getTextComponent("Chat.Style.Admin", author.getAuthoredName(ChatChannel.ADMIN), message);
return LocaleLoader.getTextComponent(
"Chat.Style.Admin", author.getAuthoredName(ChatChannel.ADMIN),
message);
} else {
return TextUtils.ofLegacyTextRaw(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(ChatChannel.ADMIN), message));
return TextUtils.ofLegacyTextRaw(
LocaleLoader.getString("Chat.Style.Admin",
author.getAuthoredName(ChatChannel.ADMIN), message));
}
}
@@ -77,8 +82,12 @@ public class AdminChatMailer extends AbstractChatMailer {
* @param isAsync whether this is being processed asynchronously
* @param canColor whether the author can use colors in chat
*/
public void processChatMessage(@NotNull Author author, @NotNull String rawString, boolean isAsync, boolean canColor) {
AdminChatMessage chatMessage = new AdminChatMessage(pluginRef, author, constructAudience(), rawString, addStyle(author, rawString, canColor));
public void processChatMessage(@NotNull Author author, @NotNull String rawString,
boolean isAsync,
boolean canColor) {
AdminChatMessage chatMessage = new AdminChatMessage(
pluginRef, author, constructAudience(), rawString,
addStyle(author, rawString, canColor));
McMMOChatEvent chatEvent = new McMMOAdminChatEvent(pluginRef, chatMessage, isAsync);
Bukkit.getPluginManager().callEvent(chatEvent);

View File

@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
public interface ChatMailer {
/**
* Send out a chat message
*
* @param chatMessage the {@link ChatMessage}
*/
void sendMail(@NotNull ChatMessage chatMessage);

View File

@@ -30,8 +30,12 @@ public class PartyChatMailer extends AbstractChatMailer {
* @param isAsync whether this is being processed asynchronously
* @param canColor whether the author can use colors in chat
*/
public void processChatMessage(@NotNull Author author, @NotNull String rawString, @NotNull Party party, boolean isAsync, boolean canColor, boolean isLeader) {
PartyChatMessage chatMessage = new PartyChatMessage(pluginRef, author, constructPartyAudience(party), rawString, addStyle(author, rawString, canColor, isLeader), party);
public void processChatMessage(@NotNull Author author, @NotNull String rawString,
@NotNull Party party,
boolean isAsync, boolean canColor, boolean isLeader) {
PartyChatMessage chatMessage = new PartyChatMessage(
pluginRef, author, constructPartyAudience(party), rawString,
addStyle(author, rawString, canColor, isLeader), party);
McMMOChatEvent chatEvent = new McMMOPartyChatEvent(pluginRef, chatMessage, party, isAsync);
Bukkit.getPluginManager().callEvent(chatEvent);
@@ -59,18 +63,29 @@ public class PartyChatMailer extends AbstractChatMailer {
* @param canColor whether to replace colors codes with colors in the raw message
* @return the styled string, based on a locale entry
*/
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message, boolean canColor, boolean isLeader) {
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message,
boolean canColor,
boolean isLeader) {
if (canColor) {
if (isLeader) {
return LocaleLoader.getTextComponent("Chat.Style.Party.Leader", author.getAuthoredName(ChatChannel.PARTY), message);
return LocaleLoader.getTextComponent(
"Chat.Style.Party.Leader",
author.getAuthoredName(ChatChannel.PARTY), message);
} else {
return LocaleLoader.getTextComponent("Chat.Style.Party", author.getAuthoredName(ChatChannel.PARTY), message);
return LocaleLoader.getTextComponent(
"Chat.Style.Party", author.getAuthoredName(ChatChannel.PARTY),
message);
}
} else {
if (isLeader) {
return TextUtils.ofLegacyTextRaw(LocaleLoader.getString("Chat.Style.Party.Leader", author.getAuthoredName(ChatChannel.PARTY), message));
return TextUtils.ofLegacyTextRaw(
LocaleLoader.getString(
"Chat.Style.Party.Leader",
author.getAuthoredName(ChatChannel.PARTY), message));
} else {
return TextUtils.ofLegacyTextRaw(LocaleLoader.getString("Chat.Style.Party", author.getAuthoredName(ChatChannel.PARTY), message));
return TextUtils.ofLegacyTextRaw(
LocaleLoader.getString("Chat.Style.Party",
author.getAuthoredName(ChatChannel.PARTY), message));
}
}
}

View File

@@ -15,7 +15,9 @@ public abstract class AbstractChatMessage implements ChatMessage {
protected @NotNull TextComponent componentMessage;
protected @NotNull Audience audience;
public AbstractChatMessage(@NotNull Plugin pluginRef, @NotNull Author author, @NotNull Audience audience, @NotNull String rawMessage, @NotNull TextComponent componentMessage) {
public AbstractChatMessage(@NotNull Plugin pluginRef, @NotNull Author author,
@NotNull Audience audience,
@NotNull String rawMessage, @NotNull TextComponent componentMessage) {
this.pluginRef = pluginRef;
this.author = author;
this.audience = audience;
@@ -38,6 +40,11 @@ public abstract class AbstractChatMessage implements ChatMessage {
return audience;
}
@Override
public void setAudience(@NotNull Audience newAudience) {
audience = newAudience;
}
@Override
public @NotNull TextComponent getChatMessage() {
return componentMessage;
@@ -48,21 +55,20 @@ public abstract class AbstractChatMessage implements ChatMessage {
this.componentMessage = textComponent;
}
@Override
public void setAudience(@NotNull Audience newAudience) {
audience = newAudience;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
AbstractChatMessage that = (AbstractChatMessage) o;
return Objects.equal(pluginRef, that.pluginRef) &&
Objects.equal(author, that.author) &&
Objects.equal(rawMessage, that.rawMessage) &&
Objects.equal(componentMessage, that.componentMessage) &&
Objects.equal(audience, that.audience);
return Objects.equal(pluginRef, that.pluginRef) && Objects.equal(author, that.author)
&& Objects.equal(
rawMessage, that.rawMessage) && Objects.equal(componentMessage,
that.componentMessage) && Objects.equal(
audience, that.audience);
}
@Override

View File

@@ -8,7 +8,9 @@ import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
public class AdminChatMessage extends AbstractChatMessage {
public AdminChatMessage(@NotNull Plugin pluginRef, @NotNull Author author, @NotNull Audience audience, @NotNull String rawMessage, @NotNull TextComponent componentMessage) {
public AdminChatMessage(@NotNull Plugin pluginRef, @NotNull Author author,
@NotNull Audience audience,
@NotNull String rawMessage, @NotNull TextComponent componentMessage) {
super(pluginRef, author, audience, rawMessage, componentMessage);
}

View File

@@ -7,8 +7,8 @@ import org.jetbrains.annotations.NotNull;
public interface ChatMessage {
/**
* The original message from the {@link Author}
* This is formatted and styled before being sent out to players by mcMMO
* The original message from the {@link Author} This is formatted and styled before being sent
* out to players by mcMMO
*
* @return the original message without any formatting or alterations
* @see #getChatMessage()
@@ -18,33 +18,42 @@ public interface ChatMessage {
/**
* The {@link Author} from which this payload originated
*
* @see #getChatMessage()
* @return the source of the chat message
* @see #getChatMessage()
*/
@NotNull Author getAuthor();
/**
* The authors display name which is used in the initial creation of the message payload, it is provided for convenience.
*
* The authors display name which is used in the initial creation of the message payload, it is
* provided for convenience.
* <p>
* This is a name generated by mcMMO during the creation of the {@link ChatMessage}
*
* <p>
* This is used by mcMMO when generating the message payload
* <p>
* This method provides the display name for the convenience of plugins constructing their own
* {@link TextComponent payloads}
*
* This method provides the display name for the convenience of plugins constructing their own {@link TextComponent payloads}
*
* @see #getChatMessage()
* @return the author display name as generated by mcMMO
* @see #getChatMessage()
*/
@NotNull String getAuthorDisplayName();
/**
* The target audience of this chat message
* Unless modified, this will include the {@link Author}
* The target audience of this chat message Unless modified, this will include the
* {@link Author}
*
* @return target audience
*/
@NotNull Audience getAudience();
/**
* Changes the audience
*
* @param newAudience the replacement audience
*/
void setAudience(@NotNull Audience newAudience);
/**
* The {@link TextComponent message} being sent to the audience
*
@@ -59,13 +68,6 @@ public interface ChatMessage {
*/
void setChatMessage(@NotNull TextComponent textComponent);
/**
* Changes the audience
*
* @param newAudience the replacement audience
*/
void setAudience(@NotNull Audience newAudience);
/**
* Deliver the message to the audience
*/

View File

@@ -19,13 +19,17 @@ public class PartyChatMessage extends AbstractChatMessage {
private final @NotNull Party party;
public PartyChatMessage(@NotNull Plugin pluginRef, @NotNull Author author, @NotNull Audience audience, @NotNull String rawMessage, @NotNull TextComponent componentMessage, @NotNull Party party) {
public PartyChatMessage(@NotNull Plugin pluginRef, @NotNull Author author,
@NotNull Audience audience,
@NotNull String rawMessage, @NotNull TextComponent componentMessage,
@NotNull Party party) {
super(pluginRef, author, audience, rawMessage, componentMessage);
this.party = party;
}
/**
* The party that this chat message was intended for
*
* @return the party that this message was intended for
*/
public @NotNull Party getParty() {
@@ -46,29 +50,33 @@ public class PartyChatMessage extends AbstractChatMessage {
//Sends to everyone but console
audience.sendMessage(author, componentMessage);
TextComponent spyMessage = LocaleLoader.getTextComponent("Chat.Spy.Party", author.getAuthoredName(ChatChannel.PARTY), rawMessage, party.getName());
final TextComponent spyMessage = LocaleLoader.getTextComponent(
"Chat.Spy.Party",
author.getAuthoredName(ChatChannel.PARTY), rawMessage, party.getName());
//Relay to spies
messagePartyChatSpies(spyMessage);
//Console message
if (ChatConfig.getInstance().isConsoleIncludedInAudience(ChatChannel.PARTY))
if (ChatConfig.getInstance().isConsoleIncludedInAudience(ChatChannel.PARTY)) {
mcMMO.p.getChatManager().sendConsoleMessage(author, spyMessage);
}
}
/**
* Console and Party Chat Spies get a more verbose version of the message
* Party Chat Spies will get a copy of the message as well
* Console and Party Chat Spies get a more verbose version of the message Party Chat Spies will
* get a copy of the message as well
*
* @param spyMessage the message to copy to spies
*/
private void messagePartyChatSpies(@NotNull TextComponent spyMessage) {
//Find the people with permissions
for(McMMOPlayer mcMMOPlayer : UserManager.getPlayers()) {
Player player = mcMMOPlayer.getPlayer();
for (McMMOPlayer mmoPlayer : UserManager.getPlayers()) {
final Player player = mmoPlayer.getPlayer();
//Check for toggled players
if (mcMMOPlayer.isPartyChatSpying()) {
Party adminParty = mcMMOPlayer.getParty();
if (mmoPlayer.isPartyChatSpying()) {
Party adminParty = mmoPlayer.getParty();
//Only message admins not part of this party
if (adminParty == null || adminParty != getParty()) {
@@ -82,10 +90,16 @@ public class PartyChatMessage extends AbstractChatMessage {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
PartyChatMessage that = (PartyChatMessage) o;
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
final PartyChatMessage that = (PartyChatMessage) o;
return Objects.equal(party, that.party);
}

View File

@@ -60,7 +60,8 @@ public class CommandManager {
if (ChatConfig.getInstance().isChatChannelEnabled(ChatChannel.ADMIN)) {
bukkitCommandManager.registerCommand(new AdminChatCommand(pluginRef));
}
if (pluginRef.getPartyConfig().isPartyEnabled() && ChatConfig.getInstance().isChatChannelEnabled(ChatChannel.PARTY)) {
if (pluginRef.getPartyConfig().isPartyEnabled() && ChatConfig.getInstance()
.isChatChannelEnabled(ChatChannel.PARTY)) {
bukkitCommandManager.registerCommand(new PartyChatCommand(pluginRef));
}
}
@@ -72,15 +73,17 @@ public class CommandManager {
}
private void registerSkillConditions() {
bukkitCommandManager.getCommandConditions().addCondition(POWER_LEVEL_CONDITION, (context) -> {
BukkitCommandIssuer issuer = context.getIssuer();
bukkitCommandManager.getCommandConditions()
.addCondition(POWER_LEVEL_CONDITION, (context) -> {
BukkitCommandIssuer issuer = context.getIssuer();
if (issuer.getIssuer() instanceof Player) {
validateLoadedData(issuer.getPlayer());
} else {
throw new ConditionFailedException(LocaleLoader.getString("Commands.NoConsole"));
}
});
if (issuer.getIssuer() instanceof Player) {
validateLoadedData(issuer.getPlayer());
} else {
throw new ConditionFailedException(
LocaleLoader.getString("Commands.NoConsole"));
}
});
}
private void registerChatCommandConditions() {
@@ -114,7 +117,8 @@ public class CommandManager {
});
}
private void validatePermission(@NotNull String permissionNode, @NotNull Permissible permissible) {
private void validatePermission(@NotNull String permissionNode,
@NotNull Permissible permissible) {
if (!permissible.hasPermission(permissionNode)) {
throw new ConditionFailedException(LocaleLoader.getString("mcMMO.NoPermission"));
}
@@ -123,7 +127,8 @@ public class CommandManager {
public void validateAdmin(@NotNull Player player) {
if (!player.isOp() && !Permissions.adminChat(player)) {
throw new ConditionFailedException("You are lacking the correct permissions to use this command.");
throw new ConditionFailedException(
"You are lacking the correct permissions to use this command.");
}
}
@@ -134,7 +139,7 @@ public class CommandManager {
}
public void validatePlayerParty(@NotNull Player player) {
McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (!pluginRef.getPartyConfig().isPartyEnabled() || mmoPlayer.getParty() == null) {
throw new ConditionFailedException(LocaleLoader.getString("Commands.Party.None"));

View File

@@ -17,9 +17,10 @@ public class McabilityCommand extends ToggleCommand {
}
@Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.Ability." + (mcMMOPlayer.getAbilityUse() ? "Off" : "On")));
mcMMOPlayer.toggleAbilityUse();
protected void applyCommandAction(McMMOPlayer mmoPlayer) {
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString(
"Commands.Ability." + (mmoPlayer.getAbilityUse() ? "Off" : "On")));
mmoPlayer.toggleAbilityUse();
}
@Override

View File

@@ -7,6 +7,9 @@ import com.gmail.nossr50.datatypes.database.DatabaseType;
import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.mcMMO;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -14,10 +17,6 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class McconvertCommand implements TabExecutor {
private static final List<String> FORMULA_TYPES;
private static final List<String> DATABASE_TYPES;
@@ -54,11 +53,13 @@ public class McconvertCommand implements TabExecutor {
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) {
return databaseConvertCommand.onCommand(sender, command, label, args);
} else if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[1].equalsIgnoreCase("exp")) {
} else if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp")
|| args[1].equalsIgnoreCase("exp")) {
return experienceConvertCommand.onCommand(sender, command, label, args);
}
@@ -68,17 +69,22 @@ public class McconvertCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
switch (args.length) {
case 1:
return StringUtil.copyPartialMatches(args[0], SUBCOMMANDS, new ArrayList<>(SUBCOMMANDS.size()));
return StringUtil.copyPartialMatches(args[0], SUBCOMMANDS,
new ArrayList<>(SUBCOMMANDS.size()));
case 2:
if (args[0].equalsIgnoreCase("database") || args[0].equalsIgnoreCase("db")) {
return StringUtil.copyPartialMatches(args[0], DATABASE_TYPES, new ArrayList<>(DATABASE_TYPES.size()));
return StringUtil.copyPartialMatches(args[0], DATABASE_TYPES,
new ArrayList<>(DATABASE_TYPES.size()));
}
if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp") || args[0].equalsIgnoreCase("exp")) {
return StringUtil.copyPartialMatches(args[0], FORMULA_TYPES, new ArrayList<>(FORMULA_TYPES.size()));
if (args[0].equalsIgnoreCase("experience") || args[0].equalsIgnoreCase("xp")
|| args[0].equalsIgnoreCase("exp")) {
return StringUtil.copyPartialMatches(args[0], FORMULA_TYPES,
new ArrayList<>(FORMULA_TYPES.size()));
}
return ImmutableList.of();

View File

@@ -17,9 +17,10 @@ public class McgodCommand extends ToggleCommand {
}
@Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.GodMode." + (mcMMOPlayer.getGodMode() ? "Disabled" : "Enabled")));
mcMMOPlayer.toggleGodMode();
protected void applyCommandAction(McMMOPlayer mmoPlayer) {
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString(
"Commands.GodMode." + (mmoPlayer.getGodMode() ? "Disabled" : "Enabled")));
mmoPlayer.toggleGodMode();
}
@Override

View File

@@ -12,7 +12,8 @@ import org.jetbrains.annotations.NotNull;
public class McmmoCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 0:
if (!Permissions.mcmmoDescription(sender)) {
@@ -27,18 +28,22 @@ public class McmmoCommand implements CommandExecutor {
if (mcMMO.p.getGeneralConfig().getDonateMessageEnabled()) {
sender.sendMessage(LocaleLoader.getString("MOTD.Donate"));
sender.sendMessage(ChatColor.GOLD + " - " + ChatColor.GREEN + "nossr50@gmail.com" + ChatColor.GOLD + " Paypal");
sender.sendMessage(
ChatColor.GOLD + " - " + ChatColor.GREEN + "nossr50@gmail.com"
+ ChatColor.GOLD + " Paypal");
}
if (Permissions.showversion(sender)) {
sender.sendMessage(LocaleLoader.getString("MOTD.Version", mcMMO.p.getDescription().getVersion()));
sender.sendMessage(LocaleLoader.getString("MOTD.Version",
mcMMO.p.getDescription().getVersion()));
}
// mcMMO.getHolidayManager().anniversaryCheck(sender);
return true;
case 1:
if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("commands")) {
if (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help")
|| args[0].equalsIgnoreCase("commands")) {
if (!Permissions.mcmmoHelp(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
@@ -72,8 +77,10 @@ public class McmmoCommand implements CommandExecutor {
private void displayOtherCommands(CommandSender sender) {
//Don't show them this category if they have none of the permissions
if (!Permissions.skillreset(sender) && !Permissions.mmoedit(sender) && !Permissions.adminChat(sender) && !Permissions.mcgod(sender))
if (!Permissions.skillreset(sender) && !Permissions.mmoedit(sender)
&& !Permissions.adminChat(sender) && !Permissions.mcgod(sender)) {
return;
}
sender.sendMessage(LocaleLoader.getString("Commands.Other"));

View File

@@ -5,39 +5,41 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class McnotifyCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (args.length == 0) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
final McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender);
//Not Loaded yet
if (mcMMOPlayer == null) {
if (mmoPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Notifications." + (mcMMOPlayer.useChatNotifications() ? "Off" : "On")));
mcMMOPlayer.toggleChatNotifications();
sender.sendMessage(LocaleLoader.getString(
"Commands.Notifications." + (mmoPlayer.useChatNotifications() ? "Off" : "On")));
mmoPlayer.toggleChatNotifications();
return true;
}
return false;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@@ -17,13 +17,13 @@ public class McrefreshCommand extends ToggleCommand {
}
@Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.setRecentlyHurt(0);
mcMMOPlayer.resetCooldowns();
mcMMOPlayer.resetToolPrepMode();
mcMMOPlayer.resetAbilityMode();
protected void applyCommandAction(McMMOPlayer mmoPlayer) {
mmoPlayer.setRecentlyHurt(0);
mmoPlayer.resetCooldowns();
mmoPlayer.resetToolPrepMode();
mmoPlayer.resetAbilityMode();
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString("Ability.Generic.Refresh"));
}
@Override

View File

@@ -5,20 +5,20 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class McscoreboardCommand implements TabExecutor {
private static final List<String> FIRST_ARGS = ImmutableList.of("keep", "time", "clear");
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
@@ -42,7 +42,8 @@ public class McscoreboardCommand implements TabExecutor {
}
if (args[0].equalsIgnoreCase("keep")) {
if (!mcMMO.p.getGeneralConfig().getAllowKeepBoard() || !mcMMO.p.getGeneralConfig().getScoreboardsEnabled()) {
if (!mcMMO.p.getGeneralConfig().getAllowKeepBoard()
|| !mcMMO.p.getGeneralConfig().getScoreboardsEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.Disabled"));
return true;
}
@@ -80,9 +81,11 @@ public class McscoreboardCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], FIRST_ARGS, new ArrayList<>(FIRST_ARGS.size()));
return StringUtil.copyPartialMatches(args[0], FIRST_ARGS,
new ArrayList<>(FIRST_ARGS.size()));
}
return ImmutableList.of();
}

View File

@@ -4,18 +4,18 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public abstract class ToggleCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 0:
if (CommandUtils.noConsoleUsage(sender)) {
@@ -41,17 +41,17 @@ public abstract class ToggleCommand implements TabExecutor {
}
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(playerName);
if (!CommandUtils.checkPlayerExistence(sender, playerName, mcMMOPlayer)) {
if (!CommandUtils.checkPlayerExistence(sender, playerName, mmoPlayer)) {
return true;
}
if (CommandUtils.isOffline(sender, mcMMOPlayer.getPlayer())) {
if (CommandUtils.isOffline(sender, mmoPlayer.getPlayer())) {
return true;
}
applyCommandAction(mcMMOPlayer);
applyCommandAction(mmoPlayer);
sendSuccessMessage(sender, playerName);
return true;
@@ -61,16 +61,21 @@ public abstract class ToggleCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
}
return ImmutableList.of();
}
protected abstract boolean hasOtherPermission(CommandSender sender);
protected abstract boolean hasSelfPermission(CommandSender sender);
protected abstract void applyCommandAction(McMMOPlayer mcMMOPlayer);
protected abstract void applyCommandAction(McMMOPlayer mmoPlayer);
protected abstract void sendSuccessMessage(CommandSender sender, String playerName);
}

View File

@@ -9,6 +9,8 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.text.StringUtils;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -16,17 +18,16 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class XprateCommand implements TabExecutor {
private final double ORIGINAL_XP_RATE = ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier();
private final double ORIGINAL_XP_RATE = ExperienceConfig.getInstance()
.getExperienceGainsGlobalMultiplier();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 1:
if (!args[0].equalsIgnoreCase("reset") && !args[0].equalsIgnoreCase("clear")) {
if (!args[0].equalsIgnoreCase("reset") && !args[0].equalsIgnoreCase("clear")) {
return false;
}
@@ -41,16 +42,19 @@ public class XprateCommand implements TabExecutor {
NotificationManager.broadcastTitle(mcMMO.p.getServer(),
LocaleLoader.getString("Commands.Event.Stop"),
LocaleLoader.getString("Commands.Event.Stop.Subtitle"),
10, 10*20, 20);
10, 10 * 20, 20);
}
if (mcMMO.p.getGeneralConfig().broadcastEventMessages()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Stop"));
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Stop.Subtitle"));
mcMMO.p.getServer()
.broadcastMessage(LocaleLoader.getString("Commands.Event.Stop"));
mcMMO.p.getServer().broadcastMessage(
LocaleLoader.getString("Commands.Event.Stop.Subtitle"));
}
//Admin notification
NotificationManager.processSensitiveCommandNotification(sender, SensitiveCommandType.XPRATE_END);
NotificationManager.processSensitiveCommandNotification(sender,
SensitiveCommandType.XPRATE_END);
mcMMO.p.toggleXpEventEnabled();
}
@@ -79,7 +83,8 @@ public class XprateCommand implements TabExecutor {
int newXpRate = Integer.parseInt(args[0]);
if (newXpRate < 0) {
sender.sendMessage(ChatColor.RED+LocaleLoader.getString("Commands.NegativeNumberWarn"));
sender.sendMessage(
ChatColor.RED + LocaleLoader.getString("Commands.NegativeNumberWarn"));
return true;
}
@@ -89,16 +94,19 @@ public class XprateCommand implements TabExecutor {
NotificationManager.broadcastTitle(mcMMO.p.getServer(),
LocaleLoader.getString("Commands.Event.Start"),
LocaleLoader.getString("Commands.Event.XP", newXpRate),
10, 10*20, 20);
10, 10 * 20, 20);
}
if (mcMMO.p.getGeneralConfig().broadcastEventMessages()) {
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.Start"));
mcMMO.p.getServer().broadcastMessage(LocaleLoader.getString("Commands.Event.XP", newXpRate));
mcMMO.p.getServer()
.broadcastMessage(LocaleLoader.getString("Commands.Event.Start"));
mcMMO.p.getServer().broadcastMessage(
LocaleLoader.getString("Commands.Event.XP", newXpRate));
}
//Admin notification
NotificationManager.processSensitiveCommandNotification(sender, SensitiveCommandType.XPRATE_MODIFY, String.valueOf(newXpRate));
NotificationManager.processSensitiveCommandNotification(sender,
SensitiveCommandType.XPRATE_MODIFY, String.valueOf(newXpRate));
return true;
@@ -108,16 +116,19 @@ public class XprateCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
switch (args.length) {
case 1:
if (StringUtils.isInt(args[0])) {
return ImmutableList.of();
}
return StringUtil.copyPartialMatches(args[0], CommandUtils.RESET_OPTIONS, new ArrayList<>(CommandUtils.RESET_OPTIONS.size()));
return StringUtil.copyPartialMatches(args[0], CommandUtils.RESET_OPTIONS,
new ArrayList<>(CommandUtils.RESET_OPTIONS.size()));
case 2:
return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS,
new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
default:
return ImmutableList.of();
}

View File

@@ -11,8 +11,8 @@ public class CompatibilityCommand implements CommandExecutor {
/**
* Executes the given command, returning its success.
* <br>
* If false is returned, then the "usage" plugin.yml entry for this command
* (if defined) will be sent to the player.
* If false is returned, then the "usage" plugin.yml entry for this command (if defined) will be
* sent to the player.
*
* @param commandSender Source of the command
* @param command Command which was executed
@@ -21,7 +21,9 @@ public class CompatibilityCommand implements CommandExecutor {
* @return true if a valid command, otherwise false
*/
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command,
@NotNull String s,
@NotNull String[] strings) {
mcMMO.getCompatibilityManager().reportCompatibilityStatus(commandSender);
return true;
}

View File

@@ -1,57 +0,0 @@
//package com.gmail.nossr50.commands.admin;
//
//import com.gmail.nossr50.config.treasure.FishingTreasureConfig;
//import com.gmail.nossr50.datatypes.player.McMMOPlayer;
//import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
//import com.gmail.nossr50.datatypes.treasure.Rarity;
//import com.gmail.nossr50.mcMMO;
//import com.gmail.nossr50.skills.fishing.FishingManager;
//import com.gmail.nossr50.util.player.UserManager;
//import org.bukkit.Location;
//import org.bukkit.command.Command;
//import org.bukkit.command.CommandExecutor;
//import org.bukkit.command.CommandSender;
//import org.bukkit.entity.Player;
//import org.jetbrains.annotations.NotNull;
//
//public class DropTreasureCommand implements CommandExecutor {
// @Override
// public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
// if (sender instanceof Player) {
// if (!sender.isOp()) {
// sender.sendMessage("This command is for Operators only");
// return false;
// }
//
// Player player = (Player) sender;
// Location location = player.getLocation();
// McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
//
// if (mmoPlayer == null) {
// //TODO: Localize
// player.sendMessage("Your player data is not loaded yet");
// return false;
// }
//
// if (args.length == 0) {
// mcMMO.p.getLogger().info(player.toString() +" is dropping all mcMMO treasures via admin command at location "+location.toString());
// for(Rarity rarity : FishingTreasureConfig.getInstance().fishingRewards.keySet()) {
// for(FishingTreasure fishingTreasure : FishingTreasureConfig.getInstance().fishingRewards.get(rarity)) {
// FishingManager fishingManager = mmoPlayer.getFishingManager();
// }
// }
// //TODO: impl
// } else {
// String targetTreasure = args[1];
//
// //Drop all treasures matching the name
// //TODO: impl
// }
//
// return true;
// } else {
// sender.sendMessage("No console support for this command");
// return false;
// }
// }
//}

View File

@@ -12,7 +12,9 @@ import org.jetbrains.annotations.NotNull;
*/
public final class McmmoReloadLocaleCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label,
String[] args) {
if (args.length == 0) {
if (!Permissions.reloadlocale(sender)) {
sender.sendMessage(command.getPermissionMessage());

View File

@@ -12,11 +12,14 @@ import org.jetbrains.annotations.NotNull;
public class PlayerDebugCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label,
String[] args) {
if (sender instanceof Player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
mcMMOPlayer.toggleDebugMode(); //Toggle debug mode
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mcMMOPlayer.isDebugMode()));
final McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender);
mmoPlayer.toggleDebugMode(); //Toggle debug mode
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(),
"Commands.Mmodebug.Toggle", String.valueOf(mmoPlayer.isDebugMode()));
return true;
} else {
return false;

View File

@@ -22,24 +22,29 @@ public class AdminChatCommand extends BaseCommand {
this.pluginRef = pluginRef;
}
@Default @Conditions(CommandManager.ADMIN_CONDITION)
@Default
@Conditions(CommandManager.ADMIN_CONDITION)
public void processCommand(String[] args) {
BukkitCommandIssuer bukkitCommandIssuer = (BukkitCommandIssuer) getCurrentCommandIssuer();
final BukkitCommandIssuer bukkitCommandIssuer = (BukkitCommandIssuer) getCurrentCommandIssuer();
if (args == null || args.length == 0) {
//Process with no arguments
if (bukkitCommandIssuer.isPlayer()) {
McMMOPlayer mmoPlayer = UserManager.getPlayer(bukkitCommandIssuer.getPlayer());
final McMMOPlayer mmoPlayer = UserManager.getPlayer(
bukkitCommandIssuer.getPlayer());
pluginRef.getChatManager().setOrToggleChatChannel(mmoPlayer, ChatChannel.ADMIN);
} else {
//Not support for console
mcMMO.p.getLogger().info("You cannot switch chat channels as console, please provide full arguments.");
mcMMO.p.getLogger()
.info("You cannot switch chat channels as console, please provide full arguments.");
}
} else {
if (bukkitCommandIssuer.isPlayer()) {
McMMOPlayer mmoPlayer = UserManager.getPlayer(bukkitCommandIssuer.getPlayer());
final McMMOPlayer mmoPlayer = UserManager.getPlayer(
bukkitCommandIssuer.getPlayer());
if (mmoPlayer == null)
if (mmoPlayer == null) {
return;
}
//Message contains the original command so it needs to be passed to this method to trim it
pluginRef.getChatManager().processPlayerMessage(mmoPlayer, args, ChatChannel.ADMIN);

View File

@@ -18,9 +18,11 @@ public class McChatSpy extends ToggleCommand {
}
@Override
protected void applyCommandAction(McMMOPlayer mcMMOPlayer) {
mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Commands.AdminChatSpy." + (mcMMOPlayer.isPartyChatSpying() ? "Disabled" : "Enabled")));
mcMMOPlayer.togglePartyChatSpying();
protected void applyCommandAction(McMMOPlayer mmoPlayer) {
mmoPlayer.getPlayer().sendMessage(LocaleLoader.getString(
"Commands.AdminChatSpy." + (mmoPlayer.isPartyChatSpying() ? "Disabled"
: "Enabled")));
mmoPlayer.togglePartyChatSpying();
}
@Override

View File

@@ -33,11 +33,13 @@ public class PartyChatCommand extends BaseCommand {
if (args == null || args.length == 0) {
//Process with no arguments
if (bukkitCommandIssuer.isPlayer()) {
McMMOPlayer mmoPlayer = UserManager.getPlayer(bukkitCommandIssuer.getPlayer());
final McMMOPlayer mmoPlayer = UserManager.getPlayer(
bukkitCommandIssuer.getPlayer());
pluginRef.getChatManager().setOrToggleChatChannel(mmoPlayer, ChatChannel.PARTY);
} else {
//Not support for console
mcMMO.p.getLogger().info("You cannot switch chat channels as console, please provide full arguments.");
mcMMO.p.getLogger()
.info("You cannot switch chat channels as console, please provide full arguments.");
}
} else {
//Here we split the logic, consoles need to target a party name and players do not
@@ -46,11 +48,12 @@ public class PartyChatCommand extends BaseCommand {
* Player Logic
*/
if (bukkitCommandIssuer.getIssuer() instanceof Player) {
McMMOPlayer mmoPlayer = UserManager.getPlayer(bukkitCommandIssuer.getPlayer());
final McMMOPlayer mmoPlayer = UserManager.getPlayer(
bukkitCommandIssuer.getPlayer());
processCommandArgsPlayer(mmoPlayer, args);
/*
* Console Logic
*/
/*
* Console Logic
*/
} else {
processCommandArgsConsole(args);
}
@@ -59,6 +62,7 @@ public class PartyChatCommand extends BaseCommand {
/**
* Processes the command with arguments for a {@link McMMOPlayer}
*
* @param mmoPlayer target player
* @param args command arguments
*/
@@ -68,19 +72,24 @@ public class PartyChatCommand extends BaseCommand {
}
/**
* Processes the command with arguments for a {@link com.gmail.nossr50.chat.author.ConsoleAuthor}
* Processes the command with arguments for a
* {@link com.gmail.nossr50.chat.author.ConsoleAuthor}
*
* @param args command arguments
*/
private void processCommandArgsConsole(@NotNull String[] args) {
if (args.length <= 1) {
//Only specific a party and not the message
mcMMO.p.getLogger().severe("You need to specify a party name and then write a message afterwards.");
mcMMO.p.getLogger()
.severe("You need to specify a party name and then write a message afterwards.");
} else {
//Grab party
Party targetParty = mcMMO.p.getPartyManager().getParty(args[0]);
if (targetParty != null) {
pluginRef.getChatManager().processConsoleMessage(StringUtils.buildStringAfterNthElement(args, 1), targetParty);
pluginRef.getChatManager()
.processConsoleMessage(StringUtils.buildStringAfterNthElement(args, 1),
targetParty);
} else {
mcMMO.p.getLogger().severe("A party with that name doesn't exist!");
}

View File

@@ -17,17 +17,25 @@ import org.jetbrains.annotations.NotNull;
public class ConvertDatabaseCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label,
String[] args) {
if (args.length == 2) {
DatabaseType previousType = DatabaseType.getDatabaseType(args[1]);
DatabaseType newType = mcMMO.getDatabaseManager().getDatabaseType();
if (previousType == newType || (newType == DatabaseType.CUSTOM && DatabaseManagerFactory.getCustomDatabaseManagerClass().getSimpleName().equalsIgnoreCase(args[1]))) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Same", newType.toString()));
if (previousType == newType || (newType == DatabaseType.CUSTOM
&& DatabaseManagerFactory.getCustomDatabaseManagerClass()
.getSimpleName()
.equalsIgnoreCase(args[1]))) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Same",
newType.toString()));
return true;
}
DatabaseManager oldDatabase = DatabaseManagerFactory.createDatabaseManager(previousType, mcMMO.getUsersFilePath(), mcMMO.p.getLogger(), mcMMO.p.getPurgeTime(), mcMMO.p.getAdvancedConfig().getStartingLevel());
DatabaseManager oldDatabase = DatabaseManagerFactory.createDatabaseManager(previousType,
mcMMO.getUsersFilePath(), mcMMO.p.getLogger(), mcMMO.p.getPurgeTime(),
mcMMO.p.getAdvancedConfig().getStartingLevel());
if (oldDatabase == null) {
sender.sendMessage("Unable to load the old database! Check your log for errors.");
return true;
@@ -40,19 +48,26 @@ public class ConvertDatabaseCommand implements CommandExecutor {
clazz = Class.forName(args[1]);
if (!DatabaseManager.class.isAssignableFrom(clazz)) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
sender.sendMessage(
LocaleLoader.getString("Commands.mcconvert.Database.InvalidType",
args[1]));
return true;
}
oldDatabase = DatabaseManagerFactory.createCustomDatabaseManager((Class<? extends DatabaseManager>) clazz);
oldDatabase = DatabaseManagerFactory.createCustomDatabaseManager(
(Class<? extends DatabaseManager>) clazz);
} catch (Throwable e) {
e.printStackTrace();
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.InvalidType", args[1]));
sender.sendMessage(
LocaleLoader.getString("Commands.mcconvert.Database.InvalidType",
args[1]));
return true;
}
}
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Start", previousType.toString(), newType.toString()));
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Database.Start",
previousType.toString(),
newType.toString()));
UserManager.saveAll();
UserManager.clearAll();
@@ -64,10 +79,14 @@ public class ConvertDatabaseCommand implements CommandExecutor {
mcMMO.getDatabaseManager().saveUser(profile);
}
mcMMO.p.getFoliaLib().getScheduler().runLaterAsync(new PlayerProfileLoadingTask(player), 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
mcMMO.p.getFoliaLib().getScheduler()
.runLaterAsync(new PlayerProfileLoadingTask(player),
1); // 1 Tick delay to ensure the player is marked as online before we begin loading
}
mcMMO.p.getFoliaLib().getScheduler().runAsync(new DatabaseConversionTask(oldDatabase, sender, previousType.toString(), newType.toString()));
mcMMO.p.getFoliaLib().getScheduler().runAsync(
new DatabaseConversionTask(oldDatabase, sender, previousType.toString(),
newType.toString()));
return true;
}
return false;

View File

@@ -3,16 +3,16 @@ package com.gmail.nossr50.commands.database;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class McpurgeCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 0) {
mcMMO.getDatabaseManager().purgePowerlessUsers();
@@ -27,7 +27,8 @@ public class McpurgeCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@@ -5,6 +5,9 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -12,17 +15,15 @@ import org.bukkit.command.TabExecutor;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class McremoveCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 1) {
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
if (UserManager.getOfflinePlayer(playerName) == null && CommandUtils.unloadedProfile(sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName))) {
if (UserManager.getOfflinePlayer(playerName) == null && CommandUtils.unloadedProfile(
sender, mcMMO.getDatabaseManager().loadPlayerProfile(playerName))) {
return true;
}
@@ -35,7 +36,8 @@ public class McremoveCommand implements TabExecutor {
if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) {
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
} else {
sender.sendMessage(playerName + " could not be removed from the database."); // Pretty sure this should NEVER happen.
sender.sendMessage(playerName
+ " could not be removed from the database."); // Pretty sure this should NEVER happen.
}
return true;
@@ -44,10 +46,12 @@ public class McremoveCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
}
return ImmutableList.of();
}

View File

@@ -4,16 +4,16 @@ import com.gmail.nossr50.database.DatabaseManagerFactory;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class MmoshowdbCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 0) {
Class<?> clazz = DatabaseManagerFactory.getCustomDatabaseManagerClass();
@@ -22,14 +22,16 @@ public class MmoshowdbCommand implements TabExecutor {
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb", (mcMMO.p.getGeneralConfig().getUseMySQL() ? "sql" : "flatfile")));
sender.sendMessage(LocaleLoader.getString("Commands.mmoshowdb",
(mcMMO.p.getGeneralConfig().getUseMySQL() ? "sql" : "flatfile")));
return true;
}
return false;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@@ -24,7 +24,8 @@ public class AddlevelsCommand extends ExperienceCommand {
}
@Override
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill, int value) {
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill,
int value) {
float xpRemoved = profile.getSkillXpLevelRaw(skill);
profile.addLevels(skill, value);
@@ -33,29 +34,35 @@ public class AddlevelsCommand extends ExperienceCommand {
return;
}
McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (mmoPlayer == null) {
EventUtils.tryLevelChangeEvent(player, skill, value, xpRemoved, true, XPGainReason.COMMAND);
EventUtils.tryLevelChangeEvent(player, skill, value, xpRemoved, true,
XPGainReason.COMMAND);
} else {
EventUtils.tryLevelChangeEvent(mmoPlayer, skill, value, xpRemoved, true, XPGainReason.COMMAND);
EventUtils.tryLevelChangeEvent(mmoPlayer, skill, value, xpRemoved, true,
XPGainReason.COMMAND);
}
}
@Override
protected void handlePlayerMessageAll(Player player, int value, boolean isSilent) {
if (isSilent)
if (isSilent) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.1", value));
}
@Override
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent) {
if (isSilent)
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill,
boolean isSilent) {
if (isSilent) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value, mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
player.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.1", value,
mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
}

View File

@@ -23,13 +23,16 @@ public class AddxpCommand extends ExperienceCommand {
}
@Override
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill, int value) {
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill,
int value) {
if (player != null) {
//Check if player profile is loaded
if (UserManager.getPlayer(player) == null)
if (UserManager.getPlayer(player) == null) {
return;
}
UserManager.getPlayer(player).applyXpGain(skill, value, XPGainReason.COMMAND, XPGainSource.COMMAND);
UserManager.getPlayer(player)
.applyXpGain(skill, value, XPGainReason.COMMAND, XPGainSource.COMMAND);
} else {
profile.addXp(skill, value);
profile.scheduleAsyncSave();
@@ -38,17 +41,21 @@ public class AddxpCommand extends ExperienceCommand {
@Override
protected void handlePlayerMessageAll(Player player, int value, boolean isSilent) {
if (isSilent)
if (isSilent) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardAll", value));
}
@Override
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent) {
if (isSilent)
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill,
boolean isSilent) {
if (isSilent) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value, mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
player.sendMessage(LocaleLoader.getString("Commands.addxp.AwardSkill", value,
mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
}

View File

@@ -6,17 +6,17 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.database.FormulaConversionTask;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.util.player.UserManager;
import java.util.Locale;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class ConvertExperienceCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
FormulaType previousType = mcMMO.getFormulaManager().getPreviousFormulaType();
FormulaType newType = FormulaType.getFormulaType(args[1].toUpperCase(Locale.ENGLISH));
@@ -27,19 +27,24 @@ public class ConvertExperienceCommand implements CommandExecutor {
}
if (previousType == newType) {
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Same", newType.toString()));
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Same",
newType.toString()));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Start", previousType.toString(), newType.toString()));
sender.sendMessage(LocaleLoader.getString("Commands.mcconvert.Experience.Start",
previousType.toString(), newType.toString()));
UserManager.saveAll();
UserManager.clearAll();
mcMMO.p.getFoliaLib().getScheduler().runLater(new FormulaConversionTask(sender, newType), 1);
mcMMO.p.getFoliaLib().getScheduler()
.runLater(new FormulaConversionTask(sender, newType), 1);
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
mcMMO.p.getFoliaLib().getScheduler().runLaterAsync(new PlayerProfileLoadingTask(player), 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
mcMMO.p.getFoliaLib().getScheduler()
.runLaterAsync(new PlayerProfileLoadingTask(player),
1); // 1 Tick delay to ensure the player is marked as online before we begin loading
}
return true;

View File

@@ -9,6 +9,8 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillTools;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -16,12 +18,10 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public abstract class ExperienceCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
PrimarySkillType skill;
if (args.length < 2) {
@@ -33,8 +33,9 @@ public abstract class ExperienceCommand implements TabExecutor {
}
if (!permissionsCheckSelf(sender)) {
if (command.getPermissionMessage() != null)
if (command.getPermissionMessage() != null) {
sender.sendMessage(command.getPermissionMessage());
}
sender.sendMessage("(mcMMO) No permission!");
return true;
}
@@ -60,8 +61,8 @@ public abstract class ExperienceCommand implements TabExecutor {
return true;
}
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill, Integer.parseInt(args[1]), isSilent(args));
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(),
skill, Integer.parseInt(args[1]), isSilent(args));
return true;
} else if ((args.length == 3 && !isSilent(args))
|| (args.length == 4 && isSilent(args))) {
@@ -88,10 +89,10 @@ public abstract class ExperienceCommand implements TabExecutor {
int value = Integer.parseInt(args[2]);
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
final McMMOPlayer mmoPlayer = UserManager.getOfflinePlayer(playerName);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
// If the mmoPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mmoPlayer == null) {
PlayerProfile profile;
profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName);
@@ -108,7 +109,8 @@ public abstract class ExperienceCommand implements TabExecutor {
editValues(null, profile, skill, value, isSilent(args));
} else {
editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill, value, isSilent(args));
editValues(mmoPlayer.getPlayer(), mmoPlayer.getProfile(), skill, value,
isSilent(args));
}
handleSenderMessage(sender, playerName, skill);
@@ -122,45 +124,60 @@ public abstract class ExperienceCommand implements TabExecutor {
private boolean isSilent(String[] args) {
int length = args.length;
if (length == 0)
if (length == 0) {
return false;
}
return args[length-1].equalsIgnoreCase("-s");
return args[length - 1].equalsIgnoreCase("-s");
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
switch (args.length) {
case 1:
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
case 2:
return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[1],
mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES,
new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}
}
protected abstract boolean permissionsCheckSelf(CommandSender sender);
protected abstract boolean permissionsCheckOthers(CommandSender sender);
protected abstract void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill, int value);
protected abstract void handleCommand(Player player, PlayerProfile profile,
PrimarySkillType skill, int value);
protected abstract void handlePlayerMessageAll(Player player, int value, boolean isSilent);
protected abstract void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent);
protected abstract void handlePlayerMessageSkill(Player player, int value,
PrimarySkillType skill, boolean isSilent);
private boolean validateArguments(CommandSender sender, String skillName, String value) {
return !(CommandUtils.isInvalidInteger(sender, value) || (!skillName.equalsIgnoreCase("all") && CommandUtils.isInvalidSkill(sender, skillName)));
return !(CommandUtils.isInvalidInteger(sender, value) || (!skillName.equalsIgnoreCase("all")
&& CommandUtils.isInvalidSkill(sender, skillName)));
}
protected static void handleSenderMessage(CommandSender sender, String playerName, PrimarySkillType skill) {
protected static void handleSenderMessage(CommandSender sender, String playerName,
PrimarySkillType skill) {
if (skill == null) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
} else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), playerName));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2",
mcMMO.p.getSkillTools().getLocalizedSkillName(skill), playerName));
}
}
protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill, int value, boolean isSilent) {
protected void editValues(Player player, PlayerProfile profile, PrimarySkillType skill,
int value, boolean isSilent) {
if (skill == null) {
for (PrimarySkillType primarySkillType : SkillTools.NON_CHILD_SKILLS) {
handleCommand(player, profile, primarySkillType, value);

View File

@@ -24,7 +24,8 @@ public class MmoeditCommand extends ExperienceCommand {
}
@Override
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill, int value) {
protected void handleCommand(Player player, PlayerProfile profile, PrimarySkillType skill,
int value) {
int skillLevel = profile.getSkillLevel(skill);
float xpRemoved = profile.getSkillXpLevelRaw(skill);
@@ -39,29 +40,35 @@ public class MmoeditCommand extends ExperienceCommand {
return;
}
McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (mmoPlayer != null) {
EventUtils.tryLevelEditEvent(mmoPlayer, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
EventUtils.tryLevelEditEvent(mmoPlayer, skill, value, xpRemoved, value > skillLevel,
XPGainReason.COMMAND, skillLevel);
} else {
EventUtils.tryLevelEditEvent(player, skill, value, xpRemoved, value > skillLevel, XPGainReason.COMMAND, skillLevel);
EventUtils.tryLevelEditEvent(player, skill, value, xpRemoved, value > skillLevel,
XPGainReason.COMMAND, skillLevel);
}
}
@Override
protected void handlePlayerMessageAll(Player player, int value, boolean isSilent) {
if (isSilent)
if (isSilent) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.AllSkills.1", value));
}
@Override
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill, boolean isSilent) {
if (isSilent)
protected void handlePlayerMessageSkill(Player player, int value, PrimarySkillType skill,
boolean isSilent) {
if (isSilent) {
return;
}
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), value));
player.sendMessage(LocaleLoader.getString("Commands.mmoedit.Modified.1",
mcMMO.p.getSkillTools().getLocalizedSkillName(skill), value));
}
}

View File

@@ -12,6 +12,8 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillTools;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -20,16 +22,14 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* This class mirrors the structure of ExperienceCommand, except the
* value/quantity argument is removed.
* This class mirrors the structure of ExperienceCommand, except the value/quantity argument is
* removed.
*/
public class SkillresetCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
PrimarySkillType skill;
switch (args.length) {
case 1:
@@ -52,7 +52,8 @@ public class SkillresetCommand implements TabExecutor {
skill = mcMMO.p.getSkillTools().matchSkill(args[0]);
}
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(), skill);
editValues((Player) sender, UserManager.getPlayer(sender.getName()).getProfile(),
skill);
return true;
case 2:
@@ -72,12 +73,13 @@ public class SkillresetCommand implements TabExecutor {
}
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
final McMMOPlayer mmoPlayer = UserManager.getOfflinePlayer(playerName);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
// If the mmoPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mmoPlayer == null) {
OfflinePlayer offlinePlayer = mcMMO.p.getServer().getOfflinePlayer(playerName);
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(offlinePlayer);
PlayerProfile profile = mcMMO.getDatabaseManager()
.loadPlayerProfile(offlinePlayer);
//Check loading by UUID
if (CommandUtils.unloadedProfile(sender, profile)) {
@@ -92,7 +94,7 @@ public class SkillresetCommand implements TabExecutor {
editValues(null, profile, skill);
} else {
editValues(mcMMOPlayer.getPlayer(), mcMMOPlayer.getProfile(), skill);
editValues(mmoPlayer.getPlayer(), mmoPlayer.getProfile(), skill);
}
handleSenderMessage(sender, playerName, skill);
@@ -104,13 +106,17 @@ public class SkillresetCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
switch (args.length) {
case 1:
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
case 2:
return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[1],
mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES,
new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
default:
return ImmutableList.of();
}
@@ -127,7 +133,8 @@ public class SkillresetCommand implements TabExecutor {
return;
}
EventUtils.tryLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false, XPGainReason.COMMAND);
EventUtils.tryLevelChangeEvent(player, skill, levelsRemoved, xpRemoved, false,
XPGainReason.COMMAND);
}
protected boolean permissionsCheckSelf(CommandSender sender) {
@@ -143,18 +150,21 @@ public class SkillresetCommand implements TabExecutor {
}
protected void handlePlayerMessageSkill(Player player, PrimarySkillType skill) {
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single", mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
player.sendMessage(LocaleLoader.getString("Commands.Reset.Single",
mcMMO.p.getSkillTools().getLocalizedSkillName(skill)));
}
private boolean validateArguments(CommandSender sender, String skillName) {
return skillName.equalsIgnoreCase("all") || !CommandUtils.isInvalidSkill(sender, skillName);
}
protected static void handleSenderMessage(CommandSender sender, String playerName, PrimarySkillType skill) {
protected static void handleSenderMessage(CommandSender sender, String playerName,
PrimarySkillType skill) {
if (skill == null) {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardAll.2", playerName));
} else {
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2", mcMMO.p.getSkillTools().getLocalizedSkillName(skill), playerName));
sender.sendMessage(LocaleLoader.getString("Commands.addlevels.AwardSkill.2",
mcMMO.p.getSkillTools().getLocalizedSkillName(skill), playerName));
}
}

View File

@@ -12,9 +12,10 @@ import org.jetbrains.annotations.NotNull;
public class PartyAcceptCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 1) {
Player player = (Player) sender;
final Player player = (Player) sender;
//Check if player profile is loaded
if (UserManager.getPlayer(player) == null) {
@@ -22,20 +23,20 @@ public class PartyAcceptCommand implements CommandExecutor {
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.hasPartyInvite()) {
if (!mmoPlayer.hasPartyInvite()) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
return true;
}
// Changing parties
if (!mcMMO.p.getPartyManager().changeOrJoinParty(mcMMOPlayer, mcMMOPlayer.getPartyInvite().getName())) {
if (!mcMMO.p.getPartyManager()
.changeOrJoinParty(mmoPlayer, mmoPlayer.getPartyInvite().getName())) {
return true;
}
mcMMO.p.getPartyManager().joinInvitedParty(mcMMOPlayer);
mcMMO.p.getPartyManager().joinInvitedParty(mmoPlayer);
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "accept"));

View File

@@ -14,7 +14,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyChangeOwnerCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {//Check if player profile is loaded
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
@@ -33,7 +34,8 @@ public class PartyChangeOwnerCommand implements CommandExecutor {
mcMMO.p.getPartyManager().setPartyLeader(target.getUniqueId(), playerParty);
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "owner", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "owner",
"<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}

View File

@@ -11,7 +11,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyChangePasswordCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
@@ -34,8 +35,10 @@ public class PartyChangePasswordCommand implements CommandExecutor {
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "password", "[clear|reset]"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "password", "<" + LocaleLoader.getString("Commands.Usage.Password") + ">"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "password",
"[clear|reset]"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "password",
"<" + LocaleLoader.getString("Commands.Usage.Password") + ">"));
return true;
}
}

View File

@@ -9,6 +9,10 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -17,15 +21,11 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class PartyCommand implements TabExecutor {
private final List<String> PARTY_SUBCOMMANDS;
private final List<String> XPSHARE_COMPLETIONS = ImmutableList.of("none", "equal");
private final List<String> ITEMSHARE_COMPLETIONS = ImmutableList.of("none", "equal", "random", "loot", "mining", "herbalism", "woodcutting", "misc");
private final List<String> ITEMSHARE_COMPLETIONS = ImmutableList.of("none", "equal", "random",
"loot", "mining", "herbalism", "woodcutting", "misc");
private final CommandExecutor partyJoinCommand;
private final CommandExecutor partyAcceptCommand;
private final CommandExecutor partyCreateCommand;
@@ -43,24 +43,25 @@ public class PartyCommand implements TabExecutor {
private final CommandExecutor partyHelpCommand;
private final CommandExecutor partyTeleportCommand;
private final CommandExecutor partyAllianceCommand;
public PartyCommand() {
partyJoinCommand = new PartyJoinCommand();
partyAcceptCommand = new PartyAcceptCommand();
partyCreateCommand = new PartyCreateCommand();
partyQuitCommand = new PartyQuitCommand();
partyXpShareCommand = new PartyXpShareCommand();
partyItemShareCommand = new PartyItemShareCommand();
partyInviteCommand = new PartyInviteCommand();
partyKickCommand = new PartyKickCommand();
partyDisbandCommand = new PartyDisbandCommand();
partyChangeOwnerCommand = new PartyChangeOwnerCommand();
partyLockCommand = new PartyLockCommand();
partyJoinCommand = new PartyJoinCommand();
partyAcceptCommand = new PartyAcceptCommand();
partyCreateCommand = new PartyCreateCommand();
partyQuitCommand = new PartyQuitCommand();
partyXpShareCommand = new PartyXpShareCommand();
partyItemShareCommand = new PartyItemShareCommand();
partyInviteCommand = new PartyInviteCommand();
partyKickCommand = new PartyKickCommand();
partyDisbandCommand = new PartyDisbandCommand();
partyChangeOwnerCommand = new PartyChangeOwnerCommand();
partyLockCommand = new PartyLockCommand();
partyChangePasswordCommand = new PartyChangePasswordCommand();
partyRenameCommand = new PartyRenameCommand();
partyInfoCommand = new PartyInfoCommand();
partyHelpCommand = new PartyHelpCommand();
partyTeleportCommand = new PtpCommand();
partyAllianceCommand = new PartyAllianceCommand();
partyRenameCommand = new PartyRenameCommand();
partyInfoCommand = new PartyInfoCommand();
partyHelpCommand = new PartyHelpCommand();
partyTeleportCommand = new PtpCommand();
partyAllianceCommand = new PartyAllianceCommand();
ArrayList<String> subcommands = new ArrayList<>();
@@ -73,7 +74,8 @@ public class PartyCommand implements TabExecutor {
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
@@ -83,21 +85,20 @@ public class PartyCommand implements TabExecutor {
return true;
}
Player player = (Player) sender;
final Player player = (Player) sender;
if (!UserManager.hasPlayerDataKey(player)) {
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (mcMMOPlayer == null) {
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (mmoPlayer == null) {
player.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
if (args.length < 1) {
if (!mcMMOPlayer.inParty()) {
if (!mmoPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return printUsage(player);
}
@@ -112,7 +113,8 @@ public class PartyCommand implements TabExecutor {
}
// Can't use this for lock/unlock since they're handled by the same command
if (subcommand != PartySubcommandType.LOCK && subcommand != PartySubcommandType.UNLOCK && !Permissions.partySubcommand(sender, subcommand)) {
if (subcommand != PartySubcommandType.LOCK && subcommand != PartySubcommandType.UNLOCK
&& !Permissions.partySubcommand(sender, subcommand)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
@@ -131,7 +133,7 @@ public class PartyCommand implements TabExecutor {
}
// Party member commands
if (!mcMMOPlayer.inParty()) {
if (!mmoPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return printUsage(player);
}
@@ -150,7 +152,7 @@ public class PartyCommand implements TabExecutor {
}
// Party leader commands
if (!mcMMOPlayer.getParty().getLeader().getUniqueId().equals(player.getUniqueId())) {
if (!mmoPlayer.getParty().getLeader().getUniqueId().equals(player.getUniqueId())) {
sender.sendMessage(LocaleLoader.getString("Party.NotOwner"));
return true;
}
@@ -170,10 +172,12 @@ public class PartyCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
switch (args.length) {
case 1:
return StringUtil.copyPartialMatches(args[0], PARTY_SUBCOMMANDS, new ArrayList<>(PARTY_SUBCOMMANDS.size()));
return StringUtil.copyPartialMatches(args[0], PARTY_SUBCOMMANDS,
new ArrayList<>(PARTY_SUBCOMMANDS.size()));
case 2:
PartySubcommandType subcommand = PartySubcommandType.getSubcommand(args[0]);
@@ -188,36 +192,46 @@ public class PartyCommand implements TabExecutor {
case INVITE:
case KICK:
case OWNER:
return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[1], playerNames,
new ArrayList<>(playerNames.size()));
case XPSHARE:
return StringUtil.copyPartialMatches(args[1], XPSHARE_COMPLETIONS, new ArrayList<>(XPSHARE_COMPLETIONS.size()));
return StringUtil.copyPartialMatches(args[1], XPSHARE_COMPLETIONS,
new ArrayList<>(XPSHARE_COMPLETIONS.size()));
case ITEMSHARE:
return StringUtil.copyPartialMatches(args[1], ITEMSHARE_COMPLETIONS, new ArrayList<>(ITEMSHARE_COMPLETIONS.size()));
return StringUtil.copyPartialMatches(args[1], ITEMSHARE_COMPLETIONS,
new ArrayList<>(ITEMSHARE_COMPLETIONS.size()));
case LOCK:
case CHAT:
return StringUtil.copyPartialMatches(args[1], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
return StringUtil.copyPartialMatches(args[1],
CommandUtils.TRUE_FALSE_OPTIONS,
new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
case PASSWORD:
return StringUtil.copyPartialMatches(args[1], CommandUtils.RESET_OPTIONS, new ArrayList<>(CommandUtils.RESET_OPTIONS.size()));
return StringUtil.copyPartialMatches(args[1], CommandUtils.RESET_OPTIONS,
new ArrayList<>(CommandUtils.RESET_OPTIONS.size()));
case TELEPORT:
List<String> matches = StringUtil.copyPartialMatches(args[1], PtpCommand.TELEPORT_SUBCOMMANDS, new ArrayList<>(PtpCommand.TELEPORT_SUBCOMMANDS.size()));
List<String> matches = StringUtil.copyPartialMatches(args[1],
PtpCommand.TELEPORT_SUBCOMMANDS,
new ArrayList<>(PtpCommand.TELEPORT_SUBCOMMANDS.size()));
if (matches.isEmpty()) {
Player player = (Player) sender;
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
//Not Loaded
if (mcMMOPlayer == null) {
if (mmoPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return ImmutableList.of();
}
if (mcMMOPlayer.getParty() == null)
if (mmoPlayer.getParty() == null) {
return ImmutableList.of();
}
final Party party = mcMMOPlayer.getParty();
final Party party = mmoPlayer.getParty();
playerNames = party.getOnlinePlayerNames(player);
return StringUtil.copyPartialMatches(args[1], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[1], playerNames,
new ArrayList<>(playerNames.size()));
}
return matches;
@@ -225,8 +239,10 @@ public class PartyCommand implements TabExecutor {
return ImmutableList.of();
}
case 3:
if (PartySubcommandType.getSubcommand(args[0]) == PartySubcommandType.ITEMSHARE && isItemShareCategory(args[1])) {
return StringUtil.copyPartialMatches(args[2], CommandUtils.TRUE_FALSE_OPTIONS, new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
if (PartySubcommandType.getSubcommand(args[0]) == PartySubcommandType.ITEMSHARE
&& isItemShareCategory(args[1])) {
return StringUtil.copyPartialMatches(args[2], CommandUtils.TRUE_FALSE_OPTIONS,
new ArrayList<>(CommandUtils.TRUE_FALSE_OPTIONS.size()));
}
return ImmutableList.of();
@@ -247,7 +263,9 @@ public class PartyCommand implements TabExecutor {
}
private boolean isItemShareCategory(String category) {
return category.equalsIgnoreCase("loot") || category.equalsIgnoreCase("mining") || category.equalsIgnoreCase("herbalism") || category.equalsIgnoreCase("woodcutting") || category.equalsIgnoreCase("misc");
return category.equalsIgnoreCase("loot") || category.equalsIgnoreCase("mining")
|| category.equalsIgnoreCase("herbalism") || category.equalsIgnoreCase(
"woodcutting") || category.equalsIgnoreCase("misc");
}
}

View File

@@ -12,12 +12,13 @@ import org.jetbrains.annotations.NotNull;
public class PartyCreateCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 2:
case 3:
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (UserManager.getPlayer(player) == null) {
player.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
@@ -30,15 +31,17 @@ public class PartyCreateCommand implements CommandExecutor {
}
// Changing parties
if (!mcMMO.p.getPartyManager().changeOrJoinParty(mcMMOPlayer, args[1])) {
if (!mcMMO.p.getPartyManager().changeOrJoinParty(mmoPlayer, args[1])) {
return true;
}
mcMMO.p.getPartyManager().createParty(mcMMOPlayer, args[1], getPassword(args));
mcMMO.p.getPartyManager().createParty(mmoPlayer, args[1], getPassword(args));
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "create", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "create",
"<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">",
"[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
return true;
}
}

View File

@@ -14,26 +14,28 @@ import org.jetbrains.annotations.NotNull;
public class PartyDisbandCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 1) {
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
if (mcMMOPlayer == null) {
final McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender);
if (mmoPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
final Party playerParty = mcMMOPlayer.getParty();
final Party playerParty = mmoPlayer.getParty();
final String partyName = playerParty.getName();
for (Player member : playerParty.getOnlineMembers()) {
if (!mcMMO.p.getPartyManager().handlePartyChangeEvent(member, partyName, null, EventReason.KICKED_FROM_PARTY)) {
if (!mcMMO.p.getPartyManager().handlePartyChangeEvent(member, partyName, null,
EventReason.KICKED_FROM_PARTY)) {
return true;
}
member.sendMessage(LocaleLoader.getString("Party.Disband"));
}
mcMMO.p.getPartyManager().disbandParty(mcMMOPlayer, playerParty);
mcMMO.p.getPartyManager().disbandParty(mmoPlayer, playerParty);
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.1", "party", "disband"));

View File

@@ -9,9 +9,11 @@ import org.jetbrains.annotations.NotNull;
public class PartyHelpCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 1) {
sender.sendMessage(LocaleLoader.getString("Party.Help.3", "/party join", "/party quit"));
sender.sendMessage(
LocaleLoader.getString("Party.Help.3", "/party join", "/party quit"));
sender.sendMessage(LocaleLoader.getString("Party.Help.1", "/party create"));
sender.sendMessage(LocaleLoader.getString("Party.Help.4", "/party <lock|unlock>"));
sender.sendMessage(LocaleLoader.getString("Party.Help.5", "/party password"));

View File

@@ -7,6 +7,8 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -14,12 +16,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class PartyInfoCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 0:
case 1:
@@ -27,14 +27,14 @@ public class PartyInfoCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party party = mcMMOPlayer.getParty();
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
Party party = mmoPlayer.getParty();
displayPartyHeader(player, party);
displayShareModeInfo(player, party);
displayPartyFeatures(player, party);
displayMemberInfo(player, mcMMOPlayer, party);
displayMemberInfo(player, mmoPlayer, party);
return true;
default:
@@ -47,7 +47,10 @@ public class PartyInfoCommand implements CommandExecutor {
player.sendMessage(LocaleLoader.getString("Commands.Party.Header"));
StringBuilder status = new StringBuilder();
status.append(LocaleLoader.getString("Commands.Party.Status", party.getName(), LocaleLoader.getString("Party.Status." + (party.isLocked() ? "Locked" : "Unlocked")), party.getLevel()));
status.append(LocaleLoader.getString("Commands.Party.Status", party.getName(),
LocaleLoader.getString(
"Party.Status." + (party.isLocked() ? "Locked" : "Unlocked")),
party.getLevel()));
if (!party.hasReachedLevelCap()) {
status.append(" (").append(party.getXpToLevelPercentage()).append(")");
@@ -74,7 +77,8 @@ public class PartyInfoCommand implements CommandExecutor {
}
}
player.sendMessage(LocaleLoader.getString("Commands.Party.UnlockedFeatures", unlockedPartyFeatures.isEmpty() ? "None" : unlockedPartyFeatures));
player.sendMessage(LocaleLoader.getString("Commands.Party.UnlockedFeatures",
unlockedPartyFeatures.isEmpty() ? "None" : unlockedPartyFeatures));
for (String message : lockedPartyFeatures) {
player.sendMessage(message);
@@ -82,7 +86,8 @@ public class PartyInfoCommand implements CommandExecutor {
}
private boolean isUnlockedFeature(Party party, PartyFeature partyFeature) {
return party.getLevel() >= mcMMO.p.getGeneralConfig().getPartyFeatureUnlockLevel(partyFeature);
return party.getLevel() >= mcMMO.p.getGeneralConfig()
.getPartyFeatureUnlockLevel(partyFeature);
}
private void displayShareModeInfo(Player player, Party party) {
@@ -99,34 +104,41 @@ public class PartyInfoCommand implements CommandExecutor {
String separator = "";
if (xpShareEnabled) {
expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare", party.getXpShareMode().toString());
expShareInfo = LocaleLoader.getString("Commands.Party.ExpShare",
party.getXpShareMode().toString());
}
if (itemShareEnabled) {
itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare", party.getItemShareMode().toString());
itemShareInfo = LocaleLoader.getString("Commands.Party.ItemShare",
party.getItemShareMode().toString());
}
if (xpShareEnabled && itemShareEnabled) {
separator = ChatColor.DARK_GRAY + " || ";
}
player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo);
player.sendMessage(
LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator
+ itemShareInfo);
if (itemSharingActive) {
player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", party.getItemShareCategories()));
player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories",
party.getItemShareCategories()));
}
}
private void displayMemberInfo(Player player, McMMOPlayer mcMMOPlayer, Party party) {
private void displayMemberInfo(Player player, McMMOPlayer mmoPlayer, Party party) {
/*
* Only show members of the party that this member can see
*/
List<Player> nearMembers = mcMMO.p.getPartyManager().getNearVisibleMembers(mcMMOPlayer);
List<Player> nearMembers = mcMMO.p.getPartyManager().getNearVisibleMembers(mmoPlayer);
int membersOnline = party.getVisibleMembers(player).size();
player.sendMessage(LocaleLoader.getString("Commands.Party.Members.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.MembersNear", nearMembers.size()+1, membersOnline));
player.sendMessage(
LocaleLoader.getString("Commands.Party.MembersNear", nearMembers.size() + 1,
membersOnline));
player.sendMessage(party.createMembersList(player));
}
}

View File

@@ -14,7 +14,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyInviteCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
String targetName = CommandUtils.getMatchedPlayerName(args[1]);
McMMOPlayer mcMMOTarget = UserManager.getOfflinePlayer(targetName);
@@ -30,8 +31,8 @@ public class PartyInviteCommand implements CommandExecutor {
return true;
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
String playerName = player.getName();
if (player.equals(target)) {
@@ -44,26 +45,32 @@ public class PartyInviteCommand implements CommandExecutor {
return true;
}
if (!mcMMO.p.getPartyManager().canInvite(mcMMOPlayer)) {
if (!mcMMO.p.getPartyManager().canInvite(mmoPlayer)) {
player.sendMessage(LocaleLoader.getString("Party.Locked"));
return true;
}
Party playerParty = mcMMOPlayer.getParty();
Party playerParty = mmoPlayer.getParty();
if (mcMMO.p.getPartyManager().isPartyFull(target, playerParty)) {
player.sendMessage(LocaleLoader.getString("Commands.Party.PartyFull.Invite", target.getName(), playerParty.toString(), mcMMO.p.getGeneralConfig().getPartyMaxSize()));
player.sendMessage(
LocaleLoader.getString("Commands.Party.PartyFull.Invite", target.getName(),
playerParty.toString(),
mcMMO.p.getGeneralConfig().getPartyMaxSize()));
return true;
}
mcMMOTarget.setPartyInvite(playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.0", playerParty.getName(), playerName));
target.sendMessage(
LocaleLoader.getString("Commands.Party.Invite.0", playerParty.getName(),
playerName));
target.sendMessage(LocaleLoader.getString("Commands.Party.Invite.1"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "invite",
"<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}

View File

@@ -9,17 +9,17 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.text.StringUtils;
import java.util.Locale;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class PartyItemShareCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
@@ -27,7 +27,8 @@ public class PartyItemShareCommand implements CommandExecutor {
Party party = UserManager.getPlayer((Player) sender).getParty();
if (party.getLevel() < mcMMO.p.getGeneralConfig().getPartyFeatureUnlockLevel(PartyFeature.ITEM_SHARE)) {
if (party.getLevel() < mcMMO.p.getGeneralConfig()
.getPartyFeatureUnlockLevel(PartyFeature.ITEM_SHARE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.4"));
return true;
}
@@ -37,7 +38,9 @@ public class PartyItemShareCommand implements CommandExecutor {
ShareMode mode = ShareMode.getShareMode(args[1].toUpperCase(Locale.ENGLISH));
if (mode == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
sender.sendMessage(
LocaleLoader.getString("Commands.Usage.2", "party", "itemshare",
"<NONE | EQUAL | RANDOM>"));
return true;
}
@@ -52,22 +55,28 @@ public class PartyItemShareCommand implements CommandExecutor {
} else if (CommandUtils.shouldDisableToggle(args[2])) {
toggle = false;
} else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting | misc> <true | false>"));
sender.sendMessage(
LocaleLoader.getString("Commands.Usage.2", "party", "itemshare",
"<loot | mining | herbalism | woodcutting | misc> <true | false>"));
return true;
}
try {
handleToggleItemShareCategory(party, ItemShareType.valueOf(args[1].toUpperCase(Locale.ENGLISH)), toggle);
}
catch (IllegalArgumentException ex) {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting | misc> <true | false>"));
handleToggleItemShareCategory(party,
ItemShareType.valueOf(args[1].toUpperCase(Locale.ENGLISH)), toggle);
} catch (IllegalArgumentException ex) {
sender.sendMessage(
LocaleLoader.getString("Commands.Usage.2", "party", "itemshare",
"<loot | mining | herbalism | woodcutting | misc> <true | false>"));
}
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<NONE | EQUAL | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "<loot | mining | herbalism | woodcutting | misc> <true | false>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare",
"<NONE | EQUAL | RANDOM>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare",
"<loot | mining | herbalism | woodcutting | misc> <true | false>"));
return true;
}
}
@@ -75,7 +84,9 @@ public class PartyItemShareCommand implements CommandExecutor {
private void handleChangingShareMode(Party party, ShareMode mode) {
party.setItemShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing",
LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString(
"Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
for (Player member : party.getOnlineMembers()) {
member.sendMessage(changeModeMessage);
@@ -85,7 +96,8 @@ public class PartyItemShareCommand implements CommandExecutor {
private void handleToggleItemShareCategory(Party party, ItemShareType type, boolean toggle) {
party.setSharingDrops(type, toggle);
String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(type.toString()), toggle ? "enabled" : "disabled");
String toggleMessage = LocaleLoader.getString("Commands.Party.ToggleShareCategory",
StringUtils.getCapitalized(type.toString()), toggle ? "enabled" : "disabled");
for (Player member : party.getOnlineMembers()) {
member.sendMessage(toggleMessage);

View File

@@ -14,7 +14,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyJoinCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 2:
case 3:
@@ -28,21 +29,23 @@ public class PartyJoinCommand implements CommandExecutor {
Player target = mcMMOTarget.getPlayer();
if (!mcMMOTarget.inParty()) {
sender.sendMessage(LocaleLoader.getString("Party.PlayerNotInParty", targetName));
sender.sendMessage(
LocaleLoader.getString("Party.PlayerNotInParty", targetName));
return true;
}
Player player = (Player) sender;
final Player player = (Player) sender;
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
Party targetParty = mcMMOTarget.getParty();
if (player.equals(target) || (mcMMOPlayer.inParty() && mcMMOPlayer.getParty().equals(targetParty))) {
if (player.equals(target) || (mmoPlayer.inParty() && mmoPlayer.getParty()
.equals(targetParty))) {
sender.sendMessage(LocaleLoader.getString("Party.Join.Self"));
return true;
}
@@ -57,21 +60,24 @@ public class PartyJoinCommand implements CommandExecutor {
String partyName = targetParty.getName();
// Changing parties
if (!mcMMO.p.getPartyManager().changeOrJoinParty(mcMMOPlayer, partyName)) {
if (!mcMMO.p.getPartyManager().changeOrJoinParty(mmoPlayer, partyName)) {
return true;
}
if (mcMMO.p.getPartyManager().isPartyFull(player, targetParty)) {
player.sendMessage(LocaleLoader.getString("Commands.Party.PartyFull", targetParty.toString()));
player.sendMessage(LocaleLoader.getString("Commands.Party.PartyFull",
targetParty.toString()));
return true;
}
player.sendMessage(LocaleLoader.getString("Commands.Party.Join", partyName));
mcMMO.p.getPartyManager().addToParty(mcMMOPlayer, targetParty);
mcMMO.p.getPartyManager().addToParty(mmoPlayer, targetParty);
return true;
default:
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "join", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">", "[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "join",
"<" + LocaleLoader.getString("Commands.Usage.Player") + ">",
"[" + LocaleLoader.getString("Commands.Usage.Password") + "]"));
return true;
}
}

View File

@@ -15,7 +15,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyKickCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
@@ -36,7 +37,8 @@ public class PartyKickCommand implements CommandExecutor {
Player onlineTarget = target.getPlayer();
String partyName = playerParty.getName();
if (!mcMMO.p.getPartyManager().handlePartyChangeEvent(onlineTarget, partyName, null, EventReason.KICKED_FROM_PARTY)) {
if (!mcMMO.p.getPartyManager().handlePartyChangeEvent(onlineTarget, partyName, null,
EventReason.KICKED_FROM_PARTY)) {
return true;
}
@@ -47,7 +49,8 @@ public class PartyKickCommand implements CommandExecutor {
mcMMO.p.getPartyManager().removeFromParty(target, playerParty);
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "kick",
"<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}

View File

@@ -13,7 +13,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyLockCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 1:
if (args[0].equalsIgnoreCase("lock")) {
@@ -59,13 +60,15 @@ public class PartyLockCommand implements CommandExecutor {
Party party = UserManager.getPlayer((Player) sender).getParty();
if (!Permissions.partySubcommand(sender, lock ? PartySubcommandType.LOCK : PartySubcommandType.UNLOCK)) {
if (!Permissions.partySubcommand(sender,
lock ? PartySubcommandType.LOCK : PartySubcommandType.UNLOCK)) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoPermission"));
return;
}
if (lock == party.isLocked()) {
sender.sendMessage(LocaleLoader.getString("Party." + (lock ? "IsLocked" : "IsntLocked")));
sender.sendMessage(
LocaleLoader.getString("Party." + (lock ? "IsLocked" : "IsntLocked")));
return;
}

View File

@@ -14,23 +14,26 @@ import org.jetbrains.annotations.NotNull;
public class PartyQuitCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 1) {
Player player = (Player) sender;
final Player player = (Player) sender;
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party playerParty = mcMMOPlayer.getParty();
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
Party playerParty = mmoPlayer.getParty();
if (!mcMMO.p.getPartyManager().handlePartyChangeEvent(player, playerParty.getName(), null, EventReason.LEFT_PARTY)) {
if (!mcMMO.p.getPartyManager()
.handlePartyChangeEvent(player, playerParty.getName(), null,
EventReason.LEFT_PARTY)) {
return true;
}
mcMMO.p.getPartyManager().removeFromParty(mcMMOPlayer);
mcMMO.p.getPartyManager().removeFromParty(mmoPlayer);
sender.sendMessage(LocaleLoader.getString("Commands.Party.Leave"));
return true;
}

View File

@@ -14,15 +14,16 @@ import org.jetbrains.annotations.NotNull;
public class PartyRenameCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender);
Party playerParty = mcMMOPlayer.getParty();
final McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender);
Party playerParty = mmoPlayer.getParty();
String oldPartyName = playerParty.getName();
String newPartyName = args[1].replace(".", "");
@@ -33,7 +34,7 @@ public class PartyRenameCommand implements CommandExecutor {
return true;
}
Player player = mcMMOPlayer.getPlayer();
Player player = mmoPlayer.getPlayer();
// Check to see if the party exists, and if it does cancel renaming the party
if (mcMMO.p.getPartyManager().checkPartyExistence(player, newPartyName)) {
@@ -43,12 +44,16 @@ public class PartyRenameCommand implements CommandExecutor {
String leaderName = playerParty.getLeader().getPlayerName();
for (Player member : playerParty.getOnlineMembers()) {
if (!mcMMO.p.getPartyManager().handlePartyChangeEvent(member, oldPartyName, newPartyName, EventReason.CHANGED_PARTIES)) {
if (!mcMMO.p.getPartyManager()
.handlePartyChangeEvent(member, oldPartyName, newPartyName,
EventReason.CHANGED_PARTIES)) {
return true;
}
if (!member.getName().equalsIgnoreCase(leaderName)) {
member.sendMessage(LocaleLoader.getString("Party.InformedOnNameChange", leaderName, newPartyName));
member.sendMessage(
LocaleLoader.getString("Party.InformedOnNameChange", leaderName,
newPartyName));
}
}
@@ -57,7 +62,8 @@ public class PartyRenameCommand implements CommandExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.Party.Rename", newPartyName));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "rename", "<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "rename",
"<" + LocaleLoader.getString("Commands.Usage.PartyName") + ">"));
return true;
}
}

View File

@@ -34,9 +34,11 @@ public enum PartySubcommandType {
return QUIT;
} else if (commandName.equalsIgnoreCase("leader")) {
return OWNER;
} else if (commandName.equalsIgnoreCase("xpshare") || commandName.equalsIgnoreCase("shareexp") || commandName.equalsIgnoreCase("sharexp")) {
} else if (commandName.equalsIgnoreCase("xpshare") || commandName.equalsIgnoreCase(
"shareexp") || commandName.equalsIgnoreCase("sharexp")) {
return XPSHARE;
} else if (commandName.equalsIgnoreCase("shareitem") || commandName.equalsIgnoreCase("shareitems")) {
} else if (commandName.equalsIgnoreCase("shareitem") || commandName.equalsIgnoreCase(
"shareitems")) {
return ITEMSHARE;
} else if (commandName.equalsIgnoreCase("ally")) {
return ALLIANCE;

View File

@@ -16,7 +16,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyXpShareCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
@@ -24,7 +25,8 @@ public class PartyXpShareCommand implements CommandExecutor {
Party party = UserManager.getPlayer((Player) sender).getParty();
if (party.getLevel() < mcMMO.p.getGeneralConfig().getPartyFeatureUnlockLevel(PartyFeature.XP_SHARE)) {
if (party.getLevel() < mcMMO.p.getGeneralConfig()
.getPartyFeatureUnlockLevel(PartyFeature.XP_SHARE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.5"));
return true;
}
@@ -32,22 +34,27 @@ public class PartyXpShareCommand implements CommandExecutor {
if (args.length == 2) {
if (args[1].equalsIgnoreCase("none") || CommandUtils.shouldDisableToggle(args[1])) {
handleChangingShareMode(party, ShareMode.NONE);
} else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even") || CommandUtils.shouldEnableToggle(args[1])) {
} else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")
|| CommandUtils.shouldEnableToggle(args[1])) {
handleChangingShareMode(party, ShareMode.EQUAL);
} else {
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "xpshare", "<NONE | EQUAL>"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "xpshare",
"<NONE | EQUAL>"));
}
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "xpshare", "<NONE | EQUAL>"));
sender.sendMessage(
LocaleLoader.getString("Commands.Usage.2", "party", "xpshare", "<NONE | EQUAL>"));
return true;
}
private void handleChangingShareMode(Party party, ShareMode mode) {
party.setXpShareMode(mode);
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Xp"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
String changeModeMessage = LocaleLoader.getString("Commands.Party.SetSharing",
LocaleLoader.getString("Party.ShareType.Xp"), LocaleLoader.getString(
"Party.ShareMode." + StringUtils.getCapitalized(mode.toString())));
for (Player member : party.getOnlineMembers()) {
member.sendMessage(changeModeMessage);

View File

@@ -12,29 +12,31 @@ import org.jetbrains.annotations.NotNull;
public class PartyAllianceAcceptCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.hasPartyAllianceInvite()) {
if (!mmoPlayer.hasPartyAllianceInvite()) {
sender.sendMessage(LocaleLoader.getString("mcMMO.NoInvites"));
return true;
}
if (mcMMOPlayer.getParty().getAlly() != null) {
if (mmoPlayer.getParty().getAlly() != null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.AlreadyAllies"));
return true;
}
mcMMO.p.getPartyManager().acceptAllianceInvite(mcMMOPlayer);
mcMMO.p.getPartyManager().acceptAllianceInvite(mmoPlayer);
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "alliance", "accept"));
sender.sendMessage(
LocaleLoader.getString("Commands.Usage.2", "party", "alliance", "accept"));
return true;
}
}

View File

@@ -8,6 +8,8 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -17,22 +19,21 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class PartyAllianceCommand implements TabExecutor {
private Player player;
private Party playerParty;
private Party targetParty;
public static final List<String> ALLIANCE_SUBCOMMANDS = ImmutableList.of("invite", "accept", "disband");
public static final List<String> ALLIANCE_SUBCOMMANDS = ImmutableList.of("invite", "accept",
"disband");
private final CommandExecutor partyAllianceInviteCommand = new PartyAllianceInviteCommand();
private final CommandExecutor partyAllianceAcceptCommand = new PartyAllianceAcceptCommand();
private final CommandExecutor partyAllianceDisbandCommand = new PartyAllianceDisbandCommand();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
@@ -43,13 +44,14 @@ public class PartyAllianceCommand implements TabExecutor {
}
player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
playerParty = mcMMOPlayer.getParty();
playerParty = mmoPlayer.getParty();
switch (args.length) {
case 1:
if (playerParty.getLevel() < mcMMO.p.getGeneralConfig().getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
if (playerParty.getLevel() < mcMMO.p.getGeneralConfig()
.getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.3"));
return true;
}
@@ -62,12 +64,13 @@ public class PartyAllianceCommand implements TabExecutor {
targetParty = playerParty.getAlly();
displayPartyHeader();
displayMemberInfo(mcMMOPlayer);
displayMemberInfo(mmoPlayer);
return true;
case 2:
case 3:
if (playerParty.getLevel() < mcMMO.p.getGeneralConfig().getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
if (playerParty.getLevel() < mcMMO.p.getGeneralConfig()
.getPartyFeatureUnlockLevel(PartyFeature.ALLIANCE)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.3"));
return true;
}
@@ -92,7 +95,7 @@ public class PartyAllianceCommand implements TabExecutor {
targetParty = playerParty.getAlly();
displayPartyHeader();
displayMemberInfo(mcMMOPlayer);
displayMemberInfo(mmoPlayer);
return true;
default:
@@ -107,13 +110,16 @@ public class PartyAllianceCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String label, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender commandSender,
@NotNull Command command, @NotNull String label, String[] args) {
if (args.length == 1) {
List<String> matches = StringUtil.copyPartialMatches(args[0], ALLIANCE_SUBCOMMANDS, new ArrayList<>(ALLIANCE_SUBCOMMANDS.size()));
List<String> matches = StringUtil.copyPartialMatches(args[0], ALLIANCE_SUBCOMMANDS,
new ArrayList<>(ALLIANCE_SUBCOMMANDS.size()));
if (matches.size() == 0) {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(commandSender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
}
return matches;
@@ -123,11 +129,13 @@ public class PartyAllianceCommand implements TabExecutor {
private void displayPartyHeader() {
player.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Header"));
player.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Ally", playerParty.getName(), targetParty.getName()));
player.sendMessage(
LocaleLoader.getString("Commands.Party.Alliance.Ally", playerParty.getName(),
targetParty.getName()));
}
private void displayMemberInfo(McMMOPlayer mcMMOPlayer) {
List<Player> nearMembers = mcMMO.p.getPartyManager().getNearMembers(mcMMOPlayer);
private void displayMemberInfo(McMMOPlayer mmoPlayer) {
List<Player> nearMembers = mcMMO.p.getPartyManager().getNearMembers(mmoPlayer);
player.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Members.Header"));
player.sendMessage(playerParty.createMembersList(player));
player.sendMessage(ChatColor.DARK_GRAY + "----------------------------");

View File

@@ -13,15 +13,16 @@ import org.jetbrains.annotations.NotNull;
public class PartyAllianceDisbandCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 2) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
Party party = mcMMOPlayer.getParty();
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
Party party = mmoPlayer.getParty();
if (party.getAlly() == null) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.None"));
@@ -31,7 +32,8 @@ public class PartyAllianceDisbandCommand implements CommandExecutor {
mcMMO.p.getPartyManager().disbandAlliance(player, party, party.getAlly());
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "alliance", "disband"));
sender.sendMessage(
LocaleLoader.getString("Commands.Usage.2", "party", "alliance", "disband"));
return true;
}
}

View File

@@ -14,7 +14,8 @@ import org.jetbrains.annotations.NotNull;
public class PartyAllianceInviteCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 3) {
String targetName = CommandUtils.getMatchedPlayerName(args[2]);
McMMOPlayer mcMMOTarget = UserManager.getOfflinePlayer(targetName);
@@ -30,8 +31,8 @@ public class PartyAllianceInviteCommand implements CommandExecutor {
return true;
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final Player player = (Player) sender;
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
String playerName = player.getName();
if (player.equals(target)) {
@@ -54,7 +55,7 @@ public class PartyAllianceInviteCommand implements CommandExecutor {
return true;
}
Party playerParty = mcMMOPlayer.getParty();
Party playerParty = mmoPlayer.getParty();
if (playerParty.getAlly() != null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.AlreadyAllies"));
@@ -64,11 +65,13 @@ public class PartyAllianceInviteCommand implements CommandExecutor {
mcMMOTarget.setPartyAllianceInvite(playerParty);
sender.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Invite.0", playerParty.getName(), playerName));
target.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Invite.0",
playerParty.getName(), playerName));
target.sendMessage(LocaleLoader.getString("Commands.Party.Alliance.Invite.1"));
return true;
}
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "alliance", "invite", "<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
sender.sendMessage(LocaleLoader.getString("Commands.Usage.3", "party", "alliance", "invite",
"<" + LocaleLoader.getString("Commands.Usage.Player") + ">"));
return true;
}
}

View File

@@ -11,13 +11,15 @@ import org.jetbrains.annotations.NotNull;
public class PtpAcceptAnyCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (!Permissions.partyTeleportAcceptAll(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord();
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName())
.getPartyTeleportRecord();
if (ptpRecord.isConfirmRequired()) {
sender.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled"));

View File

@@ -15,7 +15,8 @@ import org.jetbrains.annotations.NotNull;
public class PtpAcceptCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (!Permissions.partyTeleportAccept(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
@@ -26,7 +27,7 @@ public class PtpAcceptCommand implements CommandExecutor {
return true;
}
Player player = (Player) sender;
final Player player = (Player) sender;
PartyTeleportRecord ptpRecord = UserManager.getPlayer(player).getPartyTeleportRecord();
if (!ptpRecord.hasRequest()) {
@@ -34,7 +35,8 @@ public class PtpAcceptCommand implements CommandExecutor {
return true;
}
if (SkillUtils.cooldownExpired(ptpRecord.getTimeout(), mcMMO.p.getGeneralConfig().getPTPCommandTimeout())) {
if (SkillUtils.cooldownExpired(ptpRecord.getTimeout(),
mcMMO.p.getGeneralConfig().getPTPCommandTimeout())) {
ptpRecord.removeRequest();
player.sendMessage(LocaleLoader.getString("Commands.ptp.RequestExpired"));
return true;
@@ -53,10 +55,13 @@ public class PtpAcceptCommand implements CommandExecutor {
if (!Permissions.partyTeleportAllWorlds(target)) {
if (!Permissions.partyTeleportWorld(target, targetWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", targetWorld.getName()));
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions",
targetWorld.getName()));
return true;
} else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(target, playerWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", playerWorld.getName()));
} else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(target,
playerWorld)) {
target.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions",
playerWorld.getName()));
return true;
}
}

View File

@@ -17,6 +17,8 @@ import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -26,172 +28,15 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class PtpCommand implements TabExecutor {
public static final List<String> TELEPORT_SUBCOMMANDS = ImmutableList.of("toggle", "accept", "acceptany", "acceptall");
public static final List<String> TELEPORT_SUBCOMMANDS = ImmutableList.of("toggle", "accept",
"acceptany",
"acceptall");
private final CommandExecutor ptpToggleCommand = new PtpToggleCommand();
private final CommandExecutor ptpAcceptAnyCommand = new PtpAcceptAnyCommand();
private final CommandExecutor ptpAcceptCommand = new PtpAcceptCommand();
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
Player player = (Player) sender;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (!WorldGuardManager.getInstance().hasMainFlag(player))
return true;
}
/* WORLD BLACKLIST CHECK */
if (WorldBlacklist.isWorldBlacklisted(player.getWorld()))
return true;
if (!UserManager.hasPlayerDataKey(player)) {
return true;
}
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
Party party = mcMMOPlayer.getParty();
if (party.getLevel() < mcMMO.p.getGeneralConfig().getPartyFeatureUnlockLevel(PartyFeature.TELEPORT)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.2"));
return true;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("toggle")) {
return ptpToggleCommand.onCommand(sender, command, label, args);
}
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
return ptpAcceptAnyCommand.onCommand(sender, command, label, args);
}
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
int hurtCooldown = mcMMO.p.getGeneralConfig().getPTPCommandRecentlyHurtCooldown();
if (hurtCooldown > 0) {
int timeRemaining = SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, hurtCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
return true;
}
}
if (args[0].equalsIgnoreCase("accept")) {
return ptpAcceptCommand.onCommand(sender, command, label, args);
}
if (!Permissions.partyTeleportSend(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
int ptpCooldown = mcMMO.p.getGeneralConfig().getPTPCommandCooldown();
long ptpLastUse = mcMMOPlayer.getPartyTeleportRecord().getLastUse();
if (ptpCooldown > 0) {
int timeRemaining = SkillUtils.calculateTimeLeft(ptpLastUse * Misc.TIME_CONVERSION_FACTOR, ptpCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
return true;
}
}
sendTeleportRequest(sender, player, CommandUtils.getMatchedPlayerName(args[0]));
return true;
}
return false;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> matches = StringUtil.copyPartialMatches(args[0], TELEPORT_SUBCOMMANDS, new ArrayList<>(TELEPORT_SUBCOMMANDS.size()));
if (matches.size() == 0) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return ImmutableList.of();
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.inParty()) {
return ImmutableList.of();
}
List<String> playerNames = mcMMOPlayer.getParty().getOnlinePlayerNames(player);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
}
return matches;
}
return ImmutableList.of();
}
private void sendTeleportRequest(CommandSender sender, Player player, String targetName) {
if (!canTeleport(sender, player, targetName)) {
return;
}
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName);
Player target = mcMMOTarget.getPlayer();
if (mcMMO.p.getGeneralConfig().getPTPCommandWorldPermissions()) {
World targetWorld = target.getWorld();
World playerWorld = player.getWorld();
if (!Permissions.partyTeleportAllWorlds(player)) {
if (!Permissions.partyTeleportWorld(target, targetWorld)) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", targetWorld.getName()));
return;
} else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(player, targetWorld)) {
player.sendMessage(LocaleLoader.getString("Commands.ptp.NoWorldPermissions", targetWorld.getName()));
return;
}
}
}
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
if (!ptpRecord.isConfirmRequired()) {
handleTeleportWarmup(player, target);
return;
}
ptpRecord.setRequestor(player);
ptpRecord.actualizeTimeout();
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request1", player.getName()));
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request2", mcMMO.p.getGeneralConfig().getPTPCommandTimeout()));
}
protected static boolean canTeleport(CommandSender sender, Player player, String targetName) {
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName);
@@ -244,9 +89,185 @@ public class PtpCommand implements TabExecutor {
if (warmup > 0) {
teleportingPlayer.sendMessage(LocaleLoader.getString("Teleport.Commencing", warmup));
mcMMO.p.getFoliaLib().getScheduler().runAtEntityLater(teleportingPlayer, new TeleportationWarmup(mcMMOPlayer, mcMMOTarget), 20 * warmup);
mcMMO.p.getFoliaLib().getScheduler().runAtEntityLater(teleportingPlayer,
new TeleportationWarmup(mcMMOPlayer, mcMMOTarget), 20 * warmup);
} else {
EventUtils.handlePartyTeleportEvent(teleportingPlayer, targetPlayer);
}
}
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label,
String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
Player player = (Player) sender;
/* WORLD GUARD MAIN FLAG CHECK */
if (WorldGuardUtils.isWorldGuardLoaded()) {
if (!WorldGuardManager.getInstance().hasMainFlag(player)) {
return true;
}
}
/* WORLD BLACKLIST CHECK */
if (WorldBlacklist.isWorldBlacklisted(player.getWorld())) {
return true;
}
if (!UserManager.hasPlayerDataKey(player)) {
return true;
}
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.inParty()) {
sender.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return true;
}
Party party = mcMMOPlayer.getParty();
if (party.getLevel() < mcMMO.p.getGeneralConfig()
.getPartyFeatureUnlockLevel(PartyFeature.TELEPORT)) {
sender.sendMessage(LocaleLoader.getString("Party.Feature.Disabled.2"));
return true;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("toggle")) {
return ptpToggleCommand.onCommand(sender, command, label, args);
}
if (args[0].equalsIgnoreCase("acceptany") || args[0].equalsIgnoreCase("acceptall")) {
return ptpAcceptAnyCommand.onCommand(sender, command, label, args);
}
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
int hurtCooldown = mcMMO.p.getGeneralConfig().getPTPCommandRecentlyHurtCooldown();
if (hurtCooldown > 0) {
int timeRemaining = SkillUtils.calculateTimeLeft(
recentlyHurt * Misc.TIME_CONVERSION_FACTOR,
hurtCooldown, player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", timeRemaining));
return true;
}
}
if (args[0].equalsIgnoreCase("accept")) {
return ptpAcceptCommand.onCommand(sender, command, label, args);
}
if (!Permissions.partyTeleportSend(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
int ptpCooldown = mcMMO.p.getGeneralConfig().getPTPCommandCooldown();
long ptpLastUse = mcMMOPlayer.getPartyTeleportRecord().getLastUse();
if (ptpCooldown > 0) {
int timeRemaining = SkillUtils.calculateTimeLeft(
ptpLastUse * Misc.TIME_CONVERSION_FACTOR, ptpCooldown,
player);
if (timeRemaining > 0) {
player.sendMessage(LocaleLoader.getString("Item.Generic.Wait", timeRemaining));
return true;
}
}
sendTeleportRequest(sender, player, CommandUtils.getMatchedPlayerName(args[0]));
return true;
}
return false;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias,
String[] args) {
if (args.length == 1) {
List<String> matches = StringUtil.copyPartialMatches(args[0], TELEPORT_SUBCOMMANDS,
new ArrayList<>(TELEPORT_SUBCOMMANDS.size()));
if (matches.size() == 0) {
if (UserManager.getPlayer((Player) sender) == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return ImmutableList.of();
}
Player player = (Player) sender;
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (!mcMMOPlayer.inParty()) {
return ImmutableList.of();
}
List<String> playerNames = mcMMOPlayer.getParty().getOnlinePlayerNames(player);
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
}
return matches;
}
return ImmutableList.of();
}
private void sendTeleportRequest(CommandSender sender, Player player, String targetName) {
if (!canTeleport(sender, player, targetName)) {
return;
}
McMMOPlayer mcMMOTarget = UserManager.getPlayer(targetName);
Player target = mcMMOTarget.getPlayer();
if (mcMMO.p.getGeneralConfig().getPTPCommandWorldPermissions()) {
World targetWorld = target.getWorld();
World playerWorld = player.getWorld();
if (!Permissions.partyTeleportAllWorlds(player)) {
if (!Permissions.partyTeleportWorld(target, targetWorld)) {
player.sendMessage(
LocaleLoader.getString("Commands.ptp.NoWorldPermissions",
targetWorld.getName()));
return;
} else if (targetWorld != playerWorld && !Permissions.partyTeleportWorld(player,
targetWorld)) {
player.sendMessage(
LocaleLoader.getString("Commands.ptp.NoWorldPermissions",
targetWorld.getName()));
return;
}
}
}
PartyTeleportRecord ptpRecord = mcMMOTarget.getPartyTeleportRecord();
if (!ptpRecord.isConfirmRequired()) {
handleTeleportWarmup(player, target);
return;
}
ptpRecord.setRequestor(player);
ptpRecord.actualizeTimeout();
player.sendMessage(LocaleLoader.getString("Commands.Invite.Success"));
target.sendMessage(LocaleLoader.getString("Commands.ptp.Request1", player.getName()));
target.sendMessage(
LocaleLoader.getString("Commands.ptp.Request2",
mcMMO.p.getGeneralConfig().getPTPCommandTimeout()));
}
}

View File

@@ -11,13 +11,15 @@ import org.jetbrains.annotations.NotNull;
public class PtpToggleCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (!Permissions.partyTeleportToggle(sender)) {
sender.sendMessage(command.getPermissionMessage());
return true;
}
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName()).getPartyTeleportRecord();
PartyTeleportRecord ptpRecord = UserManager.getPlayer(sender.getName())
.getPartyTeleportRecord();
if (ptpRecord.isEnabled()) {
sender.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled"));

View File

@@ -11,6 +11,8 @@ import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.gmail.nossr50.util.skills.SkillTools;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -18,19 +20,18 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class InspectCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (args.length == 1) {
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
final McMMOPlayer mmoPlayer = UserManager.getOfflinePlayer(playerName);
// If the mcMMOPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mcMMOPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName); // Temporary Profile
// If the mmoPlayer doesn't exist, create a temporary profile and check if it's present in the database. If it's not, abort the process.
if (mmoPlayer == null) {
PlayerProfile profile = mcMMO.getDatabaseManager()
.loadPlayerProfile(playerName); // Temporary Profile
if (!CommandUtils.isLoaded(sender, profile)) {
return true;
@@ -65,27 +66,26 @@ public class InspectCommand implements TabExecutor {
// Sum power level
int powerLevel = 0;
for (PrimarySkillType skill : SkillTools.NON_CHILD_SKILLS)
for (PrimarySkillType skill : SkillTools.NON_CHILD_SKILLS) {
powerLevel += profile.getSkillLevel(skill);
}
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", powerLevel));
} else {
Player target = mcMMOPlayer.getPlayer();
boolean isVanished = false;
if (CommandUtils.hidden(sender, target, Permissions.inspectHidden(sender))) {
isVanished = true;
}
Player target = mmoPlayer.getPlayer();
boolean isVanished = CommandUtils.hidden(sender, target,
Permissions.inspectHidden(sender));
//Only distance check players who are online and not vanished
if (!isVanished && CommandUtils.tooFar(sender, target, Permissions.inspectFar(sender))) {
if (!isVanished && CommandUtils.tooFar(sender, target,
Permissions.inspectFar(sender))) {
return true;
}
if (mcMMO.p.getGeneralConfig().getScoreboardsEnabled()
&& sender instanceof Player
&& mcMMO.p.getGeneralConfig().getInspectUseBoard()) {
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, mcMMOPlayer);
ScoreboardManager.enablePlayerInspectScoreboard((Player) sender, mmoPlayer);
if (!mcMMO.p.getGeneralConfig().getInspectUseChat()) {
return true;
@@ -102,7 +102,8 @@ public class InspectCommand implements TabExecutor {
CommandUtils.printCombatSkills(target, sender);
CommandUtils.printMiscSkills(target, sender);
sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel", mcMMOPlayer.getPowerLevel()));
sender.sendMessage(
LocaleLoader.getString("Commands.PowerLevel", mmoPlayer.getPowerLevel()));
}
return true;
@@ -111,10 +112,12 @@ public class InspectCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
}
return ImmutableList.of();
}

View File

@@ -9,6 +9,8 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -17,12 +19,10 @@ import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class McRankCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
switch (args.length) {
case 0:
if (CommandUtils.noConsoleUsage(sender)) {
@@ -53,10 +53,10 @@ public class McRankCommand implements TabExecutor {
}
String playerName = CommandUtils.getMatchedPlayerName(args[0]);
McMMOPlayer mcMMOPlayer = UserManager.getOfflinePlayer(playerName);
final McMMOPlayer mmoPlayer = UserManager.getOfflinePlayer(playerName);
if (mcMMOPlayer != null) {
Player player = mcMMOPlayer.getPlayer();
if (mmoPlayer != null) {
Player player = mmoPlayer.getPlayer();
playerName = player.getName();
if (CommandUtils.tooFar(sender, player, Permissions.mcrankFar(sender))) {
@@ -73,27 +73,31 @@ public class McRankCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
List<String> playerNames = CommandUtils.getOnlinePlayerNames(sender);
return StringUtil.copyPartialMatches(args[0], playerNames, new ArrayList<>(playerNames.size()));
return StringUtil.copyPartialMatches(args[0], playerNames,
new ArrayList<>(playerNames.size()));
}
return ImmutableList.of();
}
private void display(CommandSender sender, String playerName) {
if (sender instanceof Player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
final McMMOPlayer mmoPlayer = UserManager.getPlayer(sender.getName());
if (mcMMOPlayer == null) {
if (mmoPlayer == null) {
sender.sendMessage(LocaleLoader.getString("Profile.PendingLoad"));
return;
}
long cooldownMillis = Math.min(mcMMO.p.getGeneralConfig().getDatabasePlayerCooldown(), 1750);
long cooldownMillis = Math.min(mcMMO.p.getGeneralConfig().getDatabasePlayerCooldown(),
1750);
if (mcMMOPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) {
sender.sendMessage(LocaleLoader.getString("Commands.Database.CooldownMS", getCDSeconds(mcMMOPlayer, cooldownMillis)));
if (mmoPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) {
sender.sendMessage(LocaleLoader.getString("Commands.Database.CooldownMS",
getCDSeconds(mmoPlayer, cooldownMillis)));
return;
}
@@ -101,19 +105,23 @@ public class McRankCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing"));
return;
} else {
((Player) sender).setMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND, new FixedMetadataValue(mcMMO.p, null));
((Player) sender).setMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND,
new FixedMetadataValue(mcMMO.p, null));
}
mcMMOPlayer.actualizeDatabaseATS();
mmoPlayer.actualizeDatabaseATS();
}
boolean useBoard = mcMMO.p.getGeneralConfig().getScoreboardsEnabled() && (sender instanceof Player) && (mcMMO.p.getGeneralConfig().getRankUseBoard());
boolean useBoard =
mcMMO.p.getGeneralConfig().getScoreboardsEnabled() && (sender instanceof Player)
&& (mcMMO.p.getGeneralConfig().getRankUseBoard());
boolean useChat = !useBoard || mcMMO.p.getGeneralConfig().getRankUseChat();
mcMMO.p.getFoliaLib().getScheduler().runAsync(new McRankCommandAsyncTask(playerName, sender, useBoard, useChat));
mcMMO.p.getFoliaLib().getScheduler()
.runAsync(new McRankCommandAsyncTask(playerName, sender, useBoard, useChat));
}
private long getCDSeconds(McMMOPlayer mcMMOPlayer, long cooldownMillis) {
return ((mcMMOPlayer.getDatabaseATS() + cooldownMillis) - System.currentTimeMillis());
private long getCDSeconds(McMMOPlayer mmoPlayer, long cooldownMillis) {
return ((mmoPlayer.getDatabaseATS() + cooldownMillis) - System.currentTimeMillis());
}
}

View File

@@ -11,6 +11,8 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.text.StringUtils;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -19,12 +21,10 @@ import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class McTopCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
PrimarySkillType skill = null;
switch (args.length) {
@@ -46,7 +46,8 @@ public class McTopCommand implements TabExecutor {
// Check if the command is for Maces but the MC version is not correct
if (skill == PrimarySkillType.MACES
&& !mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 21, 0)) {
&& !mcMMO.getCompatibilityManager().getMinecraftGameVersion()
.isAtLeast(1, 21, 0)) {
return true;
}
@@ -66,7 +67,8 @@ public class McTopCommand implements TabExecutor {
// Check if the command is for Maces but the MC version is not correct
if (skill == PrimarySkillType.MACES
&& !mcMMO.getCompatibilityManager().getMinecraftGameVersion().isAtLeast(1, 21, 0)) {
&& !mcMMO.getCompatibilityManager().getMinecraftGameVersion()
.isAtLeast(1, 21, 0)) {
return true;
}
@@ -79,9 +81,12 @@ public class McTopCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[0],
mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES,
new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
}
return ImmutableList.of();
}
@@ -97,16 +102,20 @@ public class McTopCommand implements TabExecutor {
return;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(sender.getName());
long cooldownMillis = Math.max(mcMMO.p.getGeneralConfig().getDatabasePlayerCooldown(), 1750);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(sender.getName());
long cooldownMillis = Math.max(mcMMO.p.getGeneralConfig().getDatabasePlayerCooldown(),
1750);
if (mcMMOPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) {
double seconds = ((mcMMOPlayer.getDatabaseATS() + cooldownMillis) - System.currentTimeMillis()) / 1000.0D;
if (mmoPlayer.getDatabaseATS() + cooldownMillis > System.currentTimeMillis()) {
double seconds =
((mmoPlayer.getDatabaseATS() + cooldownMillis) - System.currentTimeMillis())
/ 1000.0D;
if (seconds < 1) {
seconds = 1;
}
sender.sendMessage(LocaleLoader.formatString(LocaleLoader.getString("Commands.Database.Cooldown"), seconds));
sender.sendMessage(LocaleLoader.formatString(
LocaleLoader.getString("Commands.Database.Cooldown"), seconds));
return;
}
@@ -114,20 +123,23 @@ public class McTopCommand implements TabExecutor {
sender.sendMessage(LocaleLoader.getString("Commands.Database.Processing"));
return;
} else {
((Player) sender).setMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND, new FixedMetadataValue(mcMMO.p, null));
((Player) sender).setMetadata(MetadataConstants.METADATA_KEY_DATABASE_COMMAND,
new FixedMetadataValue(mcMMO.p, null));
}
mcMMOPlayer.actualizeDatabaseATS();
mmoPlayer.actualizeDatabaseATS();
}
display(page, skill, sender);
}
private void display(int page, PrimarySkillType skill, CommandSender sender) {
boolean useBoard = (sender instanceof Player) && (mcMMO.p.getGeneralConfig().getTopUseBoard());
boolean useBoard =
(sender instanceof Player) && (mcMMO.p.getGeneralConfig().getTopUseBoard());
boolean useChat = !useBoard || mcMMO.p.getGeneralConfig().getTopUseChat();
mcMMO.p.getFoliaLib().getScheduler().runAsync(new McTopCommandAsyncTask(page, skill, sender, useBoard, useChat));
mcMMO.p.getFoliaLib().getScheduler()
.runAsync(new McTopCommandAsyncTask(page, skill, sender, useBoard, useChat));
}
private PrimarySkillType extractSkill(CommandSender sender, String skillName) {

View File

@@ -8,17 +8,17 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class MccooldownCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
@@ -28,9 +28,10 @@ public class MccooldownCommand implements TabExecutor {
}
if (args.length == 0) {
Player player = (Player) sender;
final Player player = (Player) sender;
if (mcMMO.p.getGeneralConfig().getScoreboardsEnabled() && mcMMO.p.getGeneralConfig().getCooldownUseBoard()) {
if (mcMMO.p.getGeneralConfig().getScoreboardsEnabled() && mcMMO.p.getGeneralConfig()
.getCooldownUseBoard()) {
ScoreboardManager.enablePlayerCooldownScoreboard(player);
if (!mcMMO.p.getGeneralConfig().getCooldownUseChat()) {
@@ -43,7 +44,7 @@ public class MccooldownCommand implements TabExecutor {
return true;
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
final McMMOPlayer mmoPlayer = UserManager.getPlayer(player);
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Header"));
player.sendMessage(LocaleLoader.getString("mcMMO.NoSkillNote"));
@@ -53,12 +54,14 @@ public class MccooldownCommand implements TabExecutor {
continue;
}
int seconds = mcMMOPlayer.calculateTimeRemaining(ability);
int seconds = mmoPlayer.calculateTimeRemaining(ability);
if (seconds <= 0) {
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.Y", ability.getLocalizedName()));
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.Y",
ability.getLocalizedName()));
} else {
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.N", ability.getLocalizedName(), seconds));
player.sendMessage(LocaleLoader.getString("Commands.Cooldowns.Row.N",
ability.getLocalizedName(), seconds));
}
}
@@ -68,7 +71,8 @@ public class MccooldownCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@@ -6,17 +6,17 @@ import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class McstatsCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
@@ -31,9 +31,10 @@ public class McstatsCommand implements TabExecutor {
return true;
}
Player player = (Player) sender;
final Player player = (Player) sender;
if (mcMMO.p.getGeneralConfig().getStatsUseBoard() && mcMMO.p.getGeneralConfig().getScoreboardsEnabled()) {
if (mcMMO.p.getGeneralConfig().getStatsUseBoard() && mcMMO.p.getGeneralConfig()
.getScoreboardsEnabled()) {
ScoreboardManager.enablePlayerStatsScoreboard(player);
if (!mcMMO.p.getGeneralConfig().getStatsUseChat()) {
@@ -51,9 +52,11 @@ public class McstatsCommand implements TabExecutor {
int powerLevelCap = mcMMO.p.getGeneralConfig().getPowerLevelCap();
if (powerLevelCap != Integer.MAX_VALUE) {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped", UserManager.getPlayer(player).getPowerLevel(), powerLevelCap));
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Capped",
UserManager.getPlayer(player).getPowerLevel(), powerLevelCap));
} else {
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel", UserManager.getPlayer(player).getPowerLevel()));
player.sendMessage(LocaleLoader.getString("Commands.PowerLevel",
UserManager.getPlayer(player).getPowerLevel()));
}
return true;
@@ -62,7 +65,8 @@ public class McstatsCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
return ImmutableList.of();
}
}

View File

@@ -9,6 +9,8 @@ import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.text.StringUtils;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -17,36 +19,39 @@ import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class XPBarCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
if (sender instanceof Player) {
McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender);
final McMMOPlayer mmoPlayer = UserManager.getPlayer((Player) sender);
if (mmoPlayer == null) {
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(), "Profile.PendingLoad");
NotificationManager.sendPlayerInformationChatOnlyPrefixed(mmoPlayer.getPlayer(),
"Profile.PendingLoad");
return false;
}
if (args.length == 0) {
return false;
} else if (args.length < 2) {
String option = args[0];
String option = args[0];
if (option.equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString())) {
mmoPlayer.getExperienceBarManager().xpBarSettingToggle(ExperienceBarManager.XPBarSettingTarget.RESET, null);
return true;
} else if (option.equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.DISABLE.toString())) {
mmoPlayer.getExperienceBarManager().disableAllBars();
return true;
} else {
return false;
}
if (option.equalsIgnoreCase(
ExperienceBarManager.XPBarSettingTarget.RESET.toString())) {
mmoPlayer.getExperienceBarManager()
.xpBarSettingToggle(ExperienceBarManager.XPBarSettingTarget.RESET,
null);
return true;
} else if (option.equalsIgnoreCase(
ExperienceBarManager.XPBarSettingTarget.DISABLE.toString())) {
mmoPlayer.getExperienceBarManager().disableAllBars();
return true;
} else {
return false;
}
//Per skill Settings path
//Per skill Settings path
} else if (args.length == 2) {
String skillName = args[1];
@@ -57,10 +62,13 @@ public class XPBarCommand implements TabExecutor {
//Target setting
String option = args[0].toLowerCase();
ExperienceBarManager.XPBarSettingTarget settingTarget = getSettingTarget(option);
if (settingTarget != null && settingTarget != ExperienceBarManager.XPBarSettingTarget.RESET) {
ExperienceBarManager.XPBarSettingTarget settingTarget = getSettingTarget(
option);
if (settingTarget != null
&& settingTarget != ExperienceBarManager.XPBarSettingTarget.RESET) {
//Change setting
mmoPlayer.getExperienceBarManager().xpBarSettingToggle(settingTarget, targetSkill);
mmoPlayer.getExperienceBarManager()
.xpBarSettingToggle(settingTarget, targetSkill);
return true;
} else {
return false;
@@ -92,19 +100,25 @@ public class XPBarCommand implements TabExecutor {
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
switch (args.length) {
case 1:
List<String> options = new ArrayList<>();
for(ExperienceBarManager.XPBarSettingTarget settingTarget : ExperienceBarManager.XPBarSettingTarget.values()) {
for (ExperienceBarManager.XPBarSettingTarget settingTarget : ExperienceBarManager.XPBarSettingTarget.values()) {
options.add(StringUtils.getCapitalized(settingTarget.toString()));
}
return StringUtil.copyPartialMatches(args[0], options, new ArrayList<>(ExperienceBarManager.XPBarSettingTarget.values().length));
return StringUtil.copyPartialMatches(args[0], options,
new ArrayList<>(ExperienceBarManager.XPBarSettingTarget.values().length));
case 2:
if (!args[0].equalsIgnoreCase(ExperienceBarManager.XPBarSettingTarget.RESET.toString()))
return StringUtil.copyPartialMatches(args[1], mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
if (!args[0].equalsIgnoreCase(
ExperienceBarManager.XPBarSettingTarget.RESET.toString())) {
return StringUtil.copyPartialMatches(args[1],
mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES,
new ArrayList<>(mcMMO.p.getSkillTools().LOCALIZED_SKILL_NAMES.size()));
}
default:
return ImmutableList.of();
}

View File

@@ -10,7 +10,8 @@ import org.jetbrains.annotations.NotNull;
*/
public class Mcmmoupgrade implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, String[] args) {
return false;
}
}

View File

@@ -8,11 +8,10 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class AcrobaticsCommand extends SkillCommand {
private String dodgeChance;
@@ -29,7 +28,8 @@ public class AcrobaticsCommand extends SkillCommand {
protected void dataCalculations(Player player, float skillValue) {
// ACROBATICS_DODGE
if (canDodge) {
final String[] dodgeStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.ACROBATICS_DODGE);
final String[] dodgeStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.ACROBATICS_DODGE);
dodgeChance = dodgeStrings[0];
dodgeChanceLucky = dodgeStrings[1];
}
@@ -42,12 +42,14 @@ public class AcrobaticsCommand extends SkillCommand {
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canDodge) {
messages.add(getStatMessage(SubSkillType.ACROBATICS_DODGE, dodgeChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", dodgeChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", dodgeChanceLucky)
: ""));
}
if (canRoll) {
@@ -55,10 +57,12 @@ public class AcrobaticsCommand extends SkillCommand {
AbstractSubSkill abstractSubSkill = InteractionManager.getAbstractByName("Roll");
if (abstractSubSkill != null) {
String[] rollStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.ACROBATICS_ROLL);
String[] rollStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.ACROBATICS_ROLL);
messages.add(getStatMessage(SubSkillType.ACROBATICS_ROLL, rollStrings[0])
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", rollStrings[1]) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", rollStrings[1])
: ""));
}
}
@@ -69,7 +73,8 @@ public class AcrobaticsCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ACROBATICS);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.ACROBATICS);
return textComponents;
}

View File

@@ -7,18 +7,17 @@ import com.gmail.nossr50.skills.alchemy.AlchemyManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class AlchemyCommand extends SkillCommand {
private String brewSpeed;
private String brewSpeedLucky;
private int tier;
private int ingredientCount;
private int tier;
private int ingredientCount;
private String ingredientList;
private boolean canCatalysis;
@@ -35,7 +34,8 @@ public class AlchemyCommand extends SkillCommand {
boolean isLucky = Permissions.lucky(player, PrimarySkillType.ALCHEMY);
displayValues[0] = decimal.format(alchemyManager.calculateBrewSpeed(false)) + "x";
displayValues[1] = isLucky ? decimal.format(alchemyManager.calculateBrewSpeed(true)) + "x" : null;
displayValues[1] =
isLucky ? decimal.format(alchemyManager.calculateBrewSpeed(true)) + "x" : null;
return displayValues;
}
@@ -65,7 +65,8 @@ public class AlchemyCommand extends SkillCommand {
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canCatalysis) {
@@ -74,8 +75,11 @@ public class AlchemyCommand extends SkillCommand {
}
if (canConcoctions) {
messages.add(getStatMessage(false, true, SubSkillType.ALCHEMY_CONCOCTIONS, String.valueOf(tier), String.valueOf(RankUtils.getHighestRank(SubSkillType.ALCHEMY_CONCOCTIONS))));
messages.add(getStatMessage(true, true, SubSkillType.ALCHEMY_CONCOCTIONS, String.valueOf(ingredientCount), ingredientList));
messages.add(getStatMessage(false, true, SubSkillType.ALCHEMY_CONCOCTIONS,
String.valueOf(tier),
String.valueOf(RankUtils.getHighestRank(SubSkillType.ALCHEMY_CONCOCTIONS))));
messages.add(getStatMessage(true, true, SubSkillType.ALCHEMY_CONCOCTIONS,
String.valueOf(ingredientCount), ingredientList));
//messages.add(LocaleLoader.getString("Alchemy.Concoctions.Rank", tier, RankUtils.getHighestRank(SubSkillType.ALCHEMY_CONCOCTIONS)));
//messages.add(LocaleLoader.getString("Alchemy.Concoctions.Ingredients", ingredientCount, ingredientList));
@@ -88,7 +92,8 @@ public class AlchemyCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ALCHEMY);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.ALCHEMY);
return textComponents;
}

View File

@@ -31,7 +31,7 @@
// skillName = StringUtils.getCapitalized(label);
//
// if (args.length == 0) {
// Player player = (Player) sender;
// final Player player = (Player) sender;
// FakeSkillType fakeSkillType = FakeSkillType.getByName(skillName);
//
// float skillValue = Misc.getRandom().nextInt(99);

View File

@@ -8,11 +8,10 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class ArcheryCommand extends SkillCommand {
private String skillShotBonus;
@@ -33,14 +32,16 @@ public class ArcheryCommand extends SkillCommand {
protected void dataCalculations(Player player, float skillValue) {
// ARCHERY_ARROW_RETRIEVAL
if (canRetrieve) {
String[] retrieveStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.ARCHERY_ARROW_RETRIEVAL);
String[] retrieveStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.ARCHERY_ARROW_RETRIEVAL);
retrieveChance = retrieveStrings[0];
retrieveChanceLucky = retrieveStrings[1];
}
// ARCHERY_DAZE
if (canDaze) {
String[] dazeStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.ARCHERY_DAZE);
String[] dazeStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.ARCHERY_DAZE);
dazeChance = dazeStrings[0];
dazeChanceLucky = dazeStrings[1];
}
@@ -59,17 +60,20 @@ public class ArcheryCommand extends SkillCommand {
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canRetrieve) {
messages.add(getStatMessage(SubSkillType.ARCHERY_ARROW_RETRIEVAL, retrieveChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", retrieveChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", retrieveChanceLucky)
: ""));
}
if (canDaze) {
messages.add(getStatMessage(SubSkillType.ARCHERY_DAZE, dazeChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", dazeChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", dazeChanceLucky)
: ""));
}
if (canSkillShot) {
@@ -78,7 +82,8 @@ public class ArcheryCommand extends SkillCommand {
if (Permissions.canUseSubSkill(player, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK)) {
messages.add(getStatMessage(SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK,
String.valueOf(CombatUtils.getLimitBreakDamageAgainstQuality(player, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK, 1000))));
String.valueOf(CombatUtils.getLimitBreakDamageAgainstQuality(player,
SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK, 1000))));
}
return messages;
@@ -88,7 +93,8 @@ public class ArcheryCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.ARCHERY);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.ARCHERY);
return textComponents;
}

View File

@@ -9,11 +9,10 @@ import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class AxesCommand extends SkillCommand {
private String critChance;
@@ -47,7 +46,8 @@ public class AxesCommand extends SkillCommand {
// CRITICAL HIT
if (canCritical) {
String[] criticalHitStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.AXES_CRITICAL_STRIKES);
String[] criticalHitStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.AXES_CRITICAL_STRIKES);
critChance = criticalHitStrings[0];
critChanceLucky = criticalHitStrings[1];
}
@@ -62,7 +62,9 @@ public class AxesCommand extends SkillCommand {
@Override
protected void permissionsCheck(Player player) {
canSkullSplitter = Permissions.skullSplitter(player) && RankUtils.hasUnlockedSubskill(player, SubSkillType.AXES_SKULL_SPLITTER);
canSkullSplitter =
Permissions.skullSplitter(player) && RankUtils.hasUnlockedSubskill(player,
SubSkillType.AXES_SKULL_SPLITTER);
canCritical = Permissions.canUseSubSkill(player, SubSkillType.AXES_CRITICAL_STRIKES);
canAxeMastery = Permissions.canUseSubSkill(player, SubSkillType.AXES_AXE_MASTERY);
canImpact = Permissions.canUseSubSkill(player, SubSkillType.AXES_ARMOR_IMPACT);
@@ -70,34 +72,44 @@ public class AxesCommand extends SkillCommand {
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canImpact) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.2"), LocaleLoader.getString("Axes.Ability.Bonus.3", impactDamage)));
messages.add(LocaleLoader.getString("Ability.Generic.Template",
LocaleLoader.getString("Axes.Ability.Bonus.2"),
LocaleLoader.getString("Axes.Ability.Bonus.3", impactDamage)));
}
if (canAxeMastery) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.0"), LocaleLoader.getString("Axes.Ability.Bonus.1", axeMasteryDamage)));
messages.add(LocaleLoader.getString("Ability.Generic.Template",
LocaleLoader.getString("Axes.Ability.Bonus.0"),
LocaleLoader.getString("Axes.Ability.Bonus.1", axeMasteryDamage)));
}
if (canCritical) {
messages.add(getStatMessage(SubSkillType.AXES_CRITICAL_STRIKES, critChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", critChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", critChanceLucky)
: ""));
}
if (canGreaterImpact) {
messages.add(LocaleLoader.getString("Ability.Generic.Template", LocaleLoader.getString("Axes.Ability.Bonus.4"), LocaleLoader.getString("Axes.Ability.Bonus.5", Axes.greaterImpactBonusDamage)));
messages.add(LocaleLoader.getString("Ability.Generic.Template",
LocaleLoader.getString("Axes.Ability.Bonus.4"),
LocaleLoader.getString("Axes.Ability.Bonus.5", Axes.greaterImpactBonusDamage)));
}
if (canSkullSplitter) {
messages.add(getStatMessage(SubSkillType.AXES_SKULL_SPLITTER, skullSplitterLength)
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", skullSplitterLengthEndurance) : ""));
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus",
skullSplitterLengthEndurance) : ""));
}
if (Permissions.canUseSubSkill(player, SubSkillType.AXES_AXES_LIMIT_BREAK)) {
messages.add(getStatMessage(SubSkillType.AXES_AXES_LIMIT_BREAK,
String.valueOf(CombatUtils.getLimitBreakDamageAgainstQuality(player, SubSkillType.AXES_AXES_LIMIT_BREAK, 1000))));
String.valueOf(CombatUtils.getLimitBreakDamageAgainstQuality(player,
SubSkillType.AXES_AXES_LIMIT_BREAK, 1000))));
}
return messages;
@@ -107,7 +119,8 @@ public class AxesCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
final List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.AXES);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.AXES);
return textComponents;
}

View File

@@ -1,17 +1,18 @@
package com.gmail.nossr50.commands.skills;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.CROSSBOWS_CROSSBOWS_LIMIT_BREAK;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.CROSSBOWS_POWERED_SHOT;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.CROSSBOWS_TRICK_SHOT;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.*;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class CrossbowsCommand extends SkillCommand {
private boolean canTrickShot;
@@ -36,7 +37,8 @@ public class CrossbowsCommand extends SkillCommand {
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (mmoPlayer == null) {
@@ -55,7 +57,8 @@ public class CrossbowsCommand extends SkillCommand {
if (Permissions.canUseSubSkill(player, CROSSBOWS_CROSSBOWS_LIMIT_BREAK)) {
messages.add(getStatMessage(CROSSBOWS_CROSSBOWS_LIMIT_BREAK,
String.valueOf(CombatUtils.getLimitBreakDamageAgainstQuality(player, CROSSBOWS_CROSSBOWS_LIMIT_BREAK, 1000))));
String.valueOf(CombatUtils.getLimitBreakDamageAgainstQuality(player,
CROSSBOWS_CROSSBOWS_LIMIT_BREAK, 1000))));
}
return messages;
@@ -65,7 +68,8 @@ public class CrossbowsCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.CROSSBOWS);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.CROSSBOWS);
return textComponents;
}

View File

@@ -7,11 +7,10 @@ import com.gmail.nossr50.skills.excavation.ExcavationManager;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class ExcavationCommand extends SkillCommand {
private String gigaDrillBreakerLength;
@@ -36,19 +35,23 @@ public class ExcavationCommand extends SkillCommand {
@Override
protected void permissionsCheck(Player player) {
canGigaDrill = Permissions.gigaDrillBreaker(player) && RankUtils.hasUnlockedSubskill(player, SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER);
canGigaDrill = Permissions.gigaDrillBreaker(player) && RankUtils.hasUnlockedSubskill(player,
SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER);
canTreasureHunt = Permissions.canUseSubSkill(player, SubSkillType.EXCAVATION_ARCHAEOLOGY);
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
ExcavationManager excavationManager = mmoPlayer.getExcavationManager();
if (canGigaDrill) {
messages.add(getStatMessage(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER, gigaDrillBreakerLength)
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", gigaDrillBreakerLengthEndurance) : ""));
messages.add(getStatMessage(SubSkillType.EXCAVATION_GIGA_DRILL_BREAKER,
gigaDrillBreakerLength)
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus",
gigaDrillBreakerLengthEndurance) : ""));
//messages.add(LocaleLoader.getString("Excavation.Effect.Length", gigaDrillBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", gigaDrillBreakerLengthEndurance) : ""));
}
@@ -68,7 +71,8 @@ public class ExcavationCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.EXCAVATION);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.EXCAVATION);
return textComponents;
}

View File

@@ -13,11 +13,10 @@ import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.StringUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class FishingCommand extends SkillCommand {
private int lootTier;
@@ -56,26 +55,40 @@ public class FishingCommand extends SkillCommand {
lootTier = fishingManager.getLootTier();
// Item drop rates
commonTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON) / 100.0);
uncommonTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON) / 100.0);
rareTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE) / 100.0);
epicTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC) / 100.0);
legendaryTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY) / 100.0);
mythicTreasure = percent.format(FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.MYTHIC) / 100.0);
commonTreasure = percent.format(
FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON)
/ 100.0);
uncommonTreasure = percent.format(
FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON)
/ 100.0);
rareTreasure = percent.format(
FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE)
/ 100.0);
epicTreasure = percent.format(
FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC)
/ 100.0);
legendaryTreasure = percent.format(
FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY)
/ 100.0);
mythicTreasure = percent.format(
FishingTreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.MYTHIC)
/ 100.0);
// Magic hunter drop rates
double totalEnchantChance = 0;
for (Rarity rarity : Rarity.values()) {
if (rarity != Rarity.MYTHIC) {
totalEnchantChance += FishingTreasureConfig.getInstance().getEnchantmentDropRate(lootTier, rarity);
totalEnchantChance += FishingTreasureConfig.getInstance()
.getEnchantmentDropRate(lootTier, rarity);
}
}
if (totalEnchantChance >= 1)
if (totalEnchantChance >= 1) {
magicChance = percent.format(totalEnchantChance / 100.0);
else
} else {
magicChance = percent.format(0);
}
}
// FISHING_SHAKE
@@ -93,31 +106,43 @@ public class FishingCommand extends SkillCommand {
// MASTER ANGLER
if (canMasterAngler) {
maMinWaitTime = StringUtils.ticksToSeconds(fishingManager.getMasterAnglerTickMinWaitReduction(RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false));
maMaxWaitTime = StringUtils.ticksToSeconds(fishingManager.getMasterAnglerTickMaxWaitReduction(RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false, 0));
maMinWaitTime = StringUtils.ticksToSeconds(
fishingManager.getMasterAnglerTickMinWaitReduction(
RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false));
maMaxWaitTime = StringUtils.ticksToSeconds(
fishingManager.getMasterAnglerTickMaxWaitReduction(
RankUtils.getRank(player, SubSkillType.FISHING_MASTER_ANGLER), false,
0));
}
}
@Override
protected void permissionsCheck(Player player) {
canTreasureHunt = Permissions.canUseSubSkill(player, SubSkillType.FISHING_TREASURE_HUNTER);
canMagicHunt = Permissions.canUseSubSkill(player, SubSkillType.FISHING_MAGIC_HUNTER) && Permissions.canUseSubSkill(player, SubSkillType.FISHING_TREASURE_HUNTER);
canMagicHunt = Permissions.canUseSubSkill(player, SubSkillType.FISHING_MAGIC_HUNTER)
&& Permissions.canUseSubSkill(player, SubSkillType.FISHING_TREASURE_HUNTER);
canShake = Permissions.canUseSubSkill(player, SubSkillType.FISHING_SHAKE);
canFishermansDiet = Permissions.canUseSubSkill(player, SubSkillType.FISHING_FISHERMANS_DIET);
canMasterAngler = mcMMO.getCompatibilityManager().getMasterAnglerCompatibilityLayer() != null && Permissions.canUseSubSkill(player, SubSkillType.FISHING_MASTER_ANGLER);
canFishermansDiet = Permissions.canUseSubSkill(player,
SubSkillType.FISHING_FISHERMANS_DIET);
canMasterAngler =
mcMMO.getCompatibilityManager().getMasterAnglerCompatibilityLayer() != null
&& Permissions.canUseSubSkill(player, SubSkillType.FISHING_MASTER_ANGLER);
canIceFish = Permissions.canUseSubSkill(player, SubSkillType.FISHING_ICE_FISHING);
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canFishermansDiet) {
messages.add(getStatMessage(false, true, SubSkillType.FISHING_FISHERMANS_DIET, String.valueOf(fishermansDietRank)));
messages.add(getStatMessage(false, true, SubSkillType.FISHING_FISHERMANS_DIET,
String.valueOf(fishermansDietRank)));
}
if (canIceFish) {
messages.add(getStatMessage(SubSkillType.FISHING_ICE_FISHING, SubSkillType.FISHING_ICE_FISHING.getLocaleStatDescription()));
messages.add(getStatMessage(SubSkillType.FISHING_ICE_FISHING,
SubSkillType.FISHING_ICE_FISHING.getLocaleStatDescription()));
}
if (canMagicHunt) {
@@ -125,22 +150,25 @@ public class FishingCommand extends SkillCommand {
}
if (canMasterAngler) {
messages.add(getStatMessage(false,true,
messages.add(getStatMessage(false, true,
SubSkillType.FISHING_MASTER_ANGLER,
maMinWaitTime));
messages.add(getStatMessage(true,true,
messages.add(getStatMessage(true, true,
SubSkillType.FISHING_MASTER_ANGLER,
maMaxWaitTime));
}
if (canShake) {
messages.add(getStatMessage(SubSkillType.FISHING_SHAKE, shakeChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", shakeChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", shakeChanceLucky)
: ""));
}
if (canTreasureHunt) {
messages.add(getStatMessage(false, true, SubSkillType.FISHING_TREASURE_HUNTER, String.valueOf(lootTier), String.valueOf(RankUtils.getHighestRank(SubSkillType.FISHING_TREASURE_HUNTER))));
messages.add(getStatMessage(false, true, SubSkillType.FISHING_TREASURE_HUNTER,
String.valueOf(lootTier), String.valueOf(
RankUtils.getHighestRank(SubSkillType.FISHING_TREASURE_HUNTER))));
messages.add(getStatMessage(true, true, SubSkillType.FISHING_TREASURE_HUNTER,
String.valueOf(commonTreasure),
String.valueOf(uncommonTreasure),
@@ -157,7 +185,8 @@ public class FishingCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.FISHING);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.FISHING);
return textComponents;
}

View File

@@ -8,13 +8,12 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public class HerbalismCommand extends SkillCommand {
private String greenTerraLength;
private String greenTerraLengthEndurance;
@@ -49,13 +48,15 @@ public class HerbalismCommand extends SkillCommand {
// DOUBLE DROPS
if (canDoubleDrop) {
String[] doubleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.HERBALISM_DOUBLE_DROPS);
String[] doubleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.HERBALISM_DOUBLE_DROPS);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
if (canTripleDrop) {
String[] tripleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.HERBALISM_VERDANT_BOUNTY);
String[] tripleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.HERBALISM_VERDANT_BOUNTY);
tripleDropChance = tripleDropStrings[0];
tripleDropChanceLucky = tripleDropStrings[1];
}
@@ -76,21 +77,24 @@ public class HerbalismCommand extends SkillCommand {
if (canGreenThumbBlocks || canGreenThumbPlants) {
greenThumbStage = RankUtils.getRank(player, SubSkillType.HERBALISM_GREEN_THUMB);
String[] greenThumbStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.HERBALISM_GREEN_THUMB);
String[] greenThumbStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.HERBALISM_GREEN_THUMB);
greenThumbChance = greenThumbStrings[0];
greenThumbChanceLucky = greenThumbStrings[1];
}
// HYLIAN LUCK
if (hasHylianLuck) {
String[] hylianLuckStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.HERBALISM_HYLIAN_LUCK);
String[] hylianLuckStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.HERBALISM_HYLIAN_LUCK);
hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1];
}
// SHROOM THUMB
if (canShroomThumb) {
String[] shroomThumbStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.HERBALISM_SHROOM_THUMB);
String[] shroomThumbStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.HERBALISM_SHROOM_THUMB);
shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1];
}
@@ -100,57 +104,80 @@ public class HerbalismCommand extends SkillCommand {
protected void permissionsCheck(Player player) {
hasHylianLuck = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_HYLIAN_LUCK);
canGreenTerra = Permissions.greenTerra(player);
canGreenThumbPlants = RankUtils.hasUnlockedSubskill(player, SubSkillType.HERBALISM_GREEN_THUMB) && (Permissions.greenThumbPlant(player, Material.WHEAT) || Permissions.greenThumbPlant(player, Material.CARROT) || Permissions.greenThumbPlant(player, Material.POTATO) || Permissions.greenThumbPlant(player, Material.BEETROOTS) || Permissions.greenThumbPlant(player, Material.NETHER_WART) || Permissions.greenThumbPlant(player, Material.COCOA));
canGreenThumbBlocks = RankUtils.hasUnlockedSubskill(player, SubSkillType.HERBALISM_GREEN_THUMB) && (Permissions.greenThumbBlock(player, Material.DIRT) || Permissions.greenThumbBlock(player, Material.COBBLESTONE) || Permissions.greenThumbBlock(player, Material.COBBLESTONE_WALL) || Permissions.greenThumbBlock(player, Material.STONE_BRICKS));
canGreenThumbPlants =
RankUtils.hasUnlockedSubskill(player, SubSkillType.HERBALISM_GREEN_THUMB) && (
Permissions.greenThumbPlant(player, Material.WHEAT)
|| Permissions.greenThumbPlant(player, Material.CARROT)
|| Permissions.greenThumbPlant(player, Material.POTATO)
|| Permissions.greenThumbPlant(player, Material.BEETROOTS)
|| Permissions.greenThumbPlant(player, Material.NETHER_WART)
|| Permissions.greenThumbPlant(player, Material.COCOA));
canGreenThumbBlocks =
RankUtils.hasUnlockedSubskill(player, SubSkillType.HERBALISM_GREEN_THUMB) && (
Permissions.greenThumbBlock(player, Material.DIRT)
|| Permissions.greenThumbBlock(player, Material.COBBLESTONE)
|| Permissions.greenThumbBlock(player, Material.COBBLESTONE_WALL)
|| Permissions.greenThumbBlock(player, Material.STONE_BRICKS));
canFarmersDiet = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_FARMERS_DIET);
canDoubleDrop = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_DOUBLE_DROPS) && !mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(skill);
canTripleDrop = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_VERDANT_BOUNTY) && !mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(skill);
canDoubleDrop = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_DOUBLE_DROPS)
&& !mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(skill);
canTripleDrop = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_VERDANT_BOUNTY)
&& !mcMMO.p.getGeneralConfig().getDoubleDropsDisabled(skill);
canShroomThumb = Permissions.canUseSubSkill(player, SubSkillType.HERBALISM_SHROOM_THUMB);
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canDoubleDrop) {
messages.add(getStatMessage(SubSkillType.HERBALISM_DOUBLE_DROPS, doubleDropChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky)
: ""));
}
if (canTripleDrop) {
messages.add(getStatMessage(SubSkillType.HERBALISM_VERDANT_BOUNTY, tripleDropChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", tripleDropChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", tripleDropChanceLucky)
: ""));
}
if (canFarmersDiet) {
messages.add(getStatMessage(false, true, SubSkillType.HERBALISM_FARMERS_DIET, String.valueOf(farmersDietRank)));
messages.add(getStatMessage(false, true, SubSkillType.HERBALISM_FARMERS_DIET,
String.valueOf(farmersDietRank)));
}
if (canGreenTerra) {
messages.add(getStatMessage(SubSkillType.HERBALISM_GREEN_TERRA, greenTerraLength)
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", greenTerraLengthEndurance) : ""));
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus",
greenTerraLengthEndurance) : ""));
//messages.add(LocaleLoader.getString("Herbalism.Ability.GTe.Length", greenTerraLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", greenTerraLengthEndurance) : ""));
}
if (canGreenThumbBlocks || canGreenThumbPlants) {
messages.add(getStatMessage(SubSkillType.HERBALISM_GREEN_THUMB, greenThumbChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", greenThumbChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", greenThumbChanceLucky)
: ""));
//messages.add(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", greenThumbChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", greenThumbChanceLucky) : ""));
}
if (canGreenThumbPlants) {
messages.add(getStatMessage(true, true,SubSkillType.HERBALISM_GREEN_THUMB, String.valueOf(greenThumbStage)));
messages.add(getStatMessage(true, true, SubSkillType.HERBALISM_GREEN_THUMB,
String.valueOf(greenThumbStage)));
}
if (hasHylianLuck) {
messages.add(getStatMessage(SubSkillType.HERBALISM_HYLIAN_LUCK, hylianLuckChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", hylianLuckChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", hylianLuckChanceLucky)
: ""));
}
if (canShroomThumb) {
messages.add(getStatMessage(SubSkillType.HERBALISM_SHROOM_THUMB, shroomThumbChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", shroomThumbChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", shroomThumbChanceLucky)
: ""));
}
return messages;
@@ -160,7 +187,8 @@ public class HerbalismCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.HERBALISM);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.HERBALISM);
return textComponents;
}

View File

@@ -1,5 +1,8 @@
package com.gmail.nossr50.commands.skills;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.MACES_CRIPPLE;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.MACES_MACES_LIMIT_BREAK;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.locale.LocaleLoader;
@@ -9,14 +12,10 @@ import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.MACES_CRIPPLE;
import static com.gmail.nossr50.datatypes.skills.SubSkillType.MACES_MACES_LIMIT_BREAK;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class MacesCommand extends SkillCommand {
@@ -30,19 +29,25 @@ public class MacesCommand extends SkillCommand {
protected void dataCalculations(Player player, float skillValue) {
if (SkillUtils.canUseSubskill(player, MACES_CRIPPLE)) {
int crippleRank = RankUtils.getRank(player, MACES_CRIPPLE);
crippleLengthAgainstPlayers = String.valueOf(MacesManager.getCrippleTickDuration(true) / 20.0D);
crippleLengthAgainstMobs = String.valueOf(MacesManager.getCrippleTickDuration(false) / 20.0D);
crippleLengthAgainstPlayers = String.valueOf(
MacesManager.getCrippleTickDuration(true) / 20.0D);
crippleLengthAgainstMobs = String.valueOf(
MacesManager.getCrippleTickDuration(false) / 20.0D);
crippleChanceToApply = String.valueOf(mcMMO.p.getAdvancedConfig().getCrippleChanceToApplyOnHit(crippleRank) + "%");
crippleChanceToApplyLucky = String.valueOf(mcMMO.p.getAdvancedConfig().getCrippleChanceToApplyOnHit(crippleRank) * 1.33);
crippleChanceToApply =
mcMMO.p.getAdvancedConfig().getCrippleChanceToApplyOnHit(crippleRank) + "%";
crippleChanceToApplyLucky = String.valueOf(
mcMMO.p.getAdvancedConfig().getCrippleChanceToApplyOnHit(crippleRank) * 1.33);
}
}
@Override
protected void permissionsCheck(Player player) {}
protected void permissionsCheck(Player player) {
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
final List<String> messages = new ArrayList<>();
if (SkillUtils.canUseSubskill(player, MACES_MACES_LIMIT_BREAK)) {
@@ -53,7 +58,8 @@ public class MacesCommand extends SkillCommand {
if (SkillUtils.canUseSubskill(player, MACES_CRIPPLE)) {
messages.add(getStatMessage(MACES_CRIPPLE, crippleChanceToApply)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", crippleChanceToApplyLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus",
crippleChanceToApplyLucky) : ""));
messages.add(getStatMessage(true, true, MACES_CRIPPLE,
crippleLengthAgainstPlayers,
crippleLengthAgainstMobs));
@@ -71,7 +77,8 @@ public class MacesCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.MACES);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.MACES);
return textComponents;
}

View File

@@ -8,11 +8,10 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.random.ProbabilityUtil;
import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.text.TextComponentFactory;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
public class MiningCommand extends SkillCommand {
private String doubleDropChance;
@@ -26,7 +25,7 @@ public class MiningCommand extends SkillCommand {
private int bonusTNTDrops;
private double blastRadiusIncrease;
private String oreBonus;
// private String debrisReduction;
// private String debrisReduction;
private String blastDamageDecrease;
private boolean canSuperBreaker;
@@ -56,14 +55,16 @@ public class MiningCommand extends SkillCommand {
// Mastery TRIPLE DROPS
if (canTripleDrop) {
String[] masteryTripleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.MINING_MOTHER_LODE);
String[] masteryTripleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.MINING_MOTHER_LODE);
tripleDropChance = masteryTripleDropStrings[0];
tripleDropChanceLucky = masteryTripleDropStrings[1];
}
// DOUBLE DROPS
if (canDoubleDrop) {
String[] doubleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer, SubSkillType.MINING_DOUBLE_DROPS);
String[] doubleDropStrings = ProbabilityUtil.getRNGDisplayValues(mmoPlayer,
SubSkillType.MINING_DOUBLE_DROPS);
doubleDropChance = doubleDropStrings[0];
doubleDropChanceLucky = doubleDropStrings[1];
}
@@ -78,47 +79,61 @@ public class MiningCommand extends SkillCommand {
@Override
protected void permissionsCheck(Player player) {
canBiggerBombs = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_BIGGER_BOMBS) && Permissions.biggerBombs(player);
canBlast = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_BLAST_MINING) && Permissions.remoteDetonation(player);
canDemoExpert = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_DEMOLITIONS_EXPERTISE) && Permissions.demolitionsExpertise(player);
canBiggerBombs = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_BIGGER_BOMBS)
&& Permissions.biggerBombs(player);
canBlast = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_BLAST_MINING)
&& Permissions.remoteDetonation(player);
canDemoExpert =
RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_DEMOLITIONS_EXPERTISE)
&& Permissions.demolitionsExpertise(player);
canDoubleDrop = Permissions.canUseSubSkill(player, SubSkillType.MINING_DOUBLE_DROPS);
canTripleDrop = Permissions.canUseSubSkill(player, SubSkillType.MINING_MOTHER_LODE);
canSuperBreaker = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_SUPER_BREAKER) && Permissions.superBreaker(player);
canSuperBreaker = RankUtils.hasUnlockedSubskill(player, SubSkillType.MINING_SUPER_BREAKER)
&& Permissions.superBreaker(player);
}
@Override
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance, boolean isLucky) {
protected List<String> statsDisplay(Player player, float skillValue, boolean hasEndurance,
boolean isLucky) {
List<String> messages = new ArrayList<>();
if (canBiggerBombs) {
messages.add(getStatMessage(true, true, SubSkillType.MINING_BLAST_MINING, String.valueOf(blastRadiusIncrease)));
messages.add(getStatMessage(true, true, SubSkillType.MINING_BLAST_MINING,
String.valueOf(blastRadiusIncrease)));
//messages.add(LocaleLoader.getString("Mining.Blast.Radius.Increase", blastRadiusIncrease));
}
if (canBlast) {
messages.add(getStatMessage(false, true, SubSkillType.MINING_BLAST_MINING, String.valueOf(blastMiningRank), String.valueOf(RankUtils.getHighestRank(SubSkillType.MINING_BLAST_MINING)), LocaleLoader.getString("Mining.Blast.Effect", oreBonus, bonusTNTDrops)));
messages.add(getStatMessage(false, true, SubSkillType.MINING_BLAST_MINING,
String.valueOf(blastMiningRank),
String.valueOf(RankUtils.getHighestRank(SubSkillType.MINING_BLAST_MINING)),
LocaleLoader.getString("Mining.Blast.Effect", oreBonus, bonusTNTDrops)));
//messages.add(LocaleLoader.getString("Mining.Blast.Rank", blastMiningRank, RankUtils.getHighestRank(SubSkillType.MINING_BLAST_MINING), LocaleLoader.getString("Mining.Blast.Effect", oreBonus, debrisReduction, bonusTNTDrops)));
}
if (canDemoExpert) {
messages.add(getStatMessage(SubSkillType.MINING_DEMOLITIONS_EXPERTISE, blastDamageDecrease));
if (canDemoExpert) {
messages.add(
getStatMessage(SubSkillType.MINING_DEMOLITIONS_EXPERTISE, blastDamageDecrease));
//messages.add(LocaleLoader.getString("Mining.Effect.Decrease", blastDamageDecrease));
}
if (canDoubleDrop) {
messages.add(getStatMessage(SubSkillType.MINING_DOUBLE_DROPS, doubleDropChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky)
: ""));
//messages.add(LocaleLoader.getString("Mining.Effect.DropChance", doubleDropChance) + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", doubleDropChanceLucky) : ""));
}
if (canTripleDrop) {
messages.add(getStatMessage(SubSkillType.MINING_MOTHER_LODE, tripleDropChance)
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", tripleDropChanceLucky) : ""));
+ (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", tripleDropChanceLucky)
: ""));
}
if (canSuperBreaker) {
messages.add(getStatMessage(SubSkillType.MINING_SUPER_BREAKER, superBreakerLength)
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", superBreakerLengthEndurance) : ""));
+ (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus",
superBreakerLengthEndurance) : ""));
//messages.add(LocaleLoader.getString("Mining.Ability.Length", superBreakerLength) + (hasEndurance ? LocaleLoader.getString("Perks.ActivationTime.Bonus", superBreakerLengthEndurance) : ""));
}
@@ -129,7 +144,8 @@ public class MiningCommand extends SkillCommand {
protected List<Component> getTextComponents(Player player) {
List<Component> textComponents = new ArrayList<>();
TextComponentFactory.getSubSkillTextComponents(player, textComponents, PrimarySkillType.MINING);
TextComponentFactory.getSubSkillTextComponents(player, textComponents,
PrimarySkillType.MINING);
return textComponents;
}

View File

@@ -6,6 +6,8 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.text.TextComponentFactory;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -13,34 +15,34 @@ import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* This is the command that retrieves data about skills from in-game sources
*/
public class MmoInfoCommand implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, String[] args) {
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command,
@NotNull String s, String[] args) {
/*
* Only allow players to use this command
*/
if (commandSender instanceof Player player) {
if (args == null || args.length < 1 || args[0] == null || args[0].isEmpty())
if (args == null || args.length < 1 || args[0] == null || args[0].isEmpty()) {
return false;
}
if (Permissions.mmoinfo(player)) {
if (args[0].equalsIgnoreCase( "???")) {
if (args[0].equalsIgnoreCase("???")) {
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Header"));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", "???"));
player.sendMessage(
LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", "???"));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader"));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Mystery"));
return true;
}
final SubSkillType subSkillType = matchSubSkill(args[0]);
if (subSkillType != null) {
if (subSkillType != null) {
displayInfo(player, subSkillType);
} else {
//Not a real skill
@@ -54,28 +56,34 @@ public class MmoInfoCommand implements TabExecutor {
}
public SubSkillType matchSubSkill(String name) {
for(SubSkillType subSkillType : SubSkillType.values()) {
for (SubSkillType subSkillType : SubSkillType.values()) {
if (subSkillType.getNiceNameNoSpaces(subSkillType).equalsIgnoreCase(name)
|| subSkillType.name().equalsIgnoreCase(name))
|| subSkillType.name().equalsIgnoreCase(name)) {
return subSkillType;
}
}
return null;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String alias, String[] args) {
if (args.length == 1) {
return StringUtil.copyPartialMatches(args[0], mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES, new ArrayList<>(mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.size()));
return StringUtil.copyPartialMatches(args[0],
mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES,
new ArrayList<>(mcMMO.p.getSkillTools().EXACT_SUBSKILL_NAMES.size()));
}
return ImmutableList.of();
}
private void displayInfo(Player player, SubSkillType subSkillType) {
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.Header"));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader", subSkillType.getLocaleName()));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.SubSkillHeader",
subSkillType.getLocaleName()));
player.sendMessage(LocaleLoader.getString("Commands.MmoInfo.DetailsHeader"));
//Send Player Wiki Link
TextComponentFactory.sendPlayerSubSkillWikiLink(player, subSkillType.getLocaleName(), subSkillType);
TextComponentFactory.sendPlayerSubSkillWikiLink(player, subSkillType.getLocaleName(),
subSkillType);
}
}

Some files were not shown because too many files have changed in this diff Show More