initial
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user