mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 00:13:11 +00:00
Change-Id: If18611eb0a6296da808aead8f1da54be094db2a9
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package com.l2jserver.service.game.world;
|
||||
|
||||
import com.l2jserver.model.world.event.WorldEvent;
|
||||
|
||||
/**
|
||||
* {@link WorldEventDispatcher} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
public void dispatch(WorldEvent event) {
|
||||
// TODO implement threaded model
|
||||
event.dispatch();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,95 @@
|
||||
package com.l2jserver.service.game.world;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* Service responsible for managing {@link WorldObject} and dispatch events.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface WorldService extends Service, Iterable<WorldObject> {
|
||||
/**
|
||||
* Register a new {@link WorldObject} to the service.
|
||||
* Adds an object into the world.
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
*/
|
||||
void register(WorldObject object);
|
||||
public void add(WorldObject object);
|
||||
|
||||
/**
|
||||
* Removes an registered {@link WorldObject} from the service.
|
||||
* Removes an object of the world
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
*/
|
||||
void unregister(WorldObject object);
|
||||
public void remove(WorldObject object);
|
||||
|
||||
/**
|
||||
* Check if this object is in the world.
|
||||
*
|
||||
* @param object
|
||||
* the object
|
||||
* @return true if object exists
|
||||
*/
|
||||
public boolean contains(WorldObject object);
|
||||
|
||||
/**
|
||||
* Get the event dispatcher
|
||||
*
|
||||
* @return the event dispatcher
|
||||
*/
|
||||
public WorldEventDispatcher getEventDispatcher();
|
||||
|
||||
/**
|
||||
* Creates a list of all objects matching <tt>filter</tt>
|
||||
*
|
||||
* @param <T>
|
||||
* the object type
|
||||
* @param filter
|
||||
* the filter
|
||||
* @return the list of objects
|
||||
*/
|
||||
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter);
|
||||
|
||||
/**
|
||||
* Creates a list of all objects of type <tt>type</tt>
|
||||
*
|
||||
* @param <T>
|
||||
* the type
|
||||
* @param type
|
||||
* the type class
|
||||
* @return the list of objects
|
||||
*/
|
||||
<T extends WorldObject> List<T> list(Class<T> type);
|
||||
|
||||
/**
|
||||
* Get the iterator for this <tt>filter</tt>
|
||||
*
|
||||
* @param <T>
|
||||
* the object type
|
||||
* @param filter
|
||||
* the filter
|
||||
* @return the iterator instance
|
||||
*/
|
||||
<T extends WorldObject> Iterator<T> iterator(
|
||||
final WorldObjectFilter<T> filter);
|
||||
|
||||
/**
|
||||
* Shortcut method for {@link Iterable#iterable()} with filters. The
|
||||
* iterable instance returns the same {@link Iterator} as
|
||||
* {@link #iterator(WorldObjectFilter)}.
|
||||
*
|
||||
* @param <T>
|
||||
* the object type
|
||||
* @param filter
|
||||
* the filter
|
||||
* @return the iterable instance
|
||||
*/
|
||||
<T extends WorldObject> Iterable<T> iterable(
|
||||
final WorldObjectFilter<T> filter);
|
||||
}
|
||||
|
||||
@@ -1,45 +1,91 @@
|
||||
package com.l2jserver.service.game.world;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||
import com.l2jserver.model.world.filter.impl.InstanceFilter;
|
||||
import com.l2jserver.model.world.iterator.FilterIterator;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
public class WorldServiceImpl implements WorldService {
|
||||
private final Set<WorldObject> objects = CollectionFactory
|
||||
.newSet(WorldObject.class);
|
||||
private final WorldEventDispatcher dispatcher;
|
||||
|
||||
@Inject
|
||||
public WorldServiceImpl(WorldEventDispatcher dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
objects.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(WorldObject object) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void add(WorldObject object) {
|
||||
objects.add(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(WorldObject object) {
|
||||
// TODO Auto-generated method stub
|
||||
public void remove(WorldObject object) {
|
||||
objects.remove(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(WorldObject object) {
|
||||
return objects.contains(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldEventDispatcher getEventDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
|
||||
final List<T> list = CollectionFactory.newList(null);
|
||||
for (final T object : this.iterable(filter)) {
|
||||
list.add(object);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> List<T> list(Class<T> type) {
|
||||
return list(new InstanceFilter<T>(type));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<WorldObject> iterator() {
|
||||
// return objects.iterator();
|
||||
return null;
|
||||
return objects.iterator();
|
||||
}
|
||||
|
||||
public <T extends WorldObject> Iterator<T> iterator(WorldObjectFilter<T> filter) {
|
||||
// return objects.iterator();
|
||||
return null;
|
||||
@Override
|
||||
public <T extends WorldObject> Iterator<T> iterator(
|
||||
final WorldObjectFilter<T> filter) {
|
||||
return new FilterIterator<T>(filter, objects.iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> Iterable<T> iterable(
|
||||
final WorldObjectFilter<T> filter) {
|
||||
return new Iterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new FilterIterator<T>(filter, objects.iterator());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws ServiceStopException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
objects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user