mirror of
https://github.com/EssentialsX/Essentials.git
synced 2026-11-05 01:00:13 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff7569c77d | ||
|
|
f0cdada4a9 |
No files matched your search
@@ -1,7 +1,6 @@
|
||||
name: Report bug
|
||||
description: Report a bug in EssentialsX.
|
||||
labels: 'bug: unconfirmed'
|
||||
type: Bug
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
@@ -71,13 +70,10 @@ body:
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
- type: markdown
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: |
|
||||
In this box, you can attach any relevant screenshots, files and links to Timings/spark profiler reports.
|
||||
value: |
|
||||
In the text box below, you can attach any relevant screenshots, files and links to Timings/spark profiler reports.
|
||||
You can also include a link to a heapdump if necessary, but please make sure you don't include any private player data in the heapdump.
|
||||
If you suspect this issue is related to a prior issue/PR/commit, please mention it here.
|
||||
validations:
|
||||
required: false
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
name: Request a feature
|
||||
description: Suggest a feature you want to see in EssentialsX!
|
||||
labels: 'type: enhancement'
|
||||
type: Feature
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
|
||||
@@ -5,9 +5,6 @@ on:
|
||||
branches:
|
||||
- 2.x
|
||||
- dev/*
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -16,32 +13,34 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Git repo
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
- name: Restore Gradle cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v3
|
||||
- name: Set up JDK 16
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: 16
|
||||
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
|
||||
- name: Build with Gradle
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
./gradlew build --stacktrace
|
||||
|
||||
- name: Publish JUnit report
|
||||
uses: mikepenz/action-junit-report@v4
|
||||
if: success() || failure() # Run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/build/test-results/test*/TEST-*.xml'
|
||||
|
||||
- name: Archive plugin jars on GitHub
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
name: EssentialsX plugin jars
|
||||
path: jars/
|
||||
@@ -67,7 +66,7 @@ jobs:
|
||||
cp -r EssentialsXMPP/build/docs/javadoc/ javadocs/EssentialsXMPP/
|
||||
|
||||
- name: Archive Javadocs
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
name: javadocs
|
||||
path: javadocs/
|
||||
@@ -80,12 +79,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
- name: Download Javadocs
|
||||
uses: actions/download-artifact@v4
|
||||
uses: actions/download-artifact@master
|
||||
with:
|
||||
name: javadocs
|
||||
path: javadocs/
|
||||
|
||||
@@ -11,9 +11,6 @@ on:
|
||||
- mc/*
|
||||
- dev/*
|
||||
|
||||
permissions:
|
||||
checks: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build and upload
|
||||
@@ -21,32 +18,34 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout Git repo
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
- name: Restore Gradle cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Setup Gradle
|
||||
uses: gradle/gradle-build-action@v3
|
||||
- name: Set up JDK 16
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'adopt'
|
||||
java-version: 16
|
||||
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
|
||||
- name: Build with Gradle
|
||||
run: |
|
||||
chmod +x gradlew
|
||||
./gradlew build --stacktrace
|
||||
|
||||
- name: Publish JUnit report
|
||||
uses: mikepenz/action-junit-report@v4
|
||||
if: success() || failure() # Run even if the previous step fails
|
||||
with:
|
||||
report_paths: '**/build/test-results/test*/TEST-*.xml'
|
||||
|
||||
- name: Archive plugin jars on GitHub
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
name: EssentialsX plugin jars
|
||||
path: jars/
|
||||
+6
-31
@@ -6,21 +6,18 @@ dependencies {
|
||||
compileOnly('com.github.milkbowl:VaultAPI:1.7') {
|
||||
exclude group: "org.bukkit", module: "bukkit"
|
||||
}
|
||||
compileOnly 'net.luckperms:api:5.3'
|
||||
compileOnly 'net.luckperms:api:5.0'
|
||||
|
||||
api 'io.papermc:paperlib:1.0.6'
|
||||
|
||||
implementation 'org.spongepowered:configurate-yaml:4.2.0'
|
||||
implementation 'org.checkerframework:checker-qual:3.49.0'
|
||||
implementation 'nu.studer:java-ordered-properties:1.0.4'
|
||||
api 'org.bstats:bstats-bukkit:2.2.1'
|
||||
|
||||
implementation 'net.kyori:adventure-api:4.19.0'
|
||||
implementation 'net.kyori:adventure-text-minimessage:4.19.0'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.4'
|
||||
implementation 'org.spongepowered:configurate-yaml:4.1.2'
|
||||
implementation 'org.checkerframework:checker-qual:3.14.0'
|
||||
|
||||
// Providers
|
||||
api project(':providers:BaseProviders')
|
||||
api project(path: ':providers:PaperProvider', configuration: 'shadow')
|
||||
api project(':providers:PaperProvider')
|
||||
api(project(':providers:NMSReflectionProvider')) {
|
||||
exclude group: "org.bukkit", module: "bukkit"
|
||||
}
|
||||
@@ -46,25 +43,8 @@ shadowJar {
|
||||
include (dependency('org.yaml:snakeyaml'))
|
||||
include (dependency('io.leangen.geantyref:geantyref'))
|
||||
include (dependency('org.checkerframework:checker-qual'))
|
||||
include (dependency('nu.studer:java-ordered-properties'))
|
||||
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:option'))
|
||||
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-json'))
|
||||
include (dependency('net.kyori:adventure-text-serializer-json-legacy-impl'))
|
||||
include (dependency('net.kyori:adventure-text-serializer-legacy'))
|
||||
include (dependency('net.kyori:adventure-text-minimessage'))
|
||||
include (project(':providers:BaseProviders'))
|
||||
include (project(path: ':providers:PaperProvider', configuration: 'shadow'))
|
||||
include (project(':providers:PaperProvider'))
|
||||
include (project(':providers:NMSReflectionProvider'))
|
||||
include (project(':providers:1_8Provider'))
|
||||
include (project(':providers:1_12Provider'))
|
||||
@@ -75,13 +55,8 @@ 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'))
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -16,7 +13,7 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class AlternativeCommandsHandler {
|
||||
private final transient Map<String, List<WeakReference<Command>>> altCommands = new HashMap<>();
|
||||
private final transient Map<String, List<Command>> altcommands = new HashMap<>();
|
||||
private final transient Map<String, String> disabledList = new HashMap<>();
|
||||
private final transient IEssentials ess;
|
||||
|
||||
@@ -33,72 +30,41 @@ public class AlternativeCommandsHandler {
|
||||
if (plugin.getDescription().getMain().contains("com.earth2me.essentials") || plugin.getDescription().getMain().contains("net.essentialsx")) {
|
||||
return;
|
||||
}
|
||||
for (final Map.Entry<String, Command> entry : getPluginCommands(plugin)) {
|
||||
for (final Map.Entry<String, Command> entry : getPluginCommands(plugin).entrySet()) {
|
||||
final String[] commandSplit = entry.getKey().split(":", 2);
|
||||
final String commandName = commandSplit.length > 1 ? commandSplit[1] : entry.getKey();
|
||||
final Command command = entry.getValue();
|
||||
|
||||
final List<WeakReference<Command>> pluginCommands = altCommands.computeIfAbsent(commandName.toLowerCase(Locale.ENGLISH), k -> new ArrayList<>());
|
||||
final List<Command> pluginCommands = altcommands.computeIfAbsent(commandName.toLowerCase(Locale.ENGLISH), k -> new ArrayList<>());
|
||||
boolean found = false;
|
||||
|
||||
final Iterator<WeakReference<Command>> pluginCmdIterator = pluginCommands.iterator();
|
||||
while (pluginCmdIterator.hasNext()) {
|
||||
final Command cmd = pluginCmdIterator.next().get();
|
||||
if (cmd == null) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Essentials: Alternative command for " + commandName + " removed due to garbage collection");
|
||||
}
|
||||
|
||||
pluginCmdIterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
for (final Command pc2 : pluginCommands) {
|
||||
// Safe cast, everything that's added comes from getPluginCommands which already performs the cast check.
|
||||
if (((PluginIdentifiableCommand) cmd).getPlugin().equals(plugin)) {
|
||||
if (((PluginIdentifiableCommand) pc2).getPlugin().equals(plugin)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
pluginCommands.add(new WeakReference<>(command));
|
||||
pluginCommands.add(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map.Entry<String, Command>> getPluginCommands(Plugin plugin) {
|
||||
private Map<String, Command> getPluginCommands(Plugin plugin) {
|
||||
final Map<String, Command> commands = new HashMap<>();
|
||||
for (final Map.Entry<String, Command> entry : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) {
|
||||
commands.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
// Try to use non-namespaced commands first if we can, some Commands may not like being registered under a
|
||||
// different label than their getName() returns, so avoid doing that when we can
|
||||
return commands.entrySet().stream().sorted((o1, o2) -> {
|
||||
if (o1.getKey().contains(":") && !o2.getKey().contains(":")) {
|
||||
return 1;
|
||||
} else if (!o1.getKey().contains(":") && o2.getKey().contains(":")) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}).collect(Collectors.toList());
|
||||
return commands;
|
||||
}
|
||||
|
||||
public void removePlugin(final Plugin plugin) {
|
||||
final Iterator<Map.Entry<String, List<WeakReference<Command>>>> iterator = altCommands.entrySet().iterator();
|
||||
final Iterator<Map.Entry<String, List<Command>>> iterator = altcommands.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Map.Entry<String, List<WeakReference<Command>>> entry = iterator.next();
|
||||
|
||||
final Iterator<WeakReference<Command>> commands = entry.getValue().iterator();
|
||||
while (commands.hasNext()) {
|
||||
final Command pc = commands.next().get();
|
||||
if (pc instanceof PluginIdentifiableCommand && !((PluginIdentifiableCommand) pc).getPlugin().equals(plugin)) {
|
||||
continue;
|
||||
}
|
||||
commands.remove();
|
||||
}
|
||||
|
||||
final Map.Entry<String, List<Command>> entry = iterator.next();
|
||||
entry.getValue().removeIf(pc -> !(pc instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) pc).getPlugin().equals(plugin));
|
||||
if (entry.getValue().isEmpty()) {
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -106,31 +72,21 @@ public class AlternativeCommandsHandler {
|
||||
}
|
||||
|
||||
public Command getAlternative(final String label) {
|
||||
final List<WeakReference<Command>> commands = altCommands.get(label);
|
||||
final List<Command> commands = altcommands.get(label);
|
||||
if (commands == null || commands.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (commands.size() == 1) {
|
||||
return commands.get(0).get();
|
||||
return commands.get(0);
|
||||
}
|
||||
|
||||
// return the first command that is not an alias
|
||||
final Iterator<WeakReference<Command>> iterator = commands.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Command cmd = iterator.next().get();
|
||||
if (cmd == null) {
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cmd.getName().equalsIgnoreCase(label)) {
|
||||
return cmd;
|
||||
for (final Command command : commands) {
|
||||
if (command.getName().equalsIgnoreCase(label)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
// return the first alias
|
||||
return commands.get(0).get();
|
||||
return commands.get(0);
|
||||
}
|
||||
|
||||
public void executed(final String label, final Command pc) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.earth2me.essentials.utils.LocationUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import net.ess3.api.events.UserWarpEvent;
|
||||
import net.ess3.api.events.teleport.PreTeleportEvent;
|
||||
import net.ess3.api.events.teleport.TeleportWarmupEvent;
|
||||
@@ -23,6 +23,8 @@ import java.util.GregorianCalendar;
|
||||
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;
|
||||
@@ -71,7 +73,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
time.setTimeInMillis(lastTime);
|
||||
time.add(Calendar.SECOND, (int) cooldown);
|
||||
time.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0));
|
||||
future.completeExceptionally(new TranslatableException("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis())));
|
||||
future.completeExceptionally(new Exception(tl("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis()))));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -105,7 +107,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
final Calendar c = new GregorianCalendar();
|
||||
c.add(Calendar.SECOND, (int) delay);
|
||||
c.add(Calendar.MILLISECOND, (int) ((delay * 1000.0) % 1000.0));
|
||||
user.sendTl("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis()));
|
||||
user.sendMessage(tl("dontMoveMessage", DateUtil.formatDateDiff(c.getTimeInMillis())));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,7 +129,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
nowAsync(teleportOwner, target, cause, future);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
teleportOwner.sendTl("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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -164,7 +166,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
|
||||
if (!ess.getSettings().isForcePassengerTeleport() && !teleportee.getBase().isEmpty()) {
|
||||
if (!ess.getSettings().isTeleportPassengerDismount()) {
|
||||
future.completeExceptionally(new TranslatableException("passengerTeleportFail"));
|
||||
future.completeExceptionally(new Exception(tl("passengerTeleportFail")));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,7 +204,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
future.completeExceptionally(new TranslatableException("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
future.completeExceptionally(new Exception(tl("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -231,7 +233,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
|
||||
@Override
|
||||
public void teleport(final Player entity, final Trade chargeFor, final TeleportCause cause, final CompletableFuture<Boolean> future) {
|
||||
teleportOwner.sendTl("teleportToPlayer", entity.getDisplayName());
|
||||
teleportOwner.sendMessage(tl("teleportToPlayer", entity.getDisplayName()));
|
||||
teleport(teleportOwner, new PlayerTarget(entity), chargeFor, cause, future);
|
||||
}
|
||||
|
||||
@@ -246,8 +248,8 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
teleport(otherUser, target, chargeFor, cause, future);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
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());
|
||||
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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -423,16 +425,16 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
final Location loc;
|
||||
try {
|
||||
loc = ess.getWarps().getWarp(warp);
|
||||
} catch (final WarpNotFoundException e) {
|
||||
} catch (final WarpNotFoundException | InvalidWorldException e) {
|
||||
future.completeExceptionally(e);
|
||||
return;
|
||||
}
|
||||
final String finalWarp = warp;
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
otherUser.sendTl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
otherUser.sendMessage(tl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
if (!otherUser.equals(teleportOwner)) {
|
||||
teleportOwner.sendTl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
teleportOwner.sendMessage(tl("warpingTo", finalWarp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -448,7 +450,7 @@ public class AsyncTeleport implements IAsyncTeleport {
|
||||
public void back(final IUser teleporter, final Trade chargeFor, final CompletableFuture<Boolean> future) {
|
||||
tpType = TeleportType.BACK;
|
||||
final Location loc = teleportOwner.getLastLocation();
|
||||
teleportOwner.sendTl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
teleportOwner.sendMessage(tl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
teleportOther(teleporter, teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND, future);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
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;
|
||||
@@ -104,14 +106,14 @@ public class AsyncTimedTeleport implements Runnable {
|
||||
try {
|
||||
teleport.cooldown(false);
|
||||
} catch (final Throwable ex) {
|
||||
teleportOwner.sendTl("cooldownWithMessage", ex.getMessage());
|
||||
teleportOwner.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
|
||||
if (teleportOwner != teleportUser) {
|
||||
teleportUser.sendTl("cooldownWithMessage", ex.getMessage());
|
||||
teleportUser.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
try {
|
||||
cancelTimer(false);
|
||||
teleportUser.sendTl("teleportationCommencing");
|
||||
teleportUser.sendMessage(tl("teleportationCommencing"));
|
||||
|
||||
if (timer_chargeFor != null) {
|
||||
timer_chargeFor.isAffordableFor(teleportOwner);
|
||||
@@ -150,9 +152,9 @@ public class AsyncTimedTeleport implements Runnable {
|
||||
try {
|
||||
ess.getServer().getScheduler().cancelTask(timer_task);
|
||||
if (notifyUser) {
|
||||
teleportOwner.sendTl("pendingTeleportCancelled");
|
||||
teleportOwner.sendMessage(tl("pendingTeleportCancelled"));
|
||||
if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) {
|
||||
ess.getUser(timer_teleportee).sendTl("pendingTeleportCancelled");
|
||||
ess.getUser(timer_teleportee).sendMessage(tl("pendingTeleportCancelled"));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -12,7 +11,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Backup implements Runnable {
|
||||
private transient final Server server;
|
||||
@@ -80,7 +79,7 @@ public class Backup implements Runnable {
|
||||
taskLock.complete(new Object());
|
||||
return;
|
||||
}
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("backupStarted")));
|
||||
ess.getLogger().log(Level.INFO, tl("backupStarted"));
|
||||
final CommandSender cs = server.getConsoleSender();
|
||||
server.dispatchCommand(cs, "save-all");
|
||||
server.dispatchCommand(cs, "save-off");
|
||||
@@ -119,7 +118,7 @@ public class Backup implements Runnable {
|
||||
}
|
||||
active = false;
|
||||
taskLock.complete(new Object());
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("backupFinished")));
|
||||
ess.getLogger().log(Level.INFO, tl("backupFinished"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class BalanceTopImpl implements BalanceTop {
|
||||
user.updateMoneyCache(userMoney);
|
||||
newTotal = newTotal.add(userMoney);
|
||||
final String name;
|
||||
if (user.getBase() instanceof OfflinePlayerStub) {
|
||||
if (user.getBase() instanceof OfflinePlayer) {
|
||||
name = user.getLastAccountName();
|
||||
} else if (user.isHidden()) {
|
||||
name = user.getName();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import net.ess3.api.TranslatableException;
|
||||
public class ChargeException extends Exception {
|
||||
public ChargeException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public class ChargeException extends TranslatableException {
|
||||
public ChargeException(String tlKey, Object... args) {
|
||||
super(tlKey, args);
|
||||
public ChargeException(final String message, final Throwable throwable) {
|
||||
super(message, throwable);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,12 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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 Essentials ess, final CommandSender base) {
|
||||
this.ess = ess;
|
||||
public CommandSource(final CommandSender base) {
|
||||
this.sender = base;
|
||||
}
|
||||
|
||||
@@ -28,42 +21,7 @@ public class CommandSource {
|
||||
return null;
|
||||
}
|
||||
|
||||
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.isEmpty()) {
|
||||
sendComponent(AdventureUtil.miniMessage().deserialize(translation));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
return AdventureUtil.miniMessage().deserialize(translation);
|
||||
}
|
||||
|
||||
public void sendComponent(final Component component) {
|
||||
final BukkitAudiences audiences = ess.getBukkitAudience();
|
||||
audiences.sender(sender).sendMessage(component);
|
||||
}
|
||||
|
||||
public final net.ess3.api.IUser getUser() {
|
||||
public final net.ess3.api.IUser getUser(final IEssentials ess) {
|
||||
if (sender instanceof Player) {
|
||||
return ess.getUser((Player) sender);
|
||||
}
|
||||
@@ -84,18 +42,15 @@ public class CommandSource {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAuthorized(final String permission) {
|
||||
//noinspection ConstantConditions
|
||||
return !(sender instanceof Player) || getUser().isAuthorized(permission);
|
||||
public boolean isAuthorized(final String permission, final IEssentials ess) {
|
||||
return !(sender instanceof Player) || getUser(ess).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();
|
||||
}
|
||||
}
|
||||
@@ -2,20 +2,17 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.messaging.IMessageRecipient;
|
||||
import com.earth2me.essentials.messaging.SimpleMessageRecipient;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public final class Console implements IMessageRecipient {
|
||||
public static final String NAME = "Console";
|
||||
public static final String DISPLAY_NAME = tlLiteral("consoleName");
|
||||
public static final String DISPLAY_NAME = tl("consoleName");
|
||||
private static Console instance; // Set in essentials
|
||||
|
||||
private final IEssentials ess;
|
||||
@@ -66,24 +63,6 @@ public final class Console implements IMessageRecipient {
|
||||
getCommandSender().sendMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTl(String tlKey, Object... args) {
|
||||
final String translation = tlLiteral(tlKey, args);
|
||||
if (translation.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Audience consoleAudience = ((Essentials) ess).getBukkitAudience().sender(getCommandSender());
|
||||
final Component component = AdventureUtil.miniMessage()
|
||||
.deserialize(translation);
|
||||
consoleAudience.sendMessage(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tlSender(String tlKey, Object... args) {
|
||||
return tlLiteral(tlKey, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReachable() {
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
@@ -16,43 +15,33 @@ public final class Enchantments {
|
||||
private static boolean isFlat;
|
||||
|
||||
static {
|
||||
final Enchantment SHARPNESS = RegistryUtil.valueOf(Enchantment.class, "DAMAGE_ALL", "SHARPNESS");
|
||||
|
||||
ENCHANTMENTS.put("alldamage", SHARPNESS);
|
||||
ALIASENCHANTMENTS.put("alldmg", SHARPNESS);
|
||||
ENCHANTMENTS.put("sharpness", SHARPNESS);
|
||||
ALIASENCHANTMENTS.put("sharp", SHARPNESS);
|
||||
ALIASENCHANTMENTS.put("dal", SHARPNESS);
|
||||
|
||||
final Enchantment BANE_OF_ARTHROPODS = RegistryUtil.valueOf(Enchantment.class, "DAMAGE_ARTHROPODS", "BANE_OF_ARTHROPODS");
|
||||
ENCHANTMENTS.put("alldamage", Enchantment.DAMAGE_ALL);
|
||||
ALIASENCHANTMENTS.put("alldmg", Enchantment.DAMAGE_ALL);
|
||||
ENCHANTMENTS.put("sharpness", Enchantment.DAMAGE_ALL);
|
||||
ALIASENCHANTMENTS.put("sharp", Enchantment.DAMAGE_ALL);
|
||||
ALIASENCHANTMENTS.put("dal", Enchantment.DAMAGE_ALL);
|
||||
|
||||
ENCHANTMENTS.put("ardmg", BANE_OF_ARTHROPODS);
|
||||
ENCHANTMENTS.put("baneofarthropods", BANE_OF_ARTHROPODS);
|
||||
ALIASENCHANTMENTS.put("baneofarthropod", BANE_OF_ARTHROPODS);
|
||||
ALIASENCHANTMENTS.put("arthropod", BANE_OF_ARTHROPODS);
|
||||
ALIASENCHANTMENTS.put("dar", BANE_OF_ARTHROPODS);
|
||||
|
||||
final Enchantment SMITE = RegistryUtil.valueOf(Enchantment.class, "DAMAGE_UNDEAD", "SMITE");
|
||||
ENCHANTMENTS.put("ardmg", Enchantment.DAMAGE_ARTHROPODS);
|
||||
ENCHANTMENTS.put("baneofarthropods", Enchantment.DAMAGE_ARTHROPODS);
|
||||
ALIASENCHANTMENTS.put("baneofarthropod", Enchantment.DAMAGE_ARTHROPODS);
|
||||
ALIASENCHANTMENTS.put("arthropod", Enchantment.DAMAGE_ARTHROPODS);
|
||||
ALIASENCHANTMENTS.put("dar", Enchantment.DAMAGE_ARTHROPODS);
|
||||
|
||||
ENCHANTMENTS.put("undeaddamage", SMITE);
|
||||
ENCHANTMENTS.put("smite", SMITE);
|
||||
ALIASENCHANTMENTS.put("du", SMITE);
|
||||
|
||||
final Enchantment EFFICIENCY = RegistryUtil.valueOf(Enchantment.class, "DIG_SPEED", "EFFICIENCY");
|
||||
ENCHANTMENTS.put("undeaddamage", Enchantment.DAMAGE_UNDEAD);
|
||||
ENCHANTMENTS.put("smite", Enchantment.DAMAGE_UNDEAD);
|
||||
ALIASENCHANTMENTS.put("du", Enchantment.DAMAGE_UNDEAD);
|
||||
|
||||
ENCHANTMENTS.put("digspeed", EFFICIENCY);
|
||||
ENCHANTMENTS.put("efficiency", EFFICIENCY);
|
||||
ALIASENCHANTMENTS.put("minespeed", EFFICIENCY);
|
||||
ALIASENCHANTMENTS.put("cutspeed", EFFICIENCY);
|
||||
ALIASENCHANTMENTS.put("ds", EFFICIENCY);
|
||||
ALIASENCHANTMENTS.put("eff", EFFICIENCY);
|
||||
|
||||
final Enchantment UNBREAKING = RegistryUtil.valueOf(Enchantment.class, "DURABILITY", "UNBREAKING");
|
||||
ENCHANTMENTS.put("digspeed", Enchantment.DIG_SPEED);
|
||||
ENCHANTMENTS.put("efficiency", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("minespeed", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("cutspeed", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("ds", Enchantment.DIG_SPEED);
|
||||
ALIASENCHANTMENTS.put("eff", Enchantment.DIG_SPEED);
|
||||
|
||||
ENCHANTMENTS.put("durability", UNBREAKING);
|
||||
ALIASENCHANTMENTS.put("dura", UNBREAKING);
|
||||
ENCHANTMENTS.put("unbreaking", UNBREAKING);
|
||||
ALIASENCHANTMENTS.put("d", UNBREAKING);
|
||||
ENCHANTMENTS.put("durability", Enchantment.DURABILITY);
|
||||
ALIASENCHANTMENTS.put("dura", Enchantment.DURABILITY);
|
||||
ENCHANTMENTS.put("unbreaking", Enchantment.DURABILITY);
|
||||
ALIASENCHANTMENTS.put("d", Enchantment.DURABILITY);
|
||||
|
||||
ENCHANTMENTS.put("thorns", Enchantment.THORNS);
|
||||
ENCHANTMENTS.put("highcrit", Enchantment.THORNS);
|
||||
@@ -70,127 +59,106 @@ public final class Enchantments {
|
||||
ALIASENCHANTMENTS.put("kback", Enchantment.KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("kb", Enchantment.KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("k", Enchantment.KNOCKBACK);
|
||||
|
||||
final Enchantment FORTUNE = RegistryUtil.valueOf(Enchantment.class, "LOOT_BONUS_BLOCKS", "FORTUNE");
|
||||
|
||||
ALIASENCHANTMENTS.put("blockslootbonus", FORTUNE);
|
||||
ENCHANTMENTS.put("fortune", FORTUNE);
|
||||
ALIASENCHANTMENTS.put("fort", FORTUNE);
|
||||
ALIASENCHANTMENTS.put("lbb", FORTUNE);
|
||||
|
||||
final Enchantment LOOTING = RegistryUtil.valueOf(Enchantment.class, "LOOT_BONUS_MOBS", "LOOTING");
|
||||
ALIASENCHANTMENTS.put("blockslootbonus", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
ENCHANTMENTS.put("fortune", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
ALIASENCHANTMENTS.put("fort", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
ALIASENCHANTMENTS.put("lbb", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
|
||||
ALIASENCHANTMENTS.put("mobslootbonus", LOOTING);
|
||||
ENCHANTMENTS.put("mobloot", LOOTING);
|
||||
ENCHANTMENTS.put("looting", LOOTING);
|
||||
ALIASENCHANTMENTS.put("lbm", LOOTING);
|
||||
|
||||
final Enchantment RESPIRATION = RegistryUtil.valueOf(Enchantment.class, "OXYGEN", "RESPIRATION");
|
||||
ALIASENCHANTMENTS.put("mobslootbonus", Enchantment.LOOT_BONUS_MOBS);
|
||||
ENCHANTMENTS.put("mobloot", Enchantment.LOOT_BONUS_MOBS);
|
||||
ENCHANTMENTS.put("looting", Enchantment.LOOT_BONUS_MOBS);
|
||||
ALIASENCHANTMENTS.put("lbm", Enchantment.LOOT_BONUS_MOBS);
|
||||
|
||||
ALIASENCHANTMENTS.put("oxygen", RESPIRATION);
|
||||
ENCHANTMENTS.put("respiration", RESPIRATION);
|
||||
ALIASENCHANTMENTS.put("breathing", RESPIRATION);
|
||||
ENCHANTMENTS.put("breath", RESPIRATION);
|
||||
ALIASENCHANTMENTS.put("o", RESPIRATION);
|
||||
|
||||
final Enchantment PROTECTION = RegistryUtil.valueOf(Enchantment.class, "PROTECTION_ENVIRONMENTAL", "PROTECTION");
|
||||
ALIASENCHANTMENTS.put("oxygen", Enchantment.OXYGEN);
|
||||
ENCHANTMENTS.put("respiration", Enchantment.OXYGEN);
|
||||
ALIASENCHANTMENTS.put("breathing", Enchantment.OXYGEN);
|
||||
ENCHANTMENTS.put("breath", Enchantment.OXYGEN);
|
||||
ALIASENCHANTMENTS.put("o", Enchantment.OXYGEN);
|
||||
|
||||
ENCHANTMENTS.put("protection", PROTECTION);
|
||||
ALIASENCHANTMENTS.put("prot", PROTECTION);
|
||||
ENCHANTMENTS.put("protect", PROTECTION);
|
||||
ALIASENCHANTMENTS.put("p", PROTECTION);
|
||||
|
||||
final Enchantment BLAST_PROTECTION = RegistryUtil.valueOf(Enchantment.class, "PROTECTION_EXPLOSIONS", "BLAST_PROTECTION");
|
||||
ENCHANTMENTS.put("protection", Enchantment.PROTECTION_ENVIRONMENTAL);
|
||||
ALIASENCHANTMENTS.put("prot", Enchantment.PROTECTION_ENVIRONMENTAL);
|
||||
ENCHANTMENTS.put("protect", Enchantment.PROTECTION_ENVIRONMENTAL);
|
||||
ALIASENCHANTMENTS.put("p", Enchantment.PROTECTION_ENVIRONMENTAL);
|
||||
|
||||
ALIASENCHANTMENTS.put("explosionsprotection", BLAST_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("explosionprotection", BLAST_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("expprot", BLAST_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("blastprotection", BLAST_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("bprotection", BLAST_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("bprotect", BLAST_PROTECTION);
|
||||
ENCHANTMENTS.put("blastprotect", BLAST_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("pe", BLAST_PROTECTION);
|
||||
|
||||
final Enchantment FEATHER_FALLING = RegistryUtil.valueOf(Enchantment.class, "PROTECTION_FALL", "FEATHER_FALLING");
|
||||
ALIASENCHANTMENTS.put("explosionsprotection", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ALIASENCHANTMENTS.put("explosionprotection", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ALIASENCHANTMENTS.put("expprot", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ALIASENCHANTMENTS.put("blastprotection", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ALIASENCHANTMENTS.put("bprotection", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ALIASENCHANTMENTS.put("bprotect", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ENCHANTMENTS.put("blastprotect", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
ALIASENCHANTMENTS.put("pe", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
|
||||
ALIASENCHANTMENTS.put("fallprotection", FEATHER_FALLING);
|
||||
ENCHANTMENTS.put("fallprot", FEATHER_FALLING);
|
||||
ENCHANTMENTS.put("featherfall", FEATHER_FALLING);
|
||||
ALIASENCHANTMENTS.put("featherfalling", FEATHER_FALLING);
|
||||
ALIASENCHANTMENTS.put("pfa", FEATHER_FALLING);
|
||||
|
||||
final Enchantment FIRE_PROTECTION = RegistryUtil.valueOf(Enchantment.class, "PROTECTION_FIRE", "FIRE_PROTECTION");
|
||||
ALIASENCHANTMENTS.put("fallprotection", Enchantment.PROTECTION_FALL);
|
||||
ENCHANTMENTS.put("fallprot", Enchantment.PROTECTION_FALL);
|
||||
ENCHANTMENTS.put("featherfall", Enchantment.PROTECTION_FALL);
|
||||
ALIASENCHANTMENTS.put("featherfalling", Enchantment.PROTECTION_FALL);
|
||||
ALIASENCHANTMENTS.put("pfa", Enchantment.PROTECTION_FALL);
|
||||
|
||||
ALIASENCHANTMENTS.put("fireprotection", FIRE_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("flameprotection", FIRE_PROTECTION);
|
||||
ENCHANTMENTS.put("fireprotect", FIRE_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("flameprotect", FIRE_PROTECTION);
|
||||
ENCHANTMENTS.put("fireprot", FIRE_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("flameprot", FIRE_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("pf", FIRE_PROTECTION);
|
||||
|
||||
final Enchantment PROJECTILE_PROTECTION = RegistryUtil.valueOf(Enchantment.class, "PROTECTION_PROJECTILE", "PROJECTILE_PROTECTION");
|
||||
ALIASENCHANTMENTS.put("fireprotection", Enchantment.PROTECTION_FIRE);
|
||||
ALIASENCHANTMENTS.put("flameprotection", Enchantment.PROTECTION_FIRE);
|
||||
ENCHANTMENTS.put("fireprotect", Enchantment.PROTECTION_FIRE);
|
||||
ALIASENCHANTMENTS.put("flameprotect", Enchantment.PROTECTION_FIRE);
|
||||
ENCHANTMENTS.put("fireprot", Enchantment.PROTECTION_FIRE);
|
||||
ALIASENCHANTMENTS.put("flameprot", Enchantment.PROTECTION_FIRE);
|
||||
ALIASENCHANTMENTS.put("pf", Enchantment.PROTECTION_FIRE);
|
||||
|
||||
ENCHANTMENTS.put("projectileprotection", PROJECTILE_PROTECTION);
|
||||
ENCHANTMENTS.put("projprot", PROJECTILE_PROTECTION);
|
||||
ALIASENCHANTMENTS.put("pp", PROJECTILE_PROTECTION);
|
||||
ENCHANTMENTS.put("projectileprotection", Enchantment.PROTECTION_PROJECTILE);
|
||||
ENCHANTMENTS.put("projprot", Enchantment.PROTECTION_PROJECTILE);
|
||||
ALIASENCHANTMENTS.put("pp", Enchantment.PROTECTION_PROJECTILE);
|
||||
|
||||
ENCHANTMENTS.put("silktouch", Enchantment.SILK_TOUCH);
|
||||
ALIASENCHANTMENTS.put("softtouch", Enchantment.SILK_TOUCH);
|
||||
ALIASENCHANTMENTS.put("st", Enchantment.SILK_TOUCH);
|
||||
|
||||
final Enchantment AQUA_AFFINITY = RegistryUtil.valueOf(Enchantment.class, "WATER_WORKER", "AQUA_AFFINITY");
|
||||
|
||||
ENCHANTMENTS.put("waterworker", AQUA_AFFINITY);
|
||||
ENCHANTMENTS.put("aquaaffinity", AQUA_AFFINITY);
|
||||
ALIASENCHANTMENTS.put("watermine", AQUA_AFFINITY);
|
||||
ALIASENCHANTMENTS.put("ww", AQUA_AFFINITY);
|
||||
|
||||
final Enchantment FLAME = RegistryUtil.valueOf(Enchantment.class, "ARROW_FIRE", "FLAME");
|
||||
ENCHANTMENTS.put("waterworker", Enchantment.WATER_WORKER);
|
||||
ENCHANTMENTS.put("aquaaffinity", Enchantment.WATER_WORKER);
|
||||
ALIASENCHANTMENTS.put("watermine", Enchantment.WATER_WORKER);
|
||||
ALIASENCHANTMENTS.put("ww", Enchantment.WATER_WORKER);
|
||||
|
||||
ALIASENCHANTMENTS.put("firearrow", FLAME);
|
||||
ENCHANTMENTS.put("flame", FLAME);
|
||||
ENCHANTMENTS.put("flamearrow", FLAME);
|
||||
ALIASENCHANTMENTS.put("af", FLAME);
|
||||
|
||||
final Enchantment POWER = RegistryUtil.valueOf(Enchantment.class, "ARROW_DAMAGE", "POWER");
|
||||
ALIASENCHANTMENTS.put("firearrow", Enchantment.ARROW_FIRE);
|
||||
ENCHANTMENTS.put("flame", Enchantment.ARROW_FIRE);
|
||||
ENCHANTMENTS.put("flamearrow", Enchantment.ARROW_FIRE);
|
||||
ALIASENCHANTMENTS.put("af", Enchantment.ARROW_FIRE);
|
||||
|
||||
ENCHANTMENTS.put("arrowdamage", POWER);
|
||||
ENCHANTMENTS.put("power", POWER);
|
||||
ALIASENCHANTMENTS.put("arrowpower", POWER);
|
||||
ALIASENCHANTMENTS.put("ad", POWER);
|
||||
|
||||
final Enchantment PUNCH = RegistryUtil.valueOf(Enchantment.class, "ARROW_KNOCKBACK", "PUNCH");
|
||||
ENCHANTMENTS.put("arrowdamage", Enchantment.ARROW_DAMAGE);
|
||||
ENCHANTMENTS.put("power", Enchantment.ARROW_DAMAGE);
|
||||
ALIASENCHANTMENTS.put("arrowpower", Enchantment.ARROW_DAMAGE);
|
||||
ALIASENCHANTMENTS.put("ad", Enchantment.ARROW_DAMAGE);
|
||||
|
||||
ENCHANTMENTS.put("arrowknockback", PUNCH);
|
||||
ALIASENCHANTMENTS.put("arrowkb", PUNCH);
|
||||
ENCHANTMENTS.put("punch", PUNCH);
|
||||
ALIASENCHANTMENTS.put("arrowpunch", PUNCH);
|
||||
ALIASENCHANTMENTS.put("ak", PUNCH);
|
||||
|
||||
final Enchantment INFINITY = RegistryUtil.valueOf(Enchantment.class, "ARROW_INFINITE", "INFINITY");
|
||||
ENCHANTMENTS.put("arrowknockback", Enchantment.ARROW_KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("arrowkb", Enchantment.ARROW_KNOCKBACK);
|
||||
ENCHANTMENTS.put("punch", Enchantment.ARROW_KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("arrowpunch", Enchantment.ARROW_KNOCKBACK);
|
||||
ALIASENCHANTMENTS.put("ak", Enchantment.ARROW_KNOCKBACK);
|
||||
|
||||
ALIASENCHANTMENTS.put("infinitearrows", INFINITY);
|
||||
ENCHANTMENTS.put("infarrows", INFINITY);
|
||||
ENCHANTMENTS.put("infinity", INFINITY);
|
||||
ALIASENCHANTMENTS.put("infinite", INFINITY);
|
||||
ALIASENCHANTMENTS.put("unlimited", INFINITY);
|
||||
ALIASENCHANTMENTS.put("unlimitedarrows", INFINITY);
|
||||
ALIASENCHANTMENTS.put("ai", INFINITY);
|
||||
|
||||
final Enchantment LUCK_OF_THE_SEA = RegistryUtil.valueOf(Enchantment.class, "LUCK", "LUCK_OF_THE_SEA");
|
||||
ALIASENCHANTMENTS.put("infinitearrows", Enchantment.ARROW_INFINITE);
|
||||
ENCHANTMENTS.put("infarrows", Enchantment.ARROW_INFINITE);
|
||||
ENCHANTMENTS.put("infinity", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("infinite", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("unlimited", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("unlimitedarrows", Enchantment.ARROW_INFINITE);
|
||||
ALIASENCHANTMENTS.put("ai", Enchantment.ARROW_INFINITE);
|
||||
|
||||
ENCHANTMENTS.put("luck", LUCK_OF_THE_SEA);
|
||||
ALIASENCHANTMENTS.put("luckofsea", LUCK_OF_THE_SEA);
|
||||
ALIASENCHANTMENTS.put("luckofseas", LUCK_OF_THE_SEA);
|
||||
ALIASENCHANTMENTS.put("rodluck", LUCK_OF_THE_SEA);
|
||||
ENCHANTMENTS.put("luck", Enchantment.LUCK);
|
||||
ALIASENCHANTMENTS.put("luckofsea", Enchantment.LUCK);
|
||||
ALIASENCHANTMENTS.put("luckofseas", Enchantment.LUCK);
|
||||
ALIASENCHANTMENTS.put("rodluck", Enchantment.LUCK);
|
||||
|
||||
ENCHANTMENTS.put("lure", Enchantment.LURE);
|
||||
ALIASENCHANTMENTS.put("rodlure", Enchantment.LURE);
|
||||
|
||||
ENCHANTMENTS.put("depthstrider", Enchantment.DEPTH_STRIDER);
|
||||
ALIASENCHANTMENTS.put("depth", Enchantment.DEPTH_STRIDER);
|
||||
ALIASENCHANTMENTS.put("strider", Enchantment.DEPTH_STRIDER);
|
||||
// 1.8
|
||||
try {
|
||||
final Enchantment depthStrider = Enchantment.getByName("DEPTH_STRIDER");
|
||||
if (depthStrider != null) {
|
||||
ENCHANTMENTS.put("depthstrider", depthStrider);
|
||||
ALIASENCHANTMENTS.put("depth", depthStrider);
|
||||
ALIASENCHANTMENTS.put("strider", depthStrider);
|
||||
}
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
// 1.9
|
||||
try {
|
||||
@@ -303,24 +271,6 @@ public final class Enchantments {
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
try { // 1.21
|
||||
final Enchantment breach = Enchantment.getByName("BREACH");
|
||||
if (breach != null) {
|
||||
ENCHANTMENTS.put("breach", breach);
|
||||
}
|
||||
final Enchantment density = Enchantment.getByName("DENSITY");
|
||||
if (density != null) {
|
||||
ENCHANTMENTS.put("density", density);
|
||||
}
|
||||
final Enchantment windBurst = Enchantment.getByName("WIND_BURST");
|
||||
if (breach != null) {
|
||||
ENCHANTMENTS.put("windburst", windBurst);
|
||||
ALIASENCHANTMENTS.put("wind", windBurst);
|
||||
ALIASENCHANTMENTS.put("burst", windBurst);
|
||||
}
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
final Class<?> namespacedKeyClass = Class.forName("org.bukkit.NamespacedKey");
|
||||
final Class<?> enchantmentClass = Class.forName("org.bukkit.enchantments.Enchantment");
|
||||
@@ -334,17 +284,6 @@ public final class Enchantments {
|
||||
private Enchantments() {
|
||||
}
|
||||
|
||||
public static String getRealName(final Enchantment enchantment) {
|
||||
if (enchantment == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isFlat) { // 1.13+ only
|
||||
return enchantment.getKey().getKey();
|
||||
}
|
||||
return enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
public static Enchantment getByName(final String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return null;
|
||||
|
||||
@@ -40,7 +40,6 @@ import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||
import com.earth2me.essentials.userstorage.ModernUserMap;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
@@ -49,7 +48,6 @@ import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IItemDb;
|
||||
import net.ess3.api.IJails;
|
||||
import net.ess3.api.ISettings;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.nms.refl.providers.ReflDataWorldInfoProvider;
|
||||
import net.ess3.nms.refl.providers.ReflFormattedCommandAliasProvider;
|
||||
import net.ess3.nms.refl.providers.ReflKnownCommandsProvider;
|
||||
@@ -59,48 +57,44 @@ import net.ess3.nms.refl.providers.ReflServerStateProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnEggProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider;
|
||||
import net.ess3.nms.refl.providers.ReflSyncCommandsProvider;
|
||||
import net.ess3.provider.InventoryViewProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.PlayerLocaleProvider;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import net.ess3.provider.ProviderListener;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.ess3.provider.ServerStateProvider;
|
||||
import net.ess3.provider.providers.BaseBannerDataProvider;
|
||||
import net.ess3.provider.providers.BaseInventoryViewProvider;
|
||||
import net.ess3.provider.SignDataProvider;
|
||||
import net.ess3.provider.SpawnEggProvider;
|
||||
import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.ess3.provider.providers.BaseLoggerProvider;
|
||||
import net.ess3.provider.providers.BasePotionDataProvider;
|
||||
import net.ess3.provider.providers.BlockMetaSpawnerItemProvider;
|
||||
import net.ess3.provider.providers.BukkitMaterialTagProvider;
|
||||
import net.ess3.provider.providers.BukkitSpawnerBlockProvider;
|
||||
import net.ess3.provider.providers.FixedHeightWorldInfoProvider;
|
||||
import net.ess3.provider.providers.FlatSpawnEggProvider;
|
||||
import net.ess3.provider.providers.LegacyBannerDataProvider;
|
||||
import net.ess3.provider.providers.LegacyDamageEventProvider;
|
||||
import net.ess3.provider.providers.LegacyInventoryViewProvider;
|
||||
import net.ess3.provider.providers.LegacyItemUnbreakableProvider;
|
||||
import net.ess3.provider.providers.LegacyPlayerLocaleProvider;
|
||||
import net.ess3.provider.providers.LegacyPotionMetaProvider;
|
||||
import net.ess3.provider.providers.LegacySpawnEggProvider;
|
||||
import net.ess3.provider.providers.ModernDamageEventProvider;
|
||||
import net.ess3.provider.providers.ModernDataWorldInfoProvider;
|
||||
import net.ess3.provider.providers.ModernItemUnbreakableProvider;
|
||||
import net.ess3.provider.providers.ModernPersistentDataProvider;
|
||||
import net.ess3.provider.providers.ModernPlayerLocaleProvider;
|
||||
import net.ess3.provider.providers.ModernPotionMetaProvider;
|
||||
import net.ess3.provider.providers.ModernSignDataProvider;
|
||||
import net.ess3.provider.providers.ModernSyncCommandsProvider;
|
||||
import net.ess3.provider.providers.PaperBiomeKeyProvider;
|
||||
import net.ess3.provider.providers.PaperContainerProvider;
|
||||
import net.ess3.provider.providers.PaperKnownCommandsProvider;
|
||||
import net.ess3.provider.providers.PaperMaterialTagProvider;
|
||||
import net.ess3.provider.providers.PaperRecipeBookListener;
|
||||
import net.ess3.provider.providers.PaperSerializationProvider;
|
||||
import net.ess3.provider.providers.PaperServerStateProvider;
|
||||
import net.ess3.provider.providers.PaperTickCountProvider;
|
||||
import net.ess3.provider.providers.PrehistoricPotionMetaProvider;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import net.essentialsx.api.v2.services.mail.MailService;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -119,7 +113,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
@@ -140,24 +133,19 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tlLocale;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private static final Logger BUKKIT_LOGGER = Logger.getLogger("Essentials");
|
||||
private static Logger LOGGER = null;
|
||||
public static boolean TESTING = false;
|
||||
private final transient TNTExplodeListener tntListener = new TNTExplodeListener();
|
||||
private final transient Set<String> vanishedPlayers = new LinkedHashSet<>();
|
||||
private final transient Map<String, IEssentialsCommand> commandMap = new HashMap<>();
|
||||
private final transient ProviderFactory providerFactory = new ProviderFactory(this);
|
||||
private transient ISettings settings;
|
||||
private transient Jails jails;
|
||||
private transient Warps warps;
|
||||
@@ -177,11 +165,27 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
private transient I18n i18n;
|
||||
private transient MetricsWrapper metrics;
|
||||
private transient EssentialsTimer timer;
|
||||
private transient SpawnerItemProvider spawnerItemProvider;
|
||||
private transient SpawnerBlockProvider spawnerBlockProvider;
|
||||
private transient SpawnEggProvider spawnEggProvider;
|
||||
private transient PotionMetaProvider potionMetaProvider;
|
||||
private transient ServerStateProvider serverStateProvider;
|
||||
private transient ContainerProvider containerProvider;
|
||||
private transient SerializationProvider serializationProvider;
|
||||
private transient KnownCommandsProvider knownCommandsProvider;
|
||||
private transient FormattedCommandAliasProvider formattedCommandAliasProvider;
|
||||
private transient ProviderListener recipeBookEventProvider;
|
||||
private transient MaterialTagProvider materialTagProvider;
|
||||
private transient SyncCommandsProvider syncCommandsProvider;
|
||||
private transient PersistentDataProvider persistentDataProvider;
|
||||
private transient ReflOnlineModeProvider onlineModeProvider;
|
||||
private transient ItemUnbreakableProvider unbreakableProvider;
|
||||
private transient WorldInfoProvider worldInfoProvider;
|
||||
private transient SignDataProvider signDataProvider;
|
||||
private transient Kits kits;
|
||||
private transient RandomTeleport randomTeleport;
|
||||
private transient UpdateChecker updateChecker;
|
||||
private transient BukkitAudiences bukkitAudience;
|
||||
private transient Map<String, IEssentialsCommand> commandMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
EconomyLayers.init();
|
||||
@@ -204,7 +208,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
}
|
||||
|
||||
public void setupForTesting(final Server server) throws IOException, InvalidDescriptionException {
|
||||
TESTING = true;
|
||||
LOGGER = new BaseLoggerProvider(this, BUKKIT_LOGGER);
|
||||
final File dataFolder = File.createTempFile("essentialstest", "");
|
||||
if (!dataFolder.delete()) {
|
||||
@@ -218,7 +221,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
i18n.updateLocale("en");
|
||||
Console.setInstance(this);
|
||||
|
||||
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("usingTempFolderForTesting")));
|
||||
LOGGER.log(Level.INFO, tl("usingTempFolderForTesting"));
|
||||
LOGGER.log(Level.INFO, dataFolder.toString());
|
||||
settings = new Settings(this);
|
||||
mail = new MailServiceImpl(this);
|
||||
@@ -230,7 +233,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
jails = new Jails(this);
|
||||
registerListeners(server.getPluginManager());
|
||||
kits = new Kits(this);
|
||||
bukkitAudience = BukkitAudiences.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -255,11 +257,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
execTimer = new ExecuteTimer();
|
||||
execTimer.start();
|
||||
|
||||
final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
|
||||
upgrade.upgradeLang();
|
||||
execTimer.mark("AdventureUpgrade");
|
||||
|
||||
i18n = new I18n(this);
|
||||
i18n.onEnable();
|
||||
execTimer.mark("I18n1");
|
||||
@@ -268,36 +265,37 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
switch (VersionUtil.getServerSupportStatus()) {
|
||||
case NMS_CLEANROOM:
|
||||
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedCleanroom")));
|
||||
getLogger().severe(tl("serverUnsupportedCleanroom"));
|
||||
break;
|
||||
case DANGEROUS_FORK:
|
||||
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedDangerous")));
|
||||
getLogger().severe(tl("serverUnsupportedDangerous"));
|
||||
break;
|
||||
case STUPID_PLUGIN:
|
||||
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedDumbPlugins")));
|
||||
getLogger().severe(tl("serverUnsupportedDumbPlugins"));
|
||||
break;
|
||||
case UNSTABLE:
|
||||
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedMods")));
|
||||
getLogger().severe(tl("serverUnsupportedMods"));
|
||||
break;
|
||||
case OUTDATED:
|
||||
getLogger().severe(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupported")));
|
||||
getLogger().severe(tl("serverUnsupported"));
|
||||
break;
|
||||
case LIMITED:
|
||||
getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedLimitedApi")));
|
||||
getLogger().info(tl("serverUnsupportedLimitedApi"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (VersionUtil.getSupportStatusClass() != null) {
|
||||
getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("serverUnsupportedClass", VersionUtil.getSupportStatusClass())));
|
||||
getLogger().info(tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass()));
|
||||
}
|
||||
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
for (final Plugin plugin : pm.getPlugins()) {
|
||||
if (plugin.getDescription().getName().startsWith("Essentials") && !plugin.getDescription().getVersion().equals(this.getDescription().getVersion()) && !plugin.getDescription().getName().equals("EssentialsAntiCheat")) {
|
||||
getLogger().warning(AdventureUtil.miniToLegacy(tlLiteral("versionMismatch", plugin.getDescription().getName())));
|
||||
getLogger().warning(tl("versionMismatch", plugin.getDescription().getName()));
|
||||
}
|
||||
}
|
||||
|
||||
final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
|
||||
upgrade.beforeSettings();
|
||||
execTimer.mark("Upgrade");
|
||||
|
||||
@@ -324,10 +322,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
upgrade.convertKits();
|
||||
execTimer.mark("Kits");
|
||||
|
||||
randomTeleport = new RandomTeleport(this);
|
||||
confList.add(randomTeleport);
|
||||
execTimer.mark("Init(RandomTeleport)");
|
||||
|
||||
upgrade.afterSettings();
|
||||
execTimer.mark("Upgrade3");
|
||||
|
||||
@@ -343,6 +337,13 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
confList.add(itemDb);
|
||||
execTimer.mark("Init(ItemDB)");
|
||||
|
||||
randomTeleport = new RandomTeleport(this);
|
||||
if (randomTeleport.getPreCache()) {
|
||||
randomTeleport.cacheRandomLocations(randomTeleport.getCenter(), randomTeleport.getMinRange(), randomTeleport.getMaxRange());
|
||||
}
|
||||
confList.add(randomTeleport);
|
||||
execTimer.mark("Init(RandomTeleport)");
|
||||
|
||||
customItemResolver = new CustomItemResolver(this);
|
||||
try {
|
||||
itemDb.registerResolver(this, "custom_items", customItemResolver);
|
||||
@@ -358,77 +359,44 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
execTimer.mark("Init(Jails)");
|
||||
|
||||
EconomyLayers.onEnable(this);
|
||||
execTimer.mark("Init(EconomyLayers)");
|
||||
|
||||
// Spawner item provider only uses one, but it's here for legacy...
|
||||
providerFactory.registerProvider(BlockMetaSpawnerItemProvider.class);
|
||||
//Spawner item provider only uses one but it's here for legacy...
|
||||
spawnerItemProvider = new BlockMetaSpawnerItemProvider();
|
||||
|
||||
// Spawner block providers
|
||||
providerFactory.registerProvider(ReflSpawnerBlockProvider.class, BukkitSpawnerBlockProvider.class);
|
||||
//Spawner block providers
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_12_0_R01)) {
|
||||
spawnerBlockProvider = new ReflSpawnerBlockProvider();
|
||||
} else {
|
||||
spawnerBlockProvider = new BukkitSpawnerBlockProvider();
|
||||
}
|
||||
|
||||
// Spawn Egg Providers
|
||||
providerFactory.registerProvider(LegacySpawnEggProvider.class, ReflSpawnEggProvider.class, FlatSpawnEggProvider.class);
|
||||
//Spawn Egg Providers
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
spawnEggProvider = new LegacySpawnEggProvider();
|
||||
} else if (VersionUtil.getServerBukkitVersion().isLowerThanOrEqualTo(VersionUtil.v1_12_2_R01)) {
|
||||
spawnEggProvider = new ReflSpawnEggProvider();
|
||||
} else {
|
||||
spawnEggProvider = new FlatSpawnEggProvider();
|
||||
}
|
||||
|
||||
//Potion Meta Provider
|
||||
providerFactory.registerProvider(PrehistoricPotionMetaProvider.class, LegacyPotionMetaProvider.class, ModernPotionMetaProvider.class);
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
potionMetaProvider = new LegacyPotionMetaProvider();
|
||||
} else {
|
||||
potionMetaProvider = new BasePotionDataProvider();
|
||||
}
|
||||
|
||||
//Banner Meta Provider
|
||||
providerFactory.registerProvider(LegacyBannerDataProvider.class, BaseBannerDataProvider.class);
|
||||
//Server State Provider
|
||||
//Container Provider
|
||||
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01)) {
|
||||
serverStateProvider = new PaperServerStateProvider();
|
||||
containerProvider = new PaperContainerProvider();
|
||||
serializationProvider = new PaperSerializationProvider();
|
||||
} else {
|
||||
serverStateProvider = new ReflServerStateProvider();
|
||||
}
|
||||
|
||||
// Server State Provider
|
||||
providerFactory.registerProvider(ReflServerStateProvider.class, PaperServerStateProvider.class);
|
||||
|
||||
// Container Provider
|
||||
providerFactory.registerProvider(PaperContainerProvider.class);
|
||||
|
||||
// Serialization Provider
|
||||
providerFactory.registerProvider(PaperSerializationProvider.class);
|
||||
|
||||
// Known Commands Provider
|
||||
providerFactory.registerProvider(ReflKnownCommandsProvider.class, PaperKnownCommandsProvider.class);
|
||||
|
||||
// Command Aliases Provider
|
||||
providerFactory.registerProvider(ReflFormattedCommandAliasProvider.class);
|
||||
|
||||
// Material Tag Providers
|
||||
providerFactory.registerProvider(BukkitMaterialTagProvider.class, PaperMaterialTagProvider.class);
|
||||
|
||||
// Sync Commands Provider
|
||||
providerFactory.registerProvider(ReflSyncCommandsProvider.class, ModernSyncCommandsProvider.class);
|
||||
|
||||
// Persistent Data Provider
|
||||
providerFactory.registerProvider(ReflPersistentDataProvider.class, ModernPersistentDataProvider.class);
|
||||
|
||||
// Online Mode Provider
|
||||
providerFactory.registerProvider(ReflOnlineModeProvider.class);
|
||||
|
||||
// Unbreakable Provider
|
||||
providerFactory.registerProvider(LegacyItemUnbreakableProvider.class, ModernItemUnbreakableProvider.class);
|
||||
|
||||
// World Info Provider
|
||||
providerFactory.registerProvider(FixedHeightWorldInfoProvider.class, ReflDataWorldInfoProvider.class, ModernDataWorldInfoProvider.class);
|
||||
|
||||
// Sign Data Provider
|
||||
providerFactory.registerProvider(ModernSignDataProvider.class);
|
||||
|
||||
// Player Locale Provider
|
||||
providerFactory.registerProvider(ModernPlayerLocaleProvider.class, LegacyPlayerLocaleProvider.class);
|
||||
|
||||
// Damage Event Provider
|
||||
providerFactory.registerProvider(ModernDamageEventProvider.class, LegacyDamageEventProvider.class);
|
||||
|
||||
// Inventory View Provider
|
||||
providerFactory.registerProvider(LegacyInventoryViewProvider.class, BaseInventoryViewProvider.class);
|
||||
|
||||
// Biome Key Provider
|
||||
providerFactory.registerProvider(PaperBiomeKeyProvider.class);
|
||||
|
||||
// Tick Count Provider
|
||||
providerFactory.registerProvider(PaperTickCountProvider.class);
|
||||
|
||||
providerFactory.finalizeRegistration();
|
||||
|
||||
// Event Providers
|
||||
//Event Providers
|
||||
if (PaperLib.isPaper()) {
|
||||
try {
|
||||
Class.forName("com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent");
|
||||
@@ -437,13 +405,54 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
((Cancellable) event).setCancelled(true);
|
||||
}
|
||||
});
|
||||
if (getSettings().isDebug()) {
|
||||
LOGGER.log(Level.INFO, "Registered Paper Recipe Book Event Listener");
|
||||
}
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
//Known Commands Provider
|
||||
if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01)) {
|
||||
knownCommandsProvider = new PaperKnownCommandsProvider();
|
||||
} else {
|
||||
knownCommandsProvider = new ReflKnownCommandsProvider();
|
||||
}
|
||||
|
||||
// Command aliases provider
|
||||
formattedCommandAliasProvider = new ReflFormattedCommandAliasProvider(PaperLib.isPaper());
|
||||
|
||||
// Material Tag Providers
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_13_0_R01)) {
|
||||
materialTagProvider = PaperLib.isPaper() ? new PaperMaterialTagProvider() : new BukkitMaterialTagProvider();
|
||||
}
|
||||
|
||||
// Sync Commands Provider
|
||||
syncCommandsProvider = new ReflSyncCommandsProvider();
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) {
|
||||
persistentDataProvider = new ModernPersistentDataProvider(this);
|
||||
} else {
|
||||
persistentDataProvider = new ReflPersistentDataProvider(this);
|
||||
}
|
||||
|
||||
onlineModeProvider = new ReflOnlineModeProvider();
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01)) {
|
||||
unbreakableProvider = new ModernItemUnbreakableProvider();
|
||||
} else {
|
||||
unbreakableProvider = new LegacyItemUnbreakableProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_17_1_R01)) {
|
||||
worldInfoProvider = new ModernDataWorldInfoProvider();
|
||||
} else if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_5_R01)) {
|
||||
worldInfoProvider = new ReflDataWorldInfoProvider();
|
||||
} else {
|
||||
worldInfoProvider = new FixedHeightWorldInfoProvider();
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) {
|
||||
signDataProvider = new ModernSignDataProvider(this);
|
||||
}
|
||||
|
||||
execTimer.mark("Init(Providers)");
|
||||
reload();
|
||||
|
||||
@@ -466,9 +475,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
updateChecker = new UpdateChecker(this);
|
||||
runTaskAsynchronously(() -> {
|
||||
getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("versionFetching")));
|
||||
for (final Component component : updateChecker.getVersionMessages(false, true, new CommandSource(this, Bukkit.getConsoleSender()))) {
|
||||
getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, AdventureUtil.adventureToLegacy(component));
|
||||
getLogger().log(Level.INFO, tl("versionFetching"));
|
||||
for (String str : updateChecker.getVersionMessages(false, true)) {
|
||||
getLogger().log(getSettings().isUpdateCheckEnabled() ? Level.WARNING : Level.INFO, str);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -547,22 +556,17 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
jails.resetListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProviderFactory getProviders() {
|
||||
return providerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
final boolean stopping = provider(ServerStateProvider.class).isStopping();
|
||||
final boolean stopping = getServerStateProvider().isStopping();
|
||||
if (!stopping) {
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading")));
|
||||
LOGGER.log(Level.SEVERE, tl("serverReloading"));
|
||||
}
|
||||
getBackup().setPendingShutdown(true);
|
||||
for (final User user : getOnlineUsers()) {
|
||||
if (user.isVanished()) {
|
||||
user.setVanished(false);
|
||||
user.sendTl("unvanishedReload");
|
||||
user.sendMessage(tl("unvanishedReload"));
|
||||
}
|
||||
if (stopping) {
|
||||
user.setLogoutLocation();
|
||||
@@ -576,7 +580,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
}
|
||||
cleanupOpenInventories();
|
||||
if (getBackup().getTaskLock() != null && !getBackup().getTaskLock().isDone()) {
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("backupInProgress")));
|
||||
LOGGER.log(Level.SEVERE, tl("backupInProgress"));
|
||||
getBackup().getTaskLock().join();
|
||||
}
|
||||
if (i18n != null) {
|
||||
@@ -599,11 +603,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
public void reload() {
|
||||
Trade.closeLog();
|
||||
|
||||
if (bukkitAudience != null) {
|
||||
bukkitAudience.close();
|
||||
bukkitAudience = null;
|
||||
}
|
||||
|
||||
for (final IConf iConf : confList) {
|
||||
iConf.reloadConfig();
|
||||
execTimer.mark("Reload(" + iConf.getClass().getSimpleName() + ")");
|
||||
@@ -613,16 +612,13 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
for (final String commandName : this.getDescription().getCommands().keySet()) {
|
||||
final Command command = this.getCommand(commandName);
|
||||
if (command != null) {
|
||||
command.setDescription(AdventureUtil.miniToLegacy(tlLiteral(commandName + "CommandDescription")));
|
||||
command.setUsage(AdventureUtil.miniToLegacy(tlLiteral(commandName + "CommandUsage")));
|
||||
command.setDescription(tl(commandName + "CommandDescription"));
|
||||
command.setUsage(tl(commandName + "CommandUsage"));
|
||||
}
|
||||
}
|
||||
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
registerListeners(pm);
|
||||
|
||||
AdventureUtil.setEss(this);
|
||||
bukkitAudience = BukkitAudiences.create(this);
|
||||
}
|
||||
|
||||
private IEssentialsCommand loadCommand(final String path, final String name, final IEssentialsModule module, final ClassLoader classLoader) throws Exception {
|
||||
@@ -671,13 +667,15 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
user = getUser((Player) cSender);
|
||||
}
|
||||
|
||||
final CommandSource sender = new CommandSource(this, cSender);
|
||||
final CommandSource sender = new CommandSource(cSender);
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel)) {
|
||||
final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
|
||||
if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this)) {
|
||||
return newCmd.tabComplete(cSender, commandLabel, args);
|
||||
if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel);
|
||||
if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) {
|
||||
return newCmd.tabComplete(cSender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -686,8 +684,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
try {
|
||||
cmd = loadCommand(commandPath, command.getName(), module, classLoader);
|
||||
} catch (final Exception ex) {
|
||||
sender.sendTl("commandNotLoaded", commandLabel);
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
|
||||
sender.sendMessage(tl("commandNotLoaded", commandLabel));
|
||||
LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -710,11 +708,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
} catch (final Exception ex) {
|
||||
showError(sender, ex, commandLabel);
|
||||
// Tab completion shouldn't fail
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
|
||||
LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} catch (final Throwable ex) {
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
|
||||
LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -739,12 +737,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
pc.execute(cSender, commandLabel, args);
|
||||
} catch (final Exception ex) {
|
||||
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
|
||||
if (cSender instanceof Player) {
|
||||
final PlayerLocaleProvider localeProvider = provider(PlayerLocaleProvider.class);
|
||||
getBukkitAudience().sender(cSender).sendMessage(AdventureUtil.miniMessage().deserialize(tlLocale(I18n.getLocale(localeProvider.getLocale((Player) cSender)), "internalError")));
|
||||
} else {
|
||||
cSender.sendMessage(tlLiteral("internalError"));
|
||||
}
|
||||
cSender.sendMessage(tl("internalError"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -769,7 +762,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
LOGGER.log(Level.INFO, cSender.getName()+ " issued server command: /" + commandLabel + " " + EssentialsCommand.getFinalArg(args, 0));
|
||||
}
|
||||
|
||||
final CommandSource sender = new CommandSource(this, cSender);
|
||||
final CommandSource sender = new CommandSource(cSender);
|
||||
|
||||
// New mail notification
|
||||
if (user != null && !getSettings().isCommandDisabled("mail") && !command.getName().equals("mail") && user.isAuthorized("essentials.mail")) {
|
||||
@@ -784,11 +777,13 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
// Check for disabled commands
|
||||
if (getSettings().isCommandDisabled(commandLabel)) {
|
||||
final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
|
||||
if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin()))) {
|
||||
return newCmd.execute(cSender, commandLabel, args);
|
||||
if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) {
|
||||
final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel);
|
||||
if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) {
|
||||
return newCmd.execute(cSender, commandLabel, args);
|
||||
}
|
||||
}
|
||||
sender.sendTl("commandDisabled", commandLabel);
|
||||
sender.sendMessage(tl("commandDisabled", commandLabel));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -796,23 +791,23 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
try {
|
||||
cmd = loadCommand(commandPath, command.getName(), module, classLoader);
|
||||
} catch (final Exception ex) {
|
||||
sender.sendTl("commandNotLoaded", commandLabel);
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandNotLoaded", commandLabel)), ex);
|
||||
sender.sendMessage(tl("commandNotLoaded", commandLabel));
|
||||
LOGGER.log(Level.SEVERE, tl("commandNotLoaded", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check authorization
|
||||
if (user != null && !user.isAuthorized(cmd, permissionPrefix)) {
|
||||
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("deniedAccessCommand", user.getName())));
|
||||
user.sendTl("noAccessCommand");
|
||||
LOGGER.log(Level.INFO, tl("deniedAccessCommand", user.getName()));
|
||||
user.sendMessage(tl("noAccessCommand"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (user != null && user.isJailed() && !user.isAuthorized(cmd, "essentials.jail.allow.")) {
|
||||
if (user.getJailTimeout() > 0) {
|
||||
user.sendTl("playerJailedFor", user.getName(), user.getFormattedJailTime());
|
||||
user.sendMessage(tl("playerJailedFor", user.getName(), user.getFormattedJailTime()));
|
||||
} else {
|
||||
user.sendTl("jailMessage");
|
||||
user.sendMessage(tl("jailMessage"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -829,22 +824,18 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return true;
|
||||
} catch (final NotEnoughArgumentsException ex) {
|
||||
if (getSettings().isVerboseCommandUsages() && !cmd.getUsageStrings().isEmpty()) {
|
||||
sender.sendTl("commandHelpLine1", commandLabel);
|
||||
String description = command.getDescription();
|
||||
try {
|
||||
description = sender.tl(command.getName() + "CommandDescription");
|
||||
} catch (MissingResourceException ignored) {}
|
||||
sender.sendTl("commandHelpLine2", description);
|
||||
sender.sendTl("commandHelpLine3");
|
||||
sender.sendMessage(tl("commandHelpLine1", commandLabel));
|
||||
sender.sendMessage(tl("commandHelpLine2", command.getDescription()));
|
||||
sender.sendMessage(tl("commandHelpLine3"));
|
||||
for (Map.Entry<String, String> usage : cmd.getUsageStrings().entrySet()) {
|
||||
sender.sendTl("commandHelpLineUsage", AdventureUtil.parsed(usage.getKey().replace("<command>", commandLabel)), AdventureUtil.parsed(usage.getValue()));
|
||||
sender.sendMessage(tl("commandHelpLineUsage", usage.getKey().replace("<command>", commandLabel), usage.getValue()));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(command.getDescription());
|
||||
sender.sendMessage(command.getUsage().replace("<command>", commandLabel));
|
||||
}
|
||||
if (!ex.getMessage().isEmpty()) {
|
||||
sender.sendComponent(AdventureUtil.miniMessage().deserialize(ex.getMessage()));
|
||||
sender.sendMessage(ex.getMessage());
|
||||
}
|
||||
if (ex.getCause() != null && settings.isDebug()) {
|
||||
ex.getCause().printStackTrace();
|
||||
@@ -858,7 +849,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return true;
|
||||
}
|
||||
} catch (final Throwable ex) {
|
||||
LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("commandFailed", commandLabel)), ex);
|
||||
LOGGER.log(Level.SEVERE, tl("commandFailed", commandLabel), ex);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -868,17 +859,14 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
}
|
||||
|
||||
public void cleanupOpenInventories() {
|
||||
final InventoryViewProvider provider = provider(InventoryViewProvider.class);
|
||||
for (final User user : getOnlineUsers()) {
|
||||
if (user.isRecipeSee()) {
|
||||
final InventoryView view = user.getBase().getOpenInventory();
|
||||
|
||||
provider.getTopInventory(view).clear();
|
||||
provider.close(view);
|
||||
user.getBase().getOpenInventory().getTopInventory().clear();
|
||||
user.getBase().getOpenInventory().close();
|
||||
user.setRecipeSee(false);
|
||||
}
|
||||
if (user.isInvSee() || user.isEnderSee()) {
|
||||
provider.close(user.getBase().getOpenInventory());
|
||||
user.getBase().getOpenInventory().close();
|
||||
user.setInvSee(false);
|
||||
user.setEnderSee(false);
|
||||
}
|
||||
@@ -887,14 +875,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
@Override
|
||||
public void showError(final CommandSource sender, final Throwable exception, final String commandLabel) {
|
||||
if (exception instanceof TranslatableException) {
|
||||
final String tlMessage = sender.tl(((TranslatableException) exception).getTlKey(), ((TranslatableException) exception).getArgs());
|
||||
sender.sendTl("errorWithMessage", AdventureUtil.parsed(tlMessage));
|
||||
} else {
|
||||
sender.sendTl("errorWithMessage", exception.getMessage());
|
||||
}
|
||||
sender.sendMessage(tl("errorWithMessage", exception.getMessage()));
|
||||
if (getSettings().isDebug()) {
|
||||
LOGGER.log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("errorCallingCommand", commandLabel)), exception);
|
||||
LOGGER.log(Level.INFO, tl("errorCallingCommand", commandLabel), exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,7 +954,17 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
//This will return null if there is not a match.
|
||||
@Override
|
||||
public User getOfflineUser(final String name) {
|
||||
return userMap.getUser(name);
|
||||
final User user = userMap.getUser(name);
|
||||
if (user != null && user.getBase() instanceof OfflinePlayer) {
|
||||
//This code should attempt to use the last known name of a user, if Bukkit returns name as null.
|
||||
final String lastName = user.getLastAccountName();
|
||||
if (lastName != null) {
|
||||
((OfflinePlayer) user.getBase()).setName(lastName);
|
||||
} else {
|
||||
((OfflinePlayer) user.getBase()).setName(name);
|
||||
}
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1059,7 +1052,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !interactee.isHiddenFrom(interactor.getBase());
|
||||
return interactor.getBase().canSee(interactee.getBase());
|
||||
}
|
||||
|
||||
//This will create a new user if there is not a match.
|
||||
@@ -1074,9 +1067,19 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return null;
|
||||
}
|
||||
|
||||
final User user = userMap.getUser(base);
|
||||
User user = userMap.getUser(base.getUniqueId());
|
||||
|
||||
if (base.getClass() != UUIDPlayer.class || user.getBase() == null) {
|
||||
if (user == null) {
|
||||
if (getSettings().isDebug()) {
|
||||
LOGGER.log(Level.INFO, "Constructing new userfile from base player " + base.getName());
|
||||
}
|
||||
user = userMap.loadUncachedUser(base);
|
||||
|
||||
// The above method will end up creating a new user, but it will not be added to the cache.
|
||||
// Since we already call UserMap#getUser() above, we are already okay with adding the user to the cache,
|
||||
// so we need to manually add the user to the cache in order to avoid a memory leak and maintain behavior.
|
||||
userMap.addCachedUser(user);
|
||||
} else {
|
||||
user.update(base);
|
||||
}
|
||||
return user;
|
||||
@@ -1084,7 +1087,8 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
private void handleCrash(final Throwable exception) {
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
getWrappedLogger().log(Level.SEVERE, exception.toString(), exception);
|
||||
LOGGER.log(Level.SEVERE, exception.toString());
|
||||
exception.printStackTrace();
|
||||
pm.registerEvents(new Listener() {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
@@ -1115,12 +1119,12 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
@Override
|
||||
public int broadcastMessage(final String message) {
|
||||
return broadcastMessage(null, null, message, true, null);
|
||||
return broadcastMessage(null, null, message, true, u -> false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int broadcastMessage(final IUser sender, final String message) {
|
||||
return broadcastMessage(sender, null, message, false, null);
|
||||
return broadcastMessage(sender, null, message, false, u -> false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1130,7 +1134,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
|
||||
@Override
|
||||
public int broadcastMessage(final String permission, final String message) {
|
||||
return broadcastMessage(null, permission, message, false, null);
|
||||
return broadcastMessage(null, permission, message, false, u -> false);
|
||||
}
|
||||
|
||||
private int broadcastMessage(final IUser sender, final String permission, final String message, final boolean keywords, final Predicate<IUser> shouldExclude) {
|
||||
@@ -1144,11 +1148,11 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
for (final Player player : players) {
|
||||
final User user = getUser(player);
|
||||
if ((permission == null && (sender == null || !user.isIgnoredPlayer(sender))) || (permission != null && user.isAuthorized(permission))) {
|
||||
if (shouldExclude != null && shouldExclude.test(user)) {
|
||||
if (shouldExclude.test(user)) {
|
||||
continue;
|
||||
}
|
||||
if (keywords) {
|
||||
broadcast = new KeywordReplacer(broadcast, new CommandSource(this, player), this, false);
|
||||
broadcast = new KeywordReplacer(broadcast, new CommandSource(player), this, false);
|
||||
}
|
||||
for (final String messageText : broadcast.getLines()) {
|
||||
user.sendMessage(messageText);
|
||||
@@ -1159,52 +1163,6 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return players.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastTl(final String tlKey, final Object... args) {
|
||||
broadcastTl(null, null, false, tlKey, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastTl(final IUser sender, final String tlKey, final Object... args) {
|
||||
broadcastTl(sender, null, false, tlKey, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastTl(final IUser sender, final String permission, final String tlKey, final Object... args) {
|
||||
broadcastTl(sender, u -> !u.isAuthorized(permission), false, tlKey, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlKey, Object... args) {
|
||||
broadcastTl(sender, shouldExclude, false, tlKey, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcastTl(final IUser sender, final Predicate<IUser> shouldExclude, final boolean parseKeywords, final String tlKey, final Object... args) {
|
||||
if (sender != null && sender.isHidden()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final User user : getOnlineUsers()) {
|
||||
if (sender != null && user.isIgnoredPlayer(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (shouldExclude != null && shouldExclude.test(user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final Object[] processedArgs;
|
||||
if (parseKeywords) {
|
||||
processedArgs = I18n.mutateArgs(args, s -> new KeywordReplacer(new SimpleTextInput(s.toString()), new CommandSource(this, user.getBase()), this, false).getLines().get(0));
|
||||
} else {
|
||||
processedArgs = args;
|
||||
}
|
||||
|
||||
user.sendTl(tlKey, processedArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitTask runTaskAsynchronously(final Runnable run) {
|
||||
return this.getScheduler().runTaskAsynchronously(this, run);
|
||||
@@ -1305,18 +1263,93 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
|
||||
return onlineUsers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerItemProvider getSpawnerItemProvider() {
|
||||
return spawnerItemProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnerBlockProvider getSpawnerBlockProvider() {
|
||||
return spawnerBlockProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpawnEggProvider getSpawnEggProvider() {
|
||||
return spawnEggProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionMetaProvider getPotionMetaProvider() {
|
||||
return potionMetaProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomItemResolver getCustomItemResolver() {
|
||||
return customItemResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginCommand getPluginCommand(final String cmd) {
|
||||
return this.getCommand(cmd);
|
||||
public ServerStateProvider getServerStateProvider() {
|
||||
return serverStateProvider;
|
||||
}
|
||||
|
||||
public BukkitAudiences getBukkitAudience() {
|
||||
return bukkitAudience;
|
||||
public MaterialTagProvider getMaterialTagProvider() {
|
||||
return materialTagProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContainerProvider getContainerProvider() {
|
||||
return containerProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnownCommandsProvider getKnownCommandsProvider() {
|
||||
return knownCommandsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerializationProvider getSerializationProvider() {
|
||||
return serializationProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FormattedCommandAliasProvider getFormattedCommandAliasProvider() {
|
||||
return formattedCommandAliasProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyncCommandsProvider getSyncCommandsProvider() {
|
||||
return syncCommandsProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentDataProvider getPersistentDataProvider() {
|
||||
return persistentDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReflOnlineModeProvider getOnlineModeProvider() {
|
||||
return onlineModeProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUnbreakableProvider getItemUnbreakableProvider() {
|
||||
return unbreakableProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldInfoProvider getWorldInfoProvider() {
|
||||
return worldInfoProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignDataProvider getSignDataProvider() {
|
||||
return signDataProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginCommand getPluginCommand(final String cmd) {
|
||||
return this.getCommand(cmd);
|
||||
}
|
||||
|
||||
private AbstractItemDb getItemDbFromConfig() {
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@@ -28,11 +26,11 @@ public class EssentialsBlockListener implements Listener {
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
final ItemStack is = event.getItemInHand();
|
||||
|
||||
if (is.getType() == MaterialUtil.SPAWNER && ess.provider(PersistentDataProvider.class).getString(is, "convert") != null) {
|
||||
if (is.getType() == MaterialUtil.SPAWNER && ess.getPersistentDataProvider().getString(is, "convert") != null) {
|
||||
final BlockState blockState = event.getBlockPlaced().getState();
|
||||
if (blockState instanceof CreatureSpawner) {
|
||||
final CreatureSpawner spawner = (CreatureSpawner) blockState;
|
||||
final EntityType type = ess.provider(SpawnerItemProvider.class).getEntityType(event.getItemInHand());
|
||||
final EntityType type = ess.getSpawnerItemProvider().getEntityType(event.getItemInHand());
|
||||
if (type != null && Mob.fromBukkitType(type) != null) {
|
||||
if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) {
|
||||
spawner.setSpawnedType(type);
|
||||
|
||||
@@ -32,6 +32,8 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class EssentialsEntityListener implements Listener {
|
||||
private static final transient Pattern powertoolPlayer = Pattern.compile("\\{player\\}");
|
||||
private final IEssentials ess;
|
||||
@@ -165,11 +167,11 @@ public class EssentialsEntityListener implements Listener {
|
||||
final User user = ess.getUser(event.getEntity());
|
||||
if (ess.getSettings().infoAfterDeath()) {
|
||||
final Location loc = user.getLocation();
|
||||
user.sendTl("infoAfterDeath", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
user.sendMessage(tl("infoAfterDeath", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
if (user.isAuthorized("essentials.back.ondeath") && !ess.getSettings().isCommandDisabled("back")) {
|
||||
user.setLastLocation();
|
||||
user.sendTl("backAfterDeath");
|
||||
user.sendMessage(tl("backAfterDeath"));
|
||||
}
|
||||
if (!ess.getSettings().areDeathMessagesEnabled()) {
|
||||
event.setDeathMessage("");
|
||||
@@ -190,15 +192,7 @@ public class EssentialsEntityListener implements Listener {
|
||||
final User user = ess.getUser(event.getEntity());
|
||||
if (user.isAuthorized("essentials.keepinv")) {
|
||||
event.setKeepInventory(true);
|
||||
// We don't do getDrops().clear() here because it would remove any loot tables that were added by other plugins/datapacks.
|
||||
// Instead, we remove the items from the drops that are in the player's inventory. This way, the loot tables can still drop items.
|
||||
// This is the same behavior as the vanilla /gamerule keepInventory.
|
||||
final ItemStack[] inventory = Inventories.getInventory(event.getEntity(), true);
|
||||
for (final ItemStack item : inventory) {
|
||||
if (item != null) {
|
||||
event.getDrops().remove(item);
|
||||
}
|
||||
}
|
||||
event.getDrops().clear();
|
||||
final ISettings.KeepInvPolicy vanish = ess.getSettings().getVanishingItemsPolicy();
|
||||
final ISettings.KeepInvPolicy bind = ess.getSettings().getBindingItemsPolicy();
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01) && (vanish != ISettings.KeepInvPolicy.KEEP || bind != ISettings.KeepInvPolicy.KEEP)) {
|
||||
|
||||
@@ -6,8 +6,6 @@ import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.TextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.CommonPlaceholders;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
@@ -17,14 +15,9 @@ import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.provider.CommandSendListenerProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.InventoryViewProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.TickCountProvider;
|
||||
import net.ess3.provider.providers.BukkitCommandSendListenerProvider;
|
||||
import net.ess3.provider.providers.PaperCommandSendListenerProvider;
|
||||
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.BanEntry;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.GameMode;
|
||||
@@ -69,6 +62,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -81,7 +75,7 @@ import java.util.function.Predicate;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
private final transient IEssentials ess;
|
||||
@@ -179,20 +173,12 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
final String dateDiff = user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : null;
|
||||
if (dateDiff == null) {
|
||||
if (user.hasMuteReason()) {
|
||||
user.sendTl("voiceSilencedReason", user.getMuteReason());
|
||||
} else {
|
||||
user.sendTl("voiceSilenced");
|
||||
}
|
||||
user.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced"));
|
||||
} else {
|
||||
if (user.hasMuteReason()) {
|
||||
user.sendTl("voiceSilencedReasonTime", dateDiff, user.getMuteReason());
|
||||
} else {
|
||||
user.sendTl("voiceSilencedTime", dateDiff);
|
||||
}
|
||||
user.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
||||
}
|
||||
|
||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("mutedUserSpeaks", user.getName(), event.getMessage())));
|
||||
ess.getLogger().info(tl("mutedUserSpeaks", user.getName(), event.getMessage()));
|
||||
}
|
||||
try {
|
||||
final Iterator<Player> it = event.getRecipients().iterator();
|
||||
@@ -284,7 +270,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
final String msg = ess.getSettings().getCustomQuitMessage()
|
||||
.replace("{PLAYER}", player.getDisplayName())
|
||||
.replace("{USERNAME}", player.getName())
|
||||
.replace("{ONLINE}", NumberFormat.getInstance().format(ess.getOnlinePlayers().size() - 1)) // Subtract 1 as the leaving player is still online during this time
|
||||
.replace("{ONLINE}", NumberFormat.getInstance().format(ess.getOnlinePlayers().size()))
|
||||
.replace("{UPTIME}", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()))
|
||||
.replace("{PREFIX}", FormatUtil.replaceFormat(ess.getPermissionsHandler().getPrefix(player)))
|
||||
.replace("{SUFFIX}", FormatUtil.replaceFormat(ess.getPermissionsHandler().getSuffix(player)));
|
||||
@@ -302,7 +288,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
}
|
||||
user.setLogoutLocation();
|
||||
if (user.isRecipeSee()) {
|
||||
ess.provider(InventoryViewProvider.class).getTopInventory(user.getBase().getOpenInventory()).clear();
|
||||
user.getBase().getOpenInventory().getTopInventory().clear();
|
||||
}
|
||||
|
||||
final ArrayList<HumanEntity> viewers = new ArrayList<>(user.getBase().getInventory().getViewers());
|
||||
@@ -437,7 +423,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
if (!ess.getSettings().isCommandDisabled("mail") && user.isAuthorized("essentials.mail")) {
|
||||
if (user.getUnreadMailAmount() == 0) {
|
||||
if (ess.getSettings().isNotifyNoNewMail()) {
|
||||
user.sendTl("noNewMail"); // Only notify if they want us to.
|
||||
user.sendMessage(tl("noNewMail")); // Only notify if they want us to.
|
||||
}
|
||||
} else {
|
||||
user.notifyOfMail();
|
||||
@@ -446,8 +432,8 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
if (user.isAuthorized("essentials.updatecheck")) {
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
for (final Component component : ess.getUpdateChecker().getVersionMessages(false, false, user.getSource())) {
|
||||
user.sendComponent(component);
|
||||
for (String str : ess.getUpdateChecker().getVersionMessages(false, false)) {
|
||||
user.sendMessage(str);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -458,7 +444,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
user.getBase().setAllowFlight(true);
|
||||
user.getBase().setFlying(true);
|
||||
if (ess.getSettings().isSendFlyEnableOnJoin()) {
|
||||
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), true), user.getDisplayName());
|
||||
user.getBase().sendMessage(tl("flyMode", tl("enabled"), user.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,14 +534,14 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
final Date banExpiry = banEntry.getExpiration();
|
||||
if (banExpiry != null) {
|
||||
final String expiry = DateUtil.formatDateDiff(banExpiry.getTime());
|
||||
event.setKickMessage(AdventureUtil.miniToLegacy(tlLiteral("tempbanJoin", expiry, banEntry.getReason())));
|
||||
event.setKickMessage(tl("tempbanJoin", expiry, banEntry.getReason()));
|
||||
} else {
|
||||
event.setKickMessage(AdventureUtil.miniToLegacy(tlLiteral("banJoin", banEntry.getReason())));
|
||||
event.setKickMessage(tl("banJoin", banEntry.getReason()));
|
||||
}
|
||||
} else {
|
||||
banEntry = ess.getServer().getBanList(BanList.Type.IP).getBanEntry(event.getAddress().getHostAddress());
|
||||
if (banEntry != null) {
|
||||
event.setKickMessage(AdventureUtil.miniToLegacy(tlLiteral("banIpJoin", banEntry.getReason())));
|
||||
event.setKickMessage(tl("banIpJoin", banEntry.getReason()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -571,7 +557,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
return;
|
||||
}
|
||||
if (ess.getSettings().isCustomServerFullMessage()) {
|
||||
event.disallow(Result.KICK_FULL, tlLiteral("serverFull"));
|
||||
event.disallow(Result.KICK_FULL, tl("serverFull"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -589,21 +575,6 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
if (ess.getSettings().isTeleportInvulnerability()) {
|
||||
user.enableInvulnerabilityAfterTeleport();
|
||||
}
|
||||
|
||||
// Mitigation for https://github.com/EssentialsX/Essentials/issues/4325
|
||||
final TickCountProvider tickCountProvider = ess.provider(TickCountProvider.class);
|
||||
if (tickCountProvider != null && ess.getSettings().isWorldChangePreserveFlying() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_17_R01)) {
|
||||
if (user.isAuthorized("essentials.fly")) {
|
||||
//noinspection DataFlowIssue - not real
|
||||
if (event.getFrom().getWorld() != event.getTo().getWorld() && player.getAllowFlight()) {
|
||||
// If the player is not flying but has the ability to fly, we set the sign of the tick count to -1
|
||||
// Later on in the PlayerChangedWorldEvent, we will set the player's flying state to true if the tick count is positive.
|
||||
// If the tick count is negative, we simply just set the player's flight ability to true.
|
||||
final int tick = player.isFlying() ? tickCountProvider.getTickCount() : -tickCountProvider.getTickCount();
|
||||
user.setFlightTick(tick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
@@ -627,17 +598,17 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
final String cmd = event.getMessage().split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final String cmd = event.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final int argStartIndex = event.getMessage().indexOf(" ");
|
||||
final String args = argStartIndex == -1 ? "" // No arguments present
|
||||
: event.getMessage().substring(argStartIndex); // arguments start at argStartIndex; substring from there.
|
||||
|
||||
// If the plugin command does not exist, check if it is an alias from commands.yml
|
||||
if (ess.getServer().getPluginCommand(cmd) == null) {
|
||||
final Command knownCommand = ess.provider(KnownCommandsProvider.class).getKnownCommands().get(cmd);
|
||||
final Command knownCommand = ess.getKnownCommandsProvider().getKnownCommands().get(cmd);
|
||||
if (knownCommand instanceof FormattedCommandAlias) {
|
||||
final FormattedCommandAlias command = (FormattedCommandAlias) knownCommand;
|
||||
for (String fullCommand : ess.provider(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) {
|
||||
for (String fullCommand : ess.getFormattedCommandAliasProvider().createCommands(command, event.getPlayer(), args.split(" "))) {
|
||||
handlePlayerCommandPreprocess(event, fullCommand);
|
||||
}
|
||||
return;
|
||||
@@ -650,7 +621,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
public void handlePlayerCommandPreprocess(final PlayerCommandPreprocessEvent event, final String effectiveCommand) {
|
||||
final Player player = event.getPlayer();
|
||||
final String cmd = effectiveCommand.split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final String cmd = effectiveCommand.toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final PluginCommand pluginCommand = ess.getServer().getPluginCommand(cmd);
|
||||
|
||||
if (ess.getSettings().getSocialSpyCommands().contains(cmd) || ess.getSettings().getSocialSpyCommands().contains("*")) {
|
||||
@@ -658,13 +629,13 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|| (!pluginCommand.getName().equals("msg") && !pluginCommand.getName().equals("r"))) { // /msg and /r are handled in SimpleMessageRecipient
|
||||
final User user = ess.getUser(player);
|
||||
if (!user.isAuthorized("essentials.chat.spy.exempt")) {
|
||||
final String playerName = ess.getSettings().isSocialSpyDisplayNames() ? player.getDisplayName() : player.getName();
|
||||
for (final User spyer : ess.getOnlineUsers()) {
|
||||
if (spyer.isSocialSpyEnabled() && !player.equals(spyer.getBase())) {
|
||||
final Component base = (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers())
|
||||
? spyer.tlComponent("socialSpyMutedPrefix")
|
||||
: spyer.tlComponent("socialSpyPrefix");
|
||||
spyer.sendComponent(base.append(AdventureUtil.legacyToAdventure(playerName)).append(Component.text(": " + event.getMessage())));
|
||||
if (user.isMuted() && ess.getSettings().getSocialSpyListenMutedPlayers()) {
|
||||
spyer.sendMessage(tl("socialSpyMutedPrefix") + player.getDisplayName() + ": " + event.getMessage());
|
||||
} else {
|
||||
spyer.sendMessage(tl("socialSpyPrefix") + player.getDisplayName() + ": " + event.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,19 +647,11 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
event.setCancelled(true);
|
||||
final String dateDiff = user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : null;
|
||||
if (dateDiff == null) {
|
||||
if (user.hasMuteReason()) {
|
||||
user.sendTl("voiceSilencedReason", user.getMuteReason());
|
||||
} else {
|
||||
user.sendTl("voiceSilenced");
|
||||
}
|
||||
player.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced"));
|
||||
} else {
|
||||
if (user.hasMuteReason()) {
|
||||
user.sendTl("voiceSilencedReasonTime", dateDiff, user.getMuteReason());
|
||||
} else {
|
||||
user.sendTl("voiceSilencedTime", dateDiff);
|
||||
}
|
||||
player.sendMessage(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
||||
}
|
||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("mutedUserSpeaks", player.getName(), event.getMessage())));
|
||||
ess.getLogger().info(tl("mutedUserSpeaks", player.getName(), event.getMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -723,17 +686,21 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
// If so, no need to check for (and write) new ones.
|
||||
boolean cooldownFound = false;
|
||||
|
||||
for (final Entry<Pattern, Long> entry : user.getCommandCooldowns().entrySet()) {
|
||||
// Iterate over a copy of getCommandCooldowns in case of concurrent modifications
|
||||
for (final Entry<Pattern, Long> entry : new HashMap<>(user.getCommandCooldowns()).entrySet()) {
|
||||
// Remove any expired cooldowns
|
||||
if (entry.getValue() <= System.currentTimeMillis()) {
|
||||
user.clearCommandCooldown(entry.getKey());
|
||||
// Don't break in case there are other command cooldowns left to clear.
|
||||
} else if (entry.getKey().matcher(fullCommand).matches()) {
|
||||
// User's current cooldown hasn't expired, inform and terminate cooldown code.
|
||||
final String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue());
|
||||
user.sendTl("commandCooldown", commandCooldownTime);
|
||||
cooldownFound = true;
|
||||
event.setCancelled(true);
|
||||
if (entry.getValue() > System.currentTimeMillis()) {
|
||||
final String commandCooldownTime = DateUtil.formatDateDiff(entry.getValue());
|
||||
user.sendMessage(tl("commandCooldown", commandCooldownTime));
|
||||
cooldownFound = true;
|
||||
event.setCancelled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,7 +724,8 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
|
||||
if (ess.getSettings().isWorldChangeFlyResetEnabled()) {
|
||||
if (user.getBase().getGameMode() != GameMode.CREATIVE
|
||||
&& user.getBase().getGameMode() != GameMode.SPECTATOR
|
||||
// COMPAT: String compare for 1.7.10
|
||||
&& !user.getBase().getGameMode().name().equals("SPECTATOR")
|
||||
&& !user.isAuthorized("essentials.fly")) {
|
||||
user.getBase().setFallDistance(0f);
|
||||
user.getBase().setAllowFlight(false);
|
||||
@@ -780,16 +748,6 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final TickCountProvider tickCountProvider = ess.provider(TickCountProvider.class);
|
||||
final int flightTick = user.getFlightTick();
|
||||
if (tickCountProvider != null && Math.abs(flightTick) == tickCountProvider.getTickCount() && user.isAuthorized("essentials.fly")) {
|
||||
user.getBase().setAllowFlight(true);
|
||||
if (flightTick > 0) {
|
||||
user.getBase().setFlying(true);
|
||||
}
|
||||
}
|
||||
user.setFlightTick(-1);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@@ -801,11 +759,11 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
if (ess.getSettings().getNoGodWorlds().contains(newWorld) && user.isGodModeEnabledRaw()) {
|
||||
// Player god mode is never disabled in order to retain it when changing worlds once more.
|
||||
// With that said, players will still take damage as per the result of User#isGodModeEnabled()
|
||||
user.sendTl("noGodWorldWarning");
|
||||
user.sendMessage(tl("noGodWorldWarning"));
|
||||
}
|
||||
|
||||
if (!user.getWorld().getName().equals(newWorld)) {
|
||||
user.sendTl("currentWorld", newWorld);
|
||||
user.sendMessage(tl("currentWorld", newWorld));
|
||||
}
|
||||
if (user.isVanished()) {
|
||||
user.setVanished(user.isAuthorized("essentials.vanish"));
|
||||
@@ -827,7 +785,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
player.getBase().setBedSpawnLocation(event.getClickedBlock().getLocation());
|
||||
// In 1.15 and above, vanilla sends its own bed spawn message.
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_15_R01)) {
|
||||
player.sendTl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
player.sendMessage(tl("bedSet", player.getLocation().getWorld().getName(), player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -920,15 +878,14 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onInventoryClickEvent(final InventoryClickEvent event) {
|
||||
Player refreshPlayer = null;
|
||||
final InventoryViewProvider provider = ess.provider(InventoryViewProvider.class);
|
||||
final Inventory top = provider.getTopInventory(event.getView());
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
|
||||
final Inventory clickedInventory;
|
||||
if (event.getRawSlot() < 0) {
|
||||
clickedInventory = null;
|
||||
} else {
|
||||
clickedInventory = event.getRawSlot() < top.getSize() ? top : provider.getBottomInventory(event.getView());
|
||||
clickedInventory = event.getRawSlot() < top.getSize() ? top : event.getView().getBottomInventory();
|
||||
}
|
||||
|
||||
final User user = ess.getUser((Player) event.getWhoClicked());
|
||||
@@ -987,8 +944,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onInventoryCloseEvent(final InventoryCloseEvent event) {
|
||||
Player refreshPlayer = null;
|
||||
final InventoryViewProvider provider = ess.provider(InventoryViewProvider.class);
|
||||
final Inventory top = provider.getTopInventory(event.getView());
|
||||
final Inventory top = event.getView().getTopInventory();
|
||||
final InventoryType type = top.getType();
|
||||
if (type == InventoryType.PLAYER) {
|
||||
final User user = ess.getUser((Player) event.getPlayer());
|
||||
@@ -1002,7 +958,7 @@ public class EssentialsPlayerListener implements Listener, FakeAccessor {
|
||||
final User user = ess.getUser((Player) event.getPlayer());
|
||||
if (user.isRecipeSee()) {
|
||||
user.setRecipeSee(false);
|
||||
provider.getTopInventory(event.getView()).clear();
|
||||
event.getView().getTopInventory().clear();
|
||||
refreshPlayer = user.getBase();
|
||||
}
|
||||
} else if (type == InventoryType.CHEST && top.getSize() == 9) {
|
||||
|
||||
@@ -3,17 +3,14 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.config.EssentialsUserConfiguration;
|
||||
import com.earth2me.essentials.config.entities.LazyLocation;
|
||||
import com.earth2me.essentials.craftbukkit.BanLookup;
|
||||
import com.earth2me.essentials.userstorage.ModernUUIDCache;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||
import nu.studer.java.util.OrderedProperties;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -52,7 +49,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class EssentialsUpgrade {
|
||||
public static final FileFilter YML_FILTER = pathname -> pathname.isFile() && pathname.getName().endsWith(".yml");
|
||||
@@ -157,41 +154,6 @@ public class EssentialsUpgrade {
|
||||
ess.getLogger().info("To rerun the conversion type /essentials uuidconvert");
|
||||
}
|
||||
|
||||
public void updateRandomTeleport() {
|
||||
if (doneFile.getBoolean("updateRandomTeleport", false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EssentialsConfiguration config = ess.getRandomTeleport().getConfig();
|
||||
|
||||
if (config.getRootNode() != null) {
|
||||
final LazyLocation center = config.getLocation("center");
|
||||
final Location centerLoc = center != null ? center.location() : null;
|
||||
if (center != null && centerLoc != null) {
|
||||
final double minRange = config.getDouble("min-range", Double.MIN_VALUE);
|
||||
final double maxRange = config.getDouble("max-range", Double.MIN_VALUE);
|
||||
for (final World world : ess.getServer().getWorlds()) {
|
||||
final String propPrefix = "locations." + world.getName() + ".";
|
||||
config.setProperty(propPrefix + "center", centerLoc);
|
||||
|
||||
if (minRange != Double.MIN_VALUE) {
|
||||
config.setProperty(propPrefix + "min-range", minRange);
|
||||
}
|
||||
if (maxRange != Double.MIN_VALUE) {
|
||||
config.setProperty(propPrefix + "max-range", maxRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
config.removeProperty("center");
|
||||
|
||||
config.blockingSave();
|
||||
}
|
||||
|
||||
doneFile.setProperty("updateRandomTeleport", true);
|
||||
doneFile.save();
|
||||
ess.getLogger().info("Done converting random teleport config.");
|
||||
}
|
||||
|
||||
public void convertMailList() {
|
||||
if (doneFile.getBoolean("updateUsersMailList", false)) {
|
||||
return;
|
||||
@@ -531,7 +493,7 @@ public class EssentialsUpgrade {
|
||||
doneFile.setProperty("move" + name + "ToFile", true);
|
||||
doneFile.save();
|
||||
} catch (final IOException e) {
|
||||
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("upgradingFilesError")), e);
|
||||
ess.getLogger().log(Level.SEVERE, tl("upgradingFilesError"), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -566,10 +528,10 @@ public class EssentialsUpgrade {
|
||||
bWriter.close();
|
||||
if (needUpdate) {
|
||||
if (!file.renameTo(new File(file.getParentFile(), file.getName().concat("." + System.currentTimeMillis() + ".upgradebackup")))) {
|
||||
throw new Exception(tlLiteral("configFileMoveError"));
|
||||
throw new Exception(tl("configFileMoveError"));
|
||||
}
|
||||
if (!tempFile.renameTo(file)) {
|
||||
throw new Exception(tlLiteral("configFileRenameError"));
|
||||
throw new Exception(tl("configFileRenameError"));
|
||||
}
|
||||
} else {
|
||||
tempFile.delete();
|
||||
@@ -694,15 +656,15 @@ public class EssentialsUpgrade {
|
||||
final File tmpFile = new File(listOfFile.getParentFile(), sanitizedFilename + ".tmp");
|
||||
final File newFile = new File(listOfFile.getParentFile(), sanitizedFilename);
|
||||
if (!listOfFile.renameTo(tmpFile)) {
|
||||
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("userdataMoveError", filename, sanitizedFilename)));
|
||||
ess.getLogger().log(Level.WARNING, tl("userdataMoveError", filename, sanitizedFilename));
|
||||
continue;
|
||||
}
|
||||
if (newFile.exists()) {
|
||||
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("duplicatedUserdata", filename, sanitizedFilename)));
|
||||
ess.getLogger().log(Level.WARNING, tl("duplicatedUserdata", filename, sanitizedFilename));
|
||||
continue;
|
||||
}
|
||||
if (!tmpFile.renameTo(newFile)) {
|
||||
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("userdataMoveBackError", sanitizedFilename, sanitizedFilename)));
|
||||
ess.getLogger().log(Level.WARNING, tl("userdataMoveBackError", sanitizedFilename, sanitizedFilename));
|
||||
}
|
||||
}
|
||||
doneFile.setProperty("sanitizeAllUserFilenames", true);
|
||||
@@ -780,7 +742,7 @@ public class EssentialsUpgrade {
|
||||
config.setProperty(entry.getKey(), loc);
|
||||
}
|
||||
if (!configFile.renameTo(new File(ess.getDataFolder(), "spawn.yml.old"))) {
|
||||
throw new Exception(tlLiteral("fileRenameError", "spawn.yml"));
|
||||
throw new Exception(tl("fileRenameError", "spawn.yml"));
|
||||
}
|
||||
config.blockingSave();
|
||||
}
|
||||
@@ -808,7 +770,7 @@ public class EssentialsUpgrade {
|
||||
config.setProperty(entry.getKey(), loc);
|
||||
}
|
||||
if (!configFile.renameTo(new File(ess.getDataFolder(), "jail.yml.old"))) {
|
||||
throw new Exception(tlLiteral("fileRenameError", "jail.yml"));
|
||||
throw new Exception(tl("fileRenameError", "jail.yml"));
|
||||
}
|
||||
config.blockingSave();
|
||||
}
|
||||
@@ -1001,7 +963,7 @@ public class EssentialsUpgrade {
|
||||
}
|
||||
}
|
||||
|
||||
uuids.put(uuid, time);
|
||||
uuids.put(uuid, config.getLong("timestamps.logout", 0L));
|
||||
nameToUuidMap.put(name, uuid);
|
||||
}
|
||||
} catch (IllegalArgumentException | IndexOutOfBoundsException ignored) {
|
||||
@@ -1024,60 +986,6 @@ public class EssentialsUpgrade {
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeLang() {
|
||||
if (doneFile.getBoolean("updateLegacyToAdventure", false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ess.getLogger().log(Level.WARNING, "Beginning Adventure locale file conversion.");
|
||||
|
||||
try {
|
||||
final File dataFolder = ess.getDataFolder();
|
||||
if (!dataFolder.exists() || !dataFolder.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final File backDir = new File(dataFolder, "msg-backups-" + System.currentTimeMillis());
|
||||
if (backDir.exists() || !backDir.mkdir()) {
|
||||
ess.getLogger().log(Level.SEVERE, "Unable to make msg-backups dir?!");
|
||||
return;
|
||||
}
|
||||
|
||||
final File messagesDir = new File(dataFolder, "messages");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
messagesDir.mkdir();
|
||||
|
||||
final File[] files = dataFolder.listFiles();
|
||||
boolean isThereAtLeastOneBackup = false;
|
||||
if (files != null) {
|
||||
for (final File file : files) {
|
||||
if (file.getName().endsWith(".properties")) {
|
||||
final File newFile = new File(messagesDir, file.getName());
|
||||
final File backup = new File(backDir, file.getName());
|
||||
Files.move(file, backup);
|
||||
isThereAtLeastOneBackup = true;
|
||||
final OrderedProperties properties = new OrderedProperties();
|
||||
properties.load(Files.newReader(backup, Charsets.UTF_8));
|
||||
for (final String key : properties.stringPropertyNames()) {
|
||||
final String value = properties.getProperty(key);
|
||||
properties.setProperty(key, AdventureUtil.legacyToMini(AdventureUtil.miniMessage().escapeTags(value), true));
|
||||
}
|
||||
properties.store(Files.newWriter(newFile, Charsets.UTF_8), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isThereAtLeastOneBackup) {
|
||||
backDir.delete();
|
||||
}
|
||||
|
||||
doneFile.setProperty("updateLegacyToAdventure", true);
|
||||
doneFile.save();
|
||||
} catch (final Throwable e) {
|
||||
ess.getLogger().log(Level.SEVERE, "Error while upgrading custom locales", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeSettings() {
|
||||
if (!ess.getDataFolder().exists()) {
|
||||
ess.getDataFolder().mkdirs();
|
||||
@@ -1104,6 +1012,5 @@ public class EssentialsUpgrade {
|
||||
convertStupidCamelCaseUserdataKeys();
|
||||
convertMailList();
|
||||
purgeBrokenNpcAccounts();
|
||||
updateRandomTeleport();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -15,34 +13,25 @@ import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.PropertyResourceBundle;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class I18n implements net.ess3.api.II18n {
|
||||
private static final String MESSAGES = "messages";
|
||||
private static final Pattern NODOUBLEMARK = Pattern.compile("''");
|
||||
private static final ExecutorService BUNDLE_LOADER_EXECUTOR = Executors.newFixedThreadPool(2);
|
||||
private static final ResourceBundle NULL_BUNDLE = new ResourceBundle() {
|
||||
@SuppressWarnings("NullableProblems")
|
||||
public Enumeration<String> getKeys() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Object handleGetObject(final @NotNull String key) {
|
||||
protected Object handleGetObject(final String key) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -51,53 +40,30 @@ public class I18n implements net.ess3.api.II18n {
|
||||
private final transient ResourceBundle defaultBundle;
|
||||
private final transient IEssentials ess;
|
||||
private transient Locale currentLocale = defaultLocale;
|
||||
private final transient Map<Locale, ResourceBundle> loadedBundles = new ConcurrentHashMap<>();
|
||||
private final transient List<Locale> loadingBundles = new ArrayList<>();
|
||||
private transient ResourceBundle customBundle;
|
||||
private transient ResourceBundle localeBundle;
|
||||
private final transient Map<Locale, Map<String, MessageFormat>> messageFormatCache = new HashMap<>();
|
||||
private transient Map<String, MessageFormat> messageFormatCache = new HashMap<>();
|
||||
|
||||
public I18n(final IEssentials ess) {
|
||||
this.ess = ess;
|
||||
defaultBundle = ResourceBundle.getBundle(MESSAGES, Locale.ENGLISH, new UTF8PropertiesControl());
|
||||
localeBundle = defaultBundle;
|
||||
customBundle = NULL_BUNDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a message using the server's configured locale.
|
||||
* @param tlKey The translation key.
|
||||
* @param objects Translation parameters, if applicable. Note: by default, these will not be parsed for MiniMessage.
|
||||
* @return The translated message.
|
||||
* @see AdventureUtil#parsed(String)
|
||||
*/
|
||||
public static String tlLiteral(final String tlKey, final Object... objects) {
|
||||
if (instance == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return tlLocale(instance.currentLocale, tlKey, objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates a message using the provided locale.
|
||||
* @param locale The locale to translate the key to.
|
||||
* @param tlKey The translation key.
|
||||
* @param objects Translation parameters, if applicable. Note: by default, these will not be parsed for MiniMessage.
|
||||
* @return The translated message.
|
||||
* @see AdventureUtil#parsed(String)
|
||||
*/
|
||||
public static String tlLocale(final Locale locale, final String tlKey, final Object... objects) {
|
||||
public static String tl(final String string, final Object... objects) {
|
||||
if (instance == null) {
|
||||
return "";
|
||||
}
|
||||
if (objects.length == 0) {
|
||||
return NODOUBLEMARK.matcher(instance.translate(locale, tlKey)).replaceAll("'");
|
||||
return NODOUBLEMARK.matcher(instance.translate(string)).replaceAll("'");
|
||||
} else {
|
||||
return instance.format(tlKey, objects);
|
||||
return instance.format(string, objects);
|
||||
}
|
||||
}
|
||||
|
||||
public static String capitalCase(final String input) {
|
||||
return input == null || input.isEmpty() ? input : input.toUpperCase(Locale.ENGLISH).charAt(0) + input.toLowerCase(Locale.ENGLISH).substring(1);
|
||||
return input == null || input.length() == 0 ? input : input.toUpperCase(Locale.ENGLISH).charAt(0) + input.toLowerCase(Locale.ENGLISH).substring(1);
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
@@ -113,106 +79,52 @@ public class I18n implements net.ess3.api.II18n {
|
||||
return currentLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ResourceBundle} for the given {@link Locale}, if loaded. If a bundle is requested which is
|
||||
* not loaded, it will be loaded asynchronously and the default bundle will be returned in the meantime.
|
||||
*/
|
||||
private ResourceBundle getBundle(final Locale locale) {
|
||||
if (loadedBundles.containsKey(locale)) {
|
||||
return loadedBundles.get(locale);
|
||||
} else {
|
||||
synchronized (loadingBundles) {
|
||||
if (!loadingBundles.contains(locale)) {
|
||||
loadingBundles.add(locale);
|
||||
BUNDLE_LOADER_EXECUTOR.submit(() -> {
|
||||
ResourceBundle bundle;
|
||||
try {
|
||||
bundle = ResourceBundle.getBundle(MESSAGES, locale, new FileResClassLoader(I18n.class.getClassLoader(), ess), new UTF8PropertiesControl());
|
||||
} catch (MissingResourceException ex) {
|
||||
try {
|
||||
bundle = ResourceBundle.getBundle(MESSAGES, locale, new UTF8PropertiesControl());
|
||||
} catch (MissingResourceException ex2) {
|
||||
bundle = NULL_BUNDLE;
|
||||
}
|
||||
}
|
||||
|
||||
loadedBundles.put(locale, bundle);
|
||||
synchronized (loadingBundles) {
|
||||
loadingBundles.remove(locale);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return defaultBundle;
|
||||
}
|
||||
}
|
||||
|
||||
private String translate(final Locale locale, final String string) {
|
||||
private String translate(final String string) {
|
||||
try {
|
||||
try {
|
||||
return getBundle(locale).getString(string);
|
||||
return customBundle.getString(string);
|
||||
} catch (final MissingResourceException ex) {
|
||||
return localeBundle.getString(string);
|
||||
}
|
||||
} catch (final MissingResourceException ex) {
|
||||
if (ess != null && ess.getSettings().isDebug()) {
|
||||
if (ess == null || ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.WARNING, String.format("Missing translation key \"%s\" in translation file %s", ex.getKey(), localeBundle.getLocale().toString()), ex);
|
||||
}
|
||||
return defaultBundle.getString(string);
|
||||
}
|
||||
}
|
||||
|
||||
private String format(final String string, final Object... objects) {
|
||||
return format(currentLocale, string, objects);
|
||||
}
|
||||
|
||||
private String format(final Locale locale, final String string, final Object... objects) {
|
||||
String format = translate(locale, string);
|
||||
|
||||
MessageFormat messageFormat = messageFormatCache.computeIfAbsent(locale, l -> new HashMap<>()).get(format);
|
||||
public String format(final String string, final Object... objects) {
|
||||
String format = translate(string);
|
||||
MessageFormat messageFormat = messageFormatCache.get(format);
|
||||
if (messageFormat == null) {
|
||||
try {
|
||||
messageFormat = new MessageFormat(format);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
ess.getLogger().log(Level.SEVERE, "Invalid Translation key for '" + string + "': " + e.getMessage());
|
||||
format = format.replaceAll("\\{(\\D*?)}", "\\[$1\\]");
|
||||
format = format.replaceAll("\\{(\\D*?)\\}", "\\[$1\\]");
|
||||
messageFormat = new MessageFormat(format);
|
||||
}
|
||||
messageFormatCache.get(locale).put(format, messageFormat);
|
||||
messageFormatCache.put(format, messageFormat);
|
||||
}
|
||||
|
||||
final Object[] processedArgs = mutateArgs(objects, arg -> {
|
||||
if (arg instanceof AdventureUtil.ParsedPlaceholder) {
|
||||
return arg.toString();
|
||||
}
|
||||
return AdventureUtil.legacyToMini(AdventureUtil.miniMessage().escapeTags(arg.toString()));
|
||||
});
|
||||
|
||||
return messageFormat.format(processedArgs).replace(' ', ' '); // replace nbsp with a space
|
||||
}
|
||||
|
||||
public static Object[] mutateArgs(final Object[] objects, final Function<Object, String> mutator) {
|
||||
final Object[] args = new Object[objects.length];
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
final Object object = objects[i];
|
||||
// MessageFormat will format these itself, troll face.
|
||||
if (object instanceof Number || object instanceof Date || object == null) {
|
||||
args[i] = object;
|
||||
continue;
|
||||
}
|
||||
|
||||
args[i] = mutator.apply(object);
|
||||
}
|
||||
return args;
|
||||
return messageFormat.format(objects).replace(' ', ' '); // replace nbsp with a space
|
||||
}
|
||||
|
||||
public void updateLocale(final String loc) {
|
||||
if (loc != null && !loc.isEmpty()) {
|
||||
currentLocale = getLocale(loc);
|
||||
final String[] parts = loc.split("[_\\.]");
|
||||
if (parts.length == 1) {
|
||||
currentLocale = new Locale(parts[0]);
|
||||
}
|
||||
if (parts.length == 2) {
|
||||
currentLocale = new Locale(parts[0], parts[1]);
|
||||
}
|
||||
if (parts.length == 3) {
|
||||
currentLocale = new Locale(parts[0], parts[1], parts[2]);
|
||||
}
|
||||
}
|
||||
ResourceBundle.clearCache();
|
||||
loadedBundles.clear();
|
||||
messageFormatCache.clear();
|
||||
messageFormatCache = new HashMap<>();
|
||||
ess.getLogger().log(Level.INFO, String.format("Using locale %s", currentLocale.toString()));
|
||||
|
||||
try {
|
||||
@@ -220,41 +132,28 @@ public class I18n implements net.ess3.api.II18n {
|
||||
} catch (final MissingResourceException ex) {
|
||||
localeBundle = NULL_BUNDLE;
|
||||
}
|
||||
}
|
||||
|
||||
public static Locale getLocale(final String loc) {
|
||||
if (loc == null || loc.isEmpty()) {
|
||||
return instance.currentLocale;
|
||||
try {
|
||||
customBundle = ResourceBundle.getBundle(MESSAGES, currentLocale, new FileResClassLoader(I18n.class.getClassLoader(), ess), new UTF8PropertiesControl());
|
||||
} catch (final MissingResourceException ex) {
|
||||
customBundle = NULL_BUNDLE;
|
||||
}
|
||||
final String[] parts = loc.split("[_.]");
|
||||
if (parts.length == 1) {
|
||||
return new Locale(parts[0]);
|
||||
}
|
||||
if (parts.length == 2) {
|
||||
return new Locale(parts[0], parts[1]);
|
||||
}
|
||||
if (parts.length == 3) {
|
||||
return new Locale(parts[0], parts[1], parts[2]);
|
||||
}
|
||||
return instance.currentLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to load properties files from the plugin directory before falling back to the jar.
|
||||
*/
|
||||
private static class FileResClassLoader extends ClassLoader {
|
||||
private final transient File messagesFolder;
|
||||
private final transient File dataFolder;
|
||||
|
||||
FileResClassLoader(final ClassLoader classLoader, final IEssentials ess) {
|
||||
super(classLoader);
|
||||
this.messagesFolder = new File(ess.getDataFolder(), "messages");
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
this.messagesFolder.mkdirs();
|
||||
this.dataFolder = ess.getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(final String string) {
|
||||
final File file = new File(messagesFolder, string);
|
||||
final File file = new File(dataFolder, string);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
return file.toURI().toURL();
|
||||
@@ -266,7 +165,7 @@ public class I18n implements net.ess3.api.II18n {
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(final String string) {
|
||||
final File file = new File(messagesFolder, string);
|
||||
final File file = new File(dataFolder, string);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
return new FileInputStream(file);
|
||||
@@ -308,13 +207,5 @@ public class I18n implements net.ess3.api.II18n {
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getFallbackLocale(String baseName, Locale locale) {
|
||||
if (baseName == null || locale == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,20 @@ import com.earth2me.essentials.commands.PlayerNotFoundException;
|
||||
import com.earth2me.essentials.perm.PermissionsHandler;
|
||||
import com.earth2me.essentials.updatecheck.UpdateChecker;
|
||||
import com.earth2me.essentials.userstorage.IUserMap;
|
||||
import net.ess3.provider.Provider;
|
||||
import net.ess3.nms.refl.providers.ReflOnlineModeProvider;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import net.ess3.provider.FormattedCommandAliasProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.MaterialTagProvider;
|
||||
import net.ess3.provider.PersistentDataProvider;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.ess3.provider.ServerStateProvider;
|
||||
import net.ess3.provider.SignDataProvider;
|
||||
import net.ess3.provider.SpawnerBlockProvider;
|
||||
import net.ess3.provider.SpawnerItemProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import net.essentialsx.api.v2.services.mail.MailService;
|
||||
import org.bukkit.Server;
|
||||
@@ -67,16 +80,6 @@ public interface IEssentials extends Plugin {
|
||||
|
||||
int broadcastMessage(String permission, String message);
|
||||
|
||||
void broadcastTl(String tlKey, Object... args);
|
||||
|
||||
void broadcastTl(IUser sender, String tlKey, Object... args);
|
||||
|
||||
void broadcastTl(IUser sender, String permission, String tlKey, Object... args);
|
||||
|
||||
void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, String tlKey, Object... args);
|
||||
|
||||
void broadcastTl(IUser sender, Predicate<IUser> shouldExclude, boolean parseKeywords, String tlKey, Object... args);
|
||||
|
||||
ISettings getSettings();
|
||||
|
||||
BukkitScheduler getScheduler();
|
||||
@@ -139,11 +142,33 @@ public interface IEssentials extends Plugin {
|
||||
|
||||
Iterable<User> getOnlineUsers();
|
||||
|
||||
SpawnerItemProvider getSpawnerItemProvider();
|
||||
|
||||
SpawnerBlockProvider getSpawnerBlockProvider();
|
||||
|
||||
ServerStateProvider getServerStateProvider();
|
||||
|
||||
MaterialTagProvider getMaterialTagProvider();
|
||||
|
||||
ContainerProvider getContainerProvider();
|
||||
|
||||
KnownCommandsProvider getKnownCommandsProvider();
|
||||
|
||||
SerializationProvider getSerializationProvider();
|
||||
|
||||
FormattedCommandAliasProvider getFormattedCommandAliasProvider();
|
||||
|
||||
SyncCommandsProvider getSyncCommandsProvider();
|
||||
|
||||
PersistentDataProvider getPersistentDataProvider();
|
||||
|
||||
ReflOnlineModeProvider getOnlineModeProvider();
|
||||
|
||||
ItemUnbreakableProvider getItemUnbreakableProvider();
|
||||
|
||||
WorldInfoProvider getWorldInfoProvider();
|
||||
|
||||
SignDataProvider getSignDataProvider();
|
||||
|
||||
PluginCommand getPluginCommand(String cmd);
|
||||
|
||||
ProviderFactory getProviders();
|
||||
|
||||
default <P extends Provider> P provider(final Class<P> providerClass) {
|
||||
return getProviders().get(providerClass);
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import net.essentialsx.api.v2.ChatType;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
@@ -38,8 +36,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
String getChatFormat(String group);
|
||||
|
||||
String getChatFormat(String group, ChatType chatType);
|
||||
|
||||
String getWorldAlias(String world);
|
||||
|
||||
int getChatRadius();
|
||||
@@ -56,8 +52,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean isChatQuestionEnabled();
|
||||
|
||||
boolean isUsePaperChatEvent();
|
||||
|
||||
BigDecimal getCommandCost(IEssentialsCommand cmd);
|
||||
|
||||
BigDecimal getCommandCost(String label);
|
||||
@@ -78,8 +72,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean isSocialSpyMessages();
|
||||
|
||||
boolean isSocialSpyDisplayNames();
|
||||
|
||||
Set<String> getMuteCommands();
|
||||
|
||||
@Deprecated
|
||||
@@ -89,8 +81,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
String getLocale();
|
||||
|
||||
boolean isPerPlayerLocale();
|
||||
|
||||
String getNewbieSpawn();
|
||||
|
||||
String getNicknamePrefix();
|
||||
@@ -105,18 +95,12 @@ public interface ISettings extends IConf {
|
||||
|
||||
List<Material> getProtectList(final String configName);
|
||||
|
||||
List<String> getProtectListRaw(final String configName);
|
||||
|
||||
boolean getProtectPreventSpawn(final String creatureName);
|
||||
|
||||
String getProtectString(final String configName);
|
||||
|
||||
boolean getRespawnAtHome();
|
||||
|
||||
String getRandomSpawnLocation();
|
||||
|
||||
String getRandomRespawnLocation();
|
||||
|
||||
boolean isRespawnAtAnchor();
|
||||
|
||||
Set getMultipleHomes();
|
||||
@@ -298,8 +282,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
int getMaxUserCacheCount();
|
||||
|
||||
long getMaxUserCacheValueExpiry();
|
||||
|
||||
boolean allowSilentJoinQuit();
|
||||
|
||||
boolean isCustomJoinMessage();
|
||||
@@ -348,8 +330,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean isWorldChangeFlyResetEnabled();
|
||||
|
||||
boolean isWorldChangePreserveFlying();
|
||||
|
||||
boolean isWorldChangeSpeedResetEnabled();
|
||||
|
||||
long getCommandCooldownMs(String label);
|
||||
@@ -424,18 +404,6 @@ public interface ISettings extends IConf {
|
||||
|
||||
boolean showZeroBaltop();
|
||||
|
||||
BigDecimal getMultiplier(final User user);
|
||||
|
||||
int getMaxItemLore();
|
||||
|
||||
Tag getPrimaryColor();
|
||||
|
||||
Tag getSecondaryColor();
|
||||
|
||||
BigDecimal getBaltopMinBalance();
|
||||
|
||||
long getBaltopMinPlaytime();
|
||||
|
||||
enum KeepInvPolicy {
|
||||
KEEP,
|
||||
DELETE,
|
||||
|
||||
@@ -3,12 +3,11 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.api.IAsyncTeleport;
|
||||
import com.earth2me.essentials.commands.IEssentialsCommand;
|
||||
import com.earth2me.essentials.config.entities.CommandCooldown;
|
||||
import net.ess3.api.ITeleport;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||
import net.essentialsx.api.v2.services.mail.MailSender;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -16,6 +15,7 @@ import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -69,9 +69,13 @@ public interface IUser {
|
||||
* @return whether there is a teleport request
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean hasOutstandingTeleportRequest() {
|
||||
return getNextTpaRequest(false, false, false) != null;
|
||||
}
|
||||
boolean hasOutstandingTeleportRequest();
|
||||
|
||||
/**
|
||||
* @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.api.IAsyncTeleport IAsyncTeleport} with {@link IUser#getAsyncTeleport()}
|
||||
*/
|
||||
@Deprecated
|
||||
ITeleport getTeleport();
|
||||
|
||||
IAsyncTeleport getAsyncTeleport();
|
||||
|
||||
@@ -138,14 +142,6 @@ public interface IUser {
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
void sendComponent(ComponentLike component);
|
||||
|
||||
Component tlComponent(String tlKey, Object... args);
|
||||
|
||||
String playerTl(String tlKey, Object... args);
|
||||
|
||||
void sendTl(String tlKey, Object... args);
|
||||
|
||||
/*
|
||||
* UserData
|
||||
*/
|
||||
|
||||
@@ -3,10 +3,8 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.config.entities.LazyLocation;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -37,10 +35,10 @@ import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Jails implements net.ess3.api.IJails {
|
||||
private static boolean enabled = false;
|
||||
private static transient boolean enabled = false;
|
||||
private final IEssentials ess;
|
||||
private final EssentialsConfiguration config;
|
||||
private final Map<String, LazyLocation> jails = new HashMap<>();
|
||||
@@ -104,17 +102,17 @@ public class Jails implements net.ess3.api.IJails {
|
||||
@Override
|
||||
public Location getJail(String jailName) throws Exception {
|
||||
if (jailName == null) {
|
||||
throw new TranslatableException("jailNotExist");
|
||||
throw new Exception(tl("jailNotExist"));
|
||||
}
|
||||
|
||||
jailName = jailName.toLowerCase(Locale.ENGLISH);
|
||||
synchronized (jails) {
|
||||
if (!jails.containsKey(jailName)) {
|
||||
throw new TranslatableException("jailNotExist");
|
||||
throw new Exception(tl("jailNotExist"));
|
||||
}
|
||||
final Location location = jails.get(jailName).location();
|
||||
if (location == null) {
|
||||
throw new TranslatableException("jailWorldNotExist");
|
||||
throw new Exception(tl("jailWorldNotExist"));
|
||||
}
|
||||
return location;
|
||||
}
|
||||
@@ -142,6 +140,28 @@ public class Jails implements net.ess3.api.IJails {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This method does not use asynchronous teleportation. Use {@link Jails#sendToJail(IUser, String, CompletableFuture)}
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public void sendToJail(final IUser user, String jail) throws Exception {
|
||||
if (jail == null || jail.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
jail = jail.toLowerCase(Locale.ENGLISH);
|
||||
synchronized (jails) {
|
||||
if (jails.containsKey(jail)) {
|
||||
if (user.getBase().isOnline()) {
|
||||
user.getTeleport().now(getJail(jail), false, TeleportCause.COMMAND);
|
||||
}
|
||||
user.setJail(jail);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToJail(final IUser user, final String jailName, final CompletableFuture<Boolean> future) throws Exception {
|
||||
if (jailName == null || jailName.isEmpty()) {
|
||||
@@ -273,9 +293,9 @@ public class Jails implements net.ess3.api.IJails {
|
||||
event.setRespawnLocation(getJail(user.getJail()));
|
||||
} catch (final Exception ex) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
|
||||
ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
|
||||
} else {
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
|
||||
ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,12 +315,12 @@ public class Jails implements net.ess3.api.IJails {
|
||||
event.setTo(getJail(user.getJail()));
|
||||
} catch (final Exception ex) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
|
||||
ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
|
||||
} else {
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
|
||||
ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
|
||||
}
|
||||
}
|
||||
user.sendTl("jailMessage");
|
||||
user.sendMessage(tl("jailMessage"));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@@ -319,13 +339,13 @@ public class Jails implements net.ess3.api.IJails {
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
future.exceptionally(ex -> {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())), ex);
|
||||
ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()), ex);
|
||||
} else {
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage())));
|
||||
ess.getLogger().log(Level.INFO, tl("returnPlayerToJailError", user.getName(), ex.getLocalizedMessage()));
|
||||
}
|
||||
return false;
|
||||
});
|
||||
future.thenAccept(success -> user.sendTl("jailMessage"));
|
||||
future.thenAccept(success -> user.sendMessage(tl("jailMessage")));
|
||||
|
||||
try {
|
||||
sendToJail(user, user.getJail(), future);
|
||||
|
||||
@@ -6,14 +6,10 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.KitClaimEvent;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import net.essentialsx.api.v2.events.KitPreExpandItemsEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -28,7 +24,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Kit {
|
||||
final IEssentials ess;
|
||||
@@ -43,7 +39,7 @@ public class Kit {
|
||||
this.charge = new Trade("kit-" + kitName, new Trade("kit-kit", ess), ess);
|
||||
|
||||
if (kit == null) {
|
||||
throw new TranslatableException("kitNotFound");
|
||||
throw new Exception(tl("kitNotFound"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +49,7 @@ public class Kit {
|
||||
|
||||
public void checkPerms(final User user) throws Exception {
|
||||
if (!user.isAuthorized("essentials.kits." + kitName)) {
|
||||
throw new TranslatableException("noKitPermission", "essentials.kits." + kitName);
|
||||
throw new Exception(tl("noKitPermission", "essentials.kits." + kitName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,10 +58,10 @@ public class Kit {
|
||||
|
||||
if (nextUse == 0L) {
|
||||
} else if (nextUse < 0L) {
|
||||
user.sendTl("kitOnce");
|
||||
user.sendMessage(tl("kitOnce"));
|
||||
throw new NoChargeException();
|
||||
} else {
|
||||
user.sendTl("kitTimed", DateUtil.formatDateDiff(nextUse));
|
||||
user.sendMessage(tl("kitTimed", DateUtil.formatDateDiff(nextUse)));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
}
|
||||
@@ -99,7 +95,7 @@ public class Kit {
|
||||
// Make sure delay is valid
|
||||
delay = kit.containsKey("delay") ? ((Number) kit.get("delay")).doubleValue() : 0.0d;
|
||||
} catch (final Exception e) {
|
||||
throw new TranslatableException("kitError2");
|
||||
throw new Exception(tl("kitError2"));
|
||||
}
|
||||
|
||||
// When was the last kit used?
|
||||
@@ -133,7 +129,7 @@ public class Kit {
|
||||
|
||||
public List<String> getItems() throws Exception {
|
||||
if (kit == null) {
|
||||
throw new TranslatableException("kitNotFound");
|
||||
throw new Exception(tl("kitNotFound"));
|
||||
}
|
||||
try {
|
||||
final List<String> itemList = new ArrayList<>();
|
||||
@@ -151,7 +147,7 @@ public class Kit {
|
||||
throw new Exception("Invalid item list");
|
||||
} catch (final Exception e) {
|
||||
ess.getLogger().log(Level.WARNING, "Error parsing kit " + kitName + ": " + e.getMessage());
|
||||
throw new TranslatableException(e,"kitError2");
|
||||
throw new Exception(tl("kitError2"), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,14 +188,13 @@ public class Kit {
|
||||
}
|
||||
|
||||
final ItemStack stack;
|
||||
final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class);
|
||||
|
||||
if (kitItem.startsWith("@")) {
|
||||
if (serializationProvider == null) {
|
||||
ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("kitError3", kitName, user.getName())));
|
||||
if (ess.getSerializationProvider() == null) {
|
||||
ess.getLogger().log(Level.WARNING, tl("kitError3", kitName, user.getName()));
|
||||
continue;
|
||||
}
|
||||
stack = serializationProvider.deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
|
||||
stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1)));
|
||||
} else {
|
||||
final String[] parts = kitItem.split(" +");
|
||||
final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1);
|
||||
@@ -224,13 +219,9 @@ public class Kit {
|
||||
final int maxStackSize = user.isAuthorized("essentials.oversizedstacks") ? ess.getSettings().getOversizedStackSize() : 0;
|
||||
final boolean isDropItemsIfFull = ess.getSettings().isDropItemsIfFull();
|
||||
|
||||
final KitPreExpandItemsEvent itemsEvent = new KitPreExpandItemsEvent(user, kitName, itemList);
|
||||
Bukkit.getPluginManager().callEvent(itemsEvent);
|
||||
|
||||
final ItemStack[] itemArray = itemList.toArray(new ItemStack[0]);
|
||||
|
||||
if (!isDropItemsIfFull && !Inventories.hasSpace(user.getBase(), maxStackSize, autoEquip, itemArray)) {
|
||||
user.sendTl("kitInvFullNoDrop");
|
||||
user.sendMessage(tl("kitInvFullNoDrop"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -242,10 +233,10 @@ public class Kit {
|
||||
|
||||
for (final ItemStack itemStack : leftover.values()) {
|
||||
int spillAmount = itemStack.getAmount();
|
||||
if (maxStackSize != 0) {
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
}
|
||||
while (spillAmount > 0) {
|
||||
if (maxStackSize != 0) {
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
}
|
||||
user.getWorld().dropItemNaturally(user.getLocation(), itemStack);
|
||||
spillAmount -= itemStack.getAmount();
|
||||
}
|
||||
@@ -267,12 +258,12 @@ public class Kit {
|
||||
}
|
||||
|
||||
if (spew) {
|
||||
user.sendTl("kitInvFull");
|
||||
user.sendMessage(tl("kitInvFull"));
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
user.getBase().updateInventory();
|
||||
ess.getLogger().log(Level.WARNING, e.getMessage());
|
||||
throw new TranslatableException(e, "kitError2");
|
||||
throw new Exception(tl("kitError2"), e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
|
||||
import java.io.File;
|
||||
@@ -15,6 +14,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.I18n.capitalCase;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Kits implements IConf {
|
||||
private final IEssentials ess;
|
||||
@@ -145,7 +145,7 @@ public class Kits implements IConf {
|
||||
String name = capitalCase(kitItem);
|
||||
final BigDecimal costPrice = new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
|
||||
if (costPrice.signum() > 0) {
|
||||
cost = user.playerTl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
|
||||
cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
|
||||
}
|
||||
|
||||
final Kit kit = new Kit(kitItem, ess);
|
||||
@@ -153,7 +153,7 @@ public class Kits implements IConf {
|
||||
if (nextUse == -1 && ess.getSettings().isSkippingUsedOneTimeKitsFromKitList()) {
|
||||
continue;
|
||||
} else if (nextUse != 0) {
|
||||
name = user.playerTl("kitDelay", name);
|
||||
name = tl("kitDelay", name);
|
||||
}
|
||||
|
||||
list.append(" ").append(name).append(cost);
|
||||
@@ -161,7 +161,7 @@ public class Kits implements IConf {
|
||||
}
|
||||
return list.toString().trim();
|
||||
} catch (final Exception ex) {
|
||||
throw new TranslatableException(ex, "kitError");
|
||||
throw new Exception(tl("kitError"), ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class MailServiceImpl implements MailService {
|
||||
private final transient ThreadLocal<SimpleDateFormat> df = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy/MM/dd HH:mm"));
|
||||
@@ -52,28 +52,10 @@ public class MailServiceImpl implements MailService {
|
||||
public String getMailLine(MailMessage mail) {
|
||||
final String message = mail.getMessage();
|
||||
if (mail.isLegacy()) {
|
||||
return tlLiteral("mailMessage", message);
|
||||
return tl("mailMessage", message);
|
||||
}
|
||||
|
||||
final String expire = mail.getTimeExpire() != 0 ? "Timed" : "";
|
||||
return tlLiteral((mail.isRead() ? "mailFormatNewRead" : "mailFormatNew") + expire, df.get().format(new Date(mail.getTimeSent())), mail.getSenderUsername(), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMailTlKey(MailMessage message) {
|
||||
if (message.isLegacy()) {
|
||||
return "mailMessage";
|
||||
}
|
||||
|
||||
final String expire = message.getTimeExpire() != 0 ? "Timed" : "";
|
||||
return (message.isRead() ? "mailFormatNewRead" : "mailFormatNew") + expire;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getMailTlArgs(MailMessage message) {
|
||||
if (message.isLegacy()) {
|
||||
return new Object[] {message.getMessage()};
|
||||
}
|
||||
return new Object[] {df.get().format(new Date(message.getTimeSent())), message.getSenderUsername(), message.getMessage()};
|
||||
return tl((mail.isRead() ? "mailFormatNewRead" : "mailFormatNew") + expire, df.get().format(new Date(mail.getTimeSent())), mail.getSenderUsername(), message);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
@@ -23,7 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class ManagedFile {
|
||||
private static final int BUFFERSIZE = 1024 * 8;
|
||||
@@ -46,7 +45,7 @@ public class ManagedFile {
|
||||
try {
|
||||
copyResourceAscii("/" + filename, file);
|
||||
} catch (final IOException ex) {
|
||||
Essentials.getWrappedLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("itemsCsvNotLoaded", filename)), ex);
|
||||
Essentials.getWrappedLogger().log(Level.SEVERE, tl("itemsCsvNotLoaded", filename), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,16 +3,13 @@ package com.earth2me.essentials;
|
||||
import com.earth2me.essentials.textreader.BookInput;
|
||||
import com.earth2me.essentials.textreader.BookPager;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.base.Joiner;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.BannerDataProvider;
|
||||
import net.ess3.provider.ItemUnbreakableProvider;
|
||||
import net.ess3.provider.PotionMetaProvider;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
@@ -32,6 +29,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
@@ -44,6 +42,8 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class MetaItemStack {
|
||||
private static final Map<String, DyeColor> colorMap = new HashMap<>();
|
||||
private static final Map<String, FireworkEffect.Type> fireworkShape = new HashMap<>();
|
||||
@@ -131,30 +131,21 @@ public class MetaItemStack {
|
||||
}
|
||||
|
||||
public boolean canSpawn(final IEssentials ess) {
|
||||
if (VersionUtil.PRE_FLATTENING) {
|
||||
try {
|
||||
ess.getServer().getUnsafe().modifyItemStack(stack.clone(), "{}");
|
||||
return true;
|
||||
} catch (final NoSuchMethodError nsme) {
|
||||
return true;
|
||||
} catch (final Throwable npe) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
|
||||
}
|
||||
return false;
|
||||
try {
|
||||
ess.getServer().getUnsafe().modifyItemStack(stack.clone(), "{}");
|
||||
return true;
|
||||
} catch (final NoSuchMethodError nsme) {
|
||||
return true;
|
||||
} catch (final Throwable npe) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return stack.getType().isItem();
|
||||
}
|
||||
|
||||
public void parseStringMeta(final CommandSource sender, final boolean allowUnsafe, final String[] string, final int fromArg, final IEssentials ess) throws Exception {
|
||||
final boolean nbtIsKill = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01);
|
||||
|
||||
if (string[fromArg].startsWith("{") && hasMetaPermission(sender, "vanilla", false, true, ess)) {
|
||||
if (nbtIsKill) {
|
||||
throw new TranslatableException("noMetaNbtKill");
|
||||
}
|
||||
|
||||
try {
|
||||
stack = ess.getServer().getUnsafe().modifyItemStack(stack, Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length)));
|
||||
} catch (final NullPointerException npe) {
|
||||
@@ -162,23 +153,7 @@ public class MetaItemStack {
|
||||
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
|
||||
}
|
||||
} catch (final NoSuchMethodError nsme) {
|
||||
throw new TranslatableException(nsme, "noMetaJson");
|
||||
} catch (final Throwable throwable) {
|
||||
throw new Exception(throwable.getMessage(), throwable);
|
||||
}
|
||||
} else if (string[fromArg].startsWith("[") && hasMetaPermission(sender, "vanilla", false, true, ess)) {
|
||||
if (!nbtIsKill) {
|
||||
throw new TranslatableException("noMetaComponents");
|
||||
}
|
||||
|
||||
try {
|
||||
final String components = Joiner.on(' ').join(Arrays.asList(string).subList(fromArg, string.length));
|
||||
// modifyItemStack requires that the item namespaced key is prepended to the components for some reason
|
||||
stack = ess.getServer().getUnsafe().modifyItemStack(stack, stack.getType().getKey() + components);
|
||||
} catch (final NullPointerException npe) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Itemstack is invalid", npe);
|
||||
}
|
||||
throw new Exception(tl("noMetaJson"), nsme);
|
||||
} catch (final Throwable throwable) {
|
||||
throw new Exception(throwable.getMessage(), throwable);
|
||||
}
|
||||
@@ -188,19 +163,19 @@ public class MetaItemStack {
|
||||
}
|
||||
if (validFirework) {
|
||||
if (!hasMetaPermission(sender, "firework", true, true, ess)) {
|
||||
throw new TranslatableException("noMetaFirework");
|
||||
throw new Exception(tl("noMetaFirework"));
|
||||
}
|
||||
final FireworkEffect effect = builder.build();
|
||||
final FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
|
||||
fmeta.addEffect(effect);
|
||||
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) {
|
||||
throw new TranslatableException("multipleCharges");
|
||||
throw new Exception(tl("multipleCharges"));
|
||||
}
|
||||
stack.setItemMeta(fmeta);
|
||||
}
|
||||
if (validFireworkCharge) {
|
||||
if (!hasMetaPermission(sender, "firework", true, true, ess)) {
|
||||
throw new TranslatableException("noMetaFirework");
|
||||
throw new Exception(tl("noMetaFirework"));
|
||||
}
|
||||
final FireworkEffect effect = builder.build();
|
||||
final FireworkEffectMeta meta = (FireworkEffectMeta) stack.getItemMeta();
|
||||
@@ -216,26 +191,21 @@ public class MetaItemStack {
|
||||
return;
|
||||
}
|
||||
|
||||
final Material WRITTEN_BOOK = EnumUtil.getMaterial("WRITTEN_BOOK");
|
||||
|
||||
if (split.length > 1 && split[0].equalsIgnoreCase("name") && hasMetaPermission(sender, "name", false, true, ess)) {
|
||||
final String displayName = FormatUtil.replaceFormat(split[1].replaceAll("(?<!\\\\)_", " ").replace("\\_", "_"));
|
||||
final String displayName = FormatUtil.replaceFormat(split[1].replace('_', ' '));
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(displayName);
|
||||
stack.setItemMeta(meta);
|
||||
} else if (split.length > 1 && (split[0].equalsIgnoreCase("lore") || split[0].equalsIgnoreCase("desc")) && hasMetaPermission(sender, "lore", false, true, ess)) {
|
||||
final List<String> lore = new ArrayList<>();
|
||||
for (final String line : split[1].split("(?<!\\\\)\\|")) {
|
||||
lore.add(FormatUtil.replaceFormat(line.replaceAll("(?<!\\\\)_", " ").replace("\\_", "_").replace("\\|", "|")));
|
||||
lore.add(FormatUtil.replaceFormat(line.replace('_', ' ').replace("\\|", "|")));
|
||||
}
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
} else if ((split[0].equalsIgnoreCase("custom-model-data") || split[0].equalsIgnoreCase("cmd")) && hasMetaPermission(sender, "custom-model-data", false, true, ess)) {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_R01)) {
|
||||
final int value = split.length <= 1 ? 0 : Integer.parseInt(split[1]);
|
||||
final ItemMeta meta = stack.getItemMeta();
|
||||
meta.setCustomModelData(value);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
} else if (split[0].equalsIgnoreCase("unbreakable") && hasMetaPermission(sender, "unbreakable", false, true, ess)) {
|
||||
final boolean value = split.length <= 1 || Boolean.parseBoolean(split[1]);
|
||||
setUnbreakable(ess, stack, value);
|
||||
@@ -244,33 +214,23 @@ public class MetaItemStack {
|
||||
final String owner = split[1];
|
||||
setSkullOwner(ess, stack, owner);
|
||||
} else {
|
||||
throw new TranslatableException("onlyPlayerSkulls");
|
||||
throw new Exception(tl("onlyPlayerSkulls"));
|
||||
}
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("book") && MaterialUtil.isEditableBook(stack.getType()) && (hasMetaPermission(sender, "book", true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))) {
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("book") && MaterialUtil.isEditableBook(stack.getType()) && (hasMetaPermission(sender, "book",true, true, ess) || hasMetaPermission(sender, "chapter-" + split[1].toLowerCase(Locale.ENGLISH), true, true, ess))) {
|
||||
final BookMeta meta = (BookMeta) stack.getItemMeta();
|
||||
final IText input = new BookInput("book", true, ess);
|
||||
final BookPager pager = new BookPager(input);
|
||||
// This fix only applies to written books - which require an author and a title. https://bugs.mojang.com/browse/MC-59153
|
||||
if (stack.getType() == Material.WRITTEN_BOOK) {
|
||||
if (!meta.hasAuthor()) {
|
||||
// The sender can be null when this method is called from {@link com.earth2me.essentials.signs.EssentialsSign#getItemMeta(ItemStack, String, IEssentials)}
|
||||
meta.setAuthor(sender == null ? Console.getInstance().getDisplayName() : sender.getPlayer().getName());
|
||||
}
|
||||
if (!meta.hasTitle()) {
|
||||
final String title = FormatUtil.replaceFormat(split[1].replace('_', ' '));
|
||||
meta.setTitle(title.length() > 32 ? title.substring(0, 32) : title);
|
||||
}
|
||||
}
|
||||
|
||||
final List<String> pages = pager.getPages(split[1]);
|
||||
meta.setPages(pages);
|
||||
stack.setItemMeta(meta);
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "author", false, true, ess)) {
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("author") && stack.getType() == WRITTEN_BOOK && hasMetaPermission(sender, "author", false, true, ess)) {
|
||||
final String author = FormatUtil.replaceFormat(split[1]);
|
||||
final BookMeta meta = (BookMeta) stack.getItemMeta();
|
||||
meta.setAuthor(author);
|
||||
stack.setItemMeta(meta);
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == Material.WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess)) {
|
||||
final String title = FormatUtil.replaceFormat(split[1].replaceAll("(?<!\\\\)_", " ").replace("\\_", "_"));
|
||||
} else if (split.length > 1 && split[0].equalsIgnoreCase("title") && stack.getType() == WRITTEN_BOOK && hasMetaPermission(sender, "title", false, true, ess)) {
|
||||
final String title = FormatUtil.replaceFormat(split[1].replace('_', ' '));
|
||||
final BookMeta meta = (BookMeta) stack.getItemMeta();
|
||||
meta.setTitle(title);
|
||||
stack.setItemMeta(meta);
|
||||
@@ -280,7 +240,7 @@ public class MetaItemStack {
|
||||
final List<String> pages = meta.hasPages() ? new ArrayList<>(meta.getPages()) : new ArrayList<>();
|
||||
final List<String> lines = new ArrayList<>();
|
||||
for (final String line : split[1].split("(?<!\\\\)\\|")) {
|
||||
lines.add(FormatUtil.replaceFormat(line.replaceAll("(?<!\\\\)_", " ").replace("\\_", "_").replace("\\|", "|")));
|
||||
lines.add(FormatUtil.replaceFormat(line.replace('_', ' ').replace("\\|", "|")));
|
||||
}
|
||||
final String content = String.join("\n", lines);
|
||||
if (page >= pages.size()) {
|
||||
@@ -341,7 +301,7 @@ public class MetaItemStack {
|
||||
meta.setColor(Color.fromRGB(red, green, blue));
|
||||
stack.setItemMeta(meta);
|
||||
} else {
|
||||
throw new TranslatableException("leatherSyntax");
|
||||
throw new Exception(tl("leatherSyntax"));
|
||||
}
|
||||
} else {
|
||||
parseEnchantmentStrings(sender, allowUnsafe, split, ess);
|
||||
@@ -351,7 +311,7 @@ public class MetaItemStack {
|
||||
public void addItemFlags(final String string) throws Exception {
|
||||
final String[] separate = splitPattern.split(string, 2);
|
||||
if (separate.length != 2) {
|
||||
throw new TranslatableException("invalidItemFlagMeta", string);
|
||||
throw new Exception(tl("invalidItemFlagMeta", string));
|
||||
}
|
||||
|
||||
final String[] split = separate[1].split(",");
|
||||
@@ -366,7 +326,7 @@ public class MetaItemStack {
|
||||
}
|
||||
|
||||
if (meta.getItemFlags().isEmpty()) {
|
||||
throw new TranslatableException("invalidItemFlagMeta", string);
|
||||
throw new Exception(tl("invalidItemFlagMeta", string));
|
||||
}
|
||||
|
||||
stack.setItemMeta(meta);
|
||||
@@ -389,7 +349,7 @@ public class MetaItemStack {
|
||||
validFireworkCharge = true;
|
||||
primaryColors.add(Color.fromRGB(Integer.decode(color)));
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
builder.withColor(primaryColors);
|
||||
@@ -399,7 +359,7 @@ public class MetaItemStack {
|
||||
if (fireworkShape.containsKey(split[1].toUpperCase())) {
|
||||
finalEffect = fireworkShape.get(split[1].toUpperCase());
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
if (finalEffect != null) {
|
||||
builder.with(finalEffect);
|
||||
@@ -413,7 +373,7 @@ public class MetaItemStack {
|
||||
} else if (hexPattern.matcher(color).matches()) {
|
||||
fadeColors.add(Color.fromRGB(Integer.decode(color)));
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
if (!fadeColors.isEmpty()) {
|
||||
@@ -427,7 +387,7 @@ public class MetaItemStack {
|
||||
} else if (effect.equalsIgnoreCase("trail")) {
|
||||
builder.trail(true);
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,13 +403,13 @@ public class MetaItemStack {
|
||||
if (split[0].equalsIgnoreCase("color") || split[0].equalsIgnoreCase("colour") || (allowShortName && split[0].equalsIgnoreCase("c"))) {
|
||||
if (validFirework) {
|
||||
if (!hasMetaPermission(sender, "firework", true, true, ess)) {
|
||||
throw new TranslatableException("noMetaFirework");
|
||||
throw new Exception(tl("noMetaFirework"));
|
||||
}
|
||||
final FireworkEffect effect = builder.build();
|
||||
final FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
|
||||
fmeta.addEffect(effect);
|
||||
if (fmeta.getEffects().size() > 1 && !hasMetaPermission(sender, "firework-multiple", true, true, ess)) {
|
||||
throw new TranslatableException("multipleCharges");
|
||||
throw new Exception(tl("multipleCharges"));
|
||||
}
|
||||
stack.setItemMeta(fmeta);
|
||||
builder = FireworkEffect.builder();
|
||||
@@ -465,7 +425,7 @@ public class MetaItemStack {
|
||||
validFirework = true;
|
||||
primaryColors.add(Color.fromRGB(Integer.decode(color)));
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
builder.withColor(primaryColors);
|
||||
@@ -475,7 +435,7 @@ public class MetaItemStack {
|
||||
if (fireworkShape.containsKey(split[1].toUpperCase())) {
|
||||
finalEffect = fireworkShape.get(split[1].toUpperCase());
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
if (finalEffect != null) {
|
||||
builder.with(finalEffect);
|
||||
@@ -489,7 +449,7 @@ public class MetaItemStack {
|
||||
} else if (hexPattern.matcher(color).matches()) {
|
||||
fadeColors.add(Color.fromRGB(Integer.decode(color)));
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
if (!fadeColors.isEmpty()) {
|
||||
@@ -503,7 +463,7 @@ public class MetaItemStack {
|
||||
} else if (effect.equalsIgnoreCase("trail")) {
|
||||
builder.trail(true);
|
||||
} else {
|
||||
throw new TranslatableException("invalidFireworkFormat", split[1], split[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", split[1], split[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -524,10 +484,10 @@ public class MetaItemStack {
|
||||
if (hasMetaPermission(sender, "potions." + pEffectType.getName().toLowerCase(Locale.ENGLISH), true, false, ess)) {
|
||||
validPotionEffect = true;
|
||||
} else {
|
||||
throw new TranslatableException("noPotionEffectPerm", pEffectType.getName().toLowerCase(Locale.ENGLISH));
|
||||
throw new Exception(tl("noPotionEffectPerm", pEffectType.getName().toLowerCase(Locale.ENGLISH)));
|
||||
}
|
||||
} else {
|
||||
throw new TranslatableException("invalidPotionMeta", split[1]);
|
||||
throw new Exception(tl("invalidPotionMeta", split[1]));
|
||||
}
|
||||
} else if (split[0].equalsIgnoreCase("power") || (allowShortName && split[0].equalsIgnoreCase("p"))) {
|
||||
if (NumberUtil.isInt(split[1])) {
|
||||
@@ -537,21 +497,21 @@ public class MetaItemStack {
|
||||
power -= 1;
|
||||
}
|
||||
} else {
|
||||
throw new TranslatableException("invalidPotionMeta", split[1]);
|
||||
throw new Exception(tl("invalidPotionMeta", split[1]));
|
||||
}
|
||||
} else if (split[0].equalsIgnoreCase("amplifier") || (allowShortName && split[0].equalsIgnoreCase("a"))) {
|
||||
if (NumberUtil.isInt(split[1])) {
|
||||
validPotionPower = true;
|
||||
power = Integer.parseInt(split[1]);
|
||||
} else {
|
||||
throw new TranslatableException("invalidPotionMeta", split[1]);
|
||||
throw new Exception(tl("invalidPotionMeta", split[1]));
|
||||
}
|
||||
} else if (split[0].equalsIgnoreCase("duration") || (allowShortName && split[0].equalsIgnoreCase("d"))) {
|
||||
if (NumberUtil.isInt(split[1])) {
|
||||
validPotionDuration = true;
|
||||
duration = Integer.parseInt(split[1]) * 20; //Duration is in ticks by default, converted to seconds
|
||||
} else {
|
||||
throw new TranslatableException("invalidPotionMeta", split[1]);
|
||||
throw new Exception(tl("invalidPotionMeta", split[1]));
|
||||
}
|
||||
} else if (split[0].equalsIgnoreCase("splash") || (allowShortName && split[0].equalsIgnoreCase("s"))) {
|
||||
isSplashPotion = Boolean.parseBoolean(split[1]);
|
||||
@@ -561,11 +521,21 @@ public class MetaItemStack {
|
||||
final PotionMeta pmeta = (PotionMeta) stack.getItemMeta();
|
||||
pEffect = pEffectType.createEffect(duration, power);
|
||||
if (pmeta.getCustomEffects().size() > 1 && !hasMetaPermission(sender, "potions.multiple", true, false, ess)) {
|
||||
throw new TranslatableException("multiplePotionEffects");
|
||||
throw new Exception(tl("multiplePotionEffects"));
|
||||
}
|
||||
pmeta.addCustomEffect(pEffect, true);
|
||||
stack.setItemMeta(pmeta);
|
||||
ess.provider(PotionMetaProvider.class).setSplashPotion(stack, isSplashPotion);
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_9_R01)) {
|
||||
if (isSplashPotion && stack.getType() != Material.SPLASH_POTION) {
|
||||
stack.setType(Material.SPLASH_POTION);
|
||||
} else if (!isSplashPotion && stack.getType() != Material.POTION) {
|
||||
stack.setType(Material.POTION);
|
||||
}
|
||||
} else {
|
||||
final Potion potion = Potion.fromDamage(stack.getDurability());
|
||||
potion.setSplash(isSplashPotion);
|
||||
potion.apply(stack);
|
||||
}
|
||||
resetPotionMeta();
|
||||
}
|
||||
}
|
||||
@@ -576,7 +546,7 @@ public class MetaItemStack {
|
||||
if (enchantment == null) {
|
||||
return false;
|
||||
}
|
||||
if (hasMetaPermission(sender, "enchantments." + Enchantments.getRealName(enchantment), false, false, ess)) {
|
||||
if (hasMetaPermission(sender, "enchantments." + enchantment.getName().toLowerCase(Locale.ENGLISH), false, false, ess)) {
|
||||
int level = -1;
|
||||
if (split.length > 1) {
|
||||
try {
|
||||
@@ -596,7 +566,7 @@ public class MetaItemStack {
|
||||
|
||||
public void addEnchantment(final CommandSource sender, final boolean allowUnsafe, final Enchantment enchantment, final int level) throws Exception {
|
||||
if (enchantment == null) {
|
||||
throw new TranslatableException("enchantmentNotFound");
|
||||
throw new Exception(tl("enchantmentNotFound"));
|
||||
}
|
||||
try {
|
||||
if (stack.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||
@@ -619,7 +589,7 @@ public class MetaItemStack {
|
||||
}
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
throw new Exception("Enchantment " + Enchantments.getRealName(enchantment) + ": " + ex.getMessage(), ex);
|
||||
throw new Exception("Enchantment " + enchantment.getName() + ": " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,10 +599,10 @@ public class MetaItemStack {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String enchantmentName = Enchantments.getRealName(enchantment);
|
||||
final String enchantmentName = enchantment.getName().toLowerCase(Locale.ENGLISH);
|
||||
|
||||
if (!hasMetaPermission(user, "enchantments." + enchantmentName, true, false)) {
|
||||
throw new TranslatableException("enchantmentPerm", enchantmentName);
|
||||
throw new Exception(tl("enchantmentPerm", enchantmentName));
|
||||
}
|
||||
return enchantment;
|
||||
}
|
||||
@@ -642,23 +612,21 @@ public class MetaItemStack {
|
||||
final String[] split = splitPattern.split(string, 2);
|
||||
|
||||
if (split.length < 2) {
|
||||
throw new TranslatableException("invalidBanner", split[1]);
|
||||
throw new Exception(tl("invalidBanner", split[1]));
|
||||
}
|
||||
|
||||
PatternType patternType = null;
|
||||
try {
|
||||
//noinspection removal
|
||||
patternType = PatternType.getByIdentifier(split[0]);
|
||||
patternType = PatternType.valueOf(split[0]);
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
|
||||
final BannerMeta meta = (BannerMeta) stack.getItemMeta();
|
||||
if (split[0].equalsIgnoreCase("basecolor")) {
|
||||
final Color color = Color.fromRGB(Integer.parseInt(split[1]));
|
||||
ess.provider(BannerDataProvider.class).setBaseColor(stack, DyeColor.getByColor(color));
|
||||
meta.setBaseColor(DyeColor.getByColor(color));
|
||||
} else if (patternType != null) {
|
||||
//noinspection removal
|
||||
final PatternType type = PatternType.getByIdentifier(split[0]);
|
||||
final PatternType type = PatternType.valueOf(split[0]);
|
||||
final DyeColor color = DyeColor.getByColor(Color.fromRGB(Integer.parseInt(split[1])));
|
||||
final org.bukkit.block.banner.Pattern pattern = new org.bukkit.block.banner.Pattern(color, type);
|
||||
meta.addPattern(pattern);
|
||||
@@ -669,13 +637,12 @@ public class MetaItemStack {
|
||||
final String[] split = splitPattern.split(string, 2);
|
||||
|
||||
if (split.length < 2) {
|
||||
throw new TranslatableException("invalidBanner", split[1]);
|
||||
throw new Exception(tl("invalidBanner", split[1]));
|
||||
}
|
||||
|
||||
PatternType patternType = null;
|
||||
try {
|
||||
//noinspection removal
|
||||
patternType = PatternType.getByIdentifier(split[0]);
|
||||
patternType = PatternType.valueOf(split[0]);
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
|
||||
@@ -686,8 +653,7 @@ public class MetaItemStack {
|
||||
final Color color = Color.fromRGB(Integer.parseInt(split[1]));
|
||||
banner.setBaseColor(DyeColor.getByColor(color));
|
||||
} else if (patternType != null) {
|
||||
//noinspection removal
|
||||
final PatternType type = PatternType.getByIdentifier(split[0]);
|
||||
final PatternType type = PatternType.valueOf(split[0]);
|
||||
final DyeColor color = DyeColor.getByColor(Color.fromRGB(Integer.parseInt(split[1])));
|
||||
final org.bukkit.block.banner.Pattern pattern = new org.bukkit.block.banner.Pattern(color, type);
|
||||
banner.addPattern(pattern);
|
||||
@@ -712,13 +678,13 @@ public class MetaItemStack {
|
||||
if (graceful) {
|
||||
return false;
|
||||
} else {
|
||||
throw new TranslatableException("noMetaPerm", metaPerm);
|
||||
throw new Exception(tl("noMetaPerm", metaPerm));
|
||||
}
|
||||
}
|
||||
|
||||
private void setUnbreakable(final IEssentials ess, final ItemStack is, final boolean unbreakable) {
|
||||
final ItemMeta meta = is.getItemMeta();
|
||||
ess.provider(ItemUnbreakableProvider.class).setUnbreakable(meta, unbreakable);
|
||||
ess.getItemUnbreakableProvider().setUnbreakable(meta, unbreakable);
|
||||
is.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@@ -15,7 +14,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
// Suffixes can be appended on the end of a mob name to make it plural
|
||||
// Entities without a suffix, will default to 's'
|
||||
@@ -42,31 +41,22 @@ public enum Mob {
|
||||
ENDERDRAGON("EnderDragon", Enemies.ENEMY, EntityType.ENDER_DRAGON),
|
||||
VILLAGER("Villager", Enemies.FRIENDLY, EntityType.VILLAGER),
|
||||
BLAZE("Blaze", Enemies.ENEMY, EntityType.BLAZE),
|
||||
MUSHROOMCOW("MushroomCow", Enemies.FRIENDLY, MobCompat.MOOSHROOM),
|
||||
MUSHROOMCOW("MushroomCow", Enemies.FRIENDLY, EntityType.MUSHROOM_COW),
|
||||
MAGMACUBE("MagmaCube", Enemies.ENEMY, EntityType.MAGMA_CUBE),
|
||||
SNOWMAN("Snowman", Enemies.FRIENDLY, "", MobCompat.SNOW_GOLEM),
|
||||
SNOWMAN("Snowman", Enemies.FRIENDLY, "", EntityType.SNOWMAN),
|
||||
OCELOT("Ocelot", Enemies.NEUTRAL, EntityType.OCELOT),
|
||||
IRONGOLEM("IronGolem", Enemies.NEUTRAL, EntityType.IRON_GOLEM),
|
||||
WITHER("Wither", Enemies.ENEMY, EntityType.WITHER),
|
||||
BAT("Bat", Enemies.FRIENDLY, EntityType.BAT),
|
||||
WITCH("Witch", Enemies.ENEMY, EntityType.WITCH),
|
||||
BOAT("Boat", Enemies.NEUTRAL, MobCompat.OAK_BOAT),
|
||||
ACACIA_BOAT("AcaciaBoat", Enemies.NEUTRAL, "ACACIA_BOAT"),
|
||||
DARK_OAK_BOAT("DarkOakBoat", Enemies.NEUTRAL, "DARK_OAK_BOAT"),
|
||||
BIRCH_BOAT("BirchBoat", Enemies.NEUTRAL, "BIRCH_BOAT"),
|
||||
JUNGLE_BOAT("JungleBoat", Enemies.NEUTRAL, "JUNGLE_BOAT"),
|
||||
SPRUCE_BOAT("SpruceBoat", Enemies.NEUTRAL, "SPRUCE_BOAT"),
|
||||
MANGROVE_BOAT("MangroveBoat", Enemies.NEUTRAL, "MANGROVE_BOAT"),
|
||||
CHERRY_BOAT("CherryBoat", Enemies.NEUTRAL, "CHERRY_BOAT"),
|
||||
BAMBOO_RAFT("BambooRaft", Enemies.NEUTRAL, "BAMBOO_RAFT"),
|
||||
PALE_OAK_BOAT("PaleOakBoat", Enemies.NEUTRAL, "PALE_OAK_BOAT"),
|
||||
BOAT("Boat", Enemies.NEUTRAL, EntityType.BOAT),
|
||||
MINECART("Minecart", Enemies.NEUTRAL, EntityType.MINECART),
|
||||
MINECART_CHEST("ChestMinecart", Enemies.NEUTRAL, MobCompat.CHEST_MINECART),
|
||||
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, MobCompat.FURNACE_MINECART),
|
||||
MINECART_TNT("TNTMinecart", Enemies.NEUTRAL, MobCompat.TNT_MINECART),
|
||||
MINECART_HOPPER("HopperMinecart", Enemies.NEUTRAL, MobCompat.HOPPER_MINECART),
|
||||
MINECART_MOB_SPAWNER("SpawnerMinecart", Enemies.NEUTRAL, MobCompat.SPAWNER_MINECART),
|
||||
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, MobCompat.END_CRYSTAL),
|
||||
MINECART_CHEST("ChestMinecart", Enemies.NEUTRAL, EntityType.MINECART_CHEST),
|
||||
MINECART_FURNACE("FurnaceMinecart", Enemies.NEUTRAL, EntityType.MINECART_FURNACE),
|
||||
MINECART_TNT("TNTMinecart", Enemies.NEUTRAL, EntityType.MINECART_TNT),
|
||||
MINECART_HOPPER("HopperMinecart", Enemies.NEUTRAL, EntityType.MINECART_HOPPER),
|
||||
MINECART_MOB_SPAWNER("SpawnerMinecart", Enemies.NEUTRAL, EntityType.MINECART_MOB_SPAWNER),
|
||||
ENDERCRYSTAL("EnderCrystal", Enemies.NEUTRAL, EntityType.ENDER_CRYSTAL),
|
||||
EXPERIENCEORB("ExperienceOrb", Enemies.NEUTRAL, "EXPERIENCE_ORB"),
|
||||
ARMOR_STAND("ArmorStand", Enemies.NEUTRAL, "ARMOR_STAND"),
|
||||
ENDERMITE("Endermite", Enemies.ENEMY, "ENDERMITE"),
|
||||
@@ -119,12 +109,6 @@ public enum Mob {
|
||||
TADPOLE("Tadpole", Enemies.FRIENDLY, "TADPOLE"),
|
||||
WARDEN("Warden", Enemies.ENEMY, "WARDEN"),
|
||||
CHEST_BOAT("ChestBoat", Enemies.NEUTRAL, "CHEST_BOAT"),
|
||||
CAMEL("Camel", Enemies.FRIENDLY, "CAMEL"),
|
||||
SNIFFER("Sniffer", Enemies.FRIENDLY, "SNIFFER"),
|
||||
ARMADILLO("Armadillo", Enemies.FRIENDLY, "ARMADILLO"),
|
||||
BREEZE("Breeze", Enemies.ENEMY, "BREEZE"),
|
||||
BOGGED("Bogged", Enemies.ENEMY, "BOGGED"),
|
||||
CREAKING("Creaking", Enemies.ENEMY, "CREAKING")
|
||||
;
|
||||
|
||||
private static final Map<String, Mob> hashMap = new HashMap<>();
|
||||
@@ -185,7 +169,7 @@ public enum Mob {
|
||||
public Entity spawn(final World world, final Server server, final Location loc) throws MobException {
|
||||
final Entity entity = world.spawn(loc, this.bukkitType.getEntityClass());
|
||||
if (entity == null) {
|
||||
Essentials.getWrappedLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("unableToSpawnMob")));
|
||||
Essentials.getWrappedLogger().log(Level.WARNING, tl("unableToSpawnMob"));
|
||||
throw new MobException();
|
||||
}
|
||||
return entity;
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.nms.refl.ReflUtil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.TreeSpecies;
|
||||
import org.bukkit.entity.Axolotl;
|
||||
import org.bukkit.entity.Boat;
|
||||
import org.bukkit.entity.Camel;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fox;
|
||||
@@ -18,12 +15,8 @@ import org.bukkit.entity.MushroomCow;
|
||||
import org.bukkit.entity.Ocelot;
|
||||
import org.bukkit.entity.Panda;
|
||||
import org.bukkit.entity.Parrot;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Salmon;
|
||||
import org.bukkit.entity.TropicalFish;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -48,22 +41,10 @@ public final class MobCompat {
|
||||
public static final EntityType AXOLOTL = getEntityType("AXOLOTL");
|
||||
public static final EntityType GOAT = getEntityType("GOAT");
|
||||
public static final EntityType FROG = getEntityType("FROG");
|
||||
public static final EntityType CAMEL = getEntityType("CAMEL");
|
||||
public static final EntityType SALMON = getEntityType("SALMON");
|
||||
|
||||
// Constants for mobs that have changed since earlier versions
|
||||
public static final EntityType CAT = getEntityType("CAT", "OCELOT");
|
||||
public static final EntityType ZOMBIFIED_PIGLIN = getEntityType("ZOMBIFIED_PIGLIN", "PIG_ZOMBIE");
|
||||
public static final EntityType MOOSHROOM = getEntityType("MOOSHROOM", "MUSHROOM_COW");
|
||||
public static final EntityType SNOW_GOLEM = getEntityType("SNOW_GOLEM", "SNOWMAN");
|
||||
public static final EntityType CHEST_MINECART = getEntityType("CHEST_MINECART", "MINECART_CHEST");
|
||||
public static final EntityType FURNACE_MINECART = getEntityType("FURNACE_MINECART", "MINECART_FURNACE");
|
||||
public static final EntityType TNT_MINECART = getEntityType("TNT_MINECART", "MINECART_TNT");
|
||||
public static final EntityType HOPPER_MINECART = getEntityType("HOPPER_MINECART", "MINECART_HOPPER");
|
||||
public static final EntityType SPAWNER_MINECART = getEntityType("SPAWNER_MINECART", "MINECART_MOB_SPAWNER");
|
||||
public static final EntityType END_CRYSTAL = getEntityType("END_CRYSTAL", "ENDER_CRYSTAL");
|
||||
public static final EntityType FIREWORK_ROCKET = getEntityType("FIREWORK_ROCKET", "FIREWORK");
|
||||
public static final EntityType OAK_BOAT = getEntityType("BOAT", "OAK_BOAT");
|
||||
|
||||
private MobCompat() {
|
||||
}
|
||||
@@ -197,7 +178,7 @@ public final class MobCompat {
|
||||
}
|
||||
|
||||
public static void setBoatVariant(final Entity entity, final BoatVariant variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_3_R01) || VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
|
||||
return;
|
||||
}
|
||||
final Boat boat;
|
||||
@@ -210,46 +191,10 @@ public final class MobCompat {
|
||||
//noinspection deprecation
|
||||
boat.setWoodType(TreeSpecies.valueOf(variant.getTreeSpecies()));
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
boat.setBoatType(Boat.Type.valueOf(variant.getBoatType()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCamelSaddle(final Entity entity, final Player target) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_20_1_R01)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof Camel) {
|
||||
final Camel camel = (Camel) entity;
|
||||
camel.setTamed(true);
|
||||
camel.setOwner(target);
|
||||
camel.getInventory().setSaddle(new ItemStack(Material.SADDLE, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setWolfVariant(final Entity entity, final String variant) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_20_6_R01)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof Wolf) {
|
||||
final Wolf wolf = (Wolf) entity;
|
||||
//noinspection DataFlowIssue
|
||||
wolf.setVariant(RegistryUtil.valueOf(Wolf.Variant.class, variant));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSalmonSize(Entity spawned, String s) {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_21_3_R01)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawned instanceof org.bukkit.entity.Salmon) {
|
||||
((Salmon) spawned).setVariant(Salmon.Variant.valueOf(s));
|
||||
}
|
||||
}
|
||||
|
||||
public enum CatType {
|
||||
// These are (loosely) Mojang names for the cats
|
||||
SIAMESE("SIAMESE", "SIAMESE_CAT"),
|
||||
@@ -310,7 +255,7 @@ public final class MobCompat {
|
||||
}
|
||||
|
||||
private Villager.Profession asEnum() {
|
||||
return RegistryUtil.valueOf(Villager.Profession.class, newProfession, oldProfession);
|
||||
return EnumUtil.valueOf(Villager.Profession.class, newProfession, oldProfession);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Ageable;
|
||||
@@ -39,6 +38,8 @@ import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public enum MobData {
|
||||
|
||||
BABY_AGEABLE("baby", Ageable.class, Data.BABY, true),
|
||||
@@ -157,8 +158,8 @@ public enum MobData {
|
||||
BLOCKFISH_TROPICAL_FISH("blockfish", MobCompat.TROPICAL_FISH, "tropicalfish:BLOCKFISH", true),
|
||||
BETTY_TROPICAL_FISH("betty", MobCompat.TROPICAL_FISH, "tropicalfish:BETTY", true),
|
||||
CLAYFISH_TROPICAL_FISH("clayfish", MobCompat.TROPICAL_FISH, "tropicalfish:CLAYFISH", true),
|
||||
BROWN_MUSHROOM_COW("brown", MobCompat.MOOSHROOM, "mooshroom:BROWN", true),
|
||||
RED_MUSHROOM_COW("red", MobCompat.MOOSHROOM, "mooshroom:RED", true),
|
||||
BROWN_MUSHROOM_COW("brown", EntityType.MUSHROOM_COW, "mooshroom:BROWN", true),
|
||||
RED_MUSHROOM_COW("red", EntityType.MUSHROOM_COW, "mooshroom:RED", true),
|
||||
AGGRESSIVE_PANDA_MAIN("aggressive", MobCompat.PANDA, "pandamain:AGGRESSIVE", true),
|
||||
LAZY_PANDA_MAIN("lazy", MobCompat.PANDA, "pandamain:LAZY", true),
|
||||
WORRIED_PANDA_MAIN("worried", MobCompat.PANDA, "pandamain:WORRIED", true),
|
||||
@@ -208,19 +209,6 @@ public enum MobData {
|
||||
MANGROVE_BOAT("mangrove", Boat.class, MobCompat.BoatVariant.MANGROVE, true),
|
||||
OAK_BOAT("oak", Boat.class, MobCompat.BoatVariant.OAK, true),
|
||||
SPRUCE_BOAT("spruce", Boat.class, MobCompat.BoatVariant.SPRUCE, true),
|
||||
SADDLE_CAMEL("saddle", MobCompat.CAMEL, Data.CAMELSADDLE, true),
|
||||
PALE_WOLF("pale", EntityType.WOLF, "wolf:PALE", true),
|
||||
SPOTTED_WOLF("spotted", EntityType.WOLF, "wolf:PALE", true),
|
||||
SNOWY_WOLF("snowy", EntityType.WOLF, "wolf:PALE", true),
|
||||
BLACK_WOLF("black", EntityType.WOLF, "wolf:BLACK", true),
|
||||
ASHEN_WOLF("ashen", EntityType.WOLF, "wolf:ASHEN", true),
|
||||
RUSTY_WOLF("rusty", EntityType.WOLF, "wolf:RUSTY", true),
|
||||
WOODS_WOLF("woods", EntityType.WOLF, "wolf:WOODS", true),
|
||||
CHESTNUT_WOLF("chestnut", EntityType.WOLF, "wolf:CHESTNUT", true),
|
||||
STRIPED_WOLF("striped", EntityType.WOLF, "wolf:STRIPED", true),
|
||||
SMALL_SALMON("small", MobCompat.SALMON, "salmon:SMALL", true),
|
||||
MEDIUM_SALMON("medium", MobCompat.SALMON, "salmon:MEDIUM", true),
|
||||
LARGE_SALMON("large", MobCompat.SALMON, "salmon:LARGE", true),
|
||||
;
|
||||
|
||||
final private String nickname;
|
||||
@@ -339,14 +327,14 @@ public enum MobData {
|
||||
}
|
||||
this.matched = rawData;
|
||||
} catch (final Exception e) {
|
||||
throw new TranslatableException(e, "sheepMalformedColor");
|
||||
throw new Exception(tl("sheepMalformedColor"), e);
|
||||
}
|
||||
} else if (this.value.equals(Data.EXP)) {
|
||||
try {
|
||||
((ExperienceOrb) spawned).setExperience(Integer.parseInt(rawData));
|
||||
this.matched = rawData;
|
||||
} catch (final NumberFormatException e) {
|
||||
throw new TranslatableException(e, "invalidNumber");
|
||||
throw new Exception(tl("invalidNumber"), e);
|
||||
}
|
||||
} else if (this.value.equals(Data.SIZE)) {
|
||||
try {
|
||||
@@ -358,7 +346,7 @@ public enum MobData {
|
||||
}
|
||||
this.matched = rawData;
|
||||
} catch (final NumberFormatException e) {
|
||||
throw new TranslatableException(e, "slimeMalformedSize");
|
||||
throw new Exception(tl("slimeMalformedSize"), e);
|
||||
}
|
||||
} else if (this.value instanceof Horse.Color) {
|
||||
((Horse) spawned).setColor((Horse.Color) this.value);
|
||||
@@ -399,8 +387,6 @@ public enum MobData {
|
||||
}
|
||||
} else if (this.value.equals(Data.GOAT_SCREAMING)) {
|
||||
((Goat) spawned).setScreaming(true);
|
||||
} else if (this.value.equals(Data.CAMELSADDLE)) {
|
||||
MobCompat.setCamelSaddle(spawned, target);
|
||||
} else if (this.value instanceof MobCompat.BoatVariant) {
|
||||
MobCompat.setBoatVariant(spawned, (MobCompat.BoatVariant) this.value);
|
||||
} else if (this.value instanceof String) {
|
||||
@@ -436,12 +422,6 @@ public enum MobData {
|
||||
case "frog":
|
||||
MobCompat.setFrogVariant(spawned, split[1]);
|
||||
break;
|
||||
case "wolf":
|
||||
MobCompat.setWolfVariant(spawned, split[1]);
|
||||
break;
|
||||
case "salmon":
|
||||
MobCompat.setSalmonSize(spawned, split[1]);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString());
|
||||
@@ -466,6 +446,5 @@ public enum MobData {
|
||||
FISH_BODY_COLOR,
|
||||
FISH_PATTERN_COLOR,
|
||||
GOAT_SCREAMING,
|
||||
CAMELSADDLE,
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -32,11 +31,4 @@ public class PlayerExtension {
|
||||
public Location getLocation() {
|
||||
return base.getLocation();
|
||||
}
|
||||
|
||||
public OfflinePlayer getOffline() {
|
||||
if (base instanceof OfflinePlayerStub) {
|
||||
return ((OfflinePlayerStub) base).base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -15,7 +14,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public final class PlayerList {
|
||||
|
||||
@@ -33,19 +32,19 @@ public final class PlayerList {
|
||||
}
|
||||
needComma = true;
|
||||
if (user.isAfk()) {
|
||||
groupString.append(tlLiteral("listAfkTag"));
|
||||
groupString.append(tl("listAfkTag"));
|
||||
}
|
||||
if (user.isHidden()) {
|
||||
groupString.append(tlLiteral("listHiddenTag"));
|
||||
groupString.append(tl("listHiddenTag"));
|
||||
}
|
||||
user.setDisplayNick();
|
||||
groupString.append(AdventureUtil.legacyToMini(user.getDisplayName()));
|
||||
groupString.append(user.getDisplayName());
|
||||
|
||||
final String strippedNick = FormatUtil.stripFormat(user.getNickname());
|
||||
if (ess.getSettings().realNamesOnList() && strippedNick != null && !strippedNick.equals(user.getName())) {
|
||||
groupString.append(" ").append(tlLiteral("listRealName",user.getName()));
|
||||
groupString.append(" ").append(tl("listRealName",user.getName()));
|
||||
}
|
||||
groupString.append("<white>");
|
||||
groupString.append(ChatColor.WHITE.toString());
|
||||
}
|
||||
return groupString.toString();
|
||||
}
|
||||
@@ -56,31 +55,27 @@ public final class PlayerList {
|
||||
int playerHidden = 0;
|
||||
int hiddenCount = 0;
|
||||
for (final User onlinePlayer : ess.getOnlineUsers()) {
|
||||
if (onlinePlayer.isHidden() || (user != null && onlinePlayer.isHiddenFrom(user.getBase()))) {
|
||||
if (onlinePlayer.isHidden() || (user != null && !user.getBase().canSee(onlinePlayer.getBase()))) {
|
||||
playerHidden++;
|
||||
if (showHidden || user != null && !onlinePlayer.isHiddenFrom(user.getBase())) {
|
||||
if (showHidden || user != null && user.getBase().canSee(onlinePlayer.getBase())) {
|
||||
hiddenCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final String tlKey;
|
||||
final Object[] objects;
|
||||
final String online;
|
||||
if (hiddenCount > 0) {
|
||||
tlKey = "listAmountHidden";
|
||||
objects = new Object[]{ess.getOnlinePlayers().size() - playerHidden, hiddenCount, server.getMaxPlayers()};
|
||||
online = tl("listAmountHidden", ess.getOnlinePlayers().size() - playerHidden, hiddenCount, server.getMaxPlayers());
|
||||
} else {
|
||||
tlKey = "listAmount";
|
||||
objects = new Object[]{ess.getOnlinePlayers().size() - playerHidden, server.getMaxPlayers()};
|
||||
online = tl("listAmount", ess.getOnlinePlayers().size() - playerHidden, server.getMaxPlayers());
|
||||
}
|
||||
return user == null ? tlLiteral(tlKey, objects) : user.playerTl(tlKey, objects);
|
||||
return online;
|
||||
}
|
||||
|
||||
// Build the basic player list, divided by groups.
|
||||
public static Map<String, List<User>> getPlayerLists(final IEssentials ess, final IUser sender, final boolean showHidden) {
|
||||
final Map<String, List<User>> playerList = new HashMap<>();
|
||||
for (final User onlineUser : ess.getOnlineUsers()) {
|
||||
if ((sender == null && !showHidden && onlineUser.isHidden()) || (sender != null && !showHidden && onlineUser.isHiddenFrom(sender.getBase()))) {
|
||||
if ((sender == null && !showHidden && onlineUser.isHidden()) || (sender != null && !showHidden && !sender.getBase().canSee(onlineUser.getBase()))) {
|
||||
continue;
|
||||
}
|
||||
final String group = FormatUtil.stripFormat(FormatUtil.stripEssentialsFormat(onlineUser.getGroup().toLowerCase()));
|
||||
@@ -122,7 +117,7 @@ public final class PlayerList {
|
||||
users.addAll(groupUsers);
|
||||
}
|
||||
if (users.isEmpty()) {
|
||||
throw new TranslatableException("groupDoesNotExist");
|
||||
throw new Exception(tl("groupDoesNotExist"));
|
||||
}
|
||||
final String displayGroupName = Character.toTitleCase(groupName.charAt(0)) +
|
||||
groupName.substring(1);
|
||||
@@ -131,11 +126,11 @@ public final class PlayerList {
|
||||
|
||||
// Build the output string
|
||||
public static String outputFormat(final String group, final String message) {
|
||||
return tlLiteral("listGroupTag", FormatUtil.replaceFormat(group)) +
|
||||
return tl("listGroupTag", FormatUtil.replaceFormat(group)) +
|
||||
message;
|
||||
}
|
||||
|
||||
public static List<String> prepareGroupedList(final IEssentials ess, final CommandSource source, final String commandLabel, final Map<String, List<User>> playerList) {
|
||||
public static List<String> prepareGroupedList(final IEssentials ess, final String commandLabel, final Map<String, List<User>> playerList) {
|
||||
final List<String> output = new ArrayList<>();
|
||||
|
||||
final Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
|
||||
@@ -168,9 +163,7 @@ public final class PlayerList {
|
||||
outputUserList = new ArrayList<>(matchedList);
|
||||
final int limit = Integer.parseInt(groupValue);
|
||||
if (matchedList.size() > limit) {
|
||||
final String tlKey = "groupNumber";
|
||||
final Object[] objects = {matchedList.size(), commandLabel, FormatUtil.stripFormat(configGroup)};
|
||||
output.add(outputFormat(oConfigGroup, source == null ? tlLiteral(tlKey, objects) : source.tl(tlKey, objects)));
|
||||
output.add(outputFormat(oConfigGroup, tl("groupNumber", matchedList.size(), commandLabel, FormatUtil.stripFormat(configGroup))));
|
||||
} else {
|
||||
output.add(outputFormat(oConfigGroup, listUsers(ess, outputUserList, ", ")));
|
||||
}
|
||||
@@ -210,7 +203,7 @@ public final class PlayerList {
|
||||
String groupName = asterisk.isEmpty() ? users.get(0).getGroup() : onlineGroup;
|
||||
|
||||
if (ess.getPermissionsHandler().getName().equals("ConfigPermissions")) {
|
||||
groupName = source == null ? tlLiteral("connectedPlayers") : source.tl("connectedPlayers");
|
||||
groupName = tl("connectedPlayers");
|
||||
}
|
||||
if (users == null || users.isEmpty()) {
|
||||
continue;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -22,68 +21,50 @@ public final class Potions {
|
||||
ALIASPOTIONS.put("sprint", PotionEffectType.SPEED);
|
||||
ALIASPOTIONS.put("swift", PotionEffectType.SPEED);
|
||||
|
||||
final PotionEffectType SLOWNESS = RegistryUtil.valueOf(PotionEffectType.class, "SLOW", "SLOWNESS");
|
||||
POTIONS.put("slowness", PotionEffectType.SLOW);
|
||||
ALIASPOTIONS.put("slow", PotionEffectType.SLOW);
|
||||
ALIASPOTIONS.put("sluggish", PotionEffectType.SLOW);
|
||||
|
||||
POTIONS.put("slowness", SLOWNESS);
|
||||
ALIASPOTIONS.put("slow", SLOWNESS);
|
||||
ALIASPOTIONS.put("sluggish", SLOWNESS);
|
||||
POTIONS.put("haste", PotionEffectType.FAST_DIGGING);
|
||||
ALIASPOTIONS.put("superpick", PotionEffectType.FAST_DIGGING);
|
||||
ALIASPOTIONS.put("quickmine", PotionEffectType.FAST_DIGGING);
|
||||
ALIASPOTIONS.put("digspeed", PotionEffectType.FAST_DIGGING);
|
||||
ALIASPOTIONS.put("digfast", PotionEffectType.FAST_DIGGING);
|
||||
ALIASPOTIONS.put("sharp", PotionEffectType.FAST_DIGGING);
|
||||
|
||||
final PotionEffectType HASTE = RegistryUtil.valueOf(PotionEffectType.class, "FAST_DIGGING", "HASTE");
|
||||
POTIONS.put("fatigue", PotionEffectType.SLOW_DIGGING);
|
||||
ALIASPOTIONS.put("slow", PotionEffectType.SLOW_DIGGING);
|
||||
ALIASPOTIONS.put("dull", PotionEffectType.SLOW_DIGGING);
|
||||
|
||||
POTIONS.put("haste", HASTE);
|
||||
ALIASPOTIONS.put("superpick", HASTE);
|
||||
ALIASPOTIONS.put("quickmine", HASTE);
|
||||
ALIASPOTIONS.put("digspeed", HASTE);
|
||||
ALIASPOTIONS.put("digfast", HASTE);
|
||||
ALIASPOTIONS.put("sharp", HASTE);
|
||||
POTIONS.put("strength", PotionEffectType.INCREASE_DAMAGE);
|
||||
ALIASPOTIONS.put("strong", PotionEffectType.INCREASE_DAMAGE);
|
||||
ALIASPOTIONS.put("bull", PotionEffectType.INCREASE_DAMAGE);
|
||||
ALIASPOTIONS.put("attack", PotionEffectType.INCREASE_DAMAGE);
|
||||
|
||||
final PotionEffectType MINING_FATIGUE = RegistryUtil.valueOf(PotionEffectType.class, "SLOW_DIGGING", "MINING_FATIGUE");
|
||||
POTIONS.put("heal", PotionEffectType.HEAL);
|
||||
ALIASPOTIONS.put("healthy", PotionEffectType.HEAL);
|
||||
ALIASPOTIONS.put("instaheal", PotionEffectType.HEAL);
|
||||
|
||||
POTIONS.put("fatigue", MINING_FATIGUE);
|
||||
ALIASPOTIONS.put("slow", MINING_FATIGUE);
|
||||
ALIASPOTIONS.put("dull", MINING_FATIGUE);
|
||||
POTIONS.put("harm", PotionEffectType.HARM);
|
||||
ALIASPOTIONS.put("harming", PotionEffectType.HARM);
|
||||
ALIASPOTIONS.put("injure", PotionEffectType.HARM);
|
||||
ALIASPOTIONS.put("damage", PotionEffectType.HARM);
|
||||
ALIASPOTIONS.put("inflict", PotionEffectType.HARM);
|
||||
|
||||
final PotionEffectType STRENGTH = RegistryUtil.valueOf(PotionEffectType.class, "INCREASE_DAMAGE", "STRENGTH");
|
||||
POTIONS.put("jump", PotionEffectType.JUMP);
|
||||
ALIASPOTIONS.put("leap", PotionEffectType.JUMP);
|
||||
|
||||
POTIONS.put("strength", STRENGTH);
|
||||
ALIASPOTIONS.put("strong", STRENGTH);
|
||||
ALIASPOTIONS.put("bull", STRENGTH);
|
||||
ALIASPOTIONS.put("attack", STRENGTH);
|
||||
|
||||
final PotionEffectType INSTANT_HEALTH = RegistryUtil.valueOf(PotionEffectType.class, "HEAL", "INSTANT_HEALTH");
|
||||
|
||||
POTIONS.put("heal", INSTANT_HEALTH);
|
||||
ALIASPOTIONS.put("healthy", INSTANT_HEALTH);
|
||||
ALIASPOTIONS.put("instaheal", INSTANT_HEALTH);
|
||||
|
||||
final PotionEffectType INSTANT_DAMAGE = RegistryUtil.valueOf(PotionEffectType.class, "HARM", "INSTANT_DAMAGE");
|
||||
|
||||
POTIONS.put("harm", INSTANT_DAMAGE);
|
||||
ALIASPOTIONS.put("harming", INSTANT_DAMAGE);
|
||||
ALIASPOTIONS.put("injure", INSTANT_DAMAGE);
|
||||
ALIASPOTIONS.put("damage", INSTANT_DAMAGE);
|
||||
ALIASPOTIONS.put("inflict", INSTANT_DAMAGE);
|
||||
|
||||
final PotionEffectType JUMP_BOOST = RegistryUtil.valueOf(PotionEffectType.class, "JUMP", "JUMP_BOOST");
|
||||
|
||||
POTIONS.put("jump", JUMP_BOOST);
|
||||
ALIASPOTIONS.put("leap", JUMP_BOOST);
|
||||
|
||||
final PotionEffectType NAUSEA = RegistryUtil.valueOf(PotionEffectType.class, "CONFUSION", "NAUSEA");
|
||||
|
||||
POTIONS.put("nausea", NAUSEA);
|
||||
ALIASPOTIONS.put("sick", NAUSEA);
|
||||
ALIASPOTIONS.put("sickness", NAUSEA);
|
||||
ALIASPOTIONS.put("confusion", NAUSEA);
|
||||
POTIONS.put("nausea", PotionEffectType.CONFUSION);
|
||||
ALIASPOTIONS.put("sick", PotionEffectType.CONFUSION);
|
||||
ALIASPOTIONS.put("sickness", PotionEffectType.CONFUSION);
|
||||
ALIASPOTIONS.put("confusion", PotionEffectType.CONFUSION);
|
||||
|
||||
POTIONS.put("regeneration", PotionEffectType.REGENERATION);
|
||||
ALIASPOTIONS.put("regen", PotionEffectType.REGENERATION);
|
||||
|
||||
final PotionEffectType RESISTANCE = RegistryUtil.valueOf(PotionEffectType.class, "DAMAGE_RESISTANCE", "RESISTANCE");
|
||||
|
||||
POTIONS.put("resistance", RESISTANCE);
|
||||
ALIASPOTIONS.put("dmgresist", RESISTANCE);
|
||||
ALIASPOTIONS.put("armor", RESISTANCE);
|
||||
POTIONS.put("resistance", PotionEffectType.DAMAGE_RESISTANCE);
|
||||
ALIASPOTIONS.put("dmgresist", PotionEffectType.DAMAGE_RESISTANCE);
|
||||
ALIASPOTIONS.put("armor", PotionEffectType.DAMAGE_RESISTANCE);
|
||||
|
||||
POTIONS.put("fireresist", PotionEffectType.FIRE_RESISTANCE);
|
||||
ALIASPOTIONS.put("fireresistance", PotionEffectType.FIRE_RESISTANCE);
|
||||
@@ -144,23 +125,6 @@ public final class Potions {
|
||||
POTIONS.put("unluck", PotionEffectType.UNLUCK);
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
|
||||
// 1.21
|
||||
try {
|
||||
POTIONS.put("infested", PotionEffectType.INFESTED);
|
||||
ALIASPOTIONS.put("silverfish", PotionEffectType.INFESTED);
|
||||
|
||||
POTIONS.put("oozing", PotionEffectType.OOZING);
|
||||
ALIASPOTIONS.put("ooze", PotionEffectType.OOZING);
|
||||
|
||||
POTIONS.put("weaving", PotionEffectType.WEAVING);
|
||||
ALIASPOTIONS.put("weave", PotionEffectType.WEAVING);
|
||||
|
||||
POTIONS.put("windcharged", PotionEffectType.WIND_CHARGED);
|
||||
ALIASPOTIONS.put("windcharge", PotionEffectType.WIND_CHARGED);
|
||||
ALIASPOTIONS.put("wind", PotionEffectType.WIND_CHARGED);
|
||||
} catch (final Throwable ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private Potions() {
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.provider.Provider;
|
||||
import net.essentialsx.providers.NullableProvider;
|
||||
import net.essentialsx.providers.ProviderData;
|
||||
import net.essentialsx.providers.ProviderTest;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ProviderFactory {
|
||||
private final Map<Class<? extends Provider>, Provider> providers = new HashMap<>();
|
||||
private final Map<Class<? extends Provider>, List<Class<? extends Provider>>> registeredProviders = new HashMap<>();
|
||||
private final Essentials essentials;
|
||||
|
||||
public ProviderFactory(final Essentials essentials) {
|
||||
this.essentials = essentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the provider which has been selected for the given type.
|
||||
* @param providerClass The provider type.
|
||||
* @return the provider or null if no provider could be selected for that type.
|
||||
*/
|
||||
public <P extends Provider> P get(final Class<P> providerClass) {
|
||||
final Provider provider = providers.get(providerClass);
|
||||
if (provider == null) {
|
||||
return null;
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (P) provider;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public final void registerProvider(final Class<? extends Provider>... toRegister) {
|
||||
for (final Class<? extends Provider> provider : toRegister) {
|
||||
final Class<?> superclass = provider.getInterfaces().length > 0 ? provider.getInterfaces()[0] : provider.getSuperclass();
|
||||
if (Provider.class.isAssignableFrom(superclass)) {
|
||||
//noinspection unchecked
|
||||
registeredProviders.computeIfAbsent((Class<? extends Provider>) superclass, k -> new ArrayList<>()).add(provider);
|
||||
if (essentials.getSettings().isDebug()) {
|
||||
essentials.getLogger().info("Registered provider " + provider.getSimpleName() + " for " + superclass.getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void finalizeRegistration() {
|
||||
for (final Map.Entry<Class<? extends Provider>, List<Class<? extends Provider>>> entry : registeredProviders.entrySet()) {
|
||||
final Class<? extends Provider> providerClass = entry.getKey();
|
||||
final boolean nullable = providerClass.isAnnotationPresent(NullableProvider.class);
|
||||
Class<? extends Provider> highestProvider = null;
|
||||
ProviderData highestProviderData = null;
|
||||
int highestWeight = -1;
|
||||
for (final Class<? extends Provider> provider : entry.getValue()) {
|
||||
try {
|
||||
final ProviderData providerData = provider.getAnnotation(ProviderData.class);
|
||||
if (providerData.weight() > highestWeight && testProvider(provider)) {
|
||||
highestWeight = providerData.weight();
|
||||
highestProvider = provider;
|
||||
highestProviderData = providerData;
|
||||
}
|
||||
} catch (final Throwable e) {
|
||||
essentials.getLogger().log(Level.SEVERE, "Failed to initialize provider " + provider.getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (highestProvider != null) {
|
||||
essentials.getLogger().info("Selected " + highestProviderData.description() + " as the provider for " + providerClass.getSimpleName());
|
||||
providers.put(providerClass, getProviderInstance(highestProvider));
|
||||
} else if (!nullable) {
|
||||
throw new IllegalStateException("No provider found for " + providerClass.getName());
|
||||
} else {
|
||||
essentials.getLogger().info("No provider found for " + providerClass.getSimpleName() + ", but it is nullable");
|
||||
}
|
||||
}
|
||||
registeredProviders.clear();
|
||||
}
|
||||
|
||||
private boolean testProvider(final Class<?> providerClass) throws InvocationTargetException, IllegalAccessException {
|
||||
try {
|
||||
for (final Method method : providerClass.getMethods()) {
|
||||
if (method.isAnnotationPresent(ProviderTest.class)) {
|
||||
return (Boolean) method.invoke(null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (final NoClassDefFoundError ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private <P extends Provider> P getProviderInstance(final Class<P> provider) {
|
||||
try {
|
||||
final Constructor<?> constructor = provider.getConstructors()[0];
|
||||
if (constructor.getParameterTypes().length == 0) {
|
||||
//noinspection unchecked
|
||||
return (P) constructor.newInstance();
|
||||
}
|
||||
final Object[] args = new Object[constructor.getParameterTypes().length];
|
||||
|
||||
/*
|
||||
Providers can have constructors with any of the following types, and this code will automatically supply them;
|
||||
- Plugin - The Essentials instance will be passed
|
||||
- boolean - True will be passed if this server is running Paper, otherwise false.
|
||||
*/
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
final Class<?> paramType = constructor.getParameterTypes()[i];
|
||||
if (paramType.isAssignableFrom(Plugin.class)) {
|
||||
args[i] = essentials;
|
||||
} else if (paramType.isAssignableFrom(boolean.class)) {
|
||||
args[i] = PaperLib.isPaper();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported parameter type " + paramType.getName());
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
return (P) constructor.newInstance(args);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
try {
|
||||
return provider.getConstructor().newInstance();
|
||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,18 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.config.entities.LazyLocation;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.provider.BiomeKeyProvider;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@@ -29,77 +24,66 @@ public class RandomTeleport implements IConf {
|
||||
private static final int HIGHEST_BLOCK_Y_OFFSET = VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_R01) ? 1 : 0;
|
||||
private final IEssentials ess;
|
||||
private final EssentialsConfiguration config;
|
||||
private final Map<String, ConcurrentLinkedQueue<Location>> cachedLocations = new HashMap<>();
|
||||
private WorldInfoProvider worldInfoProvider;
|
||||
private final ConcurrentLinkedQueue<Location> cachedLocations = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public RandomTeleport(final IEssentials essentials) {
|
||||
this.ess = essentials;
|
||||
config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml",
|
||||
"Configuration for the random teleport command.\nUse the /settpr command in-game to set random teleport locations.");
|
||||
}
|
||||
|
||||
public EssentialsConfiguration getConfig() {
|
||||
return config;
|
||||
"Configuration for the random teleport command.\nSome settings may be defaulted, and can be changed via the /settpr command in-game.");
|
||||
reloadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
worldInfoProvider = ess.provider(WorldInfoProvider.class);
|
||||
config.load();
|
||||
cachedLocations.clear();
|
||||
}
|
||||
|
||||
public boolean hasLocation(final String name) {
|
||||
return config.hasProperty("locations." + name);
|
||||
}
|
||||
|
||||
public Location getCenter(final String name) {
|
||||
final LazyLocation center = config.getLocation(locationKey(name, "center"));
|
||||
if (center != null && center.location() != null) {
|
||||
return center.location();
|
||||
public Location getCenter() {
|
||||
try {
|
||||
final LazyLocation center = config.getLocation("center");
|
||||
if (center != null && center.location() != null) {
|
||||
return center.location();
|
||||
}
|
||||
} catch (final InvalidWorldException ignored) {
|
||||
}
|
||||
|
||||
final Location worldCenter = ess.getServer().getWorlds().get(0).getWorldBorder().getCenter();
|
||||
worldCenter.setY(worldCenter.getWorld().getHighestBlockYAt(worldCenter) + HIGHEST_BLOCK_Y_OFFSET);
|
||||
setCenter(name, worldCenter);
|
||||
return worldCenter;
|
||||
final Location center = ess.getServer().getWorlds().get(0).getWorldBorder().getCenter();
|
||||
center.setY(center.getWorld().getHighestBlockYAt(center) + HIGHEST_BLOCK_Y_OFFSET);
|
||||
setCenter(center);
|
||||
return center;
|
||||
}
|
||||
|
||||
public void setCenter(final String name, final Location center) {
|
||||
config.setProperty(locationKey(name, "center"), center);
|
||||
public void setCenter(final Location center) {
|
||||
config.setProperty("center", center);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public double getMinRange(final String name) {
|
||||
return config.getDouble(locationKey(name, "min-range"), 0d);
|
||||
public double getMinRange() {
|
||||
return config.getDouble("min-range", 0d);
|
||||
}
|
||||
|
||||
public void setMinRange(final String name, final double minRange) {
|
||||
config.setProperty(locationKey(name, "min-range"), minRange);
|
||||
public void setMinRange(final double minRange) {
|
||||
config.setProperty("min-range", minRange);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public double getMaxRange(final String name) {
|
||||
return config.getDouble(locationKey(name, "max-range"), getCenter(name).getWorld().getWorldBorder().getSize() / 2);
|
||||
public double getMaxRange() {
|
||||
return config.getDouble("max-range", getCenter().getWorld().getWorldBorder().getSize() / 2);
|
||||
}
|
||||
|
||||
public void setMaxRange(final String name, final double maxRange) {
|
||||
config.setProperty(locationKey(name, "max-range"), maxRange);
|
||||
public void setMaxRange(final double maxRange) {
|
||||
config.setProperty("max-range", maxRange);
|
||||
config.save();
|
||||
}
|
||||
|
||||
public String getDefaultLocation() {
|
||||
return config.getString("default-location", "{world}");
|
||||
}
|
||||
|
||||
public boolean isPerLocationPermission() {
|
||||
return config.getBoolean("per-location-permission", false);
|
||||
}
|
||||
|
||||
public Set<String> getExcludedBiomes() {
|
||||
final Set<String> excludedBiomes = new HashSet<>();
|
||||
for (final String key : config.getList("excluded-biomes", String.class)) {
|
||||
excludedBiomes.add(key.toLowerCase());
|
||||
public Set<Biome> getExcludedBiomes() {
|
||||
final List<String> biomeNames = config.getList("excluded-biomes", String.class);
|
||||
final Set<Biome> excludedBiomes = new HashSet<>();
|
||||
for (final String biomeName : biomeNames) {
|
||||
try {
|
||||
excludedBiomes.add(Biome.valueOf(biomeName.toUpperCase()));
|
||||
} catch (final IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
return excludedBiomes;
|
||||
}
|
||||
@@ -112,48 +96,39 @@ public class RandomTeleport implements IConf {
|
||||
return config.getInt("cache-threshold", 10);
|
||||
}
|
||||
|
||||
public List<String> listLocations() {
|
||||
return new ArrayList<>(ConfigurateUtil.getKeys(config.getRootNode().node("locations")));
|
||||
public boolean getPreCache() {
|
||||
return config.getBoolean("pre-cache", false);
|
||||
}
|
||||
|
||||
public Queue<Location> getCachedLocations(final String name) {
|
||||
this.cachedLocations.computeIfAbsent(name, x -> new ConcurrentLinkedQueue<>());
|
||||
return cachedLocations.get(name);
|
||||
public Queue<Location> getCachedLocations() {
|
||||
return cachedLocations;
|
||||
}
|
||||
|
||||
// Get a named random teleport location; cached if possible, otherwise on demand.
|
||||
public CompletableFuture<Location> getRandomLocation(final String name) {
|
||||
final Queue<Location> cached = this.getCachedLocations(name);
|
||||
// Get a random location; cached if possible. Otherwise on demand.
|
||||
public CompletableFuture<Location> getRandomLocation(final Location center, final double minRange, final double maxRange) {
|
||||
final int findAttempts = this.getFindAttempts();
|
||||
final Queue<Location> cachedLocations = this.getCachedLocations();
|
||||
// Try to build up the cache if it is below the threshold
|
||||
if (cached.size() < this.getCacheThreshold()) {
|
||||
cacheRandomLocations(name);
|
||||
if (cachedLocations.size() < this.getCacheThreshold()) {
|
||||
cacheRandomLocations(center, minRange, maxRange);
|
||||
}
|
||||
final CompletableFuture<Location> future = new CompletableFuture<>();
|
||||
// Return a random location immediately if one is available, otherwise try to find one now
|
||||
if (cached.isEmpty()) {
|
||||
final int findAttempts = this.getFindAttempts();
|
||||
final Location center = this.getCenter(name);
|
||||
final double minRange = this.getMinRange(name);
|
||||
final double maxRange = this.getMaxRange(name);
|
||||
if (cachedLocations.isEmpty()) {
|
||||
attemptRandomLocation(findAttempts, center, minRange, maxRange).thenAccept(future::complete);
|
||||
} else {
|
||||
future.complete(cached.poll());
|
||||
future.complete(cachedLocations.poll());
|
||||
}
|
||||
return future;
|
||||
}
|
||||
|
||||
// Get a random location with specific parameters (note: not cached).
|
||||
public CompletableFuture<Location> getRandomLocation(final Location center, final double minRange, final double maxRange) {
|
||||
return attemptRandomLocation(this.getFindAttempts(), center, minRange, maxRange);
|
||||
}
|
||||
|
||||
// Prompts caching random valid locations, up to a maximum number of attempts.
|
||||
public void cacheRandomLocations(final String name) {
|
||||
// Prompts caching random valid locations, up to a maximum number of attempts
|
||||
public void cacheRandomLocations(final Location center, final double minRange, final double maxRange) {
|
||||
ess.getServer().getScheduler().scheduleSyncDelayedTask(ess, () -> {
|
||||
for (int i = 0; i < this.getFindAttempts(); ++i) {
|
||||
calculateRandomLocation(getCenter(name), getMinRange(name), getMaxRange(name)).thenAccept(location -> {
|
||||
calculateRandomLocation(center, minRange, maxRange).thenAccept(location -> {
|
||||
if (isValidRandomLocation(location)) {
|
||||
this.getCachedLocations(name).add(location);
|
||||
this.getCachedLocations().add(location);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -202,7 +177,7 @@ public class RandomTeleport implements IConf {
|
||||
final Location location = new Location(
|
||||
center.getWorld(),
|
||||
center.getX() + offsetX,
|
||||
worldInfoProvider.getMaxHeight(center.getWorld()),
|
||||
ess.getWorldInfoProvider().getMaxHeight(center.getWorld()),
|
||||
center.getZ() + offsetZ,
|
||||
360 * RANDOM.nextFloat() - 180,
|
||||
0
|
||||
@@ -218,50 +193,18 @@ public class RandomTeleport implements IConf {
|
||||
return future;
|
||||
}
|
||||
|
||||
// Returns an appropriate elevation for a given location in the nether, or MIN_VALUE if none is found
|
||||
// Returns an appropriate elevation for a given location in the nether, or -1 if none is found
|
||||
private double getNetherYAt(final Location location) {
|
||||
final World world = location.getWorld();
|
||||
for (int y = 32; y < worldInfoProvider.getMaxHeight(world); ++y) {
|
||||
if (Material.BEDROCK.equals(world.getBlockAt(location.getBlockX(), y, location.getBlockZ()).getType())) {
|
||||
break;
|
||||
}
|
||||
if (!LocationUtil.isBlockUnsafe(ess, world, location.getBlockX(), y, location.getBlockZ())) {
|
||||
for (int y = 32; y < ess.getWorldInfoProvider().getMaxHeight(location.getWorld()); ++y) {
|
||||
if (!LocationUtil.isBlockUnsafe(ess, location.getWorld(), location.getBlockX(), y, location.getBlockZ())) {
|
||||
return y;
|
||||
}
|
||||
}
|
||||
return Double.MIN_VALUE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private boolean isValidRandomLocation(final Location location) {
|
||||
return location.getBlockY() > worldInfoProvider.getMinHeight(location.getWorld()) && !isExcludedBiome(location);
|
||||
}
|
||||
|
||||
// Exclude biome if enum or namespaced key matches
|
||||
private boolean isExcludedBiome(final Location location) {
|
||||
final Set<String> excluded = getExcludedBiomes();
|
||||
final String enumKey = location.getBlock().getBiome().name().toLowerCase();
|
||||
// Try with good old bukkit enum
|
||||
if (excluded.contains(enumKey)) {
|
||||
return true;
|
||||
}
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_14_4_R01)) {
|
||||
// No way to get the biome key on versions below this
|
||||
return false;
|
||||
}
|
||||
final String biomeKey;
|
||||
final BiomeKeyProvider biomeKeyProvider = ess.provider(BiomeKeyProvider.class);
|
||||
if (biomeKeyProvider != null) {
|
||||
// Works with custom biome keys
|
||||
biomeKey = biomeKeyProvider.getBiomeKey(location.getBlock()).toString();
|
||||
} else {
|
||||
// Custom biome keys resolve as "minecraft:custom" which is unfortunate
|
||||
biomeKey = location.getBlock().getBiome().getKey().toString();
|
||||
}
|
||||
return excluded.contains(biomeKey);
|
||||
}
|
||||
|
||||
private String locationKey(final String name, final String key) {
|
||||
return "locations." + name + "." + key;
|
||||
return location.getBlockY() > ess.getWorldInfoProvider().getMinHeight(location.getWorld()) && !this.getExcludedBiomes().contains(location.getBlock().getBiome());
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
|
||||
@@ -8,25 +8,16 @@ import com.earth2me.essentials.signs.EssentialsSign;
|
||||
import com.earth2me.essentials.signs.Signs;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.SyncCommandsProvider;
|
||||
import net.essentialsx.api.v2.ChatType;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
|
||||
import java.io.File;
|
||||
@@ -38,7 +29,6 @@ import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -49,22 +39,19 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Settings implements net.ess3.api.ISettings {
|
||||
private static final BigDecimal DEFAULT_MAX_MONEY = new BigDecimal("10000000000000");
|
||||
private static final BigDecimal DEFAULT_MIN_MONEY = new BigDecimal("-10000000000000");
|
||||
private static final Tag DEFAULT_PRIMARY_COLOR = Tag.styling(NamedTextColor.GOLD);
|
||||
private static final Tag DEFAULT_SECONDARY_COLOR = Tag.styling(NamedTextColor.RED);
|
||||
private final transient EssentialsConfiguration config;
|
||||
private final transient IEssentials ess;
|
||||
private final transient AtomicInteger reloadCount = new AtomicInteger(0);
|
||||
private final ChatFormats chatFormats = new ChatFormats();
|
||||
private final Map<String, String> chatFormats = Collections.synchronizedMap(new HashMap<>());
|
||||
private int chatRadius = 0;
|
||||
// #easteregg
|
||||
private char chatShout = '!';
|
||||
@@ -149,10 +136,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
private double maxProjectileSpeed;
|
||||
private boolean removeEffectsOnHeal;
|
||||
private Map<String, String> worldAliases;
|
||||
private Tag primaryColor = DEFAULT_PRIMARY_COLOR;
|
||||
private Tag secondaryColor = DEFAULT_SECONDARY_COLOR;
|
||||
private Set<String> multiplierPerms;
|
||||
private BigDecimal defaultMultiplier;
|
||||
|
||||
public Settings(final IEssentials ess) {
|
||||
this.ess = ess;
|
||||
@@ -170,16 +153,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("respawn-at-home", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomSpawnLocation() {
|
||||
return config.getString("random-spawn-location", "none");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRandomRespawnLocation() {
|
||||
return config.getString("random-respawn-location", "none");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRespawnAtAnchor() {
|
||||
return config.getBoolean("respawn-at-anchor", false);
|
||||
@@ -206,7 +179,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
final Set<String> homeList = getMultipleHomes();
|
||||
if (homeList != null) {
|
||||
for (final String set : homeList) {
|
||||
if (user.isAuthorized("essentials.sethome.multiple." + set) && limit < getHomeLimit(set)) {
|
||||
if (user.isAuthorized("essentials.sethome.multiple." + set) && (limit < getHomeLimit(set))) {
|
||||
limit = getHomeLimit(set);
|
||||
}
|
||||
}
|
||||
@@ -266,11 +239,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("chat.question-enabled", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsePaperChatEvent() {
|
||||
return config.getBoolean("chat.paper-chat-events", true);
|
||||
}
|
||||
|
||||
public boolean _isTeleportSafetyEnabled() {
|
||||
return config.getBoolean("teleport-safety", true);
|
||||
}
|
||||
@@ -345,11 +313,9 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
private void _addAlternativeCommand(final String label, final Command current) {
|
||||
final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class);
|
||||
|
||||
Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label);
|
||||
if (cmd == null) {
|
||||
for (final Map.Entry<String, Command> entry : knownCommandsProvider.getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
final String[] split = entry.getKey().split(":");
|
||||
if (entry.getValue() != current && split[split.length - 1].equals(label)) {
|
||||
cmd = entry.getValue();
|
||||
@@ -359,7 +325,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
if (cmd != null) {
|
||||
knownCommandsProvider.getKnownCommands().put(label, cmd);
|
||||
ess.getKnownCommandsProvider().getKnownCommands().put(label, cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,11 +447,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("socialspy-messages", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSocialSpyDisplayNames() {
|
||||
return config.getBoolean("socialspy-uses-displaynames", true);
|
||||
}
|
||||
|
||||
private Set<String> _getMuteCommands() {
|
||||
final Set<String> muteCommands = new HashSet<>();
|
||||
if (config.isList("mute-commands")) {
|
||||
@@ -604,132 +565,32 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
|
||||
@Override
|
||||
public String getChatFormat(final String group) {
|
||||
return getChatFormat(group, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChatFormat(final String group, final ChatType chatType) {
|
||||
final String mFormat = chatFormats.getFormat(group, chatType, new ChatFormatConfigSupplier(group, chatType));
|
||||
String mFormat = chatFormats.get(group);
|
||||
if (mFormat == null) {
|
||||
mFormat = config.getString("chat.group-formats." + (group == null ? "Default" : group), config.getString("chat.format", "&7[{GROUP}]&r {DISPLAYNAME}&7:&r {MESSAGE}"));
|
||||
mFormat = FormatUtil.replaceFormat(mFormat);
|
||||
mFormat = mFormat.replace("{DISPLAYNAME}", "%1$s");
|
||||
mFormat = mFormat.replace("{MESSAGE}", "%2$s");
|
||||
mFormat = mFormat.replace("{GROUP}", "{0}");
|
||||
mFormat = mFormat.replace("{WORLD}", "{1}");
|
||||
mFormat = mFormat.replace("{WORLDNAME}", "{1}");
|
||||
mFormat = mFormat.replace("{SHORTWORLDNAME}", "{2}");
|
||||
mFormat = mFormat.replace("{TEAMPREFIX}", "{3}");
|
||||
mFormat = mFormat.replace("{TEAMSUFFIX}", "{4}");
|
||||
mFormat = mFormat.replace("{TEAMNAME}", "{5}");
|
||||
mFormat = mFormat.replace("{PREFIX}", "{6}");
|
||||
mFormat = mFormat.replace("{SUFFIX}", "{7}");
|
||||
mFormat = mFormat.replace("{USERNAME}", "{8}");
|
||||
mFormat = mFormat.replace("{NICKNAME}", "{9}");
|
||||
mFormat = "§r".concat(mFormat);
|
||||
chatFormats.put(group, mFormat);
|
||||
}
|
||||
if (isDebug()) {
|
||||
ess.getLogger().info(String.format("Found format '%s' for group '%s'", mFormat, group));
|
||||
}
|
||||
return mFormat;
|
||||
}
|
||||
|
||||
private class ChatFormatConfigSupplier implements Supplier<String> {
|
||||
private final String group;
|
||||
private final ChatType chatType;
|
||||
|
||||
ChatFormatConfigSupplier(String group, ChatType chatType) {
|
||||
this.group = group;
|
||||
this.chatType = chatType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
final String chatKey = chatType.key();
|
||||
|
||||
final String groupPath = "chat.group-formats." + (group == null ? "Default" : group);
|
||||
String configFormat = config.getString(groupPath + "." + chatKey, null);
|
||||
|
||||
if (configFormat == null) {
|
||||
configFormat = config.getString(groupPath, null);
|
||||
}
|
||||
|
||||
final String formatPath = "chat.format";
|
||||
if (configFormat == null) {
|
||||
configFormat = config.getString(formatPath + "." + chatKey, null);
|
||||
}
|
||||
|
||||
if (configFormat == null) {
|
||||
configFormat = config.getString(formatPath, null);
|
||||
}
|
||||
|
||||
if (configFormat == null) {
|
||||
configFormat = "&7[{GROUP}]&r {DISPLAYNAME}&7:&r {MESSAGE}";
|
||||
}
|
||||
|
||||
configFormat = FormatUtil.replaceFormat(configFormat);
|
||||
configFormat = configFormat.replace("{DISPLAYNAME}", "%1$s");
|
||||
configFormat = configFormat.replace("{MESSAGE}", "%2$s");
|
||||
configFormat = configFormat.replace("{GROUP}", "{0}");
|
||||
configFormat = configFormat.replace("{WORLD}", "{1}");
|
||||
configFormat = configFormat.replace("{WORLDNAME}", "{1}");
|
||||
configFormat = configFormat.replace("{SHORTWORLDNAME}", "{2}");
|
||||
configFormat = configFormat.replace("{TEAMPREFIX}", "{3}");
|
||||
configFormat = configFormat.replace("{TEAMSUFFIX}", "{4}");
|
||||
configFormat = configFormat.replace("{TEAMNAME}", "{5}");
|
||||
configFormat = configFormat.replace("{PREFIX}", "{6}");
|
||||
configFormat = configFormat.replace("{SUFFIX}", "{7}");
|
||||
configFormat = configFormat.replace("{USERNAME}", "{8}");
|
||||
configFormat = configFormat.replace("{NICKNAME}", "{9}");
|
||||
configFormat = "§r".concat(configFormat);
|
||||
return configFormat;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChatFormats {
|
||||
|
||||
private final Map<String, TypedChatFormat> groupFormats;
|
||||
private TypedChatFormat defaultFormat;
|
||||
|
||||
ChatFormats() {
|
||||
defaultFormat = null;
|
||||
groupFormats = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getFormat(String group, ChatType type, Supplier<String> configSupplier) {
|
||||
// With such a large synchronize block, we synchronize a potential config deserialization
|
||||
// It does not matter as it needs to be done. It's even better as we ensure to do it once
|
||||
// TypedChatFormat is also synchronized
|
||||
synchronized (this) {
|
||||
final TypedChatFormat typedChatFormat;
|
||||
if (group == null) {
|
||||
if (defaultFormat == null) {
|
||||
defaultFormat = new TypedChatFormat();
|
||||
}
|
||||
typedChatFormat = defaultFormat;
|
||||
} else {
|
||||
typedChatFormat = groupFormats.computeIfAbsent(group, s -> new TypedChatFormat());
|
||||
}
|
||||
return typedChatFormat.getFormat(type, configSupplier);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
synchronized (this) {
|
||||
defaultFormat = null;
|
||||
groupFormats.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class TypedChatFormat {
|
||||
|
||||
private final Map<ChatType, String> typedFormats;
|
||||
private String defaultFormat;
|
||||
|
||||
TypedChatFormat() {
|
||||
defaultFormat = null;
|
||||
typedFormats = new EnumMap<>(ChatType.class);
|
||||
}
|
||||
|
||||
public String getFormat(ChatType type, Supplier<String> configSupplier) {
|
||||
final String format;
|
||||
if (type == null) {
|
||||
if (defaultFormat == null) {
|
||||
defaultFormat = configSupplier.get();
|
||||
}
|
||||
format = defaultFormat;
|
||||
} else {
|
||||
format = typedFormats.computeIfAbsent(type, c -> configSupplier.get());
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWorldAlias(String world) {
|
||||
return worldAliases.getOrDefault(world.toLowerCase(), world);
|
||||
@@ -818,32 +679,18 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
overriddenCommands = _getOverriddenCommands();
|
||||
playerCommands = _getPlayerCommands();
|
||||
|
||||
final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class);
|
||||
|
||||
// This will be late loaded
|
||||
if (knownCommandsProvider != null) {
|
||||
if (ess.getKnownCommandsProvider() != null) {
|
||||
boolean mapModified = false;
|
||||
if (!disabledBukkitCommands.isEmpty()) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!");
|
||||
}
|
||||
knownCommandsProvider.getKnownCommands().putAll(disabledBukkitCommands);
|
||||
ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands);
|
||||
disabledBukkitCommands.clear();
|
||||
mapModified = true;
|
||||
}
|
||||
|
||||
if (reloadCount.get() < 2) {
|
||||
// on startup: add plugins again in case they registered commands with the new API
|
||||
// we need to schedule this task before any of the below tasks using _addAlternativeCommand.
|
||||
ess.scheduleSyncDelayedTask(() -> {
|
||||
for (final Plugin plugin : ess.getServer().getPluginManager().getPlugins()) {
|
||||
if (plugin.isEnabled()) {
|
||||
ess.getAlternativeCommandsHandler().addPlugin(plugin);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (final String command : disabledCommands) {
|
||||
final String effectiveAlias = command.toLowerCase(Locale.ENGLISH);
|
||||
final Command toDisable = ess.getPluginCommand(effectiveAlias);
|
||||
@@ -851,7 +698,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias);
|
||||
}
|
||||
final Command removed = knownCommandsProvider.getKnownCommands().remove(effectiveAlias);
|
||||
final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias);
|
||||
if (removed != null) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!");
|
||||
@@ -869,16 +716,14 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
}
|
||||
|
||||
final SyncCommandsProvider syncCommandsProvider = ess.provider(SyncCommandsProvider.class);
|
||||
|
||||
if (mapModified) {
|
||||
if (isDebug()) {
|
||||
ess.getLogger().log(Level.INFO, "Syncing commands");
|
||||
}
|
||||
if (reloadCount.get() < 2) {
|
||||
ess.scheduleSyncDelayedTask(syncCommandsProvider::syncCommands);
|
||||
ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands());
|
||||
} else {
|
||||
syncCommandsProvider.syncCommands();
|
||||
ess.getSyncCommandsProvider().syncCommands();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -934,10 +779,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
bindingItemPolicy = _getBindingItemsPolicy();
|
||||
currencySymbol = _getCurrencySymbol();
|
||||
worldAliases = _getWorldAliases();
|
||||
primaryColor = _getPrimaryColor();
|
||||
secondaryColor = _getSecondaryColor();
|
||||
multiplierPerms = _getMultiplierPerms();
|
||||
defaultMultiplier = _getDefaultMultiplier();
|
||||
|
||||
reloadCount.incrementAndGet();
|
||||
}
|
||||
@@ -968,7 +809,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
final ItemStack iStack = itemDb.get(itemName);
|
||||
epItemSpwn.add(iStack.getType());
|
||||
} catch (final Exception ex) {
|
||||
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", itemName, "item-spawn-blacklist")), ex);
|
||||
ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"), ex);
|
||||
}
|
||||
}
|
||||
return epItemSpwn;
|
||||
@@ -996,7 +837,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
try {
|
||||
newSigns.add(Signs.valueOf(signName).getSign());
|
||||
} catch (final Exception ex) {
|
||||
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", signName, "enabledSigns")));
|
||||
ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "enabledSigns"));
|
||||
continue;
|
||||
}
|
||||
signsEnabled = true;
|
||||
@@ -1042,11 +883,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getString("locale", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPerPlayerLocale() {
|
||||
return config.getBoolean("per-player-locale", false);
|
||||
}
|
||||
|
||||
private String currencySymbol = "$";
|
||||
|
||||
// A valid currency symbol value must be one non-integer character.
|
||||
@@ -1096,23 +932,14 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getProtectListRaw(String configName) {
|
||||
final List<String> list = new ArrayList<>();
|
||||
public List<Material> getProtectList(final String configName) {
|
||||
final List<Material> list = new ArrayList<>();
|
||||
for (String itemName : config.getString(configName, "").split(",")) {
|
||||
itemName = itemName.trim();
|
||||
if (itemName.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
list.add(itemName);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> getProtectList(final String configName) {
|
||||
final List<Material> list = new ArrayList<>();
|
||||
for (String itemName : getProtectListRaw(configName)) {
|
||||
Material mat = EnumUtil.getMaterial(itemName.toUpperCase());
|
||||
|
||||
if (mat == null) {
|
||||
@@ -1124,7 +951,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
}
|
||||
|
||||
if (mat == null) {
|
||||
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", itemName, configName)));
|
||||
ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", itemName, configName));
|
||||
} else {
|
||||
list.add(mat);
|
||||
}
|
||||
@@ -1642,16 +1469,10 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
// #easteregg
|
||||
@Override
|
||||
public int getMaxUserCacheCount() {
|
||||
final long count = Runtime.getRuntime().maxMemory() / 1024 / 1024;
|
||||
final long count = Runtime.getRuntime().maxMemory() / 1024 / 96;
|
||||
return config.getInt("max-user-cache-count", (int) count);
|
||||
}
|
||||
|
||||
// #easteregg
|
||||
@Override
|
||||
public long getMaxUserCacheValueExpiry() {
|
||||
return config.getLong("max-user-cache-value-expiry", 600);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLastMessageReplyRecipient() {
|
||||
return config.getBoolean("last-message-reply-recipient", false);
|
||||
@@ -1872,7 +1693,7 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
try {
|
||||
newSigns.add(Signs.valueOf(signName).getSign());
|
||||
} catch (final Exception ex) {
|
||||
ess.getLogger().log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("unknownItemInList", signName, "unprotected-sign-names")));
|
||||
ess.getLogger().log(Level.SEVERE, tl("unknownItemInList", signName, "unprotected-sign-names"));
|
||||
}
|
||||
}
|
||||
return newSigns;
|
||||
@@ -1933,11 +1754,6 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
return config.getBoolean("world-change-fly-reset", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldChangePreserveFlying() {
|
||||
return config.getBoolean("world-change-preserve-flying", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWorldChangeSpeedResetEnabled() {
|
||||
return config.getBoolean("world-change-speed-reset", true);
|
||||
@@ -1945,7 +1761,9 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
|
||||
private List<String> _getDefaultEnabledConfirmCommands() {
|
||||
final List<String> commands = config.getList("default-enabled-confirm-commands", String.class);
|
||||
commands.replaceAll(String::toLowerCase);
|
||||
for (int i = 0; i < commands.size(); i++) {
|
||||
commands.set(i, commands.get(i).toLowerCase());
|
||||
}
|
||||
return commands;
|
||||
}
|
||||
|
||||
@@ -2119,84 +1937,4 @@ public class Settings implements net.ess3.api.ISettings {
|
||||
public boolean showZeroBaltop() {
|
||||
return config.getBoolean("show-zero-baltop", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getMultiplier(final User user) {
|
||||
BigDecimal multiplier = defaultMultiplier;
|
||||
if (multiplierPerms == null) {
|
||||
return defaultMultiplier;
|
||||
}
|
||||
|
||||
for (final String multiplierPerm : multiplierPerms) {
|
||||
if (user.isAuthorized("essentials.sell.multiplier." + multiplierPerm)) {
|
||||
final BigDecimal value = config.getBigDecimal("sell-multipliers." + multiplierPerm, BigDecimal.ZERO);
|
||||
if (value.compareTo(multiplier) > 0) {
|
||||
multiplier = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return multiplier;
|
||||
}
|
||||
|
||||
private BigDecimal _getDefaultMultiplier() {
|
||||
return config.getBigDecimal("sell-multipliers.default", BigDecimal.ONE);
|
||||
}
|
||||
|
||||
private Set<String> _getMultiplierPerms() {
|
||||
final CommentedConfigurationNode section = config.getSection("sell-multipliers");
|
||||
return section == null ? null : ConfigurateUtil.getKeys(section);
|
||||
}
|
||||
|
||||
public int getMaxItemLore() {
|
||||
return config.getInt("max-itemlore-lines", 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag getPrimaryColor() {
|
||||
return primaryColor;
|
||||
}
|
||||
|
||||
private Tag _getPrimaryColor() {
|
||||
final String color = config.getString("message-colors.primary", "#ffaa00");
|
||||
final TextColor textColor = _getTagColor(color);
|
||||
return textColor != null ? Tag.styling(textColor) : DEFAULT_PRIMARY_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag getSecondaryColor() {
|
||||
return secondaryColor;
|
||||
}
|
||||
|
||||
private Tag _getSecondaryColor() {
|
||||
final String color = config.getString("message-colors.secondary", "#ff5555");
|
||||
final TextColor textColor = _getTagColor(color);
|
||||
return textColor != null ? Tag.styling(textColor) : DEFAULT_SECONDARY_COLOR;
|
||||
}
|
||||
|
||||
private TextColor _getTagColor(final String color) {
|
||||
try {
|
||||
if (color.startsWith("#") && color.length() == 7 && NumberUtil.isHexadecimal(color.substring(1))) {
|
||||
return TextColor.color(Color.fromRGB(Integer.decode(color)).asRGB());
|
||||
}
|
||||
|
||||
if (color.length() == 1) {
|
||||
return AdventureUtil.fromChar(color.charAt(0));
|
||||
}
|
||||
|
||||
return NamedTextColor.NAMES.value(color.toLowerCase(Locale.ENGLISH));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBaltopMinBalance() {
|
||||
return config.getBigDecimal("baltop-requirements.minimum-balance", BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBaltopMinPlaytime() {
|
||||
return config.getLong("baltop-requirements.minimum-playtime", 0);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
@@ -28,6 +27,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public final class SpawnMob {
|
||||
|
||||
private static final Material GOLDEN_HELMET = EnumUtil.getMaterial("GOLDEN_HELMET", "GOLD_HELMET");
|
||||
@@ -48,7 +49,7 @@ public final class SpawnMob {
|
||||
}
|
||||
}
|
||||
if (availableList.isEmpty()) {
|
||||
availableList.add(user.playerTl("none"));
|
||||
availableList.add(tl("none"));
|
||||
}
|
||||
return StringUtil.joinList(availableList);
|
||||
}
|
||||
@@ -90,7 +91,7 @@ public final class SpawnMob {
|
||||
public static void spawnmob(final IEssentials ess, final Server server, final User user, final List<String> parts, final List<String> data, final int mobCount) throws Exception {
|
||||
final Block block = LocationUtil.getTarget(user.getBase()).getBlock();
|
||||
if (block == null) {
|
||||
throw new TranslatableException("unableToSpawnMob");
|
||||
throw new Exception(tl("unableToSpawnMob"));
|
||||
}
|
||||
spawnmob(ess, server, user.getSource(), user, block.getLocation(), parts, data, mobCount);
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public final class SpawnMob {
|
||||
|
||||
if (mobCount > effectiveLimit) {
|
||||
mobCount = effectiveLimit;
|
||||
sender.sendTl("mobSpawnLimit");
|
||||
sender.sendMessage(tl("mobSpawnLimit"));
|
||||
}
|
||||
|
||||
final Mob mob = Mob.fromName(parts.get(0)); // Get the first mob
|
||||
@@ -129,13 +130,13 @@ public final class SpawnMob {
|
||||
for (int i = 0; i < mobCount; i++) {
|
||||
spawnMob(ess, server, sender, target, sloc, parts, data);
|
||||
}
|
||||
sender.sendMessage(mobCount * parts.size() + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + sender.tl("spawned"));
|
||||
sender.sendMessage(mobCount * parts.size() + " " + mob.name.toLowerCase(Locale.ENGLISH) + mob.suffix + " " + tl("spawned"));
|
||||
} catch (final MobException e1) {
|
||||
throw new TranslatableException(e1, "unableToSpawnMob");
|
||||
throw new Exception(tl("unableToSpawnMob"), e1);
|
||||
} catch (final NumberFormatException e2) {
|
||||
throw new TranslatableException(e2, "numberRequired");
|
||||
throw new Exception(tl("numberRequired"), e2);
|
||||
} catch (final NullPointerException np) {
|
||||
throw new TranslatableException(np, "soloMob");
|
||||
throw new Exception(tl("soloMob"), np);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,15 +176,15 @@ public final class SpawnMob {
|
||||
|
||||
private static void checkSpawnable(final IEssentials ess, final CommandSource sender, final Mob mob) throws Exception {
|
||||
if (mob == null || mob.getType() == null) {
|
||||
throw new TranslatableException("invalidMob");
|
||||
throw new Exception(tl("invalidMob"));
|
||||
}
|
||||
|
||||
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
|
||||
throw new TranslatableException("disabledToSpawnMob");
|
||||
throw new Exception(tl("disabledToSpawnMob"));
|
||||
}
|
||||
|
||||
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.spawnmob." + mob.name.toLowerCase(Locale.ENGLISH))) {
|
||||
throw new TranslatableException("noPermToSpawnMob");
|
||||
throw new Exception(tl("noPermToSpawnMob"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +192,7 @@ public final class SpawnMob {
|
||||
String data = inputData;
|
||||
|
||||
if (data.isEmpty()) {
|
||||
sender.sendTl("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned)));
|
||||
sender.sendMessage(tl("mobDataList", StringUtil.joinList(MobData.getValidHelp(spawned))));
|
||||
}
|
||||
|
||||
if (spawned instanceof Zombie) {
|
||||
|
||||
@@ -0,0 +1,403 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.ITeleport;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.events.UserWarpEvent;
|
||||
import net.ess3.api.events.teleport.PreTeleportEvent;
|
||||
import net.ess3.api.events.teleport.TeleportWarmupEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
/**
|
||||
* @deprecated This API is not asynchronous. Use {@link com.earth2me.essentials.AsyncTeleport AsyncTeleport}
|
||||
*/
|
||||
@Deprecated
|
||||
public class Teleport implements ITeleport {
|
||||
private final IUser teleportOwner;
|
||||
private final IEssentials ess;
|
||||
private TimedTeleport timedTeleport;
|
||||
|
||||
private TeleportType tpType;
|
||||
|
||||
@Deprecated
|
||||
public Teleport(final IUser user, final IEssentials ess) {
|
||||
this.teleportOwner = user;
|
||||
this.ess = ess;
|
||||
tpType = TeleportType.NORMAL;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void cooldown(final boolean check) throws Exception {
|
||||
final Calendar time = new GregorianCalendar();
|
||||
if (teleportOwner.getLastTeleportTimestamp() > 0) {
|
||||
// Take the current time, and remove the delay from it.
|
||||
final double cooldown = ess.getSettings().getTeleportCooldown();
|
||||
final Calendar earliestTime = new GregorianCalendar();
|
||||
earliestTime.add(Calendar.SECOND, -(int) cooldown);
|
||||
earliestTime.add(Calendar.MILLISECOND, -(int) ((cooldown * 1000.0) % 1000.0));
|
||||
// This value contains the most recent time a teleportPlayer could have been used that would allow another use.
|
||||
final long earliestLong = earliestTime.getTimeInMillis();
|
||||
|
||||
// When was the last teleportPlayer used?
|
||||
final long lastTime = teleportOwner.getLastTeleportTimestamp();
|
||||
|
||||
if (lastTime > time.getTimeInMillis()) {
|
||||
// This is to make sure time didn't get messed up on last teleportPlayer use.
|
||||
// If this happens, let's give the user the benifit of the doubt.
|
||||
teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis());
|
||||
return;
|
||||
} else if (lastTime > earliestLong
|
||||
&& cooldownApplies()) {
|
||||
time.setTimeInMillis(lastTime);
|
||||
time.add(Calendar.SECOND, (int) cooldown);
|
||||
time.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0));
|
||||
throw new Exception(tl("timeBeforeTeleport", DateUtil.formatDateDiff(time.getTimeInMillis())));
|
||||
}
|
||||
}
|
||||
// if justCheck is set, don't update lastTeleport; we're just checking
|
||||
if (!check) {
|
||||
teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private boolean cooldownApplies() {
|
||||
boolean applies = true;
|
||||
final String globalBypassPerm = "essentials.teleport.cooldown.bypass";
|
||||
switch (tpType) {
|
||||
case NORMAL:
|
||||
applies = !teleportOwner.isAuthorized(globalBypassPerm);
|
||||
break;
|
||||
case BACK:
|
||||
applies = !(teleportOwner.isAuthorized(globalBypassPerm) &&
|
||||
teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass.back"));
|
||||
break;
|
||||
case TPA:
|
||||
applies = !(teleportOwner.isAuthorized(globalBypassPerm) &&
|
||||
teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass.tpa"));
|
||||
break;
|
||||
}
|
||||
return applies;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
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())));
|
||||
}
|
||||
|
||||
//The now function is used when you want to skip tp delay when teleporting someone to a location or player.
|
||||
@Override
|
||||
@Deprecated
|
||||
public void now(final Location loc, final boolean cooldown, final TeleportCause cause) throws Exception {
|
||||
if (cooldown) {
|
||||
cooldown(false);
|
||||
}
|
||||
final ITarget target = new LocationTarget(loc);
|
||||
now(teleportOwner, target, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void now(final Player entity, final boolean cooldown, final TeleportCause cause) throws Exception {
|
||||
if (cooldown) {
|
||||
cooldown(false);
|
||||
}
|
||||
final ITarget target = new PlayerTarget(entity);
|
||||
now(teleportOwner, target, cause);
|
||||
teleportOwner.sendMessage(tl("teleporting", target.getLocation().getWorld().getName(), target.getLocation().getBlockX(), target.getLocation().getBlockY(), target.getLocation().getBlockZ()));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void now(final IUser teleportee, final ITarget target, final TeleportCause cause) throws Exception {
|
||||
cancel(false);
|
||||
Location loc = target.getLocation();
|
||||
|
||||
final PreTeleportEvent event = new PreTeleportEvent(teleportee, cause, target);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (teleportee.isAuthorized("essentials.back.onteleport")) {
|
||||
teleportee.setLastLocation();
|
||||
}
|
||||
|
||||
if (!teleportee.getBase().isEmpty()) {
|
||||
if (!ess.getSettings().isTeleportPassengerDismount()) {
|
||||
throw new Exception(tl("passengerTeleportFail"));
|
||||
}
|
||||
teleportee.getBase().eject();
|
||||
}
|
||||
|
||||
if (LocationUtil.isBlockUnsafeForUser(ess, teleportee, loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
|
||||
if (ess.getSettings().isTeleportSafetyEnabled()) {
|
||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
} else {
|
||||
PaperLib.teleportAsync(teleportee.getBase(), LocationUtil.getSafeDestination(ess, teleportee, loc), cause);
|
||||
}
|
||||
} else {
|
||||
throw new Exception(tl("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
} else {
|
||||
if (ess.getSettings().isForceDisableTeleportSafety()) {
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
} else {
|
||||
if (ess.getSettings().isTeleportToCenterLocation()) {
|
||||
loc = LocationUtil.getRoundedDestination(loc);
|
||||
}
|
||||
PaperLib.teleportAsync(teleportee.getBase(), loc, cause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//The teleportPlayer function is used when you want to normally teleportPlayer someone to a location or player.
|
||||
//This method is nolonger used internally and will be removed.
|
||||
@Deprecated
|
||||
@Override
|
||||
public void teleport(final Location loc, final Trade chargeFor) throws Exception {
|
||||
teleport(loc, chargeFor, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleport(final Location loc, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
teleport(teleportOwner, new LocationTarget(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//This is used when teleporting to a player
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleport(final Player entity, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
final ITarget target = new PlayerTarget(entity);
|
||||
teleportOwner.sendMessage(tl("teleportToPlayer", entity.getDisplayName()));
|
||||
teleport(teleportOwner, target, chargeFor, cause);
|
||||
}
|
||||
|
||||
//This is used when teleporting to stored location
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleportPlayer(final IUser teleportee, final Location loc, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//This is used on /tphere
|
||||
@Override
|
||||
@Deprecated
|
||||
public void teleportPlayer(final IUser teleportee, final Player entity, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
final ITarget target = new PlayerTarget(entity);
|
||||
teleport(teleportee, target, chargeFor, cause);
|
||||
teleportee.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()));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void teleport(final IUser teleportee, final ITarget target, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
final TeleportWarmupEvent event = new TeleportWarmupEvent(teleportee, cause, target, delay);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
delay = event.getDelay();
|
||||
|
||||
Trade cashCharge = chargeFor;
|
||||
|
||||
if (chargeFor != null) {
|
||||
chargeFor.isAffordableFor(teleportOwner);
|
||||
|
||||
//This code is to make sure that commandcosts are checked in the initial world, and not in the resulting world.
|
||||
if (!chargeFor.getCommandCost(teleportOwner).equals(BigDecimal.ZERO)) {
|
||||
//By converting a command cost to a regular cost, the command cost permission isn't checked when executing the charge after teleport.
|
||||
cashCharge = new Trade(chargeFor.getCommandCost(teleportOwner), ess);
|
||||
}
|
||||
}
|
||||
|
||||
cooldown(true);
|
||||
if (delay <= 0 || teleportOwner.isAuthorized("essentials.teleport.timer.bypass") || teleportee.isAuthorized("essentials.teleport.timer.bypass")) {
|
||||
cooldown(false);
|
||||
now(teleportee, target, cause);
|
||||
if (cashCharge != null) {
|
||||
cashCharge.charge(teleportOwner);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(teleportee, delay);
|
||||
initTimer((long) (delay * 1000.0), teleportee, target, cashCharge, cause, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void teleportOther(final IUser teleporter, final IUser teleportee, final ITarget target, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
final TeleportWarmupEvent event = new TeleportWarmupEvent(teleporter, teleportee, cause, target, delay);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
delay = event.getDelay();
|
||||
|
||||
Trade cashCharge = chargeFor;
|
||||
|
||||
if (teleporter != null && chargeFor != null) {
|
||||
chargeFor.isAffordableFor(teleporter);
|
||||
|
||||
//This code is to make sure that commandcosts are checked in the initial world, and not in the resulting world.
|
||||
if (!chargeFor.getCommandCost(teleporter).equals(BigDecimal.ZERO)) {
|
||||
//By converting a command cost to a regular cost, the command cost permission isn't checked when executing the charge after teleport.
|
||||
cashCharge = new Trade(chargeFor.getCommandCost(teleporter), ess);
|
||||
}
|
||||
}
|
||||
|
||||
cooldown(true);
|
||||
if (delay <= 0 || teleporter == null
|
||||
|| teleporter.isAuthorized("essentials.teleport.timer.bypass")
|
||||
|| teleportOwner.isAuthorized("essentials.teleport.timer.bypass")
|
||||
|| teleportee.isAuthorized("essentials.teleport.timer.bypass")) {
|
||||
cooldown(false);
|
||||
now(teleportee, target, cause);
|
||||
if (teleporter != null && cashCharge != null) {
|
||||
cashCharge.charge(teleporter);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(teleportee, delay);
|
||||
initTimer((long) (delay * 1000.0), teleportee, target, cashCharge, cause, false);
|
||||
}
|
||||
|
||||
//The respawn function is a wrapper used to handle tp fallback, on /jail and /home
|
||||
@Override
|
||||
@Deprecated
|
||||
public void respawn(final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
double delay = ess.getSettings().getTeleportDelay();
|
||||
|
||||
final TeleportWarmupEvent event = new TeleportWarmupEvent(teleportOwner, cause, null, delay);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
delay = event.getDelay();
|
||||
|
||||
if (chargeFor != null) {
|
||||
chargeFor.isAffordableFor(teleportOwner);
|
||||
}
|
||||
cooldown(true);
|
||||
if (delay <= 0 || teleportOwner.isAuthorized("essentials.teleport.timer.bypass")) {
|
||||
cooldown(false);
|
||||
respawnNow(teleportOwner, cause);
|
||||
if (chargeFor != null) {
|
||||
chargeFor.charge(teleportOwner);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
cancel(false);
|
||||
warnUser(teleportOwner, delay);
|
||||
initTimer((long) (delay * 1000.0), teleportOwner, null, chargeFor, cause, true);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
void respawnNow(final IUser teleportee, final TeleportCause cause) throws Exception {
|
||||
final Player player = teleportee.getBase();
|
||||
final Location bed = player.getBedSpawnLocation();
|
||||
if (bed != null) {
|
||||
now(teleportee, new LocationTarget(bed), cause);
|
||||
} else {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("Could not find bed spawn, forcing respawn event.");
|
||||
}
|
||||
final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false);
|
||||
ess.getServer().getPluginManager().callEvent(pre);
|
||||
now(teleportee, new LocationTarget(pre.getRespawnLocation()), cause);
|
||||
}
|
||||
}
|
||||
|
||||
//The warp function is a wrapper used to teleportPlayer a player to a /warp
|
||||
@Override
|
||||
@Deprecated
|
||||
public void warp(final IUser teleportee, String warp, final Trade chargeFor, final TeleportCause cause) throws Exception {
|
||||
final UserWarpEvent event = new UserWarpEvent(teleportee, warp, chargeFor);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
warp = event.getWarp();
|
||||
final Location loc = ess.getWarps().getWarp(warp);
|
||||
teleportee.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
if (!teleportee.equals(teleportOwner)) {
|
||||
teleportOwner.sendMessage(tl("warpingTo", warp, loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
teleport(teleportee, new LocationTarget(loc), chargeFor, cause);
|
||||
}
|
||||
|
||||
//The back function is a wrapper used to teleportPlayer a player /back to their previous location.
|
||||
@Override
|
||||
@Deprecated
|
||||
public void back(final Trade chargeFor) throws Exception {
|
||||
back(teleportOwner, chargeFor);
|
||||
}
|
||||
|
||||
//This function is a wrapper over the other back function for cases where another player performs back for them
|
||||
@Override
|
||||
@Deprecated
|
||||
public void back(final IUser teleporter, final Trade chargeFor) throws Exception {
|
||||
tpType = TeleportType.BACK;
|
||||
final Location loc = teleportOwner.getLastLocation();
|
||||
teleportOwner.sendMessage(tl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
teleportOther(teleporter, teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND);
|
||||
}
|
||||
|
||||
//This function is used to throw a user back after a jail sentence
|
||||
@Override
|
||||
@Deprecated
|
||||
public void back() throws Exception {
|
||||
now(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), TeleportCause.COMMAND);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setTpType(final TeleportType tpType) {
|
||||
this.tpType = tpType;
|
||||
}
|
||||
|
||||
//If we need to cancelTimer a pending teleportPlayer call this method
|
||||
@Deprecated
|
||||
private void cancel(final boolean notifyUser) {
|
||||
if (timedTeleport != null) {
|
||||
timedTeleport.cancelTimer(notifyUser);
|
||||
timedTeleport = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private void initTimer(final long delay, final IUser teleportUser, final ITarget target, final Trade chargeFor, final TeleportCause cause, final boolean respawn) {
|
||||
timedTeleport = new TimedTeleport(teleportOwner, ess, this, delay, teleportUser, target, chargeFor, cause, respawn);
|
||||
}
|
||||
|
||||
public enum TeleportType {
|
||||
TPA,
|
||||
BACK,
|
||||
NORMAL
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
@Deprecated
|
||||
public class TimedTeleport implements Runnable {
|
||||
private static final double MOVE_CONSTANT = 0.3;
|
||||
private final IUser teleportOwner;
|
||||
private final IEssentials ess;
|
||||
private final Teleport teleport;
|
||||
private final UUID timer_teleportee;
|
||||
private final long timer_started; // time this task was initiated
|
||||
private final long timer_delay; // how long to delay the teleportPlayer
|
||||
// note that I initially stored a clone of the location for reference, but...
|
||||
// when comparing locations, I got incorrect mismatches (rounding errors, looked like)
|
||||
// so, the X/Y/Z values are stored instead and rounded off
|
||||
private final long timer_initX;
|
||||
private final long timer_initY;
|
||||
private final long timer_initZ;
|
||||
private final ITarget timer_teleportTarget;
|
||||
private final boolean timer_respawn;
|
||||
private final boolean timer_canMove;
|
||||
private final Trade timer_chargeFor;
|
||||
private final TeleportCause timer_cause;
|
||||
private int timer_task;
|
||||
private double timer_health;
|
||||
|
||||
TimedTeleport(final IUser user, final IEssentials ess, final Teleport teleport, final long delay, final IUser teleportUser, final ITarget target, final Trade chargeFor, final TeleportCause cause, final boolean respawn) {
|
||||
this.teleportOwner = user;
|
||||
this.ess = ess;
|
||||
this.teleport = teleport;
|
||||
this.timer_started = System.currentTimeMillis();
|
||||
this.timer_delay = delay;
|
||||
this.timer_health = teleportUser.getBase().getHealth();
|
||||
this.timer_initX = Math.round(teleportUser.getBase().getLocation().getX() * MOVE_CONSTANT);
|
||||
this.timer_initY = Math.round(teleportUser.getBase().getLocation().getY() * MOVE_CONSTANT);
|
||||
this.timer_initZ = Math.round(teleportUser.getBase().getLocation().getZ() * MOVE_CONSTANT);
|
||||
this.timer_teleportee = teleportUser.getBase().getUniqueId();
|
||||
this.timer_teleportTarget = target;
|
||||
this.timer_chargeFor = chargeFor;
|
||||
this.timer_cause = cause;
|
||||
this.timer_respawn = respawn;
|
||||
this.timer_canMove = user.isAuthorized("essentials.teleport.timer.move");
|
||||
|
||||
timer_task = ess.runTaskTimerAsynchronously(this, 20, 20).getTaskId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (teleportOwner == null || !teleportOwner.getBase().isOnline() || teleportOwner.getBase().getLocation() == null) {
|
||||
cancelTimer(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final IUser teleportUser = ess.getUser(this.timer_teleportee);
|
||||
|
||||
if (teleportUser == null || !teleportUser.getBase().isOnline()) {
|
||||
cancelTimer(false);
|
||||
return;
|
||||
}
|
||||
|
||||
final Location currLocation = teleportUser.getBase().getLocation();
|
||||
if (currLocation == null) {
|
||||
cancelTimer(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!timer_canMove && (Math.round(currLocation.getX() * MOVE_CONSTANT) != timer_initX || Math.round(currLocation.getY() * MOVE_CONSTANT) != timer_initY || Math.round(currLocation.getZ() * MOVE_CONSTANT) != timer_initZ || teleportUser.getBase().getHealth() < timer_health)) {
|
||||
// user moved, cancelTimer teleportPlayer
|
||||
cancelTimer(true);
|
||||
return;
|
||||
}
|
||||
|
||||
class DelayedTeleportTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
timer_health = teleportUser.getBase().getHealth(); // in case user healed, then later gets injured
|
||||
final long now = System.currentTimeMillis();
|
||||
if (now > timer_started + timer_delay) {
|
||||
try {
|
||||
teleport.cooldown(false);
|
||||
} catch (final Exception ex) {
|
||||
teleportOwner.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
|
||||
if (teleportOwner != teleportUser) {
|
||||
teleportUser.sendMessage(tl("cooldownWithMessage", ex.getMessage()));
|
||||
}
|
||||
}
|
||||
try {
|
||||
cancelTimer(false);
|
||||
teleportUser.sendMessage(tl("teleportationCommencing"));
|
||||
|
||||
if (timer_chargeFor != null) {
|
||||
timer_chargeFor.isAffordableFor(teleportOwner);
|
||||
}
|
||||
if (timer_respawn) {
|
||||
teleport.respawnNow(teleportUser, timer_cause);
|
||||
} else {
|
||||
teleport.now(teleportUser, timer_teleportTarget, timer_cause);
|
||||
}
|
||||
if (timer_chargeFor != null) {
|
||||
timer_chargeFor.charge(teleportOwner);
|
||||
}
|
||||
|
||||
} catch (final Exception ex) {
|
||||
ess.showError(teleportOwner.getSource(), ex, "\\ teleport");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ess.scheduleSyncDelayedTask(new DelayedTeleportTask());
|
||||
}
|
||||
|
||||
//If we need to cancelTimer a pending teleportPlayer call this method
|
||||
void cancelTimer(final boolean notifyUser) {
|
||||
if (timer_task == -1) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ess.getServer().getScheduler().cancelTask(timer_task);
|
||||
if (notifyUser) {
|
||||
teleportOwner.sendMessage(tl("pendingTeleportCancelled"));
|
||||
if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getBase().getUniqueId())) {
|
||||
ess.getUser(timer_teleportee).sendMessage(tl("pendingTeleportCancelled"));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
timer_task = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.IEssentials;
|
||||
@@ -24,6 +23,8 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Trade {
|
||||
private static FileWriter fw = null;
|
||||
private final transient String command;
|
||||
@@ -192,23 +193,23 @@ public class Trade {
|
||||
}
|
||||
|
||||
if (getMoney() != null && getMoney().signum() > 0 && !user.canAfford(getMoney())) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess))));
|
||||
future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (getItemStack() != null && !Inventories.containsAtLeast(user.getBase(), itemStack, itemStack.getAmount())) {
|
||||
future.completeExceptionally(new ChargeException("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack())));
|
||||
future.completeExceptionally(new ChargeException(tl("missingItems", getItemStack().getAmount(), ess.getItemDb().name(getItemStack()))));
|
||||
return;
|
||||
}
|
||||
|
||||
final BigDecimal money;
|
||||
if (command != null && !command.isEmpty() && (money = getCommandCost(user)).signum() > 0 && !user.canAfford(money)) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(money, ess))));
|
||||
future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(money, ess))));
|
||||
return;
|
||||
}
|
||||
|
||||
if (exp != null && exp > 0 && SetExpFix.getTotalExperience(user.getBase()) < exp) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughExperience"));
|
||||
future.completeExceptionally(new ChargeException(tl("notEnoughExperience")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,8 +243,8 @@ public class Trade {
|
||||
} else {
|
||||
for (final ItemStack itemStack : leftover.values()) {
|
||||
int spillAmount = itemStack.getAmount();
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
while (spillAmount > 0) {
|
||||
itemStack.setAmount(Math.min(spillAmount, itemStack.getMaxStackSize()));
|
||||
user.getBase().getWorld().dropItemNaturally(user.getBase().getLocation(), itemStack);
|
||||
spillAmount -= itemStack.getAmount();
|
||||
}
|
||||
@@ -286,7 +287,7 @@ public class Trade {
|
||||
ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " money " + getMoney().toPlainString());
|
||||
}
|
||||
if (!user.canAfford(getMoney()) && getMoney().signum() > 0) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess))));
|
||||
future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(getMoney(), ess))));
|
||||
return;
|
||||
}
|
||||
user.takeMoney(getMoney());
|
||||
@@ -296,7 +297,7 @@ public class Trade {
|
||||
ess.getLogger().log(Level.INFO, "charging user " + user.getName() + " itemstack " + getItemStack().toString());
|
||||
}
|
||||
if (!Inventories.containsAtLeast(user.getBase(), getItemStack(), getItemStack().getAmount())) {
|
||||
future.completeExceptionally(new ChargeException("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " ")));
|
||||
future.completeExceptionally(new ChargeException(tl("missingItems", getItemStack().getAmount(), getItemStack().getType().toString().toLowerCase(Locale.ENGLISH).replace("_", " "))));
|
||||
return;
|
||||
}
|
||||
Inventories.removeItemAmount(user.getBase(), getItemStack(), getItemStack().getAmount());
|
||||
@@ -305,7 +306,7 @@ public class Trade {
|
||||
if (command != null) {
|
||||
final BigDecimal cost = getCommandCost(user);
|
||||
if (!user.canAfford(cost) && cost.signum() > 0) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(cost, ess))));
|
||||
future.completeExceptionally(new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(cost, ess))));
|
||||
return;
|
||||
}
|
||||
user.takeMoney(cost);
|
||||
@@ -316,7 +317,7 @@ public class Trade {
|
||||
}
|
||||
final int experience = SetExpFix.getTotalExperience(user.getBase());
|
||||
if (experience < getExperience() && getExperience() > 0) {
|
||||
future.completeExceptionally(new ChargeException("notEnoughExperience"));
|
||||
future.completeExceptionally(new ChargeException(tl("notEnoughExperience")));
|
||||
return;
|
||||
}
|
||||
SetExpFix.setTotalExperience(user.getBase(), experience - getExperience());
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.earth2me.essentials.economy.EconomyLayer;
|
||||
import com.earth2me.essentials.economy.EconomyLayers;
|
||||
import com.earth2me.essentials.messaging.IMessageRecipient;
|
||||
import com.earth2me.essentials.messaging.SimpleMessageRecipient;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
@@ -16,16 +15,12 @@ import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import net.ess3.api.events.JailStatusChangeEvent;
|
||||
import net.ess3.api.events.MuteStatusChangeEvent;
|
||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||
import net.ess3.provider.PlayerLocaleProvider;
|
||||
import net.essentialsx.api.v2.events.TransactionEvent;
|
||||
import net.essentialsx.api.v2.services.mail.MailSender;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
@@ -54,8 +49,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tlLocale;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class User extends UserData implements Comparable<User>, IMessageRecipient, net.ess3.api.IUser {
|
||||
private static final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||
@@ -63,11 +57,10 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
// User modules
|
||||
private final IMessageRecipient messageRecipient;
|
||||
private transient final AsyncTeleport teleport;
|
||||
private transient final Teleport legacyTeleport;
|
||||
|
||||
// User command confirmation strings
|
||||
private final Map<User, BigDecimal> confirmingPayments = new WeakHashMap<>();
|
||||
private String confirmingClearCommand;
|
||||
private String lastHomeConfirmation;
|
||||
|
||||
// User teleport variables
|
||||
private final transient LinkedHashMap<String, TpaRequest> teleportRequestQueue = new LinkedHashMap<>();
|
||||
@@ -81,32 +74,30 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
private boolean recipeSee = false;
|
||||
private boolean enderSee = false;
|
||||
private boolean ignoreMsg = false;
|
||||
private Boolean toggleShout;
|
||||
private boolean freeze = false;
|
||||
|
||||
// User afk variables
|
||||
private String afkMessage;
|
||||
private long afkSince;
|
||||
private transient Location afkPosition = null;
|
||||
|
||||
// Timestamps
|
||||
// Misc
|
||||
private transient long lastOnlineActivity;
|
||||
private transient long lastThrottledAction;
|
||||
private transient long lastActivity = System.currentTimeMillis();
|
||||
private transient long teleportInvulnerabilityTimestamp = 0;
|
||||
private String confirmingClearCommand;
|
||||
private long lastNotifiedAboutMailsMs;
|
||||
private String lastHomeConfirmation;
|
||||
private long lastHomeConfirmationTimestamp;
|
||||
|
||||
// Misc
|
||||
private Boolean toggleShout;
|
||||
private boolean freeze = false;
|
||||
private transient final List<String> signCopy = Lists.newArrayList("", "", "", "");
|
||||
private transient long lastVanishTime = System.currentTimeMillis();
|
||||
private transient int flightTick = -1;
|
||||
private String lastLocaleString;
|
||||
private Locale playerLocale;
|
||||
|
||||
public User(final Player base, final IEssentials ess) {
|
||||
super(base, ess);
|
||||
teleport = new AsyncTeleport(this, ess);
|
||||
legacyTeleport = new Teleport(this, ess);
|
||||
if (isAfk()) {
|
||||
afkPosition = this.getLocation();
|
||||
}
|
||||
@@ -161,7 +152,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
|
||||
private boolean isAuthorizedCheck(final String node) {
|
||||
if (base instanceof OfflinePlayerStub) {
|
||||
if (base instanceof OfflinePlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -179,7 +170,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
|
||||
private boolean isPermSetCheck(final String node) {
|
||||
if (base instanceof OfflinePlayerStub) {
|
||||
if (base instanceof OfflinePlayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -197,7 +188,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
|
||||
private TriState isAuthorizedExactCheck(final String node) {
|
||||
if (base instanceof OfflinePlayerStub) {
|
||||
if (base instanceof OfflinePlayer) {
|
||||
return TriState.UNSET;
|
||||
}
|
||||
|
||||
@@ -224,7 +215,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
cooldownTime.add(Calendar.SECOND, (int) cooldown);
|
||||
cooldownTime.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0));
|
||||
if (cooldownTime.after(now) && !isAuthorized("essentials.heal.cooldown.bypass")) {
|
||||
throw new TranslatableException("timeBeforeHeal", DateUtil.formatDateDiff(cooldownTime.getTimeInMillis()));
|
||||
throw new Exception(tl("timeBeforeHeal", DateUtil.formatDateDiff(cooldownTime.getTimeInMillis())));
|
||||
}
|
||||
}
|
||||
setLastHealTimestamp(now.getTimeInMillis());
|
||||
@@ -245,9 +236,9 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return;
|
||||
}
|
||||
setMoney(getMoney().add(value), cause);
|
||||
sendTl("addedToAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)));
|
||||
sendMessage(tl("addedToAccount", NumberUtil.displayCurrency(value, ess)));
|
||||
if (initiator != null) {
|
||||
initiator.sendTl("addedToOthersAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
initiator.sendMessage(tl("addedToOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,18 +249,18 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
|
||||
public void payUser(final User reciever, final BigDecimal value, final UserBalanceUpdateEvent.Cause cause) throws Exception {
|
||||
if (value.compareTo(BigDecimal.ZERO) < 1) {
|
||||
throw new Exception(tlLocale(playerLocale, "payMustBePositive"));
|
||||
throw new Exception(tl("payMustBePositive"));
|
||||
}
|
||||
|
||||
if (canAfford(value)) {
|
||||
setMoney(getMoney().subtract(value), cause);
|
||||
reciever.setMoney(reciever.getMoney().add(value), cause);
|
||||
sendTl("moneySentTo", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), reciever.getDisplayName());
|
||||
reciever.sendTl("moneyRecievedFrom", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName());
|
||||
sendMessage(tl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName()));
|
||||
reciever.sendMessage(tl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()));
|
||||
final TransactionEvent transactionEvent = new TransactionEvent(this.getSource(), reciever, value);
|
||||
ess.getServer().getPluginManager().callEvent(transactionEvent);
|
||||
} else {
|
||||
throw new ChargeException("notEnoughMoney", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)));
|
||||
throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(value, ess)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,9 +283,9 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
} catch (final MaxMoneyException ex) {
|
||||
ess.getLogger().log(Level.WARNING, "Invalid call to takeMoney, total balance can't be more than the max-money limit.", ex);
|
||||
}
|
||||
sendTl("takenFromAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)));
|
||||
sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess)));
|
||||
if (initiator != null) {
|
||||
initiator.sendTl("takenFromOthersAccount", AdventureUtil.parsed(NumberUtil.displayCurrency(value, ess)), getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
initiator.sendMessage(tl("takenFromOthersAccount", NumberUtil.displayCurrency(value, ess), this.getDisplayName(), NumberUtil.displayCurrency(getMoney(), ess)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +311,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
|
||||
private void _dispose() {
|
||||
if (!base.isOnline()) {
|
||||
this.base = new OfflinePlayerStub(getConfigUUID(), ess.getServer());
|
||||
this.base = new OfflinePlayer(getConfigUUID(), ess.getServer());
|
||||
}
|
||||
cleanup();
|
||||
}
|
||||
@@ -334,9 +325,8 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return true;
|
||||
|
||||
if (VersionUtil.PRE_FLATTENING) {
|
||||
//noinspection deprecation
|
||||
final int id = material.getId();
|
||||
return isAuthorized("essentials.itemspawn.item-" + id);
|
||||
if (isAuthorized("essentials.itemspawn.item-" + id)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -373,6 +363,12 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
teleportRequestQueue.put(request.getName(), request);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean hasOutstandingTeleportRequest() {
|
||||
return getNextTpaRequest(false, false, false) != null;
|
||||
}
|
||||
|
||||
public Collection<String> getPendingTpaKeys() {
|
||||
return teleportRequestQueue.keySet();
|
||||
}
|
||||
@@ -399,7 +395,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
teleportRequestQueue.remove(playerUsername);
|
||||
if (inform) {
|
||||
sendTl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName());
|
||||
sendMessage(tl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -433,7 +429,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
} else {
|
||||
if (inform) {
|
||||
sendTl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName());
|
||||
sendMessage(tl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName()));
|
||||
}
|
||||
teleportRequestQueue.remove(key);
|
||||
}
|
||||
@@ -448,15 +444,14 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
/**
|
||||
* Needed for backwards compatibility.
|
||||
*/
|
||||
public String getNick(@SuppressWarnings("unused") final boolean longNick) {
|
||||
public String getNick(final boolean longnick) {
|
||||
return getNick(true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed for backwards compatibility.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public String getNick(@SuppressWarnings("unused") final boolean longNick, final boolean withPrefix, final boolean withSuffix) {
|
||||
public String getNick(final boolean longnick, final boolean withPrefix, final boolean withSuffix) {
|
||||
return getNick(withPrefix, withSuffix);
|
||||
}
|
||||
|
||||
@@ -538,7 +533,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
//noinspection ConstantConditions
|
||||
return super.getBase().getDisplayName() == null || (ess.getSettings().hideDisplayNameInVanish() && isHidden()) ? super.getBase().getName() : super.getBase().getDisplayName();
|
||||
}
|
||||
|
||||
@@ -556,6 +550,15 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return teleport;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This API is not asynchronous. Use {@link User#getAsyncTeleport()}
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public Teleport getTeleport() {
|
||||
return legacyTeleport;
|
||||
}
|
||||
|
||||
public long getLastOnlineActivity() {
|
||||
return lastOnlineActivity;
|
||||
}
|
||||
@@ -626,7 +629,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setAfk(final boolean set) {
|
||||
setAfk(set, AfkStatusChangeEvent.Cause.UNKNOWN);
|
||||
@@ -677,9 +679,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
|
||||
@Override
|
||||
public boolean isHiddenFrom(Player player) {
|
||||
if (getBase() instanceof OfflinePlayerStub || player instanceof OfflinePlayerStub) {
|
||||
return true;
|
||||
}
|
||||
return !player.canSee(getBase());
|
||||
}
|
||||
|
||||
@@ -707,7 +706,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
|
||||
public boolean isHidden(final Player player) {
|
||||
return hidden || isHiddenFrom(player);
|
||||
return hidden || !player.canSee(getBase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -720,7 +719,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
|
||||
//Returns true if status expired during this check
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean checkJailTimeout(final long currentTime) {
|
||||
if (getJailTimeout() > 0) {
|
||||
|
||||
@@ -738,7 +736,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
setJailTimeout(0);
|
||||
setOnlineJailedTime(0);
|
||||
setJailed(false);
|
||||
sendTl("haveBeenReleased");
|
||||
sendMessage(tl("haveBeenReleased"));
|
||||
setJail(null);
|
||||
if (ess.getSettings().getTeleportWhenFreePolicy() == ISettings.TeleportWhenFreePolicy.BACK) {
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
@@ -758,7 +756,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
|
||||
//Returns true if status expired during this check
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public boolean checkMuteTimeout(final long currentTime) {
|
||||
if (getMuteTimeout() > 0 && getMuteTimeout() < currentTime && isMuted()) {
|
||||
final MuteStatusChangeEvent event = new MuteStatusChangeEvent(this, null, false, getMuteTimeout(), getMuteReason());
|
||||
@@ -766,7 +763,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
setMuteTimeout(0);
|
||||
sendTl("canTalkAgain");
|
||||
sendMessage(tl("canTalkAgain"));
|
||||
setMuted(false);
|
||||
setMuteReason(null);
|
||||
return true;
|
||||
@@ -785,10 +782,15 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
setAfk(false, cause);
|
||||
if (broadcast && !isHidden() && !isAfk()) {
|
||||
setDisplayNick();
|
||||
if (ess.getSettings().broadcastAfkMessage()) {
|
||||
ess.broadcastTl(this, u -> u == this, "userIsNotAway", getDisplayName());
|
||||
final String msg = tl("userIsNotAway", getDisplayName());
|
||||
final String selfmsg = tl("userIsNotAwaySelf", getDisplayName());
|
||||
if (!msg.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||
// exclude user from receiving general AFK announcement in favor of personal message
|
||||
ess.broadcastMessage(this, msg, u -> u == this);
|
||||
}
|
||||
if (!selfmsg.isEmpty()) {
|
||||
this.sendMessage(selfmsg);
|
||||
}
|
||||
sendTl("userIsNotAwaySelf", getDisplayName());
|
||||
}
|
||||
}
|
||||
lastActivity = System.currentTimeMillis();
|
||||
@@ -809,12 +811,14 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
public void updateActivityOnChat(final boolean broadcast) {
|
||||
if (ess.getSettings().cancelAfkOnChat()) {
|
||||
//Chat happens async, make sure we have a sync context
|
||||
ess.scheduleSyncDelayedTask(() -> updateActivity(broadcast, AfkStatusChangeEvent.Cause.CHAT));
|
||||
ess.scheduleSyncDelayedTask(() -> {
|
||||
updateActivity(broadcast, AfkStatusChangeEvent.Cause.CHAT);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void checkActivity() {
|
||||
// Graceful time before the first afk check call.
|
||||
// Graceful time before the first afk check call.
|
||||
if (System.currentTimeMillis() - lastActivity <= 10000) {
|
||||
return;
|
||||
}
|
||||
@@ -824,14 +828,13 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
&& lastActivity > 0 && (lastActivity + (autoafkkick * 1000)) < System.currentTimeMillis()
|
||||
&& !isAuthorized("essentials.kick.exempt")
|
||||
&& !isAuthorized("essentials.afk.kickexempt")) {
|
||||
final String kickReason = tl("autoAfkKickReason", autoafkkick / 60.0);
|
||||
lastActivity = 0;
|
||||
final double kickTime = autoafkkick / 60.0;
|
||||
|
||||
this.getBase().kickPlayer(AdventureUtil.miniToLegacy(playerTl("autoAfkKickReason", kickTime)));
|
||||
this.getBase().kickPlayer(kickReason);
|
||||
|
||||
for (final User user : ess.getOnlineUsers()) {
|
||||
if (user.isAuthorized("essentials.kick.notify")) {
|
||||
user.sendTl("playerKicked", Console.DISPLAY_NAME, getName(), user.playerTl("autoAfkKickReason", kickTime));
|
||||
user.sendMessage(tl("playerKicked", Console.DISPLAY_NAME, getName(), kickReason));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -840,10 +843,15 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
setAfk(true, AfkStatusChangeEvent.Cause.ACTIVITY);
|
||||
if (isAfk() && !isHidden()) {
|
||||
setDisplayNick();
|
||||
if (ess.getSettings().broadcastAfkMessage()) {
|
||||
ess.broadcastTl(this, u -> u == this, "userIsAway", getDisplayName());
|
||||
final String msg = tl("userIsAway", getDisplayName());
|
||||
final String selfmsg = tl("userIsAwaySelf", getDisplayName());
|
||||
if (!msg.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||
// exclude user from receiving general AFK announcement in favor of personal message
|
||||
ess.broadcastMessage(this, msg, u -> u == this);
|
||||
}
|
||||
if (!selfmsg.isEmpty()) {
|
||||
this.sendMessage(selfmsg);
|
||||
}
|
||||
sendTl("userIsAwaySelf", getDisplayName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -858,7 +866,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
// This enables the no-god-in-worlds functionality where the actual player god mode state is never modified in disabled worlds,
|
||||
// but this method gets called every time the player takes damage. In the case that the world has god-mode disabled then this method
|
||||
// will return false and the player will take damage, even though they are in god mode (isGodModeEnabledRaw()).
|
||||
//noinspection ConstantConditions
|
||||
if (!ess.getSettings().getNoGodWorlds().contains(this.getLocation().getWorld().getName())) {
|
||||
return true;
|
||||
}
|
||||
@@ -900,7 +907,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
return ess.getPermissionsHandler().canBuild(base, getGroup());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public long getTeleportRequestTime() {
|
||||
@@ -969,7 +975,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
if (set) {
|
||||
for (final User user : ess.getOnlineUsers()) {
|
||||
if (!user.isAuthorized("essentials.vanish.see")) {
|
||||
//noinspection deprecation
|
||||
user.getBase().hidePlayer(getBase());
|
||||
}
|
||||
}
|
||||
@@ -985,7 +990,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
} else {
|
||||
for (final Player p : ess.getOnlinePlayers()) {
|
||||
//noinspection deprecation
|
||||
p.showPlayer(getBase());
|
||||
}
|
||||
setHidden(false);
|
||||
@@ -1045,49 +1049,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponent(ComponentLike component) {
|
||||
ess.getBukkitAudience().player(base).sendMessage(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component tlComponent(String tlKey, Object... args) {
|
||||
final String translation = playerTl(tlKey, args);
|
||||
return AdventureUtil.miniMessage().deserialize(translation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTl(String tlKey, Object... args) {
|
||||
final String translation = playerTl(tlKey, args);
|
||||
if (translation.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendComponent(AdventureUtil.miniMessage().deserialize(translation));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String playerTl(String tlKey, Object... args) {
|
||||
if (ess.getSettings().isPerPlayerLocale()) {
|
||||
final PlayerLocaleProvider provider = ess.provider(PlayerLocaleProvider.class);
|
||||
return tlLocale(getPlayerLocale(provider.getLocale(base)), tlKey, args);
|
||||
}
|
||||
return tlLiteral(tlKey, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String tlSender(String tlKey, Object... args) {
|
||||
return playerTl(tlKey, args);
|
||||
}
|
||||
|
||||
public Locale getPlayerLocale(final String locale) {
|
||||
if (locale.equals(lastLocaleString)) {
|
||||
return playerLocale;
|
||||
}
|
||||
lastLocaleString = locale;
|
||||
return playerLocale = I18n.getLocale(locale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(final User other) {
|
||||
return FormatUtil.stripFormat(getDisplayName()).compareToIgnoreCase(FormatUtil.stripFormat(other.getDisplayName()));
|
||||
@@ -1109,7 +1070,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
|
||||
@Override
|
||||
public CommandSource getSource() {
|
||||
return new CommandSource(ess, getBase());
|
||||
return new CommandSource(getBase());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1194,7 +1155,6 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
ess.getMail().sendMail(this, sender, message, expireAt);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addMail(String mail) {
|
||||
@@ -1206,7 +1166,7 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
if (unread != 0) {
|
||||
final int notifyPlayerOfMailCooldown = ess.getSettings().getNotifyPlayerOfMailCooldown() * 1000;
|
||||
if (System.currentTimeMillis() - lastNotifiedAboutMailsMs >= notifyPlayerOfMailCooldown) {
|
||||
sendTl("youHaveNewMail", unread);
|
||||
sendMessage(tl("youHaveNewMail", unread));
|
||||
lastNotifiedAboutMailsMs = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -1279,12 +1239,4 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
|
||||
}
|
||||
return toggleShout == null ? toggleShout = ess.getSettings().isShoutDefault() : toggleShout;
|
||||
}
|
||||
|
||||
public int getFlightTick() {
|
||||
return flightTick;
|
||||
}
|
||||
|
||||
public void setFlightTick(int flightTick) {
|
||||
this.flightTick = flightTick;
|
||||
}
|
||||
}
|
||||
@@ -11,13 +11,13 @@ import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.essentialsx.api.v2.services.mail.MailMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
@@ -32,15 +32,17 @@ import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public abstract class UserData extends PlayerExtension implements IConf {
|
||||
protected final transient Essentials ess;
|
||||
protected final transient IEssentials ess;
|
||||
private final EssentialsUserConfiguration config;
|
||||
private UserConfigHolder holder;
|
||||
private BigDecimal money;
|
||||
|
||||
protected UserData(final Player base, final IEssentials ess) {
|
||||
super(base);
|
||||
this.ess = (Essentials) ess;
|
||||
this.ess = ess;
|
||||
final File folder = new File(ess.getDataFolder(), "userdata");
|
||||
if (!folder.exists() && !folder.mkdirs()) {
|
||||
throw new RuntimeException("Unable to create userdata folder!");
|
||||
@@ -81,7 +83,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
config.load();
|
||||
try {
|
||||
holder = config.getRootNode().get(UserConfigHolder.class);
|
||||
} catch (Throwable e) {
|
||||
} catch (SerializationException e) {
|
||||
ess.getLogger().log(Level.SEVERE, "Error while reading user config: " + config.getFile().getName(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -193,7 +195,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
holder.homes().remove(search);
|
||||
config.save();
|
||||
} else {
|
||||
throw new TranslatableException("invalidHome", search);
|
||||
throw new Exception(tl("invalidHome", search));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +205,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
holder.homes().put(StringUtil.safeString(newName), location);
|
||||
config.save();
|
||||
} else {
|
||||
throw new TranslatableException("invalidHome", name);
|
||||
throw new Exception(tl("invalidHome", name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,17 +350,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
}
|
||||
|
||||
public int getMailAmount() {
|
||||
if (holder.mail() == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int amount = 0;
|
||||
for (MailMessage element : holder.mail()) {
|
||||
if (!element.isExpired()) {
|
||||
amount++;
|
||||
}
|
||||
}
|
||||
return amount;
|
||||
return holder.mail() == null ? 0 : holder.mail().size();
|
||||
}
|
||||
|
||||
public int getUnreadMailAmount() {
|
||||
@@ -368,7 +360,7 @@ public abstract class UserData extends PlayerExtension implements IConf {
|
||||
|
||||
int unread = 0;
|
||||
for (MailMessage element : holder.mail()) {
|
||||
if (!element.isRead() && !element.isExpired()) {
|
||||
if (!element.isRead()) {
|
||||
unread++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UserMap {
|
||||
if (player instanceof Player) {
|
||||
userPlayer = (Player) player;
|
||||
} else {
|
||||
final OfflinePlayerStub essPlayer = new OfflinePlayerStub(player.getUniqueId(), Bukkit.getServer());
|
||||
final com.earth2me.essentials.OfflinePlayer essPlayer = new com.earth2me.essentials.OfflinePlayer(player.getUniqueId(), Bukkit.getServer());
|
||||
essPlayer.setName(player.getName());
|
||||
userPlayer = essPlayer;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.commands.WarpNotFoundException;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import net.ess3.api.InvalidNameException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.InvalidWorldException;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.io.File;
|
||||
@@ -18,7 +17,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
private final Map<StringIgnoreCase, EssentialsConfiguration> warpPoints = new HashMap<>();
|
||||
@@ -53,7 +52,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getWarp(final String warp) throws WarpNotFoundException {
|
||||
public Location getWarp(final String warp) throws WarpNotFoundException, InvalidWorldException {
|
||||
final EssentialsConfiguration conf = warpPoints.get(new StringIgnoreCase(warp));
|
||||
if (conf == null) {
|
||||
throw new WarpNotFoundException();
|
||||
@@ -78,7 +77,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
if (conf == null) {
|
||||
final File confFile = new File(warpsFolder, filename + ".yml");
|
||||
if (confFile.exists()) {
|
||||
throw new TranslatableException("similarWarpExist");
|
||||
throw new Exception(tl("similarWarpExist"));
|
||||
}
|
||||
conf = new EssentialsConfiguration(confFile);
|
||||
conf.load();
|
||||
@@ -110,10 +109,10 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
public void removeWarp(final String name) throws Exception {
|
||||
final EssentialsConfiguration conf = warpPoints.get(new StringIgnoreCase(name));
|
||||
if (conf == null) {
|
||||
throw new TranslatableException("warpNotExist");
|
||||
throw new Exception(tl("warpNotExist"));
|
||||
}
|
||||
if (!conf.getFile().delete()) {
|
||||
throw new TranslatableException("warpDeleteError");
|
||||
throw new Exception(tl("warpDeleteError"));
|
||||
}
|
||||
warpPoints.remove(new StringIgnoreCase(name));
|
||||
}
|
||||
@@ -122,7 +121,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
public final void reloadConfig() {
|
||||
warpPoints.clear();
|
||||
final File[] listOfFiles = warpsFolder.listFiles();
|
||||
if (listOfFiles != null) {
|
||||
if (listOfFiles.length >= 1) {
|
||||
for (final File listOfFile : listOfFiles) {
|
||||
final String filename = listOfFile.getName();
|
||||
if (listOfFile.isFile() && filename.endsWith(".yml")) {
|
||||
@@ -134,7 +133,7 @@ public class Warps implements IConf, net.ess3.api.IWarps {
|
||||
warpPoints.put(new StringIgnoreCase(name), conf);
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
Essentials.getWrappedLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("loadWarpError", filename)), ex);
|
||||
Essentials.getWrappedLogger().log(Level.WARNING, tl("loadWarpError", filename), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.earth2me.essentials.config.ConfigurateUtil;
|
||||
import com.earth2me.essentials.config.EssentialsConfiguration;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
@@ -14,6 +13,8 @@ import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Worth implements IConf {
|
||||
private final EssentialsConfiguration config;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class Worth implements IConf {
|
||||
*/
|
||||
public int getAmount(final IEssentials ess, final User user, final ItemStack is, final String[] args, final boolean isBulkSell) throws Exception {
|
||||
if (is == null || is.getType() == Material.AIR) {
|
||||
throw new TranslatableException("itemSellAir");
|
||||
throw new Exception(tl("itemSellAir"));
|
||||
}
|
||||
|
||||
int amount = 0;
|
||||
@@ -97,7 +98,7 @@ public class Worth implements IConf {
|
||||
final boolean requireStack = ess.getSettings().isTradeInStacks(is.getType());
|
||||
|
||||
if (requireStack && !stack) {
|
||||
throw new TranslatableException("itemMustBeStacked");
|
||||
throw new Exception(tl("itemMustBeStacked"));
|
||||
}
|
||||
|
||||
int max = 0;
|
||||
@@ -120,9 +121,9 @@ public class Worth implements IConf {
|
||||
}
|
||||
if (amount > max || amount < 1) {
|
||||
if (!isBulkSell) {
|
||||
user.sendTl("itemNotEnough2");
|
||||
user.sendTl("itemNotEnough3");
|
||||
throw new TranslatableException("itemNotEnough1");
|
||||
user.sendMessage(tl("itemNotEnough2"));
|
||||
user.sendMessage(tl("itemNotEnough3"));
|
||||
throw new Exception(tl("itemNotEnough1"));
|
||||
} else {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,17 @@ public interface IJails extends IConf {
|
||||
*/
|
||||
void removeJail(String jail) throws Exception;
|
||||
|
||||
/**
|
||||
* Attempts to send the given user to the given jail
|
||||
*
|
||||
* @param user the user to send to jail
|
||||
* @param jail the jail to send the user to
|
||||
* @throws Exception if the user is offline or jail does not exist
|
||||
* @deprecated Use {@link IJails#sendToJail(IUser, String, CompletableFuture)}
|
||||
*/
|
||||
@Deprecated
|
||||
void sendToJail(IUser user, String jail) throws Exception;
|
||||
|
||||
/**
|
||||
* Attempts to send the given user to the given jail
|
||||
*
|
||||
|
||||
@@ -22,8 +22,9 @@ public interface IWarps extends IConf {
|
||||
* @param warp - Warp name
|
||||
* @return - Location the warp is set to
|
||||
* @throws WarpNotFoundException When the warp is not found
|
||||
* @throws net.ess3.api.InvalidWorldException When the world the warp is in is not found
|
||||
*/
|
||||
Location getWarp(String warp) throws WarpNotFoundException;
|
||||
Location getWarp(String warp) throws WarpNotFoundException, net.ess3.api.InvalidWorldException;
|
||||
|
||||
/**
|
||||
* Checks if the provided name is a warp.
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.earth2me.essentials.api;
|
||||
|
||||
import net.ess3.api.TranslatableException;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
/**
|
||||
* @deprecated This exception is unused. Use {@link net.ess3.api.InvalidWorldException} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public class InvalidWorldException extends TranslatableException {
|
||||
public class InvalidWorldException extends Exception {
|
||||
private final String world;
|
||||
|
||||
public InvalidWorldException(final String world) {
|
||||
super("invalidWorld");
|
||||
super(tl("invalidWorld"));
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package com.earth2me.essentials.api;
|
||||
|
||||
import net.ess3.api.TranslatableException;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
/**
|
||||
* Thrown when the requested user does not exist.
|
||||
*/
|
||||
public class UserDoesNotExistException extends TranslatableException {
|
||||
public class UserDoesNotExistException extends Exception {
|
||||
public UserDoesNotExistException(final String name) {
|
||||
super("userDoesNotExist", name);
|
||||
super(tl("userDoesNotExist", name));
|
||||
}
|
||||
|
||||
public UserDoesNotExistException(final UUID uuid) {
|
||||
super("uuidDoesNotExist", uuid.toString());
|
||||
super(tl("uuidDoesNotExist", uuid.toString()));
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,14 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandafk extends EssentialsCommand {
|
||||
public Commandafk() {
|
||||
super("afk");
|
||||
@@ -49,23 +50,17 @@ public class Commandafk extends EssentialsCommand {
|
||||
if (sender.isMuted()) {
|
||||
final String dateDiff = sender.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(sender.getMuteTimeout()) : null;
|
||||
if (dateDiff == null) {
|
||||
if (sender.hasMuteReason()) {
|
||||
throw new TranslatableException("voiceSilencedReason", sender.getMuteReason());
|
||||
} else {
|
||||
throw new TranslatableException("voiceSilenced");
|
||||
}
|
||||
}
|
||||
if (sender.hasMuteReason()) {
|
||||
throw new TranslatableException("voiceSilencedReasonTime", dateDiff, sender.getMuteReason());
|
||||
} else {
|
||||
throw new TranslatableException("voiceSilencedTime", dateDiff);
|
||||
throw new Exception(sender.hasMuteReason() ? tl("voiceSilencedReason", sender.getMuteReason()) : tl("voiceSilenced"));
|
||||
}
|
||||
throw new Exception(sender.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, sender.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
||||
}
|
||||
if (!sender.isAuthorized("essentials.afk.message")) {
|
||||
throw new TranslatableException("noPermToAFKMessage");
|
||||
throw new Exception(tl("noPermToAFKMessage"));
|
||||
}
|
||||
}
|
||||
user.setDisplayNick();
|
||||
String msg = "";
|
||||
String selfmsg = "";
|
||||
|
||||
final boolean currentStatus = user.isAfk();
|
||||
final boolean afterStatus = user.toggleAfk(AfkStatusChangeEvent.Cause.COMMAND);
|
||||
@@ -73,39 +68,37 @@ public class Commandafk extends EssentialsCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
String tlKey = "";
|
||||
String selfTlKey = "";
|
||||
if (!afterStatus) {
|
||||
if (!user.isHidden()) {
|
||||
tlKey = "userIsNotAway";
|
||||
selfTlKey = "userIsNotAwaySelf";
|
||||
msg = tl("userIsNotAway", user.getDisplayName());
|
||||
selfmsg = tl("userIsNotAwaySelf", user.getDisplayName());
|
||||
}
|
||||
user.updateActivity(false, AfkStatusChangeEvent.Cause.COMMAND);
|
||||
} else {
|
||||
if (!user.isHidden()) {
|
||||
if (message != null) {
|
||||
tlKey = "userIsAwayWithMessage";
|
||||
selfTlKey = "userIsAwaySelfWithMessage";
|
||||
msg = tl("userIsAwayWithMessage", user.getDisplayName(), message);
|
||||
selfmsg = tl("userIsAwaySelfWithMessage", user.getDisplayName(), message);
|
||||
} else {
|
||||
tlKey = "userIsAway";
|
||||
selfTlKey = "userIsAwaySelf";
|
||||
msg = tl("userIsAway", user.getDisplayName());
|
||||
selfmsg = tl("userIsAwaySelf", user.getDisplayName());
|
||||
}
|
||||
}
|
||||
user.setAfkMessage(message);
|
||||
}
|
||||
if (!tlKey.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||
if (!msg.isEmpty() && ess.getSettings().broadcastAfkMessage()) {
|
||||
// exclude user from receiving general AFK announcement in favor of personal message
|
||||
ess.broadcastTl(user, u -> u == user, tlKey, user.getDisplayName(), message);
|
||||
ess.broadcastMessage(user, msg, u -> u == user);
|
||||
}
|
||||
if (!selfTlKey.isEmpty()) {
|
||||
user.sendTl(selfTlKey, user.getDisplayName(), message);
|
||||
if (!selfmsg.isEmpty()) {
|
||||
user.sendMessage(selfmsg);
|
||||
}
|
||||
user.setDisplayNick(); // Set this again after toggling
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.afk.others")) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.afk.others", ess)) {
|
||||
return getPlayers(server, sender);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandanvil extends EssentialsCommand {
|
||||
|
||||
public Commandanvil() {
|
||||
@@ -12,13 +13,11 @@ public class Commandanvil extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openAnvil(user.getBase());
|
||||
ess.getContainerProvider().openAnvil(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,13 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandback extends EssentialsCommand {
|
||||
public Commandback() {
|
||||
super("back");
|
||||
@@ -36,13 +37,13 @@ public class Commandback extends EssentialsCommand {
|
||||
|
||||
private void parseOthers(final Server server, final CommandSource sender, final String[] args, final String commandLabel) throws Exception {
|
||||
final User player = getPlayer(server, args, 0, true, false);
|
||||
sender.sendTl("backOther", player.getName());
|
||||
sender.sendMessage(tl("backOther", player.getName()));
|
||||
teleportBack(sender, player, commandLabel);
|
||||
}
|
||||
|
||||
private void teleportBack(final CommandSource sender, final User user, final String commandLabel) throws Exception {
|
||||
if (user.getLastLocation() == null) {
|
||||
throw new TranslatableException("noLocationFound");
|
||||
throw new Exception(tl("noLocationFound"));
|
||||
}
|
||||
|
||||
final String lastWorldName = user.getLastLocation().getWorld().getName();
|
||||
@@ -52,11 +53,11 @@ public class Commandback extends EssentialsCommand {
|
||||
requester = ess.getUser(sender.getPlayer());
|
||||
|
||||
if (user.getWorld() != user.getLastLocation().getWorld() && this.ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + lastWorldName)) {
|
||||
throw new TranslatableException("noPerm", "essentials.worlds." + lastWorldName);
|
||||
throw new Exception(tl("noPerm", "essentials.worlds." + lastWorldName));
|
||||
}
|
||||
|
||||
if (!requester.isAuthorized("essentials.back.into." + lastWorldName)) {
|
||||
throw new TranslatableException("noPerm", "essentials.back.into." + lastWorldName);
|
||||
throw new Exception(tl("noPerm", "essentials.back.into." + lastWorldName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.Backup;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbackup extends EssentialsCommand {
|
||||
public Commandbackup() {
|
||||
super("backup");
|
||||
@@ -14,13 +15,13 @@ public class Commandbackup extends EssentialsCommand {
|
||||
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
final Backup backup = ess.getBackup();
|
||||
if (backup == null) {
|
||||
throw new TranslatableException("backupDisabled");
|
||||
throw new Exception(tl("backupDisabled"));
|
||||
}
|
||||
final String command = ess.getSettings().getBackupCommand();
|
||||
if (command == null || "".equals(command) || "save-all".equalsIgnoreCase(command)) {
|
||||
throw new TranslatableException("backupDisabled");
|
||||
throw new Exception(tl("backupDisabled"));
|
||||
}
|
||||
backup.run();
|
||||
sender.sendTl("backupStarted");
|
||||
sender.sendMessage(tl("backupStarted"));
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,14 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbalance extends EssentialsCommand {
|
||||
public Commandbalance() {
|
||||
super("balance");
|
||||
@@ -21,16 +22,16 @@ public class Commandbalance extends EssentialsCommand {
|
||||
}
|
||||
|
||||
final User target = getPlayer(server, args, 0, false, true);
|
||||
sender.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(target.getMoney(), ess)));
|
||||
sender.sendMessage(tl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length == 1 && user.isAuthorized("essentials.balance.others")) {
|
||||
final User target = getPlayer(server, args, 0, true, true);
|
||||
user.sendTl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(target.getMoney(), ess)));
|
||||
user.sendMessage(tl("balanceOther", target.isHidden() ? target.getName() : target.getDisplayName(), NumberUtil.displayCurrency(target.getMoney(), ess)));
|
||||
} else if (args.length < 2) {
|
||||
user.sendTl("balance", AdventureUtil.parsed(NumberUtil.displayCurrency(user.getMoney(), ess)));
|
||||
user.sendMessage(tl("balance", NumberUtil.displayCurrency(user.getMoney(), ess)));
|
||||
} else {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
@@ -38,7 +39,7 @@ public class Commandbalance extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.balance.others")) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.balance.others", ess)) {
|
||||
return getPlayers(server, sender);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.essentialsx.api.v2.services.BalanceTop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -23,7 +18,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbalancetop extends EssentialsCommand {
|
||||
public static final int MINUSERS = 50;
|
||||
@@ -39,7 +34,7 @@ public class Commandbalancetop extends EssentialsCommand {
|
||||
cal.setTimeInMillis(ess.getBalanceTop().getCacheAge());
|
||||
final DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||
final Runnable runnable = () -> {
|
||||
sender.sendTl("balanceTop", format.format(cal.getTime()));
|
||||
sender.sendMessage(tl("balanceTop", format.format(cal.getTime())));
|
||||
new TextPager(cache).showPage(Integer.toString(page), null, "balancetop", sender);
|
||||
};
|
||||
if (sender.getSender() instanceof BlockCommandSender) {
|
||||
@@ -70,7 +65,7 @@ public class Commandbalancetop extends EssentialsCommand {
|
||||
|
||||
// If there are less than 50 users in our usermap, there is no need to display a warning as these calculations should be done quickly
|
||||
if (ess.getUsers().getUserCount() > MINUSERS) {
|
||||
sender.sendTl("orderBalances", ess.getUsers().getUserCount());
|
||||
sender.sendMessage(tl("orderBalances", ess.getUsers().getUserCount()));
|
||||
}
|
||||
|
||||
ess.runTaskAsynchronously(new Viewer(sender, page, force));
|
||||
@@ -114,32 +109,17 @@ public class Commandbalancetop extends EssentialsCommand {
|
||||
future.thenRun(() -> {
|
||||
if (fresh) {
|
||||
final SimpleTextInput newCache = new SimpleTextInput();
|
||||
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("serverTotal", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess)))));
|
||||
newCache.getLines().add(tl("serverTotal", NumberUtil.displayCurrency(ess.getBalanceTop().getBalanceTopTotal(), ess)));
|
||||
int pos = 1;
|
||||
for (final Map.Entry<UUID, BalanceTop.Entry> entry : ess.getBalanceTop().getBalanceTopCache().entrySet()) {
|
||||
final BigDecimal balance = entry.getValue().getBalance();
|
||||
final User user = ess.getUser(entry.getKey());
|
||||
|
||||
final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK");
|
||||
final long playtime;
|
||||
if (user.getBase() == null || !user.getBase().isOnline()) {
|
||||
playtime = Bukkit.getServer().getOfflinePlayer(entry.getKey()).getStatistic(PLAY_ONE_TICK);
|
||||
} else {
|
||||
playtime = user.getBase().getStatistic(PLAY_ONE_TICK);
|
||||
}
|
||||
// Play time in seconds
|
||||
final long playTimeSecs = Math.max(playtime / 20, 0);
|
||||
|
||||
// Checking if player meets the requirements of minimum balance and minimum playtime to be listed in baltop list
|
||||
if ((ess.getSettings().showZeroBaltop() || balance.compareTo(BigDecimal.ZERO) > 0)
|
||||
&& balance.compareTo(ess.getSettings().getBaltopMinBalance()) >= 0 &&
|
||||
playTimeSecs >= ess.getSettings().getBaltopMinPlaytime()) {
|
||||
newCache.getLines().add(AdventureUtil.miniToLegacy(tlLiteral("balanceTopLine", pos, entry.getValue().getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(balance, ess)))));
|
||||
if (ess.getSettings().showZeroBaltop() || entry.getValue().getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
||||
newCache.getLines().add(tl("balanceTopLine", pos, entry.getValue().getDisplayName(), NumberUtil.displayCurrency(entry.getValue().getBalance(), ess)));
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
cache = newCache;
|
||||
}
|
||||
|
||||
outputCache(sender, page);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,11 +2,9 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.Console;
|
||||
import com.earth2me.essentials.OfflinePlayerStub;
|
||||
import com.earth2me.essentials.OfflinePlayer;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.Server;
|
||||
|
||||
@@ -14,7 +12,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandban extends EssentialsCommand {
|
||||
public Commandban() {
|
||||
@@ -32,14 +30,14 @@ public class Commandban extends EssentialsCommand {
|
||||
user = getPlayer(server, args, 0, true, true);
|
||||
} catch (final PlayerNotFoundException e) {
|
||||
nomatch = true;
|
||||
user = ess.getUser(new OfflinePlayerStub(args[0], ess.getServer()));
|
||||
user = ess.getUser(new OfflinePlayer(args[0], ess.getServer()));
|
||||
}
|
||||
if (!user.getBase().isOnline()) {
|
||||
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.ban.offline")) {
|
||||
throw new TranslatableException("banExemptOffline");
|
||||
throw new Exception(tl("banExemptOffline"));
|
||||
}
|
||||
} else if (user.isAuthorized("essentials.ban.exempt") && sender.isPlayer()) {
|
||||
throw new TranslatableException("banExempt");
|
||||
throw new Exception(tl("banExempt"));
|
||||
}
|
||||
|
||||
final String senderName = sender.isPlayer() ? sender.getPlayer().getDisplayName() : Console.NAME;
|
||||
@@ -48,21 +46,21 @@ public class Commandban extends EssentialsCommand {
|
||||
if (args.length > 1) {
|
||||
banReason = FormatUtil.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n"));
|
||||
} else {
|
||||
banReason = tlLiteral("defaultBanReason");
|
||||
banReason = tl("defaultBanReason");
|
||||
}
|
||||
|
||||
ess.getServer().getBanList(BanList.Type.NAME).addBan(user.getName(), banReason, null, senderName);
|
||||
|
||||
final String banDisplay = tlLiteral("banFormat", banReason, senderDisplayName);
|
||||
final String banDisplay = tl("banFormat", banReason, senderDisplayName);
|
||||
|
||||
user.getBase().kickPlayer(AdventureUtil.miniToLegacy(banDisplay));
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanned", senderDisplayName, user.getName(), banDisplay)));
|
||||
user.getBase().kickPlayer(banDisplay);
|
||||
ess.getLogger().log(Level.INFO, tl("playerBanned", senderDisplayName, user.getName(), banDisplay));
|
||||
|
||||
if (nomatch) {
|
||||
sender.sendTl("userUnknown", user.getName());
|
||||
sender.sendMessage(tl("userUnknown", user.getName()));
|
||||
}
|
||||
|
||||
ess.broadcastTl(null, u -> !u.isAuthorized("essentials.ban.notify"), "playerBanned", senderDisplayName, user.getName(), banReason);
|
||||
ess.broadcastMessage("essentials.ban.notify", tl("playerBanned", senderDisplayName, user.getName(), banReason));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.Console;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.Server;
|
||||
@@ -13,7 +12,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbanip extends EssentialsCommand {
|
||||
public Commandbanip() {
|
||||
@@ -49,13 +48,13 @@ public class Commandbanip extends EssentialsCommand {
|
||||
if (args.length > 1) {
|
||||
banReason = FormatUtil.replaceFormat(getFinalArg(args, 1).replace("\\n", "\n").replace("|", "\n"));
|
||||
} else {
|
||||
banReason = tlLiteral("defaultBanReason");
|
||||
banReason = tl("defaultBanReason");
|
||||
}
|
||||
|
||||
final String banDisplay = AdventureUtil.miniToLegacy(tlLiteral("banFormat", banReason, senderDisplayName));
|
||||
final String banDisplay = tl("banFormat", banReason, senderDisplayName);
|
||||
|
||||
ess.getServer().getBanList(BanList.Type.IP).addBan(ipAddress, banReason, null, senderName);
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("playerBanIpAddress", senderDisplayName, ipAddress, banReason)));
|
||||
ess.getLogger().log(Level.INFO, tl("playerBanIpAddress", senderDisplayName, ipAddress, banReason));
|
||||
|
||||
for (final Player player : ess.getServer().getOnlinePlayers()) {
|
||||
if (player.getAddress().getAddress().getHostAddress().equalsIgnoreCase(ipAddress)) {
|
||||
@@ -63,7 +62,7 @@ public class Commandbanip extends EssentialsCommand {
|
||||
}
|
||||
}
|
||||
|
||||
ess.broadcastTl(null, u -> !u.isAuthorized("essentials.banip.notify"), "playerBanIpAddress", senderDisplayName, ipAddress, banReason);
|
||||
ess.broadcastMessage("essentials.banip.notify", tl("playerBanIpAddress", senderDisplayName, ipAddress, banReason));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbeezooka extends EssentialsCommand {
|
||||
|
||||
public Commandbeezooka() {
|
||||
@@ -16,7 +18,7 @@ public class Commandbeezooka extends EssentialsCommand {
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_15_R01)) {
|
||||
user.sendTl("unsupportedFeature");
|
||||
user.sendMessage(tl("unsupportedFeature"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.TreeType;
|
||||
@@ -11,6 +10,8 @@ import org.bukkit.TreeType;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbigtree extends EssentialsCommand {
|
||||
public Commandbigtree() {
|
||||
super("bigtree");
|
||||
@@ -33,13 +34,13 @@ public class Commandbigtree extends EssentialsCommand {
|
||||
|
||||
final Location loc = LocationUtil.getTarget(user.getBase(), ess.getSettings().getMaxTreeCommandRange()).add(0, 1, 0);
|
||||
if (loc.getBlock().getType().isSolid()) {
|
||||
throw new TranslatableException("bigTreeFailure");
|
||||
throw new Exception(tl("bigTreeFailure"));
|
||||
}
|
||||
final boolean success = user.getWorld().generateTree(loc, tree);
|
||||
if (success) {
|
||||
user.sendTl("bigTreeSuccess");
|
||||
user.sendMessage(tl("bigTreeSuccess"));
|
||||
} else {
|
||||
throw new TranslatableException("bigTreeFailure");
|
||||
throw new Exception(tl("bigTreeFailure"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.WritableBookMeta;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbook extends EssentialsCommand {
|
||||
|
||||
private static final Material WRITABLE_BOOK = EnumUtil.getMaterial("WRITABLE_BOOK", "BOOK_AND_QUILL");
|
||||
@@ -26,7 +25,7 @@ public class Commandbook extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ItemStack item = Inventories.getItemInMainHand(user.getBase());
|
||||
final ItemStack item = user.getItemInHand();
|
||||
final String player = user.getName();
|
||||
if (item.getType() == Material.WRITTEN_BOOK) {
|
||||
final BookMeta bmeta = (BookMeta) item.getItemMeta();
|
||||
@@ -36,34 +35,27 @@ public class Commandbook extends EssentialsCommand {
|
||||
final String newAuthor = FormatUtil.formatString(user, "essentials.book.author", getFinalArg(args, 1)).trim();
|
||||
bmeta.setAuthor(newAuthor);
|
||||
item.setItemMeta(bmeta);
|
||||
user.sendTl("bookAuthorSet", newAuthor);
|
||||
user.sendMessage(tl("bookAuthorSet", newAuthor));
|
||||
} else {
|
||||
throw new TranslatableException("denyChangeAuthor");
|
||||
throw new Exception(tl("denyChangeAuthor"));
|
||||
}
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("title")) {
|
||||
if (user.isAuthorized("essentials.book.title") && (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others"))) {
|
||||
final String newTitle = FormatUtil.formatString(user, "essentials.book.title", getFinalArg(args, 1)).trim();
|
||||
bmeta.setTitle(newTitle);
|
||||
item.setItemMeta(bmeta);
|
||||
user.sendTl("bookTitleSet", newTitle);
|
||||
user.sendMessage(tl("bookTitleSet", newTitle));
|
||||
} else {
|
||||
throw new TranslatableException("denyChangeTitle");
|
||||
throw new Exception(tl("denyChangeTitle"));
|
||||
}
|
||||
} else {
|
||||
if (isAuthor(bmeta, player) || user.isAuthorized("essentials.book.others")) {
|
||||
final ItemStack newItem = new ItemStack(WRITABLE_BOOK, item.getAmount());
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
final WritableBookMeta wbmeta = (WritableBookMeta) newItem.getItemMeta();
|
||||
//noinspection DataFlowIssue
|
||||
wbmeta.setPages(bmeta.getPages());
|
||||
newItem.setItemMeta(wbmeta);
|
||||
} else {
|
||||
newItem.setItemMeta(bmeta);
|
||||
}
|
||||
newItem.setItemMeta(bmeta);
|
||||
Inventories.setItemInMainHand(user.getBase(), newItem);
|
||||
user.sendTl("editBookContents");
|
||||
user.sendMessage(tl("editBookContents"));
|
||||
} else {
|
||||
throw new TranslatableException("denyBookEdit");
|
||||
throw new Exception(tl("denyBookEdit"));
|
||||
}
|
||||
}
|
||||
} else if (item.getType() == WRITABLE_BOOK) {
|
||||
@@ -72,19 +64,11 @@ public class Commandbook extends EssentialsCommand {
|
||||
bmeta.setAuthor(player);
|
||||
}
|
||||
final ItemStack newItem = new ItemStack(Material.WRITTEN_BOOK, item.getAmount());
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) {
|
||||
final BookMeta real = (BookMeta) newItem.getItemMeta();
|
||||
real.setAuthor(bmeta.getAuthor());
|
||||
real.setTitle(bmeta.getTitle());
|
||||
real.setPages(bmeta.getPages());
|
||||
newItem.setItemMeta(real);
|
||||
} else {
|
||||
newItem.setItemMeta(bmeta);
|
||||
}
|
||||
newItem.setItemMeta(bmeta);
|
||||
Inventories.setItemInMainHand(user.getBase(), newItem);
|
||||
user.sendTl("bookLocked");
|
||||
user.sendMessage(tl("bookLocked"));
|
||||
} else {
|
||||
throw new TranslatableException("holdBook");
|
||||
throw new Exception(tl("holdBook"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import net.ess3.provider.WorldInfoProvider;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbottom extends EssentialsCommand {
|
||||
|
||||
public Commandbottom() {
|
||||
@@ -22,12 +23,12 @@ public class Commandbottom extends EssentialsCommand {
|
||||
final int bottomZ = user.getLocation().getBlockZ();
|
||||
final float pitch = user.getLocation().getPitch();
|
||||
final float yaw = user.getLocation().getYaw();
|
||||
final Location unsafe = new Location(user.getWorld(), bottomX, ess.provider(WorldInfoProvider.class).getMinHeight(user.getWorld()), bottomZ, yaw, pitch);
|
||||
final Location unsafe = new Location(user.getWorld(), bottomX, ess.getWorldInfoProvider().getMinHeight(user.getWorld()), bottomZ, yaw, pitch);
|
||||
final Location safe = LocationUtil.getSafeDestination(ess, unsafe);
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
user.sendTl("teleportBottom", safe.getWorld().getName(), safe.getBlockX(), safe.getBlockY(), safe.getBlockZ());
|
||||
user.sendMessage(tl("teleportBottom", safe.getWorld().getName(), safe.getBlockX(), safe.getBlockY(), safe.getBlockZ()));
|
||||
}
|
||||
});
|
||||
user.getAsyncTeleport().teleport(safe, new Trade(this.getName(), ess), PlayerTeleportEvent.TeleportCause.COMMAND, future);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbreak extends EssentialsCommand {
|
||||
public Commandbreak() {
|
||||
super("break");
|
||||
@@ -21,7 +22,7 @@ public class Commandbreak extends EssentialsCommand {
|
||||
throw new NoChargeException();
|
||||
}
|
||||
if (block.getType() == Material.BEDROCK && !user.isAuthorized("essentials.break.bedrock")) {
|
||||
throw new TranslatableException("noBreakBedrock");
|
||||
throw new Exception(tl("noBreakBedrock"));
|
||||
}
|
||||
//final List<ItemStack> list = (List<ItemStack>)block.getDrops();
|
||||
//final BlockBreakEvent event = new BlockBreakEvent(block, user.getBase(), list);
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbroadcast extends EssentialsCommand {
|
||||
public Commandbroadcast() {
|
||||
super("broadcast");
|
||||
@@ -15,6 +17,6 @@ public class Commandbroadcast extends EssentialsCommand {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
ess.broadcastTl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), sender.getDisplayName());
|
||||
ess.broadcastMessage(tl("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0)).replace("\\n", "\n"), sender.getDisplayName()));
|
||||
}
|
||||
}
|
||||
+27
-7
@@ -2,16 +2,21 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.SimpleTextInput;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandbroadcastworld extends EssentialsCommand {
|
||||
|
||||
public Commandbroadcastworld() {
|
||||
@@ -20,13 +25,13 @@ public class Commandbroadcastworld extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
if (args.length == 0) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
World world = user.getWorld();
|
||||
String message = getFinalArg(args, 0);
|
||||
if (ess.getSettings().isAllowWorldInBroadcastworld()) {
|
||||
if (args.length > 1 && ess.getSettings().isAllowWorldInBroadcastworld()) {
|
||||
final World argWorld = ess.getWorld(args[0]);
|
||||
if (argWorld != null) {
|
||||
world = argWorld;
|
||||
@@ -40,12 +45,12 @@ public class Commandbroadcastworld extends EssentialsCommand {
|
||||
@Override
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
throw new NotEnoughArgumentsException("world");
|
||||
}
|
||||
|
||||
final World world = ess.getWorld(args[0]);
|
||||
if (world == null) {
|
||||
throw new TranslatableException("invalidWorld");
|
||||
throw new Exception(tl("invalidWorld"));
|
||||
}
|
||||
sendBroadcast(world, sender.getSender().getName(), getFinalArg(args, 1));
|
||||
}
|
||||
@@ -54,7 +59,22 @@ public class Commandbroadcastworld extends EssentialsCommand {
|
||||
if (message.isEmpty()) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
ess.broadcastTl(null, u -> !u.getBase().getWorld().equals(world), true, "broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), AdventureUtil.parsed(AdventureUtil.legacyToMini(name)));
|
||||
sendToWorld(world, tl("broadcast", FormatUtil.replaceFormat(message).replace("\\n", "\n"), name));
|
||||
}
|
||||
|
||||
private void sendToWorld(final World world, final String message) {
|
||||
IText broadcast = new SimpleTextInput(message);
|
||||
final Collection<Player> players = ess.getOnlinePlayers();
|
||||
|
||||
for (final Player player : players) {
|
||||
if (player.getWorld().equals(world)) {
|
||||
final User user = ess.getUser(player);
|
||||
broadcast = new KeywordReplacer(broadcast, new CommandSource(player), ess, false);
|
||||
for (final String messageText : broadcast.getLines()) {
|
||||
user.sendMessage(messageText);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,6 +7,8 @@ import org.bukkit.Server;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandburn extends EssentialsCommand {
|
||||
public Commandburn() {
|
||||
super("burn");
|
||||
@@ -20,7 +22,7 @@ public class Commandburn extends EssentialsCommand {
|
||||
|
||||
final User user = getPlayer(server, sender, args, 0);
|
||||
user.getBase().setFireTicks(Integer.parseInt(args[1]) * 20);
|
||||
sender.sendTl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1]));
|
||||
sender.sendMessage(tl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1])));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-6
@@ -1,9 +1,10 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandcartographytable extends EssentialsCommand {
|
||||
|
||||
public Commandcartographytable() {
|
||||
@@ -12,13 +13,11 @@ public class Commandcartographytable extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openCartographyTable(user.getBase());
|
||||
ess.getContainerProvider().openCartographyTable(user.getBase());
|
||||
}
|
||||
}
|
||||
+10
-13
@@ -6,7 +6,6 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -20,6 +19,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandclearinventory extends EssentialsCommand {
|
||||
private static final int EXTENDED_CAP = 8;
|
||||
|
||||
@@ -54,7 +55,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
}
|
||||
|
||||
if (allowAll && args.length > 0 && args[0].contentEquals("*")) {
|
||||
sender.sendTl("inventoryClearingFromAll");
|
||||
sender.sendMessage(tl("inventoryClearingFromAll"));
|
||||
offset = 1;
|
||||
players = ess.getOnlinePlayers();
|
||||
} else if (allowOthers && args.length > 0 && args[0].trim().length() > 2) {
|
||||
@@ -71,7 +72,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
if (senderUser != null && senderUser.isPromptingClearConfirm()) {
|
||||
if (!formattedCommand.equals(previousClearCommand)) {
|
||||
senderUser.setConfirmingClearCommand(formattedCommand);
|
||||
senderUser.sendTl("confirmClear", formattedCommand);
|
||||
senderUser.sendMessage(tl("confirmClear", formattedCommand));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearHandler(final CommandSource sender, final Player player, final String[] args, final int offset, final boolean showExtended) throws TranslatableException {
|
||||
protected void clearHandler(final CommandSource sender, final Player player, final String[] args, final int offset, final boolean showExtended) {
|
||||
ClearHandlerType type = ClearHandlerType.ALL_EXCEPT_ARMOR;
|
||||
final Set<Item> items = new HashSet<>();
|
||||
int amount = -1;
|
||||
@@ -114,7 +115,7 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
if (type != ClearHandlerType.SPECIFIC_ITEM) {
|
||||
final boolean armor = type == ClearHandlerType.ALL_INCLUDING_ARMOR;
|
||||
if (showExtended) {
|
||||
sender.sendTl(armor ? "inventoryClearingAllArmor" : "inventoryClearingAllItems", player.getDisplayName());
|
||||
sender.sendMessage(tl(armor ? "inventoryClearingAllArmor" : "inventoryClearingAllItems", player.getDisplayName()));
|
||||
}
|
||||
Inventories.removeItems(player, item -> true, armor);
|
||||
} else {
|
||||
@@ -125,23 +126,19 @@ public class Commandclearinventory extends EssentialsCommand {
|
||||
stack.setDurability(item.getData());
|
||||
}
|
||||
|
||||
// can't remove a negative amount of items. (it adds them)
|
||||
if (amount < -1) {
|
||||
throw new TranslatableException("cannotRemoveNegativeItems");
|
||||
}
|
||||
|
||||
// amount -1 means all items will be cleared
|
||||
if (amount == -1) {
|
||||
final int removedAmount = Inventories.removeItemSimilar(player, stack, true);
|
||||
if (removedAmount > 0 || showExtended) {
|
||||
sender.sendTl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName());
|
||||
sender.sendMessage(tl("inventoryClearingStack", removedAmount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()));
|
||||
}
|
||||
} else {
|
||||
stack.setAmount(amount < 0 ? 1 : amount);
|
||||
if (Inventories.removeItemAmount(player, stack, amount)) {
|
||||
sender.sendTl("inventoryClearingStack", amount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName());
|
||||
sender.sendMessage(tl("inventoryClearingStack", amount, stack.getType().toString().toLowerCase(Locale.ENGLISH), player.getDisplayName()));
|
||||
} else {
|
||||
if (showExtended) {
|
||||
sender.sendTl("inventoryClearFail", player.getDisplayName(), amount, stack.getType().toString().toLowerCase(Locale.ENGLISH));
|
||||
sender.sendMessage(tl("inventoryClearFail", player.getDisplayName(), amount, stack.getType().toString().toLowerCase(Locale.ENGLISH)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandclearinventoryconfirmtoggle extends EssentialsCommand {
|
||||
|
||||
public Commandclearinventoryconfirmtoggle() {
|
||||
@@ -19,9 +21,9 @@ public class Commandclearinventoryconfirmtoggle extends EssentialsCommand {
|
||||
}
|
||||
user.setPromptingClearConfirm(confirmingClear);
|
||||
if (confirmingClear) {
|
||||
user.sendTl("clearInventoryConfirmToggleOn");
|
||||
user.sendMessage(tl("clearInventoryConfirmToggleOn"));
|
||||
} else {
|
||||
user.sendTl("clearInventoryConfirmToggleOff");
|
||||
user.sendMessage(tl("clearInventoryConfirmToggleOff"));
|
||||
}
|
||||
user.setConfirmingClearCommand(null);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandcompass extends EssentialsCommand {
|
||||
public Commandcompass() {
|
||||
super("compass");
|
||||
@@ -13,24 +15,24 @@ public class Commandcompass extends EssentialsCommand {
|
||||
final int bearing = (int) (user.getLocation().getYaw() + 180 + 360) % 360;
|
||||
final String dir;
|
||||
if (bearing < 23) {
|
||||
dir = user.playerTl("north");
|
||||
dir = tl("north");
|
||||
} else if (bearing < 68) {
|
||||
dir = user.playerTl("northEast");
|
||||
dir = tl("northEast");
|
||||
} else if (bearing < 113) {
|
||||
dir = user.playerTl("east");
|
||||
dir = tl("east");
|
||||
} else if (bearing < 158) {
|
||||
dir = user.playerTl("southEast");
|
||||
dir = tl("southEast");
|
||||
} else if (bearing < 203) {
|
||||
dir = user.playerTl("south");
|
||||
dir = tl("south");
|
||||
} else if (bearing < 248) {
|
||||
dir = user.playerTl("southWest");
|
||||
dir = tl("southWest");
|
||||
} else if (bearing < 293) {
|
||||
dir = user.playerTl("west");
|
||||
dir = tl("west");
|
||||
} else if (bearing < 338) {
|
||||
dir = user.playerTl("northWest");
|
||||
dir = tl("northWest");
|
||||
} else {
|
||||
dir = user.playerTl("north");
|
||||
dir = tl("north");
|
||||
}
|
||||
user.sendTl("compassBearing", dir, bearing);
|
||||
user.sendMessage(tl("compassBearing", dir, bearing));
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandcondense extends EssentialsCommand {
|
||||
private final Map<ItemStack, SimpleRecipe> condenseList = new HashMap<>();
|
||||
|
||||
@@ -56,9 +58,9 @@ public class Commandcondense extends EssentialsCommand {
|
||||
user.getBase().updateInventory();
|
||||
|
||||
if (didConvert) {
|
||||
user.sendTl("itemsConverted");
|
||||
user.sendMessage(tl("itemsConverted"));
|
||||
} else {
|
||||
user.sendTl("itemsNotConverted");
|
||||
user.sendMessage(tl("itemsNotConverted"));
|
||||
throw new NoChargeException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.PasteUtil;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.SerializationProvider;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -23,7 +21,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandcreatekit extends EssentialsCommand {
|
||||
public Commandcreatekit() {
|
||||
@@ -43,11 +41,10 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
final ItemStack[] items = Inventories.getInventory(user.getBase(), true);
|
||||
final List<String> list = new ArrayList<>();
|
||||
|
||||
final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class);
|
||||
boolean useSerializationProvider = ess.getSettings().isUseBetterKits();
|
||||
|
||||
if (useSerializationProvider && serializationProvider == null) {
|
||||
ess.showError(user.getSource(), new TranslatableException("createKitUnsupported"), commandLabel);
|
||||
if (useSerializationProvider && ess.getSerializationProvider() == null) {
|
||||
ess.showError(user.getSource(), new Exception(tl("createKitUnsupported")), commandLabel);
|
||||
useSerializationProvider = false;
|
||||
}
|
||||
|
||||
@@ -55,7 +52,7 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
|
||||
final String serialized;
|
||||
if (useSerializationProvider) {
|
||||
serialized = "@" + Base64Coder.encodeLines(serializationProvider.serializeItem(is));
|
||||
serialized = "@" + Base64Coder.encodeLines(ess.getSerializationProvider().serializeItem(is));
|
||||
} else {
|
||||
serialized = ess.getItemDb().serialize(is);
|
||||
}
|
||||
@@ -65,7 +62,7 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
// Some users might want to directly write to config knowing the consequences. *shrug*
|
||||
if (!ess.getSettings().isPastebinCreateKit()) {
|
||||
ess.getKits().addKit(kitname, list, delay);
|
||||
user.sendTl("createdKit", kitname, list.size(), delay);
|
||||
user.sendMessage(tl("createdKit", kitname, list.size(), delay));
|
||||
} else {
|
||||
uploadPaste(user.getSource(), kitname, delay, list);
|
||||
}
|
||||
@@ -89,10 +86,10 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(Collections.singletonList(new PasteUtil.PasteFile("kit_" + kitName + ".yml", fileContents)));
|
||||
future.thenAccept(result -> {
|
||||
if (result != null) {
|
||||
final String separator = tlLiteral("createKitSeparator");
|
||||
final String separator = tl("createKitSeparator");
|
||||
final String delayFormat = delay <= 0 ? "0" : DateUtil.formatDateDiff(System.currentTimeMillis() + (delay * 1000));
|
||||
sender.sendMessage(separator);
|
||||
sender.sendTl("createKitSuccess", kitName, delayFormat, result.getPasteUrl());
|
||||
sender.sendMessage(tl("createKitSuccess", kitName, delayFormat, result.getPasteUrl()));
|
||||
sender.sendMessage(separator);
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info(sender.getSender().getName() + " created a kit: " + result.getPasteUrl());
|
||||
@@ -100,12 +97,12 @@ public class Commandcreatekit extends EssentialsCommand {
|
||||
}
|
||||
});
|
||||
future.exceptionally(throwable -> {
|
||||
sender.sendTl("createKitFailed", kitName);
|
||||
sender.sendMessage(tl("createKitFailed", kitName));
|
||||
ess.getLogger().log(Level.SEVERE, "Error creating kit: ", throwable);
|
||||
return null;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
sender.sendTl("createKitFailed", kitName);
|
||||
sender.sendMessage(tl("createKitFailed", kitName));
|
||||
ess.getLogger().log(Level.SEVERE, "Error creating kit: ", e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,9 +3,6 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.IUser;
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.essentialsx.api.v2.events.HomeModifyEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -13,29 +10,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commanddelhome extends EssentialsCommand {
|
||||
public Commanddelhome() {
|
||||
super("delhome");
|
||||
}
|
||||
|
||||
private void deleteHome(CommandSource sender, User user, String home) {
|
||||
final HomeModifyEvent event = new HomeModifyEvent(sender.getUser(), user, home, user.getHome(home), false);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("HomeModifyEvent canceled for /delhome execution by " + sender.getDisplayName());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
user.delHome(home);
|
||||
} catch (Exception e) {
|
||||
sender.sendTl("invalidHome", home);
|
||||
}
|
||||
sender.sendTl("deleteHome", home);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length < 1) {
|
||||
@@ -56,32 +37,25 @@ public class Commanddelhome extends EssentialsCommand {
|
||||
|
||||
if (expandedArg.length > 1 && (user == null || user.isAuthorized("essentials.delhome.others"))) {
|
||||
user = getPlayer(server, expandedArg, 0, true, true);
|
||||
name = expandedArg[1].toLowerCase(Locale.ENGLISH);
|
||||
name = expandedArg[1];
|
||||
} else if (user == null) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
} else {
|
||||
name = expandedArg[0].toLowerCase(Locale.ENGLISH);
|
||||
name = expandedArg[0];
|
||||
}
|
||||
|
||||
switch (name) {
|
||||
case "bed":
|
||||
throw new TranslatableException("invalidHomeName");
|
||||
case "*":
|
||||
final List<String> homes = user.getHomes();
|
||||
for (String home : homes) {
|
||||
deleteHome(sender, user, home);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
deleteHome(sender, user, name);
|
||||
break;
|
||||
if (name.equalsIgnoreCase("bed")) {
|
||||
throw new Exception(tl("invalidHomeName"));
|
||||
}
|
||||
|
||||
user.delHome(name.toLowerCase(Locale.ENGLISH));
|
||||
sender.sendMessage(tl("deleteHome", name));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
final IUser user = sender.getUser();
|
||||
final boolean canDelOthers = sender.isAuthorized("essentials.delhome.others");
|
||||
final IUser user = sender.getUser(ess);
|
||||
final boolean canDelOthers = sender.isAuthorized("essentials.delhome.others", ess);
|
||||
if (args.length == 1) {
|
||||
final List<String> homes = user == null ? new ArrayList<>() : user.getHomes();
|
||||
if (canDelOthers) {
|
||||
@@ -97,7 +71,6 @@ public class Commanddelhome extends EssentialsCommand {
|
||||
return homes;
|
||||
}
|
||||
otherUser.getHomes().forEach(home -> homes.add(namePart + ":" + home));
|
||||
homes.add(namePart + ":" + "*");
|
||||
}
|
||||
}
|
||||
return homes;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commanddeljail extends EssentialsCommand {
|
||||
public Commanddeljail() {
|
||||
super("deljail");
|
||||
@@ -20,11 +21,11 @@ public class Commanddeljail extends EssentialsCommand {
|
||||
}
|
||||
|
||||
if (ess.getJails().getJail(args[0]) == null) {
|
||||
throw new TranslatableException("jailNotExist");
|
||||
throw new Exception(tl("jailNotExist"));
|
||||
}
|
||||
|
||||
ess.getJails().removeJail(args[0]);
|
||||
sender.sendTl("deleteJail", args[0]);
|
||||
sender.sendMessage(tl("deleteJail", args[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.Server;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commanddelkit extends EssentialsCommand {
|
||||
public Commanddelkit() {
|
||||
super("delkit");
|
||||
@@ -17,7 +19,7 @@ public class Commanddelkit extends EssentialsCommand {
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
if (args.length == 0) {
|
||||
final String kitList = ess.getKits().listKits(ess, null);
|
||||
sender.sendTl(kitList.length() > 0 ? "kits" : "noKits", kitList);
|
||||
sender.sendMessage(kitList.length() > 0 ? tl("kits", kitList) : tl("noKits"));
|
||||
throw new NoChargeException();
|
||||
} else {
|
||||
final String kitName = ess.getKits().matchKit(args[0]);
|
||||
@@ -28,7 +30,7 @@ public class Commanddelkit extends EssentialsCommand {
|
||||
}
|
||||
|
||||
ess.getKits().removeKit(kitName);
|
||||
sender.sendTl("deleteKit", kitName);
|
||||
sender.sendMessage(tl("deleteKit", kitName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.essentialsx.api.v2.events.WarpModifyEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@@ -11,6 +10,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commanddelwarp extends EssentialsCommand {
|
||||
public Commanddelwarp() {
|
||||
super("delwarp");
|
||||
@@ -30,15 +31,15 @@ public class Commanddelwarp extends EssentialsCommand {
|
||||
// World is unloaded/deleted
|
||||
location = null;
|
||||
}
|
||||
final WarpModifyEvent event = new WarpModifyEvent(sender.getUser(), args[0], location, null, WarpModifyEvent.WarpModifyCause.DELETE);
|
||||
final WarpModifyEvent event = new WarpModifyEvent(sender.getUser(this.ess), args[0], location, null, WarpModifyEvent.WarpModifyCause.DELETE);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
ess.getWarps().removeWarp(args[0]);
|
||||
sender.sendTl("deleteWarp", args[0]);
|
||||
sender.sendMessage(tl("deleteWarp", args[0]));
|
||||
} else {
|
||||
throw new TranslatableException("warpNotExist");
|
||||
throw new Exception(tl("warpNotExist"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commanddepth extends EssentialsCommand {
|
||||
public Commanddepth() {
|
||||
super("depth");
|
||||
@@ -12,11 +14,11 @@ public class Commanddepth extends EssentialsCommand {
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final int depth = user.getLocation().getBlockY() - user.getWorld().getSeaLevel();
|
||||
if (depth > 0) {
|
||||
user.sendTl("depthAboveSea", depth);
|
||||
user.sendMessage(tl("depthAboveSea", depth));
|
||||
} else if (depth < 0) {
|
||||
user.sendTl("depthBelowSea", -depth);
|
||||
user.sendMessage(tl("depthBelowSea", -depth));
|
||||
} else {
|
||||
user.sendTl("depth");
|
||||
user.sendMessage(tl("depth"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commanddisposal extends EssentialsCommand {
|
||||
|
||||
public Commanddisposal() {
|
||||
@@ -11,8 +13,8 @@ public class Commanddisposal extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
user.sendTl("openingDisposal");
|
||||
user.getBase().openInventory(ess.getServer().createInventory(user.getBase(), 36, user.playerTl("disposal")));
|
||||
user.sendMessage(tl("openingDisposal"));
|
||||
user.getBase().openInventory(ess.getServer().createInventory(user.getBase(), 36, tl("disposal")));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.ChargeException;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.MaxMoneyException;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.UserBalanceUpdateEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
@@ -16,6 +14,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandeco extends EssentialsLoopCommand {
|
||||
|
||||
public Commandeco() {
|
||||
@@ -54,7 +54,7 @@ public class Commandeco extends EssentialsLoopCommand {
|
||||
if (player.getMoney().subtract(userAmount).compareTo(ess.getSettings().getMinMoney()) >= 0) {
|
||||
player.takeMoney(userAmount, sender, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
|
||||
} else {
|
||||
ess.showError(sender, new TranslatableException("minimumBalanceError", AdventureUtil.parsed(NumberUtil.displayCurrency(ess.getSettings().getMinMoney(), ess))), commandLabel);
|
||||
ess.showError(sender, new Exception(tl("minimumBalanceError", NumberUtil.displayCurrency(ess.getSettings().getMinMoney(), ess))), commandLabel);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -65,8 +65,8 @@ public class Commandeco extends EssentialsLoopCommand {
|
||||
final boolean underMin = userAmount.compareTo(minBal) < 0;
|
||||
final boolean aboveMax = userAmount.compareTo(maxBal) > 0;
|
||||
player.setMoney(underMin ? minBal : aboveMax ? maxBal : userAmount, UserBalanceUpdateEvent.Cause.COMMAND_ECO);
|
||||
player.sendTl("setBal", AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
sender.sendTl("setBalOthers", player.getDisplayName(), AdventureUtil.parsed(NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
player.sendMessage(tl("setBal", NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
sender.sendMessage(tl("setBalOthers", player.getDisplayName(), NumberUtil.displayCurrency(player.getMoney(), ess)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,17 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.type.HangingSign;
|
||||
import org.bukkit.block.data.type.WallHangingSign;
|
||||
import org.bukkit.block.data.type.WallSign;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandeditsign extends EssentialsCommand {
|
||||
public Commandeditsign() {
|
||||
super("editsign");
|
||||
@@ -37,109 +27,67 @@ public class Commandeditsign extends EssentialsCommand {
|
||||
|
||||
final Block target = user.getTargetBlock(5); //5 is a good number
|
||||
if (!(target.getState() instanceof Sign)) {
|
||||
throw new TranslatableException("editsignCommandTarget");
|
||||
throw new Exception(tl("editsignCommandTarget"));
|
||||
}
|
||||
final ModifiableSign sign = wrapSign((Sign) target.getState(), user);
|
||||
final Sign sign = (Sign) target.getState();
|
||||
try {
|
||||
if (args[0].equalsIgnoreCase("set") && args.length > 2) {
|
||||
final String[] existingLines = sign.getLines();
|
||||
final int line = Integer.parseInt(args[1]) - 1;
|
||||
final String text = FormatUtil.formatString(user, "essentials.editsign", getFinalArg(args, 2)).trim();
|
||||
if (ChatColor.stripColor(text).length() > 15 && !user.isAuthorized("essentials.editsign.unlimited")) {
|
||||
throw new TranslatableException("editsignCommandLimit");
|
||||
throw new Exception(tl("editsignCommandLimit"));
|
||||
}
|
||||
existingLines[line] = text;
|
||||
if (callSignEvent(sign, user.getBase(), existingLines)) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.sendTl("editsignCommandSetSuccess", line + 1, text);
|
||||
sign.setLine(line, text);
|
||||
sign.update();
|
||||
user.sendMessage(tl("editsignCommandSetSuccess", line + 1, text));
|
||||
} else if (args[0].equalsIgnoreCase("clear")) {
|
||||
if (args.length == 1) {
|
||||
final String[] existingLines = sign.getLines();
|
||||
for (int i = 0; i < 4; i++) { // A whole one line of line savings!
|
||||
existingLines[i] = "";
|
||||
sign.setLine(i, "");
|
||||
}
|
||||
|
||||
if (callSignEvent(sign, user.getBase(), existingLines)) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.sendTl("editsignCommandClear");
|
||||
sign.update();
|
||||
user.sendMessage(tl("editsignCommandClear"));
|
||||
} else {
|
||||
final String[] existingLines = sign.getLines();
|
||||
final int line = Integer.parseInt(args[1]) - 1;
|
||||
existingLines[line] = "";
|
||||
|
||||
if (callSignEvent(sign, user.getBase(), existingLines)) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.sendTl("editsignCommandClearLine", line + 1);
|
||||
sign.setLine(line, "");
|
||||
sign.update();
|
||||
user.sendMessage(tl("editsignCommandClearLine", line + 1));
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("copy")) {
|
||||
} else if (args[0].equalsIgnoreCase("copy") || args[0].equalsIgnoreCase("paste")) {
|
||||
final boolean copy = args[0].equalsIgnoreCase("copy");
|
||||
final String tlPrefix = copy ? "editsignCopy" : "editsignPaste";
|
||||
final int line = args.length == 1 ? -1 : Integer.parseInt(args[1]) - 1;
|
||||
|
||||
if (line == -1) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// We use unformat here to prevent players from copying signs with colors that they do not have permission to use.
|
||||
user.getSignCopy().set(i, FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(i)));
|
||||
processSignCopyPaste(user, sign, i, copy);
|
||||
}
|
||||
user.sendTl("editsignCopy", commandLabel);
|
||||
user.sendMessage(tl(tlPrefix, commandLabel));
|
||||
} else {
|
||||
// We use unformat here to prevent players from copying signs with colors that they do not have permission to use.
|
||||
user.getSignCopy().set(line, FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(line)));
|
||||
user.sendTl("editsignCopyLine", line + 1, commandLabel);
|
||||
processSignCopyPaste(user, sign, line, copy);
|
||||
user.sendMessage(tl(tlPrefix + "Line", line + 1, commandLabel));
|
||||
}
|
||||
|
||||
} else if (args[0].equalsIgnoreCase("paste")) {
|
||||
final int line = args.length == 1 ? -1 : Integer.parseInt(args[1]) - 1;
|
||||
|
||||
final String[] existingLines = sign.getLines();
|
||||
if (line == -1) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
existingLines[i] = FormatUtil.formatString(user, "essentials.editsign", user.getSignCopy().get(i));
|
||||
}
|
||||
user.sendTl("editsignPaste", commandLabel);
|
||||
} else {
|
||||
existingLines[line] = FormatUtil.formatString(user, "essentials.editsign", user.getSignCopy().get(line));
|
||||
user.sendTl("editsignPasteLine", line + 1, commandLabel);
|
||||
if (!copy) {
|
||||
sign.update();
|
||||
}
|
||||
|
||||
callSignEvent(sign, user.getBase(), existingLines);
|
||||
} else {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
throw new TranslatableException(e, "editsignCommandNoLine");
|
||||
throw new Exception(tl("editsignCommandNoLine"), e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean callSignEvent(final ModifiableSign sign, final Player player, final String[] lines) {
|
||||
final SignChangeEvent event;
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_1_R01)) {
|
||||
if (sign.isWaxed() && !player.hasPermission("essentials.editsign.waxed.exempt")) {
|
||||
return true;
|
||||
}
|
||||
event = new SignChangeEvent(sign.getBlock(), player, lines, sign.isFront() ? Side.FRONT : Side.BACK);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
event = new SignChangeEvent(sign.getBlock(), player, lines);
|
||||
private void processSignCopyPaste(final User user, final Sign sign, final int index, final boolean copy) {
|
||||
if (copy) {
|
||||
// We use unformat here to prevent players from copying signs with colors that they do not have permission to use.
|
||||
user.getSignCopy().set(index, FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(index)));
|
||||
return;
|
||||
}
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
if (ess.getSettings().isDebug()) {
|
||||
ess.getLogger().info("SignChangeEvent canceled for /editsign execution by " + player.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
sign.setLine(i, lines[i]);
|
||||
}
|
||||
sign.update();
|
||||
return false;
|
||||
final String line = FormatUtil.formatString(user, "essentials.editsign", user.getSignCopy().get(index));
|
||||
sign.setLine(index, line == null ? "" : line);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -152,7 +100,7 @@ public class Commandeditsign extends EssentialsCommand {
|
||||
final int line = Integer.parseInt(args[1]);
|
||||
final Block target = user.getTargetBlock(5);
|
||||
if (target.getState() instanceof Sign && line <= 4) {
|
||||
final ModifiableSign sign = wrapSign((Sign) target.getState(), user);
|
||||
final Sign sign = (Sign) target.getState();
|
||||
return Lists.newArrayList(FormatUtil.unformatString(user, "essentials.editsign", sign.getLine(line - 1)));
|
||||
}
|
||||
return Collections.emptyList();
|
||||
@@ -160,105 +108,4 @@ public class Commandeditsign extends EssentialsCommand {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
private ModifiableSign wrapSign(final Sign sign, final User user) {
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_1_R01)) {
|
||||
final Vector eyeLocLessSign = user.getBase().getEyeLocation().toVector().subtract(sign.getLocation().add(.5, .5, .5).toVector());
|
||||
final BlockData signBlockData = sign.getBlockData();
|
||||
|
||||
final BlockFace signDirection;
|
||||
if (signBlockData instanceof org.bukkit.block.data.type.Sign) {
|
||||
signDirection = ((org.bukkit.block.data.type.Sign) signBlockData).getRotation();
|
||||
} else if (signBlockData instanceof WallSign) {
|
||||
signDirection = ((WallSign) signBlockData).getFacing();
|
||||
} else if (signBlockData instanceof HangingSign) {
|
||||
signDirection = ((HangingSign) signBlockData).getRotation();
|
||||
} else if (signBlockData instanceof WallHangingSign) {
|
||||
signDirection = ((WallHangingSign) signBlockData).getFacing();
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown block data for sign: " + signBlockData.getClass());
|
||||
}
|
||||
|
||||
final Side side = eyeLocLessSign.dot(signDirection.getDirection()) > 0 ? Side.FRONT : Side.BACK;
|
||||
|
||||
return new ModifiableSign(sign) {
|
||||
@Override
|
||||
String[] getLines() {
|
||||
return sign.getSide(side).getLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
String getLine(int line) {
|
||||
return sign.getSide(side).getLine(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
void setLine(int line, String text) {
|
||||
sign.getSide(side).setLine(line, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isFront() {
|
||||
return side == Side.FRONT;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isWaxed() {
|
||||
return sign.isWaxed();
|
||||
}
|
||||
};
|
||||
}
|
||||
return new ModifiableSign(sign) {
|
||||
@Override
|
||||
String[] getLines() {
|
||||
return sign.getLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
String getLine(int line) {
|
||||
return sign.getLine(line);
|
||||
}
|
||||
|
||||
@Override
|
||||
void setLine(int line, String text) {
|
||||
sign.setLine(line, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isFront() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isWaxed() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private abstract static class ModifiableSign {
|
||||
protected final Sign sign;
|
||||
|
||||
protected ModifiableSign(final Sign sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
abstract String getLine(int line);
|
||||
|
||||
abstract String[] getLines();
|
||||
|
||||
abstract void setLine(int line, String text);
|
||||
|
||||
abstract boolean isFront();
|
||||
|
||||
abstract boolean isWaxed();
|
||||
|
||||
Block getBlock() {
|
||||
return sign.getBlock();
|
||||
}
|
||||
|
||||
void update() {
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.Enchantments;
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -14,10 +14,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandenchant extends EssentialsCommand {
|
||||
public Commandenchant() {
|
||||
super("enchant");
|
||||
@@ -28,18 +31,18 @@ public class Commandenchant extends EssentialsCommand {
|
||||
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ItemStack stack = user.getItemInHand();
|
||||
if (stack == null || stack.getType() == Material.AIR) {
|
||||
throw new TranslatableException("nothingInHand");
|
||||
throw new Exception(tl("nothingInHand"));
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
final Set<String> usableEnchants = new TreeSet<>();
|
||||
for (final Map.Entry<String, Enchantment> entry : Enchantments.entrySet()) {
|
||||
final String name = Enchantments.getRealName(entry.getValue());
|
||||
final String name = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
|
||||
if (usableEnchants.contains(name) || (user.isAuthorized("essentials.enchantments." + name) && entry.getValue().canEnchantItem(stack))) {
|
||||
usableEnchants.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
throw new NotEnoughArgumentsException(user.playerTl("enchantments", StringUtil.joinList(usableEnchants.toArray())));
|
||||
throw new NotEnoughArgumentsException(tl("enchantments", StringUtil.joinList(usableEnchants.toArray())));
|
||||
}
|
||||
|
||||
int level = 1;
|
||||
@@ -54,13 +57,13 @@ public class Commandenchant extends EssentialsCommand {
|
||||
final MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
final Enchantment enchantment = metaStack.getEnchantment(user, args[0]);
|
||||
metaStack.addEnchantment(user.getSource(), ess.getSettings().allowUnsafeEnchantments() && user.isAuthorized("essentials.enchantments.allowunsafe"), enchantment, level);
|
||||
stack.setItemMeta(metaStack.getItemStack().getItemMeta());
|
||||
Inventories.setItemInMainHand(user.getBase(), metaStack.getItemStack());
|
||||
user.getBase().updateInventory();
|
||||
final String enchantName = Enchantments.getRealName(enchantment).replace('_', ' ');
|
||||
final String enchantName = enchantment.getName().toLowerCase(Locale.ENGLISH).replace('_', ' ');
|
||||
if (level == 0) {
|
||||
user.sendTl("enchantmentRemoved", enchantName);
|
||||
user.sendMessage(tl("enchantmentRemoved", enchantName));
|
||||
} else {
|
||||
user.sendTl("enchantmentApplied", enchantName);
|
||||
user.sendMessage(tl("enchantmentApplied", enchantName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.economy.EconomyLayer;
|
||||
import com.earth2me.essentials.economy.EconomyLayers;
|
||||
import com.earth2me.essentials.userstorage.ModernUserMap;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.CommandMapUtil;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.EnumUtil;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.PasteUtil;
|
||||
import com.earth2me.essentials.utils.RegistryUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -21,12 +20,8 @@ import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import net.ess3.provider.OnlineModeProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
@@ -64,13 +59,13 @@ import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
// This command has 4 undocumented behaviours #EasterEgg
|
||||
public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
private static final Sound NOTE_HARP = RegistryUtil.valueOf(Sound.class, "BLOCK_NOTE_BLOCK_HARP", "BLOCK_NOTE_HARP", "NOTE_PIANO");
|
||||
private static final Sound MOO_SOUND = RegistryUtil.valueOf(Sound.class, "COW_IDLE", "ENTITY_COW_MILK");
|
||||
private static final Sound NOTE_HARP = EnumUtil.valueOf(Sound.class, "BLOCK_NOTE_BLOCK_HARP", "BLOCK_NOTE_HARP", "NOTE_PIANO");
|
||||
private static final Sound MOO_SOUND = EnumUtil.valueOf(Sound.class, "COW_IDLE", "ENTITY_COW_MILK");
|
||||
|
||||
private static final String HOMES_USAGE = "/<command> homes (fix | delete [world])";
|
||||
|
||||
@@ -182,7 +177,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
}
|
||||
|
||||
public void runItemTest(Server server, CommandSource sender, String commandLabel, String[] args) {
|
||||
if (!sender.isAuthorized("essentials.itemtest") || args.length < 2 || !sender.isPlayer()) {
|
||||
if (!sender.isAuthorized("essentials.itemtest", ess) || args.length < 2 || !sender.isPlayer()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -239,11 +234,11 @@ public class Commandessentials extends EssentialsCommand {
|
||||
// Lists commands that are being handed over to other plugins.
|
||||
private void runCommands(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (ess.getAlternativeCommandsHandler().disabledCommands().size() == 0) {
|
||||
sender.sendTl("blockListEmpty");
|
||||
sender.sendMessage(tl("blockListEmpty"));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendTl("blockList");
|
||||
sender.sendMessage(tl("blockList"));
|
||||
for (final Map.Entry<String, String> entry : ess.getAlternativeCommandsHandler().disabledCommands().entrySet()) {
|
||||
sender.sendMessage(entry.getKey() + " => " + entry.getValue());
|
||||
}
|
||||
@@ -251,7 +246,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
// Generates a paste of useful information
|
||||
private void runDump(Server server, CommandSource sender, String commandLabel, String[] args) {
|
||||
sender.sendTl("dumpCreating");
|
||||
sender.sendMessage(tl("dumpCreating"));
|
||||
|
||||
final JsonObject dump = new JsonObject();
|
||||
|
||||
@@ -265,7 +260,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
serverData.addProperty("bukkit-version", Bukkit.getBukkitVersion());
|
||||
serverData.addProperty("server-version", Bukkit.getVersion());
|
||||
serverData.addProperty("server-brand", Bukkit.getName());
|
||||
serverData.addProperty("online-mode", ess.provider(OnlineModeProvider.class).getOnlineModeString());
|
||||
serverData.addProperty("online-mode", ess.getOnlineModeProvider().getOnlineModeString());
|
||||
final JsonObject supportStatus = new JsonObject();
|
||||
final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus();
|
||||
supportStatus.addProperty("status", status.name());
|
||||
@@ -333,10 +328,9 @@ public class Commandessentials extends EssentialsCommand {
|
||||
files.add(new PasteUtil.PasteFile("dump.json", dump.toString()));
|
||||
|
||||
final Plugin essDiscord = Bukkit.getPluginManager().getPlugin("EssentialsDiscord");
|
||||
final Plugin essDiscordLink = Bukkit.getPluginManager().getPlugin("EssentialsDiscordLink");
|
||||
final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
|
||||
|
||||
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.provider(KnownCommandsProvider.class).getKnownCommands());
|
||||
final Map<String, Command> knownCommandsCopy = new HashMap<>(ess.getKnownCommandsProvider().getKnownCommands());
|
||||
final Map<String, String> disabledCommandsCopy = new HashMap<>(ess.getAlternativeCommandsHandler().disabledCommands());
|
||||
|
||||
// Further operations will be heavy IO
|
||||
@@ -383,7 +377,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
try {
|
||||
files.add(new PasteUtil.PasteFile("config.yml", new String(Files.readAllBytes(ess.getSettings().getConfigFile().toPath()), StandardCharsets.UTF_8)));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "config.yml", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "config.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,16 +387,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
new String(Files.readAllBytes(essDiscord.getDataFolder().toPath().resolve("config.yml")), StandardCharsets.UTF_8)
|
||||
.replaceAll("[A-Za-z\\d]{24}\\.[\\w-]{6}\\.[\\w-]{27}", "<censored token>")));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "discord-config.yml", e.getMessage());
|
||||
}
|
||||
|
||||
if (essDiscordLink != null) {
|
||||
try {
|
||||
files.add(new PasteUtil.PasteFile("discord-link-config.yml",
|
||||
new String(Files.readAllBytes(essDiscordLink.getDataFolder().toPath().resolve("config.yml")), StandardCharsets.UTF_8)));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "discord-link-config.yml", e.getMessage());
|
||||
}
|
||||
sender.sendMessage(tl("dumpErrorUpload", "discord-config.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,7 +395,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
try {
|
||||
files.add(new PasteUtil.PasteFile("kits.yml", new String(Files.readAllBytes(ess.getKits().getFile().toPath()), StandardCharsets.UTF_8)));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "kits.yml", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "kits.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +405,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
.replaceAll("(?m)^\\[\\d\\d:\\d\\d:\\d\\d] \\[.+/(?:DEBUG|TRACE)]: .+\\s(?:[A-Za-z.]+:.+\\s(?:\\t.+\\s)*)?\\s*(?:\"[A-Za-z]+\" : .+[\\s}\\]]+)*", "")
|
||||
.replaceAll("(?:[0-9]{1,3}\\.){3}[0-9]{1,3}", "<censored ip address>")));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "latest.log", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "latest.log", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +413,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
try {
|
||||
files.add(new PasteUtil.PasteFile("worth.yml", new String(Files.readAllBytes(ess.getWorth().getFile().toPath()), StandardCharsets.UTF_8)));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "worth.yml", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "worth.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,7 +421,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
try {
|
||||
files.add(new PasteUtil.PasteFile("tpr.yml", new String(Files.readAllBytes(ess.getRandomTeleport().getFile().toPath()), StandardCharsets.UTF_8)));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "tpr.yml", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "tpr.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +429,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
try {
|
||||
files.add(new PasteUtil.PasteFile("spawn.yml", new String(Files.readAllBytes(ess.getDataFolder().toPath().resolve("spawn.yml")), StandardCharsets.UTF_8)));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "spawn.yml", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "spawn.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,27 +439,25 @@ public class Commandessentials extends EssentialsCommand {
|
||||
files.add(new PasteUtil.PasteFile("commandmap.json", CommandMapUtil.toJsonPretty(ess, knownCommandsCopy)));
|
||||
files.add(new PasteUtil.PasteFile("commandoverride.json", disabledCommandsCopy.toString()));
|
||||
} catch (IOException e) {
|
||||
sender.sendTl("dumpErrorUpload", "commands.yml", e.getMessage());
|
||||
sender.sendMessage(tl("dumpErrorUpload", "commands.yml", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
|
||||
future.thenAccept(result -> {
|
||||
if (result != null) {
|
||||
final String dumpUrl = "https://essentialsx.net/dump.html?bytebin=" + result.getPasteId();
|
||||
sender.sendTl("dumpUrl", dumpUrl);
|
||||
// pastes.dev doesn't support deletion keys
|
||||
//sender.sendTl("dumpDeleteKey", result.getDeletionKey());
|
||||
final String dumpUrl = "https://essentialsx.net/dump.html?id=" + result.getPasteId();
|
||||
sender.sendMessage(tl("dumpUrl", dumpUrl));
|
||||
sender.sendMessage(tl("dumpDeleteKey", result.getDeletionKey()));
|
||||
if (sender.isPlayer()) {
|
||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpConsoleUrl", dumpUrl)));
|
||||
// pastes.dev doesn't support deletion keys
|
||||
//ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
|
||||
ess.getLogger().info(tl("dumpConsoleUrl", dumpUrl));
|
||||
ess.getLogger().info(tl("dumpDeleteKey", result.getDeletionKey()));
|
||||
}
|
||||
}
|
||||
files.clear();
|
||||
});
|
||||
future.exceptionally(throwable -> {
|
||||
sender.sendTl("dumpError", throwable.getMessage());
|
||||
sender.sendMessage(tl("dumpError", throwable.getMessage()));
|
||||
return null;
|
||||
});
|
||||
});
|
||||
@@ -499,7 +482,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
// Reloads all reloadable configs.
|
||||
private void runReload(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
ess.reload();
|
||||
sender.sendTl("essentialsReload", ess.getDescription().getVersion());
|
||||
sender.sendMessage(tl("essentialsReload", ess.getDescription().getVersion()));
|
||||
}
|
||||
|
||||
// Pop tarts.
|
||||
@@ -543,10 +526,10 @@ public class Commandessentials extends EssentialsCommand {
|
||||
throw new Exception("/<command> cleanup <days> [money] [homes]");
|
||||
}
|
||||
|
||||
sender.sendTl("cleaning");
|
||||
sender.sendMessage(tl("cleaning"));
|
||||
|
||||
final long daysArg = Long.parseLong(args[1]);
|
||||
final double moneyArg = args.length >= 3 ? FloatUtil.parseDouble(args[2].replaceAll("[^0-9.]", "")) : 0;
|
||||
final double moneyArg = args.length >= 3 ? FloatUtil.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0;
|
||||
final int homesArg = args.length >= 4 && NumberUtil.isInt(args[3]) ? Integer.parseInt(args[3]) : 0;
|
||||
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
@@ -584,7 +567,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
user.reset();
|
||||
}
|
||||
sender.sendTl("cleaned");
|
||||
sender.sendMessage(tl("cleaned"));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -599,7 +582,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
switch (args[1]) {
|
||||
case "fix":
|
||||
sender.sendTl("fixingHomes");
|
||||
sender.sendMessage(tl("fixingHomes"));
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
for (final UUID u : ess.getUsers().getAllUserUUIDs()) {
|
||||
final User user = ess.getUsers().loadUncachedUser(u);
|
||||
@@ -616,19 +599,15 @@ public class Commandessentials extends EssentialsCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
sender.sendTl("fixedHomes");
|
||||
sender.sendMessage(tl("fixedHomes"));
|
||||
});
|
||||
break;
|
||||
case "delete":
|
||||
final boolean filterByWorld = args.length >= 3;
|
||||
if (filterByWorld && server.getWorld(args[2]) == null) {
|
||||
throw new TranslatableException("invalidWorld");
|
||||
}
|
||||
if (filterByWorld) {
|
||||
sender.sendTl("deletingHomesWorld", args[2]);
|
||||
} else {
|
||||
sender.sendTl("deletingHomes");
|
||||
throw new Exception(tl("invalidWorld"));
|
||||
}
|
||||
sender.sendMessage(filterByWorld ? tl("deletingHomesWorld", args[2]) : tl("deletingHomes"));
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
for (final UUID u : ess.getUsers().getAllUserUUIDs()) {
|
||||
final User user = ess.getUsers().loadUncachedUser(u);
|
||||
@@ -646,12 +625,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (filterByWorld) {
|
||||
sender.sendTl("deletedHomesWorld", args[2]);
|
||||
} else {
|
||||
sender.sendTl("deletedHomes");
|
||||
}
|
||||
sender.sendMessage(filterByWorld ? tl("deletedHomesWorld", args[2]) : tl("deletedHomes"));
|
||||
});
|
||||
break;
|
||||
default:
|
||||
@@ -661,21 +635,21 @@ public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
// Gets information about cached users
|
||||
private void runUserMap(final CommandSource sender, final String[] args) {
|
||||
if (!sender.isAuthorized("essentials.usermap")) {
|
||||
if (!sender.isAuthorized("essentials.usermap", ess)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ModernUserMap userMap = (ModernUserMap) ess.getUsers();
|
||||
sender.sendTl("usermapSize", userMap.getCachedCount(), userMap.getUserCount(), ess.getSettings().getMaxUserCacheCount());
|
||||
sender.sendMessage(tl("usermapSize", userMap.getCachedCount(), userMap.getUserCount(), ess.getSettings().getMaxUserCacheCount()));
|
||||
if (args.length > 1) {
|
||||
if (args[1].equals("full")) {
|
||||
for (final Map.Entry<String, UUID> entry : userMap.getNameCache().entrySet()) {
|
||||
sender.sendTl("usermapEntry", entry.getKey(), entry.getValue().toString());
|
||||
sender.sendMessage(tl("usermapEntry", entry.getKey(), entry.getValue().toString()));
|
||||
}
|
||||
} else if (args[1].equals("purge")) {
|
||||
final boolean seppuku = args.length > 2 && args[2].equals("iknowwhatimdoing");
|
||||
|
||||
sender.sendTl("usermapPurge", String.valueOf(seppuku));
|
||||
sender.sendMessage(tl("usermapPurge", String.valueOf(seppuku)));
|
||||
|
||||
final Set<UUID> uuids = new HashSet<>(ess.getUsers().getAllUserUUIDs());
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
@@ -716,19 +690,17 @@ public class Commandessentials extends EssentialsCommand {
|
||||
}
|
||||
ess.getLogger().info("Found " + total + " orphaned userdata files.");
|
||||
});
|
||||
} else if (args[1].equalsIgnoreCase("cache")) {
|
||||
sender.sendTl("usermapKnown", ess.getUsers().getAllUserUUIDs().size(), ess.getUsers().getNameCache().size());
|
||||
} else {
|
||||
try {
|
||||
final UUID uuid = UUID.fromString(args[1]);
|
||||
for (final Map.Entry<String, UUID> entry : userMap.getNameCache().entrySet()) {
|
||||
if (entry.getValue().equals(uuid)) {
|
||||
sender.sendTl("usermapEntry", entry.getKey(), args[1]);
|
||||
sender.sendMessage(tl("usermapEntry", entry.getKey(), args[1]));
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
final String sanitizedName = userMap.getSanitizedName(args[1]);
|
||||
sender.sendTl("usermapEntry", sanitizedName, userMap.getNameCache().get(sanitizedName).toString());
|
||||
sender.sendMessage(tl("usermapEntry", sanitizedName, userMap.getNameCache().get(sanitizedName).toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -754,9 +726,9 @@ public class Commandessentials extends EssentialsCommand {
|
||||
serverMessageKey = "versionOutputWarn";
|
||||
}
|
||||
|
||||
sender.sendTl(serverMessageKey, "Server", server.getBukkitVersion() + " " + server.getVersion());
|
||||
sender.sendTl(serverMessageKey, "Brand", server.getName());
|
||||
sender.sendTl("versionOutputFine", "EssentialsX", essVer);
|
||||
sender.sendMessage(tl(serverMessageKey, "Server", server.getBukkitVersion() + " " + server.getVersion()));
|
||||
sender.sendMessage(tl(serverMessageKey, "Brand", server.getName()));
|
||||
sender.sendMessage(tl("versionOutputFine", "EssentialsX", essVer));
|
||||
|
||||
for (final Plugin plugin : pm.getPlugins()) {
|
||||
final PluginDescriptionFile desc = plugin.getDescription();
|
||||
@@ -769,22 +741,22 @@ public class Commandessentials extends EssentialsCommand {
|
||||
|
||||
if (!version.equalsIgnoreCase(essVer)) {
|
||||
isMismatched = true;
|
||||
sender.sendTl("versionOutputWarn", name, version);
|
||||
sender.sendMessage(tl("versionOutputWarn", name, version));
|
||||
} else {
|
||||
sender.sendTl("versionOutputFine", name, version);
|
||||
sender.sendMessage(tl("versionOutputFine", name, version));
|
||||
}
|
||||
} else {
|
||||
sender.sendTl("versionOutputUnsupported", name, version);
|
||||
sender.sendMessage(tl("versionOutputUnsupported", name, version));
|
||||
isUnsupported = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (versionPlugins.contains(name)) {
|
||||
if (warnPlugins.contains(name)) {
|
||||
sender.sendTl("versionOutputUnsupported", name, version);
|
||||
sender.sendMessage(tl("versionOutputUnsupported", name, version));
|
||||
isUnsupported = true;
|
||||
} else {
|
||||
sender.sendTl("versionOutputFine", name, version);
|
||||
sender.sendMessage(tl("versionOutputFine", name, version));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -800,48 +772,48 @@ public class Commandessentials extends EssentialsCommand {
|
||||
} else {
|
||||
layer = "None";
|
||||
}
|
||||
sender.sendTl("versionOutputEconLayer", layer);
|
||||
sender.sendMessage(tl("versionOutputEconLayer", layer));
|
||||
|
||||
if (isMismatched) {
|
||||
sender.sendTl("versionMismatchAll");
|
||||
sender.sendMessage(tl("versionMismatchAll"));
|
||||
}
|
||||
|
||||
if (!isVaultInstalled) {
|
||||
sender.sendTl("versionOutputVaultMissing");
|
||||
sender.sendMessage(tl("versionOutputVaultMissing"));
|
||||
}
|
||||
|
||||
if (isUnsupported) {
|
||||
sender.sendTl("versionOutputUnsupportedPlugins");
|
||||
sender.sendMessage(tl("versionOutputUnsupportedPlugins"));
|
||||
}
|
||||
|
||||
switch (supportStatus) {
|
||||
case NMS_CLEANROOM:
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupportedCleanroom").color(NamedTextColor.DARK_RED));
|
||||
sender.sendMessage(ChatColor.DARK_RED + tl("serverUnsupportedCleanroom"));
|
||||
break;
|
||||
case DANGEROUS_FORK:
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupportedDangerous").color(NamedTextColor.DARK_RED));
|
||||
sender.sendMessage(ChatColor.DARK_RED + tl("serverUnsupportedDangerous"));
|
||||
break;
|
||||
case STUPID_PLUGIN:
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupportedDumbPlugins").color(NamedTextColor.DARK_RED));
|
||||
sender.sendMessage(ChatColor.DARK_RED + tl("serverUnsupportedDumbPlugins"));
|
||||
break;
|
||||
case UNSTABLE:
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupportedMods").color(NamedTextColor.DARK_RED));
|
||||
sender.sendMessage(ChatColor.DARK_RED + tl("serverUnsupportedMods"));
|
||||
break;
|
||||
case OUTDATED:
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupported").color(NamedTextColor.RED));
|
||||
sender.sendMessage(ChatColor.RED + tl("serverUnsupported"));
|
||||
break;
|
||||
case LIMITED:
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupportedLimitedApi").color(NamedTextColor.RED));
|
||||
sender.sendMessage(ChatColor.RED + tl("serverUnsupportedLimitedApi"));
|
||||
break;
|
||||
}
|
||||
if (VersionUtil.getSupportStatusClass() != null) {
|
||||
sender.sendComponent(sender.tlComponent("serverUnsupportedClass").color(NamedTextColor.RED));
|
||||
sender.sendMessage(ChatColor.RED + tl("serverUnsupportedClass", VersionUtil.getSupportStatusClass()));
|
||||
}
|
||||
|
||||
sender.sendTl("versionFetching");
|
||||
sender.sendMessage(tl("versionFetching"));
|
||||
ess.runTaskAsynchronously(() -> {
|
||||
for (final Component component : ess.getUpdateChecker().getVersionMessages(true, true, sender)) {
|
||||
sender.sendComponent(component);
|
||||
for (String str : ess.getUpdateChecker().getVersionMessages(true, true)) {
|
||||
sender.sendMessage(str);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandexp extends EssentialsLoopCommand {
|
||||
public Commandexp() {
|
||||
super("exp");
|
||||
@@ -20,7 +22,7 @@ public class Commandexp extends EssentialsLoopCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
final IUser user = sender.getUser();
|
||||
final IUser user = sender.getUser(ess);
|
||||
if (args.length == 0 || (args.length < 2 && user == null)) {
|
||||
if (user == null) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
@@ -37,7 +39,7 @@ public class Commandexp extends EssentialsLoopCommand {
|
||||
}
|
||||
|
||||
if (!cmd.hasPermission(user)) {
|
||||
user.sendTl("noAccessSubCommand", "/" + commandLabel + " " + cmd.name().toLowerCase(Locale.ENGLISH));
|
||||
user.sendMessage(tl("noAccessSubCommand", "/" + commandLabel + " " + cmd.name().toLowerCase(Locale.ENGLISH)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ public class Commandexp extends EssentialsLoopCommand {
|
||||
}
|
||||
|
||||
private void showExp(final CommandSource sender, final IUser target) {
|
||||
sender.sendTl("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target.getBase()), target.getBase().getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase()));
|
||||
sender.sendMessage(tl("exp", target.getDisplayName(), SetExpFix.getTotalExperience(target.getBase()), target.getBase().getLevel(), SetExpFix.getExpUntilNextLevel(target.getBase())));
|
||||
}
|
||||
|
||||
//TODO: Limit who can give negative exp?
|
||||
@@ -129,7 +131,7 @@ public class Commandexp extends EssentialsLoopCommand {
|
||||
amount = 0L;
|
||||
}
|
||||
SetExpFix.setTotalExperience(target.getBase(), (int) amount);
|
||||
sender.sendTl("expSet", target.getDisplayName(), amount);
|
||||
sender.sendMessage(tl("expSet", target.getDisplayName(), amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.entity.Player;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandext extends EssentialsLoopCommand {
|
||||
public Commandext() {
|
||||
super("ext");
|
||||
@@ -30,13 +32,13 @@ public class Commandext extends EssentialsLoopCommand {
|
||||
}
|
||||
|
||||
extPlayer(user.getBase());
|
||||
user.sendTl("extinguish");
|
||||
user.sendMessage(tl("extinguish"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) {
|
||||
extPlayer(player.getBase());
|
||||
sender.sendTl("extinguishOthers", player.getDisplayName());
|
||||
sender.sendMessage(tl("extinguishOthers", player.getDisplayName()));
|
||||
}
|
||||
|
||||
private void extPlayer(final Player player) {
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandfeed extends EssentialsLoopCommand {
|
||||
public Commandfeed() {
|
||||
super("feed");
|
||||
@@ -26,7 +28,7 @@ public class Commandfeed extends EssentialsLoopCommand {
|
||||
}
|
||||
|
||||
feedPlayer(user.getBase());
|
||||
user.sendTl("feed");
|
||||
user.sendMessage(tl("feed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,7 +44,7 @@ public class Commandfeed extends EssentialsLoopCommand {
|
||||
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException {
|
||||
try {
|
||||
feedPlayer(player.getBase());
|
||||
sender.sendTl("feedOther", player.getDisplayName());
|
||||
sender.sendMessage(tl("feedOther", player.getDisplayName()));
|
||||
} catch (final QuietAbortException e) {
|
||||
//Handle Quietly
|
||||
}
|
||||
@@ -64,7 +66,7 @@ public class Commandfeed extends EssentialsLoopCommand {
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.feed.others")) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.feed.others", ess)) {
|
||||
return getPlayers(server, sender);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.earth2me.essentials.utils.FloatUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.DragonFireball;
|
||||
@@ -19,7 +18,6 @@ import org.bukkit.entity.Snowball;
|
||||
import org.bukkit.entity.SplashPotion;
|
||||
import org.bukkit.entity.ThrownExpBottle;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.entity.WindCharge;
|
||||
import org.bukkit.entity.WitherSkull;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -29,6 +27,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandfireball extends EssentialsCommand {
|
||||
|
||||
public static final String FIREBALL_META_KEY = "ess_fireball_proj";
|
||||
@@ -56,10 +56,6 @@ public class Commandfireball extends EssentialsCommand {
|
||||
builder.put("trident", Trident.class);
|
||||
}
|
||||
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_R01)) {
|
||||
builder.put("windcharge", WindCharge.class);
|
||||
}
|
||||
|
||||
types = builder.build();
|
||||
}
|
||||
|
||||
@@ -82,7 +78,7 @@ public class Commandfireball extends EssentialsCommand {
|
||||
}
|
||||
|
||||
if (!user.isAuthorized("essentials.fireball." + type)) {
|
||||
throw new TranslatableException("noPerm", "essentials.fireball." + type);
|
||||
throw new Exception(tl("noPerm", "essentials.fireball." + type));
|
||||
}
|
||||
|
||||
final Vector direction = user.getBase().getEyeLocation().getDirection().multiply(speed);
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.MetaItemStack;
|
||||
import com.earth2me.essentials.MobCompat;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.MaterialUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.FireworkEffect;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Firework;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.FireworkMeta;
|
||||
@@ -18,6 +17,8 @@ import org.bukkit.util.Vector;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
//This command has quite a complicated syntax, in theory it has 4 seperate syntaxes which are all variable:
|
||||
//
|
||||
//1: /firework clear - This clears all of the effects on a firework stack
|
||||
@@ -48,21 +49,21 @@ public class Commandfirework extends EssentialsCommand {
|
||||
|
||||
final ItemStack stack = user.getItemInHand();
|
||||
if (!MaterialUtil.isFirework(stack.getType())) {
|
||||
throw new TranslatableException("holdFirework");
|
||||
throw new Exception(tl("holdFirework"));
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("clear")) {
|
||||
final FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
|
||||
fmeta.clearEffects();
|
||||
stack.setItemMeta(fmeta);
|
||||
user.sendTl("fireworkEffectsCleared");
|
||||
user.sendMessage(tl("fireworkEffectsCleared"));
|
||||
} else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || args[0].equalsIgnoreCase("p"))) {
|
||||
final FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
|
||||
try {
|
||||
final int power = Integer.parseInt(args[1]);
|
||||
fmeta.setPower(power > 3 ? 4 : power);
|
||||
} catch (final NumberFormatException e) {
|
||||
throw new TranslatableException("invalidFireworkFormat", args[1], args[0]);
|
||||
throw new Exception(tl("invalidFireworkFormat", args[1], args[0]));
|
||||
}
|
||||
stack.setItemMeta(fmeta);
|
||||
} else if ((args[0].equalsIgnoreCase("fire") || args[0].equalsIgnoreCase("f")) && user.isAuthorized("essentials.firework.fire")) {
|
||||
@@ -74,14 +75,14 @@ public class Commandfirework extends EssentialsCommand {
|
||||
amount = Integer.parseInt(args[1]);
|
||||
if (amount > serverLimit) {
|
||||
amount = serverLimit;
|
||||
user.sendTl("mobSpawnLimit");
|
||||
user.sendMessage(tl("mobSpawnLimit"));
|
||||
}
|
||||
} else {
|
||||
direction = true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < amount; i++) {
|
||||
final Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), MobCompat.FIREWORK_ROCKET);
|
||||
final Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
|
||||
final FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
|
||||
if (direction) {
|
||||
final Vector vector = user.getBase().getEyeLocation().getDirection().multiply(0.070);
|
||||
@@ -98,7 +99,7 @@ public class Commandfirework extends EssentialsCommand {
|
||||
try {
|
||||
mStack.addFireworkMeta(user.getSource(), true, arg, ess);
|
||||
} catch (final Exception e) {
|
||||
user.sendTl("fireworkSyntax");
|
||||
user.sendMessage(tl("fireworkSyntax"));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -107,13 +108,13 @@ public class Commandfirework extends EssentialsCommand {
|
||||
final FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta();
|
||||
final FireworkEffect effect = mStack.getFireworkBuilder().build();
|
||||
if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) {
|
||||
throw new TranslatableException("multipleCharges");
|
||||
throw new Exception(tl("multipleCharges"));
|
||||
}
|
||||
fmeta.addEffect(effect);
|
||||
stack.setItemMeta(fmeta);
|
||||
} else {
|
||||
user.sendTl("fireworkSyntax");
|
||||
throw new TranslatableException("fireworkColor");
|
||||
user.sendMessage(tl("fireworkSyntax"));
|
||||
throw new Exception(tl("fireworkColor"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.CommonPlaceholders;
|
||||
import net.ess3.api.events.FlyStatusChangeEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandfly extends EssentialsToggleCommand {
|
||||
public Commandfly() {
|
||||
super("fly", "essentials.fly.others");
|
||||
@@ -38,9 +39,9 @@ public class Commandfly extends EssentialsToggleCommand {
|
||||
user.getBase().setFlying(false);
|
||||
}
|
||||
|
||||
user.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), enabled), user.getDisplayName());
|
||||
user.sendMessage(tl("flyMode", tl(enabled ? "enabled" : "disabled"), user.getDisplayName()));
|
||||
if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) {
|
||||
sender.sendTl("flyMode", CommonPlaceholders.enableDisable(user.getSource(), enabled), user.getDisplayName());
|
||||
sender.sendMessage(tl("flyMode", tl(enabled ? "enabled" : "disabled"), user.getDisplayName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandgamemode extends EssentialsLoopCommand {
|
||||
private final List<String> STANDARD_OPTIONS = ImmutableList.of("creative", "survival", "adventure", "spectator", "toggle");
|
||||
|
||||
@@ -55,26 +57,26 @@ public class Commandgamemode extends EssentialsLoopCommand {
|
||||
}
|
||||
|
||||
if (isProhibitedChange(user, gameMode)) {
|
||||
user.sendTl("cantGamemode", user.playerTl(gameMode.toString().toLowerCase(Locale.ENGLISH)));
|
||||
user.sendMessage(tl("cantGamemode", gameMode.name()));
|
||||
return;
|
||||
}
|
||||
|
||||
user.getBase().setGameMode(gameMode);
|
||||
user.sendTl("gameMode", user.playerTl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName());
|
||||
user.sendMessage(tl("gameMode", tl(user.getBase().getGameMode().toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
|
||||
}
|
||||
|
||||
private void setUserGamemode(final CommandSource sender, final GameMode gameMode, final User user) throws NotEnoughArgumentsException {
|
||||
if (gameMode == null) {
|
||||
throw new NotEnoughArgumentsException(sender.tl("gameModeInvalid"));
|
||||
throw new NotEnoughArgumentsException(tl("gameModeInvalid"));
|
||||
}
|
||||
|
||||
if (sender.isPlayer() && isProhibitedChange(sender.getUser(), gameMode)) {
|
||||
sender.sendTl("cantGamemode", gameMode.name());
|
||||
if (sender.isPlayer() && isProhibitedChange(sender.getUser(ess), gameMode)) {
|
||||
sender.sendMessage(tl("cantGamemode", gameMode.name()));
|
||||
return;
|
||||
}
|
||||
|
||||
user.getBase().setGameMode(gameMode);
|
||||
sender.sendTl("gameMode", sender.tl(gameMode.toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName());
|
||||
sender.sendMessage(tl("gameMode", tl(gameMode.toString().toLowerCase(Locale.ENGLISH)), user.getDisplayName()));
|
||||
}
|
||||
|
||||
// essentials.gamemode will let them change to any but essentials.gamemode.survival would only let them change to survival.
|
||||
|
||||
@@ -12,6 +12,8 @@ import java.lang.management.ManagementFactory;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandgc extends EssentialsCommand {
|
||||
public Commandgc() {
|
||||
super("gc");
|
||||
@@ -29,11 +31,11 @@ public class Commandgc extends EssentialsCommand {
|
||||
color = ChatColor.RED;
|
||||
}
|
||||
|
||||
sender.sendTl("uptime", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime()));
|
||||
sender.sendTl("tps", "" + color + NumberUtil.formatDouble(tps));
|
||||
sender.sendTl("gcmax", Runtime.getRuntime().maxMemory() / 1024 / 1024);
|
||||
sender.sendTl("gctotal", Runtime.getRuntime().totalMemory() / 1024 / 1024);
|
||||
sender.sendTl("gcfree", Runtime.getRuntime().freeMemory() / 1024 / 1024);
|
||||
sender.sendMessage(tl("uptime", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime())));
|
||||
sender.sendMessage(tl("tps", "" + color + NumberUtil.formatDouble(tps)));
|
||||
sender.sendMessage(tl("gcmax", Runtime.getRuntime().maxMemory() / 1024 / 1024));
|
||||
sender.sendMessage(tl("gctotal", Runtime.getRuntime().totalMemory() / 1024 / 1024));
|
||||
sender.sendMessage(tl("gcfree", Runtime.getRuntime().freeMemory() / 1024 / 1024));
|
||||
|
||||
final List<World> worlds = server.getWorlds();
|
||||
for (final World w : worlds) {
|
||||
@@ -57,7 +59,7 @@ public class Commandgc extends EssentialsCommand {
|
||||
ess.getLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex);
|
||||
}
|
||||
|
||||
sender.sendTl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities);
|
||||
sender.sendMessage(tl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import org.bukkit.Server;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandgetpos extends EssentialsCommand {
|
||||
public Commandgetpos() {
|
||||
super("getpos");
|
||||
@@ -33,20 +35,20 @@ public class Commandgetpos extends EssentialsCommand {
|
||||
}
|
||||
|
||||
private void outputPosition(final CommandSource sender, final Location coords, final Location distance) {
|
||||
sender.sendTl("currentWorld", coords.getWorld().getName());
|
||||
sender.sendTl("posX", coords.getBlockX());
|
||||
sender.sendTl("posY", coords.getBlockY());
|
||||
sender.sendTl("posZ", coords.getBlockZ());
|
||||
sender.sendTl("posYaw", (coords.getYaw() + 360) % 360);
|
||||
sender.sendTl("posPitch", coords.getPitch());
|
||||
sender.sendMessage(tl("currentWorld", coords.getWorld().getName()));
|
||||
sender.sendMessage(tl("posX", coords.getBlockX()));
|
||||
sender.sendMessage(tl("posY", coords.getBlockY()));
|
||||
sender.sendMessage(tl("posZ", coords.getBlockZ()));
|
||||
sender.sendMessage(tl("posYaw", (coords.getYaw() + 360) % 360));
|
||||
sender.sendMessage(tl("posPitch", coords.getPitch()));
|
||||
if (distance != null && coords.getWorld().equals(distance.getWorld())) {
|
||||
sender.sendTl("distance", coords.distance(distance));
|
||||
sender.sendMessage(tl("distance", coords.distance(distance)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.getpos.others")) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.getpos.others", ess)) {
|
||||
return getPlayers(server, sender);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.earth2me.essentials.craftbukkit.Inventories;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
@@ -18,6 +17,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandgive extends EssentialsLoopCommand {
|
||||
public Commandgive() {
|
||||
super("give");
|
||||
@@ -33,7 +34,7 @@ public class Commandgive extends EssentialsLoopCommand {
|
||||
final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
|
||||
|
||||
if (sender.isPlayer() && !ess.getUser(sender.getPlayer()).canSpawnItem(stack.getType())) {
|
||||
throw new TranslatableException("cantSpawnItem", itemname);
|
||||
throw new Exception(tl("cantSpawnItem", itemname));
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -44,7 +45,7 @@ public class Commandgive extends EssentialsLoopCommand {
|
||||
stack.setAmount(Integer.parseInt(args[2]));
|
||||
} else if (ess.getSettings().getDefaultStackSize() > 0) {
|
||||
stack.setAmount(ess.getSettings().getDefaultStackSize());
|
||||
} else if (ess.getSettings().getOversizedStackSize() > 0 && sender.isAuthorized("essentials.oversizedstacks")) {
|
||||
} else if (ess.getSettings().getOversizedStackSize() > 0 && sender.isAuthorized("essentials.oversizedstacks", ess)) {
|
||||
stack.setAmount(ess.getSettings().getOversizedStackSize());
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
@@ -53,7 +54,7 @@ public class Commandgive extends EssentialsLoopCommand {
|
||||
|
||||
final MetaItemStack metaStack = new MetaItemStack(stack);
|
||||
if (!metaStack.canSpawn(ess)) {
|
||||
throw new TranslatableException("unableToSpawnItem", itemname);
|
||||
throw new Exception(tl("unableToSpawnItem", itemname));
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
@@ -72,14 +73,14 @@ public class Commandgive extends EssentialsLoopCommand {
|
||||
}
|
||||
|
||||
if (stack.getType() == Material.AIR) {
|
||||
throw new TranslatableException("cantSpawnItem", "Air");
|
||||
throw new Exception(tl("cantSpawnItem", "Air"));
|
||||
}
|
||||
|
||||
final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
|
||||
final boolean isDropItemsIfFull = ess.getSettings().isDropItemsIfFull();
|
||||
final ItemStack finalStack = stack;
|
||||
loopOnlinePlayersConsumer(server, sender, false, true, args[0], player -> {
|
||||
sender.sendTl("giveSpawn", finalStack.getAmount(), itemName, player.getDisplayName());
|
||||
sender.sendMessage(tl("giveSpawn", finalStack.getAmount(), itemName, player.getDisplayName()));
|
||||
|
||||
final Map<Integer, ItemStack> leftovers = Inventories.addItem(player.getBase(), player.isAuthorized("essentials.oversizedstacks") ? ess.getSettings().getOversizedStackSize() : 0, finalStack);
|
||||
|
||||
@@ -88,7 +89,7 @@ public class Commandgive extends EssentialsLoopCommand {
|
||||
final World w = player.getWorld();
|
||||
w.dropItemNaturally(player.getLocation(), item);
|
||||
} else {
|
||||
sender.sendTl("giveSpawnFailure", item.getAmount(), itemName, player.getDisplayName());
|
||||
sender.sendMessage(tl("giveSpawnFailure", item.getAmount(), itemName, player.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.CommonPlaceholders;
|
||||
import net.ess3.api.events.GodStatusChangeEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandgod extends EssentialsToggleCommand {
|
||||
public Commandgod() {
|
||||
super("god", "essentials.god.others");
|
||||
@@ -37,9 +38,9 @@ public class Commandgod extends EssentialsToggleCommand {
|
||||
user.getBase().setFoodLevel(20);
|
||||
}
|
||||
|
||||
user.sendTl("godMode", CommonPlaceholders.enableDisable(user.getSource(), enabled));
|
||||
user.sendMessage(tl("godMode", enabled ? tl("enabled") : tl("disabled")));
|
||||
if (!sender.isPlayer() || !sender.getPlayer().equals(user.getBase())) {
|
||||
sender.sendTl("godMode", CommonPlaceholders.enableDisable(user.getSource(), enabled));
|
||||
sender.sendMessage(tl("godMode", tl(enabled ? "godEnabledFor" : "godDisabledFor", user.getDisplayName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.User;
|
||||
import net.ess3.provider.ContainerProvider;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandgrindstone extends EssentialsCommand {
|
||||
|
||||
public Commandgrindstone() {
|
||||
@@ -12,13 +13,11 @@ public class Commandgrindstone extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
final ContainerProvider containerProvider = ess.provider(ContainerProvider.class);
|
||||
|
||||
if (containerProvider == null) {
|
||||
user.sendTl("unsupportedBrand");
|
||||
if (ess.getContainerProvider() == null) {
|
||||
user.sendMessage(tl("unsupportedBrand"));
|
||||
return;
|
||||
}
|
||||
|
||||
containerProvider.openGrindstone(user.getBase());
|
||||
ess.getContainerProvider().openGrindstone(user.getBase());
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandhat extends EssentialsCommand {
|
||||
|
||||
// The prefix for hat prevention commands
|
||||
@@ -28,45 +30,45 @@ public class Commandhat extends EssentialsCommand {
|
||||
if (args.length == 0 || (!args[0].contains("rem") && !args[0].contains("off") && !args[0].equalsIgnoreCase("0"))) {
|
||||
final ItemStack hand = Inventories.getItemInMainHand(user.getBase());
|
||||
if (hand == null || hand.getType() == Material.AIR) {
|
||||
user.sendTl("hatFail");
|
||||
user.sendMessage(tl("hatFail"));
|
||||
return;
|
||||
}
|
||||
|
||||
final TriState wildcard = user.isAuthorizedExact(PERM_PREFIX + "*");
|
||||
final TriState material = user.isAuthorizedExact(PERM_PREFIX + hand.getType().name().toLowerCase());
|
||||
if ((wildcard == TriState.TRUE && material != TriState.FALSE) || ((wildcard != TriState.TRUE) && material == TriState.TRUE)) {
|
||||
user.sendTl("hatFail");
|
||||
user.sendMessage(tl("hatFail"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (hand.getType().getMaxDurability() != 0) {
|
||||
user.sendTl("hatArmor");
|
||||
user.sendMessage(tl("hatArmor"));
|
||||
return;
|
||||
}
|
||||
|
||||
final PlayerInventory inv = user.getBase().getInventory();
|
||||
final ItemStack head = inv.getHelmet();
|
||||
if (VersionUtil.getServerBukkitVersion().isHigherThan(VersionUtil.v1_9_4_R01) && head != null && head.getEnchantments().containsKey(Enchantment.BINDING_CURSE) && !user.isAuthorized("essentials.hat.ignore-binding")) {
|
||||
user.sendTl("hatCurse");
|
||||
user.sendMessage(tl("hatCurse"));
|
||||
return;
|
||||
}
|
||||
inv.setHelmet(hand);
|
||||
Inventories.setItemInMainHand(user.getBase(), head);
|
||||
user.sendTl("hatPlaced");
|
||||
user.sendMessage(tl("hatPlaced"));
|
||||
return;
|
||||
}
|
||||
|
||||
final PlayerInventory inv = user.getBase().getInventory();
|
||||
final ItemStack head = inv.getHelmet();
|
||||
if (head == null || head.getType() == Material.AIR) {
|
||||
user.sendTl("hatEmpty");
|
||||
user.sendMessage(tl("hatEmpty"));
|
||||
} else if (VersionUtil.getServerBukkitVersion().isHigherThan(VersionUtil.v1_9_4_R01) && head.getEnchantments().containsKey(Enchantment.BINDING_CURSE) && !user.isAuthorized("essentials.hat.ignore-binding")) {
|
||||
user.sendTl("hatCurse");
|
||||
user.sendMessage(tl("hatCurse"));
|
||||
} else {
|
||||
final ItemStack air = new ItemStack(Material.AIR);
|
||||
inv.setHelmet(air);
|
||||
Inventories.addItem(user.getBase(), head);
|
||||
user.sendTl("hatRemoved");
|
||||
user.sendMessage(tl("hatRemoved"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.bukkit.potion.PotionEffect;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandheal extends EssentialsLoopCommand {
|
||||
public Commandheal() {
|
||||
super("heal");
|
||||
@@ -45,7 +47,7 @@ public class Commandheal extends EssentialsLoopCommand {
|
||||
final Player player = user.getBase();
|
||||
|
||||
if (player.getHealth() == 0) {
|
||||
throw new PlayerExemptException("healDead");
|
||||
throw new PlayerExemptException(tl("healDead"));
|
||||
}
|
||||
|
||||
final double amount = player.getMaxHealth() - player.getHealth();
|
||||
@@ -63,13 +65,13 @@ public class Commandheal extends EssentialsLoopCommand {
|
||||
player.setHealth(newAmount);
|
||||
player.setFoodLevel(20);
|
||||
player.setFireTicks(0);
|
||||
user.sendTl("heal");
|
||||
user.sendMessage(tl("heal"));
|
||||
if (ess.getSettings().isRemovingEffectsOnHeal()) {
|
||||
for (final PotionEffect effect : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
sender.sendTl("healOther", user.getDisplayName());
|
||||
sender.sendMessage(tl("healOther", user.getDisplayName()));
|
||||
} catch (final QuietAbortException e) {
|
||||
//Handle Quietly
|
||||
}
|
||||
@@ -77,7 +79,7 @@ public class Commandheal extends EssentialsLoopCommand {
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.heal.others")) {
|
||||
if (args.length == 1 && sender.isAuthorized("essentials.heal.others", ess)) {
|
||||
return getPlayers(server, sender);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -7,9 +7,7 @@ import com.earth2me.essentials.textreader.IText;
|
||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||
import com.earth2me.essentials.textreader.TextInput;
|
||||
import com.earth2me.essentials.textreader.TextPager;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import net.ess3.provider.KnownCommandsProvider;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
@@ -19,7 +17,8 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandhelp extends EssentialsCommand {
|
||||
public Commandhelp() {
|
||||
@@ -37,27 +36,20 @@ public class Commandhelp extends EssentialsCommand {
|
||||
if (input.getLines().isEmpty()) {
|
||||
if (pageStr != null && pageStr.startsWith("/")) {
|
||||
final String cmd = pageStr.substring(1);
|
||||
for (final Map.Entry<String, Command> knownCmd : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
|
||||
for (final Map.Entry<String, Command> knownCmd : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
|
||||
if (knownCmd.getKey().equalsIgnoreCase(cmd)) {
|
||||
final Command bukkit = knownCmd.getValue();
|
||||
final boolean isEssCommand = bukkit instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) bukkit).getPlugin().equals(ess);
|
||||
final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(bukkit.getName()) : null;
|
||||
user.sendTl("commandHelpLine1", cmd);
|
||||
String description = bukkit.getDescription();
|
||||
if (essCommand != null) {
|
||||
try {
|
||||
description = user.playerTl(bukkit.getName() + "CommandDescription");
|
||||
} catch (MissingResourceException ignored) {}
|
||||
}
|
||||
user.sendTl("commandHelpLine2", description);
|
||||
user.sendTl("commandHelpLine4", bukkit.getAliases().toString());
|
||||
user.sendTl("commandHelpLine3");
|
||||
user.sendMessage(tl("commandHelpLine1", cmd));
|
||||
user.sendMessage(tl("commandHelpLine2", knownCmd.getValue().getDescription()));
|
||||
user.sendMessage(tl("commandHelpLine4", knownCmd.getValue().getAliases().toString()));
|
||||
user.sendMessage(tl("commandHelpLine3"));
|
||||
final boolean isEssCommand = knownCmd.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) knownCmd.getValue()).getPlugin().equals(ess);
|
||||
final IEssentialsCommand essCommand = isEssCommand ? ess.getCommandMap().get(knownCmd.getValue().getName()) : null;
|
||||
if (essCommand != null && !essCommand.getUsageStrings().isEmpty()) {
|
||||
for (Map.Entry<String, String> usage : essCommand.getUsageStrings().entrySet()) {
|
||||
user.sendTl("commandHelpLineUsage", AdventureUtil.parsed(usage.getKey().replace("<command>", cmd)), AdventureUtil.parsed(usage.getValue()));
|
||||
user.sendMessage(tl("commandHelpLineUsage", usage.getKey().replace("<command>", cmd), usage.getValue()));
|
||||
}
|
||||
} else {
|
||||
user.sendMessage(bukkit.getUsage());
|
||||
user.sendMessage(knownCmd.getValue().getUsage());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -85,7 +77,7 @@ public class Commandhelp extends EssentialsCommand {
|
||||
|
||||
@Override
|
||||
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
sender.sendTl("helpConsole");
|
||||
sender.sendMessage(tl("helpConsole"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,19 +3,14 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.Console;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.messaging.IMessageRecipient;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.FormatUtil;
|
||||
import net.ess3.api.IUser;
|
||||
import net.essentialsx.api.v2.events.HelpopMessageSendEvent;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tlLiteral;
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandhelpop extends EssentialsCommand {
|
||||
public Commandhelpop() {
|
||||
@@ -25,40 +20,25 @@ public class Commandhelpop extends EssentialsCommand {
|
||||
@Override
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
||||
user.setDisplayNick();
|
||||
sendMessage(user, args);
|
||||
final String message = sendMessage(server, user.getDisplayName(), args);
|
||||
if (!user.isAuthorized("essentials.helpop.receive")) {
|
||||
user.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
||||
sendMessage(Console.getInstance(), args);
|
||||
sendMessage(server, Console.DISPLAY_NAME, args);
|
||||
}
|
||||
|
||||
private void sendMessage(final IMessageRecipient from, final String[] args) throws Exception {
|
||||
private String sendMessage(final Server server, final String from, final String[] args) throws Exception {
|
||||
if (args.length < 1) {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
|
||||
final String message = FormatUtil.stripFormat(getFinalArg(args, 0));
|
||||
ess.getLogger().log(Level.INFO, AdventureUtil.miniToLegacy(tlLiteral("helpOp", from.getDisplayName(), message)));
|
||||
|
||||
final List<IUser> recipients = new ArrayList<>();
|
||||
for (IUser user : ess.getOnlineUsers()) {
|
||||
if (user.getBase().hasPermission("essentials.helpop.receive")) {
|
||||
recipients.add(user);
|
||||
}
|
||||
}
|
||||
|
||||
final HelpopMessageSendEvent sendEvent = new HelpopMessageSendEvent(from, recipients, message);
|
||||
ess.getServer().getPluginManager().callEvent(sendEvent);
|
||||
|
||||
final IUser sender = (IUser) from;
|
||||
if(!recipients.contains(sender)){
|
||||
from.sendTl("helpOp", from.getDisplayName(), message);
|
||||
}
|
||||
|
||||
for (IUser recipient : sendEvent.getRecipients()) {
|
||||
recipient.sendTl("helpOp", from.getDisplayName(), message);
|
||||
}
|
||||
final String message = tl("helpOp", from, FormatUtil.stripFormat(getFinalArg(args, 0)));
|
||||
ess.getLogger().log(Level.INFO, message);
|
||||
ess.broadcastMessage("essentials.helpop.receive", message);
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.OfflinePlayerStub;
|
||||
import com.earth2me.essentials.OfflinePlayer;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.AdventureUtil;
|
||||
import com.earth2me.essentials.utils.StringUtil;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.ess3.api.TranslatableException;
|
||||
import net.ess3.api.events.UserTeleportHomeEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
@@ -17,6 +15,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.earth2me.essentials.I18n.tl;
|
||||
|
||||
public class Commandhome extends EssentialsCommand {
|
||||
public Commandhome() {
|
||||
super("home");
|
||||
@@ -42,8 +42,8 @@ public class Commandhome extends EssentialsCommand {
|
||||
}
|
||||
try {
|
||||
if ("bed".equalsIgnoreCase(homeName) && user.isAuthorized("essentials.home.bed")) {
|
||||
if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayerStub) {
|
||||
throw new TranslatableException("bedOffline");
|
||||
if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayer) {
|
||||
throw new Exception(tl("bedOffline"));
|
||||
}
|
||||
PaperLib.getBedSpawnLocationAsync(player.getBase(), true).thenAccept(location -> {
|
||||
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
||||
@@ -55,12 +55,12 @@ public class Commandhome extends EssentialsCommand {
|
||||
}
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
user.sendTl("teleportHome", "bed");
|
||||
user.sendMessage(tl("teleportHome", "bed"));
|
||||
}
|
||||
});
|
||||
user.getAsyncTeleport().teleport(location, charge, TeleportCause.COMMAND, future);
|
||||
} else {
|
||||
showError(user.getBase(), new TranslatableException("bedMissing"), commandLabel);
|
||||
showError(user.getBase(), new Exception(tl("bedMissing")), commandLabel);
|
||||
}
|
||||
});
|
||||
throw new NoChargeException();
|
||||
@@ -79,10 +79,10 @@ public class Commandhome extends EssentialsCommand {
|
||||
user.getAsyncTeleport().respawn(charge, TeleportCause.COMMAND, getNewExceptionFuture(user.getSource(), commandLabel));
|
||||
}
|
||||
} else {
|
||||
showError(user.getBase(), new TranslatableException("noHomeSetPlayer"), commandLabel);
|
||||
showError(user.getBase(), new Exception(tl("noHomeSetPlayer")), commandLabel);
|
||||
}
|
||||
} else if (homes.isEmpty() || !finalPlayer.hasValidHomes()) {
|
||||
showError(user.getBase(), new TranslatableException("noHomeSetPlayer"), commandLabel);
|
||||
showError(user.getBase(), new Exception(tl("noHomeSetPlayer")), commandLabel);
|
||||
} else if (homes.size() == 1 && finalPlayer.equals(user)) {
|
||||
try {
|
||||
goHome(user, finalPlayer, homes.get(0), charge, getNewExceptionFuture(user.getSource(), commandLabel));
|
||||
@@ -93,15 +93,15 @@ public class Commandhome extends EssentialsCommand {
|
||||
final int count = homes.size();
|
||||
if (user.isAuthorized("essentials.home.bed")) {
|
||||
if (bed != null) {
|
||||
homes.add(user.playerTl("bed"));
|
||||
homes.add(tl("bed"));
|
||||
} else {
|
||||
homes.add(user.playerTl("bedNull"));
|
||||
homes.add(tl("bedNull"));
|
||||
}
|
||||
}
|
||||
user.sendTl("homes", AdventureUtil.parsed(StringUtil.joinList(homes)), count, getHomeLimit(finalPlayer));
|
||||
user.sendMessage(tl("homes", StringUtil.joinList(homes), count, getHomeLimit(finalPlayer)));
|
||||
}
|
||||
});
|
||||
if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayerStub) {
|
||||
if (!player.getBase().isOnline() || player.getBase() instanceof OfflinePlayer) {
|
||||
message.complete(null);
|
||||
return;
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class Commandhome extends EssentialsCommand {
|
||||
throw new NotEnoughArgumentsException();
|
||||
}
|
||||
if (user.getWorld() != loc.getWorld() && ess.getSettings().isWorldHomePermissions() && !user.isAuthorized("essentials.worlds." + loc.getWorld().getName())) {
|
||||
throw new TranslatableException("noPerm", "essentials.worlds." + loc.getWorld().getName());
|
||||
throw new Exception(tl("noPerm", "essentials.worlds." + loc.getWorld().getName()));
|
||||
}
|
||||
final UserTeleportHomeEvent event = new UserTeleportHomeEvent(user, home, loc, UserTeleportHomeEvent.HomeType.HOME);
|
||||
user.getServer().getPluginManager().callEvent(event);
|
||||
@@ -137,7 +137,7 @@ public class Commandhome extends EssentialsCommand {
|
||||
user.getAsyncTeleport().teleport(loc, charge, TeleportCause.COMMAND, future);
|
||||
future.thenAccept(success -> {
|
||||
if (success) {
|
||||
user.sendTl("teleportHome", home);
|
||||
user.sendMessage(tl("teleportHome", home));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loaded 100 of 477 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user