Skip to content

Commit

Permalink
Merge branch '2.x' into randomteleport-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pop4959 committed Feb 13, 2022
2 parents e4e1bbb + 19837f9 commit 26ff6ec
Show file tree
Hide file tree
Showing 33 changed files with 2,147 additions and 240 deletions.
8 changes: 4 additions & 4 deletions Essentials/src/main/java/com/earth2me/essentials/IUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ public interface IUser {
* period are removed from queue and therefore not returned here. The maximum size of this
* queue is determined by {@link ISettings#getTpaMaxRequests()}.
*
* @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration.
* @param performExpirations true if this method should not spend time validating time for all items in the queue and just return the first item in the queue.
* @param excludeHere true if /tphere requests should be ignored in fetching the next tpa request.
* @param inform true if the underlying {@link IUser} should be informed if a request expires during iteration.
* @param ignoreExpirations true if this method should not process expirations for the entire queue and stop execution on the first unexpired request.
* @param excludeHere true if /tphere requests should be ignored in fetching the next tpa request.
* @return A {@link TpaRequest} corresponding to the next available request or null if no valid request is present.
*/
@Nullable TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, boolean excludeHere);
@Nullable TpaRequest getNextTpaRequest(boolean inform, boolean ignoreExpirations, boolean excludeHere);

/**
* Whether or not this {@link IUser} has any valid TPA requests in queue.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,8 @@ private boolean isValidRandomLocation(final Location location) {
private String locationKey(final String name, final String key) {
return "locations." + name + "." + key;
}

public File getFile() {
return config.getFile();
}
}
24 changes: 12 additions & 12 deletions Essentials/src/main/java/com/earth2me/essentials/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
import org.checkerframework.checker.nullness.qual.Nullable;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -349,11 +350,8 @@ public void requestTeleport(final User player, final boolean here) {
// Handle max queue size
teleportRequestQueue.remove(request.getName());
if (teleportRequestQueue.size() >= ess.getSettings().getTpaMaxRequests()) {
String lastKey = null;
for (Map.Entry<String, TpaRequest> entry : teleportRequestQueue.entrySet()) {
lastKey = entry.getKey();
}
teleportRequestQueue.remove(lastKey);
final List<String> keys = new ArrayList<>(teleportRequestQueue.keySet());
teleportRequestQueue.remove(keys.get(keys.size() - 1));
}

// Add request to queue
Expand Down Expand Up @@ -402,22 +400,24 @@ public TpaRequest removeTpaRequest(String playerUsername) {
}

@Override
public TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations, boolean excludeHere) {
public TpaRequest getNextTpaRequest(boolean inform, boolean ignoreExpirations, boolean excludeHere) {
if (teleportRequestQueue.isEmpty()) {
return null;
}

final long timeout = ess.getSettings().getTpaAcceptCancellation();
final Iterator<Map.Entry<String, TpaRequest>> iterator = teleportRequestQueue.entrySet().iterator();
final List<String> keys = new ArrayList<>(teleportRequestQueue.keySet());
Collections.reverse(keys);

TpaRequest nextRequest = null;
while (iterator.hasNext()) {
final TpaRequest request = iterator.next().getValue();
for (final String key : keys) {
final TpaRequest request = teleportRequestQueue.get(key);
if (timeout < 1 || (System.currentTimeMillis() - request.getTime()) <= TimeUnit.SECONDS.toMillis(timeout)) {
if (excludeHere && request.isHere()) {
continue;
}

if (performExpirations) {
if (ignoreExpirations) {
return request;
} else if (nextRequest == null) {
nextRequest = request;
Expand All @@ -426,7 +426,7 @@ public TpaRequest getNextTpaRequest(boolean inform, boolean performExpirations,
if (inform) {
sendMessage(tl("requestTimedOutFrom", ess.getUser(request.getRequesterUuid()).getDisplayName()));
}
iterator.remove();
teleportRequestQueue.remove(key);
}
}
return nextRequest;
Expand Down
4 changes: 4 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Worth.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public void setPrice(final IEssentials ess, final ItemStack itemStack, final dou
config.save();
}

public File getFile() {
return config.getFile();
}

@Override
public void reloadConfig() {
config.load();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,26 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S
files.add(new PasteUtil.PasteFile("dump.json", dump.toString()));

final Plugin essDiscord = Bukkit.getPluginManager().getPlugin("EssentialsDiscord");
final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn");

// Further operations will be heavy IO
ess.runTaskAsynchronously(() -> {
boolean config = false;
boolean discord = false;
boolean kits = false;
boolean log = false;
boolean worth = false;
boolean tpr = false;
boolean spawns = false;
for (final String arg : args) {
if (arg.equals("*") || arg.equalsIgnoreCase("all")) {
config = true;
discord = true;
kits = true;
log = true;
worth = true;
tpr = true;
spawns = true;
break;
} else if (arg.equalsIgnoreCase("config")) {
config = true;
Expand All @@ -280,6 +287,12 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S
kits = true;
} else if (arg.equalsIgnoreCase("log")) {
log = true;
} else if (arg.equalsIgnoreCase("worth")) {
worth = true;
} else if (arg.equalsIgnoreCase("tpr")) {
tpr = true;
} else if (arg.equalsIgnoreCase("spawns")) {
spawns = true;
}
}

Expand Down Expand Up @@ -319,6 +332,30 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S
}
}

if (worth) {
try {
files.add(new PasteUtil.PasteFile("worth.yml", new String(Files.readAllBytes(ess.getWorth().getFile().toPath()), StandardCharsets.UTF_8)));
} catch (IOException e) {
sender.sendMessage(tl("dumpErrorUpload", "worth.yml", e.getMessage()));
}
}

if (tpr) {
try {
files.add(new PasteUtil.PasteFile("tpr.yml", new String(Files.readAllBytes(ess.getRandomTeleport().getFile().toPath()), StandardCharsets.UTF_8)));
} catch (IOException e) {
sender.sendMessage(tl("dumpErrorUpload", "tpr.yml", e.getMessage()));
}
}

if (spawns && essSpawn != null) {
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.sendMessage(tl("dumpErrorUpload", "spawn.yml", e.getMessage()));
}
}

final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
future.thenAccept(result -> {
if (result != null) {
Expand Down Expand Up @@ -719,7 +756,7 @@ protected List<String> getTabCompleteOptions(final Server server, final CommandS
}
break;
case "dump":
final List<String> list = Lists.newArrayList("config", "kits", "log", "discord", "all");
final List<String> list = Lists.newArrayList("config", "kits", "log", "discord", "worth", "tpr", "spawns", "all");
for (String arg : args) {
if (arg.equals("*") || arg.equalsIgnoreCase("all")) {
list.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
Expand Down Expand Up @@ -109,7 +108,7 @@ private String getLocal(final User user, final long radius) {
if (nearbyPlayer == null) {
continue;
}
output.append(nearbyPlayer.getDisplayName()).append(ChatColor.WHITE + "(" + ChatColor.RED).append((long) nearbyPlayer.getLocation().distance(loc)).append("m" + ChatColor.WHITE + ")");
output.append(tl("nearbyPlayersList", nearbyPlayer.getDisplayName(), (long)nearbyPlayer.getLocation().distance(loc)));
}

return output.length() > 1 ? output.toString() : tl("none");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public void run(final Server server, final User user, final String commandLabel,
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
if (!ess.getSettings().changeDisplayName()) {
throw new Exception(tl("nickDisplayName"));
}

if (args.length > 1 && user.isAuthorized("essentials.nick.others")) {
loopOfflinePlayers(server, user.getSource(), false, true, args[0], formatNickname(user, args[1]).split(" "));
Expand All @@ -41,9 +38,6 @@ public void run(final Server server, final CommandSource sender, final String co
if (args.length < 2) {
throw new NotEnoughArgumentsException();
}
if (!ess.getSettings().changeDisplayName()) {
throw new Exception(tl("nickDisplayName"));
}
loopOfflinePlayers(server, sender, false, true, args[0], formatNickname(null, args[1]).split(" "));
sender.sendMessage(tl("nickChanged"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public void run(final Server server, final User user, final String commandLabel,
throw new NotEnoughArgumentsException();
}

final double x = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Integer.parseInt(args[0].substring(1)) : 0) : Integer.parseInt(args[0]);
final double y = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Integer.parseInt(args[1].substring(1)) : 0) : Integer.parseInt(args[1]);
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Integer.parseInt(args[2].substring(1)) : 0) : Integer.parseInt(args[2]);
final double x = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Double.parseDouble(args[0].substring(1)) : 0) : Double.parseDouble(args[0]);
final double y = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Double.parseDouble(args[1].substring(1)) : 0) : Double.parseDouble(args[1]);
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Double.parseDouble(args[2].substring(1)) : 0) : Double.parseDouble(args[2]);
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
if (args.length == 4) {
final World w = ess.getWorld(args[3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ public CompletableFuture<RemoteVersion> fetchLatestRelease() {
// Locally built?
pendingReleaseFuture.complete(cachedRelease = new RemoteVersion(BranchStatus.UNKNOWN));
break catchBlock;
}
if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
// Github is down
} else if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR || connection.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
// GitHub is down or rate limit exceeded
pendingReleaseFuture.complete(new RemoteVersion(BranchStatus.ERROR));
break catchBlock;
}
Expand Down Expand Up @@ -146,8 +145,7 @@ private RemoteVersion fetchDistance(final String head, final String hash) {
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
// Locally built?
return new RemoteVersion(BranchStatus.UNKNOWN);
}
if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR || connection.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
} else if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR || connection.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
// GitHub is down or we hit a local rate limit
return new RemoteVersion(BranchStatus.ERROR);
}
Expand Down
1 change: 1 addition & 0 deletions Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ nearCommandUsage3Description=Lists all players within the default near radius of
nearCommandUsage4=/<command> <player> <radius>
nearCommandUsage4Description=Lists all players within the given radius of the specified player
nearbyPlayers=\u00a76Players nearby\:\u00a7r {0}
nearbyPlayersList={0}\u00a7f(\u00a7c{1}m\u00a7f)
negativeBalanceError=\u00a74User is not allowed to have a negative balance.
nickChanged=\u00a76Nickname changed.
nickCommandDescription=Change your nickname or that of another player.
Expand Down
11 changes: 11 additions & 0 deletions Essentials/src/main/resources/messages_cs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1022,14 +1022,17 @@ replyLastRecipientDisabledFor=§6Odpovídání poslednímu příjemci §cvypnuto
replyLastRecipientEnabled=§6Odpovídání poslednímu příjemci §czapnuto§6.
replyLastRecipientEnabledFor=§6Odpovídání poslednímu příjemci §czapnuto §6proa §c{0}§6.
requestAccepted=§6Zadost o teleport prijata.
requestAcceptedAll=§6Přijato §c{0} §6žádostí o teleportování.
requestAcceptedAuto=§6Automaticky přijata žádost o teleportování od {0}.
requestAcceptedFrom=§6Hráč §c{0} §6přijal tvou žádost o teleportování.
requestAcceptedFromAuto=§6Hráč §c{0} §6automaticky přijal tvou žádost o teleportování.
requestDenied=§6Žádost o teleportování odmítnuta.
requestDeniedAll=§6Odmítnuto §c{0} §6žádostí o teleportování.
requestDeniedFrom=§6Hráč §c{0} §6odmítl tvou žádost o teleportování.
requestSent=§6Žádost odeslána hráči §c{0}§6.
requestSentAlready=§4Žádost o teleportování byla hráči §c{0}§4 už poslána.
requestTimedOut=§4Žádost o teleportování vypršela.
requestTimedOutFrom=§4Žádost o teleportování od §c{0} §4vypršela.
resetBal=§6Stav účtu všech připojených hráčů byl obnoven na §c{0}§6.
resetBalAll=§6Stav účtu všech hráčů byl obnoven na §c{0}§6.
rest=§6Cítíš se dobře odpočatý.
Expand Down Expand Up @@ -1289,10 +1292,14 @@ tpacancelCommandUsage1=/<command>
tpacancelCommandUsage1Description=Zruší všechny tvoje nevyřízené žádosti o teleportaci
tpacancelCommandUsage2=/<command> <hráč>
tpacancelCommandUsage2Description=Zruší všechny tvoje nevyřízené žádosti o teleportaci na určitého hráče
tpacceptCommandDescription=Přijme žádost o teleportování.
tpacceptCommandUsage=/<command> [jiný_hráč]
tpacceptCommandUsage1=/<command>
tpacceptCommandUsage1Description=Přijme nejnovější žádost o teleportování
tpacceptCommandUsage2=/<command> <hráč>
tpacceptCommandUsage2Description=Přijme žádost o teleportování od zadaného hráče
tpacceptCommandUsage3=/<command> *
tpacceptCommandUsage3Description=Přijme všechny žádosti o teleportování
tpahereCommandDescription=Požádej, aby se hráč teleportoval k tobě.
tpahereCommandUsage=/<command> <hráč>
tpahereCommandUsage1=/<command> <hráč>
Expand All @@ -1305,10 +1312,14 @@ tpautoCommandDescription=Automaticky přijímat žádosti o teleportaci.
tpautoCommandUsage=/<command> [hráč]
tpautoCommandUsage1=/<command> [hráč]
tpautoCommandUsage1Description=Přepne automatický příjem tpa žádostí pro tebe nebo jiného hráče, pokud je uveden
tpdenyCommandDescription=Odmítne žádost o teleportování.
tpdenyCommandUsage=/<command>
tpdenyCommandUsage1=/<command>
tpdenyCommandUsage1Description=Odmítne nejnovější žádost o teleportování
tpdenyCommandUsage2=/<command> <hráč>
tpdenyCommandUsage2Description=Odmítne žádost o teleportování od určeného hráče
tpdenyCommandUsage3=/<command> *
tpdenyCommandUsage3Description=Odmítne všechny žádosti o teleportování
tphereCommandDescription=Teleportuje hráče k tobě.
tphereCommandUsage=/<command> <hráč>
tphereCommandUsage1=/<command> <hráč>
Expand Down
Loading

0 comments on commit 26ff6ec

Please sign in to comment.