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>
</configuration>
</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>
<resources>
<resource>
@ -111,7 +78,6 @@
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
<dependency>

View file

@ -35,20 +35,7 @@ public final class Main extends JavaPlugin implements Listener {
public void onEnable() {
getConfig().options().copyDefaults();
saveDefaultConfig();
new VanishCommand();
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);
new CommandManager(this).register();
bossbar = Bukkit.createBossBar(ChatColor.GOLD + "Kuudra", BarColor.RED, BarStyle.SEGMENTED_12);
Bukkit.getPluginManager().registerEvents(this, this);
Bukkit.getPluginManager().registerEvents(new MenuListener(), this);
@ -67,7 +54,6 @@ public final class Main extends JavaPlugin implements Listener {
public void onJoin(PlayerJoinEvent e) {
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("§1NOT ENOUGH MANNER"));
bossbar.addPlayer(e.getPlayer());
}
@EventHandler

View file

@ -1,31 +1,48 @@
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.craftbukkit.v1_19_R1.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.List;
import static me.night.nullvalkyrie.database.Client.getUser;
public class BetaCommand extends Command {
public BetaCommand() {
super(
"beta",
new String[]{"b"},
"Beta",
""
);
private Main main;
public BetaCommand(Main main) {
super("beta", new String[]{"b"}, "Beta", "");
this.main = main;
}
@Override
public void onCommand(CommandSender sender, String[] args) {
getUser("Kaly15");
if(sender instanceof Player) {
CraftPlayer p = (CraftPlayer) sender;
ClientboundSetHealthPacket packet = new ClientboundSetHealthPacket(19.5f, 20, 0.0f);
p.getHandle().connection.send(packet);
if (sender instanceof Player) {
Player pa = (Player) sender;
CraftPlayer cp = (CraftPlayer) sender;
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.setDescription(description);
this.setPermission(permission);
this.setPermission(ChatColor.RED + "You must have" + permission + "in order to use this command");
try {
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 {
private Main main;
public CustomItemEvents(Main main) {
this.main = main;
}
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
if (e.getDamager().getType().equals(EntityType.SNOWBALL)) {
@ -47,7 +49,7 @@ public class CustomItemEvents implements Listener {
Player player = (Player) e.getDamager();
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if(name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Fabled Widow Sword")) {
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Fabled Widow Sword")) {
if (e.getEntity() instanceof Zombie) {
int zombie = CustomItemManager.loadConfig("ItemData\\WidowSword.yml").getInt("zombie");
e.setDamage(e.getDamage() * (1 + zombie / 100));
@ -69,13 +71,14 @@ public class CustomItemEvents implements Listener {
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(Rarity.RARE.getColor() + "Grappling Hook")) {
if(e.getState().equals(PlayerFishEvent.State.REEL_IN)) {
if (e.getState().equals(PlayerFishEvent.State.REEL_IN)) {
Location change = e.getHook().getLocation().subtract(player.getLocation());
player.setVelocity(change.toVector().multiply(0.4));
}
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
Player player = e.getPlayer();
@ -112,7 +115,7 @@ public class CustomItemEvents implements Listener {
a2.setShooter(player);
a2.setDamage(50);
e.setCancelled(true);
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
arrow.setVelocity(arrow.getVelocity().multiply(5));
arrow.setShooter(player);
@ -137,7 +140,7 @@ public class CustomItemEvents implements Listener {
a2.setShooter(player);
a2.setDamage(50);
e.setCancelled(true);
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
Arrow arrow = player.launchProjectile(Arrow.class, player.getEyeLocation().getDirection());
arrow.setVelocity(arrow.getVelocity().multiply(5));
arrow.setShooter(player);
@ -147,6 +150,7 @@ public class CustomItemEvents implements Listener {
}
}
}
@EventHandler
public void onEntityShoot(EntityShootBowEvent e) {
if (e.getProjectile() instanceof Arrow) {
@ -156,29 +160,30 @@ public class CustomItemEvents implements Listener {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(Rarity.MYTHIC.getColor() + "Terminator")) {
e.setCancelled(true);
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
e.setCancelled(true);
}
}
}
}
}
@EventHandler
public void onProjectileHit(ProjectileHitEvent e) {
if(e.getEntity().getShooter() instanceof Player) {
if (e.getEntity().getShooter() instanceof Player) {
Player shooter = (Player) e.getEntity().getShooter();
if(shooter.getInventory().getItemInMainHand().getItemMeta() != null) {
if (shooter.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = shooter.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
if(e.getHitBlock() == null) {
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
if (e.getHitBlock() == null) {
Location l = e.getHitEntity().getLocation();
e.getEntity().setShooter(shooter);
e.getHitEntity().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
} else if(e.getHitEntity() == null) {
e.getHitEntity().getWorld().createExplosion(l.getX(), l.getY(), l.getZ(), 100, false, false);
} else if (e.getHitEntity() == null) {
Location l = e.getHitBlock().getLocation();
e.getHitBlock().getWorld().createExplosion(l.getX(),l.getY(),l.getZ(),100,false,false);
e.getHitBlock().getWorld().createExplosion(l.getX(), l.getY(), l.getZ(), 100, false, false);
}
} else if(name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
} else if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Explosive Bow")) {
Arrow arrow = (Arrow) e.getEntity();
Location al = arrow.getLocation();
arrow.setShooter(shooter);
@ -188,17 +193,19 @@ public class CustomItemEvents implements Listener {
}
}
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.EGG) {
event.setCancelled(true);
}
}
@EventHandler
public void Projectile(ProjectileLaunchEvent e) {
if(e.getEntity().getShooter() instanceof Player) {
if (e.getEntity().getShooter() instanceof Player) {
Player player = (Player) e.getEntity().getShooter();
if(player.getInventory().getItemInMainHand().getItemMeta() != null) {
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(Rarity.LEGENDARY.getColor() + "Frag Grenade")) {
Egg s = (Egg) e.getEntity();
@ -207,35 +214,40 @@ public class CustomItemEvents implements Listener {
}
}
}
@EventHandler
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent e) {
int x = e.getBlockClicked().getX() + e.getBlockFace().getModX();
int y = e.getBlockClicked().getY() + e.getBlockFace().getModY();
int z = e.getBlockClicked().getZ() + e.getBlockFace().getModZ();
Player player = e.getPlayer();
if(player.getInventory().getItemInMainHand().getItemMeta() != null) {
if (player.getInventory().getItemInMainHand().getItemMeta() != null) {
String name = player.getInventory().getItemInMainHand().getItemMeta().getDisplayName();
if (name.equalsIgnoreCase(Rarity.EPIC.getColor() + "Infinite Water Bucket")) {
e.getPlayer().getWorld().getBlockAt(x,y,z).setType(Material.WATER);
e.getPlayer().getWorld().getBlockAt(x, y, z).setType(Material.WATER);
e.setCancelled(true);
} else if (name.equalsIgnoreCase(Rarity.EPIC.getColor() + "Infinite LAVA Bucket")) {
e.getPlayer().getWorld().getBlockAt(x,y,z).setType(Material.LAVA);
e.getPlayer().getWorld().getBlockAt(x, y, z).setType(Material.LAVA);
e.setCancelled(true);
}
}
}
private Location l;
private boolean spawnable = false;
@EventHandler
public void onDamage(EntityDamageByEntityEvent e) {
if(e.getEntity() instanceof Player) {
if (e.getEntity() instanceof Player) {
Player player = (Player) e.getEntity();
if((player.getHealth() - e.getDamage()) <= 0) {
if ((player.getHealth() - e.getDamage()) <= 0) {
e.setCancelled(true);
Location loc = player.getWorld().getBlockAt(-3,23,-3).getLocation();
Location loc = player.getWorld().getBlockAt(-3, 23, -3).getLocation();
player.teleport(loc);
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);
}
new BukkitRunnable() {
@ -260,19 +272,26 @@ public class CustomItemEvents implements Listener {
}
}
public Location generateRandomCoord(int size, World world) {
int ranX = SpawnCommand.getRandomWithNeg(size), ranZ = SpawnCommand.getRandomWithNeg(size);
Block block = world.getHighestBlockAt(ranX, ranZ);
return block.getLocation();
}
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();
return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid() && upperBlock.isPassable() && !upperBlock.isLiquid();
Block feetBlock = loc.getBlock(), headBlock = loc.clone().add(0, 1, 0).getBlock(),
upperBlock = loc.clone().add(0, 2, 0).getBlock();
return feetBlock.isPassable() && !feetBlock.isLiquid() && headBlock.isPassable() && !headBlock.isLiquid()
&& upperBlock.isPassable() && !upperBlock.isLiquid();
}
private int taskID;
public void run(Player player, int[] a) {
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]--;
if (a[0] == 0) {
Bukkit.getScheduler().cancelTask(taskID);
@ -281,12 +300,14 @@ public class CustomItemEvents implements Listener {
}
private final Map<UUID, Merchant> villagerlist = new HashMap<>();
@EventHandler
public void onClick(PlayerInteractEntityEvent e) {
Player p = e.getPlayer();
Entity clickedEntity = e.getRightClicked();
if (clickedEntity instanceof Creeper) {
if (p.getInventory().getItemInMainHand().getType() != Material.STICK) return;
if (p.getInventory().getItemInMainHand().getType() != Material.STICK)
return;
clickedEntity.remove();
Location loc = clickedEntity.getLocation();
Villager villager = (Villager) p.getWorld().spawnEntity(loc, EntityType.VILLAGER);
@ -309,7 +330,8 @@ public class CustomItemEvents implements Listener {
}
if (e.getRightClicked() instanceof Villager) {
Merchant merchant = villagerlist.get(clickedEntity.getUniqueId());
if (merchant == null) return;
if (merchant == null)
return;
e.setCancelled(true);
p.openMerchant(merchant, true);
}

View file

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