Sneaking...

Discussion in 'Spigot Plugin Development' started by valaiyar, Jun 1, 2016.

  1. What I'm trying to pull off is while a player is sneaking with a certain item in their hand a number will increase, and when that number gets to the certain cap that I provide, it will release immediately. And if the player stops sneaking while they are already in the process of the number increasing, it will release with that certain number.

    This certain number will be the radius for certain effects to happen to the players within that radius.

    Now I know how to do most of this, but I've just been having problems/bugs with the sneaking part (no errors, just buggy), and I want to know the best way to do this.

    What I was doing before

    Code (Text):
    hashmap with string (player name) and an integer
    arraylist with string (affected players' names)

    togglesneak event

    if the item in their hand isn't the item i want
    return

    if the player is already in the hashmap then remove them release and add nearby players to arraylist

    else

    put them in a hashmap and a bukkit runnable that increases the number in the hashmap by 1 every second
    and once it gets to 10
    release and add nearby players to arraylist

    playermove event

    if the player's name is in the arraylist
    do something here

    playerquit event

    if the player is in the arraylist or the hashmap remove them

    playerkick event

    if the player is in the arraylist or the hashmap remove them
     
  2. Skript or concept? ;P
     
  3. Keep in mind I did this at about 5 in the morning about 3 weeks ago and I just want to remake it. It's one simple thing part of a big project I'm doing and I wanted to know how I should do it.
     
  4. concept, i don't know skript
     
  5. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerToggleSneakEvent.html

    Just add the user to a Map <String, Integer> with integer as 0 (or 1 if thats what you want to start with) when they toggle sneaking ON.

    When they toggle sneaking OFF then you can just use the number from this Map (the number will be explained below) for whatever it is youre doing. If the user is not in this Map then dont do anything...

    In the meanwhile there should be a master task to runs every tick (or few ticks you want, up to you for accuracy). Every time the event runs the ONLY thing it should do is iterate the entire map and increment each value by 1 (or whatever you want to increment by).

    Thats it. Simple. ;)