feat: add project files
This commit is contained in:
11
.gitattributes
vendored
Normal file
11
.gitattributes
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
#region Gradle
|
||||
/gradlew text eol=lf
|
||||
#endregion
|
||||
|
||||
#region Java
|
||||
*.jar binary
|
||||
#endregion
|
||||
|
||||
#region Windows
|
||||
*.bat text eol=crlf
|
||||
#endregion
|
||||
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
#region Visual Studio Code
|
||||
.vscode/
|
||||
*.code-workspace
|
||||
#endregion
|
||||
|
||||
#region Java
|
||||
bin/
|
||||
build/
|
||||
run/
|
||||
#endregion
|
||||
|
||||
#region Gradle
|
||||
.gradle/
|
||||
|
||||
!gradle-wrapper.jar
|
||||
!gradle-wrapper.properties
|
||||
#endregion
|
||||
62
chancery/build.gradle.kts
Normal file
62
chancery/build.gradle.kts
Normal file
@@ -0,0 +1,62 @@
|
||||
plugins {
|
||||
id("java-library")
|
||||
id("com.gradleup.shadow") version "9.4.1"
|
||||
id("xyz.jpenilla.run-paper") version "3.0.2"
|
||||
}
|
||||
|
||||
group = "io.github.axolotsh"
|
||||
version = "1.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
||||
maven {
|
||||
name = "axolotsh-repository"
|
||||
url = uri("https://maven.axolotsh.org/snapshots")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.axolotsh:localizationlib:1.0-SNAPSHOT")
|
||||
implementation("org.axolotsh:formatterlib:1.0-SNAPSHOT")
|
||||
implementation("org.axolotsh:plugin-utils:1.0-SNAPSHOT")
|
||||
|
||||
implementation("com.google.inject:guice:7.0.0")
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.46")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.46")
|
||||
|
||||
compileOnly("dev.jorel:commandapi-paper-core:11.2.0")
|
||||
|
||||
compileOnly("io.papermc.paper:paper-api:26.1.2.build.+")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(25)
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(shadowJar)
|
||||
}
|
||||
|
||||
runServer {
|
||||
minecraftVersion("26.1.2")
|
||||
jvmArgs("-Xms2G", "-Xmx2G", "-Dcom.mojang.eula.agree=true")
|
||||
|
||||
downloadPlugins {
|
||||
hangar("CommandAPI", "11.2.0")
|
||||
}
|
||||
}
|
||||
|
||||
processResources {
|
||||
val props = mapOf("version" to version, "description" to project.description)
|
||||
filesMatching("plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
filesMatching("paper-plugin.yml") {
|
||||
expand(props)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.axolotsh.chancery;
|
||||
|
||||
import org.axolotsh.pluginutils.configuration.LocalizationConfiguration;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
public class Configuration {
|
||||
private String bababui;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private LocalizationConfiguration localization;
|
||||
|
||||
public LocalizationConfiguration localization() {
|
||||
return localization == null ? LocalizationConfiguration.defaultConfiguration() : localization;
|
||||
}
|
||||
}
|
||||
60
chancery/src/main/java/org/axolotsh/chancery/Module.java
Normal file
60
chancery/src/main/java/org/axolotsh/chancery/Module.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package org.axolotsh.chancery;
|
||||
|
||||
import org.axolotsh.chancery.commands.ChanceryCommand;
|
||||
import org.axolotsh.chancery.commands.ReloadCommand;
|
||||
import org.axolotsh.chancery.modules.signature.SignatureModule;
|
||||
import org.axolotsh.localizationlib.LocalizationFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.localizationlib.providers.DirectoryProvider;
|
||||
import org.axolotsh.pluginutils.dependency_injection.JavaPluginModule;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
public class Module extends JavaPluginModule {
|
||||
public Module(Plugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
createListenersMultibinder();
|
||||
createTasksMultibinder();
|
||||
createConfigurationMultibinder();
|
||||
|
||||
var commandBinder = createCommandsMultibinder();
|
||||
commandBinder.addBinding().to(ChanceryCommand.class);
|
||||
commandBinder.addBinding().to(ReloadCommand.class);
|
||||
|
||||
install(new SignatureModule());
|
||||
|
||||
this.bind(Configuration.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
protected ILocalizationFactory provideLocalizationFactory(
|
||||
JavaPlugin plugin,
|
||||
Configuration configuration,
|
||||
Logger logger) {
|
||||
var localization = configuration.localization();
|
||||
var directory = localization.directory(plugin);
|
||||
|
||||
return LocalizationFactory.builder()
|
||||
.defaultLocale(localization.defaultLocale())
|
||||
.provider(
|
||||
DirectoryProvider.builder()
|
||||
.directory(directory)
|
||||
.onEmptyInitializer(() -> {
|
||||
logger.warn("Localization files ({}/*) not found! Load default ones.",
|
||||
directory.getAbsolutePath());
|
||||
|
||||
plugin.saveResource("locales/en-US.jsonc", false);
|
||||
plugin.saveResource("locales/ru-RU.jsonc", false);
|
||||
})
|
||||
.build())
|
||||
.build().reloadProviders();
|
||||
}
|
||||
}
|
||||
24
chancery/src/main/java/org/axolotsh/chancery/Plugin.java
Normal file
24
chancery/src/main/java/org/axolotsh/chancery/Plugin.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.axolotsh.chancery;
|
||||
|
||||
import org.axolotsh.pluginutils.dependency_injection.BaseJavaPlugin;
|
||||
|
||||
public class Plugin extends BaseJavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
createInjector(new Module(this));
|
||||
|
||||
registerListeners();
|
||||
registerCommands();
|
||||
registerTasks();
|
||||
registerConfiguration();
|
||||
|
||||
configurations.forEach(conf -> {
|
||||
if (conf instanceof Configuration configuration)
|
||||
logger.info(configuration.bababui());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.axolotsh.chancery.commands;
|
||||
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class ChanceryCommand extends BaseCommand {
|
||||
@Override
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("chancery");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.axolotsh.chancery.commands;
|
||||
|
||||
import static org.axolotsh.pluginutils.ComponentUtils.component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.axolotsh.localizationlib.LocalizationFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationService;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class ReloadCommand extends BaseCommand {
|
||||
private final ILocalizationFactory lFactory;
|
||||
|
||||
@Override
|
||||
public Class<? extends BaseCommand> parentCommand() {
|
||||
return ChanceryCommand.class;
|
||||
}
|
||||
|
||||
private static final String PERMISSION = "chancery.reload";
|
||||
@Getter
|
||||
private final Permission permission = new Permission(
|
||||
PERMISSION,
|
||||
"Allows players to reload chancery plugin");
|
||||
|
||||
public Collection<Permission> permissions() {
|
||||
return Set.of(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("reload")
|
||||
.withPermission(PERMISSION)
|
||||
.executes((sender, _) -> {
|
||||
execute(sender);
|
||||
});
|
||||
}
|
||||
|
||||
public void execute(CommandSender sender) throws WrapperCommandSyntaxException {
|
||||
ILocalizationService localization;
|
||||
if (sender instanceof Player player)
|
||||
localization = lFactory.service(player.locale());
|
||||
else
|
||||
localization = lFactory.service();
|
||||
|
||||
sender.sendMessage(component(
|
||||
localization.translate("command.reload.success.reloading")));
|
||||
|
||||
if (lFactory instanceof LocalizationFactory localizationFactory)
|
||||
localizationFactory.reloadProviders();
|
||||
|
||||
sender.sendMessage(component(
|
||||
localization.translate("command.reload.success.reloaded")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package org.axolotsh.chancery.modules.itemlore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.axolotsh.chancery.modules.itemlore.entities.LoreEntry;
|
||||
import org.axolotsh.chancery.modules.itemlore.entities.LoreEntryType;
|
||||
import org.axolotsh.pluginutils.persistent_data_container.PersistentMap;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor
|
||||
public class ItemLoreFactory {
|
||||
private final Configuration configuration;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@Builder(toBuilder = true)
|
||||
public static class Configuration {
|
||||
@NonNull
|
||||
private String namespace;
|
||||
|
||||
@Builder.Default
|
||||
private String loreEntriesKey = "lore_entries";
|
||||
|
||||
public NamespacedKey loreEntries() {
|
||||
return new NamespacedKey(namespace, loreEntriesKey);
|
||||
};
|
||||
|
||||
public static Configuration fromPlugin(JavaPlugin plugin) {
|
||||
return builder()
|
||||
.namespace(plugin.namespace())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
public ItemLoreFactory(JavaPlugin plugin) {
|
||||
this(Configuration.fromPlugin(plugin));
|
||||
}
|
||||
|
||||
public ItemLoreService service(ItemStack item) {
|
||||
Map<Key, List<Component>> lore = new LinkedHashMap<>();
|
||||
var loreMap = loreEntries(item).get();
|
||||
var itemLore = item.lore();
|
||||
if (itemLore == null)
|
||||
itemLore = List.of();
|
||||
|
||||
var usedIndices = new boolean[itemLore.size()];
|
||||
|
||||
for (var entry : loreMap.entrySet()) {
|
||||
var info = entry.getValue();
|
||||
lore.put(entry.getKey(), info.get(itemLore));
|
||||
|
||||
var start = Math.min(info.position(), itemLore.size());
|
||||
var end = Math.min(info.endPosition(), itemLore.size());
|
||||
for (var i = start; i < end; i++)
|
||||
usedIndices[i] = true;
|
||||
}
|
||||
|
||||
List<Component> unmappedLines = new ArrayList<>();
|
||||
for (int i = 0; i < itemLore.size(); i++)
|
||||
if (!usedIndices[i])
|
||||
unmappedLines.add(itemLore.get(i));
|
||||
|
||||
if (!unmappedLines.isEmpty())
|
||||
lore.put(ItemLoreService.UNKNOWN_LORE_KEY, unmappedLines);
|
||||
|
||||
return new ItemLoreService(this, lore, item);
|
||||
}
|
||||
|
||||
PersistentMap<Key, LoreEntry> loreEntries(ItemStack item) {
|
||||
return new PersistentMap<Key, LoreEntry>(
|
||||
configuration.loreEntries(), LoreEntryType.INSTANCE, item,
|
||||
(entry) -> Map.entry(entry.id(), entry), LinkedHashMap::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.axolotsh.chancery.modules.itemlore;
|
||||
|
||||
import org.axolotsh.pluginutils.dependency_injection.PluginModule;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
public class ItemLoreModule extends PluginModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
protected ItemLoreFactory provideItemLoreFactory(JavaPlugin plugin) {
|
||||
return new ItemLoreFactory(plugin);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.axolotsh.chancery.modules.itemlore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.axolotsh.chancery.modules.itemlore.entities.LoreEntry;
|
||||
import org.axolotsh.pluginutils.wrappers.MapWrapper;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
public class ItemLoreService extends MapWrapper<Key, List<Component>> implements AutoCloseable {
|
||||
public static final Key UNKNOWN_LORE_KEY = Key.key("unknown_lore");
|
||||
|
||||
private final ItemLoreFactory factory;
|
||||
private final ItemStack item;
|
||||
|
||||
ItemLoreService(ItemLoreFactory factory, Map<Key, List<Component>> innerMap, ItemStack item) {
|
||||
super(innerMap);
|
||||
this.factory = factory;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
List<Component> lore = new ArrayList<>();
|
||||
Map<Key, LoreEntry> loreMap = new LinkedHashMap<>();
|
||||
|
||||
var position = 0;
|
||||
for (Map.Entry<Key, List<Component>> entry : innerMap.entrySet()) {
|
||||
var key = entry.getKey();
|
||||
var value = entry.getValue();
|
||||
|
||||
var size = value.size();
|
||||
if (!key.equals(UNKNOWN_LORE_KEY)) {
|
||||
var loreEntry = new LoreEntry(key, position, size);
|
||||
loreMap.put(key, loreEntry);
|
||||
}
|
||||
|
||||
lore.addAll(value);
|
||||
|
||||
position += size;
|
||||
}
|
||||
|
||||
factory.loreEntries(item).set(loreMap);
|
||||
item.lore(lore);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.axolotsh.chancery.modules.itemlore.entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@Builder(toBuilder = true)
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
public class LoreEntry {
|
||||
@NonNull
|
||||
private Key id;
|
||||
|
||||
private int position;
|
||||
private int length;
|
||||
|
||||
public int endPosition() {
|
||||
return position + length;
|
||||
}
|
||||
|
||||
public List<Component> get(List<Component> lore) {
|
||||
Objects.requireNonNull(lore);
|
||||
|
||||
var toIndex = Math.min(endPosition(), lore.size());
|
||||
var fromIndex = Math.min(position, toIndex);
|
||||
|
||||
return new ArrayList<>(lore.subList(fromIndex, toIndex));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.axolotsh.chancery.modules.itemlore.entities;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.persistence.PersistentDataAdapterContext;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
|
||||
public class LoreEntryType implements PersistentDataType<byte[], LoreEntry> {
|
||||
public static final LoreEntryType INSTANCE = new LoreEntryType();
|
||||
|
||||
private LoreEntryType() {
|
||||
};
|
||||
|
||||
@Override
|
||||
public @NotNull Class<byte[]> getPrimitiveType() {
|
||||
return byte[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Class<LoreEntry> getComplexType() {
|
||||
return LoreEntry.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte @NotNull [] toPrimitive(@NotNull LoreEntry complex, @NotNull PersistentDataAdapterContext context) {
|
||||
var baos = new ByteArrayOutputStream();
|
||||
try (var dos = new DataOutputStream(baos)) {
|
||||
dos.writeInt(complex.position());
|
||||
dos.writeInt(complex.length());
|
||||
|
||||
var id = complex.id();
|
||||
dos.writeUTF(id.asMinimalString());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull LoreEntry fromPrimitive(byte @NotNull [] primitive, @NotNull PersistentDataAdapterContext context) {
|
||||
var bais = new ByteArrayInputStream(primitive);
|
||||
try (var dis = new DataInputStream(bais)) {
|
||||
var position = dis.readInt();
|
||||
var length = dis.readInt();
|
||||
|
||||
var minimalString = dis.readUTF();
|
||||
var key = Key.key(minimalString);
|
||||
return new LoreEntry(key, position, length);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.axolotsh.chancery.modules.signature;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import org.axolotsh.pluginutils.ConfigurationUtils;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.IConfiguration;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Singular;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
public class SignatureConfiguration implements IConfiguration {
|
||||
@Singular
|
||||
private Collection<Material> blacklistMaterials;
|
||||
|
||||
@Singular
|
||||
private Collection<Material> whitelistMaterials;
|
||||
|
||||
@Builder.Default
|
||||
private String signaturesKey = "chancery:signatures";
|
||||
|
||||
public NamespacedKey signatures() {
|
||||
return NamespacedKey.fromString(signaturesKey);
|
||||
};
|
||||
|
||||
@Builder.Default
|
||||
private String signaturesLockKey = "chancery:signatures_lock";
|
||||
|
||||
public NamespacedKey signaturesLock() {
|
||||
return NamespacedKey.fromString(signaturesLockKey);
|
||||
};
|
||||
|
||||
public Map<String, Object> serialize() {
|
||||
return ConfigurationUtils.serialize(this);
|
||||
}
|
||||
|
||||
public static SignatureConfiguration deserialize(Map<String, Object> args) {
|
||||
return ConfigurationUtils.deserialize(args, SignatureConfiguration.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package org.axolotsh.chancery.modules.signature;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.axolotsh.chancery.modules.itemlore.ItemLoreFactory;
|
||||
import org.axolotsh.chancery.modules.signature.entities.SignatureDataType;
|
||||
import org.axolotsh.chancery.modules.signature.entities.SignatureInfo;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationService;
|
||||
import org.axolotsh.pluginutils.persistent_data_container.PersistentEntry;
|
||||
import org.axolotsh.pluginutils.persistent_data_container.PersistentMap;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor()
|
||||
public class SignatureFactory {
|
||||
private final ItemLoreFactory loreFactory;
|
||||
private final ILocalizationFactory localizationFactory;
|
||||
|
||||
private final SignatureConfiguration moduleConfiguration;
|
||||
private final Configuration configuration;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@Builder(toBuilder = true)
|
||||
public static class Configuration {
|
||||
@NonNull
|
||||
private String namespace;
|
||||
|
||||
@Builder.Default
|
||||
private String signaturesKey = "signatures";
|
||||
|
||||
public NamespacedKey signatures() {
|
||||
return new NamespacedKey(namespace, signaturesKey);
|
||||
};
|
||||
|
||||
@Builder.Default
|
||||
private String signaturesLockKey = "signatures_lock";
|
||||
|
||||
public NamespacedKey signaturesLock() {
|
||||
return new NamespacedKey(namespace, signaturesLockKey);
|
||||
};
|
||||
|
||||
public static Configuration fromPlugin(JavaPlugin plugin) {
|
||||
return builder()
|
||||
.namespace(plugin.namespace())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
public SignatureFactory(JavaPlugin plugin, ItemLoreFactory loreFactory, ILocalizationFactory localizationFactory,
|
||||
SignatureConfiguration moduleConfiguration) {
|
||||
this(loreFactory, localizationFactory, moduleConfiguration, Configuration.fromPlugin(plugin));
|
||||
}
|
||||
|
||||
public SignatureService service(ItemStack item) {
|
||||
return service(item, localizationFactory.service());
|
||||
}
|
||||
|
||||
public SignatureService service(ItemStack item, Locale locale) {
|
||||
return service(item, localizationFactory.service(locale));
|
||||
}
|
||||
|
||||
public SignatureService service(ItemStack item, ILocalizationService localization) {
|
||||
return new SignatureService(this, loreFactory, localization,
|
||||
signatures(item).get(),
|
||||
signatureLock(item).get().orElse(false),
|
||||
item);
|
||||
}
|
||||
|
||||
PersistentMap<UUID, SignatureInfo> signatures(ItemStack item) {
|
||||
return new PersistentMap<UUID, SignatureInfo>(
|
||||
configuration.signatures(), SignatureDataType.INSTANCE, item,
|
||||
entry -> Map.entry(entry.owner(), entry), HashMap::new);
|
||||
}
|
||||
|
||||
PersistentEntry<Boolean> signatureLock(ItemStack item) {
|
||||
return new PersistentEntry<Boolean>(
|
||||
configuration.signaturesLock(), PersistentDataType.BOOLEAN, item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.axolotsh.chancery.modules.signature;
|
||||
|
||||
import org.axolotsh.chancery.modules.signature.commands.SignClearCommand;
|
||||
import org.axolotsh.chancery.modules.signature.commands.SignCommand;
|
||||
import org.axolotsh.chancery.modules.signature.commands.SignListCommand;
|
||||
import org.axolotsh.chancery.modules.signature.commands.SignLockCommand;
|
||||
import org.axolotsh.chancery.modules.signature.commands.SignUnlockCommand;
|
||||
import org.axolotsh.pluginutils.dependency_injection.PluginModule;
|
||||
|
||||
public class SignatureModule extends PluginModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
var commandBinder = createCommandsMultibinder();
|
||||
commandBinder.addBinding().to(SignCommand.class);
|
||||
commandBinder.addBinding().to(SignClearCommand.class);
|
||||
commandBinder.addBinding().to(SignListCommand.class);
|
||||
commandBinder.addBinding().to(SignLockCommand.class);
|
||||
commandBinder.addBinding().to(SignUnlockCommand.class);
|
||||
|
||||
var configurationBinder = createConfigurationMultibinder();
|
||||
configurationBinder.addBinding().to(SignatureConfiguration.class);
|
||||
|
||||
this.bind(SignatureFactory.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package org.axolotsh.chancery.modules.signature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.axolotsh.chancery.modules.itemlore.ItemLoreFactory;
|
||||
import org.axolotsh.chancery.modules.signature.entities.SignatureInfo;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationService;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
public class SignatureService implements AutoCloseable {
|
||||
private final SignatureFactory factory;
|
||||
private final ItemLoreFactory loreFactory;
|
||||
private final ILocalizationService localization;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private final Map<UUID, SignatureInfo> signatures;
|
||||
|
||||
@Setter
|
||||
private boolean signatureLock;
|
||||
|
||||
private final ItemStack item;
|
||||
|
||||
public Collection<SignatureInfo> signatures() {
|
||||
return Collections.unmodifiableCollection(signatures.values());
|
||||
}
|
||||
|
||||
public boolean signed(OfflinePlayer owner) {
|
||||
return signed(owner.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean signed(UUID owner) {
|
||||
return signatures.containsKey(owner);
|
||||
}
|
||||
|
||||
public boolean signed(SignatureInfo signature) {
|
||||
return signatures.containsValue(signature);
|
||||
}
|
||||
|
||||
public void sign(OfflinePlayer owner) {
|
||||
sign(owner.getUniqueId());
|
||||
}
|
||||
|
||||
public void sign(UUID owner) {
|
||||
sign(SignatureInfo.builder()
|
||||
.owner(owner).build());
|
||||
}
|
||||
|
||||
public void sign(SignatureInfo signature) {
|
||||
signatures.put(signature.owner(), signature);
|
||||
}
|
||||
|
||||
public void unsign(SignatureInfo signature) {
|
||||
unsign(signature.owner());
|
||||
}
|
||||
|
||||
public void unsign(OfflinePlayer owner) {
|
||||
unsign(owner.getUniqueId());
|
||||
}
|
||||
|
||||
public void unsign(UUID owner) {
|
||||
signatures.remove(owner);
|
||||
}
|
||||
|
||||
public Optional<SignatureInfo> signature(OfflinePlayer player) {
|
||||
return signature(player.getUniqueId());
|
||||
}
|
||||
|
||||
public Optional<SignatureInfo> signature(UUID owner) {
|
||||
return Optional.ofNullable(signatures.get(owner));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
factory.signatures(item).set(signatures);
|
||||
factory.signatureLock(item).set(signatureLock);
|
||||
|
||||
var loreService = loreFactory.service(item);
|
||||
loreService.put(factory.configuration().signatures(), component());
|
||||
loreService.close();
|
||||
}
|
||||
|
||||
private List<Component> component() {
|
||||
List<Component> result = new ArrayList<>();
|
||||
|
||||
for (var signature : signatures()) {
|
||||
result.add(signature.component("SIGNATURE: <owner>"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package org.axolotsh.chancery.modules.signature.commands;
|
||||
|
||||
import static org.axolotsh.pluginutils.CommandUtils.failCommand;
|
||||
import static org.axolotsh.pluginutils.ComponentUtils.component;
|
||||
import static org.axolotsh.pluginutils.InventoryUtils.handItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.axolotsh.chancery.modules.signature.SignatureFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class SignClearCommand extends BaseCommand {
|
||||
private final ILocalizationFactory lFactory;
|
||||
private final SignatureFactory sFactory;
|
||||
|
||||
@Override
|
||||
public Class<? extends BaseCommand> parentCommand() {
|
||||
return SignCommand.class;
|
||||
}
|
||||
|
||||
private static final String PERMISSION = "chancery.sign.clear";
|
||||
@Getter
|
||||
private final Permission permission = new Permission(
|
||||
PERMISSION,
|
||||
"Allows you to remove your signature from an item",
|
||||
PermissionDefault.TRUE);
|
||||
|
||||
public Collection<Permission> permissions() {
|
||||
return Set.of(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("clear")
|
||||
.withPermission(PERMISSION)
|
||||
.executesPlayer((sender, _) -> {
|
||||
execute(sender);
|
||||
});
|
||||
}
|
||||
|
||||
public void execute(Player player) throws WrapperCommandSyntaxException {
|
||||
var localization = lFactory.service(player.locale());
|
||||
|
||||
var item = handItem(player);
|
||||
if (item.getType() == Material.AIR)
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_clear.fail.no_item")));
|
||||
|
||||
try (var signatures = sFactory.service(item)) {
|
||||
if (signatures.signatureLock())
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_clear.fail.cant_be_signed")));
|
||||
|
||||
if (!signatures.signed(player))
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_clear.fail.not_signed")));
|
||||
|
||||
signatures.unsign(player);
|
||||
}
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign_clear.success.cleared"),
|
||||
SignCommand.itemTag(item)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package org.axolotsh.chancery.modules.signature.commands;
|
||||
|
||||
import static org.axolotsh.pluginutils.CommandUtils.failCommand;
|
||||
import static org.axolotsh.pluginutils.ComponentUtils.component;
|
||||
import static org.axolotsh.pluginutils.InventoryUtils.handItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.axolotsh.chancery.modules.signature.SignatureFactory;
|
||||
import org.axolotsh.chancery.modules.signature.entities.SignatureInfo;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class SignCommand extends BaseCommand {
|
||||
private final ILocalizationFactory lFactory;
|
||||
private final SignatureFactory sFactory;
|
||||
|
||||
private static final String PERMISSION = "chancery.sign";
|
||||
@Getter
|
||||
private final Permission permission = new Permission(
|
||||
PERMISSION,
|
||||
"Allows you to sign items",
|
||||
PermissionDefault.TRUE);
|
||||
|
||||
private static final String ANONYMOUS_PERMISSION = "chancery.sign.anonymous";
|
||||
@Getter
|
||||
private final Permission anonymousPermission = new Permission(
|
||||
ANONYMOUS_PERMISSION,
|
||||
"Allows you to sign items anonymously",
|
||||
PermissionDefault.TRUE);
|
||||
|
||||
private static final String MESSAGE_PERMISSION = "chancery.sign.message";
|
||||
@Getter
|
||||
private final Permission messagePermission = new Permission(
|
||||
MESSAGE_PERMISSION,
|
||||
"Allows you to sign items with message",
|
||||
PermissionDefault.TRUE);
|
||||
|
||||
public Collection<Permission> permissions() {
|
||||
return Set.of(permission);
|
||||
}
|
||||
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("sign")
|
||||
.withPermission(PERMISSION)
|
||||
.withSubcommands(
|
||||
messageCommand(false),
|
||||
anonymousCommand()
|
||||
.withSubcommand(messageCommand(true)))
|
||||
.executesPlayer((sender, args) -> {
|
||||
execute(sender, null, false);
|
||||
});
|
||||
}
|
||||
|
||||
private static final Argument<String> MESSAGE_ARGUMENT = new GreedyStringArgument("message");
|
||||
|
||||
private CommandAPICommand messageCommand(boolean anonymous) {
|
||||
return new CommandAPICommand("message")
|
||||
.withPermission(MESSAGE_PERMISSION)
|
||||
.withArguments(MESSAGE_ARGUMENT)
|
||||
.executesPlayer((sender, args) -> {
|
||||
execute(sender, args.getByArgument(MESSAGE_ARGUMENT), anonymous);
|
||||
});
|
||||
}
|
||||
|
||||
private CommandAPICommand anonymousCommand() {
|
||||
return new CommandAPICommand("anonymous")
|
||||
.withPermission(ANONYMOUS_PERMISSION)
|
||||
.executesPlayer((sender, args) -> {
|
||||
execute(sender, null, true);
|
||||
});
|
||||
}
|
||||
|
||||
public void execute(Player player, @Nullable String message, boolean anonymous)
|
||||
throws WrapperCommandSyntaxException {
|
||||
var localization = lFactory.service(player.locale());
|
||||
|
||||
var item = handItem(player);
|
||||
|
||||
var itemType = item.getType();
|
||||
if (itemType == Material.AIR)
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign.fail.no_item")));
|
||||
|
||||
try (var signatures = sFactory.service(item)) {
|
||||
if (signatures.signatureLock())
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign.fail.cant_be_signed")));
|
||||
|
||||
var signature = SignatureInfo.builder()
|
||||
.owner(player)
|
||||
.message(message)
|
||||
.anonymous(anonymous).build();
|
||||
|
||||
if (signatures.signed(signature))
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign.fail.already_signed")));
|
||||
|
||||
signatures.sign(signature);
|
||||
}
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign.success.signed"),
|
||||
itemTag(item)));
|
||||
}
|
||||
|
||||
static TagResolver itemTag(ItemStack item) {
|
||||
return Placeholder.component("item", component(item));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.axolotsh.chancery.modules.signature.commands;
|
||||
|
||||
import static org.axolotsh.pluginutils.CommandUtils.failCommand;
|
||||
import static org.axolotsh.pluginutils.ComponentUtils.component;
|
||||
import static org.axolotsh.pluginutils.InventoryUtils.handItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.axolotsh.chancery.modules.signature.SignatureFactory;
|
||||
import org.axolotsh.chancery.modules.signature.entities.SignatureInfo;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class SignListCommand extends BaseCommand {
|
||||
private final ILocalizationFactory lFactory;
|
||||
private final SignatureFactory sFactory;
|
||||
|
||||
@Override
|
||||
public Class<? extends BaseCommand> parentCommand() {
|
||||
return SignCommand.class;
|
||||
}
|
||||
|
||||
private static final String PERMISSION = "chancery.sign.list";
|
||||
@Getter
|
||||
private final Permission permission = new Permission(
|
||||
PERMISSION,
|
||||
"Allows you to see all the signatures on an item",
|
||||
PermissionDefault.TRUE);
|
||||
|
||||
public Collection<Permission> permissions() {
|
||||
return Set.of(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("list")
|
||||
.withPermission(PERMISSION)
|
||||
.executesPlayer((sender, _) -> {
|
||||
execute(sender);
|
||||
});
|
||||
}
|
||||
|
||||
public void execute(Player player) throws WrapperCommandSyntaxException {
|
||||
var localization = lFactory.service(player.locale());
|
||||
|
||||
var item = handItem(player);
|
||||
if (item.getType() == Material.AIR)
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_list.fail.no_item")));
|
||||
|
||||
List<SignatureInfo> signatureList;
|
||||
|
||||
try (var signatures = sFactory.service(item)) {
|
||||
if (!signatures.signed(player))
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_list.fail.not_signed")));
|
||||
|
||||
signatureList = signatures.signatures()
|
||||
.stream().toList();
|
||||
}
|
||||
|
||||
var tags = Set.of(
|
||||
Placeholder.unparsed("count", String.valueOf(signatureList.size())),
|
||||
SignCommand.itemTag(item));
|
||||
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign_list.success.list_title"), tags));
|
||||
|
||||
for (int i = 0; i < signatureList.size(); i++) {
|
||||
var signature = signatureList.get(i);
|
||||
|
||||
Set<TagResolver> signatureTags = new HashSet<>(tags);
|
||||
signatureTags.add(Placeholder.unparsed("index", String.valueOf(i + 1)));
|
||||
signatureTags.add(Placeholder.component("signature", signature.component(
|
||||
localization.translate("command.sign_list.success.list_entry"))));
|
||||
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign_list.success.list_content"),
|
||||
signatureTags));
|
||||
}
|
||||
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign_list.success.list_footer"), tags));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.axolotsh.chancery.modules.signature.commands;
|
||||
|
||||
import static org.axolotsh.pluginutils.CommandUtils.failCommand;
|
||||
import static org.axolotsh.pluginutils.ComponentUtils.component;
|
||||
import static org.axolotsh.pluginutils.InventoryUtils.handItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.axolotsh.chancery.modules.signature.SignatureFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class SignLockCommand extends BaseCommand {
|
||||
private final ILocalizationFactory lFactory;
|
||||
private final SignatureFactory sFactory;
|
||||
|
||||
@Override
|
||||
public Class<? extends BaseCommand> parentCommand() {
|
||||
return SignCommand.class;
|
||||
}
|
||||
|
||||
private static final String PERMISSION = "chancery.sign.lock";
|
||||
@Getter
|
||||
private final Permission permission = new Permission(
|
||||
PERMISSION,
|
||||
"Allows players to lock item signatures");
|
||||
|
||||
public Collection<Permission> permissions() {
|
||||
return Set.of(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("lock")
|
||||
.withPermission(PERMISSION)
|
||||
.executesPlayer((sender, _) -> {
|
||||
execute(sender);
|
||||
});
|
||||
}
|
||||
|
||||
public void execute(Player player) throws WrapperCommandSyntaxException {
|
||||
var localization = lFactory.service(player.locale());
|
||||
|
||||
var item = handItem(player);
|
||||
if (item.getType() == Material.AIR)
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_lock.fail.no_item")));
|
||||
|
||||
try (var signatures = sFactory.service(item)) {
|
||||
if (signatures.signatureLock())
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_lock.fail.signatures_locked")));
|
||||
|
||||
signatures.signatureLock(false);
|
||||
}
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign_lock.success.locked"),
|
||||
SignCommand.itemTag(item)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.axolotsh.chancery.modules.signature.commands;
|
||||
|
||||
import static org.axolotsh.pluginutils.CommandUtils.failCommand;
|
||||
import static org.axolotsh.pluginutils.ComponentUtils.component;
|
||||
import static org.axolotsh.pluginutils.InventoryUtils.handItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.axolotsh.chancery.modules.signature.SignatureFactory;
|
||||
import org.axolotsh.localizationlib.abstraction.ILocalizationFactory;
|
||||
import org.axolotsh.pluginutils.dependency_injection.entities.BaseCommand;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@AllArgsConstructor(onConstructor_ = @Inject)
|
||||
public class SignUnlockCommand extends BaseCommand {
|
||||
private final ILocalizationFactory lFactory;
|
||||
private final SignatureFactory sFactory;
|
||||
|
||||
@Override
|
||||
public Class<? extends BaseCommand> parentCommand() {
|
||||
return SignCommand.class;
|
||||
}
|
||||
|
||||
private static final String PERMISSION = "chancery.sign.unlock";
|
||||
@Getter
|
||||
private final Permission permission = new Permission(
|
||||
PERMISSION,
|
||||
"Allows players to unlock item signatures");
|
||||
|
||||
public Collection<Permission> permissions() {
|
||||
return Set.of(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandAPICommand command() {
|
||||
return new CommandAPICommand("unlock")
|
||||
.withPermission(PERMISSION)
|
||||
.executesPlayer((sender, _) -> {
|
||||
execute(sender);
|
||||
});
|
||||
}
|
||||
|
||||
public void execute(Player player) throws WrapperCommandSyntaxException {
|
||||
var localization = lFactory.service(player.locale());
|
||||
|
||||
var item = handItem(player);
|
||||
if (item.getType() == Material.AIR)
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_unlock.fail.no_item")));
|
||||
|
||||
try (var signatures = sFactory.service(item)) {
|
||||
if (!signatures.signatureLock())
|
||||
throw failCommand(component(
|
||||
localization.translate("command.sign_unlock.fail.signatures_unlocked")));
|
||||
|
||||
signatures.signatureLock(true);
|
||||
}
|
||||
player.sendMessage(component(
|
||||
localization.translate("command.sign_unlock.success.unlocked"),
|
||||
SignCommand.itemTag(item)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package org.axolotsh.chancery.modules.signature.entities;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.persistence.PersistentDataAdapterContext;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SignatureDataType implements PersistentDataType<byte[], SignatureInfo> {
|
||||
public static final SignatureDataType INSTANCE = new SignatureDataType();
|
||||
|
||||
private SignatureDataType() {
|
||||
};
|
||||
|
||||
@Override
|
||||
public @NotNull Class<byte[]> getPrimitiveType() {
|
||||
return byte[].class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Class<SignatureInfo> getComplexType() {
|
||||
return SignatureInfo.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte @NotNull [] toPrimitive(@NotNull SignatureInfo complex, @NotNull PersistentDataAdapterContext context) {
|
||||
var baos = new ByteArrayOutputStream();
|
||||
try (var dos = new DataOutputStream(baos)) {
|
||||
var uuid = complex.owner();
|
||||
dos.writeLong(uuid.getMostSignificantBits());
|
||||
dos.writeLong(uuid.getLeastSignificantBits());
|
||||
|
||||
dos.writeLong(complex.creationTime().getEpochSecond());
|
||||
|
||||
dos.writeBoolean(complex.anonymous());
|
||||
|
||||
var message = complex.message();
|
||||
dos.writeUTF(message == null ? "" : message);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SignatureInfo fromPrimitive(byte @NotNull [] primitive,
|
||||
@NotNull PersistentDataAdapterContext context) {
|
||||
var bais = new ByteArrayInputStream(primitive);
|
||||
try (var dis = new DataInputStream(bais)) {
|
||||
var mostSignificantBits = dis.readLong();
|
||||
var leastSignificantBits = dis.readLong();
|
||||
var uuid = new UUID(mostSignificantBits, leastSignificantBits);
|
||||
|
||||
var creationTime = Instant.ofEpochSecond(dis.readLong());
|
||||
|
||||
var anonymous = dis.readBoolean();
|
||||
|
||||
var message = dis.readUTF();
|
||||
if (message == "")
|
||||
message = null;
|
||||
|
||||
return new SignatureInfo(uuid, creationTime, message, anonymous);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package org.axolotsh.chancery.modules.signature.entities;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.axolotsh.pluginutils.ComponentUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Formatter;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
@Getter
|
||||
@Accessors(chain = true, fluent = true)
|
||||
@Builder(toBuilder = true)
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
@EqualsAndHashCode
|
||||
public class SignatureInfo {
|
||||
@NonNull
|
||||
private UUID owner;
|
||||
|
||||
public OfflinePlayer playerOwner() {
|
||||
return Bukkit.getOfflinePlayer(owner);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Builder.Default
|
||||
@EqualsAndHashCode.Exclude
|
||||
private Instant creationTime = Instant.now();
|
||||
|
||||
@Nullable
|
||||
private String message;
|
||||
@Builder.Default
|
||||
private boolean anonymous = false;
|
||||
|
||||
public static class SignatureInfoBuilder {
|
||||
public SignatureInfoBuilder owner(OfflinePlayer owner) {
|
||||
return owner(owner.getUniqueId());
|
||||
}
|
||||
|
||||
public SignatureInfoBuilder owner(UUID owner) {
|
||||
this.owner = owner;
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private MiniMessageTags $tags = new MiniMessageTags();
|
||||
|
||||
public Component component(String miniMessage) {
|
||||
return ComponentUtils.component(miniMessage, $tags.tags());
|
||||
}
|
||||
|
||||
private class MiniMessageTags {
|
||||
public TagResolver[] tags() {
|
||||
return new TagResolver[] {
|
||||
ownerTag(),
|
||||
ownerNameTag(),
|
||||
ownerUUIDTag(),
|
||||
|
||||
creationTimeTag(),
|
||||
|
||||
messageTag(),
|
||||
anonymousTag() };
|
||||
}
|
||||
|
||||
public TagResolver ownerTag() {
|
||||
if (anonymous)
|
||||
return Placeholder
|
||||
.parsed("owner", anonymousName());
|
||||
return Placeholder
|
||||
.component("owner", ComponentUtils.component(playerOwner()));
|
||||
}
|
||||
|
||||
public TagResolver ownerNameTag() {
|
||||
if (anonymous)
|
||||
return Placeholder
|
||||
.parsed("owner_name", anonymousName());
|
||||
return Placeholder
|
||||
.unparsed("owner_name", playerOwner().getName());
|
||||
}
|
||||
|
||||
public TagResolver ownerUUIDTag() {
|
||||
return Placeholder
|
||||
.unparsed("owner_uuid", owner.toString());
|
||||
}
|
||||
|
||||
public TagResolver creationTimeTag() {
|
||||
return Formatter
|
||||
.date("creation-time", creationTime);
|
||||
}
|
||||
|
||||
public TagResolver messageTag() {
|
||||
return Placeholder
|
||||
.unparsed("message", message == null ? "" : message);
|
||||
}
|
||||
|
||||
public TagResolver anonymousTag() {
|
||||
return TagResolver.resolver("anonymous", (args, context) -> {
|
||||
var message = args.pop().value();
|
||||
return Tag.preProcessParsed(message);
|
||||
});
|
||||
}
|
||||
|
||||
private static String anonymousName() {
|
||||
return "<obf>" + randomString('#', 4, 8) + "</obf>";
|
||||
}
|
||||
|
||||
private static String randomString(char character, int min, int max) {
|
||||
int length = ThreadLocalRandom.current().nextInt(min, max);
|
||||
return String.valueOf(character).repeat(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
43
chancery/src/main/resources/locales/en-US.jsonc
Normal file
43
chancery/src/main/resources/locales/en-US.jsonc
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
//#region Commands
|
||||
//#region Sign Command
|
||||
"command.reload.success.reloading": "Reloading Chancery...",
|
||||
"command.reload.success.reloaded": "Plugin reloaded!",
|
||||
//#endregion
|
||||
//#region Sign Command
|
||||
"command.sign.fail.no_item": "There is no item to sign!",
|
||||
"command.sign.fail.already_signed": "You have already signed this item!",
|
||||
"command.sign.fail.cant_be_signed": "This item cannot be signed!",
|
||||
"command.sign.success.signed": "You have signed the <item>.",
|
||||
"command.sign.success.edited": "You have changed your signature on the <item>.",
|
||||
//#endregion
|
||||
//#region Sign Lock Command
|
||||
"command.sign_list.fail.no_item": "There is no item to lock!",
|
||||
"command.sign_list.fail.not_signet": "There is no signature on <item>!",
|
||||
"command.sign_list.success.list_entry": "<hover:show_text:'<message>'><owner_name></hover>",
|
||||
"command.sign_list.success.list_title": "<item>:",
|
||||
"command.sign_list.success.list_content": "<index> - <signature>",
|
||||
"command.sign_list.success.list_footer": "There is <count> signature(s).",
|
||||
//#endregion
|
||||
//#region Sign Clear Command
|
||||
"command.sign_clear.fail.no_item": "There is no item to clear!",
|
||||
"command.sign_clear.fail.not_signet": "There is no signature on <item>!",
|
||||
"command.sign_clear.fail.cant_be_signed": "This item can't be cleared!",
|
||||
"command.sign_clear.success.cleared": "You cleared <item>.",
|
||||
//#endregion
|
||||
//#region Sign Lock Command
|
||||
"command.sign_lock.fail.no_item": "There is no item to lock!",
|
||||
"command.sign_lock.fail.already_locked": "This item is already locked!",
|
||||
"command.sign_lock.success.locked": "You locked <item>.",
|
||||
//#endregion
|
||||
//#region Sign Unlock Command
|
||||
"command.sign_unlock.fail.no_item": "There is no item to unlock!",
|
||||
"command.sign_unlock.fail.not_locked": "This item is not locked!",
|
||||
"command.sign_unlock.success.unlocked": "You unlocked <item>.",
|
||||
//#endregion
|
||||
//#region Signature
|
||||
"signature": "<gradient:green:blue>Signature: <owner></gradient>",
|
||||
"signature.description": "<message>\n\n<gray></gray>"
|
||||
//#endregion
|
||||
//#endregion
|
||||
}
|
||||
43
chancery/src/main/resources/locales/ru-RU.jsonc
Normal file
43
chancery/src/main/resources/locales/ru-RU.jsonc
Normal file
@@ -0,0 +1,43 @@
|
||||
{ //TODO: Add RU localization
|
||||
//#region Commands
|
||||
//#region Sign Command
|
||||
"command.reload.success.reloading": "Reloading Chancery...",
|
||||
"command.reload.success.reloaded": "Plugin reloaded!",
|
||||
//#endregion
|
||||
//#region Sign Command
|
||||
"command.sign.fail.no_item": "There is no item to sign!",
|
||||
"command.sign.fail.already_signed": "You have already signed this item!",
|
||||
"command.sign.fail.cant_be_signed": "This item cannot be signed!",
|
||||
"command.sign.success.signed": "You have signed the <item>.",
|
||||
"command.sign.success.edited": "You have changed your signature on the <item>.",
|
||||
//#endregion
|
||||
//#region Sign Lock Command
|
||||
"command.sign_list.fail.no_item": "There is no item to lock!",
|
||||
"command.sign_list.fail.not_signet": "There is no signature on <item>!",
|
||||
"command.sign_list.success.list_entry": "<hover:show_text:'<message>'><owner_name></hover>",
|
||||
"command.sign_list.success.list_title": "<item>:",
|
||||
"command.sign_list.success.list_content": "<index> - <signature>",
|
||||
"command.sign_list.success.list_footer": "There is <count> signature(s).",
|
||||
//#endregion
|
||||
//#region Sign Clear Command
|
||||
"command.sign_clear.fail.no_item": "There is no item to clear!",
|
||||
"command.sign_clear.fail.not_signet": "There is no signature on <item>!",
|
||||
"command.sign_clear.fail.cant_be_signed": "This item can't be cleared!",
|
||||
"command.sign_clear.success.cleared": "You cleared <item>.",
|
||||
//#endregion
|
||||
//#region Sign Lock Command
|
||||
"command.sign_lock.fail.no_item": "There is no item to lock!",
|
||||
"command.sign_lock.fail.already_locked": "This item is already locked!",
|
||||
"command.sign_lock.success.locked": "You locked <item>.",
|
||||
//#endregion
|
||||
//#region Sign Unlock Command
|
||||
"command.sign_unlock.fail.no_item": "There is no item to unlock!",
|
||||
"command.sign_unlock.fail.not_locked": "This item is not locked!",
|
||||
"command.sign_unlock.success.unlocked": "You unlocked <item>.",
|
||||
//#endregion
|
||||
//#region Signature
|
||||
"signature": "<gradient:green:blue>Signature: <owner></gradient>",
|
||||
"signature.description": "<message>\n\n<gray></gray>"
|
||||
//#endregion
|
||||
//#endregion
|
||||
}
|
||||
17
chancery/src/main/resources/paper-plugin.yml
Executable file
17
chancery/src/main/resources/paper-plugin.yml
Executable file
@@ -0,0 +1,17 @@
|
||||
name: Chancery
|
||||
description: ${description}
|
||||
prefix: Chancery
|
||||
version: ${version}
|
||||
|
||||
main: org.axolotsh.chancery.Plugin
|
||||
api-version: '26.1.2'
|
||||
load: POSTWORLD
|
||||
|
||||
authors: [ AXOLOTsh ]
|
||||
website: https://github.com/AXOLOTsh
|
||||
|
||||
dependencies:
|
||||
server:
|
||||
CommandAPI:
|
||||
load: BEFORE
|
||||
required: true
|
||||
11
chancery/src/main/resources/plugin.yml
Executable file
11
chancery/src/main/resources/plugin.yml
Executable file
@@ -0,0 +1,11 @@
|
||||
name: Chancery
|
||||
description: ${description}
|
||||
prefix: Chancery
|
||||
version: ${version}
|
||||
|
||||
main: org.axolotsh.chancery.Plugin
|
||||
api-version: '26.1.2'
|
||||
load: POSTWORLD
|
||||
|
||||
authors: [ AXOLOTsh ]
|
||||
website: https://github.com/AXOLOTsh
|
||||
6
gradle.properties
Normal file
6
gradle.properties
Normal file
@@ -0,0 +1,6 @@
|
||||
group=io.github.axolotsh
|
||||
version=0.1
|
||||
description=TODO
|
||||
org.gradle.configuration-cache=true
|
||||
org.gradle.parallel=true
|
||||
org.gradle.caching=true
|
||||
12
gradle/libs.versions.toml
Normal file
12
gradle/libs.versions.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
# This file was generated by the Gradle 'init' task.
|
||||
# https://docs.gradle.org/current/userguide/version_catalogs.html#sec::toml-dependencies-format
|
||||
|
||||
[versions]
|
||||
commons-math3 = "3.6.1"
|
||||
guava = "33.5.0-jre"
|
||||
junit-jupiter = "6.0.1"
|
||||
|
||||
[libraries]
|
||||
commons-math3 = { module = "org.apache.commons:commons-math3", version.ref = "commons-math3" }
|
||||
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
Binary file not shown.
9
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
9
gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
|
||||
networkTimeout=10000
|
||||
retries=0
|
||||
retryBackOffMs=500
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
248
gradlew
vendored
Executable file
248
gradlew
vendored
Executable file
@@ -0,0 +1,248 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/<unknown>/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
82
gradlew.bat
vendored
Normal file
82
gradlew.bat
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables, and ensure extensions are enabled
|
||||
setlocal EnableExtensions
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
"%COMSPEC%" /c exit 1
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
|
||||
@rem which allows us to clear the local environment before executing the java command
|
||||
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
|
||||
|
||||
:exitWithErrorLevel
|
||||
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
|
||||
"%COMSPEC%" /c exit %ERRORLEVEL%
|
||||
2
settings.gradle.kts
Normal file
2
settings.gradle.kts
Normal file
@@ -0,0 +1,2 @@
|
||||
rootProject.name = "Chancery"
|
||||
include("chancery")
|
||||
Reference in New Issue
Block a user