NullValkyrie

Minecraft 1.19 multipurpose plugin for spigot servers with a lot of features where most modern servers have.
git clone https://codeberg.org/night0721/NullValkyrie
Log | Files | Refs | README | LICENSE

commit d697a7bb26724ae7753c1f549f56c463fe90e23b
parent f70a800320f732ffac88414620e47ed357786eb0
Author: NK <[email protected]>
Date:   Fri, 18 Nov 2022 17:30:25 +0000

mining faster + protocollib

Diffstat:
Mpom.xml | 10++++++++++
Msrc/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java | 64++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/main/resources/plugin.yml | 1+
3 files changed, 55 insertions(+), 20 deletions(-)

diff --git a/pom.xml b/pom.xml @@ -71,6 +71,10 @@ <id>sonatype</id> <url>https://oss.sonatype.org/content/groups/public/</url> </repository> + <repository> + <id>dmulloy2-repo</id> + <url>https://repo.dmulloy2.net/repository/public/</url> + </repository> </repositories> <dependencies> @@ -91,5 +95,11 @@ <version>3.12.11</version> <scope>compile</scope> </dependency> + <dependency> + <groupId>com.comphenix.protocol</groupId> + <artifactId>ProtocolLib</artifactId> + <version>4.7.0</version> + <scope>provided</scope> + </dependency> </dependencies> </project> diff --git a/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java b/src/main/java/me/night/nullvalkyrie/events/CustomItemEvents.java @@ -1,5 +1,10 @@ package me.night.nullvalkyrie.events; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.BlockPosition; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import me.night.nullvalkyrie.items.CustomItemManager; @@ -22,6 +27,7 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; +import java.lang.reflect.InvocationTargetException; import java.util.*; import java.util.concurrent.TimeUnit; @@ -262,7 +268,9 @@ public class CustomItemEvents implements Listener { } } + private int taskID; + public void countDown(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); @@ -272,6 +280,7 @@ public class CustomItemEvents implements Listener { } }, 0L, 20L); } + private final Map<UUID, Merchant> villagerlist = new HashMap<>(); @EventHandler @@ -313,28 +322,43 @@ public class CustomItemEvents implements Listener { // e.getEntity().setCustomName(ChatColor.RED + "Changed name since you ust clicked lol"); // } - private Cache<UUID, Long> BreakAbility = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.MILLISECONDS).build(); - private HashMap<Block, Integer> blockStages = new HashMap<>(); + private final Cache<UUID, Long> BreakAbility = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.MILLISECONDS).build(); + private final HashMap<Location, Integer> blockStages = new HashMap<>(); + @EventHandler - public void onPlayAnimation(PlayerAnimationEvent e) { + public void onAnimationEvent(PlayerAnimationEvent e) { Player player = e.getPlayer(); - if (player.getGameMode().equals(GameMode.SURVIVAL)) { - if (!BreakAbility.asMap().containsKey(player.getUniqueId())) { - if (e.getAnimationType().equals(PlayerAnimationType.ARM_SWING)) { - Block block = player.getTargetBlock(null, 3); - if (!blockStages.containsKey(block)) blockStages.put(block, 0); - else { - BreakAbility.put(player.getUniqueId(), System.currentTimeMillis() + 60); - int blockStage = blockStages.get(block) + 1; - blockStages.replace(block, blockStage); - if (blockStages.get(block) == 10) { - player.sendBlockDamage(block.getLocation(), 1); - block.breakNaturally(); - blockStages.remove(block); - } else player.sendBlockDamage(block.getLocation(), (float) blockStage / 10); - } - } - } + if (!player.getGameMode().equals(GameMode.SURVIVAL)) return; + if (BreakAbility.asMap().containsKey(player.getUniqueId())) return; + if (!e.getAnimationType().equals(PlayerAnimationType.ARM_SWING)) return; + Block block = player.getTargetBlockExact(4); + if (block == null) return; + BreakAbility.put(player.getUniqueId(), System.currentTimeMillis() + 60); + int blockStage = blockStages.getOrDefault(block.getLocation(), 0); + blockStage = blockStage == 10 ? 0 : blockStage + 1; + blockStages.put(block.getLocation(), blockStage); + sendBlockDamage(player, block); + if (blockStage == 0) { + blockStages.remove(block.getLocation()); + block.breakNaturally(); + } + } + + ProtocolManager manager = ProtocolLibrary.getProtocolManager(); + public void sendBlockDamage(Player player, Location location) { + int locationId = location.getBlockX() + location.getBlockY() + location.getBlockZ(); + PacketContainer packet = manager.createPacket(PacketType.Play.Server.BLOCK_BREAK_ANIMATION); + packet.getIntegers().write(0, locationId); // set entity ID to the location + packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector())); // set the block location + packet.getIntegers().write(1, blockStages.get(location)); // set the damage to blockStage + try { + manager.sendServerPacket(player, packet); + } catch (InvocationTargetException e) { + e.printStackTrace(); } } + + public void sendBlockDamage(Player player, Block block) { + sendBlockDamage(player, block.getLocation()); + } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml @@ -5,6 +5,7 @@ api-version: 1.18 authors: [ NightKaly, Leocthl ] description: Null Valkyrie website: https://github.com/night0721/nullvalkyrie +depend: [ProtocolLib] permissions: nv.command.use: default: true