Use Persistence API

This commit is contained in:
fullwall 2012-10-08 15:11:49 +08:00
parent 2da1a6d58d
commit 9efc3a5572
6 changed files with 19 additions and 25 deletions

View File

@ -9,7 +9,6 @@ import net.citizensnpcs.command.exception.CommandException;
import net.citizensnpcs.trait.waypoint.Waypoints;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.command.CommandSender;
@ -34,12 +33,12 @@ public class WaypointCommands {
waypoints.describeProviders(sender);
} else
Messaging.sendTr(sender, Messages.CURRENT_WAYPOINT_PROVIDER,
StringHelper.wrap(waypoints.getCurrentProviderName()));
waypoints.getCurrentProviderName());
return;
}
boolean success = waypoints.setWaypointProvider(args.getString(1));
if (!success)
throw new CommandException("Provider not found.");
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, StringHelper.wrap(args.getString(1)));
Messaging.sendTr(sender, Messages.WAYPOINT_PROVIDER_SET, args.getString(1));
}
}

View File

@ -8,6 +8,7 @@ import net.citizensnpcs.api.event.NPCDespawnEvent;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.persistence.PersistenceLoader;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.trait.Spawned;
import net.citizensnpcs.api.util.DataKey;
@ -98,6 +99,7 @@ public abstract class CitizensNPC extends AbstractNPC {
}
try {
trait.load(traitKey);
PersistenceLoader.load(trait, traitKey);
} catch (NPCLoadException ex) {
Messaging.logTr(Messages.TRAIT_LOAD_FAILED, traitKey.name(), getId());
}
@ -121,7 +123,9 @@ public abstract class CitizensNPC extends AbstractNPC {
// Save all existing traits
for (Trait trait : traits.values()) {
trait.save(root.getRelative("traits." + trait.getName()));
DataKey traitKey = root.getRelative("traits." + trait.getName());
trait.save(traitKey);
PersistenceLoader.save(trait, traitKey);
}
}

View File

@ -116,10 +116,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
navigation.e();
moveOnCurrentHeading();
} else if (!npc.getNavigator().isNavigating() && (motX != 0 || motZ != 0 || motY != 0)) {
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
motX = motY = motZ = 0;
} else
e(0, 0); // is this necessary? it does gravity/controllable but
e(0, 0); // is this necessary? it does gravity/controllable but
// sometimes players sink into the ground
}
if (noDamageTicks > 0)
@ -169,9 +166,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
motY = 0.6;
bE = 10;
}
} else {
} else
bE = 0;
}
br *= 0.98F;
bs *= 0.98F;
bt *= 0.9F;
@ -183,7 +180,5 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
as = yaw; // update head yaw to match entity yaw
}
private static final float EPSILON = 0.001F;
private static final float STEP_HEIGHT = 1F;
}

View File

@ -5,7 +5,6 @@ import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Ageable;
@ -19,8 +18,7 @@ public class Age extends Trait implements Toggleable {
}
public void describe(CommandSender sender) {
Messaging.sendTr(sender, Messages.AGE_TRAIT_DESCRIPTION, StringHelper.wrap(npc.getName()),
StringHelper.wrap(age), StringHelper.wrap(locked));
Messaging.sendTr(sender, Messages.AGE_TRAIT_DESCRIPTION, npc.getName(), age, locked);
}
private boolean isAgeable() {

View File

@ -19,7 +19,6 @@ import net.citizensnpcs.editor.Editor;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Messaging;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.StringHelper;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -146,7 +145,7 @@ public class LinearWaypointProvider implements WaypointProvider {
}
private String formatLoc(Location location) {
return String.format("<e>%d<a>, <e>%d<a>, <e>%d<a>", location.getBlockX(), location.getBlockY(),
return String.format("[[%d]], [[%d]], [[%d]]", location.getBlockX(), location.getBlockY(),
location.getBlockZ());
}
@ -205,8 +204,7 @@ public class LinearWaypointProvider implements WaypointProvider {
double maxDistance = Math.pow(npc.getNavigator().getDefaultParameters().range(), 2);
if (distance > maxDistance) {
Messaging.sendErrorTr(player, Messages.LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED,
StringHelper.wrap(Math.sqrt(distance), ChatColor.RED),
StringHelper.wrap(Math.sqrt(maxDistance), ChatColor.RED));
Math.sqrt(distance), Math.sqrt(maxDistance), ChatColor.RED);
return;
}
}
@ -216,8 +214,8 @@ public class LinearWaypointProvider implements WaypointProvider {
if (showPath)
createWaypointMarker(editingSlot, element);
editingSlot = Math.min(editingSlot + 1, waypoints.size());
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, editingSlot + 1,
waypoints.size());
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at),
editingSlot + 1, waypoints.size());
} else if (waypoints.size() > 0) {
event.setCancelled(true);
editingSlot = Math.min(0, Math.max(waypoints.size() - 1, editingSlot));

View File

@ -141,7 +141,7 @@ citizens.notifications.locale=Using locale {0}.
citizens.notifications.metrics-load-error=Unable to start metrics: {0}.
citizens.notifications.metrics-started=Metrics started.
citizens.notifications.missing-translations=Missing translations file for locale {0}. Defaulting to en locale.
citizens.notifications.npc-name-not-found=Could not find a name for ID '{0}'.
citizens.notifications.npc-name-not-found=Could not find a name for ID {0}.
citizens.notifications.npc-not-found=No NPC could be found.
citizens.notifications.npcs-loaded=Loaded {0} NPCs ({1} spawned).
citizens.notifications.reloaded=Citizens reloaded.
@ -157,7 +157,7 @@ citizens.saves.load-failed=Unable to load saves, disabling...
citizens.settings.writing-default=Writing default setting: '{0}'
citizens.sub-plugins.error-on-load={0} initializing {1}
citizens.sub-plugins.load=Loading {0}
citizens.traits.age-description={0}'s age is {1}. Locked is {2}.
citizens.traits.age-description={0}'s age is [[{1}]]. Locked is [[{2}]].
citizens.waypoints.available-providers-header=<b>List of available providers
citizens.waypoints.current-provider=The current waypoint provider is {0}.
citizens.waypoints.set-provider=Set the waypoint provider to {0}.
citizens.waypoints.current-provider=The current waypoint provider is [[{0}]].
citizens.waypoints.set-provider=Set the waypoint provider to [[{0}]].