Initial commit

This commit is contained in:
Scifi9902
2026-10-12 13:57:05 -03:00
commit 4bde3b176a
2576 changed files with 212659 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ProjectCranked</artifactId>
<groupId>net.crankedpvp</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Captcha</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>net.crankedpvp</groupId>
<artifactId>Utils</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,27 @@
package net.crankedpvp.captcha;
import net.crankedpvp.captcha.inventory.CaptchaInventory;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
public class CaptchaAPI {
public static void forceCaptchaForPlayer(Player player) {
CaptchaInventory captchaInventory = new CaptchaInventory(player);
captchaInventory.getCaptchaInventory().open(player);
player.playSound(player.getLocation(), Sound.CHEST_OPEN, 2.0f, 2.0f);
//player.sendMessage(CC.translate("&cYou must complete the captcha to close this inventory"));
}
public static void incrementInventoriesOpened(Player player) {
CaptchaPlugin.getInstance().getCaptchaManager().increment(player);
}
public static int getAmountOfInventoriesOpened(Player player) {
return CaptchaPlugin.getInstance().getCaptchaManager().getAmountOfInventoriesOpened(player);
}
public static void resetAmountOfInventoriesOpened(Player player) {
CaptchaPlugin.getInstance().getCaptchaManager().reset(player);
}
}
@@ -0,0 +1,36 @@
package net.crankedpvp.captcha;
import lombok.Getter;
import me.mattstudios.mf.base.CommandManager;
import net.crankedpvp.captcha.commands.AdminCaptchaCommand;
import net.crankedpvp.captcha.struct.CaptchaManager;
import org.bukkit.plugin.java.JavaPlugin;
public class CaptchaPlugin extends JavaPlugin {
@Getter
private static CaptchaPlugin instance;
@Getter
private CommandManager commandManager;
@Getter
private CaptchaManager captchaManager;
@Override
public void onEnable() {
instance = this;
this.commandManager = new CommandManager(this);
this.commandManager.register(new AdminCaptchaCommand(this));
this.captchaManager = new CaptchaManager(this);
}
@Override
public void onDisable() {
instance = null;
}
}
@@ -0,0 +1,36 @@
package net.crankedpvp.captcha.commands;
import me.mattstudios.mf.annotations.*;
import me.mattstudios.mf.base.CommandBase;
import net.crankedpvp.captcha.CaptchaPlugin;
import net.crankedpvp.captcha.inventory.CaptchaInventory;
import net.crankedpvp.crankedutils.utils.CC;
import net.crankedpvp.crankedutils.utils.SoundUtils;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Command("acaptcha")
@Alias("admincaptcha")
public class AdminCaptchaCommand extends CommandBase {
private final CaptchaPlugin plugin;
public AdminCaptchaCommand(CaptchaPlugin plugin) {
this.plugin = plugin;
}
@Default
public void defaultCommand(CommandSender commandSender) {
}
@SubCommand("force")
@Permission("captcha.force")
@WrongUsage("&c/acaptcha force <player>")
public void forceCaptchaCommand(final CommandSender commandSender, Player player) {
CaptchaInventory captchaInventory = new CaptchaInventory(player);
captchaInventory.getCaptchaInventory().open(player);
commandSender.sendMessage(CC.translate("&aForcefully setup a captcha for player: " + player.getName()));
SoundUtils.playSoundIfPlayer(commandSender, Sound.SUCCESSFUL_HIT);
}
}
@@ -0,0 +1,110 @@
package net.crankedpvp.captcha.inventory;
import dev.triumphteam.gui.guis.Gui;
import dev.triumphteam.gui.guis.GuiItem;
import lombok.Getter;
import net.crankedpvp.captcha.CaptchaAPI;
import net.crankedpvp.captcha.CaptchaPlugin;
import net.crankedpvp.crankedutils.utils.CC;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Random;
public class CaptchaInventory {
@Getter
private final Gui captchaInventory;
private final Material materialToClick;
private final Player player;
private boolean clickSuccess = false;
private int errors = 0;
public CaptchaInventory(Player player) {
player.closeInventory();
if(CaptchaAPI.getAmountOfInventoriesOpened(player) >= 5) {
CaptchaAPI.resetAmountOfInventoriesOpened(player);
player.kickPlayer(CC.translate("&4&lLucifier &8- &cAuto Grinding"));
}
this.materialToClick = generateRandomMaterial();
this.player = player;
this.captchaInventory = new Gui(6, "Click the " + materialToClick.name());
this.captchaInventory.setDefaultClickAction(event -> event.setCancelled(true));
this.captchaInventory.setCloseGuiAction(inventoryCloseEvent -> {
if(clickSuccess) return;
Bukkit.getScheduler().runTaskLater(CaptchaPlugin.getInstance(), () -> {
player.closeInventory();
this.captchaInventory.open(player);
}, 1L);
});
setupRandomMaterials();
setupFinalMaterial();
}
private void setupFinalMaterial() {
if(!this.player.getOpenInventory().getTopInventory().getName().contains("Click the")) return;
this.captchaInventory.setItem(new Random().nextInt(this.captchaInventory.getInventory().getContents().length), new GuiItem(materialToClick, event -> {
if(!event.getCurrentItem().getType().equals(materialToClick)) {
wrongMaterial();
return;
}
correctMaterial();
}));
}
private void setupRandomMaterials() {
if(!this.player.getOpenInventory().getTopInventory().getName().contains("Click the")) return;
for(int i = 0; i < this.captchaInventory.getInventory().getContents().length; i++) {
Material material = generateRandomMaterial();
this.captchaInventory.addItem(new GuiItem(new ItemStack(material), event -> {
if(!event.getCurrentItem().getType().equals(materialToClick)) {
wrongMaterial();
return;
}
correctMaterial();
}));
}
}
private void correctMaterial() {
clickSuccess = true;
this.player.closeInventory();
this.player.playSound(this.player.getLocation(), Sound.SUCCESSFUL_HIT, 2.0f, 2.0f);
CaptchaAPI.resetAmountOfInventoriesOpened(this.player);
}
private void wrongMaterial() {
this.errors++;
if(this.errors >= 10) {
clickSuccess = true;
this.player.closeInventory();
CaptchaInventory captchaInventory = new CaptchaInventory(this.player);
captchaInventory.getCaptchaInventory().open(this.player);
CaptchaAPI.incrementInventoriesOpened(player);
}
this.player.playSound(this.player.getLocation(), Sound.ANVIL_LAND, 1.0f, 1.0f);
}
Material[] validMaterials = new Material[]{
Material.DIAMOND_HELMET, Material.DIAMOND_LEGGINGS, Material.DIAMOND_CHESTPLATE, Material.DIAMOND_BOOTS,
Material.DIRT, Material.STAINED_CLAY, Material.STONE, Material.WOOD, Material.GRAVEL, Material.SADDLE,
Material.SAND, Material.TORCH, Material.REDSTONE, Material.DIODE, Material.JACK_O_LANTERN, Material.PUMPKIN,
Material.PUMPKIN_PIE, Material.COBBLESTONE, Material.DIAMOND_ORE, Material.GOLD_BLOCK, Material.SLIME_BLOCK,
Material.CACTUS, Material.FLOWER_POT_ITEM, Material.YELLOW_FLOWER, Material.DAYLIGHT_DETECTOR, Material.VINE,
Material.RED_SANDSTONE_STAIRS, Material.LAPIS_ORE, Material.SANDSTONE, Material.SHEARS, Material.BOOK,
Material.BOOKSHELF, Material.BOW, Material.FISHING_ROD, Material.RAW_FISH, Material.QUARTZ_BLOCK
};
private Material generateRandomMaterial() {
int pick = new Random().nextInt(validMaterials.length);
return validMaterials[pick];
}
}
@@ -0,0 +1,45 @@
package net.crankedpvp.captcha.struct;
import net.crankedpvp.captcha.CaptchaPlugin;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class CaptchaManager {
private final CaptchaPlugin plugin;
public CaptchaManager(CaptchaPlugin plugin) {
this.plugin = plugin;
this.captchaInventoriesOpened = new HashMap<>();
}
private Map<UUID, Integer> captchaInventoriesOpened;
public int getAmountOfInventoriesOpened(Player player) {
UUID uuid = player.getUniqueId();
if(this.captchaInventoriesOpened.containsKey(uuid)) {
return this.captchaInventoriesOpened.get(uuid);
}
return 0;
}
public void increment(Player player) {
UUID uuid = player.getUniqueId();
if(this.captchaInventoriesOpened.containsKey(uuid)) {
int amount = this.captchaInventoriesOpened.get(uuid);
this.captchaInventoriesOpened.put(uuid, amount+1);
return;
}
this.captchaInventoriesOpened.put(uuid, 1);
}
public void reset(Player player) {
UUID uuid = player.getUniqueId();
this.captchaInventoriesOpened.remove(uuid);
}
}
+7
View File
@@ -0,0 +1,7 @@
name: CrankedCaptcha
main: net.crankedpvp.captcha.CaptchaPlugin
version: ${git.total.commit.count}.0
description: "§fCommit ID: §a${git.commit.id.abbrev}"
website: https://crankedpvp.net/
depend:
- CrankedUtils