This commit is contained in:
yaohunya 2024-08-07 23:54:34 +08:00
parent f5ce425677
commit 0d0a662ef8

View File

@ -3,11 +3,13 @@ package me.Demon.AskyBlockWarps.Listener;
import cn.hamster3.cdapi.CDTimeAPI; import cn.hamster3.cdapi.CDTimeAPI;
import com.wasteofplastic.askyblock.ASkyBlockAPI; import com.wasteofplastic.askyblock.ASkyBlockAPI;
import com.wasteofplastic.askyblock.Island; import com.wasteofplastic.askyblock.Island;
import de.tr7zw.itemnbtapi.NBTItem;
import me.Demon.AskyBlockWarps.Data.WarpData; import me.Demon.AskyBlockWarps.Data.WarpData;
import me.Demon.AskyBlockWarps.Main; import me.Demon.AskyBlockWarps.Main;
import me.Demon.AskyBlockWarps.Util.itemUtil; import me.Demon.AskyBlockWarps.Util.itemUtil;
import me.Demon.DemonPlugin.DemonAPI; import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -28,22 +30,24 @@ public class WarpGui implements Listener {
@EventHandler @EventHandler
public void onclick(InventoryClickEvent e) { public void onclick(InventoryClickEvent e) {
int rawSlot = e.getRawSlot();
Inventory inv = e.getInventory();
Player p = (Player) e.getWhoClicked(); Player p = (Player) e.getWhoClicked();
String name = p.getName();
if (e.getInventory() != null && e.getInventory().getTitle().contains(invtitle)) { if (e.getInventory() != null && e.getInventory().getTitle().contains(invtitle)) {
e.setCancelled(true); e.setCancelled(true);
ItemStack item = e.getCurrentItem(); ItemStack item = e.getCurrentItem();
if (e.getRawSlot() >= 0 && e.getRawSlot() < e.getInventory().getSize() && !DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)) { if (rawSlot >= 0 && rawSlot < inv.getSize()) {
if (CDTimeAPI.getCD(p.getUniqueId(), "islandwarptp") < 0) { if(DemonAPI.itemIsNull(item)){return;}
String playName = item.getItemMeta().getDisplayName().replace("§6§l传送到 §e", "").replace(" §6§l的空岛",""); p.closeInventory();
UUID islandOwner = ASkyBlockAPI.getInstance().getOwner(p.getLocation()); p.playSound(p.getLocation(),Sound.BLOCK_COMPARATOR_CLICK,1,1);
p.teleport(Main.LandWarpLoc(playName)); NBTItem nbtItem = new NBTItem(item);
p.sendMessage(Main.prefix + "您已传送至 §e" + Main.convertUUIDToName(islandOwner) + "§f 的空岛地标旁."); if(nbtItem.hasKey("warpKey")){
CDTimeAPI.setPlayerCD(p.getUniqueId(), "islandwarptp", 1000 * 3); String warpKey = nbtItem.getString("warpKey");
p.playSound(p.getLocation(), Sound.ENTITY_ENDEREYE_DEATH, 1.0F, 2.0F); WarpData warpData = Main.gameManage.getWarpData(warpKey);
p.closeInventory(); Location location = warpData.getLocation().add(0,0.5,0);
} else { p.teleport(location);
p.sendMessage(Main.prefix + "空岛地标传送冷却中..."); p.sendMessage(Main.prefix + "您已传送至 §e" + warpKey + "§f 的空岛地标旁.");
p.closeInventory();
} }
} }
} }
@ -70,6 +74,8 @@ public class WarpGui implements Listener {
lore.add("§6▸ §e点击传送"); lore.add("§6▸ §e点击传送");
meta.setLore(lore); meta.setLore(lore);
item.setItemMeta(meta); item.setItemMeta(meta);
return item; NBTItem nbtItem = new NBTItem(item);
nbtItem.setString("warpKey",wData.getKey());
return nbtItem.getItem();
} }
} }