mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 02:55:45 +01:00
Add PlayerAnimation waypoint trigger
This commit is contained in:
parent
4a40ef8778
commit
9c7173c284
@ -102,7 +102,6 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
@Override
|
||||
public void begin() {
|
||||
Messaging.sendTr(player, Messages.LINEAR_WAYPOINT_EDITOR_BEGIN);
|
||||
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
||||
}
|
||||
|
||||
private void createWaypointMarker(int index, Waypoint waypoint) {
|
||||
@ -179,6 +178,14 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||
if (!event.getPlayer().equals(player))
|
||||
return;
|
||||
if (event.getMessage().equalsIgnoreCase("triggers")) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
conversation = TriggerEditPrompt.start(player, LinearWaypointEditor.this);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!event.getMessage().equalsIgnoreCase("toggle path"))
|
||||
return;
|
||||
event.setCancelled(true);
|
||||
@ -188,7 +195,7 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
// we need to spawn entities, get back on the main thread.
|
||||
togglePath();
|
||||
}
|
||||
}, 1);
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
|
@ -0,0 +1,41 @@
|
||||
package net.citizensnpcs.trait.waypoint.triggers;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class AnimationTrigger implements WaypointTrigger {
|
||||
@Persist(required = true)
|
||||
private List<PlayerAnimation> animations;
|
||||
|
||||
public AnimationTrigger() {
|
||||
}
|
||||
|
||||
public AnimationTrigger(Collection<PlayerAnimation> collection) {
|
||||
animations = Lists.newArrayList(animations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return String.format("Animation Trigger [animating %s]", Joiner.on(", ").join(animations));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWaypointReached(NPC npc, Location waypoint) {
|
||||
if (npc.getBukkitEntity().getType() != EntityType.PLAYER)
|
||||
return;
|
||||
Player player = (Player) npc.getBukkitEntity();
|
||||
for (PlayerAnimation animation : animations)
|
||||
animation.play(player);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package net.citizensnpcs.trait.waypoint.triggers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.citizensnpcs.util.Messages;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
import net.citizensnpcs.util.PlayerAnimation;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.conversations.StringPrompt;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class AnimationTriggerPrompt extends StringPrompt implements WaypointTriggerPrompt {
|
||||
private final List<PlayerAnimation> animations = Lists.newArrayList();
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(ConversationContext context, String input) {
|
||||
if (input.equalsIgnoreCase("back"))
|
||||
return (Prompt) context.getSessionData("previous");
|
||||
if (input.equalsIgnoreCase("finish")) {
|
||||
context.setSessionData(WaypointTriggerPrompt.CREATED_TRIGGER_KEY,
|
||||
new AnimationTrigger(animations));
|
||||
return (Prompt) context.getSessionData(WaypointTriggerPrompt.RETURN_PROMPT_KEY);
|
||||
}
|
||||
PlayerAnimation animation = Util.matchEnum(PlayerAnimation.values(), input);
|
||||
if (animation == null)
|
||||
Messaging.sendErrorTr((CommandSender) context.getForWhom(), Messages.INVALID_ANIMATION, input,
|
||||
getValidAnimations());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(ConversationContext context) {
|
||||
Messaging.sendTr((CommandSender) context.getForWhom(), Messages.ANIMATION_TRIGGER_PROMPT,
|
||||
getValidAnimations());
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getValidAnimations() {
|
||||
return Joiner.on(", ").join(PlayerAnimation.values());
|
||||
}
|
||||
}
|
@ -49,8 +49,9 @@ public class WaypointTriggerRegistry implements Persister {
|
||||
}
|
||||
|
||||
static {
|
||||
addTrigger("teleport", TeleportTrigger.class, TeleportTriggerPrompt.class);
|
||||
addTrigger("delay", DelayTrigger.class, DelayTriggerPrompt.class);
|
||||
addTrigger("animation", AnimationTrigger.class, AnimationTriggerPrompt.class);
|
||||
addTrigger("chat", ChatTrigger.class, ChatTriggerPrompt.class);
|
||||
addTrigger("delay", DelayTrigger.class, DelayTriggerPrompt.class);
|
||||
addTrigger("teleport", TeleportTrigger.class, TeleportTriggerPrompt.class);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public class Messages {
|
||||
public static final String ANCHOR_ALREADY_EXISTS = "citizens.commands.npc.anchor.already-exists";
|
||||
public static final String ANCHOR_MISSING = "citizens.commands.npc.anchor.missing";
|
||||
public static final String ANCHOR_REMOVED = "citizens.commands.npc.anchor.removed";
|
||||
public static final String ANIMATION_TRIGGER_PROMPT = "citizens.editors.waypoints.triggers.animation.prompt";
|
||||
public static final String AVAILABLE_WAYPOINT_PROVIDERS = "citizens.waypoints.available-providers-header";
|
||||
public static final String BEHAVIOUR_HELP = "citizens.commands.npc.behaviour.help";
|
||||
public static final String BEHAVIOURS_ADDED = "citizens.commands.npc.behaviour.added";
|
||||
@ -77,6 +78,7 @@ public class Messages {
|
||||
public static final String GRAVITY_ENABLED = "citizens.commands.npc.gravity.enabled";
|
||||
public static final String INVALID_AGE = "citizens.commands.npc.age.invalid-age";
|
||||
public static final String INVALID_ANCHOR_NAME = "citizens.commands.npc.anchor.invalid-name";
|
||||
public static final String INVALID_ANIMATION = "citizens.editors.waypoints.triggers.animation.invalid-animation";
|
||||
public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name";
|
||||
public static final String INVALID_PROFESSION = "citizens.commands.npc.profession.invalid-profession";
|
||||
public static final String INVALID_SPAWN_LOCATION = "citizens.commands.npc.create.invalid-location";
|
||||
|
@ -10,6 +10,13 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public enum PlayerAnimation {
|
||||
ARM_SWING {
|
||||
@Override
|
||||
protected void playAnimation(EntityPlayer player, int radius) {
|
||||
Packet18ArmAnimation packet = new Packet18ArmAnimation(player, 1);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
}
|
||||
},
|
||||
HURT {
|
||||
@Override
|
||||
protected void playAnimation(EntityPlayer player, int radius) {
|
||||
@ -47,13 +54,6 @@ public enum PlayerAnimation {
|
||||
sendPacketNearby(new Packet40EntityMetadata(player.id, player.getDataWatcher(), true), player,
|
||||
radius);
|
||||
}
|
||||
},
|
||||
ARM_SWING {
|
||||
@Override
|
||||
protected void playAnimation(EntityPlayer player, int radius) {
|
||||
Packet18ArmAnimation packet = new Packet18ArmAnimation(player, 1);
|
||||
sendPacketNearby(packet, player, radius);
|
||||
}
|
||||
};
|
||||
|
||||
public void play(Player player) {
|
||||
|
@ -174,6 +174,29 @@ public class Translator {
|
||||
|
||||
public static final String PREFIX = "messages";
|
||||
|
||||
private static void createInstance() {
|
||||
Locale locale = Locale.getDefault();
|
||||
String setting = Setting.LOCALE.asString();
|
||||
if (!setting.isEmpty()) {
|
||||
String[] parts = setting.split("[\\._]");
|
||||
switch (parts.length) {
|
||||
case 1:
|
||||
locale = new Locale(parts[0]);
|
||||
break;
|
||||
case 2:
|
||||
locale = new Locale(parts[0], parts[1]);
|
||||
break;
|
||||
case 3:
|
||||
locale = new Locale(parts[0], parts[1], parts[2]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
instance = new Translator(new File(CitizensAPI.getDataFolder(), "lang"), locale);
|
||||
Messaging.logTr(Messages.LOCALE_NOTIFICATION, locale);
|
||||
}
|
||||
|
||||
private static Properties getDefaultBundleProperties() {
|
||||
Properties defaults = new Properties();
|
||||
InputStream in = null;
|
||||
@ -261,27 +284,4 @@ public class Translator {
|
||||
createInstance();
|
||||
return translate(key, instance.defaultLocale, msg);
|
||||
}
|
||||
|
||||
private static void createInstance() {
|
||||
Locale locale = Locale.getDefault();
|
||||
String setting = Setting.LOCALE.asString();
|
||||
if (!setting.isEmpty()) {
|
||||
String[] parts = setting.split("[\\._]");
|
||||
switch (parts.length) {
|
||||
case 1:
|
||||
locale = new Locale(parts[0]);
|
||||
break;
|
||||
case 2:
|
||||
locale = new Locale(parts[0], parts[1]);
|
||||
break;
|
||||
case 3:
|
||||
locale = new Locale(parts[0], parts[1], parts[2]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
instance = new Translator(new File(CitizensAPI.getDataFolder(), "lang"), locale);
|
||||
Messaging.logTr(Messages.LOCALE_NOTIFICATION, locale);
|
||||
}
|
||||
}
|
||||
|
@ -88,22 +88,22 @@ public class Util {
|
||||
return BlockFace.SELF;
|
||||
}
|
||||
|
||||
private static boolean isFacingNorth(double degrees, double leeway) {
|
||||
return (45 - leeway <= degrees) && (degrees < 135 + leeway);
|
||||
}
|
||||
|
||||
private static boolean isFacingWest(double degrees, double leeway) {
|
||||
return ((0 <= degrees) && (degrees < 45 + leeway)) || ((315 - leeway <= degrees) && (degrees <= 360));
|
||||
}
|
||||
|
||||
private static boolean isFacingEast(double degrees, double leeway) {
|
||||
return (135 - leeway <= degrees) && (degrees < 225 + leeway);
|
||||
}
|
||||
|
||||
private static boolean isFacingNorth(double degrees, double leeway) {
|
||||
return (45 - leeway <= degrees) && (degrees < 135 + leeway);
|
||||
}
|
||||
|
||||
private static boolean isFacingSouth(double degrees, double leeway) {
|
||||
return (225 - leeway <= degrees) && (degrees < 315 + leeway);
|
||||
}
|
||||
|
||||
private static boolean isFacingWest(double degrees, double leeway) {
|
||||
return ((0 <= degrees) && (degrees < 45 + leeway)) || ((315 - leeway <= degrees) && (degrees <= 360));
|
||||
}
|
||||
|
||||
public static boolean isSettingFulfilled(Player player, Setting setting) {
|
||||
String parts = setting.asString();
|
||||
if (parts.contains("*"))
|
||||
@ -120,7 +120,12 @@ public class Util {
|
||||
EntityType type = EntityType.fromName(toMatch);
|
||||
if (type != null)
|
||||
return type;
|
||||
for (EntityType check : EntityType.values()) {
|
||||
return matchEnum(EntityType.values(), toMatch);
|
||||
}
|
||||
|
||||
public static <T extends Enum<?>> T matchEnum(T[] values, String toMatch) {
|
||||
T type = null;
|
||||
for (T check : values) {
|
||||
String name = check.name();
|
||||
if (name.matches(toMatch) || name.equalsIgnoreCase(toMatch)
|
||||
|| name.replace("_", "").equalsIgnoreCase(toMatch)
|
||||
|
@ -147,12 +147,14 @@ citizens.editors.waypoints.linear.showing-markers=[[Showing]] waypoint markers.
|
||||
citizens.editors.waypoints.triggers.add.added=<b>[[Added]] waypoint trigger successfully ({0}).
|
||||
citizens.editors.waypoints.triggers.add.invalid-trigger=Couldn''t create a trigger by the name [[{0}]].
|
||||
citizens.editors.waypoints.triggers.add.prompt=Enter in a trigger name to add or type [[back]] to return to the edit prompt. Valid trigger names are {0}.
|
||||
citizens.editors.waypoints.triggers.animation.prompt=Enter in animations to perform - valid animations are {0}.<br>Type in [[finish]] to finish the animation trigger or [[back]] to return to the previous prompt.
|
||||
citizens.editors.waypoints.triggers.animation.invalid-animation=Invalid animation [[{0}]]. Valid animations are {1}.
|
||||
citizens.editors.waypoints.triggers.chat.invalid-radius=The radius must be a number.
|
||||
citizens.editors.waypoints.triggers.chat.missing-radius=No radius supplied.
|
||||
citizens.editors.waypoints.triggers.chat.prompt=Enter in chat lines to say. <br>Type in [[radius (radius)]] to set the block radius to broadcast the messages.<br>Type [[finish]] to finish the chat trigger or [[back]] to return to the previous prompt.
|
||||
citizens.editors.waypoints.triggers.chat.prompt=Enter in chat lines to say.<br>Type in [[radius (radius)]] to set the block radius to broadcast the messages.<br>Type [[finish]] to finish the chat trigger or [[back]] to return to the previous prompt.
|
||||
citizens.editors.waypoints.triggers.delay.prompt=Enter the delay in [[server ticks]] to use. (20 ticks = 1 second)
|
||||
citizens.editors.waypoints.triggers.main.missing-waypoint=Not editing a waypoint.
|
||||
citizens.editors.waypoints.triggers.main.prompt=<b>Entered the waypoint trigger editor.<br> Type [[add]] to begin adding triggers and [[remove]] to remove triggers.<br> Current triggers are:
|
||||
citizens.editors.waypoints.triggers.main.prompt=<b>Entered the waypoint trigger editor.<br> Type [[add]] to begin adding triggers and [[remove]] to remove triggers.<br> Type [[triggers]] to enter the waypoint trigger editor.<br> Current triggers are:
|
||||
citizens.editors.waypoints.triggers.remove.index-out-of-range=Index must be in the range [[1-{0}]].
|
||||
citizens.editors.waypoints.triggers.remove.not-a-number=Index must be a number.
|
||||
citizens.editors.waypoints.triggers.remove.prompt=Enter in the index of the trigger to delete or [[back]] to return to the edit prompt. Current triggers are:
|
||||
|
Loading…
Reference in New Issue
Block a user