From 9d05349b26a161d4fa8aaa1256d8193b801b52eb Mon Sep 17 00:00:00 2001 From: Major- Date: Sat, 19 Jul 2014 04:46:20 +0100 Subject: [PATCH] Move attribute persistence to its own file. --- data/plugins/entity/attributes/attributes.rb | 11 ++------ .../entity/attr/AttributeDefinition.java | 25 +++---------------- .../entity/attr/AttributePersistence.java | 18 +++++++++++++ .../io/player/impl/BinaryPlayerSaver.java | 3 ++- 4 files changed, 26 insertions(+), 31 deletions(-) create mode 100644 src/org/apollo/game/model/entity/attr/AttributePersistence.java diff --git a/data/plugins/entity/attributes/attributes.rb b/data/plugins/entity/attributes/attributes.rb index 720d8bd8..161ac917 100644 --- a/data/plugins/entity/attributes/attributes.rb +++ b/data/plugins/entity/attributes/attributes.rb @@ -4,6 +4,7 @@ java_import 'org.apollo.game.model.entity.Entity' java_import 'org.apollo.game.model.entity.attr.Attribute' java_import 'org.apollo.game.model.entity.attr.AttributeDefinition' java_import 'org.apollo.game.model.entity.attr.AttributeMap' +java_import 'org.apollo.game.model.entity.attr.AttributePersistence' java_import 'org.apollo.game.model.entity.attr.AttributeType' java_import 'org.apollo.game.model.entity.attr.BooleanAttribute' java_import 'org.apollo.game.model.entity.attr.NumericalAttribute' @@ -66,13 +67,5 @@ end def get_persistence(persistence) raise "Undefined persistence type #{persistence}." unless persistence == :serialized || persistence == :transient - return persistence == :serialized ? AttributeDefinition::Persistence::SERIALIZED : AttributeDefinition::Persistence::TRANSIENT -end - -declare_attribute :test, 42, :serialized - -on :command, :test do |player, command| - player.send_message(player.test.to_s) - player.test = 6.5 - player.send_message(player.test.to_s) + return persistence == :serialized ? AttributePersistence::SERIALIZED : AttributePersistence::TRANSIENT end \ No newline at end of file diff --git a/src/org/apollo/game/model/entity/attr/AttributeDefinition.java b/src/org/apollo/game/model/entity/attr/AttributeDefinition.java index b6cba520..9a48b15d 100644 --- a/src/org/apollo/game/model/entity/attr/AttributeDefinition.java +++ b/src/org/apollo/game/model/entity/attr/AttributeDefinition.java @@ -9,23 +9,6 @@ package org.apollo.game.model.entity.attr; */ public final class AttributeDefinition { - /** - * The persistence state of an attribute - either {@code PERSISTENT} (saved) or {@code TRANSIENT} (not saved). - */ - public enum Persistence { - - /** - * The serialized persistence type, indicating that the attribute will be saved. - */ - SERIALIZED, - - /** - * The transient persistence type, indicating that the attribute will not be saved. - */ - TRANSIENT; - - } - /** * The default value of this definition. */ @@ -34,7 +17,7 @@ public final class AttributeDefinition { /** * The persistence state of this definition. */ - private final Persistence persistence; + private final AttributePersistence persistence; /** * The type of this definition. @@ -45,10 +28,10 @@ public final class AttributeDefinition { * Creates the attribute definition. * * @param defaultValue The default value. - * @param persistence The {@link Persistence} state. + * @param persistence The {@link AttributePersistence} state. * @param type The {@link AttributeType}. */ - public AttributeDefinition(T defaultValue, Persistence persistence, AttributeType type) { + public AttributeDefinition(T defaultValue, AttributePersistence persistence, AttributeType type) { this.defaultValue = defaultValue; this.persistence = persistence; this.type = type; @@ -68,7 +51,7 @@ public final class AttributeDefinition { * * @return The persistence. */ - public Persistence getPersistence() { + public AttributePersistence getPersistence() { return persistence; } diff --git a/src/org/apollo/game/model/entity/attr/AttributePersistence.java b/src/org/apollo/game/model/entity/attr/AttributePersistence.java new file mode 100644 index 00000000..29cb365f --- /dev/null +++ b/src/org/apollo/game/model/entity/attr/AttributePersistence.java @@ -0,0 +1,18 @@ +package org.apollo.game.model.entity.attr; + +/** + * The persistence state of an attribute - either {@code PERSISTENT} (saved) or {@code TRANSIENT} (not saved). + */ +public enum AttributePersistence { + + /** + * The serialized persistence type, indicating that the attribute will be saved. + */ + SERIALIZED, + + /** + * The transient persistence type, indicating that the attribute will not be saved. + */ + TRANSIENT; + +} \ No newline at end of file diff --git a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java index b530c0ad..5dd050c7 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java @@ -18,6 +18,7 @@ import org.apollo.game.model.entity.attr.Attribute; import org.apollo.game.model.entity.attr.AttributeDefinition; import org.apollo.game.model.entity.attr.AttributeMap; import org.apollo.game.model.entity.attr.AttributeType; +import org.apollo.game.model.entity.attr.AttributePersistence; import org.apollo.game.model.inv.Inventory; import org.apollo.io.player.PlayerSaver; import org.apollo.util.NameUtil; @@ -101,7 +102,7 @@ public final class BinaryPlayerSaver implements PlayerSaver { String name = entry.getKey(); AttributeDefinition definition = AttributeMap.getDefinition(name); - if (definition.getPersistence() == AttributeDefinition.Persistence.SERIALIZED) { + if (definition.getPersistence() == AttributePersistence.SERIALIZED) { StreamUtil.writeString(out, name); saveAttribute(out, entry.getValue()); }