Bukkit death swap recreation help

Discussion in 'Plugin Development' started by matthewgeek123, Jul 11, 2014.

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

    matthewgeek123

    Hi
    I thought I'd re-make minecraft death swap (by sethbling) in bukkit.
    The idea is you do /startswap <player1> <player2> and it starts a process which is basically an infinite timer loop, and at random intervals (generated inside the timer) it swaps the players.
    I have got some of the basic structure but I can't figure out how to get the loop. I'm a bit confused by all the bootstrap stuff.
    Link to code (sorry if its messy): http://pastebin.com/ZgCA9L8K
    Then when you do /stopswap its stops the swapping
    I have googled round but can't get a timer that can stop. Also if I have any variable issues (like randomNum won't update timer etc) please help me fix them.

    Thanks,
    Matthew
    p.s. link to death swap video:
     
  2. Offline

    Gater12

  3. Offline

    TheMcScavenger

    To create a repeating task:
    Code:
    int ID = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
                public void run(){
                    // Your code
                }
            }, 0, 20);
    To cancel it:
    Code:
    Bukkit.getScheduler().cancelTask(ID);
     
  4. Offline

    xTigerRebornx

  5. Offline

    matthewgeek123

    Hi
    I an trying TheMcScaverger's ieda.
    I haven't really played round with it yet but is the 20 at the end the time? Also is it milliseconds or what?

    Matthew
     
  6. Offline

    xTigerRebornx

    matthewgeek123 The 20 is the time in ticks, 20 ticks = 1 second, meaning that code he posted would run every second.
     
  7. Offline

    matthewgeek123

    Hi
    I made the bukkit scheduler function do the loop and it completely crashed my computer. Then my minecraft server kicked me. So is it my computer or something about that bit of code?

    Matthew

    Ok so looking through my log file I found something. Here's a link to the interesting part: http://pastebin.com/1Ze9sYcP
    That goes on for about forever. Then it says
    Code:
    [00:01:42] [Server thread/WARN]: [deathswap_plugin] Task #9359 for deathswap_plugin v1 generated an exception
    java.lang.NullPointerException
    about a million times. Literally. The log file is about 19,000 kb in size. And I stopped the ftp because it was that ridiculous.

    Help!

    Matthew

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  8. Offline

    TheMcScavenger

    Gonna need to see your code. I've once accidentally set it to 1 tick instead of half a second, causing it to crash HARD..
     
  9. Offline

    matthewgeek123

  10. Offline

    matthewgeek123

    ummm... I need help
     
  11. Offline

    DevilMental

    matthewgeek123 Considering your error, you can see that the line 84 from your code throws a NPE.
    Code:java
    1. // Line 84
    2. Location xyz2 = p2.getLocation();

    That means that the player p2 doesn't exist. First, you need to check if the two players in the swap command exist. Then, why do you repeat the loop every time a loop gets executed ? That makes your computer and minecraft lag.
    Tell me what you wanted to do

    Hope that helps,
    ~DevilMental
     
Thread Status:
Not open for further replies.

Share This Page