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

We're going on an Adventure! #4717

Merged
merged 129 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
28d562e
Fix bstats *still* being transitive
JRoy Dec 26, 2021
c1af477
Add support for per-player-locale and MiniMessage
JRoy Dec 28, 2021
aade96c
Begin per-player-locale conversion
JRoy Dec 28, 2021
d4e9f57
Prevent all locales from falling back to English
JRoy Dec 28, 2021
54617e2
zml woke up
JRoy Dec 28, 2021
2ffeb00
Bump adventure, moar debug
JRoy Dec 28, 2021
aafaf94
Bump run-paper
JRoy Dec 28, 2021
17709e2
Fix audiences not working
JRoy Dec 28, 2021
2f38558
i hate this i hate this i hate this i hate this i hate this i hate th…
JRoy Dec 28, 2021
14c532f
get out of my head get out of my head get out of my head get out of m…
JRoy Dec 28, 2021
3d78dfe
Move MiniMessage prefix to constant
JRoy Dec 29, 2021
66e5977
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Dec 29, 2021
07f9320
Actually support TranslatableException in EssentialsCommand#showError
JRoy Dec 29, 2021
cd8c8df
Give CommandSource an Essentials instance on creation
JRoy Dec 29, 2021
90103ba
Bump checkstyle
JRoy Dec 29, 2021
3f69809
i want to die i want to die i want to die i want to die i want to die…
JRoy Dec 29, 2021
cbcce93
Revert "Bump checkstyle"
JRoy Dec 29, 2021
63b5974
some progress or whatever
JRoy Dec 30, 2021
771831e
Use adventure HSVLike in DownsampleUtil
JRoy Dec 30, 2021
0252b01
The main module compiles
JRoy Dec 30, 2021
d0bc567
AntiBuild converted
JRoy Dec 30, 2021
c32e8b9
Chat converted
JRoy Dec 30, 2021
d60e52e
Discord converted
JRoy Dec 30, 2021
1243f9d
GeoIP converted
JRoy Dec 30, 2021
686f32f
Protect converted
JRoy Dec 30, 2021
7cd9fa2
Spawn converted
JRoy Dec 30, 2021
e718595
XMPP converted lmfao
JRoy Dec 30, 2021
f2ffa84
tests converted
JRoy Dec 30, 2021
59a1502
begone old method
JRoy Dec 30, 2021
c13ac29
Fix missing check for broadcasting afk messages
JRoy Jan 3, 2022
3305d40
Don't send messages which yield an empty translation
JRoy Jan 3, 2022
0372302
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jan 20, 2022
9aadaaa
Fix compile errors
JRoy Jan 20, 2022
f0659b3
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Feb 1, 2022
f155465
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Feb 13, 2022
007d9a4
Adventure don't rename method for more than a day challenge [IMPOSSIBLE]
JRoy Feb 13, 2022
f479621
Remove class deprecation suppression for User
JRoy Feb 13, 2022
ec8ee7e
Remove some whitespace
JRoy Feb 13, 2022
7435ada
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Feb 22, 2022
725ff91
Adventure 4.10.0
JRoy Feb 28, 2022
be9676d
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Mar 5, 2022
04a1dea
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Mar 23, 2022
48c8a0d
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy May 23, 2022
4354c65
Update adventure
JRoy May 23, 2022
459c535
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jun 10, 2022
d31f7fd
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jun 17, 2022
fc75042
Fix build
JRoy Jun 17, 2022
606ac55
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jun 27, 2022
370ce8f
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jul 5, 2022
ddf84f6
Update adventure
JRoy Jul 7, 2022
63b10b5
Merge remote-tracking branch 'upstream/refactor/we-are-going-on-an-ad…
JRoy Jul 7, 2022
c505746
Fix usage of non-initialised logger in handleCrash
mdcfe Jul 10, 2022
7a452c6
Prevent relocation of Paper native adventure usage
mdcfe Jul 10, 2022
e30871e
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jul 11, 2022
bfa4a58
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Jul 23, 2022
119797c
Use the kezz magic character so we're allowed to escape tags
JRoy Jul 26, 2022
d16ded0
Add support for minimessage in mails
JRoy Jul 26, 2022
c84f02b
Fix hex color support in mini message
JRoy Jul 26, 2022
af2b755
Fix some oops
JRoy Jul 27, 2022
fb8ccca
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Aug 2, 2022
3d844d2
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Aug 12, 2022
6b2b6c9
Update latest to adventure
JRoy Aug 12, 2022
ff16484
lmfao
JRoy Aug 13, 2022
cea2406
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Aug 17, 2022
956acc7
Fix nullability issues
JRoy Aug 17, 2022
9b6db3d
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Aug 19, 2022
9cd6d9e
Load resource bundles off the main thread
JRoy Aug 20, 2022
12d1701
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Aug 22, 2022
48333e0
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Oct 13, 2022
71fff3c
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Dec 26, 2022
b7d6a1b
Update link module to adventure
JRoy Dec 26, 2022
4239c09
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Feb 6, 2023
d2d31bd
md has a small monitor
JRoy Mar 7, 2023
4471d09
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Mar 7, 2023
1356cd9
with this commit we fix compatability with a staggering 1% of users
JRoy Mar 8, 2023
56a90ab
Bump adventure to 4.12.0 and platform to 4.2.0
mdcfe Mar 12, 2023
8767548
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
mdcfe Mar 17, 2023
421952b
Update adventure for 1.19.4
mdcfe Mar 17, 2023
b866f82
Fix wrong broadcast method being used in /sucicide
JRoy Mar 25, 2023
8372c23
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Apr 10, 2023
e80dd1d
Fix build
JRoy Apr 10, 2023
212c855
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy May 23, 2023
03d61ae
Fix build?????????????????????
JRoy May 23, 2023
326ff13
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Jun 15, 2023
40b1d7a
Fix build
JRoy Jun 15, 2023
e6278e5
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Jul 29, 2023
124ac2e
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Aug 5, 2023
24b34a8
Fix build
JRoy Aug 5, 2023
bdb8e92
toComponent -> deserializeLegacy
JRoy Aug 5, 2023
e1e9d7d
Initial conversion code, just exists so far
JRoy Aug 5, 2023
e6b4254
Add configurable primary and secondary colors
JRoy Aug 6, 2023
67b8513
Get rid of the kezz magic char
JRoy Aug 6, 2023
c074a70
Allow passing in unescaped tags
JRoy Aug 6, 2023
f79f3be
Get rid of the mini message prefix
JRoy Aug 6, 2023
ad03d91
Hopefully mark all args that need to be parsed
JRoy Aug 6, 2023
c2dabab
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Aug 22, 2023
4cfab66
Placeholder -> ParsedPlaceholder
JRoy Sep 17, 2023
fa239d3
Make conversion method names more consistent
JRoy Sep 17, 2023
3407bba
Create CommonPlaceholders
JRoy Sep 17, 2023
9f0270a
Okayeg
JRoy Sep 17, 2023
56bd965
Add log message for adventure conversion
JRoy Sep 17, 2023
cece34d
Fix helpop behavior change
JRoy Sep 17, 2023
e47969e
Clarify SignException tlKey parameter
JRoy Sep 17, 2023
638233d
clean up worth a lil bit
JRoy Sep 17, 2023
b3db135
clean up sell a lil bit
JRoy Sep 17, 2023
a4f12fe
displayname fuck ah
JRoy Sep 17, 2023
1c4deb7
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Sep 17, 2023
72fbd20
fix
JRoy Sep 18, 2023
b5eaca9
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Sep 22, 2023
3a66d59
a reminder
JRoy Sep 22, 2023
d5c7403
Update locale docs link in config
mdcfe Nov 5, 2023
56bbaf1
Apply suggestions from code review
JRoy Nov 5, 2023
a9360f6
Update Essentials/src/main/java/com/earth2me/essentials/Settings.java
JRoy Nov 5, 2023
7667176
Support named colors for customizable color codes
JRoy Nov 5, 2023
6acd45d
Support customizable colors for the upgrade
JRoy Nov 6, 2023
8012e93
Enable the upgrade
JRoy Nov 6, 2023
7858beb
Merge remote-tracking branch 'upstream/2.x' into refactor/we-are-goin…
JRoy Nov 6, 2023
0385dc7
Update Essentials/src/main/java/com/earth2me/essentials/Essentials.java
mdcfe Dec 17, 2023
9c4715c
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
JRoy Dec 18, 2023
86862f6
Bump Adventure
JRoy Dec 18, 2023
d0cbe26
Move custom message files to separate directory
JRoy Dec 18, 2023
f9a2afe
Fix minor adventure trolling
JRoy Dec 18, 2023
2d86f6f
Preserve messages order
JRoy Dec 18, 2023
ae7590a
Add some javadocs
JRoy Dec 21, 2023
f14f5df
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
mdcfe Feb 3, 2024
1646427
Merge branch '2.x' into refactor/we-are-going-on-an-adventure
mdcfe Feb 3, 2024
521c5e1
Update messages files to use MiniMessage
mdcfe Feb 3, 2024
ef2da87
Set up BukkitAudiences in unit tests
mdcfe Feb 3, 2024
9730d61
Shade kyori option lib
mdcfe Feb 3, 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
32 changes: 26 additions & 6 deletions Essentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ dependencies {
compileOnly('com.github.milkbowl:VaultAPI:1.7') {
exclude group: "org.bukkit", module: "bukkit"
}
compileOnly 'net.luckperms:api:5.0'
compileOnly 'net.luckperms:api:5.3'

api 'io.papermc:paperlib:1.0.6'

api 'org.bstats:bstats-bukkit:2.2.1'

implementation 'org.spongepowered:configurate-yaml:4.1.2'
implementation 'org.checkerframework:checker-qual:3.14.0'
implementation 'org.checkerframework:checker-qual:3.21.0'

implementation 'net.kyori:adventure-api:4.11.0'
implementation('net.kyori:adventure-text-minimessage:4.11.0')
implementation 'net.kyori:adventure-platform-bukkit:4.1.1'

// Providers
api project(':providers:BaseProviders')
api project(':providers:PaperProvider')
api project(path: ':providers:PaperProvider', configuration: 'shadow')
api(project(':providers:NMSReflectionProvider')) {
exclude group: "org.bukkit", module: "bukkit"
}
Expand All @@ -43,8 +45,21 @@ shadowJar {
include (dependency('org.yaml:snakeyaml'))
include (dependency('io.leangen.geantyref:geantyref'))
include (dependency('org.checkerframework:checker-qual'))
include (dependency('net.kyori:adventure-api'))
include (dependency('net.kyori:adventure-key'))
include (dependency('net.kyori:examination-api'))
include (dependency('net.kyori:examination-string'))
include (dependency('net.kyori:adventure-platform-bukkit'))
include (dependency('net.kyori:adventure-platform-api'))
include (dependency('net.kyori:adventure-platform-facet'))
include (dependency('net.kyori:adventure-nbt'))
include (dependency('net.kyori:adventure-text-serializer-bungeecord'))
include (dependency('net.kyori:adventure-text-serializer-gson'))
include (dependency('net.kyori:adventure-text-serializer-gson-legacy-impl'))
include (dependency('net.kyori:adventure-text-serializer-legacy'))
include (dependency('net.kyori:adventure-text-minimessage'))
include (project(':providers:BaseProviders'))
include (project(':providers:PaperProvider'))
include (project(path: ':providers:PaperProvider', configuration: 'shadow'))
include (project(':providers:NMSReflectionProvider'))
include (project(':providers:1_8Provider'))
include (project(':providers:1_12Provider'))
Expand All @@ -55,8 +70,13 @@ shadowJar {
relocate 'org.yaml.snakeyaml', 'com.earth2me.essentials.libs.snakeyaml'
relocate 'io.leangen.geantyref', 'com.earth2me.essentials.libs.geantyref'
relocate 'org.checkerframework', 'com.earth2me.essentials.libs.checkerframework'
relocate 'net.kyori', 'com.earth2me.essentials.libs.kyori'
relocate 'net.essentialsx.temp.adventure', 'net.kyori.adventure'

minimize {
include(dependency('org.checkerframework:checker-qual'))
include(dependency('net.kyori:adventure-api'))
include(dependency('net.kyori:adventure-platform-bukkit'))
include(dependency('net.kyori:adventure-text-minimessage'))
}
}
25 changes: 12 additions & 13 deletions Essentials/src/main/java/com/earth2me/essentials/AsyncTeleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import net.ess3.api.InvalidWorldException;
import net.ess3.api.TranslatableException;
import net.ess3.api.events.UserWarpEvent;
import net.ess3.api.events.teleport.PreTeleportEvent;
import net.ess3.api.events.teleport.TeleportWarmupEvent;
Expand All @@ -23,8 +24,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

import static com.earth2me.essentials.I18n.tl;

public class AsyncTeleport implements IAsyncTeleport {
private final IUser teleportOwner;
private final IEssentials ess;
Expand Down Expand Up @@ -73,7 +72,7 @@ && cooldownApplies()) {
time.setTimeInMillis(lastTime);
time.add(Calendar.SECOND, (int) cooldown);
time.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0));
future.completeExceptionally(new Exception(tl("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis()))));
future.completeExceptionally(new TranslatableException("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis())));
return true;
}
}
Expand Down Expand Up @@ -107,7 +106,7 @@ private void warnUser(final IUser user, final double delay) {
final Calendar c = new GregorianCalendar();
c.add(Calendar.SECOND, (int) delay);
c.add(Calendar.MILLISECOND, (int) ((delay * 1000.0) % 1000.0));
user.sendMessage(tl("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis())));
user.sendTl("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis()));
}

@Override
Expand All @@ -129,7 +128,7 @@ public void now(final Player entity, final boolean cooldown, final TeleportCause
nowAsync(teleportOwner, target, cause, future);
future.thenAccept(success -> {
if (success) {
teleportOwner.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
}
});
}
Expand Down Expand Up @@ -166,7 +165,7 @@ protected void nowAsync(final IUser teleportee, final ITarget target, final Tele

if (!ess.getSettings().isForcePassengerTeleport() && !teleportee.getBase().isEmpty()) {
if (!ess.getSettings().isTeleportPassengerDismount()) {
future.completeExceptionally(new Exception(tl("passengerTeleportFail")));
future.completeExceptionally(new TranslatableException("passengerTeleportFail"));
return;
}

Expand Down Expand Up @@ -204,7 +203,7 @@ protected void nowAsync(final IUser teleportee, final ITarget target, final Tele
}
}
} else {
future.completeExceptionally(new Exception(tl("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
future.completeExceptionally(new TranslatableException("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
return;
}
} else {
Expand Down Expand Up @@ -233,7 +232,7 @@ public void teleport(final Location loc, final Trade chargeFor, final TeleportCa

@Override
public void teleport(final Player entity, final Trade chargeFor, final TeleportCause cause, final CompletableFuture<Boolean> future) {
teleportOwner.sendMessage(tl("teleportToPlayer", entity.getDisplayName()));
teleportOwner.sendTl("teleportToPlayer", entity.getDisplayName());
teleport(teleportOwner, new PlayerTarget(entity), chargeFor, cause, future);
}

Expand All @@ -248,8 +247,8 @@ public void teleportPlayer(final IUser otherUser, final Player entity, final Tra
teleport(otherUser, target, chargeFor, cause, future);
future.thenAccept(success -> {
if (success) {
otherUser.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
teleportOwner.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
otherUser.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
teleportOwner.sendTl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ());
}
});
}
Expand Down Expand Up @@ -432,9 +431,9 @@ public void warp(final IUser otherUser, String warp, final Trade chargeFor, fina
final String finalWarp = warp;
future.thenAccept(success -> {
if (success) {
otherUser.sendMessage(tl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
otherUser.sendTl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
if (!otherUser.equals(teleportOwner)) {
teleportOwner.sendMessage(tl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
teleportOwner.sendTl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
}
});
Expand All @@ -450,7 +449,7 @@ public void back(final Trade chargeFor, final CompletableFuture<Boolean> future)
public void back(final IUser teleporter, final Trade chargeFor, final CompletableFuture<Boolean> future) {
tpType = TeleportType.BACK;
final Location loc = teleportOwner.getLastLocation();
teleportOwner.sendMessage(tl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
teleportOwner.sendTl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
teleportOther(teleporter, teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND, future);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;

import static com.earth2me.essentials.I18n.tl;

public class AsyncTimedTeleport implements Runnable {
private static final double MOVE_CONSTANT = 0.3;
private final IUser teleportOwner;
Expand Down Expand Up @@ -106,14 +104,14 @@ public void run() {
try {
teleport.cooldown(false);
} catch (final Throwable ex) {
teleportOwner.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
teleportOwner.sendTl("cooldownWithMessage", ex.getMessage());
if (teleportOwner != teleportUser) {
teleportUser.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
teleportUser.sendTl("cooldownWithMessage", ex.getMessage());
}
}
try {
cancelTimer(false);
teleportUser.sendMessage(tl("teleportationCommencing"));
teleportUser.sendTl("teleportationCommencing");

if (timer_chargeFor != null) {
timer_chargeFor.isAffordableFor(teleportOwner);
Expand Down Expand Up @@ -152,9 +150,9 @@ void cancelTimer(final boolean notifyUser) {
try {
ess.getServer().getScheduler().cancelTask(timer_task);
if (notifyUser) {
teleportOwner.sendMessage(tl("pendingTeleportCancelled"));
teleportOwner.sendTl("pendingTeleportCancelled");
if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) {
ess.getUser(timer_teleportee).sendMessage(tl("pendingTeleportCancelled"));
ess.getUser(timer_teleportee).sendTl("pendingTeleportCancelled");
}
}
} finally {
Expand Down
6 changes: 3 additions & 3 deletions Essentials/src/main/java/com/earth2me/essentials/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlLiteral;

public class Backup implements Runnable {
private transient final Server server;
Expand Down Expand Up @@ -79,7 +79,7 @@ public void run() {
taskLock.complete(new Object());
return;
}
ess.getLogger().log(Level.INFO, tl("backupStarted"));
ess.getLogger().log(Level.INFO, tlLiteral("backupStarted"));
final CommandSender cs = server.getConsoleSender();
server.dispatchCommand(cs, "save-all");
server.dispatchCommand(cs, "save-off");
Expand Down Expand Up @@ -118,7 +118,7 @@ public void run() {
}
active = false;
taskLock.complete(new Object());
ess.getLogger().log(Level.INFO, tl("backupFinished"));
ess.getLogger().log(Level.INFO, tlLiteral("backupFinished"));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.AdventureUtil;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import static com.earth2me.essentials.I18n.tlLiteral;

public class CommandSource {
protected Essentials ess;
protected CommandSender sender;

public CommandSource(final CommandSender base) {
public CommandSource(final Essentials ess, final CommandSender base) {
this.ess = ess;
this.sender = base;
}

Expand All @@ -21,7 +29,47 @@ public final Player getPlayer() {
return null;
}

public final net.ess3.api.IUser getUser(final IEssentials ess) {
public void sendTl(final String tlKey, final Object... args) {
if (isPlayer()) {
//noinspection ConstantConditions
getUser().sendTl(tlKey, args);
return;
}

final String translation = tlLiteral(tlKey, args);
if (!translation.startsWith(AdventureUtil.MINI_MESSAGE_PREFIX)) {
sendMessage(translation);
return;
}
sendComponent(MiniMessage.miniMessage().deserialize(translation.substring(AdventureUtil.MINI_MESSAGE_PREFIX.length())));
}

public String tl(final String tlKey, final Object... args) {
if (isPlayer()) {
//noinspection ConstantConditions
return getUser().playerTl(tlKey, args);
}
return tlLiteral(tlKey, args);
}

public Component tlComponent(final String tlKey, final Object... args) {
if (isPlayer()) {
//noinspection ConstantConditions
return getUser().tlComponent(tlKey, args);
}
final String translation = tlLiteral(tlKey, args);
if (!translation.startsWith(AdventureUtil.MINI_MESSAGE_PREFIX)) {
return AdventureUtil.toComponent(translation);
}
return MiniMessage.miniMessage().deserialize(translation.substring(AdventureUtil.MINI_MESSAGE_PREFIX.length()));
}

public void sendComponent(final Component component) {
final BukkitAudiences audiences = ess.getBukkitAudience();
audiences.sender(sender).sendMessage(component);
}

public final net.ess3.api.IUser getUser() {
if (sender instanceof Player) {
return ess.getUser((Player) sender);
}
Expand All @@ -42,15 +90,18 @@ public void sendMessage(final String message) {
}
}

public boolean isAuthorized(final String permission, final IEssentials ess) {
return !(sender instanceof Player) || getUser(ess).isAuthorized(permission);
public boolean isAuthorized(final String permission) {
//noinspection ConstantConditions
return !(sender instanceof Player) || getUser().isAuthorized(permission);
}

public String getSelfSelector() {
//noinspection ConstantConditions
return sender instanceof Player ? getPlayer().getName() : "*";
}

public String getDisplayName() {
//noinspection ConstantConditions
return sender instanceof Player ? getPlayer().getDisplayName() : getSender().getName();
}
}
21 changes: 19 additions & 2 deletions Essentials/src/main/java/com/earth2me/essentials/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.messaging.SimpleMessageRecipient;
import com.earth2me.essentials.utils.AdventureUtil;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.UUID;

import static com.earth2me.essentials.I18n.tl;
import static com.earth2me.essentials.I18n.tlLiteral;

public final class Console implements IMessageRecipient {
public static final String NAME = "Console";
public static final String DISPLAY_NAME = tl("consoleName");
public static final String DISPLAY_NAME = tlLiteral("consoleName");
private static Console instance; // Set in essentials

private final IEssentials ess;
Expand Down Expand Up @@ -63,6 +65,21 @@ public void sendMessage(final String message) {
getCommandSender().sendMessage(message);
}

@Override
public void sendTl(String tlKey, Object... args) {
final String translation = tlLiteral(tlKey, args);
if (!translation.startsWith(AdventureUtil.MINI_MESSAGE_PREFIX)) {
sendMessage(translation);
return;
}
((Essentials) ess).getBukkitAudience().sender(getCommandSender()).sendMessage(MiniMessage.miniMessage().deserialize(translation.substring(AdventureUtil.MINI_MESSAGE_PREFIX.length())));
JRoy marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public String tlSender(String tlKey, Object... args) {
return tlLiteral(tlKey, args);
}

@Override
public boolean isReachable() {
return true;
Expand Down
Loading