Skip to content

Commit

Permalink
Update to upto 1.21.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakllp committed Nov 4, 2024
1 parent f12fedf commit 5c0a67d
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 35 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
<version>5.3.0</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<artifactId>spigot-api</artifactId>
<version>1.13.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Expand All @@ -127,5 +127,5 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<version>1.20-R1.1.5</version>
<version>1.21-R1.1.5</version>
</project>
26 changes: 21 additions & 5 deletions src/main/java/com/useful/ucars/CartOrientationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ public static void setPitch(Entity cart, float pitch){
Class <?> ema = Reflect.getNMSClass("world.entity.","Entity");

if(ucars.MCVersion.get(0) == 1) {
if(ucars.MCVersion.get(1) >= 20) {
p = ema.getDeclaredField("aH");
if(ucars.MCVersion.get(1) >= 21) {
if(ucars.MCVersion.get(2) >= 2)
p = ema.getDeclaredField("aB");
else
p = ema.getDeclaredField("aE");
} else if(ucars.MCVersion.get(1) >= 20) {
if(ucars.MCVersion.get(2) >= 5)
p = ema.getDeclaredField("aG");
else
p = ema.getDeclaredField("aH");
} else if(ucars.MCVersion.get(1) >= 18) {
p = ema.getDeclaredField("aB");
} else if(ucars.MCVersion.get(1) == 17) {
Expand Down Expand Up @@ -76,10 +84,18 @@ public static void setYaw(Entity cart, float yaw){
Class<?> ema = Reflect.getNMSClass("world.entity.","Entity");
Object nmsCart = getHandle.invoke(cmr.cast(cart));
Field p = null;

if(ucars.MCVersion.get(0) == 1) {
if(ucars.MCVersion.get(1) >= 20) {
p = ema.getDeclaredField("aG");
if(ucars.MCVersion.get(1) >= 21) {
if(ucars.MCVersion.get(2) >= 2)
p = ema.getDeclaredField("aA");
else
p = ema.getDeclaredField("aD");
} else if(ucars.MCVersion.get(1) >= 20) {
if(ucars.MCVersion.get(2) >= 5)
p = ema.getDeclaredField("aF");
else
p = ema.getDeclaredField("aG");
} else if(ucars.MCVersion.get(1) >= 18) {
p = ema.getDeclaredField("aA");
} else if(ucars.MCVersion.get(1) == 17) {
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/useful/ucars/MotionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.useful.ucarsCommon.StatValue;

public class MotionManager {

public static MoveIntent MOVE_INTENT = null;

public static Vector rotateXZVector3dDegrees(Vector original, double degrees){
double[] out = rotateVector2dRadians(original.getX(), original.getZ(), Math.toRadians(degrees));
Expand All @@ -33,6 +35,12 @@ public static double[] rotateVector2dRadians(double x, double y, double radians)
return result;
}

public static void move(Player player) {
if (MOVE_INTENT == null)
return;
move(player, MOVE_INTENT.forward, MOVE_INTENT.sideways, MOVE_INTENT.jumping);
}

public static void move(Player player, float f, float s, boolean jumping) { // 'f' and 's' are values taken in by the vehicle control packet
Vector vec = new Vector();
Entity ent = player.getVehicle();
Expand Down Expand Up @@ -265,5 +273,4 @@ public void run() {
return;
}
}

}
19 changes: 19 additions & 0 deletions src/main/java/com/useful/ucars/MoveIntent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.useful.ucars;

public class MoveIntent {
public float forward;
public float sideways;
public boolean jumping;

public MoveIntent(float forward, float sideways, boolean jumping) {
this.forward = forward;
this.sideways = sideways;
this.jumping = jumping;
}

public void update(float forward, float sideways, boolean jumping) {
this.forward = forward;
this.sideways = sideways;
this.jumping = jumping;
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/useful/ucars/uCarsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,17 @@ public void tickCalcsAndLegacy(VehicleUpdateEvent event) {
return;
}

// TODO add motionmanager.move with current intent if Intent exists

if (MotionManager.MOVE_INTENT != null)
MotionManager.move(player);

Vehicle car = (Vehicle) vehicle;

if (!isACar(car)) {
return;
}


Vector vel = car.getVelocity();

Expand Down
89 changes: 63 additions & 26 deletions src/main/java/com/useful/ucars/ucars.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -17,6 +18,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.comphenix.protocol.events.InternalStructure;
import com.comphenix.protocol.wrappers.Vector3F;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
Expand All @@ -39,6 +42,7 @@
import com.useful.ucars.util.UMeta;

import net.milkbowl.vault.economy.Economy;
import org.bukkit.util.Vector;

public class ucars extends JavaPlugin {
// The main file
Expand Down Expand Up @@ -144,26 +148,59 @@ private Boolean setupProtocol() {
* PacketAdapter(plugin, ConnectionSide.CLIENT_SIDE,
* ListenerPriority.NORMAL, 0x1b) {
*/

((ProtocolManager) this.protocolManager).addPacketListener(
new PacketAdapter(this, PacketType.Play.Client.STEER_VEHICLE) {
@Override
public void onPacketReceiving(final PacketEvent event) {
PacketContainer packet = event.getPacket();
final float sideways = packet.getFloat().read(0);
final float forwards = packet.getFloat().read(1);
final boolean jumping = packet.getBooleans().read(0);
Bukkit.getScheduler().runTask(ucars.plugin, new Runnable(){

@Override
public void run() {
MotionManager.move(event.getPlayer(), forwards,
sideways, jumping);
return;
}});

}
});

if(MCVersion.get(0) == 1) {
if (MCVersion.get(1) >= 22 || MCVersion.get(1) == 21 && MCVersion.get(2) >= 2) {
MotionManager.MOVE_INTENT = new MoveIntent(0F, 0F, false);

((ProtocolManager) this.protocolManager).addPacketListener(
new PacketAdapter(this, PacketType.Play.Client.STEER_VEHICLE) {
@Override
public void onPacketReceiving(final PacketEvent event) {
PacketContainer packet = event.getPacket();

InternalStructure struct = packet.getStructures().getValues().getFirst();
// forward, backward, left, right, jump, shift, sprint
List<Boolean> bools = struct.getBooleans().getValues();
float forwards = bools.get(0) ? 1F : bools.get(1) ? -1F : 0F;
float sideways = bools.get(2) ? 1F : bools.get(3) ? -1F : 0F;
boolean jumping = bools.get(4);

Bukkit.getScheduler().runTask(ucars.plugin, new Runnable() {

@Override
public void run() {
MotionManager.MOVE_INTENT.update(forwards, sideways, jumping);
return;
}
});

}
});
}
else
((ProtocolManager) this.protocolManager).addPacketListener(
new PacketAdapter(this, PacketType.Play.Client.STEER_VEHICLE) {
@Override
public void onPacketReceiving(final PacketEvent event) {
PacketContainer packet = event.getPacket();

final float forwards = packet.getFloat().read(1);
final float sideways = packet.getFloat().read(0);
final boolean jumping = packet.getBooleans().read(0);
Bukkit.getScheduler().runTask(ucars.plugin, new Runnable() {

@Override
public void run() {
MotionManager.move(event.getPlayer(), forwards,
sideways, jumping);
return;
}
});

}
});
}
} catch (Exception e) {
return false;
}
Expand All @@ -174,10 +211,10 @@ public void run() {
public void onEnable() {
plugin = this;

Pattern pattern = Pattern.compile(".v(.*?)_R"); //Get MC-Version
Matcher matcher = pattern.matcher(Bukkit.getServer().getClass().getPackage().getName());
Pattern pattern = Pattern.compile("\\(MC: (\\d\\.\\d+(?:\\.\\d+)?)"); //Get MC-Version
Matcher matcher = pattern.matcher(Bukkit.getVersion());
if(matcher.find()) {
String[] MCVersionStr = matcher.group(1).split("_");
String[] MCVersionStr = matcher.group(1).split("\\.");
for(String s:MCVersionStr) {
MCVersion.add(Integer.parseInt(s));
}
Expand Down Expand Up @@ -781,10 +818,10 @@ public Boolean isPluginHooked(Plugin plugin) {
return getAPI().isPluginHooked(plugin);
}

public Plugin getPlugin(String name){
public Plugin getPlugin(String name) {
try {
for(Plugin p:this.hookedPlugins){
if(p.getName().equalsIgnoreCase(name)){
for (Plugin p : this.hookedPlugins) {
if (p.getName().equalsIgnoreCase(name)) {
return p;
}
}
Expand Down

0 comments on commit 5c0a67d

Please sign in to comment.