1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 00:42:56 +00:00

Several improvements

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-21 20:19:13 -03:00
parent 6efce6615f
commit ab38e7d5ba
125 changed files with 969 additions and 205 deletions

View File

@@ -19,8 +19,12 @@ package com.l2jserver.service.game;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.Service;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
import com.l2jserver.util.exception.L2ChatServiceException;
/**
* This service manages {@link L2Character} instances
@@ -33,16 +37,24 @@ public interface CharacterService extends Service {
*
* @param character
* the character
* @throws SpawnPointNotFoundServiceException
* if the character does not have an spawn point defined
* @throws AlreadySpawnedServiceException
* if the character is already spawned in the world
*/
void enterWorld(L2Character character);
void enterWorld(L2Character character)
throws SpawnPointNotFoundServiceException,
AlreadySpawnedServiceException;
/**
* Perform all operations required to this character leave the world
*
* @param character
* the character
* @throws NotSpawnedServiceException
* if the object is not spawned in the world
*/
void leaveWorld(L2Character character);
void leaveWorld(L2Character character) throws NotSpawnedServiceException;
/**
* Set the target of this <tt>character</tt>
@@ -51,8 +63,11 @@ public interface CharacterService extends Service {
* the character
* @param actor
* the targeted actor
* @throws CannotSetTargetServiceException
* if target cannot be set
*/
void target(L2Character character, Actor actor);
void target(L2Character character, Actor actor)
throws CannotSetTargetServiceException;
/**
* Attacks with the given <tt>character</tt> the <tt>target</tt>
@@ -61,8 +76,36 @@ public interface CharacterService extends Service {
* the character
* @param target
* the target
* @throws CannotSetTargetServiceException
* if target cannot be set
*/
void attack(L2Character character, Actor target);
void attack(L2Character character, Actor target)
throws CannotSetTargetServiceException;
/**
* Jails the given <tt>character</tt> for <tt>time</tt> seconds.
*
* @param character
* the character
* @param time
* the jail time, in seconds
* @param reason
* the jail reason
* @throws CharacterInJailServiceException
* if the character is already in jail
*/
void jail(L2Character character, long time, String reason)
throws CharacterInJailServiceException;
/**
* Unjails the given <tt>character</tt>
*
* @param character
* the character to be unjailed
* @throws CharacterNotInJailServiceException
* if character is not in jail
*/
void unjail(L2Character character) throws CharacterNotInJailServiceException;
/**
* Moves the given <tt>character</tt> to <tt>coordinate</tt>
@@ -109,4 +152,32 @@ public interface CharacterService extends Service {
* the character
*/
void run(L2Character character);
/**
* Exception thrown when the target cannot be set
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CannotSetTargetServiceException extends L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when the character is in jail
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterInJailServiceException extends L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when the character is <b>not</b> in jail
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterNotInJailServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.game;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.db.dao.ItemDAO;
import com.l2jserver.game.net.Lineage2Connection;
@@ -47,6 +48,9 @@ import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.chat.ChatMessageDestination;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.chat.channel.ChatChannel;
@@ -114,15 +118,14 @@ public class CharacterServiceImpl extends AbstractService implements
}
@Override
public void enterWorld(final L2Character character) {
public void enterWorld(final L2Character character)
throws SpawnPointNotFoundServiceException,
AlreadySpawnedServiceException {
Preconditions.checkNotNull(character, "character");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
if (conn == null)
return;
if (!worldService.add(character))
// TODO this should throw an exception
// character is already in the world!
return;
itemDao.loadInventory(character);
@@ -224,34 +227,23 @@ public class CharacterServiceImpl extends AbstractService implements
eventDispatcher.dispatch(new CharacterEnterWorldEvent(character));
// spawn the player -- this will also dispatch a spawn event
// here the object is registered in the world
spawnService.spawn(character, null);
}
@Override
public void move(L2Character character, Coordinate coordinate) {
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
// we don't set the character coordinate here, this will be done by
// validation packets, sent by client
// for now, let's just write the packet, we don't have much validation
// to be done yet. With character validation packet, another packet of
// these will be broadcasted.
conn.write(new ActorMovementPacket(character, coordinate));
// we don't dispatch events here, they will be dispatched by
// with the same packet referred up here.
}
@Override
public void leaveWorld(L2Character character) {
if (!worldService.remove(character))
return;
public void leaveWorld(L2Character character)
throws NotSpawnedServiceException {
Preconditions.checkNotNull(character, "character");
spawnService.unspawn(character);
eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character));
}
@Override
public void target(L2Character character, Actor target) {
public void target(L2Character character, Actor target)
throws CannotSetTargetServiceException {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(target, "target");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
@@ -277,17 +269,19 @@ public class CharacterServiceImpl extends AbstractService implements
character, target));
conn.write(new CharacterTargetSelectedPacket(target));
} else {
// this indicates an inconsistency, send an action failed and reset
// target, i.e. deselect with no target
// TODO instead of sending action failed, we should throw an
// exception here
conn.sendActionFailed();
// this indicates an inconsistency: reset target and throws an
// exception
// this happens if tried deselect with no target
character.setTargetID(null);
throw new CannotSetTargetServiceException();
}
}
@Override
public void attack(L2Character character, Actor target) {
public void attack(L2Character character, Actor target)
throws CannotSetTargetServiceException {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(target, "target");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
// check if this Actor can be attacked
@@ -305,19 +299,59 @@ public class CharacterServiceImpl extends AbstractService implements
}
}
@Override
public void jail(L2Character character, long time, String reason)
throws CharacterInJailServiceException {
Preconditions.checkNotNull(character, "character");
Preconditions.checkArgument(time > 0, "time <= 0");
Preconditions.checkNotNull(reason, "reason");
// TODO implement jailing
throw new CharacterInJailServiceException();
}
@Override
public void unjail(L2Character character)
throws CharacterNotInJailServiceException {
Preconditions.checkNotNull(character, "character");
// TODO implement jailing
throw new CharacterNotInJailServiceException();
}
@Override
public void move(L2Character character, Coordinate coordinate) {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(coordinate, "coordinate");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
// we don't set the character coordinate here, this will be done by
// validation packets, sent by client
// for now, let's just write the packet, we don't have much validation
// to be done yet. With character validation packet, another packet of
// these will be broadcasted.
conn.write(new ActorMovementPacket(character, coordinate));
// we don't dispatch events here, they will be dispatched by
// with the same packet referred up here.
}
@Override
public void validate(L2Character character, Point point) {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(point, "point");
// TODO implement position validation
}
@Override
public void receivedValidation(L2Character character, Point point) {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(point, "point");
character.setPoint(point);
eventDispatcher.dispatch(new CharacterMoveEvent(character, point));
}
@Override
public void walk(L2Character character) {
Preconditions.checkNotNull(character, "character");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
// test if character is running
@@ -332,6 +366,7 @@ public class CharacterServiceImpl extends AbstractService implements
@Override
public void run(L2Character character) {
Preconditions.checkNotNull(character, "character");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
// test if character is walking

View File

@@ -24,6 +24,11 @@ import com.l2jserver.service.Service;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface GameTimeService extends Service {
/**
* The real time length of a day in-game in milliseconds.
*/
public static final int GAME_DAY = 120 * 60 * 1000;
/**
* Returns the in-game time
*

View File

@@ -27,7 +27,6 @@ public class GameTimeServiceImpl extends AbstractService implements
GameTimeService {
@Override
public int getGameTime() {
// TODO implement this!
return (int) (System.currentTimeMillis() / 1000);
return (int) (System.currentTimeMillis() % GAME_DAY) / 1000;
}
}

View File

@@ -0,0 +1,38 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.service.game;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.Service;
/**
* This service controls {@link NPC}s
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface MonsterService extends Service {
/**
* Interacts the given <tt>player</tt> with the given <tt>npc</tt>
*
* @param npc
* the npc
* @param character
* the character
*/
void interact(NPC npc, L2Character character);
}

View File

@@ -23,6 +23,7 @@ import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
import com.l2jserver.util.exception.L2SpawnServiceException;
/**
* This service is responsible for spawning monsters, npcs and players.
@@ -41,8 +42,15 @@ public interface SpawnService extends Service {
* @param point
* the spawning point. If null, will try to use
* {@link Spawnable#getPoint()}.
* @throws SpawnPointNotFoundServiceException
* if could not find an spawn point (i.e <tt>point</tt> and
* {@link Spawnable#getPoint()} are null)
* @throws AlreadySpawnedServiceException
* if the object is already spawned in the world
*/
void spawn(Spawnable spawnable, Point point);
void spawn(Spawnable spawnable, Point point)
throws SpawnPointNotFoundServiceException,
AlreadySpawnedServiceException;
/**
* Teleports the object to the given <tt>point</tt>.
@@ -54,11 +62,16 @@ public interface SpawnService extends Service {
* the player object
* @param coordinate
* the teleportation coordinate
* @throws NotSpawnedServiceException
* if the object to be teleported is not spawned
*/
void teleport(Player player, Coordinate coordinate);
void teleport(Player player, Coordinate coordinate)
throws NotSpawnedServiceException;
/**
* Schedules an {@link Spawnable} object to be respawn in a certain time.
* <p>
* TODO this is not complete
*
* @param spawnable
* the spawnable object
@@ -70,6 +83,37 @@ public interface SpawnService extends Service {
*
* @param spawnable
* the spawnable object
* @throws NotSpawnedServiceException
* if the object is not spawned
*/
void unspawn(Spawnable spawnable);
void unspawn(Spawnable spawnable) throws NotSpawnedServiceException;
/**
* Exception thrown when the object is already spawned and registered in the
* world
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AlreadySpawnedServiceException extends L2SpawnServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when the target spawn point is not found
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SpawnPointNotFoundServiceException extends
L2SpawnServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown when trying to unspawn an object that is not spawned
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NotSpawnedServiceException extends L2SpawnServiceException {
private static final long serialVersionUID = 1L;
}
}

View File

@@ -19,6 +19,7 @@ package com.l2jserver.service.game;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.CharacterTeleportPacket;
@@ -72,16 +73,16 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
}
@Override
public void spawn(Spawnable spawnable, Point point) {
public void spawn(Spawnable spawnable, Point point)
throws SpawnPointNotFoundServiceException {
Preconditions.checkNotNull(spawnable, "spawnable");
// sanitize
if (point == null)
// retrieving stored point
point = spawnable.getPoint();
if (point == null) {
// not point send and no point stored, aborting
// TODO this should throw an exception
log.warn("Trying to spawn {} to a null point", spawnable);
return;
throw new SpawnPointNotFoundServiceException();
}
// set the spawning point
@@ -110,6 +111,8 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
@Override
public void teleport(Player player, Coordinate coordinate) {
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(coordinate, "coordinate");
player.setPosition(coordinate);
if (player instanceof L2Character) {
final Lineage2Connection conn = networkService
@@ -127,12 +130,14 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
@Override
public void scheduleRespawn(Spawnable spawnable) {
Preconditions.checkNotNull(spawnable, "spawnable");
// TODO Auto-generated method stub
}
@Override
public void unspawn(Spawnable spawnable) {
Preconditions.checkNotNull(spawnable, "spawnable");
// TODO Auto-generated method stub
}

View File

@@ -22,11 +22,11 @@ import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.core.threading.ThreadService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.service.threading.ThreadService;
import com.l2jserver.util.dimensional.Coordinate;
/**

View File

@@ -16,6 +16,11 @@
*/
package com.l2jserver.service.game.chat;
/**
* Enumeration of all possible message destinations
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum ChatMessageDestination {
/**
* Everyone
@@ -44,9 +49,17 @@ public enum ChatMessageDestination {
/**
* $
*/
ALLIANCE(9), ANNOUNCEMENT(10), BOAT(11), L2FRIEND(12), MSNCHAT(13), PARTYMATCH_ROOM(
14), PARTYROOM_COMMANDER(15), PARTYROOM_ALL(16), HERO_VOICE(17), CRITICAL_ANNOUNCE(
18), SCREEN_ANNOUNCE(19), BATTLEFIELD(20), MPCC_ROOM(21);
ALLIANCE(9),
/**
* Announcement
*/
ANNOUNCEMENT(10),
/**
* Boat
*/
BOAT(11), L2FRIEND(12), MSNCHAT(13), PARTYMATCH_ROOM(14), PARTYROOM_COMMANDER(
15), PARTYROOM_ALL(16), HERO_VOICE(17), CRITICAL_ANNOUNCE(18), SCREEN_ANNOUNCE(
19), BATTLEFIELD(20), MPCC_ROOM(21);
public final int id;

View File

@@ -110,16 +110,32 @@ public interface ChatService extends Service {
// TODO party chat
/**
* Exception thrown when the target of an private chat is not found
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class TargetNotFoundChatServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown if the player is trying to chat with itself.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CannotChatToSelfChatServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;
}
/**
* Exception thrown if the player trying to send a message is currently
* banned.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ChatBanActiveChatServiceException extends
L2ChatServiceException {
private static final long serialVersionUID = 1L;

View File

@@ -19,6 +19,7 @@ package com.l2jserver.service.game.chat;
import java.util.Map;
import java.util.Set;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.model.id.object.CharacterID;
@@ -106,7 +107,12 @@ public class SimpleChatService extends AbstractService implements ChatService {
public void send(CharacterID sender, ChatMessageDestination chat,
String message, String extra)
throws TargetNotFoundChatServiceException,
CannotChatToSelfChatServiceException {
CannotChatToSelfChatServiceException,
ChatBanActiveChatServiceException {
Preconditions.checkNotNull(sender, "sender");
Preconditions.checkNotNull(message, "message");
Preconditions.checkNotNull(extra, "extra");
final ChatChannel channel;
switch (chat) {
case ALL:
@@ -122,7 +128,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
final L2Character character = charDao.selectByName(extra);
if (character == null)
throw new TargetNotFoundChatServiceException();
if (character.equals(sender))
if (character.getID().equals(sender))
throw new CannotChatToSelfChatServiceException();
channel = getChannel(character.getID());
break;
@@ -152,6 +158,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
@Override
public PublicChatChannel getRegionChannel(L2Character character) {
Preconditions.checkNotNull(character, "character");
final Region region = regionService.getRegion(character);
RegionChatChannelImpl channel = regionChannels.get(region);
if (channel == null) {
@@ -163,6 +170,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
@Override
public PrivateChatChannel getChannel(CharacterID character) {
Preconditions.checkNotNull(character, "character");
if (character == null)
return null;
PrivateChatChannelImpl channel = privateChannels.get(character);
@@ -175,6 +183,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
@Override
public PublicChatChannel getChannel(ClanID clan) {
Preconditions.checkNotNull(clan, "clan");
if (clan == null)
return null;
ClanChatChannelImpl channel = clanChannels.get(clan);
@@ -207,6 +216,9 @@ public class SimpleChatService extends AbstractService implements ChatService {
@Override
public void send(CharacterID sender, String message) {
Preconditions.checkNotNull(sender, "sender");
Preconditions.checkNotNull(message, "message");
// TODO throw exception if sender is banned from chat
for (final ChatChannelListener listener : listeners) {
listener.onMessage(this, sender, message);
}
@@ -214,11 +226,13 @@ public class SimpleChatService extends AbstractService implements ChatService {
@Override
public void addChatChannelListener(ChatChannelListener listener) {
Preconditions.checkNotNull(listener, "listener");
listeners.add(listener);
}
@Override
public void removeChatChannelListener(ChatChannelListener listener) {
Preconditions.checkNotNull(listener, "listener");
listeners.remove(listener);
}
}
@@ -233,6 +247,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
private final CharacterID character;
public PrivateChatChannelImpl(CharacterID character) {
Preconditions.checkNotNull(character, "character");
this.character = character;
}
@@ -288,6 +303,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
* @param clanID
*/
public ClanChatChannelImpl(ClanID clanID) {
Preconditions.checkNotNull(clanID, "clanID");
this.clanID = clanID;
}
}
@@ -311,6 +327,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
* @param clanID
*/
public RegionChatChannelImpl(Region region) {
Preconditions.checkNotNull(region, "region");
this.region = region;
}
}

View File

@@ -17,6 +17,7 @@
package com.l2jserver.service.game.chat.channel;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.service.game.chat.ChatService.ChatBanActiveChatServiceException;
/**
* The {@link ChatChannel} object is used to send messages to a channel.
@@ -35,8 +36,11 @@ public interface ChatChannel {
* the character sending the message
* @param message
* the message to be sent
* @throws ChatBanActiveChatServiceException
* if <tt>sender</tt> is banned from chatting
*/
void send(CharacterID sender, String message);
void send(CharacterID sender, String message)
throws ChatBanActiveChatServiceException;
/**
* Adds a {@link ChatChannelListener} that will be notified once a message

View File

@@ -28,16 +28,17 @@ import javax.xml.bind.Unmarshaller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.game.scripting.impl.ScriptContextImpl;
import com.l2jserver.service.game.scripting.scriptmanager.ScriptInfo;
import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
/**
@@ -84,6 +85,7 @@ public class ScriptingServiceImpl extends AbstractService implements
@Override
public synchronized List<ScriptContext> load(File scriptDescriptor)
throws Exception {
Preconditions.checkNotNull(scriptDescriptor, "scriptDescriptor");
final JAXBContext c = JAXBContext.newInstance(ScriptInfo.class,
ScriptList.class);
final Unmarshaller u = c.createUnmarshaller();
@@ -115,6 +117,9 @@ public class ScriptingServiceImpl extends AbstractService implements
*/
private ScriptContext createContext(ScriptInfo si, ScriptContext parent)
throws Exception {
Preconditions.checkNotNull(si, "si");
Preconditions.checkNotNull(parent, "parent");
ScriptContext context = getScriptContext(si.getRoot(), parent);
context.setLibraries(si.getLibraries());
context.setCompilerClassName(si.getCompilerClass());
@@ -153,6 +158,9 @@ public class ScriptingServiceImpl extends AbstractService implements
*/
private ScriptContext getScriptContext(File root, ScriptContext parent)
throws InstantiationException {
Preconditions.checkNotNull(root, "root");
Preconditions.checkNotNull(parent, "parent");
ScriptContextImpl ctx;
if (parent == null) {
ctx = new ScriptContextImpl(injector, root);

View File

@@ -18,6 +18,7 @@ package com.l2jserver.service.game.template;
import java.util.Map;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.model.id.TemplateID;
@@ -27,9 +28,9 @@ import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.game.scripting.ScriptContext;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
@Depends({ LoggingService.class, ConfigurationService.class,
@@ -73,10 +74,13 @@ public class ScriptTemplateService extends AbstractService implements
@Override
@SuppressWarnings("unchecked")
public <T extends Template<?>> T getTemplate(TemplateID<T> id) {
Preconditions.checkNotNull(id, "id");
return (T) templates.get(id);
}
public void addTemplate(Class<? extends Template<?>> t) {
Preconditions.checkNotNull(t, "t");
final Template<?> template = injector.getInstance(t);
if (templates.containsKey(template.getID()))
throw new TemplateException("Template with ID" + template.getID()
@@ -88,6 +92,7 @@ public class ScriptTemplateService extends AbstractService implements
}
public void removeTemplate(Template<?> t) {
Preconditions.checkNotNull(t, "t");
// TODO templates.remove(t);
}

View File

@@ -23,6 +23,7 @@ import net.sf.ehcache.Element;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.db.dao.CharacterDAO;
import com.l2jserver.db.dao.ItemDAO;
@@ -114,6 +115,7 @@ public class CachedWorldIDService extends AbstractService implements
* an collection of ids
*/
private void load(Collection<? extends ObjectID<?>> ids) {
Preconditions.checkNotNull(ids, "ids");
for (final ObjectID<?> id : ids) {
allocator.allocate(id.getID());
add(id);
@@ -123,6 +125,7 @@ public class CachedWorldIDService extends AbstractService implements
@Override
@SuppressWarnings("unchecked")
public <I extends ObjectID<?>> I resolve(int id) {
Preconditions.checkNotNull(id, "id");
if (!loaded) {
// ignore resolving before all IDs are loaded
return null;
@@ -136,6 +139,7 @@ public class CachedWorldIDService extends AbstractService implements
@Override
public <I extends ObjectID<?>> void add(I id) {
Preconditions.checkNotNull(id, "id");
if (id == null)
return;
cache.put(new Element(id.getID(), id));
@@ -143,6 +147,7 @@ public class CachedWorldIDService extends AbstractService implements
@Override
public <I extends ObjectID<?>> void remove(I id) {
Preconditions.checkNotNull(id, "id");
cache.remove(id.getID());
}

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
@@ -31,6 +32,7 @@ import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService;
@@ -41,7 +43,6 @@ import com.l2jserver.service.game.world.filter.WorldObjectFilter;
import com.l2jserver.service.game.world.filter.impl.IDFilter;
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
/**
@@ -87,12 +88,14 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public boolean add(WorldObject object) {
Preconditions.checkNotNull(object, "object");
log.debug("Adding object {} to world", object);
return objects.add(object);
}
@Override
public boolean remove(WorldObject object) {
Preconditions.checkNotNull(object, "object");
log.debug("Removing object {} from world", object);
// we also need to remove all listeners for this object
dispatcher.clear(object.getID());
@@ -101,12 +104,14 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public boolean contains(WorldObject object) {
Preconditions.checkNotNull(object, "object");
return objects.contains(object);
}
@Override
@SuppressWarnings("unchecked")
public <T extends WorldObject> T find(ObjectID<T> id) {
Preconditions.checkNotNull(id, "id");
final IDFilter filter = new IDFilter(id);
for (final WorldObject object : objects) {
if (filter.accept(object))
@@ -118,10 +123,8 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public void knownlist(Positionable object, KnownListCallback callback) {
if (object == null)
return;
if (callback == null)
return;
Preconditions.checkNotNull(object, "object");
Preconditions.checkNotNull(callback, "callback");
for (Positionable known : iterable(new KnownListFilter(object))) {
callback.knownObject(known);
}
@@ -134,6 +137,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
Preconditions.checkNotNull(filter, "filter");
log.debug("Listing objects with filter {}", filter);
final List<T> list = CollectionFactory.newList();
for (final T object : this.iterable(filter)) {
@@ -144,6 +148,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public <T extends WorldObject> List<T> list(Class<T> type) {
Preconditions.checkNotNull(type, "type");
log.debug("Listing of type {}", type);
return list(new InstanceFilter<T>(type));
}
@@ -156,12 +161,14 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public <T extends WorldObject> Iterator<T> iterator(
final WorldObjectFilter<T> filter) {
Preconditions.checkNotNull(filter, "filter");
return new FilterIterator<T>(filter, objects.iterator());
}
@Override
public <T extends WorldObject> Iterable<T> iterable(
final WorldObjectFilter<T> filter) {
Preconditions.checkNotNull(filter, "filter");
return new Iterable<T>() {
@Override
public Iterator<T> iterator() {

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.game.world.event;
import com.google.common.base.Preconditions;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
@@ -30,6 +31,7 @@ public abstract class FilteredWorldListener<T extends WorldObject> implements
private final WorldObjectFilter<T> filter;
public FilteredWorldListener(WorldObjectFilter<T> filter) {
Preconditions.checkNotNull(filter, "filter");
this.filter = filter;
}

View File

@@ -16,6 +16,8 @@
*/
package com.l2jserver.service.game.world.event;
import com.google.common.base.Preconditions;
/**
* This listener will filter to only dispatch an certain type events.
*
@@ -25,6 +27,7 @@ public abstract class TypedWorldListener<T> implements WorldListener {
private final Class<T> type;
public TypedWorldListener(Class<T> type) {
Preconditions.checkNotNull(type, "type");
this.type = type;
}

View File

@@ -28,6 +28,7 @@ import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.AbstractFuture;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
@@ -92,6 +93,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
@Override
public <E extends WorldEvent> WorldEventFuture<E> dispatch(E event) {
Preconditions.checkNotNull(event, "event");
log.debug("Queing dispatch for event {}", event);
final WorldEventFutureImpl<E> future = new WorldEventFutureImpl<E>();
events.add(new EventContainer(event, future));
@@ -119,10 +121,9 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
if (!listener.dispatch(event.event))
// remove listener if return value is false
listeners.remove(listener);
} catch (ClassCastException e) {
log.debug(
"Exception in Listener. This might indicate an implementation issue in {}",
listener.getClass());
} catch (Throwable t) {
log.warn("Exception in listener", t);
// always remove any listener that throws an exception
listeners.remove(listener);
}
}
@@ -132,33 +133,43 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
@Override
public void addListener(WorldListener listener) {
Preconditions.checkNotNull(listener, "listener");
log.debug("Adding new listener global {}", listener);
globalListeners.add(listener);
}
@Override
public void addListener(WorldObject object, WorldListener listener) {
Preconditions.checkNotNull(object, "object");
Preconditions.checkNotNull(listener, "listener");
addListener(object.getID(), listener);
}
@Override
public void addListener(ObjectID<?> id, WorldListener listener) {
Preconditions.checkNotNull(id, "id");
Preconditions.checkNotNull(listener, "listener");
log.debug("Adding new listener {} to {}", listener, id);
getListeners(id).add(listener);
}
@Override
public void removeListener(WorldListener listener) {
Preconditions.checkNotNull(listener, "listener");
globalListeners.remove(listener);
}
@Override
public void removeListener(WorldObject object, WorldListener listener) {
Preconditions.checkNotNull(object, "object");
Preconditions.checkNotNull(listener, "listener");
removeListener(object.getID(), listener);
}
@Override
public void removeListener(ObjectID<?> id, WorldListener listener) {
Preconditions.checkNotNull(id, "id");
Preconditions.checkNotNull(listener, "listener");
log.debug("Removing new listener {} from {}", listener, id);
getListeners(id).remove(listener);
}
@@ -170,6 +181,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
* the object id
*/
public void clear(ObjectID<?> id) {
Preconditions.checkNotNull(id, "id");
listeners.remove(id);
}
@@ -182,6 +194,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
* @return the {@link Set}. Never null.
*/
private Set<WorldListener> getListeners(ObjectID<?> id) {
Preconditions.checkNotNull(id, "id");
Set<WorldListener> set = listeners.get(id);
if (set == null) {
set = CollectionFactory.newSet();
@@ -189,7 +202,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
}
return set;
}
public void stop() {
timer.cancel();
timer = null;

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.game.world.filter.impl;
import com.google.common.base.Preconditions;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
@@ -38,6 +39,7 @@ public class IDFilter implements WorldObjectFilter<WorldObject> {
* the desired object ID
*/
public IDFilter(final ObjectID<?> id) {
Preconditions.checkNotNull(id, "id");
this.id = id;
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.game.world.filter.impl;
import com.google.common.base.Preconditions;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
@@ -40,6 +41,7 @@ public class InstanceFilter<T extends WorldObject> implements
* the instance type
*/
public InstanceFilter(Class<?> instance) {
Preconditions.checkNotNull(instance, "instance");
this.type = instance;
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.game.world.filter.impl;
import com.google.common.base.Preconditions;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
@@ -43,6 +44,8 @@ public class RangeFilter implements WorldObjectFilter<Positionable> {
* the desired maximum distance of the object
*/
public RangeFilter(final Positionable object, final int range) {
Preconditions.checkNotNull(object, "object");
Preconditions.checkState(range >= 0, "range < 0");
this.object = object;
this.range = range;
}