Problems with block.getType and onBlockPlace

Discussion in 'Plugin Development' started by andret, Mar 8, 2011.

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

    andret

    I have some problems with getType,
    I cant get either of the following to work, no errors in eclipse:(

    if(block.getType().equals(Material.REDSTONE)){

    if(block.getType() == Material.REDSTONE){

    But the following works:
    if(block.getType() == Material.REDSTONE_ORE){
    if(block.getType() == Material.RAILS){

    Without changeing anything other then "REDSTONE" everything works.

    Is there some other ways to get redstonedust placement then Material.REDSTONE?
    [MERGETIME="1299673677"][/MERGETIME]
    Anyone?

    All other materials works, but redstone dust. If I spawn myself redstonewire and use REDSTONE_WIRE it works, but then again...
    [MERGETIME="1299697913"][/MERGETIME]
    This is just plain stupid, I have now tried using getTypeId() and several other methodes, but I can't get it to fire something when placeing redstone dust.

    I could write a complicated thing that checks if the placed block have power or not,
    or do a if(block.getType().equals) for all other block types, and make do the needed things on else {}

    But this is not an ideal way is it?
    [MERGETIME="1299698950"][/MERGETIME]
    It does not show up with player.sendMessage(block.getType().toString()); so the above method wont work :p
     
  2. Offline

    Nohup

    Are you trying to determine when someone places a redstone wire on a block? If so you are going about it the wrong way... You need to register a player listener and use onPlayerItem. The player isn't placing a block in this case, they are using a material (REDSTONE) on the block that exists...
     
  3. Offline

    andret

    Thats what I was afraid of, and not logic at all.
    If I spawn myself redstonewire instead of redstonedust and place that, I can use blocklistener to do what I want. besides, it works with RAILS.



    Code:
        public void onBlockPlace(BlockPlaceEvent event) {
             //Get the player doing the placing
                Player player = event.getPlayer();
                //Get the block that was placed
                Block block = event.getBlockPlaced();
                Account account = iConomy.getBank().getAccount(player.getName());
                double balance = account.getBalance();
                if(block.getType() == Material.REDSTONE){
                    if (RAILTAX.Permissions.has(player, "nation.nologium")) {
                        player.sendMessage("isNologium Debug");
                  }
                    else  {
                        if(balance > 150){
                            //Take 150 from players account
                            int amount = 150;
                            account.subtract(amount);
                            account.save();
                            player.sendMessage("150EC given to Nologium");
                            Account account1 = iConomy.getBank().getAccount("nation-Nologium");
                            account1.add(amount);
                            account1.save();
    
                                }
                                else {
                                player.sendMessage("Not enough money");
                                   event.setCancelled(true);
                            }
                            }
                }
    //This one works
                if(block.getType() == Material.RAILS){
                    if (RAILTAX.Permissions.has(player, "nation.nologium")) {
                        player.sendMessage("isNologium Debug");
                  }
                    else  {
    
                        if(balance > 250){
                            //Take 250 from players account
                            int amount = 250;
                            account.subtract(amount);
                            account.save();
                            player.sendMessage("250EC given to Nologium ");
                            Account account1 = iConomy.getBank().getAccount("nation-Nologium");
                            account1.add(amount);
                            account1.save();
                                }
                                else {
                                player.sendMessage("Not enough money!");
                                   event.setCancelled(true);
                            }
                            }
                }
                else {
                    player.sendMessage("#Plugin Debug: You placed:" + block.getType().toString());
                }
    
            }
    }
        
     
  4. Offline

    Nohup

    the only rationale that I can think of is that rails don't change the block that is targeted, they go on top of it. Redstone mutates the blocks that exist. In using the latest RB though there is a onBlockRedstoneChange that you can use I bet :) It all just depends on what you are trying to capture.
     
  5. Offline

    andret

    Yea, hehe. I just wanted to check if it was possible with onblockplace. Thanks for your reply :)
     
Thread Status:
Not open for further replies.

Share This Page