How i can set a permanent life

Discussion in 'Spigot Plugin Development' started by RavortMC, Jun 8, 2015.

  1. Hey, sorry for my noob question, how i can set a permanent life to all players?
  2. Are you talking about invincibility?

    If so, just listen to the EntityDamageEvent, check if the entity is an instance of player, then cancel the event.
  3. Ok so you need to create an onPlayerDamage() method like this:
    public void onPlayerDamage(EntityDamageEvent event) {
        if(godPlayers.containsKey(p.getName())) {
    so now we have told our server what to do with players in our array list "godPlayers" now we add the array list:
    public ArrayList<String> godPlayers = new ArrayList<String>();
    Now we can add players to our ArrayList how we please (command, ect) ect, basically we throw this wherever we need it:
    Don't forget to register the event in your onEnable() method:
    getServer().getPluginManager().registerEvents(this, this);
    Make sure your class implements listener
    And your virtually done, good luck!
    #3 Karatechimp29, Jun 8, 2015
    Last edited: Jun 8, 2015
    • Funny Funny x 1
  4. Oh thanks you!
  5. And you failed to 1) explain what certain things are doing 2) giving bad code to spoonfeed
    You should brush up on your java before you attempt to teach people
    Not gonna waste my time fixing bad spoonfed code and the bad explanations that came with it
  6. I'm not on an IDE ATM...
    Where have I faulted?
    #6 Karatechimp29, Jun 8, 2015
    Last edited: Jun 8, 2015
  7. EntityDamageEvent -> no instance check, checking if a list contains an entity object (which would lead to a mem leak if not cleaned up)
    list -> not declaring with supertype, hard typing it to ArrayList, is String generic type when you used Entity earlier, why do you even need a list if its for all players? umm you dont
    registering events, you should avoid making your main plugin instance a listener instance, and if not, the code you put doesnt tell a user what each param type for registerEvents, they'd have to look them up themselves

    Not having an IDE is not an excuse for shoddy spoonfeeding code. If you can't write proper spoonfeeding code with proper explanations, then either write a paragraph covering what to do in chronological order, or give pseudo code. (though if you're not gonna write decent pseudo code, then a paragraph would be better)
    • Agree Agree x 1
    • Winner Winner x 1
  8. Use a HashSet rather than an ArrayList, as it's faster for contains