fixed team warps. still need to document what works and what doesn't.

probably a job for tomorrow
This commit is contained in:
2025-09-06 23:18:22 +01:00
parent b56a3c8218
commit 3ca436b7e4
11 changed files with 600 additions and 316 deletions
+37
View File
@@ -0,0 +1,37 @@
// Project tasks configuration. See https://zed.dev/docs/tasks for documentation.
[
{
"label": "Maven Compile",
"command": "mvn",
"args": ["compile"],
"shell": "system",
"use_new_terminal": false
},
{
"label": "Maven Clean Package",
"command": "mvn",
"args": ["clean", "package"],
"shell": "system",
"use_new_terminal": false
},
{
"label": "Maven Test",
"command": "mvn",
"args": ["test"],
"shell": "system",
"use_new_terminal": false
},
{
"label": "Run Project",
"command": "./run.sh",
"shell": "system",
"use_new_terminal": false
},
{
"label": "Maven Package (Skip Tests)",
"command": "mvn",
"args": ["clean", "package", "-DskipTests"],
"shell": "system",
"use_new_terminal": false
}
]
Executable
+4
View File
@@ -0,0 +1,4 @@
mkdir -p ./run/plugins/
cp ./target/fantasysmp*.jar run/plugins/fantasysmp.jar
cd run/
java -jar ./paper.jar nogui
@@ -3,7 +3,6 @@ package dev.zxq5.fantasysmp.events;
import org.bukkit.*;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -11,7 +10,6 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -1,6 +1,20 @@
package dev.zxq5.fantasysmp.events;
import static org.bukkit.Bukkit.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -9,34 +23,23 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.Plugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import static org.bukkit.Bukkit.*;
public class XrayDetector implements Listener {
private final HashMap<Player, HashMap<Material, Integer>> players = new HashMap<>();
private final HashMap<Player, HashMap<Material, Integer>> players =
new HashMap<>();
private String token;
private final ArrayList<Material> trackedBlocks = new ArrayList<>(Arrays.asList(
Material.ANCIENT_DEBRIS,
Material.DIAMOND_ORE,
Material.EMERALD_ORE,
Material.GOLD_ORE,
Material.IRON_ORE,
Material.LAPIS_ORE,
Material.REDSTONE_ORE
));
private final ArrayList<Material> trackedBlocks = new ArrayList<>(
Arrays.asList(
Material.ANCIENT_DEBRIS,
Material.DIAMOND_ORE,
Material.EMERALD_ORE,
Material.GOLD_ORE,
Material.IRON_ORE,
Material.LAPIS_ORE,
Material.REDSTONE_ORE
)
);
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
@@ -45,46 +48,67 @@ public class XrayDetector implements Listener {
Material block = event.getBlock().getType();
Plugin plugin = getPluginManager().getPlugin("fantasysmp");
if (!this.players.containsKey(player)) this.players.put(player, new HashMap<>());
if (!this.players.containsKey(player)) this.players.put(
player,
new HashMap<>()
);
blocks = this.players.get(player);
if (this.trackedBlocks.contains(block)) {
if (!(blocks.containsKey(block))) blocks.put(block, 0);
blocks.put(block, blocks.get(block) + 1);
Bukkit.getScheduler().runTaskLater(plugin, () -> {
blocks.put(block, blocks.get(block) - 1);
}, 1200);
Bukkit.getScheduler().runTaskLater(
plugin,
() -> {
blocks.put(block, blocks.get(block) - 1);
},
1200
);
}
}
private void uploadData() {
HashMap<String, HashMap<String, Integer>> data = new HashMap<>();
for (Map.Entry<Player, HashMap<Material, Integer>> entry : players.entrySet()) {
for (Map.Entry<
Player,
HashMap<Material, Integer>
> entry : players.entrySet()) {
HashMap<String, Integer> materials = new HashMap<>();
for (Map.Entry<Material, Integer> materialEntry : entry.getValue().entrySet()) {
materials.put(materialEntry.getKey().toString(), materialEntry.getValue());
for (Map.Entry<Material, Integer> materialEntry : entry
.getValue()
.entrySet()) {
materials.put(
materialEntry.getKey().toString(),
materialEntry.getValue()
);
}
data.put(entry.getKey().getName(), materials);
}
Gson gson = new Gson();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://mcapi.zxq5.dev/xray?token=" + token))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(data)))
.build();
HttpRequest request = HttpRequest.newBuilder(
URI.create("https://mcapi.zxq5.dev/xray?token=" + token)
)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(data)))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.join();
client
.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.join();
}
public XrayDetector() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, "token.txt");
BufferedReader reader;
@@ -96,29 +120,11 @@ public class XrayDetector implements Listener {
return;
}
Bukkit.getScheduler().runTaskTimerAsynchronously(getPluginManager().getPlugin("fantasysmp"), this::uploadData, 0, 20 * 60);
Bukkit.getScheduler().runTaskTimerAsynchronously(
getPluginManager().getPlugin("fantasysmp"),
this::uploadData,
0,
20 * 60
);
}
}
@@ -3,13 +3,10 @@ package dev.zxq5.fantasysmp.groups;
import dev.zxq5.fantasysmp.chatutils.Chat;
import dev.zxq5.fantasysmp.warps.Warp;
import dev.zxq5.fantasysmp.warps.WarpType;
import java.util.ArrayList;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import static org.bukkit.Bukkit.getServer;
/*
* Commands:
*
@@ -41,7 +38,12 @@ import static org.bukkit.Bukkit.getServer;
public class Commands implements CommandExecutor {
@Override
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
public boolean onCommand(
org.bukkit.command.CommandSender sender,
org.bukkit.command.Command command,
String label,
String[] args
) {
if (!(sender instanceof Player player)) return false;
if (command.getName().equals("team")) handleTeamCommands(player, args);
@@ -72,7 +74,10 @@ public class Commands implements CommandExecutor {
public void handleRankCommands(Player player, String[] args) {
// check perms
if (!(player.hasPermission("fantasysmp.ranks"))) {
Chat.error(player, "You do not have permission to use this command.");
Chat.error(
player,
"You do not have permission to use this command."
);
return;
}
@@ -87,167 +92,182 @@ public class Commands implements CommandExecutor {
public void handleList(Player player, String[] args) {
String[] teams = Team.getTeams();
String result = "Teams: [\n " + String.join("\n ", teams) + "\n]";
Chat.info(player, result);
Chat.info(player, String.join(" ", teams));
}
public void handleCreate(Player player, String[] args) {
public void handleCreate(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team create <name>");
Chat.error(caller, "Usage: /team create <name>");
return;
}
Team.createTeam(player, args[1]);
Team.createTeam(caller, args[1]);
Chat.success(caller, "Created team " + args[1] + "!");
}
public void handleSetColour(Player player, String[] args) {
public void handleSetColour(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team colour <color>");
Chat.error(caller, "Usage: /team colour <color>");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
team.setColour(player, args[1]);
team.setColour(caller, args[1]);
Chat.success(caller, "Set colour to " + args[1] + "!");
}
public void handleRename(Player player, String[] args) {
public void handleRename(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team rename <new name>");
Chat.error(caller, "Usage: /team rename <new name>");
return;
}
if (args[1].isEmpty() || args[1].contains(" ") || args[1].contains("\t")) {
Chat.error(player, "Invalid name!");
if (
args[1].isEmpty() || args[1].contains(" ") || args[1].contains("\t")
) {
Chat.error(caller, "Invalid name!");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
team.renameTeam(player, args[1]);
team.renameTeam(caller, args[1]);
Chat.success(caller, "Renamed team to " + args[1] + "!");
}
public void handleSetTag(Player player, String[] args) {
public void handleSetTag(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team tag <tag>");
Chat.error(caller, "Usage: /team tag <tag>");
return;
}
if (args[1].length() < 3 || args[1].contains(" ") || args[1].contains("\t") || args[1].length() > 8) {
Chat.error(player, "Invalid tag!");
Chat.error(player, "tags should be 3-8 chars, alphanumeric and have no spaces");
if (
args[1].length() < 3 ||
args[1].contains(" ") ||
args[1].contains("\t") ||
args[1].length() > 8
) {
Chat.error(caller, "Invalid tag!");
Chat.error(
caller,
"tags should be 3-8 chars, alphanumeric and have no spaces"
);
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
team.changeTeamTag(player, args[1]);
team.changeTeamTag(caller, args[1]);
Chat.success(caller, "Changed tag to " + args[1] + "!");
}
public void handleTransfer(Player player, String[] args) {
public void handleTransfer(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team transfer <player>");
Chat.error(caller, "Usage: /team transfer <player>");
return;
}
// Chat.success(caller, "Transferred ownership to: " + args[1] + "!");
}
public void handleJoin(Player player, String[] args) {
public void handleJoin(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team join <name>");
Chat.error(caller, "Usage: /team join <name>");
return;
}
// Chat.success(caller, "Joined team: " + args[1] + "!");
}
public void handleInvite(Player player, String[] args) {
public void handleInvite(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team invite <player>");
Chat.error(caller, "Usage: /team invite <player>");
return;
}
// Chat.success(caller, "Changed tag to: " + args[1] + "!");
}
public void handleLeave(Player player, String[] args) {
public void handleLeave(Player caller, String[] args) {
if (args.length != 1) {
Chat.error(player, "Usage: /team leave");
Chat.error(caller, "Usage: /team leave");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
team.leaveTeam(player);
team.leaveTeam(caller);
}
public void handleDisband(Player player, String[] args) {
public void handleDisband(Player caller, String[] args) {
if (args.length != 1) {
Chat.error(player, "Usage: /team disband");
Chat.error(caller, "Usage: /team disband");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
team.disbandTeam(player);
team.disbandTeam(caller);
}
public void handleSetWarp(Player player, String[] args) {
public void handleSetWarp(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team setwarp <name>");
Chat.error(caller, "Usage: /team setwarp <name>");
return;
}
Warp.setWarp(args[1], player, WarpType.TEAM);
Warp.setWarp(args[1], caller, WarpType.TEAM);
}
public void handleDelWarp(Player player, String[] args) {
public void handleDelWarp(Player caller, String[] args) {}
}
public void handleWarp(Player player, String[] args) {
public void handleWarp(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team warp <name>");
Chat.error(caller, "Usage: /team warp <name>");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
Warp warp = Warp.getTeamWarp(team, args[1]);
Warp warp = Warp.getTeamWarp(team, caller, args[1]);
warp.execute(caller);
}
public void handleKick(Player player, String[] args) {
public void handleKick(Player caller, String[] args) {
if (args.length != 2) {
Chat.error(player, "Usage: /team kick <player>");
Chat.error(caller, "Usage: /team kick <player>");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
team.removePlayer(player, args[1]);
team.removePlayer(caller, args[1]);
}
public void handleLog(Player player, String[] args) {
public void handleLog(Player caller, String[] args) {
if (args.length != 1) {
Chat.error(player, "Usage: /team log");
Chat.error(caller, "Usage: /team log");
return;
}
Team team = Team.fromMember(player);
Team team = Team.fromMember(caller);
if (team == null) return;
ArrayList<String> logs = team.getLogs(player);
ArrayList<String> logs = team.getLogs(caller);
String result = "Logs: [\n " + String.join("\n ", logs) + "\n]";
Chat.info(player, result);
Chat.info(caller, result);
}
public void handleCreateRank(Player player, String[] args) {}
public void handleCreateRank(Player caller, String[] args) {}
public void handleRenameRank(Player player, String[] args) {}
public void handleRenameRank(Player caller, String[] args) {}
public void handleDeleteRank(Player player, String[] args) {}
public void handleDeleteRank(Player caller, String[] args) {}
public void handleAddRank(Player player, String[] args) {}
public void handleAddRank(Player caller, String[] args) {}
public void handleRemoveRank(Player player, String[] args) {}
public void handleRemoveRank(Player caller, String[] args) {}
public Commands() {}
}
@@ -1,25 +1,27 @@
package dev.zxq5.fantasysmp.groups;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import dev.zxq5.fantasysmp.chatutils.Chat;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.io.*;
import java.util.ArrayList;
import java.util.UUID;
import static org.bukkit.Bukkit.broadcastMessage;
import static org.bukkit.Bukkit.getServer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import dev.zxq5.fantasysmp.chatutils.Chat;
import java.io.*;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class Team {
private static ArrayList<Team> teams;
private final static String FILENAME = "teams.json";
private static final String FILENAME = "teams.json";
private String name;
private String ownerUUID;
private ArrayList<String> members;
private ArrayList<String> invites;
private ArrayList<String> logs;
private String teamUUID;
private String tag;
@@ -50,7 +52,9 @@ public class Team {
public static Team fromMember(Player member) {
for (Team team : teams) {
if (team.members.contains(member.getUniqueId().toString())) return team;
if (
team.members.contains(member.getUniqueId().toString())
) return team;
}
Team.error(member, Error.TEAM_NOT_FOUND);
@@ -87,10 +91,13 @@ public class Team {
this.tag = newTag;
this.log(player.getName() + " changed the team tag to " + newTag + ".");
Chat.success(player, "You changed the tag of " + this.name + " to " + newTag + ".");
Chat.success(
player,
"You changed the tag of " + this.name + " to " + newTag + "."
);
}
public void setColour (Player player, String colour) {
public void setColour(Player player, String colour) {
if (!this.ownerUUID.equals(player.getUniqueId().toString())) {
Team.error(player, Error.NO_PERMISSION);
return;
@@ -114,8 +121,13 @@ public class Team {
case "black" -> this.tag = ChatColor.BLACK + this.tag;
}
this.log(player.getName() + " changed the team colour to " + colour + ".");
Chat.success(player, "You changed the colour of " + this.name + " to " + colour + ".");
this.log(
player.getName() + " changed the team colour to " + colour + "."
);
Chat.success(
player,
"You changed the colour of " + this.name + " to " + colour + "."
);
}
public void transferTeam(Player player, String playerName) {
@@ -137,9 +149,21 @@ public class Team {
}
this.ownerUUID = newUUID;
this.log(player.getName() + " transferred ownership to " + newOwner.getName() + ".");
this.log(
player.getName() +
" transferred ownership to " +
newOwner.getName() +
"."
);
Chat.success(player, "You transferred ownership of " + this.name + " to " + newOwner.getName() + ".");
Chat.success(
player,
"You transferred ownership of " +
this.name +
" to " +
newOwner.getName() +
"."
);
}
public void removePlayer(Player remover, String playerName) {
@@ -169,9 +193,21 @@ public class Team {
}
this.members.remove(removedPlayerUUID);
this.log(remover.getName() + " removed " + removedPlayer.getName() + " from the team.");
this.log(
remover.getName() +
" removed " +
removedPlayer.getName() +
" from the team."
);
Chat.success(remover, "You removed " + removedPlayer.getName() + " from " + this.name + ".");
Chat.success(
remover,
"You removed " +
removedPlayer.getName() +
" from " +
this.name +
"."
);
}
public void leaveTeam(Player member) {
@@ -211,7 +247,9 @@ public class Team {
}
public ArrayList<String> getLogs(Player member) {
if (this.ownerUUID.equals(member.getUniqueId().toString())) return this.logs;
if (
this.ownerUUID.equals(member.getUniqueId().toString())
) return this.logs;
Team.error(member, Error.NO_PERMISSION);
return null;
@@ -223,7 +261,10 @@ public class Team {
}
public static void loadTeams() throws Exception {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME);
if (!file.exists()) {
@@ -233,17 +274,23 @@ public class Team {
BufferedReader reader;
reader = new BufferedReader(new FileReader(file));
Gson gson = new Gson();
teams = gson.fromJson(reader, new TypeToken<ArrayList<Team>>(){}.getType());
Gson gson = new GsonBuilder().setPrettyPrinting().create();
teams = gson.fromJson(
reader,
new TypeToken<ArrayList<Team>>() {}.getType()
);
reader.close();
}
public static void saveTeams() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME);
Gson gson = new Gson();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(teams);
try {
@@ -257,13 +304,16 @@ public class Team {
}
public static void createTeamsFile() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME);
if (!file.exists()) {
try {
Team[] t = new Team[0];
Gson gson = new Gson();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(t);
Writer writer = new FileWriter(file);
writer.write(json);
@@ -274,6 +324,15 @@ public class Team {
}
}
// utility methods
public boolean hasMember(Player player) {
for (String uuid : this.members) {
if (player.getUniqueId().toString() == uuid) return true;
}
return false;
}
public String getUUID() {
return this.teamUUID;
}
@@ -283,16 +342,19 @@ public class Team {
}
public static void error(Player player, Error error) {
Chat.error(player, switch (error) {
case NO_PERMISSION -> "You do not have permission to do that!";
case SELF_IN_TEAM -> "You are already in a team!";
case NOT_IN_TEAM -> "You are not in a team!";
case TEAM_NOT_FOUND -> "Team not found!";
case PLAYER_NOT_FOUND -> "Player not found!";
case ALREADY_TAKEN -> "That name is already taken!";
case PLAYER_IN_TEAM -> "That player is already in a team!";
case TEAM_OWNER -> "You cannot do this to/as the owner!";
});
Chat.error(
player,
switch (error) {
case NO_PERMISSION -> "You do not have permission to do that!";
case SELF_IN_TEAM -> "You are already in a team!";
case NOT_IN_TEAM -> "You are not in a team!";
case TEAM_NOT_FOUND -> "Team not found!";
case PLAYER_NOT_FOUND -> "Player not found!";
case ALREADY_TAKEN -> "That name is already taken!";
case PLAYER_IN_TEAM -> "That player is already in a team!";
case TEAM_OWNER -> "You cannot do this to/as the owner!";
}
);
}
}
@@ -305,4 +367,4 @@ enum Error {
PLAYER_NOT_FOUND,
ALREADY_TAKEN,
PLAYER_IN_TEAM,
}
}
@@ -5,8 +5,6 @@ import dev.zxq5.fantasysmp.util.LoreChecker;
import org.bukkit.*;
import org.bukkit.command.CommandExecutor;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.SmallFireball;
import org.bukkit.event.EventHandler;
@@ -15,16 +13,10 @@ import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.SmithingTransformRecipe;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static org.bukkit.Bukkit.*;
@@ -1,40 +1,37 @@
package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.broadcastMessage;
import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.items.ItemStats;
import dev.zxq5.fantasysmp.util.LoreChecker;
import java.util.ArrayList;
import java.util.Objects;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.command.CommandExecutor;
import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.components.EquippableComponent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
public class DragonGear
extends GenericGearSet
implements Listener, CommandExecutor {
import static org.bukkit.Bukkit.broadcastMessage;
import static org.bukkit.Bukkit.getServer;
public class DragonGear extends GenericGearSet implements Listener, 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) {
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());
@@ -49,7 +46,9 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
public void registerRecipes() {}
@EventHandler
public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) {
public void onEntityPotionEffectEvent(
org.bukkit.event.entity.EntityPotionEffectEvent event
) {
if (event.getEntity() instanceof Player player) {
if (event.getNewEffect() == null) return;
@@ -58,10 +57,23 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
}
try {
if (LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore)
if (
LoreChecker.itemLoreContains(
player.getInventory().getHelmet(),
this.helmet.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getChestplate(),
this.chestplate.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getLeggings(),
this.leggings.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getBoots(),
this.boots.lore
)
) {
event.setCancelled(true);
}
@@ -72,27 +84,54 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
}
@EventHandler
public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event) {
public void onEntityDamage(
org.bukkit.event.entity.EntityDamageEvent event
) {
// check if fall damage
if (!(event.getEntity() instanceof Player player)) return;
if (!(LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore)
)) return;
if (!(event.getDamageSource().getDamageType() == DamageType.FLY_INTO_WALL)) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getHelmet(),
this.helmet.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getChestplate(),
this.chestplate.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getLeggings(),
this.leggings.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getBoots(),
this.boots.lore
))
) return;
if (
!(event.getDamageSource().getDamageType() ==
DamageType.FLY_INTO_WALL)
) return;
event.setCancelled(true);
}
@EventHandler
public void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
public void onEntityDamageByEntity(
org.bukkit.event.entity.EntityDamageByEntityEvent event
) {
if (!(event.getDamager() instanceof Player player)) return;
if (!(LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore))) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getItemInMainHand(),
this.sword.lore
))
) return;
if (!(player.isFlying() || player.isGliding())) return;
double baseDamage = event.getDamage();
double newDamage = baseDamage * Math.min(Math.max(player.getVelocity().length(), 1.0), 2.0);
double newDamage =
baseDamage *
Math.min(Math.max(player.getVelocity().length(), 1.0), 2.0);
broadcastMessage("damage " + baseDamage);
broadcastMessage("velocity " + player.getVelocity().length());
@@ -106,7 +145,10 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
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)) {
if (
!(event.getAction() == Action.RIGHT_CLICK_AIR ||
event.getAction() == Action.RIGHT_CLICK_BLOCK)
) {
return;
}
@@ -123,15 +165,17 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
cooldown.add(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(
Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")),
() -> cooldown.remove(player),
25
Objects.requireNonNull(
Bukkit.getPluginManager().getPlugin("fantasysmp")
),
() -> cooldown.remove(player),
25
);
}
@Override
public ItemStack getHelmet() {
// helmet.setMaterial(Material.DRAGON_HEAD);
// helmet.setMaterial(Material.DRAGON_HEAD);
return super.getHelmet();
}
@@ -147,22 +191,27 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
public DragonGear() {
this.setTier5();
this.sword.name = ChatColor.DARK_PURPLE + "Dragon Sword" + ChatColor.RESET;
this.sword.name =
ChatColor.DARK_PURPLE + "Dragon Sword" + ChatColor.RESET;
this.sword.customItemModel = "dragon_sword";
this.helmet.name = ChatColor.DARK_PURPLE + "Dragon Helmet" + ChatColor.RESET;
this.helmet.name =
ChatColor.DARK_PURPLE + "Dragon Helmet" + ChatColor.RESET;
this.helmet.customItemModel = "dragon_helmet";
this.helmet.customEquipmentModel = "dragon";
this.chestplate.name = ChatColor.DARK_PURPLE + "Dragon Chestplate" + ChatColor.RESET;
this.chestplate.name =
ChatColor.DARK_PURPLE + "Dragon Chestplate" + ChatColor.RESET;
this.chestplate.customItemModel = "dragon_chestplate";
this.chestplate.customEquipmentModel = "dragon";
this.leggings.name = ChatColor.DARK_PURPLE + "Dragon Leggings" + ChatColor.RESET;
this.leggings.name =
ChatColor.DARK_PURPLE + "Dragon Leggings" + ChatColor.RESET;
this.leggings.customItemModel = "dragon_leggings";
this.leggings.customEquipmentModel = "dragon";
this.boots.name = ChatColor.DARK_PURPLE + "Dragon Boots" + ChatColor.RESET;
this.boots.name =
ChatColor.DARK_PURPLE + "Dragon Boots" + ChatColor.RESET;
this.boots.customItemModel = "dragon_boots";
this.boots.customEquipmentModel = "dragon";
@@ -1,23 +1,28 @@
package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.getPluginManager;
import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.items.ItemStats;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandExecutor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import static org.bukkit.Bukkit.getPluginManager;
public class PoseidonGear
extends GenericGearSet
implements CommandExecutor, Listener {
public class PoseidonGear extends GenericGearSet implements CommandExecutor, Listener {
@Override
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
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.getTrident());
@@ -48,7 +53,12 @@ public class PoseidonGear extends GenericGearSet implements CommandExecutor, Lis
@Override
public void registerRecipes() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(getPluginManager().getPlugin("fantasysmp"), this::checkPlayerAir, 0, 20);
Bukkit.getScheduler().scheduleSyncRepeatingTask(
getPluginManager().getPlugin("fantasysmp"),
this::checkPlayerAir,
0,
20
);
}
public void checkPlayerAir() {
@@ -68,26 +78,34 @@ public class PoseidonGear extends GenericGearSet implements CommandExecutor, Lis
this.sword.attackDamage = 10;
this.sword.attackSpeed = 1.2f;
this.sword.name = ChatColor.AQUA + "Poseidon's Fury" + ChatColor.RESET;
this.sword.lore = "A powerful trident imbued with the power of the ocean.";
this.sword.lore =
"A powerful trident imbued with the power of the ocean.";
this.sword.customItemModel = "poseidons_trident";
this.helmet.name = ChatColor.AQUA + "Poseidon's Crown" + ChatColor.RESET;
this.helmet.lore = "A helmet granted to those who harness the power of the ocean.";
this.helmet.name =
ChatColor.AQUA + "Poseidon's Crown" + ChatColor.RESET;
this.helmet.lore =
"A helmet granted to those who harness the power of the ocean.";
this.helmet.customItemModel = "poseidons_helmet";
this.helmet.customEquipmentModel = "poseidon";
this.chestplate.name = ChatColor.AQUA + "Poseidon's Chestplate" + ChatColor.RESET;
this.chestplate.lore = "A chestplate granted to those who harness the power of the ocean.";
this.chestplate.name =
ChatColor.AQUA + "Poseidon's Chestplate" + ChatColor.RESET;
this.chestplate.lore =
"A chestplate granted to those who harness the power of the ocean.";
this.chestplate.customItemModel = "poseidons_chestplate";
this.chestplate.customEquipmentModel = "poseidon";
this.leggings.name = ChatColor.AQUA + "Poseidon's Leggings" + ChatColor.RESET;
this.leggings.lore = "Leggings granted to those who harness the power of the ocean.";
this.leggings.name =
ChatColor.AQUA + "Poseidon's Leggings" + ChatColor.RESET;
this.leggings.lore =
"Leggings granted to those who harness the power of the ocean.";
this.leggings.customItemModel = "poseidons_leggings";
this.leggings.customEquipmentModel = "poseidon";
this.boots.name = ChatColor.AQUA + "Poseidon's Boots" + ChatColor.RESET;
this.boots.lore = "Boots granted to those who harness the power of the ocean.";
this.boots.lore =
"Boots granted to those who harness the power of the ocean.";
this.boots.customItemModel = "poseidons_boots";
this.boots.customEquipmentModel = "poseidon";
}
@@ -1,7 +1,11 @@
package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.getServer;
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.command.CommandExecutor;
import org.bukkit.entity.LivingEntity;
@@ -16,17 +20,19 @@ import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.SmithingTransformRecipe;
import org.bukkit.potion.PotionEffect;
import java.util.ArrayList;
import java.util.Objects;
public class WitheriteGear
extends GenericGearSet
implements Listener, CommandExecutor {
import static org.bukkit.Bukkit.broadcastMessage;
import static org.bukkit.Bukkit.getServer;
public class WitheriteGear extends GenericGearSet implements Listener, 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) {
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());
@@ -40,55 +46,115 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
@Override
public void registerRecipes() {
ItemStack sword = this.getSword();
NamespacedKey swordKey = new NamespacedKey("fantasysmp.items", "witherite_sword");
RecipeChoice swordChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_SWORD);
SmithingTransformRecipe swordRecipe = new SmithingTransformRecipe(swordKey, sword, NETHERITE_UPGRADE, swordChoice, WITHER_SKULL);
NamespacedKey swordKey = new NamespacedKey(
"fantasysmp.items",
"witherite_sword"
);
RecipeChoice swordChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_SWORD
);
SmithingTransformRecipe swordRecipe = new SmithingTransformRecipe(
swordKey,
sword,
NETHERITE_UPGRADE,
swordChoice,
WITHER_SKULL
);
getServer().addRecipe(swordRecipe);
ItemStack helmet = this.getHelmet();
NamespacedKey helmetKey = new NamespacedKey("fantasysmp.items", "witherite_helmet");
RecipeChoice helmetChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_HELMET);
SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(helmetKey, helmet, NETHERITE_UPGRADE, helmetChoice, WITHER_SKULL);
NamespacedKey helmetKey = new NamespacedKey(
"fantasysmp.items",
"witherite_helmet"
);
RecipeChoice helmetChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_HELMET
);
SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(
helmetKey,
helmet,
NETHERITE_UPGRADE,
helmetChoice,
WITHER_SKULL
);
getServer().addRecipe(helmetRecipe);
ItemStack chestplate = this.getChestplate();
NamespacedKey chestplateKey = new NamespacedKey("fantasysmp.items", "witherite_chestplate");
RecipeChoice chestplateChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_CHESTPLATE);
SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(chestplateKey, chestplate, NETHERITE_UPGRADE, chestplateChoice, WITHER_SKULL);
NamespacedKey chestplateKey = new NamespacedKey(
"fantasysmp.items",
"witherite_chestplate"
);
RecipeChoice chestplateChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_CHESTPLATE
);
SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(
chestplateKey,
chestplate,
NETHERITE_UPGRADE,
chestplateChoice,
WITHER_SKULL
);
getServer().addRecipe(chestplateRecipe);
ItemStack leggings = this.getLeggings();
NamespacedKey leggingsKey = new NamespacedKey("fantasysmp.items", "witherite_leggings");
RecipeChoice leggingsChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_LEGGINGS);
SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(leggingsKey, leggings, NETHERITE_UPGRADE, leggingsChoice, WITHER_SKULL);
NamespacedKey leggingsKey = new NamespacedKey(
"fantasysmp.items",
"witherite_leggings"
);
RecipeChoice leggingsChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_LEGGINGS
);
SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(
leggingsKey,
leggings,
NETHERITE_UPGRADE,
leggingsChoice,
WITHER_SKULL
);
getServer().addRecipe(leggingsRecipe);
ItemStack boots = this.getBoots();
NamespacedKey bootsKey = new NamespacedKey("fantasysmp.items", "witherite_boots");
RecipeChoice bootsChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_BOOTS);
SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(bootsKey, boots, NETHERITE_UPGRADE, bootsChoice, WITHER_SKULL);
NamespacedKey bootsKey = new NamespacedKey(
"fantasysmp.items",
"witherite_boots"
);
RecipeChoice bootsChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_BOOTS
);
SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(
bootsKey,
boots,
NETHERITE_UPGRADE,
bootsChoice,
WITHER_SKULL
);
getServer().addRecipe(bootsRecipe);
}
@EventHandler
public void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
public void onEntityDamageByEntity(
org.bukkit.event.entity.EntityDamageByEntityEvent event
) {
// checks that it is a player that is performing the attack.
if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) {
return;
}
if (!LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore)) {
if (
!LoreChecker.itemLoreContains(
player.getInventory().getItemInMainHand(),
this.sword.lore
)
) {
return;
}
PotionEffect effect = new PotionEffect(
org.bukkit.potion.PotionEffectType.WITHER,
20 * 5,
1
org.bukkit.potion.PotionEffectType.WITHER,
20 * 5,
1
);
effect.apply((LivingEntity) event.getEntity());
}
@EventHandler
@@ -96,7 +162,10 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
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)) {
if (
!(event.getAction() == Action.RIGHT_CLICK_AIR ||
event.getAction() == Action.RIGHT_CLICK_BLOCK)
) {
return;
}
@@ -111,26 +180,46 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
cooldown.add(player);
Bukkit.getScheduler().scheduleSyncDelayedTask(
Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")),
() -> cooldown.remove(player),
25
Objects.requireNonNull(
Bukkit.getPluginManager().getPlugin("fantasysmp")
),
() -> cooldown.remove(player),
25
);
}
@EventHandler
public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) {
public void onEntityPotionEffectEvent(
org.bukkit.event.entity.EntityPotionEffectEvent event
) {
if (event.getEntity() instanceof Player player) {
if (event.getNewEffect() == null) return;
if (event.getNewEffect().getType() != org.bukkit.potion.PotionEffectType.WITHER) {
if (
event.getNewEffect().getType() !=
org.bukkit.potion.PotionEffectType.WITHER
) {
return;
}
try {
if (LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore)
&& LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore)
if (
LoreChecker.itemLoreContains(
player.getInventory().getHelmet(),
this.helmet.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getChestplate(),
this.chestplate.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getLeggings(),
this.leggings.lore
) &&
LoreChecker.itemLoreContains(
player.getInventory().getBoots(),
this.boots.lore
)
) {
event.setCancelled(true);
}
@@ -148,18 +237,24 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
this.sword.lore = "A sword forged with the skulls of wither skeletons.";
this.sword.customItemModel = "witherite_sword";
this.helmet.name = ChatColor.BLACK + "Witherite Helmet" + ChatColor.RESET;
this.helmet.lore = "A helmet forged with the skulls of wither skeletons.";
this.helmet.name =
ChatColor.BLACK + "Witherite Helmet" + ChatColor.RESET;
this.helmet.lore =
"A helmet forged with the skulls of wither skeletons.";
this.helmet.customItemModel = "witherite_helmet";
this.helmet.customEquipmentModel = "witherite";
this.chestplate.name = ChatColor.BLACK + "Witherite Chestplate" + ChatColor.RESET;
this.chestplate.lore = "A chestplate forged with the skulls of wither skeletons.";
this.chestplate.name =
ChatColor.BLACK + "Witherite Chestplate" + ChatColor.RESET;
this.chestplate.lore =
"A chestplate forged with the skulls of wither skeletons.";
this.chestplate.customItemModel = "witherite_chestplate";
this.chestplate.customEquipmentModel = "witherite";
this.leggings.name = ChatColor.BLACK + "Witherite Leggings" + ChatColor.RESET;
this.leggings.lore = "Leggings forged with the skulls of wither skeletons.";
this.leggings.name =
ChatColor.BLACK + "Witherite Leggings" + ChatColor.RESET;
this.leggings.lore =
"Leggings forged with the skulls of wither skeletons.";
this.leggings.customItemModel = "witherite_leggings";
this.leggings.customEquipmentModel = "witherite";
@@ -1,19 +1,15 @@
package dev.zxq5.fantasysmp.warps;
import com.google.gson.Gson;
import dev.zxq5.fantasysmp.groups.Team;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
import java.io.*;
import java.util.UUID;
import static org.bukkit.Bukkit.broadcastMessage;
import static org.bukkit.Bukkit.getServer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import dev.zxq5.fantasysmp.groups.Team;
import java.io.*;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class Warp {
@@ -30,7 +26,12 @@ public class Warp {
private int z;
public boolean execute(Player player) {
Location location = new Location(getServer().getWorld(world), this.x, this.y, this.z);
Location location = new Location(
getServer().getWorld(world),
this.x,
this.y,
this.z
);
location.setPitch(player.getLocation().getPitch());
location.setYaw(player.getLocation().getYaw());
player.teleport(location);
@@ -38,7 +39,10 @@ public class Warp {
}
public static void loadWarps() throws Exception {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME);
if (!file.exists()) {
@@ -48,17 +52,20 @@ public class Warp {
BufferedReader reader;
reader = new BufferedReader(new FileReader(file));
Gson gson = new Gson();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
warps = gson.fromJson(reader, Warp[].class);
reader.close();
}
public static void saveWarps() throws Exception {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME);
Gson gson = new Gson();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(warps);
Writer writer = new FileWriter(file);
writer.write(json);
@@ -66,13 +73,16 @@ public class Warp {
}
public static void createWarpFile() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME);
if (!file.exists()) {
try {
Warp[] w = new Warp[0];
Gson gson = new Gson();
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(w);
Writer writer = new FileWriter(file);
writer.write(json);
@@ -108,10 +118,13 @@ public class Warp {
return null;
}
public static Warp getTeamWarp(Team team, String name) {
public static Warp getTeamWarp(Team team, Player player, String name) {
for (Warp warp : warps) {
if (warp.type.equals(WarpType.TEAM)) {
if (warp.name.equals(name) && warp.setby.equals(team.getUUID())) {
if (
warp.name.equals(name) &&
warp.setby.equals(player.getUniqueId().toString())
) {
return warp;
}
}
@@ -123,7 +136,10 @@ public class Warp {
String message = ChatColor.WHITE + "All Warps: [\n" + ChatColor.GREEN;
for (Warp warp : warps) {
if (warp.type.equals(WarpType.PUBLIC) || warp.setby.equals(player.toString())) {
if (
warp.type.equals(WarpType.PUBLIC) ||
warp.setby.equals(player.toString())
) {
message += " " + warp.name + "\n";
}
}
@@ -175,16 +191,3 @@ public class Warp {
}
}
}