mirror of
https://github.com/md5sha256/AreaShop.git
synced 2026-11-06 17:32:43 -05:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7907498c9 | ||
|
|
afbdc6c009 | ||
|
|
cc3a0b32a4 | ||
|
|
aca6103b1c | ||
|
|
02c02dad8d | ||
|
|
822f300e65 | ||
|
|
1671dc8c26 |
No files matched your search
@@ -31,7 +31,7 @@ dependencies {
|
||||
api("com.google.inject.extensions:guice-assistedinject:7.0.0") {
|
||||
exclude("com.google.guava")
|
||||
}
|
||||
implementation("org.incendo:cloud-paper:2.0.0-beta.9") {
|
||||
implementation("org.incendo:cloud-paper:2.0.0-beta.10") {
|
||||
exclude("com.google.guava")
|
||||
}
|
||||
implementation("org.incendo:cloud-processors-confirmation:1.0.0-beta.3") {
|
||||
@@ -130,15 +130,15 @@ tasks {
|
||||
// Configure the Minecraft version for our task.
|
||||
// This is the only required configuration besides applying the plugin.
|
||||
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
||||
minecraftVersion("1.21")
|
||||
minecraftVersion("1.21.1")
|
||||
|
||||
downloadPlugins {
|
||||
github("EssentialsX", "essentials", "2.20.1", "EssentialsX-2.20.1.jar")
|
||||
github("MilkBowl", "Vault", "1.7.3", "Vault.jar")
|
||||
// WorldEdit 7.3.3
|
||||
url("https://mediafilez.forgecdn.net/files/5400/331/worldedit-bukkit-7.3.3.jar")
|
||||
// WorldGuard 7.0.10
|
||||
url("https://mediafilez.forgecdn.net/files/5344/377/worldguard-bukkit-7.0.10-dist.jar")
|
||||
// WorldEdit 7.3.9
|
||||
url("https://mediafilez.forgecdn.net/files/5935/693/worldedit-bukkit-7.3.9.jar")
|
||||
// WorldGuard 7.0.12
|
||||
url("https://mediafilez.forgecdn.net/files/5719/698/worldguard-bukkit-7.0.12-dist.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,10 @@ import me.wiefferink.areashop.interfaces.AreaShopInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditInterface;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.listeners.PlayerLoginLogoutListener;
|
||||
import me.wiefferink.areashop.managers.CacheManager;
|
||||
import me.wiefferink.areashop.managers.FeatureManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.FileManager;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.managers.Manager;
|
||||
import me.wiefferink.areashop.managers.SignErrorLogger;
|
||||
import me.wiefferink.areashop.managers.SignLinkerManager;
|
||||
@@ -56,6 +57,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -81,6 +83,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
private MessageBridge messageBridge;
|
||||
private IFileManager fileManager = null;
|
||||
private LanguageManager languageManager = null;
|
||||
private CacheManager cacheManager = null;
|
||||
private SignLinkerManager signLinkerManager = null;
|
||||
private FeatureManager featureManager = null;
|
||||
private SignManager signManager;
|
||||
@@ -285,11 +288,17 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
managers.add(featureManager);
|
||||
signManager = injector.getInstance(SignManager.class);
|
||||
managers.add(signManager);
|
||||
cacheManager = injector.getInstance(CacheManager.class);
|
||||
String rawExpiryDuration = fileManager.getConfig().getString("cacheExpiryDuration", "7d");
|
||||
long millis = Utils.durationStringToLong(rawExpiryDuration);
|
||||
cacheManager.initialize(new File(getDataFolder(), "uuid-cache.bin"), Duration.ofMillis(millis));
|
||||
cacheManager.loadCache();
|
||||
managers.add(cacheManager);
|
||||
|
||||
loadExtensions();
|
||||
|
||||
// Register the event listeners
|
||||
getServer().getPluginManager().registerEvents(new PlayerLoginLogoutListener(this, messageBridge), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerLoginLogoutListener(this, messageBridge, this.cacheManager), this);
|
||||
|
||||
setupTasks();
|
||||
|
||||
@@ -384,6 +393,10 @@ public final class AreaShop extends JavaPlugin implements AreaShopApi {
|
||||
return version;
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on shutdown or reload of the server.
|
||||
*/
|
||||
|
||||
@@ -75,7 +75,7 @@ public class GroupInfoCommand extends AreashopCommandBean {
|
||||
throw new AreaShopCommandException("groupinfo-noMembers", group.getName());
|
||||
}
|
||||
String seperatedMembers = Utils.createCommaSeparatedList(members);
|
||||
this.messageBridge.message(context.sender(), "groupinfo-members", group.getName(), seperatedMembers);
|
||||
this.messageBridge.message(context.sender().sender(), "groupinfo-members", group.getName(), seperatedMembers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package me.wiefferink.areashop.commands;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.commands.util.AreashopCommandBean;
|
||||
import me.wiefferink.areashop.commands.util.RegionParseUtil;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.managers.IFileManager;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.incendo.cloud.Command;
|
||||
import org.incendo.cloud.bean.CommandProperties;
|
||||
import org.incendo.cloud.context.CommandContext;
|
||||
import org.incendo.cloud.key.CloudKey;
|
||||
import org.incendo.cloud.parser.flag.CommandFlag;
|
||||
import org.incendo.cloud.parser.standard.IntegerParser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@Singleton
|
||||
public class SetMaxExtends extends AreashopCommandBean {
|
||||
|
||||
private static final CloudKey<Integer> KEY_EXTENDS = CloudKey.of("extends", Integer.class);
|
||||
private final MessageBridge messageBridge;
|
||||
private final CommandFlag<RentRegion> regionFlag;
|
||||
|
||||
@Inject
|
||||
public SetMaxExtends(
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull IFileManager fileManager
|
||||
) {
|
||||
this.messageBridge = messageBridge;
|
||||
this.regionFlag = RegionParseUtil.createDefaultRent(fileManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpKey(@NotNull CommandSender target) {
|
||||
if (target.hasPermission("areashop.setmaxextends")) {
|
||||
return "help-setmaxextends";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String stringDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Command.Builder<? extends CommandSource<?>> configureCommand(Command.@NotNull Builder<CommandSource<?>> builder) {
|
||||
return builder.literal("setmaxextends")
|
||||
.required(KEY_EXTENDS, IntegerParser.integerParser(0))
|
||||
.flag(this.regionFlag)
|
||||
.handler(this::handleCommand);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NonNull CommandProperties properties() {
|
||||
return CommandProperties.of("setmaxextends");
|
||||
}
|
||||
|
||||
private void handleCommand(@Nonnull CommandContext<CommandSource<?>> context) {
|
||||
CommandSender sender = context.sender().sender();
|
||||
if (!sender.hasPermission("areashop.setmaxextends") && (!sender.hasPermission("areashop.setmaxextends.landlord") && sender instanceof Player)) {
|
||||
this.messageBridge.message(sender, "setmaxextends-noPermission");
|
||||
return;
|
||||
}
|
||||
RentRegion rent = RegionParseUtil.getOrParseRentRegion(context, sender, this.regionFlag);
|
||||
if (!sender.hasPermission("areashop.setmaxextends")
|
||||
&& !(sender instanceof Player player
|
||||
&& rent.isLandlord(player.getUniqueId()))
|
||||
) {
|
||||
this.messageBridge.message(sender, "setmaxextends-noLandlord", rent);
|
||||
return;
|
||||
}
|
||||
int extend = context.get(KEY_EXTENDS);
|
||||
|
||||
sender.sendMessage();
|
||||
rent.setMaxExtends(extend);
|
||||
rent.update();
|
||||
this.messageBridge.message(sender, "setmaxextends-success", rent);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,6 +46,7 @@ import me.wiefferink.areashop.commands.TeleportCommand;
|
||||
import me.wiefferink.areashop.commands.ToggleHomeCommand;
|
||||
import me.wiefferink.areashop.commands.TransferCommand;
|
||||
import me.wiefferink.areashop.commands.UnrentCommand;
|
||||
import me.wiefferink.areashop.commands.SetMaxExtends;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSource;
|
||||
import me.wiefferink.areashop.commands.util.commandsource.CommandSourceMapper;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -109,7 +110,8 @@ public class AreashopCommands {
|
||||
TeleportCommand.class,
|
||||
ToggleHomeCommand.class,
|
||||
TransferCommand.class,
|
||||
UnrentCommand.class
|
||||
UnrentCommand.class,
|
||||
SetMaxExtends.class
|
||||
);
|
||||
|
||||
private final MessageBridge messageBridge;
|
||||
@@ -147,14 +149,14 @@ public class AreashopCommands {
|
||||
private void initCommandManager() {
|
||||
ExceptionController<CommandSource<?>> exceptionController = this.commandManager.exceptionController();
|
||||
// We need to unwrap ArgumentParseException because they wrap the custom exception messages
|
||||
exceptionController.registerHandler(ArgumentParseException.class,
|
||||
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
|
||||
exceptionController.registerHandler(CommandExecutionException.class,
|
||||
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
|
||||
exceptionController.registerHandler(InvalidCommandSenderException.class,
|
||||
new InvalidCommandSenderHandler(this.messageBridge));
|
||||
exceptionController.registerHandler(AreaShopCommandException.class,
|
||||
new ArgumentParseExceptionHandler<>(this.messageBridge));
|
||||
exceptionController.registerHandler(ArgumentParseException.class,
|
||||
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
|
||||
exceptionController.registerHandler(CommandExecutionException.class,
|
||||
ExceptionHandler.unwrappingHandler(AreaShopCommandException.class));
|
||||
var confirmationConfiguration = ConfirmationConfiguration.<CommandSource<?>>builder()
|
||||
.cache(GuavaCache.of(CacheBuilder.newBuilder().build()))
|
||||
.noPendingCommandNotifier(x -> {
|
||||
|
||||
+11
-1
@@ -2,10 +2,12 @@ package me.wiefferink.areashop.listeners;
|
||||
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.MessageBridge;
|
||||
import me.wiefferink.areashop.managers.CacheManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.areashop.tools.Utils;
|
||||
import me.wiefferink.areashop.tools.CacheWrapper;
|
||||
import me.wiefferink.bukkitdo.Do;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -27,14 +29,20 @@ public final class PlayerLoginLogoutListener implements Listener {
|
||||
|
||||
private final AreaShop plugin;
|
||||
private final MessageBridge messageBridge;
|
||||
private final CacheManager cacheManager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param plugin The AreaShop plugin
|
||||
*/
|
||||
public PlayerLoginLogoutListener(@Nonnull AreaShop plugin, @Nonnull MessageBridge messageBridge) {
|
||||
public PlayerLoginLogoutListener(
|
||||
@Nonnull AreaShop plugin,
|
||||
@Nonnull MessageBridge messageBridge,
|
||||
@Nonnull CacheManager cacheManager
|
||||
) {
|
||||
this.plugin = plugin;
|
||||
this.messageBridge = messageBridge;
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,6 +56,8 @@ public final class PlayerLoginLogoutListener implements Listener {
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
this.cacheManager.computeIfAbsent(player.getUniqueId(), uuid -> new CacheWrapper(uuid, player.getName()));
|
||||
|
||||
// Schedule task to check for notifications, prevents a lag spike at login
|
||||
Do.syncTimerLater(25, 25, () -> {
|
||||
// Delay until all regions are loaded
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
package me.wiefferink.areashop.managers;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import me.wiefferink.areashop.tools.CacheWrapper;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class CacheManager extends Manager {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final Map<UUID, CacheWrapper> cache;
|
||||
|
||||
private File cacheFile;
|
||||
private Duration expiryDuration;
|
||||
|
||||
@Inject
|
||||
CacheManager(@Nonnull Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.cache = new HashMap<>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
if (this.expiryDuration != null) {
|
||||
trimCache(expiryDuration);
|
||||
}
|
||||
if (this.cacheFile != null) {
|
||||
saveCache(cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void initialize(@Nonnull File cacheFile, @Nonnull Duration expiryDuration) {
|
||||
this.cacheFile = cacheFile;
|
||||
this.expiryDuration = expiryDuration;
|
||||
}
|
||||
|
||||
public void loadCache() {
|
||||
if (this.cacheFile != null) {
|
||||
loadCache(this.cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the cache from the file
|
||||
*/
|
||||
public void loadCache(@Nonnull File cacheFile) {
|
||||
if (Files.notExists(cacheFile.toPath())) {
|
||||
this.plugin.getLogger().info("uuid cache file does not exist, loaded 0 entries");
|
||||
return;
|
||||
}
|
||||
this.cache.clear();
|
||||
|
||||
try (FileInputStream input = new FileInputStream(cacheFile)) {
|
||||
byte[] bytes = input.readAllBytes();
|
||||
ByteBuffer buffer = ByteBuffer.wrap(bytes).asReadOnlyBuffer();
|
||||
while (buffer.hasRemaining()) {
|
||||
long lastUsed = buffer.getLong();
|
||||
long lsb = buffer.getLong();
|
||||
long msb = buffer.getLong();
|
||||
int stringLen = buffer.getInt();
|
||||
byte[] stringBytes = new byte[stringLen];
|
||||
buffer.get(stringBytes);
|
||||
String name = new String(stringBytes, StandardCharsets.UTF_8);
|
||||
UUID uuid = new UUID(msb, lsb);
|
||||
CacheWrapper wrapper = new CacheWrapper(uuid, name, lastUsed);
|
||||
this.cache.put(wrapper.getUuid(), wrapper);
|
||||
}
|
||||
this.plugin.getLogger()
|
||||
.info(String.format("Loaded %d cached uuid name entries", this.cache.size()));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
this.plugin.getLogger().warning("Failed to load the uuid cache!");
|
||||
}
|
||||
}
|
||||
|
||||
public void saveCache() {
|
||||
if (this.cacheFile != null) {
|
||||
saveCache(this.cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveCacheAsync() {
|
||||
if (this.cacheFile != null) {
|
||||
saveCacheAsync(this.cacheFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save the cache to the file
|
||||
*/
|
||||
public void saveCache(@Nonnull File cacheFile) {
|
||||
List<CacheWrapper> copy = this.cache.values().stream().map(CacheWrapper::new).toList();
|
||||
try {
|
||||
// Ensure parent directory exists
|
||||
Path parentDir = cacheFile.toPath().getParent();
|
||||
if (parentDir != null) { // parent might be null if cacheFile is relative with no parent
|
||||
Files.createDirectories(parentDir);
|
||||
}
|
||||
byte[] bytes = serialize(copy);
|
||||
try (FileOutputStream fos = new FileOutputStream(cacheFile)) {
|
||||
fos.write(bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to save cache.json", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveCacheAsync(@Nonnull File cacheFile) {
|
||||
List<CacheWrapper> copy = this.cache.values().stream().map(CacheWrapper::new).toList();
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
// Ensure parent directory exists
|
||||
Path parentDir = cacheFile.toPath().getParent();
|
||||
if (parentDir != null) { // parent might be null if cacheFile is relative with no parent
|
||||
Files.createDirectories(parentDir);
|
||||
}
|
||||
byte[] bytes = serialize(copy);
|
||||
try (FileOutputStream fos = new FileOutputStream(cacheFile)) {
|
||||
fos.write(bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to save cache.json", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private byte[] serialize(List<CacheWrapper> wrappers) {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(256 * wrappers.size());
|
||||
for (CacheWrapper wrapper : wrappers) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(256);
|
||||
byte[] stringBytes = wrapper.getName().getBytes(StandardCharsets.UTF_8);
|
||||
int stringLen = stringBytes.length;
|
||||
long lsb = wrapper.getUuid().getLeastSignificantBits();
|
||||
long msb = wrapper.getUuid().getMostSignificantBits();
|
||||
long lastUsed = wrapper.getLastUsed();
|
||||
buffer.putLong(lastUsed);
|
||||
buffer.putLong(lsb);
|
||||
buffer.putLong(msb);
|
||||
buffer.putInt(stringLen);
|
||||
buffer.put(stringBytes);
|
||||
|
||||
buffer.flip();
|
||||
|
||||
bos.write(buffer.array(), buffer.position(), buffer.remaining());
|
||||
}
|
||||
return bos.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a cache entry
|
||||
*/
|
||||
public CacheWrapper get(UUID uuid) {
|
||||
return cache.get(uuid);
|
||||
}
|
||||
|
||||
public CacheWrapper computeIfAbsent(@Nonnull UUID uuid, Function<UUID, CacheWrapper> function) {
|
||||
return this.cache.computeIfAbsent(uuid, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a cache entry
|
||||
*/
|
||||
public void put(UUID uuid, CacheWrapper wrapper) {
|
||||
cache.put(uuid, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache entry
|
||||
*/
|
||||
public CacheWrapper remove(UUID uuid) {
|
||||
return cache.remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if cache contains a UUID
|
||||
*/
|
||||
public boolean contains(UUID uuid) {
|
||||
return cache.containsKey(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all cache entries
|
||||
*/
|
||||
public Map<UUID, CacheWrapper> getAllEntries() {
|
||||
return new HashMap<>(cache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cache entries
|
||||
*/
|
||||
public void clear() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the cache
|
||||
*/
|
||||
public int size() {
|
||||
return cache.size();
|
||||
}
|
||||
|
||||
public void trimCache() {
|
||||
if (this.expiryDuration != null) {
|
||||
trimCache(this.expiryDuration);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim the cache by removing entries older than 1 week
|
||||
*/
|
||||
public void trimCache(@Nonnull Duration expiryDuration) {
|
||||
long expiryMillis = expiryDuration.toMillis();
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
Iterator<Map.Entry<UUID, CacheWrapper>> iterator = cache.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<UUID, CacheWrapper> entry = iterator.next();
|
||||
CacheWrapper wrapper = entry.getValue();
|
||||
|
||||
if (wrapper.getLastUsed() != -1 && (currentTime - wrapper.getLastUsed()) >= expiryMillis) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -190,6 +190,9 @@ public class RentRegion extends GeneralRegion {
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxExtends(int times) {
|
||||
setSetting("rent.maxExtends", times); }
|
||||
|
||||
@Override
|
||||
public Object provideReplacement(String variable) {
|
||||
return switch (variable) {
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CacheWrapper {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CacheWrapper.class);
|
||||
private final UUID uuid;
|
||||
private final String name;
|
||||
private long lastUsed;
|
||||
|
||||
public CacheWrapper(CacheWrapper other) {
|
||||
this.uuid = other.uuid;
|
||||
this.name = other.name;
|
||||
this.lastUsed = other.lastUsed;
|
||||
}
|
||||
|
||||
public CacheWrapper(@Nonnull UUID uuid, @Nonnull String name) {
|
||||
this(uuid, name, -1);
|
||||
}
|
||||
|
||||
public CacheWrapper(@Nonnull UUID uuid, @Nonnull String name, long lastUsed) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.lastUsed = lastUsed;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
this.lastUsed = System.currentTimeMillis();
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getLastUsed() {
|
||||
return lastUsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CacheWrapper that = (CacheWrapper) o;
|
||||
return lastUsed == that.lastUsed && Objects.equals(uuid,
|
||||
that.uuid) && Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid, name, lastUsed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CacheWrapper{" +
|
||||
"uuid=" + uuid +
|
||||
", name='" + name + '\'' +
|
||||
", lastUsed=" + lastUsed +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import jakarta.inject.Inject;
|
||||
import me.wiefferink.areashop.AreaShop;
|
||||
import me.wiefferink.areashop.interfaces.WorldEditSelection;
|
||||
import me.wiefferink.areashop.interfaces.WorldGuardInterface;
|
||||
import me.wiefferink.areashop.managers.CacheManager;
|
||||
import me.wiefferink.areashop.regions.BuyRegion;
|
||||
import me.wiefferink.areashop.regions.GeneralRegion;
|
||||
import me.wiefferink.areashop.regions.RentRegion;
|
||||
@@ -805,10 +806,20 @@ public class Utils {
|
||||
if (uuid == null) {
|
||||
return "";
|
||||
}
|
||||
String name = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
|
||||
final CacheManager cacheManager = plugin.getCacheManager();
|
||||
|
||||
if (cacheManager.contains(uuid))
|
||||
return cacheManager.get(uuid).getName();
|
||||
|
||||
|
||||
final String name = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
|
||||
if (name != null) {
|
||||
cacheManager.put(uuid, new CacheWrapper(uuid, name, System.currentTimeMillis()));
|
||||
return name;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,7 @@ forceClearEntities: false
|
||||
# Maximum number of locations the teleport function should check to find a safe spot.
|
||||
maximumTries: 50000
|
||||
|
||||
cacheExpiryDuration: '7d'
|
||||
|
||||
# ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
# │ VARIABLES: Variables that can be used in messages and settings where a region is available. │
|
||||
|
||||
@@ -374,6 +374,11 @@ setduration-noLandlord: You don't have permission to change the duration because
|
||||
setduration-successRemoved: 'Duration of %lang:region% has been removed, it will now
|
||||
use the duration from a group or the default.yml file, new duration: %duration%.'
|
||||
|
||||
setmaxextends-noPermission: You don't have permission to change the amount of times a region can have rent extended.
|
||||
setmaxextends-help: /as setmaxextends \<amount> [region], the region you stand in will be used if not specified.
|
||||
setmaxextends-noLandlord: You don't have permission to change the duration because you are not the landlord of %lang:region%.
|
||||
setmaxextends-success: Max extensions of %lang:region% changed to %maxextends%
|
||||
|
||||
setup-noRegion: You did not specify a region on the second line.
|
||||
setup-alreadyRentSign: The region you specified is already added to AreaShop as a
|
||||
rent region, add signs with [as] on the first line or '/as addsign'.
|
||||
|
||||
@@ -81,6 +81,7 @@ help-reload: "%lang:helpCommand|/as reload|% Reload all files and update the reg
|
||||
help-setrestore: "%lang:helpCommand|/as setrestore|% Set restoring on/off and choose profile."
|
||||
help-setprice: "%lang:helpCommand|/as setprice|% Change the price of a region."
|
||||
help-setduration: "%lang:helpCommand|/as setduration|% Change the duration of a rent region."
|
||||
help-setmaxextends: "%lang:helpCommand|/as setmaxextends|% Change the amount of times a renter can extend their rent by."
|
||||
help-settransfer: "%lang:helpCommand|/as settransfer|% Set transfer on/off."
|
||||
help-teleport: "%lang:helpCommand|/as tp|% Teleport to a rent/buy region."
|
||||
help-setteleport: "%lang:helpCommand|/as settp|% Set teleport position for a region."
|
||||
@@ -350,6 +351,11 @@ setduration-success: "Duration of region %lang:region% changed to '%duration%'."
|
||||
setduration-noLandlord: "You don't have permission to change the duration because you are not the landlord of %lang:region%."
|
||||
setduration-successRemoved: "Duration of %lang:region% has been removed, it will now use the duration from a group or the default.yml file, new duration: %duration%."
|
||||
|
||||
setmaxextends-noPermission: "You don't have permission to change the amount of times a region can have rent extended."
|
||||
setmaxextends-help: "/as setmaxextends <amount> [region], the region you stand in will be used if not specified."
|
||||
setmaxextends-noLandlord: "You don't have permission to change the duration because you are not the landlord of %lang:region%."
|
||||
setmaxextends-success: "Max extensions of %lang:region% changed to %maxextends%"
|
||||
|
||||
setup-noRegion: "You did not specify a region on the second line."
|
||||
setup-alreadyRentSign: "The region you specified is already added to AreaShop as a rent region, add signs with [as] on the first line or '/as addsign'."
|
||||
setup-alreadyOtherWorld: "The region you specified is already added to AreaShop in another world, regions from different worlds still need different names."
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
<h1>
|
||||
The project is no longer maintained. See this alternative <a href="https://github.com/MCCitiesNetwork/realty">realty</a>
|
||||
</h1>
|
||||
<br>
|
||||
|
||||
<br/>
|
||||
[](https://jitpack.io/#md5sha256/AreaShop)
|
||||
<br>
|
||||
@@ -74,4 +79,4 @@ For a preview join 'mc.go-craft.com' and go to the Survival server, the shops ar
|
||||
**Made by [PerkulatorTime](https://www.youtube.com/user/PerkulatorTime)**<br/>
|
||||
[](https://www.youtube.com/watch?v=OQOsOG-EdNc)
|
||||
|
||||
Old video for AreaShop v1.0: [Tutorial by VariationVault](https://www.youtube.com/watch?v=k2HMCxCCOYo)
|
||||
Old video for AreaShop v1.0: [Tutorial by VariationVault](https://www.youtube.com/watch?v=k2HMCxCCOYo)
|
||||
@@ -1,6 +1,6 @@
|
||||
[versions]
|
||||
# Platforms
|
||||
minecraft = "1.21-R0.1-SNAPSHOT"
|
||||
minecraft = "1.21.1-R0.1-SNAPSHOT"
|
||||
|
||||
# Minecraft Plugins
|
||||
worldedit = "7.3.3"
|
||||
|
||||
Reference in new issue
Block a user