Improving Chimaera Wing - part 2

* Added a warmup before using a Chimaera Wing
 * Closes #740
This commit is contained in:
TfT_02 2013-03-22 00:38:15 +01:00
parent 9f55c25775
commit 5b5b73cde0
5 changed files with 107 additions and 21 deletions

View File

@ -107,6 +107,7 @@ public class Config extends AutoUpdateConfigLoader {
public boolean getChimaeraEnabled() { return config.getBoolean("Items.Chimaera_Wing.Enabled", true); }
public boolean getChimaeraPreventUseUnderground() { return config.getBoolean("Items.Chimaera_Wing.Prevent_Use_Underground", true); }
public int getChimaeraCooldown() { return config.getInt("Items.Chimaera_Wing.Cooldown", 240); }
public int getChimaeraWarmup() { return config.getInt("Items.Chimaera_Wing.Warmup", 5); }
/* Particles */
public boolean getAbilityActivationEffectEnabled() { return config.getBoolean("Particles.Ability_Activation", true); }

View File

@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Set;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -78,8 +79,10 @@ public class McMMOPlayer {
private Map<ToolType, Boolean> toolMode = new HashMap<ToolType, Boolean>();
private Map<ToolType, Integer> toolATS = new HashMap<ToolType, Integer>();
private int recentlyHurt;
private int chimaeraWing;
private Location chimaeraWingCommence;
private int recentlyHurt;
private int respawnATS;
public McMMOPlayer(Player player) {
@ -315,6 +318,17 @@ public class McMMOPlayer {
chimaeraWing = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR);
}
public Location getChimaeraCommenceLocation() {
return chimaeraWingCommence;
}
public void setChimaeraCommenceLocation(Location location) {
chimaeraWingCommence = location;
}
public void actualizeChimaeraCommenceLocation(Player player) {
setChimaeraCommenceLocation(player.getLocation());
}
/*
* Exploit Prevention

View File

@ -0,0 +1,49 @@
package com.gmail.nossr50.runnables.items;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.ChimaeraWing;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.SkillUtils;
public class ChimaeraWingWarmup extends BukkitRunnable {
private McMMOPlayer mcMMOPlayer;
public ChimaeraWingWarmup(McMMOPlayer mcMMOPlayer) {
this.mcMMOPlayer = mcMMOPlayer;
}
@Override
public void run() {
checkChimaeraWingTeleport();
}
private void checkChimaeraWingTeleport() {
Player player = mcMMOPlayer.getPlayer();
Location previousLocation = mcMMOPlayer.getChimaeraCommenceLocation();
Location newLocation = mcMMOPlayer.getPlayer().getLocation();
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
if (newLocation.distanceSquared(previousLocation) > 1.0) {
player.sendMessage(ChatColor.RED + "Teleportation canceled!"); //TODO Locale!
mcMMOPlayer.setChimaeraCommenceLocation(null);
return;
}
if (!SkillUtils.cooldownOver(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, player)) {
player.sendMessage(LocaleLoader.getString("Item.Injured.Wait", SkillUtils.calculateTimeLeft(recentlyHurt * Misc.TIME_CONVERSION_FACTOR, 60, player)));
mcMMOPlayer.setChimaeraCommenceLocation(null);
return;
}
ChimaeraWing.chimaeraExecuteTeleport();
mcMMOPlayer.setChimaeraCommenceLocation(null);
}
}

View File

@ -13,14 +13,20 @@ import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.Vector;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.metrics.MetricsManager;
import com.gmail.nossr50.runnables.items.ChimaeraWingWarmup;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public final class ChimaeraWing {
private static McMMOPlayer mcMMOPlayer;
private static Location location;
private ChimaeraWing() {}
/**
@ -35,12 +41,18 @@ public final class ChimaeraWing {
return;
}
Location location = player.getLocation();
mcMMOPlayer = UserManager.getPlayer(player);
location = player.getLocation();
int amount = inHand.getAmount();
long recentlyHurt = UserManager.getPlayer(player).getRecentlyHurt();
long lastChimaeraWing = (UserManager.getPlayer(player).getLastChimaeraTeleport());
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
long lastChimaeraWing = mcMMOPlayer.getLastChimaeraTeleport();
if (Permissions.chimaeraWing(player) && ItemUtils.isChimaeraWing(inHand)) {
if (mcMMOPlayer.getChimaeraCommenceLocation() != null) {
return;
}
if (!SkillUtils.cooldownOver(lastChimaeraWing * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player)) {
player.sendMessage(ChatColor.RED + "You need to wait before you can use this again! " + ChatColor.YELLOW + "(" + SkillUtils.calculateTimeLeft(lastChimaeraWing * Misc.TIME_CONVERSION_FACTOR, Config.getInstance().getChimaeraCooldown(), player) + ")"); //TODO Locale!
return;
@ -56,37 +68,46 @@ public final class ChimaeraWing {
return;
}
player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
if (Config.getInstance().getChimaeraPreventUseUnderground()) {
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
player.setItemInHand(new ItemStack(getChimaeraWing(amount - Config.getInstance().getChimaeraUseCost())));
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Fail"));
player.setVelocity(new Vector(0, 0.5D, 0));
CombatUtils.dealDamage(player, Misc.getRandom().nextInt(player.getHealth() - 10));
UserManager.getPlayer(player).actualizeLastChimaeraTeleport();
mcMMOPlayer.actualizeLastChimaeraTeleport();
return;
}
}
mcMMOPlayer.actualizeChimaeraCommenceLocation(player);
if (player.getBedSpawnLocation() != null) {
player.teleport(player.getBedSpawnLocation());
long warmup = Config.getInstance().getChimaeraWarmup();
player.sendMessage(ChatColor.GRAY + "Commencing teleport in " + ChatColor.GOLD + "(" + warmup + ")" + ChatColor.GRAY + " seconds, please stand still..."); //TODO Locale!
new ChimaeraWingWarmup(mcMMOPlayer).runTaskLater(mcMMO.p, 20 * warmup);
}
}
public static void chimaeraExecuteTeleport() {
Player player = mcMMOPlayer.getPlayer();
if (player.getBedSpawnLocation() != null) {
player.teleport(player.getBedSpawnLocation());
}
else {
Location spawnLocation = player.getWorld().getSpawnLocation();
if (spawnLocation.getBlock().getType() == Material.AIR) {
player.teleport(spawnLocation);
}
else {
Location spawnLocation = player.getWorld().getSpawnLocation();
if (spawnLocation.getBlock().getType() == Material.AIR) {
player.teleport(spawnLocation);
}
else {
player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
}
player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
}
UserManager.getPlayer(player).actualizeLastChimaeraTeleport();
MetricsManager.chimeraWingUsed();
player.playSound(location, Sound.BAT_TAKEOFF, Misc.BAT_VOLUME, Misc.BAT_PITCH);
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));
}
player.setItemInHand(new ItemStack(getChimaeraWing(player.getItemInHand().getAmount() - Config.getInstance().getChimaeraUseCost())));
UserManager.getPlayer(player).actualizeLastChimaeraTeleport();
MetricsManager.chimeraWingUsed();
player.playSound(location, Sound.BAT_TAKEOFF, Misc.BAT_VOLUME, Misc.BAT_PITCH);
player.sendMessage(LocaleLoader.getString("Item.ChimaeraWing.Pass"));
}
public static ItemStack getChimaeraWing(int amount) {

View File

@ -73,6 +73,7 @@ Items:
Chimaera_Wing:
Enabled: true
Cooldown: 240
Warmup: 5
Prevent_Use_Underground: true
Use_Cost: 1
Recipe_Cost: 5