Well go into the onPlayerBedEnter event. Cancel the event, and broadcast or send the message you want to. Then have a config where a list of worlds where this should take place is defined. Put in some if-clauses and your done .
Here is my code so far i cant get it to work (this is my second plugin) Code: package me.plugins.sleep; import java.util.logging.Logger; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Type; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; public class sleepblocker extends JavaPlugin { private static final Priority DENY = null; Logger log = Logger.getLogger ("Minecraft"); @Override public void onDisable() { log.info ("SleepBlocker 1.0 Has Been Disabled D:"); } @Override public void onEnable() { log.info ("SleepBlocker 1.0 Has Been Enabled :D"); PluginManager pm = getServer().getPluginManager (); pm.registerEvent (Event.Type.PLAYER_BED_ENTER , Priority.Normal, DENY); } }
Got it done in 24 33 lines. So your not far off! If you need any help, feel free to ask me anything! That includes a configuration like this where you can specify what worlds people can sleep in. Code: worlds: worldname: true/false You should change: Code: pm.registerEvent(Event.Type.PLAYER_BED_ENTER, Priority.Normal, DENY); to: Code: pm.registerEvent(Event.Type.PLAYER_BED_ENTER, new PlayerListen(), Priority.Normal, this); and create a new class called PlayerListen @544nick101 EDIT by Moderator: merged posts, please use the edit button instead of double posting.
So this should work right? sleepblocker.java Code: package me.plugins.sleep; import java.util.logging.Logger; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; public class sleepblocker extends JavaPlugin { Logger log = Logger.getLogger ("Minecraft"); @Override public void onDisable() { log.info ("SleepBlocker 1.0 Has Been Disabled D:"); } @Override public void onEnable() { log.info ("SleepBlocker 1.0 Has Been Enabled :D"); PluginManager pm = getServer().getPluginManager (); pm.registerEvent(Event.Type.PLAYER_BED_ENTER, new PlayerListen(), Priority.Normal, this); } } PlayerListen Code: package me.plugins.sleep; import org.bukkit.event.Listener; public class PlayerListen implements Listener { } If you would EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Sure! The code is: Code: package tk.ninjokin.sleepblocker; import java.util.logging.Logger; import org.bukkit.configuration.Configuration; import org.bukkit.event.Event; import org.bukkit.event.player.PlayerBedEnterEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.plugin.java.JavaPlugin; public class SleepBlocker extends JavaPlugin { public void onEnable() { Log.info("Plugin now enabled!"); getServer().getPluginManager().registerEvent(Event.Type.PLAYER_BED_ENTER, new PlayerListener() { public void onPlayerBedEnter(PlayerBedEnterEvent event) { if(config.getBoolean("worlds." + event.getPlayer().getWorld().getName(), false) == true) { saveConfig(); event.setCancelled(true); event.getPlayer().sendMessage("You can't sleep in this world!"); } } }, Event.Priority.Normal, this); config = getConfig(); saveConfig(); } public void onDisable() { Log.info("Plugin now disabled!"); } protected Configuration config; private Logger Log = Logger.getLogger("Minecraft"); } Lets look at this code: Code: if(config.getBoolean("worlds." + event.getPlayer().getWorld().getName(), false) == true) { saveConfig(); event.setCancelled(true); event.getPlayer().sendMessage("You can't sleep in this world!"); } What this does, is get the config.yml file and attempt to find a Boolean (a true or false) under the tag of worlds.worldnamehere. If it equals true, the event is cancelled and I send a message. If false, it lets them sleep. This will make the config.yml file look like: Code: worlds: myworld123: true Thats how the multi world bit works. Understand now?
@Ninjokin And how would i go about adding a error message like "You Can't Sleep" O nvm you added that THX so much in do you mind if i message you if i have a problem with another plugin and im putting you in the credits EDIT by Moderator: merged posts, please use the edit button instead of double posting.
And if you want it, http://goo.gl/5M2wO To use it, just open the config.yml in the plugins folder and use this format: Code: worlds: world: false world_nether: true world_the_end: true but replace the 'world, world_nether, etc' with your world names! Nope thats fine! You can ask me anything.... I don't know everything but I will always try to help! EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Good thats just what i wanted you helped so much thank you Say want to be a mod on my server? It 24/7 SMP and all that