Merge branch '2.x' into rework/providers

This commit is contained in:
Josh Roy 2022-11-08 11:56:37 -05:00 committed by GitHub
commit 02b6b1b481
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 102 additions and 23 deletions

View File

@ -203,6 +203,10 @@ public class Jails implements net.ess3.api.IJails {
private class JailListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onJailBlockBreak(final BlockBreakEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (user.isJailed() && !user.isAuthorized("essentials.jail.allow-break")) {
event.setCancelled(true);
@ -211,6 +215,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onJailBlockPlace(final BlockPlaceEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (user.isJailed() && !user.isAuthorized("essentials.jail.allow-place")) {
event.setCancelled(true);
@ -219,6 +227,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onJailBlockDamage(final BlockDamageEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (user.isJailed() && !user.isAuthorized("essentials.jail.allow-block-damage")) {
event.setCancelled(true);
@ -232,6 +244,9 @@ public class Jails implements net.ess3.api.IJails {
}
final Entity damager = event.getDamager();
if (damager.getType() == EntityType.PLAYER) {
if (shouldIgnore((Player) damager)) {
return;
}
final User user = ess.getUser((Player) damager);
if (user != null && user.isJailed()) {
event.setCancelled(true);
@ -241,6 +256,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onJailPlayerInteract(final PlayerInteractEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (user.isJailed() && !user.isAuthorized("essentials.jail.allow-interact")) {
event.setCancelled(true);
@ -249,6 +268,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onJailPlayerGameModeChange(final PlayerGameModeChangeEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (user.isJailed()) {
event.setCancelled(true);
@ -257,6 +280,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.HIGHEST)
public void onJailPlayerRespawn(final PlayerRespawnEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty()) {
return;
@ -275,6 +302,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.HIGH)
public void onJailPlayerTeleport(final PlayerTeleportEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
if (!user.isJailed() || user.getJail() == null || user.getJail().isEmpty()) {
return;
@ -294,6 +325,10 @@ public class Jails implements net.ess3.api.IJails {
@EventHandler(priority = EventPriority.HIGHEST)
public void onJailPlayerJoin(final PlayerJoinEvent event) {
if (shouldIgnore(event.getPlayer())) {
return;
}
final User user = ess.getUser(event.getPlayer());
final long currentTime = System.currentTimeMillis();
user.checkJailTimeout(currentTime);
@ -318,5 +353,10 @@ public class Jails implements net.ess3.api.IJails {
future.completeExceptionally(ex);
}
}
private boolean shouldIgnore(final Player base) {
// Ignore Citizens NPCs
return base.getUniqueId().version() == 2 || base.hasMetadata("NPC");
}
}
}

View File

@ -4,15 +4,17 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.UUID;
public class PlayerTarget implements ITarget {
private final String name;
private final UUID uuid;
public PlayerTarget(final Player entity) {
this.name = entity.getName();
this.uuid = entity.getUniqueId();
}
@Override
public Location getLocation() {
return Bukkit.getServer().getPlayerExact(name).getLocation();
return Bukkit.getPlayer(uuid).getLocation();
}
}

View File

@ -464,7 +464,11 @@ public class User extends UserData implements Comparable<User>, IMessageRecipien
} else if (nick.equalsIgnoreCase(getName())) {
nickname = nick;
} else {
nickname = FormatUtil.replaceFormat(ess.getSettings().getNicknamePrefix()) + nick;
if (isAuthorized("essentials.nick.hideprefix")) {
nickname = nick;
} else {
nickname = FormatUtil.replaceFormat(ess.getSettings().getNicknamePrefix()) + nick;
}
suffix = "§r";
}

View File

@ -298,9 +298,21 @@ public class Commandmail extends EssentialsCommand {
if (pages == 0) {
return Lists.newArrayList("0");
} else {
final List<String> options = Lists.newArrayList("1");
if (pages > 1) {
options.add(String.valueOf(pages));
final List<String> options = new ArrayList<>();
for (int i = 0; i < pages; i++) {
options.add(String.valueOf(i + 1));
}
return options;
}
} else if (args[0].equalsIgnoreCase("clear")) {
final ArrayList<MailMessage> mail = user.getMailMessages();
// We show up to 9 mails on a page, we don't need to autocomplete more than that...
if (mail.size() >= 9) {
return Lists.newArrayList("1", "2", "3", "4", "5", "6", "7", "8", "9");
} else {
final List<String> options = new ArrayList<>();
for (int i = 0; i < mail.size(); i++) {
options.add(String.valueOf(i + 1));
}
return options;
}

View File

@ -16,7 +16,6 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -42,7 +41,7 @@ public class ModernUUIDCache {
* caching the {@code last-account-name} value.
*/
private final ConcurrentHashMap<String, UUID> nameToUuidMap = new ConcurrentHashMap<>();
private final CopyOnWriteArraySet<UUID> uuidCache = new CopyOnWriteArraySet<>();
private final Set<UUID> uuidCache = ConcurrentHashMap.newKeySet();
private final ScheduledExecutorService writeExecutor = Executors.newSingleThreadScheduledExecutor();
private final AtomicBoolean pendingNameWrite = new AtomicBoolean(false);

View File

@ -27,9 +27,10 @@
ops-name-color: '4'
# The character(s) to prefix all nicknames, so that you know they are not true usernames.
# Users with essentials.nick.hideprefix will not be prefixed with the character(s)
nickname-prefix: '~'
# The maximum length allowed in nicknames. The nickname prefix is included in this.
# The maximum length allowed in nicknames. The nickname prefix is not included in this.
max-nick-length: 15
# A list of phrases that cannot be used in nicknames. You can include regular expressions here.
@ -160,7 +161,7 @@ notify-player-of-mail-cooldown: 60
#
# If you have two plugin with the same command and you wish to force Essentials to take over, you need an alias.
# To force essentials to take 'god' alias 'god' to 'egod'.
# See http://wiki.bukkit.org/Commands.yml#aliases for more information.
# See https://bukkit.fandom.com/wiki/Commands.yml#aliases for more information.
overridden-commands:
# - god
@ -168,7 +169,7 @@ overridden-commands:
# Disabling commands here will prevent Essentials handling the command, this will not affect command conflicts.
# You should not have to disable commands used in other plugins, they will automatically get priority.
# See http://wiki.bukkit.org/Commands.yml#aliases to map commands to other plugins.
# See https://bukkit.fandom.com/wiki/Commands.yml#aliases to map commands to other plugins.
disabled-commands:
# - nick
# - clear

View File

@ -709,3 +709,6 @@ permissions:
essentials.sudo.exempt: true
essentials.tempban.exempt: true
essentials.exempt.protect: true
essentials.nick.hideprefix:
default: false
description: Players with this permission will not have the nickname prefix applied to them

View File

@ -1,5 +1,6 @@
package net.essentialsx.api.v2.events.discord;
import net.ess3.api.IUser;
import net.essentialsx.api.v2.services.discord.InteractionChannel;
import net.essentialsx.api.v2.services.discord.InteractionMember;
import org.bukkit.Bukkit;
@ -23,6 +24,7 @@ public class DiscordRelayEvent extends Event implements Cancellable {
private final List<String> groupNames;
private final String rawMessage;
private String formattedMessage;
private final List<IUser> viewers;
private boolean cancelled = false;
/**
@ -31,14 +33,16 @@ public class DiscordRelayEvent extends Event implements Cancellable {
* @param groupNames The message type keys which will be used to determine which player group the message should be sent to.
* @param rawMessage The raw message sent from Discord.
* @param formattedMessage The formatted message that will be sent to Minecraft.
* @param viewers The users that will see this relayed message.
*/
public DiscordRelayEvent(final InteractionMember member, final InteractionChannel channel, final List<String> groupNames, final String rawMessage, final String formattedMessage) {
public DiscordRelayEvent(final InteractionMember member, final InteractionChannel channel, final List<String> groupNames, final String rawMessage, final String formattedMessage, final List<IUser> viewers) {
super(!Bukkit.isPrimaryThread());
this.member = member;
this.channel = channel;
this.groupNames = groupNames;
this.rawMessage = rawMessage;
this.formattedMessage = formattedMessage;
this.viewers = viewers;
}
/**
@ -89,6 +93,15 @@ public class DiscordRelayEvent extends Event implements Cancellable {
this.formattedMessage = formattedMessage;
}
/**
* Gets the users that will be sent the relayed message.
* The returned list is mutable. Removing a player from it will hide the message from them.
* @return The mutable list of users.
*/
public List<IUser> getViewers() {
return viewers;
}
@Override
public boolean isCancelled() {
return cancelled;

View File

@ -19,6 +19,7 @@ import net.essentialsx.discord.util.MessageUtil;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
@ -105,11 +106,22 @@ public class DiscordListener extends ListenerAdapter {
}
}
final List<IUser> viewers = new ArrayList<>();
for (final IUser essUser : plugin.getPlugin().getEss().getOnlineUsers()) {
for (final String group : keys) {
final String perm = "essentials.discord.receive." + group;
final boolean primaryOverride = plugin.getSettings().isAlwaysReceivePrimary() && group.equalsIgnoreCase("primary");
if (primaryOverride || (essUser.isPermissionSet(perm) && essUser.isAuthorized(perm))) {
viewers.add(essUser);
break;
}
}
}
// Do not create the event specific objects if there are no listeners
if (DiscordRelayEvent.getHandlerList().getRegisteredListeners().length != 0) {
final DiscordRelayEvent relayEvent = new DiscordRelayEvent(
new InteractionMemberImpl(member), new InteractionChannelImpl(event.getChannel()),
Collections.unmodifiableList(keys), event.getMessage().getContentRaw(), formattedMessage);
Collections.unmodifiableList(keys), event.getMessage().getContentRaw(), formattedMessage, viewers);
Bukkit.getPluginManager().callEvent(relayEvent);
if (relayEvent.isCancelled()) {
return;
@ -117,15 +129,8 @@ public class DiscordListener extends ListenerAdapter {
formattedMessage = relayEvent.getFormattedMessage();
}
for (IUser essUser : plugin.getPlugin().getEss().getOnlineUsers()) {
for (String group : keys) {
final String perm = "essentials.discord.receive." + group;
final boolean primaryOverride = plugin.getSettings().isAlwaysReceivePrimary() && group.equalsIgnoreCase("primary");
if (primaryOverride || (essUser.isPermissionSet(perm) && essUser.isAuthorized(perm))) {
essUser.sendMessage(formattedMessage);
break;
}
}
for (final IUser essUser : viewers) {
essUser.sendMessage(formattedMessage);
}
}
}