Rename package name from org.zhdev to net.zhira
This commit is contained in:
parent
cc7f16f941
commit
6ab7e89561
61 changed files with 314 additions and 192 deletions
16
README.md
16
README.md
|
|
@ -2,15 +2,15 @@
|
|||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>zhdev-repo</id>
|
||||
<url>https://maven.zhdev.org/repository/</url>
|
||||
<id>zhira-repo</id>
|
||||
<url>https://maven.zhira.net/repository/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
```
|
||||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<artifactId>all</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
```java
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.zhdev.varioutil.ReflectionUtils;
|
||||
import net.zhira.varioutil.ReflectionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class BukkitFields {
|
||||
|
|
@ -53,7 +53,7 @@ public class BukkitFields {
|
|||
```xml
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<artifactId>io</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
|
@ -62,8 +62,8 @@ public class BukkitFields {
|
|||
#### Code
|
||||
|
||||
```java
|
||||
import org.zhdev.varioutil.Config;
|
||||
import org.zhdev.varioutil.YamlConfig;
|
||||
import net.zhira.varioutil.Config;
|
||||
import net.zhira.varioutil.YamlConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
|
@ -44,7 +47,7 @@
|
|||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil;
|
||||
package net.zhira.varioutil;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
package org.zhdev.varioutil;
|
||||
package net.zhira.varioutil;
|
||||
|
||||
import net.zhira.varioutil.language.Language;
|
||||
import net.zhira.varioutil.util.CollectionUtils;
|
||||
import net.zhira.varioutil.util.ColorUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginIdentifiableCommand;
|
||||
|
|
@ -9,17 +12,14 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.zhdev.varioutil.bukkit.command.PreparedPluginCommand;
|
||||
import org.zhdev.varioutil.config.BukkitYamlConfig;
|
||||
import org.zhdev.varioutil.config.Config;
|
||||
import org.zhdev.varioutil.config.ConfigSection;
|
||||
import org.zhdev.varioutil.config.YamlConfig;
|
||||
import org.zhdev.varioutil.language.Language;
|
||||
import org.zhdev.varioutil.sql.SqlAdapter;
|
||||
import org.zhdev.varioutil.util.BukkitUtils;
|
||||
import org.zhdev.varioutil.util.CollectionUtils;
|
||||
import org.zhdev.varioutil.util.ColorUtils;
|
||||
import org.zhdev.varioutil.util.ConfigUtils;
|
||||
import net.zhira.varioutil.bukkit.command.PreparedPluginCommand;
|
||||
import net.zhira.varioutil.config.BukkitYamlConfig;
|
||||
import net.zhira.varioutil.config.Config;
|
||||
import net.zhira.varioutil.config.ConfigSection;
|
||||
import net.zhira.varioutil.config.YamlConfig;
|
||||
import net.zhira.varioutil.sql.SqlAdapter;
|
||||
import net.zhira.varioutil.util.BukkitUtils;
|
||||
import net.zhira.varioutil.util.ConfigUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit;
|
||||
package net.zhira.varioutil.bukkit;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.command;
|
||||
package net.zhira.varioutil.bukkit.command;
|
||||
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.command;
|
||||
package net.zhira.varioutil.bukkit.command;
|
||||
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.zhdev.varioutil.config.ConfigSection;
|
||||
import net.zhira.varioutil.config.ConfigSection;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.zhdev.varioutil.util.BukkitUtils;
|
||||
import net.zhira.varioutil.util.BukkitUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import net.zhira.varioutil.config.ConfigSection;
|
||||
import net.zhira.varioutil.util.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.zhdev.varioutil.bukkit.LegacyMaterial;
|
||||
import org.zhdev.varioutil.config.ConfigSection;
|
||||
import org.zhdev.varioutil.util.StringUtils;
|
||||
import net.zhira.varioutil.bukkit.LegacyMaterial;
|
||||
|
||||
public class GuiIconConfig {
|
||||
protected final Material type;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.bukkit.gui;
|
||||
package net.zhira.varioutil.bukkit.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
package net.zhira.varioutil.util;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class BukkitReflectionUtils {
|
||||
private static final String OBC_PACKAGE = Bukkit.getServer().getClass().getPackage().getName();
|
||||
|
||||
private static final Class<?> __CraftServer__CLASS = ReflectionUtils.searchType(OBC_PACKAGE + ".CraftServer");
|
||||
private static final Class<?> __CraftMetaSkull__CLASS = ReflectionUtils.searchType(OBC_PACKAGE + ".inventory.CraftMetaSkull");
|
||||
|
||||
private static final Field __commandMap__CraftServer__FIELD = ReflectionUtils.fieldSearcher()
|
||||
.type(__CraftServer__CLASS)
|
||||
.fieldOf("commandMap")
|
||||
.fieldType(CommandMap.class)
|
||||
.search();
|
||||
private static final Field __knownCommands__SimpleCommandMap__FIELD = ReflectionUtils.fieldSearcher()
|
||||
.type(SimpleCommandMap.class)
|
||||
.fieldOf("knownCommands")
|
||||
.fieldType(Map.class)
|
||||
.search();
|
||||
|
||||
private static final GameProfileConsumer GAME_PROFILE_CONSUMER;
|
||||
|
||||
static CommandMap getCommandMap() {
|
||||
return (CommandMap) ReflectionUtils.getFieldValue(Bukkit.getServer(), __commandMap__CraftServer__FIELD);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Map<String, Command> getKnownCommands() {
|
||||
return (Map<String, Command>) ReflectionUtils.getFieldValue(getCommandMap(), __knownCommands__SimpleCommandMap__FIELD);
|
||||
}
|
||||
|
||||
static void setProfile(SkullMeta meta, GameProfile profile) {
|
||||
GAME_PROFILE_CONSUMER.accept(meta, profile);
|
||||
}
|
||||
|
||||
private interface GameProfileConsumer {
|
||||
void accept(SkullMeta meta, GameProfile profile);
|
||||
}
|
||||
|
||||
private static class ModernGameProfileConsumer implements GameProfileConsumer {
|
||||
private final Class<?> __ResolvableProfile_CLASS = ReflectionUtils.getType("net.minecraft.world.item.component.ResolvableProfile");
|
||||
private final Constructor<?> __ResolvableProfile_CONSTRUCTOR;
|
||||
protected final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.methodSearcher()
|
||||
.type(__CraftMetaSkull__CLASS)
|
||||
.methodOf("setProfile")
|
||||
.parameters(__ResolvableProfile_CLASS)
|
||||
.returns(void.class)
|
||||
.search();
|
||||
|
||||
ModernGameProfileConsumer() {
|
||||
Constructor<?> resolvableConstructor;
|
||||
try {
|
||||
resolvableConstructor = __ResolvableProfile_CLASS.getConstructor(GameProfile.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new NoSuchMethodError("Cannot get constructor of " + __ResolvableProfile_CLASS);
|
||||
}
|
||||
__ResolvableProfile_CONSTRUCTOR = resolvableConstructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(SkullMeta meta, GameProfile profile) {
|
||||
try {
|
||||
Object resolvableProfile = __ResolvableProfile_CONSTRUCTOR.newInstance(profile);
|
||||
ReflectionUtils.invokeMethod(meta, __setProfile__CraftMetaSkull__METHOD, resolvableProfile);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class LegacyGameProfileConsumer implements GameProfileConsumer {
|
||||
protected final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.methodSearcher()
|
||||
.type(__CraftMetaSkull__CLASS)
|
||||
.methodOf("setProfile")
|
||||
.parameters(GameProfile.class)
|
||||
.returns(void.class)
|
||||
.search();
|
||||
|
||||
@Override
|
||||
public void accept(SkullMeta meta, GameProfile profile) {
|
||||
ReflectionUtils.invokeMethod(meta, __setProfile__CraftMetaSkull__METHOD, profile);
|
||||
}
|
||||
}
|
||||
|
||||
private static class AncientGameProfileConsumer implements GameProfileConsumer {
|
||||
private final Field __profile__CraftMetaSkull__FIELD = ReflectionUtils.fieldSearcher()
|
||||
.type(__CraftMetaSkull__CLASS)
|
||||
.fieldOf("profile")
|
||||
.fieldType(GameProfile.class)
|
||||
.search();
|
||||
|
||||
@Override
|
||||
public void accept(SkullMeta meta, GameProfile profile) {
|
||||
ReflectionUtils.setFieldValue(meta, __profile__CraftMetaSkull__FIELD, profile);
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static GameProfileConsumer tryCreateGameProfileConsumer(Supplier<GameProfileConsumer>... suppliers) {
|
||||
List<String> errorMessages = new ArrayList<>();
|
||||
for (Supplier<GameProfileConsumer> supplier : suppliers) {
|
||||
try {
|
||||
return supplier.get();
|
||||
} catch (Exception | Error e) {
|
||||
errorMessages.add(e.getClass() + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Cannot create GameProfileConsumer: " + String.join("; ", errorMessages));
|
||||
}
|
||||
|
||||
static {
|
||||
GAME_PROFILE_CONSUMER = tryCreateGameProfileConsumer(
|
||||
ModernGameProfileConsumer::new,
|
||||
LegacyGameProfileConsumer::new,
|
||||
AncientGameProfileConsumer::new
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.zhira.varioutil.Version;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
|
|
@ -9,15 +10,11 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.zhdev.varioutil.Version;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class BukkitUtils {
|
||||
|
|
@ -28,6 +25,8 @@ public class BukkitUtils {
|
|||
|
||||
private static final Map<String, GameProfile> PROFILE_CACHE = new HashMap<>();
|
||||
|
||||
private static final String PROFILE_NAME_CHARACTERS = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890_";
|
||||
|
||||
public static Command getCommand(String label) {
|
||||
return KNOWN_COMMANDS.get(label);
|
||||
}
|
||||
|
|
@ -55,7 +54,12 @@ public class BukkitUtils {
|
|||
public static void setSkullTexture(SkullMeta meta, String base64) {
|
||||
GameProfile profile = PROFILE_CACHE.get(base64);
|
||||
if (profile == null) {
|
||||
profile = new GameProfile(UUID.randomUUID(), base64);
|
||||
Random random = new Random();
|
||||
char[] buffer = new char[16];
|
||||
for (int i = 0; i < 16; i++) {
|
||||
buffer[i] = PROFILE_NAME_CHARACTERS.charAt(random.nextInt(PROFILE_NAME_CHARACTERS.length()));
|
||||
}
|
||||
profile = new GameProfile(UUID.randomUUID(), String.valueOf(buffer));
|
||||
profile.getProperties().put("textures", new Property("textures", base64));
|
||||
PROFILE_CACHE.put(base64, profile);
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.zhdev.varioutil.util.ReflectionUtils.*;
|
||||
|
||||
class BukkitReflectionUtils {
|
||||
private static final String VERSION = Bukkit.getServer().getClass().getName().split("\\.")[3];
|
||||
|
||||
private static final Class<?> __CraftServer__CLASS = searchType("org.bukkit.craftbukkit." + VERSION + ".CraftServer");
|
||||
|
||||
private static final Method __setProfile__CraftMetaSkull__METHOD = ReflectionUtils.methodSearcher()
|
||||
.typeOf("org.bukkit.craftbukkit." + VERSION + ".inventory.CraftMetaSkull")
|
||||
.methodOf("setProfile")
|
||||
.parameters(GameProfile.class)
|
||||
.returns(void.class)
|
||||
.search();
|
||||
|
||||
private static final Field __commandMap__CraftServer__FIELD = fieldSearcher()
|
||||
.fieldOf("commandMap")
|
||||
.type(__CraftServer__CLASS)
|
||||
.fieldType(CommandMap.class)
|
||||
.search();
|
||||
private static final Field __knownCommands__SimpleCommandMap__FIELD = fieldSearcher()
|
||||
.fieldOf("knownCommands")
|
||||
.type(SimpleCommandMap.class)
|
||||
.fieldType(Map.class)
|
||||
.search();
|
||||
|
||||
static CommandMap getCommandMap() {
|
||||
return (CommandMap) getFieldValue(__commandMap__CraftServer__FIELD, Bukkit.getServer());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static Map<String, Command> getKnownCommands() {
|
||||
return (Map<String, Command>) getFieldValue(__knownCommands__SimpleCommandMap__FIELD, getCommandMap());
|
||||
}
|
||||
|
||||
static void setProfile(SkullMeta meta, GameProfile profile) {
|
||||
ReflectionUtils.invokeMethod(meta, __setProfile__CraftMetaSkull__METHOD, profile);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil;
|
||||
package net.zhira.varioutil;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.language;
|
||||
package net.zhira.varioutil.language;
|
||||
|
||||
import org.zhdev.varioutil.util.StringUtils;
|
||||
import net.zhira.varioutil.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.reflection;
|
||||
package net.zhira.varioutil.reflection;
|
||||
|
||||
import org.zhdev.varioutil.util.ReflectionUtils;
|
||||
import net.zhira.varioutil.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ public class FieldSearcher {
|
|||
}
|
||||
|
||||
public Object get() {
|
||||
return ReflectionUtils.getFieldValue(search(), instance);
|
||||
return ReflectionUtils.getFieldValue(instance, search());
|
||||
}
|
||||
|
||||
public <T> T get(Class<T> type) {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.reflection;
|
||||
package net.zhira.varioutil.reflection;
|
||||
|
||||
import org.zhdev.varioutil.util.ReflectionUtils;
|
||||
import net.zhira.varioutil.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.Function;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
public class EnumUtils {
|
||||
private static <T extends Enum<T>> T[] getValues(T eNum) {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import org.zhdev.varioutil.reflection.FieldSearcher;
|
||||
import org.zhdev.varioutil.reflection.MethodSearcher;
|
||||
import net.zhira.varioutil.reflection.FieldSearcher;
|
||||
import net.zhira.varioutil.reflection.MethodSearcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -61,7 +61,8 @@ public class ReflectionUtils {
|
|||
for (String typeName : typeNames) {
|
||||
try {
|
||||
return Class.forName(typeName);
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoClassDefFoundError(String.join(", ", typeNames));
|
||||
|
|
@ -81,7 +82,8 @@ public class ReflectionUtils {
|
|||
for (String typeName : typeNames) {
|
||||
try {
|
||||
return Class.forName(packageName + '.' + typeName);
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +105,8 @@ public class ReflectionUtils {
|
|||
return checkMethodType(getMethod0(type, methodName, parameterTypes), returnType);
|
||||
} catch (IllegalStateException e) {
|
||||
exception = e;
|
||||
} catch (NoSuchMethodException ignored) { }
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (parameterTypes.length > 0) {
|
||||
|
|
@ -144,7 +147,8 @@ public class ReflectionUtils {
|
|||
return checkFieldType(getField0(type, fieldName), fieldType);
|
||||
} catch (IllegalStateException e) {
|
||||
exception = e;
|
||||
} catch (NoSuchFieldException ignored) {}
|
||||
} catch (NoSuchFieldException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (exception != null) {
|
||||
|
|
@ -154,7 +158,7 @@ public class ReflectionUtils {
|
|||
throw new NoSuchFieldError(String.join(", ", fieldNames) + " in " + type);
|
||||
}
|
||||
|
||||
public static Object getFieldValue(Field field, Object instance) throws IllegalStateException {
|
||||
public static Object getFieldValue(Object instance, Field field) throws IllegalStateException {
|
||||
try {
|
||||
return field.get(instance);
|
||||
} catch (IllegalAccessException e) {
|
||||
|
|
@ -162,7 +166,7 @@ public class ReflectionUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static void setFieldValue(Field field, Object instance, Object value) throws IllegalStateException {
|
||||
public static void setFieldValue(Object instance, Field field, Object value) throws IllegalStateException {
|
||||
try {
|
||||
field.set(instance, value);
|
||||
} catch (IllegalAccessException e) {
|
||||
|
|
@ -186,7 +190,8 @@ public class ReflectionUtils {
|
|||
if (packagePath.equals(packageName)) {
|
||||
try {
|
||||
consumer.accept(loader.loadClass(link));
|
||||
} catch (ClassNotFoundException ignored) {}
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import org.zhdev.varioutil.util.SqlUtils;
|
||||
import net.zhira.varioutil.util.SqlUtils;
|
||||
|
||||
public class H2Provider extends AbstractProvider {
|
||||
public H2Provider(String path, String username, String password) {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import org.zhdev.varioutil.util.SqlUtils;
|
||||
import net.zhira.varioutil.util.SqlUtils;
|
||||
|
||||
public class MysqlProvider extends AbstractProvider {
|
||||
public MysqlProvider(String address, String dbname, String username, String password, boolean ssl) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import org.zhdev.varioutil.util.CheckedFunction;
|
||||
import net.zhira.varioutil.util.CheckedFunction;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
public class SqlException extends RuntimeException {
|
||||
public SqlException() {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.sql;
|
||||
package net.zhira.varioutil.sql;
|
||||
|
||||
import org.zhdev.varioutil.util.SqlUtils;
|
||||
import net.zhira.varioutil.util.SqlUtils;
|
||||
|
||||
public class SqliteProvider extends AbstractProvider {
|
||||
public SqliteProvider(String path) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CheckedFunction<T, R, E extends Exception> {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import org.zhdev.varioutil.sql.SqlException;
|
||||
import net.zhira.varioutil.sql.SqlException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
|
@ -42,14 +42,14 @@ public class SqlUtils {
|
|||
try {
|
||||
Connection connection;
|
||||
if (username != null) {
|
||||
connection = DriverManager.getConnection("jdbc:h2:./" + encodeUrlValue(path) + ";mode=MySQL;AUTO_SERVER=TRUE", username, password);
|
||||
connection = DriverManager.getConnection("jdbc:h2:./" + path + ";mode=MySQL;AUTO_SERVER=TRUE", username, password);
|
||||
} else {
|
||||
connection = DriverManager.getConnection("jdbc:h2:./" + encodeUrlValue(path) + ";mode=MySQL;AUTO_SERVER=TRUE", "sa", "");
|
||||
connection = DriverManager.getConnection("jdbc:h2:./" + path + ";mode=MySQL;AUTO_SERVER=TRUE", "sa", "");
|
||||
}
|
||||
return connection;
|
||||
} catch (NoClassDefFoundError e) {
|
||||
throw new SqlException("No suitable driver");
|
||||
} catch (SQLException | UnsupportedEncodingException e) {
|
||||
} catch (SQLException e) {
|
||||
throw new SqlException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -68,8 +68,8 @@ public class SqlUtils {
|
|||
}
|
||||
}
|
||||
try {
|
||||
return DriverManager.getConnection("jdbc:sqlite:" + encodeUrlValue(path.toString()));
|
||||
} catch (SQLException | UnsupportedEncodingException e) {
|
||||
return DriverManager.getConnection("jdbc:sqlite:" + path);
|
||||
} catch (SQLException e) {
|
||||
throw new SqlException(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
public class ConfigException extends RuntimeException {
|
||||
public ConfigException() {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
final class ConfigSectionNode {
|
||||
Object value;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.constructor.SafeConstructor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
|
@ -1,9 +1,12 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package org.zhdev.varioutil;
|
||||
package net.zhira.varioutil;
|
||||
|
||||
import org.zhdev.varioutil.config.Config;
|
||||
import org.zhdev.varioutil.config.ConfigException;
|
||||
import org.zhdev.varioutil.language.Language;
|
||||
import org.zhdev.varioutil.sql.SqlAdapter;
|
||||
import org.zhdev.varioutil.util.ResourceUtils;
|
||||
import net.zhira.varioutil.config.Config;
|
||||
import net.zhira.varioutil.config.ConfigException;
|
||||
import net.zhira.varioutil.language.Language;
|
||||
import net.zhira.varioutil.util.ResourceUtils;
|
||||
import net.zhira.varioutil.sql.SqlAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -26,7 +26,7 @@ public interface PreparedPlugin {
|
|||
|
||||
default Path loadConfig(Config config, String pathname, boolean resourcePreload) {
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
Path path = Paths.get(pathname);
|
||||
Path path = Paths.get(getDataDirectory().toString() + '/' + pathname);
|
||||
try (InputStream stream = ResourceUtils.getResource(pathname, classLoader)) {
|
||||
if (stream != null) {
|
||||
if (resourcePreload) {
|
||||
|
|
@ -1,13 +1,21 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ColorUtils {
|
||||
public static final char COLOR_CHAR = '§';
|
||||
|
||||
private static final Map<String, Pattern> COMPILED_PATTERNS = new HashMap<>();
|
||||
|
||||
private static Pattern getPattern(String regexp) {
|
||||
return COMPILED_PATTERNS.computeIfAbsent(regexp, s -> Pattern.compile(regexp));
|
||||
}
|
||||
|
||||
public static void translateAlternateColorCodes(StringBuilder builder, char replaceChar) {
|
||||
Matcher m = Pattern.compile(Pattern.quote(String.valueOf(replaceChar)) + "(#[0-9a-fA-F]{6})").matcher(builder);
|
||||
Matcher m = getPattern(Pattern.quote(String.valueOf(replaceChar)) + "(#[0-9a-fA-F]{6})").matcher(builder);
|
||||
int start = 0;
|
||||
while (m.find(start)) {
|
||||
String hex = m.group(1);
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package org.zhdev.varioutil.util;
|
||||
package net.zhira.varioutil.util;
|
||||
|
||||
import org.zhdev.varioutil.config.ConfigSection;
|
||||
import org.zhdev.varioutil.language.Language;
|
||||
import org.zhdev.varioutil.sql.*;
|
||||
import net.zhira.varioutil.config.ConfigSection;
|
||||
import net.zhira.varioutil.language.Language;
|
||||
import net.zhira.varioutil.sql.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
13
pom.xml
13
pom.xml
|
|
@ -1,7 +1,10 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
|
@ -23,8 +26,8 @@
|
|||
|
||||
<distributionManagement>
|
||||
<repository>
|
||||
<id>zhdev-repo</id>
|
||||
<url>https://maven.zhdev.org/repository/</url>
|
||||
<id>zhira-repo</id>
|
||||
<url>https://maven.zhira.net/repository/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
|
|
@ -72,7 +75,7 @@
|
|||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>repo
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
<project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>org.zhdev.varioutil</groupId>
|
||||
<groupId>net.zhira.varioutil</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil;
|
||||
package net.zhira.varioutil;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
package org.zhdev.varioutil;
|
||||
package net.zhira.varioutil;
|
||||
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.zhira.varioutil.config.ConfigSection;
|
||||
import net.zhira.varioutil.language.Language;
|
||||
import net.zhira.varioutil.util.ColorUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.zhdev.varioutil.config.Config;
|
||||
import org.zhdev.varioutil.config.ConfigSection;
|
||||
import org.zhdev.varioutil.config.VelocityTomlConfig;
|
||||
import org.zhdev.varioutil.language.Language;
|
||||
import org.zhdev.varioutil.sql.SqlAdapter;
|
||||
import org.zhdev.varioutil.util.ColorUtils;
|
||||
import org.zhdev.varioutil.util.ConfigUtils;
|
||||
import net.zhira.varioutil.config.Config;
|
||||
import net.zhira.varioutil.config.VelocityTomlConfig;
|
||||
import net.zhira.varioutil.sql.SqlAdapter;
|
||||
import net.zhira.varioutil.util.ConfigUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.zhdev.varioutil.config;
|
||||
package net.zhira.varioutil.config;
|
||||
|
||||
import com.electronwill.nightconfig.core.CommentedConfig;
|
||||
import com.electronwill.nightconfig.toml.TomlFormat;
|
||||
Loading…
Add table
Add a link
Reference in a new issue