added shadowstep, totemShield, and gravity gauntlet mechanics

This commit is contained in:
kai ohara 2025-02-07 13:16:33 -05:00
parent 09209e894b
commit 405cd905bd
31 changed files with 268 additions and 0 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -61,8 +61,15 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
}.runTaskTimer(this, 0, 2); // Runs every 10 ticks (0.5 seconds) }.runTaskTimer(this, 0, 2); // Runs every 10 ticks (0.5 seconds)
// Register Gravity Gauntlet // Register Gravity Gauntlet
new GravityGauntlet(this); new GravityGauntlet(this);
// Register TotemShield
new TotemShield(this);
// Register the ShadowStep listener
getServer().getPluginManager().registerEvents(new ShadowStep(this), this);
// Register command // Register command
this.getCommand("gravitygauntlet").setExecutor(new GravityGauntletCommand()); this.getCommand("gravitygauntlet").setExecutor(new GravityGauntletCommand());
// Register the PhantomDodge listener
getServer().getPluginManager().registerEvents(new PhantomDodge(this), this);
} }
@Override @Override

View File

@ -0,0 +1,75 @@
package CoswayUtil;
import org.bukkit.entity.Player;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.entity.EntityType;
import org.bukkit.Location;
import org.bukkit.event.EventPriority;
public class PhantomDodge implements Listener {
private final CoswayUtil plugin;
public PhantomDodge(CoswayUtil plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerAttack(EntityDamageByEntityEvent event) {
// Check if the entity being attacked is a player
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
// Check if player is sprinting and jumping
if (player.isSprinting() && player.isFlying() && isValidPlayerMove(player)) {
// Momentarily turn invisible
makeInvisible(player);
// Spawn the phantom version of the player
spawnPhantom(player);
// Prevent damage for a short period while the phantom is active
event.setCancelled(true);
}
}
}
// Check if player is jumping, indicating Phantom Dodge
private boolean isValidPlayerMove(Player player) {
return player.getVelocity().getY() > 0.2; // Check if the player is jumping (based on Y velocity)
}
// Make the player invisible for 1 second
private void makeInvisible(Player player) {
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 20, 1)); // 1 second of invisibility
}
// Spawn the phantom version of the player
private void spawnPhantom(Player player) {
Location playerLocation = player.getLocation();
Entity phantom = player.getWorld().spawnEntity(playerLocation, EntityType.PLAYER);
// Set phantom's name and appearance to confuse enemies (could customize more here)
phantom.setCustomName(player.getName() + " Phantom");
phantom.setCustomNameVisible(true);
phantom.setInvisible(true); // Make phantom invisible
// Phantom will despawn after 1 second
new BukkitRunnable() {
@Override
public void run() {
phantom.remove(); // Remove the phantom after 1 second
}
}.runTaskLater(plugin, 20); // Delay of 1 second (20 ticks)
}
}

View File

