diff --git a/pom.xml b/pom.xml
index 1f56ed3..123a918 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,6 +37,16 @@
CDTimeAPI
1.0
+
+ com.wasteofplastic.askyblock
+ AskyBlockAPI
+ 1.0.0
+
+
+ com.yaohun.nbtapi
+ NBT-API
+ 1.12.2
+
\ No newline at end of file
diff --git a/src/main/java/me/Demon/AskyBlockWarps/Data/WarpData.java b/src/main/java/me/Demon/AskyBlockWarps/Data/WarpData.java
new file mode 100644
index 0000000..7fc366c
--- /dev/null
+++ b/src/main/java/me/Demon/AskyBlockWarps/Data/WarpData.java
@@ -0,0 +1,77 @@
+package me.Demon.AskyBlockWarps.Data;
+
+import com.wasteofplastic.askyblock.ASkyBlockAPI;
+import com.wasteofplastic.askyblock.Island;
+import me.Demon.AskyBlockWarps.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.configuration.file.FileConfiguration;
+
+import java.util.HashMap;
+
+public class WarpData {
+
+ private String key;
+ private Location location;
+ private boolean locSwitch;
+ private Island island;
+
+ public WarpData(String key){
+ FileConfiguration yml = Main.plugin.getConfig();
+ this.key = key;
+ String string = "Stats."+key+".";
+ String worldName = yml.getString(string+"world");
+ World world = Bukkit.getWorld(worldName);
+ if(world==null){
+ System.out.println("[错误 - Sky坐标] "+key+"无法检测该世界.");
+ return;
+ }
+ double x = yml.getDouble(string+"x");
+ double y = yml.getDouble(string+"y");
+ double z = yml.getDouble(string+"z");
+ float yaw = (float) yml.getDouble(string+"yaw");
+ float pitch = (float) yml.getDouble(string+"pitch");
+ this.location = new Location(world,x,y,z,yaw,pitch);
+ this.island = ASkyBlockAPI.getInstance().getIslandAt(location);
+ this.locSwitch = yml.getBoolean(string+"switch");
+ }
+ public WarpData(String key,Location location){
+ this.key = key;
+ this.location = location;
+ this.locSwitch = true;
+ }
+
+ public void SaveData(){
+ FileConfiguration yml = Main.plugin.getConfig();
+ String string = "Stats."+key+".";
+ yml.set(string+"switch",this.locSwitch);
+ yml.set(string+"world",location.getWorld().getName());
+ yml.set(string+"x",location.getX());
+ yml.set(string+"y",location.getY());
+ yml.set(string+"z",location.getZ());
+ yml.set(string+"yaw",location.getYaw());
+ yml.set(string+"pitch",location.getPitch());
+ Main.plugin.saveConfig();
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
+ public boolean isLocSwitch() {
+ return locSwitch;
+ }
+
+ public Island getIsland() {
+ return island;
+ }
+}
diff --git a/src/main/java/me/Demon/AskyBlockWarps/Listener/LandTeamGui.java b/src/main/java/me/Demon/AskyBlockWarps/Listener/LandTeamGui.java
index 1454cae..94b6eac 100644
--- a/src/main/java/me/Demon/AskyBlockWarps/Listener/LandTeamGui.java
+++ b/src/main/java/me/Demon/AskyBlockWarps/Listener/LandTeamGui.java
@@ -24,7 +24,7 @@ public class LandTeamGui implements Listener {
e.setCancelled(true);
ItemStack item = e.getCurrentItem();
if (e.getRawSlot() >= 0 && e.getRawSlot() < e.getInventory().getSize() && !DemonAPI.itemIsNull(item) && !DemonAPI.itemIsLore(item)) {
- if (ASkyBlockAPI.getInstance().getOwner(p.getLocation()).equals(p.getUniqueId())) {
+ if (ASkyBlockAPI.getInstance().getIslandAt(p.getLocation()).equals(p.getUniqueId())) {
String playName = item.getItemMeta().getDisplayName().replace("§6§l成员 §e", "");
p.performCommand("is expel " + playName);
}
diff --git a/src/main/java/me/Demon/AskyBlockWarps/Listener/MainGui.java b/src/main/java/me/Demon/AskyBlockWarps/Listener/MainGui.java
index fc1c93a..8900bb3 100644
--- a/src/main/java/me/Demon/AskyBlockWarps/Listener/MainGui.java
+++ b/src/main/java/me/Demon/AskyBlockWarps/Listener/MainGui.java
@@ -3,6 +3,7 @@ package me.Demon.AskyBlockWarps.Listener;
import cn.hamster3.cdapi.CDTimeAPI;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
import me.Demon.AskyBlockWarps.Main;
+import me.Demon.AskyBlockWarps.Manage.GameManage;
import me.Demon.AskyBlockWarps.Util.itemUtil;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
@@ -23,11 +24,13 @@ public class MainGui implements Listener {
@EventHandler
public void onclick(InventoryClickEvent e) {
+ int rawSlot = e.getRawSlot();
+ Inventory inv = e.getInventory();
Player p = (Player) e.getWhoClicked();
- if (e.getInventory() != null && e.getInventory().getTitle().contains(invtitle)) {
+ String name = p.getName();
+ if (inv != null && inv.getTitle().contains(invtitle)) {
e.setCancelled(true);
- 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()) {
UUID islandOwner = ASkyBlockAPI.getInstance().getOwner(p.getLocation());
if (e.getRawSlot() == 1) {
p.performCommand("is");
@@ -38,7 +41,7 @@ public class MainGui implements Listener {
if (e.getRawSlot() == 3) {
if (islandOwner != null && islandOwner.equals(p.getUniqueId())) {
if (CDTimeAPI.getCD(p.getUniqueId(), "islandsetwarp") < 0) {
- SetLocation("Stats." + p.getName(), p.getLocation());
+ Main.gameManage.setWarpLoc(name,p.getLocation());
p.sendMessage(Main.prefix + "设置空岛地标点成功.");
CDTimeAPI.setPlayerCD(p.getUniqueId(), "islandsetwarp", 1000 * 3);
p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F, 2.0F);
diff --git a/src/main/java/me/Demon/AskyBlockWarps/Listener/WarpGui.java b/src/main/java/me/Demon/AskyBlockWarps/Listener/WarpGui.java
index 815abfb..c1a8ee9 100644
--- a/src/main/java/me/Demon/AskyBlockWarps/Listener/WarpGui.java
+++ b/src/main/java/me/Demon/AskyBlockWarps/Listener/WarpGui.java
@@ -2,10 +2,13 @@ package me.Demon.AskyBlockWarps.Listener;
import cn.hamster3.cdapi.CDTimeAPI;
import com.wasteofplastic.askyblock.ASkyBlockAPI;
+import com.wasteofplastic.askyblock.Island;
+import me.Demon.AskyBlockWarps.Data.WarpData;
import me.Demon.AskyBlockWarps.Main;
import me.Demon.AskyBlockWarps.Util.itemUtil;
import me.Demon.DemonPlugin.DemonAPI;
import org.bukkit.Bukkit;
+import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -13,7 +16,11 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.UUID;
public class WarpGui implements Listener {
@@ -43,10 +50,25 @@ public class WarpGui implements Listener {
public static void Opengui(Player p) {
Inventory inv = Bukkit.createInventory(null, 54, invtitle);
- for (String warpName : Main.plugin.getConfig().getConfigurationSection("Stats").getKeys(false)) {
- inv.addItem(itemUtil.warpShow(warpName));
+ HashMap warpDataHashMap = Main.gameManage.getWarpDataMap();
+ for (String key : warpDataHashMap.keySet()){
+ WarpData warpData = warpDataHashMap.get(key);
+ inv.addItem(warpShow(warpData));
}
-
p.openInventory(inv);
}
+
+ public static ItemStack warpShow(WarpData wData) {
+ ItemStack item = new ItemStack(Material.SIGN);
+ ItemMeta meta = item.getItemMeta();
+ meta.setDisplayName("§6§l传送到 §e" + wData.getKey() + " §6§l的空岛");
+ List lore = new ArrayList<>();
+ Island island = wData.getIsland();
+ lore.add(" §7岛屿等级: §f"+island.getLevelHandicap());
+ lore.add("§r");
+ lore.add("§6▸ §e点击传送");
+ meta.setLore(lore);
+ item.setItemMeta(meta);
+ return item;
+ }
}
diff --git a/src/main/java/me/Demon/AskyBlockWarps/Main.java b/src/main/java/me/Demon/AskyBlockWarps/Main.java
index 027dd68..f21099c 100644
--- a/src/main/java/me/Demon/AskyBlockWarps/Main.java
+++ b/src/main/java/me/Demon/AskyBlockWarps/Main.java
@@ -5,6 +5,7 @@ import me.Demon.AskyBlockWarps.Listener.LandInviteGui;
import me.Demon.AskyBlockWarps.Listener.LandTeamGui;
import me.Demon.AskyBlockWarps.Listener.MainGui;
import me.Demon.AskyBlockWarps.Listener.WarpGui;
+import me.Demon.AskyBlockWarps.Manage.GameManage;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
@@ -16,10 +17,12 @@ import java.util.UUID;
public class Main extends JavaPlugin {
public static Main plugin;
public static String prefix = "§7[§6帝国战争§7] §f";
+ public static GameManage gameManage;
@Override
public void onEnable() {
plugin = this;
+ gameManage = new GameManage(getConfig());
saveDefaultConfig();
Bukkit.getServer().getPluginManager().registerEvents(new MainGui(), plugin);
Bukkit.getServer().getPluginManager().registerEvents(new WarpGui(), plugin);
diff --git a/src/main/java/me/Demon/AskyBlockWarps/Manage/GameManage.java b/src/main/java/me/Demon/AskyBlockWarps/Manage/GameManage.java
new file mode 100644
index 0000000..195e93a
--- /dev/null
+++ b/src/main/java/me/Demon/AskyBlockWarps/Manage/GameManage.java
@@ -0,0 +1,72 @@
+package me.Demon.AskyBlockWarps.Manage;
+
+import me.Demon.AskyBlockWarps.Data.WarpData;
+import me.Demon.AskyBlockWarps.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.configuration.file.FileConfiguration;
+
+import java.util.HashMap;
+
+public class GameManage {
+
+ private FileConfiguration yml;
+ private HashMap warpDataMap = new HashMap<>();
+
+ public GameManage(FileConfiguration yml){
+ this.yml = yml;
+ if(yml.getConfigurationSection("Stats") == null){
+ yml.createSection("Stats");
+ }
+ for (String key : yml.getConfigurationSection("Stats").getKeys(false)){
+ warpDataMap.put(key,new WarpData(key));
+ }
+ Bukkit.getConsoleSender().sendMessage("[载入岛屿地标] "+warpDataMap.size()+"个");
+ }
+
+ public HashMap getWarpDataMap() {
+ return warpDataMap;
+ }
+
+ public WarpData getWarpData(String key){
+ if(warpDataMap.get(key) == null){
+ return null;
+ }
+ return warpDataMap.get(key);
+ }
+
+ public void setWarpLoc(String key,Location location){
+ if(warpDataMap.get(key) == null){
+ warpDataMap.put(key,new WarpData(key,location));
+ warpDataMap.get(key).SaveData();
+ }else{
+ warpDataMap.get(key).setLocation(location);
+ warpDataMap.get(key).SaveData();
+ }
+ }
+
+ public void removeWarpLoc(String key){
+ if(warpDataMap.get(key) == null){
+ return;
+ }
+ warpDataMap.remove(key);
+ yml.set("Stats."+key,null);
+ Main.plugin.saveConfig();
+ }
+
+ // 获取这个传送点是否开启
+ public boolean getWarpSwitch(String key){
+ if(warpDataMap.get(key) == null){
+ return false;
+ }
+ return warpDataMap.get(key).isLocSwitch();
+ }
+
+ // 获取这个坐标点的坐标
+ public Location getWarpLoc(String key){
+ if(warpDataMap.get(key) == null){
+ return null;
+ }
+ return warpDataMap.get(key).getLocation();
+ }
+}