NO longer generate the class dynamicly, just 2 different classes for 2 supported versions will be enough

This commit is contained in:
Shevchik 2014-01-12 02:29:53 +04:00
parent 6205d80ae1
commit 445077a81e
12 changed files with 60 additions and 55 deletions

View File

@ -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.

View File

@ -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();

View File

@ -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()) {

View File

@ -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();
}
}

View 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");
}
}

View File

@ -0,0 +1,5 @@
package com.cnaude.chairs.vehiclearrow.nms164;
public class VehicleArrow {
}

View 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();
}
}
}

View File

@ -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.