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.
90 lines
2.3 KiB
90 lines
2.3 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.Material;
|
|
|
|
import com.entryrise.afkguard.Main;
|
|
|
|
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<Material> getShuffledFiller() {
|
|
List<Material> raw = new ArrayList<Material>();
|
|
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<Material> members = new ArrayList<Material>();
|
|
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(Material.getMaterial(stg));
|
|
}
|
|
}
|
|
|
|
public Material getRandom(Material 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;
|
|
Material mat;
|
|
do {
|
|
mat = members.get(sr.nextInt(members.size()));
|
|
} while (mat.equals(exception) && --i > 0);
|
|
|
|
return mat;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public List<Material> getAllowed() {
|
|
return members;
|
|
}
|
|
|
|
}
|