NO longer generate the class dynamicly, just 2 different classes for 2 supported versions will be enough
This commit is contained in:
parent
6205d80ae1
commit
445077a81e
@ -11,7 +11,6 @@
|
||||
<fileset file="src/config.yml" />
|
||||
<fileset file="src/plugin.yml" />
|
||||
</copy>
|
||||
<unzip src="libs/javassist.jar" dest="build/classes/" />
|
||||
<jar destfile="target/Chairs.jar" basedir="build/classes" />
|
||||
<delete dir="build" />
|
||||
</target>
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -25,7 +25,7 @@ import com.cnaude.chairs.listeners.TrySitEventListener;
|
||||
import com.cnaude.chairs.listeners.TryUnsitEventListener;
|
||||
import com.cnaude.chairs.sitaddons.ChairEffects;
|
||||
import com.cnaude.chairs.sitaddons.CommandRestrict;
|
||||
import com.cnaude.chairs.vehiclearrow.GenVehicleArrowClass;
|
||||
import com.cnaude.chairs.vehiclearrow.GetVehicleArrowClass;
|
||||
|
||||
public class Chairs extends JavaPlugin {
|
||||
public ChairEffects chairEffects;
|
||||
@ -60,7 +60,7 @@ public class Chairs extends JavaPlugin {
|
||||
return vehiclearrowclass;
|
||||
}
|
||||
|
||||
GenVehicleArrowClass genvehiclearrow = new GenVehicleArrowClass();
|
||||
GetVehicleArrowClass genvehiclearrow = new GetVehicleArrowClass();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -75,7 +75,7 @@ public class Chairs extends JavaPlugin {
|
||||
getHandle.setAccessible(true);
|
||||
Class<?> entityarrow = getHandle.invoke(arrow).getClass();
|
||||
Class<?> craftserver = getServer().getClass();
|
||||
vehiclearrowclass = genvehiclearrow.genAndLoadClass(arrowclass, entityarrow, craftserver);
|
||||
vehiclearrowclass = genvehiclearrow.getVehicleArrowClass(arrowclass, entityarrow, craftserver);
|
||||
arrow.remove();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -50,7 +50,7 @@ public class ChairEffects {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (plugin.getPlayerSitData().isSitting(p)) {
|
||||
if (p.hasPermission("chairs.sit.health")) {
|
||||
double pHealthPcnt = ((double) p.getHealth()) / (double) p.getMaxHealth() * 100d;
|
||||
double pHealthPcnt = (p.getHealth()) / p.getMaxHealth() * 100d;
|
||||
if ((pHealthPcnt < plugin.sitMaxHealth) && (p.getHealth() < p.getMaxHealth())) {
|
||||
double newHealth = plugin.sitHealthPerInterval + p.getHealth();
|
||||
if (newHealth > p.getMaxHealth()) {
|
||||
|
@ -1,49 +0,0 @@
|
||||
package com.cnaude.chairs.vehiclearrow;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
|
||||
import javassist.CannotCompileException;
|
||||
import javassist.ClassClassPath;
|
||||
import javassist.ClassPool;
|
||||
import javassist.CtClass;
|
||||
import javassist.CtNewConstructor;
|
||||
import javassist.CtNewMethod;
|
||||
import javassist.NotFoundException;
|
||||
|
||||
public class GenVehicleArrowClass {
|
||||
|
||||
public Class<?> genAndLoadClass(String arrowclass, Class<?> entityarrow, Class<?> craftserver) throws IOException, ClassNotFoundException, NotFoundException, CannotCompileException
|
||||
{
|
||||
ClassPool pool = ClassPool.getDefault();
|
||||
pool.insertClassPath
|
||||
(
|
||||
new ClassClassPath(Bukkit.class)
|
||||
);
|
||||
CtClass vehiclearrow = pool.makeClass("com.cnaude.chairs.VehicleArrow");
|
||||
vehiclearrow.setSuperclass(pool.getCtClass(arrowclass));
|
||||
vehiclearrow.setInterfaces
|
||||
(
|
||||
new CtClass[]
|
||||
{
|
||||
pool.get(Vehicle.class.getName())
|
||||
}
|
||||
);
|
||||
String counstructorsource = "public VehicleArrow("+craftserver.getName()+" server, "+entityarrow.getName()+" entity)\n{\nsuper(server, entity);\n}";
|
||||
vehiclearrow.addConstructor
|
||||
(
|
||||
CtNewConstructor.make(counstructorsource, vehiclearrow)
|
||||
);
|
||||
String removemethodsource = "public void remove()\n{\nif (this.getPassenger() == null)\n{\nsuper.remove();\n}\n}";
|
||||
vehiclearrow.addMethod
|
||||
(
|
||||
CtNewMethod.make(removemethodsource, vehiclearrow)
|
||||
);
|
||||
return vehiclearrow.toClass();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
25
src/com/cnaude/chairs/vehiclearrow/GetVehicleArrowClass.java
Normal file
25
src/com/cnaude/chairs/vehiclearrow/GetVehicleArrowClass.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.cnaude.chairs.vehiclearrow;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class GetVehicleArrowClass {
|
||||
|
||||
private String pkgname = this.getClass().getPackage().getName();
|
||||
private String vehiclearrowclassname = "VehicleArrow";
|
||||
public Class<?> getVehicleArrowClass(String arrowclass, Class<?> entityarrow, Class<?> craftserver) throws Exception
|
||||
{
|
||||
String packageName = Bukkit.getServer().getClass().getPackage().getName();
|
||||
String nmspackageversion = packageName.substring(packageName.lastIndexOf('.') + 1);
|
||||
if (nmspackageversion.equals("v1_7_R1"))
|
||||
{
|
||||
return Class.forName(pkgname+"."+"nms172"+"."+vehiclearrowclassname);
|
||||
} else if (nmspackageversion.equals("v1_6_R3"))
|
||||
{
|
||||
return Class.forName(pkgname+"."+"nms164"+"."+vehiclearrowclassname);
|
||||
}
|
||||
throw new Exception("ChiarsReloaded is not compatible with your server version");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.cnaude.chairs.vehiclearrow.nms164;
|
||||
|
||||
public class VehicleArrow {
|
||||
|
||||
}
|
25
src/com/cnaude/chairs/vehiclearrow/nms172/VehicleArrow.java
Normal file
25
src/com/cnaude/chairs/vehiclearrow/nms172/VehicleArrow.java
Normal file
@ -0,0 +1,25 @@
|
||||
package com.cnaude.chairs.vehiclearrow.nms172;
|
||||
|
||||
import net.minecraft.server.v1_7_R1.EntityArrow;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_7_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_7_R1.entity.CraftArrow;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
|
||||
public class VehicleArrow extends CraftArrow implements Vehicle {
|
||||
|
||||
public VehicleArrow(CraftServer server, EntityArrow entity)
|
||||
{
|
||||
super(server, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
if (this.getPassenger() == null)
|
||||
{
|
||||
super.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ authors:
|
||||
- spoothie
|
||||
- cnaude
|
||||
- _Shevchik_
|
||||
main: com.cnaude.chairs.Chairs
|
||||
main: com.cnaude.chairs.core.Chairs
|
||||
commands:
|
||||
chairs:
|
||||
description: Various commands for Chairs.
|
||||
|
Loading…
Reference in New Issue
Block a user