1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +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

@@ -27,6 +27,8 @@ import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.SpawnService;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.pathing.PathingService;
import com.l2jserver.service.game.scripting.ScriptingService;
@@ -67,6 +69,7 @@ public class L2JGameServerMain {
} catch (Exception e) {
System.out.println("GameServer could not be started!");
e.printStackTrace();
System.exit(0);
}
// Thread.sleep(60 * 60 * 1000);
@@ -74,8 +77,13 @@ public class L2JGameServerMain {
/**
* This method does an static spawn for an object
*
* @throws AlreadySpawnedServiceException
* @throws SpawnPointNotFoundServiceException
*/
private static void staticSpawn(Injector injector) {
private static void staticSpawn(Injector injector)
throws SpawnPointNotFoundServiceException,
AlreadySpawnedServiceException {
final NPCTemplateIDProvider templateProvider = injector
.getInstance(NPCTemplateIDProvider.class);
final NPCIDProvider provider = injector

View File

@@ -30,6 +30,7 @@ import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.CharacterService.CannotSetTargetServiceException;
import com.l2jserver.util.dimensional.Coordinate;
/**
@@ -124,6 +125,10 @@ public class CharacterAttackRequestPacket extends AbstractClientPacket {
return;
}
final Actor actor = id.getObject();
try {
charService.attack(character, actor);
} catch (CannotSetTargetServiceException e) {
conn.sendActionFailed();
}
}
}

View File

@@ -25,6 +25,8 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
/**
* The client is requesting a logout. Currently, when this packet is received
@@ -75,6 +77,13 @@ public class EnterWorld extends AbstractClientPacket {
conn.close();
return;
}
// TODO send fail message
try {
characterService.enterWorld(id.getObject());
} catch (SpawnPointNotFoundServiceException e) {
} catch (AlreadySpawnedServiceException e) {
}
}
}

View File

@@ -28,6 +28,7 @@ import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.game.CharacterService.CannotSetTargetServiceException;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.html.markup.HtmlTemplate;
@@ -107,21 +108,25 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
if (conn == null)
return;
throw new RuntimeException("Testing...");
// // target this npc
// charService.target(character, npc);
//
// // generate not implemented message
// final HtmlTemplate template = new HtmlTemplate(name) {
// @Override
// public void build(MarkupTag body) {
// body.text("The NPC ${name} is not yet implemented!", "ff0000")
// .p();
// body.addLink("Click me!", "test");
// }
// };
// template.register("name", name);
// conn.write(new NPCHtmlMessagePacket(npc, template));
// target this npc
try {
charService.target(character, npc);
} catch (CannotSetTargetServiceException e) {
conn.sendActionFailed();
return;
}
// generate not implemented message
final HtmlTemplate template = new HtmlTemplate(name) {
@Override
public void build(MarkupTag body) {
body.text("The NPC ${name} is not yet implemented!", "ff0000")
.p().p();
body.addLink("Click me!", "test");
}
};
template.register("name", name);
conn.write(new NPCHtmlMessagePacket(npc, template));
}
/**

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.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public abstract class AbstractVillageMasterNPCTemplate extends NPCTemplate {
/**
* Creates a new instance of this template
*
* @param id
* the template id
* @param race
* the npc race
*/
protected AbstractVillageMasterNPCTemplate(NPCTemplateID id) {
super(id);
}
}

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -17,14 +17,12 @@
package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class DarkElfVillageMasterNPCTemplate extends NPCTemplate {
public class DarkElfVillageMasterNPCTemplate extends AbstractVillageMasterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,13 +18,12 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class DwarfVillageMasterNPCTemplate extends NPCTemplate {
public class DwarfVillageMasterNPCTemplate extends AbstractVillageMasterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -17,14 +17,12 @@
package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class FightherVillageMasterNPCTemplate extends NPCTemplate {
public class FightherVillageMasterNPCTemplate extends AbstractVillageMasterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -17,14 +17,12 @@
package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class FlyMonsterNPCTemplate extends NPCTemplate {
public class FlyMonsterNPCTemplate extends MonsterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -17,14 +17,12 @@
package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class FriendlyMonsterNPCTemplate extends NPCTemplate {
public class FriendlyMonsterNPCTemplate extends MonsterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,13 +18,12 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class KamaelVillageMasterNPCTemplate extends NPCTemplate {
public class KamaelVillageMasterNPCTemplate extends AbstractVillageMasterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -16,11 +16,8 @@
*/
package com.l2jserver.model.template.npc;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -38,19 +35,4 @@ public class MonsterNPCTemplate extends NPCTemplate {
protected MonsterNPCTemplate(NPCTemplateID id) {
super(id);
}
@Override
public void action(NPC npc, L2Character character, CharacterAction action) {
super.action(npc, character, action);
}
/**
* Called when an character is executing an attack action
*
* @param attacker
* the attacking character
*/
public void attack(L2Character attacker) {
}
}

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,13 +18,12 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class OrcVillageMasterNPCTemplate extends NPCTemplate {
public class OrcVillageMasterNPCTemplate extends AbstractVillageMasterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -17,14 +17,12 @@
package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class PriestVillageMasterNPCTemplate extends NPCTemplate {
public class PriestVillageMasterNPCTemplate extends AbstractVillageMasterNPCTemplate {
/**
* Creates a new instance of this template
*

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -18,7 +18,6 @@ package com.l2jserver.model.template.npc;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.NPC;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -17,15 +17,20 @@
package com.l2jserver.model.world;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.id.TemplateID;
import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.ai.AIScript;
import com.l2jserver.util.calculator.Calculator;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
* NPC stand for "Not Playable Character" and is an character that not player
* has control over it. In most cases they are controlled by an {@link AIScript}
* .
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NPC extends AbstractActor {
/**
@@ -33,6 +38,12 @@ public class NPC extends AbstractActor {
*/
private final NPCTemplateID templateID;
/**
* Creates a new instance
*
* @param templateID
* the {@link NPC} {@link TemplateID}
*/
public NPC(NPCTemplateID templateID) {
this.templateID = templateID;
}

View File

@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.util.ClassUtils;
import com.l2jserver.util.factory.CollectionFactory;

View File

@@ -23,6 +23,8 @@ import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.cache.EhCacheService;
import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.configuration.ProxyConfigurationService;
import com.l2jserver.service.core.Log4JLoggingService;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.MySQLDatabaseService;
import com.l2jserver.service.game.CharacterService;
@@ -43,8 +45,6 @@ import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.WorldServiceImpl;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl;
import com.l2jserver.service.logging.Log4JLoggingService;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.service.network.NettyNetworkService;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.service.network.keygen.BlowfishKeygenService;

View File

@@ -29,6 +29,7 @@ import net.sf.ehcache.config.Configuration;
import net.sf.ehcache.config.DiskStoreConfiguration;
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
import com.google.common.base.Preconditions;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
@@ -58,6 +59,9 @@ public class EhCacheService extends AbstractService implements CacheService {
@Override
public <T extends Cacheable> T decorate(final Class<T> interfaceType,
final T instance) {
Preconditions.checkNotNull(interfaceType, "interfaceType");
Preconditions.checkNotNull(instance, "instance");
if (!interfaceType.isInterface())
return null;
@SuppressWarnings("unchecked")
@@ -85,6 +89,9 @@ public class EhCacheService extends AbstractService implements CacheService {
@Override
public Cache createCache(String name, int size) {
Preconditions.checkNotNull(name, "name");
Preconditions.checkArgument(size > 0, "size <= 0");
Cache cache = new Cache(new CacheConfiguration(name, size)
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
.overflowToDisk(true).eternal(false).timeToLiveSeconds(60)
@@ -96,16 +103,19 @@ public class EhCacheService extends AbstractService implements CacheService {
@Override
public Cache createCache(String name) {
Preconditions.checkNotNull(name, "name");
return createCache(name, 200);
}
@Override
public void register(Cache cache) {
Preconditions.checkNotNull(cache, "cache");
manager.addCache(cache);
}
@Override
public void unregister(Cache cache) {
Preconditions.checkNotNull(cache, "cache");
manager.removeCache(cache.getName());
}

View File

@@ -26,11 +26,11 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
@@ -38,7 +38,7 @@ import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.transformer.Transformer;
import com.l2jserver.util.transformer.TransformerFactory;
@@ -77,6 +77,8 @@ public class ProxyConfigurationService extends AbstractService implements
@Override
@SuppressWarnings("unchecked")
public <C extends Configuration> C get(Class<C> config) {
Preconditions.checkNotNull(config, "config");
if (cache.containsKey(config))
return (C) cache.get(config);
logger.info("Trying to create {} proxy", config);
@@ -242,6 +244,8 @@ public class ProxyConfigurationService extends AbstractService implements
* if any i/o error occur
*/
private Properties findProperties(Class<?> clazz) throws IOException {
Preconditions.checkNotNull(clazz, "clazz");
ConfigurationName config = findAnnotation(ConfigurationName.class,
clazz);
if (config == null)
@@ -270,6 +274,9 @@ public class ProxyConfigurationService extends AbstractService implements
*/
private <T extends Annotation> T findAnnotation(Class<T> annotationClass,
Class<?> clazz) {
Preconditions.checkNotNull(annotationClass, "annotationClass");
Preconditions.checkNotNull(clazz, "clazz");
T ann = clazz.getAnnotation(annotationClass);
if (ann != null)
return ann;
@@ -298,6 +305,7 @@ public class ProxyConfigurationService extends AbstractService implements
* the directory
*/
public void setDirectory(File directory) {
Preconditions.checkNotNull(directory, "directory");
this.directory = directory;
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.core;
import com.l2jserver.service.Service;
/**
* Service used to manage unhandled exceptions
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ExceptionService extends Service {
/**
* Handles an unhandled exception
*
* @param t
* the exception
*/
void thrown(Throwable t);
/**
* Handles an unhandled exception and rethrows it again
*
* @param <T>
* the exception type
* @param t
* the exception
* @throws T
* same exception in <tt>t</tt>
*/
<T extends Throwable> void rethrown(T t) throws T;
}

View File

@@ -14,12 +14,13 @@
* 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.logging;
package com.l2jserver.service.core;
import org.apache.log4j.BasicConfigurator;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
/**
* Logging service implementation for Log4J
@@ -32,4 +33,9 @@ public class Log4JLoggingService extends AbstractService implements
protected void doStart() throws ServiceStartException {
BasicConfigurator.configure();
}
@Override
protected void doStop() throws ServiceStopException {
BasicConfigurator.resetConfiguration();
}
}

View File

@@ -14,7 +14,7 @@
* 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.logging;
package com.l2jserver.service.core;
import org.slf4j.Logger;

View File

@@ -0,0 +1,73 @@
/*
* 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.core.threading;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
* This future instance extends {@link Future} but also adds some additional
* features, such as waiting for an given task to finish.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AsyncFuture<T> extends Future<T> {
/**
* Waits until the task is executed
*
* @throws InterruptedException
* if the thread has been interrupted while waiting
*/
void await() throws InterruptedException;
/**
* Waits until the task is executed
*
* @param timeout
* the timeout
* @param unit
* the timeout unit
*
* @throws InterruptedException
* if the thread has been interrupted while waiting
* @throws TimeoutException
* if timeout was exceeded
*/
void await(long timeout, TimeUnit unit) throws InterruptedException,
TimeoutException;
/**
* Waits until the task is executed
*
* @return true if execution ended with no error, false otherwise
*/
boolean awaitUninterruptibly();
/**
* Waits until the task is executed
*
* @param timeout
* the timeout
* @param unit
* the timeout unit
*
* @return true if execution ended with no error, false otherwise. Please
* note that false will be returned if the timeout has expired too!
*/
boolean awaitUninterruptibly(long timeout, TimeUnit unit);
}

View File

@@ -0,0 +1,58 @@
/*
* 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.core.threading;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import com.l2jserver.service.Service;
/**
* This service is responsible for scheduling tasks and executing them in
* parallel.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ThreadService extends Service {
/**
* Executes an asynchronous tasks.
*
* @param <T>
* the task return type
* @param callable
* the callable instance
* @return the {@link AsyncFuture} notified once the task has completed
*/
<T> AsyncFuture<T> async(Callable<T> callable);
/**
* Executes an asynchronous tasks at an scheduled time. <b>Please note that
* resources in scheduled thread pool are limited and tasks should be
* performed fast.</b>
*
* @param <T>
* the task return type
* @param callable
* the callable instance
* @param delay
* the initial delay to wait before the task is executed
* @param unit
* the time unit of delay
* @return the {@link AsyncFuture} notified once the task has completed
*/
<T> AsyncFuture<T> async(long delay, TimeUnit unit, Callable<T> callable);
}

View File

@@ -0,0 +1,187 @@
/*
* 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.core.threading;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Preconditions;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
/**
* The default implementation for {@link ThreadService}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ThreadServiceImpl extends AbstractService implements ThreadService {
/**
* The logger
*/
private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* The scheduler Thread pool
*/
private ScheduledExecutorService scheduler;
/**
* The asynchronous Thread pool
*/
private ExecutorService async;
@Override
protected void doStart() throws ServiceStartException {
scheduler = Executors.newScheduledThreadPool(10);
async = Executors.newCachedThreadPool();
}
@Override
public <T> AsyncFuture<T> async(Callable<T> callable) {
Preconditions.checkNotNull(callable, "callable");
return new AsyncFutureImpl<T>(async.submit(callable));
}
@Override
public <T> AsyncFuture<T> async(long delay, TimeUnit unit,
Callable<T> callable) {
Preconditions.checkArgument(delay >= 0, "delay < 0");
Preconditions.checkNotNull(unit, "unit");
Preconditions.checkNotNull(callable, "callable");
return new AsyncFutureImpl<T>(scheduler.schedule(callable, delay, unit));
}
@Override
protected void doStop() throws ServiceStopException {
scheduler.shutdown();
async.shutdown();
try {
scheduler.awaitTermination(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.warn("Scheduler thread did not stop in 60 seconds", e);
}
try {
async.awaitTermination(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.warn("Asynchronous thread did not stop in 60 seconds", e);
}
scheduler = null;
async = null;
}
/**
* Simple delegated implementation for {@link AsyncFuture}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @param <T>
* the return type
*/
public static class AsyncFutureImpl<T> implements AsyncFuture<T> {
/**
* The future that is delegated in this implementation
*/
private final Future<T> future;
/**
* Creates a new instance
*
* @param future
* the future
*/
private AsyncFutureImpl(Future<T> future) {
this.future = future;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return future.cancel(mayInterruptIfRunning);
}
@Override
public boolean isCancelled() {
return future.isCancelled();
}
@Override
public boolean isDone() {
return future.isDone();
}
@Override
public T get() throws InterruptedException, ExecutionException {
return future.get();
}
@Override
public T get(long timeout, TimeUnit unit) throws InterruptedException,
ExecutionException, TimeoutException {
return future.get(timeout, unit);
}
@Override
public void await() throws InterruptedException {
try {
this.get();
} catch (ExecutionException e) {
}
}
@Override
public void await(long timeout, TimeUnit unit)
throws InterruptedException, TimeoutException {
try {
this.get(timeout, unit);
} catch (ExecutionException e) {
}
}
@Override
public boolean awaitUninterruptibly() {
try {
this.get();
return true;
} catch (InterruptedException e) {
return false;
} catch (ExecutionException e) {
return false;
}
}
@Override
public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
try {
this.get(timeout, unit);
return true;
} catch (InterruptedException e) {
return false;
} catch (ExecutionException e) {
return false;
} catch (TimeoutException e) {
return false;
}
}
}
}

View File

@@ -39,6 +39,7 @@ import org.apache.commons.pool.impl.GenericObjectPool;
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.id.object.allocator.IDAllocator;
@@ -49,8 +50,8 @@ import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.core.LoggingService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.ArrayIterator;
import com.l2jserver.util.factory.CollectionFactory;
@@ -137,6 +138,7 @@ public class MySQLDatabaseService extends AbstractService implements
* @return an instance of <tt>T</tt>
*/
public <T> T query(Query<T> query) {
Preconditions.checkNotNull(query, "query");
try {
final Connection conn = dataSource.getConnection();
try {
@@ -155,6 +157,7 @@ public class MySQLDatabaseService extends AbstractService implements
@Override
public Object getCachedObject(Object id) {
Preconditions.checkNotNull(id, "id");
final Element element = objectCache.get(id);
if (element == null)
return null;
@@ -163,16 +166,20 @@ public class MySQLDatabaseService extends AbstractService implements
@Override
public boolean hasCachedObject(Object id) {
Preconditions.checkNotNull(id, "id");
return objectCache.get(id) != null;
}
@Override
public void updateCache(Object key, Object value) {
Preconditions.checkNotNull(key, "key");
Preconditions.checkNotNull(value, "value");
objectCache.put(new Element(key, value));
}
@Override
public void removeCache(Object key) {
Preconditions.checkNotNull(key, "key");
objectCache.remove(key);
}
@@ -254,6 +261,7 @@ public class MySQLDatabaseService extends AbstractService implements
@Override
public Integer query(Connection conn) throws SQLException {
Preconditions.checkNotNull(conn, "conn");
int rows = 0;
while (iterator.hasNext()) {
final T object = iterator.next();
@@ -314,6 +322,7 @@ public class MySQLDatabaseService extends AbstractService implements
public static abstract class SelectListQuery<T> implements Query<List<T>> {
@Override
public List<T> query(Connection conn) throws SQLException {
Preconditions.checkNotNull(conn, "conn");
final PreparedStatement st = conn.prepareStatement(query());
parametize(st);
st.execute();
@@ -368,6 +377,7 @@ public class MySQLDatabaseService extends AbstractService implements
public static abstract class SelectSingleQuery<T> implements Query<T> {
@Override
public T query(Connection conn) throws SQLException {
Preconditions.checkNotNull(conn, "conn");
final PreparedStatement st = conn.prepareStatement(query());
parametize(st);
st.execute();
@@ -465,6 +475,7 @@ public class MySQLDatabaseService extends AbstractService implements
@SuppressWarnings("unchecked")
public final T map(ResultSet rs) throws SQLException {
final I id = createID(rs);
Preconditions.checkNotNull(id, "id");
if (database.hasCachedObject(id))
return (T) database.getCachedObject(id);

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
*

Some files were not shown because too many files have changed in this diff Show More