diff --git a/api/src/main/java/org/anvilpowered/ontime/api/member/repository/MemberRepository.java b/api/src/main/java/org/anvilpowered/ontime/api/member/repository/MemberRepository.java index 33e0e77..4abbe4f 100644 --- a/api/src/main/java/org/anvilpowered/ontime/api/member/repository/MemberRepository.java +++ b/api/src/main/java/org/anvilpowered/ontime/api/member/repository/MemberRepository.java @@ -30,9 +30,9 @@ public interface MemberRepository< TDataStore> extends Repository, TDataStore> { - CompletableFuture>> getOneOrGenerateForUser(UUID userUUID); + CompletableFuture>> getOneOrGenerateForUser(UUID userUUID, long time); - CompletableFuture>> generateUserFromConfig(UUID userUUID, long time); + CompletableFuture>> getOneOrGenerateForUser(UUID userUUID); CompletableFuture>> getOneForUser(UUID userUUID); diff --git a/build.gradle b/build.gradle index 32d348d..6f9b46c 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ subprojects { maven { url 'https://jetbrains.bintray.com/xodus' } } dependencies { - implementation 'org.anvilpowered:anvil-api:1.0-SNAPSHOT' + implementation 'org.anvilpowered:anvil-api:0.1-SNAPSHOT' } if (project.hasProperty("buildNumber") && version.contains("-SNAPSHOT")) { version = version.replace("-SNAPSHOT", "-RC${buildNumber}") diff --git a/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeAddCommand.java b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeAddCommand.java new file mode 100644 index 0000000..40c4b96 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeAddCommand.java @@ -0,0 +1,27 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.common.command; + +public class CommonOnTimeAddCommand + extends CommonOnTimeTwoArgCommand { + + public void sendAdd(TCommandSource source, String[] context) { + send(source, context, "add", memberManager::addBonusTime); + } +} diff --git a/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeCheckCommand.java b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeCheckCommand.java new file mode 100644 index 0000000..f290bc0 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeCheckCommand.java @@ -0,0 +1,101 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.plugin.PluginInfo; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.ontime.api.data.key.OnTimeKeys; +import org.anvilpowered.ontime.api.member.MemberManager; + +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +@SuppressWarnings("unchecked") +public class CommonOnTimeCheckCommand { + + @Inject + protected MemberManager memberManager; + + @Inject + private PermissionService permissionService; + + @Inject + private PluginInfo pluginInfo; + + @Inject + protected Registry registry; + + @Inject + private TextService textService; + + @Inject + private UserService userService; + + public void sendError(TCommandSource source) { + textService.builder() + .append(pluginInfo.getPrefix()) + .red().append("Specify user or run as player!") + .sendTo(source); + } + + public void sendCheck(TCommandSource source, String[] context, + Class playerClass, Class consoleClass) { + final boolean isConsole = consoleClass.isAssignableFrom(source.getClass()); + final boolean isPlayer = playerClass.isAssignableFrom(source.getClass()); + if (!isConsole && !(isPlayer && permissionService.hasPermission((TSubject) source, + registry.getOrDefault(OnTimeKeys.CHECK_PERMISSION)))) { + textService.builder() + .append(pluginInfo.getPrefix()) + .red().append("You do not have permission for this command!") + .sendTo(source); + return; + } + final boolean hasExtended = isConsole || permissionService.hasPermission((TSubject) source, + registry.getOrDefault(OnTimeKeys.CHECK_EXTENDED_PERMISSION)); + + CompletableFuture> futureUUID; + if (context.length == 1 && hasExtended) { + futureUUID = userService.getUUID(context[0]); + } else { + futureUUID = CompletableFuture.completedFuture(Optional.empty()); + } + futureUUID.thenAcceptAsync(optionalUserUUID -> { + if (optionalUserUUID.isPresent()) { + memberManager.infoExtended(optionalUserUUID.get()) + .thenAcceptAsync(result -> textService.send(result, source)); + } else if (isPlayer) { + UUID userUUID = userService.getUUID((TUser) source); + if (hasExtended) { + memberManager.infoExtended(userUUID) + .thenAcceptAsync(result -> textService.send(result, source)); + } else { + memberManager.info(userUUID) + .thenAcceptAsync(result -> textService.send(result, source)); + } + } else { + sendError(source); + } + }); + } +} diff --git a/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetBonusCommand.java b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetBonusCommand.java new file mode 100644 index 0000000..3578da8 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetBonusCommand.java @@ -0,0 +1,27 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.common.command; + +public class CommonOnTimeSetBonusCommand + extends CommonOnTimeTwoArgCommand { + + public void sendSetBonus(TCommandSource source, String[] context) { + send(source, context, "setbonus", memberManager::setBonusTime); + } +} diff --git a/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetTotalCommand.java b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetTotalCommand.java new file mode 100644 index 0000000..76ae319 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeSetTotalCommand.java @@ -0,0 +1,27 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.common.command; + +public class CommonOnTimeSetTotalCommand + extends CommonOnTimeTwoArgCommand { + + public void sendSetTotal(TCommandSource source, String[] context) { + send(source, context, "set", memberManager::setTotalTime); + } +} diff --git a/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeTwoArgCommand.java b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeTwoArgCommand.java new file mode 100644 index 0000000..fa7c256 --- /dev/null +++ b/common/src/main/java/org/anvilpowered/ontime/common/command/CommonOnTimeTwoArgCommand.java @@ -0,0 +1,89 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.common.command; + +import com.google.inject.Inject; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.plugin.PluginInfo; +import org.anvilpowered.anvil.api.util.PermissionService; +import org.anvilpowered.anvil.api.util.TextService; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.ontime.api.data.key.OnTimeKeys; +import org.anvilpowered.ontime.api.member.MemberManager; + +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.function.BiFunction; + +public class CommonOnTimeTwoArgCommand { + + @Inject + protected MemberManager memberManager; + + @Inject + protected PermissionService permissionService; + + @Inject + private PluginInfo pluginInfo; + + @Inject + protected Registry registry; + + @Inject + private TextService textService; + + @Inject + private UserService userService; + + public void send(TCommandSource source, String[] context, String command, + BiFunction> function) { + if (!permissionService.hasPermission((TSubject) source, + registry.getOrDefault(OnTimeKeys.EDIT_PERMISSION))) { + textService.builder() + .append(pluginInfo.getPrefix()) + .red().append("You do not have permission for this command!") + .sendTo(source); + return; + } + if (context.length != 2) { + textService.builder() + .append(pluginInfo.getPrefix()) + .red().append("Not enough arguments!") + .append("\n", command, " ").appendJoining(" ", context) + .append("\n^\nUsage: /ontime ", command, " ") + .sendTo(source); + return; + } + userService.getUUID(context[0]).thenAcceptAsync(userUUID -> { + if (!userUUID.isPresent()) { + textService.builder() + .append(pluginInfo.getPrefix()) + .red().append("No values matching pattern '", context[0], "' present for user!") + .append("\n", command, " ").appendJoining(" ", context) + .append("\n").appendCount(command.length() + 1, " ") + .append("^\nUsage: /ontime ", command, " ") + .sendTo(source); + return; + } + function.apply(userUUID.get(), context[1]) + .thenAcceptAsync(result -> textService.send(result, source)); + }); + } +} diff --git a/common/src/main/java/org/anvilpowered/ontime/common/member/CommonMemberManager.java b/common/src/main/java/org/anvilpowered/ontime/common/member/CommonMemberManager.java index 86e59c5..81c207c 100644 --- a/common/src/main/java/org/anvilpowered/ontime/common/member/CommonMemberManager.java +++ b/common/src/main/java/org/anvilpowered/ontime/common/member/CommonMemberManager.java @@ -39,7 +39,7 @@ public class CommonMemberManager< TUser, - TPlayer extends TCommandSource, + TPlayer, TString, TCommandSource> extends BaseManager> @@ -64,8 +64,8 @@ public CommonMemberManager(Registry registry) { @Override public CompletableFuture info(UUID userUUID) { - String name = userService.getUserName(userUUID).orElse(userUUID.toString()); return getPrimaryComponent().getOneForUser(userUUID).thenApplyAsync(optionalMember -> { + String name = userService.getUserName(userUUID).join().orElse(userUUID.toString()); if (optionalMember.isPresent()) { Member member = optionalMember.get(); String totalTime = timeFormatService.format( @@ -83,7 +83,7 @@ public CompletableFuture info(UUID userUUID) { .append("\n\n", textService.builder() .dark_gray().append("========= ") .gold().append(pluginInfo.getPrefix()) - .dark_gray().append(" =========")) + .dark_gray().append("=========")) .build(); } return getNotFoundError(name); @@ -92,8 +92,8 @@ public CompletableFuture info(UUID userUUID) { @Override public CompletableFuture infoExtended(UUID userUUID) { - String name = userService.getUserName(userUUID).orElse(userUUID.toString()); return getPrimaryComponent().getOneForUser(userUUID).thenApplyAsync(optionalMember -> { + String name = userService.getUserName(userUUID).join().orElse(userUUID.toString()); if (optionalMember.isPresent()) { Member member = optionalMember.get(); String playTime = timeFormatService.format( @@ -154,8 +154,8 @@ public CompletableFuture> sync(UUID userUUID) { @Override public CompletableFuture addBonusTime(UUID userUUID, long time) { - String name = userService.getUserName(userUUID).orElse(userUUID.toString()); return getPrimaryComponent().addBonusTimeForUser(userUUID, time).thenApplyAsync(result -> { + String name = userService.getUserName(userUUID).join().orElse(userUUID.toString()); if (result) { return textService.builder() .append(pluginInfo.getPrefix()) @@ -192,8 +192,8 @@ public CompletableFuture addBonusTime(UUID userUUID, String time) { @Override public CompletableFuture setBonusTime(UUID userUUID, long time) { - String name = userService.getUserName(userUUID).orElse(userUUID.toString()); return getPrimaryComponent().setBonusTimeForUser(userUUID, time).thenApplyAsync(result -> { + String name = userService.getUserName(userUUID).join().orElse(userUUID.toString()); if (result) { return textService.builder() .append(pluginInfo.getPrefix()) @@ -212,8 +212,8 @@ public CompletableFuture setBonusTime(UUID userUUID, String time) { @Override public CompletableFuture setTotalTime(UUID userUUID, long time) { - String name = userService.getUserName(userUUID).orElse(userUUID.toString()); return getPrimaryComponent().setTotalTimeForUser(userUUID, time).thenApplyAsync(result -> { + String name = userService.getUserName(userUUID).join().orElse(userUUID.toString()); if (result) { return textService.builder() .append(pluginInfo.getPrefix()) diff --git a/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMemberRepository.java b/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMemberRepository.java index b0f2313..bbf0c67 100644 --- a/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMemberRepository.java +++ b/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMemberRepository.java @@ -26,6 +26,8 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; +import java.util.stream.Stream; public abstract class CommonMemberRepository< TKey, @@ -44,13 +46,12 @@ public Class> getTClass() { } @Override - public CompletableFuture>> getOneOrGenerateForUser(UUID userUUID) { - return CompletableFuture.supplyAsync(() -> { - Optional> optionalMember = getOneForUser(userUUID).join(); + public CompletableFuture>> getOneOrGenerateForUser(UUID userUUID, long time) { + return getOneForUser(userUUID).thenApplyAsync(optionalMember -> { if (optionalMember.isPresent()) return optionalMember; // if there isn't one already, create a new one Member member = generateEmpty(); - member.setBonusTime(0); + member.setBonusTime(time); member.setPlayTime(0); member.setUserUUID(userUUID); return insertOne(member).join(); @@ -58,22 +59,7 @@ public CompletableFuture>> getOneOrGenerateForUser(UUID us } @Override - public CompletableFuture>> generateUserFromConfig(UUID userUUID, long time) { - return CompletableFuture.supplyAsync(() -> { - try { - Optional> optionalMember = getOneForUser(userUUID).join(); - if (optionalMember.isPresent()) return optionalMember; - //If the user doens't exist in the db, create it from the values - //Specified in the config - Member member = generateEmpty(); - member.setBonusTime(time); - member.setPlayTime(0); - member.setUserUUID(userUUID); - return insertOne(member).join(); - } catch (Exception e) { - e.printStackTrace(); - return Optional.empty(); - } - }); + public CompletableFuture>> getOneOrGenerateForUser(UUID userUUID) { + return getOneOrGenerateForUser(userUUID, 0); } } diff --git a/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMongoMemberRepository.java b/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMongoMemberRepository.java index 7e7e86e..e53d488 100644 --- a/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMongoMemberRepository.java +++ b/common/src/main/java/org/anvilpowered/ontime/common/member/repository/CommonMongoMemberRepository.java @@ -26,6 +26,7 @@ import org.bson.types.ObjectId; import org.mongodb.morphia.Datastore; import org.mongodb.morphia.query.Query; +import org.mongodb.morphia.query.UpdateOperations; import java.util.Optional; import java.util.UUID; diff --git a/common/src/main/java/org/anvilpowered/ontime/common/module/CommonModule.java b/common/src/main/java/org/anvilpowered/ontime/common/module/CommonModule.java index 530ca17..efc12b6 100644 --- a/common/src/main/java/org/anvilpowered/ontime/common/module/CommonModule.java +++ b/common/src/main/java/org/anvilpowered/ontime/common/module/CommonModule.java @@ -45,7 +45,7 @@ @SuppressWarnings("UnstableApiUsage") public class CommonModule< TUser, - TPlayer extends TCommandSource, + TPlayer, TString, TCommandSource> extends AbstractModule { diff --git a/common/src/main/java/org/anvilpowered/ontime/common/tasks/CommonSyncTaskService.java b/common/src/main/java/org/anvilpowered/ontime/common/task/CommonSyncTaskService.java similarity index 96% rename from common/src/main/java/org/anvilpowered/ontime/common/tasks/CommonSyncTaskService.java rename to common/src/main/java/org/anvilpowered/ontime/common/task/CommonSyncTaskService.java index 4d08b40..6de03b3 100644 --- a/common/src/main/java/org/anvilpowered/ontime/common/tasks/CommonSyncTaskService.java +++ b/common/src/main/java/org/anvilpowered/ontime/common/task/CommonSyncTaskService.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.common.tasks; +package org.anvilpowered.ontime.common.task; import org.anvilpowered.anvil.api.data.registry.Registry; import org.anvilpowered.ontime.api.tasks.SyncTaskService; diff --git a/common/src/main/java/org/anvilpowered/ontime/common/util/CommonDataImportService.java b/common/src/main/java/org/anvilpowered/ontime/common/util/CommonDataImportService.java index f1d6a38..da7cd04 100644 --- a/common/src/main/java/org/anvilpowered/ontime/common/util/CommonDataImportService.java +++ b/common/src/main/java/org/anvilpowered/ontime/common/util/CommonDataImportService.java @@ -50,7 +50,7 @@ public void importData(Path dataPath) { continue; } //Insert the user into MongoDB - memberManager.getPrimaryComponent().generateUserFromConfig(UUID.fromString(key), Long.parseLong(ontime) * 60L); + memberManager.getPrimaryComponent().getOneOrGenerateForUser(UUID.fromString(key), Long.parseLong(ontime) * 60L); } } catch (IOException e) { diff --git a/gradle.properties b/gradle.properties index 082e83b..9f3c605 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,6 @@ # dependencies configurate_hocon=org.spongepowered:configurate-hocon:3.6 +luckperms=net.luckperms:api:5.0 +spigot=org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT sponge=org.spongepowered:spongeapi:7.3.0-SNAPSHOT +velocity=com.velocitypowered:velocity-api:1.1.0-SNAPSHOT diff --git a/luckperms/build.gradle b/luckperms/build.gradle new file mode 100644 index 0000000..18bd501 --- /dev/null +++ b/luckperms/build.gradle @@ -0,0 +1,5 @@ +dependencies { + implementation project(':api') + implementation project(':common') + implementation luckperms +} diff --git a/luckperms/src/main/java/org/anvilpowered/ontime/luckperms/task/LuckPermsSyncTaskService.java b/luckperms/src/main/java/org/anvilpowered/ontime/luckperms/task/LuckPermsSyncTaskService.java new file mode 100644 index 0000000..1773bef --- /dev/null +++ b/luckperms/src/main/java/org/anvilpowered/ontime/luckperms/task/LuckPermsSyncTaskService.java @@ -0,0 +1,77 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.luckperms.task; + +import com.google.inject.Inject; +import net.luckperms.api.LuckPerms; +import net.luckperms.api.LuckPermsProvider; +import net.luckperms.api.model.user.User; +import net.luckperms.api.node.Node; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.anvil.api.util.UserService; +import org.anvilpowered.ontime.api.data.key.OnTimeKeys; +import org.anvilpowered.ontime.api.member.MemberManager; +import org.anvilpowered.ontime.common.task.CommonSyncTaskService; + +import java.util.Set; +import java.util.UUID; + +public abstract class LuckPermsSyncTaskService + extends CommonSyncTaskService { + + private final LuckPerms luckPerms; + + @Inject + private MemberManager memberManager; + + @Inject + private UserService userService; + + protected LuckPermsSyncTaskService(Registry registry) { + super(registry); + luckPerms = LuckPermsProvider.get(); + } + + @Override + public Runnable getSyncTask() { + return () -> { + Set configRanks = registry.getOrDefault(OnTimeKeys.RANKS).keySet(); + for (TPlayer player : userService.getOnlinePlayers()) { + UUID userUUID = userService.getUUID((TUser) player); + memberManager.sync(userUUID).thenAcceptAsync(optionalRank -> { + if (!optionalRank.isPresent()) { + return; + } + String rank = optionalRank.get(); + User user = luckPerms.getUserManager().getUser(userUUID); + if (user == null) { + return; + } + user.data().add(Node.builder("group." + rank).build()); + for (String configRank : configRanks) { + if (!rank.equals(configRank)) { + user.data().remove(Node.builder("group." + configRank).build()); + } + } + luckPerms.getUserManager().saveUser(user); + }); + } + }; + } +} diff --git a/settings.gradle b/settings.gradle index e166f5d..6cb2336 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,4 +2,7 @@ rootProject.name = 'OnTime' include 'api' include 'common' +include 'luckperms' +include 'spigot' include 'sponge' +include 'velocity' diff --git a/spigot/build.gradle b/spigot/build.gradle new file mode 100644 index 0000000..22f2163 --- /dev/null +++ b/spigot/build.gradle @@ -0,0 +1,33 @@ +plugins { + id 'com.github.johnrengelman.shadow' version '5.2.0' +} + +jar.enabled = false // we only want shadowJar + +repositories { + maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots" } +} + +dependencies { + implementation project(':api') + implementation project(':common') + implementation project(':luckperms') + implementation configurate_hocon + implementation spigot +} + +shadowJar { + String jarName = "OnTime-Spigot-${project.version}.jar" + println "Building: " + jarName + archiveFileName = jarName + + dependencies { + include project(':api') + include project(':common') + include project(':luckperms') + } +} + +artifacts { + archives shadowJar +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeAddCommand.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeAddCommand.java new file mode 100644 index 0000000..a307f99 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeAddCommand.java @@ -0,0 +1,43 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.command; + +import net.md_5.bungee.api.chat.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeAddCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; + +public class SpigotOnTimeAddCommand + extends CommonOnTimeAddCommand + implements CommandExecutor { + + @Override + public boolean onCommand( + CommandSender source, + Command command, + String alias, + String[] context + ) { + sendAdd(source, context); + return true; + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeCheckCommand.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeCheckCommand.java new file mode 100644 index 0000000..c08dfb2 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeCheckCommand.java @@ -0,0 +1,44 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.command; + +import net.md_5.bungee.api.chat.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeCheckCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; + +public class SpigotOnTimeCheckCommand + extends CommonOnTimeCheckCommand + implements CommandExecutor { + + @Override + public boolean onCommand( + CommandSender source, + Command command, + String alias, + String[] context + ) { + sendCheck(source, context, Player.class, ConsoleCommandSender.class); + return true; + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeCommandNode.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeCommandNode.java new file mode 100644 index 0000000..294e1a2 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeCommandNode.java @@ -0,0 +1,74 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.command; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.ontime.common.command.CommonOnTimeCommandNode; +import org.anvilpowered.ontime.common.plugin.OnTimePluginInfo; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.PluginCommand; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@Singleton +public class SpigotOnTimeCommandNode + extends CommonOnTimeCommandNode { + + @Inject + private SpigotOnTimeAddCommand onTimeAddCommand; + + @Inject + private SpigotOnTimeCheckCommand onTimeCheckCommand; + + @Inject + private SpigotOnTimeSetBonusCommand onTimeSetBonusCommand; + + @Inject + private SpigotOnTimeSetTotalCommand onTimeSetTotalCommand; + + @Inject + public SpigotOnTimeCommandNode(Registry registry) { + super(registry); + } + + @Override + protected void loadCommands() { + Map, CommandExecutor> subCommands = new HashMap<>(); + + subCommands.put(ADD_ALIAS, onTimeAddCommand); + subCommands.put(CHECK_ALIAS, onTimeCheckCommand); + subCommands.put(SET_BONUS_ALIAS, onTimeSetBonusCommand); + subCommands.put(SET_TOTAL_ALIAS, onTimeSetTotalCommand); + subCommands.put(HELP_ALIAS, commandService.generateHelpCommand(this)); + subCommands.put(VERSION_ALIAS, commandService.generateVersionCommand(HELP_COMMAND)); + + JavaPlugin plugin = environment.getPlugin().getPluginContainer(); + PluginCommand root = plugin.getCommand(OnTimePluginInfo.id); + Objects.requireNonNull(root, "OnTime command not registered"); + root.setExecutor(commandService.generateRoutingCommand( + commandService.generateRootCommand(HELP_COMMAND), subCommands, false)); + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeSetBonusCommand.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeSetBonusCommand.java new file mode 100644 index 0000000..80272c0 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeSetBonusCommand.java @@ -0,0 +1,43 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.command; + +import net.md_5.bungee.api.chat.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeSetBonusCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; + +public class SpigotOnTimeSetBonusCommand + extends CommonOnTimeSetBonusCommand + implements CommandExecutor { + + @Override + public boolean onCommand( + CommandSender source, + Command command, + String alias, + String[] context + ) { + sendSetBonus(source, context); + return true; + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeSetTotalCommand.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeSetTotalCommand.java new file mode 100644 index 0000000..b4835e3 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/command/SpigotOnTimeSetTotalCommand.java @@ -0,0 +1,43 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.command; + +import net.md_5.bungee.api.chat.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeSetTotalCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; + +public class SpigotOnTimeSetTotalCommand + extends CommonOnTimeSetTotalCommand + implements CommandExecutor { + + @Override + public boolean onCommand( + CommandSender source, + Command command, + String alias, + String[] context + ) { + sendSetTotal(source, context); + return true; + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/listener/SpigotPlayerListener.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/listener/SpigotPlayerListener.java new file mode 100644 index 0000000..8b9dfc2 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/listener/SpigotPlayerListener.java @@ -0,0 +1,38 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.listener; + +import com.google.inject.Inject; +import net.md_5.bungee.api.chat.TextComponent; +import org.anvilpowered.ontime.api.member.MemberManager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class SpigotPlayerListener implements Listener { + + @Inject + private MemberManager memberManager; + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + memberManager.getPrimaryComponent() + .getOneOrGenerateForUser(event.getPlayer().getUniqueId()); + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/module/SpigotModule.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/module/SpigotModule.java new file mode 100644 index 0000000..a524c2b --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/module/SpigotModule.java @@ -0,0 +1,55 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.module; + +import com.google.inject.TypeLiteral; +import net.md_5.bungee.api.chat.TextComponent; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import org.anvilpowered.anvil.api.command.CommandNode; +import org.anvilpowered.ontime.api.tasks.SyncTaskService; +import org.anvilpowered.ontime.common.module.CommonModule; +import org.anvilpowered.ontime.common.plugin.OnTimePluginInfo; +import org.anvilpowered.ontime.spigot.command.SpigotOnTimeCommandNode; +import org.anvilpowered.ontime.spigot.task.SpigotSyncTaskService; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.io.File; +import java.nio.file.Paths; + +public class SpigotModule extends CommonModule { + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(SpigotOnTimeCommandNode.class); + File configFilesLocation = Paths.get("plugins/" + OnTimePluginInfo.id).toFile(); + if (!configFilesLocation.exists()) { + if (!configFilesLocation.mkdirs()) { + throw new IllegalStateException("Unable to create config directory"); + } + } + bind(new TypeLiteral>() { + }).toInstance(HoconConfigurationLoader.builder().setPath(Paths.get(configFilesLocation + "/ontime.conf")).build()); + bind(SyncTaskService.class).to(SpigotSyncTaskService.class); + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/plugin/OnTimeSpigot.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/plugin/OnTimeSpigot.java new file mode 100644 index 0000000..ae52b51 --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/plugin/OnTimeSpigot.java @@ -0,0 +1,55 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.plugin; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.anvilpowered.anvil.api.Environment; +import org.anvilpowered.ontime.common.plugin.OnTime; +import org.anvilpowered.ontime.spigot.listener.SpigotPlayerListener; +import org.anvilpowered.ontime.spigot.module.SpigotModule; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; + +public class OnTimeSpigot extends JavaPlugin { + protected final Inner inner; + public OnTimeSpigot() { + AbstractModule module = new AbstractModule() { + @Override + protected void configure() { + bind(JavaPlugin.class).toInstance(OnTimeSpigot.this); + } + }; + Injector injector = Guice.createInjector(module); + inner = new Inner(injector); + } + + private final class Inner extends OnTime { + private Inner(Injector injector) { + super(injector, new SpigotModule()); + } + @Override + protected void applyToBuilder(Environment.Builder builder) { + super.applyToBuilder(builder); + builder.addEarlyServices(SpigotPlayerListener.class, t -> + Bukkit.getPluginManager().registerEvents(t, OnTimeSpigot.this)); + } + } +} diff --git a/spigot/src/main/java/org/anvilpowered/ontime/spigot/task/SpigotSyncTaskService.java b/spigot/src/main/java/org/anvilpowered/ontime/spigot/task/SpigotSyncTaskService.java new file mode 100644 index 0000000..4dc369a --- /dev/null +++ b/spigot/src/main/java/org/anvilpowered/ontime/spigot/task/SpigotSyncTaskService.java @@ -0,0 +1,54 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.spigot.task; + +import com.google.inject.Inject; +import net.md_5.bungee.api.chat.TextComponent; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.ontime.luckperms.task.LuckPermsSyncTaskService; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitTask; + +public class SpigotSyncTaskService + extends LuckPermsSyncTaskService { + + @Inject + private JavaPlugin plugin; + + private BukkitTask task; + + @Inject + public SpigotSyncTaskService(Registry registry) { + super(registry); + } + + @Override + public void startSyncTask() { + task = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, getSyncTask(), 0, 1200); + } + + @Override + public void stopSyncTask() { + if (task != null) { + task.cancel(); + } + } +} diff --git a/spigot/src/main/resources/plugin.yml b/spigot/src/main/resources/plugin.yml new file mode 100644 index 0000000..6a86fc7 --- /dev/null +++ b/spigot/src/main/resources/plugin.yml @@ -0,0 +1,10 @@ +name: OnTime +version: "1.0.0-SNAPSHOT" +main: org.anvilpowered.ontime.spigot.plugin.OnTimeSpigot +api-version: 1.15 +authors: [Cableguy20, STG_Allen] +description: Playtime tracker +depend: [Anvil, LuckPerms] +commands: + ontime: + description: OnTime root command diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeAddCommand.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeAddBonusCommand.java similarity index 93% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeAddCommand.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeAddBonusCommand.java index bdba784..b7fe20b 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeAddCommand.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeAddBonusCommand.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.commands; +package org.anvilpowered.ontime.sponge.command; import com.google.inject.Inject; import org.anvilpowered.ontime.api.member.MemberManager; @@ -27,7 +27,7 @@ import org.spongepowered.api.entity.living.player.User; import org.spongepowered.api.text.Text; -public class OnTimeAddCommand implements CommandExecutor { +public class SpongeOnTimeAddBonusCommand implements CommandExecutor { @Inject private MemberManager memberManager; diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeCheckCommand.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeCheckCommand.java similarity index 85% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeCheckCommand.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeCheckCommand.java index 5bdeb8f..8284425 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeCheckCommand.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeCheckCommand.java @@ -16,24 +16,27 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.commands; +package org.anvilpowered.ontime.sponge.command; import com.google.inject.Inject; import org.anvilpowered.anvil.api.data.registry.Registry; import org.anvilpowered.ontime.api.data.key.OnTimeKeys; import org.anvilpowered.ontime.api.member.MemberManager; -import org.spongepowered.api.command.CommandException; +import org.anvilpowered.ontime.common.command.CommonOnTimeCheckCommand; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.args.CommandContext; import org.spongepowered.api.command.spec.CommandExecutor; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.User; +import org.spongepowered.api.service.permission.Subject; import org.spongepowered.api.text.Text; import java.util.Optional; -public class OnTimeCheckCommand implements CommandExecutor { +public class SpongeOnTimeCheckCommand + extends CommonOnTimeCheckCommand + implements CommandExecutor { @Inject private MemberManager memberManager; @@ -42,7 +45,7 @@ public class OnTimeCheckCommand implements CommandExecutor { private Registry registry; @Override - public CommandResult execute(CommandSource source, CommandContext context) throws CommandException { + public CommandResult execute(CommandSource source, CommandContext context) { Optional optionalUser = context.getOne(Text.of("user")); if (optionalUser.isPresent()) { memberManager.infoExtended(optionalUser.get().getUniqueId()).thenAcceptAsync(source::sendMessage); @@ -53,7 +56,7 @@ public CommandResult execute(CommandSource source, CommandContext context) throw memberManager.info(((Player) source).getUniqueId()).thenAcceptAsync(source::sendMessage); } } else { - throw new CommandException(Text.of("Specify user or run as player!")); + sendError(source); } return CommandResult.success(); } diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSpongeCommandNode.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeCommandNode.java similarity index 90% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSpongeCommandNode.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeCommandNode.java index 2170f5c..17c7718 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSpongeCommandNode.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeCommandNode.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.commands; +package org.anvilpowered.ontime.sponge.command; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -36,26 +36,26 @@ import java.util.Map; @Singleton -public class OnTimeSpongeCommandNode +public class SpongeOnTimeCommandNode extends CommonOnTimeCommandNode { @Inject - private OnTimeAddCommand onTimeAddCommand; + private SpongeOnTimeAddBonusCommand onTimeAddCommand; @Inject - private OnTimeCheckCommand onTimeCheckCommand; + private SpongeOnTimeCheckCommand onTimeCheckCommand; @Inject - private OnTimeImportCommand onTimeImportCommand; + private SpongeOnTimeImportCommand onTimeImportCommand; @Inject - private OnTimeSetBonusCommand onTimeSetBonusCommand; + private SpongeOnTimeSetBonusCommand onTimeSetBonusCommand; @Inject - private OnTimeSetCommand onTimeSetCommand; + private SpongeOnTimeSetTotalCommand onTimeSetTotalCommand; @Inject - public OnTimeSpongeCommandNode(Registry registry) { + public SpongeOnTimeCommandNode(Registry registry) { super(registry); } @@ -114,7 +114,7 @@ protected void loadCommands() { GenericArguments.onlyOne(GenericArguments.user(Text.of("user"))), GenericArguments.remainingJoinedStrings(Text.of("time")) ) - .executor(onTimeSetCommand) + .executor(onTimeSetTotalCommand) .build() ); diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeImportCommand.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeImportCommand.java similarity index 95% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeImportCommand.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeImportCommand.java index dd85c6b..babca60 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeImportCommand.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeImportCommand.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.commands; +package org.anvilpowered.ontime.sponge.command; import com.google.inject.Inject; import org.anvilpowered.anvil.api.plugin.PluginInfo; @@ -33,7 +33,7 @@ import java.nio.file.Paths; import java.util.Optional; -public class OnTimeImportCommand implements CommandExecutor { +public class SpongeOnTimeImportCommand implements CommandExecutor { @Inject private DataImportService importService; diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSetBonusCommand.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeSetBonusCommand.java similarity index 93% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSetBonusCommand.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeSetBonusCommand.java index 6d7554b..8083b18 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSetBonusCommand.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeSetBonusCommand.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.commands; +package org.anvilpowered.ontime.sponge.command; import com.google.inject.Inject; import org.anvilpowered.ontime.api.member.MemberManager; @@ -27,7 +27,7 @@ import org.spongepowered.api.entity.living.player.User; import org.spongepowered.api.text.Text; -public class OnTimeSetBonusCommand implements CommandExecutor { +public class SpongeOnTimeSetBonusCommand implements CommandExecutor { @Inject private MemberManager memberManager; diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSetCommand.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeSetTotalCommand.java similarity index 93% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSetCommand.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeSetTotalCommand.java index a6b712a..1d8d982 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/commands/OnTimeSetCommand.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/command/SpongeOnTimeSetTotalCommand.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.commands; +package org.anvilpowered.ontime.sponge.command; import com.google.inject.Inject; import org.anvilpowered.ontime.api.member.MemberManager; @@ -27,7 +27,7 @@ import org.spongepowered.api.entity.living.player.User; import org.spongepowered.api.text.Text; -public class OnTimeSetCommand implements CommandExecutor { +public class SpongeOnTimeSetTotalCommand implements CommandExecutor { @Inject private MemberManager memberManager; diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/listeners/PlayerListener.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/listener/SpongePlayerListener.java similarity index 81% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/listeners/PlayerListener.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/listener/SpongePlayerListener.java index a7e4415..e31a208 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/listeners/PlayerListener.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/listener/SpongePlayerListener.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.listeners; +package org.anvilpowered.ontime.sponge.listener; import com.google.inject.Inject; import org.anvilpowered.ontime.api.member.MemberManager; @@ -24,13 +24,14 @@ import org.spongepowered.api.event.network.ClientConnectionEvent; import org.spongepowered.api.text.Text; -public class PlayerListener { +public class SpongePlayerListener { @Inject - MemberManager memberManager; + private MemberManager memberManager; @Listener public void onPlayerJoin(ClientConnectionEvent.Join event) { - memberManager.getPrimaryComponent().getOneOrGenerateForUser(event.getTargetEntity().getUniqueId()); + memberManager.getPrimaryComponent() + .getOneOrGenerateForUser(event.getTargetEntity().getUniqueId()); } } diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/module/SpongeModule.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/module/SpongeModule.java index 70d902f..622530b 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/module/SpongeModule.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/module/SpongeModule.java @@ -23,9 +23,9 @@ import org.anvilpowered.ontime.api.tasks.SyncTaskService; import org.anvilpowered.ontime.common.data.config.CommonConfigurationService; import org.anvilpowered.ontime.common.module.CommonModule; -import org.anvilpowered.ontime.sponge.commands.OnTimeSpongeCommandNode; +import org.anvilpowered.ontime.sponge.command.SpongeOnTimeCommandNode; import org.anvilpowered.ontime.sponge.data.config.SpongeConfigurationService; -import org.anvilpowered.ontime.sponge.tasks.SpongeSyncTaskService; +import org.anvilpowered.ontime.sponge.task.SpongeSyncTaskService; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.User; @@ -38,7 +38,7 @@ protected void configure() { super.configure(); bind(new TypeLiteral>() { - }).to(OnTimeSpongeCommandNode.class); + }).to(SpongeOnTimeCommandNode.class); bind(CommonConfigurationService.class).to(SpongeConfigurationService.class); bind(SyncTaskService.class).to(SpongeSyncTaskService.class); diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/plugin/OnTimeSponge.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/plugin/OnTimeSponge.java index 69cfb4b..d5999ca 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/plugin/OnTimeSponge.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/plugin/OnTimeSponge.java @@ -21,10 +21,9 @@ import com.google.inject.Inject; import com.google.inject.Injector; import org.anvilpowered.anvil.api.Environment; -import org.anvilpowered.ontime.api.tasks.SyncTaskService; import org.anvilpowered.ontime.common.plugin.OnTime; import org.anvilpowered.ontime.common.plugin.OnTimePluginInfo; -import org.anvilpowered.ontime.sponge.listeners.PlayerListener; +import org.anvilpowered.ontime.sponge.listener.SpongePlayerListener; import org.anvilpowered.ontime.sponge.module.SpongeModule; import org.spongepowered.api.Sponge; import org.spongepowered.api.plugin.Dependency; @@ -50,8 +49,7 @@ public OnTimeSponge(Injector injector) { @Override protected void applyToBuilder(Environment.Builder builder) { super.applyToBuilder(builder); - builder.addEarlyServices(PlayerListener.class, t -> + builder.addEarlyServices(SpongePlayerListener.class, t -> Sponge.getEventManager().registerListeners(this, t)); - builder.addEarlyServices(SyncTaskService.class); } } diff --git a/sponge/src/main/java/org/anvilpowered/ontime/sponge/tasks/SpongeSyncTaskService.java b/sponge/src/main/java/org/anvilpowered/ontime/sponge/task/SpongeSyncTaskService.java similarity index 91% rename from sponge/src/main/java/org/anvilpowered/ontime/sponge/tasks/SpongeSyncTaskService.java rename to sponge/src/main/java/org/anvilpowered/ontime/sponge/task/SpongeSyncTaskService.java index 50ba56f..04df077 100644 --- a/sponge/src/main/java/org/anvilpowered/ontime/sponge/tasks/SpongeSyncTaskService.java +++ b/sponge/src/main/java/org/anvilpowered/ontime/sponge/task/SpongeSyncTaskService.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package org.anvilpowered.ontime.sponge.tasks; +package org.anvilpowered.ontime.sponge.task; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -24,7 +24,7 @@ import org.anvilpowered.anvil.api.data.registry.Registry; import org.anvilpowered.ontime.api.data.key.OnTimeKeys; import org.anvilpowered.ontime.api.member.MemberManager; -import org.anvilpowered.ontime.common.tasks.CommonSyncTaskService; +import org.anvilpowered.ontime.common.task.CommonSyncTaskService; import org.spongepowered.api.Sponge; import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.service.permission.PermissionService; @@ -41,10 +41,10 @@ public class SpongeSyncTaskService extends CommonSyncTaskService { @Inject - MemberManager memberManager; + private MemberManager memberManager; @Inject - Environment environment; + private Environment environment; PermissionService permissionService; @@ -53,7 +53,7 @@ public class SpongeSyncTaskService extends CommonSyncTaskService { @Inject public SpongeSyncTaskService(Registry registry) { super(registry); - permissionService = Sponge.getServiceManager().provide(PermissionService.class).orElseThrow(() -> new IllegalStateException("Missing PermissionService")); + permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class); } @Override diff --git a/velocity/build.gradle b/velocity/build.gradle new file mode 100644 index 0000000..aa03e21 --- /dev/null +++ b/velocity/build.gradle @@ -0,0 +1,32 @@ +plugins { + id 'com.github.johnrengelman.shadow' version '5.2.0' +} + +jar.enabled = false // we only want shadowJar + +repositories { + maven { url 'https://repo.velocitypowered.com/snapshots/' } +} +dependencies { + implementation project(':api') + implementation project(':common') + implementation project(':luckperms') + implementation velocity + annotationProcessor velocity +} + +shadowJar { + String jarName = "OnTime-Velocity-${project.version}.jar" + println "Building: " + jarName + archiveFileName = jarName + + dependencies { + include project(':api') + include project(':common') + include project(':luckperms') + } +} + +artifacts { + archives shadowJar +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeAddCommand.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeAddCommand.java new file mode 100644 index 0000000..2e599ec --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeAddCommand.java @@ -0,0 +1,36 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.command; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.permission.PermissionSubject; +import com.velocitypowered.api.proxy.Player; +import net.kyori.text.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeAddCommand; + +public class VelocityOnTimeAddCommand + extends CommonOnTimeAddCommand + implements Command { + + @Override + public void execute(CommandSource source, String[] context) { + sendAdd(source, context); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeCheckCommand.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeCheckCommand.java new file mode 100644 index 0000000..6bbf236 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeCheckCommand.java @@ -0,0 +1,37 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.command; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.permission.PermissionSubject; +import com.velocitypowered.api.proxy.ConsoleCommandSource; +import com.velocitypowered.api.proxy.Player; +import net.kyori.text.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeCheckCommand; + +public class VelocityOnTimeCheckCommand + extends CommonOnTimeCheckCommand + implements Command { + + @Override + public void execute(CommandSource source, String[] context) { + sendCheck(source, context, Player.class, ConsoleCommandSource.class); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeCommandNode.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeCommandNode.java new file mode 100644 index 0000000..31d0276 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeCommandNode.java @@ -0,0 +1,74 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.command; + +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.ProxyServer; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.ontime.common.command.CommonOnTimeCommandNode; +import org.anvilpowered.ontime.common.plugin.OnTimePluginInfo; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Singleton +public class VelocityOnTimeCommandNode + extends CommonOnTimeCommandNode { + + @Inject + private ProxyServer proxyServer; + + @Inject + private VelocityOnTimeAddCommand onTimeAddCommand; + + @Inject + private VelocityOnTimeCheckCommand onTimeCheckCommand; + + @Inject + private VelocityOnTimeSetBonusCommand onTimeSetBonusCommand; + + @Inject + private VelocityOnTimeSetTotalCommand onTimeSetTotalCommand; + + @Inject + public VelocityOnTimeCommandNode(Registry registry) { + super(registry); + } + + @Override + protected void loadCommands() { + Map, Command> subCommands = new HashMap<>(); + + subCommands.put(ADD_ALIAS, onTimeAddCommand); + subCommands.put(CHECK_ALIAS, onTimeCheckCommand); + subCommands.put(SET_BONUS_ALIAS, onTimeSetBonusCommand); + subCommands.put(SET_TOTAL_ALIAS, onTimeSetTotalCommand); + subCommands.put(HELP_ALIAS, commandService.generateHelpCommand(this)); + subCommands.put(VERSION_ALIAS, commandService.generateVersionCommand(HELP_COMMAND)); + + proxyServer.getCommandManager().register(OnTimePluginInfo.id, + commandService.generateRoutingCommand( + commandService.generateRootCommand(HELP_COMMAND), subCommands, false), + "ot"); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeSetBonusCommand.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeSetBonusCommand.java new file mode 100644 index 0000000..80ae9be --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeSetBonusCommand.java @@ -0,0 +1,36 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.command; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.permission.PermissionSubject; +import com.velocitypowered.api.proxy.Player; +import net.kyori.text.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeSetBonusCommand; + +public class VelocityOnTimeSetBonusCommand + extends CommonOnTimeSetBonusCommand + implements Command { + + @Override + public void execute(CommandSource source, String[] context) { + sendSetBonus(source, context); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeSetTotalCommand.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeSetTotalCommand.java new file mode 100644 index 0000000..2c320e5 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/command/VelocityOnTimeSetTotalCommand.java @@ -0,0 +1,36 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.command; + +import com.velocitypowered.api.command.Command; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.permission.PermissionSubject; +import com.velocitypowered.api.proxy.Player; +import net.kyori.text.TextComponent; +import org.anvilpowered.ontime.common.command.CommonOnTimeSetTotalCommand; + +public class VelocityOnTimeSetTotalCommand + extends CommonOnTimeSetTotalCommand + implements Command { + + @Override + public void execute(CommandSource source, String[] context) { + sendSetTotal(source, context); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/listener/VelocityPlayerListener.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/listener/VelocityPlayerListener.java new file mode 100644 index 0000000..eccb78a --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/listener/VelocityPlayerListener.java @@ -0,0 +1,37 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.listener; + +import com.google.inject.Inject; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.LoginEvent; +import net.kyori.text.TextComponent; +import org.anvilpowered.ontime.api.member.MemberManager; + +public class VelocityPlayerListener { + + @Inject + private MemberManager memberManager; + + @Subscribe + public void onPlayerJoin(LoginEvent event) { + memberManager.getPrimaryComponent() + .getOneOrGenerateForUser(event.getPlayer().getUniqueId()); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/module/VelocityModule.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/module/VelocityModule.java new file mode 100644 index 0000000..9c307b7 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/module/VelocityModule.java @@ -0,0 +1,55 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.module; + +import com.google.inject.TypeLiteral; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import net.kyori.text.TextComponent; +import ninja.leaping.configurate.commented.CommentedConfigurationNode; +import ninja.leaping.configurate.hocon.HoconConfigurationLoader; +import ninja.leaping.configurate.loader.ConfigurationLoader; +import org.anvilpowered.anvil.api.command.CommandNode; +import org.anvilpowered.ontime.api.tasks.SyncTaskService; +import org.anvilpowered.ontime.common.module.CommonModule; +import org.anvilpowered.ontime.common.plugin.OnTimePluginInfo; +import org.anvilpowered.ontime.velocity.command.VelocityOnTimeCommandNode; +import org.anvilpowered.ontime.velocity.task.VelocitySyncTaskService; + +import java.io.File; +import java.nio.file.Paths; + +public class VelocityModule extends CommonModule { + + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(VelocityOnTimeCommandNode.class); + File configFilesLocation = Paths.get("plugins/" + OnTimePluginInfo.id).toFile(); + if (!configFilesLocation.exists()) { + if (!configFilesLocation.mkdirs()) { + throw new IllegalStateException("Unable to create config directory"); + } + } + bind(new TypeLiteral>() { + }).toInstance(HoconConfigurationLoader.builder().setPath(Paths.get(configFilesLocation + "/ontime.conf")).build()); + bind(SyncTaskService.class).to(VelocitySyncTaskService.class); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/plugin/OnTimeVelocity.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/plugin/OnTimeVelocity.java new file mode 100644 index 0000000..6cfe776 --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/plugin/OnTimeVelocity.java @@ -0,0 +1,58 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.plugin; + +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.velocitypowered.api.plugin.Dependency; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.PluginContainer; +import com.velocitypowered.api.proxy.ProxyServer; +import org.anvilpowered.anvil.api.Environment; +import org.anvilpowered.ontime.common.plugin.OnTime; +import org.anvilpowered.ontime.common.plugin.OnTimePluginInfo; +import org.anvilpowered.ontime.velocity.listener.VelocityPlayerListener; +import org.anvilpowered.ontime.velocity.module.VelocityModule; + +@Plugin( + id = OnTimePluginInfo.id, + name = OnTimePluginInfo.name, + version = OnTimePluginInfo.version, + dependencies = @Dependency(id = "anvil"), + description = OnTimePluginInfo.description, + url = OnTimePluginInfo.url, + authors = {"Cableguy20", "STG_Allen"} +) +public class OnTimeVelocity extends OnTime { + + @Inject + private ProxyServer proxyServer; + + @Inject + public OnTimeVelocity(Injector injector) { + super(injector, new VelocityModule()); + } + + @Override + protected void applyToBuilder(Environment.Builder builder) { + super.applyToBuilder(builder); + builder.addEarlyServices(VelocityPlayerListener.class, t -> + proxyServer.getEventManager().register(this, t)); + } +} diff --git a/velocity/src/main/java/org/anvilpowered/ontime/velocity/task/VelocitySyncTaskService.java b/velocity/src/main/java/org/anvilpowered/ontime/velocity/task/VelocitySyncTaskService.java new file mode 100644 index 0000000..b66b2bb --- /dev/null +++ b/velocity/src/main/java/org/anvilpowered/ontime/velocity/task/VelocitySyncTaskService.java @@ -0,0 +1,62 @@ +/* + * OnTime - AnvilPowered + * Copyright (C) 2020 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package org.anvilpowered.ontime.velocity.task; + +import com.google.inject.Inject; +import com.velocitypowered.api.plugin.PluginContainer; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.scheduler.ScheduledTask; +import net.kyori.text.TextComponent; +import org.anvilpowered.anvil.api.data.registry.Registry; +import org.anvilpowered.ontime.luckperms.task.LuckPermsSyncTaskService; + +import java.util.concurrent.TimeUnit; + +public class VelocitySyncTaskService + extends LuckPermsSyncTaskService { + + @Inject + private ProxyServer proxyServer; + + @Inject + private PluginContainer pluginContainer; + + private ScheduledTask task; + + @Inject + public VelocitySyncTaskService(Registry registry) { + super(registry); + } + + @Override + public void startSyncTask() { + task = proxyServer.getScheduler() + .buildTask(pluginContainer, getSyncTask()) + .repeat(1, TimeUnit.MINUTES) + .schedule(); + } + + @Override + public void stopSyncTask() { + if (task != null) { + task.cancel(); + } + } +}