SleepBlocker

Discussion in 'Archived: Plugin Requests' started by 544nick101, Dec 8, 2011.

  1. Offline

    544nick101

    NVM im done with this plugin
     
  2. Offline

    BlackHawkLex

    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 :).
     
  3. Offline

    544nick101

    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);
    	}
    
    }
    
    
     
  4. Offline

    Ninjokin

    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.
     
    Last edited by a moderator: May 22, 2016
  5. Offline

    544nick101

    Then... and how do i add multi world support if you know
     
  6. Offline

    Ninjokin

    Do you want me to post my code and explain how to multi-world support works?

    @544nick101
     
  7. Offline

    544nick101

    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 :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  8. Offline

    Ninjokin

    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?
     
  9. Offline

    544nick101

    @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.
     
    Last edited by a moderator: May 22, 2016
  10. Offline

    Ninjokin

    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.
     
    Last edited by a moderator: May 22, 2016
  11. Offline

    544nick101

    so it has world, world_nether and world_the_end disabled right?
     
  12. Offline

    Ninjokin

    With that config, people could use beds in the normal world, but not the nether and the end.
     
  13. Offline

    544nick101

    Good thats just what i wanted you helped so much thank you :D
    Say want to be a mod on my server? It 24/7 SMP and all that
     
  14. Offline

    Ninjokin

    Yea sure!
    My user TheRandomGuy10
     
  15. Offline

    544nick101

    The ips
    nickcraftsmp.net
    Join in :D
     

Share This Page