This forum is in archive mode. You will not be able to post new content.

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - DeathSpirit

Pages: [1]
1
Creative Arts / Re: The Music Thread
« on: April 10, 2012, 08:18:39 PM »
A few of my favourite songs, got a lot more, but yeah.  :P
 
 
Fu-Schnickens - True Fuschnick 
http://www.youtube.com/watch?v=o3TwzXr_jFQ

Biggie Smalls - If I Should Die Before I Wake OG
http://www.youtube.com/watch?v=6uaxMlLuzro

Big Pun and Fat Joe - Twinz
http://www.youtube.com/watch?v=C-XJiiQft_Y

Ice Cube - Check Yo Self
http://www.youtube.com/watch?v=Afr6I74ms9k

50 Cent - Im Supposed To Die Tonight
http://www.youtube.com/watch?v=GeOQSn1KXQs

Tupac - Smoke Weed All Day
http://www.youtube.com/watch?v=U-KQn3WR2_g
 
Bob Marley - Is This Love
http://www.youtube.com/watch?v=CHekNnySAfM

2
General discussion / Re: Any evilzone bodybuilders?
« on: April 09, 2012, 12:56:50 AM »
Yeah, I am.

3
General discussion / Re: Would you be interested in a meetup?
« on: March 28, 2012, 12:02:28 AM »
Yeah I can go to Amsterdam, we can smoke some weed 'n go to the red light district etc.
 
Greetings from the Netherlands.

4
That will be because the Event() is defined in-line, making it an inner-class. I figured as much.

First thing I would recommend is assigning all of those integer values to static finals (constants) so it actually makes more sense when reading the code. c.playerHasItem(6823) && c.playerHasItem(6829) && c.playerHasItem(6835) , doesn't make much sense unless you have an item lookup table.

Not sure how to fix your other problem with inner-classes, you should find a way to pass the variable to the Event class when you make it, perhaps another constructor, or the long winded way of redesigning your code. Which in the long run, might be simpler.
Yes we had a item database

5
nawww, no one asked me for a picture of my dick!
Would you like that?

6


So... did my suggestion fix the problem? :D




... and puddi, not only did you almost post a complete replica of my {broken} code, but you also added another bracket on the end, which would just cause another error to come up xD

Don't troll a programmer bish
No, it didn't.

7
I remember the rebellion XD logging in and being like "dah fuck". The drama with Joepie, boy oh boy was i around for a lot. Comeing back to see that we atleast this time have some settled structure is nice. I hope we keep the drama out of it this time? Ande, a question, what will you do for those Evilzone oldfags who have returned?
Joepie told me that I should take a photo of my dick, what's wrong with him anyway?

8
Yeah well, I asked Mitko to search for the solution since we're part of a development team, I want him to find out stuff too.  :D

9
Why not just use Threads instead of event managers? Is EventManager something you have created yourselves?


I recommend you read the following and implement your event handlers better:

Lesson: Writing Event Listeners
http://download.oracle.com/javase/tutorial/uiswing/events/index.html




Another solution would be to create the new Event() outside of the singleton and just pass it to addevent. Like so.


Code: [Select]

public void doubleBaubleCheck(int a) {

    Event ev = new Event() {
        public void execute(EventContainer g) {
            Client c = (Client) PlayerHandler.players[a];
            // ... your other shit here
        }
    }, 500);

    EventManager.getSingleton().addEvent(ev);
}


This may run into a similar issue though..




Option 3


Because you're probably looking for Timers more than EventManagers. Take a look at this:


http://download.oracle.com/javase/1.4.2/docs/api/java/util/Timer.html

