Solved Setting player invincible is not possible since change to 1.8

Discussion in 'Plugin Development' started by OverDodo, Jan 28, 2017.

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

    OverDodo

    I canged my craftbukkit.jar to 1.8.8. Now it sayes the following:

    The method isInvulnerable() is undefined for the type Player

    Heres the code:
    @EventHandler
    public void onAdminTool(PlayerInteractEvent e) {
    Player p = e.getPlayer();
    if(p.isInvulnerable() {
    p.sendMessage("...");
    }
     
  2. Offline

    JanTuck

  3. Offline

    Zombie_Striker

    @OverDodo
    Why are you going back to 1.8? You should keep your server up to date and use 1.11.2.

    Read what @JanTuck posted. If that solves, your problem, mark this thread as solved.
     
  4. Offline

    OverDodo

    Hey,

    I went back to 1.8, because I want to have a KitPvP-Server. His post didn't help me at all. I don't know, how to store the Players, who are in GodMode in a HashMap and I don't know, how to add a Player to the HashMap. I am new to HashMaps.
     
  5. Offline

    Drkmaster83

    I'm sure KitPvP can be recreated in 1.11.2 (you could completely ignore the new combat mechanics, I'm sure there are plugins you can decompile or threads to look up that demonstrate this).

    Aside from that, HashMaps are basically objects stored in memory that are an enhanced list (it's the best way to think about it). Maps are formatted in <Key, Value> system, meaning that a key is mapped to a value (similar to how mathematical functions are mapped to points when X is plugged in). If you were to store the key "Hello" with "World" as its value (HashMap#put(key, value)), then try and get "World" back out, this would be accomplished by calling HashMap#get(key) (returns value). It is important to note that if you were to store "Hello" again as the key, it'd replace the value ("World") with whatever you choose.

    Basically, a HashMap creates an easy one-way link to another object. Of course, it can be two-way if you choose to do so (getting a key by a value), but it gets complicated, as multiple different keys can contain the same values.

    Examples of what a HashMap is good for:
    Code:
    HashMap<UUID, Integer> playerScores = new HashMap<UUID, Integer>(); //<Player's UUID, Score>
    HashMap<UUID, Integer> jailTimeLeft = new HashMap<UUID, Integer>(); //<Player's UUID, Jail time in seconds left>
    HashMap<UUID, Integer> godModeDurations = new HashMap<UUID, Integer>(); //<Player's UUID, Time in seconds left in god mode>
    
    When an ArrayList should be used:
    Code:
    ArrayList<UUID> godModePlayers = new ArrayList<UUID>(); //<Player's UUID>
    ArrayList<UUID> flyingPlayers = new ArrayList<UUID>(); //<Player's UUID>
    ArrayList<String> broadcastMessages = new ArrayList<String>(); //<Each respective message to send in chat>
    
    Any questions? Let me know.
     
    Zombie_Striker likes this.
  6. Offline

    Zombie_Striker

    @OverDodo
    As @Drkmaster83 posted, you can get 1.8 combat for 1.11. Going to 1.8 prevents you from getting plugin support and prevents you from getting any new updates for plugins (since most plugins are trying to make it so server have to update their servers to 1.11). You should really stay on 1.11 and just find one of the many combat plugins for pvp.
     
  7. Offline

    OverDodo

    Thanks a lot! Just one more question. Can I make the GodModeDuration unlimited? And how to I "add" a Player's UUID to the HashMap?
     
  8. Offline

    aztk

    1. If you want to have god for some time and ulimited god, use something like boolean isInGod. If isInGod && time > 0 - player has limited god, else if isInGod && time = 0 - player has unlimited god, if isInGod == false, player has no god.

    It is hard to guess what code you're using, so I told probably the easiest solution.

    2. You just have to have HashMap in which you can put UUID and do as you would do in every another HashMap
     
  9. Offline

    Drkmaster83

    This is something I tried to do in my early stages of coding (my plugin Ungodly), but failed -- I tried using hashmaps, but it wasn't necessary for the application. For an infinite boolean, you should just use an ArrayList - it's better for memory and simplicity. HashMaps are only the answer if the second value isn't a boolean, otherwise use an ArrayList.

    To get a player's UUID, you call Player#get UniqueId() and pass that into the add method for the ArrayList. If you still think you want the HashMap, then you'd use HashMap#put(), and the first one would be the UUID. If you want a mix of limited and unlimited duration, then the second value is an Integer (or long), making a HashMap necessary. At this point, I'd make a detection to see if it's a certain negative value on the second part (say, -1337), and if that matches, they're unlimited, and you should subtract from their timer. Alternatively, you can have a HashMap for the limited people and an ArrayList for the unlimited people.
     
  10. Offline

    OverDodo

    I tried now. How do I cancell that event now? I think I was able to put the UUID into the HashMap, but I don´t know, which Event is used for getting damage!
     
  11. Offline

    Drkmaster83

    EntotyDamageEvent, just set it cancelled when the event.getEntity() is the player
     
Thread Status:
Not open for further replies.

Share This Page