mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-28 19:54:44 +02:00
Put McMMOPlayer to use where it made sense
It's basically a wrapper for anything related to players, as a consequence Users.getProfile() is now depreciated. Also removed SkillTools.xpProcessing() because of some redundancy with McMMOPlayer.addXp(). + some cleanup for consistency sake.
This commit is contained in:
@ -10,21 +10,19 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.util.BlockChecks;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class BlastMiningDropEventHandler {
|
||||
private MiningManager manager;
|
||||
private int skillLevel;
|
||||
|
||||
private EntityExplodeEvent event;
|
||||
private float yield;
|
||||
private List<Block> blocks;
|
||||
|
||||
private List<Block> ores = new ArrayList<Block>();
|
||||
private List<Block> debris = new ArrayList<Block>();
|
||||
private List<Block> droppedOres = new ArrayList<Block>();
|
||||
|
||||
private float oreBonus;
|
||||
private float debrisReduction;
|
||||
private int dropMultiplier;
|
||||
@ -36,7 +34,6 @@ public class BlastMiningDropEventHandler {
|
||||
this.event = event;
|
||||
this.yield = event.getYield();
|
||||
this.blocks = event.blockList();
|
||||
|
||||
}
|
||||
|
||||
protected void sortExplosionBlocks() {
|
||||
@ -51,9 +48,11 @@ public class BlastMiningDropEventHandler {
|
||||
}
|
||||
|
||||
protected void processXPGain() {
|
||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
||||
|
||||
for (Block block : droppedOres) {
|
||||
if (!mcMMO.placeStore.isTrue(block)) {
|
||||
Mining.miningXP(manager.getPlayer(), manager.getProfile(), block, block.getType());
|
||||
Mining.miningXP(mcMMOPlayer, block, block.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class DemoltionsExpertiseEventHandler {
|
||||
private int skillLevel;
|
||||
|
||||
private EntityDamageEvent event;
|
||||
private int damage;
|
||||
private double damageModifier;
|
||||
|
@ -5,16 +5,14 @@ import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.mods.ModChecks;
|
||||
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
@ -35,10 +33,10 @@ public class Mining {
|
||||
/**
|
||||
* Award XP for Mining blocks.
|
||||
*
|
||||
* @param player The player to award XP to
|
||||
* @param mcMMOPlayer The player to award XP to
|
||||
* @param block The block to award XP for
|
||||
*/
|
||||
protected static void miningXP(Player player, PlayerProfile profile, Block block, Material type) {
|
||||
protected static void miningXP(McMMOPlayer mcMMOPlayer, Block block, Material type) {
|
||||
int xp = 0;
|
||||
|
||||
switch (type) {
|
||||
@ -106,7 +104,7 @@ public class Mining {
|
||||
break;
|
||||
}
|
||||
|
||||
SkillTools.xpProcessing(player, profile, SkillType.MINING, xp);
|
||||
mcMMOPlayer.addXp(SkillType.MINING, xp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,24 +4,18 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class MiningBlockEventHandler {
|
||||
private MiningManager manager;
|
||||
private Player player;
|
||||
|
||||
private Block block;
|
||||
private Location blockLocation;
|
||||
private Material blockType;
|
||||
|
||||
protected int skillModifier;
|
||||
|
||||
protected MiningBlockEventHandler(MiningManager manager, Block block) {
|
||||
this.manager = manager;
|
||||
this.player = manager.getPlayer();
|
||||
|
||||
this.block = block;
|
||||
this.blockLocation = block.getLocation();
|
||||
this.blockType = block.getType();
|
||||
@ -37,7 +31,7 @@ public class MiningBlockEventHandler {
|
||||
* Process Mining block drops.
|
||||
*/
|
||||
protected void processDrops() {
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
if (manager.getMcMMOPlayer().getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
Mining.silkTouchDrops(block, blockLocation, blockType);
|
||||
}
|
||||
else {
|
||||
@ -46,6 +40,6 @@ public class MiningBlockEventHandler {
|
||||
}
|
||||
|
||||
protected void processXPGain() {
|
||||
Mining.miningXP(player, manager.getProfile(), block, blockType);
|
||||
Mining.miningXP(manager.getMcMMOPlayer(), block, blockType);
|
||||
}
|
||||
}
|
||||
|
@ -2,21 +2,21 @@ package com.gmail.nossr50.skills.mining;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
|
||||
public class MiningManager extends SkillManager{
|
||||
public MiningManager (Player player) {
|
||||
super(player, SkillType.MINING);
|
||||
public MiningManager (McMMOPlayer mcMMOPlayer) {
|
||||
super(mcMMOPlayer, SkillType.MINING);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,11 +33,11 @@ public class MiningManager extends SkillManager{
|
||||
|
||||
eventHandler.targetTNT();
|
||||
|
||||
if (eventHandler.block.getType() != Material.TNT) {
|
||||
if (eventHandler.getBlock().getType() != Material.TNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Misc.blockBreakSimulate(eventHandler.block, player, true)) {
|
||||
if (!Misc.blockBreakSimulate(eventHandler.getBlock(), mcMMOPlayer.getPlayer(), true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ public class MiningManager extends SkillManager{
|
||||
* @param event Event whose explosion is being processed
|
||||
*/
|
||||
public void blastMiningDropProcessing(EntityExplodeEvent event) {
|
||||
if (Misc.isNPCPlayer(player)) {
|
||||
if (Misc.isNPCPlayer(mcMMOPlayer.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ public class MiningManager extends SkillManager{
|
||||
* @param event Event whose explosion radius is being changed
|
||||
*/
|
||||
public void biggerBombs(ExplosionPrimeEvent event) {
|
||||
if (Misc.isNPCPlayer(player)) {
|
||||
if (Misc.isNPCPlayer(mcMMOPlayer.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class MiningManager extends SkillManager{
|
||||
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
|
||||
eventHandler.processXPGain();
|
||||
|
||||
if (!Permissions.miningDoubleDrops(player)) {
|
||||
if (!Permissions.miningDoubleDrops(mcMMOPlayer.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -129,7 +129,7 @@ public class MiningManager extends SkillManager{
|
||||
* @param block The block being affected
|
||||
*/
|
||||
public void superBreakerBlockCheck(Block block) {
|
||||
if (mcMMO.placeStore.isTrue(block) || !Misc.blockBreakSimulate(block, player, true)) {
|
||||
if (mcMMO.placeStore.isTrue(block) || !Misc.blockBreakSimulate(block, mcMMOPlayer.getPlayer(), true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.AbilityType;
|
||||
@ -16,18 +17,13 @@ import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class RemoteDetonationEventHandler {
|
||||
private Player player;
|
||||
private PlayerProfile profile;
|
||||
|
||||
private MiningManager manager;
|
||||
private PlayerInteractEvent event;
|
||||
protected Block block;
|
||||
|
||||
private Block block;
|
||||
private HashSet<Byte> transparentBlocks = new HashSet<Byte>();
|
||||
|
||||
public RemoteDetonationEventHandler(MiningManager manager, PlayerInteractEvent event) {
|
||||
this.player = manager.getPlayer();
|
||||
this.profile = manager.getProfile();
|
||||
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
this.block = event.getClickedBlock();
|
||||
}
|
||||
@ -35,7 +31,7 @@ public class RemoteDetonationEventHandler {
|
||||
protected void targetTNT() {
|
||||
if (block == null || block.getType() != Material.TNT) {
|
||||
generateTransparentBlockList();
|
||||
block = player.getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
|
||||
block = manager.getMcMMOPlayer().getPlayer().getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
|
||||
}
|
||||
else {
|
||||
event.setCancelled(true); // This is the only way I know to avoid the original TNT to be triggered (in case the player is close to it)
|
||||
@ -43,6 +39,10 @@ public class RemoteDetonationEventHandler {
|
||||
}
|
||||
|
||||
protected boolean cooldownOver() {
|
||||
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
PlayerProfile profile = mcMMOPlayer.getProfile();
|
||||
|
||||
if (!SkillTools.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) {
|
||||
player.sendMessage(LocaleLoader.getString("Skills.TooTired", new Object[] { SkillTools.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player) }));
|
||||
|
||||
@ -53,19 +53,24 @@ public class RemoteDetonationEventHandler {
|
||||
}
|
||||
|
||||
protected void sendMessages() {
|
||||
Player player = manager.getMcMMOPlayer().getPlayer();
|
||||
|
||||
Misc.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
|
||||
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
||||
}
|
||||
|
||||
protected void handleDetonation() {
|
||||
Player player = manager.getMcMMOPlayer().getPlayer();
|
||||
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
|
||||
|
||||
mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
|
||||
tnt.setFuseTicks(0);
|
||||
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
protected void setProfileData() {
|
||||
PlayerProfile profile = manager.getMcMMOPlayer().getProfile();
|
||||
|
||||
profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
|
||||
profile.setAbilityInformed(AbilityType.BLAST_MINING, false);
|
||||
}
|
||||
@ -77,4 +82,8 @@ public class RemoteDetonationEventHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Block getBlock() {
|
||||
return block;
|
||||
}
|
||||
}
|
||||
|
@ -14,29 +14,22 @@ import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class SuperBreakerEventHandler {
|
||||
private MiningManager manager;
|
||||
private Player player;
|
||||
|
||||
private Block block;
|
||||
private Material blockType;
|
||||
private boolean customBlock;
|
||||
|
||||
private ItemStack heldItem;
|
||||
private int tier;
|
||||
|
||||
private int durabilityLoss;
|
||||
private FakePlayerAnimationEvent armswing;
|
||||
|
||||
protected SuperBreakerEventHandler (MiningManager manager, Block block) {
|
||||
this.manager = manager;
|
||||
this.player = manager.getPlayer();
|
||||
|
||||
this.block = block;
|
||||
this.blockType = block.getType();
|
||||
this.customBlock = ModChecks.isCustomMiningBlock(block);
|
||||
|
||||
Player player = manager.getMcMMOPlayer().getPlayer();
|
||||
this.heldItem = player.getItemInHand();
|
||||
this.tier = Misc.getTier(heldItem);
|
||||
|
||||
this.armswing = new FakePlayerAnimationEvent(player);
|
||||
|
||||
calculateDurabilityLoss();
|
||||
@ -55,7 +48,7 @@ public class SuperBreakerEventHandler {
|
||||
}
|
||||
|
||||
protected void playSound() {
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
|
||||
manager.getMcMMOPlayer().getPlayer().playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.POP_PITCH);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user