diff --git a/src/main/java/me/night/nullvalkyrie/Main.java b/src/main/java/me/night/nullvalkyrie/Main.java index 7f7c628..ab896cb 100644 --- a/src/main/java/me/night/nullvalkyrie/Main.java +++ b/src/main/java/me/night/nullvalkyrie/Main.java @@ -4,6 +4,8 @@ import me.night.nullvalkyrie.chests.MenuListener; import me.night.nullvalkyrie.discord.DiscordClientManager; import me.night.nullvalkyrie.enchantments.EnchantmentManager; import me.night.nullvalkyrie.events.CustomItemEvents; +//import me.night.nullvalkyrie.hardpoint.GameEvent; +import me.night.nullvalkyrie.events.DamageEffect; import me.night.nullvalkyrie.items.CustomItemManager; import me.night.nullvalkyrie.rank.ScoreboardListener; import me.night.nullvalkyrie.util.Util; @@ -41,7 +43,8 @@ public final class Main extends JavaPlugin implements Listener { Bukkit.getPluginManager().registerEvents(new MenuListener(), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new CustomItemEvents(this), this); - Bukkit.getPluginManager().registerEvents(new SpawnCommand(this), this); + Bukkit.getPluginManager().registerEvents(new DamageEffect(this), this); + //Bukkit.getPluginManager().registerEvents(new GameEvent(this), this); EnchantmentManager.register(); new DiscordClientManager(); customItemManager = new CustomItemManager(this); @@ -49,7 +52,6 @@ public final class Main extends JavaPlugin implements Listener { new Client(); } - @EventHandler public void onJoin(PlayerJoinEvent e) { e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("ยง1NOT ENOUGH MANNER")); @@ -69,13 +71,4 @@ public final class Main extends JavaPlugin implements Listener { } } - - -// For hologram clicks to change page -// @EventHandler -// public void onEntityInteract(EntityInteractEvent e) { -// System.out.println(e.getEntity().getLocation()); -// e.getEntity().setCustomName(ChatColor.RED + "Changed name since you ust clicked lol"); -// } - } diff --git a/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java b/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java index 6dc39d0..2723bff 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/AnvilCommand.java @@ -1,14 +1,17 @@ package me.night.nullvalkyrie.commands; -//import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; -//import net.minecraft.server.level.EntityPlayer; -//import net.minecraft.server.network.PlayerConnection; -//import net.minecraft.world.inventory.Containers; +import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; +import net.minecraft.server.level.EntityPlayer; +import net.minecraft.server.network.PlayerConnection; +import net.minecraft.world.inventory.Containers; + import org.bukkit.command.CommandSender; //import org.bukkit.craftbukkit.v1_18_R1.entity.CraftHumanEntity; //import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer; //import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage; +import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_19_R1.util.CraftChatMessage; import org.bukkit.entity.Player; import java.util.List; @@ -26,14 +29,14 @@ public class AnvilCommand extends Command { @Override public void onCommand(CommandSender sender, String[] args) { - if(sender instanceof Player) { -// Player player = (Player) sender; -// CraftPlayer craftPlayer = (CraftPlayer) player; -// EntityPlayer entityPlayer = craftPlayer.getHandle(); -// int id = 0; -// PacketPlayOutOpenWindow OpenWindow = new PacketPlayOutOpenWindow(id, Containers.h, CraftChatMessage.fromStringOrNull("Test")); -// PlayerConnection playerConnection = entityPlayer.b; -// playerConnection.a(OpenWindow); + if (sender instanceof Player) { + Player player = (Player) sender; + CraftPlayer craftPlayer = (CraftPlayer) player; + EntityPlayer entityPlayer = craftPlayer.getHandle(); + int id = 0; + PacketPlayOutOpenWindow OpenWindow = new PacketPlayOutOpenWindow(id, Containers.h, CraftChatMessage.fromStringOrNull("Test")); + PlayerConnection playerConnection = entityPlayer.b; + playerConnection.a(OpenWindow); } } diff --git a/src/main/java/me/night/nullvalkyrie/events/DamageEffect.java b/src/main/java/me/night/nullvalkyrie/events/DamageEffect.java new file mode 100644 index 0000000..0594654 --- /dev/null +++ b/src/main/java/me/night/nullvalkyrie/events/DamageEffect.java @@ -0,0 +1,111 @@ +package me.night.nullvalkyrie.events; + +import me.night.nullvalkyrie.Main; +import me.night.nullvalkyrie.util.Util; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Zombie; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.scheduler.BukkitRunnable; + +import java.text.DecimalFormat; +import java.util.*; + +public class DamageEffect implements Listener { + private final Main main; + + public DamageEffect(Main main) { + this.main = main; + } + + public World world = Bukkit.getWorld("world"); + public final Map indicators = new HashMap<>(); + private final DecimalFormat formatter = new DecimalFormat("#"); + + @EventHandler + public void onDamage(EntityDamageByEntityEvent e) { + double damage = e.getFinalDamage(); + if (e.getEntity() instanceof Zombie) { + Location loc = e.getEntity().getLocation().clone().add(getRandomOffset(), 1, getRandomOffset()); + world.spawn(loc, ArmorStand.class, armorStand -> { + armorStand.setMarker(true); + armorStand.setVisible(false); + armorStand.setGravity(false); + armorStand.setSmall(true); + armorStand.setCustomNameVisible(true); + armorStand.setCustomName(Util.color("&c&l" + formatter.format(damage))); + indicators.put(armorStand, 30); + }); + removeStands(); + } + } + + public void removeStands() { + new BukkitRunnable() { + final Set stands = indicators.keySet(); + final List removal = new ArrayList<>(); + + @Override + public void run() { + for (Entity stand : stands) { + int ticksLeft = indicators.get(stand); + if (ticksLeft == 0) { + stand.remove(); + removal.add(stand); + continue; + } + ticksLeft--; + indicators.put(stand, ticksLeft); + } + stands.removeAll(removal); + } + }.runTaskTimer(main, 0L, 1L); + } + + public static 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(); + } + + private static double getRandomOffset() { + double random = Math.random(); + if (Math.random() > 0.5) random *= -1; + return random; + } + + public static int getRandomWithNeg(int size) { + int random = (int) (Math.random() * (size + 1)); + if (Math.random() > 0.5) random *= -1; + return random; + } + + public Location generateRandomCoord(int size, World world) { + int ranX = getRandomWithNeg(size), ranZ = getRandomWithNeg(size); + Block block = world.getHighestBlockAt(ranX, ranZ); + return block.getLocation(); + } + + public Location generateRandomCoordIsSpawnable(int size) { + while (true) { + Location coord = generateRandomCoord(size, world); + boolean spawnable = isSpawnable(coord); + if (spawnable) { + return coord; + } + } + } +} +// +// @EventHandler +// public void onEntityDeath(EntityDeathEvent event) { +// if (!entities.containsKey(event.getEntity())) return; +// event.setDroppedExp(0); +// event.getDrops().clear(); +// entities.remove(event.getEntity()).tryDropLoot(event.getEntity().getLocation()); +// } \ No newline at end of file