1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-08 08:23:11 +00:00

Automatic database updates

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-31 19:03:03 -03:00
parent 657b555fe1
commit 551dc6917e
26 changed files with 355 additions and 113 deletions

View File

@@ -32,7 +32,7 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
/**
* The database object state
*/
protected transient ObjectState state = ObjectState.NOT_STORED;
protected transient ObjectDesire desire = ObjectDesire.INSERT;
@Override
public T getID() {
@@ -46,13 +46,26 @@ public abstract class AbstractModel<T extends ID<?>> implements Model<T> {
}
@Override
public ObjectState getObjectState() {
return state;
public ObjectDesire getObjectDesire() {
return desire;
}
@Override
public void setObjectState(ObjectState state) {
this.state = state;
public void setObjectDesire(ObjectDesire desire) {
if (desire == null)
desire = ObjectDesire.NONE;
this.desire = desire;
}
/**
* Set this object desire to {@link ObjectDesire#UPDATE}. If the desire is
* {@link ObjectDesire#INSERT} or {@link ObjectDesire#DELETE} the desire
* will not be changed.
*/
protected void desireUpdate() {
if (this.desire != ObjectDesire.INSERT
&& this.desire != ObjectDesire.DELETE)
this.desire = ObjectDesire.UPDATE;
}
@Override

View File

@@ -37,15 +37,15 @@ public interface Model<T extends ID<?>> {
/**
* @return the database object state
*/
ObjectState getObjectState();
ObjectDesire getObjectDesire();
/**
* @param state
* the database object state to set
*/
void setObjectState(ObjectState state);
void setObjectDesire(ObjectDesire state);
public enum ObjectState {
STORED, NOT_STORED, ORPHAN;
public enum ObjectDesire {
NONE, INSERT, UPDATE, DELETE;
}
}

View File

@@ -89,6 +89,7 @@ public class Fort extends AbstractModel<FortID> {
* the castleID to set
*/
public void setCastleID(CastleID castleID) {
desireUpdate();
this.castleID = castleID;
}
@@ -104,6 +105,7 @@ public class Fort extends AbstractModel<FortID> {
* the ownerID to set
*/
public void setOwnerID(CharacterID ownerID) {
desireUpdate();
this.ownerID = ownerID;
}
@@ -119,6 +121,7 @@ public class Fort extends AbstractModel<FortID> {
* the name to set
*/
public void setName(String name) {
desireUpdate();
this.name = name;
}
@@ -134,6 +137,7 @@ public class Fort extends AbstractModel<FortID> {
* the siegeDate to set
*/
public void setSiegeDate(Date siegeDate) {
desireUpdate();
this.siegeDate = siegeDate;
}
@@ -149,6 +153,7 @@ public class Fort extends AbstractModel<FortID> {
* the lastOwnedTime to set
*/
public void setLastOwnedTime(Date lastOwnedTime) {
desireUpdate();
this.lastOwnedTime = lastOwnedTime;
}
@@ -164,6 +169,7 @@ public class Fort extends AbstractModel<FortID> {
* the fortType to set
*/
public void setFortType(FortType fortType) {
desireUpdate();
this.fortType = fortType;
}
@@ -179,6 +185,7 @@ public class Fort extends AbstractModel<FortID> {
* the state to set
*/
public void setState(boolean state) {
desireUpdate();
this.state = state;
}
@@ -194,6 +201,7 @@ public class Fort extends AbstractModel<FortID> {
* the blood to set
*/
public void setBlood(boolean blood) {
desireUpdate();
this.blood = blood;
}
@@ -209,6 +217,7 @@ public class Fort extends AbstractModel<FortID> {
* the supplyLvL to set
*/
public void setSupplyLvL(int supplyLvL) {
desireUpdate();
this.supplyLvL = supplyLvL;
}
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.model.game;
import com.l2jserver.model.AbstractModel;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ItemID;
import com.l2jserver.model.id.template.SkillTemplateID;
@@ -24,9 +25,10 @@ import com.l2jserver.model.world.L2Character;
/**
* An shortcut in Lineage II game interface
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @author <a href="http://www.rogiel.com">Rogiel</a><br />
* TODO create the shortcut id
*/
public class Shortcut {
public class Shortcut extends AbstractModel {
/**
* The character id
*/
@@ -179,6 +181,7 @@ public class Shortcut {
* the skillID to set
*/
public void setSkillID(SkillTemplateID skillID) {
desireUpdate();
this.skillID = skillID;
}
@@ -194,6 +197,7 @@ public class Shortcut {
* the itemID to set
*/
public void setItemID(ItemID itemID) {
desireUpdate();
this.itemID = itemID;
}
@@ -209,6 +213,7 @@ public class Shortcut {
* the slot to set
*/
public void setSlot(int slot) {
desireUpdate();
this.slot = slot;
}
@@ -224,6 +229,7 @@ public class Shortcut {
* the page to set
*/
public void setPage(int page) {
desireUpdate();
this.page = page;
}
@@ -239,6 +245,7 @@ public class Shortcut {
* the type to set
*/
public void setType(ShortcutType type) {
desireUpdate();
this.type = type;
}
@@ -254,6 +261,7 @@ public class Shortcut {
* the level to set
*/
public void setLevel(int level) {
desireUpdate();
this.level = level;
}
@@ -269,6 +277,7 @@ public class Shortcut {
* the characterType to set
*/
public void setCharacterType(int characterType) {
desireUpdate();
this.characterType = characterType;
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.model.game;
import com.l2jserver.model.AbstractModel;
import com.l2jserver.model.id.object.ActorID;
import com.l2jserver.model.id.template.SkillTemplateID;
import com.l2jserver.model.template.SkillTemplate;
@@ -26,7 +27,7 @@ import com.l2jserver.model.world.Actor;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Skill {
public class Skill extends AbstractModel {
/**
* The skill template ID
*/
@@ -90,6 +91,7 @@ public class Skill {
* the actor ID to set
*/
public void setActorID(ActorID<?> actorID) {
desireUpdate();
this.actorID = actorID;
}
@@ -105,6 +107,7 @@ public class Skill {
* the level to set
*/
public void setLevel(int level) {
desireUpdate();
this.level = level;
}

View File

@@ -268,7 +268,13 @@ public class NPCTemplate extends ActorTemplate<NPC> {
@Override
protected NPC createInstance() {
return new NPC(this.id);
final NPC npc = new NPC(this.id);
// new npcs are full hp/mp
npc.setHP(getMaximumHP());
npc.setMP(getMaximumMP());
return npc;
}
/**

View File

@@ -148,6 +148,7 @@ public abstract class Actor extends PositionableObject {
* the race to set
*/
public void setRace(ActorRace race) {
desireUpdate();
this.race = race;
}
@@ -163,6 +164,7 @@ public abstract class Actor extends PositionableObject {
* the sex to set
*/
public void setSex(ActorSex sex) {
desireUpdate();
this.sex = sex;
}
@@ -178,6 +180,7 @@ public abstract class Actor extends PositionableObject {
* the level to set
*/
public void setLevel(int level) {
desireUpdate();
this.level = level;
}
@@ -193,6 +196,7 @@ public abstract class Actor extends PositionableObject {
* the hP to set
*/
public void setHP(double hP) {
desireUpdate();
HP = hP;
}
@@ -208,6 +212,7 @@ public abstract class Actor extends PositionableObject {
* the mP to set
*/
public void setMP(double mP) {
desireUpdate();
MP = mP;
}
@@ -223,6 +228,7 @@ public abstract class Actor extends PositionableObject {
* the experience to set
*/
public void setExperience(long experience) {
desireUpdate();
this.experience = experience;
}
@@ -238,6 +244,7 @@ public abstract class Actor extends PositionableObject {
* the sp to set
*/
public void setSP(int sp) {
desireUpdate();
this.sp = sp;
}

View File

@@ -58,6 +58,7 @@ public class Clan extends AbstractObject implements Iterable<L2Character> {
* the leaderID to set
*/
public void setLeaderID(CharacterID leaderID) {
desireUpdate();
this.leaderID = leaderID;
}

View File

@@ -85,6 +85,7 @@ public class Item extends PositionableObject {
* the count to set
*/
public void setCount(long count) {
desireUpdate();
this.count = count;
}
@@ -100,6 +101,7 @@ public class Item extends PositionableObject {
* the location to set
*/
public void setLocation(InventoryLocation location) {
desireUpdate();
this.location = location;
if (location != InventoryLocation.PAPERDOLL)
this.paperdoll = null;
@@ -117,6 +119,7 @@ public class Item extends PositionableObject {
* the paperdoll to set
*/
public void setPaperdoll(InventoryPaperdoll paperdoll) {
desireUpdate();
this.paperdoll = paperdoll;
}
@@ -146,6 +149,7 @@ public class Item extends PositionableObject {
* the ownerID to set
*/
public void setOwnerID(CharacterID ownerID) {
desireUpdate();
this.ownerID = ownerID;
}
}

View File

@@ -203,6 +203,7 @@ public class L2Character extends Player {
* the account ID to set
*/
public void setAccountID(AccountID accountID) {
desireUpdate();
this.accountID = accountID;
}
@@ -227,6 +228,7 @@ public class L2Character extends Player {
* the clanID to set
*/
public void setClanID(ClanID clanID) {
desireUpdate();
this.clanID = clanID;
}
@@ -251,6 +253,7 @@ public class L2Character extends Player {
* the petID to set
*/
public void setPetID(PetID petID) {
desireUpdate();
this.petID = petID;
}
@@ -266,6 +269,7 @@ public class L2Character extends Player {
* the name to set
*/
public void setName(String name) {
desireUpdate();
this.name = name;
}
@@ -281,6 +285,7 @@ public class L2Character extends Player {
* the title to set
*/
public void setTitle(String title) {
desireUpdate();
this.title = title;
}
@@ -296,6 +301,7 @@ public class L2Character extends Player {
* the characterClass to set
*/
public void setCharacterClass(CharacterClass characterClass) {
desireUpdate();
this.characterClass = characterClass;
}
@@ -311,6 +317,7 @@ public class L2Character extends Player {
* the character CP to set
*/
public void setCP(double CP) {
desireUpdate();
this.CP = CP;
}
@@ -326,6 +333,7 @@ public class L2Character extends Player {
* the online to set
*/
public void setOnline(boolean online) {
desireUpdate();
this.online = online;
}
@@ -341,6 +349,7 @@ public class L2Character extends Player {
* the lastAccess to set
*/
public void setLastAccess(Date lastAccess) {
desireUpdate();
this.lastAccess = lastAccess;
}
@@ -363,6 +372,7 @@ public class L2Character extends Player {
* the character karma points to set
*/
public void setKarma(int karma) {
desireUpdate();
this.karma = karma;
}
@@ -378,6 +388,7 @@ public class L2Character extends Player {
* the character PK kills to set
*/
public void setPkKills(int pkKills) {
desireUpdate();
this.pkKills = pkKills;
}
@@ -393,6 +404,7 @@ public class L2Character extends Player {
* the character PVP kills to set
*/
public void setPvpKills(int pvpKills) {
desireUpdate();
this.pvpKills = pvpKills;
}

View File

@@ -43,6 +43,7 @@ public abstract class PositionableObject extends AbstractObject {
* the coordinate point to set
*/
public void setPoint(Point3D point) {
desireUpdate();
this.point = point;
}
@@ -51,6 +52,7 @@ public abstract class PositionableObject extends AbstractObject {
}
public void setPosition(Coordinate coord) {
desireUpdate();
this.point = new Point3D(coord, (point != null ? point.getAngle() : 0));
}
}