getSize and setSize for slimes

Discussion in 'Plugin Development' started by bill45, Jun 21, 2011.

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

    bill45

    I'm learning java at the same time of making the plugin, but I can't figure out how to it make so when a slime spawns the size changes. Here is this code I keep kicking around:
    Code:
     public void OnSlimeSpawn(CreatureSpawnEvent event)
          {
              Slime slime;
              event.getEntity();
              event.getCreatureType();
              if(event.getCreatureType()==CreatureType.SLIME)
              {
                  slime= (Slime)event.getEntity();
                     slime.setSize(slime.getSize()*2);
    
              }
     
          }
    I'm probably missing something simple...
     
  2. public void OnSlimeSpawn(CreatureSpawnEvent event)
    Ummm, you should take a closer look at events ;)
    If you listen to a CREATURE_SPAWN-event, your method needs to be called "onCreateSpawn" (with an CreatureSpawnEvent but you already have that).
    Also I highly recommend you to use the "@Override"-annotation, since it directly prevents mistakes like that.
    Code:
    @Override
    public void onCreatureSpawn(CreatureSpawnEvent event){
    ...
     
  3. Offline

    bill45

    Oh..I had no idea that java was like that. Thank you, I was thinking like C++ where I can name the function just about whatever I want unless its the constructor. Thank you very much, it works now and with that info it will help me understand all this better.
     
  4. @bill45
    It's not exactly Java that forces you to take that method-name.
    It's the bukkit-API that just calls a method called "onCreateSpawn" when a creature spawns ...
    You should check out some tutorials to get started though.
     
  5. Offline

    bill45

    Oh I see. That makes more sense.
     
Thread Status:
Not open for further replies.

Share This Page