mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-05 02:10:10 +01:00
Use Persistence API
This commit is contained in:
parent
2da1a6d58d
commit
9efc3a5572
@ -9,7 +9,6 @@ import net.citizensnpcs.command.exception.CommandException;
|
|||||||
import net.citizensnpcs.trait.waypoint.Waypoints;
|
import net.citizensnpcs.trait.waypoint.Waypoints;
|
||||||
import net.citizensnpcs.util.Messages;
|
import net.citizensnpcs.util.Messages;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
@ -34,12 +33,12 @@ public class WaypointCommands {
|
|||||||
waypoints.describeProviders(sender);
|
waypoints.describeProviders(sender);
|
||||||
} else
|
} else
|
||||||
Messaging.sendTr(sender, Messages.CURRENT_WAYPOINT_PROVIDER,
|
Messaging.sendTr(sender, Messages.CURRENT_WAYPOINT_PROVIDER,
|
||||||
StringHelper.wrap(waypoints.getCurrentProviderName()));
|
waypoints.getCurrentProviderName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean success = waypoints.setWaypointProvider(args.getString(1));
|
boolean success = waypoints.setWaypointProvider(args.getString(1));
|
||||||
if (!success)
|
if (!success)
|
||||||
throw new CommandException("Provider not found.");
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import net.citizensnpcs.api.event.NPCDespawnEvent;
|
|||||||
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
import net.citizensnpcs.api.event.NPCSpawnEvent;
|
||||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||||
import net.citizensnpcs.api.npc.AbstractNPC;
|
import net.citizensnpcs.api.npc.AbstractNPC;
|
||||||
|
import net.citizensnpcs.api.persistence.PersistenceLoader;
|
||||||
import net.citizensnpcs.api.trait.Trait;
|
import net.citizensnpcs.api.trait.Trait;
|
||||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||||
import net.citizensnpcs.api.util.DataKey;
|
import net.citizensnpcs.api.util.DataKey;
|
||||||
@ -98,6 +99,7 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
trait.load(traitKey);
|
trait.load(traitKey);
|
||||||
|
PersistenceLoader.load(trait, traitKey);
|
||||||
} catch (NPCLoadException ex) {
|
} catch (NPCLoadException ex) {
|
||||||
Messaging.logTr(Messages.TRAIT_LOAD_FAILED, traitKey.name(), getId());
|
Messaging.logTr(Messages.TRAIT_LOAD_FAILED, traitKey.name(), getId());
|
||||||
}
|
}
|
||||||
@ -121,7 +123,9 @@ public abstract class CitizensNPC extends AbstractNPC {
|
|||||||
|
|
||||||
// Save all existing traits
|
// Save all existing traits
|
||||||
for (Trait trait : traits.values()) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,10 +116,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
navigation.e();
|
navigation.e();
|
||||||
moveOnCurrentHeading();
|
moveOnCurrentHeading();
|
||||||
} else if (!npc.getNavigator().isNavigating() && (motX != 0 || motZ != 0 || motY != 0)) {
|
} else if (!npc.getNavigator().isNavigating() && (motX != 0 || motZ != 0 || motY != 0)) {
|
||||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
e(0, 0); // is this necessary? it does gravity/controllable but
|
||||||
motX = motY = motZ = 0;
|
|
||||||
} else
|
|
||||||
e(0, 0); // is this necessary? it does gravity/controllable but
|
|
||||||
// sometimes players sink into the ground
|
// sometimes players sink into the ground
|
||||||
}
|
}
|
||||||
if (noDamageTicks > 0)
|
if (noDamageTicks > 0)
|
||||||
@ -169,9 +166,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
motY = 0.6;
|
motY = 0.6;
|
||||||
bE = 10;
|
bE = 10;
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
bE = 0;
|
bE = 0;
|
||||||
}
|
|
||||||
br *= 0.98F;
|
br *= 0.98F;
|
||||||
bs *= 0.98F;
|
bs *= 0.98F;
|
||||||
bt *= 0.9F;
|
bt *= 0.9F;
|
||||||
@ -183,7 +180,5 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder {
|
|||||||
as = yaw; // update head yaw to match entity yaw
|
as = yaw; // update head yaw to match entity yaw
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final float EPSILON = 0.001F;
|
|
||||||
|
|
||||||
private static final float STEP_HEIGHT = 1F;
|
private static final float STEP_HEIGHT = 1F;
|
||||||
}
|
}
|
@ -5,7 +5,6 @@ import net.citizensnpcs.api.trait.Trait;
|
|||||||
import net.citizensnpcs.api.util.DataKey;
|
import net.citizensnpcs.api.util.DataKey;
|
||||||
import net.citizensnpcs.util.Messages;
|
import net.citizensnpcs.util.Messages;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.Ageable;
|
||||||
@ -19,8 +18,7 @@ public class Age extends Trait implements Toggleable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void describe(CommandSender sender) {
|
public void describe(CommandSender sender) {
|
||||||
Messaging.sendTr(sender, Messages.AGE_TRAIT_DESCRIPTION, StringHelper.wrap(npc.getName()),
|
Messaging.sendTr(sender, Messages.AGE_TRAIT_DESCRIPTION, npc.getName(), age, locked);
|
||||||
StringHelper.wrap(age), StringHelper.wrap(locked));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAgeable() {
|
private boolean isAgeable() {
|
||||||
|
@ -19,7 +19,6 @@ import net.citizensnpcs.editor.Editor;
|
|||||||
import net.citizensnpcs.util.Messages;
|
import net.citizensnpcs.util.Messages;
|
||||||
import net.citizensnpcs.util.Messaging;
|
import net.citizensnpcs.util.Messaging;
|
||||||
import net.citizensnpcs.util.NMS;
|
import net.citizensnpcs.util.NMS;
|
||||||
import net.citizensnpcs.util.StringHelper;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -146,7 +145,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String formatLoc(Location location) {
|
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());
|
location.getBlockZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +204,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
double maxDistance = Math.pow(npc.getNavigator().getDefaultParameters().range(), 2);
|
double maxDistance = Math.pow(npc.getNavigator().getDefaultParameters().range(), 2);
|
||||||
if (distance > maxDistance) {
|
if (distance > maxDistance) {
|
||||||
Messaging.sendErrorTr(player, Messages.LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED,
|
Messaging.sendErrorTr(player, Messages.LINEAR_WAYPOINT_EDITOR_RANGE_EXCEEDED,
|
||||||
StringHelper.wrap(Math.sqrt(distance), ChatColor.RED),
|
Math.sqrt(distance), Math.sqrt(maxDistance), ChatColor.RED);
|
||||||
StringHelper.wrap(Math.sqrt(maxDistance), ChatColor.RED));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,8 +214,8 @@ public class LinearWaypointProvider implements WaypointProvider {
|
|||||||
if (showPath)
|
if (showPath)
|
||||||
createWaypointMarker(editingSlot, element);
|
createWaypointMarker(editingSlot, element);
|
||||||
editingSlot = Math.min(editingSlot + 1, waypoints.size());
|
editingSlot = Math.min(editingSlot + 1, waypoints.size());
|
||||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, editingSlot + 1,
|
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_ADDED_WAYPOINT, formatLoc(at),
|
||||||
waypoints.size());
|
editingSlot + 1, waypoints.size());
|
||||||
} else if (waypoints.size() > 0) {
|
} else if (waypoints.size() > 0) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
editingSlot = Math.min(0, Math.max(waypoints.size() - 1, editingSlot));
|
editingSlot = Math.min(0, Math.max(waypoints.size() - 1, editingSlot));
|
||||||
|
@ -141,7 +141,7 @@ citizens.notifications.locale=Using locale {0}.
|
|||||||
citizens.notifications.metrics-load-error=Unable to start metrics: {0}.
|
citizens.notifications.metrics-load-error=Unable to start metrics: {0}.
|
||||||
citizens.notifications.metrics-started=Metrics started.
|
citizens.notifications.metrics-started=Metrics started.
|
||||||
citizens.notifications.missing-translations=Missing translations file for locale {0}. Defaulting to en locale.
|
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.npc-not-found=No NPC could be found.
|
||||||
citizens.notifications.npcs-loaded=Loaded {0} NPCs ({1} spawned).
|
citizens.notifications.npcs-loaded=Loaded {0} NPCs ({1} spawned).
|
||||||
citizens.notifications.reloaded=Citizens reloaded.
|
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.settings.writing-default=Writing default setting: '{0}'
|
||||||
citizens.sub-plugins.error-on-load={0} initializing {1}
|
citizens.sub-plugins.error-on-load={0} initializing {1}
|
||||||
citizens.sub-plugins.load=Loading {0}
|
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.available-providers-header=<b>List of available providers
|
||||||
citizens.waypoints.current-provider=The current waypoint provider is {0}.
|
citizens.waypoints.current-provider=The current waypoint provider is [[{0}]].
|
||||||
citizens.waypoints.set-provider=Set the waypoint provider to {0}.
|
citizens.waypoints.set-provider=Set the waypoint provider to [[{0}]].
|
Loading…
Reference in New Issue
Block a user