Initial Commit
This commit is contained in:
parent
9ccaaca6da
commit
1a8fdede45
8 changed files with 212 additions and 14 deletions
30
pom.xml
30
pom.xml
|
|
@ -14,14 +14,7 @@
|
|||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
|
|
@ -33,4 +26,25 @@
|
|||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.28</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,17 +1,53 @@
|
|||
package me.firephoenix.anticheatmanager;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.firephoenix.anticheatmanager.cmds.AnticheatManagerGUI;
|
||||
import me.firephoenix.anticheatmanager.cmds.AnticheatSelector;
|
||||
import me.firephoenix.anticheatmanager.listener.InvClick;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public final class AnticheatManager extends JavaPlugin {
|
||||
|
||||
public static AnticheatManager INSTANCE;
|
||||
|
||||
public LuckPerms luckPermsAPI;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
setInstance(this);
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
getCommand("anticheatselect").setExecutor(new AnticheatSelector());
|
||||
|
||||
getCommand("anticheatgui").setExecutor(new AnticheatManagerGUI());
|
||||
|
||||
getServer().getPluginManager().registerEvents(new InvClick(), this);
|
||||
|
||||
RegisteredServiceProvider<LuckPerms> provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
|
||||
if (provider != null) {
|
||||
luckPermsAPI = provider.getProvider();
|
||||
} else {
|
||||
getLogger().log(Level.SEVERE, "LuckPerms API is not available, disabling...");
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
public void setInstance(AnticheatManager INSTANCE) {
|
||||
AnticheatManager.INSTANCE = INSTANCE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,44 @@
|
|||
package me.firephoenix.anticheatmanager.cmds;
|
||||
|
||||
import me.firephoenix.anticheatmanager.AnticheatManager;
|
||||
import me.firephoenix.anticheatmanager.util.ItemBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2023, All Rights Reserved.
|
||||
*/
|
||||
public class AnticheatManagerGUI {
|
||||
public class AnticheatManagerGUI implements CommandExecutor {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String string, String[] args) {
|
||||
Player player = AnticheatManager.INSTANCE.getServer().getPlayer(commandSender.getName());
|
||||
if (player != null) {
|
||||
List<String> anticheatList = AnticheatManager.INSTANCE.getConfig().getStringList("name-list");
|
||||
Inventory inventory = Bukkit.createInventory(player, 27, "Anticheats");
|
||||
for (int i = 0; i < inventory.getSize(); i++) {
|
||||
inventory.setItem(i, new ItemBuilder(Material.STAINED_GLASS_PANE).toItemStack());
|
||||
}
|
||||
for (int i = 0; i < anticheatList.size(); i++) {
|
||||
Material material = Material.valueOf(AnticheatManager.INSTANCE.getConfig().getString("anticheats." + anticheatList.get(i) + ".material"));
|
||||
String name = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + anticheatList.get(i) + ".name");
|
||||
String version = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + anticheatList.get(i) + ".version");
|
||||
String price = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + anticheatList.get(i) + ".price");
|
||||
inventory.setItem(i, new ItemBuilder(material).setName(name).addLoreLine("Version: " + version).addLoreLine("Price: " + price).toItemStack());
|
||||
}
|
||||
player.openInventory(inventory);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,75 @@
|
|||
package me.firephoenix.anticheatmanager.cmds;/**
|
||||
package me.firephoenix.anticheatmanager.cmds;
|
||||
|
||||
import me.firephoenix.anticheatmanager.AnticheatManager;
|
||||
import net.luckperms.api.model.data.NodeMap;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.NodeBuilder;
|
||||
import net.luckperms.api.node.NodeEqualityPredicate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2023, All Rights Reserved.
|
||||
*/
|
||||
public class AnticheatSelector {
|
||||
public class AnticheatSelector implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, Command command, String string, String[] args) {
|
||||
Player player = AnticheatManager.INSTANCE.getServer().getPlayer(commandSender.getName());
|
||||
if (player == null) return false;
|
||||
List<String> anticheatList = AnticheatManager.INSTANCE.getConfig().getStringList("name-list");
|
||||
if (args.length != 1) {
|
||||
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cUsage: acsel <name>"));
|
||||
return true;
|
||||
}
|
||||
if (anticheatList.isEmpty()) {
|
||||
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNo Anticheats configured!"));
|
||||
return true;
|
||||
}
|
||||
if (anticheatList.contains(args[0])) {
|
||||
anticheatList.remove(args[0]);
|
||||
|
||||
String bypassPermission = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + args[0] + ".bypass-permission");
|
||||
|
||||
// Manage permissions via luckperms, because that is what I use and this will only be a private plugin
|
||||
if (AnticheatManager.INSTANCE.getLuckPermsAPI().getUserManager().getUser(player.getUniqueId()) == null) {
|
||||
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCouldn't manage permissions via the LuckPerms API!"));
|
||||
return true;
|
||||
}
|
||||
Node permissionNode = Node.builder(bypassPermission).negated(true).build();
|
||||
NodeMap permissions = AnticheatManager.INSTANCE.getLuckPermsAPI().getUserManager().getUser(player.getUniqueId()).data();
|
||||
|
||||
String anticheatname = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + args[0] + ".name");
|
||||
String anticheatVersion = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + args[0] + ".version");
|
||||
|
||||
//Remove all other anticheat bypass permissions
|
||||
|
||||
anticheatList.forEach(anticheat -> {
|
||||
String permission = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + anticheat + ".bypass-permission");
|
||||
Node permissionNode2 = Node.builder(permission).negated(true).build();
|
||||
permissions.remove(permissionNode2);
|
||||
});
|
||||
|
||||
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cChanged Anticheat to " + anticheatname + " V" + anticheatVersion));
|
||||
|
||||
//Add bypass permission for selected anticheat
|
||||
|
||||
permissions.add(permissionNode);
|
||||
|
||||
AnticheatManager.INSTANCE.getLuckPermsAPI().getUserManager().saveUser(Objects.requireNonNull(AnticheatManager.INSTANCE.getLuckPermsAPI().getUserManager().getUser(player.getUniqueId())));
|
||||
return true;
|
||||
} else {
|
||||
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCouldn't find an anticheat with the name: " + args[0] + "."));
|
||||
commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', "List of all anticheats: " + anticheatList));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,31 @@
|
|||
package me.firephoenix.anticheatmanager.listener;
|
||||
|
||||
import me.firephoenix.anticheatmanager.AnticheatManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
/**
|
||||
* @author NieGestorben
|
||||
* Copyright© (c) 2023, All Rights Reserved.
|
||||
*/
|
||||
public class InvClick {
|
||||
public class InvClick implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInvClick(InventoryClickEvent e) {
|
||||
Player player = (Player) e.getWhoClicked();
|
||||
if (e.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
AnticheatManager.INSTANCE.getConfig().getStringList("name-list").forEach(name -> {
|
||||
Material material = Material.valueOf(AnticheatManager.INSTANCE.getConfig().getString("anticheats." + name + ".material"));
|
||||
String acName = AnticheatManager.INSTANCE.getConfig().getString("anticheats." + name + ".name");
|
||||
if (e.getCurrentItem().getType() == material && e.getCurrentItem().getItemMeta().getDisplayName().equals(acName)) {
|
||||
player.performCommand("acsel " + name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package me.firephoenix.anticheatmanager.cmds.util;
|
||||
package me.firephoenix.anticheatmanager.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
name-list: # List of all anticheats, please enter the exact same name as in anticheats.NAME, Max of 9 anticheats is currently supported.
|
||||
- example
|
||||
anticheats:
|
||||
example: # Name of the anticheat, only lowercase characters please
|
||||
bypass-permission: inferno.bypass # Permission to bypass the anticheat
|
||||
name: Example # Name of the anticheat but as a string, you can use lower and upper case characters!
|
||||
version: 1.0.0 # Version of the anticheat
|
||||
price: Free # Price (free if it's not paid)
|
||||
material: BLAZE_POWDER # Bukkit Material for GUI, only <=1.8.8 Materials
|
||||
|
|
@ -1,3 +1,14 @@
|
|||
name: AnticheatManager
|
||||
version: '${project.version}'
|
||||
version: '1.0'
|
||||
main: me.firephoenix.anticheatmanager.AnticheatManager
|
||||
commands:
|
||||
anticheatselect:
|
||||
description: Select an anticheat to test
|
||||
usage: /anticheatsel <anticheat name>
|
||||
aliases: [acsel]
|
||||
permission: anticheatmanager.select
|
||||
anticheatgui:
|
||||
description: Select an anticheat to test
|
||||
usage: /anticheatgui
|
||||
aliases: [ acgui ]
|
||||
permission: anticheatmanager.gui
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue