Simple block-protection plugin

Discussion in 'Archived: Plugin Requests' started by randomizer1234, Jan 15, 2013.

  1. Offline

    randomizer1234

    Hello,
    can anyone write (and mostly important compile, because I can't do it, otherwise I would have also written the plugin itself) a simple plugin which listens for block breaking and block placing events and cancels them if the Player is not OP?
    I need it because of the fact that a player in adventure mode is still able to break transparent blocks, and allowing a Player in my server to do this means that he can break vital parts of the map :(
    I know I could do this with existing plugin, but I'm doing this request because a simple ad-hoc plugin would be much much faster.
    I need it for Bukkit-1.4.6-R0.3.

    Thank you very much!

    EDIT: and maybe a /food command which gives the player 5 red apples? (in the same plugin)

    Thanks :)

    EDIT 2: I've written the plugin, can anyone compile it for me?
    plugin.yml:
    Code:
    name: TFHelper
    main: eu.th3game.tfhelper.TFHelperMainClass
    version: 0.0.1
     
    commands:
        food:
            description: This command give 3 apples.
            usage: /food
    TFHelperMainClass.java:
    PHP:
    package eu.th3game.tfhelper;
     
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.Listener;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.Command;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
     
    public final class 
    TFHelperMainClass extends JavaPlugin implements Listener {
        @
    Override
        
    public void onEnable() {
            
    getServer().getPluginManager().registerEvents(thisthis);
        }
       
        public 
    boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {
            if (
    cmd.getName().equalsIgnoreCase("food")) {
                if (
    sender instanceof Player) {
                    ((
    Player)sender).getInventory().addItem(new ItemStack(2603));
                }
                return 
    true;
            }
            return 
    false;
        }
       
        @
    EventHandler(priority EventPriority.MONITOR)
        public 
    void onBlockBreakEvent(BlockBreakEvent e) {
            if (!
    e.getPlayer().isOp()) {
                
    e.setCancelled(true);
            }
        }
       
        @
    EventHandler(priority EventPriority.MONITOR)
        public 
    void onBlockPlaceEvent(BlockPlaceEvent e) {
            if (!
    e.getPlayer().isOp()) {
                
    e.setCancelled(true);
            }
        }
    }
    I've written the code with Notepad, so if I've forgot to import anything, please do it for me :)
     
  2. Offline

    Craftiii4

    If you have permissionsEX, this can block it anyway's I believe.
     
  3. Offline

    randomizer1234

    I don't have permissionsEX, and it couldn't help me with the food thing anyway.
    I've written the plugin by myself, now I only need someone who can compile it for me, because I don't have my PC at the moment and I can't install anything on this one...

    Sorry if I bump this, but I need is urgently :(

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

    JayzaSapphire

    randomizer1234 likes this.
  5. Offline

    randomizer1234

    Thank you very much! :D
     

Share This Page