I am aware posts about this have been made before, however i have not found a solid answer... I need a simple, solid solution. I am aware this will require packets which I have not worked with yet. What i need is a solution which allows me to do ./away and it will make my body start sleeping. In mid air. This can be done as there is a command (I have forgotten) which allows you to do this i believe with Essentials. Please reply soon -JustRayz
The Dev of ProtocolLib has created some nice code for you right here: https://gist.github.com/aadnk/8611384
Thankyou, this really helped! Only this error: Code: [22:45:40 ERROR]: Error occurred while enabling RPGCustom v1.0 (Is it up to date?) java.lang.NoClassDefFoundError: com/comphenix/protocol/ProtocolLibrary at me.JustRayz.rpgcustom.RPGCustom.onEnable(RPGCustom.java:42) ~[?:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot. jar:git-Spigot-eb39b47-0899683] at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java: 335) [spigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java :405) [spigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:355) [spigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:3 15) [spigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:744) [sp igot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.Bukkit.reload(Bukkit.java:534) [spigot.jar:git-Spigot-eb39b47-08 99683] at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [s pigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [sp igot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java :645) [spigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServe r.java:631) [spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [ spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-eb39b47-0899683] at java.lang.Thread.run(Unknown Source) [?:1.8.0_31] Caused by: java.lang.ClassNotFoundException: com.comphenix.protocol.ProtocolLibrary at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_31] at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.8.0_31] at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_31] at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_31] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:1 01) ~[spigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:8 6) ~[spigot.jar:git-Spigot-eb39b47-0899683] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_31] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_31] ... 17 more [22:45:40 INFO]: Server permissions file permissions.yml is empty, ignoring it [22:45:40 INFO]: CONSOLE: Reload complete. >
You need the plugin ProtocolLib on your server and you need the same version of it on your server AND your build path.
Code: package me.JustRayz.rpgcustom; import java.util.ArrayList; import java.util.Collections; import java.util.Set; import java.util.WeakHashMap; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.Configuration; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketContainer; import me.JustRayz.rpgcustom.RPGCustom; import me.JustRayz.rpgcustom.SettingsManager; import net.minecraft.server.v1_8_R3.Block; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.Packet; public class RPGCustom extends JavaPlugin{ private ProtocolManager manager; private Set<Player> sleeping = Collections.newSetFromMap(new WeakHashMap<Player, Boolean>()); public static SettingsManager configmanager = SettingsManager.getInstance(); public static RPGCustom plugin; String prefix = "&8&l[&cServer&8&l] &e".replace("&", "ยง"); ArrayList<String> away = new ArrayList<String>(); @Override public void onEnable(){ manager = ProtocolLibrary.getProtocolManager(); saveConfig(); reloadConfig(); } public void onDisable(){ saveConfig(); } private void playSleepAnimation(Player asleep) { final PacketContainer bedPacket = manager.createPacket(PacketType.Play.Server.BED, false); final Location loc = asleep.getLocation(); // http://wiki.vg/Protocol#Use_Bed bedPacket.getEntityModifier(asleep.getWorld()). write(0, asleep); bedPacket.getIntegers(). write(1, loc.getBlockX()). write(2, loc.getBlockY() + 1). write(3, loc.getBlockZ()); configmanager.getConfig().set(asleep.getName(), asleep.getCustomName()); asleep.setCustomNameVisible(false); asleep.setCustomName(ChatColor.RED + "" + ChatColor.BOLD + "Away " + asleep.getCustomName()); } private void stopSleepAnimation(Player sleeping) { final PacketContainer animation = manager.createPacket(PacketType.Play.Server.ANIMATION, false); // http://wiki.vg/Protocol#Animation animation.getEntityModifier(sleeping.getWorld()). write(0, sleeping); animation.getIntegers(). write(1, 2); sleeping.setCustomNameVisible(true); sleeping.setCustomName((String) configmanager.getConfig().get(sleeping.getName())); } public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args){ if (cmd.getName().equalsIgnoreCase("away")){ if (!(sender instanceof Player)){ return true; }else{ Player p = (Player) sender; if (away.contains(p.getName())){ p.sendMessage(prefix + "You are now " + ChatColor.RED + "no longer away"); stopSleepAnimation(p); away.remove(p.getName()); }else{ p.sendMessage(prefix + "You are now " + ChatColor.RED + "away! " + ChatColor.YELLOW + "Do " + ChatColor.RED + "/away " + ChatColor.YELLOW + "to come back!"); playSleepAnimation(p); away.add(p.getName()); } } } return true; } }
Make sure ProtocolLib is installed on your server with the version you're using in your build and make sure you add it to the depend list inside the plugin.yml.
oh shit yeh, i forgot you have to install it.... Code: ... 14 more [23:07:38 INFO]: JustRayz issued server command: /away [23:07:38 ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'away' in p lugin RPGCustom v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.ja r:git-Spigot-eb39b47-0899683] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[s pigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java :645) ~[spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnectio n.java:1115) [spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [ spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [ spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.ja r:git-Spigot-eb39b47-0899683] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8. 0_31] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31] at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-eb39b47-0899683] at java.lang.Thread.run(Unknown Source) [?:1.8.0_31] Caused by: com.comphenix.protocol.reflect.FieldAccessException: Field index out of bou nds. (Index: 1, Size: 1) at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureMod ifier.java:351) ~[?:?] at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.ja va:327) ~[?:?] at me.JustRayz.rpgcustom.RPGCustom.playSleepAnimation(RPGCustom.java:59) ~[?:? ] at me.JustRayz.rpgcustom.RPGCustom.onCommand(RPGCustom.java:98) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.ja r:git-Spigot-eb39b47-0899683] ... 14 more > Something to do with out of bounds location... I don't know why. I changed the loc from final Location loc = asleep.getLocation(); to asleep.getLocation().getBlockX(); asleep.getLocation().getBlockY + 1(); asleep.getLocation().getBlockZ(); etc and no difference. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
That's something to do with the ProtcolLib packets code and to be honest, I've never really messed with that, but yea it's an IndexOutOfBoundsException. Try checking if the size (bedpacket.getIntegers().size()) is greater than the index.
Code: bedPacket.getIntegers(). write(1, loc.getBlockX()). write(2, loc.getBlockY() + 1). write(3, loc.getBlockZ()); is supposed to be Code: bedPacket.getIntegers(). write(0, loc.getBlockX()). write(1, loc.getBlockY() + 1). write(2, loc.getBlockZ()); But i don't think thats all the changes as it says the size is 1. EDIT: Nvm Code: private void broadcastNearby(Player asleep, PacketContainer bedPacket) { for (Player observer : manager.getEntityTrackers(asleep)) { try { manager.sendServerPacket(observer, bedPacket); } catch (InvocationTargetException e) { throw new RuntimeException("Cannot send packet.", e); } } } You are missing that method you need to call it in playSleepAnimation and stopSleepAnimation EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code: [23:33:04 INFO]: JustRayz issued server command: /away [23:33:04 ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'away' in p lugin RPGCustom v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.ja r:git-Spigot-eb39b47-0899683] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[s pigot.jar:git-Spigot-eb39b47-0899683] at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java :645) ~[spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnectio n.java:1115) [spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [ spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [ spigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.ja r:git-Spigot-eb39b47-0899683] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8. 0_31] at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31] at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [s pigot.jar:git-Spigot-eb39b47-0899683] at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-eb39b47-0899683] at java.lang.Thread.run(Unknown Source) [?:1.8.0_31] Caused by: com.comphenix.protocol.reflect.FieldAccessException: Field index out of bou nds. (Index: 1, Size: 1) at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureMod ifier.java:351) ~[?:?] at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.ja va:327) ~[?:?] at me.JustRayz.rpgcustom.RPGCustom.playSleepAnimation(RPGCustom.java:72) ~[?:? ] at me.JustRayz.rpgcustom.RPGCustom.onCommand(RPGCustom.java:111) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.ja r:git-Spigot-eb39b47-0899683] ... 14 more > new error, ty for everyone helping so far! @MCMatters @khave