callable) {
663 | super(chartId);
664 | this.callable = callable;
665 | }
666 |
667 | @Override
668 | protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
669 | int value = callable.call();
670 | if (value == 0) {
671 | // Null = skip the chart
672 | return null;
673 | }
674 | return new JsonObjectBuilder().appendField("value", value).build();
675 | }
676 | }
677 |
678 | /**
679 | * An extremely simple JSON builder.
680 | *
681 | * While this class is neither feature-rich nor the most performant one, it's sufficient enough
682 | * for its use-case.
683 | */
684 | public static class JsonObjectBuilder {
685 |
686 | private StringBuilder builder = new StringBuilder();
687 |
688 | private boolean hasAtLeastOneField = false;
689 |
690 | public JsonObjectBuilder() {
691 | builder.append("{");
692 | }
693 |
694 | /**
695 | * Appends a null field to the JSON.
696 | *
697 | * @param key The key of the field.
698 | * @return A reference to this object.
699 | */
700 | public JsonObjectBuilder appendNull(String key) {
701 | appendFieldUnescaped(key, "null");
702 | return this;
703 | }
704 |
705 | /**
706 | * Appends a string field to the JSON.
707 | *
708 | * @param key The key of the field.
709 | * @param value The value of the field.
710 | * @return A reference to this object.
711 | */
712 | public JsonObjectBuilder appendField(String key, String value) {
713 | if (value == null) {
714 | throw new IllegalArgumentException("JSON value must not be null");
715 | }
716 | appendFieldUnescaped(key, "\"" + escape(value) + "\"");
717 | return this;
718 | }
719 |
720 | /**
721 | * Appends an integer field to the JSON.
722 | *
723 | * @param key The key of the field.
724 | * @param value The value of the field.
725 | * @return A reference to this object.
726 | */
727 | public JsonObjectBuilder appendField(String key, int value) {
728 | appendFieldUnescaped(key, String.valueOf(value));
729 | return this;
730 | }
731 |
732 | /**
733 | * Appends an object to the JSON.
734 | *
735 | * @param key The key of the field.
736 | * @param object The object.
737 | * @return A reference to this object.
738 | */
739 | public JsonObjectBuilder appendField(String key, JsonObject object) {
740 | if (object == null) {
741 | throw new IllegalArgumentException("JSON object must not be null");
742 | }
743 | appendFieldUnescaped(key, object.toString());
744 | return this;
745 | }
746 |
747 | /**
748 | * Appends a string array to the JSON.
749 | *
750 | * @param key The key of the field.
751 | * @param values The string array.
752 | * @return A reference to this object.
753 | */
754 | public JsonObjectBuilder appendField(String key, String[] values) {
755 | if (values == null) {
756 | throw new IllegalArgumentException("JSON values must not be null");
757 | }
758 | String escapedValues =
759 | Arrays.stream(values)
760 | .map(value -> "\"" + escape(value) + "\"")
761 | .collect(Collectors.joining(","));
762 | appendFieldUnescaped(key, "[" + escapedValues + "]");
763 | return this;
764 | }
765 |
766 | /**
767 | * Appends an integer array to the JSON.
768 | *
769 | * @param key The key of the field.
770 | * @param values The integer array.
771 | * @return A reference to this object.
772 | */
773 | public JsonObjectBuilder appendField(String key, int[] values) {
774 | if (values == null) {
775 | throw new IllegalArgumentException("JSON values must not be null");
776 | }
777 | String escapedValues =
778 | Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
779 | appendFieldUnescaped(key, "[" + escapedValues + "]");
780 | return this;
781 | }
782 |
783 | /**
784 | * Appends an object array to the JSON.
785 | *
786 | * @param key The key of the field.
787 | * @param values The integer array.
788 | * @return A reference to this object.
789 | */
790 | public JsonObjectBuilder appendField(String key, JsonObject[] values) {
791 | if (values == null) {
792 | throw new IllegalArgumentException("JSON values must not be null");
793 | }
794 | String escapedValues =
795 | Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
796 | appendFieldUnescaped(key, "[" + escapedValues + "]");
797 | return this;
798 | }
799 |
800 | /**
801 | * Appends a field to the object.
802 | *
803 | * @param key The key of the field.
804 | * @param escapedValue The escaped value of the field.
805 | */
806 | private void appendFieldUnescaped(String key, String escapedValue) {
807 | if (builder == null) {
808 | throw new IllegalStateException("JSON has already been built");
809 | }
810 | if (key == null) {
811 | throw new IllegalArgumentException("JSON key must not be null");
812 | }
813 | if (hasAtLeastOneField) {
814 | builder.append(",");
815 | }
816 | builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
817 | hasAtLeastOneField = true;
818 | }
819 |
820 | /**
821 | * Builds the JSON string and invalidates this builder.
822 | *
823 | * @return The built JSON string.
824 | */
825 | public JsonObject build() {
826 | if (builder == null) {
827 | throw new IllegalStateException("JSON has already been built");
828 | }
829 | JsonObject object = new JsonObject(builder.append("}").toString());
830 | builder = null;
831 | return object;
832 | }
833 |
834 | /**
835 | * Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
836 | *
837 | *
This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
838 | * Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
839 | *
840 | * @param value The value to escape.
841 | * @return The escaped value.
842 | */
843 | private static String escape(String value) {
844 | final StringBuilder builder = new StringBuilder();
845 | for (int i = 0; i < value.length(); i++) {
846 | char c = value.charAt(i);
847 | if (c == '"') {
848 | builder.append("\\\"");
849 | } else if (c == '\\') {
850 | builder.append("\\\\");
851 | } else if (c <= '\u000F') {
852 | builder.append("\\u000").append(Integer.toHexString(c));
853 | } else if (c <= '\u001F') {
854 | builder.append("\\u00").append(Integer.toHexString(c));
855 | } else {
856 | builder.append(c);
857 | }
858 | }
859 | return builder.toString();
860 | }
861 |
862 | /**
863 | * A super simple representation of a JSON object.
864 | *
865 | *
This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
866 | * allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
867 | * JsonObject)}.
868 | */
869 | public static class JsonObject {
870 |
871 | private final String value;
872 |
873 | private JsonObject(String value) {
874 | this.value = value;
875 | }
876 |
877 | @Override
878 | public String toString() {
879 | return value;
880 | }
881 | }
882 | }
883 | }
884 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/Utils/OfflineScannerResultType.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.Utils;
2 |
3 | public enum OfflineScannerResultType {
4 | Authorized,
5 | BlackListedPerms,
6 | UnlistedOP,
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/Utils/Prefix.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.Utils;
2 |
3 | public class Prefix {
4 | //this class provide temp prefix solution until we add messages.yml
5 |
6 | public static final String INFO = "§7[§bOPProtector§7] §f";
7 | public static final String ERROR = "§7[§bOPProtector§7] §c";
8 | public static final String WARNING = "§7[§bOPProtector§7] §e";
9 | public static final String SUCCESS = "§7[§bOPProtector§7] §a";
10 | public static final String DEBUG = "§7[§bOPProtector§7] §3";
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/VerificationProcess/PasswordFlash.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.VerificationProcess;
2 |
3 |
4 | import org.bukkit.ChatColor;
5 | import org.bukkit.Sound;
6 | import org.bukkit.entity.Player;
7 | import org.bukkit.scheduler.BukkitRunnable;
8 | import org.bukkit.scheduler.BukkitTask;
9 | import org.kasun.opprotector.OPProtector;
10 | import org.kasun.opprotector.Utils.CommandExecutor;
11 | import org.kasun.opprotector.Utils.Log;
12 | import org.kasun.opprotector.Utils.Prefix;
13 |
14 | import java.util.List;
15 |
16 | public class PasswordFlash {
17 | private BukkitTask titleTask;
18 | private BukkitTask countdownTask;
19 | private boolean stopTasks = false;
20 | private int countdownSeconds = 20;
21 | private Player player;
22 | private OPProtector plugin = OPProtector.getInstance();
23 | public PasswordFlash(Player Player) {
24 | this.player = Player;
25 | }
26 |
27 | public void start(){
28 | titleTask = new BukkitRunnable() {
29 | boolean flash = false;
30 |
31 | @Override
32 | public void run() {
33 |
34 | String titlebefore = ChatColor.GOLD + "OP" + ChatColor.YELLOW + "P";
35 | String title = ChatColor.BOLD + titlebefore;
36 |
37 | if (flash) {
38 | player.sendTitle(title, ChatColor.RED + "█████████", 0, 15, 0);;
39 | Sound sound = Sound.BLOCK_NOTE_BLOCK_HARP;
40 | player.playSound(player.getLocation(), sound, 1, 1);
41 | } else {
42 | player.sendTitle("", "", 0, 20, 0);
43 | }
44 |
45 | flash = !flash;
46 | }
47 | }.runTaskTimer(plugin, 0, 10); // Change the flashing interval if desired (10 ticks = 0.5 seconds)
48 |
49 | countdownTask = new BukkitRunnable() {
50 | int remainingTime = plugin.getMainManager().getConfigManager().getMainConfig().interval_secounds;
51 | @Override
52 | public void run() {
53 | if (remainingTime > 0) {
54 | player.sendMessage(Prefix.ERROR + "You have " + remainingTime + " seconds to enter the password.(/pas )");
55 | remainingTime--;
56 | } else {
57 | List commands = plugin.getMainManager().getConfigManager().getMainConfig().failed_password_timeout;
58 | CommandExecutor commandExecutor = new CommandExecutor(player, commands);
59 | Log log = plugin.getMainManager().getLog();
60 | log.failedPassword(player);
61 | player.setOp(false);
62 | player.kickPlayer(ChatColor.RED + "You have failed to enter the password in time.");
63 | cancel();
64 | }
65 | }
66 | }.runTaskTimer(plugin, 0, 20); // Change the countdown interval if desired (20 ticks = 1 second)
67 | }
68 |
69 | public void stopTasks() {
70 | stopTasks = true;
71 | if (titleTask != null) {
72 | titleTask.cancel();
73 | }
74 | if (countdownTask != null) {
75 | countdownTask.cancel();
76 | }
77 | }
78 |
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/VerificationProcess/PasswordVerification.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.VerificationProcess;
2 |
3 |
4 |
5 | import org.bukkit.entity.Player;
6 | import org.kasun.opprotector.OPProtector;
7 | import org.kasun.opprotector.inventories.PasswordGui;
8 |
9 |
10 |
11 |
12 | public class PasswordVerification {
13 | private OPProtector plugin = OPProtector.getInstance();
14 | private boolean isgui;
15 | public PasswordVerification(Player player) {
16 | isgui = plugin.getMainManager().getConfigManager().getMainConfig().use_gui;
17 | if (isgui) {
18 | String password = plugin.getMainManager().getConfigManager().getOperatorConfig().getOperator(player.getName()).getPassword();
19 | PasswordGui passwordGui = new PasswordGui("Enter The Password", password, player);
20 | passwordGui.show();
21 | }
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/VerificationProcess/VerificationProcessManager.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.VerificationProcess;
2 |
3 | import org.bukkit.GameMode;
4 | import org.bukkit.entity.Player;
5 | import org.kasun.opprotector.AuthObjects.IpTable;
6 | import org.kasun.opprotector.OPProtector;
7 | import org.kasun.opprotector.Punishments.Ban;
8 | import org.kasun.opprotector.Punishments.Lockdown;
9 | import org.kasun.opprotector.Utils.CommandExecutor;
10 |
11 | import java.util.List;
12 | import java.util.concurrent.ConcurrentHashMap;
13 |
14 | public class VerificationProcessManager {
15 | private static final OPProtector plugin = OPProtector.getInstance();
16 | private List blacklistedPermissions;
17 | private PasswordFlash passwordFlash;
18 | private ConcurrentHashMap verificationStatusMap;
19 | private boolean allowScanBlackListedPerms;
20 | private boolean allowScanCreative;
21 | private IpTable ipTable;
22 |
23 | public VerificationProcessManager() {
24 | verificationStatusMap = new ConcurrentHashMap<>();
25 | }
26 |
27 | public void start(Player player) {
28 | blacklistedPermissions = plugin.getMainManager().getConfigManager().getMainConfig().blacklisted_permissions;
29 | allowScanCreative = plugin.getMainManager().getConfigManager().getMainConfig().scan_for_gamemode_creative;
30 | allowScanBlackListedPerms = plugin.getMainManager().getConfigManager().getMainConfig().scan_for_blacklisted_permissions;
31 | boolean opContainsInYml = plugin.getMainManager().getConfigManager().getOperatorConfig().isContains(player.getName());
32 |
33 | if (allowScanBlackListedPerms) {
34 | checkForBlacklistedPermissions(player, opContainsInYml);
35 | }
36 |
37 | if (player.isOp() || (player.getGameMode() == GameMode.CREATIVE && allowScanCreative)) {
38 | checkForOp(player, opContainsInYml);
39 | }
40 | }
41 |
42 | private void checkForBlacklistedPermissions(Player player, boolean opContainsInYml) {
43 | for (String permission : blacklistedPermissions) {
44 | if (player.hasPermission(permission) && !opContainsInYml) {
45 | executeCommandsAndBanPlayer(player, "You aren't listed in OPProtector/operators.yml", "Unauthorized Access");
46 | }
47 | }
48 | }
49 |
50 | private void checkForOp(Player player, boolean opContainsInYml) {
51 | if (!opContainsInYml) {
52 | executeCommandsAndBanPlayer(player, "You aren't listed in OPProtector/operators.yml", "Unauthorized Access");
53 | } else if (plugin.getMainManager().getAuthorizedPlayers().isAuthorizedPlayer(player) && isPlayerVerified(player)) {
54 | announceVerified(player);
55 | } else if (isPlayerInPasswordVerification(player)) {
56 | // Do nothing
57 | } else if (isPlayerLoggedInUsingSameIp(player)) {
58 | announceVerified(player);
59 | verificationStatusMap.put(player.getName(), VerificationStatus.VERIFIED);
60 | } else if (!plugin.getMainManager().getConfigManager().getMainConfig().password_enabled) {
61 | announceVerified(player);
62 | verificationStatusMap.put(player.getName(), VerificationStatus.VERIFIED);
63 | } else {
64 | startPasswordVerificationProcess(player);
65 | }
66 | }
67 |
68 | private void executeCommandsAndBanPlayer(Player player, String banReason, String logReason) {
69 | List commands = plugin.getMainManager().getConfigManager().getMainConfig().not_in_operators_list;
70 | CommandExecutor commandExecutor = new CommandExecutor(player, commands);
71 | Ban ban = new Ban(player, banReason, logReason);
72 | plugin.getMainManager().getLog().banned(player, logReason);
73 | }
74 |
75 | private boolean isPlayerVerified(Player player) {
76 | return verificationStatusMap.containsKey(player.getName()) && verificationStatusMap.get(player.getName()) == VerificationStatus.VERIFIED;
77 | }
78 |
79 | private void announceVerified(Player player) {
80 | VerifiedAnnouncer verifiedAnnouncer = new VerifiedAnnouncer(player);
81 | }
82 |
83 | private boolean isPlayerInPasswordVerification(Player player) {
84 | return verificationStatusMap.containsKey(player.getName()) && verificationStatusMap.get(player.getName()) == VerificationStatus.IN_PASSWORD_VERIFICATION;
85 | }
86 |
87 | private boolean isPlayerLoggedInUsingSameIp(Player player) {
88 | ipTable = plugin.getMainManager().getIpTable();
89 | return ipTable.IsContains(player) && ipTable.isIp(player);
90 | }
91 |
92 | private void startPasswordVerificationProcess(Player player) {
93 | verificationStatusMap.put(player.getName(), VerificationStatus.IN_PASSWORD_VERIFICATION);
94 | Lockdown lockdown = plugin.getMainManager().getPunishmentManager().getLockdown();
95 | lockdown.lockPlayer(player);
96 | PasswordVerification passwordVerification = new PasswordVerification(player);
97 | passwordFlash = new PasswordFlash(player);
98 | passwordFlash.start();
99 | }
100 |
101 | public void setVerified(Player player) {
102 | passwordFlash.stopTasks();
103 | plugin.getMainManager().getAuthorizedPlayers().addAuthorizedPlayer(player);
104 |
105 | ipTable = plugin.getMainManager().getIpTable();
106 | ipTable.addIp(player);
107 |
108 | Lockdown lockdown = plugin.getMainManager().getPunishmentManager().getLockdown();
109 | lockdown.unlockPlayer(player);
110 |
111 | announceVerified(player);
112 | plugin.getMainManager().getLog().authorized(player);
113 | verificationStatusMap.put(player.getName(), VerificationStatus.VERIFIED);
114 | }
115 |
116 | public PasswordFlash getPasswordFlash() {
117 | return passwordFlash;
118 | }
119 |
120 | public ConcurrentHashMap getVerificationStatusMap() {
121 | return verificationStatusMap;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/VerificationProcess/VerificationStatus.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.VerificationProcess;
2 |
3 | public enum VerificationStatus {
4 | NOT_VERIFIED,
5 | IN_PASSWORD_VERIFICATION,
6 | VERIFIED;
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/VerificationProcess/VerifiedAnnouncer.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.VerificationProcess;
2 |
3 |
4 | import org.bukkit.Bukkit;
5 | import org.bukkit.ChatColor;
6 |
7 | import org.bukkit.OfflinePlayer;
8 | import org.bukkit.Sound;
9 | import org.bukkit.entity.Player;
10 |
11 | import org.bukkit.scheduler.BukkitRunnable;
12 | import org.kasun.opprotector.OPProtector;
13 | import org.kasun.opprotector.Utils.Prefix;
14 |
15 |
16 | import java.util.Set;
17 |
18 | public class VerifiedAnnouncer {
19 | OPProtector plugin = OPProtector.getInstance();
20 |
21 | public VerifiedAnnouncer(Player player) {
22 |
23 |
24 |
25 | sendTitile(player);
26 |
27 |
28 | Set operatorSet = plugin.getServer().getOperators();
29 |
30 | for (OfflinePlayer offlinePlayer : operatorSet) {
31 | if (offlinePlayer.isOnline()) {
32 | Player onlinePlayer = offlinePlayer.getPlayer();
33 | onlinePlayer.sendMessage(Prefix.ERROR + "[" + player.getName() + "] " + ChatColor.BLUE + "[" + player.getAddress().getHostName() + "]" + ChatColor.GRAY + " is Authorized, and now have Operator Access ✔");
34 |
35 | }
36 | }
37 | }
38 |
39 |
40 | private void sendTitile(Player player){
41 |
42 | //send animated title
43 | BukkitRunnable titleTask = new BukkitRunnable() {
44 | int tick = 0;
45 | String titlebefore = ChatColor.GOLD + "OP" + ChatColor.YELLOW + "P";
46 | String title = ChatColor.BOLD + titlebefore;
47 |
48 | @Override
49 | public void run() {
50 | if (tick < 1) {
51 |
52 | player.sendTitle(title, ChatColor.GREEN + "█", 1, 10, 0);
53 | sleep(200);
54 |
55 | player.sendTitle(title, ChatColor.GREEN + "██", 0, 10, 0);
56 | sleep(200);
57 |
58 | player.sendTitle(title, ChatColor.GREEN + "███", 0, 10, 0);
59 | sleep(200);
60 |
61 | player.sendTitle(title, ChatColor.GREEN + "████", 0, 10, 0);
62 | sleep(200);
63 |
64 | player.sendTitle(title, ChatColor.GREEN + "█████", 0, 10, 0);
65 | sleep(200);
66 |
67 | player.sendTitle(title, ChatColor.GREEN + "██████", 0, 10, 0);
68 | sleep(200);
69 |
70 | player.sendTitle(title, ChatColor.GREEN + "███████", 0, 10, 0);
71 | sleep(200);
72 |
73 | player.sendTitle(title, ChatColor.GREEN + "████████", 0, 10, 0);
74 | sleep(200);
75 |
76 | player.sendTitle(title, ChatColor.GREEN + "█████████", 0, 10, 0);
77 | sleep(200);
78 |
79 | Sound sound = Sound.BLOCK_NOTE_BLOCK_HARP;
80 | player.playSound(player.getLocation(), sound, 5, 1);
81 |
82 | player.sendTitle(title, ChatColor.GREEN + "Authenticated!", 0, 100, 20);
83 | tick++;
84 | } else {
85 | // Animation is done, so cancel the task
86 | this.cancel();
87 | }
88 | }
89 |
90 | private void sleep(int ms) {
91 | try{
92 | Thread.sleep(ms);
93 | } catch (InterruptedException e) {
94 | e.printStackTrace();
95 | }
96 | }
97 |
98 | };
99 |
100 | titleTask.runTaskTimerAsynchronously(plugin, 0, 20*5); // 1 tick interval
101 |
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/org/kasun/opprotector/inventories/PasswordGui.java:
--------------------------------------------------------------------------------
1 | package org.kasun.opprotector.inventories;
2 |
3 | import com.github.stefvanschie.inventoryframework.gui.GuiItem;
4 | import com.github.stefvanschie.inventoryframework.gui.type.AnvilGui;
5 | import com.github.stefvanschie.inventoryframework.pane.StaticPane;
6 | import org.bukkit.ChatColor;
7 | import org.bukkit.Material;
8 | import org.bukkit.entity.Player;
9 | import org.bukkit.inventory.ItemStack;
10 | import org.bukkit.inventory.meta.ItemMeta;
11 | import org.kasun.opprotector.OPProtector;
12 | import org.kasun.opprotector.Utils.Prefix;
13 | import org.kasun.opprotector.VerificationProcess.VerificationProcessManager;
14 | import org.kasun.opprotector.VerificationProcess.VerificationStatus;
15 |
16 |
17 | public class PasswordGui {
18 | private String title;
19 | private String correctPassword;
20 | private Player player;
21 | private boolean isPasswordCorrect = false;
22 | private int attempts = 0;
23 | private VerificationProcessManager verificationProcessManager;
24 | OPProtector plugin = OPProtector.getInstance();
25 |
26 | public PasswordGui(String title, String correctPassword, Player player) {
27 | this.title = title;
28 | this.correctPassword = correctPassword;
29 | this.player = player;
30 | verificationProcessManager = OPProtector.getInstance().getMainManager().getVerificationProcessManager();
31 | }
32 |
33 | public void show(){
34 |
35 |
36 | AnvilGui gui = new AnvilGui(title);
37 | ItemStack itemStack1 = new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE);
38 | ItemMeta itemMeta1 = itemStack1.getItemMeta();
39 | itemMeta1.setDisplayName(" ");
40 | itemStack1.setItemMeta(itemMeta1);
41 |
42 | GuiItem item1 = new GuiItem(itemStack1, event -> event.setCancelled(true));
43 | StaticPane pane1 = new StaticPane(0, 0, 1, 1);
44 | pane1.addItem(item1, 0, 0);
45 | gui.getFirstItemComponent().addPane(pane1);
46 |
47 | ItemStack itemStack2 = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
48 | ItemMeta itemMeta2 = itemStack2.getItemMeta();
49 | itemMeta2.setDisplayName(ChatColor.GREEN + "Enter");
50 | itemStack2.setItemMeta(itemMeta2);
51 |
52 | GuiItem item2 = new GuiItem(itemStack2, event -> {
53 | attempts++;
54 | if (gui.getRenameText().equals(correctPassword) || gui.getRenameText().equals(" " + correctPassword)){
55 |
56 | isPasswordCorrect = true;
57 | player.closeInventory();
58 | verificationProcessManager.setVerified(player);
59 |
60 | }else{
61 | isPasswordCorrect = false;
62 | player.sendMessage(Prefix.ERROR + "You have entered the wrong password.");
63 |
64 | }
65 | });
66 | StaticPane pane2 = new StaticPane(0, 0, 1, 1);
67 | pane2.addItem(item2, 0, 0);
68 | gui.getResultComponent().addPane(pane2);
69 |
70 | gui.setOnNameInputChanged(event -> {
71 | attempts++;
72 | if (event.equals(correctPassword) || event.equals(" " + correctPassword)){
73 | if (attempts < 20){
74 | isPasswordCorrect = true;
75 | player.closeInventory();
76 | verificationProcessManager.setVerified(player);
77 | }
78 | }
79 | });
80 | gui.setOnGlobalClick(event -> event.setCancelled(true));
81 |
82 | // inventory close event
83 | /*
84 | gui.setOnClose(event -> {
85 | OPProtector plugin = OPProtector.getInstance();
86 | if (verificationProcessManager.getVerificationStatusMap().get(player.getName()) == VerificationStatus.IN_PASSWORD_VERIFICATION){
87 | gui.show(player);
88 | }
89 |
90 | });
91 | */
92 |
93 | gui.show(player);
94 |
95 | }
96 |
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/resources/config.yml:
--------------------------------------------------------------------------------
1 | #
2 | # ██████╗ ██████╗ ██████╗ OPProtector 2023 (Operator Security System)
3 | # ██╔═══██╗██╔══██╗██╔══██╗ Version: 1.0.2
4 | # ██║ ██║██████╔╝██████╔╝ Contributors: Kasun Hapangama(ka0un)
5 | # ██║ ██║██╔═══╝ ██╔═══╝ GitHub:https://github.com/ka0un/OPProtector
6 | # ╚██████╔╝██║ ██║ Discord:https://dsc.gg/sundevs
7 | # ╚═════╝ ╚═╝ ╚═╝ Website: https://ka0un.github.io/OPProtector/
8 | #
9 |
10 | #===============================================================================
11 | # Password Settings
12 | #===============================================================================
13 |
14 | password-settings:
15 | enabled: true # you can disable the password in the lobby server (since you have login system)
16 | session-hours: 24 # how many hours the password will be valid
17 | use-gui: true # use gui to enter the password
18 | interval-secounds: 20 # within how many secounds the player should enter the password
19 | pas-command: "pas" # the command to open the password gui
20 | encrypt-passwords: true # encrypt the passwords in the config file
21 |
22 | #===============================================================================
23 | # Lockdown Settings
24 | #===============================================================================
25 |
26 | lockdown-settings:
27 | block-player-move: true
28 | block-break-blocks: true
29 | block-place-blocks: true
30 | block-player-commands: true
31 | block-item-drop: true
32 | block-item-pickup: true
33 | block-damage: true
34 | allow-flight: false
35 | commands-whitelist: # commands that are allowed to execute while lockdown
36 | - "/pas"
37 | - "/auth"
38 | - "/register"
39 | - "/login"
40 | - "/changepassword"
41 | - "/changepass"
42 |
43 | #===============================================================================
44 | # Scanner Settings
45 | #===============================================================================
46 |
47 | scanner-settings:
48 | scan-on-join: true
49 | scan-on-player-op-command: true
50 | scan-on-console-op-command: true
51 | scan-from-live-scanner: true
52 | scan-for-blacklisted-permissions: true
53 | scan-for-gamemode-creative: true
54 | blacklisted-permissions:
55 | - "essentials.*"
56 | - "*"
57 | - "bungeecord.command.*"
58 | - "minecraft.command.*"
59 | - "bungeecord.*"
60 | - "fawe.*"
61 | - "worledit.*"
62 | - "bukkit.*"
63 | - "minecraft.*"
64 | - "worldedit.*"
65 | - "worldguard.*"
66 | - "luckperms.*"
67 | - "lp.*"
68 | - "luckperms.*"
69 | - "luckperms.trusteditor"
70 | - "luckperms.editor"
71 | - "luckperms.user.permission.set"
72 | - "lands.admin.*"
73 | - "lands.bypass.*"
74 | - "excellentcrates.*"
75 | - "citizens.admin"
76 | - "minecraft.admin"
77 | - "plhide.bypass"
78 |
79 | #===============================================================================
80 | # Commands Settings
81 | #===============================================================================
82 |
83 | commands-settings:
84 | not-in-operators-list:
85 | - 'deop %player%'
86 |
87 | have-blacklisted-perms:
88 | - 'deop %player%'
89 |
90 | admin-ip-changed:
91 |
92 | failed-password-timeout:
93 |
94 | #===============================================================================
95 | # Discord Notifier Settings
96 | #===============================================================================
97 | discord-notifications:
98 | discord-webhook: ""
99 | notify-op-join: false
100 | notify-op-leave: false
101 | notify-auth-success : false
102 | notify-auth-failed: false
103 | notify-unauth-access: false
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/src/main/resources/iplist.yml:
--------------------------------------------------------------------------------
1 | test: "ii"
2 | #do not make changes here manually, unless you know what you are doing
--------------------------------------------------------------------------------
/src/main/resources/operators.yml:
--------------------------------------------------------------------------------
1 | KASUNhapangama2:
2 | password: password123
3 | commandBlacklist:
4 | - blacklistedCommand1
5 | - blacklistedCommand2
6 |
7 | Yourname:
8 | password: password123
9 | commandBlacklist:
10 | - blacklistedCommand1
11 | - blacklistedCommand2
12 |
13 | #make sure to do /opp reload after changeing this file
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: OPProtector
2 | version: '${project.version}'
3 | main: org.kasun.opprotector.OPProtector
4 | api-version: 1.13
5 | description: Operator Security Plugin That Provide Multi Factor Auth for staff members
6 | author: Kasun Hapangama
7 | website: https://opp.hapangama.com
8 | softdepend:
9 | - LuckPerms
10 | commands:
11 | pas:
12 | description: Operator Password
13 | usage: / password
14 | permission: opp.admin
15 | opp:
16 | description: OPProtector Admin Command
17 | usage: /
18 | permission: opp.admin
19 | aliases:
20 | - opprotector
--------------------------------------------------------------------------------
/ver.txt:
--------------------------------------------------------------------------------
1 | Version: 1.0.5
2 |
--------------------------------------------------------------------------------