diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e09f657 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.externalToolBuilders/New_Builder.launch b/.externalToolBuilders/New_Builder.launch new file mode 100644 index 0000000..2cdd24b --- /dev/null +++ b/.externalToolBuilders/New_Builder.launch @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index a568390..aab245a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /nbproject/private/ /build/ -/dist/ \ No newline at end of file +/dist/ +/bin diff --git a/.project b/.project new file mode 100644 index 0000000..be3815f --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ + + + Chairs + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.ui.externaltools.ExternalToolBuilder + full,incremental, + + + LaunchConfigHandle + <project>/.externalToolBuilders/New_Builder.launch + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.core.runtime.prefs b/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000..5a0ad22 --- /dev/null +++ b/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/.settings/org.eclipse.ltk.core.refactoring.prefs b/.settings/org.eclipse.ltk.core.refactoring.prefs new file mode 100644 index 0000000..b196c64 --- /dev/null +++ b/.settings/org.eclipse.ltk.core.refactoring.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/build.xml b/build.xml index dcdcb6b..5f217c5 100644 --- a/build.xml +++ b/build.xml @@ -1,83 +1,18 @@ - - - - - - - - - - - Builds, tests, and runs the project Chairs. - - - - - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libs/ProtocolLib-2.6.1-SNAPSHOT.jar b/libs/ProtocolLib-2.6.1-SNAPSHOT.jar new file mode 100644 index 0000000..da35c6c Binary files /dev/null and b/libs/ProtocolLib-2.6.1-SNAPSHOT.jar differ diff --git a/libs/bukkit-1.6.2-R0.2-20130829.060124-15.jar b/libs/bukkit-1.6.2-R0.2-20130829.060124-15.jar new file mode 100644 index 0000000..d5306f5 Binary files /dev/null and b/libs/bukkit-1.6.2-R0.2-20130829.060124-15.jar differ diff --git a/libs/craftbukkit-1.6.2-R0.2-20130830.024149-24.jar b/libs/craftbukkit-1.6.2-R0.2-20130830.024149-24.jar new file mode 100644 index 0000000..9c61bda Binary files /dev/null and b/libs/craftbukkit-1.6.2-R0.2-20130830.024149-24.jar differ diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml deleted file mode 100644 index 082f931..0000000 --- a/nbproject/build-impl.xml +++ /dev/null @@ -1,1411 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - - - - - - java -cp "${run.classpath.with.dist.jar}" ${main.class} - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties deleted file mode 100644 index 6fcdcab..0000000 --- a/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=c7d31434 -build.xml.script.CRC32=eeae364c -build.xml.stylesheet.CRC32=28e38971@1.53.1.46 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=c7d31434 -nbproject/build-impl.xml.script.CRC32=03b57061 -nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.54.1.46 diff --git a/nbproject/project.properties b/nbproject/project.properties deleted file mode 100644 index 525ab7b..0000000 --- a/nbproject/project.properties +++ /dev/null @@ -1,90 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=Chairs -application.vendor=cnaude -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/Chairs.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -file.reference.craftbukkit-1.5.2.jar=C:\\Users\\cnaude\\Dropbox\\Development\\Libraries\\craftbukkit-1.5.2.jar -file.reference.craftbukkit-1.5.2.jar-1=/home/naudec/Libraries/craftbukkit-1.5.2.jar -file.reference.ProtocolLib-2.4.1.jar=C:\\Users\\cnaude\\Dropbox\\Development\\Libraries\\ProtocolLib-2.4.1.jar -file.reference.ProtocolLib-2.4.1.jar-1=/home/naudec/Libraries/ProtocolLib-2.4.1.jar -includes=** -jar.archive.disabled=${jnlp.enabled} -jar.compress=false -jar.index=${jnlp.enabled} -javac.classpath=\ - ${file.reference.craftbukkit-1.5.2.jar}:\ - ${file.reference.ProtocolLib-2.4.1.jar}:\ - ${file.reference.craftbukkit-1.5.2.jar-1}:\ - ${file.reference.ProtocolLib-2.4.1.jar-1} -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.6 -javac.target=1.6 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -jnlp.codebase.type=no.codebase -jnlp.descriptor=application -jnlp.enabled=false -jnlp.mixed.code=default -jnlp.offline-allowed=false -jnlp.signed=false -jnlp.signing= -jnlp.signing.alias= -jnlp.signing.keystore= -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=true -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/nbproject/project.xml b/nbproject/project.xml deleted file mode 100644 index de69cb8..0000000 --- a/nbproject/project.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - Chairs - - - - - - - - - diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index ea1ee5d..13eb0cf 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -6,17 +6,22 @@ import java.util.HashMap; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; + import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; + public class Chairs extends JavaPlugin { private static Chairs instance = null; public static ChairEffects chairEffects; @@ -32,7 +37,6 @@ public class Chairs extends JavaPlugin { public int sitEffectInterval; private File pluginFolder; private File configFile; - public byte sitByte; public HashMap sit = new HashMap(); public static final String PLUGIN_NAME = "Chairs"; public static final String LOG_HEADER = "[" + PLUGIN_NAME + "]"; @@ -40,6 +44,7 @@ public class Chairs extends JavaPlugin { public PluginManager pm; public static ChairsIgnoreList ignoreList; public String msgSitting, msgStanding, msgOccupied, msgNoPerm, msgReloaded, msgDisabled, msgEnabled; + private ProtocolManager protocolManager; @Override public void onEnable() { @@ -59,16 +64,19 @@ public class Chairs extends JavaPlugin { logInfo("Enabling sitting effects."); chairEffects = new ChairEffects(this); } + protocolManager = ProtocolLibrary.getProtocolManager(); + new PacketListener(protocolManager, this); } @Override public void onDisable() { + protocolManager.removePacketListeners(this); + protocolManager = null; for (String pName : sit.keySet()) { Player player = getServer().getPlayer(pName); Location loc = player.getLocation().clone(); loc.setY(loc.getY() + 1); player.teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN); - } if (ignoreList != null) { ignoreList.save(); @@ -76,6 +84,8 @@ public class Chairs extends JavaPlugin { if (chairEffects != null) { chairEffects.cancel(); } + HandlerList.unregisterAll(this); + instance = null; } public void restartEffectsTask() { @@ -106,9 +116,7 @@ public class Chairs extends JavaPlugin { return (getServer().getPluginManager().getPlugin("ProtocolLib") != null); } - public void loadConfig() { - sitByte = Byte.parseByte(getConfig().getString("packet")); - logInfo("Sitting packet byte: " + sitByte); + public void loadConfig() { autoRotate = getConfig().getBoolean("auto-rotate"); sneaking = getConfig().getBoolean("sneaking"); signCheck = getConfig().getBoolean("sign-check"); diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index dc9d25e..74bda65 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -4,6 +4,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow; import org.bukkit.entity.Entity; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; @@ -134,8 +135,6 @@ public class EventListener implements Listener { } for (ChairBlock cb : plugin.allowedBlocks) { - //plugin.logInfo("Comparing: (" + cb.getMat().name() + " ? " + block.getType().name() + ") (" - // + cb.getDamage() + " ? " + block.getData() + ")"); if (cb.getMat().toString().contains("STAIRS")) { if (cb.getMat().equals(block.getType())) { blockOkay = true; @@ -157,16 +156,12 @@ public class EventListener implements Listener { if (block.getState().getData() instanceof Stairs) { stairs = (Stairs) block.getState().getData(); - //plugin.logInfo("STAIR"); } else if (block.getState().getData() instanceof Step) { step = (Step) block.getState().getData(); - //plugin.logInfo("STEP"); } else if (block.getState().getData() instanceof WoodenStep) { wStep = (WoodenStep) block.getState().getData(); - //plugin.logInfo("WOODEN_STEP"); } else { sh += plugin.sittingHeightAdj; - //plugin.logInfo("OTHER"); } int chairwidth = 1; @@ -202,7 +197,7 @@ public class EventListener implements Listener { return; } } - + // Check for signs. if (plugin.signCheck == true && stairs != null) { boolean sign1 = false; @@ -235,9 +230,8 @@ public class EventListener implements Listener { return; } } - + // Sit-down process. - if (!plugin.sneaking || (plugin.sneaking && event.getPlayer().isSneaking())) { if (plugin.seatOccupiedCheck) { if (!plugin.sit.isEmpty()) { for (String s : plugin.sit.keySet()) { @@ -268,6 +262,8 @@ public class EventListener implements Listener { break; case WEST: plocation.setYaw(90); + default: + ; } player.teleport(plocation); } else { @@ -280,13 +276,11 @@ public class EventListener implements Listener { player.getPlayer().teleport(plocation); Entity arrow = block.getWorld().spawnArrow(getBlockCentre(block).subtract(0, 0.5, 0), new Vector(0, 0, 0), 0, 0); - arrow.setPassenger(player); player.setSneaking(false); arrow.setTicksLived(1); plugin.sit.put(player.getName(), arrow); event.setCancelled(true); - } } } } diff --git a/src/com/cnaude/chairs/PacketListener.java b/src/com/cnaude/chairs/PacketListener.java new file mode 100644 index 0000000..2ed9e30 --- /dev/null +++ b/src/com/cnaude/chairs/PacketListener.java @@ -0,0 +1,77 @@ +package com.cnaude.chairs; + +import java.util.HashSet; + +import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_6_R2.entity.CraftArrow; +import org.bukkit.entity.Entity; + +import com.comphenix.protocol.Packets; +import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.events.ListenerPriority; +import com.comphenix.protocol.events.PacketAdapter; +import com.comphenix.protocol.events.PacketEvent; + +public class PacketListener { + + private ProtocolManager pm; + private Chairs pluginInstance; + public PacketListener(ProtocolManager pm, Chairs plugin) + { + this.pm = pm; + this.pluginInstance = plugin; + playerDismountListener(); + } + + + private void playerDismountListener() + { + pm.getAsynchronousManager().registerAsyncHandler( + new PacketAdapter(PacketAdapter + .params(pluginInstance, Packets.Client.PLAYER_INPUT) + .clientSide() + .listenerPriority(ListenerPriority.HIGHEST) + .optionIntercept() + ) + { + @Override + public void onPacketReceiving(final PacketEvent e) + { + System.out.println("Checking packet"); + if (!e.isCancelled()) + { + System.out.println(e.getPacket().getBooleans().getValues().get(1)); + final String playername = e.getPlayer().getName(); + if (e.getPacket().getBooleans().getValues().get(1)) + { + Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable() + { + public void run() + { + System.out.println("Doing magic"); + Entity arrow = pluginInstance.sit.get(playername); + if (arrow != null) + { + net.minecraft.server.v1_6_R2.EntityArrow nmsarrow = ((CraftArrow) arrow).getHandle(); + nmsarrow.motX = 0; + nmsarrow.motY = 0; + nmsarrow.motZ = 0; + nmsarrow.boundingBox.b = 0.1; + } + } + }); + e.getAsyncMarker().incrementProcessingDelay(); + + Bukkit.getScheduler().scheduleSyncDelayedTask(pluginInstance, new Runnable() + { + public void run() { + pm.getAsynchronousManager().signalPacketTransmission(e); + } + }, 2); + } + } + } + }).start(); + } + +} diff --git a/src/plugin.yml b/src/plugin.yml index 3a8aea3..332e168 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -5,6 +5,7 @@ website: http://dev.bukkit.org/bukkit-plugins/chairsreloaded/ authors: - spoothie - cnaude +depend: [ProtocolLib] main: com.cnaude.chairs.Chairs commands: chairs: diff --git a/target/Chairs.jar b/target/Chairs.jar new file mode 100644 index 0000000..de0b0c5 Binary files /dev/null and b/target/Chairs.jar differ