Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commands and translations overhaul #105

Merged
merged 100 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
ce33d6e
improve output messages in majority of commands (still wip)
Grabsky Mar 8, 2024
30f1576
command: /fancynpcs (untested)
Grabsky Mar 30, 2024
77180a7
fix translation key in /fancynpcs command
Grabsky Apr 2, 2024
3f0632a
command: /npc attribute
Grabsky Apr 2, 2024
4eb5186
Merge branch 'main' into feature/lang-v2
Grabsky Apr 2, 2024
672a329
colors
Grabsky Apr 2, 2024
7d0db92
use correct translation key in /npc attribute command
Grabsky Apr 4, 2024
dedeca0
FancyLib 1.0.14
Grabsky Apr 4, 2024
27b09c5
FancyLib 1.0.15
Grabsky Apr 6, 2024
4efdaf5
FancyLib 1.0.16
Grabsky Apr 6, 2024
5600011
FancyLib 1.0.17
Grabsky Apr 6, 2024
10fbe9d
FancyLib 1.0.18
Grabsky Apr 6, 2024
0320837
/npc help
Grabsky Apr 6, 2024
908c288
command_wrong_usage, command_missing_permissions, command_player_only
Grabsky Apr 6, 2024
4ee68b3
fix /fancynpcs reload (temporarily)
Grabsky Apr 6, 2024
146cd53
/npc collidable
Grabsky Apr 6, 2024
66d7d91
/npc copy
Grabsky Apr 6, 2024
d265b24
/npc create
Grabsky Apr 6, 2024
490aa79
fix /npc copy placeholders
Grabsky Apr 7, 2024
e3ce097
command_incomplete_usage
Grabsky Apr 7, 2024
e6f4d13
/npc displayname
Grabsky Apr 7, 2024
4de865d
fix brackets
Grabsky Apr 7, 2024
a1cd286
/npc equipment
Grabsky Apr 7, 2024
a34d2ac
/npc fix
Grabsky Apr 7, 2024
ffbc068
/npc glowingColor
Grabsky Apr 7, 2024
c841718
tweak default colors
Grabsky Apr 7, 2024
4838059
/npc glowing
Grabsky Apr 7, 2024
1d8f1fa
fix /npc glowingColor
Grabsky Apr 7, 2024
4f1fc81
/npc interactionCooldown
Grabsky Apr 7, 2024
9cd0290
/npc mirrorSkin
Grabsky Apr 7, 2024
2815d26
/npc moveHere
Grabsky Apr 7, 2024
93e0f83
/npc remove
Grabsky Apr 7, 2024
195fcda
/npc showInTab
Grabsky Apr 8, 2024
c491eff
FancyLib 1.0.19
Grabsky Apr 8, 2024
3c1d769
FancyLib 1.0.20
Grabsky Apr 9, 2024
3da3495
/npc info
Grabsky Apr 9, 2024
3f591cc
remove unused placeholders
Grabsky Apr 9, 2024
9d63934
/npc turnToPlayer
Grabsky Apr 9, 2024
0d20b8f
/npc teleport
Grabsky Apr 9, 2024
3925df7
cloud commands base
Grabsky Apr 18, 2024
6c449c0
port majority of commands
Grabsky Apr 28, 2024
f97e065
more
Grabsky Apr 30, 2024
e2bcc2d
Merge branch 'refs/heads/main' into feature/commands-v2
Grabsky Apr 30, 2024
0bed9a3
port /fancynpcs
Grabsky Apr 30, 2024
d29880a
half-baked `/npc message` command
Grabsky May 4, 2024
6a55f87
fix `npc_attribute_set` color
Grabsky May 4, 2024
dbaf665
stricter regex for new NPC names
Grabsky May 4, 2024
aeada4a
temp fix for default flag values
Grabsky May 4, 2024
66ed094
allow uuid in npc argument
Grabsky May 4, 2024
1fdf912
extract GlowingColor enum, minor tweak to formatting
Grabsky May 4, 2024
2c2da02
Merge branch 'refs/heads/main' into feature/commands-v2
Grabsky May 7, 2024
db445f8
Merge branch 'refs/heads/main' into feature/commands-v2
Grabsky May 7, 2024
6c3ebd4
tweak `/npc info` format
Grabsky May 7, 2024
f4d062e
use snapshot version of cloud
Grabsky May 7, 2024
7cc28ff
complete `/npc message` command (hopefully)
Grabsky May 7, 2024
cba20ea
add missing context aware completions for `/npc message`
Grabsky May 7, 2024
a6b1c15
update regex matching in `/npc copy`
Grabsky May 8, 2024
a388466
use `@none` as an addition to `<empty>` in `/npc displayname`, split …
Grabsky May 8, 2024
95c0dbd
small message format changes
Grabsky May 8, 2024
59579a1
more sensible comments for `NpcArgument`
Grabsky May 8, 2024
c676bd3
remove notes regarding `@Default` annotation
Grabsky May 8, 2024
911ff91
add missing error message when creating npc and no world has been spe…
Grabsky May 8, 2024
fe51a4c
make `/npc list` and `/npc nearby` look better
Grabsky May 8, 2024
149889f
fix comments and translations for `/npc message`
Grabsky May 9, 2024
e10e397
add `/npc player_command`
Grabsky May 9, 2024
e2a1f84
`/npc attribute` and `/npc equipment`
Grabsky May 10, 2024
fe08e4a
cloud 2.0.0-rc.1
Grabsky May 14, 2024
d1a5497
FancyLib 1.0.22
Grabsky May 14, 2024
e7b6f2e
suggest relative coords and target location for `Location` argument
Grabsky May 15, 2024
6f87ca2
add `cloud-annotations` annotation processor
Grabsky May 15, 2024
f7efd5a
small clean-up for `/npc collidable` and `/npc glowing`
Grabsky May 15, 2024
e361224
clean-up all commands (once more) and add context-aware syntax except…
Grabsky May 15, 2024
ffe4c33
fix colors in some syntax messages
Grabsky May 15, 2024
32b86aa
Merge branch 'refs/heads/main' into feature/commands-v2
Grabsky May 15, 2024
9a354cc
Merge branch 'refs/heads/main' into feature/commands-v2
Grabsky May 15, 2024
43bdfa6
Add multiple server commands
OliverSchlueter May 15, 2024
accc889
show total number of entries in list footers
Grabsky May 15, 2024
2dda60a
add `--look-in-my-direction` presence flag to `/npc move_to`
Grabsky May 15, 2024
690304a
sort locale, add comments, add `FancyNpcsPlugin#getTranslator`, repla…
Grabsky May 15, 2024
67b09ea
configurable language
Grabsky May 15, 2024
aaad75c
suggest command names for `player_command` and `server_command` sub-c…
Grabsky May 16, 2024
de9c10e
improve `interaction_cooldown` sub-command
Grabsky May 16, 2024
cd174cb
fix import
Grabsky May 16, 2024
cc148c9
format interaction cooldown in `info` sub-command
Grabsky May 16, 2024
32d3bd5
add missing and improve existing exception handlers
Grabsky May 17, 2024
69ef3d4
minor `skin` sub-command changes
Grabsky May 17, 2024
96854b8
additional completions for `interaction_cooldown` sub-command
Grabsky May 17, 2024
eb136ba
remove days, months and years from suggestions for interval argument …
Grabsky May 17, 2024
772d851
migrate all remaining usages of MessageHelper to Translator
Grabsky May 17, 2024
2c4e7b9
small refactor of GlowingColor
Grabsky May 17, 2024
d497c67
improve `feature_flags` sub-command format
Grabsky May 17, 2024
23f6ef6
minor code refactor
Grabsky May 17, 2024
a648928
rename NpcHelpCMD to HelpCMD
Grabsky May 17, 2024
16b16ac
fix `shown_in_tab` not updating
Grabsky May 17, 2024
881412b
more tweaks and fixes
Grabsky May 19, 2024
8027959
some help stuff (not finished)
Grabsky May 19, 2024
2c31827
fix help pagination, add remaining help entries
Grabsky May 20, 2024
80903ac
fix help pagination (again)
Grabsky May 20, 2024
de8bfe8
FancyLib 1.0.24, use release versions of cloud instead of snapshots
Grabsky May 23, 2024
afc64ad
remove snapshot repo
Grabsky May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.oliver.fancynpcs.api;

