Skip to content

Commit

Permalink
Potentially fixed issue where highlighting could not be ended in 1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Aug 17, 2021
1 parent 3f225d0 commit e3d7931
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pluginVersion = 2.4.1
pluginVersion = 2.4.2
pluginGroup = nl.thedutchmc.harotorch
pluginName = HaroTorch
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

return c.run(this.plugin, sender, args);
c.run(this.plugin, sender, args);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.regex.Pattern;

import org.bukkit.Location;
import org.bukkit.command.CommandSender;
Expand All @@ -20,6 +21,11 @@
@SuppressWarnings("deprecation")
public class HighlightExecutor implements SubCommand {

/**
* HashMap to keep track of command usage as to avoid spam
* K = The UUID of the player
* V = Miliseconds since Jan 1 1970 after which the Player may execute a command again
*/
private static HashMap<UUID, Long> lastCommandTimestamps = new HashMap<>();

private static Class<?> craftPlayerClass;
Expand Down Expand Up @@ -117,6 +123,12 @@ public void run() {
return true;
}

/**
* Spawn magma cubes for the provided Player at the given Locations
* @param player The Player
* @param locations The Locations
* @return Returns a List of Entity IDs
*/
public List<Integer> spawnHighlight(Player player, List<Location> locations) {

List<Integer> result = new ArrayList<>();
Expand Down Expand Up @@ -177,6 +189,11 @@ public List<Integer> spawnHighlight(Player player, List<Location> locations) {
return result;
}

/**
* Kill the spawned Magma cubes to end highlighting
* @param ids The Entity IDs of the Entities to remove
* @param player The Player for which the Entities are showing
*/
public void killHighlighted(List<Integer> ids, Player player) {
try {
Object entityPlayerObject = ReflectionUtil.invokeMethod(craftPlayerClass, player, "getHandle");
Expand All @@ -188,8 +205,21 @@ public void killHighlighted(List<Integer> ids, Player player) {
}

if(ReflectionUtil.isUseNewSpigotPackaging()) {
for(int id : ids) {
Object destroyEntityPacket = ReflectionUtil.invokeConstructor(packetPlayOutEntityDestroyClass, new Class<?>[] { int.class }, new Object[] { id });
String[] vParts = ReflectionUtil.SERVER_VERSION.split(Pattern.quote(","));
int patch = Integer.valueOf(vParts[2]);
int minor = Integer.valueOf(vParts[1]);

// In 1.17.0 the constructor only took a single integer
// As of 1.17.1 it takes an int[]
if(patch == 0 && minor == 17) {
for(int id : ids) {
Object destroyEntityPacket = ReflectionUtil.invokeConstructor(packetPlayOutEntityDestroyClass, new Class<?>[] { int.class }, new Object[] { id });
ReflectionUtil.invokeMethod(playerConnectionObject, "sendPacket",
new Class<?>[] { packetPlayOutEntityDestroyInterfaceClass },
new Object[] { destroyEntityPacket });
}
} else {
Object destroyEntityPacket = ReflectionUtil.invokeConstructor(packetPlayOutEntityDestroyClass, new Class<?>[] { int[].class }, new Object[] { toIntArray(ids) });
ReflectionUtil.invokeMethod(playerConnectionObject, "sendPacket",
new Class<?>[] { packetPlayOutEntityDestroyInterfaceClass },
new Object[] { destroyEntityPacket });
Expand All @@ -207,6 +237,11 @@ public void killHighlighted(List<Integer> ids, Player player) {
}
}

/**
* Convert a List of Integers to an int[]
* @param a The List to convert
* @return The List as an int[]
*/
private int[] toIntArray(List<Integer> a) {
int[] b = new int[a.size()];
for(int i = 0; i < a.size(); i++) {
Expand Down

0 comments on commit e3d7931

Please sign in to comment.