Refactor all the listeners!

This commit is contained in:
nossr50 2012-04-26 10:42:09 -07:00
parent 05724ae64f
commit fea3bd6aa4
10 changed files with 1192 additions and 1197 deletions

View File

@ -300,6 +300,7 @@ public class Config extends ConfigLoader{
// Setup default HUD // Setup default HUD
String temp = config.getString("Spout.HUD.Default", "STANDARD"); String temp = config.getString("Spout.HUD.Default", "STANDARD");
for (HUDType x : HUDType.values()) { for (HUDType x : HUDType.values()) {
if (x.toString().equalsIgnoreCase(temp)) { if (x.toString().equalsIgnoreCase(temp)) {
defaulthud = x; defaulthud = x;
@ -323,12 +324,6 @@ public class Config extends ConfigLoader{
showDisplayName = config.getBoolean("Spout.Party.HUD.Show_Display_Name", false); showDisplayName = config.getBoolean("Spout.Party.HUD.Show_Display_Name", false);
partybar = config.getBoolean("Spout.Party.HUD.Enabled", true); partybar = config.getBoolean("Spout.Party.HUD.Enabled", true);
enableOnlyActivateWhenSneaking = config.getBoolean("Abilities.Activation.Only_Activate_When_Sneaking", false); enableOnlyActivateWhenSneaking = config.getBoolean("Abilities.Activation.Only_Activate_When_Sneaking", false);
greenTerraCooldown = config.getInt("Abilities.Cooldowns.Green_Terra", 240); greenTerraCooldown = config.getInt("Abilities.Cooldowns.Green_Terra", 240);

View File

@ -1,304 +1,304 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import java.util.List; import java.util.List;
import com.gmail.nossr50.BlockChecks; import com.gmail.nossr50.BlockChecks;
import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.ItemChecks;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.ToolType; import com.gmail.nossr50.datatypes.ToolType;
import com.gmail.nossr50.skills.Excavation; import com.gmail.nossr50.skills.Excavation;
import com.gmail.nossr50.skills.Herbalism; import com.gmail.nossr50.skills.Herbalism;
import com.gmail.nossr50.skills.Mining; import com.gmail.nossr50.skills.Mining;
import com.gmail.nossr50.skills.Repair; import com.gmail.nossr50.skills.Repair;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.WoodCutting; import com.gmail.nossr50.skills.WoodCutting;
import com.gmail.nossr50.spout.SpoutSounds; import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent; import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent; import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
import org.bukkit.CropState; import org.bukkit.CropState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.getspout.spoutapi.sound.SoundEffect; import org.getspout.spoutapi.sound.SoundEffect;
public class mcBlockListener implements Listener { public class BlockListener implements Listener {
private final mcMMO plugin; private final mcMMO plugin;
public mcBlockListener(final mcMMO plugin) { public BlockListener(final mcMMO plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/** /**
* Monitor BlockPistonExtend events. * Monitor BlockPistonExtend events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonExtend(BlockPistonExtendEvent event) { public void onBlockPistonExtend(BlockPistonExtendEvent event) {
List<Block> blocks = event.getBlocks(); List<Block> blocks = event.getBlocks();
BlockFace direction = event.getDirection(); BlockFace direction = event.getDirection();
for (Block b : blocks) { for (Block b : blocks) {
if (b.hasMetadata("mcmmoPlacedBlock")) { if (b.hasMetadata("mcmmoPlacedBlock")) {
b.getRelative(direction).setMetadata("mcmmoNeedsTracking", new FixedMetadataValue(plugin, true)); b.getRelative(direction).setMetadata("mcmmoNeedsTracking", new FixedMetadataValue(plugin, true));
b.removeMetadata("mcmmoPlacedBlock", plugin); b.removeMetadata("mcmmoPlacedBlock", plugin);
} }
} }
for (Block b : blocks) { for (Block b : blocks) {
if (b.getRelative(direction).hasMetadata("mcmmoNeedsTracking")) { if (b.getRelative(direction).hasMetadata("mcmmoNeedsTracking")) {
b.getRelative(direction).setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true)); b.getRelative(direction).setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true));
b.getRelative(direction).removeMetadata("mcmmoNeedsTracking", plugin); b.getRelative(direction).removeMetadata("mcmmoNeedsTracking", plugin);
} }
} }
} }
/** /**
* Monitor BlockPistonRetract events. * Monitor BlockPistonRetract events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onBlockPistonRetract(BlockPistonRetractEvent event) { public void onBlockPistonRetract(BlockPistonRetractEvent event) {
Block block = event.getRetractLocation().getBlock(); Block block = event.getRetractLocation().getBlock();
if (block.hasMetadata("mcmmoPlacedBlock")) { if (block.hasMetadata("mcmmoPlacedBlock")) {
block.removeMetadata("mcmmoPlacedBlock", plugin); block.removeMetadata("mcmmoPlacedBlock", plugin);
event.getBlock().getRelative(event.getDirection()).setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true)); event.getBlock().getRelative(event.getDirection()).setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true));
} }
} }
/** /**
* Monitor BlockPlace events. * Monitor BlockPlace events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
int id = block.getTypeId(); int id = block.getTypeId();
Material mat = block.getType(); Material mat = block.getType();
/* Code to prevent issues with placed falling Sand/Gravel not being tracked */ /* Code to prevent issues with placed falling Sand/Gravel not being tracked */
if (mat.equals(Material.SAND) || mat.equals(Material.GRAVEL)) { if (mat.equals(Material.SAND) || mat.equals(Material.GRAVEL)) {
for (int y = -1; y + block.getY() >= 0; y--) { for (int y = -1; y + block.getY() >= 0; y--) {
if (block.getRelative(0, y, 0).getType().equals(Material.AIR)) { if (block.getRelative(0, y, 0).getType().equals(Material.AIR)) {
continue; continue;
} }
else { else {
Block newLocation = block.getRelative(0, y + 1, 0); Block newLocation = block.getRelative(0, y + 1, 0);
newLocation.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true)); newLocation.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true));
break; break;
} }
} }
} }
/* Check if the blocks placed should be monitored so they do not give out XP in the future */ /* Check if the blocks placed should be monitored so they do not give out XP in the future */
if (BlockChecks.shouldBeWatched(mat)) { if (BlockChecks.shouldBeWatched(mat)) {
block.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true)); block.setMetadata("mcmmoPlacedBlock", new FixedMetadataValue(plugin, true));
} }
if (id == Config.anvilID && Config.anvilmessages) { if (id == Config.anvilID && Config.anvilmessages) {
Repair.placedAnvilCheck(player, id); Repair.placedAnvilCheck(player, id);
} }
} }
/** /**
* Monitor BlockBreak events. * Monitor BlockBreak events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
Block block = event.getBlock(); Block block = event.getBlock();
Material mat = block.getType(); Material mat = block.getType();
ItemStack inhand = player.getItemInHand(); ItemStack inhand = player.getItemInHand();
if (event instanceof FakeBlockBreakEvent) { if (event instanceof FakeBlockBreakEvent) {
return; return;
} }
/* /*
* HERBALISM * HERBALISM
*/ */
/* Green Terra */ /* Green Terra */
if (PP.getToolPreparationMode(ToolType.HOE) && mcPermissions.getInstance().greenTerra(player) && ((mat.equals(Material.CROPS) && block.getData() == CropState.RIPE.getData()) || Herbalism.canBeGreenTerra(mat))) { if (PP.getToolPreparationMode(ToolType.HOE) && mcPermissions.getInstance().greenTerra(player) && ((mat.equals(Material.CROPS) && block.getData() == CropState.RIPE.getData()) || Herbalism.canBeGreenTerra(mat))) {
Skills.abilityCheck(player, SkillType.HERBALISM); Skills.abilityCheck(player, SkillType.HERBALISM);
} }
/* Triple drops */ /* Triple drops */
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && Herbalism.canBeGreenTerra(mat)) { if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && Herbalism.canBeGreenTerra(mat)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin);
} }
if (mcPermissions.getInstance().herbalism(player) && Herbalism.canBeGreenTerra(mat)) { if (mcPermissions.getInstance().herbalism(player) && Herbalism.canBeGreenTerra(mat)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin);
} }
/* /*
* MINING * MINING
*/ */
if (mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(mat)) { if (mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(mat)) {
if (Config.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) { if (Config.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) {
Mining.miningBlockCheck(player, block); Mining.miningBlockCheck(player, block);
} }
else if (!Config.miningrequirespickaxe) { else if (!Config.miningrequirespickaxe) {
Mining.miningBlockCheck(player, block); Mining.miningBlockCheck(player, block);
} }
} }
/* /*
* WOOD CUTTING * WOOD CUTTING
*/ */
if (mcPermissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) { if (mcPermissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) {
if (Config.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) { if (Config.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) {
WoodCutting.woodcuttingBlockCheck(player, block); WoodCutting.woodcuttingBlockCheck(player, block);
} }
else if (!Config.woodcuttingrequiresaxe) { else if (!Config.woodcuttingrequiresaxe) {
WoodCutting.woodcuttingBlockCheck(player, block); WoodCutting.woodcuttingBlockCheck(player, block);
} }
} }
if (PP.getAbilityMode(AbilityType.TREE_FELLER) && mcPermissions.getInstance().treeFeller(player)) { if (PP.getAbilityMode(AbilityType.TREE_FELLER) && mcPermissions.getInstance().treeFeller(player)) {
WoodCutting.treeFeller(event); WoodCutting.treeFeller(event);
} }
/* /*
* EXCAVATION * EXCAVATION
*/ */
if (Excavation.canBeGigaDrillBroken(mat) && mcPermissions.getInstance().excavation(player) && !block.hasMetadata("mcmmoPlacedBlock")) { if (Excavation.canBeGigaDrillBroken(mat) && mcPermissions.getInstance().excavation(player) && !block.hasMetadata("mcmmoPlacedBlock")) {
if (Config.excavationRequiresShovel && ItemChecks.isShovel(inhand)) { if (Config.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
} }
else if (!Config.excavationRequiresShovel) { else if (!Config.excavationRequiresShovel) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
} }
} }
//Remove metadata when broken //Remove metadata when broken
if (block.hasMetadata("mcmmoPlacedBlock") && BlockChecks.shouldBeWatched(mat)) { if (block.hasMetadata("mcmmoPlacedBlock") && BlockChecks.shouldBeWatched(mat)) {
block.removeMetadata("mcmmoPlacedBlock", plugin); block.removeMetadata("mcmmoPlacedBlock", plugin);
} }
} }
/** /**
* Monitor BlockDamage events. * Monitor BlockDamage events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
final int LEAF_BLOWER_LEVEL = 100; final int LEAF_BLOWER_LEVEL = 100;
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
ItemStack inhand = player.getItemInHand(); ItemStack inhand = player.getItemInHand();
Block block = event.getBlock(); Block block = event.getBlock();
Material mat = block.getType(); Material mat = block.getType();
/* /*
* ABILITY PREPARATION CHECKS * ABILITY PREPARATION CHECKS
*/ */
if (BlockChecks.abilityBlockCheck(mat)) { if (BlockChecks.abilityBlockCheck(mat)) {
if (PP.getToolPreparationMode(ToolType.HOE) && (Herbalism.canBeGreenTerra(mat) || Herbalism.makeMossy(mat))) { if (PP.getToolPreparationMode(ToolType.HOE) && (Herbalism.canBeGreenTerra(mat) || Herbalism.makeMossy(mat))) {
Skills.abilityCheck(player, SkillType.HERBALISM); Skills.abilityCheck(player, SkillType.HERBALISM);
} }
else if (PP.getToolPreparationMode(ToolType.AXE) && mat.equals(Material.LOG) && mcPermissions.getInstance().treeFeller(player)) { //Why are we checking the permissions here? else if (PP.getToolPreparationMode(ToolType.AXE) && mat.equals(Material.LOG) && mcPermissions.getInstance().treeFeller(player)) { //Why are we checking the permissions here?
Skills.abilityCheck(player, SkillType.WOODCUTTING); Skills.abilityCheck(player, SkillType.WOODCUTTING);
} }
else if (PP.getToolPreparationMode(ToolType.PICKAXE) && Mining.canBeSuperBroken(mat)) { else if (PP.getToolPreparationMode(ToolType.PICKAXE) && Mining.canBeSuperBroken(mat)) {
Skills.abilityCheck(player, SkillType.MINING); Skills.abilityCheck(player, SkillType.MINING);
} }
else if (PP.getToolPreparationMode(ToolType.SHOVEL) && Excavation.canBeGigaDrillBroken(mat)) { else if (PP.getToolPreparationMode(ToolType.SHOVEL) && Excavation.canBeGigaDrillBroken(mat)) {
Skills.abilityCheck(player, SkillType.EXCAVATION); Skills.abilityCheck(player, SkillType.EXCAVATION);
} }
else if (PP.getToolPreparationMode(ToolType.FISTS) && (Excavation.canBeGigaDrillBroken(mat) || mat.equals(Material.SNOW))) { else if (PP.getToolPreparationMode(ToolType.FISTS) && (Excavation.canBeGigaDrillBroken(mat) || mat.equals(Material.SNOW))) {
Skills.abilityCheck(player, SkillType.UNARMED); Skills.abilityCheck(player, SkillType.UNARMED);
} }
} }
/* TREE FELLER SOUNDS */ /* TREE FELLER SOUNDS */
if (Config.spoutEnabled && mat.equals(Material.LOG) && PP.getAbilityMode(AbilityType.TREE_FELLER)) { if (Config.spoutEnabled && mat.equals(Material.LOG) && PP.getAbilityMode(AbilityType.TREE_FELLER)) {
SpoutSounds.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation()); SpoutSounds.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
} }
/* /*
* ABILITY TRIGGER CHECKS * ABILITY TRIGGER CHECKS
*/ */
if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && mcPermissions.getInstance().greenTerra(player) && Herbalism.makeMossy(mat)) { if (PP.getAbilityMode(AbilityType.GREEN_TERRA) && mcPermissions.getInstance().greenTerra(player) && Herbalism.makeMossy(mat)) {
Herbalism.greenTerra(player, block); Herbalism.greenTerra(player, block);
} }
else if (PP.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) { else if (PP.getAbilityMode(AbilityType.GIGA_DRILL_BREAKER) && Skills.triggerCheck(player, block, AbilityType.GIGA_DRILL_BREAKER)) {
if (Config.excavationRequiresShovel && ItemChecks.isShovel(inhand)) { if (Config.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
event.setInstaBreak(true); event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block); Excavation.gigaDrillBreaker(player, block);
} }
else if (!Config.excavationRequiresShovel) { else if (!Config.excavationRequiresShovel) {
event.setInstaBreak(true); event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block); Excavation.gigaDrillBreaker(player, block);
} }
} }
else if (PP.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) { else if (PP.getAbilityMode(AbilityType.BERSERK) && Skills.triggerCheck(player, block, AbilityType.BERSERK)) {
if (inhand.getType().equals(Material.AIR)) { if (inhand.getType().equals(Material.AIR)) {
FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player); FakePlayerAnimationEvent armswing = new FakePlayerAnimationEvent(player);
plugin.getServer().getPluginManager().callEvent(armswing); plugin.getServer().getPluginManager().callEvent(armswing);
event.setInstaBreak(true); event.setInstaBreak(true);
} }
if (Config.spoutEnabled) { if (Config.spoutEnabled) {
SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); SpoutSounds.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
} }
} }
else if (PP.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) { else if (PP.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
if (Config.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) { if (Config.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) {
event.setInstaBreak(true); event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block); Mining.SuperBreakerBlockCheck(player, block);
} }
else if (!Config.miningrequirespickaxe) { else if (!Config.miningrequirespickaxe) {
event.setInstaBreak(true); event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block); Mining.SuperBreakerBlockCheck(player, block);
} }
} }
else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && mat.equals(Material.LEAVES)) { else if (PP.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && mat.equals(Material.LEAVES)) {
if (Config.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) { if (Config.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) {
if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
event.setInstaBreak(true); event.setInstaBreak(true);
WoodCutting.leafBlower(player, block); WoodCutting.leafBlower(player, block);
} }
} }
else if (!Config.woodcuttingrequiresaxe && !inhand.getType().equals(Material.SHEARS)) { else if (!Config.woodcuttingrequiresaxe && !inhand.getType().equals(Material.SHEARS)) {
if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) { if (Skills.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
event.setInstaBreak(true); event.setInstaBreak(true);
WoodCutting.leafBlower(player, block); WoodCutting.leafBlower(player, block);
} }
} }
} }
} }
} }

