Need some help with my plugin...

Discussion in 'Plugin Development' started by Mr_Matijs, May 4, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Mr_Matijs

    Hi, i'm new to bukkit plugins, I want to make a plugin that delete exp from your exp bar when you break blocks, this is what I've got now, but it don't work:

    This is the "ExpBreak.java":
    Code:
    package com.minecraftprison.ExpBreak;
     
    import java.util.logging.Logger;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class ExpBreak extends JavaPlugin{
     
        public static final Logger log = Logger.getLogger("Minecraft"); 
        public final ExpBreakBlockListener blockListener = new ExpBreakBlockListener(null);
     
        public void onEnable(){ 
            getServer().getPluginManager().registerEvents((Listener) blockListener,this); 
        }
     
        public void onDisable(){ 
        log.info("Byebye");
        }
     
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args){
            if (command.getName().equalsIgnoreCase("firstcommand")){
                if (!(sender instanceof Player)){ 
                    log.info("Hello console!");
                    return true;
                }
     
            }
       
       
            return false;
        }
     
    }
    This is the "ExpBreakBlockListener.java":
    Code:
    package com.minecraftprison.ExpBreak;
     
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.Material;
     
    public class ExpBreakBlockListener implements Listener{
     
        public static ExpBreak plugin = new ExpBreak();
     
     
        public ExpBreakBlockListener(ExpBreak plugin)
        {
            ExpBreakBlockListener.plugin = plugin;
        }
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void onBlockPlace(BlockPlaceEvent event){
       
            Player player = event.getPlayer();
            Block block = event.getBlock();
            Material mat = block.getType();
       
       
            if (event.getBlockPlaced().getType().equals(Material.TNT)){
                if (event.getPlayer().hasPermission("firstplugin.tnt")){
                    ExpBreak.log.info(event.getPlayer().getName()+" placed a TNT block!");
                }
                else{
                    event.setCancelled(true);
                    ExpBreak.log.info(event.getPlayer().getName()+" tried to place TNT, but was denied acces.");
                    player.sendMessage("Not allowed to place someting with ID: " + mat);
                }
            }
        }
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event){
            Player player = event.getPlayer();
            Block block = event.getBlock();
            @SuppressWarnings("unused")
            Material mat = block.getType();
       
            if(event.getBlock() != null){
                player.setExp(1);
            }
        }
    }
    
    It will be kind when someone helps me.

    Thanks,

    Matijs
     
  2. Offline

    Komak57

    There seems to be some problems with your setup. Your main file appears to be the old Craftbukkit plugin template, while the Block handler appears to be the new format.
    Check my command handler template for guidelines on your project:
    http://forums.bukkit.org/posts/1105024/
     
  3. Offline

    Mr_Matijs

    Ok thanks, but is the exp get part right ?
     
  4. Offline

    Komak57

    player.setExp(player.getExp()+1); is what you want to increase exp by 1

    if(event.getBlock() != null){} ? Not sure the function of this, since block will never be null? You may want to do a block.getTypeId() and set exp depending on what block was destroyed? That, or keep track of blocks (HashMap<Location, Double> which saves block at locations and the time it was set) to prevent exp farming? (place block, destroy, gain exp, repeat)
     
  5. Offline

    Mr_Matijs

    I did that because eclipse said there was an error, and that was the solution of it, I just want it so if(you destroy a block){exp-1} like that...

    Greetings
     
  6. Offline

    Komak57

    if (player.getExp() > 0) {
    player.setExp(player.getExp()-1);
    } else {
    event.setCancelled(true);
    }

    cmon now, these are the basics >_>
     
  7. Offline

    Mr_Matijs

    Maybe, I'm just trying to learn the basics.
    Thx for re^ply
     
  8. Offline

    Mr_Matijs

    I've a little problem, when I now destroy a block, all the xp is gone, and the level don't gose down.
    So: xp lvl: 500 (bar is full), I destroy block, lvl: 500 (bar is empty). When I destroy a block after this, nothing happend
     
Thread Status:
Not open for further replies.

Share This Page