command manager

This commit is contained in:
NK 2022-11-14 21:13:35 +00:00
parent 786bb682d7
commit 1a0f33dcdb
7 changed files with 126 additions and 107 deletions

34
pom.xml
View file

@ -54,39 +54,6 @@
<outputDirectory>E:\Files\SB\plugins</outputDirectory> <outputDirectory>E:\Files\SB\plugins</outputDirectory>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:1.19.2-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
<resources> <resources>
<resource> <resource>
@ -111,7 +78,6 @@
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version> <version>1.19.2-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -35,20 +35,7 @@ public final class Main extends JavaPlugin implements Listener {
public void onEnable() { public void onEnable() {
getConfig().options().copyDefaults(); getConfig().options().copyDefaults();
saveDefaultConfig(); saveDefaultConfig();
new VanishCommand(); new CommandManager(this).register();
new TestCommand();
new AnvilCommand();
new ArmorCommand();
new MenuCommand();
new MessageCommand();
new HologramCommand();
new CraftCommand();
new EnchantingCommand();
new BetaCommand();
new RankCommand(this);
new UtilCommand(this);
new WeaponCommand(this);
new MinerCommand(this);
bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12); bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12);
Bukkit.getPluginManager().registerEvents(this, this); Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new MenuListener(), this); Bukkit.getPluginManager().registerEvents(new MenuListener(), this);
@ -67,7 +54,6 @@ public final class Main extends JavaPlugin implements Listener {
public void onJoin(PlayerJoinEvent e) { public void onJoin(PlayerJoinEvent e) {
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§1NOT ENOUGH MANNER")); e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§1NOT ENOUGH MANNER"));
bossbar.addPlayer(e.getPlayer()); bossbar.addPlayer(e.getPlayer());
} }
@EventHandler @EventHandler

View file

@ -1,31 +1,48 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
import net.minecraft.network.protocol.game.ClientboundSetHealthPacket; import me.night.nullvalkyrie.Main;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import net.minecraft.network.protocol.game.*;
import net.minecraft.server.level.EntityPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static me.night.nullvalkyrie.database.Client.getUser; import static me.night.nullvalkyrie.database.Client.getUser;
public class BetaCommand extends Command { public class BetaCommand extends Command {
public BetaCommand() { private Main main;
super(
"beta", public BetaCommand(Main main) {
new String[]{"b"}, super("beta", new String[]{"b"}, "Beta", "");
"Beta", this.main = main;
""
);
} }
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
getUser("Kaly15"); getUser("Kaly15");
if (sender instanceof Player) { if (sender instanceof Player) {
CraftPlayer p = (CraftPlayer) sender; Player pa = (Player) sender;
ClientboundSetHealthPacket packet = new ClientboundSetHealthPacket(19.5f, 20, 0.0f); CraftPlayer cp = (CraftPlayer) sender;
p.getHandle().connection.send(packet); EntityPlayer ep = cp.getHandle();
Entity e = (Entity) ep;
PacketPlayOutUpdateHealth packet = new PacketPlayOutUpdateHealth(20f, 20, 5.0f); // health, food, food
// saturation
ep.b.a(packet); // Sends the Packet
new BukkitRunnable() {
@Override
public void run() {
pa.spigot().sendMessage(ChatMessageType.ACTION_BAR,
TextComponent.fromLegacyText("§1NOT ENOUGH MANNER"));
}
}.runTaskTimer(main, 0L, 10);
} }
} }

View file

