Refactor McMMOAbilityEvent(s) and fix TextComponentFactory

This commit is contained in:
nossr50
2019-09-23 19:42:47 -07:00
parent 815131a013
commit 14fa243b69
8 changed files with 455 additions and 465 deletions

View File

@@ -5,18 +5,11 @@ 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.behaviours.ExcavationBehaviour;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import org.bukkit.Location;
import org.bukkit.block.BlockState;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.entity.Player;
import java.util.List;
public class ExcavationManager extends SkillManager {
private final ExcavationBehaviour excavationBehaviour;
@@ -34,29 +27,29 @@ public class ExcavationManager extends SkillManager {
public void excavationBlockCheck(BlockState blockState) {
int xp = excavationBehaviour.getBlockXP(blockState);
if (pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.EXCAVATION_ARCHAEOLOGY)) {
List<ExcavationTreasure> treasures = excavationBehaviour.getTreasures(blockState);
if (!treasures.isEmpty()) {
int skillLevel = getSkillLevel();
Location location = Misc.getBlockCenter(blockState);
for (ExcavationTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel()
&& pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(getPlayer(), PrimarySkillType.EXCAVATION, treasure.getDropChance())) {
//Spawn Vanilla XP orbs if a dice roll succeeds
if(pluginRef.getRandomChanceTools().rollDice(getArchaelogyExperienceOrbChance(), 100)) {
ExperienceOrb experienceOrb = (ExperienceOrb) getPlayer().getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB);
experienceOrb.setExperience(getExperienceOrbsReward());
}
xp += treasure.getXp();
Misc.dropItem(location, treasure.getDrop());
}
}
}
}
// if (pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.EXCAVATION_ARCHAEOLOGY)) {
// List<ExcavationTreasure> treasures = excavationBehaviour.getTreasures(blockState);
//
// if (!treasures.isEmpty()) {
// int skillLevel = getSkillLevel();
// Location location = Misc.getBlockCenter(blockState);
//
// for (ExcavationTreasure treasure : treasures) {
// if (skillLevel >= treasure.getDropLevel()
// && pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(getPlayer(), PrimarySkillType.EXCAVATION, treasure.getDropChance())) {
//
// //Spawn Vanilla XP orbs if a dice roll succeeds
// if(pluginRef.getRandomChanceTools().rollDice(getArchaelogyExperienceOrbChance(), 100)) {
// ExperienceOrb experienceOrb = (ExperienceOrb) getPlayer().getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB);
// experienceOrb.setExperience(getExperienceOrbsReward());
// }
//
// xp += treasure.getXp();
// Misc.dropItem(location, treasure.getDrop());
// }
// }
// }
// }
applyXpGain(xp, XPGainReason.PVE);
}
@@ -75,21 +68,21 @@ public class ExcavationManager extends SkillManager {
public void printExcavationDebug(Player player, BlockState blockState)
{
if (pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.EXCAVATION_ARCHAEOLOGY)) {
List<ExcavationTreasure> treasures = excavationBehaviour.getTreasures(blockState);
if (!treasures.isEmpty()) {
for (ExcavationTreasure treasure : treasures) {
player.sendMessage("|||||||||||||||||||||||||||||||||");
player.sendMessage("[mcMMO DEBUG] Treasure found: (" + treasure.getDrop().getType().toString() + ")");
player.sendMessage("[mcMMO DEBUG] Drop Chance for Treasure: " + treasure.getDropChance());
player.sendMessage("[mcMMO DEBUG] Skill Level Required: " + treasure.getDropLevel());
player.sendMessage("[mcMMO DEBUG] XP for Treasure: " + treasure.getXp());
}
} else {
player.sendMessage("[mcMMO DEBUG] No treasures found for this block.");
}
}
// if (pluginRef.getPermissionTools().isSubSkillEnabled(getPlayer(), SubSkillType.EXCAVATION_ARCHAEOLOGY)) {
// List<ExcavationTreasure> treasures = excavationBehaviour.getTreasures(blockState);
//
// if (!treasures.isEmpty()) {
// for (ExcavationTreasure treasure : treasures) {
// player.sendMessage("|||||||||||||||||||||||||||||||||");
// player.sendMessage("[mcMMO DEBUG] Treasure found: (" + treasure.getDrop().getType().toString() + ")");
// player.sendMessage("[mcMMO DEBUG] Drop Chance for Treasure: " + treasure.getDropChance());
// player.sendMessage("[mcMMO DEBUG] Skill Level Required: " + treasure.getDropLevel());
// player.sendMessage("[mcMMO DEBUG] XP for Treasure: " + treasure.getXp());
// }
// } else {
// player.sendMessage("[mcMMO DEBUG] No treasures found for this block.");
// }
// }
}
/**

View File

@@ -11,16 +11,13 @@ import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.datatypes.skills.behaviours.HerbalismBehaviour;
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.runnables.skills.DelayedHerbalismXPCheckTask;
import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.random.RandomChanceSkillStatic;
import com.gmail.nossr50.util.skills.SkillActivationType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -36,7 +33,6 @@ import org.bukkit.metadata.FixedMetadataValue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
public class HerbalismManager extends SkillManager {
@@ -556,35 +552,36 @@ public class HerbalismManager extends SkillManager {
* @return true if the ability was successful, false otherwise
*/
public boolean processHylianLuck(BlockState blockState) {
if (!pluginRef.getRandomChanceTools().isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_HYLIAN_LUCK, getPlayer())) {
return false;
}
String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
if (!HerbalismTreasureConfig.getInstance().hylianMap.containsKey(friendly))
return false;
List<HylianTreasure> treasures = HerbalismTreasureConfig.getInstance().hylianMap.get(friendly);
Player player = getPlayer();
if (treasures.isEmpty()) {
return false;
}
int skillLevel = getSkillLevel();
Location location = Misc.getBlockCenter(blockState);
for (HylianTreasure treasure : treasures) {
if (skillLevel >= treasure.getDropLevel()
&& pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(treasure.getDropChance(), getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK))) {
if (!pluginRef.getEventManager().simulateBlockBreak(blockState.getBlock(), player, false)) {
return false;
}
blockState.setType(Material.AIR);
Misc.dropItem(location, treasure.getDrop());
pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Herbalism.HylianLuck");
return true;
}
}
// if (!pluginRef.getRandomChanceTools().isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.HERBALISM_HYLIAN_LUCK, getPlayer())) {
// return false;
// }
//
// String friendly = StringUtils.getFriendlyConfigBlockDataString(blockState.getBlockData());
// if (!HerbalismTreasureConfig.getInstance().hylianMap.containsKey(friendly))
// return false;
// List<HylianTreasure> treasures = HerbalismTreasureConfig.getInstance().hylianMap.get(friendly);
//
// Player player = getPlayer();
//
// if (treasures.isEmpty()) {
// return false;
// }
// int skillLevel = getSkillLevel();
// Location location = Misc.getBlockCenter(blockState);
//
// for (HylianTreasure treasure : treasures) {
// if (skillLevel >= treasure.getDropLevel()
// && pluginRef.getRandomChanceTools().checkRandomChanceExecutionSuccess(new RandomChanceSkillStatic(treasure.getDropChance(), getPlayer(), SubSkillType.HERBALISM_HYLIAN_LUCK))) {
// if (!pluginRef.getEventManager().simulateBlockBreak(blockState.getBlock(), player, false)) {
// return false;
// }
// blockState.setType(Material.AIR);
// Misc.dropItem(location, treasure.getDrop());
// pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Herbalism.HylianLuck");
// return true;
// }
// }
// return false;
return false;
}