mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-04-19 18:16:23 +02:00
Chimaera wing code is a little bit less disgusting now Fixes #5049
This commit is contained in:
parent
61c5ded677
commit
65d4d2b059
@ -1,5 +1,6 @@
|
|||||||
package com.gmail.nossr50.runnables.items;
|
package com.gmail.nossr50.runnables.items;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
||||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
@ -7,16 +8,24 @@ import com.gmail.nossr50.util.CancellableRunnable;
|
|||||||
import com.gmail.nossr50.util.ChimaeraWing;
|
import com.gmail.nossr50.util.ChimaeraWing;
|
||||||
import com.gmail.nossr50.util.ItemUtils;
|
import com.gmail.nossr50.util.ItemUtils;
|
||||||
import com.gmail.nossr50.util.Misc;
|
import com.gmail.nossr50.util.Misc;
|
||||||
|
import com.gmail.nossr50.util.player.NotificationManager;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
||||||
|
import com.gmail.nossr50.util.sounds.SoundType;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
public class ChimaeraWingWarmup extends CancellableRunnable {
|
import static com.gmail.nossr50.util.ChimaeraWing.expendChimaeraWing;
|
||||||
private final McMMOPlayer mcMMOPlayer;
|
|
||||||
|
|
||||||
public ChimaeraWingWarmup(McMMOPlayer mcMMOPlayer) {
|
public class ChimaeraWingWarmup extends CancellableRunnable {
|
||||||
this.mcMMOPlayer = mcMMOPlayer;
|
private final McMMOPlayer mmoPlayer;
|
||||||
|
private final Location location;
|
||||||
|
|
||||||
|
public ChimaeraWingWarmup(McMMOPlayer mmoPlayer, Location location) {
|
||||||
|
this.mmoPlayer = mmoPlayer;
|
||||||
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -25,23 +34,24 @@ public class ChimaeraWingWarmup extends CancellableRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkChimaeraWingTeleport() {
|
private void checkChimaeraWingTeleport() {
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
final Player player = mmoPlayer.getPlayer();
|
||||||
Location previousLocation = mcMMOPlayer.getTeleportCommenceLocation();
|
final Location previousLocation = mmoPlayer.getTeleportCommenceLocation();
|
||||||
|
|
||||||
if (player.getLocation().distanceSquared(previousLocation) > 1.0 || !player.getInventory().containsAtLeast(ChimaeraWing.getChimaeraWing(0), 1)) {
|
if (player.getLocation().distanceSquared(previousLocation) > 1.0
|
||||||
|
|| !player.getInventory().containsAtLeast(ChimaeraWing.getChimaeraWing(1), 1)) {
|
||||||
player.sendMessage(LocaleLoader.getString("Teleport.Cancelled"));
|
player.sendMessage(LocaleLoader.getString("Teleport.Cancelled"));
|
||||||
mcMMOPlayer.setTeleportCommenceLocation(null);
|
mmoPlayer.setTeleportCommenceLocation(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack inHand = player.getInventory().getItemInMainHand();
|
final ItemStack inHand = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (!ItemUtils.isChimaeraWing(inHand) || inHand.getAmount() < mcMMO.p.getGeneralConfig().getChimaeraUseCost()) {
|
if (!ItemUtils.isChimaeraWing(inHand) || inHand.getAmount() < mcMMO.p.getGeneralConfig().getChimaeraUseCost()) {
|
||||||
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name")));
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", LocaleLoader.getString("Item.ChimaeraWing.Name")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long recentlyHurt = mcMMOPlayer.getRecentlyHurt();
|
long recentlyHurt = mmoPlayer.getRecentlyHurt();
|
||||||
int hurtCooldown = mcMMO.p.getGeneralConfig().getChimaeraRecentlyHurtCooldown();
|
int hurtCooldown = mcMMO.p.getGeneralConfig().getChimaeraRecentlyHurtCooldown();
|
||||||
|
|
||||||
if (hurtCooldown > 0) {
|
if (hurtCooldown > 0) {
|
||||||
@ -53,6 +63,32 @@ public class ChimaeraWingWarmup extends CancellableRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ChimaeraWing.chimaeraExecuteTeleport();
|
chimaeraExecuteTeleport();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void chimaeraExecuteTeleport() {
|
||||||
|
final Player player = mmoPlayer.getPlayer();
|
||||||
|
|
||||||
|
if (mcMMO.p.getGeneralConfig().getChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
|
||||||
|
mcMMO.p.getFoliaLib().getScheduler().teleportAsync(player, player.getBedSpawnLocation());
|
||||||
|
} else {
|
||||||
|
final Location spawnLocation = player.getWorld().getSpawnLocation();
|
||||||
|
if (spawnLocation.getBlock().getType() == Material.AIR) {
|
||||||
|
mcMMO.p.getFoliaLib().getScheduler().teleportAsync(player, spawnLocation);
|
||||||
|
} else {
|
||||||
|
mcMMO.p.getFoliaLib().getScheduler().teleportAsync(
|
||||||
|
player, player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expendChimaeraWing(player, mcMMO.p.getGeneralConfig().getChimaeraUseCost(), player.getInventory().getItemInMainHand());
|
||||||
|
mmoPlayer.actualizeChimeraWingLastUse();
|
||||||
|
mmoPlayer.setTeleportCommenceLocation(null);
|
||||||
|
|
||||||
|
if (mcMMO.p.getGeneralConfig().getChimaeraSoundEnabled()) {
|
||||||
|
SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING);
|
||||||
|
}
|
||||||
|
|
||||||
|
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,6 @@ import com.gmail.nossr50.util.player.NotificationManager;
|
|||||||
import com.gmail.nossr50.util.player.UserManager;
|
import com.gmail.nossr50.util.player.UserManager;
|
||||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||||
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
||||||
import com.gmail.nossr50.util.sounds.SoundType;
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -25,9 +23,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class ChimaeraWing {
|
public final class ChimaeraWing {
|
||||||
private static McMMOPlayer mcMMOPlayer;
|
|
||||||
private static Location location;
|
|
||||||
|
|
||||||
private ChimaeraWing() {}
|
private ChimaeraWing() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +35,7 @@ public final class ChimaeraWing {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack inHand = player.getInventory().getItemInMainHand();
|
final ItemStack inHand = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
if (!ItemUtils.isChimaeraWing(inHand)) {
|
if (!ItemUtils.isChimaeraWing(inHand)) {
|
||||||
return;
|
return;
|
||||||
@ -51,7 +46,7 @@ public final class ChimaeraWing {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer = UserManager.getPlayer(player);
|
final McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
|
|
||||||
//Not loaded
|
//Not loaded
|
||||||
if (mcMMOPlayer == null)
|
if (mcMMOPlayer == null)
|
||||||
@ -61,10 +56,10 @@ public final class ChimaeraWing {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int amount = inHand.getAmount();
|
int amountInHand = inHand.getAmount();
|
||||||
|
|
||||||
if (amount < mcMMO.p.getGeneralConfig().getChimaeraUseCost()) {
|
if (amountInHand < mcMMO.p.getGeneralConfig().getChimaeraUseCost()) {
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.NotEnough",String.valueOf(mcMMO.p.getGeneralConfig().getChimaeraUseCost() - amount), "Item.ChimaeraWing.Name");
|
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.NotEnough",String.valueOf(mcMMO.p.getGeneralConfig().getChimaeraUseCost() - amountInHand), "Item.ChimaeraWing.Name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,13 +87,13 @@ public final class ChimaeraWing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
location = player.getLocation();
|
final Location playerLocation = player.getLocation();
|
||||||
|
|
||||||
if (mcMMO.p.getGeneralConfig().getChimaeraPreventUseUnderground()) {
|
if (mcMMO.p.getGeneralConfig().getChimaeraPreventUseUnderground()) {
|
||||||
if (location.getY() < player.getWorld().getHighestBlockYAt(location)) {
|
if (playerLocation.getY() < player.getWorld().getHighestBlockYAt(playerLocation)) {
|
||||||
player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(amount - mcMMO.p.getGeneralConfig().getChimaeraUseCost())));
|
expendChimaeraWing(player, amountInHand, inHand);
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail");
|
NotificationManager.sendPlayerInformation(player,
|
||||||
player.updateInventory();
|
NotificationType.REQUIREMENTS_NOT_MET, "Item.ChimaeraWing.Fail");
|
||||||
player.setVelocity(new Vector(0, 0.5D, 0));
|
player.setVelocity(new Vector(0, 0.5D, 0));
|
||||||
CombatUtils.dealDamage(player, Misc.getRandom().nextInt((int) (player.getHealth() - 10)));
|
CombatUtils.dealDamage(player, Misc.getRandom().nextInt((int) (player.getHealth() - 10)));
|
||||||
mcMMOPlayer.actualizeChimeraWingLastUse();
|
mcMMOPlayer.actualizeChimeraWingLastUse();
|
||||||
@ -107,46 +102,25 @@ public final class ChimaeraWing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mcMMOPlayer.actualizeTeleportCommenceLocation(player);
|
mcMMOPlayer.actualizeTeleportCommenceLocation(player);
|
||||||
|
long teleportDelay = mcMMO.p.getGeneralConfig().getChimaeraWarmup();
|
||||||
long warmup = mcMMO.p.getGeneralConfig().getChimaeraWarmup();
|
if (teleportDelay > 0) {
|
||||||
|
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(teleportDelay));
|
||||||
if (warmup > 0) {
|
mcMMO.p.getFoliaLib().getScheduler().runAtEntityLater(player, new ChimaeraWingWarmup(mcMMOPlayer, playerLocation), 20 * teleportDelay);
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Teleport.Commencing", String.valueOf(warmup));
|
|
||||||
mcMMO.p.getFoliaLib().getScheduler().runAtEntityLater(player, new ChimaeraWingWarmup(mcMMOPlayer), 20 * warmup);
|
|
||||||
} else {
|
} else {
|
||||||
chimaeraExecuteTeleport();
|
mcMMO.p.getFoliaLib().getScheduler().runAtEntityLater(player, new ChimaeraWingWarmup(mcMMOPlayer, playerLocation), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void chimaeraExecuteTeleport() {
|
public static void expendChimaeraWing(Player player, int amountInHand, ItemStack inHand) {
|
||||||
Player player = mcMMOPlayer.getPlayer();
|
int amountAfterUse = amountInHand - mcMMO.p.getGeneralConfig().getChimaeraUseCost();
|
||||||
|
if (amountAfterUse >= 1) {
|
||||||
if (mcMMO.p.getGeneralConfig().getChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) {
|
inHand.setAmount(amountAfterUse);
|
||||||
// player.teleport(player.getBedSpawnLocation());
|
player.getInventory().setItemInMainHand(inHand);
|
||||||
mcMMO.p.getFoliaLib().getScheduler().teleportAsync(player, player.getBedSpawnLocation());
|
|
||||||
} else {
|
} else {
|
||||||
Location spawnLocation = player.getWorld().getSpawnLocation();
|
player.getInventory().removeItem(inHand);
|
||||||
if (spawnLocation.getBlock().getType() == Material.AIR) {
|
|
||||||
// player.teleport(spawnLocation);
|
|
||||||
mcMMO.p.getFoliaLib().getScheduler().teleportAsync(player, spawnLocation);
|
|
||||||
} else {
|
|
||||||
// player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
|
||||||
mcMMO.p.getFoliaLib().getScheduler().teleportAsync(player, player.getWorld().getHighestBlockAt(spawnLocation).getLocation());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(player.getInventory().getItemInMainHand().getAmount() - mcMMO.p.getGeneralConfig().getChimaeraUseCost())));
|
|
||||||
player.updateInventory();
|
|
||||||
mcMMOPlayer.actualizeChimeraWingLastUse();
|
|
||||||
mcMMOPlayer.setTeleportCommenceLocation(null);
|
|
||||||
|
|
||||||
if (mcMMO.p.getGeneralConfig().getChimaeraSoundEnabled()) {
|
|
||||||
SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING);
|
|
||||||
}
|
|
||||||
|
|
||||||
NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack getChimaeraWing(int amount) {
|
public static ItemStack getChimaeraWing(int amount) {
|
||||||
ItemStack itemStack = new ItemStack(mcMMO.p.getGeneralConfig().getChimaeraItem(), amount);
|
ItemStack itemStack = new ItemStack(mcMMO.p.getGeneralConfig().getChimaeraItem(), amount);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user