@ -17,7 +17,6 @@ public abstract class Command extends BukkitCommand {
this.setAliases(Arrays.asList(aliases)); this.setAliases(Arrays.asList(aliases));
this.setDescription(description); this.setDescription(description);
this.setPermission(permission); this.setPermission(permission);
this.setPermission(ChatColor.RED + "You must have" + permission + "in order to use this command");
try { try {
Field field = Bukkit.getServer().getClass().getDeclaredField("commandMap"); Field field = Bukkit.getServer().getClass().getDeclaredField("commandMap");

View file

@ -0,0 +1,26 @@
package me.night.nullvalkyrie.commands;
import me.night.nullvalkyrie.Main;
public class CommandManager {
private Main main;
public CommandManager(Main main) {
this.main = main;
}
public void register() {
new VanishCommand();
new TestCommand();
new AnvilCommand();
new ArmorCommand();
new MenuCommand();
new MessageCommand();
new HologramCommand();
new CraftCommand();
new EnchantingCommand();
new BetaCommand(main);
new RankCommand(main);
new UtilCommand(main);
new WeaponCommand(main);
new MinerCommand(main);
}
}

View file

@ -24,9 +24,11 @@ import java.util.*;
public class CustomItemEvents implements Listener { public class CustomItemEvents implements Listener {
private Main main; private Main main;
public CustomItemEvents(Main main) { public CustomItemEvents(Main main) {
this.main = main; this.main = main;
} }
@EventHandler @EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) { public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
if (e.getDamager().getType().equals(EntityType.SNOWBALL)) { if (e.getDamager().getType().equals(EntityType.SNOWBALL)) {
@ -76,6 +78,7 @@ public class CustomItemEvents implements Listener {
} }
} }
} }
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent e) { public void onPlayerInteract(PlayerInteractEvent e) {
Player player = e.getPlayer(); Player player = e.getPlayer();
@ -147,6 +150,7 @@ public class CustomItemEvents implements Listener {
} }
} }
} }
@EventHandler @EventHandler
public void onEntityShoot(EntityShootBowEvent e) { public void onEntityShoot(EntityShootBowEvent e) {
if (e.getProjectile() instanceof Arrow) { if (e.getProjectile() instanceof Arrow) {
@ -163,6 +167,7 @@ public class CustomItemEvents implements Listener {
} }
} }
} }
@EventHandler @EventHandler
public void onProjectileHit(ProjectileHitEvent e) { public void onProjectileHit(ProjectileHitEvent e) {
if (e.getEntity().getShooter() instanceof Player) { if (e.getEntity().getShooter() instanceof Player) {
@ -188,12 +193,14 @@ public class CustomItemEvents implements Listener {
} }
} }
@EventHandler @EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) { if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler @EventHandler
public void Projectile(ProjectileLaunchEvent e) { public void Projectile(ProjectileLaunchEvent e) {
if (e.getEntity().getShooter() instanceof Player) { if (e.getEntity().getShooter() instanceof Player) {
@ -207,6 +214,7 @@ public class CustomItemEvents implements Listener {
} }
} }
} }
@EventHandler @EventHandler
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent e) { public void onPlayerBucketEmpty(PlayerBucketEmptyEvent e) {
int x = e.getBlockClicked().getX() + e.getBlockFace().getModX(); int x = e.getBlockClicked().getX() + e.getBlockFace().getModX();
@ -224,8 +232,10 @@ public class CustomItemEvents implements Listener {
} }
} }
} }
private Location l; private Location l;
private boolean spawnable = false; private boolean spawnable = false;
@EventHandler @EventHandler
public void onDamage(EntityDamageByEntityEvent e) { public void onDamage(EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Player) { if (e.getEntity() instanceof Player) {
@ -235,7 +245,9 @@ public class CustomItemEvents implements Listener {
Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation(); Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation();
player.teleport(loc); player.teleport(loc);
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
p.sendMessage(e.getDamager() instanceof Player ? ChatColor.RED + player.getName() + " has been killed by " + e.getDamager().getName() : ChatColor.RED + player.getName() + " died"); p.sendMessage(e.getDamager() instanceof Player
? ChatColor.RED + player.getName() + " has been killed by " + e.getDamager().getName()
: ChatColor.RED + player.getName() + " died");
p.hidePlayer(player); p.hidePlayer(player);
} }
new BukkitRunnable() { new BukkitRunnable() {
@ -260,19 +272,26 @@ public class CustomItemEvents implements Listener {
} }
} }
public Location generateRandomCoord(int size, World world) { public Location generateRandomCoord(int size, World world) {
int ranX = SpawnCommand.getRandomWithNeg(size), ranZ = SpawnCommand.getRandomWithNeg(size); int ranX = SpawnCommand.getRandomWithNeg(size), ranZ = SpawnCommand.getRandomWithNeg(size);
Block block = world.getHighestBlockAt(ranX, ranZ); Block block = world.getHighestBlockAt(ranX, ranZ);
return block.getLocation(); return block.getLocation();
} }
public boolean isSpawnable(Location loc) { public boolean isSpawnable(Location loc) {
Block feetBlock = loc.getBlock(), headBlock = loc.clone().add(0, 1, 0).getBlock(), upperBlock = loc.clone().add(0, 2, 0).getBlock(); Block feetBlock = loc.getBlock(), headBlock = loc.clone().add(0, 1, 0).getBlock(),
return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid() && upperBlock.isPassable() && !upperBlock.isLiquid(); upperBlock = loc.clone().add(0, 2, 0).getBlock();
return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid()
&& upperBlock.isPassable() && !upperBlock.isLiquid();
} }
private int taskID; private int taskID;
public void run(Player player, int[] a) { public void run(Player player, int[] a) {
taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> { taskID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main, () -> {
player.sendTitle(ChatColor.RED +"YOU DIED!",ChatColor.GREEN +"You will revive in " + a[0] + " seconds",0,20,0); player.sendTitle(ChatColor.RED + "YOU DIED!", ChatColor.GREEN + "You will revive in " + a[0] + " seconds",
0, 20, 0);
a[0]--; a[0]--;
if (a[0] == 0) { if (a[0] == 0) {
Bukkit.getScheduler().cancelTask(taskID); Bukkit.getScheduler().cancelTask(taskID);
@ -281,12 +300,14 @@ public class CustomItemEvents implements Listener {
} }
private final Map<UUID, Merchant> villagerlist = new HashMap<>(); private final Map<UUID, Merchant> villagerlist = new HashMap<>();
@EventHandler @EventHandler
public void onClick(PlayerInteractEntityEvent e) { public void onClick(PlayerInteractEntityEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
Entity clickedEntity = e.getRightClicked(); Entity clickedEntity = e.getRightClicked();
if (clickedEntity instanceof Creeper) { if (clickedEntity instanceof Creeper) {
if (p.getInventory().getItemInMainHand().getType() != Material.STICK) return; if (p.getInventory().getItemInMainHand().getType() != Material.STICK)
return;
clickedEntity.remove(); clickedEntity.remove();
Location loc = clickedEntity.getLocation(); Location loc = clickedEntity.getLocation();
Villager villager = (Villager) p.getWorld().spawnEntity(loc, EntityType.VILLAGER); Villager villager = (Villager) p.getWorld().spawnEntity(loc, EntityType.VILLAGER);
@ -309,7 +330,8 @@ public class CustomItemEvents implements Listener {
} }
if (e.getRightClicked() instanceof Villager) { if (e.getRightClicked() instanceof Villager) {
Merchant merchant = villagerlist.get(clickedEntity.getUniqueId()); Merchant merchant = villagerlist.get(clickedEntity.getUniqueId());
if (merchant == null) return; if (merchant == null)
return;
e.setCancelled(true); e.setCancelled(true);
p.openMerchant(merchant, true); p.openMerchant(merchant, true);
} }

View file

@ -5,3 +5,6 @@ api-version: 1.18
authors: [ NightKaly, Leocthl ] authors: [ NightKaly, Leocthl ]
description: Null Valkyrie description: Null Valkyrie
website: https://github.com/night0721/nullvalkyrie website: https://github.com/night0721/nullvalkyrie
permissions:
nv.command.use:
default: true