damage effect

This commit is contained in:
NK 2022-11-17 10:40:38 +00:00
parent 4274820d65
commit 8b6cd099fd
3 changed files with 130 additions and 23 deletions

View file

@ -4,6 +4,8 @@ import me.night.nullvalkyrie.chests.MenuListener;
import me.night.nullvalkyrie.discord.DiscordClientManager; import me.night.nullvalkyrie.discord.DiscordClientManager;
import me.night.nullvalkyrie.enchantments.EnchantmentManager; import me.night.nullvalkyrie.enchantments.EnchantmentManager;
import me.night.nullvalkyrie.events.CustomItemEvents; 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.items.CustomItemManager;
import me.night.nullvalkyrie.rank.ScoreboardListener; import me.night.nullvalkyrie.rank.ScoreboardListener;
import me.night.nullvalkyrie.util.Util; 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 MenuListener(), this);
Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this); Bukkit.getPluginManager().registerEvents(new ScoreboardListener(this), this);
Bukkit.getPluginManager().registerEvents(new CustomItemEvents(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(); EnchantmentManager.register();
new DiscordClientManager(); new DiscordClientManager();
customItemManager = new CustomItemManager(this); customItemManager = new CustomItemManager(this);
@ -49,7 +52,6 @@ public final class Main extends JavaPlugin implements Listener {
new Client(); new Client();
} }
@EventHandler @EventHandler
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"));
@ -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");
// }
} }

View file

@ -1,14 +1,17 @@
package me.night.nullvalkyrie.commands; package me.night.nullvalkyrie.commands;
//import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow; import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow;
//import net.minecraft.server.level.EntityPlayer; import net.minecraft.server.level.EntityPlayer;
//import net.minecraft.server.network.PlayerConnection; import net.minecraft.server.network.PlayerConnection;
//import net.minecraft.world.inventory.Containers; import net.minecraft.world.inventory.Containers;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
//import org.bukkit.craftbukkit.v1_18_R1.entity.CraftHumanEntity; //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.entity.CraftPlayer;
//import org.bukkit.craftbukkit.v1_18_R1.util.CraftChatMessage; //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 org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@ -26,14 +29,14 @@ public class AnvilCommand extends Command {
@Override @Override
public void onCommand(CommandSender sender, String[] args) { public void onCommand(CommandSender sender, String[] args) {
if(sender instanceof Player) { if (sender instanceof Player) {
// Player player = (Player) sender; Player player = (Player) sender;
// CraftPlayer craftPlayer = (CraftPlayer) player; CraftPlayer craftPlayer = (CraftPlayer) player;
// EntityPlayer entityPlayer = craftPlayer.getHandle(); EntityPlayer entityPlayer = craftPlayer.getHandle();
// int id = 0; int id = 0;
// PacketPlayOutOpenWindow OpenWindow = new PacketPlayOutOpenWindow(id, Containers.h, CraftChatMessage.fromStringOrNull("Test")); PacketPlayOutOpenWindow OpenWindow = new PacketPlayOutOpenWindow(id, Containers.h, CraftChatMessage.fromStringOrNull("Test"));
// PlayerConnection playerConnection = entityPlayer.b; PlayerConnection playerConnection = entityPlayer.b;
// playerConnection.a(OpenWindow); playerConnection.a(OpenWindow);
} }
} }

View file

@ -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<Entity, Integer> 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<Entity> stands = indicators.keySet();
final List<Entity> 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());
// }