4 Commits

Author SHA1 Message Date
zxq5 ec542a6188 fixed some lints and some bugs in the teams implementation 2025-09-07 20:45:27 +01:00
zxq5 3ca436b7e4 fixed team warps. still need to document what works and what doesn't.
probably a job for tomorrow
2025-09-06 23:18:22 +01:00
zxq5 b56a3c8218 for non-main branches CI/CD only runs on pull req
Java CI with Maven / build (pull_request) Successful in 27s
2025-09-06 20:40:11 +01:00
zxq5 27fd92ff2c added more death messages
Java CI with Maven / build (push) Successful in 29s
2025-09-02 20:57:56 +01:00
25 changed files with 1103 additions and 494 deletions
+57
View File
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
+22 -16
View File
@@ -1,23 +1,29 @@
name: Java CI with Maven name: Java CI with Maven
on: [push] on:
push:
branches:
- "main"
pull_request:
branches:
- "*"
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Set up JDK 21 - name: Set up JDK 21
uses: actions/setup-java@v4 uses: actions/setup-java@v4
with: with:
java-version: '21' java-version: "21"
distribution: 'temurin' distribution: "temurin"
cache: maven cache: maven
- uses: stCarolas/setup-maven@v5 - uses: stCarolas/setup-maven@v5
- name: Build with Maven - name: Build with Maven
run: mvn -B package --file pom.xml run: mvn -B package --file pom.xml
- name: Release - name: Release
uses: akkuman/gitea-release-action@v1 uses: akkuman/gitea-release-action@v1
with: with:
files: ./target/fantasysmp*.jar files: ./target/fantasysmp*.jar
token: '${{secrets.RELEASE_TOKEN}}' token: "${{secrets.RELEASE_TOKEN}}"
+34
View File
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>fantasysmp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1756828330981</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
+2
View File
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
+9
View File
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=21
+4
View File
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
+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
@@ -12,7 +12,6 @@ public final class Fantasysmp extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
Items items = new Items(this); Items items = new Items(this);
getCommand("items").setExecutor(items); getCommand("items").setExecutor(items);
// Plugin startup logic // Plugin startup logic
@@ -39,9 +38,9 @@ public final class Fantasysmp extends JavaPlugin {
heresyChecker.scheduleHeresyChecker(); heresyChecker.scheduleHeresyChecker();
getServer().getPluginManager().registerEvents(heresyChecker, this); getServer().getPluginManager().registerEvents(heresyChecker, this);
getServer().getPluginManager().registerEvents(new DeathMessageCustomiser(), this); getServer()
.getPluginManager()
.registerEvents(new DeathMessageCustomiser(), this);
XrayDetector xrayDetector = new XrayDetector(); XrayDetector xrayDetector = new XrayDetector();
getServer().getPluginManager().registerEvents(xrayDetector, this); getServer().getPluginManager().registerEvents(xrayDetector, this);
@@ -20,7 +20,11 @@ public class DeathMessageCustomiser implements Listener {
"%p thought the ravine was a boulder problem", "%p thought the ravine was a boulder problem",
"%p's fingers were not cut out for crack climbing", "%p's fingers were not cut out for crack climbing",
"%p got a leg cramp", "%p got a leg cramp",
"%p forgot to check their harness" "%p forgot to check their harness",
"%p didn't send the dyno",
"%p tried to static a 4 block jump",
"%p's climbing shoes didn't fit",
"%p wasn't flexible enough"
}; };
@EventHandler @EventHandler
@@ -3,7 +3,6 @@ package dev.zxq5.fantasysmp.events;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.Chicken; import org.bukkit.entity.Chicken;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; 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.EntityDamageEvent;
import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent; import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@@ -1,6 +1,20 @@
package dev.zxq5.fantasysmp.events; package dev.zxq5.fantasysmp.events;
import static org.bukkit.Bukkit.*;
import com.google.gson.Gson; 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.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -9,34 +23,23 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.Plugin; 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 { 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 String token;
private final ArrayList<Material> trackedBlocks = new ArrayList<>(Arrays.asList( private final ArrayList<Material> trackedBlocks = new ArrayList<>(
Material.ANCIENT_DEBRIS, Arrays.asList(
Material.DIAMOND_ORE, Material.ANCIENT_DEBRIS,
Material.EMERALD_ORE, Material.DIAMOND_ORE,
Material.GOLD_ORE, Material.EMERALD_ORE,
Material.IRON_ORE, Material.GOLD_ORE,
Material.LAPIS_ORE, Material.IRON_ORE,
Material.REDSTONE_ORE Material.LAPIS_ORE,
)); Material.REDSTONE_ORE
)
);
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
@@ -45,80 +48,84 @@ public class XrayDetector implements Listener {
Material block = event.getBlock().getType(); Material block = event.getBlock().getType();
Plugin plugin = getPluginManager().getPlugin("fantasysmp"); 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); blocks = this.players.get(player);
if (this.trackedBlocks.contains(block)) { if (this.trackedBlocks.contains(block)) {
if (!(blocks.containsKey(block))) blocks.put(block, 0); if (!(blocks.containsKey(block))) blocks.put(block, 0);
blocks.put(block, blocks.get(block) + 1); blocks.put(block, blocks.get(block) + 1);
Bukkit.getScheduler().runTaskLater(plugin, () -> { Bukkit.getScheduler().runTaskLater(
blocks.put(block, blocks.get(block) - 1); plugin,
}, 1200); () -> {
blocks.put(block, blocks.get(block) - 1);
},
1200
);
} }
} }
private void uploadData() { private void uploadData() {
HashMap<String, HashMap<String, Integer>> data = new HashMap<>(); 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<>(); HashMap<String, Integer> materials = new HashMap<>();
for (Map.Entry<Material, Integer> materialEntry : entry.getValue().entrySet()) { for (Map.Entry<Material, Integer> materialEntry : entry
materials.put(materialEntry.getKey().toString(), materialEntry.getValue()); .getValue()
.entrySet()) {
materials.put(
materialEntry.getKey().toString(),
materialEntry.getValue()
);
} }
data.put(entry.getKey().getName(), materials); data.put(entry.getKey().getName(), materials);
} }
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
HttpClient client = HttpClient.newHttpClient(); HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("https://mcapi.zxq5.dev/xray?token=" + token)) HttpRequest request = HttpRequest.newBuilder(
.header("Content-Type", "application/json") URI.create("https://mcapi.zxq5.dev/xray?token=" + token)
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(data))) )
.build(); .header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(gson.toJson(data)))
.build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) client
.thenApply(HttpResponse::body) .sendAsync(request, HttpResponse.BodyHandlers.ofString())
.join(); .thenApply(HttpResponse::body)
.join();
} }
public XrayDetector() { public XrayDetector() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder(); File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, "token.txt"); File file = new File(dataFolder, "token.txt");
BufferedReader reader; BufferedReader reader;
try { try {
reader = new BufferedReader(new FileReader(file)); reader = new BufferedReader(new FileReader(file));
this.token = reader.readLine(); this.token = reader.readLine();
reader.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return; return;
} }
Bukkit.getScheduler().runTaskTimerAsynchronously(getPluginManager().getPlugin("fantasysmp"), this::uploadData, 0, 20 * 60); Bukkit.getScheduler().runTaskTimerAsynchronously(
getPluginManager().getPlugin("fantasysmp"),
this::uploadData,
0,
20 * 60
);
} }
} }
@@ -1,31 +1,30 @@
package dev.zxq5.fantasysmp.groups; package dev.zxq5.fantasysmp.groups;
import static org.bukkit.Bukkit.getServer;
import dev.zxq5.fantasysmp.chatutils.Chat; import dev.zxq5.fantasysmp.chatutils.Chat;
import dev.zxq5.fantasysmp.warps.Warp; import dev.zxq5.fantasysmp.warps.Warp;
import dev.zxq5.fantasysmp.warps.WarpType; import dev.zxq5.fantasysmp.warps.WarpType;
import java.util.ArrayList;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import static org.bukkit.Bukkit.getServer;
/* /*
* Commands: * Commands:
* *
* ** PLAYER ** * ** PLAYER **
* *
* team list => TODO * team list => DONE
* team create <name> => TODO * team create <name> => DONE
* team rename <new name> => TODO * team rename <new name> => TODO TEST
* team transfer <player> => TODO * team transfer <player> => TODO
* team join <name> => TODO * team join <name> => TODO
* team invite <player> => TODO * team invite <player> => TODO
* team leave => TODO * team leave => TODO
* team disband => TODO * team disband => DONE
* team setwarp => TODO * team setwarp => DONE
* team delwarp => TODO * team delwarp => TODO
* team warp <name> => TODO * team warp <name> => TODO TEST
* team kick => TODO * team kick => TODO
* team log => TODO * team log => TODO
* *
@@ -41,7 +40,12 @@ import static org.bukkit.Bukkit.getServer;
public class Commands implements CommandExecutor { public class Commands implements CommandExecutor {
@Override @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 (!(sender instanceof Player player)) return false;
if (command.getName().equals("team")) handleTeamCommands(player, args); if (command.getName().equals("team")) handleTeamCommands(player, args);
@@ -72,7 +76,10 @@ public class Commands implements CommandExecutor {
public void handleRankCommands(Player player, String[] args) { public void handleRankCommands(Player player, String[] args) {
// check perms // check perms
if (!(player.hasPermission("fantasysmp.ranks"))) { 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; return;
} }
@@ -87,167 +94,181 @@ public class Commands implements CommandExecutor {
public void handleList(Player player, String[] args) { public void handleList(Player player, String[] args) {
String[] teams = Team.getTeams(); String[] teams = Team.getTeams();
String result = "Teams: [\n " + String.join("\n ", teams) + "\n]"; Chat.info(player, String.join(" ", teams));
Chat.info(player, result);
} }
public void handleCreate(Player player, String[] args) { public void handleCreate(Player caller, String[] args) {
if (args.length != 2) { if (args.length != 2) {
Chat.error(player, "Usage: /team create <name>"); Chat.error(caller, "Usage: /team create <name>");
return; return;
} }
Team.createTeam(player, args[1]); Team.createTeam(caller, args[1]);
} }
public void handleSetColour(Player player, String[] args) { public void handleSetColour(Player caller, String[] args) {
if (args.length != 2) { if (args.length != 2) {
Chat.error(player, "Usage: /team colour <color>"); Chat.error(caller, "Usage: /team colour <color>");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; if (team == null) return;
team.setColour(player, args[1]); team.setColour(caller, args[1]);
} }
public void handleRename(Player player, String[] args) { public void handleRename(Player caller, String[] args) {
if (args.length != 2) { if (args.length != 2) {
Chat.error(player, "Usage: /team rename <new name>"); Chat.error(caller, "Usage: /team rename <new name>");
return; return;
} }
if (args[1].isEmpty() || args[1].contains(" ") || args[1].contains("\t")) { if (
Chat.error(player, "Invalid name!"); args[1].isEmpty() || args[1].contains(" ") || args[1].contains("\t")
) {
Chat.error(caller, "Invalid name!");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; if (team == null) return;
team.renameTeam(player, args[1]); team.renameTeam(caller, args[1]);
} }
public void handleSetTag(Player player, String[] args) { public void handleSetTag(Player caller, String[] args) {
if (args.length != 2) { if (args.length != 2) {
Chat.error(player, "Usage: /team tag <tag>"); Chat.error(caller, "Usage: /team tag <tag>");
return; return;
} }
if (args[1].length() < 3 || args[1].contains(" ") || args[1].contains("\t") || args[1].length() > 8) { if (
Chat.error(player, "Invalid tag!"); args[1].length() < 3 ||
Chat.error(player, "tags should be 3-8 chars, alphanumeric and have no spaces"); 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; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; 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) { if (args.length != 2) {
Chat.error(player, "Usage: /team transfer <player>"); Chat.error(caller, "Usage: /team transfer <player>");
return; return;
} }
Team.fromMember(caller).transferTeam(caller, args[1]);
// 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) { if (args.length != 2) {
Chat.error(player, "Usage: /team join <name>"); Chat.error(caller, "Usage: /team join <name>");
return; 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) { if (args.length != 2) {
Chat.error(player, "Usage: /team invite <player>"); Chat.error(caller, "Usage: /team invite <player>");
return; 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) { if (args.length != 1) {
Chat.error(player, "Usage: /team leave"); Chat.error(caller, "Usage: /team leave");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; 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) { if (args.length != 1) {
Chat.error(player, "Usage: /team disband"); Chat.error(caller, "Usage: /team disband");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; 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) { if (args.length != 2) {
Chat.error(player, "Usage: /team setwarp <name>"); Chat.error(caller, "Usage: /team setwarp <name>");
return; 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 caller, String[] args) {
public void handleWarp(Player player, String[] args) {
if (args.length != 2) { if (args.length != 2) {
Chat.error(player, "Usage: /team warp <name>"); Chat.error(caller, "Usage: /team warp <name>");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; 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) { if (args.length != 2) {
Chat.error(player, "Usage: /team kick <player>"); Chat.error(caller, "Usage: /team kick <player>");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; 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) { if (args.length != 1) {
Chat.error(player, "Usage: /team log"); Chat.error(caller, "Usage: /team log");
return; return;
} }
Team team = Team.fromMember(player); Team team = Team.fromMember(caller);
if (team == null) return; 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]"; 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() {} public Commands() {}
} }
@@ -1,28 +1,31 @@
package dev.zxq5.fantasysmp.groups; 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.broadcastMessage;
import static org.bukkit.Bukkit.getServer; 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 { public class Team {
private static ArrayList<Team> teams; private static ArrayList<Team> teams;
private final static String FILENAME = "teams.json"; private static final String FILENAME = "teams.json";
private String name; private String name;
private String ownerUUID; private String ownerUUID;
private ArrayList<String> members; private ArrayList<String> members;
private ArrayList<String> invites;
private ArrayList<String> logs; private ArrayList<String> logs;
private String teamUUID; private String teamUUID;
private String tag; private String tag;
private ChatColor color;
public Team(Player creator, String name, String tag) { public Team(Player creator, String name, String tag) {
this.name = name; this.name = name;
@@ -50,7 +53,9 @@ public class Team {
public static Team fromMember(Player member) { public static Team fromMember(Player member) {
for (Team team : teams) { 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); Team.error(member, Error.TEAM_NOT_FOUND);
@@ -87,35 +92,44 @@ public class Team {
this.tag = newTag; this.tag = newTag;
this.log(player.getName() + " changed the team tag to " + 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())) { if (!this.ownerUUID.equals(player.getUniqueId().toString())) {
Team.error(player, Error.NO_PERMISSION); Team.error(player, Error.NO_PERMISSION);
return; return;
} }
switch (colour) { this.color = switch (colour) {
case "red" -> this.tag = ChatColor.RED + this.tag; case "red" -> ChatColor.RED;
case "green" -> this.tag = ChatColor.GREEN + this.tag; case "green" -> ChatColor.GREEN;
case "blue" -> this.tag = ChatColor.BLUE + this.tag; case "blue" -> ChatColor.BLUE;
case "yellow" -> this.tag = ChatColor.YELLOW + this.tag; case "yellow" -> ChatColor.YELLOW;
case "aqua" -> this.tag = ChatColor.AQUA + this.tag; case "aqua" -> ChatColor.AQUA;
case "dark_aqua" -> this.tag = ChatColor.DARK_AQUA + this.tag; case "dark_aqua" -> ChatColor.DARK_AQUA;
case "dark_blue" -> this.tag = ChatColor.DARK_BLUE + this.tag; case "dark_blue" -> ChatColor.DARK_BLUE;
case "dark_gray" -> this.tag = ChatColor.DARK_GRAY + this.tag; case "dark_gray" -> ChatColor.DARK_GRAY;
case "dark_green" -> this.tag = ChatColor.DARK_GREEN + this.tag; case "dark_green" -> ChatColor.DARK_GREEN;
case "dark_purple" -> this.tag = ChatColor.DARK_PURPLE + this.tag; case "dark_purple" -> ChatColor.DARK_PURPLE;
case "gold" -> this.tag = ChatColor.GOLD + this.tag; case "gold" -> ChatColor.GOLD;
case "gray" -> this.tag = ChatColor.GRAY + this.tag; case "gray" -> ChatColor.GRAY;
case "light_purple" -> this.tag = ChatColor.LIGHT_PURPLE + this.tag; case "light_purple" -> ChatColor.LIGHT_PURPLE;
case "white" -> this.tag = ChatColor.WHITE + this.tag; case "white" -> ChatColor.WHITE;
case "black" -> this.tag = ChatColor.BLACK + this.tag; case "black" -> ChatColor.BLACK;
} default -> ChatColor.WHITE;
};
this.log(player.getName() + " changed the team colour to " + colour + "."); this.log(
Chat.success(player, "You changed the colour of " + this.name + " to " + colour + "."); 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) { public void transferTeam(Player player, String playerName) {
@@ -137,9 +151,21 @@ public class Team {
} }
this.ownerUUID = newUUID; 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) { public void removePlayer(Player remover, String playerName) {
@@ -169,9 +195,21 @@ public class Team {
} }
this.members.remove(removedPlayerUUID); 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) { public void leaveTeam(Player member) {
@@ -211,7 +249,9 @@ public class Team {
} }
public ArrayList<String> getLogs(Player member) { 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); Team.error(member, Error.NO_PERMISSION);
return null; return null;
@@ -223,7 +263,10 @@ public class Team {
} }
public static void loadTeams() throws Exception { 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); File file = new File(dataFolder, FILENAME);
if (!file.exists()) { if (!file.exists()) {
@@ -233,17 +276,23 @@ public class Team {
BufferedReader reader; BufferedReader reader;
reader = new BufferedReader(new FileReader(file)); reader = new BufferedReader(new FileReader(file));
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
teams = gson.fromJson(reader, new TypeToken<ArrayList<Team>>(){}.getType()); teams = gson.fromJson(
reader,
new TypeToken<ArrayList<Team>>() {}.getType()
);
reader.close(); reader.close();
} }
public static void saveTeams() { public static void saveTeams() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder(); File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME); File file = new File(dataFolder, FILENAME);
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(teams); String json = gson.toJson(teams);
try { try {
@@ -257,13 +306,16 @@ public class Team {
} }
public static void createTeamsFile() { public static void createTeamsFile() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder(); File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME); File file = new File(dataFolder, FILENAME);
if (!file.exists()) { if (!file.exists()) {
try { try {
Team[] t = new Team[0]; Team[] t = new Team[0];
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(t); String json = gson.toJson(t);
Writer writer = new FileWriter(file); Writer writer = new FileWriter(file);
writer.write(json); writer.write(json);
@@ -274,25 +326,37 @@ 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() { public String getUUID() {
return this.teamUUID; return this.teamUUID;
} }
public String getTag() { public String getTag() {
return this.tag; return this.color + this.tag;
} }
public static void error(Player player, Error error) { public static void error(Player player, Error error) {
Chat.error(player, switch (error) { Chat.error(
case NO_PERMISSION -> "You do not have permission to do that!"; player,
case SELF_IN_TEAM -> "You are already in a team!"; switch (error) {
case NOT_IN_TEAM -> "You are not in a team!"; case NO_PERMISSION -> "You do not have permission to do that!";
case TEAM_NOT_FOUND -> "Team not found!"; case SELF_IN_TEAM -> "You are already in a team!";
case PLAYER_NOT_FOUND -> "Player not found!"; case NOT_IN_TEAM -> "You are not in a team!";
case ALREADY_TAKEN -> "That name is already taken!"; case TEAM_NOT_FOUND -> "Team not found!";
case PLAYER_IN_TEAM -> "That player is already in a team!"; case PLAYER_NOT_FOUND -> "Player not found!";
case TEAM_OWNER -> "You cannot do this to/as the owner!"; 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 +369,4 @@ enum Error {
PLAYER_NOT_FOUND, PLAYER_NOT_FOUND,
ALREADY_TAKEN, ALREADY_TAKEN,
PLAYER_IN_TEAM, PLAYER_IN_TEAM,
} }
@@ -1,45 +1,43 @@
package dev.zxq5.fantasysmp.items.gear; package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.*;
import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.util.LoreChecker; import dev.zxq5.fantasysmp.util.LoreChecker;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.damage.DamageType; import org.bukkit.damage.DamageType;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.SmallFireball; import org.bukkit.entity.SmallFireball;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.SmithingTransformRecipe;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.ArrayList; public class BlazingGear extends GenericGearSet implements CommandExecutor {
import java.util.List;
import java.util.Objects;
import static org.bukkit.Bukkit.*;
public class BlazingGear extends GenericGearSet implements Listener, CommandExecutor {
private ArrayList<Player> cooldown = new ArrayList<>(); private ArrayList<Player> cooldown = new ArrayList<>();
private final ArrayList<DamageType> damageTypes = new ArrayList<>(List.of( private final ArrayList<DamageType> damageTypes = new ArrayList<>(
DamageType.HOT_FLOOR, List.of(
DamageType.ON_FIRE, DamageType.HOT_FLOOR,
DamageType.IN_FIRE, DamageType.ON_FIRE,
DamageType.LAVA DamageType.IN_FIRE,
)); DamageType.LAVA
)
);
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
player.getInventory().addItem(this.getHelmet()); player.getInventory().addItem(this.getHelmet());
@@ -54,15 +52,39 @@ public class BlazingGear extends GenericGearSet implements Listener, CommandExec
public void registerRecipes() {} public void registerRecipes() {}
@EventHandler @EventHandler
public void onPlayerSetOnFire(org.bukkit.event.entity.EntityDamageEvent event) { public void onPlayerSetOnFire(
org.bukkit.event.entity.EntityDamageEvent event
) {
if (!(event.getEntity() instanceof Player player)) return; if (!(event.getEntity() instanceof Player player)) return;
if (!(LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore))) return; if (
if (!(LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore))) return; !(LoreChecker.itemLoreContains(
if (!(LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore))) return; player.getInventory().getHelmet(),
if (!(LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore))) return; this.helmet.lore
))
) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getChestplate(),
this.chestplate.lore
))
) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getLeggings(),
this.leggings.lore
))
) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getBoots(),
this.boots.lore
))
) return;
if (damageTypes.contains(event.getDamageSource().getDamageType())) event.setCancelled(true); if (
damageTypes.contains(event.getDamageSource().getDamageType())
) event.setCancelled(true);
player.setFireTicks(0); player.setFireTicks(0);
} }
@@ -72,7 +94,10 @@ public class BlazingGear extends GenericGearSet implements Listener, CommandExec
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = event.getItem(); // Get the item the player interacted with 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; return;
} }
@@ -82,18 +107,37 @@ public class BlazingGear extends GenericGearSet implements Listener, CommandExec
Plugin plugin = getPluginManager().getPlugin("fantasysmp"); Plugin plugin = getPluginManager().getPlugin("fantasysmp");
cooldown.add(player); cooldown.add(player);
Bukkit.getScheduler().runTaskLater(plugin, () -> cooldown.remove(player), 25); Bukkit.getScheduler().runTaskLater(
plugin,
() -> cooldown.remove(player),
25
);
shootFireball(player); shootFireball(player);
Bukkit.getScheduler().runTaskLater(plugin, () -> shootFireball(player), 4); Bukkit.getScheduler().runTaskLater(
Bukkit.getScheduler().runTaskLater(plugin, () -> shootFireball(player), 8); plugin,
() -> shootFireball(player),
4
);
Bukkit.getScheduler().runTaskLater(
plugin,
() -> shootFireball(player),
8
);
} }
@EventHandler @EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (!(event.getDamager() instanceof Player player)) return; if (!(event.getDamager() instanceof Player player)) return;
if (!(LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore))) return; if (
if (event.getEntity().getFireTicks() < 240) event.getEntity().setFireTicks(240); !(LoreChecker.itemLoreContains(
player.getInventory().getItemInMainHand(),
this.sword.lore
))
) return;
if (event.getEntity().getFireTicks() < 240) event
.getEntity()
.setFireTicks(240);
} }
public void shootFireball(Player player) { public void shootFireball(Player player) {
@@ -115,11 +159,13 @@ public class BlazingGear extends GenericGearSet implements Listener, CommandExec
this.helmet.customItemModel = "blazing_helmet"; this.helmet.customItemModel = "blazing_helmet";
this.helmet.customEquipmentModel = "blazing"; this.helmet.customEquipmentModel = "blazing";
this.chestplate.name = ChatColor.GOLD + "Blazing Chestplate" + ChatColor.RESET; this.chestplate.name =
ChatColor.GOLD + "Blazing Chestplate" + ChatColor.RESET;
this.chestplate.customItemModel = "blazing_chestplate"; this.chestplate.customItemModel = "blazing_chestplate";
this.chestplate.customEquipmentModel = "blazing"; this.chestplate.customEquipmentModel = "blazing";
this.leggings.name = ChatColor.GOLD + "Blazing Leggings" + ChatColor.RESET; this.leggings.name =
ChatColor.GOLD + "Blazing Leggings" + ChatColor.RESET;
this.leggings.customItemModel = "blazing_leggings"; this.leggings.customItemModel = "blazing_leggings";
this.leggings.customEquipmentModel = "blazing"; this.leggings.customEquipmentModel = "blazing";
@@ -129,8 +175,10 @@ public class BlazingGear extends GenericGearSet implements Listener, CommandExec
this.sword.lore = "Forged from molten lava and the essence of blazes"; this.sword.lore = "Forged from molten lava and the essence of blazes";
this.helmet.lore = "Forged from molten lava and the essence of blazes"; this.helmet.lore = "Forged from molten lava and the essence of blazes";
this.chestplate.lore = "Forged from molten lava and the essence of blazes"; this.chestplate.lore =
this.leggings.lore = "Forged from molten lava and the essence of blazes"; "Forged from molten lava and the essence of blazes";
this.leggings.lore =
"Forged from molten lava and the essence of blazes";
this.boots.lore = "Forged from molten lava and the essence of blazes"; this.boots.lore = "Forged from molten lava and the essence of blazes";
} }
} }
@@ -6,11 +6,16 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class CrimsonGear extends GenericGearSet implements CommandExecutor, Listener { public class CrimsonGear extends GenericGearSet implements CommandExecutor {
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
@@ -22,19 +27,50 @@ public class CrimsonGear extends GenericGearSet implements CommandExecutor, List
} }
@EventHandler @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 (!(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;
player.setHealth( Math.min(player.getHealth() + 1, player.getMaxHealth()) ); player.setHealth(
Math.min(player.getHealth() + 1, player.getMaxHealth())
);
if (!(LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore))) return; if (
if (!(LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore))) return; !(LoreChecker.itemLoreContains(
if (!(LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore))) return; player.getInventory().getHelmet(),
if (!(LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore))) return; this.helmet.lore
))
) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getChestplate(),
this.chestplate.lore
))
) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getLeggings(),
this.leggings.lore
))
) return;
if (
!(LoreChecker.itemLoreContains(
player.getInventory().getBoots(),
this.boots.lore
))
) return;
player.setHealth( Math.min(player.getHealth() + 1, player.getMaxHealth()) ); player.setHealth(
player.setFoodLevel( Math.min(player.getFoodLevel() + 1, 20) ); Math.min(player.getHealth() + 1, player.getMaxHealth())
);
player.setFoodLevel(Math.min(player.getFoodLevel() + 1, 20));
} }
@Override @Override
@@ -46,24 +82,31 @@ public class CrimsonGear extends GenericGearSet implements CommandExecutor, List
this.sword.customItemModel = "crimson_sword"; this.sword.customItemModel = "crimson_sword";
this.sword.lore = "Live off the blood of your enemies."; this.sword.lore = "Live off the blood of your enemies.";
this.helmet.name = ChatColor.DARK_RED + "Crimson Helmet" + ChatColor.RESET; this.helmet.name =
ChatColor.DARK_RED + "Crimson Helmet" + ChatColor.RESET;
this.helmet.customItemModel = "crimson_helmet"; this.helmet.customItemModel = "crimson_helmet";
this.helmet.customEquipmentModel = "crimson"; this.helmet.customEquipmentModel = "crimson";
this.helmet.lore = "A helmet that grants its wearer vampiric senses."; this.helmet.lore = "A helmet that grants its wearer vampiric senses.";
this.chestplate.name = ChatColor.DARK_RED + "Crimson Chestplate" + ChatColor.RESET; this.chestplate.name =
ChatColor.DARK_RED + "Crimson Chestplate" + ChatColor.RESET;
this.chestplate.customItemModel = "crimson_chestplate"; this.chestplate.customItemModel = "crimson_chestplate";
this.chestplate.customEquipmentModel = "crimson"; this.chestplate.customEquipmentModel = "crimson";
this.chestplate.lore = "A chestplate that strengthens the heart of the wearer."; this.chestplate.lore =
"A chestplate that strengthens the heart of the wearer.";
this.leggings.name = ChatColor.DARK_RED + "Crimson Leggings" + ChatColor.RESET; this.leggings.name =
ChatColor.DARK_RED + "Crimson Leggings" + ChatColor.RESET;
this.leggings.customItemModel = "crimson_leggings"; this.leggings.customItemModel = "crimson_leggings";
this.leggings.customEquipmentModel = "crimson"; this.leggings.customEquipmentModel = "crimson";
this.leggings.lore = "Leggings that enhance the wearer's speed and agility."; this.leggings.lore =
"Leggings that enhance the wearer's speed and agility.";
this.boots.name = ChatColor.DARK_RED + "Crimson Boots" + ChatColor.RESET; this.boots.name =
ChatColor.DARK_RED + "Crimson Boots" + ChatColor.RESET;
this.boots.customItemModel = "crimson_boots"; this.boots.customItemModel = "crimson_boots";
this.boots.customEquipmentModel = "crimson"; this.boots.customEquipmentModel = "crimson";
this.boots.lore = "Boots that allow the wearer to move silently and swiftly."; this.boots.lore =
"Boots that allow the wearer to move silently and swiftly.";
} }
} }
@@ -1,40 +1,34 @@
package dev.zxq5.fantasysmp.items.gear; package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.broadcastMessage;
import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.items.ItemStats;
import dev.zxq5.fantasysmp.util.LoreChecker; import dev.zxq5.fantasysmp.util.LoreChecker;
import java.util.ArrayList;
import java.util.Objects;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.damage.DamageType; import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.*; 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.potion.PotionEffectType;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; public class DragonGear extends GenericGearSet implements CommandExecutor {
import java.util.List;
import java.util.Objects;
import java.util.UUID;
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<>(); private ArrayList<Player> cooldown = new ArrayList<>();
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
player.getInventory().addItem(this.getHelmet()); player.getInventory().addItem(this.getHelmet());
@@ -49,7 +43,9 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
public void registerRecipes() {} public void registerRecipes() {}
@EventHandler @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.getEntity() instanceof Player player) {
if (event.getNewEffect() == null) return; if (event.getNewEffect() == null) return;
@@ -58,10 +54,23 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
} }
try { try {
if (LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore) if (
&& LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore) LoreChecker.itemLoreContains(
&& LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore) player.getInventory().getHelmet(),
&& LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore) 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); event.setCancelled(true);
} }
@@ -72,27 +81,54 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
} }
@EventHandler @EventHandler
public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event) { public void onEntityDamage(
org.bukkit.event.entity.EntityDamageEvent event
) {
// check if fall damage // check if fall damage
if (!(event.getEntity() instanceof Player player)) return; if (!(event.getEntity() instanceof Player player)) return;
if (!(LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore) if (
&& LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore) !(LoreChecker.itemLoreContains(
&& LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore) player.getInventory().getHelmet(),
&& LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore) this.helmet.lore
)) return; ) &&
if (!(event.getDamageSource().getDamageType() == DamageType.FLY_INTO_WALL)) return; 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); event.setCancelled(true);
} }
@EventHandler @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 (!(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; if (!(player.isFlying() || player.isGliding())) return;
double baseDamage = event.getDamage(); 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("damage " + baseDamage);
broadcastMessage("velocity " + player.getVelocity().length()); broadcastMessage("velocity " + player.getVelocity().length());
@@ -106,7 +142,10 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = event.getItem(); // Get the item the player interacted with 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; return;
} }
@@ -123,15 +162,17 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
cooldown.add(player); cooldown.add(player);
Bukkit.getScheduler().scheduleSyncDelayedTask( Bukkit.getScheduler().scheduleSyncDelayedTask(
Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")), Objects.requireNonNull(
() -> cooldown.remove(player), Bukkit.getPluginManager().getPlugin("fantasysmp")
25 ),
() -> cooldown.remove(player),
25
); );
} }
@Override @Override
public ItemStack getHelmet() { public ItemStack getHelmet() {
// helmet.setMaterial(Material.DRAGON_HEAD); // helmet.setMaterial(Material.DRAGON_HEAD);
return super.getHelmet(); return super.getHelmet();
} }
@@ -147,22 +188,27 @@ public class DragonGear extends GenericGearSet implements Listener, CommandExecu
public DragonGear() { public DragonGear() {
this.setTier5(); 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.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.customItemModel = "dragon_helmet";
this.helmet.customEquipmentModel = "dragon"; 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.customItemModel = "dragon_chestplate";
this.chestplate.customEquipmentModel = "dragon"; 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.customItemModel = "dragon_leggings";
this.leggings.customEquipmentModel = "dragon"; 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.customItemModel = "dragon_boots";
this.boots.customEquipmentModel = "dragon"; this.boots.customEquipmentModel = "dragon";
@@ -2,25 +2,29 @@ package dev.zxq5.fantasysmp.items.gear;
import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.util.LoreChecker; import dev.zxq5.fantasysmp.util.LoreChecker;
import java.util.ArrayList;
import java.util.Objects;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.*; import org.bukkit.inventory.*;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList; public class EnderGear extends GenericGearSet implements CommandExecutor {
import java.util.Objects;
public class EnderGear extends GenericGearSet implements Listener, CommandExecutor {
private ArrayList<Player> cooldown = new ArrayList<>(); private ArrayList<Player> cooldown = new ArrayList<>();
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
player.getInventory().addItem(this.getHelmet()); player.getInventory().addItem(this.getHelmet());
@@ -39,7 +43,10 @@ public class EnderGear extends GenericGearSet implements Listener, CommandExecut
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = event.getItem(); // Get the item the player interacted with 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; return;
} }
@@ -48,32 +55,52 @@ public class EnderGear extends GenericGearSet implements Listener, CommandExecut
Location old_location = player.getLocation(); Location old_location = player.getLocation();
World world = player.getWorld(); World world = player.getWorld();
Vector direction = old_location.getDirection();
// find nearest block in that direction // find nearest block in that direction
Block block = player.getTargetBlock(null, 64); Block block = player.getTargetBlock(null, 64);
if (block.getType() == Material.AIR || block.getType() == Material.CAVE_AIR) { if (
block.getType() == Material.AIR ||
block.getType() == Material.CAVE_AIR
) {
return; return;
} }
player.playSound(old_location, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f); player.playSound(
old_location,
Sound.ENTITY_ENDERMAN_TELEPORT,
1.0f,
1.0f
);
world.spawnParticle(Particle.PORTAL, old_location, 100); world.spawnParticle(Particle.PORTAL, old_location, 100);
Location new_location = block.getLocation(); Location new_location = block.getLocation();
new_location.setPitch(old_location.getPitch()); new_location.setPitch(old_location.getPitch());
new_location.setYaw(old_location.getYaw()); new_location.setYaw(old_location.getYaw());
player.setVelocity(new Vector(player.getVelocity().getX(), 0, player.getVelocity().getZ())); player.setVelocity(
new Vector(
player.getVelocity().getX(),
0,
player.getVelocity().getZ()
)
);
player.teleport(new_location); player.teleport(new_location);
player.playSound(new_location, Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 1.0f); player.playSound(
new_location,
Sound.ENTITY_ENDERMAN_TELEPORT,
1.0f,
1.0f
);
world.spawnParticle(Particle.PORTAL, new_location, 100); world.spawnParticle(Particle.PORTAL, new_location, 100);
cooldown.add(player); cooldown.add(player);
Bukkit.getScheduler().scheduleSyncDelayedTask( Bukkit.getScheduler().scheduleSyncDelayedTask(
Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")), Objects.requireNonNull(
() -> cooldown.remove(player), Bukkit.getPluginManager().getPlugin("fantasysmp")
25 ),
() -> cooldown.remove(player),
25
); );
} }
@@ -84,15 +111,18 @@ public class EnderGear extends GenericGearSet implements Listener, CommandExecut
this.sword.name = ChatColor.DARK_AQUA + "Ender Sword" + ChatColor.RESET; this.sword.name = ChatColor.DARK_AQUA + "Ender Sword" + ChatColor.RESET;
this.sword.customItemModel = "ender_sword"; this.sword.customItemModel = "ender_sword";
this.helmet.name = ChatColor.DARK_AQUA + "Ender Helmet" + ChatColor.RESET; this.helmet.name =
ChatColor.DARK_AQUA + "Ender Helmet" + ChatColor.RESET;
this.helmet.customItemModel = "ender_helmet"; this.helmet.customItemModel = "ender_helmet";
this.helmet.customEquipmentModel = "ender"; this.helmet.customEquipmentModel = "ender";
this.chestplate.name = ChatColor.DARK_AQUA + "Ender Chestplate" + ChatColor.RESET; this.chestplate.name =
ChatColor.DARK_AQUA + "Ender Chestplate" + ChatColor.RESET;
this.chestplate.customItemModel = "ender_chestplate"; this.chestplate.customItemModel = "ender_chestplate";
this.chestplate.customEquipmentModel = "ender"; this.chestplate.customEquipmentModel = "ender";
this.leggings.name = ChatColor.DARK_AQUA + "Ender Leggings" + ChatColor.RESET; this.leggings.name =
ChatColor.DARK_AQUA + "Ender Leggings" + ChatColor.RESET;
this.leggings.customItemModel = "ender_leggings"; this.leggings.customItemModel = "ender_leggings";
this.leggings.customEquipmentModel = "ender"; this.leggings.customEquipmentModel = "ender";
@@ -102,8 +132,10 @@ public class EnderGear extends GenericGearSet implements Listener, CommandExecut
this.sword.lore = "A sword forged from the essence of ender pearls,"; 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.helmet.lore = "A helmet forged from the essence of ender pearls,";
this.chestplate.lore = "A chestplate forged from the essence of ender pearls,"; this.chestplate.lore =
this.leggings.lore = "Leggings forged from the essence of ender pearls,"; "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,"; this.boots.lore = "Boots forged from the essence of ender pearls,";
} }
} }
@@ -1,5 +1,7 @@
package dev.zxq5.fantasysmp.items.gear; package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.getServer;
import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.util.LoreChecker; import dev.zxq5.fantasysmp.util.LoreChecker;
import org.bukkit.Location; import org.bukkit.Location;
@@ -9,17 +11,19 @@ import org.bukkit.World;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import static org.bukkit.Bukkit.getServer; public class LightningSword extends GenericGearSet implements CommandExecutor {
public class LightningSword extends GenericGearSet implements Listener, CommandExecutor {
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
return true; return true;
@@ -28,7 +32,10 @@ public class LightningSword extends GenericGearSet implements Listener, CommandE
@Override @Override
public void registerRecipes() { public void registerRecipes() {
ItemStack sword = this.getSword(); ItemStack sword = this.getSword();
NamespacedKey swordKey = new NamespacedKey("fantasysmp.items", "lightning_sword"); NamespacedKey swordKey = new NamespacedKey(
"fantasysmp.items",
"lightning_sword"
);
ShapedRecipe swordRecipe = new ShapedRecipe(swordKey, sword); ShapedRecipe swordRecipe = new ShapedRecipe(swordKey, sword);
swordRecipe.shape(" N ", " N ", " R "); swordRecipe.shape(" N ", " N ", " R ");
swordRecipe.setIngredient('N', Material.NETHER_STAR); swordRecipe.setIngredient('N', Material.NETHER_STAR);
@@ -37,23 +44,29 @@ public class LightningSword extends GenericGearSet implements Listener, CommandE
} }
@EventHandler @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. // checks that it is a player that is performing the attack.
if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) { if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) {
return; return;
} }
if (!( LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore) )) return;
if ( if (
player.isOnGround() !(LoreChecker.itemLoreContains(
|| player.getVelocity().getY() >= 0 player.getInventory().getItemInMainHand(),
|| player.isClimbing() this.sword.lore
|| player.isInWater() ))
|| player.isInsideVehicle()
|| player.hasPotionEffect(PotionEffectType.BLINDNESS)
) return; ) return;
if (
player.isOnGround() ||
player.getVelocity().getY() >= 0 ||
player.isClimbing() ||
player.isInWater() ||
player.isInsideVehicle() ||
player.hasPotionEffect(PotionEffectType.BLINDNESS)
) return;
Location location = event.getEntity().getLocation(); Location location = event.getEntity().getLocation();
World world = location.getWorld(); World world = location.getWorld();
@@ -64,17 +77,25 @@ public class LightningSword extends GenericGearSet implements Listener, CommandE
} }
@EventHandler @EventHandler
public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event) { public void onEntityDamage(
org.bukkit.event.entity.EntityDamageEvent event
) {
if (event.getEntity() instanceof Player player) { if (event.getEntity() instanceof Player player) {
if (!(event if (
.getDamageSource() !(event
.getDamageType() .getDamageSource()
.getKey() .getDamageType()
.toString() .getKey()
.equals("minecraft:lightning_bolt") .toString()
)) return; .equals("minecraft:lightning_bolt"))
) return;
if (LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore)) { if (
LoreChecker.itemLoreContains(
player.getInventory().getItemInMainHand(),
this.sword.lore
)
) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@@ -83,13 +104,29 @@ public class LightningSword extends GenericGearSet implements Listener, CommandE
@EventHandler @EventHandler
public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent event) { public void onEntityDeath(org.bukkit.event.entity.EntityDeathEvent event) {
if (event.getEntity() instanceof Mob mob) { if (event.getEntity() instanceof Mob) {
if ( if (
event.getDamageSource().getDamageType().getKey().toString().equals("minecraft:lightning_bolt") event
|| event.getDamageSource().getDamageType().getKey().toString().equals("minecraft:on_fire") .getDamageSource()
.getDamageType()
.getKey()
.toString()
.equals("minecraft:lightning_bolt") ||
event
.getDamageSource()
.getDamageType()
.getKey()
.toString()
.equals("minecraft:on_fire")
) { ) {
Entity e = event.getEntity(); Entity e = event.getEntity();
((ExperienceOrb) e.getLocation().getWorld().spawn(e.getLocation(), ExperienceOrb.class)).setExperience(10); ((ExperienceOrb) e
.getLocation()
.getWorld()
.spawn(
e.getLocation(),
ExperienceOrb.class
)).setExperience(10);
} }
} }
} }
@@ -1,23 +1,25 @@
package dev.zxq5.fantasysmp.items.gear; package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.getPluginManager;
import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.items.ItemStats;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import static org.bukkit.Bukkit.getPluginManager; public class PoseidonGear extends GenericGearSet implements CommandExecutor {
public class PoseidonGear extends GenericGearSet implements CommandExecutor, Listener {
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getTrident()); player.getInventory().addItem(this.getTrident());
@@ -48,7 +50,12 @@ public class PoseidonGear extends GenericGearSet implements CommandExecutor, Lis
@Override @Override
public void registerRecipes() { 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() { public void checkPlayerAir() {
@@ -68,26 +75,34 @@ public class PoseidonGear extends GenericGearSet implements CommandExecutor, Lis
this.sword.attackDamage = 10; this.sword.attackDamage = 10;
this.sword.attackSpeed = 1.2f; this.sword.attackSpeed = 1.2f;
this.sword.name = ChatColor.AQUA + "Poseidon's Fury" + ChatColor.RESET; 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.sword.customItemModel = "poseidons_trident";
this.helmet.name = ChatColor.AQUA + "Poseidon's Crown" + ChatColor.RESET; this.helmet.name =
this.helmet.lore = "A helmet granted to those who harness the power of the ocean."; 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.customItemModel = "poseidons_helmet";
this.helmet.customEquipmentModel = "poseidon"; this.helmet.customEquipmentModel = "poseidon";
this.chestplate.name = ChatColor.AQUA + "Poseidon's Chestplate" + ChatColor.RESET; this.chestplate.name =
this.chestplate.lore = "A chestplate granted to those who harness the power of the ocean."; 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.customItemModel = "poseidons_chestplate";
this.chestplate.customEquipmentModel = "poseidon"; this.chestplate.customEquipmentModel = "poseidon";
this.leggings.name = ChatColor.AQUA + "Poseidon's Leggings" + ChatColor.RESET; this.leggings.name =
this.leggings.lore = "Leggings granted to those who harness the power of the ocean."; 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.customItemModel = "poseidons_leggings";
this.leggings.customEquipmentModel = "poseidon"; this.leggings.customEquipmentModel = "poseidon";
this.boots.name = ChatColor.AQUA + "Poseidon's Boots" + ChatColor.RESET; 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.customItemModel = "poseidons_boots";
this.boots.customEquipmentModel = "poseidon"; this.boots.customEquipmentModel = "poseidon";
} }
@@ -6,21 +6,29 @@ import org.bukkit.*;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class StevensWrath extends GenericGearSet implements Listener, CommandExecutor { public class StevensWrath extends GenericGearSet implements CommandExecutor {
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
return true; return true;
} }
@EventHandler @EventHandler
public void onCraft(org.bukkit.event.inventory.PrepareItemCraftEvent event) { public void onCraft(
org.bukkit.event.inventory.PrepareItemCraftEvent event
) {
if (!event.getInventory().contains(Material.NETHERITE_BLOCK)) return; if (!event.getInventory().contains(Material.NETHERITE_BLOCK)) return;
if (!event.getInventory().contains(new LightningSword().getSword())) return; if (
!event.getInventory().contains(new LightningSword().getSword())
) return;
event.getInventory().setResult(new StevensWrath().getSword()); event.getInventory().setResult(new StevensWrath().getSword());
} }
@@ -28,17 +36,24 @@ public class StevensWrath extends GenericGearSet implements Listener, CommandExe
public void registerRecipes() {} public void registerRecipes() {}
@EventHandler @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. // checks that it is a player that is performing the attack.
if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) { if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) {
return; return;
} }
if (!( if (
LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore) !(LoreChecker.itemLoreContains(
|| LoreChecker.itemLoreContains(player.getInventory().getItemInOffHand(), this.sword.lore) player.getInventory().getItemInMainHand(),
)) return; this.sword.lore
) ||
LoreChecker.itemLoreContains(
player.getInventory().getItemInOffHand(),
this.sword.lore
))
) return;
Location location = event.getEntity().getLocation(); Location location = event.getEntity().getLocation();
World world = location.getWorld(); World world = location.getWorld();
@@ -49,19 +64,29 @@ public class StevensWrath extends GenericGearSet implements Listener, CommandExe
} }
@EventHandler @EventHandler
public void onEntityDamage(org.bukkit.event.entity.EntityDamageEvent event) { public void onEntityDamage(
org.bukkit.event.entity.EntityDamageEvent event
) {
if (event.getEntity() instanceof Player player) { if (event.getEntity() instanceof Player player) {
if (
!(event
.getDamageSource()
.getDamageType()
.getKey()
.toString()
.equals("minecraft:lightning_bolt"))
) return;
if (!(event if (
.getDamageSource() LoreChecker.itemLoreContains(
.getDamageType() player.getInventory().getItemInMainHand(),
.getKey() this.sword.lore
.toString() ) ||
.equals("minecraft:lightning_bolt") LoreChecker.itemLoreContains(
)) return; player.getInventory().getItemInOffHand(),
this.sword.lore
if (LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore) || )
LoreChecker.itemLoreContains(player.getInventory().getItemInOffHand(), this.sword.lore)) { ) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@@ -71,8 +96,11 @@ public class StevensWrath extends GenericGearSet implements Listener, CommandExe
public StevensWrath() { public StevensWrath() {
this.setTier6(); this.setTier6();
this.sword.name = ChatColor.LIGHT_PURPLE + "Stevens Wrath" + ChatColor.RESET; this.sword.name =
ChatColor.LIGHT_PURPLE + "Stevens Wrath" + ChatColor.RESET;
this.sword.customItemModel = "stevens_wrath"; this.sword.customItemModel = "stevens_wrath";
this.sword.lore = ChatColor.LIGHT_PURPLE + "All who oppose the mighty Steven shall face his wrath of lightning."; this.sword.lore =
ChatColor.LIGHT_PURPLE +
"All who oppose the mighty Steven shall face his wrath of lightning.";
} }
} }
@@ -4,11 +4,18 @@ import dev.zxq5.fantasysmp.items.GenericGearSet;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public class TrueNetheriteGear extends GenericGearSet implements CommandExecutor, Listener { public class TrueNetheriteGear
extends GenericGearSet
implements CommandExecutor {
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
@@ -24,27 +31,35 @@ public class TrueNetheriteGear extends GenericGearSet implements CommandExecutor
public TrueNetheriteGear() { public TrueNetheriteGear() {
this.setTier6(); this.setTier6();
this.sword.name = ChatColor.WHITE + "True Netherite Sword" + ChatColor.RESET; this.sword.name =
ChatColor.WHITE + "True Netherite Sword" + ChatColor.RESET;
this.sword.lore = "A sword forged with the skulls of wither skeletons."; this.sword.lore = "A sword forged with the skulls of wither skeletons.";
this.sword.customItemModel = "true_netherite_sword"; this.sword.customItemModel = "true_netherite_sword";
this.sword.lore = "Destruction awaits."; this.sword.lore = "Destruction awaits.";
this.helmet.name = ChatColor.WHITE + "True Netherite Helmet" + ChatColor.RESET; this.helmet.name =
this.helmet.lore = "A helmet forged with the skulls of wither skeletons."; ChatColor.WHITE + "True Netherite Helmet" + ChatColor.RESET;
this.helmet.lore =
"A helmet forged with the skulls of wither skeletons.";
this.helmet.customItemModel = "true_netherite_helmet"; this.helmet.customItemModel = "true_netherite_helmet";
this.helmet.customEquipmentModel = "true_netherite"; this.helmet.customEquipmentModel = "true_netherite";
this.chestplate.name = ChatColor.WHITE + "True Netherite Chestplate" + ChatColor.RESET; this.chestplate.name =
this.chestplate.lore = "A chestplate forged with the skulls of wither skeletons."; ChatColor.WHITE + "True Netherite Chestplate" + ChatColor.RESET;
this.chestplate.lore =
"A chestplate forged with the skulls of wither skeletons.";
this.chestplate.customItemModel = "true_netherite_chestplate"; this.chestplate.customItemModel = "true_netherite_chestplate";
this.chestplate.customEquipmentModel = "true_netherite"; this.chestplate.customEquipmentModel = "true_netherite";
this.leggings.name = ChatColor.WHITE + "True Netherite Leggings" + ChatColor.RESET; this.leggings.name =
this.leggings.lore = "Leggings forged with the skulls of wither skeletons."; ChatColor.WHITE + "True Netherite Leggings" + ChatColor.RESET;
this.leggings.lore =
"Leggings forged with the skulls of wither skeletons.";
this.leggings.customItemModel = "true_netherite_leggings"; this.leggings.customItemModel = "true_netherite_leggings";
this.leggings.customEquipmentModel = "true_netherite"; this.leggings.customEquipmentModel = "true_netherite";
this.boots.name = ChatColor.WHITE + "True Netherite Boots" + ChatColor.RESET; this.boots.name =
ChatColor.WHITE + "True Netherite Boots" + ChatColor.RESET;
this.boots.lore = "Boots forged with the skulls of wither skeletons."; this.boots.lore = "Boots forged with the skulls of wither skeletons.";
this.boots.customItemModel = "true_netherite_boots"; this.boots.customItemModel = "true_netherite_boots";
this.boots.customEquipmentModel = "true_netherite"; this.boots.customEquipmentModel = "true_netherite";
@@ -1,14 +1,17 @@
package dev.zxq5.fantasysmp.items.gear; package dev.zxq5.fantasysmp.items.gear;
import static org.bukkit.Bukkit.getServer;
import dev.zxq5.fantasysmp.items.GenericGearSet; import dev.zxq5.fantasysmp.items.GenericGearSet;
import dev.zxq5.fantasysmp.util.LoreChecker; import dev.zxq5.fantasysmp.util.LoreChecker;
import java.util.ArrayList;
import java.util.Objects;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.WitherSkull; import org.bukkit.entity.WitherSkull;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -16,17 +19,17 @@ import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.SmithingTransformRecipe; import org.bukkit.inventory.SmithingTransformRecipe;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import java.util.ArrayList; public class WitheriteGear extends GenericGearSet implements CommandExecutor {
import java.util.Objects;
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<>(); private ArrayList<Player> cooldown = new ArrayList<>();
@Override @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 player = (Player) sender;
player.getInventory().addItem(this.getSword()); player.getInventory().addItem(this.getSword());
player.getInventory().addItem(this.getHelmet()); player.getInventory().addItem(this.getHelmet());
@@ -40,55 +43,115 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
@Override @Override
public void registerRecipes() { public void registerRecipes() {
ItemStack sword = this.getSword(); ItemStack sword = this.getSword();
NamespacedKey swordKey = new NamespacedKey("fantasysmp.items", "witherite_sword"); NamespacedKey swordKey = new NamespacedKey(
RecipeChoice swordChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_SWORD); "fantasysmp.items",
SmithingTransformRecipe swordRecipe = new SmithingTransformRecipe(swordKey, sword, NETHERITE_UPGRADE, swordChoice, WITHER_SKULL); "witherite_sword"
);
RecipeChoice swordChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_SWORD
);
SmithingTransformRecipe swordRecipe = new SmithingTransformRecipe(
swordKey,
sword,
NETHERITE_UPGRADE,
swordChoice,
WITHER_SKULL
);
getServer().addRecipe(swordRecipe); getServer().addRecipe(swordRecipe);
ItemStack helmet = this.getHelmet(); ItemStack helmet = this.getHelmet();
NamespacedKey helmetKey = new NamespacedKey("fantasysmp.items", "witherite_helmet"); NamespacedKey helmetKey = new NamespacedKey(
RecipeChoice helmetChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_HELMET); "fantasysmp.items",
SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(helmetKey, helmet, NETHERITE_UPGRADE, helmetChoice, WITHER_SKULL); "witherite_helmet"
);
RecipeChoice helmetChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_HELMET
);
SmithingTransformRecipe helmetRecipe = new SmithingTransformRecipe(
helmetKey,
helmet,
NETHERITE_UPGRADE,
helmetChoice,
WITHER_SKULL
);
getServer().addRecipe(helmetRecipe); getServer().addRecipe(helmetRecipe);
ItemStack chestplate = this.getChestplate(); ItemStack chestplate = this.getChestplate();
NamespacedKey chestplateKey = new NamespacedKey("fantasysmp.items", "witherite_chestplate"); NamespacedKey chestplateKey = new NamespacedKey(
RecipeChoice chestplateChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_CHESTPLATE); "fantasysmp.items",
SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(chestplateKey, chestplate, NETHERITE_UPGRADE, chestplateChoice, WITHER_SKULL); "witherite_chestplate"
);
RecipeChoice chestplateChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_CHESTPLATE
);
SmithingTransformRecipe chestplateRecipe = new SmithingTransformRecipe(
chestplateKey,
chestplate,
NETHERITE_UPGRADE,
chestplateChoice,
WITHER_SKULL
);
getServer().addRecipe(chestplateRecipe); getServer().addRecipe(chestplateRecipe);
ItemStack leggings = this.getLeggings(); ItemStack leggings = this.getLeggings();
NamespacedKey leggingsKey = new NamespacedKey("fantasysmp.items", "witherite_leggings"); NamespacedKey leggingsKey = new NamespacedKey(
RecipeChoice leggingsChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_LEGGINGS); "fantasysmp.items",
SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(leggingsKey, leggings, NETHERITE_UPGRADE, leggingsChoice, WITHER_SKULL); "witherite_leggings"
);
RecipeChoice leggingsChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_LEGGINGS
);
SmithingTransformRecipe leggingsRecipe = new SmithingTransformRecipe(
leggingsKey,
leggings,
NETHERITE_UPGRADE,
leggingsChoice,
WITHER_SKULL
);
getServer().addRecipe(leggingsRecipe); getServer().addRecipe(leggingsRecipe);
ItemStack boots = this.getBoots(); ItemStack boots = this.getBoots();
NamespacedKey bootsKey = new NamespacedKey("fantasysmp.items", "witherite_boots"); NamespacedKey bootsKey = new NamespacedKey(
RecipeChoice bootsChoice = new RecipeChoice.MaterialChoice(Material.NETHERITE_BOOTS); "fantasysmp.items",
SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(bootsKey, boots, NETHERITE_UPGRADE, bootsChoice, WITHER_SKULL); "witherite_boots"
);
RecipeChoice bootsChoice = new RecipeChoice.MaterialChoice(
Material.NETHERITE_BOOTS
);
SmithingTransformRecipe bootsRecipe = new SmithingTransformRecipe(
bootsKey,
boots,
NETHERITE_UPGRADE,
bootsChoice,
WITHER_SKULL
);
getServer().addRecipe(bootsRecipe); getServer().addRecipe(bootsRecipe);
} }
@EventHandler @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. // checks that it is a player that is performing the attack.
if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) { if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) {
return; return;
} }
if (!LoreChecker.itemLoreContains(player.getInventory().getItemInMainHand(), this.sword.lore)) { if (
!LoreChecker.itemLoreContains(
player.getInventory().getItemInMainHand(),
this.sword.lore
)
) {
return; return;
} }
PotionEffect effect = new PotionEffect( PotionEffect effect = new PotionEffect(
org.bukkit.potion.PotionEffectType.WITHER, org.bukkit.potion.PotionEffectType.WITHER,
20 * 5, 20 * 5,
1 1
); );
effect.apply((LivingEntity) event.getEntity()); effect.apply((LivingEntity) event.getEntity());
} }
@EventHandler @EventHandler
@@ -96,7 +159,10 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack item = event.getItem(); // Get the item the player interacted with 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; return;
} }
@@ -111,26 +177,46 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
cooldown.add(player); cooldown.add(player);
Bukkit.getScheduler().scheduleSyncDelayedTask( Bukkit.getScheduler().scheduleSyncDelayedTask(
Objects.requireNonNull(Bukkit.getPluginManager().getPlugin("fantasysmp")), Objects.requireNonNull(
() -> cooldown.remove(player), Bukkit.getPluginManager().getPlugin("fantasysmp")
25 ),
() -> cooldown.remove(player),
25
); );
} }
@EventHandler @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.getEntity() instanceof Player player) {
if (event.getNewEffect() == null) return; if (event.getNewEffect() == null) return;
if (event.getNewEffect().getType() != org.bukkit.potion.PotionEffectType.WITHER) { if (
event.getNewEffect().getType() !=
org.bukkit.potion.PotionEffectType.WITHER
) {
return; return;
} }
try { try {
if (LoreChecker.itemLoreContains(player.getInventory().getHelmet(), this.helmet.lore) if (
&& LoreChecker.itemLoreContains(player.getInventory().getChestplate(), this.chestplate.lore) LoreChecker.itemLoreContains(
&& LoreChecker.itemLoreContains(player.getInventory().getLeggings(), this.leggings.lore) player.getInventory().getHelmet(),
&& LoreChecker.itemLoreContains(player.getInventory().getBoots(), this.boots.lore) 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); event.setCancelled(true);
} }
@@ -148,18 +234,24 @@ public class WitheriteGear extends GenericGearSet implements Listener, CommandEx
this.sword.lore = "A sword forged with the skulls of wither skeletons."; this.sword.lore = "A sword forged with the skulls of wither skeletons.";
this.sword.customItemModel = "witherite_sword"; this.sword.customItemModel = "witherite_sword";
this.helmet.name = ChatColor.BLACK + "Witherite Helmet" + ChatColor.RESET; this.helmet.name =
this.helmet.lore = "A helmet forged with the skulls of wither skeletons."; 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.customItemModel = "witherite_helmet";
this.helmet.customEquipmentModel = "witherite"; this.helmet.customEquipmentModel = "witherite";
this.chestplate.name = ChatColor.BLACK + "Witherite Chestplate" + ChatColor.RESET; this.chestplate.name =
this.chestplate.lore = "A chestplate forged with the skulls of wither skeletons."; 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.customItemModel = "witherite_chestplate";
this.chestplate.customEquipmentModel = "witherite"; this.chestplate.customEquipmentModel = "witherite";
this.leggings.name = ChatColor.BLACK + "Witherite Leggings" + ChatColor.RESET; this.leggings.name =
this.leggings.lore = "Leggings forged with the skulls of wither skeletons."; ChatColor.BLACK + "Witherite Leggings" + ChatColor.RESET;
this.leggings.lore =
"Leggings forged with the skulls of wither skeletons.";
this.leggings.customItemModel = "witherite_leggings"; this.leggings.customItemModel = "witherite_leggings";
this.leggings.customEquipmentModel = "witherite"; this.leggings.customEquipmentModel = "witherite";
@@ -1,19 +1,15 @@
package dev.zxq5.fantasysmp.warps; 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 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 { public class Warp {
@@ -30,7 +26,12 @@ public class Warp {
private int z; private int z;
public boolean execute(Player player) { 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.setPitch(player.getLocation().getPitch());
location.setYaw(player.getLocation().getYaw()); location.setYaw(player.getLocation().getYaw());
player.teleport(location); player.teleport(location);
@@ -38,7 +39,10 @@ public class Warp {
} }
public static void loadWarps() throws Exception { 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); File file = new File(dataFolder, FILENAME);
if (!file.exists()) { if (!file.exists()) {
@@ -48,17 +52,20 @@ public class Warp {
BufferedReader reader; BufferedReader reader;
reader = new BufferedReader(new FileReader(file)); reader = new BufferedReader(new FileReader(file));
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
warps = gson.fromJson(reader, Warp[].class); warps = gson.fromJson(reader, Warp[].class);
reader.close(); reader.close();
} }
public static void saveWarps() throws Exception { 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); File file = new File(dataFolder, FILENAME);
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(warps); String json = gson.toJson(warps);
Writer writer = new FileWriter(file); Writer writer = new FileWriter(file);
writer.write(json); writer.write(json);
@@ -66,13 +73,16 @@ public class Warp {
} }
public static void createWarpFile() { public static void createWarpFile() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder(); File dataFolder = getServer()
.getPluginManager()
.getPlugin("Fantasysmp")
.getDataFolder();
File file = new File(dataFolder, FILENAME); File file = new File(dataFolder, FILENAME);
if (!file.exists()) { if (!file.exists()) {
try { try {
Warp[] w = new Warp[0]; Warp[] w = new Warp[0];
Gson gson = new Gson(); Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(w); String json = gson.toJson(w);
Writer writer = new FileWriter(file); Writer writer = new FileWriter(file);
writer.write(json); writer.write(json);
@@ -108,10 +118,13 @@ public class Warp {
return null; return null;
} }
public static Warp getTeamWarp(Team team, String name) { public static Warp getTeamWarp(Team team, Player player, String name) {
for (Warp warp : warps) { for (Warp warp : warps) {
if (warp.type.equals(WarpType.TEAM)) { 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; return warp;
} }
} }
@@ -123,7 +136,10 @@ public class Warp {
String message = ChatColor.WHITE + "All Warps: [\n" + ChatColor.GREEN; String message = ChatColor.WHITE + "All Warps: [\n" + ChatColor.GREEN;
for (Warp warp : warps) { 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"; message += " " + warp.name + "\n";
} }
} }
@@ -175,16 +191,3 @@ public class Warp {
} }
} }
} }