-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Случайно было удалено из-за ошибки синхронизации в Intellij IDEA.
- Loading branch information
Showing
35 changed files
with
2,638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
package me.re4erka.lpmetaplus; | ||
|
||
import com.google.common.collect.Lists; | ||
import de.exlll.configlib.NameFormatters; | ||
import de.exlll.configlib.YamlConfigurationProperties; | ||
import de.exlll.configlib.YamlConfigurations; | ||
import dev.triumphteam.cmd.bukkit.BukkitCommandManager; | ||
import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; | ||
import dev.triumphteam.cmd.core.message.MessageKey; | ||
import dev.triumphteam.cmd.core.suggestion.SuggestionKey; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import me.re4erka.lpmetaplus.command.type.CustomCommand; | ||
import me.re4erka.lpmetaplus.command.type.MainCommand; | ||
import me.re4erka.lpmetaplus.configuration.ConfigurationMetas; | ||
import me.re4erka.lpmetaplus.manager.type.GroupManager; | ||
import me.re4erka.lpmetaplus.manager.type.MetaManager; | ||
import me.re4erka.lpmetaplus.message.Message; | ||
import me.re4erka.lpmetaplus.placeholder.MetaPlaceholder; | ||
import me.re4erka.lpmetaplus.plugin.BasePlugin; | ||
import me.re4erka.lpmetaplus.util.PluginEmulator; | ||
import net.luckperms.api.LuckPermsProvider; | ||
import net.luckperms.api.model.PermissionHolder; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.CommandSender; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public final class LPMetaPlus extends BasePlugin<LPMetaPlus> { | ||
|
||
@Accessors(fluent = true) | ||
private Settings settings; | ||
@Accessors(fluent = true) | ||
private Messages messages; | ||
|
||
private GroupManager groupManager; | ||
|
||
@Accessors(fluent = true) | ||
private ConfigurationMetas metas; | ||
private MetaManager metaManager; | ||
|
||
@Override | ||
public void enable() { | ||
initialize("MetaManager", plugin -> this.metaManager = new MetaManager(plugin)); | ||
initialize("GroupManager", plugin -> this.groupManager = new GroupManager(plugin)); | ||
|
||
initialize("Emulation", plugin -> { | ||
if (settings.emulation().enabled()) { | ||
settings.emulation().applyTo().forEach(emulation -> { | ||
if (Bukkit.getPluginManager().isPluginEnabled(emulation.getPluginName())) { | ||
logError("The " + emulation.getPluginName() + " plugin cannot be emulated as it is already running on the server. " | ||
+ "Please disable the " + emulation.getPluginName() + " plugin to make the emulation work correctly."); | ||
return; | ||
} | ||
|
||
if (settings.emulation().emulateLookupNames()) { | ||
PluginEmulator.emulate(emulation.getPluginName()); | ||
} | ||
|
||
emulation.load(plugin); | ||
logInfo(emulation.getPluginName() + " plugin is successfully emulated."); | ||
}); | ||
} | ||
}); | ||
|
||
initialize("MetaPlaceholder", plugin -> { | ||
if (isSupportPlaceholderAPI()) { | ||
new MetaPlaceholder(plugin).register(); | ||
} else { | ||
logNotFoundPlaceholderAPI(); | ||
} | ||
}); | ||
|
||
System.out.println("CoinsEngine isEnabled(): " + Bukkit.getPluginManager().isPluginEnabled("CoinsEngine")); | ||
System.out.println("PlayerPoints isEnabled(): " + Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")); | ||
|
||
Bukkit.getScheduler().runTaskLater(this, () -> { | ||
settings.emulation().applyTo().forEach(emulation -> { | ||
PluginEmulator.emulate(emulation.getPluginName()); | ||
}); | ||
|
||
System.out.println("CoinsEngine isEnabled(): " + Bukkit.getPluginManager().isPluginEnabled("CoinsEngine")); | ||
System.out.println("PlayerPoints isEnabled(): " + Bukkit.getPluginManager().isPluginEnabled("PlayerPoints")); | ||
}, 3); | ||
|
||
groupManager.load(metas); | ||
metaManager.registerWarningEvents(); | ||
} | ||
|
||
@Override | ||
protected void loadConfigurations() { | ||
final YamlConfigurationProperties properties = YamlConfigurationProperties.newBuilder() | ||
.charset(StandardCharsets.UTF_8) | ||
.setNameFormatter(NameFormatters.LOWER_UNDERSCORE) | ||
.addSerializer(Message.class, new Message.Serializer()) | ||
.build(); | ||
|
||
final Path dataFolder = getDataFolder().toPath(); | ||
this.settings = YamlConfigurations.update( | ||
dataFolder.resolve("config.yml"), | ||
Settings.class, properties | ||
); | ||
this.messages = YamlConfigurations.update( | ||
dataFolder.resolve("messages.yml"), | ||
Messages.class, properties | ||
); | ||
this.metas = YamlConfigurations.update( | ||
dataFolder.resolve("metas.yml"), | ||
ConfigurationMetas.class, properties | ||
); | ||
} | ||
|
||
@Override | ||
protected void registerCommands() { | ||
final BukkitCommandManager<CommandSender> manager = BukkitCommandManager.create(this); | ||
|
||
final Messages.Command messages = messages().command(); | ||
manager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, | ||
(sender, context) -> messages.tooManyArguments().send(sender)); | ||
manager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, | ||
(sender, context) -> messages.notEnoughArguments().send(sender)); | ||
manager.registerMessage(MessageKey.INVALID_ARGUMENT, | ||
(sender, context) -> messages.invalidArguments().send(sender)); | ||
manager.registerMessage(MessageKey.UNKNOWN_COMMAND, | ||
(sender, context) -> messages.unknownCommand().send(sender)); | ||
manager.registerMessage(BukkitMessageKey.NO_PERMISSION, | ||
(sender, context) -> messages.noPermission().send(sender)); | ||
|
||
manager.registerSuggestion( | ||
SuggestionKey.of("meta_types"), | ||
(sender, argument) -> metas.names() | ||
); | ||
manager.registerSuggestion( | ||
SuggestionKey.of("any_count"), | ||
(sender, argument) -> Lists.newArrayList("1", "10", "50", "100") | ||
); | ||
manager.registerSuggestion( | ||
SuggestionKey.of("loaded_user_names"), | ||
(sender, argument) -> LuckPermsProvider.get().getUserManager() | ||
.getLoadedUsers().stream() | ||
.map(PermissionHolder::getFriendlyName) | ||
.collect(Collectors.toList()) | ||
); | ||
|
||
manager.registerCommand(new MainCommand(this)); | ||
metas.types().entrySet().stream() | ||
.filter(entry -> entry.getValue().isCommandEnabled()) | ||
.forEach(entry -> manager.registerCommand( | ||
new CustomCommand(this, entry.getKey(), entry.getValue()))); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected LPMetaPlus self() { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.re4erka.lpmetaplus; | ||
|
||
import de.exlll.configlib.Configuration; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
import me.re4erka.lpmetaplus.message.Message; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
@SuppressWarnings("FieldMayBeFinal") | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class Messages { | ||
|
||
private Meta meta = new Meta(); | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
public static final class Meta { | ||
|
||
private Message get = Message.of("&fУ игрока &6%target% &fмета-данной &r%display_name% &fв количестве&8: &e%balance% %symbol%"); | ||
private Message set = Message.of("&fИгроку &6%target% &fбыло установлено мета-данной &r%display_name%&8: &e%balance% %symbol%"); | ||
private Message given = Message.of("&fИгроку &6%target% &fбыла выдана мета-данная &r%display_name%&8: &e%balance% %symbol%"); | ||
private Message taken = Message.of("&fИгроку &6%target% &fбыло отнято мета-данных &r%display_name%&8: &e%balance% %symbol%"); | ||
private Message reset = Message.of("&fИгроку &6%target% &fбыл сброшен баланс мета-данной &r%display_name%&f!"); | ||
|
||
private Message notFound = Message.of("&fВведенная вами мета-данная &cне была найдена&f!"); | ||
private Message unsignedNotSupported = Message.of("&fБеззнаковые значения &cне поддерживаются&f!"); | ||
} | ||
|
||
private Command command = new Command(); | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
public static final class Command { | ||
|
||
private Message unknownCommand = Message.of("&fВведенная вами команда &cне была найдена&f!"); | ||
private Message tooManyArguments = Message.of("&fВами введенно &cслишком много &fаргументов!"); | ||
private Message notEnoughArguments = Message.of("&fВами введенно &cнедостаточно &fаргументов!"); | ||
private Message invalidArguments = Message.of("&fВведенные вами аргументы &cнекорректны&f! Используйте &e/lpmetaplus help &fдля помощи"); | ||
|
||
private Message noPermission = Message.of("&fУ вас &cнедостаточно прав&f, чтобы использовать эту команду!"); | ||
|
||
private Message migrationInProgress = Message.of("&fМиграция из плагина &a%name% &fв процессе..."); | ||
private Message migrated = Message.of("&fПлагин &aуспешно мигрировал &fигроков &e%count% &fза &6%took%ms &fиз плагина &a%name%&f."); | ||
private Message migrationFailed = Message.of("&fМиграция из плагина &a%name% &fбыла &cпровалена&f! Заняло &6%took%ms"); | ||
|
||
private Message reloaded = Message.of("&fПлагин был &aуспешно перезагружен&f!"); | ||
private List<Message> help = Arrays.asList( | ||
Message.of("&fДоступные команды&8:"), | ||
Message.of("&8- &e/lpmetaplus get &f<тип> <ник>"), | ||
Message.of("&8- &e/lpmetaplus set &f<тип> <количество> <ник> &7(-silent)"), | ||
Message.of("&8- &e/lpmetaplus take &f<тип> <количество> <ник> &7(-silent)"), | ||
Message.of("&8- &e/lpmetaplus give &f<тип> <количество> <ник> &7(-silent)"), | ||
Message.of("&8- &e/lpmetaplus reload") | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package me.re4erka.lpmetaplus; | ||
|
||
import com.google.common.collect.Sets; | ||
import de.exlll.configlib.Comment; | ||
import de.exlll.configlib.Configuration; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
import me.re4erka.lpmetaplus.emulation.SupportedEmulation; | ||
|
||
import java.util.Set; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
@SuppressWarnings("FieldMayBeFinal") | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class Settings { | ||
|
||
@Comment({"Миграция с других плагинов на донатную валюту.", | ||
"Например: /lpmetaplus migrate PLAYER_POINTS SQLITE"}) | ||
private Migration migration = new Migration(); | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
public static final class Migration { | ||
|
||
@Comment({"Тип мета-данной по-умолчанию для миграции.", | ||
"Какой тип донатной валюты будет мигрироваться из плагина PlayerPoints?", | ||
"Требуется обязательно указать существующий тип плагина LPMetaPlus."}) | ||
private String defaultType = "RUBIES"; | ||
|
||
@Comment("Настройка подключения к базе-данных для миграции.") | ||
private Credentials credentials = new Credentials(); | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
public static final class Credentials { | ||
|
||
private String host = "localhost"; | ||
private int port = 3306; | ||
|
||
@Comment("Название базы-данных плагина для миграции.") | ||
private String database = "points"; | ||
private String username = "root"; | ||
private String password = "password"; | ||
} | ||
} | ||
|
||
@Comment({"Эмуляция методов из API других плагинов на донатную валюту.", | ||
"Не влияет на производительность."}) | ||
private Emulation emulation = new Emulation(); | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Configuration | ||
public static final class Emulation { | ||
|
||
@Comment("Включить ли эмуляцию других плагинов?") | ||
private boolean enabled = false; | ||
|
||
@Comment({"Какая мета будет по-дефолту для эмуляции?", | ||
"Необходимо указать для: PLAYER_POINTS"}) | ||
private String defaultMeta = "RUBIES"; | ||
|
||
@Comment({"Выполнять ли методы из эмуляции всегда принудительно в тихом режиме?", | ||
"Если включено, то не будет логгирования от LuckPerms в консоли."}) | ||
private boolean forcedSilent = false; | ||
|
||
@Comment({"Игнорировать ли методы которые нереализованы для эмуляции?", | ||
"Если включено, то не будет выбрасываться исключение NotEmulatedException."}) | ||
private boolean ignoreNotEmulatedMethods = false; | ||
|
||
@Comment({"Эмулировать список плагинов?", | ||
"Если включено, то будет вносить в список плагинов эмулированный плагин, что позволит ", | ||
"запускаться другим плагинам которые проверяют включен или нет эмулируемый плагин.", | ||
"Влияет на поведение метода PluginManager.isPluginEnabled()"}) | ||
private boolean emulateLookupNames = true; | ||
|
||
@Comment({"Список плагинов которые будут эмулироваться.", | ||
"Доступно: PLAYER_POINTS и COINS_ENGINE"}) | ||
private Set<SupportedEmulation> applyTo = Sets.newHashSet( | ||
SupportedEmulation.PLAYER_POINTS, SupportedEmulation.COINS_ENGINE); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/me/re4erka/lpmetaplus/action/MetaAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package me.re4erka.lpmetaplus.action; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
import me.re4erka.lpmetaplus.util.Key; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.time.Instant; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Builder | ||
public class MetaAction { | ||
|
||
private final Type type; | ||
|
||
private final Key key; | ||
private final int count; | ||
|
||
private final Instant timestamp = Instant.now(); | ||
|
||
private static final CharSequence SPACE = " "; | ||
private static final String META_PREFIX = "meta"; | ||
|
||
@NotNull | ||
public String toDescription() { | ||
return String.join(SPACE, META_PREFIX, type.action, key.toString(), Integer.toUnsignedString(count)); | ||
} | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum Type { | ||
SET("set"), | ||
GIVE("give"), | ||
TAKE("take"); | ||
|
||
@Accessors(fluent = true) | ||
private final String action; | ||
} | ||
} |
Oops, something went wrong.