2013-01-10 03:44:53 +01:00
|
|
|
package com.gmail.nossr50.skills.mining;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.TNTPrimed;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2013-01-10 03:44:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.AbilityType;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
2013-01-10 03:44:53 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
|
|
|
|
public class RemoteDetonationEventHandler {
|
2013-02-01 06:38:25 +01:00
|
|
|
private MiningManager manager;
|
2013-01-10 03:44:53 +01:00
|
|
|
private PlayerInteractEvent event;
|
2013-02-01 06:38:25 +01:00
|
|
|
private Block block;
|
2013-01-10 03:44:53 +01:00
|
|
|
private HashSet<Byte> transparentBlocks = new HashSet<Byte>();
|
|
|
|
|
|
|
|
public RemoteDetonationEventHandler(MiningManager manager, PlayerInteractEvent event) {
|
2013-02-01 06:38:25 +01:00
|
|
|
this.manager = manager;
|
2013-01-10 03:44:53 +01:00
|
|
|
this.event = event;
|
|
|
|
this.block = event.getClickedBlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void targetTNT() {
|
|
|
|
if (block == null || block.getType() != Material.TNT) {
|
|
|
|
generateTransparentBlockList();
|
2013-02-01 06:38:25 +01:00
|
|
|
block = manager.getMcMMOPlayer().getPlayer().getTargetBlock(transparentBlocks, BlastMining.MAXIMUM_REMOTE_DETONATION_DISTANCE);
|
2013-01-10 03:44:53 +01:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean cooldownOver() {
|
2013-02-01 06:38:25 +01:00
|
|
|
McMMOPlayer mcMMOPlayer = manager.getMcMMOPlayer();
|
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
|
|
|
PlayerProfile profile = mcMMOPlayer.getProfile();
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
if (!SkillTools.cooldownOver(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)) {
|
2013-02-02 08:55:49 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.TooTired", SkillTools.calculateTimeLeft(profile.getSkillDATS(AbilityType.BLAST_MINING) * Misc.TIME_CONVERSION_FACTOR, AbilityType.BLAST_MINING.getCooldown(), player)));
|
2013-01-10 03:44:53 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void sendMessages() {
|
2013-02-01 06:38:25 +01:00
|
|
|
Player player = manager.getMcMMOPlayer().getPlayer();
|
|
|
|
|
2013-01-10 03:44:53 +01:00
|
|
|
Misc.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player));
|
|
|
|
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void handleDetonation() {
|
2013-02-01 06:38:25 +01:00
|
|
|
Player player = manager.getMcMMOPlayer().getPlayer();
|
2013-01-10 03:44:53 +01:00
|
|
|
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
|
2013-02-01 06:38:25 +01:00
|
|
|
|
2013-01-10 03:44:53 +01:00
|
|
|
mcMMO.p.addToTNTTracker(tnt.getEntityId(), player.getName());
|
|
|
|
tnt.setFuseTicks(0);
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void setProfileData() {
|
2013-02-01 06:38:25 +01:00
|
|
|
PlayerProfile profile = manager.getMcMMOPlayer().getProfile();
|
|
|
|
|
2013-01-10 03:44:53 +01:00
|
|
|
profile.setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
|
|
|
|
profile.setAbilityInformed(AbilityType.BLAST_MINING, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void generateTransparentBlockList() {
|
2013-01-28 18:51:20 +01:00
|
|
|
for (Material material : Material.values()) {
|
|
|
|
if (material.isTransparent()) {
|
|
|
|
transparentBlocks.add((byte) material.getId());
|
|
|
|
}
|
|
|
|
}
|
2013-01-10 03:44:53 +01:00
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
|
|
|
|
protected Block getBlock() {
|
|
|
|
return block;
|
|
|
|
}
|
2013-01-10 03:44:53 +01:00
|
|
|
}
|