mining faster + protocollib
This commit is contained in:
parent
f70a800320
commit
d697a7bb26
3 changed files with 55 additions and 20 deletions
10
pom.xml
10
pom.xml
|
@ -71,6 +71,10 @@
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>dmulloy2-repo</id>
|
||||||
|
<url>https://repo.dmulloy2.net/repository/public/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -91,5 +95,11 @@
|
||||||
<version>3.12.11</version>
|
<version>3.12.11</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.7.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package me.night.nullvalkyrie.events;
|
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.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import me.night.nullvalkyrie.items.CustomItemManager;
|
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.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@ -262,7 +268,9 @@ public class CustomItemEvents implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int taskID;
|
private int taskID;
|
||||||
|
|
||||||
public void countDown(Player player, int[] a) {
|
public void countDown(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);
|
||||||
|
@ -272,6 +280,7 @@ public class CustomItemEvents implements Listener {
|
||||||
}
|
}
|
||||||
}, 0L, 20L);
|
}, 0L, 20L);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Map<UUID, Merchant> villagerlist = new HashMap<>();
|
private final Map<UUID, Merchant> villagerlist = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -313,28 +322,43 @@ public class CustomItemEvents implements Listener {
|
||||||
// e.getEntity().setCustomName(ChatColor.RED + "Changed name since you ust clicked lol");
|
// 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 final Cache<UUID, Long> BreakAbility = CacheBuilder.newBuilder().expireAfterWrite(60, TimeUnit.MILLISECONDS).build();
|
||||||
private HashMap<Block, Integer> blockStages = new HashMap<>();
|
private final HashMap<Location, Integer> blockStages = new HashMap<>();
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayAnimation(PlayerAnimationEvent e) {
|
public void onAnimationEvent(PlayerAnimationEvent e) {
|
||||||
Player player = e.getPlayer();
|
Player player = e.getPlayer();
|
||||||
if (player.getGameMode().equals(GameMode.SURVIVAL)) {
|
if (!player.getGameMode().equals(GameMode.SURVIVAL)) return;
|
||||||
if (!BreakAbility.asMap().containsKey(player.getUniqueId())) {
|
if (BreakAbility.asMap().containsKey(player.getUniqueId())) return;
|
||||||
if (e.getAnimationType().equals(PlayerAnimationType.ARM_SWING)) {
|
if (!e.getAnimationType().equals(PlayerAnimationType.ARM_SWING)) return;
|
||||||
Block block = player.getTargetBlock(null, 3);
|
Block block = player.getTargetBlockExact(4);
|
||||||
if (!blockStages.containsKey(block)) blockStages.put(block, 0);
|
if (block == null) return;
|
||||||
else {
|
BreakAbility.put(player.getUniqueId(), System.currentTimeMillis() + 60);
|
||||||
BreakAbility.put(player.getUniqueId(), System.currentTimeMillis() + 60);
|
int blockStage = blockStages.getOrDefault(block.getLocation(), 0);
|
||||||
int blockStage = blockStages.get(block) + 1;
|
blockStage = blockStage == 10 ? 0 : blockStage + 1;
|
||||||
blockStages.replace(block, blockStage);
|
blockStages.put(block.getLocation(), blockStage);
|
||||||
if (blockStages.get(block) == 10) {
|
sendBlockDamage(player, block);
|
||||||
player.sendBlockDamage(block.getLocation(), 1);
|
if (blockStage == 0) {
|
||||||
block.breakNaturally();
|
blockStages.remove(block.getLocation());
|
||||||
blockStages.remove(block);
|
block.breakNaturally();
|
||||||
} else player.sendBlockDamage(block.getLocation(), (float) blockStage / 10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -5,6 +5,7 @@ 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
|
||||||
|
depend: [ProtocolLib]
|
||||||
permissions:
|
permissions:
|
||||||
nv.command.use:
|
nv.command.use:
|
||||||
default: true
|
default: true
|
||||||
|
|
Loading…
Reference in a new issue