"Unknown command" - Plugin commands not working

Discussion in 'Plugin Development' started by Firemx, Jul 1, 2013.

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

    Firemx

    HashMap<String, Long> startTimes = new HashMap<String, Long>;

    Seems to cause the error: Syntax error on Token(s), Misplaced Construct(s).

    Why is that? :/
     
  2. Offline

    AmShaegar

    missed () at the end. sorry.
    Code:java
    1. HashMap<String, Long> startTimes = new HashMap<String, Long>();
     
  3. Offline

    Firemx

    :p
    Hashmaps become quite confusing at 3AM. XD

    So do I call on the Cooldown 'script' you sent in place of the "Sleep" thread I had?

    EDIT: How exactly does the 'script' work?

    This is what I had assumed:

    Code:java
    1.  
    2. long start = startTimes.get(player.getName()),
    3. // Is this the end "Time", as in (eg.) 9:40:23PM?
    4. end = start + duration;
    5. // Will this constantly check if the time is the end time?
    6. if(end < System.currentTimeMillis()) { // means if current time is after the end
    7. //What exactly goes here?
    8. startTimes.put(player.getName(), System.currentTimeMillis());
    9. } else {
    10. long timeToWait = end - System.currentTimeMillis(); // Is this variable just for display to the user?
     
  4. Offline

    AmShaegar

    First of all: No, you do not have to just replace the Thread.sleep(). I need to understand your code to give a qualified answer.

    If I get that right, your plugin does the following when you enter /afki on:
    1. Wait 30s
      • Interrupt if player moves
    2. Activate AFKI
    I slightly misunderstood it before/was mislead by other comments. So let's rethink the concept.

    1. Wait 30s + 2. Activate AFKI
    Code:
    BukkitTask task = new BukkitRunnable() {
     
        @Override
        public void run() {
            // you code for activating AFKI goes here
            // sendMessage, enableFlying, walkspeed = 0, no dmg ticks = -1
        }
    }.runTaskLater(this, 30*20); // in ticks; 20 ticks per second
    Interrupt if player moves: In order to interrupt the timer you need to save the resulting BukkitTask in a HashMap. This goes into your class as a field:
    Code:
    private HashMap<String, BukkitTask> taskMap = new HashMap<String BukkitTask>();
    Then save the task into that HashMap:
    Code:
    taskMap.add(player.getName(), task);
    Then create a proper Listener that implements PlayerMoveEvent(keywords: Listener, PluginManager, registerEvents, @EventHandler; Tutorial). In that event check if the HashMap contains the player and if so, cancel the task and remove it.

    Code:
    if(taskMap.contains(player.getName()) {
        taskMap.get(player.getName()).cancel();
        taskMap.remove(player.getName());
    }
    You do not need boolean wait, Thread.sleep(), and you do not need setExecutor for your command. Explained that on page 1.

    Disclaimer: All codes are untestested. I typed them strictly from my mind. I did this to teach you how to do it. This may include some thinking on your side.
     
  5. Offline

    Firemx

    It's 3PM now, I should be able to incorporate some thinking of my own. ;)

    Thanks, i'll give it a try. Honestly, your method is a lot more straight forward than mine. XD
     
Thread Status:
Not open for further replies.

Share This Page