You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.5 KiB
87 lines
2.5 KiB
package com.entryrise.afkguard.antiafk.captcha;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.SplittableRandom;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import com.entryrise.afkguard.Main;
|
|
import com.entryrise.afkguard.mineutils.ItemBuilder;
|
|
|
|
public class CaptchaCategory {
|
|
|
|
private static SplittableRandom sr = new SplittableRandom();
|
|
private static List<CaptchaCategory> categories = new ArrayList<CaptchaCategory>();
|
|
|
|
public static void Enabler(boolean reload) {
|
|
if (!reload) {
|
|
Main.p.getServer().getPluginManager().registerEvents(new CaptchaGUI(), Main.p);
|
|
}
|
|
for (String stg : Main.config.getConfigurationSection("settings.captcha.categories").getKeys(false)) {
|
|
categories.add(new CaptchaCategory(stg));
|
|
|
|
}
|
|
Bukkit.getLogger().info(" §e[§a✔§e] §fCategories Added");
|
|
}
|
|
|
|
public static CaptchaCategory getCategory(CaptchaCategory exception) {
|
|
// For safety if the random randomly breaks out of some reason or another.
|
|
// Will render plugin kind of unsafe but still usable and won't crash server.
|
|
int i = 50;
|
|
CaptchaCategory categ;
|
|
do {
|
|
categ = categories.get(sr.nextInt(categories.size()));
|
|
} while (categ.equals(exception) && --i > 0);
|
|
|
|
return categ;
|
|
}
|
|
|
|
public List<ItemStack> getShuffledFiller() {
|
|
List<ItemStack> raw = new ArrayList<ItemStack>();
|
|
for (CaptchaCategory cat : categories) {
|
|
if (cat.equals(this)) {
|
|
continue;
|
|
}
|
|
for (int i = 0; i < 5; i++) {
|
|
raw.addAll(cat.members);
|
|
}
|
|
}
|
|
|
|
Collections.shuffle(raw);
|
|
return raw;
|
|
}
|
|
|
|
// This is where objective stuff starts and no more statics roam the land.
|
|
|
|
private List<ItemStack> members = new ArrayList<ItemStack>();
|
|
private String name;
|
|
|
|
private CaptchaCategory(String name) {
|
|
String loc = "settings.captcha.categories." + name;
|
|
|
|
this.name = name;
|
|
for (String stg : Main.config.getStringList(loc)) {
|
|
members.add(new ItemBuilder(Main.config, "settings.captcha.gui.item").setType(stg).build());
|
|
}
|
|
}
|
|
|
|
public ItemStack getRandom(ItemStack exception) {
|
|
// For safety if the random randomly breaks out of some reason or another.
|
|
// Will render plugin kind of unsafe but still usable and won't crash server.
|
|
List<ItemStack> items = new ArrayList<>(members);
|
|
items.remove(exception);
|
|
return items.get(sr.nextInt(items.size()));
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public List<ItemStack> getAllowed() {
|
|
return members;
|
|
}
|
|
|
|
}
|