142 lines
4.6 KiB
Java
142 lines
4.6 KiB
Java
package dev.zxq5.fantasysmp.items.gear;
|
|
|
|
import dev.zxq5.fantasysmp.items.GenericGearSet;
|
|
import dev.zxq5.fantasysmp.util.LoreChecker;
|
|
import java.util.ArrayList;
|
|
import java.util.Objects;
|
|
import org.bukkit.*;
|
|
import org.bukkit.block.Block;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.block.Action;
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
import org.bukkit.inventory.*;
|
|
import org.bukkit.util.Vector;
|
|
|
|
public class EnderGear extends GenericGearSet implements CommandExecutor {
|
|
|
|
private ArrayList<Player> cooldown = new ArrayList<>();
|
|
|
|
@Override
|
|
public boolean onCommand(
|
|
org.bukkit.command.CommandSender sender,
|
|
org.bukkit.command.Command command,
|
|
String label,
|
|
String[] args
|
|
) {
|
|
Player player = (Player) sender;
|
|
player.getInventory().addItem(this.getSword());
|
|
player.getInventory().addItem(this.getHelmet());
|
|
player.getInventory().addItem(this.getChestplate());
|
|
player.getInventory().addItem(this.getLeggings());
|
|
player.getInventory().addItem(this.getBoots());
|
|
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void registerRecipes() {}
|
|
|
|
@EventHandler
|
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
Player player = event.getPlayer();
|
|
ItemStack item = event.getItem(); // Get the item the player interacted with
|
|
|
|
if (
|
|
!(event.getAction() == Action.RIGHT_CLICK_AIR ||
|
|
event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
|
) {
|
|
return;
|
|
}
|
|
|
|
if (!(LoreChecker.itemLoreContains(item, this.sword.lore))) return;
|
|
if (cooldown.contains(player)) return;
|
|
|
|
Location old_location = player.getLocation();
|
|
World world = player.getWorld();
|
|
// find nearest block in that direction
|
|
|
|
Block block = player.getTargetBlock(null, 64);
|
|
|
|
if (
|
|
block.getType() == Material.AIR ||
|
|
block.getType() == Material.CAVE_AIR
|
|
) {
|
|
return;
|
|
}
|
|
|
|
player.playSound(
|
|
old_location,
|
|
Sound.ENTITY_ENDERMAN_TELEPORT,
|
|
1.0f,
|
|
1.0f
|
|
);
|
|
world.spawnParticle(Particle.PORTAL, old_location, 100);
|
|
|
|
Location new_location = block.getLocation();
|
|
new_location.setPitch(old_location.getPitch());
|
|
new_location.setYaw(old_location.getYaw());
|
|
player.setVelocity(
|
|
new Vector(
|
|
player.getVelocity().getX(),
|
|
0,
|
|
player.getVelocity().getZ()
|
|
)
|
|
);
|
|
player.teleport(new_location);
|
|
|
|
player.playSound(
|
|
new_location,
|
|
Sound.ENTITY_ENDERMAN_TELEPORT,
|
|
1.0f,
|
|
1.0f
|
|
);
|
|
world.spawnParticle(Particle.PORTAL, new_location, 100);
|
|
|
|
cooldown.add(player);
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(
|
|
Objects.requireNonNull(
|
|
Bukkit.getPluginManager().getPlugin("fantasysmp")
|
|
),
|
|
() -> cooldown.remove(player),
|
|
25
|
|
);
|
|
}
|
|
|
|
public static void init() {}
|
|
|
|
public EnderGear() {
|
|
this.setTier4();
|
|
this.sword.name = ChatColor.DARK_AQUA + "Ender Sword" + ChatColor.RESET;
|
|
this.sword.customItemModel = "ender_sword";
|
|
|
|
this.helmet.name =
|
|
ChatColor.DARK_AQUA + "Ender Helmet" + ChatColor.RESET;
|
|
this.helmet.customItemModel = "ender_helmet";
|
|
this.helmet.customEquipmentModel = "ender";
|
|
|
|
this.chestplate.name =
|
|
ChatColor.DARK_AQUA + "Ender Chestplate" + ChatColor.RESET;
|
|
this.chestplate.customItemModel = "ender_chestplate";
|
|
this.chestplate.customEquipmentModel = "ender";
|
|
|
|
this.leggings.name =
|
|
ChatColor.DARK_AQUA + "Ender Leggings" + ChatColor.RESET;
|
|
this.leggings.customItemModel = "ender_leggings";
|
|
this.leggings.customEquipmentModel = "ender";
|
|
|
|
this.boots.name = ChatColor.DARK_AQUA + "Ender Boots" + ChatColor.RESET;
|
|
this.boots.customItemModel = "ender_boots";
|
|
this.boots.customEquipmentModel = "ender";
|
|
|
|
this.sword.lore = "A sword forged from the essence of ender pearls,";
|
|
this.helmet.lore = "A helmet forged from the essence of ender pearls,";
|
|
this.chestplate.lore =
|
|
"A chestplate forged from the essence of ender pearls,";
|
|
this.leggings.lore =
|
|
"Leggings forged from the essence of ender pearls,";
|
|
this.boots.lore = "Boots forged from the essence of ender pearls,";
|
|
}
|
|
}
|