Thread: GroundItemManager Nullpointer

Results 1 to 3 of 3
  1. #1 GroundItemManager Nullpointer 
    Registered Member
    Join Date
    Oct 2010
    Posts
    705
    Thanks given
    96
    Thanks received
    36
    Rep Power
    16
    Could somebody help me out with this:

    Code:
    java.lang.NullPointerException
    	at org.dementhium.model.GroundItemManager.removeGlobalItem(GroundItemManager.java:74)
    	at org.dementhium.model.GroundItemManager.removeGlobalItem(GroundItemManager.java:81)
    	at org.dementhium.model.GroundItemManager$1.execute(GroundItemManager.java:52)
    	at org.dementhium.event.Tickable.run(Tickable.java:22)
    	at org.dementhium.model.World.processTickables(World.java:296)
    	at org.dementhium.event.impl.UpdateEvent.run(UpdateEvent.java:33)
    	at org.dementhium.GameExecutor$3.run(GameExecutor.java:75)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
    	at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    my GroundItemManager:
    Code:
    package org.dementhium.model;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import org.dementhium.event.Tickable;
    import org.dementhium.model.definition.ItemDefinition;
    import org.dementhium.model.map.Region;
    import org.dementhium.model.player.Player;
    import org.dementhium.net.ActionSender;
    
    /**
     * @author Stephen
     */
    public class GroundItemManager {
    
    	public static final int DEFAULT_DELAY = 60;
    	private List<GroundItem> groundItems = new ArrayList<GroundItem>();
    
    	public void sendGlobalGroundItem(GroundItem item, boolean unique) {
    		checkStacking(null, item);
    		groundItems.add(item);
    		for (Player pl : Region.getLocalPlayers(item.getLocation())) {
    			ActionSender.sendGroundItem(pl, item.getLocation(), item, unique);
    		}
    	}
    
    	/**
    	 * Delay is usually 60.
    	 */
    	public void sendDelayedGlobalGroundItem(int ticks, final GroundItem item, final boolean unique) {
    		checkStacking(item.getDropper(), item);
    		ActionSender.sendGroundItem(item.getDropper(), item.getLocation(), item, unique);
    		groundItems.add(item);
    		World.getWorld().submit(new Tickable(ticks) {
    			int timesThrough = 1;
    			@Override
    			public void execute() {
    				if (timesThrough == 1) {
    					if (worldContainsGroundItem(item.getId(), item.getLocation())) {
    						for (Player pl : Region.getLocalPlayers(item.getLocation())) {
    							if (!pl.equals(item.getDropper())) {
    								item.setGlobal(true);
    								ActionSender.sendGroundItem(pl, item.getLocation(), item, unique);
    							}
    						}
    					}
    					timesThrough++;
    				} else if (timesThrough == 2) {
    					if (item != null) {
    						if (worldContainsGroundItem(item.getId(), item.getLocation())) {
    							removeGlobalItem(item);
    						}
    					}
    					this.stop();
    				}
    			}
    
    		});
    	}
    
    	private void checkStacking(Player player, GroundItem item) {
    		if (getGroundItemAtPos(item.getId(), item.getLocation()) != null) {
    			GroundItem itemToDelete = getGroundItemAtPos(item.getId(), item.getLocation());
    			if (itemToDelete.getDefinition().isStackable() || itemToDelete.getDefinition().isNoted() && (itemToDelete.isGlobal() || (item.getDropper() != null ? item.getDropper().equals(player) : false))) {
    				removeGlobalItem(itemToDelete.getLocation().getX(), itemToDelete.getLocation().getY(), itemToDelete.getLocation().getZ(), itemToDelete.getId());
    				item.setAmount(item.getAmount() + itemToDelete.getAmount());
    			}
    		}
    	}
    
    	public void removeGlobalItem(int x, int y, int z, int itemId) {
    		GroundItem item = getGroundItemAtPos(itemId, Location.create(x, y, z));
    		for (Player p : Region.getLocalPlayers(item.getLocation())) {
    			ActionSender.removeGroundItem(p, item);
    		}
    		groundItems.remove(item);
    	}
    
    	public void removeGlobalItem(GroundItem item) {
    		removeGlobalItem(item.getLocation().getX(), item.getLocation().getY(), 0, item.getId());
    	}
    
    	public boolean worldContainsGroundItem(int itemId, Location pos) {
    		for (GroundItem g : groundItems) {
    			if (g.getLocation().getX() == pos.getX() && g.getLocation().getY() == pos.getY() && g.getLocation().getZ() == pos.getZ() && itemId == g.getId()) {
    				return true;
    			}
    		}
    		return false;
    	}
    
    	public GroundItem getGroundItemAtPos(int itemId, Location pos) {
    		for (GroundItem g : groundItems) {
    			if (g.getLocation().getX() == pos.getX() && g.getLocation().getY() == pos.getY() && g.getLocation().getZ() == pos.getZ() && itemId == g.getId()) {
    				return g;
    			}
    		}
    		return null;
    	}
    	
    	
    	public void refreshItems(Player p) {
    		for (GroundItem g : Region.getLocalItems(p.getLocation())) {
    			if (g.isGlobal()) {
    				ActionSender.sendGroundItem(p, g.getLocation(), g, false);
    			}
    		}
    	}
    	
    	public void removeItems(Player p) {
    		for (GroundItem g : Region.getLocalItems(p.getLocation())) {
    			if (g.isGlobal()) {
    				ActionSender.removeGroundItem(p, g);
    			}
    		}
    	}
    
    	public class GroundItem extends Entity {
    
    		private Item item;
    		private boolean isGlobal = false;
    		private final Player dropper;
    
    		public GroundItem(Player dropper, int id, int amount, Location loc) {
    			this(dropper, new Item(id, amount), loc);
    		}
    
    		public Player getDropper() {
    			return dropper;
    		}
    
    		public GroundItem(Player dropper, Item item, Location loc) {
    			this.item = item;
    			setLocation(loc);
    			this.dropper = dropper;
    		}
    
    		public int getId() {
    			return item.getId();
    		}
    
    		public int getAmount() {
    			return item.getAmount();
    		}
    
    		public void setAmount(int amount) {
    			item.setAmount(amount);
    		}
    
    		public ItemDefinition getDefinition() {
    			return item.getDefinition();
    		}
    
    		public Item getItem() {
    			return item;
    		}
    
    		@Override
    		public boolean isGroundItem() {
    			return true;
    		}
    
    		@Override
    		public GroundItem getGroundItem() {
    			return this;
    		}
    		
    		public void setGlobal(boolean b) {
    			this.isGlobal = b;
    		}
    		
    		public boolean isGlobal() {
    			return isGlobal;
    		}
    
    	}
    
    	public GroundItem create(Player p, Item item, Location location) {
    		return new GroundItem(p, item, location);
    	}
    
    
    }

    Quitted Development
    Spoiler for Siggy ;D:

    Reply With Quote  
     

  2. #2  
    Registered Member
    IngeniousPentaSquid's Avatar
    Join Date
    Jun 2011
    Age
    28
    Posts
    993
    Thanks given
    47
    Thanks received
    140
    Rep Power
    79
    Probably because it is not reading the height. Happens with most dementhium
    ©®
    Reply With Quote  
     

  3. #3  
    Registered Member `Basher's Avatar
    Join Date
    May 2011
    Posts
    447
    Thanks given
    136
    Thanks received
    40
    Rep Power
    23
    Yeh I had this problem a while back also but I used this and fixed it:

    In grounditemmanager.java

    change:
    [code]
    public void removeGlobalItem(GroundItem item) {
    removeGlobalItem(item.getLocation().getX(), item.getLocation().getY(), 0, item.getId());
    }
    [/code[

    to this:
    Code:
    	 public void removeGlobalItem(GroundItem item) {
    		removeGlobalItem(item.getLocation().getX(), item.getLocation().getY(),  item.getLocation().getZ(), item.getId());
    
    	}
    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. Nullpointer, but how?
    By Cjay00091 in forum Help
    Replies: 3
    Last Post: 03-08-2011, 05:34 AM
  2. NullPointer?
    By Phat 4 u in forum Help
    Replies: 21
    Last Post: 07-14-2010, 05:19 AM
  3. Nullpointer
    By Goro in forum Help
    Replies: 3
    Last Post: 07-14-2010, 12:53 AM
  4. NullPointer
    By Cjay00091 in forum Help
    Replies: 3
    Last Post: 06-20-2010, 04:24 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •