mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-11-14 13:13:32 +00:00
Merge pull request #25 from AtlasMediaGroup/module/NetworkManager-Hook
Create Cladis (NetworkManager Hook)
This commit is contained in:
commit
0f848f434c
42
Cladis/.gitignore
vendored
Normal file
42
Cladis/.gitignore
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
.gradle
|
||||||
|
build/
|
||||||
|
!gradle/wrapper/gradle-wrapper.jar
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/modules.xml
|
||||||
|
.idea/jarRepositories.xml
|
||||||
|
.idea/compiler.xml
|
||||||
|
.idea/libraries/
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
25
Cladis/build.gradle
Normal file
25
Cladis/build.gradle
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'fns.cladis'
|
||||||
|
version = '1.0.0'
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven {
|
||||||
|
url 'https://repo.networkmanager.xyz/repository/maven-public/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly project(":Patchwork")
|
||||||
|
compileOnly 'nl.chimpgamer.networkmanager:api:2.13.1'
|
||||||
|
|
||||||
|
testImplementation platform('org.junit:junit-bom:5.9.1')
|
||||||
|
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
45
Cladis/src/main/java/fns/cladis/Cladis.java
Normal file
45
Cladis/src/main/java/fns/cladis/Cladis.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
package fns.cladis;
|
||||||
|
|
||||||
|
import fns.cladis.command.OpCommand;
|
||||||
|
import fns.patchwork.base.Registration;
|
||||||
|
import fns.patchwork.command.CommandHandler;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class Cladis extends JavaPlugin
|
||||||
|
{
|
||||||
|
private NMLink nmLink;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable()
|
||||||
|
{
|
||||||
|
if (this.getServer().getPluginManager().getPlugin("NetworkManager") == null)
|
||||||
|
{
|
||||||
|
getLogger().severe("NetworkManager not found! Disabling Cladis...");
|
||||||
|
this.getServer().getPluginManager().disablePlugin(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.nmLink = new NMLink(this);
|
||||||
|
|
||||||
|
new CommandHandler(this).registerCommands(OpCommand.class);
|
||||||
|
|
||||||
|
Registration.getModuleRegistry()
|
||||||
|
.addModule(this);
|
||||||
|
|
||||||
|
getLogger().info("Cladis enabled!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable()
|
||||||
|
{
|
||||||
|
Registration.getModuleRegistry()
|
||||||
|
.removeModule(this);
|
||||||
|
|
||||||
|
getLogger().info("Cladis disabled!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NMLink getNMLink()
|
||||||
|
{
|
||||||
|
return this.nmLink;
|
||||||
|
}
|
||||||
|
}
|
118
Cladis/src/main/java/fns/cladis/NMLink.java
Normal file
118
Cladis/src/main/java/fns/cladis/NMLink.java
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package fns.cladis;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
|
||||||
|
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
|
||||||
|
import nl.chimpgamer.networkmanager.api.cache.CacheManager;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.permissions.Group;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.permissions.PermissionPlayer;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.player.Player;
|
||||||
|
|
||||||
|
public class NMLink
|
||||||
|
{
|
||||||
|
private NetworkManagerPlugin networkManager;
|
||||||
|
|
||||||
|
public NMLink(final Cladis plugin)
|
||||||
|
{
|
||||||
|
this.networkManager = NetworkManagerProvider.Companion.get();
|
||||||
|
plugin.getSLF4JLogger().info("NetworkManager successfully linked!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheManager getCacheManager()
|
||||||
|
{
|
||||||
|
return this.networkManager.getCacheManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Player> getPlayer(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getCacheManager().getCachedPlayers().getPlayerSafe(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionPlayer getPermissionsPlayer(final UUID uuid)
|
||||||
|
{
|
||||||
|
return networkManager.getPermissionManager().getPermissionPlayer(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Group> getPlayerGroups(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPermissionsPlayer(uuid).getGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<Integer, Group> getLoadedGroups()
|
||||||
|
{
|
||||||
|
return networkManager.getPermissionManager().getGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Group> locateGroup(final String name)
|
||||||
|
{
|
||||||
|
return Optional.of(networkManager.getPermissionManager().getGroup(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group opGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("fake_op").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group deopGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("fake_deop").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group masterBuilderGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("master_builder").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group adminGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("admin").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group seniorGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("senior").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group devGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("developer").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Group execGroup()
|
||||||
|
{
|
||||||
|
return locateGroup("executive").orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOp(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlayerGroups(uuid).contains(opGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeop(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlayerGroups(uuid).contains(deopGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAdmin(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlayerGroups(uuid).contains(seniorGroup()) || getPlayerGroups(uuid).contains(adminGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSenior(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlayerGroups(uuid).contains(seniorGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDev(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlayerGroups(uuid).contains(devGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isExec(final UUID uuid)
|
||||||
|
{
|
||||||
|
return getPlayerGroups(uuid).contains(execGroup());
|
||||||
|
}
|
||||||
|
}
|
90
Cladis/src/main/java/fns/cladis/command/DeopCommand.java
Normal file
90
Cladis/src/main/java/fns/cladis/command/DeopCommand.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite
|
||||||
|
* Copyright (C) 2023 Total Freedom Server Network and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fns.cladis.command;
|
||||||
|
|
||||||
|
import fns.cladis.Cladis;
|
||||||
|
import fns.cladis.NMLink;
|
||||||
|
import fns.patchwork.base.Shortcuts;
|
||||||
|
import fns.patchwork.command.Commander;
|
||||||
|
import fns.patchwork.command.annotation.Completion;
|
||||||
|
import fns.patchwork.command.annotation.Info;
|
||||||
|
import fns.patchwork.command.annotation.Permissive;
|
||||||
|
import fns.patchwork.command.annotation.Subcommand;
|
||||||
|
import java.util.UUID;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.permissions.Group;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@Info(
|
||||||
|
name = "deop",
|
||||||
|
description = "Deop a player.",
|
||||||
|
usage = "/deop <player>"
|
||||||
|
)
|
||||||
|
@Permissive(perm = "cladis.deop")
|
||||||
|
@Completion(index = 0, args = {"%player%"})
|
||||||
|
public class DeopCommand extends Commander
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the
|
||||||
|
* command.
|
||||||
|
* <p>
|
||||||
|
* This constructor will automatically register all subcommands and completions for this command. It will also
|
||||||
|
* automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin which contains this command.
|
||||||
|
*/
|
||||||
|
protected DeopCommand(@NotNull final JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subcommand(permission = "cladis.deop", args = {Player.class})
|
||||||
|
public void deop(final CommandSender sender, final Player player)
|
||||||
|
{
|
||||||
|
final UUID playerUUID = player.getUniqueId();
|
||||||
|
|
||||||
|
final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink();
|
||||||
|
final Group opGroup = nmLink.deopGroup();
|
||||||
|
|
||||||
|
if (opGroup == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("Unable to deop player. Please contact an administrator.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nmLink.isDeop(playerUUID))
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("Player is not op.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nmLink.getPlayerGroups(playerUUID).remove(opGroup);
|
||||||
|
|
||||||
|
sender.sendPlainMessage("Player deopped.");
|
||||||
|
player.sendPlainMessage("You have been deopped!");
|
||||||
|
}
|
||||||
|
}
|
239
Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java
Normal file
239
Cladis/src/main/java/fns/cladis/command/ModStaffCommand.java
Normal file
@ -0,0 +1,239 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite
|
||||||
|
* Copyright (C) 2023 Total Freedom Server Network and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fns.cladis.command;
|
||||||
|
|
||||||
|
import fns.cladis.Cladis;
|
||||||
|
import fns.cladis.NMLink;
|
||||||
|
import fns.patchwork.base.Shortcuts;
|
||||||
|
import fns.patchwork.command.Commander;
|
||||||
|
import fns.patchwork.command.annotation.Base;
|
||||||
|
import fns.patchwork.command.annotation.Completion;
|
||||||
|
import fns.patchwork.command.annotation.Info;
|
||||||
|
import fns.patchwork.command.annotation.Permissive;
|
||||||
|
import fns.patchwork.command.annotation.Subcommand;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.permissions.Group;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@Info(
|
||||||
|
name = "modstaff",
|
||||||
|
description = "Mod a player.",
|
||||||
|
usage = """
|
||||||
|
/modstaff
|
||||||
|
/modstaff info <player>
|
||||||
|
/modstaff <add | remove> <player> <group>
|
||||||
|
/modstaff <promote | demote> <player>
|
||||||
|
""",
|
||||||
|
aliases = {"ms", "saconfig", "adminlist", "al"}
|
||||||
|
)
|
||||||
|
@Permissive(perm = "cladis.modstaff")
|
||||||
|
@Completion(index = 0, args = {"info", "add", "remove", "promote", "demote"})
|
||||||
|
@Completion(index = 1, args = {"%player%"})
|
||||||
|
@Completion(index = 2, args = {"<group>"})
|
||||||
|
public class ModStaffCommand extends Commander
|
||||||
|
{
|
||||||
|
|
||||||
|
public static final String USER_NOT_FOUND = "That user does not exist!";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the
|
||||||
|
* command.
|
||||||
|
* <p>
|
||||||
|
* This constructor will automatically register all subcommands and completions for this command. It will also
|
||||||
|
* automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin which contains this command.
|
||||||
|
*/
|
||||||
|
public ModStaffCommand(@NotNull final JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Base
|
||||||
|
public void base(final CommandSender sender)
|
||||||
|
{
|
||||||
|
final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink();
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
nmLink.getCacheManager()
|
||||||
|
.getCachedPlayers()
|
||||||
|
.getPlayers()
|
||||||
|
.forEach((u, p) ->
|
||||||
|
{
|
||||||
|
if (nmLink.isAdmin(u) || nmLink.isSenior(u))
|
||||||
|
{
|
||||||
|
stringBuilder.append(nmLink.getPermissionsPlayer(u)
|
||||||
|
.getPrimaryGroup()
|
||||||
|
.getPrefixes()
|
||||||
|
.values()
|
||||||
|
.stream()
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> "[Admin]"))
|
||||||
|
.append(" ")
|
||||||
|
.append(p.getName()).append(", ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sender.sendPlainMessage(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subcommand(permission = "cladis.modstaff.info", args = {String.class, Player.class})
|
||||||
|
public void info(final CommandSender sender, final String info, final Player player)
|
||||||
|
{
|
||||||
|
if (!info.equalsIgnoreCase("info"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink();
|
||||||
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer =
|
||||||
|
nmLink.getPlayer(player.getUniqueId()).orElse(null);
|
||||||
|
|
||||||
|
if (nmPlayer == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage(USER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stringBuilder.append("Player: ")
|
||||||
|
.append(player.getName())
|
||||||
|
.append("\n");
|
||||||
|
stringBuilder.append("UUID: ")
|
||||||
|
.append(nmPlayer.getUuid())
|
||||||
|
.append("\n");
|
||||||
|
stringBuilder.append("Rank: ")
|
||||||
|
.append(nmLink.getPermissionsPlayer(player.getUniqueId()).getPrimaryGroup().getName())
|
||||||
|
.append("\n");
|
||||||
|
stringBuilder.append("IP: ")
|
||||||
|
.append(nmPlayer.getIp())
|
||||||
|
.append("\n");
|
||||||
|
stringBuilder.append("Playtime: ")
|
||||||
|
.append(nmPlayer.getPlaytime())
|
||||||
|
.append("\n");
|
||||||
|
stringBuilder.append("Last Online: ")
|
||||||
|
.append(nmPlayer.getLastlogin())
|
||||||
|
.append("\n");
|
||||||
|
|
||||||
|
sender.sendPlainMessage(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subcommand(permission = "cladis.modstaff.modify", args = {String.class, Player.class, String.class})
|
||||||
|
public void modify(final CommandSender sender, final String arg, final Player target, final String group)
|
||||||
|
{
|
||||||
|
final UUID playerUUID = target.getUniqueId();
|
||||||
|
final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink();
|
||||||
|
final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer =
|
||||||
|
nmLink.getPlayer(playerUUID).orElse(null);
|
||||||
|
|
||||||
|
if (nmPlayer == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage(USER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Map.Entry<Integer, Group> g =
|
||||||
|
nmLink.getLoadedGroups().entrySet().stream().filter(e -> e.getValue().getName().equalsIgnoreCase(group))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
|
||||||
|
if (g == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("That group does not exist!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender instanceof Player s && (nmLink.getPermissionsPlayer(s.getUniqueId())
|
||||||
|
.getPrimaryGroup()
|
||||||
|
.getId() <= g.getKey()))
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("You cannot modify a player to a higher rank than yourself!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.equalsIgnoreCase("add"))
|
||||||
|
{
|
||||||
|
nmLink.getPlayerGroups(playerUUID).add(g.getValue());
|
||||||
|
sender.sendPlainMessage("Added " + target.getName() + " to " + group);
|
||||||
|
}
|
||||||
|
else if (arg.equalsIgnoreCase("remove"))
|
||||||
|
{
|
||||||
|
nmLink.getPlayerGroups(playerUUID).remove(g.getValue());
|
||||||
|
sender.sendPlainMessage("Removed " + target.getName() + " from " + group);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("Invalid argument!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subcommand(permission = "cladis.modstaff.track", args = {String.class, Player.class})
|
||||||
|
public void track(final CommandSender sender, final String arg, final Player target)
|
||||||
|
{
|
||||||
|
final UUID playerUUID = target.getUniqueId();
|
||||||
|
final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink();
|
||||||
|
final nl.chimpgamer.networkmanager.api.models.player.Player nmPlayer =
|
||||||
|
nmLink.getPlayer(playerUUID).orElse(null);
|
||||||
|
|
||||||
|
if (nmPlayer == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage(USER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Group primary = nmLink.getPermissionsPlayer(playerUUID).getPrimaryGroup();
|
||||||
|
final int groupLevel = primary.getId();
|
||||||
|
|
||||||
|
if (arg.equalsIgnoreCase("promote"))
|
||||||
|
{
|
||||||
|
final Group promo = nmLink.getLoadedGroups().get(groupLevel + 1);
|
||||||
|
if (promo == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("That user is already at the highest rank!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nmLink.getPlayerGroups(playerUUID).remove(primary);
|
||||||
|
nmLink.getPlayerGroups(playerUUID).add(promo);
|
||||||
|
sender.sendPlainMessage("Promoted " + target.getName());
|
||||||
|
}
|
||||||
|
else if (arg.equalsIgnoreCase("demote"))
|
||||||
|
{
|
||||||
|
final Group demo = nmLink.getLoadedGroups().get(groupLevel - 1);
|
||||||
|
if (demo == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("That user is already at the lowest rank!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nmLink.getPlayerGroups(playerUUID).remove(primary);
|
||||||
|
nmLink.getPlayerGroups(playerUUID).add(demo);
|
||||||
|
sender.sendPlainMessage("Demoted " + target.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("Invalid argument!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
90
Cladis/src/main/java/fns/cladis/command/OpCommand.java
Normal file
90
Cladis/src/main/java/fns/cladis/command/OpCommand.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Freedom-Network-Suite - https://github.com/AtlasMediaGroup/Freedom-Network-Suite
|
||||||
|
* Copyright (C) 2023 Total Freedom Server Network and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fns.cladis.command;
|
||||||
|
|
||||||
|
|
||||||
|
import fns.cladis.Cladis;
|
||||||
|
import fns.cladis.NMLink;
|
||||||
|
import fns.patchwork.base.Shortcuts;
|
||||||
|
import fns.patchwork.command.Commander;
|
||||||
|
import fns.patchwork.command.annotation.Completion;
|
||||||
|
import fns.patchwork.command.annotation.Info;
|
||||||
|
import fns.patchwork.command.annotation.Permissive;
|
||||||
|
import fns.patchwork.command.annotation.Subcommand;
|
||||||
|
import java.util.UUID;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.permissions.Group;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@Info(
|
||||||
|
name = "op",
|
||||||
|
description = "Op a player.",
|
||||||
|
usage = "/op <player>"
|
||||||
|
)
|
||||||
|
@Permissive(perm = "cladis.op")
|
||||||
|
@Completion(index = 0, args = {"%player%"})
|
||||||
|
public class OpCommand extends Commander
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the
|
||||||
|
* command.
|
||||||
|
* <p>
|
||||||
|
* This constructor will automatically register all subcommands and completions for this command. It will also
|
||||||
|
* automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin which contains this command.
|
||||||
|
*/
|
||||||
|
public OpCommand(@NotNull final JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subcommand(permission = "cladis.op", args = {Player.class})
|
||||||
|
public void op(@NotNull final CommandSender sender, final Player player)
|
||||||
|
{
|
||||||
|
final NMLink nmLink = Shortcuts.provideModule(Cladis.class).getNMLink();
|
||||||
|
final Group opGroup = nmLink.locateGroup("fake_op").orElse(null);
|
||||||
|
final UUID playerUUID = player.getUniqueId();
|
||||||
|
|
||||||
|
if (opGroup == null)
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("Unable to op player. Please contact an administrator.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nmLink.isOp(playerUUID))
|
||||||
|
{
|
||||||
|
sender.sendPlainMessage("Player is already op.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nmLink.getPlayerGroups(playerUUID).add(opGroup);
|
||||||
|
|
||||||
|
sender.sendPlainMessage("You have opped " + player.getName() + ".");
|
||||||
|
player.sendPlainMessage("You have been opped.");
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
package fns.datura;
|
package fns.datura;
|
||||||
|
|
||||||
|
import fns.datura.cmd.LockerCommand;
|
||||||
import fns.datura.features.CommandSpy;
|
import fns.datura.features.CommandSpy;
|
||||||
import fns.datura.features.Fuckoff;
|
import fns.datura.features.Fuckoff;
|
||||||
import fns.datura.punishment.Cager;
|
import fns.datura.punishment.Cager;
|
||||||
@ -30,6 +31,7 @@ import fns.datura.punishment.Halter;
|
|||||||
import fns.datura.punishment.Locker;
|
import fns.datura.punishment.Locker;
|
||||||
import fns.datura.sql.MySQL;
|
import fns.datura.sql.MySQL;
|
||||||
import fns.patchwork.base.Registration;
|
import fns.patchwork.base.Registration;
|
||||||
|
import fns.patchwork.command.CommandHandler;
|
||||||
import fns.patchwork.service.SubscriptionProvider;
|
import fns.patchwork.service.SubscriptionProvider;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -55,17 +57,19 @@ public class Datura extends JavaPlugin
|
|||||||
Registration.getServiceTaskRegistry()
|
Registration.getServiceTaskRegistry()
|
||||||
.registerService(SubscriptionProvider.syncService(this, locker));
|
.registerService(SubscriptionProvider.syncService(this, locker));
|
||||||
Registration.getServiceTaskRegistry()
|
Registration.getServiceTaskRegistry()
|
||||||
.registerService(SubscriptionProvider.syncService(this, cager));
|
.registerService(SubscriptionProvider.syncService(this, cager));
|
||||||
Registration.getServiceTaskRegistry()
|
Registration.getServiceTaskRegistry()
|
||||||
.registerService(SubscriptionProvider.syncService(this, fuckoff));
|
.registerService(SubscriptionProvider.syncService(this, fuckoff));
|
||||||
|
|
||||||
Bukkit.getPluginManager()
|
Bukkit.getPluginManager()
|
||||||
.registerEvents(halter, this);
|
.registerEvents(halter, this);
|
||||||
Bukkit.getPluginManager()
|
Bukkit.getPluginManager()
|
||||||
.registerEvents(commandSpy, this);
|
.registerEvents(commandSpy, this);
|
||||||
|
|
||||||
|
new CommandHandler(this).registerCommands(LockerCommand.class);
|
||||||
|
|
||||||
Registration.getModuleRegistry()
|
Registration.getModuleRegistry()
|
||||||
.addModule(this);
|
.addModule(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MySQL getSQL()
|
public MySQL getSQL()
|
||||||
|
@ -23,8 +23,10 @@
|
|||||||
|
|
||||||
package fns.fossil;
|
package fns.fossil;
|
||||||
|
|
||||||
|
import fns.fossil.cmd.CakeCommand;
|
||||||
import fns.fossil.trail.Trailer;
|
import fns.fossil.trail.Trailer;
|
||||||
import fns.patchwork.base.Registration;
|
import fns.patchwork.base.Registration;
|
||||||
|
import fns.patchwork.command.CommandHandler;
|
||||||
import fns.patchwork.service.SubscriptionProvider;
|
import fns.patchwork.service.SubscriptionProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@ -36,9 +38,11 @@ public class Fossil extends JavaPlugin
|
|||||||
{
|
{
|
||||||
Registration.getServiceTaskRegistry()
|
Registration.getServiceTaskRegistry()
|
||||||
.registerService(
|
.registerService(
|
||||||
SubscriptionProvider.syncService(this, trailer));
|
SubscriptionProvider.syncService(this, trailer));
|
||||||
|
|
||||||
|
new CommandHandler(this).registerCommands(CakeCommand.class);
|
||||||
|
|
||||||
Registration.getModuleRegistry()
|
Registration.getModuleRegistry()
|
||||||
.addModule(this);
|
.addModule(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,11 @@
|
|||||||
|
|
||||||
package fns.patchwork.command;
|
package fns.patchwork.command;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the registration of commands. The plugin which initializes this class should be the plugin that is
|
* Handles the registration of commands. The plugin which initializes this class should be the plugin that is
|
||||||
@ -64,4 +66,32 @@ public class CommandHandler
|
|||||||
Bukkit.getCommandMap()
|
Bukkit.getCommandMap()
|
||||||
.register(plugin.getName(), delegate);
|
.register(plugin.getName(), delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers all commands in the specified package that contains the provided class. This method will automatically
|
||||||
|
* delegate the command information to the Bukkit API and register with the {@link CommandMap}.
|
||||||
|
*
|
||||||
|
* @param commandClass The class to register commands from.
|
||||||
|
* @param <T> The type of the command.
|
||||||
|
*/
|
||||||
|
public <T extends Commander> void registerCommands(final Class<T> commandClass)
|
||||||
|
{
|
||||||
|
final Reflections reflections = new Reflections(commandClass.getPackageName());
|
||||||
|
reflections.getSubTypesOf(commandClass)
|
||||||
|
.stream()
|
||||||
|
.map(c ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return c.getDeclaredConstructor(JavaPlugin.class).newInstance(this);
|
||||||
|
}
|
||||||
|
catch (ReflectiveOperationException ex)
|
||||||
|
{
|
||||||
|
plugin.getSLF4JLogger().error("Unable to register command: " + c.getName(), ex);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.forEach(this::registerCommand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
package fns.patchwork.provider;
|
package fns.patchwork.provider;
|
||||||
|
|
||||||
import fns.patchwork.command.BukkitDelegate;
|
|
||||||
import fns.patchwork.command.annotation.Subcommand;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -33,8 +31,8 @@ import net.kyori.adventure.text.Component;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -65,12 +63,13 @@ public class ContextProvider
|
|||||||
public <T> T fromString(final String string, final Class<T> clazz)
|
public <T> T fromString(final String string, final Class<T> clazz)
|
||||||
{
|
{
|
||||||
return Stream.of(toBoolean(string, clazz),
|
return Stream.of(toBoolean(string, clazz),
|
||||||
|
toLong(string, clazz),
|
||||||
toDouble(string, clazz),
|
toDouble(string, clazz),
|
||||||
toInt(string, clazz),
|
toInt(string, clazz),
|
||||||
toLong(string, clazz),
|
|
||||||
toFloat(string, clazz),
|
toFloat(string, clazz),
|
||||||
toMaterial(string, clazz),
|
toMaterial(string, clazz),
|
||||||
toPlayer(string, clazz),
|
toPlayer(string, clazz),
|
||||||
|
toOfflinePlayer(string, clazz),
|
||||||
toWorld(string, clazz),
|
toWorld(string, clazz),
|
||||||
toLocation(string, clazz),
|
toLocation(string, clazz),
|
||||||
toComponent(string, clazz))
|
toComponent(string, clazz))
|
||||||
@ -127,7 +126,7 @@ public class ContextProvider
|
|||||||
|
|
||||||
private @Nullable Long toLong(final String string, final Class<?> clazz)
|
private @Nullable Long toLong(final String string, final Class<?> clazz)
|
||||||
{
|
{
|
||||||
if (clazz != Long.class)
|
if (clazz != Long.class || !string.endsWith("L"))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -142,7 +141,7 @@ public class ContextProvider
|
|||||||
|
|
||||||
private @Nullable Float toFloat(final String string, final Class<?> clazz)
|
private @Nullable Float toFloat(final String string, final Class<?> clazz)
|
||||||
{
|
{
|
||||||
if (clazz != Float.class)
|
if (clazz != Float.class || !string.endsWith("F"))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -169,6 +168,16 @@ public class ContextProvider
|
|||||||
return Bukkit.getPlayer(string);
|
return Bukkit.getPlayer(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OfflinePlayer toOfflinePlayer(final String string, final Class<?> clazz)
|
||||||
|
{
|
||||||
|
if (clazz != OfflinePlayer.class)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Bukkit.getOfflinePlayer(string);
|
||||||
|
}
|
||||||
|
|
||||||
private @Nullable World toWorld(final String string, final Class<?> clazz)
|
private @Nullable World toWorld(final String string, final Class<?> clazz)
|
||||||
{
|
{
|
||||||
if (clazz != World.class)
|
if (clazz != World.class)
|
||||||
|
@ -3,4 +3,4 @@ include 'Patchwork'
|
|||||||
include 'Datura'
|
include 'Datura'
|
||||||
include 'Fossil'
|
include 'Fossil'
|
||||||
include 'Corvo'
|
include 'Corvo'
|
||||||
|
include 'Cladis'
|
Loading…
Reference in New Issue
Block a user