*CLEANUP* - mcPlayerListener.java

Also moved some stuff around to more appropriate files, created classes
for a few Runnables, and mcLocale'd a couple of strings.
This commit is contained in:
GJ
2012-03-10 22:21:53 -05:00
parent 28c590f079
commit 4359dc764f
17 changed files with 759 additions and 602 deletions

View File

@ -1,19 +1,27 @@
package com.gmail.nossr50.skills;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import com.gmail.nossr50.BlockChecks;
import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
public class BlastMining{
@ -160,7 +168,7 @@ public class BlastMining{
if(skillLevel >= 750)
radius++;
if(skillLevel >= 1000)
radius++;
radius++;
event.setRadius(radius);
}
@ -185,5 +193,41 @@ public class BlastMining{
event.setDamage(damage);
}
public static void remoteDetonation(Player player, mcMMO plugin) {
PlayerProfile PP = Users.getProfile(player);
HashSet<Byte> transparent = new HashSet<Byte>();
transparent.add((byte) 78); //SNOW
transparent.add((byte) 0); //AIR
Block b = player.getTargetBlock(transparent, 100);
if(b.getType().equals(Material.TNT) && m.blockBreakSimulate(b, player, true) && PP.getSkillLevel(SkillType.MINING) >= 125) {
AbilityType ability = AbilityType.BLAST_MINING;
/* Check Cooldown */
if(!Skills.cooldownOver(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown())) {
player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(player, (PP.getSkillDATS(ability) * 1000), ability.getCooldown()) + "s)");
return;
}
/* Send message to nearby players */
for(Player y : player.getWorld().getPlayers()) {
if(y != player && m.isNear(player.getLocation(), y.getLocation(), 10)) {
y.sendMessage(ability.getAbilityPlayer(player));
}
}
player.sendMessage(mcLocale.getString("BlastMining.Boom"));
/* Create the TNT entity */
TNTPrimed tnt = player.getWorld().spawn(b.getLocation(), TNTPrimed.class);
plugin.misc.tntTracker.put(tnt.getEntityId(), player);
b.setType(Material.AIR);
tnt.setFuseTicks(0);
PP.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
PP.setBlastMiningInformed(false);
}
}
}

View File

@ -15,6 +15,8 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.runnables.GreenThumbTimer;
public class Herbalism {
@ -36,14 +38,16 @@ public class Herbalism {
inventory.removeItem(new ItemStack(Material.SEEDS, 1));
player.updateInventory();
if (LoadProperties.enableSmoothToMossy && type.equals(Material.SMOOTH_BRICK)) {
block.setData((byte) 0x1);
}
else if (LoadProperties.enableDirtToGrass && type.equals(Material.DIRT)) {
block.setType(Material.GRASS);
}
else if (LoadProperties.enableCobbleToMossy && type.equals(Material.COBBLESTONE)) {
block.setType(Material.MOSSY_COBBLESTONE);
if (m.blockBreakSimulate(block, player, false)) {
if (LoadProperties.enableSmoothToMossy && type.equals(Material.SMOOTH_BRICK)) {
block.setData((byte) 0x1);
}
else if (LoadProperties.enableDirtToGrass && type.equals(Material.DIRT)) {
block.setType(Material.GRASS);
}
else if (LoadProperties.enableCobbleToMossy && type.equals(Material.COBBLESTONE)) {
block.setType(Material.MOSSY_COBBLESTONE);
}
}
}
}
@ -142,7 +146,7 @@ public class Herbalism {
if (data == (byte) 0x7) {
mat = Material.WHEAT;
xp = LoadProperties.mwheat;
greenThumb(block, player, event, plugin);
greenThumbWheat(block, player, event, plugin);
}
break;
@ -241,15 +245,15 @@ public class Herbalism {
}
/**
* Apply the Green Thumb ability.
* Apply the Green Thumb ability to crops.
*
* @param block The block to apply the ability to
* @param player The player using the ability
* @param event The event triggering the ability
* @param plugin mcMMO plugin instance
*/
private static void greenThumb(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
final PlayerProfile PP = Users.getProfile(player);
private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
PlayerProfile PP = Users.getProfile(player);
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
PlayerInventory inventory = player.getInventory();
boolean hasSeeds = inventory.contains(Material.SEEDS);
@ -257,31 +261,36 @@ public class Herbalism {
if (hasSeeds && PP.getGreenTerraMode() || hasSeeds && (herbLevel >= 1500 || (Math.random() * 1500 <= herbLevel))) {
event.setCancelled(true);
m.mcDropItem(loc, new ItemStack(Material.WHEAT, 1));
m.mcDropItems(loc, new ItemStack(Material.SEEDS, 1), 3);
m.mcRandomDropItems(loc, new ItemStack(Material.SEEDS, 1), 50, 3);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
block.setType(Material.CROPS);
//This replants the wheat at a certain stage in development based on Herbalism Skill
if (!PP.getGreenTerraMode()) {
if (PP.getSkillLevel(SkillType.HERBALISM) >= 600)
block.setData((byte) 0x4);
else if (PP.getSkillLevel(SkillType.HERBALISM) >= 400)
block.setData((byte) 0x3);
else if (PP.getSkillLevel(SkillType.HERBALISM) >= 200)
block.setData((byte) 0x2);
else
block.setData((byte) 0x1);
}
else
block.setData((byte) 0x4);
}
}, 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, PP), 1);
inventory.removeItem(new ItemStack(Material.SEEDS, 1));
player.updateInventory();
}
}
/**
* Apply the Green Thumb ability to blocks.
*
* @param is The item in the player's hand
* @param player The player activating the ability
* @param block The block being used in the ability
*/
public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
PlayerProfile PP = Users.getProfile(player);
int skillLevel = PP.getSkillLevel(SkillType.HERBALISM);
int seeds = is.getAmount();
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
if (skillLevel > 1500 || Math.random() * 1500 <= skillLevel) {
greenTerra(player, block);
}
else {
player.sendMessage(mcLocale.getString("mcPlayerListener.GreenThumbFail"));
}
}
}