Calculating time(I don't know where is the error.)

Discussion in 'Plugin Development' started by ServerfromMinecraft, Apr 2, 2013.

Thread Status:
Not open for further replies.
  1. Hi!

    After a long break, i want to re-start coding plugins - And since the start the command prompt showed me an error, but don't know why... It's just a little test-plugin.

    The Error:

    PHP:
    org.bukkit.command.CommandExceptionUnhandled exception executing command 'test_ra' in plugin Test_RA v1.0
            at org
    .bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    8
    )
            
    at org.bukkit.craftbukkit.v1_5_R2.CraftServer.dispatchCommand(CraftServe
    r
    .java:523)
            
    at net.minecraft.server.v1_5_R2.PlayerConnection.handleCommand(PlayerCon
    nection
    .java:966)
            
    at net.minecraft.server.v1_5_R2.PlayerConnection.chat(PlayerConnection.j
    ava
    :884)
            
    at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java
    :841)
            
    at net.minecraft.server.v1_5_R2.Packet3Chat.handle(Packet3Chat.java:44)
            
    at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292
    )
            
    at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java
    :110)
            
    at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
            
    at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:3
    0
    )
            
    at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:5
    78
    )
            
    at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:2
    25
    )
            
    at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:4
    74
    )
            
    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java
    :407)
            
    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:5
    73
    )
    Caused byjava.lang.NullPointerException
            at 
    --.---.--.Cmd.getWaitingTime(Cmd.java:58)
            
    at --.---.--.Cmd.repairInv(Cmd.java:32)
            
    at --.---.--.Cmd.onCommand(Cmd.java:20)
            
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 
    15 more
    My "Cmd" Class, implementing the CommandExecutor-Interface:
    PHP:
    public class Cmd implements CommandExecutor {
     
    protected 
    TR mc;
    public 
    Cmd(TR mainclass){
    mc mainclass;
    }
     
    @
    Override
    public boolean onCommand(CommandSender senderCommand cmdString labelString[] args) {
    if(
    cmd.getName().equalsIgnoreCase("Test_RA")){
    if(
    sender instanceof Player){
    repairInv((Player)sender);
    }
    }
    return 
    true;
    }
     
     
    void repairInv(Player p){
    int max mc.timeperms.keySet().size();
    int c 0;
    for(
    String perm mc.timeperms.keySet()){
    if(
    p.hasPermission("Test_RA." perm)){
    int wait getWaitingTime(p);
    if(
    wait == 0){
    reloadTimestamp(pperm);
    for(
    ItemStack is p.getInventory().getContents()){
    ItemStack isn = new ItemStack(is.getTypeId(), is.getAmount());
    isn.addEnchantments(is.getEnchantments());
    p.getInventory().remove(is);
    p.getInventory().addItem(isn);
    }
    p.sendMessage("WORKS!");
    break;
    }else{
    p.sendMessage("WAIT!");
    break;
    }
    }
    c++;
    }
    if( 
    != max ){
    p.sendMessage("NOPERM!");
    }
    }
     
    int getWaitingTime(Player p){
    if(
    mc.pt.containsKey(p.getName())){
    TimeStamp ts mc.pt.get(p);
    ts.setNew(System.nanoTime());
    return 
    ts.calculateDifference();
    }else{
    return 
    0;
    }
    }
     
    void reloadTimestamp(Player pString perm){
    mc.pt.put(p.getName(), new TimeStamp(00));
    }
     
    }
    TimeStamp Class:
    PHP:
    public class TimeStamp {
     
    private 
    long beforeafter;
    public 
    TimeStamp(long oldlong now){
    before oldafter now;
    }
     
    public 
    void setOld(long o){
    before o;
    }
    public 
    void setNew(long n){
    after n;
    }
    public 
    long getOld(){
    return 
    before;
    }
    public 
    long getNew(){
    return 
    after;
    }
    public 
    void reset(){
    before 0;after 0;
    }
    public 
    int calculateDifference(){
    return (int) ((
    after before) * 1000000000);
    }
     
    }
    What is wrong? I did not get it...
    Can anyone maybe help me please :(?
    Kindly Regards,
    -

    Anyone has an Idea :(?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    Ribesg

  3. Ribesg I already tryed to solve it by myself, but failed.

    Oh, and here the line where the error "happens" (Sorry that i've forgotten to post it before :( ...):
    Code:
    ts.setNew(System.nanoTime());
    The rest of the code ist above.
     
  4. Offline

    Ribesg

    ts is null.
     
  5. But it can't, I surrounded it by an if-query - Oh..

    if(mc.pt.containsKey(p.getName())){
    TimeStamp ts = mc.pt.get(p);

    I see, sorry xD!

    Thanks :)!
     
Thread Status:
Not open for further replies.

Share This Page