Thread: NullPointerException - HELP PLEASE [667]

Results 1 to 6 of 6
  1. #1 NullPointerException - HELP PLEASE [667] 
    Owner of Ikadia || Founder of DX


    Join Date
    Jan 2014
    Posts
    450
    Thanks given
    114
    Thanks received
    32
    Rep Power
    83
    well i wanted to add EvilTree into my server , but when i chop it it gives me a nullpointerexception :
    Spoiler for Code:
    java.lang.NullPointerException
    at com.rs.game.player.content.EvilTree.addChop(EvilTr ee.java:72)
    at com.rs.game.player.actions.Woodcutting.addLog(Wood cutting.java:336)
    at com.rs.game.player.actions.Woodcutting.processWith Delay(Woodcutting.java:319)
    at com.rs.game.player.ActionManager.process(ActionMan ager.java:30)
    at com.rs.game.player.Player.processEntity(Player.jav a:713)
    at com.rs.cores.WorldThread.run(WorldThread.java:56)


    can someone help me please?

    Spoiler for EvilTree.java:

    package com.rs.game.player.content;

    import java.util.Random;

    import com.rs.game.Animation;
    import com.rs.game.Graphics;
    import com.rs.game.player.Player;
    import com.rs.game.tasks.WorldTask;
    import com.rs.game.tasks.WorldTasksManager;
    import com.rs.game.World;
    import com.rs.game.WorldTile;
    import com.rs.utils.WriteFile;
    import com.rs.utils.Misc;
    import com.rs.cache.loaders.ItemDefinitions;
    import com.rs.game.item.Item;
    import com.rs.utils.Utils;
    import com.rs.Settings;
    import com.rs.game.WorldObject;
    import com.rs.game.player.actions.Woodcutting;
    import com.rs.game.player.actions.Woodcutting.TreeDefinit ions;
    import com.rs.game.player.Skills;

    public class EvilTree {

    public static WorldObject EVIL_TREE;
    public static WorldObject[] ROOTS = new WorldObject[5];

    public static final int TREE_X = 2606;
    public static final int TREE_Y = 4770;

    public static final int ROOT_ID = 11426;
    public static final int[][] ROOT_SPAWNS = {{2605, 4772}, {2606, 4769}, {2605, 4771}, {2609, 4771}, {2608, 4773}};

    public static boolean STAGE2 = false;
    public static boolean STAGE3 = false;
    public static boolean STAGEDEAD = false;

    public static int KEY;
    public static int[][] REWARDS = {{10933, 1}, {10939, 1}, {10940, 1}, {10941, 1}, {21416, 1}, {19879, 1}};

    public enum STAGES {

    STAGE_ONE(11436, 1000),
    STAGE_TWO(11435, 500),
    STAGE_THREE(11434, 250),
    DEAD(15488, 0);

    public int objectId, life;

    private STAGES(int objectId, int life) {
    this.objectId = objectId;
    this.life = life;
    }

    public int getId() {
    return objectId;
    }

    public int getLife() {
    return life;
    }
    }

    public static void startChop(Player player, WorldObject object) {
    if(!player.isEvilTree()) {
    return;
    }
    player.getActionManager().setSkill(new Woodcutting(object, TreeDefinitions.NORMAL));
    }

    public static void addChop(WorldObject object, Player player) {
    if(!object.getDefinitions().getName().toLowerCase( ).contains("evil")) {
    return;
    }
    if(object.getDefinitions().getName().toLowerCase() .contains("tree")) {
    if(!canChopTree(object, player)) {
    message(player, "The Evil Tree is immune to your axe whilst it's roots are alive!");
    return;
    }
    player.getSkills().addXp(Skills.WOODCUTTING, 15, true);
    checkTree(player);
    message(player, "You hack away some of the Evil Tree");
    } else {
    player.getSkills().addXp(Skills.WOODCUTTING, 10, true);
    object.takeLife(1);
    checkRoot(player, object);
    message(player, "You hack away some of the Evil Root");
    System.out.println("Root life: "+object.getLife());
    }
    if(player.evilTreeKey != KEY) {
    player.evilTreeKey = KEY;
    player.evilTreeContribution = 0;
    player.evilTreeContribution++;
    }
    player.evilTreeContribution++;
    }

    public static boolean canChopTree(WorldObject object, Player player) {
    boolean canChop = true;
    for(int i=0;i<5;i++) {
    if(ROOTS[i] == null)
    continue;
    if(ROOTS[i].getLife() > 0) {
    canChop = false;
    }
    }
    return canChop;
    }

    public EvilTree() {
    EVIL_TREE = null;
    STAGE2 = false;
    STAGE3 = false;
    STAGEDEAD = false;
    if(EVIL_TREE == null)
    EVIL_TREE = new WorldObject(STAGES.STAGE_ONE.getId(), 10, 1, TREE_X, TREE_Y, 0, STAGES.STAGE_ONE.getLife());
    EVIL_TREE.setLife(STAGES.STAGE_ONE.getLife());
    World.spawnObject(EVIL_TREE, false);
    for(int i=0;i<5;i++) {
    if(ROOTS[i] == null) {
    ROOTS[i] = new WorldObject(ROOT_ID, 10, 1, ROOT_SPAWNS[i][0], ROOT_SPAWNS[i][1], 0, 100);
    }
    ROOTS[i].setLife(100);
    World.spawnObject(ROOTS[i], false);
    }
    KEY = Misc.random(10000000);
    globalMessage("The Evil Tree has grown back! Get down there and kill it! [::eviltree]");
    for(Player players : World.getPlayers()) {
    if(players.isEvilTree()) {
    players.getActionManager().forceStop();
    }
    }
    }

    public static void sendRewards() {
    for(Player players : World.getPlayers()) {
    if(players.isEvilTree()) {
    players.succeedMessage("Well done! You have hacked away the Evil Tree! He will grow back soon so be aware!");
    sendRewards(players);
    }
    }
    }

    public static void message(Player player, String message) {
    player.getPackets().sendGameMessage("<col=ffd700>< shad=03b9ff>"+message);
    }

    public static void globalMessage(String message) {
    for(Player player : World.getPlayers()) {
    player.getPackets().sendGameMessage("<col=ffd700>< shad=03b9ff>"+message);
    }
    }

    public static void sendRewards(Player player) {
    if(player.evilTreeKey != KEY) {
    return;
    }
    int coins = player.evilTreeContribution * 400000;
    player.getInventory().addItem(995, coins);
    message(player, "You've received: Coins x"+coins+" as a reward!");
    int amount = player.evilTreeContribution / 40;
    if(amount == 0) {
    player.errorMessage("You didn't contribute enough to earn any extra rewards!");
    }
    if(amount >= 8)
    amount = 8;
    for(int i=0;i<amount;i++) {
    int index = Misc.random(REWARDS.length);
    Item item = new Item(REWARDS[index][0], REWARDS[index][1]);
    player.getInventory().addItem(item.getId(), item.getAmount());
    message(player, "You've received: "+item.getDefinitions().getName()+" x"+item.getAmount()+" as a reward!");
    int ring = Misc.random(3000);
    if(ring == 232 || ring == 233) {
    globalMessage(player.getDisplayName()+" has received an Enchanted Ring from the Evil Tree!");
    player.getInventory().addItem(19879, 1);
    }
    if(ring == 480 || ring == 500 || ring == 520) {
    globalMessage(player.getDisplayName()+" has received a Dragon Axe from the Evil Tree!");
    player.getInventory().addItem(6739, 1);
    }
    if(ring == 645) {
    globalMessage(player.getDisplayName()+" has received an Inferno Adze from the Evil Tree!");
    player.getInventory().addItem(13661, 1);
    }
    }
    for(int i=0;i<player.evilTreeContribution;i++) {
    //player.getFamiliar().whiteFamiliarReward();
    }
    player.evilTreeContribution = 0;
    player.evilTrees++;
    }

    public static void checkTree(Player player) {
    if(EVIL_TREE.getLife() == STAGES.STAGE_TWO.getLife() && !STAGE2) {
    EVIL_TREE = new WorldObject(STAGES.STAGE_TWO.getId(), 10, 1, TREE_X, TREE_Y, 0, STAGES.STAGE_TWO.getLife());
    globalMessage("The evil tree currently has "+EVIL_TREE.getLife()+" health! [::eviltree]");
    STAGE2 = true;
    }
    if(EVIL_TREE.getLife() == STAGES.STAGE_THREE.getLife() && !STAGE3) {
    EVIL_TREE = new WorldObject(STAGES.STAGE_THREE.getId(), 10, 1, TREE_X, TREE_Y, 0, STAGES.STAGE_THREE.getLife());
    globalMessage("The evil tree currently has "+EVIL_TREE.getLife()+" health! [::eviltree]");
    STAGE3 = true;
    }
    if(EVIL_TREE.getLife() == 0 && !STAGEDEAD) {
    STAGEDEAD = true;
    EVIL_TREE = new WorldObject(STAGES.DEAD.getId(), 10, 1, TREE_X, TREE_Y, 0, STAGES.DEAD.getLife());
    globalMessage(player.getDisplayName()+" had the last hack and killed the Evil Tree!");
    player.evilTreeLatHack++;
    sendRewards();
    World.removeObject(EVIL_TREE, false);
    for(Player players : World.getPlayers()) {
    if(players.isEvilTree()) {
    players.getActionManager().forceStop();
    }
    }
    }
    if(EVIL_TREE != null)
    EVIL_TREE.setLife(1);
    }

    public static void checkRoot(Player player, WorldObject object) {
    if(object.getLife() <= 0) {
    World.removeObject(object, false);
    player.getActionManager().forceStop();
    }
    }
    }
    Attached image
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Feb 2013
    Posts
    4,409
    Thanks given
    59
    Thanks received
    478
    Rep Power
    138
    Edit your original post and include the EvilTree file, and highlight row 72
    Reply With Quote  
     

  3. #3  
    Banned
    Join Date
    Apr 2011
    Age
    29
    Posts
    1,360
    Thanks given
    370
    Thanks received
    184
    Rep Power
    0
    You're most likely passing a null value to addchop and addlog, and woodcutting is having a null issue because evil tree isn't recognized as a tree? Not entirely sure.
    Reply With Quote  
     

  4. #4  
    Owner of Ikadia || Founder of DX


    Join Date
    Jan 2014
    Posts
    450
    Thanks given
    114
    Thanks received
    32
    Rep Power
    83
    Added EvilTree.java
    Attached image
    Reply With Quote  
     

  5. #5  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    WorldObject is probably nulled. If it happens rarely you can add something like:

    Code:
     if (object == null) {
    	return;
     }
    If not, you'll need to work on the addChop method and how it's used.

    My thought is that the object ends up disapearing but the player is still trying to woodcut it and it tries to forcecut it, therefor causing a null error because the object has already been cut by another player.
    Reply With Quote  
     

  6. #6  
    Owner of Ikadia || Founder of DX


    Join Date
    Jan 2014
    Posts
    450
    Thanks given
    114
    Thanks received
    32
    Rep Power
    83
    bump
    Attached image
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Need quick help please [667/711]
    By Xoath in forum Help
    Replies: 4
    Last Post: 04-21-2012, 12:35 AM
  2. 667/706 Error - Help Please
    By xCHRiS in forum Help
    Replies: 2
    Last Post: 04-06-2012, 09:35 PM
  3. 667/704 Error - Need Help Please
    By xCHRiS in forum Help
    Replies: 2
    Last Post: 04-05-2012, 03:16 PM
  4. 667 help please!
    By N9ne in forum Help
    Replies: 1
    Last Post: 03-21-2012, 07:59 AM
  5. 667/704 Help please connects to local
    By garrydowling2011 in forum Help
    Replies: 5
    Last Post: 03-09-2012, 02:37 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •