Help - identifying ID with ":"

Discussion in 'Plugin Development' started by GiladS, Sep 13, 2013.

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

    GiladS

    Hello,
    I have this code:
    Code:
    if (s.getTypeId() == 82) {
    I want to make identification of ID like this: 159:14
    But it shows me an error when I do this:
    Code:
    if (s.getTypeId() == 159:14) {
    Error: " Syntax error on token ":", expected "
    What to do? :rolleyes:
     
  2. Offline

    jayfella

    that number after the colon is a damage value, but it has different meanings depending on what it is. If it is a ladder, it would determine its facing state, if it was a sapling, it would determine its treeType..

    You would be better off using generics and casting the item to its inherant type.

    for example:

    Code:java
    1.  
    2. if (this.itemStack.getData() instanceof Colorable)
    3. {
    4. boolean isColored = true;
    5. DyeColor color = ((Colorable)this.itemStack.getData()).getColor();
    6. }
    7.  
    8. if (this.getItemStack().getData() instanceof Tree)
    9. {
    10. boolean isTree = true;
    11. Tree tree = (Tree)this.getItemStack().getData();
    12. TreeSpecies treeSpecies = tree.getSpecies();
    13. }
    14.  


    Not only does this read better, but it also makes your code extremely unlikely to fault.
     
  3. Offline

    GiladS

    I did not understand :(
    It's a big part of the code:
    Code:java
    1. if (s.getTypeId() == 159:14) {
    2. if (!e.getPlayer().hasPermission("s.159:14")){
    3. EconomyResponse m = economy.withdrawPlayer(e.getPlayer().getName(), 600);
    4. if (m.transactionSuccess()){
    5. e.getPlayer().sendMessage(Error1 + s.getType().toString().toLowerCase() + Error2);
    6. permission.playerAdd(e.getPlayer(), "s.159:14");
    7. } else e.getPlayer().sendMessage(Error3);
    8. } else e.getPlayer().sendMessage(Error4);
    9. }

    What do you recommend doing? :rolleyes:
     
  4. Offline

    MisterErwin

    GiladS:

    Code:java
    1. if (s.getTypeID() == 159 && s.getDurability() == 14)
    2.  

    This should work ;)
     
  5. Offline

    GiladS

    It shows me an error :(
    [​IMG]
     
  6. Offline

    Necrodoom

    Removed flame bait.
    jayfella Not everyone knows everything. Insulting them will not get them to understand it better.

    GiladS I recommend reading java tutorials before trying to code plugins, you seem to be missing some information on how java works. You will be able to understand what you are doing much better that way.
     
  7. Offline

    GiladS

    Thank you :)
     
Thread Status:
Not open for further replies.

Share This Page