More dependency injection fixes in many file

This commit is contained in:
nossr50 2019-09-24 16:34:12 -07:00
parent 4b1cdbf493
commit 564b8ceb94
13 changed files with 41 additions and 112 deletions

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.commands.admin; package com.gmail.nossr50.commands.admin;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.mcMMO;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -9,10 +9,16 @@ import org.bukkit.entity.Player;
public class PlayerDebugCommand implements CommandExecutor { public class PlayerDebugCommand implements CommandExecutor {
private final mcMMO pluginRef;
public PlayerDebugCommand(mcMMO pluginRef) {
this.pluginRef = pluginRef;
}
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(sender instanceof Player) { if(sender instanceof Player) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer((Player) sender); McMMOPlayer mcMMOPlayer = pluginRef.getUserManager().getPlayer((Player) sender);
mcMMOPlayer.toggleDebugMode(); //Toggle debug mode mcMMOPlayer.toggleDebugMode(); //Toggle debug mode
pluginRef.getNotificationManager().sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mcMMOPlayer.isDebugMode())); pluginRef.getNotificationManager().sendPlayerInformationChatOnlyPrefixed(mcMMOPlayer.getPlayer(), "Commands.Mmodebug.Toggle", String.valueOf(mcMMOPlayer.isDebugMode()));
return true; return true;

View File

@ -22,7 +22,6 @@ public class ConvertExperienceCommand implements CommandExecutor {
switch (args.length) { switch (args.length) {
case 2: case 2:
for(FormulaType formulaType : FormulaType.values()) { for(FormulaType formulaType : FormulaType.values()) {
if(formulaType.toString().equalsIgnoreCase(args[1])) { if(formulaType.toString().equalsIgnoreCase(args[1])) {
FormulaType previousType = formulaType; FormulaType previousType = formulaType;
@ -32,10 +31,10 @@ public class ConvertExperienceCommand implements CommandExecutor {
pluginRef.getUserManager().saveAll(); pluginRef.getUserManager().saveAll();
pluginRef.getUserManager().clearAll(); pluginRef.getUserManager().clearAll();
new FormulaConversionTask(sender, previousType).runTaskLater(pluginRef, 1); new FormulaConversionTask(pluginRef, sender, previousType).runTaskLater(pluginRef, 1);
for (Player player : pluginRef.getServer().getOnlinePlayers()) { for (Player player : pluginRef.getServer().getOnlinePlayers()) {
new PlayerProfileLoadingTask(player).runTaskLaterAsynchronously(pluginRef, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading new PlayerProfileLoadingTask(pluginRef, player).runTaskLaterAsynchronously(pluginRef, 1); // 1 Tick delay to ensure the player is marked as online before we begin loading
} }
return true; return true;
@ -45,8 +44,6 @@ public class ConvertExperienceCommand implements CommandExecutor {
sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.mcconvert.Experience.Invalid")); sender.sendMessage(pluginRef.getLocaleManager().getString("Commands.mcconvert.Experience.Invalid"));
return true; return true;
default: default:
return false; return false;
} }

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.commands.player;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType; import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.scoreboards.SidebarType;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -33,10 +34,10 @@ public class CooldownCommand implements TabExecutor {
case 0: case 0:
Player player = (Player) sender; Player player = (Player) sender;
if (pluginRef.getScoreboardSettings().getScoreboardsEnabled() && pluginRef.getScoreboardSettings().isScoreboardEnabled(pluginRef.getScoreboardManager().SidebarType.COOLDOWNS_BOARD)) { if (pluginRef.getScoreboardSettings().getScoreboardsEnabled() && pluginRef.getScoreboardSettings().isScoreboardEnabled(SidebarType.COOLDOWNS_BOARD)) {
pluginRef.getScoreboardManager().enablePlayerCooldownScoreboard(player); pluginRef.getScoreboardManager().enablePlayerCooldownScoreboard(player);
if (!pluginRef.getScoreboardSettings().isScoreboardPrinting(pluginRef.getScoreboardManager().SidebarType.COOLDOWNS_BOARD)) { if (!pluginRef.getScoreboardSettings().isScoreboardPrinting(SidebarType.COOLDOWNS_BOARD)) {
return true; return true;
} }
} }
@ -51,17 +52,17 @@ public class CooldownCommand implements TabExecutor {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Cooldowns.Header")); player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Cooldowns.Header"));
player.sendMessage(pluginRef.getLocaleManager().getString("mcMMO.NoSkillNote")); player.sendMessage(pluginRef.getLocaleManager().getString("mcMMO.NoSkillNote"));
for (SuperAbilityType ability : SuperAbilityType.values()) { for (SuperAbilityType superAbilityType : SuperAbilityType.values()) {
if (!ability.superAbilityPermissionCheck(player)) { if (!pluginRef.getSkillTools().superAbilityPermissionCheck(superAbilityType, player)) {
continue; continue;
} }
int seconds = mcMMOPlayer.calculateTimeRemaining(ability); int seconds = mcMMOPlayer.calculateTimeRemaining(superAbilityType);
if (seconds <= 0) { if (seconds <= 0) {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Cooldowns.Row.Y", ability.getPrettySuperAbilityName())); player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Cooldowns.Row.Y", pluginRef.getSkillTools().getPrettySuperAbilityName(superAbilityType)));
} else { } else {
player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Cooldowns.Row.N", ability.getPrettySuperAbilityName(), seconds)); player.sendMessage(pluginRef.getLocaleManager().getString("Commands.Cooldowns.Row.N", pluginRef.getSkillTools().getPrettySuperAbilityName(superAbilityType), seconds));
} }
} }

View File

@ -50,17 +50,17 @@ public class InspectCommand implements TabExecutor {
sender.sendMessage(pluginRef.getLocaleManager().getString("Inspect.OfflineStats", playerName)); sender.sendMessage(pluginRef.getLocaleManager().getString("Inspect.OfflineStats", playerName));
sender.sendMessage(pluginRef.getLocaleManager().getString("Stats.Header.Gathering")); sender.sendMessage(pluginRef.getLocaleManager().getString("Stats.Header.Gathering"));
for (PrimarySkillType skill : PrimarySkillType.GATHERING_SKILLS) { for (PrimarySkillType skill : pluginRef.getSkillTools().GATHERING_SKILLS) {
sender.sendMessage(pluginRef.getCommandTools().displaySkill(profile, skill)); sender.sendMessage(pluginRef.getCommandTools().displaySkill(profile, skill));
} }
sender.sendMessage(pluginRef.getLocaleManager().getString("Stats.Header.Combat")); sender.sendMessage(pluginRef.getLocaleManager().getString("Stats.Header.Combat"));
for (PrimarySkillType skill : PrimarySkillType.COMBAT_SKILLS) { for (PrimarySkillType skill : pluginRef.getSkillTools().COMBAT_SKILLS) {
sender.sendMessage(pluginRef.getCommandTools().displaySkill(profile, skill)); sender.sendMessage(pluginRef.getCommandTools().displaySkill(profile, skill));
} }
sender.sendMessage(pluginRef.getLocaleManager().getString("Stats.Header.Misc")); sender.sendMessage(pluginRef.getLocaleManager().getString("Stats.Header.Misc"));
for (PrimarySkillType skill : PrimarySkillType.MISC_SKILLS) { for (PrimarySkillType skill : pluginRef.getSkillTools().MISC_SKILLS) {
sender.sendMessage(pluginRef.getCommandTools().displaySkill(profile, skill)); sender.sendMessage(pluginRef.getCommandTools().displaySkill(profile, skill));
} }

View File

@ -6,6 +6,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.commands.LeaderboardsCommandAsyncTask; import com.gmail.nossr50.runnables.commands.LeaderboardsCommandAsyncTask;
import com.gmail.nossr50.util.StringUtils; import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.scoreboards.SidebarType;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -116,10 +117,10 @@ public class LeaderboardCommand implements TabExecutor {
} }
private void display(int page, PrimarySkillType skill, CommandSender sender) { private void display(int page, PrimarySkillType skill, CommandSender sender) {
boolean useBoard = (sender instanceof Player) && (pluginRef.getScoreboardSettings().isScoreboardEnabled(pluginRef.getScoreboardManager().SidebarType.TOP_BOARD)); boolean useBoard = (sender instanceof Player) && (pluginRef.getScoreboardSettings().isScoreboardEnabled(SidebarType.TOP_BOARD));
boolean useChat = !useBoard || pluginRef.getScoreboardSettings().isScoreboardPrinting(pluginRef.getScoreboardManager().SidebarType.TOP_BOARD); boolean useChat = !useBoard || pluginRef.getScoreboardSettings().isScoreboardPrinting(SidebarType.TOP_BOARD);
new LeaderboardsCommandAsyncTask(page, skill, sender, useBoard, useChat).runTaskAsynchronously(pluginRef); new LeaderboardsCommandAsyncTask(pluginRef, page, skill, sender, useBoard, useChat).runTaskAsynchronously(pluginRef);
} }
private PrimarySkillType extractSkill(CommandSender sender, String skillName) { private PrimarySkillType extractSkill(CommandSender sender, String skillName) {
@ -127,7 +128,7 @@ public class LeaderboardCommand implements TabExecutor {
return null; return null;
} }
PrimarySkillType skill = PrimarySkillType.matchSkill(skillName); PrimarySkillType skill = pluginRef.getSkillTools().matchSkill(skillName);
if (pluginRef.getCommandTools().isChildSkill(sender, skill)) { if (pluginRef.getCommandTools().isChildSkill(sender, skill)) {
return null; return null;

View File

@ -113,8 +113,8 @@ public class RankCommand implements TabExecutor {
} }
boolean useBoard = pluginRef.getScoreboardSettings().getScoreboardsEnabled() && (sender instanceof Player) boolean useBoard = pluginRef.getScoreboardSettings().getScoreboardsEnabled() && (sender instanceof Player)
&& (pluginRef.getScoreboardSettings().isScoreboardEnabled(pluginRef.getScoreboardManager().SidebarType.RANK_BOARD)); && (pluginRef.getScoreboardSettings().isScoreboardEnabled(SidebarType.RANK_BOARD));
boolean useChat = !useBoard || pluginRef.getScoreboardSettings().isScoreboardPrinting(pluginRef.getScoreboardManager().SidebarType.RANK_BOARD); boolean useChat = !useBoard || pluginRef.getScoreboardSettings().isScoreboardPrinting(SidebarType.RANK_BOARD);
new RankCommandAsyncTask(playerName, sender, useBoard, useChat).runTaskAsynchronously(pluginRef); new RankCommandAsyncTask(playerName, sender, useBoard, useChat).runTaskAsynchronously(pluginRef);
} }

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.commands.player; package com.gmail.nossr50.commands.player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.scoreboards.SidebarType;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -36,10 +37,10 @@ public class SkillStatsCommand implements TabExecutor {
Player player = (Player) sender; Player player = (Player) sender;
if (pluginRef.getScoreboardSettings().isScoreboardEnabled(pluginRef.getScoreboardManager().SidebarType.STATS_BOARD) && pluginRef.getScoreboardSettings().getScoreboardsEnabled()) { if (pluginRef.getScoreboardSettings().isScoreboardEnabled(SidebarType.STATS_BOARD) && pluginRef.getScoreboardSettings().getScoreboardsEnabled()) {
pluginRef.getScoreboardManager().enablePlayerStatsScoreboard(player); pluginRef.getScoreboardManager().enablePlayerStatsScoreboard(player);
if (!pluginRef.getScoreboardSettings().isScoreboardPrinting(pluginRef.getScoreboardManager().SidebarType.STATS_BOARD)) { if (!pluginRef.getScoreboardSettings().isScoreboardPrinting(SidebarType.STATS_BOARD)) {
return true; return true;
} }
} }

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.config.hocon.skills.taming; package com.gmail.nossr50.config.hocon.skills.taming;
import com.gmail.nossr50.config.ConfigConstants; import com.gmail.nossr50.config.ConfigConstants;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ -47,10 +46,6 @@ public class ConfigTaming {
return subSkills.getPummel(); return subSkills.getPummel();
} }
public String getItemString(CallOfTheWildType callOfTheWildType) {
return subSkills.getItemString(callOfTheWildType);
}
public double getMinHorseJumpStrength() { public double getMinHorseJumpStrength() {
return subSkills.getMinHorseJumpStrength(); return subSkills.getMinHorseJumpStrength();
} }

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.config.hocon.skills.taming; package com.gmail.nossr50.config.hocon.skills.taming;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ -63,10 +62,6 @@ public class ConfigTamingSubSkills {
return pummel; return pummel;
} }
public String getItemString(CallOfTheWildType callOfTheWildType) {
return callOfTheWild.getItemString(callOfTheWildType);
}
public double getMinHorseJumpStrength() { public double getMinHorseJumpStrength() {
return callOfTheWild.getMinHorseJumpStrength(); return callOfTheWild.getMinHorseJumpStrength();
} }

View File

@ -42,7 +42,8 @@ public class TamingItemManager {
} }
public void registerSummonItemRelationships(CallOfTheWildType callOfTheWildType, Material defaultType) { public void registerSummonItemRelationships(CallOfTheWildType callOfTheWildType, Material defaultType) {
String materialString = pluginRef.getConfigManager().getConfigTaming().getSubSkills().getCallOfTheWild().getItemString(callOfTheWildType); //TODO: Unnecessarily complicated
String materialString = pluginRef.getConfigManager().getConfigTaming().getSubSkills().getCallOfTheWild().getCOTWSummon(callOfTheWildType).getItemType().getKey().toString();
pluginRef.getLogger().info("Registering COTW Summon Item - "+callOfTheWildType.toString()+" | "+materialString); pluginRef.getLogger().info("Registering COTW Summon Item - "+callOfTheWildType.toString()+" | "+materialString);
Material material = Material.matchMaterial(materialString); Material material = Material.matchMaterial(materialString);

View File

@ -9,23 +9,23 @@ import org.bukkit.scheduler.BukkitRunnable;
public class AbilityCooldownTask extends BukkitRunnable { public class AbilityCooldownTask extends BukkitRunnable {
private final mcMMO pluginRef; private final mcMMO pluginRef;
private final McMMOPlayer mcMMOPlayer; private final McMMOPlayer mcMMOPlayer;
private final SuperAbilityType ability; private final SuperAbilityType superAbilityType;
public AbilityCooldownTask(mcMMO pluginRef, McMMOPlayer mcMMOPlayer, SuperAbilityType ability) { public AbilityCooldownTask(mcMMO pluginRef, McMMOPlayer mcMMOPlayer, SuperAbilityType superAbilityType) {
this.pluginRef = pluginRef; this.pluginRef = pluginRef;
this.mcMMOPlayer = mcMMOPlayer; this.mcMMOPlayer = mcMMOPlayer;
this.ability = ability; this.superAbilityType = superAbilityType;
} }
@Override @Override
public void run() { public void run() {
if (!mcMMOPlayer.getPlayer().isOnline() || mcMMOPlayer.getSuperAbilityInformed(ability)) { if (!mcMMOPlayer.getPlayer().isOnline() || mcMMOPlayer.getSuperAbilityInformed(superAbilityType)) {
return; return;
} }
mcMMOPlayer.setAbilityInformed(ability, true); mcMMOPlayer.setAbilityInformed(superAbilityType, true);
pluginRef.getNotificationManager().sendPlayerInformation(mcMMOPlayer.getPlayer(), NotificationType.ABILITY_REFRESHED, ability.getSuperAbilityRefreshedStr()); pluginRef.getNotificationManager().sendPlayerInformation(mcMMOPlayer.getPlayer(), NotificationType.ABILITY_REFRESHED, pluginRef.getSkillTools().getSuperAbilityRefreshedStr(superAbilityType));
//mcMMOPlayer.getPlayer().sendMessage(ability.getAbilityRefresh()); //mcMMOPlayer.getPlayer().sendMessage(ability.getAbilityRefresh());
} }
} }

View File

@ -1,69 +0,0 @@
package com.gmail.nossr50.skills.unarmed;
import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.inventory.ItemStack;
public class Unarmed {
// public static boolean blockCrackerSmoothBrick = MainConfig.getInstance().getUnarmedBlockCrackerSmoothbrickToCracked();
public static double berserkDamageModifier = 1.5;
public static void handleItemPickup(Player player, EntityPickupItemEvent event) {
ItemStack[] storageContents = player.getInventory().getStorageContents();
ItemStack itemDrop = event.getItem().getItemStack();
int heldItemSlotID = player.getInventory().getHeldItemSlot();
int amount = itemDrop.getAmount();
boolean grabbedItem = false;
for (int i = 0; i <= storageContents.length - 1; i++) {
if (amount <= 0)
break;
if (i == heldItemSlotID)
continue;
//EMPTY SLOT!
if (storageContents[i] == null) {
player.getInventory().setItem(i, itemDrop);
amount = 0;
grabbedItem = true;
break;
} else if (itemDrop.isSimilar(storageContents[i]) && storageContents[i].getAmount() < storageContents[i].getMaxStackSize()) {
//If we can fit this whole itemstack into this item
if (amount + storageContents[i].getAmount() <= storageContents[i].getMaxStackSize()) {
ItemStack modifiedAmount = storageContents[i];
modifiedAmount.setAmount(amount + storageContents[i].getAmount());
player.getInventory().setItem(i, modifiedAmount);
grabbedItem = true;
amount = 0;
} else {
//Add what we can from this stack
ItemStack modifiedAmount = storageContents[i];
int amountThatCanFit = storageContents[i].getMaxStackSize() - storageContents[i].getAmount();
modifiedAmount.setAmount(amountThatCanFit);
player.getInventory().setItem(i, modifiedAmount);
//Remove the amount we've added
grabbedItem = true;
amount -= amountThatCanFit;
}
}
}
if (amount <= 0)
event.getItem().remove(); //Cleanup Item
else
event.getItem().getItemStack().setAmount(amount);
event.setCancelled(true);
if (grabbedItem) {
pluginRef.getSoundManager().sendSound(player, player.getLocation(), SoundType.POP);
player.updateInventory();
}
}
}

View File

@ -21,6 +21,7 @@ import org.bukkit.inventory.ItemStack;
public class UnarmedManager extends SkillManager { public class UnarmedManager extends SkillManager {
private long lastAttacked; private long lastAttacked;
private long attackInterval; private long attackInterval;
public double berserkDamageModifier = 1.5;
public UnarmedManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) { public UnarmedManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
super(pluginRef, mcMMOPlayer, PrimarySkillType.UNARMED); super(pluginRef, mcMMOPlayer, PrimarySkillType.UNARMED);
@ -135,7 +136,7 @@ public class UnarmedManager extends SkillManager {
* @param damage The amount of damage initially dealt by the event * @param damage The amount of damage initially dealt by the event
*/ */
public double berserkDamage(double damage) { public double berserkDamage(double damage) {
damage = (damage * Unarmed.berserkDamageModifier) - damage; damage = (damage * berserkDamageModifier) - damage;
return damage; return damage;
} }