More cleanup on ability activation handling

This commit is contained in:
nossr50 2020-07-31 17:41:43 -07:00
parent 03f1733387
commit ea2e2bdc9a
8 changed files with 275 additions and 131 deletions

View File

@ -5,7 +5,7 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import org.bukkit.command.CommandSender;
public class McabilityCommand extends ToggleCommand {
public class AbilityToggleCommand extends ToggleCommand {
@Override
protected boolean hasOtherPermission(CommandSender sender) {
return Permissions.mcabilityOthers(sender);

View File

@ -39,6 +39,7 @@ import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.experience.ExperienceBarManager;
import com.gmail.nossr50.util.input.AbilityActivationProcessor;
import com.gmail.nossr50.util.input.SuperAbilityManager;
import com.gmail.nossr50.util.player.NotificationManager;
import com.gmail.nossr50.util.player.UserManager;
@ -93,6 +94,7 @@ public class McMMOPlayer {
private final FixedMetadataValue playerMetadata;
private final String playerName;
private final SuperAbilityManager superAbilityManager;
private final AbilityActivationProcessor abilityActivationProcessor;
public McMMOPlayer(Player player, PlayerProfile profile) {
this.playerName = player.getName();
@ -122,6 +124,7 @@ public class McMMOPlayer {
}
superAbilityManager = new SuperAbilityManager(this);
abilityActivationProcessor = new AbilityActivationProcessor(this);
experienceBarManager = new ExperienceBarManager(this, profile.getXpBarStateMap());
@ -834,6 +837,9 @@ public class McMMOPlayer {
return superAbilityManager;
}
public AbilityActivationProcessor getAbilityActivationProcessor() {
return abilityActivationProcessor;
}
/**
* Cleanup various things related to this player

View File

@ -11,20 +11,16 @@ import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.runnables.player.PlayerProfileLoadingTask;
import com.gmail.nossr50.skills.fishing.FishingManager;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.RepairManager;
import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.skills.salvage.SalvageManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.*;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.scoreboards.ScoreboardManager;
@ -34,11 +30,9 @@ import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import com.gmail.nossr50.worldguard.WorldGuardManager;
import com.gmail.nossr50.worldguard.WorldGuardUtils;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.*;
import org.bukkit.entity.minecart.PoweredMinecart;
import org.bukkit.event.Event;
@ -709,15 +703,15 @@ public class PlayerListener implements Listener {
/**
* Monitor PlayerInteractEvents.
*
* @param event The event to monitor
* @param playerInteractEvent The playerInteractEvent to monitor
*/
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerInteractMonitor(PlayerInteractEvent event) {
public void onPlayerInteractMonitor(PlayerInteractEvent playerInteractEvent) {
/* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getPlayer().getWorld()))
if(WorldBlacklist.isWorldBlacklisted(playerInteractEvent.getPlayer().getWorld()))
return;
Player player = event.getPlayer();
Player player = playerInteractEvent.getPlayer();
/* WORLD GUARD MAIN FLAG CHECK */
if(WorldGuardUtils.isWorldGuardLoaded())
@ -726,7 +720,7 @@ public class PlayerListener implements Listener {
return;
}
if (event.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) {
if (playerInteractEvent.getHand() != EquipmentSlot.HAND || !UserManager.hasPlayerDataKey(player) || player.getGameMode() == GameMode.CREATIVE) {
return;
}
@ -740,7 +734,7 @@ public class PlayerListener implements Listener {
ItemStack heldItem = player.getInventory().getItemInMainHand();
//Spam Fishing Detection
if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)
if(playerInteractEvent.getAction() == Action.RIGHT_CLICK_BLOCK || playerInteractEvent.getAction() == Action.RIGHT_CLICK_AIR)
{
if(ExperienceConfig.getInstance().isFishingExploitingPrevented()
&& (heldItem.getType() == Material.FISHING_ROD || player.getInventory().getItemInOffHand().getType() == Material.FISHING_ROD))
@ -755,123 +749,7 @@ public class PlayerListener implements Listener {
}
}
switch (event.getAction()) {
case RIGHT_CLICK_BLOCK:
if(player.getInventory().getItemInOffHand().getType() != Material.AIR && !player.isInsideVehicle() && !player.isSneaking()) {
break;
}
//Hmm
if(event.getClickedBlock() == null)
return;
Block block = event.getClickedBlock();
BlockState blockState = block.getState();
/* ACTIVATION & ITEM CHECKS */
if (BlockUtils.canActivateTools(blockState)) {
if (Config.getInstance().getAbilitiesEnabled()) {
if (BlockUtils.canActivateHerbalism(blockState)) {
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.HERBALISM);
}
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.AXES);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.EXCAVATION);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.MINING);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.SWORDS);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.UNARMED);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.WOODCUTTING);
}
ChimaeraWing.activationCheck(player);
}
/* GREEN THUMB CHECK */
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
if (heldItem.getType() == Material.BONE_MEAL) {
switch (blockState.getType()) {
case BEETROOTS:
case CARROT:
case COCOA:
case WHEAT:
case NETHER_WART_BLOCK:
case POTATO:
mcMMO.getPlaceStore().setFalse(blockState);
}
}
FakePlayerAnimationEvent fakeSwing = new FakePlayerAnimationEvent(event.getPlayer()); //PlayerAnimationEvent compat
if (herbalismManager.canGreenThumbBlock(blockState)) {
Bukkit.getPluginManager().callEvent(fakeSwing);
player.getInventory().setItemInMainHand(new ItemStack(Material.WHEAT_SEEDS, heldItem.getAmount() - 1));
if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
blockState.update(true);
}
}
/* SHROOM THUMB CHECK */
else if (herbalismManager.canUseShroomThumb(blockState)) {
Bukkit.getPluginManager().callEvent(fakeSwing);
event.setCancelled(true);
if (herbalismManager.processShroomThumb(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
blockState.update(true);
}
}
break;
case RIGHT_CLICK_AIR:
if(player.getInventory().getItemInOffHand().getType() != Material.AIR && !player.isInsideVehicle() && !player.isSneaking()) {
break;
}
/* ACTIVATION CHECKS */
if (Config.getInstance().getAbilitiesEnabled()) {
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.AXES);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.EXCAVATION);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.HERBALISM);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.MINING);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.SWORDS);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.UNARMED);
mcMMOPlayer.getSuperAbilityManager().processAbilityActivation(PrimarySkillType.WOODCUTTING);
}
/* ITEM CHECKS */
ChimaeraWing.activationCheck(player);
/* BLAST MINING CHECK */
MiningManager miningManager = mcMMOPlayer.getMiningManager();
if (miningManager.canDetonate()) {
miningManager.remoteDetonation();
}
break;
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
if (!player.isSneaking()) {
break;
}
/* CALL OF THE WILD CHECKS */
Material type = heldItem.getType();
TamingManager tamingManager = mcMMOPlayer.getTamingManager();
if (type == Config.getInstance().getTamingCOTWMaterial(CallOfTheWildType.WOLF.getConfigEntityTypeEntry())) {
tamingManager.summonWolf();
}
else if (type == Config.getInstance().getTamingCOTWMaterial(CallOfTheWildType.CAT.getConfigEntityTypeEntry())) {
tamingManager.summonOcelot();
}
else if (type == Config.getInstance().getTamingCOTWMaterial(CallOfTheWildType.HORSE.getConfigEntityTypeEntry())) {
tamingManager.summonHorse();
}
break;
default:
break;
}
mcMMOPlayer.getAbilityActivationProcessor().processAbilityAndToolActivations(playerInteractEvent);
}
/**

View File

@ -11,6 +11,7 @@ import com.gmail.nossr50.skills.salvage.Salvage;
import com.gmail.nossr50.util.random.RandomChanceSkill;
import com.gmail.nossr50.util.random.RandomChanceUtil;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
@ -94,6 +95,48 @@ public final class BlockUtils {
&& blockState.getType() != Salvage.anvilMaterial;
}
/**
* Check if a given block should allow for the activation of tools
* Activating a tool is step 1 of a 2 step process for super ability activation
*
* @param block The {@link Block} of the block to check
* @return true if the block should allow ability activation, false
* otherwise
*/
public static boolean canActivateTools(Block block) {
return !mcMMO.getMaterialMapStore().isToolActivationBlackListed(block.getType())
&& block.getType() != Repair.anvilMaterial
&& block.getType() != Salvage.anvilMaterial;
}
/**
* Check if a given block should allow for the activation of tools
* Activating a tool is step 1 of a 2 step process for super ability activation
*
* @param material The {@link Material} of the block to check
* @return true if the block should allow ability activation, false
* otherwise
*/
public static boolean canActivateTools(Material material) {
return !mcMMO.getMaterialMapStore().isToolActivationBlackListed(material)
&& material != Repair.anvilMaterial
&& material != Salvage.anvilMaterial;
}
/**
* Check if a given block should allow for the activation of tools
* Activating a tool is step 1 of a 2 step process for super ability activation
*
* @param blockId The {@link String} of the block namespaced id to check
* @return true if the block should allow ability activation, false
* otherwise
*/
public static boolean canActivateTools(String blockId) {
return !mcMMO.getMaterialMapStore().isToolActivationBlackListed(blockId)
&& !blockId.equals(Repair.anvilMaterial.getKey().getKey())
&& !blockId.equals(Salvage.anvilMaterial.getKey().getKey());
}
/**
* Check if a given block is an ore
*
@ -205,6 +248,17 @@ public final class BlockUtils {
return mcMMO.getMaterialMapStore().isHerbalismAbilityWhiteListed(blockState.getType());
}
/**
* Determine if a given block can activate Herbalism abilities
*
* @param block The {@link Block} of the block to check
* @return true if the block can be activate Herbalism abilities, false
* otherwise
*/
public static boolean canActivateHerbalism(Block block) {
return mcMMO.getMaterialMapStore().isHerbalismAbilityWhiteListed(block.getType());
}
/**
* Determine if a given block should be affected by Block Cracker
*

View File

@ -120,6 +120,11 @@ public class MaterialMapStore {
return toolBlackList.contains(material.getKey().getKey());
}
public boolean isToolActivationBlackListed(String blockId)
{
return toolBlackList.contains(blockId);
}
public boolean isMossyWhiteListed(Material material)
{
return mossyWhiteList.contains(material.getKey().getKey());

View File

@ -243,7 +243,7 @@ public final class CommandRegistrationManager {
command.setPermission("mcmmo.commands.mcability;mcmmo.commands.mcability.others");
command.setPermissionMessage(permissionsMessage);
command.setUsage(LocaleLoader.getString("Commands.Usage.1", "mcability", "[" + LocaleLoader.getString("Commands.Usage.Player") + "]"));
command.setExecutor(new McabilityCommand());
command.setExecutor(new AbilityToggleCommand());
}
private static void registerMcmmoCommand() {

View File

@ -0,0 +1,189 @@
package com.gmail.nossr50.util.input;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.EventUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class AbilityActivationProcessor {
private final McMMOPlayer mmoPlayer;
private final Player player;
public AbilityActivationProcessor(McMMOPlayer mmoPlayer) {
this.mmoPlayer = mmoPlayer;
this.player = mmoPlayer.getPlayer();
}
public void processAbilityAndToolActivations(PlayerInteractEvent event) {
switch(event.getAction()) {
case LEFT_CLICK_BLOCK:
processLeftClickBlock();
break;
case RIGHT_CLICK_BLOCK:
processRightClickBlock(event);
break;
case LEFT_CLICK_AIR:
processLeftClickAir();
break;
case RIGHT_CLICK_AIR:
processRightClickAir();
break;
case PHYSICAL:
break;
}
}
private void processRightClickBlock(PlayerInteractEvent playerInteractEvent) {
/*
Right clicked on block
*/
if(player.getInventory().getItemInOffHand().getType() != Material.AIR && !player.isInsideVehicle() && !player.isSneaking()) {
return;
}
Block block = playerInteractEvent.getClickedBlock();
if(block == null)
return;
BlockState blockState = block.getState();
if(playerInteractEvent.getClickedBlock() != null) {
if (BlockUtils.canActivateTools(playerInteractEvent.getClickedBlock())) {
if (Config.getInstance().getAbilitiesEnabled()) {
if (BlockUtils.canActivateHerbalism(playerInteractEvent.getClickedBlock())) {
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.HERBALISM);
}
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.AXES);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.EXCAVATION);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.MINING);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.SWORDS);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.UNARMED);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.WOODCUTTING);
}
//TODO: Move this
ChimaeraWing.activationCheck(player);
}
}
/* GREEN THUMB CHECK */
HerbalismManager herbalismManager = mmoPlayer.getHerbalismManager();
if (getHeldItem().getType() == Material.BONE_MEAL) {
switch (blockState.getType()) {
case BEETROOTS:
case CARROT:
case COCOA:
case WHEAT:
case NETHER_WART_BLOCK:
case POTATO:
mcMMO.getPlaceStore().setFalse(blockState);
}
}
FakePlayerAnimationEvent fakeSwing = new FakePlayerAnimationEvent(playerInteractEvent.getPlayer()); //PlayerAnimationEvent compat
if (herbalismManager.canGreenThumbBlock(blockState)) {
Bukkit.getPluginManager().callEvent(fakeSwing);
player.getInventory().setItemInMainHand(new ItemStack(Material.WHEAT_SEEDS, getHeldItem().getAmount() - 1));
if (herbalismManager.processGreenThumbBlocks(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
blockState.update(true);
}
}
/* SHROOM THUMB CHECK */
else if (herbalismManager.canUseShroomThumb(blockState)) {
Bukkit.getPluginManager().callEvent(fakeSwing);
playerInteractEvent.setCancelled(true);
if (herbalismManager.processShroomThumb(blockState) && EventUtils.simulateBlockBreak(block, player, false)) {
blockState.update(true);
}
}
}
private void processRightClickAir() {
if(player.getInventory().getItemInOffHand().getType() != Material.AIR && !player.isInsideVehicle() && !player.isSneaking()) {
return;
}
/* ACTIVATION CHECKS */
if (Config.getInstance().getAbilitiesEnabled()) {
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.AXES);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.EXCAVATION);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.HERBALISM);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.MINING);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.SWORDS);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.UNARMED);
getSuperAbilityManager().processAbilityActivation(PrimarySkillType.WOODCUTTING);
}
/* ITEM CHECKS */
ChimaeraWing.activationCheck(player);
//TODO: This is strange, why is this needed?
//TODO: This is strange, why is this needed?
//TODO: This is strange, why is this needed?
//TODO: This is strange, why is this needed?
//TODO: This is strange, why is this needed?
/* BLAST MINING CHECK */
MiningManager miningManager = mmoPlayer.getMiningManager();
if (miningManager.canDetonate()) {
miningManager.remoteDetonation();
}
}
private void processLeftClickBlock() {
processCallOfTheWildActivation();
}
private void processLeftClickAir() {
processCallOfTheWildActivation();
}
private void processCallOfTheWildActivation() {
if (!player.isSneaking()) {
return;
}
/* CALL OF THE WILD CHECKS */
Material type = getHeldItem().getType();
TamingManager tamingManager = mmoPlayer.getTamingManager();
if (type == Config.getInstance().getTamingCOTWMaterial(CallOfTheWildType.WOLF.getConfigEntityTypeEntry())) {
tamingManager.summonWolf();
}
else if (type == Config.getInstance().getTamingCOTWMaterial(CallOfTheWildType.CAT.getConfigEntityTypeEntry())) {
tamingManager.summonOcelot();
}
else if (type == Config.getInstance().getTamingCOTWMaterial(CallOfTheWildType.HORSE.getConfigEntityTypeEntry())) {
tamingManager.summonHorse();
}
}
private SuperAbilityManager getSuperAbilityManager() {
return mmoPlayer.getSuperAbilityManager();
}
private ItemStack getHeldItem() {
return player.getInventory().getItemInMainHand();
}
}

View File

@ -7,9 +7,16 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.skills.subskills.taming.CallOfTheWildType;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.AbilityDisableTask;
import com.gmail.nossr50.runnables.skills.ToolLowerTask;
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.BlockUtils;
import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.player.NotificationManager;
@ -18,7 +25,12 @@ import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
import com.gmail.nossr50.util.sounds.SoundManager;
import com.gmail.nossr50.util.sounds.SoundType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;