Thread: [Pi] "Trade" option in shops shuts down the server.

Results 1 to 4 of 4
  1. #1 [Pi] "Trade" option in shops shuts down the server. 
    Registered Member
    Join Date
    Apr 2016
    Posts
    7
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    When i try to trade any shop added in the ActionHandler.java/Shops.cfg the server either restarts without opening the shop interface, or shuts down.

    Code:
    [03/05/16 3:06 AM]: java.lang.NullPointerException
    [03/05/16 3:06 AM]:     at server.model.players.skills.Thieving$pickpocket.access$000(Thieving.java:35)
    [03/05/16 3:06 AM]:     at server.model.players.skills.Thieving.isPickPocketNpc(Thieving.java:114)
    [03/05/16 3:06 AM]:     at server.model.players.ActionHandler.secondClickNpc(ActionHandler.java:1471)
    [03/05/16 3:06 AM]:     at server.model.players.packets.ClickNPC$2.execute(ClickNPC.java:261)
    [03/05/16 3:06 AM]:     at server.event.CycleEventContainer.execute(CycleEventContainer.java:59)
    [03/05/16 3:06 AM]:     at server.event.CycleEventHandler.process(CycleEventHandler.java:63)
    [03/05/16 3:06 AM]:     at server.Server.main(Server.java:137)
    [03/05/16 3:06 AM]: A fatal exception has been thrown!
    [03/05/16 3:06 AM]: Mass save.
    [03/05/16 3:06 AM]: Saving players...
    Press any key to continue . . .
    Reply With Quote  
     

  2. #2  
    Donator
    clrlslwi's Avatar
    Join Date
    Mar 2016
    Posts
    201
    Thanks given
    32
    Thanks received
    110
    Rep Power
    102
    Post the code from the Thieving class if you want help.
    Reply With Quote  
     

  3. #3  
    RSPS SERVICES PROVIDER

    The Plateau's Avatar
    Join Date
    May 2015
    Posts
    999
    Thanks given
    592
    Thanks received
    191
    Rep Power
    129
    Quote Originally Posted by Gamble View Post
    When i try to trade any shop added in the ActionHandler.java/Shops.cfg the server either restarts without opening the shop interface, or shuts down.

    Code:
    [03/05/16 3:06 AM]: java.lang.NullPointerException
    [03/05/16 3:06 AM]:     at server.model.players.skills.Thieving$pickpocket.access$000(Thieving.java:35)
    [03/05/16 3:06 AM]:     at server.model.players.skills.Thieving.isPickPocketNpc(Thieving.java:114)
    [03/05/16 3:06 AM]:     at server.model.players.ActionHandler.secondClickNpc(ActionHandler.java:1471)
    [03/05/16 3:06 AM]:     at server.model.players.packets.ClickNPC$2.execute(ClickNPC.java:261)
    [03/05/16 3:06 AM]:     at server.event.CycleEventContainer.execute(CycleEventContainer.java:59)
    [03/05/16 3:06 AM]:     at server.event.CycleEventHandler.process(CycleEventHandler.java:63)
    [03/05/16 3:06 AM]:     at server.Server.main(Server.java:137)
    [03/05/16 3:06 AM]: A fatal exception has been thrown!
    [03/05/16 3:06 AM]: Mass save.
    [03/05/16 3:06 AM]: Saving players...
    Press any key to continue . . .

    post your Thieving.java here
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Apr 2016
    Posts
    7
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Code:
    package server.model.players.skills;
    
    import java.util.HashMap;
    
    import server.Server;
    import server.event.CycleEvent;
    import server.event.CycleEventContainer;
    import server.event.CycleEventHandler;
    import server.model.players.Client;
    import server.util.Misc;
    import server.model.players.Player;
    import server.model.players.PlayerHandler;
    import server.model.players.ActionHandler;
    
    public class Thieving extends SkillHandler {
    
    	public static boolean playerIsStunned = false;
    	public static long lastStunned;
    	private static boolean playerIsPickpocketing = false;
    	private static boolean successfulThief = true;
    
    	/**
    	 * This enum contains all the items that can
    	 * be pickpocket from each npc. It also contains
    	 * the level required, the xp gained, stun time
    	 * and stun damage.
    	 * 
    	 * To implement this, you will first need to check
    	 * if the npc you are trying to pickpocket is an npc
    	 * that can be pickpocketed. Then, you will call the
    	 * actual pickpocket method below.
    	 * 
    	 * @author L A
    	 *
    	 */
    
    	private static enum pickpocket {
    
    		MAN(new int[] {1, 2, 3}, new int[][] {{995, 3}}, 1, 8, 5, 1),
    		WOMAN(new int[] {4, 5, 6}, new int[][] {{995, 3}}, 1, 8, 5, 1),
    		FARMER(new int[] {7, 1757, 1758, 1759, 1760, 1761}, new int[][] {{995, 9}, {5318, 1}}, 10, 14.5, 5, 1),
    		FEMALE_HAM_MEMBER(new int[] {1715}, new int[][] {{882, 20}, {1351, 1}, {1265, 1}, {1349, 1}, {1267, 1}, {886, 20}, {1353, 1}, {1207, 1}, {1129, 1}, {4170, 1}, {4302, 1}, {4298, 1}, {4300, 1}, {4304, 1}, {4306, 1}, {4308, 1}, {4310, 1}, {995, 21}, {319, 1}, {2138, 1}, {668, 1}, {453, 1}, {440, 1}, {1739, 1}, {314, 5}, {1734, 6}, {1733, 1}, {1511, 1}, {686, 1}, {697, 1}, {1625, 1}, {1627, 1}, {1617, 1}, {199, 1}, {201, 1}, {203, 1}}, 15, 18.5, 4, 3),
    		MALE_HAM_MEMBER(new int[] {1714, 1715}, new int[][] {{882, 20}, {1351, 1}, {1265, 1}, {1349, 1}, {1267, 1}, {886, 20}, {1353, 1}, {1207, 1}, {1129, 1}, {4170, 1}, {4302, 1}, {4298, 1}, {4300, 1}, {4304, 1}, {4306, 1}, {4308, 1}, {4310, 1}, {995, 21}, {319, 1}, {2138, 1}, {668, 1}, {453, 1}, {440, 1}, {1739, 1}, {314, 5}, {1734, 6}, {1733, 1}, {1511, 1}, {686, 1}, {697, 1}, {1625, 1}, {1627, 1}, {199, 1}, {201, 1}, {203, 1}}, 20, 22.5, 4, 3),
    		HAM_GUARD(new int[] {1710, 1711, 1712}, new int[][] {{882, 20}, {1351, 1}, {1265, 1}, {1349, 1}, {1267, 1}, {886, 20}, {1353, 1}, {1207, 1}, {1129, 1}, {4170, 1}, {4302, 1}, {4298, 1}, {4300, 1}, {4304, 1}, {4306, 1}, {4308, 1}, {4310, 1}, {995, 21}, {319, 1}, {2138, 1}, {668, 1}, {453, 1}, {440, 1}, {1739, 1}, {314, 5}, {1734, 6}, {1733, 1}, {1511, 1}, {686, 1}, {697, 1}, {1625, 1}, {1627, 1}, {199, 1}, {201, 1}, {203, 1}, {5321, 4}, {5323, 4}, {5319, 4}, {5324, 1}}, 20, 22.5, 4, 3),
    		WARRIOR_WOMAN(new int[] {15}, new int[][] {{995, 18}}, 25, 26, 5, 2),
    		AL_KHARID_WARRIOR(new int[] {18}, new int[][] {{995, 18}}, 25, 26, 5, 2),
    		ROGUE(new int[] {187}, new int[][] {{995, 120}, {556, 8}, {1523, 1}, {1219, 1}, {1993, 1}, {2357, 1}, {1227, 1}}, 32, 35.5, 5, 20),
    		MASTER_FARMER(new int[] {2234, 2235}, new int[][] {{5318, 1}, {5319, 1}, {5324, 3}, {5323, 2},  {5321, 2}, {5305, 4}, {5307, 2}, {5308, 2}, {5306, 3}, {5309, 2}, {5310, 1}, {5311, 1}, {5101, 1}, {5102, 1}, {5103, 1}, {5104, 1}, {5105, 1}, {5106, 1}, {5096, 1}, {5097, 1}, {5098, 1}, {5099, 1}, {5100, 1}, {5291, 1}, {5292, 1}, {5293, 1}, {5294, 1}, {5295, 1}, {5296, 1}, {5297, 1}, {5298, 1}, {5299, 1}, {5300, 1}, {5301, 1}, {5302, 1}, {5303, 1}, {5304, 1}, {5280, 1}, {5281, 1}}, 38, 43, 5, 3),
    		GUARD(new int[] {9, 10}, new int[][] {{995, 30}}, 40, 46.5, 5, 20),
    		POLLNIVIAN_BEARDED_BANDIT(new int[] {1880, 1881}, new int[][] {{995, 40}}, 45, 65, 5, 5),
    		DESERT_BANDIT(new int[] {1926, 1927, 1928, 1929, 1930, 1931}, new int[][] {{995, 30}, {179, 1}, {1523, 1}}, 53, 79.5, 5, 30),
    		KNIGHT_OF_ARDOUGNE(new int[] {23, 26}, new int[][] {{995, 50}}, 55, 84.3, 5, 3),
    		POLLNIVIAN_BANDIT(new int[] {1883, 1884}, new int[][] {{995, 50}}, 55, 84.3, 5, 5),
    		ARDOUGNE_GUARD(new int[] {32}, new int[][] {{995, 60}, {2309, 1}}, 65, 137.5, 5, 3),
    		MENAPHITE_THUG(new int[] {1904, 1905}, new int[][] {{995, 60}}, 65, 137.5, 5, 5),
    		PALADIN(new int[] {20, 365, 2256}, new int[][] {{995, 80}, {562, 2}}, 70, 151.75, 5, 3),
    		GNOME(new int[] {66, 67, 68}, new int[][] {{995, 300}, {557, 1}, {444, 1}, {569, 1}, {2150, 1}, {2162, 1}}, 75, 198.5, 5, 1),
    		HERO(new int[] {21}, new int[][] {{995, 300}, {560, 2}, {565, 1}, {444, 1}, {1993, 1}, {569, 1}, {1601, 1}}, 80, 273.3, 6, 4);
    
    		private int[] npcId;
    		private int[][] npcYield;
    		private int level, stunTime, damage;
    		private double xp;
    
    		private pickpocket(int[] npcId, int[][] npcYield, int level, double xp, int stunTime, int damage) {
    			this.npcId = npcId;
    			this.npcYield = npcYield;
    			this.level = level;
    			this.xp = xp;
    			this.stunTime = stunTime;
    			this.damage = damage;
    		}
    
    		public static HashMap<Integer, pickpocket> pick = new HashMap<Integer, pickpocket>();
    
    		public static pickpocket forNpcId(int npcId) {
    			return pick.get(npcId);
    		}
    
    		static {
    			for (pickpocket p : pickpocket.values()) {
    				for (int npcId : p.npcId) {
    					pick.put(npcId, p);
    				}
    			}
    		}
    
    		private int[][] getNpcYield() {
    			return npcYield;
    		}
    
    		private int getRequiredLevel() {
    			return level;
    		}
    
    		private double getXp() {
    			return xp;
    		}
    
    		private int getStunTime() {
    			return stunTime;
    		}
    
    		private int damageDealt() {
    			return damage;
    		}
    	}
    
    	/**
    	 * This boolean checks to see if the npc can be pickpocketed or not
    	 * @param npcType The npc id
    	 * @return If the npc is an npc that can be pickpocketed or not
    	 */
    	public static boolean isPickPocketNpc(final int npcType) {
    		final pickpocket p = pickpocket.forNpcId(npcType);
    		for (int i = 0; i < p.npcId.length; i++) {
    			if (npcType == p.npcId[i]) {
    				return true;
    			}
    		}
    		return false;
    	}
    
    	/**
    	 * The lower the return value, the lower the failure rate
    	 * @param c the client
    	 * @param npcType the npc id
    	 * @return an integer to determine how often you will fail
    	 */
    
    	private static int failureRate(final Client c, final int npcType) {
    		final pickpocket p = pickpocket.forNpcId(npcType);
    		double npcFactor = p.getRequiredLevel() / 10;
    		double levelFactor = 100 / ((c.playerLevel[c.playerThieving] + 1) - p.getRequiredLevel());
    		return (int)Math.floor((levelFactor + npcFactor) / 2);
    	}
    
    	/**
    	 * Checks to see if the client has the required level to pickpocket the npc
    	 * @param c the client 
    	 * @param npcType the npc id
    	 * @return if the player has the required level or not
    	 */
    
    	private static boolean canThieveNpc(final Client c, final int npcType) {
    		final pickpocket p = pickpocket.forNpcId(npcType);
    		if (c.playerLevel[c.playerThieving] >= p.getRequiredLevel()) {
    			return true;
    		}
    		c.sendMessage("You need a thieving level of "+ p.getRequiredLevel() +" to pickpocket this "+ p.toString().toLowerCase().replaceAll("_", " "));
    		return false;
    	}
    
    	/**
    	 * This will add the item that you pickpocket
    	 * @param c the client
    	 * @param npcType the npc id
    	 */
    
    	private static void addThievedItem(final Client c, final int npcType) {
    		final pickpocket p = pickpocket.forNpcId(npcType);
    		int i = Misc.random(p.getNpcYield().length - 1);
    		c.getItems().addItem(p.npcYield[i][0], p.npcYield[i][1]);
    		c.getPA().addSkillXP((int) p.getXp() * THIEVING_XP, c.playerThieving);
    
    	}
    
    	/**
    	 * What will happen if you fail to pickpocket the npc
    	 * @param c the client
    	 * @param stunTime how long you will be stunned for
    	 * @param damage how much damage will be dealt
    	 * @param npcId the npc id
    	 */
    
    	private static void applyStun(final Client c, final int stunTime, final int damage, int npcId) {
    		c.startAnimation(c.getCombat().getBlockEmote());
    		c.setHitDiff(damage);
    		c.setHitUpdateRequired(true);
    		c.playerLevel[3] -= damage;
    		c.getPA().refreshSkill(3);
    		playerIsStunned = true;
    		c.gfx100(80);
    		CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    			@Override
    			public void execute(CycleEventContainer container) {
    				if (System.currentTimeMillis() - lastStunned > stunTime) {
    					container.stop();
    				}
    			}
    			@Override
    			public void stop() {
    				playerIsStunned = false;
    				c.startAnimation(65535);
    			}
    		}, 2);
    	}
    
    	/**
    	 * This is the actual method to pickpocket the npc
    	 * @param c the client
    	 * @param npcType the npc id
    	 */
    
    	public static void pickpocketNpc(final Client c, final int npcType) {
    		final pickpocket p = pickpocket.forNpcId(npcType);
    		if (playerIsPickpocketing) {
    			return;
    		}
    		if (System.currentTimeMillis() - c.lastThieve < 2000 || playerIsStunned) {
    			return;
    		}
    		if(c.underAttackBy > 0 || c.underAttackBy2 > 0) {
    			c.sendMessage("You can't pickpocket while in combat!");
    			return;	
    		}
    		if (canThieveNpc(c, npcType)) {
    			c.startAnimation(881);
    			c.sendMessage("You attempt to pickpocket the "+ p.toString().toLowerCase().replaceAll("_", " ") +".");
    			c.lastThieve = System.currentTimeMillis();
    			CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    				@Override 
    				public void execute(CycleEventContainer container) {
    					playerIsPickpocketing = true;						
    					c.startAnimation(881);
    					if (Misc.random(100) < failureRate(c, npcType)) {
    						c.sendMessage("You failed to pickpocket the "+ p.toString().toLowerCase().replaceAll("_", " "));
    						successfulThief = false;
    						container.stop();
    					} else {
    						successfulThief = true;
    						container.stop();
    					}
    				}
    				@Override
    				public void stop() {
    					playerIsPickpocketing = false;
    					if (successfulThief) {
    						c.lastThieve = System.currentTimeMillis();
    						addThievedItem(c, npcType);	
    						c.sendMessage("You successfully pickpocket the "+ p.toString().toLowerCase().replaceAll("_", " ") +".");
    						return;
    					} else if (!successfulThief) {
    						c.lastThieve = System.currentTimeMillis();
    						applyStun(c, p.getStunTime() * 1000, p.damageDealt(), npcType);
    						lastStunned = System.currentTimeMillis();
    						return;
    					}
    				}
    			}, 1);
    		}
    	}
    	/*
    	 * ints that hold that items gained from stealing from stalls
    	 */
    	public static int gem[] = {1623,1623,1623,1623,1623,1621,1621,1621,1621,1619,1619,1619,1617,1617,16311623,1623,1623,1623,1623,1621,1621,1621,1621,1619,1619,1619,1617,1617,1631};
    	public static int randomGem() {
    	return gem[(int) (Math.random() * gem.length)];
    }
    	/*
    	 * Stealing from stalls
    	 */
    	public static void stealFromStall(final Client c, final int id, int amount, int xp, int level, final int i, final int x, final int y, final int face) {
    		if (System.currentTimeMillis() - c.lastThieve < 2500)
    			return;
    		if(c.underAttackBy > 0) {
    			c.sendMessage("You can't steal from a stall while in combat!");
    			return;	
    		}
    		if (c.playerLevel[c.playerThieving] >= level) {
    			if (c.getItems().addItem(id,amount)) {
    				c.startAnimation(832);
    				c.getPA().addSkillXP(xp * THIEVING_XP, c.playerThieving);
    				c.lastThieve = System.currentTimeMillis();
    				c.sendMessage("You steal some coins.");
    
    				Server.objectHandler.createAnObject(c, 634, x, y, face);
    
    				CycleEventHandler.getSingleton().addEvent(c, new CycleEvent() {
    					@Override
    					public void execute(CycleEventContainer container) {
    						Server.objectHandler.createAnObject(c, i, x, y, face);
    						container.stop();
    					}
    					@Override
    					public void stop() {
    
    					}
    				}, getRespawnTime(c, i));
    			}
    		} else {
    			c.sendMessage("You must have a thieving level of " + level + " to thieve from this stall.");
    		}
    	}
    
    	private static int getRespawnTime(Client c, int i) {
    		switch (i) {
    			case 2561: return 4;	//BAKER
    			case 2560: return 12;	//SILK
    			case 7053: return 17;	//SEED
    			case 2563: return 25;	//FUR
    			case 2565: return 50;	//SILVER
    			case 2564: return 130;	//SPICE
    			case 2562: return 500;	//GEM
    			case 14011: return 5;	//JUG
    			default: return 5;
    		}
    	}
    }
    Sorry i haven't been online lately, but a late reply is better than nothing
    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. Replies: 17
    Last Post: 01-15-2015, 11:37 PM
  2. Jagex can shut down a server running in Brasil?
    By IceBlitzRSPS in forum RS2 Server
    Replies: 23
    Last Post: 02-09-2014, 12:24 AM
  3. Replies: 4
    Last Post: 01-18-2012, 05:00 AM
  4. Replies: 7
    Last Post: 12-26-2010, 12:54 PM
  5. Replies: 0
    Last Post: 12-24-2010, 12:33 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
  •