some events not working?

Discussion in 'Plugin Development' started by _TBCM_, Jul 15, 2020.

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

    _TBCM_

    hey, im a very new Bukkit programmer and im making a R6S plugin. its fine if you dont know what that is! anyway, i havent figured out how to organise my events because some stuff was going wrong on creating new packages in eclipse. soooooo i put my events in my main.java class :/ . the code below shows that 90% is working except for the events PlayerDeathEvent and ProjectileHitEvent. my only guess is that there is a CAP on how many events are allowed in one class, because no one has mentioned my problem before. im using spigot/bukkit 1.15.2 and eclipse.and, can someone guide me through making multiple classes and packages in 1.15.2 / eclipse, as im very confused on that part. i would really appreciate some feedback!(THERE ARE NO ERRORS IN CONSOLE APART FROM ONE WHICH DOESNT RELATE)

    error: no legacy enum for WOODEN_SHOVEL did you forget to mention version 1.13 in your .yml file?

    error elaboration: i dont have WOODEN_SOHOVEL in my code?!
     

    Attached Files:

  2. Offline

    timtower Moderator Moderator

    @_TBCM_ Line 70 "
    publicItemStackitem = newItemStack(Material.WOODEN_SHOVEL);"
    You do have WOODEN_SHOVEL in your code -.-

    doc == EachPlayer.getName().toString()
    That will not work, use String#equals or equalsIgnoreCase instead

    Did you add the api-version in your plugin.yml?
     
  3. Offline

    _TBCM_

    doc == EachPlayer.getName().toString() does actually work, and ill link my plugin.yml

    and as for the wooden shovel, im very blind!
     

    Attached Files:

  4. Offline

    timtower Moderator Moderator

    @_TBCM_ You did not specify the api-version, please do that.
     
  5. Offline

    _TBCM_


    ok, done. but do you have an explanation on why the events arent working?

    i really appreciate your help :)
     
  6. Offline

    timtower Moderator Moderator

    @_TBCM_ So there is not "Player Has Died" message in the terminal when somebody dies?
     
  7. Offline

    _TBCM_

    Nope, it just won’t run...
    I’ve tried /kill and getting friends to kill me and it doesn’t show

    there is also no message OnProjectileHit, when i sumon an arrow at LN:463

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 15, 2020
  8. Offline

    timtower Moderator Moderator

    @_TBCM_ The ProjectileHitEvent is because you can only have the event there, not the hitBlock or projectile.
     
  9. Offline

    Strahan

    There is no limit to the amount of events in a class, no. It would be FAR better though to not throw all your stuff in one class just for the sake of organization. All you need to do in Eclipse is right click src then choose new package. Give it an appropriate name (like me.TheCringeMaster_.plugins.events or something) then you create your event classes in there. Just don't name them like "ProjectileHitEvent" as that already is a class. I just drop the "Event" part when I make event classes.

    Speaking of classes, classes are PascalCase and methods/variables are supposed to be camelCase. It's not going to hurt anything, but it's better if you stop using PascalCase for methods and vars early as you may form the habit otherwise.

    I only took a brief glance at your code but one thing I wanted to mention about your death event is you should not make assumptions when coding. You have "String killer = event.getEntity().getKiller().getName();". If the player fell to their death, there is no killer so the plugin will crash there. You should be sure to check things before assuming they can be used that way. Your code also doesn't take into account whether or not someone is in a game, it just assumes everyone is. For that matter, you realize the way it's coded you can only have one game at a time right?

    Also your randomization could be simplified to just int randPlayer = ThreadLocalRandom.current().nextInt(0, BlueTeam.size()); for example.
     
    _TBCM_ likes this.
  10. Offline

    _TBCM_

    thanks so much for the reply! im not putting it for creating new games for the sake of dev purposes. when the game is 100% complete, i will account for that. and the organisation will come when i finish(this is my first plugin). but does anyone know how to get these events working? its driving me nust thinking about it. :)

    im confused, the event should be running but its not logging "nice shot" or "player has died", so therefore its not running because it cant log a string?


    i followed all the syntax needed just like "event handler" and importing the event from bukkit. it just wont fire

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 15, 2020
  11. Offline

    Strahan

    He means the constructor is wrong. Change:
    Code:
    public void onHit(ProjectileHitEvent event,Block hitBlock,Projectile arrow) {
    to
    Code:
    public void onHit(ProjectileHitEvent event) {
    It isn't firing because of that bad constructor. If you start your server and watch the log, bet my next paycheck you'll see a line where it bitches about that :)
     
  12. Offline

    _TBCM_

    Hmm, I did have that original constructer but I looked at 1.15.2 spigot/bukkit and it said a Player parameter is optional and a block. I’ll try it again though thanks! Any luck on the player death event, my aim is so when a player dies they spectate a random person on their team and get removed from An “ aliveplayers “ array list.
     
Thread Status:
Not open for further replies.

Share This Page