Yes, I wrote the EventManager:
A simple interface for an Event.
Code: [Select]
public interface Event {
 /**
  * Called when the event is executed.
  *
  * @param container
  *            The event container, so the event can dynamically change the
  *            tick time etc.
  */
 public void execute(EventContainer container);
}
Holds extra data for an event (for example the tick time etc).
Code: [Select]
public class EventContainer {
 /**
  * The tick time in milliseconds.
  */
 private int tick;
 /**
  * The actual event.
  */
 private Event event;
 /**
  * A flag which specifies if the event is running;
  */
 private boolean isRunning;
 /**
  * When this event was last run.
  */
 private long lastRun;
 /**
  * The event container.
  *
  * @param evt
  * @param tick
  */
 protected EventContainer(Event evt, int tick) {
  this.tick = tick;
  this.event = evt;
  this.isRunning = true;
  this.lastRun = System.currentTimeMillis();
  // can be changed to 0 if you want events to run straight away
 }
 /**
  * Executes the event!
  */
 public void execute() {
  this.lastRun = System.currentTimeMillis();
  this.event.execute(this);
 }
 /**
  * Gets the last run time.
  *
  * @return
  */
 public long getLastRun() {
  return this.lastRun;
 }
 /**
  * Returns the tick time.
  *
  * @return
  */
 public int getTick() {
  return this.tick;
 }
 /**
  * Returns the is running flag.
  *
  * @return
  */
 public boolean isRunning() {
  return this.isRunning;
 }
 /**
  * Stops this event.
  */
 public void stop() {
  System.out.println("EventManager: EventManaged command has been executed.");
  this.isRunning = false;
 }
}
Manages events which will be run in the future. Has its own thread since some
events may need to be ran faster than the cycle time in the main thread.
Code: [Select]
import java.util.ArrayList;
import java.util.List;
public class EventManager implements Runnable {
 /**
  * A reference to the singleton;
  */
 private static EventManager singleton = null;
 /**
  * The waitFor variable is multiplied by this before the call to wait() is
  * made. We do this because other events may be executed after waitFor is
  * set (and take time). We may need to modify this depending on event count?
  * Some proper tests need to be done.
  */
 private static final double WAIT_FOR_FACTOR = 0.5;
 /**
  * Gets the event manager singleton. If there is no singleton, the singleton
  * is created.
  *
  * @return The event manager singleton.
  */
 public static EventManager getSingleton() {
  if (singleton == null) {
   singleton = new EventManager();
   singleton.thread = new Thread(singleton);
   singleton.thread.start();
  }
  return singleton;
 }
 /**
  * Initialises the event manager (if it needs to be).
  */
 public static void initialise() {
  getSingleton();
 }
 /**
  * A list of events that are being executed.
  */
 private List<EventContainer> events;
 /**
  * The event manager thread. So we can interrupt it and end it nicely on
  * shutdown.
  */
 private Thread thread;
 /**
  * Initialise the event manager.
  */
 private EventManager() {
  events = new ArrayList<EventContainer>();
 }
 /**
  * Adds an event.
  *
  * @param event
  *            The event to add.
  * @param tick
  *            The tick time.
  */
 public synchronized void addEvent(Event event, int tick) {
  events.add(new EventContainer(event, tick));
  notify();
 }
 @Override
 /**
  * Processes events. Works kinda like newer versions of cron.
  */
 public synchronized void run() {
  long waitFor = -1;
  List<EventContainer> remove = new ArrayList<EventContainer>();
  while (true) {
   // reset wait time
   waitFor = -1;
   // process all events
   for (EventContainer container : events) {
    if (container.isRunning()) {
     if ((System.currentTimeMillis() - container.getLastRun()) >= container
       .getTick()) {
      container.execute();
     }
     if (container.getTick() < waitFor || waitFor == -1) {
      waitFor = container.getTick();
     }
    } else {
     // add to remove list
     remove.add(container);
    }
   }
   // remove events that have completed
   for (EventContainer container : remove) {
    events.remove(container);
   }
   remove.clear();
   // no events running
   try {
    if (waitFor == -1) {
     wait(); // wait with no timeout
    } else {
     // an event is running, wait for that time or until a new
     // event is added
     int decimalWaitFor = (int) (Math.ceil(waitFor
       * WAIT_FOR_FACTOR));
     wait(decimalWaitFor);
    }
   } catch (InterruptedException e) {
    break; // stop running
   }
  }
 }
 /**
  * Shuts the event manager down.
  */
 public void shutdown() {
  this.thread.interrupt();
 }
}

 
 

Pages: [1]


Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.