import de.oliver.fancylib.LanguageConfig;
import de.oliver.fancylib.serverSoftware.schedulers.FancyScheduler;
import de.oliver.fancylib.translations.Translator;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -32,5 +32,5 @@ static FancyNpcsPlugin get() {

AttributeManager getAttributeManager();

LanguageConfig getLanguageConfig();
Translator getTranslator();
}
31 changes: 12 additions & 19 deletions api/src/main/java/de/oliver/fancynpcs/api/Npc.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import de.oliver.fancylib.LanguageConfig;
import de.oliver.fancylib.MessageHelper;
import de.oliver.fancylib.RandomUtils;
import de.oliver.fancylib.translations.Translator;
import de.oliver.fancynpcs.api.events.NpcInteractEvent;
import de.oliver.fancynpcs.api.events.NpcInteractEvent.InteractionType;
import de.oliver.fancynpcs.api.util.Interval;
import de.oliver.fancynpcs.api.util.Interval.Unit;
import me.dave.chatcolorhandler.ChatColorHandler;
import me.dave.chatcolorhandler.ModernChatColorHandler;
import me.dave.chatcolorhandler.parsers.custom.PlaceholderAPIParser;
Expand All @@ -16,7 +17,6 @@
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;
import java.util.Random;
Expand All @@ -26,13 +26,12 @@
public abstract class Npc {

private static final NpcAttribute INVISIBLE_ATTRIBUTE = FancyNpcsPlugin.get().getAttributeManager().getAttributeByName(EntityType.PLAYER, "invisible");
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("##.##");
private static final char[] localNameChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'k', 'l', 'm', 'n', 'o', 'r'};
protected final Map<UUID, Boolean> isTeamCreated = new ConcurrentHashMap<>();
protected final Map<UUID, Boolean> isVisibleForPlayer = new ConcurrentHashMap<>();
protected final Map<UUID, Boolean> isLookingAtPlayer = new ConcurrentHashMap<>();
protected final Map<UUID, Long> lastPlayerInteraction = new ConcurrentHashMap<>();
private final LanguageConfig lang = FancyNpcsPlugin.get().getLanguageConfig();
private final Translator translator = FancyNpcsPlugin.get().getTranslator();
protected NpcData data;
protected boolean saveToFile;

Expand Down Expand Up @@ -150,22 +149,17 @@ public void interact(Player player) {

public void interact(Player player, InteractionType interactionType) {
if (data.getInteractionCooldown() > 0) {
if (lastPlayerInteraction.containsKey(player.getUniqueId())) {
long nextAllowedInteraction = lastPlayerInteraction.get(player.getUniqueId()) + Math.round(data.getInteractionCooldown() * 1000L);
if (nextAllowedInteraction > System.currentTimeMillis()) {
if (!FancyNpcsPlugin.get().getFancyNpcConfig().isInteractionCooldownMessageDisabled()) {
float timeLeft = (nextAllowedInteraction - System.currentTimeMillis()) / 1000F;
String cooldownMessage = lang.get("on-interaction-cooldown", "time", DECIMAL_FORMAT.format(timeLeft));
MessageHelper.warning(player, cooldownMessage);
}
return;
}
final long interactionCooldownMillis = (long) (data.getInteractionCooldown() * 1000);
final long lastInteractionMillis = lastPlayerInteraction.getOrDefault(player.getUniqueId(), 0L);
final Interval interactionCooldownLeft = Interval.between(lastInteractionMillis + interactionCooldownMillis, System.currentTimeMillis(), Unit.MILLISECONDS);
if (interactionCooldownLeft.as(Unit.MILLISECONDS) > 0 && !FancyNpcsPlugin.get().getFancyNpcConfig().isInteractionCooldownMessageDisabled()) {
translator.translate("interaction_on_cooldown").replace("time", interactionCooldownLeft.toString()).send(player);
return;
}

lastPlayerInteraction.put(player.getUniqueId(), System.currentTimeMillis());
}

NpcInteractEvent npcInteractEvent = new NpcInteractEvent(this, data.getPlayerCommands(), data.getServerCommand(), data.getOnClick(), player, interactionType);
NpcInteractEvent npcInteractEvent = new NpcInteractEvent(this, data.getPlayerCommands(), data.getServerCommands(), data.getOnClick(), player, interactionType);
npcInteractEvent.callEvent();

if (npcInteractEvent.isCancelled()) {
Expand All @@ -190,8 +184,7 @@ public void interact(Player player, InteractionType interactionType) {
}

// serverCommand
if (data.getServerCommand() != null && data.getServerCommand().length() > 0) {
String command = data.getServerCommand();
for (String command : data.getServerCommands()) {
command = command.replace("{player}", player.getName());

String finalCommand = ChatColorHandler.translate(command, player, List.of(PlaceholderAPIParser.class));
Expand Down
25 changes: 18 additions & 7 deletions api/src/main/java/de/oliver/fancynpcs/api/NpcData.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class NpcData {
private Map<NpcEquipmentSlot, ItemStack> equipment;
private Consumer<Player> onClick;
private boolean turnToPlayer;
private String serverCommand;
private List<String> playerCommands;
private List<String> serverCommands;
private List<String> messages;
private boolean sendMessagesRandomly;
private float interactionCooldown;
Expand All @@ -55,7 +55,7 @@ public NpcData(
Consumer<Player> onClick,
List<String> messages,
boolean sendMessagesRandomly,
String serverCommand,
List<String> serverCommands,
List<String> playerCommands,
float interactionCooldown,
Map<NpcAttribute, String> attributes,
Expand All @@ -76,7 +76,7 @@ public NpcData(
this.equipment = equipment;
this.onClick = onClick;
this.turnToPlayer = turnToPlayer;
this.serverCommand = serverCommand;
this.serverCommands = serverCommands;
this.playerCommands = playerCommands;
this.messages = messages;
this.sendMessagesRandomly = sendMessagesRandomly;
Expand Down Expand Up @@ -105,6 +105,7 @@ public NpcData(String name, UUID creator, Location location) {
};
this.turnToPlayer = false;
this.messages = new ArrayList<>();
this.serverCommands = new ArrayList<>();
this.playerCommands = new ArrayList<>();
this.sendMessagesRandomly = false;
this.interactionCooldown = 0;
Expand Down Expand Up @@ -253,16 +254,26 @@ public NpcData setTurnToPlayer(boolean turnToPlayer) {
return this;
}

public String getServerCommand() {
return serverCommand;
public List<String> getServerCommands() {
return serverCommands;
}

public NpcData setServerCommand(String serverCommand) {
this.serverCommand = serverCommand;
public NpcData setServerCommands(List<String> serverCommands) {
this.serverCommands = serverCommands;
isDirty = true;
return this;
}

public void addServerCommand(String command) {
serverCommands.add(command);
isDirty = true;
}

public void removeServerCommand(int index) {
serverCommands.remove(index);
isDirty = true;
}

public List<String> getPlayerCommands() {
return playerCommands;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.function.Consumer;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Is fired when a player interacts with a NPC
*/
Expand All @@ -23,18 +22,18 @@ public class NpcInteractEvent extends Event implements Cancellable {
@Nullable
private final List<String> playerCommands;
@Nullable
private final String serverCommand;
private final List<String> serverCommands;
@NotNull
private final Consumer<Player> onClick;
@NotNull
private final Player player;
private final InteractionType interactionType;
private boolean isCancelled;

public NpcInteractEvent(@NotNull Npc npc, @Nullable List<String> playerCommands, @Nullable String serverCommand, @NotNull Consumer<Player> onClick, @NotNull Player player, @NotNull InteractionType interactionType) {
public NpcInteractEvent(@NotNull Npc npc, @Nullable List<String> playerCommands, @Nullable List<String> serverCommands, @NotNull Consumer<Player> onClick, @NotNull Player player, @NotNull InteractionType interactionType) {
this.npc = npc;
this.playerCommands = playerCommands;
this.serverCommand = serverCommand;
this.serverCommands = serverCommands;
this.onClick = onClick;
this.player = player;
this.interactionType = interactionType;
Expand All @@ -59,10 +58,10 @@ public static HandlerList getHandlerList() {
}

/**
* @return the command that the server will run
* @return the commands that the server will run
*/
public @Nullable String getServerCommand() {
return serverCommand;
public @Nullable List<String> getServerCommands() {
return serverCommands;
}

/**
Expand Down Expand Up @@ -104,7 +103,9 @@ public void setCancelled(boolean cancel) {
public enum InteractionType {
LEFT_CLICK,
RIGHT_CLICK,
/** {@link InteractionType#CUSTOM InteractionType#CUSTOM} represents interactions invoked by the API. */
/**
* {@link InteractionType#CUSTOM InteractionType#CUSTOM} represents interactions invoked by the API.
*/
CUSTOM
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,38 @@ public void setCancelled(boolean cancel) {
}

public enum NpcModification {
LOCATION,
SKIN,
ATTRIBUTE,
COLLIDABLE,
DISPLAY_NAME,
EQUIPMENT,
SERVER_COMMAND,
PLAYER_COMMAND,
SHOW_IN_TAB,
GLOWING,
GLOWING_COLOR,
TURN_TO_PLAYER,
CUSTOM_MESSAGE,
TYPE,
ATTRIBUTE,
COLLIDABLE,
INTERACTION_COOLDOWN,
LOCATION,
MIRROR_SKIN,
PLAYER_COMMAND,
SERVER_COMMAND,
SHOW_IN_TAB,
SKIN,
TURN_TO_PLAYER,
TYPE,
// Messages.
MESSAGE_ADD,
MESSAGE_SET,
MESSAGE_REMOVE,
MESSAGE_CLEAR,
MESSAGE_SEND_RANDOMLY,
// Player commands.
PLAYER_COMMAND_ADD,
PLAYER_COMMAND_SET,
PLAYER_COMMAND_REMOVE,
PLAYER_COMMAND_CLEAR,
PLAYER_COMMAND_SEND_RANDOMLY,
// Server commands.
SERVER_COMMAND_ADD,
SERVER_COMMAND_SET,
SERVER_COMMAND_REMOVE,
SERVER_COMMAND_CLEAR,
SERVER_COMMAND_SEND_RANDOMLY
}
}
Loading