This commit is contained in:
FantasyPvP
2025-01-05 18:42:39 +00:00
commit b8f9b7749b
10 changed files with 835 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
# User-specific stuff
.idea/
*.iml
*.ipr
*.iws
# IntelliJ
out/
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
.flattened-pom.xml
# Common working directory
run/
+78
View File
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.zxq5</groupId>
<artifactId>fantasysmp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>fantasysmp</name>
<properties>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.21.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,28 @@
package dev.zxq5.fantasysmp;
import dev.zxq5.fantasysmp.events.StevenKillCheck;
import dev.zxq5.fantasysmp.items.Items;
import dev.zxq5.fantasysmp.items.Witherite;
import dev.zxq5.fantasysmp.warps.Warper;
import org.bukkit.plugin.java.JavaPlugin;
public final class Fantasysmp extends JavaPlugin {
@Override
public void onEnable() {
Items items = new Items(this);
getCommand("items").setExecutor(items);
// Plugin startup logic
getCommand("home").setExecutor(new Warper());
getCommand("sethome").setExecutor(new Warper());
getServer().getPluginManager().registerEvents(new StevenKillCheck(), this);
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}
@@ -0,0 +1,25 @@
package dev.zxq5.fantasysmp.events;
import org.bukkit.Location;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wither;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import static org.bukkit.Bukkit.getServer;
public class StevenKillCheck implements Listener {
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof Chicken && event.getDamager() instanceof Player player) {
Location coords = player.getLocation();
// summon lightning at location
getServer().getWorlds().getFirst().strikeLightning(coords);
}
}
}
@@ -0,0 +1,215 @@
package dev.zxq5.fantasysmp.items;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public abstract class GenericGearSet {
protected int swordAttackDamage = 0;
protected float swordAttackSpeed = 0;
protected int swordDurability = 0;
protected String swordName = "wooden sword";
protected String swordLore = "";
protected int helmetArmour = 0;
protected int helmetArmourToughness = 0;
protected int helmetDurability = 0;
protected String helmetName = "leather cap";
protected String helmetLore = "";
protected int chestplateArmour = 0;
protected int chestplateArmourToughness = 0;
protected int chestplateDurability = 0;
protected String chestplateName = "leather tunic";
protected String chestplateLore = "";
protected int leggingsArmour = 0;
protected int leggingsArmourToughness = 0;
protected int leggingsDurability = 0;
protected String leggingsName = "leather pants";
protected String leggingsLore = "";
protected int bootsArmour = 0;
protected int bootsArmourToughness = 0;
protected int bootsDurability = 0;
protected String bootsName = "leather boots";
protected String bootsLore = "";
public void setTier1() {
swordAttackDamage = 4;
swordAttackSpeed = 1.6f;
// todo: idk
}
public void setTier3() {
swordAttackDamage = 6;
swordAttackSpeed = 1.6f;
helmetArmour = 2;
helmetArmourToughness = 0;
chestplateArmour = 6;
chestplateArmourToughness = 0;
leggingsArmour = 5;
leggingsArmourToughness = 0;
bootsArmour = 2;
bootsArmourToughness = 0;
}
public void setTier4() {
swordAttackDamage = 7;
swordAttackSpeed = 1.6f;
helmetArmour = 3;
helmetArmourToughness = 2;
chestplateArmour = 8;
chestplateArmourToughness = 2;
leggingsArmour = 6;
leggingsArmourToughness = 2;
bootsArmour = 3;
bootsArmourToughness = 2;
}
public void setTier5() {
swordAttackDamage = 8;
swordAttackSpeed = 1.6f;
helmetArmour = 3;
helmetArmourToughness = 3;
chestplateArmour = 8;
chestplateArmourToughness = 3;
leggingsArmour = 6;
leggingsArmourToughness = 3;
bootsArmour = 3;
bootsArmourToughness = 3;
}
public void setTier6() {
swordAttackDamage = 10;
swordAttackSpeed = 1.6f;
helmetArmour = 3;
helmetArmourToughness = 5;
chestplateArmour = 8;
chestplateArmourToughness = 5;
leggingsArmour = 6;
leggingsArmourToughness = 5;
bootsArmour = 3;
bootsArmourToughness = 5;
}
// this must be overridden by the child class.
public static void init() {}
public ItemStack getSword() {
ItemStack item = new ItemStack(Material.WOODEN_SWORD, 1);
ItemMeta meta = item.getItemMeta();
meta.addAttributeModifier(Attribute.ATTACK_DAMAGE, new AttributeModifier(
NamespacedKey.minecraft("generic.attackDamage"),
swordAttackDamage,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.HAND
));
meta.addAttributeModifier(Attribute.ATTACK_SPEED, new AttributeModifier(
NamespacedKey.minecraft("generic.attackSpeed"),
swordAttackSpeed,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.HAND
));
item.setItemMeta(meta);
return item;
}
public ItemStack getHelmet() {
ItemStack item = new ItemStack(Material.LEATHER_HELMET, 1);
ItemMeta meta = item.getItemMeta();
meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier(
NamespacedKey.minecraft("generic.armor"),
helmetArmour,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.HEAD
));
meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier(
NamespacedKey.minecraft("generic.armorToughness"),
helmetArmourToughness,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.HEAD
));
item.setItemMeta(meta);
return item;
}
public ItemStack getChestplate() {
ItemStack item = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
ItemMeta meta = item.getItemMeta();
meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier(
NamespacedKey.minecraft("generic.armor"),
chestplateArmour,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.CHEST
));
meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier(
NamespacedKey.minecraft("generic.armorToughness"),
chestplateArmourToughness,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.CHEST
));
item.setItemMeta(meta);
return item;
}
public ItemStack getLeggings() {
ItemStack item = new ItemStack(Material.LEATHER_LEGGINGS, 1);
ItemMeta meta = item.getItemMeta();
meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier(
NamespacedKey.minecraft("generic.armor"),
leggingsArmour,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.LEGS
));
meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier(
NamespacedKey.minecraft("generic.armorToughness"),
leggingsArmourToughness,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.LEGS
));
item.setItemMeta(meta);
return item;
}
public ItemStack getBoots() {
ItemStack item = new ItemStack(Material.LEATHER_BOOTS, 1);
ItemMeta meta = item.getItemMeta();
meta.addAttributeModifier(Attribute.ARMOR, new AttributeModifier(
NamespacedKey.minecraft("generic.armor"),
bootsArmour,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.FEET
));
meta.addAttributeModifier(Attribute.ARMOR_TOUGHNESS, new AttributeModifier(
NamespacedKey.minecraft("generic.armorToughness"),
bootsArmourToughness,
AttributeModifier.Operation.ADD_NUMBER,
EquipmentSlotGroup.FEET
));
item.setItemMeta(meta);
return item;
}
}
@@ -0,0 +1,52 @@
package dev.zxq5.fantasysmp.items;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wither;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import static org.bukkit.Bukkit.getServer;
public class Items implements CommandExecutor {
@Override
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
Player player = (Player) sender;
if (!(sender instanceof Player)) {
return false;
}
if (!(command.getName().equals("items"))) {
return false;
}
if (args.length != 1) {
return false;
}
if (!(player.hasPermission("fantasysmp.items"))) {
player.sendMessage("You do not have permission to use this command.");
return false;
}
CommandExecutor handler;
switch (args[0]) {
case "witherite" -> handler = new Witherite();
default -> { return false; }
}
handler.onCommand(sender, command, label, args);
return true;
}
public Items(JavaPlugin plugin) {
Witherite.init();
getServer().getPluginManager().registerEvents(new Witherite(), plugin);
}
}
@@ -0,0 +1,87 @@
package dev.zxq5.fantasysmp.items;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.potion.PotionEffect;
public class Witherite extends GenericGearSet implements Listener, CommandExecutor {
@Override
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
if (!(args[0].equals("witherite"))) {
return false;
}
Player player = (Player) sender;
player.getInventory().addItem(new Witherite().getSword());
player.getInventory().addItem(new Witherite().getHelmet());
player.getInventory().addItem(new Witherite().getChestplate());
player.getInventory().addItem(new Witherite().getLeggings());
player.getInventory().addItem(new Witherite().getBoots());
return true;
}
@EventHandler
public void onEntityDamageByEntity(org.bukkit.event.entity.EntityDamageByEntityEvent event) {
// checks that it is a player that is performing the attack.
if (!(event.getDamager() instanceof org.bukkit.entity.Player player)) {
return;
}
try {
if (!player.getInventory().getItemInMainHand().getItemMeta().getLore().toString().contains(this.swordLore)) {
return;
}
} catch (Exception e) {
e.printStackTrace();
return;
}
PotionEffect effect = new PotionEffect(
org.bukkit.potion.PotionEffectType.WITHER,
20 * 5,
1
);
effect.apply((LivingEntity) event.getEntity());
}
@EventHandler
public void onEntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent event) {
if (event.getEntity() instanceof Player player) {
try {
if (player.getInventory().getHelmet().getItemMeta().getLore().toString().contains(this.helmetLore)
&& player.getInventory().getChestplate().getItemMeta().getLore().toString().contains(this.chestplateLore)
&& player.getInventory().getLeggings().getItemMeta().getLore().toString().contains(this.leggingsLore)
&& player.getInventory().getBoots().getItemMeta().getLore().toString().contains(this.bootsLore)) {
event.setCancelled(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void init() {}
public Witherite() {
this.setTier5();
this.swordName = "Witherite Sword";
this.helmetName = "Witherite Helmet";
this.chestplateName = "Witherite Chestplate";
this.leggingsName = "Witherite Leggings";
this.bootsName = "Witherite Boots";
this.swordLore = "A sword forged with the skulls of wither skeletons.";
this.helmetLore = "A helmet forged with the skulls of wither skeletons.";
this.chestplateLore = "A chestplate forged with the skulls of wither skeletons.";
this.leggingsLore = "A leggings forged with the skulls of wither skeletons.";
this.bootsLore = "A boots forged with the skulls of wither skeletons.";
}
}
@@ -0,0 +1,155 @@
package dev.zxq5.fantasysmp.warps;
import com.google.gson.Gson;
import org.bukkit.Location;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
import java.io.*;
import java.util.UUID;
import static org.bukkit.Bukkit.getServer;
public class Warp {
private String setby;
private String world;
private WarpType type;
private int x;
private int y;
private int z;
public boolean execute(Player player) {
Location location = new Location(player.getWorld(), this.x, this.y, this.z);
location.setPitch(player.getLocation().getPitch());
location.setYaw(player.getLocation().getYaw());
player.teleport(location);
return true;
}
public static Warp[] getWarps() throws Exception {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File file = new File(dataFolder, "warps.json");
if (!file.exists()) {
init();
}
BufferedReader reader;
reader = new BufferedReader(new FileReader(file));
Gson gson = new Gson();
Warp[] warps = gson.fromJson(reader, Warp[].class);
reader.close();
return warps;
}
public static void saveWarps(Warp[] warps) throws Exception {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File file = new File(dataFolder, "warps.json");
Gson gson = new Gson();
String json = gson.toJson(warps);
Writer writer = new FileWriter(file);
writer.write(json);
writer.close();
}
public static Warp getHome(UUID uuid) {
String uuidString = uuid.toString();
Warp[] warps;
try {
warps = getWarps();
} catch (Exception e) {
e.printStackTrace();
return null;
}
for (Warp warp : warps) {
if (warp.setby.equals(uuidString)) {
if (warp.type.equals(WarpType.HOME)) {
return warp;
}
return warp;
}
}
return null;
}
public static void init() {
File dataFolder = getServer().getPluginManager().getPlugin("Fantasysmp").getDataFolder();
File file = new File(dataFolder, "warps.json");
if (!file.exists()) {
try {
Warp[] w = new Warp[0];
Gson gson = new Gson();
String json = gson.toJson(w);
Writer writer = new FileWriter(file);
writer.write(json);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void setHome(Player player) {
String uuid = player.getUniqueId().toString();
Warp[] warps;
try {
warps = getWarps();
} catch (Exception e) {
e.printStackTrace();
return;
}
int x, y, z;
x = (int) player.getLocation().getX();
y = (int) player.getLocation().getY();
z = (int) player.getLocation().getZ();
Warp warp = null;
for (Warp w : warps) {
if (w.setby.equals(uuid)) {
warp = w;
break;
}
}
if (warp == null) {
warp = new Warp();
}
warp.type = WarpType.HOME;
warp.setby = uuid;
warp.world = player.getWorld().getName();
warp.x = x;
warp.y = y;
warp.z = z;
warps = new Warp[warps.length + 1];
System.arraycopy(warps, 0, warps, 0, warps.length - 1);
warps[warps.length - 1] = warp;
try {
saveWarps(warps);
} catch (Exception e) {
e.printStackTrace();
}
return;
}
}
enum WarpType {
HOME,
PUBLIC,
DEATH,
TEAM,
}
@@ -0,0 +1,37 @@
package dev.zxq5.fantasysmp.warps;
import org.bukkit.command.CommandExecutor;
import org.bukkit.entity.Player;
public class Warper implements CommandExecutor {
@Override
public boolean onCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
return false;
}
if (command.getName().equals("home")) {
if (args.length != 0) {
player.sendMessage("Usage: /home");
return true;
}
Warp warp = Warp.getHome(player.getUniqueId());
if (warp != null) {
warp.execute(player);
}
}
if (command.getName().equals("sethome")) {
if (args.length != 0) {
player.sendMessage("Usage: /sethome");
return true;
}
Warp.setHome(player);
}
return true;
}
}
+45
View File
@@ -0,0 +1,45 @@
name: fantasysmp
version: '1.0-SNAPSHOT'
main: dev.zxq5.fantasysmp.Fantasysmp
api-version: '1.21'
authors: [ zxq5 ]
description: plugin for fantasysmp
website: https://zxq5.dev
commands:
items:
description: create custom items from plugin
usage: /items <set name>
home:
description: teleport to your home
usage: /home
permission: fantasysmp.home
sethome:
description: set your home
usage: /sethome
permission: fantasysmp.home
permissions:
fantasysmp.admin:
description: Manage plugin
default: op
children:
fantasysmp.*: true
fantasysmp.items:
description: create custom items from plugin
default: false
fantasysmp.warps:
description: create custom warps from plugin
default: false
fantasysmp.manage_warps:
description: commands for managing warps
default: false
fantasysmp.home:
description: commands for teleporting home
default: true