@ -0,0 +1,86 @@
package CoswayUtil;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class ShadowStep implements Listener {
private final CoswayUtil plugin;
public ShadowStep(CoswayUtil plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerUseEnderPearl(PlayerInteractEvent event) {
Player player = event.getPlayer();
// Check if player is sneaking and right-clicking with Ender Pearl
if (player.isSneaking() && event.getAction().toString().contains("RIGHT_CLICK") &&
player.getInventory().getItemInMainHand().getType() == Material.ENDER_PEARL) {
// Cancel the event to prevent the pearl from being thrown
event.setCancelled(true);
// Find the nearest enemy (Player or Hostile Mob)
Entity nearestEnemy = findNearestEnemy(player);
if (nearestEnemy != null) {
teleportBehindEnemy(player, nearestEnemy);
applyBlindnessEffect(nearestEnemy);
}
}
}
private Entity findNearestEnemy(Player player) {
Entity nearestEnemy = null;
double closestDistance = 10.0;
for (Entity entity : player.getWorld().getEntities()) {
if (entity != player && isHostile(entity)) {
double distance = player.getLocation().distance(entity.getLocation());
if (distance <= closestDistance) {
closestDistance = distance;
nearestEnemy = entity;
}
}
}
return nearestEnemy;
}
// Check if the entity is a hostile mob or player
private boolean isHostile(Entity entity) {
if (entity instanceof Player) {
return true; // Players are considered hostile for this mechanic
}
if (entity instanceof Monster) {
return true; // Check if the entity is a hostile mob (Monster subclass)
}
return false;
}
private void teleportBehindEnemy(Player player, Entity enemy) {
if (enemy == null) return;
Location enemyLocation = enemy.getLocation();
Vector direction = enemyLocation.getDirection().normalize();
Location teleportLocation = enemyLocation.subtract(direction.multiply(2)); // Teleport 2 blocks behind
player.teleport(teleportLocation);
}
private void applyBlindnessEffect(Entity enemy) {
if (enemy instanceof Player) {
Player targetPlayer = (Player) enemy;
targetPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1)); // 5 seconds of blindness
} else if (enemy instanceof LivingEntity) {
// If it's a mob, apply blindness
LivingEntity mob = (LivingEntity) enemy;
mob.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1)); // 5 seconds of blindness
}
}
}

View File

@ -0,0 +1,100 @@
package CoswayUtil;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityResurrectEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class TotemShield implements Listener {
private final JavaPlugin plugin;
private final Random random = new Random();
private static final double SAVE_CHANCE = 0.5; // 50% chance to not consume the Totem
private final Set<Player> shieldedPlayers = new HashSet<>();
private static final int SHIELD_DURATION = 100; // 5 seconds (100 ticks)
public TotemShield(JavaPlugin plugin) {
this.plugin = plugin;
Bukkit.getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
// Check if player is holding a totem
if (!hasTotem(player)) return;
if (shieldedPlayers.contains(player)) {
event.setCancelled(true); // Cancel damage if shield is active
return;
}
activateShield(player);
}
private boolean hasTotem(Player player) {
ItemStack offHand = player.getInventory().getItemInOffHand();
return offHand.getType() == Material.TOTEM_OF_UNDYING;
}
private void activateShield(Player player) {
shieldedPlayers.add(player);
player.getWorld().playSound(player.getLocation(), Sound.ITEM_TOTEM_USE, 1.0f, 1.0f);
player.getWorld().spawnParticle(Particle.TOTEM_OF_UNDYING, player.getLocation(), 50, 1, 1, 1);
new BukkitRunnable() {
@Override
public void run() {
shieldedPlayers.remove(player);
consumeTotem(player);
}
}.runTaskLater(plugin, SHIELD_DURATION);
}
private void consumeTotem(Player player) {
ItemStack offHand = player.getInventory().getItemInOffHand();
if (random.nextDouble() < SAVE_CHANCE) {
player.sendMessage("§6Your Totem activated, but was not consumed!");
} else {
if (offHand.getType() == Material.TOTEM_OF_UNDYING) {
offHand.setAmount(offHand.getAmount() - 1);
player.sendMessage("§6Your Totem activated, and was consumed!");
}
}
}
@EventHandler
public void onTotemUse(EntityResurrectEvent event) {
if (!(event.getEntity() instanceof Player player)) {
return; // Ensure it's a player using the Totem
}
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
return; // Do nothing for creative/spectator mode
}
// Random chance to prevent Totem consumption
if (random.nextDouble() < SAVE_CHANCE) {
event.setCancelled(true); // Prevents the Totem from being consumed
player.setHealth(Math.min(player.getMaxHealth(), 10.0)); // Revives with half HP
player.getWorld().playSound(player.getLocation(), Sound.ITEM_TOTEM_USE, 1.0f, 1.0f);
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_BEACON_ACTIVATE, 1.5f, 0.5f);
player.getWorld().spawnParticle(Particle.TOTEM_OF_UNDYING, player.getLocation(), 50);
player.sendMessage("§6Your Totem activated, but was not consumed!");
} else {
player.sendMessage("§cYour Totem was consumed as usual.");
}
}
}