View File

@ -1,317 +1,317 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityTameEvent; import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import com.gmail.nossr50.Combat; import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m; import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent;
import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.runnables.mcBleedTimer; import com.gmail.nossr50.runnables.mcBleedTimer;
import com.gmail.nossr50.skills.Acrobatics; import com.gmail.nossr50.skills.Acrobatics;
import com.gmail.nossr50.skills.Archery; import com.gmail.nossr50.skills.Archery;
import com.gmail.nossr50.skills.BlastMining; import com.gmail.nossr50.skills.BlastMining;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.Taming; import com.gmail.nossr50.skills.Taming;
public class mcEntityListener implements Listener { public class EntityListener implements Listener {
private final mcMMO plugin; private final mcMMO plugin;
public mcEntityListener(final mcMMO plugin) { public EntityListener(final mcMMO plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/** /**
* Monitor EntityDamageByEntity events. * Monitor EntityDamageByEntity events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event instanceof FakeEntityDamageByEntityEvent) { if (event instanceof FakeEntityDamageByEntityEvent) {
return; return;
} }
Entity defender = event.getEntity(); Entity defender = event.getEntity();
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
if (attacker instanceof Player && defender instanceof Player) { if (attacker instanceof Player && defender instanceof Player) {
if (!defender.getWorld().getPVP()) { if (!defender.getWorld().getPVP()) {
return; return;
} }
if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) { if (Party.getInstance().inSameParty((Player)defender, (Player)attacker)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
/* Check for invincibility */ /* Check for invincibility */
if (defender instanceof LivingEntity) { if (defender instanceof LivingEntity) {
LivingEntity livingDefender = (LivingEntity)defender; LivingEntity livingDefender = (LivingEntity)defender;
if (!m.isInvincible(livingDefender, event)) { if (!m.isInvincible(livingDefender, event)) {
Combat.combatChecks(event, plugin); Combat.combatChecks(event, plugin);
} }
} }
} }
/** /**
* Monitor EntityDamage events. * Monitor EntityDamage events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof FakeEntityDamageEvent) { if (event instanceof FakeEntityDamageEvent) {
return; return;
} }
Entity entity = event.getEntity(); Entity entity = event.getEntity();
EntityType type = entity.getType(); EntityType type = entity.getType();
DamageCause cause = event.getCause(); DamageCause cause = event.getCause();
switch(type) { switch(type) {
case PLAYER: case PLAYER:
/* Check for invincibility */ /* Check for invincibility */
Player player = (Player) entity; Player player = (Player) entity;
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if (PP.getGodMode()) { if (PP.getGodMode()) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!m.isInvincible(player, event)) { if (!m.isInvincible(player, event)) {
if (cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) { if (cause == DamageCause.FALL && mcPermissions.getInstance().acrobatics(player)) {
Acrobatics.acrobaticsCheck(player, event); Acrobatics.acrobaticsCheck(player, event);
} }
else if (cause == DamageCause.BLOCK_EXPLOSION && mcPermissions.getInstance().demolitionsExpertise(player)) { else if (cause == DamageCause.BLOCK_EXPLOSION && mcPermissions.getInstance().demolitionsExpertise(player)) {
BlastMining.demolitionsExpertise(player, event); BlastMining.demolitionsExpertise(player, event);
} }
if (event.getDamage() >= 1) { if (event.getDamage() >= 1) {
PP.setRecentlyHurt(System.currentTimeMillis()); PP.setRecentlyHurt(System.currentTimeMillis());
} }
} }
break; break;
case WOLF: case WOLF:
Wolf wolf = (Wolf) entity; Wolf wolf = (Wolf) entity;
if ((!m.isInvincible(wolf, event)) && wolf.isTamed() && (wolf.getOwner() instanceof Player)) { if ((!m.isInvincible(wolf, event)) && wolf.isTamed() && (wolf.getOwner() instanceof Player)) {
Taming.preventDamage(event); Taming.preventDamage(event);
} }
break; break;
default: default:
break; break;
} }
} }
/** /**
* Monitor EntityDeath events. * Monitor EntityDeath events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler (priority = EventPriority.MONITOR) @EventHandler (priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
LivingEntity x = event.getEntity(); LivingEntity x = event.getEntity();
x.setFireTicks(0); x.setFireTicks(0);
/* Remove bleed track */ /* Remove bleed track */
mcBleedTimer.remove(x); mcBleedTimer.remove(x);
Archery.arrowRetrievalCheck(x, plugin); Archery.arrowRetrievalCheck(x, plugin);
if (x instanceof Player) { if (x instanceof Player) {
Users.getProfile((Player)x).resetBleedTicks(); Users.getProfile((Player)x).resetBleedTicks();
} }
} }
/** /**
* Monitor CreatureSpawn events. * Monitor CreatureSpawn events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler (priority = EventPriority.MONITOR) @EventHandler (priority = EventPriority.MONITOR)
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {
SpawnReason reason = event.getSpawnReason(); SpawnReason reason = event.getSpawnReason();
if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && !Config.xpGainsMobSpawners) { if ((reason.equals(SpawnReason.SPAWNER) || reason.equals(SpawnReason.SPAWNER_EGG)) && !Config.xpGainsMobSpawners) {
event.getEntity().setMetadata("mcmmoFromMobSpawner", new FixedMetadataValue(plugin, true)); event.getEntity().setMetadata("mcmmoFromMobSpawner", new FixedMetadataValue(plugin, true));
} }
} }
/** /**
* Monitor ExplosionPrime events. * Monitor ExplosionPrime events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onExplosionPrime(ExplosionPrimeEvent event) { public void onExplosionPrime(ExplosionPrimeEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof TNTPrimed) { if (entity instanceof TNTPrimed) {
int id = entity.getEntityId(); int id = entity.getEntityId();
if (plugin.tntTracker.containsKey(id)) { if (plugin.tntTracker.containsKey(id)) {
Player player = plugin.tntTracker.get(id); Player player = plugin.tntTracker.get(id);
if (mcPermissions.getInstance().biggerBombs(player)) { if (mcPermissions.getInstance().biggerBombs(player)) {
BlastMining.biggerBombs(player, event); BlastMining.biggerBombs(player, event);
} }
} }
} }
} }
/** /**
* Monitor EntityExplode events. * Monitor EntityExplode events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnitityExplode(EntityExplodeEvent event) { public void onEnitityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (event.getEntity() instanceof TNTPrimed) { if (event.getEntity() instanceof TNTPrimed) {
int id = entity.getEntityId(); int id = entity.getEntityId();
if (plugin.tntTracker.containsKey(id)) { if (plugin.tntTracker.containsKey(id)) {
Player player = plugin.tntTracker.get(id); Player player = plugin.tntTracker.get(id);
BlastMining.dropProcessing(player, event); BlastMining.dropProcessing(player, event);
plugin.tntTracker.remove(id); plugin.tntTracker.remove(id);
} }
} }
} }
/** /**
* Monitor FoodLevelChange events. * Monitor FoodLevelChange events.
* *
* @param event The event to monitor * @param event The event to monitor
*/ */
@EventHandler (priority = EventPriority.LOW) @EventHandler (priority = EventPriority.LOW)
public void onFoodLevelChange(FoodLevelChangeEvent event) { public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (Config.getHerbalismHungerBonusEnabled()) { if (Config.getHerbalismHungerBonusEnabled()) {
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
int currentFoodLevel = player.getFoodLevel(); int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel(); int newFoodLevel = event.getFoodLevel();
/* /*
* Some foods have 3 ranks * Some foods have 3 ranks
* Some foods have 5 ranks * Some foods have 5 ranks
* The number of ranks is based on how 'common' the item is * The number of ranks is based on how 'common' the item is
* We can adjust this quite easily if we find something is giving too much of a bonus * We can adjust this quite easily if we find something is giving too much of a bonus
*/ */
if (newFoodLevel > currentFoodLevel) { if (newFoodLevel > currentFoodLevel) {
Material food = player.getItemInHand().getType(); Material food = player.getItemInHand().getType();
int herbLevel = PP.getSkillLevel(SkillType.HERBALISM); int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
int foodChange = newFoodLevel - currentFoodLevel; int foodChange = newFoodLevel - currentFoodLevel;
int rankChange = 0; int rankChange = 0;
switch (food) { switch (food) {
case BREAD: case BREAD:
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ /* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
rankChange = 200; rankChange = 200;
break; break;
case COOKIE: case COOKIE:
/* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ /* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
rankChange = 400; rankChange = 400;
break; break;
case MELON: case MELON:
/* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ /* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
rankChange = 400; rankChange = 400;
break; break;
case MUSHROOM_SOUP: case MUSHROOM_SOUP:
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ /* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
rankChange = 200; rankChange = 200;
break; break;
default: default:
return; return;
} }
for (int i = 200; i <= 1000; i += rankChange) { for (int i = 200; i <= 1000; i += rankChange) {
if (herbLevel >= i) { if (herbLevel >= i) {
foodChange++; foodChange++;
} }
} }
/* Make sure we don't go over the max value */ /* Make sure we don't go over the max value */
newFoodLevel = currentFoodLevel + foodChange; newFoodLevel = currentFoodLevel + foodChange;
if (newFoodLevel > 20) { if (newFoodLevel > 20) {
event.setFoodLevel(20); event.setFoodLevel(20);
} }
else { else {
event.setFoodLevel(newFoodLevel); event.setFoodLevel(newFoodLevel);
} }
} }
} }
} }
} }
/** /**
* Monitor EntityTame events. * Monitor EntityTame events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler (priority = EventPriority.MONITOR) @EventHandler (priority = EventPriority.MONITOR)
public void onEntityTame(EntityTameEvent event) { public void onEntityTame(EntityTameEvent event) {
Player player = (Player) event.getOwner(); Player player = (Player) event.getOwner();
if (mcPermissions.getInstance().taming(player) && !event.getEntity().hasMetadata("mcmmoSummoned")) { if (mcPermissions.getInstance().taming(player) && !event.getEntity().hasMetadata("mcmmoSummoned")) {
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
EntityType type = event.getEntityType(); EntityType type = event.getEntityType();
int xp = 0; int xp = 0;
switch (type) { switch (type) {
case WOLF: case WOLF:
xp = Config.getTamingXPWolf(); xp = Config.getTamingXPWolf();
break; break;
case OCELOT: case OCELOT:
xp = Config.getTamingXPOcelot(); xp = Config.getTamingXPOcelot();
break; break;
default: default:
break; break;
} }
PP.addXP(SkillType.TAMING, xp); PP.addXP(SkillType.TAMING, xp);
Skills.XpCheckSkill(SkillType.TAMING, player); Skills.XpCheckSkill(SkillType.TAMING, player);
} }
} }
} }

View File

@ -1,374 +1,374 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerFishEvent; import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerFishEvent.State; import org.bukkit.event.player.PlayerFishEvent.State;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.BlockChecks; import com.gmail.nossr50.BlockChecks;
import com.gmail.nossr50.Combat; import com.gmail.nossr50.Combat;
import com.gmail.nossr50.Item; import com.gmail.nossr50.Item;
import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.ItemChecks;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.commands.general.XprateCommand; import com.gmail.nossr50.commands.general.XprateCommand;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.runnables.RemoveProfileFromMemoryTask; import com.gmail.nossr50.runnables.RemoveProfileFromMemoryTask;
import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.SpoutStuff;
import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.skills.BlastMining; import com.gmail.nossr50.skills.BlastMining;
import com.gmail.nossr50.skills.Fishing; import com.gmail.nossr50.skills.Fishing;
import com.gmail.nossr50.skills.Herbalism; import com.gmail.nossr50.skills.Herbalism;
import com.gmail.nossr50.skills.Repair; import com.gmail.nossr50.skills.Repair;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.Taming; import com.gmail.nossr50.skills.Taming;
public class mcPlayerListener implements Listener { public class PlayerListener implements Listener {
private final mcMMO plugin; private final mcMMO plugin;
public mcPlayerListener(final mcMMO plugin) { public PlayerListener(final mcMMO plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/** /**
* Monitor PlayerChangedWorld events. * Monitor PlayerChangedWorld events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) { public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if (PP.getGodMode()) { if (PP.getGodMode()) {
if (!mcPermissions.getInstance().mcgod(player)) { if (!mcPermissions.getInstance().mcgod(player)) {
PP.toggleGodMode(); PP.toggleGodMode();
player.sendMessage(mcLocale.getString("Commands.GodMode.Forbidden")); player.sendMessage(mcLocale.getString("Commands.GodMode.Forbidden"));
} }
} }
if (PP.inParty()) { if (PP.inParty()) {
if (!mcPermissions.getInstance().party(player)) { if (!mcPermissions.getInstance().party(player)) {
PP.removeParty(); PP.removeParty();
player.sendMessage(mcLocale.getString("Party.Forbidden")); player.sendMessage(mcLocale.getString("Party.Forbidden"));
} }
} }
} }
/** /**
* Monitor PlayerFish events. * Monitor PlayerFish events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) { public void onPlayerFish(PlayerFishEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (mcPermissions.getInstance().fishing(player)) { if (mcPermissions.getInstance().fishing(player)) {
State state = event.getState(); State state = event.getState();
switch (state) { switch (state) {
case CAUGHT_FISH: case CAUGHT_FISH:
Fishing.processResults(event); Fishing.processResults(event);
break; break;
case CAUGHT_ENTITY: case CAUGHT_ENTITY:
if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) >= 150 && mcPermissions.getInstance().shakeMob(player)) { if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) >= 150 && mcPermissions.getInstance().shakeMob(player)) {
Fishing.shakeMob(event); Fishing.shakeMob(event);
} }
break; break;
default: default:
break; break;
} }
} }
} }
/** /**
* Monitor PlaterPickupItem events. * Monitor PlaterPickupItem events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) { public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (Users.getProfile(event.getPlayer()).getAbilityMode(AbilityType.BERSERK)) { if (Users.getProfile(event.getPlayer()).getAbilityMode(AbilityType.BERSERK)) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
/** /**
* Monitor PlayerLogin events. * Monitor PlayerLogin events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) { public void onPlayerLogin(PlayerLoginEvent event) {
Users.addUser(event.getPlayer()); Users.addUser(event.getPlayer());
} }
/** /**
* Monitor PlayerQuit events. * Monitor PlayerQuit events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
/* GARBAGE COLLECTION */ /* GARBAGE COLLECTION */
//Remove Spout Stuff //Remove Spout Stuff
if (Config.spoutEnabled && SpoutStuff.playerHUDs.containsKey(player)) { if (Config.spoutEnabled && SpoutStuff.playerHUDs.containsKey(player)) {
SpoutStuff.playerHUDs.remove(player); SpoutStuff.playerHUDs.remove(player);
} }
//Bleed it out //Bleed it out
if(PP.getBleedTicks() > 0) { if(PP.getBleedTicks() > 0) {
Combat.dealDamage(player, PP.getBleedTicks() * 2); Combat.dealDamage(player, PP.getBleedTicks() * 2);
} }
//Schedule PlayerProfile removal 2 minutes after quitting //Schedule PlayerProfile removal 2 minutes after quitting
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveProfileFromMemoryTask(player), 2400); plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveProfileFromMemoryTask(player), 2400);
} }
/** /**
* Monitor PlayerJoin events. * Monitor PlayerJoin events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (mcPermissions.getInstance().motd(player) && Config.enableMotd) { if (mcPermissions.getInstance().motd(player) && Config.enableMotd) {
player.sendMessage(mcLocale.getString("mcMMO.MOTD", new Object[] {plugin.getDescription().getVersion()})); player.sendMessage(mcLocale.getString("mcMMO.MOTD", new Object[] {plugin.getDescription().getVersion()}));
player.sendMessage(mcLocale.getString("mcMMO.Wiki")); player.sendMessage(mcLocale.getString("mcMMO.Wiki"));
} }
//THIS IS VERY BAD WAY TO DO THINGS, NEED BETTER WAY //THIS IS VERY BAD WAY TO DO THINGS, NEED BETTER WAY
if (XprateCommand.xpevent) { if (XprateCommand.xpevent) {
player.sendMessage(mcLocale.getString("XPRate.Event", new Object[] {Config.xpGainMultiplier})); player.sendMessage(mcLocale.getString("XPRate.Event", new Object[] {Config.xpGainMultiplier}));
} }
} }
/** /**
* Monitor PlayerInteract events. * Monitor PlayerInteract events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Action action = event.getAction(); Action action = event.getAction();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
ItemStack is = player.getItemInHand(); ItemStack is = player.getItemInHand();
Material mat; Material mat;
/* Fix for NPE on interacting with air */ /* Fix for NPE on interacting with air */
if (block == null) { if (block == null) {
mat = Material.AIR; mat = Material.AIR;
} }
else { else {
mat = block.getType(); mat = block.getType();
} }
switch (action) { switch (action) {
case RIGHT_CLICK_BLOCK: case RIGHT_CLICK_BLOCK:
/* REPAIR CHECKS */ /* REPAIR CHECKS */
if (mcPermissions.getInstance().repair(player) && block.getTypeId() == Config.anvilID && (ItemChecks.isTool(is) || ItemChecks.isArmor(is))) { if (mcPermissions.getInstance().repair(player) && block.getTypeId() == Config.anvilID && (ItemChecks.isTool(is) || ItemChecks.isArmor(is))) {
Repair.repairCheck(player, is); Repair.repairCheck(player, is);
event.setCancelled(true); event.setCancelled(true);
player.updateInventory(); player.updateInventory();
} }
/* ACTIVATION CHECKS */ /* ACTIVATION CHECKS */
if (Config.enableAbilities && BlockChecks.abilityBlockCheck(mat)) { if (Config.enableAbilities && BlockChecks.abilityBlockCheck(mat)) {
if (!mat.equals(Material.DIRT) && !mat.equals(Material.GRASS) && !mat.equals(Material.SOIL)) { if (!mat.equals(Material.DIRT) && !mat.equals(Material.GRASS) && !mat.equals(Material.SOIL)) {
Skills.activationCheck(player, SkillType.HERBALISM); Skills.activationCheck(player, SkillType.HERBALISM);
} }
Skills.activationCheck(player, SkillType.AXES); Skills.activationCheck(player, SkillType.AXES);
Skills.activationCheck(player, SkillType.EXCAVATION); Skills.activationCheck(player, SkillType.EXCAVATION);
Skills.activationCheck(player, SkillType.MINING); Skills.activationCheck(player, SkillType.MINING);
Skills.activationCheck(player, SkillType.SWORDS); Skills.activationCheck(player, SkillType.SWORDS);
Skills.activationCheck(player, SkillType.UNARMED); Skills.activationCheck(player, SkillType.UNARMED);
Skills.activationCheck(player, SkillType.WOODCUTTING); Skills.activationCheck(player, SkillType.WOODCUTTING);
} }
/* GREEN THUMB CHECK */ /* GREEN THUMB CHECK */
if (mcPermissions.getInstance().greenThumbBlocks(player) && Herbalism.makeMossy(mat) && is.getType().equals(Material.SEEDS)) { if (mcPermissions.getInstance().greenThumbBlocks(player) && Herbalism.makeMossy(mat) && is.getType().equals(Material.SEEDS)) {
Herbalism.greenThumbBlocks(is, player, block); Herbalism.greenThumbBlocks(is, player, block);
} }
/* ITEM CHECKS */ /* ITEM CHECKS */
if (BlockChecks.abilityBlockCheck(mat)) { if (BlockChecks.abilityBlockCheck(mat)) {
Item.itemchecks(player); Item.itemchecks(player);
} }
/* BLAST MINING CHECK */ /* BLAST MINING CHECK */
if (mcPermissions.getInstance().blastMining(player) && is.getTypeId() == Config.getDetonatorItemID()) { if (mcPermissions.getInstance().blastMining(player) && is.getTypeId() == Config.getDetonatorItemID()) {
BlastMining.remoteDetonation(player, plugin); BlastMining.remoteDetonation(player, plugin);
} }
break; break;
case RIGHT_CLICK_AIR: case RIGHT_CLICK_AIR:
/* ACTIVATION CHECKS */ /* ACTIVATION CHECKS */
if (Config.enableAbilities) { if (Config.enableAbilities) {
Skills.activationCheck(player, SkillType.AXES); Skills.activationCheck(player, SkillType.AXES);
Skills.activationCheck(player, SkillType.EXCAVATION); Skills.activationCheck(player, SkillType.EXCAVATION);
Skills.activationCheck(player, SkillType.HERBALISM); Skills.activationCheck(player, SkillType.HERBALISM);
Skills.activationCheck(player, SkillType.MINING); Skills.activationCheck(player, SkillType.MINING);
Skills.activationCheck(player, SkillType.SWORDS); Skills.activationCheck(player, SkillType.SWORDS);
Skills.activationCheck(player, SkillType.UNARMED); Skills.activationCheck(player, SkillType.UNARMED);
Skills.activationCheck(player, SkillType.WOODCUTTING); Skills.activationCheck(player, SkillType.WOODCUTTING);
} }
/* ITEM CHECKS */ /* ITEM CHECKS */
Item.itemchecks(player); Item.itemchecks(player);
/* BLAST MINING CHECK */ /* BLAST MINING CHECK */
if (mcPermissions.getInstance().blastMining(player) && is.getTypeId() == Config.getDetonatorItemID()) { if (mcPermissions.getInstance().blastMining(player) && is.getTypeId() == Config.getDetonatorItemID()) {
BlastMining.remoteDetonation(player, plugin); BlastMining.remoteDetonation(player, plugin);
} }
break; break;
case LEFT_CLICK_AIR: case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK: case LEFT_CLICK_BLOCK:
/* CALL OF THE WILD CHECKS */ /* CALL OF THE WILD CHECKS */
if (player.isSneaking() && mcPermissions.getInstance().taming(player)) { if (player.isSneaking() && mcPermissions.getInstance().taming(player)) {
if (is.getType().equals(Material.RAW_FISH)) { if (is.getType().equals(Material.RAW_FISH)) {
Taming.animalSummon(EntityType.OCELOT, player, plugin); Taming.animalSummon(EntityType.OCELOT, player, plugin);
} }
else if (is.getType().equals(Material.BONE)) { else if (is.getType().equals(Material.BONE)) {
Taming.animalSummon(EntityType.WOLF, player, plugin); Taming.animalSummon(EntityType.WOLF, player, plugin);
} }
} }
break; break;
default: default:
break; break;
} }
} }
/** /**
* Monitor PlayerChat events. * Monitor PlayerChat events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(PlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
boolean partyChat = PP.getPartyChatMode(); boolean partyChat = PP.getPartyChatMode();
boolean adminChat = PP.getAdminChatMode(); boolean adminChat = PP.getAdminChatMode();
Set<Player> recipients = event.getRecipients(); Set<Player> recipients = event.getRecipients();
Set<Player> intendedRecipients = new HashSet<Player>(); Set<Player> intendedRecipients = new HashSet<Player>();
ChatColor color = null; ChatColor color = null;
if (partyChat || adminChat) { if (partyChat || adminChat) {
if (partyChat) { if (partyChat) {
if (!PP.inParty()) { if (!PP.inParty()) {
player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale
return; return;
} }
color = ChatColor.GREEN; color = ChatColor.GREEN;
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), PP.getParty(), event.getMessage()); McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), PP.getParty(), event.getMessage());
plugin.getServer().getPluginManager().callEvent(chatEvent); plugin.getServer().getPluginManager().callEvent(chatEvent);
if(chatEvent.isCancelled()) return; if(chatEvent.isCancelled()) return;
event.setMessage(chatEvent.getMessage()); event.setMessage(chatEvent.getMessage());
for (Player x : Party.getInstance().getOnlineMembers(player)) { for (Player x : Party.getInstance().getOnlineMembers(player)) {
intendedRecipients.add(x); intendedRecipients.add(x);
} }
event.setFormat(color + "(" + ChatColor.WHITE + "%1$s" + color + ") %2$s"); event.setFormat(color + "(" + ChatColor.WHITE + "%1$s" + color + ") %2$s");
} }
if (adminChat) { if (adminChat) {
color = ChatColor.AQUA; color = ChatColor.AQUA;
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), event.getMessage()); McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), event.getMessage());
plugin.getServer().getPluginManager().callEvent(chatEvent); plugin.getServer().getPluginManager().callEvent(chatEvent);
if(chatEvent.isCancelled()) return; if(chatEvent.isCancelled()) return;
event.setMessage(chatEvent.getMessage()); event.setMessage(chatEvent.getMessage());
for (Player x : plugin.getServer().getOnlinePlayers()) { for (Player x : plugin.getServer().getOnlinePlayers()) {
if (x.isOp() || mcPermissions.getInstance().adminChat(x)) { if (x.isOp() || mcPermissions.getInstance().adminChat(x)) {
intendedRecipients.add(x); intendedRecipients.add(x);
} }
} }
event.setFormat(color + "{" + ChatColor.WHITE + "%1$s" + color + "} %2$s"); event.setFormat(color + "{" + ChatColor.WHITE + "%1$s" + color + "} %2$s");
} }
recipients.retainAll(intendedRecipients); recipients.retainAll(intendedRecipients);
} }
} }
// Dynamically aliasing commands need to be re-done. // Dynamically aliasing commands need to be re-done.
// For now, using a command with an alias will send both the original command, and the mcMMO command // For now, using a command with an alias will send both the original command, and the mcMMO command
/** /**
* Monitor PlayerCommandPreprocess events. * Monitor PlayerCommandPreprocess events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String message = event.getMessage(); String message = event.getMessage();
if (!message.startsWith("/")) { if (!message.startsWith("/")) {
return; return;
} }
String command = message.substring(1).split(" ")[0]; String command = message.substring(1).split(" ")[0];
if (plugin.aliasMap.containsKey(command)) { if (plugin.aliasMap.containsKey(command)) {
if (command.equalsIgnoreCase(plugin.aliasMap.get(command))) { if (command.equalsIgnoreCase(plugin.aliasMap.get(command))) {
return; return;
} }
event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command))); event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command)));
} }
} }
} }

View File

@ -8,7 +8,7 @@ import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
/** /**
* Listener for listening to our own events, only really useful for catching errors * Listener for listening to our own events, only really useful for catching errors
*/ */
public class mcSelfListener implements Listener { public class SelfListener implements Listener {
/** /**
* Monitor internal XP gain events. * Monitor internal XP gain events.

View File

@ -1,48 +1,48 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.input.KeyPressedEvent; import org.getspout.spoutapi.event.input.KeyPressedEvent;
import org.getspout.spoutapi.gui.ScreenType; import org.getspout.spoutapi.gui.ScreenType;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.popups.PopupMMO; import com.gmail.nossr50.datatypes.popups.PopupMMO;
import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.SpoutStuff;
public class mcSpoutInputListener implements Listener { public class SpoutInputListener implements Listener {
private mcMMO plugin; private mcMMO plugin;
public mcSpoutInputListener(mcMMO plugin) { public SpoutInputListener(mcMMO plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
/** /**
* Monitor Spout KeyPressed events. * Monitor Spout KeyPressed events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler @EventHandler
public void onKeyPressedEvent(KeyPressedEvent event) { public void onKeyPressedEvent(KeyPressedEvent event) {
SpoutPlayer sPlayer = event.getPlayer(); SpoutPlayer sPlayer = event.getPlayer();
if (!sPlayer.isSpoutCraftEnabled() || sPlayer.getMainScreen().getActivePopup() != null || event.getScreenType() != ScreenType.GAME_SCREEN) { if (!sPlayer.isSpoutCraftEnabled() || sPlayer.getMainScreen().getActivePopup() != null || event.getScreenType() != ScreenType.GAME_SCREEN) {
return; return;
} }
if (event.getKey() == SpoutStuff.keypress) { if (event.getKey() == SpoutStuff.keypress) {
if (!SpoutStuff.playerScreens.containsKey(sPlayer)) { if (!SpoutStuff.playerScreens.containsKey(sPlayer)) {
PopupMMO mmoPop = new PopupMMO(sPlayer, Users.getProfile(sPlayer), plugin); PopupMMO mmoPop = new PopupMMO(sPlayer, Users.getProfile(sPlayer), plugin);
SpoutStuff.playerScreens.put(sPlayer, mmoPop); SpoutStuff.playerScreens.put(sPlayer, mmoPop);
sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer)); sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer));
sPlayer.getMainScreen().setDirty(true); sPlayer.getMainScreen().setDirty(true);
} }
else { else {
sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer)); sPlayer.getMainScreen().attachPopupScreen(SpoutStuff.playerScreens.get(sPlayer));
sPlayer.getMainScreen().setDirty(true); sPlayer.getMainScreen().setDirty(true);
} }
} }
} }
} }

View File

@ -1,46 +1,46 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent; import org.getspout.spoutapi.event.spout.SpoutCraftEnableEvent;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.HUDmmo; import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.SpoutStuff;
public class mcSpoutListener implements Listener { public class SpoutListener implements Listener {
//Why do we have this here? We never use it... //Why do we have this here? We never use it...
mcMMO plugin = null; mcMMO plugin = null;
public mcSpoutListener(mcMMO pluginx) { public SpoutListener(mcMMO pluginx) {
plugin = pluginx; plugin = pluginx;
} }
/** /**
* Monitor SpoutCraftEnable events. * Monitor SpoutCraftEnable events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler @EventHandler
public void onSpoutCraftEnable(SpoutCraftEnableEvent event) { public void onSpoutCraftEnable(SpoutCraftEnableEvent event) {
SpoutPlayer sPlayer = event.getPlayer(); SpoutPlayer sPlayer = event.getPlayer();
PlayerProfile PPs = Users.getProfile(sPlayer); PlayerProfile PPs = Users.getProfile(sPlayer);
//TODO: Add custom titles based on skills //TODO: Add custom titles based on skills
if (Config.getShowPowerLevelForSpout()) { if (Config.getShowPowerLevelForSpout()) {
sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl" sPlayer.setTitle(sPlayer.getName()+ "\n" + ChatColor.YELLOW + "P" + ChatColor.GOLD + "lvl"
+ ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(PPs.getPowerLevel())); + ChatColor.WHITE+"." + ChatColor.GREEN + String.valueOf(PPs.getPowerLevel()));
} }
if (sPlayer.isSpoutCraftEnabled()) { if (sPlayer.isSpoutCraftEnabled()) {
SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin)); //Setup Party HUD stuff SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin)); //Setup Party HUD stuff
PPs.toggleSpoutEnabled(); PPs.toggleSpoutEnabled();
} }
} }
} }

View File

@ -1,91 +1,91 @@
package com.gmail.nossr50.listeners; package com.gmail.nossr50.listeners;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.getspout.spoutapi.event.screen.ButtonClickEvent; import org.getspout.spoutapi.event.screen.ButtonClickEvent;
import org.getspout.spoutapi.event.screen.ScreenCloseEvent; import org.getspout.spoutapi.event.screen.ScreenCloseEvent;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.HUDType; import com.gmail.nossr50.datatypes.HUDType;
import com.gmail.nossr50.datatypes.HUDmmo; import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.buttons.ButtonEscape; import com.gmail.nossr50.datatypes.buttons.ButtonEscape;
import com.gmail.nossr50.datatypes.buttons.ButtonHUDStyle; import com.gmail.nossr50.datatypes.buttons.ButtonHUDStyle;
import com.gmail.nossr50.datatypes.buttons.ButtonPartyToggle; import com.gmail.nossr50.datatypes.buttons.ButtonPartyToggle;
import com.gmail.nossr50.datatypes.popups.PopupMMO; import com.gmail.nossr50.datatypes.popups.PopupMMO;
import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.SpoutStuff;
public class mcSpoutScreenListener implements Listener { public class SpoutScreenListener implements Listener {
//Why do we have this here? We never use it... //Why do we have this here? We never use it...
mcMMO plugin = null; mcMMO plugin = null;
public mcSpoutScreenListener(mcMMO pluginx) { public SpoutScreenListener(mcMMO pluginx) {
plugin = pluginx; plugin = pluginx;
} }
/** /**
* Monitor Spout ButtonClick events. * Monitor Spout ButtonClick events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler @EventHandler
public void onButtonClick(ButtonClickEvent event) { public void onButtonClick(ButtonClickEvent event) {
SpoutPlayer sPlayer = event.getPlayer(); SpoutPlayer sPlayer = event.getPlayer();
PlayerProfile PP = Users.getProfile(sPlayer); PlayerProfile PP = Users.getProfile(sPlayer);
if (event.getButton() instanceof ButtonHUDStyle) { if (event.getButton() instanceof ButtonHUDStyle) {
if (SpoutStuff.playerHUDs.containsKey(sPlayer)) { if (SpoutStuff.playerHUDs.containsKey(sPlayer)) {
SpoutStuff.playerHUDs.get(sPlayer).resetHUD(); SpoutStuff.playerHUDs.get(sPlayer).resetHUD();
SpoutStuff.playerHUDs.remove(sPlayer); SpoutStuff.playerHUDs.remove(sPlayer);
switch (PP.getHUDType()) { switch (PP.getHUDType()) {
case RETRO: case RETRO:
PP.setHUDType(HUDType.STANDARD); PP.setHUDType(HUDType.STANDARD);
break; break;
case STANDARD: case STANDARD:
PP.setHUDType(HUDType.SMALL); PP.setHUDType(HUDType.SMALL);
break; break;
case SMALL: case SMALL:
PP.setHUDType(HUDType.DISABLED); PP.setHUDType(HUDType.DISABLED);
break; break;
case DISABLED: case DISABLED:
PP.setHUDType(HUDType.RETRO); PP.setHUDType(HUDType.RETRO);
break; break;
default: default:
break; break;
} }
SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin)); SpoutStuff.playerHUDs.put(sPlayer, new HUDmmo(sPlayer, plugin));
SpoutStuff.playerScreens.get(sPlayer).updateButtons(PP); SpoutStuff.playerScreens.get(sPlayer).updateButtons(PP);
} }
} }
else if (event.getButton() instanceof ButtonEscape) { else if (event.getButton() instanceof ButtonEscape) {
sPlayer.getMainScreen().closePopup(); sPlayer.getMainScreen().closePopup();
} }
else if (event.getButton() instanceof ButtonPartyToggle) { else if (event.getButton() instanceof ButtonPartyToggle) {
PP.togglePartyHUD(); PP.togglePartyHUD();
ButtonPartyToggle bpt = (ButtonPartyToggle) event.getButton(); ButtonPartyToggle bpt = (ButtonPartyToggle) event.getButton();
bpt.updateText(PP); bpt.updateText(PP);
SpoutStuff.playerHUDs.get(sPlayer).resetHUD(); SpoutStuff.playerHUDs.get(sPlayer).resetHUD();
SpoutStuff.playerHUDs.get(sPlayer).initializeHUD(sPlayer); SpoutStuff.playerHUDs.get(sPlayer).initializeHUD(sPlayer);
} }
} }
/** /**
* Monitor Spout ScreenClose events. * Monitor Spout ScreenClose events.
* *
* @param event The event to watch * @param event The event to watch
*/ */
@EventHandler @EventHandler
public void onScreenClose(ScreenCloseEvent event) { public void onScreenClose(ScreenCloseEvent event) {
if (event.getScreen() instanceof PopupMMO) { if (event.getScreen() instanceof PopupMMO) {
SpoutStuff.playerScreens.remove(event.getPlayer()); SpoutStuff.playerScreens.remove(event.getPlayer());
} }
} }
} }

