mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-03 22:21:12 +00:00
feat: add commandapi
This commit is contained in:
6 files changed
+200
-26
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.github.alathra</groupId>
|
<groupId>com.github.alathra</groupId>
|
||||||
<artifactId>SiegeEngines</artifactId>
|
<artifactId>SiegeEngines</artifactId>
|
||||||
<version>0.3.0</version>
|
<version>0.4.0</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>SiegeEngines</name>
|
<name>SiegeEngines</name>
|
||||||
@@ -63,6 +63,30 @@
|
|||||||
<version>5.0.0</version>
|
<version>5.0.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>dev.jorel</groupId>
|
||||||
|
<artifactId>commandapi-bukkit-shade</artifactId>
|
||||||
|
<version>9.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.milkdrinkers</groupId>
|
||||||
|
<artifactId>colorparser</artifactId>
|
||||||
|
<version>2.0.0</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.intellij.lang.annotations</groupId>
|
||||||
|
<artifactId>*</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.jetbrains.lang.annotations</groupId>
|
||||||
|
<artifactId>*</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>*</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -84,6 +108,7 @@
|
|||||||
<version>3.5.0</version>
|
<version>3.5.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
|
<id>shade</id>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
@@ -101,6 +126,16 @@
|
|||||||
</excludes>
|
</excludes>
|
||||||
</filter>
|
</filter>
|
||||||
</filters>
|
</filters>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>dev.jorel.commandapi</pattern>
|
||||||
|
<shadedPattern>${project.groupId}.siegeengines.libs.commandapi</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.github.milkdrinkers.colorparser</pattern>
|
||||||
|
<shadedPattern>${project.groupId}.siegeengines.libs.colorparser</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ public class GunnerEquipment implements Cloneable {
|
|||||||
return (GunnerEquipment) super.clone();
|
return (GunnerEquipment) super.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean equals(String EquipmentId) {
|
||||||
|
return this.EquipmentId.equals(EquipmentId);
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean Enabled = true;
|
public Boolean Enabled = true;
|
||||||
public UUID EntityId;
|
public UUID EntityId;
|
||||||
public Entity Entity;
|
public Entity Entity;
|
||||||
@@ -38,6 +42,7 @@ public class GunnerEquipment implements Cloneable {
|
|||||||
|
|
||||||
public String WorldName;
|
public String WorldName;
|
||||||
public String EquipmentName = "Peckle Gun";
|
public String EquipmentName = "Peckle Gun";
|
||||||
|
public String EquipmentId = this.EquipmentName.replaceAll(" ", "_").toLowerCase();
|
||||||
public int XOffset = 7;
|
public int XOffset = 7;
|
||||||
public int YOffset = 0;
|
public int YOffset = 0;
|
||||||
public int PitchOffset = 0;
|
public int PitchOffset = 0;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.Random;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.github.alathra.siegeengines.command.CommandHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -52,34 +53,19 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
public static MetadataValueAdapter metadata;
|
public static MetadataValueAdapter metadata;
|
||||||
public static Random random = new Random();
|
public static Random random = new Random();
|
||||||
private static String Path;
|
private static String Path;
|
||||||
|
private CommandHandler commandHandler;
|
||||||
//public static Towny towny;
|
//public static Towny towny;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onLoad() {
|
||||||
for (GunnerEquipment equip : equipment.values()) {
|
plugin = this;
|
||||||
if (equip.Entity != null) {
|
commandHandler = new CommandHandler(this);
|
||||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
commandHandler.onLoad();
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
equip.AmmoHolder = new EquipmentMagazine();
|
|
||||||
|
|
||||||
meta.setCustomModelData(equip.ReadyModelNumber);
|
|
||||||
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
|
|
||||||
List<String> Lore = new ArrayList<String>();
|
|
||||||
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
|
|
||||||
meta.setLore(Lore);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
plugin = this;
|
|
||||||
Path = this.getDataFolder().getAbsolutePath();
|
Path = this.getDataFolder().getAbsolutePath();
|
||||||
this.getCommand("SiegeEngines").setExecutor(new GunnersCommand());
|
this.getCommand("SiegeEngines").setExecutor(new GunnersCommand());
|
||||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||||
@@ -98,6 +84,29 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
System.out.println("§eWeapon Projectile ItemStacks : " + proj);
|
System.out.println("§eWeapon Projectile ItemStacks : " + proj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
commandHandler.onEnable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
commandHandler.onDisable();
|
||||||
|
for (GunnerEquipment equip : equipment.values()) {
|
||||||
|
if (equip.Entity != null) {
|
||||||
|
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
equip.AmmoHolder = new EquipmentMagazine();
|
||||||
|
|
||||||
|
meta.setCustomModelData(equip.ReadyModelNumber);
|
||||||
|
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
|
||||||
|
List<String> Lore = new ArrayList<String>();
|
||||||
|
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
|
||||||
|
meta.setLore(Lore);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FixedMetadataValue addMetaDataValue(Object value) {
|
public static FixedMetadataValue addMetaDataValue(Object value) {
|
||||||
@@ -215,6 +224,7 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
if (fuelVelocityMod == null)
|
if (fuelVelocityMod == null)
|
||||||
fuelVelocityMod = 0.95f;
|
fuelVelocityMod = 0.95f;
|
||||||
equip.EquipmentName = name;
|
equip.EquipmentName = name;
|
||||||
|
equip.EquipmentId = equip.EquipmentName.replaceAll(" ", "_").toLowerCase();
|
||||||
equip.XOffset = XOffset;
|
equip.XOffset = XOffset;
|
||||||
equip.YOffset = YOffset;
|
equip.YOffset = YOffset;
|
||||||
equip.RotateStandHead = true;
|
equip.RotateStandHead = true;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.github.alathra.siegeengines.command;
|
||||||
|
|
||||||
|
import com.github.alathra.siegeengines.SiegeEngines;
|
||||||
|
import dev.jorel.commandapi.CommandAPI;
|
||||||
|
import dev.jorel.commandapi.CommandAPIBukkitConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class to handle registration of commands.
|
||||||
|
*/
|
||||||
|
public class CommandHandler {
|
||||||
|
private final SiegeEngines instance;
|
||||||
|
|
||||||
|
public CommandHandler(SiegeEngines instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onLoad() {
|
||||||
|
CommandAPI.onLoad(new CommandAPIBukkitConfig(instance).shouldHookPaperReload(true).silentLogs(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEnable() {
|
||||||
|
CommandAPI.onEnable();
|
||||||
|
|
||||||
|
// Register commands here
|
||||||
|
new SiegeEnginesCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDisable() {
|
||||||
|
CommandAPI.onDisable();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.github.alathra.siegeengines.command;
|
||||||
|
|
||||||
|
import com.github.alathra.siegeengines.GunnerEquipment;
|
||||||
|
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
|
||||||
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
|
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||||
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
|
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
|
||||||
|
import dev.jorel.commandapi.arguments.PlayerArgument;
|
||||||
|
import dev.jorel.commandapi.arguments.StringArgument;
|
||||||
|
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||||
|
import dev.jorel.commandapi.executors.CommandArguments;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.github.alathra.siegeengines.SiegeEngines.*;
|
||||||
|
|
||||||
|
public class SiegeEnginesCommand {
|
||||||
|
public SiegeEnginesCommand() {
|
||||||
|
new CommandAPICommand("siegeengines")
|
||||||
|
.withFullDescription("Example command.")
|
||||||
|
.withShortDescription("Example command.")
|
||||||
|
.withPermission("siegeengines.command")
|
||||||
|
.withSubcommands(
|
||||||
|
commandGetAll(),
|
||||||
|
commandReload()
|
||||||
|
)
|
||||||
|
.executesPlayer(this::onExecute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onExecute(CommandSender sender, CommandArguments args) {
|
||||||
|
sender.sendMessage(ColorParser.of("<yellow>Incorrect usage, /SiegeEngines get, /SiegeEngines reload").build());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommandAPICommand commandGetAll() {
|
||||||
|
return new CommandAPICommand("getAll")
|
||||||
|
.withPermission("siegeengines.command.getAll")
|
||||||
|
.executesPlayer(this::onGetAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommandAPICommand commandReload() {
|
||||||
|
return new CommandAPICommand("reload")
|
||||||
|
.withPermission("siegeengines.command.reload")
|
||||||
|
.executesPlayer(this::onReload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onGetAll(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||||
|
if (!(sender instanceof Player player))
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
||||||
|
|
||||||
|
for (GunnerEquipment i : DefinedEquipment.values()) {
|
||||||
|
giveEquipment(player, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onReload(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
|
||||||
|
if (!(sender instanceof Player))
|
||||||
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
||||||
|
|
||||||
|
equipment.clear();
|
||||||
|
TrackedStands.clear();
|
||||||
|
DefinedEquipment.clear();
|
||||||
|
AddDefaults();
|
||||||
|
HashMap<ItemStack, GunnersProjectile> projObj = new HashMap<>();
|
||||||
|
GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
|
||||||
|
for (GunnerEquipment i : DefinedEquipment.values()) {
|
||||||
|
sender.sendMessage(ColorParser.of("<yellow>Enabled Weapon : %s".formatted(i.EquipmentName)).build());
|
||||||
|
sender.sendMessage(ColorParser.of("<yellow>Weapon Propellant/\"Fuel\" ItemStacks : %s".formatted(i.FuelMaterial)).build());
|
||||||
|
for (ItemStack proj : i.Projectiles.keySet()) {
|
||||||
|
sender.sendMessage(ColorParser.of("<yellow>Weapon Projectile ItemStacks : %s".formatted(proj)).build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender.sendMessage("<yellow>Gunners Core configs reloaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void giveEquipment(Player player, GunnerEquipment gunnerEquipment) {
|
||||||
|
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
meta.setCustomModelData(gunnerEquipment.ReadyModelNumber);
|
||||||
|
meta.displayName(ColorParser.of("<yellow>%s Item".formatted(gunnerEquipment.EquipmentName)).build());
|
||||||
|
List<Component> lore = new ArrayList<>();
|
||||||
|
lore.add(ColorParser.of("<yellow>Place as a block to spawn a '%s'".formatted(gunnerEquipment.EquipmentName)).build());
|
||||||
|
lore.add(ColorParser.of("<yellow>or put on an Armor Stand.").build());
|
||||||
|
lore.add(ColorParser.of("<yellow>Right click to toggle visibility of stand.").build());
|
||||||
|
meta.lore(lore);
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
player.getInventory().addItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,3 @@ version: "${project.version}"
|
|||||||
api-version: "1.19"
|
api-version: "1.19"
|
||||||
libraries:
|
libraries:
|
||||||
- org.apache.commons:commons-math3:3.6.1
|
- org.apache.commons:commons-math3:3.6.1
|
||||||
commands:
|
|
||||||
SiegeEngines:
|
|
||||||
description: "SiegeEngines Commands"
|
|
||||||
default: false
|
|
||||||
usage: "SiegeEngines"
|
|
||||||
Reference in new issue
Block a user