diff --git a/.classpath b/.classpath
index ca7327a91..0ff9af658 100644
--- a/.classpath
+++ b/.classpath
@@ -3,8 +3,6 @@
-
-
diff --git a/data/.gitignore b/data/.gitignore
index 0c17b5b9d..3303592d0 100644
--- a/data/.gitignore
+++ b/data/.gitignore
@@ -1,2 +1,3 @@
/cache
/pathing.db
+/database.h2.db
diff --git a/data/script/ai/script/AIInterest.java b/data/script/ai/script/AIInterest.java
deleted file mode 100644
index ba987a13d..000000000
--- a/data/script/ai/script/AIInterest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package script;
-
-/**
- * The {@link AIInterest} defines what the AI is interested in doing.
- *
- * @author Rogiel
- */
-public enum AIInterest {
- /**
- * Idle
- */
- INTEREST_IDLE,
- /**
- * Will scan for attackable targets, if mob is aggressive or if it is
- * aggrided.
- */
- INTEREST_ACTIVE,
- /**
- * Rest (sit until attacked)
- */
- INTEREST_REST,
- /**
- * Attack target (cast combat magic, go to target, combat), may be ignored,
- * if target is locked on another character or a peacefull zone and so on
- */
- INTEREST_ATTACK,
- /**
- * Cast a spell, depending on the spell - may start or stop attacking
- */
- INTEREST_CAST,
- /**
- * Just move to another location
- */
- INTEREST_MOVE_TO,
- /**
- * Like move, but check target's movement and follow it
- */
- INTEREST_FOLLOW,
- /**
- * PickUp and item, (got to item, pickup it, become idle
- */
- INTEREST_PICK_UP,
- /**
- * Move to target, then interact
- */
- INTEREST_INTERACT;
-}
\ No newline at end of file
diff --git a/data/script/ai/script/AIScriptFactory.java b/data/script/ai/script/AIScriptFactory.java
deleted file mode 100644
index a5fb860ee..000000000
--- a/data/script/ai/script/AIScriptFactory.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package script;
-
-import script.ai.CharacterAI;
-
-import com.google.inject.Inject;
-import com.l2jserver.game.net.Lineage2Connection;
-import com.l2jserver.model.id.object.CharacterID;
-import com.l2jserver.model.world.L2Character;
-import com.l2jserver.model.world.WorldObject;
-import com.l2jserver.service.game.ai.AIScript;
-import com.l2jserver.service.game.world.event.WorldEventDispatcher;
-import com.l2jserver.service.network.NetworkService;
-
-/**
- * @author Rogiel
- */
-public class AIScriptFactory {
- private final WorldEventDispatcher eventDispatcher;
- private final NetworkService networkService;
-
- @Inject
- public AIScriptFactory(WorldEventDispatcher eventDispatcher,
- NetworkService networkService) {
- this.eventDispatcher = eventDispatcher;
- this.networkService = networkService;
- }
-
- public AIScript create(WorldObject object) {
- if (object instanceof L2Character) {
- final Lineage2Connection conn = networkService
- .discover((CharacterID) object.getID());
- return new CharacterAI((L2Character) object, conn, eventDispatcher);
- }
- return null;
- }
-}
diff --git a/data/script/ai/script/ai/CharacterAI.java b/data/script/ai/script/ai/CharacterAI.java
deleted file mode 100644
index 30e8526c7..000000000
--- a/data/script/ai/script/ai/CharacterAI.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package script.ai;
-
-import script.AIInterest;
-
-import com.l2jserver.game.net.Lineage2Connection;
-import com.l2jserver.game.net.packet.server.ActorMovementPacket;
-import com.l2jserver.model.world.Actor;
-import com.l2jserver.model.world.L2Character;
-import com.l2jserver.model.world.PositionableObject;
-import com.l2jserver.model.world.character.event.CharacterMoveEvent;
-import com.l2jserver.service.game.ai.AIScript;
-import com.l2jserver.service.game.ai.script.AttackAIScript;
-import com.l2jserver.service.game.ai.script.WalkingAIScript;
-import com.l2jserver.service.game.world.WorldService;
-import com.l2jserver.service.game.world.event.WorldEventDispatcher;
-import com.l2jserver.util.dimensional.Coordinate;
-
-/**
- * This {@link AIScript} is for {@link L2Character} object instances
- *
- * @author Rogiel
- */
-public class CharacterAI implements AIScript, WalkingAIScript, AttackAIScript {
- /**
- * The {@link L2Character} being controlled by this AI
- */
- private final L2Character character;
- /**
- * The {@link Lineage2Connection} instance for this character
- */
- private final Lineage2Connection conn;
- /**
- * The {@link WorldService} event dispatcher
- */
- private final WorldEventDispatcher eventDispatcher;
- /**
- * The AI interest
- */
- private AIInterest interest;
-
- // walking
- /**
- * Walking destination coordinate
- */
- private Coordinate coordinate;
-
- public CharacterAI(L2Character character, Lineage2Connection conn,
- WorldEventDispatcher eventDispatcher) {
- this.character = character;
- this.conn = conn;
- this.eventDispatcher = eventDispatcher;
- }
-
- @Override
- public void start() {
- // TODO implement listener
- }
-
- @Override
- public void run(double time) {
- if (interest == AIInterest.INTEREST_IDLE)
- return;
-
- switch (interest) {
- case INTEREST_MOVE_TO:
- final Coordinate source = character.getPosition();
- character.setPosition(coordinate);
- conn.write(new ActorMovementPacket(character, source));
- eventDispatcher.dispatch(new CharacterMoveEvent(character,
- coordinate.toPoint()));
- // double speed = character.getAttributes().getMoveSpeed();
- // double move = time * speed;
- // // Calculate movement angles needed
- // final double distance = coordinate.getDistance(character
- // .getPosition());
- // final int dy = coordinate.getY() - character.getPoint().getY();
- // final int dx = coordinate.getX() - character.getPoint().getX();
- //
- // double sin = dy / distance;
- // double cos = dx / distance;
- //
- // double angleTarget = Math.toDegrees(Math.atan2(sin, cos));
- // if (angleTarget < 0)
- // angleTarget = 360 + angleTarget;
- // final int angle = (int) (angleTarget * 182.044444444);
- this.interest = AIInterest.INTEREST_IDLE;
- break;
- default:
- break;
- }
- }
-
- @Override
- public void stop() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void walk(Coordinate coordinate) {
- this.interest = AIInterest.INTEREST_MOVE_TO;
- this.coordinate = coordinate;
- }
-
- @Override
- public void follow(PositionableObject positionable) {
- }
-
- @Override
- public void attack(Actor target) {
- }
-}
diff --git a/src/dao/h2/com/l2jserver/db/dao/H2DAOModule.java b/src/dao/com/l2jserver/db/H2DAOModule.java
similarity index 87%
rename from src/dao/h2/com/l2jserver/db/dao/H2DAOModule.java
rename to src/dao/com/l2jserver/db/H2DAOModule.java
index 0da1f22f8..afd550470 100644
--- a/src/dao/h2/com/l2jserver/db/dao/H2DAOModule.java
+++ b/src/dao/com/l2jserver/db/H2DAOModule.java
@@ -14,11 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao;
+package com.l2jserver.db;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Scopes;
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.CharacterFriendDAO;
+import com.l2jserver.db.dao.ClanDAO;
+import com.l2jserver.db.dao.ItemDAO;
+import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.h2.H2CharacterDAO;
import com.l2jserver.db.dao.h2.H2CharacterFriendDAO;
import com.l2jserver.db.dao.h2.H2ClanDAO;
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/MySQL5DAOModule.java b/src/dao/com/l2jserver/db/MySQL5DAOModule.java
similarity index 88%
rename from src/dao/mysql5/com/l2jserver/db/dao/MySQL5DAOModule.java
rename to src/dao/com/l2jserver/db/MySQL5DAOModule.java
index 448a74673..5ea734c43 100644
--- a/src/dao/mysql5/com/l2jserver/db/dao/MySQL5DAOModule.java
+++ b/src/dao/com/l2jserver/db/MySQL5DAOModule.java
@@ -14,11 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao;
+package com.l2jserver.db;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Scopes;
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.CharacterFriendDAO;
+import com.l2jserver.db.dao.ClanDAO;
+import com.l2jserver.db.dao.ItemDAO;
+import com.l2jserver.db.dao.NPCDAO;
import com.l2jserver.db.dao.mysql5.MySQL5CharacterDAO;
import com.l2jserver.db.dao.mysql5.MySQL5CharacterFriendDAO;
import com.l2jserver.db.dao.mysql5.MySQL5ClanDAO;
diff --git a/src/dao/com/l2jserver/db/dao/h2/H2CharacterDAO.java b/src/dao/com/l2jserver/db/dao/h2/H2CharacterDAO.java
new file mode 100644
index 000000000..1d8f08317
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/h2/H2CharacterDAO.java
@@ -0,0 +1,41 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.h2;
+
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.jdbc.JDBCCharacterDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.object.provider.ClanIDProvider;
+import com.l2jserver.model.id.provider.AccountIDProvider;
+import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class H2CharacterDAO extends JDBCCharacterDAO implements
+ CharacterDAO {
+ public H2CharacterDAO(DatabaseService database,
+ CharacterIDProvider idFactory,
+ CharacterTemplateIDProvider templateIdFactory,
+ AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
+ super(database, idFactory, templateIdFactory, accountIdFactory,
+ clanIdFactory);
+ }
+}
diff --git a/src/dao/h2/com/l2jserver/db/dao/h2/AbstractH2DAO.java b/src/dao/com/l2jserver/db/dao/h2/H2CharacterFriendDAO.java
similarity index 55%
rename from src/dao/h2/com/l2jserver/db/dao/h2/AbstractH2DAO.java
rename to src/dao/com/l2jserver/db/dao/h2/H2CharacterFriendDAO.java
index 28f89f952..1db2638ab 100644
--- a/src/dao/h2/com/l2jserver/db/dao/h2/AbstractH2DAO.java
+++ b/src/dao/com/l2jserver/db/dao/h2/H2CharacterFriendDAO.java
@@ -16,33 +16,21 @@
*/
package com.l2jserver.db.dao.h2;
-import com.google.inject.Inject;
-import com.l2jserver.model.Model;
-import com.l2jserver.model.id.ID;
-import com.l2jserver.service.database.AbstractDAO;
+import com.l2jserver.db.dao.CharacterFriendDAO;
+import com.l2jserver.db.dao.jdbc.JDBCCharacterFriendDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.provider.FriendIDProvider;
import com.l2jserver.service.database.DatabaseService;
-import com.l2jserver.service.database.JDBCDatabaseService;
/**
- * {@link AbstractDAO} for H2 DAO implementation
+ * {@link CharacterFriendDAO} implementation for MySQL5
*
* @author Rogiel
- *
- * @param
- * the object for the DAO
- * @param
- * the object ID type
*/
-public abstract class AbstractH2DAO, I extends ID>>
- extends AbstractDAO {
- /**
- * The H2 Database Service
- */
- protected final JDBCDatabaseService database;
-
- @Inject
- protected AbstractH2DAO(DatabaseService database) {
- super(database);
- this.database = (JDBCDatabaseService) database;
+public class H2CharacterFriendDAO extends JDBCCharacterFriendDAO implements
+ CharacterFriendDAO {
+ public H2CharacterFriendDAO(DatabaseService database,
+ FriendIDProvider idProvider, CharacterIDProvider charIdProvider) {
+ super(database, idProvider, charIdProvider);
}
}
diff --git a/src/dao/com/l2jserver/db/dao/h2/H2ClanDAO.java b/src/dao/com/l2jserver/db/dao/h2/H2ClanDAO.java
new file mode 100644
index 000000000..c65a25b67
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/h2/H2ClanDAO.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.h2;
+
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.ClanDAO;
+import com.l2jserver.db.dao.jdbc.JDBCClanDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.object.provider.ClanIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class H2ClanDAO extends JDBCClanDAO implements ClanDAO {
+ public H2ClanDAO(DatabaseService database,
+ ClanIDProvider clanIdFactory, CharacterIDProvider idFactory) {
+ super(database, clanIdFactory, idFactory);
+ }
+}
diff --git a/src/dao/com/l2jserver/db/dao/h2/H2ItemDAO.java b/src/dao/com/l2jserver/db/dao/h2/H2ItemDAO.java
new file mode 100644
index 000000000..7d0bbca49
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/h2/H2ItemDAO.java
@@ -0,0 +1,37 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.h2;
+
+import com.l2jserver.db.dao.ItemDAO;
+import com.l2jserver.db.dao.jdbc.JDBCItemDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.object.provider.ItemIDProvider;
+import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link ItemDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class H2ItemDAO extends JDBCItemDAO implements ItemDAO {
+ public H2ItemDAO(DatabaseService database, ItemIDProvider idFactory,
+ ItemTemplateIDProvider templateIdFactory,
+ CharacterIDProvider charIdFactory) {
+ super(database, idFactory, templateIdFactory, charIdFactory);
+ }
+}
diff --git a/src/dao/com/l2jserver/db/dao/h2/H2NPCDAO.java b/src/dao/com/l2jserver/db/dao/h2/H2NPCDAO.java
new file mode 100644
index 000000000..6c63ffe31
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/h2/H2NPCDAO.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.h2;
+
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.NPCDAO;
+import com.l2jserver.db.dao.jdbc.JDBCNPCDAO;
+import com.l2jserver.model.id.object.provider.NPCIDProvider;
+import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class H2NPCDAO extends JDBCNPCDAO implements NPCDAO {
+ public H2NPCDAO(DatabaseService database, NPCIDProvider idProvider,
+ NPCTemplateIDProvider templateIdProvider) {
+ super(database, idProvider, templateIdProvider);
+ }
+}
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/AbstractMySQL5DAO.java b/src/dao/com/l2jserver/db/dao/jdbc/AbstractJDBCDAO.java
similarity index 85%
rename from src/dao/mysql5/com/l2jserver/db/dao/mysql5/AbstractMySQL5DAO.java
rename to src/dao/com/l2jserver/db/dao/jdbc/AbstractJDBCDAO.java
index 465492d99..cb3bc7484 100644
--- a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/AbstractMySQL5DAO.java
+++ b/src/dao/com/l2jserver/db/dao/jdbc/AbstractJDBCDAO.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao.mysql5;
+package com.l2jserver.db.dao.jdbc;
import com.google.inject.Inject;
import com.l2jserver.model.Model;
@@ -24,7 +24,7 @@ import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService;
/**
- * {@link AbstractDAO} for MySQL DAO implementation
+ * {@link AbstractDAO} for JDBC DAO implementation
*
* @author Rogiel
*
@@ -33,7 +33,7 @@ import com.l2jserver.service.database.JDBCDatabaseService;
* @param
* the object ID type
*/
-public abstract class AbstractMySQL5DAO, I extends ID>>
+public abstract class AbstractJDBCDAO, I extends ID>>
extends AbstractDAO {
/**
* The MySQL Database Service
@@ -41,7 +41,7 @@ public abstract class AbstractMySQL5DAO, I extends ID>>
protected final JDBCDatabaseService database;
@Inject
- protected AbstractMySQL5DAO(DatabaseService database) {
+ protected AbstractJDBCDAO(DatabaseService database) {
super(database);
this.database = (JDBCDatabaseService) database;
}
diff --git a/src/dao/h2/com/l2jserver/db/dao/h2/H2CharacterDAO.java b/src/dao/com/l2jserver/db/dao/jdbc/JDBCCharacterDAO.java
similarity index 97%
rename from src/dao/h2/com/l2jserver/db/dao/h2/H2CharacterDAO.java
rename to src/dao/com/l2jserver/db/dao/jdbc/JDBCCharacterDAO.java
index ecbef6c60..f54203ae9 100644
--- a/src/dao/h2/com/l2jserver/db/dao/h2/H2CharacterDAO.java
+++ b/src/dao/com/l2jserver/db/dao/jdbc/JDBCCharacterDAO.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao.h2;
+package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -48,15 +48,15 @@ import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
- * {@link CharacterDAO} implementation for H2
+ * {@link CharacterDAO} implementation for JDBC
*
* @author Rogiel
*/
-public class H2CharacterDAO extends
- AbstractH2DAO implements CharacterDAO {
+public class JDBCCharacterDAO extends
+ AbstractJDBCDAO implements CharacterDAO {
/**
* The {@link CharacterID} factory
*/
@@ -106,7 +106,7 @@ public class H2CharacterDAO extends
public static final String APPEARANCE_FACE = "apperance_face";
@Inject
- public H2CharacterDAO(DatabaseService database,
+ public JDBCCharacterDAO(DatabaseService database,
final CharacterIDProvider idFactory,
CharacterTemplateIDProvider templateIdFactory,
AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
@@ -164,7 +164,7 @@ public class H2CharacterDAO extends
character.setMP(rs.getDouble(MP));
character.setCP(rs.getDouble(CP));
- character.setPoint(Point.fromXYZA(rs.getInt(POINT_X),
+ character.setPoint(Point3D.fromXYZA(rs.getInt(POINT_X),
rs.getInt(POINT_Y), rs.getInt(POINT_Z),
rs.getDouble(POINT_ANGLE)));
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5CharacterFriendDAO.java b/src/dao/com/l2jserver/db/dao/jdbc/JDBCCharacterFriendDAO.java
similarity index 93%
rename from src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5CharacterFriendDAO.java
rename to src/dao/com/l2jserver/db/dao/jdbc/JDBCCharacterFriendDAO.java
index df9d3885c..3a7cfd9c5 100644
--- a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5CharacterFriendDAO.java
+++ b/src/dao/com/l2jserver/db/dao/jdbc/JDBCCharacterFriendDAO.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao.mysql5;
+package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -38,12 +38,12 @@ import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
/**
- * {@link CharacterFriendDAO} implementation for MySQL5
+ * {@link CharacterFriendDAO} implementation for JDBC
*
* @author Rogiel
*/
-public class MySQL5CharacterFriendDAO extends
- AbstractMySQL5DAO implements
+public class JDBCCharacterFriendDAO extends
+ AbstractJDBCDAO implements
CharacterFriendDAO {
/**
* The {@link FriendID} provider
@@ -59,12 +59,12 @@ public class MySQL5CharacterFriendDAO extends
*/
public static final String TABLE = "character_friend";
// FIELDS
- public static final String CHAR_ID = MySQL5CharacterDAO.CHAR_ID;
- public static final String CHAR_ID_FRIEND = MySQL5CharacterDAO.CHAR_ID
+ public static final String CHAR_ID = JDBCCharacterDAO.CHAR_ID;
+ public static final String CHAR_ID_FRIEND = JDBCCharacterDAO.CHAR_ID
+ "_friend";
@Inject
- public MySQL5CharacterFriendDAO(DatabaseService database,
+ public JDBCCharacterFriendDAO(DatabaseService database,
final FriendIDProvider idProvider,
CharacterIDProvider charIdProvider) {
super(database);
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5ClanDAO.java b/src/dao/com/l2jserver/db/dao/jdbc/JDBCClanDAO.java
similarity index 95%
rename from src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5ClanDAO.java
rename to src/dao/com/l2jserver/db/dao/jdbc/JDBCClanDAO.java
index a8cbfb224..89f048399 100644
--- a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5ClanDAO.java
+++ b/src/dao/com/l2jserver/db/dao/jdbc/JDBCClanDAO.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao.mysql5;
+package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -37,11 +37,11 @@ import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
/**
- * {@link CharacterDAO} implementation for MySQL5
+ * {@link CharacterDAO} implementation for JDBC
*
* @author Rogiel
*/
-public class MySQL5ClanDAO extends AbstractMySQL5DAO implements
+public class JDBCClanDAO extends AbstractJDBCDAO implements
ClanDAO {
/**
* The {@link ClanID} factory
@@ -62,7 +62,7 @@ public class MySQL5ClanDAO extends AbstractMySQL5DAO implements
public static final String CHAR_ID_LEADER = "character_id_leader";
@Inject
- public MySQL5ClanDAO(DatabaseService database,
+ public JDBCClanDAO(DatabaseService database,
ClanIDProvider clanIdFactory, final CharacterIDProvider idFactory) {
super(database);
this.idFactory = clanIdFactory;
diff --git a/src/dao/h2/com/l2jserver/db/dao/h2/H2ItemDAO.java b/src/dao/com/l2jserver/db/dao/jdbc/JDBCItemDAO.java
similarity index 95%
rename from src/dao/h2/com/l2jserver/db/dao/h2/H2ItemDAO.java
rename to src/dao/com/l2jserver/db/dao/jdbc/JDBCItemDAO.java
index 829a8cda1..57fd455fa 100644
--- a/src/dao/h2/com/l2jserver/db/dao/h2/H2ItemDAO.java
+++ b/src/dao/com/l2jserver/db/dao/jdbc/JDBCItemDAO.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao.h2;
+package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -41,14 +41,14 @@ import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
/**
- * {@link ItemDAO} implementation for H2f
+ * {@link ItemDAO} implementation for JDBC
*
* @author Rogiel
*/
-public class H2ItemDAO extends AbstractH2DAO implements
+public class JDBCItemDAO extends AbstractJDBCDAO implements
ItemDAO {
/**
* The {@link ItemID} factory
@@ -70,7 +70,7 @@ public class H2ItemDAO extends AbstractH2DAO implements
// FIELDS
public static final String ITEM_ID = "item_id";
public static final String TEMPLATE_ID = "template_id";
- public static final String CHAR_ID = H2CharacterDAO.CHAR_ID;
+ public static final String CHAR_ID = JDBCCharacterDAO.CHAR_ID;
public static final String LOCATION = "location";
public static final String PAPERDOLL = "paperdoll";
@@ -80,7 +80,7 @@ public class H2ItemDAO extends AbstractH2DAO implements
public static final String COORD_Z = "coord_z";
@Inject
- public H2ItemDAO(DatabaseService database,
+ public JDBCItemDAO(DatabaseService database,
final ItemIDProvider idFactory,
ItemTemplateIDProvider templateIdFactory,
CharacterIDProvider charIdFactory) {
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5NPCDAO.java b/src/dao/com/l2jserver/db/dao/jdbc/JDBCNPCDAO.java
similarity index 95%
rename from src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5NPCDAO.java
rename to src/dao/com/l2jserver/db/dao/jdbc/JDBCNPCDAO.java
index 23fffe37e..f2d8ef771 100644
--- a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5NPCDAO.java
+++ b/src/dao/com/l2jserver/db/dao/jdbc/JDBCNPCDAO.java
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see .
*/
-package com.l2jserver.db.dao.mysql5;
+package com.l2jserver.db.dao.jdbc;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -39,14 +39,14 @@ import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
- * {@link CharacterDAO} implementation for MySQL5
+ * {@link CharacterDAO} implementation for JDBC
*
* @author Rogiel
*/
-public class MySQL5NPCDAO extends AbstractMySQL5DAO implements
+public class JDBCNPCDAO extends AbstractJDBCDAO implements
NPCDAO {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@@ -73,7 +73,7 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO implements
public static final String POINT_ANGLE = "point_angle";
@Inject
- public MySQL5NPCDAO(DatabaseService database,
+ public JDBCNPCDAO(DatabaseService database,
final NPCIDProvider idProvider,
NPCTemplateIDProvider templateIdProvider) {
super(database);
@@ -113,7 +113,7 @@ public class MySQL5NPCDAO extends AbstractMySQL5DAO implements
final NPC npc = template.create();
npc.setID(id);
- npc.setPoint(Point.fromXYZA(rs.getInt(POINT_X), rs.getInt(POINT_Y),
+ npc.setPoint(Point3D.fromXYZA(rs.getInt(POINT_X), rs.getInt(POINT_Y),
rs.getInt(POINT_Z), rs.getDouble(POINT_ANGLE)));
return npc;
diff --git a/src/dao/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAO.java b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAO.java
new file mode 100644
index 000000000..01b7cf33c
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAO.java
@@ -0,0 +1,41 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.mysql5;
+
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.jdbc.JDBCCharacterDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.object.provider.ClanIDProvider;
+import com.l2jserver.model.id.provider.AccountIDProvider;
+import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class MySQL5CharacterDAO extends JDBCCharacterDAO implements
+ CharacterDAO {
+ public MySQL5CharacterDAO(DatabaseService database,
+ CharacterIDProvider idFactory,
+ CharacterTemplateIDProvider templateIdFactory,
+ AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
+ super(database, idFactory, templateIdFactory, accountIdFactory,
+ clanIdFactory);
+ }
+}
diff --git a/src/dao/com/l2jserver/db/dao/mysql5/MySQL5CharacterFriendDAO.java b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5CharacterFriendDAO.java
new file mode 100644
index 000000000..6e4568204
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5CharacterFriendDAO.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.mysql5;
+
+import com.l2jserver.db.dao.CharacterFriendDAO;
+import com.l2jserver.db.dao.jdbc.JDBCCharacterFriendDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.provider.FriendIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterFriendDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class MySQL5CharacterFriendDAO extends JDBCCharacterFriendDAO implements
+ CharacterFriendDAO {
+ public MySQL5CharacterFriendDAO(DatabaseService database,
+ FriendIDProvider idProvider, CharacterIDProvider charIdProvider) {
+ super(database, idProvider, charIdProvider);
+ }
+}
diff --git a/src/dao/com/l2jserver/db/dao/mysql5/MySQL5ClanDAO.java b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5ClanDAO.java
new file mode 100644
index 000000000..c777f9ce2
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5ClanDAO.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.mysql5;
+
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.ClanDAO;
+import com.l2jserver.db.dao.jdbc.JDBCClanDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.object.provider.ClanIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class MySQL5ClanDAO extends JDBCClanDAO implements ClanDAO {
+ public MySQL5ClanDAO(DatabaseService database,
+ ClanIDProvider clanIdFactory, CharacterIDProvider idFactory) {
+ super(database, clanIdFactory, idFactory);
+ }
+}
diff --git a/src/dao/com/l2jserver/db/dao/mysql5/MySQL5ItemDAO.java b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5ItemDAO.java
new file mode 100644
index 000000000..96551d509
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5ItemDAO.java
@@ -0,0 +1,37 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.mysql5;
+
+import com.l2jserver.db.dao.ItemDAO;
+import com.l2jserver.db.dao.jdbc.JDBCItemDAO;
+import com.l2jserver.model.id.object.provider.CharacterIDProvider;
+import com.l2jserver.model.id.object.provider.ItemIDProvider;
+import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link ItemDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class MySQL5ItemDAO extends JDBCItemDAO implements ItemDAO {
+ public MySQL5ItemDAO(DatabaseService database, ItemIDProvider idFactory,
+ ItemTemplateIDProvider templateIdFactory,
+ CharacterIDProvider charIdFactory) {
+ super(database, idFactory, templateIdFactory, charIdFactory);
+ }
+}
diff --git a/src/dao/com/l2jserver/db/dao/mysql5/MySQL5NPCDAO.java b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5NPCDAO.java
new file mode 100644
index 000000000..160e93a7d
--- /dev/null
+++ b/src/dao/com/l2jserver/db/dao/mysql5/MySQL5NPCDAO.java
@@ -0,0 +1,36 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.db.dao.mysql5;
+
+import com.l2jserver.db.dao.CharacterDAO;
+import com.l2jserver.db.dao.NPCDAO;
+import com.l2jserver.db.dao.jdbc.JDBCNPCDAO;
+import com.l2jserver.model.id.object.provider.NPCIDProvider;
+import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * {@link CharacterDAO} implementation for MySQL5
+ *
+ * @author Rogiel
+ */
+public class MySQL5NPCDAO extends JDBCNPCDAO implements NPCDAO {
+ public MySQL5NPCDAO(DatabaseService database, NPCIDProvider idProvider,
+ NPCTemplateIDProvider templateIdProvider) {
+ super(database, idProvider, templateIdProvider);
+ }
+}
diff --git a/src/dao/h2/com/l2jserver/db/dao/h2/H2CharacterFriendDAO.java b/src/dao/h2/com/l2jserver/db/dao/h2/H2CharacterFriendDAO.java
deleted file mode 100644
index f78b27538..000000000
--- a/src/dao/h2/com/l2jserver/db/dao/h2/H2CharacterFriendDAO.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package com.l2jserver.db.dao.h2;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import com.google.inject.Inject;
-import com.l2jserver.db.dao.CharacterFriendDAO;
-import com.l2jserver.model.game.CharacterFriend;
-import com.l2jserver.model.id.FriendID;
-import com.l2jserver.model.id.object.CharacterID;
-import com.l2jserver.model.id.object.provider.CharacterIDProvider;
-import com.l2jserver.model.id.provider.FriendIDProvider;
-import com.l2jserver.model.world.L2Character;
-import com.l2jserver.model.world.character.CharacterFriendList;
-import com.l2jserver.service.database.DatabaseService;
-import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
-import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-
-/**
- * {@link CharacterFriendDAO} implementation for H2
- *
- * @author Rogiel
- */
-public class H2CharacterFriendDAO extends
- AbstractH2DAO implements CharacterFriendDAO {
- /**
- * The {@link FriendID} provider
- */
- private final FriendIDProvider idProvider;
- /**
- * The {@link CharacterID} provider
- */
- private final CharacterIDProvider charIdProvider;
-
- /**
- * Character table name
- */
- public static final String TABLE = "character_friend";
- // FIELDS
- public static final String CHAR_ID = H2CharacterDAO.CHAR_ID;
- public static final String CHAR_ID_FRIEND = H2CharacterDAO.CHAR_ID
- + "_friend";
-
- @Inject
- public H2CharacterFriendDAO(DatabaseService database,
- final FriendIDProvider idProvider,
- CharacterIDProvider charIdProvider) {
- super(database);
- this.idProvider = idProvider;
- this.charIdProvider = charIdProvider;
- }
-
- /**
- * The {@link Mapper} for {@link FriendID}
- */
- private final Mapper idMapper = new Mapper() {
- @Override
- public FriendID map(ResultSet rs) throws SQLException {
- final CharacterID characterId = charIdProvider.createID(rs
- .getInt(CHAR_ID));
- final CharacterID friendId = charIdProvider.createID(rs
- .getInt(CHAR_ID_FRIEND));
- return idProvider.createID(characterId, friendId);
- }
- };
-
- /**
- * The {@link Mapper} for {@link CharacterFriend}
- */
- private final Mapper mapper = new CachedMapper(
- database, idMapper) {
- @Override
- protected CharacterFriend map(FriendID id, ResultSet rs)
- throws SQLException {
- return new CharacterFriend(id);
- }
- };
-
- @Override
- public CharacterFriend select(final FriendID id) {
- return database.query(new SelectSingleQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
- + "` = ? AND `" + CHAR_ID_FRIEND + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, id.getID1().getID());
- st.setInt(2, id.getID2().getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public void load(final L2Character character) {
- final List list = database
- .query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `"
- + CHAR_ID + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st)
- throws SQLException {
- st.setInt(1, character.getID().getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- character.getFriendList().load(list);
- }
-
- @Override
- public List selectIDs() {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "`";
- }
-
- @Override
- protected Mapper mapper() {
- return idMapper;
- }
- });
- }
-
- @Override
- public boolean insert(CharacterFriend friend) {
- return database.query(new InsertUpdateQuery(friend) {
- @Override
- protected String query() {
- return "INSERT INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
- + CHAR_ID_FRIEND + "`) VALUES(?,?)";
- }
-
- @Override
- protected void parametize(PreparedStatement st,
- CharacterFriend friend) throws SQLException {
- st.setInt(1, friend.getCharacterID().getID());
- st.setInt(2, friend.getFriendID().getID());
- }
- }) > 0;
- }
-
- @Override
- public boolean update(CharacterFriend friend) {
- // it is not possible update friend objects, because they are only a ID
- // pair and IDs are immutable
- return false;
- }
-
- @Override
- public boolean delete(CharacterFriend friend) {
- return database.query(new InsertUpdateQuery(friend) {
- @Override
- protected String query() {
- return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
- + "` = ?,`" + CHAR_ID_FRIEND + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st,
- CharacterFriend friend) throws SQLException {
- st.setInt(1, friend.getCharacterID().getID());
- st.setInt(2, friend.getFriendID().getID());
- }
- }) > 0;
- }
-
- @Override
- public boolean save(final CharacterFriendList friends) {
- for (final CharacterFriend friend : friends) {
- if (!save(friend))
- return false;
- }
- return true;
- }
-
- @Override
- public boolean delete(final CharacterFriendList friends) {
- for (final CharacterFriend friend : friends) {
- if (!delete(friend))
- return false;
- }
- return true;
- }
-}
diff --git a/src/dao/h2/com/l2jserver/db/dao/h2/H2ClanDAO.java b/src/dao/h2/com/l2jserver/db/dao/h2/H2ClanDAO.java
deleted file mode 100644
index 5b051c3d4..000000000
--- a/src/dao/h2/com/l2jserver/db/dao/h2/H2ClanDAO.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package com.l2jserver.db.dao.h2;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import com.google.inject.Inject;
-import com.l2jserver.db.dao.CharacterDAO;
-import com.l2jserver.db.dao.ClanDAO;
-import com.l2jserver.model.id.object.CharacterID;
-import com.l2jserver.model.id.object.ClanID;
-import com.l2jserver.model.id.object.provider.CharacterIDProvider;
-import com.l2jserver.model.id.object.provider.ClanIDProvider;
-import com.l2jserver.model.world.Clan;
-import com.l2jserver.service.database.DatabaseService;
-import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
-import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-
-/**
- * {@link CharacterDAO} implementation for H2
- *
- * @author Rogiel
- */
-public class H2ClanDAO extends AbstractH2DAO implements ClanDAO {
- /**
- * The {@link ClanID} factory
- */
- private final ClanIDProvider idFactory;
- /**
- * The {@link CharacterID} factory
- */
- @SuppressWarnings("unused")
- private final CharacterIDProvider charIdFactory;
-
- /**
- * Character table name
- */
- public static final String TABLE = "clan";
- // FIELDS
- public static final String CLAN_ID = "clan_id";
- public static final String CHAR_ID_LEADER = "character_id_leader";
-
- @Inject
- public H2ClanDAO(DatabaseService database, ClanIDProvider clanIdFactory,
- final CharacterIDProvider idFactory) {
- super(database);
- this.idFactory = clanIdFactory;
- this.charIdFactory = idFactory;
- }
-
- /**
- * The {@link Mapper} for {@link ClanID}
- */
- private final Mapper idMapper = new Mapper() {
- @Override
- public ClanID map(ResultSet rs) throws SQLException {
- return idFactory.createID(rs.getInt(CLAN_ID));
- }
- };
-
- /**
- * The {@link Mapper} for {@link Clan}
- */
- private final Mapper mapper = new CachedMapper(
- database, idMapper) {
- @Override
- protected Clan map(ClanID id, ResultSet rs) throws SQLException {
- final Clan clan = new Clan();
- clan.setID(id);
- return clan;
- }
- };
-
- @Override
- public Clan select(final ClanID id) {
- return database.query(new SelectSingleQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + CLAN_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, id.getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public List selectIDs() {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "`";
- }
-
- @Override
- protected Mapper mapper() {
- return idMapper;
- }
- });
- }
-
- @Override
- public boolean insert(Clan clan) {
- return database.query(new InsertUpdateQuery(clan) {
- @Override
- protected String query() {
- return "INSERT INTO `" + TABLE + "` (`" + CLAN_ID
- + "`) VALUES(?)";
- }
-
- @Override
- protected void parametize(PreparedStatement st, Clan clan)
- throws SQLException {
- int i = 1;
- st.setInt(i++, clan.getID().getID());
- }
- }) > 0;
- }
-
- @Override
- public boolean update(Clan clan) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean delete(Clan clan) {
- return database.query(new InsertUpdateQuery(clan) {
- @Override
- protected String query() {
- return "DELETE FROM `" + TABLE + "` WHERE `" + CLAN_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st, Clan clan)
- throws SQLException {
- st.setInt(1, clan.getID().getID());
- }
- }) > 0;
- }
-}
diff --git a/src/dao/h2/com/l2jserver/db/dao/h2/H2NPCDAO.java b/src/dao/h2/com/l2jserver/db/dao/h2/H2NPCDAO.java
deleted file mode 100644
index 02971e1ec..000000000
--- a/src/dao/h2/com/l2jserver/db/dao/h2/H2NPCDAO.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package com.l2jserver.db.dao.h2;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.inject.Inject;
-import com.l2jserver.db.dao.CharacterDAO;
-import com.l2jserver.db.dao.NPCDAO;
-import com.l2jserver.model.id.object.NPCID;
-import com.l2jserver.model.id.object.provider.NPCIDProvider;
-import com.l2jserver.model.id.template.NPCTemplateID;
-import com.l2jserver.model.id.template.provider.NPCTemplateIDProvider;
-import com.l2jserver.model.template.NPCTemplate;
-import com.l2jserver.model.world.NPC;
-import com.l2jserver.service.database.DatabaseService;
-import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
-import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-import com.l2jserver.util.dimensional.Point;
-
-/**
- * {@link CharacterDAO} implementation for H2
- *
- * @author Rogiel
- */
-public class H2NPCDAO extends AbstractH2DAO implements NPCDAO {
- private final Logger log = LoggerFactory.getLogger(this.getClass());
-
- /**
- * The {@link NPCID} provider
- */
- private final NPCIDProvider idProvider;
- /**
- * The {@link NPCTemplateID} provider
- */
- private final NPCTemplateIDProvider templateIdProvider;
-
- /**
- * Character table name
- */
- public static final String TABLE = "npc";
- // FIELDS
- public static final String NPC_ID = "npc_id";
- public static final String NPC_TEMPLATE_ID = "npc_template_id";
-
- public static final String POINT_X = "point_x";
- public static final String POINT_Y = "point_y";
- public static final String POINT_Z = "point_z";
- public static final String POINT_ANGLE = "point_angle";
-
- @Inject
- public H2NPCDAO(DatabaseService database, final NPCIDProvider idProvider,
- NPCTemplateIDProvider templateIdProvider) {
- super(database);
- this.idProvider = idProvider;
- this.templateIdProvider = templateIdProvider;
- }
-
- /**
- * The {@link Mapper} for {@link NPCID}
- */
- private final Mapper idMapper = new Mapper() {
- @Override
- public NPCID map(ResultSet rs) throws SQLException {
- if (rs.getString(NPC_ID) == null)
- return null;
- return idProvider.createID(rs.getInt(NPC_ID));
- }
- };
-
- /**
- * The {@link Mapper} for {@link NPC}
- */
- private final Mapper mapper = new CachedMapper(database,
- idMapper) {
- @Override
- protected NPC map(NPCID id, ResultSet rs) throws SQLException {
- NPCTemplateID templateId = templateIdProvider.createID(rs
- .getInt(NPC_TEMPLATE_ID));
- NPCTemplate template = templateId.getTemplate();
- if (template == null) {
- // set default npc instance, for now!
- // RoxxyGatekeeperTemplate - 30006
- log.warn("No template found for {}", templateId);
- return null;
- }
-
- final NPC npc = template.create();
-
- npc.setID(id);
- npc.setPoint(Point.fromXYZA(rs.getInt(POINT_X), rs.getInt(POINT_Y),
- rs.getInt(POINT_Z), rs.getDouble(POINT_ANGLE)));
-
- return npc;
- }
- };
-
- @Override
- public NPC select(final NPCID id) {
- return database.query(new SelectSingleQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + NPC_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, id.getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public List loadAll() {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "`";
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public List selectByTemplate(final NPCTemplateID template) {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `"
- + NPC_TEMPLATE_ID + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, template.getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public List selectIDs() {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT `" + NPC_ID + "` FROM `" + TABLE + "`";
- }
-
- @Override
- protected Mapper mapper() {
- return idMapper;
- }
- });
- }
-
- @Override
- public boolean insert(NPC npc) {
- return database.query(new InsertUpdateQuery(npc) {
- @Override
- protected String query() {
- return "INSERT INTO `" + TABLE + "` (`" + NPC_ID + "`,`"
- + NPC_TEMPLATE_ID + "`,`" + POINT_X + "`,`" + POINT_Y
- + "`,`" + POINT_Z + "`,`" + POINT_ANGLE
- + "`) VALUES(?,?,?,?,?,?)";
- }
-
- @Override
- protected void parametize(PreparedStatement st, NPC npc)
- throws SQLException {
- int i = 1;
-
- st.setInt(i++, npc.getID().getID());
- st.setInt(i++, npc.getTemplateID().getID());
-
- st.setInt(i++, npc.getPoint().getX());
- st.setInt(i++, npc.getPoint().getY());
- st.setInt(i++, npc.getPoint().getZ());
- st.setDouble(i++, npc.getPoint().getAngle());
- }
- }) > 0;
- }
-
- @Override
- public boolean update(NPC npc) {
- return database.query(new InsertUpdateQuery(npc) {
- @Override
- protected String query() {
- return "UPDATE `" + TABLE + "` SET " + NPC_TEMPLATE_ID
- + "` = ?,`" + POINT_X + "` = ?,`" + POINT_Y + "` = ?,`"
- + POINT_Z + "` = ?,`" + POINT_ANGLE + "` = ? WHERE `"
- + NPC_ID + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st, NPC npc)
- throws SQLException {
- int i = 1;
-
- // SET
- st.setInt(i++, npc.getTemplateID().getID());
-
- st.setInt(i++, npc.getPoint().getX());
- st.setInt(i++, npc.getPoint().getY());
- st.setInt(i++, npc.getPoint().getZ());
- st.setDouble(i++, npc.getPoint().getAngle());
-
- // WHERE
- st.setInt(i++, npc.getID().getID());
- }
- }) > 0;
- }
-
- @Override
- public boolean delete(NPC npc) {
- return database.query(new InsertUpdateQuery(npc) {
- @Override
- protected String query() {
- return "DELETE FROM `" + TABLE + "` WHERE `" + NPC_ID + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st, NPC npc)
- throws SQLException {
- st.setInt(1, npc.getID().getID());
- }
- }) > 0;
- }
-}
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAO.java b/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAO.java
deleted file mode 100644
index 6b1747442..000000000
--- a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5CharacterDAO.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package com.l2jserver.db.dao.mysql5;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.List;
-
-import com.google.inject.Inject;
-import com.l2jserver.db.dao.CharacterDAO;
-import com.l2jserver.model.id.AccountID;
-import com.l2jserver.model.id.object.CharacterID;
-import com.l2jserver.model.id.object.ClanID;
-import com.l2jserver.model.id.object.provider.CharacterIDProvider;
-import com.l2jserver.model.id.object.provider.ClanIDProvider;
-import com.l2jserver.model.id.provider.AccountIDProvider;
-import com.l2jserver.model.id.template.CharacterTemplateID;
-import com.l2jserver.model.id.template.provider.CharacterTemplateIDProvider;
-import com.l2jserver.model.template.CharacterTemplate;
-import com.l2jserver.model.world.Actor.ActorRace;
-import com.l2jserver.model.world.Actor.ActorSex;
-import com.l2jserver.model.world.Clan;
-import com.l2jserver.model.world.L2Character;
-import com.l2jserver.model.world.character.CharacterAppearance;
-import com.l2jserver.model.world.character.CharacterAppearance.CharacterFace;
-import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairColor;
-import com.l2jserver.model.world.character.CharacterAppearance.CharacterHairStyle;
-import com.l2jserver.model.world.character.CharacterClass;
-import com.l2jserver.service.database.DatabaseService;
-import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
-import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-import com.l2jserver.util.dimensional.Point;
-
-/**
- * {@link CharacterDAO} implementation for MySQL5
- *
- * @author Rogiel
- */
-public class MySQL5CharacterDAO extends
- AbstractMySQL5DAO implements CharacterDAO {
- /**
- * The {@link CharacterID} factory
- */
- private final CharacterIDProvider idFactory;
- /**
- * The {@link CharacterTemplateID} factory
- */
- private final CharacterTemplateIDProvider templateIdFactory;
- /**
- * The {@link AccountID} factory
- */
- private final AccountIDProvider accountIdFactory;
- /**
- * The {@link ClanID} factory
- */
- private final ClanIDProvider clanIdFactory;
-
- /**
- * Character table name
- */
- public static final String TABLE = "character";
- // FIELDS
- public static final String CHAR_ID = "character_id";
- public static final String ACCOUNT_ID = "account_id";
- public static final String CLAN_ID = "clan_id";
- public static final String NAME = "name";
-
- public static final String RACE = "race";
- public static final String CLASS = "class";
- public static final String SEX = "sex";
-
- public static final String LEVEL = "level";
- public static final String EXPERIENCE = "experience";
- public static final String SP = "sp";
-
- public static final String HP = "hp";
- public static final String MP = "mp";
- public static final String CP = "cp";
-
- public static final String POINT_X = "point_x";
- public static final String POINT_Y = "point_y";
- public static final String POINT_Z = "point_z";
- public static final String POINT_ANGLE = "point_angle";
-
- public static final String APPEARANCE_HAIR_STYLE = "appearance_hair_style";
- public static final String APPEARANCE_HAIR_COLOR = "appearance_hair_color";
- public static final String APPEARANCE_FACE = "apperance_face";
-
- @Inject
- public MySQL5CharacterDAO(DatabaseService database,
- final CharacterIDProvider idFactory,
- CharacterTemplateIDProvider templateIdFactory,
- AccountIDProvider accountIdFactory, ClanIDProvider clanIdFactory) {
- super(database);
- this.idFactory = idFactory;
- this.templateIdFactory = templateIdFactory;
- this.accountIdFactory = accountIdFactory;
- this.clanIdFactory = clanIdFactory;
- }
-
- /**
- * The mapper for {@link CharacterID}
- */
- private final Mapper idMapper = new Mapper() {
- @Override
- public CharacterID map(ResultSet rs) throws SQLException {
- return idFactory.createID(rs.getInt(CHAR_ID));
- }
- };
-
- /**
- * The {@link Mapper} for {@link L2Character}
- */
- private final Mapper mapper = new CachedMapper(
- database, idMapper) {
- @Override
- protected L2Character map(CharacterID id, ResultSet rs)
- throws SQLException {
- final CharacterClass charClass = CharacterClass.valueOf(rs
- .getString(CLASS));
- final CharacterTemplateID templateId = templateIdFactory
- .createID(charClass.id);
- final CharacterTemplate template = templateId.getTemplate();
-
- final L2Character character = template.create();
-
- character.setID(id);
- character.setAccountID(accountIdFactory.createID(rs
- .getString(ACCOUNT_ID)));
- if (rs.getString(CLAN_ID) != null)
- character.setClanID(clanIdFactory.createID(rs.getInt(CLAN_ID)));
-
- character.setName(rs.getString(NAME));
-
- character.setRace(ActorRace.valueOf(rs.getString(RACE)));
- character.setCharacterClass(CharacterClass.valueOf(rs
- .getString(CLASS)));
- character.setSex(ActorSex.valueOf(rs.getString(SEX)));
-
- character.setLevel(rs.getInt(LEVEL));
- character.setExperience(rs.getLong(EXPERIENCE));
- character.setSP(rs.getInt(SP));
-
- character.setHP(rs.getDouble(HP));
- character.setMP(rs.getDouble(MP));
- character.setCP(rs.getDouble(CP));
-
- character.setPoint(Point.fromXYZA(rs.getInt(POINT_X),
- rs.getInt(POINT_Y), rs.getInt(POINT_Z),
- rs.getDouble(POINT_ANGLE)));
-
- // appearance
- character.getAppearance().setHairStyle(
- CharacterHairStyle.valueOf(rs
- .getString(APPEARANCE_HAIR_STYLE)));
- character.getAppearance().setHairColor(
- CharacterHairColor.valueOf(rs
- .getString(APPEARANCE_HAIR_COLOR)));
- character.getAppearance().setFace(
- CharacterFace.valueOf(rs.getString(APPEARANCE_FACE)));
-
- return character;
- }
- };
-
- @Override
- public L2Character select(final CharacterID id) {
- return database.query(new SelectSingleQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, id.getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public void load(final Clan clan) {
- clan.getMembers().load(
- database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT `" + CHAR_ID + "` FROM `" + TABLE
- + "` WHERE `" + CLAN_ID + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st)
- throws SQLException {
- st.setInt(1, clan.getID().getID());
- }
-
- @Override
- protected Mapper mapper() {
- return idMapper;
- }
- }));
- }
-
- @Override
- public L2Character selectByName(final String name) {
- return database.query(new SelectSingleQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + NAME + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setString(1, name);
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public List selectByAccount(final AccountID account) {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + ACCOUNT_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setString(1, account.getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public List selectIDs() {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT `" + CHAR_ID + "` FROM `" + TABLE + "`";
- }
-
- @Override
- protected Mapper mapper() {
- return idMapper;
- }
- });
- }
-
- @Override
- public boolean insert(L2Character character) {
- return database.query(new InsertUpdateQuery(character) {
- @Override
- protected String query() {
- return "INSERT INTO `" + TABLE + "` (`" + CHAR_ID + "`,`"
- + ACCOUNT_ID + "`,`" + CLAN_ID + "`,`" + NAME + "`,`"
- + RACE + "`,`" + CLASS + "`,`" + SEX + "`,`" + LEVEL
- + "`,`" + EXPERIENCE + "`,`" + SP + "`,`" + HP + "`,`"
- + MP + "`,`" + CP + "`,`" + POINT_X + "`,`" + POINT_Y
- + "`,`" + POINT_Z + "`,`" + POINT_ANGLE + "`,`"
- + APPEARANCE_HAIR_STYLE + "`,`" + APPEARANCE_HAIR_COLOR
- + "`,`" + APPEARANCE_FACE
- + "`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- }
-
- @Override
- protected void parametize(PreparedStatement st,
- L2Character character) throws SQLException {
- final CharacterAppearance appearance = character
- .getAppearance();
- int i = 1;
-
- st.setInt(i++, character.getID().getID());
- st.setString(i++, character.getAccountID().getID());
- if (character.getClanID() != null)
- st.setInt(i++, character.getClanID().getID());
- else
- st.setNull(i++, Types.INTEGER);
-
- st.setString(i++, character.getName());
-
- st.setString(i++, character.getRace().name());
- st.setString(i++, character.getCharacterClass().name());
- st.setString(i++, character.getSex().name());
-
- st.setInt(i++, character.getLevel());
- st.setLong(i++, character.getExperience());
- st.setInt(i++, character.getSP());
-
- st.setDouble(i++, character.getHP());
- st.setDouble(i++, character.getMP());
- st.setDouble(i++, character.getCP());
-
- st.setInt(i++, character.getPoint().getX());
- st.setInt(i++, character.getPoint().getY());
- st.setInt(i++, character.getPoint().getZ());
- st.setDouble(i++, character.getPoint().getAngle());
-
- // appearance
- st.setString(i++, appearance.getHairStyle().name());
- st.setString(i++, appearance.getHairColor().name());
- st.setString(i++, appearance.getFace().name());
- }
- }) > 0;
- }
-
- @Override
- public boolean update(L2Character character) {
- return database.query(new InsertUpdateQuery(character) {
- @Override
- protected String query() {
- return "UPDATE `" + TABLE + "` SET " + ACCOUNT_ID + "` = ?,`"
- + CLAN_ID + "` = ?,`" + NAME + "` = ?,`" + RACE
- + "` = ?,`" + CLASS + "` = ?,`" + SEX + "` = ?,`"
- + LEVEL + "` = ?,`" + EXPERIENCE + "` = ?,`" + SP
- + "` = ?,`" + HP + "` = ?,`" + MP + "` = ?,`" + CP
- + "` = ?,`" + POINT_X + "` = ?,`" + POINT_Y + "` = ?,`"
- + POINT_Z + "` = ?,`" + POINT_ANGLE + "` = ?,`"
- + APPEARANCE_HAIR_STYLE + "` = ?,`"
- + APPEARANCE_HAIR_COLOR + "` = ?,`" + APPEARANCE_FACE
- + "` = ? WHERE `" + CHAR_ID + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st,
- L2Character character) throws SQLException {
- final CharacterAppearance appearance = character
- .getAppearance();
- int i = 1;
-
- // SET
- st.setString(i++, character.getAccountID().getID());
- if (character.getClanID() != null)
- st.setInt(i++, character.getClanID().getID());
- else
- st.setNull(i++, Types.INTEGER);
-
- st.setString(i++, character.getName());
-
- st.setString(i++, character.getRace().name());
- st.setString(i++, character.getCharacterClass().name());
- st.setString(i++, character.getSex().name());
-
- st.setInt(i++, character.getLevel());
- st.setLong(i++, character.getExperience());
- st.setInt(i++, character.getSP());
-
- st.setDouble(i++, character.getHP());
- st.setDouble(i++, character.getMP());
- st.setDouble(i++, character.getCP());
-
- // position
- st.setInt(i++, character.getPoint().getX());
- st.setInt(i++, character.getPoint().getY());
- st.setInt(i++, character.getPoint().getZ());
- st.setDouble(i++, character.getPoint().getAngle());
-
- // appearance
- st.setString(i++, appearance.getHairStyle().name());
- st.setString(i++, appearance.getHairColor().name());
- st.setString(i++, appearance.getFace().name());
-
- // WHERE
- st.setInt(i++, character.getID().getID());
- }
- }) > 0;
- }
-
- @Override
- public boolean delete(L2Character character) {
- return database.query(new InsertUpdateQuery(character) {
- @Override
- protected String query() {
- return "DELETE FROM `" + TABLE + "` WHERE `" + CHAR_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st,
- L2Character character) throws SQLException {
- st.setInt(1, character.getID().getID());
- }
- }) > 0;
- }
-}
diff --git a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5ItemDAO.java b/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5ItemDAO.java
deleted file mode 100644
index 457f0f900..000000000
--- a/src/dao/mysql5/com/l2jserver/db/dao/mysql5/MySQL5ItemDAO.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * This file is part of l2jserver .
- *
- * 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 .
- */
-package com.l2jserver.db.dao.mysql5;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.List;
-
-import com.google.inject.Inject;
-import com.l2jserver.db.dao.ItemDAO;
-import com.l2jserver.model.id.object.CharacterID;
-import com.l2jserver.model.id.object.ItemID;
-import com.l2jserver.model.id.object.provider.CharacterIDProvider;
-import com.l2jserver.model.id.object.provider.ItemIDProvider;
-import com.l2jserver.model.id.template.ItemTemplateID;
-import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
-import com.l2jserver.model.template.ItemTemplate;
-import com.l2jserver.model.world.Item;
-import com.l2jserver.model.world.L2Character;
-import com.l2jserver.model.world.character.CharacterInventory;
-import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
-import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
-import com.l2jserver.service.database.DatabaseService;
-import com.l2jserver.service.database.JDBCDatabaseService.CachedMapper;
-import com.l2jserver.service.database.JDBCDatabaseService.InsertUpdateQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.Mapper;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectListQuery;
-import com.l2jserver.service.database.JDBCDatabaseService.SelectSingleQuery;
-import com.l2jserver.util.dimensional.Coordinate;
-
-/**
- * {@link ItemDAO} implementation for MySQL5
- *
- * @author Rogiel
- */
-public class MySQL5ItemDAO extends AbstractMySQL5DAO implements
- ItemDAO {
- /**
- * The {@link ItemID} factory
- */
- private final ItemIDProvider idFactory;
- /**
- * The {@link ItemTemplateID} factory
- */
- private final ItemTemplateIDProvider templateIdFactory;
- /**
- * The {@link CharacterID} factory
- */
- private final CharacterIDProvider charIdFactory;
-
- /**
- * Character table name
- */
- public static final String TABLE = "item";
- // FIELDS
- public static final String ITEM_ID = "item_id";
- public static final String TEMPLATE_ID = "template_id";
- public static final String CHAR_ID = MySQL5CharacterDAO.CHAR_ID;
-
- public static final String LOCATION = "location";
- public static final String PAPERDOLL = "paperdoll";
- public static final String COUNT = "count";
- public static final String COORD_X = "coord_x";
- public static final String COORD_Y = "coord_y";
- public static final String COORD_Z = "coord_z";
-
- @Inject
- public MySQL5ItemDAO(DatabaseService database,
- final ItemIDProvider idFactory,
- ItemTemplateIDProvider templateIdFactory,
- CharacterIDProvider charIdFactory) {
- super(database);
- this.idFactory = idFactory;
- this.templateIdFactory = templateIdFactory;
- this.charIdFactory = charIdFactory;
- }
-
- /**
- * The {@link Mapper} for {@link ItemID}
- */
- private final Mapper idMapper = new Mapper() {
- @Override
- public ItemID map(ResultSet rs) throws SQLException {
- return idFactory.createID(rs.getInt(ITEM_ID));
- }
- };
-
- /**
- * The {@link Mapper} instance
- */
- private final Mapper mapper = new CachedMapper(
- database, idMapper) {
- @Override
- public Item map(ItemID id, ResultSet rs) throws SQLException {
- final ItemTemplateID templateId = templateIdFactory.createID(rs
- .getInt(TEMPLATE_ID));
- final ItemTemplate template = templateId.getTemplate();
- final Item item = template.create();
-
- item.setID(id);
- if (rs.getObject(CHAR_ID) != null)
- item.setOwnerID(charIdFactory.createID(rs.getInt(CHAR_ID)));
- if (rs.getObject(LOCATION) != null)
- item.setLocation(InventoryLocation.valueOf(rs
- .getString(LOCATION)));
- if (rs.getObject(PAPERDOLL) != null)
- item.setPaperdoll(InventoryPaperdoll.valueOf(rs
- .getString(PAPERDOLL)));
-
- item.setCount(rs.getInt(COUNT));
-
- if (rs.getObject(COORD_X) != null && rs.getObject(COORD_Y) != null
- && rs.getObject(COORD_Z) != null)
- item.setPosition(Coordinate.fromXYZ(rs.getInt(COORD_X),
- rs.getInt(COORD_Y), rs.getInt(COORD_Z)));
-
- return item;
- }
- };
-
- @Override
- public Item select(final ItemID id) {
- return database.query(new SelectSingleQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + ITEM_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, id.getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- }
-
- @Override
- public int loadInventory(final L2Character character) {
- final CharacterInventory inventory = character.getInventory();
- final List items = database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT * FROM `" + TABLE + "` WHERE `" + CHAR_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st) throws SQLException {
- st.setInt(1, character.getID().getID());
- }
-
- @Override
- protected Mapper mapper() {
- return mapper;
- }
- });
- inventory.load(items);
- return items.size();
- }
-
- @Override
- public List selectIDs() {
- return database.query(new SelectListQuery() {
- @Override
- protected String query() {
- return "SELECT `" + ITEM_ID + "` FROM `" + TABLE + "`";
- }
-
- @Override
- protected Mapper mapper() {
- return idMapper;
- }
- });
- }
-
- @Override
- public boolean insert(Item item) {
- throw new UnsupportedOperationException(
- "Saving items is not yet implemented!");
- }
-
- @Override
- public boolean update(Item item) {
- return false;
- }
-
- @Override
- public boolean delete(Item item) {
- return database.query(new InsertUpdateQuery(item) {
- @Override
- protected String query() {
- return "DELETE FROM `" + TABLE + "` WHERE `" + ITEM_ID
- + "` = ?";
- }
-
- @Override
- protected void parametize(PreparedStatement st, Item item)
- throws SQLException {
- st.setInt(1, item.getID().getID());
- }
- }) > 0;
- }
-}
diff --git a/src/main/java/com/l2jserver/GameServerModule.java b/src/main/java/com/l2jserver/GameServerModule.java
index 918eb44ca..6d4c26eaa 100644
--- a/src/main/java/com/l2jserver/GameServerModule.java
+++ b/src/main/java/com/l2jserver/GameServerModule.java
@@ -18,7 +18,7 @@ package com.l2jserver;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
-import com.l2jserver.db.dao.H2DAOModule;
+import com.l2jserver.db.H2DAOModule;
import com.l2jserver.model.id.provider.IDProviderModule;
import com.l2jserver.service.ServiceModule;
diff --git a/src/main/java/com/l2jserver/Installer.java b/src/main/java/com/l2jserver/Installer.java
new file mode 100644
index 000000000..866caf42e
--- /dev/null
+++ b/src/main/java/com/l2jserver/Installer.java
@@ -0,0 +1,40 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver;
+
+import com.l2jserver.service.ServiceManager;
+import com.l2jserver.service.database.DatabaseService;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class Installer {
+ public static void main(String[] args) {
+ final L2JGameServer server = new L2JGameServer();
+ try {
+ final ServiceManager serviceManager = server.getInjector()
+ .getInstance(ServiceManager.class);
+
+ serviceManager.start(DatabaseService.class).install();
+ } catch (Exception e) {
+ System.out.println("GameServer could not be installed!");
+ e.printStackTrace();
+ System.exit(0);
+ }
+ }
+}
diff --git a/src/main/java/com/l2jserver/game/ProtocolVersion.java b/src/main/java/com/l2jserver/game/ProtocolVersion.java
index 1f4141522..5cad785c6 100644
--- a/src/main/java/com/l2jserver/game/ProtocolVersion.java
+++ b/src/main/java/com/l2jserver/game/ProtocolVersion.java
@@ -23,16 +23,20 @@ package com.l2jserver.game;
*/
public enum ProtocolVersion {
/**
- * Release version
+ * The Release version, this is acctually a pseudo version. It never really
+ * existed.
*/
RELEASE(0),
-
/**
- * Freya(216)
+ * The Interlude(200) version
+ */
+ INTERLUDE(200, RELEASE),
+ /**
+ * The Freya(216) version
*/
FREYA(216, RELEASE),
/**
- * High5(268)
+ * The High5(268) version
*/
HIGH5(268, FREYA);
diff --git a/src/main/java/com/l2jserver/game/ai/AI.java b/src/main/java/com/l2jserver/game/ai/AI.java
new file mode 100644
index 000000000..05c9bc3e8
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/AI.java
@@ -0,0 +1,39 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai;
+
+import com.l2jserver.game.ai.desires.Desire;
+import com.l2jserver.game.ai.desires.DesireQueue;
+import com.l2jserver.model.world.Actor;
+
+/**
+ * @author Rogiel
+ * @param
+ * the {@link Actor} type for this {@link AI}
+ */
+public abstract class AI {
+ protected DesireQueue desireQueue = new DesireQueue();
+ protected final T creature;
+
+ protected AI(T creature) {
+ this.creature = creature;
+ }
+
+ protected void handleDesire(Desire desire) {
+ desire.handleDesire(this);
+ }
+}
diff --git a/src/main/java/com/l2jserver/game/ai/desires/AbstractDesire.java b/src/main/java/com/l2jserver/game/ai/desires/AbstractDesire.java
new file mode 100644
index 000000000..58674cf38
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/AbstractDesire.java
@@ -0,0 +1,74 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+/**
+ * This class implements basic functionality common for each desire
+ *
+ * @author Rogiel
+ * @see com.l2jserver.game.ai.desires.Desire
+ * @see com.l2jserver.game.ai.desires.DesireQueue
+ * @see com.l2jserver.game.ai.AI
+ * @see com.l2jserver.game.ai.AI#handleDesire(Desire)
+ */
+public abstract class AbstractDesire implements Desire {
+
+ /**
+ * Desire power. It's used to calculate what npc whants to do most of all.
+ */
+ protected int desirePower;
+
+ /**
+ * Creates new desire. By design any desire should have desire power. So
+ * constructor accepts basic amout.
+ *
+ * @param desirePower
+ * basic amount of desirePower
+ */
+ protected AbstractDesire(int desirePower) {
+ this.desirePower = desirePower;
+ }
+
+ /**
+ * Compares this desire with another, used by
+ * {@link com.l2jserver.game.ai.desires.DesireQueue} to keep track of desire
+ * priorities.
+ *
+ * @param o
+ * desire to compare with
+ * @return result of desire comparation
+ */
+ @Override
+ public int compareTo(Desire o) {
+ return o.getDesirePower() - getDesirePower();
+ }
+
+ @Override
+ public int getDesirePower() {
+ return desirePower;
+ }
+
+ @Override
+ public synchronized void increaseDesirePower(int desirePower) {
+ this.desirePower = this.desirePower + desirePower;
+ }
+
+ @Override
+ public synchronized void reduceDesirePower(int desirePower) {
+ this.desirePower = this.desirePower - desirePower;
+ }
+}
diff --git a/src/main/java/com/l2jserver/game/ai/desires/AttackDesire.java b/src/main/java/com/l2jserver/game/ai/desires/AttackDesire.java
new file mode 100644
index 000000000..181a732f6
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/AttackDesire.java
@@ -0,0 +1,76 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+import com.l2jserver.game.ai.AI;
+import com.l2jserver.model.world.Actor;
+
+/**
+ * This class indicates that character wants to attack somebody
+ *
+ * @author Rogiel
+ */
+public final class AttackDesire extends AbstractDesire {
+ /**
+ * Target of this desire
+ */
+ protected final Actor target;
+
+ /**
+ * Creates new attack desire, target can't be changed
+ *
+ * @param target
+ * whom to attack
+ * @param desirePower
+ * initial attack power
+ */
+ protected AttackDesire(Actor target, int desirePower) {
+ super(desirePower);
+ this.target = target;
+ }
+
+ @Override
+ public void handleDesire(AI> ai) {
+ // TODO: Implement
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof AttackDesire))
+ return false;
+
+ AttackDesire that = (AttackDesire) o;
+
+ return target.equals(that.target);
+ }
+
+ @Override
+ public int hashCode() {
+ return target.hashCode();
+ }
+
+ /**
+ * Returns target of this desire
+ *
+ * @return target of this desire
+ */
+ public Actor getTarget() {
+ return target;
+ }
+}
diff --git a/src/main/java/com/l2jserver/game/ai/desires/Desire.java b/src/main/java/com/l2jserver/game/ai/desires/Desire.java
new file mode 100644
index 000000000..1f35cc309
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/Desire.java
@@ -0,0 +1,93 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+import com.l2jserver.game.ai.AI;
+
+/**
+ * This interface represents basic desire functions.
+ * Each desire should implement {@link #handleDesire(com.l2jserver.game.ai.AI)}
+ * method with default behavior.
+ * AI can override {@link com.l2jserver.game.ai.AI#handleDesire(Desire)} to
+ * implement custom behavior of desire.
+ *
+ * @author Rogiel
+ * @see com.l2jserver.game.ai.AI
+ * @see com.l2jserver.game.ai.AI#handleDesire(Desire)
+ * @see com.l2jserver.game.ai.desires.AbstractDesire
+ */
+public interface Desire extends Comparable {
+ /**
+ * Invokes default desire action. AI can override invocation of this method
+ * to handle desire in it's own way
+ *
+ * @param ai
+ * actor that is doing this desire
+ */
+ void handleDesire(AI> ai);
+
+ /**
+ * Returns hashcode for this object, must be overrided by child
+ *
+ * @return hashcode for this object
+ */
+ int hashCode();
+
+ /**
+ * Compares this Desire with another object, must overriden by child
+ *
+ * @param obj
+ * another object to compare with
+ * @return result of object comparation
+ */
+ boolean equals(Object obj);
+
+ /**
+ * Returns desire power of this object
+ *
+ * @return desire power of the object
+ */
+ int getDesirePower();
+
+ /**
+ * Adds desire power to this desire, this call is synchronized.
+ *
+ * WARNING!!! Changing desire power after adding it to queue will not
+ * affect it's position, you have to call
+ * {@link com.l2jserver.game.ai.desires.DesireQueue#addDesire(Desire)}
+ * passing this instance as argument
+ *
+ * @param desirePower
+ * amount of desirePower to add
+ * @see DesireQueue#addDesire(Desire)
+ */
+ void increaseDesirePower(int desirePower);
+
+ /**
+ * Reduces desire power by give amount.
+ *
+ * WARNING!!! Changing desire power after adding it to queue will not
+ * affect it's position, you have to call
+ * {@link com.l2jserver.game.ai.desires.DesireQueue#addDesire(Desire)}
+ * passing this instance as argument
+ *
+ * @param desirePower
+ * amount of desirePower to substract
+ * @see DesireQueue#addDesire(Desire)
+ */
+ void reduceDesirePower(int desirePower);
+}
diff --git a/src/main/java/com/l2jserver/game/ai/desires/DesireIteratorFilter.java b/src/main/java/com/l2jserver/game/ai/desires/DesireIteratorFilter.java
new file mode 100644
index 000000000..14451345e
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/DesireIteratorFilter.java
@@ -0,0 +1,45 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+/**
+ * This class represents simple filter for desire iterations.
+ *
+ * @author Rogiel
+ */
+public interface DesireIteratorFilter {
+ /**
+ * This method is called each time for every desire that is in the queue.
+ * {@link java.util.ConcurrentModificationException} will be thrown by
+ * {@link com.l2jserver.game.ai.desires.DesireQueue#iterateDesires(DesireIteratorHandler, DesireIteratorFilter[])}
+ * if any of the following methods will be called from here:
+ *
+ *
+ * However {@link com.l2jserver.game.ai.desires.DesireQueue#clear()} can be
+ * called.
+ *
+ * @param desire
+ * current element of iteration that is beeing filtered
+ * @return true if this filter accepted desire, false otherwise
+ */
+ public boolean isOk(Desire desire);
+}
diff --git a/src/main/java/com/l2jserver/game/ai/desires/DesireIteratorHandler.java b/src/main/java/com/l2jserver/game/ai/desires/DesireIteratorHandler.java
new file mode 100644
index 000000000..4ca87f648
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/DesireIteratorHandler.java
@@ -0,0 +1,55 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+import java.util.Iterator;
+
+/**
+ * This class is designed to be a helper class for desires.
+ * Direct access to desire list is not allowed, however this interface can be
+ * used for iteration.
+ *
+ *
+ * @author Rogiel
+ * @see com.l2jserver.game.ai.desires.DesireIteratorFilter
+ * @see com.l2jserver.game.ai.desires.DesireQueue#iterateDesires(DesireIteratorHandler,
+ * DesireIteratorFilter[])
+ */
+public interface DesireIteratorHandler {
+ /**
+ * This method is called each time for every desire that is in the queue.
+ * Remove of desire must be handeled by iterator.remove();
+ * {@link java.util.ConcurrentModificationException} will be thrown by
+ * {@link com.l2jserver.game.ai.desires.DesireQueue#iterateDesires(DesireIteratorHandler, DesireIteratorFilter[])}
+ * if any of the following methods will be called from here:
+ *
+ *
+ * However {@link com.l2jserver.game.ai.desires.DesireQueue#clear()} can be
+ * called.
+ *
+ * @param desire
+ * current element of iteration
+ * @param iterator
+ * iterator object
+ */
+ public void next(Desire desire, Iterator iterator);
+}
diff --git a/src/main/java/com/l2jserver/game/ai/desires/DesireQueue.java b/src/main/java/com/l2jserver/game/ai/desires/DesireQueue.java
new file mode 100644
index 000000000..786b20dad
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/DesireQueue.java
@@ -0,0 +1,212 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.PriorityQueue;
+
+/**
+ * This class represents desire queue, it's thread-safe. Desires can be added
+ * and removed. If desire is added - previous desires will be checked, if same
+ * desire found then desire previous one will be removed from the queue
+ *
+ * @author Rogiel
+ * @see com.l2jserver.game.ai.desires.Desire
+ * @see com.l2jserver.game.ai.desires.AbstractDesire
+ */
+public class DesireQueue {
+ /**
+ * Prioritized Queue of desires, lazy initialization.
+ */
+ protected PriorityQueue queue;
+
+ /**
+ * Returns first element of this queue not removing it. Returns null if
+ * there is no elements.
+ *
+ * @return first element or null
+ */
+ public synchronized Desire peek() {
+ return queue != null ? queue.peek() : null;
+ }
+
+ /**
+ * Removes first element from the desires list and removes it. Returns null
+ * if there are no elements.
+ *
+ * @return first element from the desires list or null.
+ */
+ public synchronized Desire poll() {
+ if (queue != null) {
+ return queue.poll();
+ }
+
+ return null;
+ }
+
+ /**
+ * Adds desire to the queue.
+ *
+ *
+ * When adding object this method checks first for the same object by
+ * {@link AbstractDesire#equals(Object)}, if such object found, next actions
+ * will be done:
+ *
+ * 1). Remove old desire instance from the list.
+ * 2). Check if those desires are same instances by "==".
+ * 3). If they are not the same instances, add desire power from old
+ * instance to new instance, if they are - do nothing.
+ *
+ * After all add new desire instance to the list.
+ *
+ * @param desire
+ * desire instance to add
+ */
+ public synchronized void addDesire(Desire desire) {
+ // Lazy initialization of desire queue
+ if (queue == null) {
+ queue = new PriorityQueue();
+ }
+
+ // Iterate over the list to find similar desires
+ Iterator iterator = queue.iterator();
+ while (iterator.hasNext()) {
+ Desire iterated = iterator.next();
+
+ // Find similar desires by #equals method, they can be different
+ // instances.
+ if (desire.equals(iterated)) {
+ // Remove the old desire from the list
+ iterator.remove();
+
+ // If current desire instance was not at the list - increase
+ // it's power by the value of another instance power
+ // and after that add it to the list
+ if (desire != iterated) {
+ desire.increaseDesirePower(iterated.getDesirePower());
+ }
+
+ // Break iteration, desire list can't contain two same desires
+ break;
+ }
+ }
+ // finally add desire to the list
+ queue.add(desire);
+ }
+
+ /**
+ * Removes desire from this desireQueue. If desire was removed successfully
+ * this method return true, false otherwise
+ *
+ * @param desire
+ * what desire to remove
+ * @return result of desire removal
+ */
+ public synchronized boolean removeDesire(Desire desire) {
+ return queue != null && queue.remove(desire);
+ }
+
+ /**
+ * Iterates over desires, you have to provide iteration handler and
+ * optionally filters.
+ *
+ * Handlers and filters can't call following methods:
+ *
+ *
{@link #addDesire(Desire)}
+ *
{@link #poll()}
+ *
{@link #removeDesire(Desire)}
+ *
+ *
+ * However, method {@link #clear() can be called}.
+ *
+ * @param handler
+ * DesireIterationhandler that will be called on the iteration
+ * @param filters
+ * optional filters that will prevent passing unneeded desires to
+ * the handler
+ * @throws java.util.ConcurrentModificationException
+ * only if called handler or filter modified this queue
+ * @see com.l2jserver.game.ai.desires.DesireIteratorFilter
+ * @see com.l2jserver.game.ai.desires.DesireIteratorFilter#isOk(Desire)
+ * @see com.l2jserver.game.ai.desires.DesireIteratorHandler
+ * @see com.l2jserver.game.ai.desires.DesireIteratorHandler#next(Desire ,
+ * java.util.Iterator)
+ */
+ public synchronized void iterateDesires(DesireIteratorHandler handler,
+ DesireIteratorFilter... filters)
+ throws ConcurrentModificationException {
+
+ if (queue == null) {
+ return;
+ }
+
+ Iterator iterator = queue.iterator();
+ outer: while (iterator.hasNext()) {
+ Desire desire = iterator.next();
+
+ if (filters != null && filters.length > 0) {
+ for (DesireIteratorFilter filter : filters) {
+ if (!filter.isOk(desire)) {
+ continue outer;
+ }
+ }
+ }
+
+ handler.next(desire, iterator);
+ }
+ }
+
+ /**
+ * Returns true if this desire list contains same desire. Desires are
+ * compared by {@link AbstractDesire#equals(Object)} method.
+ *
+ * @param desire
+ * what desire to search
+ * @return true if there is equal desire, false in other case.
+ */
+ public synchronized boolean contains(Desire desire) {
+ return queue.contains(desire);
+ }
+
+ /**
+ * Returns true if this NPC has no any desires added
+ *
+ * @return true if this NPC has no any desires added
+ */
+ public synchronized boolean isEmpty() {
+ return queue == null || queue.isEmpty();
+ }
+
+ /**
+ * Clears all desires
+ */
+ public synchronized void clear() {
+ if (queue != null) {
+ queue.clear();
+ }
+ }
+
+ /**
+ * Returns size of the desire list
+ *
+ * @return size of remaining desires
+ */
+ public synchronized int size() {
+ return queue == null ? 0 : queue.size();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/l2jserver/game/ai/desires/MoveDesire.java b/src/main/java/com/l2jserver/game/ai/desires/MoveDesire.java
new file mode 100644
index 000000000..47af94c8d
--- /dev/null
+++ b/src/main/java/com/l2jserver/game/ai/desires/MoveDesire.java
@@ -0,0 +1,83 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.game.ai.desires;
+
+import com.l2jserver.game.ai.AI;
+import com.l2jserver.model.world.Actor;
+import com.l2jserver.util.geometry.Point3D;
+
+/**
+ * This class indicates that {@link Actor} wants to move somewhere
+ *
+ * @author Rogiel
+ */
+public final class MoveDesire extends AbstractDesire {
+ /**
+ * Target of this desire
+ */
+ protected final Point3D point;
+
+ /**
+ * Creates new move desire. Target can't be changed
+ *
+ * @param point
+ * where to move
+ * @param desirePower
+ * initial attack power
+ */
+ protected MoveDesire(Point3D point, int desirePower) {
+ super(desirePower);
+ this.point = point;
+ }
+
+ @Override
+ public void handleDesire(AI> ai) {
+ // TODO: Implement
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof MoveDesire))
+ return false;
+
+ MoveDesire that = (MoveDesire) o;
+
+ return point.equals(that.point);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ return point.hashCode();
+ }
+
+ /**
+ * Returns target of this desire
+ *
+ * @return target of this desire
+ */
+ public Point3D getTarget() {
+ return point;
+ }
+}
diff --git a/src/main/java/com/l2jserver/game/net/packet/client/AdminCommandPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/AdminCommandPacket.java
index 2edeb6e5e..a6c94dce1 100644
--- a/src/main/java/com/l2jserver/game/net/packet/client/AdminCommandPacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/client/AdminCommandPacket.java
@@ -27,7 +27,7 @@ import com.l2jserver.service.game.spawn.CharacterAlreadyTeleportingServiceExcept
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.util.BufferUtils;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
/**
* Executes an administrator action
diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java
index e0cc9325c..85e25437b 100644
--- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterActionPacket.java
@@ -27,7 +27,7 @@ import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.game.npc.ActionServiceException;
import com.l2jserver.service.game.npc.NPCService;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
/**
* Executes an action from an character to an NPC
diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java
index 031d3db79..27637f8ef 100644
--- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java
@@ -33,7 +33,7 @@ import com.l2jserver.service.game.character.ActorIsNotAttackableServiceException
import com.l2jserver.service.game.character.CannotSetTargetServiceException;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.npc.NotAttackableNPCServiceException;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
/**
* Completes the creation of an character. Creates the object, inserts into the
diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java
index d27a1e3ea..1478bb418 100644
--- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterRequestMovePacket.java
@@ -26,7 +26,7 @@ import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.game.net.packet.server.CharacterStopMovePacket;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.game.character.CharacterService;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
/**
* This packet notifies the server which character the player has chosen to use.
diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java
index e237c6629..e11fbcceb 100644
--- a/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterValidatePositionPacket.java
@@ -22,7 +22,7 @@ import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.service.game.character.CharacterService;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* This packet notifies the server which character the player has chosen to use.
@@ -40,7 +40,7 @@ public class CharacterValidatePositionPacket extends AbstractClientPacket {
*/
private final CharacterService charService;
- private Point point;
+ private Point3D point;
@SuppressWarnings("unused")
private int extra; // vehicle id
@@ -51,7 +51,7 @@ public class CharacterValidatePositionPacket extends AbstractClientPacket {
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
- point = Point.fromXYZA(buffer.readInt(), buffer.readInt(),
+ point = Point3D.fromXYZA(buffer.readInt(), buffer.readInt(),
buffer.readInt(), buffer.readInt());
extra = buffer.readInt();
}
diff --git a/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java
index 45419b948..cdc63ee81 100644
--- a/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java
@@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.model.world.Actor;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
/**
* This packet notifies the client that the character is moving to an certain
diff --git a/src/main/java/com/l2jserver/game/net/packet/server/CharacterTeleportPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/CharacterTeleportPacket.java
index 9955ee2a2..3ea075c7b 100644
--- a/src/main/java/com/l2jserver/game/net/packet/server/CharacterTeleportPacket.java
+++ b/src/main/java/com/l2jserver/game/net/packet/server/CharacterTeleportPacket.java
@@ -22,7 +22,7 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.CharacterCreateFailPacket.Reason;
import com.l2jserver.model.world.L2Character;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* This packet notifies the client that the chosen character has been
@@ -44,9 +44,9 @@ public class CharacterTeleportPacket extends AbstractServerPacket {
/**
* The teleportation point
*/
- private final Point point;
+ private final Point3D point;
- public CharacterTeleportPacket(L2Character character, Point point) {
+ public CharacterTeleportPacket(L2Character character, Point3D point) {
super(OPCODE);
this.character = character;
this.point = point;
diff --git a/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java b/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java
index 8ce8430ca..b23694578 100644
--- a/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java
+++ b/src/main/java/com/l2jserver/model/template/TeleportationTemplate.java
@@ -28,7 +28,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.TeleportationTemplateID;
-import com.l2jserver.util.dimensional.Coordinate;
+import com.l2jserver.util.geometry.Coordinate;
import com.l2jserver.util.jaxb.CoordinateAdapter;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
diff --git a/src/main/java/com/l2jserver/model/world/L2Character.java b/src/main/java/com/l2jserver/model/world/L2Character.java
index 9c028e5b3..aa6763a89 100644
--- a/src/main/java/com/l2jserver/model/world/L2Character.java
+++ b/src/main/java/com/l2jserver/model/world/L2Character.java
@@ -31,7 +31,7 @@ import com.l2jserver.model.world.character.CharacterFriendList;
import com.l2jserver.model.world.character.CharacterInventory;
import com.l2jserver.model.world.character.CharacterShortcutContainer;
import com.l2jserver.model.world.character.CharacterStats;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* This class represents a playable character in Lineage II world.
@@ -179,7 +179,7 @@ public class L2Character extends Player {
/**
* The point the player is moving, teleporting etc...
*/
- private transient Point targetLocation;
+ private transient Point3D targetLocation;
/**
* Creates a new instance
@@ -502,7 +502,7 @@ public class L2Character extends Player {
/**
* @return the targetLocation
*/
- public Point getTargetLocation() {
+ public Point3D getTargetLocation() {
return targetLocation;
}
@@ -510,7 +510,7 @@ public class L2Character extends Player {
* @param targetLocation
* the targetLocation to set
*/
- public void setTargetLocation(Point targetLocation) {
+ public void setTargetLocation(Point3D targetLocation) {
this.targetLocation = targetLocation;
}
diff --git a/src/main/java/com/l2jserver/model/world/PositionableObject.java b/src/main/java/com/l2jserver/model/world/PositionableObject.java
index 8a0fa4226..c75d9839c 100644
--- a/src/main/java/com/l2jserver/model/world/PositionableObject.java
+++ b/src/main/java/com/l2jserver/model/world/PositionableObject.java
@@ -16,8 +16,8 @@
*/
package com.l2jserver.model.world;
-import com.l2jserver.util.dimensional.Coordinate;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Coordinate;
+import com.l2jserver.util.geometry.Point3D;
/**
* This is an abstract object that objects that can be placed in world should
@@ -29,12 +29,12 @@ public abstract class PositionableObject extends AbstractObject {
/**
* The point this object is currently in
*/
- private Point point;
+ private Point3D point;
/**
* @return the coordinate point
*/
- public Point getPoint() {
+ public Point3D getPoint() {
return point;
}
@@ -42,7 +42,7 @@ public abstract class PositionableObject extends AbstractObject {
* @param point
* the coordinate point to set
*/
- public void setPoint(Point point) {
+ public void setPoint(Point3D point) {
this.point = point;
}
@@ -51,6 +51,6 @@ public abstract class PositionableObject extends AbstractObject {
}
public void setPosition(Coordinate coord) {
- this.point = new Point(coord, (point != null ? point.getAngle() : 0));
+ this.point = new Point3D(coord, (point != null ? point.getAngle() : 0));
}
}
diff --git a/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java b/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java
index 8b77650a2..646cde1c4 100644
--- a/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java
+++ b/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java
@@ -20,7 +20,7 @@ import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.event.SpawnEvent;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event dispatcher once an actor has spawned in the world
@@ -35,7 +35,7 @@ public class ActorSpawnEvent implements ActorEvent, SpawnEvent {
/**
* The spawning point
*/
- private final Point point;
+ private final Point3D point;
/**
* Creates a new instance
@@ -45,7 +45,7 @@ public class ActorSpawnEvent implements ActorEvent, SpawnEvent {
* @param point
* the spawn point
*/
- public ActorSpawnEvent(Actor actor, Point point) {
+ public ActorSpawnEvent(Actor actor, Point3D point) {
this.actor = actor;
this.point = point;
}
@@ -61,7 +61,7 @@ public class ActorSpawnEvent implements ActorEvent, SpawnEvent {
}
@Override
- public Point getPoint() {
+ public Point3D getPoint() {
return point;
}
diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java
index 32046f041..dfa073446 100644
--- a/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java
+++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java
@@ -21,7 +21,7 @@ import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event triggered once a character moves
@@ -36,7 +36,7 @@ public class CharacterMoveEvent implements CharacterEvent {
/**
* The old point of the character
*/
- private final Point point;
+ private final Point3D point;
/**
* Creates a new instance
@@ -46,7 +46,7 @@ public class CharacterMoveEvent implements CharacterEvent {
* @param point
* the character point before moving
*/
- public CharacterMoveEvent(L2Character character, Point point) {
+ public CharacterMoveEvent(L2Character character, Point3D point) {
this.character = character;
this.point = point;
}
@@ -54,7 +54,7 @@ public class CharacterMoveEvent implements CharacterEvent {
/**
* @return the old point
*/
- public Point getPoint() {
+ public Point3D getPoint() {
return point;
}
diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java
index 74427e05a..89d83ab13 100644
--- a/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java
+++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java
@@ -21,7 +21,7 @@ import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event triggered once a character moves
@@ -36,7 +36,7 @@ public class CharacterStopMoveEvent implements CharacterEvent {
/**
* The new point of the character
*/
- private final Point point;
+ private final Point3D point;
/**
* Creates a new instance
@@ -46,7 +46,7 @@ public class CharacterStopMoveEvent implements CharacterEvent {
* @param point
* the character point
*/
- public CharacterStopMoveEvent(L2Character character, Point point) {
+ public CharacterStopMoveEvent(L2Character character, Point3D point) {
this.character = character;
this.point = point;
}
@@ -54,7 +54,7 @@ public class CharacterStopMoveEvent implements CharacterEvent {
/**
* @return the point
*/
- public Point getPoint() {
+ public Point3D getPoint() {
return point;
}
diff --git a/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java b/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java
index 440e7606e..892ea8efa 100644
--- a/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java
+++ b/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java
@@ -17,7 +17,7 @@
package com.l2jserver.model.world.event;
import com.l2jserver.service.game.world.event.WorldEvent;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event for objects spawning
@@ -28,5 +28,5 @@ public interface SpawnEvent extends WorldEvent {
/**
* @return the spawning point
*/
- Point getPoint();
+ Point3D getPoint();
}
\ No newline at end of file
diff --git a/src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java b/src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java
index 6529a933a..9cc5c6914 100644
--- a/src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java
+++ b/src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java
@@ -18,7 +18,7 @@ package com.l2jserver.model.world.npc.event;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.actor.event.ActorSpawnEvent;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event dispatched once a {@link NPC} has spawned in the world.
@@ -32,7 +32,7 @@ public class NPCSpawnEvent extends ActorSpawnEvent implements NPCEvent {
* @param point
* the spawn point
*/
- public NPCSpawnEvent(NPC npc, Point point) {
+ public NPCSpawnEvent(NPC npc, Point3D point) {
super(npc, point);
}
diff --git a/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java b/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java
index 8f7866e32..2bc1978d5 100644
--- a/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java
+++ b/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java
@@ -18,7 +18,7 @@ package com.l2jserver.model.world.player.event;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.actor.event.ActorSpawnEvent;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event dispatcher once an player has spawned in the world
@@ -32,7 +32,7 @@ public class PlayerSpawnEvent extends ActorSpawnEvent implements PlayerEvent {
* @param point
* the spawn point
*/
- public PlayerSpawnEvent(Player player, Point point) {
+ public PlayerSpawnEvent(Player player, Point3D point) {
super(player, point);
}
diff --git a/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportedEvent.java b/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportedEvent.java
index b272aae22..001adb8f1 100644
--- a/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportedEvent.java
+++ b/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportedEvent.java
@@ -17,7 +17,7 @@
package com.l2jserver.model.world.player.event;
import com.l2jserver.model.world.Player;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event dispatched once an player has completed its teleportation to another
@@ -34,7 +34,7 @@ public class PlayerTeleportedEvent extends PlayerSpawnEvent {
* @param point
* the teleport point
*/
- public PlayerTeleportedEvent(Player player, Point point) {
+ public PlayerTeleportedEvent(Player player, Point3D point) {
super(player, point);
}
}
diff --git a/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportingEvent.java b/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportingEvent.java
index 1ea4fa7f8..f26952fe2 100644
--- a/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportingEvent.java
+++ b/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportingEvent.java
@@ -20,7 +20,7 @@ import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
-import com.l2jserver.util.dimensional.Point;
+import com.l2jserver.util.geometry.Point3D;
/**
* Event dispatched once an player has started his teleported to another
@@ -30,7 +30,7 @@ import com.l2jserver.util.dimensional.Point;
*/
public class PlayerTeleportingEvent implements PlayerEvent {
private final Player player;
- private final Point point;
+ private final Point3D point;
/**
* Creates a new instance
@@ -40,7 +40,7 @@ public class PlayerTeleportingEvent implements PlayerEvent {
* @param point
* the teleport point
*/
- public PlayerTeleportingEvent(Player player, Point point) {
+ public PlayerTeleportingEvent(Player player, Point3D point) {
this.player = player;
this.point = point;
}
@@ -65,7 +65,7 @@ public class PlayerTeleportingEvent implements PlayerEvent {
*
* @return the teleported point
*/
- public Point getPoint() {
+ public Point3D getPoint() {
return point;
}
diff --git a/src/main/java/com/l2jserver/service/cache/AbstractReferenceCache.java b/src/main/java/com/l2jserver/service/cache/AbstractReferenceCache.java
new file mode 100644
index 000000000..d4119a5cc
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/cache/AbstractReferenceCache.java
@@ -0,0 +1,113 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.cache;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.l2jserver.service.cache.SoftCacheService.SoftCache;
+import com.l2jserver.util.factory.CollectionFactory;
+import com.sun.beans.WeakCache;
+
+/**
+ * Base class for {@link WeakCache} and {@link SoftCache}
+ *
+ * @author Rogiel
+ *
+ * @param
+ * the key type
+ * @param
+ * the value type
+ */
+abstract class AbstractReferenceCache implements Cache {
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * The cache name
+ */
+ protected final String cacheName;
+
+ /**
+ * Map storing references to cached objects
+ */
+ protected final Map> cacheMap = CollectionFactory.newMap();
+ /**
+ * The reference queue
+ */
+ protected final ReferenceQueue refQueue = CollectionFactory
+ .newReferenceQueue();
+
+ /**
+ * @param cacheName
+ * the cache name
+ */
+ protected AbstractReferenceCache(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ @Override
+ public void put(K key, V value) {
+ cleanQueue();
+
+ Reference entry = newReference(key, value, refQueue);
+ cacheMap.put(key, entry);
+
+ log.debug("{}: added for key: {}", cacheName, key);
+ }
+
+ @Override
+ public V get(K key) {
+ cleanQueue();
+
+ Reference reference = cacheMap.get(key);
+ if (reference == null)
+ return null;
+
+ V res = reference.get();
+ if (res != null)
+ log.debug("{}: obtained for key: {}", cacheName, key);
+
+ return res;
+ }
+
+ @Override
+ public boolean contains(K key) {
+ cleanQueue();
+ return cacheMap.containsKey(key);
+ }
+
+ protected abstract void cleanQueue();
+
+ @Override
+ public void remove(K key) {
+ cacheMap.remove(key);
+ log.debug("{}: removed for key: {}", cacheName, key);
+ }
+
+ @Override
+ public void clear() {
+ cacheMap.clear();
+ log.debug("{}: cleared", cacheName);
+ }
+
+ protected abstract Reference newReference(K key, V value,
+ ReferenceQueue queue);
+}
diff --git a/src/main/java/com/l2jserver/service/cache/Cache.java b/src/main/java/com/l2jserver/service/cache/Cache.java
new file mode 100644
index 000000000..370b2e69f
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/cache/Cache.java
@@ -0,0 +1,64 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.cache;
+
+/**
+ * This interface represents a Map structure for cache usage.
+ *
+ * @author Rogiel
+ */
+public interface Cache {
+ /**
+ * Adds a pair to cache.
+ *
+ *
+ * NOTICE: if there is already a value with
+ * given id in the map, {@link IllegalArgumentException} will be thrown.
+ *
+ * @param key
+ * @param value
+ */
+ void put(K key, V value);
+
+ /**
+ * Returns cached value correlated to given key.
+ *
+ * @param key
+ * @return
+ */
+ V get(K key);
+
+ /**
+ * Checks whether this map contains a value related to given key.
+ *
+ * @param key
+ * @return
+ */
+ boolean contains(K key);
+
+ /**
+ * Removes an entry from the map, that has given key.
+ *
+ * @param key
+ */
+ void remove(K key);
+
+ /**
+ * Clears this cache
+ */
+ void clear();
+}
diff --git a/src/main/java/com/l2jserver/service/cache/CacheService.java b/src/main/java/com/l2jserver/service/cache/CacheService.java
index 5b0e17a46..7de117c10 100644
--- a/src/main/java/com/l2jserver/service/cache/CacheService.java
+++ b/src/main/java/com/l2jserver/service/cache/CacheService.java
@@ -16,8 +16,6 @@
*/
package com.l2jserver.service.cache;
-import net.sf.ehcache.Cache;
-
import com.l2jserver.service.Service;
/**
@@ -31,7 +29,6 @@ import com.l2jserver.service.Service;
* {@link IgnoreCaching}
*
* @author Rogiel
- *
*/
public interface CacheService extends Service {
/**
@@ -50,39 +47,60 @@ public interface CacheService extends Service {
/**
* Creates a new cache with default configurations. Eviction mode is LRU
- * (Last Recently Used). If you wish more customization, you should manually
- * create the cache and register it using {@link #register(Cache)}.
+ * (Last Recently Used). The size is only a guarantee that you can store
+ * at leastn items.
*
+ * @param
+ * the cache key type
+ * @param
+ * the cache value type
* @param name
* the cache name
* @size the maximum cache size
* @return the created cache
*/
- Cache createCache(String name, int size);
+ Cache createCache(String name, int size);
+
+ /**
+ * Creates a new eternal cache with default configurations. An eternal cache
+ * is guaranteed to never automatically expire items. The size is only a
+ * guarantee that you can store at leastn items.
+ *
+ * @param
+ * the cache key type
+ * @param
+ * the cache value type
+ * @param name
+ * the cache name
+ * @size the maximum cache size
+ * @return the created cache
+ */
+ Cache createEternalCache(String name, int size);
/**
* Creates a new cache with default configurations. The default cache size
- * is 200.
+ * is 200. The size is only a guarantee that you can store at least
+ * 200 items.
*
+ * @param
+ * the cache key type
+ * @param
+ * the cache value type
* @param name
* the cache name
* @return the created cache
*/
- Cache createCache(String name);
+ Cache createCache(String name);
/**
- * Registers a new cache
+ * Disposes the cache. Once the cache is disposed it cannot be used anymore.
*
+ * @param
+ * the cache key type
+ * @param
+ * the cache value type
* @param cache
* the cache
*/
- void register(Cache cache);
-
- /**
- * Unregisters an already registered cache
- *
- * @param cache
- * the cache
- */
- void unregister(Cache cache);
+ void dispose(Cache cache);
}
diff --git a/src/main/java/com/l2jserver/service/cache/EhCacheService.java b/src/main/java/com/l2jserver/service/cache/EhCacheService.java
index 7ba709670..07d19e95d 100644
--- a/src/main/java/com/l2jserver/service/cache/EhCacheService.java
+++ b/src/main/java/com/l2jserver/service/cache/EhCacheService.java
@@ -20,9 +20,7 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.Arrays;
-import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.config.CacheConfiguration;
@@ -48,7 +46,7 @@ public class EhCacheService extends AbstractService implements CacheService {
/**
* The interface cache
*/
- private Cache interfaceCache;
+ private Cache interfaceCache;
@Override
protected void doStart() throws ServiceStartException {
@@ -76,10 +74,7 @@ public class EhCacheService extends AbstractService implements CacheService {
return method.invoke(instance, args);
final MethodInvocation invocation = new MethodInvocation(
method, args);
- Element element = interfaceCache.get(invocation);
- if (element == null)
- return doInvoke(invocation, proxy, method, args);
- Object result = element.getObjectValue();
+ Object result = interfaceCache.get(invocation);
if (result == null)
return doInvoke(invocation, proxy, method, args);
return result;
@@ -90,43 +85,94 @@ public class EhCacheService extends AbstractService implements CacheService {
throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
Object result = method.invoke(instance, args);
- interfaceCache.put(new Element(invocation, result));
+ interfaceCache.put(invocation, result);
return result;
}
});
return proxy;
}
+ // @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)
+ // .timeToIdleSeconds(30).diskPersistent(false)
+ // .diskExpiryThreadIntervalSeconds(0));
+ // register(cache);
+ // return cache;
+ // }
+ //
+ // @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());
+ // }
+
@Override
- public Cache createCache(String name, int size) {
+ 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)
- .timeToIdleSeconds(30).diskPersistent(false)
- .diskExpiryThreadIntervalSeconds(0));
- register(cache);
- return cache;
- }
-
- @Override
- public Cache createCache(String name) {
- Preconditions.checkNotNull(name, "name");
- return createCache(name, 200);
- }
-
- @Override
- public void register(Cache cache) {
- Preconditions.checkNotNull(cache, "cache");
+ net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(
+ new CacheConfiguration(name, size)
+ .memoryStoreEvictionPolicy(
+ MemoryStoreEvictionPolicy.LRU)
+ .overflowToDisk(true).eternal(false)
+ .timeToLiveSeconds(60).timeToIdleSeconds(30)
+ .diskPersistent(false)
+ .diskExpiryThreadIntervalSeconds(0));
manager.addCache(cache);
+ return new EhCacheFacade(cache);
}
@Override
- public void unregister(Cache cache) {
- Preconditions.checkNotNull(cache, "cache");
- manager.removeCache(cache.getName());
+ public Cache createEternalCache(String name, int size) {
+ Preconditions.checkNotNull(name, "name");
+ Preconditions.checkArgument(size > 0, "size <= 0");
+
+ net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(
+ new CacheConfiguration(name, size)
+ .memoryStoreEvictionPolicy(
+ MemoryStoreEvictionPolicy.LRU)
+ .overflowToDisk(true).eternal(true)
+ .diskExpiryThreadIntervalSeconds(0));
+ manager.addCache(cache);
+ return new EhCacheFacade(cache);
+ }
+
+ @Override
+ public Cache createCache(String name) {
+ net.sf.ehcache.Cache cache = new net.sf.ehcache.Cache(
+ new CacheConfiguration(name, 200)
+ .memoryStoreEvictionPolicy(
+ MemoryStoreEvictionPolicy.LRU)
+ .overflowToDisk(true).eternal(true)
+ .diskExpiryThreadIntervalSeconds(0));
+ manager.addCache(cache);
+ return new EhCacheFacade(cache);
+ }
+
+ @Override
+ public void dispose(Cache cache) {
+ if (cache instanceof EhCacheFacade) {
+ manager.removeCache(((EhCacheFacade) cache).cache.getName());
+ }
}
@Override
@@ -136,42 +182,40 @@ public class EhCacheService extends AbstractService implements CacheService {
interfaceCache = null;
}
- private static class MethodInvocation {
- private final Method method;
- private final Object[] args;
+ private class EhCacheFacade implements Cache {
+ private final net.sf.ehcache.Cache cache;
- public MethodInvocation(Method method, Object[] args) {
- this.method = method;
- this.args = args;
+ public EhCacheFacade(net.sf.ehcache.Cache cache) {
+ this.cache = cache;
}
@Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(args);
- result = prime * result
- + ((method == null) ? 0 : method.hashCode());
- return result;
+ public void put(K key, V value) {
+ cache.put(new Element(key, value));
}
@Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- MethodInvocation other = (MethodInvocation) obj;
- if (!Arrays.equals(args, other.args))
- return false;
- if (method == null) {
- if (other.method != null)
- return false;
- } else if (!method.equals(other.method))
- return false;
- return true;
+ @SuppressWarnings("unchecked")
+ public V get(K key) {
+ final Element element = cache.get(key);
+ if (element == null)
+ return null;
+ return (V) element.getValue();
+ }
+
+ @Override
+ public boolean contains(K key) {
+ return cache.get(key) != null;
+ }
+
+ @Override
+ public void remove(K key) {
+ cache.remove(key);
+ }
+
+ @Override
+ public void clear() {
+ cache.removeAll();
}
}
}
diff --git a/src/main/java/com/l2jserver/service/cache/EternalCache.java b/src/main/java/com/l2jserver/service/cache/EternalCache.java
new file mode 100644
index 000000000..41d55da7d
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/cache/EternalCache.java
@@ -0,0 +1,87 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.cache;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.l2jserver.util.factory.CollectionFactory;
+
+/**
+ * Cache class for an eternal cache
+ *
+ * @author Rogiel
+ *
+ * @param
+ * the key type
+ * @param
+ * the value type
+ */
+class EternalCache implements Cache {
+ protected final Logger log = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * The cache name
+ */
+ protected final String cacheName;
+
+ /**
+ * Map storing references to cached objects
+ */
+ protected final Map cacheMap = CollectionFactory.newMap();
+
+ /**
+ * @param cacheName
+ * the cache name
+ */
+ protected EternalCache(String cacheName) {
+ this.cacheName = cacheName;
+ }
+
+ @Override
+ public void put(K key, V value) {
+ cacheMap.put(key, value);
+ log.debug("{}: added for key: {}", cacheName, key);
+ }
+
+ @Override
+ public V get(K key) {
+ V obj = cacheMap.get(key);
+ if (obj != null)
+ log.debug("{}: obtained for key: {}", cacheName, key);
+ return obj;
+ }
+
+ @Override
+ public boolean contains(K key) {
+ return cacheMap.containsKey(key);
+ }
+
+ @Override
+ public void remove(K key) {
+ cacheMap.remove(key);
+ log.debug("{}: removed for key: {}", cacheName, key);
+ }
+
+ @Override
+ public void clear() {
+ cacheMap.clear();
+ log.debug("{}: cleared", cacheName);
+ }
+}
diff --git a/src/main/java/com/l2jserver/service/cache/MethodInvocation.java b/src/main/java/com/l2jserver/service/cache/MethodInvocation.java
new file mode 100644
index 000000000..84a3bb386
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/cache/MethodInvocation.java
@@ -0,0 +1,69 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.cache;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+/**
+ * Simple class used to store method invocations for the proxied cache.
+ *
+ * @author Rogiel
+ */
+class MethodInvocation {
+ /**
+ * The invoked method
+ */
+ private final Method method;
+ /**
+ * The invocation arguments
+ */
+ private final Object[] args;
+
+ public MethodInvocation(Method method, Object[] args) {
+ this.method = method;
+ this.args = args;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(args);
+ result = prime * result + ((method == null) ? 0 : method.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ MethodInvocation other = (MethodInvocation) obj;
+ if (!Arrays.equals(args, other.args))
+ return false;
+ if (method == null) {
+ if (other.method != null)
+ return false;
+ } else if (!method.equals(other.method))
+ return false;
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/l2jserver/service/cache/SoftCacheService.java b/src/main/java/com/l2jserver/service/cache/SoftCacheService.java
new file mode 100644
index 000000000..edddab5bf
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/cache/SoftCacheService.java
@@ -0,0 +1,164 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.cache;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import com.google.common.base.Preconditions;
+import com.l2jserver.service.AbstractService;
+import com.l2jserver.service.ServiceStartException;
+import com.l2jserver.service.ServiceStopException;
+
+/**
+ * This {@link Cache} service implementation uses a {@link SoftReference} to
+ * store values.
+ *
+ * @author Rogiel
+ */
+public class SoftCacheService extends AbstractService implements CacheService {
+ /**
+ * The interface cache
+ */
+ private Cache interfaceCache;
+
+ @Override
+ protected void doStart() throws ServiceStartException {
+ interfaceCache = createCache("interface-cache");
+ }
+
+ @Override
+ public T decorate(final Class interfaceType,
+ final T instance) {
+ Preconditions.checkNotNull(interfaceType, "interfaceType");
+ Preconditions.checkNotNull(instance, "instance");
+
+ if (!interfaceType.isInterface())
+ return null;
+ @SuppressWarnings("unchecked")
+ final T proxy = (T) Proxy.newProxyInstance(this.getClass()
+ .getClassLoader(), new Class[] { interfaceType },
+ new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method,
+ Object[] args) throws Throwable {
+ if (method.isAnnotationPresent(IgnoreCaching.class))
+ return method.invoke(instance, args);
+ final MethodInvocation invocation = new MethodInvocation(
+ method, args);
+ Object result = interfaceCache.get(invocation);
+ if (result == null)
+ return doInvoke(invocation, proxy, method, args);
+ return result;
+ }
+
+ private Object doInvoke(MethodInvocation invocation,
+ Object proxy, Method method, Object[] args)
+ throws IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException {
+ Object result = method.invoke(instance, args);
+ interfaceCache.put(invocation, result);
+ return result;
+ }
+ });
+ return proxy;
+ }
+
+ @Override
+ public Cache createCache(String name, int size) {
+ return new SoftCache(name);
+ }
+
+ @Override
+ public Cache createEternalCache(String name, int size) {
+ return new EternalCache(name);
+ }
+
+ @Override
+ public Cache createCache(String name) {
+ return new SoftCache(name);
+ }
+
+ @Override
+ public void dispose(Cache cache) {
+ cache.clear();
+ }
+
+ @Override
+ protected void doStop() throws ServiceStopException {
+ dispose(interfaceCache);
+ interfaceCache = null;
+ }
+
+ /**
+ * This class is a simple map implementation for cache usage.
+ *
+ * Value may be stored in map really long, but it for sure will be removed
+ * if there is low memory (and of course there isn't any strong reference to
+ * value object)
+ *
+ * @author Rogiel
+ */
+ public class SoftCache extends AbstractReferenceCache implements
+ Cache {
+ /**
+ * This class is a {@link SoftReference} with additional responsibility
+ * of holding key object
+ *
+ * @author Rogiel
+ */
+ private class SoftEntry extends SoftReference {
+ private K key;
+
+ SoftEntry(K key, V referent, ReferenceQueue super V> q) {
+ super(referent, q);
+ this.key = key;
+ }
+
+ K getKey() {
+ return key;
+ }
+ }
+
+ public SoftCache(String cacheName) {
+ super(cacheName);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected synchronized void cleanQueue() {
+ SoftEntry en = null;
+ while ((en = (SoftEntry) refQueue.poll()) != null) {
+ K key = en.getKey();
+ if (log.isDebugEnabled())
+ log.debug("{} : cleaned up {} for key: {}", cacheName, key);
+ cacheMap.remove(key);
+ }
+ }
+
+ @Override
+ protected Reference newReference(K key, V value,
+ ReferenceQueue vReferenceQueue) {
+ return new SoftEntry(key, value, vReferenceQueue);
+ }
+ }
+}
diff --git a/src/main/java/com/l2jserver/service/cache/WeakCacheService.java b/src/main/java/com/l2jserver/service/cache/WeakCacheService.java
new file mode 100644
index 000000000..b5cca9590
--- /dev/null
+++ b/src/main/java/com/l2jserver/service/cache/WeakCacheService.java
@@ -0,0 +1,164 @@
+/*
+ * This file is part of l2jserver .
+ *
+ * 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 .
+ */
+package com.l2jserver.service.cache;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import com.google.common.base.Preconditions;
+import com.l2jserver.service.AbstractService;
+import com.l2jserver.service.ServiceStartException;
+import com.l2jserver.service.ServiceStopException;
+
+/**
+ * This {@link Cache} service implementation uses a {@link SoftReference} to
+ * store values.
+ *
+ * @author Rogiel
+ */
+public class WeakCacheService extends AbstractService implements CacheService {
+ /**
+ * The interface cache
+ */
+ private Cache interfaceCache;
+
+ @Override
+ protected void doStart() throws ServiceStartException {
+ interfaceCache = createCache("interface-cache");
+ }
+
+ @Override
+ public T decorate(final Class interfaceType,
+ final T instance) {
+ Preconditions.checkNotNull(interfaceType, "interfaceType");
+ Preconditions.checkNotNull(instance, "instance");
+
+ if (!interfaceType.isInterface())
+ return null;
+ @SuppressWarnings("unchecked")
+ final T proxy = (T) Proxy.newProxyInstance(this.getClass()
+ .getClassLoader(), new Class[] { interfaceType },
+ new InvocationHandler() {
+ @Override
+ public Object invoke(Object proxy, Method method,
+ Object[] args) throws Throwable {
+ if (method.isAnnotationPresent(IgnoreCaching.class))
+ return method.invoke(instance, args);
+ final MethodInvocation invocation = new MethodInvocation(
+ method, args);
+ Object result = interfaceCache.get(invocation);
+ if (result == null)
+ return doInvoke(invocation, proxy, method, args);
+ return result;
+ }
+
+ private Object doInvoke(MethodInvocation invocation,
+ Object proxy, Method method, Object[] args)
+ throws IllegalArgumentException,
+ IllegalAccessException, InvocationTargetException {
+ Object result = method.invoke(instance, args);
+ interfaceCache.put(invocation, result);
+ return result;
+ }
+ });
+ return proxy;
+ }
+
+ @Override
+ public Cache createCache(String name, int size) {
+ return new WeakCache(name);
+ }
+
+ @Override
+ public Cache createEternalCache(String name, int size) {
+ return new EternalCache(name);
+ }
+
+ @Override
+ public Cache createCache(String name) {
+ return new WeakCache(name);
+ }
+
+ @Override
+ public void dispose(Cache cache) {
+ cache.clear();
+ }
+
+ @Override
+ protected void doStop() throws ServiceStopException {
+ dispose(interfaceCache);
+ interfaceCache = null;
+ }
+
+ /**
+ * This class is a simple map implementation for cache usage.
+ *
+ * Values from the map will be removed after the first garbage collector run
+ * if there isn't any strong reference to the value object.
+ *
+ * @author Rogiel
+ */
+ private class WeakCache extends AbstractReferenceCache
+ implements Cache {
+ /**
+ * This class is a {@link WeakReference} with additional responsibility
+ * of holding key object
+ *
+ * @author Rogiel
+ */
+ private class Entry extends WeakReference {
+ private K key;
+
+ Entry(K key, V referent, ReferenceQueue super V> q) {
+ super(referent, q);
+ this.key = key;
+ }
+
+ K getKey() {
+ return key;
+ }
+ }
+
+ WeakCache(String cacheName) {
+ super(cacheName);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected synchronized void cleanQueue() {
+ Entry en = null;
+ while ((en = (Entry) refQueue.poll()) != null) {
+ K key = en.getKey();
+ if (log.isDebugEnabled())
+ log.debug("{}: cleaned up for key: {}", cacheName, key);
+ cacheMap.remove(key);
+ }
+ }
+
+ @Override
+ protected Reference newReference(K key, V value,
+ ReferenceQueue vReferenceQueue) {
+ return new Entry(key, value, vReferenceQueue);
+ }
+ }
+}
diff --git a/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java b/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java
index 438ae9e01..8fcc392a0 100644
--- a/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java
+++ b/src/main/java/com/l2jserver/service/database/JDBCDatabaseService.java
@@ -28,11 +28,6 @@ import java.util.List;
import javax.sql.DataSource;
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.Element;
-import net.sf.ehcache.config.CacheConfiguration;
-import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
-
import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;
import org.apache.commons.dbcp.PoolableConnectionFactory;
@@ -53,6 +48,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.cache.Cache;
import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.core.LoggingService;
@@ -105,7 +101,7 @@ public class JDBCDatabaseService extends AbstractService implements
/**
* An cache object
*/
- private Cache objectCache;
+ private Cache