Skip to content

Commit

Permalink
Compat for 1.19, move NMS code to bukkitreflectionutil
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasDeBruijn committed Oct 13, 2022
1 parent 6e419b1 commit f57edf8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 255 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id 'java'
id 'eclipse'
id 'com.github.johnrengelman.shadow' version '7.0.0'

}
Expand All @@ -14,6 +13,7 @@ allprojects {
group = pluginGroup

repositories {
mavenLocal()
mavenCentral()
maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
Expand All @@ -34,7 +34,7 @@ dependencies {

implementation 'com.github.TheDutchMC:HaroTorch:v1-SNAPSHOT'
implementation 'commons-io:commons-io:2.6'
implementation 'dev.array21:bukkit-reflection-util:1.1.1'
implementation 'dev.array21:bukkit-reflection-util:1.2.0'
implementation 'dev.array21:classvalidator:1.0.0'
implementation 'dev.array21:httplib:1.2.2'
}
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/dev/array21/harotorch/commands/CommandCooldown.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.array21.harotorch.commands;

import dev.array21.harotorch.HaroTorch;
import dev.array21.harotorch.lang.LangHandler;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.HashMap;
import java.util.UUID;

public class CommandCooldown {
public static boolean checkCommandCooldown(HaroTorch plugin, CommandSender sender, HashMap<UUID, Long> lastCommandTimestamps) {
Integer commandCooldown = plugin.getConfigManifest().commandCooldown;
if(commandCooldown != null && commandCooldown > 0) {
Long lastCommandUseTimestamp = lastCommandTimestamps.get(((Player) sender).getUniqueId());
if(lastCommandUseTimestamp != null) {
if(lastCommandUseTimestamp >= System.currentTimeMillis()) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("commandCooldown"));
return true;
}
}

lastCommandTimestamps.put(((Player) sender).getUniqueId(), System.currentTimeMillis() + (commandCooldown * 1000));
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import dev.array21.harotorch.commands.CommandCooldown;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Particle;
Expand All @@ -35,27 +36,27 @@
public class HighlightAreaOfEffectExecutor implements SubCommand {

private static final ExecutorService POOL = Executors.newFixedThreadPool(3);
private static HashMap<UUID, Long> lastCommandTimestamps = new HashMap<>();
private final static HashMap<UUID, Long> lastCommandTimestamps = new HashMap<>();

private static Class<?> packetPlayOutWorldParticleClass;
private static Class<?> packetPlayOutWorldParticleInterfaceClass;
private static Class<?> craftPlayerClass;
private static Class<?> craftParticleClass;
private static Class<?> particleParamClass;

static {
try {
if(ReflectionUtil.isUseNewSpigotPackaging()) {
packetPlayOutWorldParticleClass = ReflectionUtil.getMinecraftClass("network.protocol.game.PacketPlayOutWorldParticles");
} else {
packetPlayOutWorldParticleClass = ReflectionUtil.getNmsClass("PacketPlayOutWorldParticles");
}

packetPlayOutWorldParticleInterfaceClass = packetPlayOutWorldParticleClass.getInterfaces()[0];

craftPlayerClass = ReflectionUtil.getBukkitClass("entity.CraftPlayer");
craftParticleClass = ReflectionUtil.getBukkitClass("CraftParticle");

if(ReflectionUtil.isUseNewSpigotPackaging()) {
particleParamClass = ReflectionUtil.getMinecraftClass("core.particles.ParticleParam");
} else {
Expand All @@ -67,20 +68,9 @@ public class HighlightAreaOfEffectExecutor implements SubCommand {
}

public boolean run(HaroTorch plugin, CommandSender sender, String[] args) {

Integer commandCooldown = plugin.getConfigManifest().commandCooldown;
if(commandCooldown != null && commandCooldown > 0) {
Long lastCommandUseTimestamp = lastCommandTimestamps.get(((Player) sender).getUniqueId());
if(lastCommandUseTimestamp != null) {
if(lastCommandUseTimestamp >= System.currentTimeMillis()) {
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + LangHandler.activeLang.getLangMessages().get("commandCooldown"));
return true;
}
}

lastCommandTimestamps.put(((Player) sender).getUniqueId(), System.currentTimeMillis() + (commandCooldown * 1000));
}


if (CommandCooldown.checkCommandCooldown(plugin, sender, lastCommandTimestamps)) return true;

String msg = LangHandler.activeLang.getLangMessages().get("startingAoe").replaceAll("%SECONDS%", ChatColor.RED + String.valueOf(plugin.getConfigManifest().torchHighlightTime) + ChatColor.GOLD);
sender.sendMessage(HaroTorch.getMessagePrefix() + ChatColor.GOLD + msg);

Expand Down Expand Up @@ -143,7 +133,7 @@ public void run() {

return true;
}

/**
* Get all TorchParticleObject's in a square range
* @param nearbyTorches Locations of the Torches
Expand Down
Loading

0 comments on commit f57edf8

Please sign in to comment.