Thread: Event Manager Crashs

Results 1 to 5 of 5
  1. #1 Event Manager Crashs 
    Registered Member
    Pilldom's Avatar
    Join Date
    Sep 2007
    Posts
    1,298
    Thanks given
    24
    Thanks received
    221
    Rep Power
    164
    Ok so for my server about a month ago I made cooking. I used only event manager and every thing worked fine. However out of the blue I am getting problems...

    When I try to cook multiple fish (the 5 button for example) this is what happens.

    Starts the cookingTimer(event), once the timer gets to 0, it goes to the cooking method(this second part is in the same method as the timer), it cooks the fish for the second time, HOWEVER, it wont start the event for the second time. Instead if gives me this.

    Code:
    Exception in thread "Thread-0" java.util.ConcurrentModificationException
            at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:3
    72)
            at java.util.AbstractList$Itr.next(AbstractList.java:343)
            at src.EventManager.run(EventManager.java:95)
            at java.lang.Thread.run(Thread.java:619)
    My guess was that it was because I was trying to run the same event at the same time. But even when I throw in a stop(), it still crashs.

    If I just put the timer in the event though, and have it so it checks to see what the timer is at in process, then it works fine.

    Here is my event if it helps.

    Code:
    	public void cookingTimer(){
    		EventManager.getSingleton().addEvent(new Event() {
    			public void execute(EventContainer c) {
    				if(cookingTimer > 0)
    					cookingTimer--;
    			       if(cookingTimer == 1)
    					Server.Cooking.secondStage(amountCooking, playerId);
                                            c.stop();
    			}
    		}, 600);
    	}
    Any help is great.


    EDIT: I found a way around the problem although if any one can tell me why the above dosnt work it would be nice for learning. This works though, simply make the event run every 5 seconds rather then having a timer count, have the event count.

    Code:
    	public void cookingTimer(){
    		EventManager.getSingleton().addEvent(new Event() {
    			public void execute(EventContainer c) {
    				//sM(""+cookingTimer+" "+cookingAmount+" "+amountCooked);
    				if(amountCooked == cookingAmount)
    					c.stop();
    				else if(amountCooked == 0){
    					
    				} else
    					Server.Cooking.secondStage(cookingAmount, playerId);
    			}
    		}, 3000);
    	}
    Attached image
    Reply With Quote  
     

  2. #2  
    Super Donator


    Join Date
    Mar 2009
    Age
    28
    Posts
    1,388
    Thanks given
    316
    Thanks received
    408
    Rep Power
    608
    Your executing a method, which executes another Event. You cannot execute an Event inside an Event. Instead Run 2 events but time them differently.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Pilldom's Avatar
    Join Date
    Sep 2007
    Posts
    1,298
    Thanks given
    24
    Thanks received
    221
    Rep Power
    164
    I am not though, I am having a method call an event, then that event stops, and calls upon the method that called it and it should cycle that way.
    Attached image
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    May 2008
    Posts
    2,327
    Thanks given
    55
    Thanks received
    67
    Rep Power
    0
    lemme see this void
    Server.Cooking.secondStage(

    probably have the same problem i had
    Reply With Quote  
     

  5. #5  
    Registered Member
    Pilldom's Avatar
    Join Date
    Sep 2007
    Posts
    1,298
    Thanks given
    24
    Thanks received
    221
    Rep Power
    164
    Code:
    public void secondStage(int amount, final int a){
    			Client c = (Client) PlayerHandler.players[a];
    			c.cookingAmount = amount;
    				if(c.playerLevel[7] < levelToCook()){
    					c.sendMessage("You need a cooking level of atleast "+levelToCook()+" to cook this");
    				} else {
    					if(!c.playerHasItem(cookingFish, 1)){
    						c.sendMessage("You dont have any more fish to cook");
    						c.amountCooked = 0;
    					} else {
    						c.cookingTimer = 5;
    					        c.cookingTimer();
    						c.amountCooked++;
    						if(c.amountCooked == amount)
    							c.amountCooked = 0;
    						c.setAnimation(883);
    						c.deleteItem(cookingFish, 1);					
    						getCooked(c.playerId);
    					}
    				}
    		}
    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

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •