Keep player names, so they don't have to be looked up again.

That way the lookup function MainUtil#getName won't get called which would throw an exception if called in the Bukkit Thread.
As the player enters the Name, we don't have to look it up again.

Fixes PS-96
This commit is contained in:
EinDev 2020-08-08 18:07:49 +02:00
parent c745b99922
commit b46a19f5ca
6 changed files with 88 additions and 86 deletions

View File

@ -35,11 +35,11 @@ import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.uuid.UUIDMapping;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -79,44 +79,49 @@ public class Add extends Command {
} else { } else {
try { try {
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]); checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
Iterator<UUID> iterator = uuids.iterator();
Iterator<UUIDMapping> iterator = uuids.iterator();
int size = plot.getTrusted().size() + plot.getMembers().size(); int size = plot.getTrusted().size() + plot.getMembers().size();
while (iterator.hasNext()) { while (iterator.hasNext()) {
UUID uuid = iterator.next(); UUIDMapping uuidMapping = iterator.next();
if (uuid == DBFunc.EVERYONE && !( if (uuidMapping.getUuid() == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) { .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.ALREADY_ADDED, uuidMapping.getUsername());
iterator.remove(); iterator.remove();
continue; continue;
} }
if (plot.isOwner(uuid)) { if (plot.isOwner(uuidMapping.getUuid())) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); new Thread(() ->
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, uuidMapping.getUsername())
).start();
iterator.remove(); iterator.remove();
continue; continue;
} }
if (plot.getMembers().contains(uuid)) { if (plot.getMembers().contains(uuidMapping.getUuid())) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); new Thread(() ->
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, uuidMapping.getUsername())
).start();
iterator.remove(); iterator.remove();
continue; continue;
} }
size += plot.getTrusted().contains(uuid) ? 0 : 1; size += plot.getTrusted().contains(uuidMapping.getUuid()) ? 0 : 1;
} }
checkTrue(!uuids.isEmpty(), null); checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= plot.getArea().getMaxPlotMembers() || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST), checkTrue(size <= plot.getArea().getMaxPlotMembers() || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
Captions.PLOT_MAX_MEMBERS); Captions.PLOT_MAX_MEMBERS);
// Success // Success
confirm.run(this, () -> { confirm.run(this, () -> {
for (UUID uuid : uuids) { for (UUIDMapping uuidMapping : uuids) {
if (uuid != DBFunc.EVERYONE) { if (uuidMapping.getUuid() != DBFunc.EVERYONE) {
if (!plot.removeTrusted(uuid)) { if (!plot.removeTrusted(uuidMapping.getUuid())) {
if (plot.getDenied().contains(uuid)) { if (plot.getDenied().contains(uuidMapping.getUuid())) {
plot.removeDenied(uuid); plot.removeDenied(uuidMapping.getUuid());
} }
} }
} }
plot.addMember(uuid); plot.addMember(uuidMapping.getUuid());
PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true); PlotSquared.get().getEventDispatcher().callMember(player, plot, uuidMapping.getUuid(), true);
MainUtil.sendMessage(player, Captions.MEMBER_ADDED); MainUtil.sendMessage(player, Captions.MEMBER_ADDED);
} }
}, null); }, null);

View File

@ -35,11 +35,11 @@ import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.uuid.UUIDMapping;
import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.gamemode.GameModes;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "deny", @CommandDeclaration(command = "deny",
@ -77,26 +77,26 @@ public class Deny extends SubCommand {
} else if (throwable != null || uuids.isEmpty()) { } else if (throwable != null || uuids.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]); MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else { } else {
for (UUID uuid : uuids) { for (UUIDMapping uuidMapping : uuids) {
if (uuid == DBFunc.EVERYONE && !( if (uuidMapping.getUuid() == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) { .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.INVALID_PLAYER, uuidMapping.getUsername());
} else if (plot.isOwner(uuid)) { } else if (plot.isOwner(uuidMapping.getUuid())) {
MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, uuidMapping.getUsername());
return; return;
} else if (plot.getDenied().contains(uuid)) { } else if (plot.getDenied().contains(uuidMapping.getUuid())) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.ALREADY_ADDED, uuidMapping.getUsername());
return; return;
} else { } else {
if (uuid != DBFunc.EVERYONE) { if (uuidMapping.getUuid() != DBFunc.EVERYONE) {
plot.removeMember(uuid); plot.removeMember(uuidMapping.getUuid());
plot.removeTrusted(uuid); plot.removeTrusted(uuidMapping.getUuid());
} }
plot.addDenied(uuid); plot.addDenied(uuidMapping.getUuid());
PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true); PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuidMapping.getUuid(), true);
if (!uuid.equals(DBFunc.EVERYONE)) { if (!uuidMapping.equals(DBFunc.EVERYONE)) {
handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid), plot); handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid()), plot);
} else { } else {
for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) { for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
// Ignore plot-owners // Ignore plot-owners

View File

@ -35,12 +35,12 @@ import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.uuid.UUIDMapping;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "kick", @CommandDeclaration(command = "kick",
@ -75,8 +75,8 @@ public class Kick extends SubCommand {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]); MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else { } else {
Set<PlotPlayer<?>> players = new HashSet<>(); Set<PlotPlayer<?>> players = new HashSet<>();
for (UUID uuid : uuids) { for (UUIDMapping uuidMapping : uuids) {
if (uuid == DBFunc.EVERYONE) { if (uuidMapping.getUuid() == DBFunc.EVERYONE) {
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) { for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
if (pp == player || Permissions if (pp == player || Permissions
.hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) { .hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
@ -86,7 +86,7 @@ public class Kick extends SubCommand {
} }
continue; continue;
} }
PlotPlayer<?> pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); PlotPlayer<?> pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
if (pp != null) { if (pp != null) {
players.add(pp); players.add(pp);
} }

View File

@ -34,10 +34,10 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.uuid.UUIDMapping;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "remove", @CommandDeclaration(command = "remove",
@ -78,37 +78,37 @@ public class Remove extends SubCommand {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]); MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return; return;
} else if (!uuids.isEmpty()) { } else if (!uuids.isEmpty()) {
for (UUID uuid : uuids) { for (UUIDMapping uuidMapping : uuids) {
if (plot.getTrusted().contains(uuid)) { if (plot.getTrusted().contains(uuidMapping.getUuid())) {
if (plot.removeTrusted(uuid)) { if (plot.removeTrusted(uuidMapping.getUuid())) {
PlotSquared.get().getEventDispatcher() PlotSquared.get().getEventDispatcher()
.callTrusted(player, plot, uuid, false); .callTrusted(player, plot, uuidMapping.getUuid(), false);
count++; count++;
} }
} else if (plot.getMembers().contains(uuid)) { } else if (plot.getMembers().contains(uuidMapping.getUuid())) {
if (plot.removeMember(uuid)) { if (plot.removeMember(uuidMapping.getUuid())) {
PlotSquared.get().getEventDispatcher() PlotSquared.get().getEventDispatcher()
.callMember(player, plot, uuid, false); .callMember(player, plot, uuidMapping.getUuid(), false);
count++; count++;
} }
} else if (plot.getDenied().contains(uuid)) { } else if (plot.getDenied().contains(uuidMapping.getUuid())) {
if (plot.removeDenied(uuid)) { if (plot.removeDenied(uuidMapping.getUuid())) {
PlotSquared.get().getEventDispatcher() PlotSquared.get().getEventDispatcher()
.callDenied(player, plot, uuid, false); .callDenied(player, plot, uuidMapping.getUuid(), false);
count++; count++;
} }
} else if (uuid == DBFunc.EVERYONE) { } else if (uuidMapping.getUuid() == DBFunc.EVERYONE) {
if (plot.removeTrusted(uuid)) { if (plot.removeTrusted(uuidMapping.getUuid())) {
PlotSquared.get().getEventDispatcher() PlotSquared.get().getEventDispatcher()
.callTrusted(player, plot, uuid, false); .callTrusted(player, plot, uuidMapping.getUuid(), false);
count++; count++;
} else if (plot.removeMember(uuid)) { } else if (plot.removeMember(uuidMapping.getUuid())) {
PlotSquared.get().getEventDispatcher() PlotSquared.get().getEventDispatcher()
.callMember(player, plot, uuid, false); .callMember(player, plot, uuidMapping.getUuid(), false);
count++; count++;
} else if (plot.removeDenied(uuid)) { } else if (plot.removeDenied(uuidMapping.getUuid())) {
PlotSquared.get().getEventDispatcher() PlotSquared.get().getEventDispatcher()
.callDenied(player, plot, uuid, false); .callDenied(player, plot, uuidMapping.getUuid(), false);
count++; count++;
} }
} }

View File

@ -35,11 +35,11 @@ import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.uuid.UUIDMapping;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -81,28 +81,28 @@ public class Trust extends Command {
return; return;
} else { } else {
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]); checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
Iterator<UUID> iterator = uuids.iterator(); Iterator<UUIDMapping> iterator = uuids.iterator();
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size(); int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
while (iterator.hasNext()) { while (iterator.hasNext()) {
UUID uuid = iterator.next(); UUIDMapping uuidMapping = iterator.next();
if (uuid == DBFunc.EVERYONE && !( if (uuidMapping.getUuid() == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) { .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.INVALID_PLAYER, uuidMapping.getUsername());
iterator.remove(); iterator.remove();
continue; continue;
} }
if (currentPlot.isOwner(uuid)) { if (currentPlot.isOwner(uuidMapping.getUuid())) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.ALREADY_ADDED, uuidMapping.getUsername());
iterator.remove(); iterator.remove();
continue; continue;
} }
if (currentPlot.getTrusted().contains(uuid)) { if (currentPlot.getTrusted().contains(uuidMapping.getUuid())) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid)); MainUtil.sendMessage(player, Captions.ALREADY_ADDED, uuidMapping.getUsername());
iterator.remove(); iterator.remove();
continue; continue;
} }
size += currentPlot.getMembers().contains(uuid) ? 0 : 1; size += currentPlot.getMembers().contains(uuidMapping.getUuid()) ? 0 : 1;
} }
checkTrue(!uuids.isEmpty(), null); checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= currentPlot.getArea().getMaxPlotMembers() || Permissions checkTrue(size <= currentPlot.getArea().getMaxPlotMembers() || Permissions
@ -110,16 +110,16 @@ public class Trust extends Command {
Captions.PLOT_MAX_MEMBERS); Captions.PLOT_MAX_MEMBERS);
// Success // Success
confirm.run(this, () -> { confirm.run(this, () -> {
for (UUID uuid : uuids) { for (UUIDMapping uuidMapping : uuids) {
if (uuid != DBFunc.EVERYONE) { if (uuidMapping.getUuid() != DBFunc.EVERYONE) {
if (!currentPlot.removeMember(uuid)) { if (!currentPlot.removeMember(uuidMapping.getUuid())) {
if (currentPlot.getDenied().contains(uuid)) { if (currentPlot.getDenied().contains(uuidMapping.getUuid())) {
currentPlot.removeDenied(uuid); currentPlot.removeDenied(uuidMapping.getUuid());
} }
} }
} }
currentPlot.addTrusted(uuid); currentPlot.addTrusted(uuidMapping.getUuid());
PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuid, true); PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuidMapping.getUuid(), true);
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED); MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
} }
}, null); }, null);

View File

@ -748,10 +748,9 @@ public class MainUtil {
return ratings; return ratings;
} }
public static void getUUIDsFromString(final String list, final BiConsumer<Collection<UUID>, Throwable> consumer) { public static void getUUIDsFromString(final String list, final BiConsumer<Collection<UUIDMapping>, Throwable> consumer) {
String[] split = list.split(","); String[] split = list.split(",");
final Set<UUIDMapping> result = new HashSet<>();
final Set<UUID> result = new HashSet<>();
final List<String> request = new LinkedList<>(); final List<String> request = new LinkedList<>();
for (final String name : split) { for (final String name : split) {
@ -759,10 +758,10 @@ public class MainUtil {
consumer.accept(Collections.emptySet(), null); consumer.accept(Collections.emptySet(), null);
return; return;
} else if ("*".equals(name)) { } else if ("*".equals(name)) {
result.add(DBFunc.EVERYONE); result.add(new UUIDMapping(DBFunc.EVERYONE, "*"));
} else if (name.length() > 16) { } else if (name.length() > 16) {
try { try {
result.add(UUID.fromString(name)); result.add(new UUIDMapping(UUID.fromString(name), name));
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
consumer.accept(Collections.emptySet(), null); consumer.accept(Collections.emptySet(), null);
return; return;
@ -780,9 +779,7 @@ public class MainUtil {
if (throwable != null) { if (throwable != null) {
consumer.accept(null, throwable); consumer.accept(null, throwable);
} else { } else {
for (final UUIDMapping uuid : uuids) { result.addAll(uuids);
result.add(uuid.getUuid());
}
consumer.accept(result, null); consumer.accept(result, null);
} }
}); });