Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 committed Jul 3, 2024
1 parent 422e7bc commit 5ad3b05
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public void startTracing(Arrow arrow) {
arrow.setCritical(false);

try {
Object packet = TurretsMain.getInstance().getNMSUtils().getNMSClass("PacketPlayOutEntityDestroy").getConstructor(int[].class).newInstance(new int[]{arrow.getEntityId()});
Object packet = TurretsMain.getInstance().getNMUtils().getNMClass("PacketPlayOutEntityDestroy").getConstructor(int[].class).newInstance(new int[]{arrow.getEntityId()});
for(Player p : TurretsMain.getInstance().getServer().getOnlinePlayers()) {
Object nmsPlayer = p.getClass().getMethod("getHandle").invoke(p);
Object pConn = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
pConn.getClass().getMethod("sendPacket", TurretsMain.getInstance().getNMSUtils().getNMSClass("Packet")).invoke(pConn, packet);
pConn.getClass().getMethod("sendPacket", TurretsMain.getInstance().getNMUtils().getNMClass("Packet")).invoke(pConn, packet);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/com/snowleopard1863/APTurrets/TurretManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import net.countercraft.movecraft.worldguard.MovecraftWorldGuard;
import net.countercraft.movecraft.worldguard.utils.WorldGuardUtils.State;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.Location;
Expand All @@ -19,7 +21,6 @@
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Rotatable;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftTippedArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
Expand Down Expand Up @@ -131,17 +132,12 @@ public void fire(Player player) {
private Arrow launchArrow(Player player) {
Arrow arrow;
try {
Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player);
Object nmsWorld = nmsPlayer.getClass().getMethod("getLevel").invoke(nmsPlayer);
CraftTippedArrow
Object nmsArrow = TurretsMain.getInstance().getNMSUtils().getNMSClass("EntityTippedArrow")
.getConstructor(TurretsMain.getInstance().getNMSUtils().getNMSClass("level.ServerLevel"),
TurretsMain.getInstance().getNMSUtils().getNMSClass("EntityLiving"))
.newInstance(nmsWorld, nmsPlayer);
nmsArrow.getClass().getMethod("setNoGravity", boolean.class).invoke(nmsArrow, true);
nmsWorld.getClass().getMethod("addEntity", TurretsMain.getInstance().getNMSUtils().getNMSClass("Entity"))
.invoke(nmsWorld, nmsArrow);
arrow = (Arrow) nmsArrow.getClass().getMethod("getBukkitEntity").invoke(nmsArrow);
ServerPlayer nmsPlayer = (ServerPlayer) player.getClass().getMethod("getHandle").invoke(player);
ServerLevel nmsWorld = nmsPlayer.getLevel();
net.minecraft.world.entity.projectile.Arrow nmsArrow = new net.minecraft.world.entity.projectile.Arrow(nmsWorld, nmsPlayer);
nmsArrow.setNoGravity(true);
nmsWorld.addFreshEntity(nmsArrow);
arrow = (Arrow) nmsArrow.getBukkitEntity();
} catch (Exception e) {
throw new ArrowLaunchException("Something went wrong when trying to launch an arrow", e);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/snowleopard1863/APTurrets/TurretsMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.snowleopard1863.APTurrets.config.Config;
import com.snowleopard1863.APTurrets.listener.*;
import com.snowleopard1863.APTurrets.task.ArrowTracerTask;
import com.snowleopard1863.APTurrets.utils.NMSUtils;
import com.snowleopard1863.APTurrets.utils.NMUtils;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
import org.bukkit.event.Listener;
Expand All @@ -20,7 +20,7 @@ public static TurretsMain getInstance() {
return instance;
}

private NMSUtils nmsUtils;
private NMUtils nmsUtils;
private TurretManager turretManager;
private TracerManager tracerManager;

Expand Down Expand Up @@ -86,7 +86,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new ProjectileHitListener(), this);
getServer().getPluginManager().registerEvents(new SignChangeListener(), this);

nmsUtils = new NMSUtils(getServer().getClass().getPackage().getName());
nmsUtils = new NMUtils();
turretManager = new TurretManager();
tracerManager = new TracerManager();
getLogger().info(getDescription().getName() + " v" + getDescription().getVersion() + " has been enabled.");
Expand All @@ -103,7 +103,7 @@ public Economy getEconomy() {
return economy;
}

public NMSUtils getNMSUtils() {
public NMUtils getNMUtils() {
return nmsUtils;
}

Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/snowleopard1863/APTurrets/utils/NMSUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.snowleopard1863.APTurrets.utils;

public class NMUtils {
public Class<?> getNMClass(String name) throws ClassNotFoundException {
return Class.forName("net.minecraft." + name);
}
}

0 comments on commit 5ad3b05

Please sign in to comment.