using block ids and not block names

Discussion in 'Plugin Development' started by fondelaar, Jun 22, 2012.

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

    fondelaar

    hey, im wondering how i can do the following:

    i have the following code:
    Code:
        public void onBlockPlace(BlockPlaceEvent event){
            if (event.isCancelled()) return;
     
            if (event.getBlock().getType() == Material.TNT){
                event.setCancelled(true);
     
                Player player = event.getPlayer();
    
    i want to replace the "material.TNT" with a block id, so i can use any item with it (so items from mods as well)

    what do i need to replace it with?
     
  2. Material.matchMaterial(int id) try something like that
     
  3. Offline

    fondelaar

    matchMaterial cannot be resolved or is not a field

    this is the code that i have now:

    Code:
    package com.gmail.fondelaar.nukenotify;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Nukenotify extends JavaPlugin{
     
        public void onEnable(){
            getLogger().info ("notifying placed nukes now!");{
               
            }
        }
        public void onDisable(){
            getLogger().info("Disabling Nukenotify");{
               
            }
        }
       
        public void onBlockPlace(BlockPlaceEvent event){
     
            if (event.getBlock().getType() == Material.X237){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed a NUKE!");
               
                return;
     
                }
            if (event.getBlock().getType() == Material.X126:10){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed a NOVA CATALYST!");
               
                return;
     
                }
            if (event.getBlock().getType() == Material.X126:11){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed a NOVA CATALYSM!");
               
                return;
     
                }
            if (event.getBlock().getType() == Material.X239){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed INDUSTRIAL TNT!!");
               
                return;
     
                }
        }
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  4. there is no Material.X237
    Material.X126:10 is not java
     
  5. Offline

    fondelaar

    yea, well this plugin is for tekkit but i can fix that problem. if i would replace X237 with 46 would it work?
     
  6. you cant use teccit things whit bukkit, bukkit is bukkit, not tekkic, use Material.TNT for tnt
     
  7. Offline

    nisovin

    Just use getTypeId() instead of getType().
     
  8. Offline

    fondelaar

    i can. tekkit has bukkit. when i use tekkit instead of bukkit there are no buggs. and ill try the get typeid thing

    only 1 thing: how do i add the seccond part of an item id? so for example, coloured wool: 35:5
    how do i add the :5
     
  9. check the data value of the target block
     
  10. Use getTypeId() to check for ID and getDurability() to check for data number...
    Code:
    if(block.getTypeId() == 126 && block.getDurability() == 10)
    {
        //...
    }

    The .getData() is confusing for some people, as it returns another object which contains methods to get the byte data value and material... IMO it's better to just use get/setDurability() because it's also a short value which can hold bigger values.
     
  11. Offline

    fondelaar

    Code:
    package com.gmail.fondelaar.nukenotify;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Nukenotify extends JavaPlugin{
     
        public void onEnable(){
            getLogger().info ("notifying placed nukes now!");{
               
            }
        }
        public void onDisable(){
            getLogger().info("Disabling Nukenotify");{
               
            }
        }
       
        public void onBlockPlace(BlockPlaceEvent event){
     
            if(block.getTypeId() == 327 && block.getDurability() == 0){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed a NUKE!");
               
                return;
     
                }
            if(block.getTypeId() == 126 && block.getDurability() == 10){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed a NOVA CATALYST!");
               
                return;
     
                }
            if(block.getTypeId() == 126 && block.getDurability() == 11){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed a NOVA CATALYSM!");
               
                return;
     
                }
            if(block.getTypeId() == 239 && block.getDurability() == 0){
     
                Player player = event.getPlayer();
     
                player.chat("Hey, I just placed INDUSTRIAL TNT!!");
               
                return;
     
                }
        }
    }
    now im getting "block cant be resolved" so for some reason it doesnt know what a block is.
     
  12. That's because it doesn't exist... if you don't know what variables are then you should start learning some basic Java, it will save everybody alot of headache, yourself included :}
     
Thread Status:
Not open for further replies.

Share This Page