View File

@ -8,9 +8,9 @@ import com.gmail.nossr50.commands.party.*;
import com.gmail.nossr50.commands.general.*; import com.gmail.nossr50.commands.general.*;
import com.gmail.nossr50.config.*; import com.gmail.nossr50.config.*;
import com.gmail.nossr50.runnables.*; import com.gmail.nossr50.runnables.*;
import com.gmail.nossr50.listeners.mcBlockListener; import com.gmail.nossr50.listeners.BlockListener;
import com.gmail.nossr50.listeners.mcEntityListener; import com.gmail.nossr50.listeners.EntityListener;
import com.gmail.nossr50.listeners.mcPlayerListener; import com.gmail.nossr50.listeners.PlayerListener;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
@ -36,9 +36,9 @@ import org.bukkit.entity.Player;
public class mcMMO extends JavaPlugin { public class mcMMO extends JavaPlugin {
private final mcPlayerListener playerListener = new mcPlayerListener(this); private final PlayerListener playerListener = new PlayerListener(this);
private final mcBlockListener blockListener = new mcBlockListener(this); private final BlockListener blockListener = new BlockListener(this);
private final mcEntityListener entityListener = new mcEntityListener(this); private final EntityListener entityListener = new EntityListener(this);
public HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command public HashMap<String, String> aliasMap = new HashMap<String, String>(); //Alias - Command
public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>(); public HashMap<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();

View File

@ -27,9 +27,9 @@ import com.gmail.nossr50.datatypes.HUDmmo;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.popups.PopupMMO; import com.gmail.nossr50.datatypes.popups.PopupMMO;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.listeners.mcSpoutInputListener; import com.gmail.nossr50.listeners.SpoutInputListener;
import com.gmail.nossr50.listeners.mcSpoutListener; import com.gmail.nossr50.listeners.SpoutListener;
import com.gmail.nossr50.listeners.mcSpoutScreenListener; import com.gmail.nossr50.listeners.SpoutScreenListener;
public class SpoutStuff { public class SpoutStuff {
private static mcMMO plugin = mcMMO.p; private static mcMMO plugin = mcMMO.p;
@ -40,9 +40,9 @@ public class SpoutStuff {
public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator; public final static String hudRetroDirectory = hudDirectory + "Retro" + File.separator;
public final static String soundDirectory = spoutDirectory + "Sound" + File.separator; public final static String soundDirectory = spoutDirectory + "Sound" + File.separator;
private final static mcSpoutListener spoutListener = new mcSpoutListener(plugin); private final static SpoutListener spoutListener = new SpoutListener(plugin);
private final static mcSpoutInputListener spoutInputListener = new mcSpoutInputListener(plugin); private final static SpoutInputListener spoutInputListener = new SpoutInputListener(plugin);
private final static mcSpoutScreenListener spoutScreenListener = new mcSpoutScreenListener(plugin); private final static SpoutScreenListener spoutScreenListener = new SpoutScreenListener(plugin);
public static HashMap<Player, HUDmmo> playerHUDs = new HashMap<Player, HUDmmo>(); public static HashMap<Player, HUDmmo> playerHUDs = new HashMap<Player, HUDmmo>();
public static HashMap<SpoutPlayer, PopupMMO> playerScreens = new HashMap<SpoutPlayer, PopupMMO>(); public static HashMap<SpoutPlayer, PopupMMO> playerScreens = new HashMap<SpoutPlayer, PopupMMO>();