2013-01-01 22:01:51 +01:00
|
|
|
package com.gmail.nossr50.skills.mining;
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
import java.util.HashSet;
|
2012-03-26 17:04:17 +02:00
|
|
|
import java.util.Random;
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2012-02-07 07:37:41 +01:00
|
|
|
import org.bukkit.block.Block;
|
2012-03-01 22:50:39 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2012-03-11 04:21:53 +01:00
|
|
|
import org.bukkit.entity.TNTPrimed;
|
2012-04-29 00:42:21 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2012-03-01 22:50:39 +01:00
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-03-11 04:21:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.AbilityType;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-03-01 22:50:39 +01:00
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-05-01 19:58:47 +02:00
|
|
|
import com.gmail.nossr50.util.Skills;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-12 22:28:13 +01:00
|
|
|
public class BlastMining {
|
2013-01-10 01:45:34 +01:00
|
|
|
private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
|
2012-03-26 17:04:17 +02:00
|
|
|
private static Random random = new Random();
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2013-01-10 01:45:34 +01:00
|
|
|
public final static int BLAST_MINING_RANK_1 = advancedConfig.getBlastMiningRank1();
|
|
|
|
public final static int BLAST_MINING_RANK_2 = advancedConfig.getBlastMiningRank2();
|
|
|
|
public final static int BLAST_MINING_RANK_3 = advancedConfig.getBlastMiningRank3();
|
|
|
|
public final static int BLAST_MINING_RANK_4 = advancedConfig.getBlastMiningRank4();
|
|
|
|
public final static int BLAST_MINING_RANK_5 = advancedConfig.getBlastMiningRank5();
|
|
|
|
public final static int BLAST_MINING_RANK_6 = advancedConfig.getBlastMiningRank6();
|
|
|
|
public final static int BLAST_MINING_RANK_7 = advancedConfig.getBlastMiningRank7();
|
|
|
|
public final static int BLAST_MINING_RANK_8 = advancedConfig.getBlastMiningRank8();
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
/**
|
2012-04-29 00:42:21 +02:00
|
|
|
* Detonate TNT for Blast Mining
|
2012-03-20 03:05:17 +01:00
|
|
|
*
|
2012-05-01 01:32:50 +02:00
|
|
|
* @param event The PlayerInteractEvent
|
2012-03-20 03:05:17 +01:00
|
|
|
* @param player Player detonating the TNT
|
|
|
|
* @param plugin mcMMO plugin instance
|
|
|
|
*/
|
2012-06-07 00:02:22 +02:00
|
|
|
public static void detonate(PlayerInteractEvent event, Player player, mcMMO plugin) {
|
2012-10-30 19:46:52 +01:00
|
|
|
if(player == null)
|
|
|
|
return;
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
if (profile.getSkillLevel(SkillType.MINING) < 125)
|
2012-04-29 00:42:21 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
Block block = event.getClickedBlock();
|
|
|
|
|
|
|
|
if (block == null || block.getType() != Material.TNT) {
|
|
|
|
final byte SNOW = 78;
|
|
|
|
final byte AIR = 0;
|
|
|
|
final int BLOCKS_AWAY = 100;
|
|
|
|
|
|
|
|
HashSet<Byte> transparent = new HashSet<Byte>();
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
transparent.add(SNOW);
|
|
|
|
transparent.add(AIR);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
block = player.getTargetBlock(transparent, BLOCKS_AWAY);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
if (block.getType() != Material.TNT) {
|
2012-03-11 04:21:53 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-04-29 00:42:21 +02:00
|
|
|
}
|
|
|
|
else if (block.getType() == Material.TNT) {
|
|
|
|
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)
|
|
|
|
}
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
if (!Misc.blockBreakSimulate(block, player, true)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final double MAX_DISTANCE_AWAY = 10.0;
|
|
|
|
final int TIME_CONVERSION_FACTOR = 1000;
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
AbilityType ability = AbilityType.BLAST_MINING;
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
/* Check Cooldown */
|
2012-07-03 16:04:04 +02:00
|
|
|
if (!Skills.cooldownOver(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
2012-11-13 06:57:57 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(profile.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown(), player) + "s)");
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-29 00:42:21 +02:00
|
|
|
return;
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
2012-04-29 00:42:21 +02:00
|
|
|
|
|
|
|
/* Send message to nearby players */
|
2012-05-01 16:39:50 +02:00
|
|
|
for (Player y : player.getWorld().getPlayers()) {
|
|
|
|
if (y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
|
2012-04-29 00:42:21 +02:00
|
|
|
y.sendMessage(ability.getAbilityPlayer(player));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
|
|
|
|
|
|
|
/* Create the TNT entity */
|
2012-12-24 22:56:25 +01:00
|
|
|
// TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT);
|
2012-04-29 00:42:21 +02:00
|
|
|
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
|
2012-06-06 21:38:44 +02:00
|
|
|
plugin.addToTNTTracker(tnt.getEntityId(), player.getName());
|
2012-04-29 00:42:21 +02:00
|
|
|
tnt.setFuseTicks(0);
|
|
|
|
|
|
|
|
/* Disable the original one */
|
|
|
|
block.setType(Material.AIR);
|
|
|
|
|
2012-07-03 16:04:04 +02:00
|
|
|
profile.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
|
|
|
|
profile.setAbilityInformed(ability, false);
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
2013-01-10 01:45:34 +01:00
|
|
|
|
|
|
|
protected static Random getRandom() {
|
|
|
|
return random;
|
|
|
|
}
|
2012-03-06 07:48:45 +01:00
|
|
|
}
|