Base Done
This commit is contained in:
90
src/main/java/io/github/thetrouper/ultradupe/UltraDupe.java
Normal file
90
src/main/java/io/github/thetrouper/ultradupe/UltraDupe.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package io.github.thetrouper.ultradupe;
|
||||
|
||||
import io.github.itzispyder.pdk.PDK;
|
||||
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
|
||||
import io.github.thetrouper.ultradupe.cmds.ChatClickCallback;
|
||||
import io.github.thetrouper.ultradupe.data.config.Config;
|
||||
import io.github.thetrouper.ultradupe.events.ChatEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class UltraDupe extends JavaPlugin {
|
||||
|
||||
private static UltraDupe instance;
|
||||
private static final File cfgfile = new File("plugins/UltraDupe/main-config.json");
|
||||
public static Config config = JsonSerializable.load(cfgfile, Config.class, new Config());
|
||||
public static final PluginManager manager = Bukkit.getPluginManager();
|
||||
|
||||
public static final Logger log = Bukkit.getLogger();
|
||||
|
||||
/**
|
||||
* Plugin startup logic
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
log.info("\n]======------ Pre-load started! ------======[");
|
||||
PDK.init(this);
|
||||
instance = this;
|
||||
|
||||
log.info("Loading Config...");
|
||||
|
||||
loadConfig();
|
||||
|
||||
startup();
|
||||
}
|
||||
|
||||
public void startup() {
|
||||
log.info("\n]======----- Loading UltraDupe! -----======[");
|
||||
|
||||
// Plugin startup logic
|
||||
log.info("Starting Up! (%s)...".formatted(getDescription().getVersion()));
|
||||
|
||||
// Commands
|
||||
new ChatClickCallback().register();
|
||||
|
||||
// Events
|
||||
new ChatEvent().register();
|
||||
|
||||
log.info("""
|
||||
Finished!
|
||||
_ _ _ _ _____ \s
|
||||
| | | | | | | __ \\ \s
|
||||
| | | | | |_ _ __ __ _| | | |_ _ _ __ ___\s
|
||||
| | | | | __| '__/ _` | | | | | | | '_ \\ / _ \\
|
||||
| |__| | | |_| | | (_| | |__| | |_| | |_) | __/
|
||||
\\____/|_|\\__|_| \\__,_|_____/ \\__,_| .__/ \\___|
|
||||
| | \s
|
||||
|_| \s
|
||||
|
||||
]====---- The only acceptable dupe plugin ----====[""");
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
|
||||
// Init
|
||||
config = JsonSerializable.load(cfgfile, Config.class,new Config());
|
||||
|
||||
// Save
|
||||
config.save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plugin shutdown logic
|
||||
*/
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
log.info("UltraDupe has disabled! (%s)".formatted(getDescription().getVersion()));
|
||||
}
|
||||
|
||||
public static UltraDupe getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.github.thetrouper.ultradupe.cmds;
|
||||
|
||||
import io.github.itzispyder.pdk.commands.Args;
|
||||
import io.github.itzispyder.pdk.commands.CommandRegistry;
|
||||
import io.github.itzispyder.pdk.commands.CustomCommand;
|
||||
import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandRegistry(value = "ultradupe", permission = @Permission("ultradupe.dupe"), printStackTrace = true)
|
||||
public class ChatClickCallback implements CustomCommand {
|
||||
@Override
|
||||
public void dispatchCommand(CommandSender sender, Args args) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchCompletions(CompletionBuilder b) {
|
||||
b.then(b.arg());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.thetrouper.ultradupe.data.config;
|
||||
|
||||
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Config implements JsonSerializable<Config> {
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
File file = new File("plugins/UltraDupe/main-config.json");
|
||||
file.getParentFile().mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
||||
public String prefix = "&9UltraDupe> &7";
|
||||
public boolean debugMode = false;
|
||||
public Plugin plugin = new Plugin();
|
||||
|
||||
public class Plugin {
|
||||
public int maxDupe = 128;
|
||||
public int maxMult = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.thetrouper.ultradupe.events;
|
||||
|
||||
import io.github.itzispyder.pdk.events.CustomListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class ChatEvent implements CustomListener {
|
||||
@EventHandler
|
||||
private void onChat(AsyncPlayerChatEvent e) {
|
||||
handleChatEvent(e);
|
||||
}
|
||||
public static void handleChatEvent(AsyncPlayerChatEvent e) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
/**
|
||||
* This file is for tutorial purposes made by ImproperIssues. Distribute if you want :)
|
||||
*
|
||||
* I made this cuz Bukkit API sounds management is trash.
|
||||
* by ImproperIssues
|
||||
*/
|
||||
|
||||
|
||||
package io.github.thetrouper.ultradupe.server.sound;
|
||||
|
||||
import io.github.thetrouper.ultradupe.UltraDupe;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class SoundPlayer {
|
||||
|
||||
private Location location;
|
||||
private Sound sound;
|
||||
private float volume;
|
||||
private float pitch;
|
||||
|
||||
/**
|
||||
* Constructs a new sound, this aims to add more methods to
|
||||
* the Bukkit APIs Sound class, as they don't have many
|
||||
* methods to use.
|
||||
*
|
||||
* @param location Location
|
||||
* @param sound Sound
|
||||
* @param volume float
|
||||
* @param pitch float
|
||||
*/
|
||||
public SoundPlayer(Location location, Sound sound, float volume, float pitch) {
|
||||
this.location = location;
|
||||
this.sound = sound;
|
||||
this.pitch = pitch;
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plays a sound to a player but at the store location
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void play(Player player) {
|
||||
player.playSound(this.location,this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound to a player but at the player's location
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
public void playAt(Player player) {
|
||||
player.playSound(player.getLocation(),this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound to all players within a distance, but at the stored location.
|
||||
*
|
||||
* @param distance double
|
||||
*/
|
||||
public void playWithin(double distance) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
|
||||
p.playSound(this.location,this.sound,this.volume,this.pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound to all players within a distance, but at the players' location.
|
||||
*
|
||||
* @param distance double
|
||||
*/
|
||||
public void playWithinAt(double distance) {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (p != null && p.getWorld() == this.location.getWorld() && p.getLocation().distanceSquared(this.location) < distance) {
|
||||
p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plays the sound to all players on the server, but at the stored location.
|
||||
*/
|
||||
public void playAll() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(this.location,this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays the sound to all players on the server, but at the players' location.
|
||||
*/
|
||||
public void playAllAt() {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) p.playSound(p.getLocation(),this.sound,this.volume,this.pitch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to a player, but at the stored location.
|
||||
*
|
||||
* @param player Player
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeat(Player player, int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
play(player);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to a player, but at the player's location.
|
||||
*
|
||||
* @param player Player
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAt(Player player, int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playAt(player);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players on the server, but at the stored location.
|
||||
*
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAll(int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playAll();
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players on the server, but at the players' location.
|
||||
*
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAllAt(int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playAllAt();
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players within a radius, but at the stored location.
|
||||
*
|
||||
* @param radius double
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAll(double radius,int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playWithin(radius);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repeats a sound to all players within a radius, but at the players' location.
|
||||
*
|
||||
* @param distance double
|
||||
* @param times int
|
||||
* @param tickDelay int
|
||||
*/
|
||||
public void repeatAllAt(double distance, int times, int tickDelay) {
|
||||
new BukkitRunnable() {
|
||||
int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i < times) {
|
||||
playWithinAt(distance);
|
||||
i ++;
|
||||
} else {
|
||||
this.cancel();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(UltraDupe.getInstance(),0,tickDelay);
|
||||
}
|
||||
|
||||
public Sound getSound() {
|
||||
return sound;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public float getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setVolume(float volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public void setSound(Sound sound) {
|
||||
this.sound = sound;
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package io.github.thetrouper.ultradupe.server.util;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.util.Base64;
|
||||
|
||||
public class CipherUtils {
|
||||
private static final String secretKey = "GG8T885O4Yd/86OMVFdL0w=="; // 16, 24, or 32 bytes
|
||||
private static final String algorithm = "AES";
|
||||
public static String encrypt(String strToEncrypt) {
|
||||
try {
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), algorithm);
|
||||
Cipher cipher = Cipher.getInstance(algorithm);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
|
||||
byte[] encryptedBytes = cipher.doFinal(strToEncrypt.getBytes());
|
||||
return Base64.getEncoder().encodeToString(encryptedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String decrypt(String strToDecrypt) {
|
||||
try {
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(), algorithm);
|
||||
Cipher cipher = Cipher.getInstance(algorithm);
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
|
||||
byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(strToDecrypt));
|
||||
return new String(decryptedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.thetrouper.ultradupe.server.util;
|
||||
|
||||
import io.github.thetrouper.ultradupe.UltraDupe;
|
||||
|
||||
import java.io.File;
|
||||
public class FileUtils {
|
||||
public static boolean folderExists(String folderName) {
|
||||
File folder = new File(UltraDupe.getInstance().getDataFolder(), folderName);
|
||||
return folder.exists() && folder.isDirectory();
|
||||
}
|
||||
public static void createFolder(String folderName) {
|
||||
File folder = new File(UltraDupe.getInstance().getDataFolder(), folderName);
|
||||
if (!folder.exists()) {
|
||||
folder.mkdirs();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package io.github.thetrouper.ultradupe.server.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public final class MathUtils {
|
||||
|
||||
public static double avg(Integer... ints) {
|
||||
final List<Integer> list = Arrays.stream(ints).filter(Objects::nonNull).toList();
|
||||
return avg(list);
|
||||
}
|
||||
|
||||
public static double avg(List<Integer> ints) {
|
||||
double sum = 0.0;
|
||||
for (Integer i : ints) sum += i;
|
||||
return sum / ints.size();
|
||||
}
|
||||
|
||||
public static double round(double value, int nthPlace) {
|
||||
return Math.floor(value * nthPlace) / nthPlace;
|
||||
}
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String SHA512(String input) {
|
||||
try {
|
||||
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
|
||||
byte[] encodedHash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
StringBuilder hexString = new StringBuilder(2 * encodedHash.length);
|
||||
for (byte b : encodedHash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package io.github.thetrouper.ultradupe.server.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Randomize items from a list
|
||||
* @param <T> list of?
|
||||
*/
|
||||
public class Randomizer<T> {
|
||||
public static long generateID() {
|
||||
Date now = new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
String formattedDate = dateFormat.format(now);
|
||||
long id = Long.parseLong(formattedDate);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
private final List<T> array;
|
||||
|
||||
/**
|
||||
* From array list
|
||||
* @param array list
|
||||
*/
|
||||
public Randomizer(List<T> array) {
|
||||
this.array = array;
|
||||
}
|
||||
|
||||
/**
|
||||
* From set
|
||||
* @param array set
|
||||
*/
|
||||
public Randomizer(Set<T> array) {
|
||||
this.array = new ArrayList<>(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* From array
|
||||
* @param array array
|
||||
*/
|
||||
public Randomizer(T[] array) {
|
||||
this.array = List.of(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick random from the array
|
||||
* @return random of list of?
|
||||
*/
|
||||
public T pickRand() {
|
||||
return array.get(rand(array.size() - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random integer from 1 to (max)
|
||||
* @param max max value
|
||||
* @return random
|
||||
*/
|
||||
public static int rand(int max) {
|
||||
if (max <= 0) throw new IllegalArgumentException("max cannot be less than 1!");
|
||||
return (int) Math.ceil(Math.random() * max);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random integer from (min) to (max)
|
||||
* @param min min value
|
||||
* @param max max value
|
||||
* @return random
|
||||
*/
|
||||
public static int rand(int min, int max) {
|
||||
if (max <= 0 || min <= 0) throw new IllegalArgumentException("max or min cannot be less than 1!");
|
||||
if (max <= min) throw new IllegalArgumentException("max cannot be less than or equal to min!");
|
||||
return min + (int) Math.floor(Math.random() * (max - min + 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package io.github.thetrouper.ultradupe.server.util;
|
||||
|
||||
import io.github.thetrouper.ultradupe.UltraDupe;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ServerUtils {
|
||||
public static void sendCommand(String command) {
|
||||
ServerUtils.verbose("Getting scheduler");
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltraDupe.getInstance(), () -> {
|
||||
try {
|
||||
ServerUtils.verbose("Attempting to run command...");
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
},1);
|
||||
}
|
||||
public static void verbose(String message) {
|
||||
if (UltraDupe.config.debugMode) {
|
||||
String log = "[UltraDupe] [DEBUG]: " + message;
|
||||
UltraDupe.log.info(log);
|
||||
for (Player trustedPlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (trustedPlayer.isOp()) {
|
||||
trustedPlayer.sendMessage("§d§lUltraDupe §7[§bDEBUG§7] §8» §7" + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Player> getPlayers() {
|
||||
return new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
public static List<Player> getStaff() {
|
||||
return getPlayers().stream().filter(Player -> Player.hasPermission("ultradupe.staff")).toList();
|
||||
}
|
||||
|
||||
public static void forEachPlayer(Consumer<Player> consumer) {
|
||||
getPlayers().forEach(consumer);
|
||||
}
|
||||
|
||||
public static void forEachStaff(Consumer<Player> consumer) {
|
||||
getStaff().forEach(consumer);
|
||||
}
|
||||
|
||||
public static void dmEachPlayer(Predicate<Player> condition, String dm) {
|
||||
forEachPlayer(p -> {
|
||||
if (condition.test(p)) p.sendMessage(dm);
|
||||
});
|
||||
}
|
||||
|
||||
public static void dmEachPlayer(String dm) {
|
||||
forEachPlayer(p -> p.sendMessage(dm));
|
||||
}
|
||||
|
||||
public static void forEachSpecified(Iterable<Player> players, Consumer<Player> consumer) {
|
||||
players.forEach(consumer);
|
||||
}
|
||||
|
||||
public static void forEachSpecified(Consumer<Player> consumer, Player... players) {
|
||||
Arrays.stream(players).forEach(consumer);
|
||||
}
|
||||
public static void forEachPlayerRun(Predicate<Player> condition, Consumer<Player> task) {
|
||||
forEachPlayer(p -> {
|
||||
if (condition.test(p)) {
|
||||
task.accept(p);
|
||||
}
|
||||
});
|
||||
}
|
||||
public static void sendActionBar(Player p, String msg) {
|
||||
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg));
|
||||
}
|
||||
|
||||
public static boolean hasBlockBelow(Player player, Material material) {
|
||||
for (int y = player.getLocation().getBlockY() - 1; y >= player.getLocation().getBlockY() - 12; y--) {
|
||||
if (player.getWorld().getBlockAt(player.getLocation().getBlockX(), y, player.getLocation().getBlockZ()).getType() == material) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player) {
|
||||
for (MetadataValue meta : player.getMetadata("vanished")) {
|
||||
if (meta.asBoolean()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String[] unVanishedPlayers() {
|
||||
return io.github.itzispyder.pdk.utils.ServerUtils.players(ServerUtils::isVanished).stream().map(Player::getName).toArray(String[]::new);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package io.github.thetrouper.ultradupe.server.util;
|
||||
|
||||
|
||||
import io.github.thetrouper.ultradupe.UltraDupe;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Text {
|
||||
|
||||
public static String regexHighlighter(String input, String regex, String startString, String endString) {
|
||||
// Create a Pattern object
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
// Create a Matcher object
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
|
||||
// StringBuffer to store the result
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
// Find and append matches
|
||||
while (matcher.find()) {
|
||||
matcher.appendReplacement(result, startString + matcher.group() + endString);
|
||||
}
|
||||
|
||||
// Append the remainder of the input
|
||||
matcher.appendTail(result);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static final char SECTION_SYMBOL = (char)167;
|
||||
|
||||
public static String color(String msg) {
|
||||
return msg.replace('&', SECTION_SYMBOL);
|
||||
}
|
||||
public static String prefix(String text) {
|
||||
String prefix = UltraDupe.config.prefix;
|
||||
return color(prefix + text);
|
||||
}
|
||||
public static String removeFirstColor(String input) {
|
||||
if (input.startsWith("\u00a7")) {
|
||||
if (input.length() > 2) {
|
||||
return input.substring(2);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
public static String replaceRepeatingLetters(String input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
return input;
|
||||
}
|
||||
|
||||
StringBuilder simplifiedText = new StringBuilder();
|
||||
char currentChar = input.charAt(0);
|
||||
int count = 1;
|
||||
|
||||
for (int i = 1; i < input.length(); i++) {
|
||||
char nextChar = input.charAt(i);
|
||||
|
||||
if (Character.toLowerCase(nextChar) == Character.toLowerCase(currentChar)) {
|
||||
count++;
|
||||
} else {
|
||||
simplifiedText.append(currentChar);
|
||||
|
||||
if (count > 1) {
|
||||
simplifiedText.append(currentChar);
|
||||
}
|
||||
|
||||
currentChar = nextChar;
|
||||
count = 1;
|
||||
}
|
||||
}
|
||||
|
||||
simplifiedText.append(currentChar);
|
||||
|
||||
if (count > 1) {
|
||||
simplifiedText.append(currentChar);
|
||||
}
|
||||
|
||||
return simplifiedText.toString();
|
||||
}
|
||||
|
||||
public static String cleanName(String type) {
|
||||
return type.replaceAll("_"," ").toLowerCase();
|
||||
}
|
||||
}
|
||||
103
src/main/resources/plugin.yml
Normal file
103
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,103 @@
|
||||
name: UltraDupe
|
||||
version: '${version}'
|
||||
main: io.github.thetrouper.ultradupe.UltraDupe
|
||||
api-version: 1.19
|
||||
authors: [ TheTrouper ]
|
||||
description: Detect Block and Ban players who attempt to grief your server.
|
||||
website: https://thetrouper.github.io/
|
||||
softdepend: [ ProtocolLib ]
|
||||
permissions:
|
||||
ultradupe.message:
|
||||
description: Access to the direct messages
|
||||
default: op
|
||||
ultradupe.reply:
|
||||
description: Reply commands
|
||||
ultradupe.debug:
|
||||
description: Permission to use debug commands
|
||||
default: op
|
||||
ultradupe.staff:
|
||||
description: Receive anti-swear and anti-spam warnings
|
||||
default: op
|
||||
ultradupe.chat.antiswear.flags:
|
||||
description: See antiSwear flags
|
||||
default: op
|
||||
ultradupe.chat.antiswear.bypass:
|
||||
description: Bypass the antiSwear
|
||||
default: op
|
||||
ultradupe.chat.antiswear.edit:
|
||||
description: Add a false positive to the config
|
||||
default: op
|
||||
ultradupe.chat.antispam.flags:
|
||||
description: See antispam flags
|
||||
default: op
|
||||
ultradupe.chat.antispam.bypass:
|
||||
description: Bypass the antispam
|
||||
default: op
|
||||
ultradupe.chat.*:
|
||||
description: bypass all chat rules and see all flags
|
||||
default: op
|
||||
children:
|
||||
ultradupe.chat.antiswear.flags: true
|
||||
ultradupe.chat.antiswear.bypass: true
|
||||
ultradupe.chat.antispam.flags: true
|
||||
ultradupe.chat.antispam.bypass: true
|
||||
commands:
|
||||
ultradupetab:
|
||||
description: trap tab completion command
|
||||
usage: /ultradupetab you got trolled
|
||||
ultradupe:
|
||||
description: A command for testing.
|
||||
usage: /ultradupe
|
||||
permission: ultradupe.info
|
||||
permission-message: You do not have permission!
|
||||
reop:
|
||||
description: Allows trusted players to elevate their permissions
|
||||
usage: /reop
|
||||
socialspy:
|
||||
permission: ultradupe.spy
|
||||
usage: /socialspy
|
||||
permission-message: You do not have permission to use this command!
|
||||
description: View direct messages sent between players
|
||||
aliases:
|
||||
- spy
|
||||
- sspy
|
||||
msg:
|
||||
permission: ultradupe.message
|
||||
usage: /msg <player> [<message>]
|
||||
permission-message: You do not have permission to message through ultradupe!
|
||||
description: Send messages directly to players
|
||||
aliases:
|
||||
- message
|
||||
- etell
|
||||
- tell
|
||||
- t
|
||||
- ewhisper
|
||||
- whisper
|
||||
- w
|
||||
- privatemessage
|
||||
- pm
|
||||
- m
|
||||
- directmessage
|
||||
- dm
|
||||
- ultradupemessage
|
||||
- sm
|
||||
- stell
|
||||
- smsg
|
||||
reply:
|
||||
description: Reply to the last person messaging you
|
||||
usage: /r [<message>]
|
||||
permission: ultradupe.reply
|
||||
permission-message: You do not have permission to reply through ultradupe!
|
||||
aliases:
|
||||
- r
|
||||
- er
|
||||
- rply
|
||||
- ereply
|
||||
- sr
|
||||
- sreply
|
||||
- ultradupereply
|
||||
ultradupecallback:
|
||||
description: Callback for chat click events
|
||||
usage: /ultradupecallback
|
||||
permission: ultradupe.callbacks
|
||||
permission-message: You have not been given permission to use UltraDupe Chat Callbacks!
|
||||
Reference in New Issue
Block a user