Initial commit.

This commit is contained in:
Trixkz 2024-09-20 05:56:10 -04:00
commit c40b27936c
28 changed files with 1955 additions and 0 deletions

101
pom.xml Normal file
View File

@ -0,0 +1,101 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.loganmagnan</groupId>
<artifactId>FirstJoinCommand</artifactId>
<version>1.0</version>
<name>FirstJoinCommand</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>fawe-repo</id>
<url>https://ci.athion.net/job/FastAsyncWorldEdit/ws/mvn/</url>
</repository>
<repository>
<id>codemc-repo</id>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.boydti</groupId>
<artifactId>fawe-api</artifactId>
<version>latest</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.9</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,58 @@
package com.loganmagnan.firstjoincommand;
import com.loganmagnan.firstjoincommand.utils.ClassRegistrationUtils;
import com.loganmagnan.firstjoincommand.utils.ColorUtils;
import com.loganmagnan.firstjoincommand.utils.command.CommandFramework;
import com.loganmagnan.firstjoincommand.utils.config.file.Config;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class FirstJoinCommand extends JavaPlugin {
@Getter private static FirstJoinCommand instance;
private Config mainConfig;
private CommandFramework commandFramework = new CommandFramework(this);
@Override
public void onEnable() {
instance = this;
this.saveDefaultConfig();
this.mainConfig = new Config("config", this);
Bukkit.getConsoleSender().sendMessage("------------------------------------------------");
Bukkit.getConsoleSender().sendMessage(ColorUtils.getMessageType("&bFirstJoinCommand &8- &av" + this.getDescription().getVersion()));
Bukkit.getConsoleSender().sendMessage(ColorUtils.getMessageType("&7Made by &eLoganM Development"));
Bukkit.getConsoleSender().sendMessage("------------------------------------------------");
this.loadCommands();
this.loadManagers();
this.loadListeners();
this.loadRunnables();
}
@Override
public void onDisable() {
instance = null;
}
private void loadCommands() {
ClassRegistrationUtils.loadCommands("com.loganmagnan.firstjoincommand.commands");
}
private void loadManagers() {
}
private void loadListeners() {
ClassRegistrationUtils.loadListeners("com.loganmagnan.firstjoincommand.listeners");
}
private void loadRunnables() {
}
}

View File

@ -0,0 +1,17 @@
package com.loganmagnan.firstjoincommand.chatcolor;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@RequiredArgsConstructor
public class ColorSet<R, G, B> {
private R red = null;
private G green = null;
private B blue = null;
}

View File

@ -0,0 +1,16 @@
package com.loganmagnan.firstjoincommand.chatcolor;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@AllArgsConstructor
@RequiredArgsConstructor
public class GradientColor {
private ColorSet<Integer, Integer, Integer> colorCodeOne;
private ColorSet<Integer, Integer, Integer> colorCodeTwo;
}

View File

@ -0,0 +1,34 @@
package com.loganmagnan.firstjoincommand.commands;
import com.loganmagnan.firstjoincommand.FirstJoinCommand;
import com.loganmagnan.firstjoincommand.utils.ColorUtils;
import com.loganmagnan.firstjoincommand.utils.command.BaseCommand;
import com.loganmagnan.firstjoincommand.utils.command.Command;
import com.loganmagnan.firstjoincommand.utils.command.CommandArguments;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.entity.Player;
import java.io.IOException;
public class ReloadFilesCommand extends BaseCommand {
private FirstJoinCommand main = FirstJoinCommand.getInstance();
@Command(name = "reloadfiles")
@Override
public void executeAs(CommandArguments command) {
Player player = command.getPlayer();
String[] args = command.getArgs();
if (args.length == 0) {
try {
this.main.getMainConfig().getConfig().load(this.main.getMainConfig().getConfigFile());
} catch (Exception exception) {
exception.printStackTrace();
}
player.sendMessage(ColorUtils.getMessageType("&aFiles reloaded"));
}
}
}

View File

@ -0,0 +1,26 @@
package com.loganmagnan.firstjoincommand.listeners;
import com.loganmagnan.firstjoincommand.FirstJoinCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;
public class PlayerJoinListener implements Listener {
private FirstJoinCommand main = FirstJoinCommand.getInstance();
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (player.hasPlayedBefore()) {
return;
}
for (String string : main.getMainConfig().getConfig().getStringList("FIRST-JOIN-COMMANDS")) {
main.getServer().dispatchCommand(main.getServer().getConsoleSender(), string.replace("%player%", player.getName()));
}
}
}

View File

@ -0,0 +1,95 @@
package com.loganmagnan.firstjoincommand.utils;
import com.google.common.collect.ImmutableSet;
import com.loganmagnan.firstjoincommand.FirstJoinCommand;
import org.bukkit.event.Listener;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ClassRegistrationUtils {
public static void loadListeners(String packageName) {
for (Class<?> clazz : getClassesInPackage(packageName)) {
if (isListener(clazz)) {
try {
FirstJoinCommand.getInstance().getServer().getPluginManager().registerEvents((Listener) clazz.newInstance(), FirstJoinCommand.getInstance());
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
}
public static void loadCommands(String packageName) {
for (Class<?> clazz : getClassesInPackage(packageName)) {
try {
clazz.newInstance();
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
public static boolean isListener(Class<?> clazz) {
for (Class<?> interfaze : clazz.getInterfaces()) {
if (interfaze == Listener.class) {
return true;
}
}
return false;
}
public static Collection<Class<?>> getClassesInPackage(String packageName) {
JarFile jarFile;
Collection<Class<?>> classes = new ArrayList<>();
CodeSource codeSource = FirstJoinCommand.getInstance().getClass().getProtectionDomain().getCodeSource();
URL resource = codeSource.getLocation();
String relPath = packageName.replace('.', '/');
String resPath = resource.getPath().replace("%20", " ");
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
try {
jarFile = new JarFile(jarPath);
} catch (IOException e) {
throw new IllegalStateException("Unexpected IOException reading JAR File '" + jarPath + "'", e);
}
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String entryName = entry.getName();
String className = null;
if (entryName.endsWith(".class") && entryName.startsWith(relPath) && entryName.length() > relPath.length() + "/".length()) {
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
}
if (className != null) {
Class<?> clazz = null;
try {
clazz = Class.forName(className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
if (clazz != null) {
classes.add(clazz);
}
}
}
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
}
return ImmutableSet.copyOf(classes);
}
}

View File

@ -0,0 +1,193 @@
package com.loganmagnan.firstjoincommand.utils;
import com.loganmagnan.firstjoincommand.chatcolor.ColorSet;
import lombok.Getter;
import lombok.Setter;
import net.md_5.bungee.api.ChatColor;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Getter
@Setter
public class ColorUtils {
private static Map<ChatColor, ColorSet<Integer, Integer, Integer>> colorMap = new HashMap<>();
public ColorUtils() {
this.registerColors();
}
public void registerColors() {
colorMap.put(ChatColor.BLACK, new ColorSet<>(0, 0, 0));
colorMap.put(ChatColor.DARK_BLUE, new ColorSet<>(0, 0, 170));
colorMap.put(ChatColor.DARK_GREEN, new ColorSet<>(0, 170, 0));
colorMap.put(ChatColor.DARK_AQUA, new ColorSet<>(0, 170, 170));
colorMap.put(ChatColor.DARK_RED, new ColorSet<>(170, 0, 0));
colorMap.put(ChatColor.DARK_PURPLE, new ColorSet<>(170, 0, 170));
colorMap.put(ChatColor.GOLD, new ColorSet<>(255, 170, 0));
colorMap.put(ChatColor.GRAY, new ColorSet<>(170, 170, 170));
colorMap.put(ChatColor.DARK_GRAY, new ColorSet<>(85, 85, 85));
colorMap.put(ChatColor.BLUE, new ColorSet<>(85, 85, 255));
colorMap.put(ChatColor.GREEN, new ColorSet<>(85, 255, 85));
colorMap.put(ChatColor.AQUA, new ColorSet<>(85, 255, 255));
colorMap.put(ChatColor.RED, new ColorSet<>(255, 85, 85));
colorMap.put(ChatColor.LIGHT_PURPLE, new ColorSet<>(255, 85, 255));
colorMap.put(ChatColor.YELLOW, new ColorSet<>(255, 255, 85));
colorMap.put(ChatColor.WHITE, new ColorSet<>(255, 255, 255));
}
public static String getMessageType(String message) {
if (message.contains("#")) {
if (isValidHexColorCode(message.substring(message.indexOf("#"), message.indexOf("#") + 7))) {
return translate(message);
} else {
return Utils.translate(message);
}
} else {
return Utils.translate(message);
}
}
public static List<String> getMessageType(List<String> message) {
List<String> messageNew = new ArrayList<String>();
for (String string : message) {
if (string.contains("#")) {
if (isValidHexColorCode(string.substring(string.indexOf("#"), string.indexOf("#") + 7))) {
messageNew.add(translate(string));
} else {
messageNew.add(Utils.translate(string));
}
} else {
messageNew.add(Utils.translate(string));
}
}
return messageNew;
}
public static ChatColor getColor(String colorCode) {
byte b;
int i;
ChatColor[] arrayOfChatColor;
for (i = (arrayOfChatColor = ChatColor.values()).length, b = 0; b < i; ) {
ChatColor colors = arrayOfChatColor[b];
String colorsDecode = untranslate(colors.toString());
if (colorCode.equalsIgnoreCase(colorsDecode)) {
return colors;
}
b++;
}
return null;
}
public static boolean lookAtColorCode(String colorCode) {
byte b;
int i;
ChatColor[] arrayOfChatColor;
for (i = (arrayOfChatColor = ChatColor.values()).length, b = 0; b < i; ) {
ChatColor colors = arrayOfChatColor[b];
String colorsDecode = untranslate(colors.toString());
if (colorCode.equalsIgnoreCase(colorsDecode)) {
return true;
}
b++;
}
return false;
}
public static ColorSet<Integer, Integer, Integer> copyColorSet(String colorCode) {
Color color = hexColorCodesToRGBColorCodes(colorCode);
return new ColorSet(color.getRed(), color.getGreen(), color.getBlue());
}
public static String getGradientString(String string, List<String> colorCodes) {
String[] split = string.split("");
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < colorCodes.size(); i++) {
stringBuilder.append(ChatColor.of(colorCodes.get(i)) + split[i]);
}
return stringBuilder.toString();
}
public static List<String> getColorCodes(String text, ColorSet<Integer, Integer, Integer> colorSetOne, ColorSet<Integer, Integer, Integer> colorSetTwo) {
List<String> colorCodes = new ArrayList<>();
int red = ((colorSetOne.getRed() < colorSetTwo.getRed()) ? (colorSetTwo.getRed() - colorSetOne.getRed()) : (colorSetOne.getRed() - colorSetTwo.getRed())) / text.length();
int green = ((colorSetOne.getGreen() < colorSetTwo.getGreen()) ? (colorSetTwo.getGreen() - colorSetOne.getGreen()) : (colorSetOne.getGreen() - colorSetTwo.getGreen())) / text.length();
int blue = ((colorSetOne.getBlue() < colorSetTwo.getBlue()) ? (colorSetTwo.getBlue() - colorSetOne.getBlue()) : (colorSetOne.getBlue() - colorSetTwo.getBlue())) / text.length();
for (int i = 0; i < text.length(); i++) {
colorSetOne.setRed((colorSetOne.getRed() <= colorSetTwo.getRed()) ? (colorSetOne.getRed() + red) : (colorSetOne.getRed() - red));
colorSetOne.setGreen((colorSetOne.getGreen() <= colorSetTwo.getGreen()) ? (colorSetOne.getGreen() + green) : (colorSetOne.getGreen() - green));
colorSetOne.setBlue((colorSetOne.getBlue() <= colorSetTwo.getBlue()) ? (colorSetOne.getBlue() + blue) : (colorSetOne.getBlue() - blue));
String hex = String.format("#%02x%02x%02x", colorSetOne.getRed(), colorSetOne.getGreen(), colorSetOne.getBlue());
colorCodes.add(hex);
}
return colorCodes;
}
public static String translate(String string) {
Pattern pattern = Pattern.compile("#[a-fA-F0-9]{6}");
for (Matcher matcher = pattern.matcher(string); matcher.find(); matcher = pattern.matcher(string)) {
String color = string.substring(matcher.start(), matcher.end());
string = string.replace(color, ChatColor.of(color) + "");
}
string = ChatColor.translateAlternateColorCodes('&', string);
return string;
}
public static Color hexColorCodesToRGBColorCodes(String string) {
return new Color(Integer.valueOf(string.substring(1, 3),16), Integer.valueOf(string.substring(3, 5),16), Integer.valueOf(string.substring(5, 7),16));
}
public static boolean isValidHexColorCode(String string) {
Pattern pattern = Pattern.compile("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$");
Matcher matcher = pattern.matcher(string);
return matcher.matches();
}
public static String untranslate(String textToTranslate) {
char[] b = textToTranslate.toCharArray();
for (int i = 0; i < b.length - 1; i++) {
if (b[i] == '§' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx".indexOf(b[i + 1]) > -1) {
b[i] = '&';
b[i + 1] = Character.toLowerCase(b[i + 1]);
}
}
return new String(b);
}
}

View File

@ -0,0 +1,125 @@
package com.loganmagnan.firstjoincommand.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.StringJoiner;
@Getter
@Setter
@AllArgsConstructor
public class CustomLocation {
private final long timestamp = System.currentTimeMillis();
private String world;
private double x;
private double y;
private double z;
private float yaw;
private float pitch;
public CustomLocation(double x, double y, double z) {
this(x, y, z, 0.0F, 0.0F);
}
public CustomLocation(String world, double x, double y, double z) {
this(world, x, y, z, 0.0F, 0.0F);
}
public CustomLocation(double x, double y, double z, float yaw, float pitch) {
this("world", x, y, z, yaw, pitch);
}
public static CustomLocation fromBukkitLocation(Location location) {
return new CustomLocation(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
public static CustomLocation stringToLocation(String string) {
String[] split = string.split(", ");
double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]);
double z = Double.parseDouble(split[2]);
CustomLocation customLocation = new CustomLocation(x, y, z);
if (split.length == 4) {
customLocation.setWorld(split[3]);
} else if (split.length >= 5) {
customLocation.setYaw(Float.parseFloat(split[3]));
customLocation.setPitch(Float.parseFloat(split[4]));
if (split.length >= 6) {
customLocation.setWorld(split[5]);
}
}
return customLocation;
}
public static String locationToString(CustomLocation loc) {
StringJoiner joiner = new StringJoiner(", ");
joiner.add(Double.toString(loc.getX()));
joiner.add(Double.toString(loc.getY()));
joiner.add(Double.toString(loc.getZ()));
if (loc.getYaw() == 0.0f && loc.getPitch() == 0.0f) {
if (loc.getWorld().equals("world")) {
return joiner.toString();
} else {
joiner.add(loc.getWorld());
return joiner.toString();
}
} else {
joiner.add(Float.toString(loc.getYaw()));
joiner.add(Float.toString(loc.getPitch()));
if (loc.getWorld().equals("world")) {
return joiner.toString();
} else {
joiner.add(loc.getWorld());
return joiner.toString();
}
}
}
public Location toBukkitLocation() {
return new Location(this.toBukkitWorld(), this.x, this.y, this.z, this.yaw, this.pitch);
}
public World toBukkitWorld() {
if (this.world == null) {
return Bukkit.getServer().getWorlds().get(0);
} else {
return Bukkit.getServer().getWorld(this.world);
}
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof CustomLocation)) {
return false;
}
CustomLocation location = (CustomLocation) obj;
return location.x == this.x && location.y == this.y && location.z == this.z && location.pitch == this.pitch && location.yaw == this.yaw;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("x", this.x)
.append("y", this.y)
.append("z", this.z)
.append("yaw", this.yaw)
.append("pitch", this.pitch)
.append("world", this.world)
.append("timestamp", this.timestamp)
.toString();
}
}

View File

@ -0,0 +1,184 @@
package com.loganmagnan.firstjoincommand.utils;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.MaterialData;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ItemBuilder implements Listener {
private final ItemStack is;
public ItemBuilder(final Material mat) {
is = new ItemStack(mat);
}
public ItemBuilder(final ItemStack is) {
this.is = is;
}
public ItemBuilder(Material m, int amount) {
this.is = new ItemStack(m, amount);
}
public ItemBuilder amount(final int amount) {
is.setAmount(amount);
return this;
}
public ItemBuilder name(final String name) {
final ItemMeta meta = is.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
is.setItemMeta(meta);
return this;
}
public ItemBuilder lore(final String name) {
final ItemMeta meta = is.getItemMeta();
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<>();
}
lore.add(name);
meta.setLore(lore);
is.setItemMeta(meta);
return this;
}
public ItemBuilder lore(final List<String> lore) {
List<String> toSet = new ArrayList<>();
ItemMeta meta = is.getItemMeta();
for (String string : lore) {
toSet.add(ChatColor.translateAlternateColorCodes('&', string));
}
meta.setLore(toSet);
is.setItemMeta(meta);
return this;
}
public ItemBuilder durability(final int durability) {
is.setDurability((short) durability);
return this;
}
public ItemBuilder owner(String owner) {
if (this.is.getType() == Material.PLAYER_HEAD) {
SkullMeta meta = (SkullMeta) this.is.getItemMeta();
meta.setOwner(owner);
this.is.setItemMeta(meta);
return this;
}
throw new IllegalArgumentException("setOwner() only applicable for Skull Item");
}
@SuppressWarnings("deprecation")
public ItemBuilder data(final int data) {
is.setData(new MaterialData(is.getType(), (byte) data));
return this;
}
public ItemBuilder enchantment(final Enchantment enchantment, final int level) {
is.addUnsafeEnchantment(enchantment, level);
return this;
}
public ItemBuilder enchantment(final Enchantment enchantment) {
is.addUnsafeEnchantment(enchantment, 1);
return this;
}
public ItemBuilder hideFlags() {
final ItemMeta meta = is.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
is.setItemMeta(meta);
return this;
}
public ItemBuilder hideEnchants() {
final ItemMeta meta = is.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
is.setItemMeta(meta);
return this;
}
public ItemBuilder hideUnbreakable() {
final ItemMeta meta = is.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
is.setItemMeta(meta);
return this;
}
public ItemBuilder addUnbreakable() {
final ItemMeta meta = is.getItemMeta();
meta.setUnbreakable(true);
is.setItemMeta(meta);
return this;
}
public ItemBuilder type(final Material material) {
is.setType(material);
return this;
}
public ItemBuilder clearLore() {
final ItemMeta meta = is.getItemMeta();
meta.setLore(new ArrayList<>());
is.setItemMeta(meta);
return this;
}
public ItemBuilder clearEnchantments() {
for (final Enchantment e : is.getEnchantments().keySet()) {
is.removeEnchantment(e);
}
return this;
}
public ItemBuilder color(Color color) {
if (is.getType() == Material.LEATHER_BOOTS || is.getType() == Material.LEATHER_CHESTPLATE
|| is.getType() == Material.LEATHER_HELMET || is.getType() == Material.LEATHER_LEGGINGS) {
LeatherArmorMeta meta = (LeatherArmorMeta) is.getItemMeta();
meta.setColor(color);
is.setItemMeta(meta);
return this;
} else {
throw new IllegalArgumentException("color() only applicable for leather armor!");
}
}
public ItemBuilder addEnchantments(Map<Enchantment, Integer> enchantments) {
this.is.addEnchantments(enchantments);
return this;
}
public ItemStack build() {
return is;
}
}

View File

@ -0,0 +1,132 @@
package com.loganmagnan.firstjoincommand.utils;
import org.bukkit.ChatColor;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
public class Utils {
public static final String scoreboardBar = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "----------------------";
public static final String chatBar = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "--------------------------------------------";
private static ThreadLocal<StringBuilder> MMSS_BUILDER = ThreadLocal.withInitial((Supplier<? extends StringBuilder>) StringBuilder::new);
public static String translate(String message) {
return ChatColor.translateAlternateColorCodes('&', message);
}
public static List<String> translate(List<String> lines) {
List<String> strings = new ArrayList<>();
for (String line : lines) {
strings.add(ChatColor.translateAlternateColorCodes('&', line));
}
return strings;
}
public static List<String> translate(String[] lines) {
List<String> strings = new ArrayList<>();
for (String line : lines) {
if (line != null) {
strings.add(ChatColor.translateAlternateColorCodes('&', line));
}
}
return strings;
}
public static String getMessage(String[] args, int number) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = number; i < args.length; i++) {
stringBuilder.append(args[i]).append(number >= args.length - 1 ? "" : " ");
}
return stringBuilder.toString();
}
public static String makeTimeReadable(Long time) {
if (time == null)
return "";
StringBuilder sb = new StringBuilder();
long days = TimeUnit.MILLISECONDS.toDays(time);
long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time));
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time));
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time));
if (days != 0L)
sb.append(" ").append(days).append("d");
if (hours != 0L)
sb.append(" ").append(hours).append("h");
if (minutes != 0L)
sb.append(" ").append(minutes).append("m");
if (seconds != 0L)
sb.append(" ").append(seconds).append("s");
return sb.toString().trim();
}
public static long parseTime(String input) {
long result = 0L;
StringBuilder number = new StringBuilder();
for (int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if (Character.isDigit(c)) {
number.append(c);
} else if (Character.isLetter(c) && number.length() > 0) {
result += convert(Integer.parseInt(number.toString()), c);
number = new StringBuilder();
}
}
return result;
}
private static long convert(long value, char unit) {
switch (unit) {
case 'd':
return value * 1000L * 60L * 60L * 24L;
case 'h':
return value * 1000L * 60L * 60L;
case 'm':
return value * 1000L * 60L;
case 's':
return value * 1000L;
}
return 0L;
}
public static String makeTimeReadable(int secs) {
final int seconds = secs % 60;
secs -= seconds;
long minutesCount = secs / 60;
final long minutes = minutesCount % 60L;
minutesCount -= minutes;
final long hours = minutesCount / 60L;
final StringBuilder result = MMSS_BUILDER.get();
result.setLength(0);
if (hours > 0L) {
if (hours < 10L) {
result.append("0");
}
result.append(hours);
result.append("h");
}
if (minutes > 0L) {
if (minutes < 10L) {
result.append("0");
}
result.append(minutes);
result.append("m");
}
result.append(seconds);
result.append("s");
return result.toString();
}
public static boolean isNumeric(String string) {
return regexNumeric(string).length() == 0;
}
public static String regexNumeric(String string) {
return string.replaceAll("[0-9]", "").replaceFirst("\\.", "");
}
}

View File

@ -0,0 +1,12 @@
package com.loganmagnan.firstjoincommand.utils.command;
import com.loganmagnan.firstjoincommand.FirstJoinCommand;
public abstract class BaseCommand {
public BaseCommand() {
FirstJoinCommand.getInstance().getCommandFramework().registerCommands(this, null);
}
public abstract void executeAs(CommandArguments command);
}

View File

@ -0,0 +1,81 @@
package com.loganmagnan.firstjoincommand.utils.command;
import org.apache.commons.lang3.Validate;
import org.bukkit.command.Command;
import org.bukkit.command.*;
import org.bukkit.plugin.Plugin;
import java.util.List;
public class BukkitCommand extends Command {
protected BukkitCompleter completer;
private Plugin ownerPlugin;
private CommandExecutor executor;
protected BukkitCommand(String label, CommandExecutor executor, Plugin owner) {
super(label);
this.executor = executor;
this.ownerPlugin = owner;
this.usageMessage = "";
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
boolean success = false;
if (!ownerPlugin.isEnabled()) {
return false;
}
if (!testPermission(sender)) {
return true;
}
try {
success = executor.onCommand(sender, this, commandLabel, args);
} catch (Throwable ex) {
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + ownerPlugin.getDescription().getFullName(), ex);
}
if (!success && usageMessage.length() > 0) {
for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) {
sender.sendMessage(line);
}
}
return success;
}
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (completer != null) {
completions = completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && executor instanceof TabCompleter) {
completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
}
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ").append(ownerPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
}

View File

@ -0,0 +1,47 @@
package com.loganmagnan.firstjoincommand.utils.command;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class BukkitCompleter implements TabCompleter {
private Map<String, Entry<Method, Object>> completers = new HashMap<>();
public void addCompleter(String label, Method m, Object obj) {
completers.put(label, new AbstractMap.SimpleEntry<>(m, obj));
}
@SuppressWarnings("unchecked")
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
for (int i = args.length; i >= 0; i--) {
StringBuffer buffer = new StringBuffer();
buffer.append(label.toLowerCase());
for (int x = 0; x < i; x++) {
if (!args[x].equals("") && !args[x].equals(" ")) {
buffer.append("." + args[x].toLowerCase());
}
}
String cmdLabel = buffer.toString();
if (completers.containsKey(cmdLabel)) {
Entry<Method, Object> entry = completers.get(cmdLabel);
try {
return (List<String>) entry.getKey().invoke(entry.getValue(), new CommandArguments(sender, command, label, args, cmdLabel.split("\\.").length - 1));
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
return null;
}
}

View File

@ -0,0 +1,23 @@
package com.loganmagnan.firstjoincommand.utils.command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Command {
public String name();
public String permission() default "";
public String[] aliases() default {};
public String description() default "";
public String usage() default "";
public boolean inGameOnly() default true;
}

View File

@ -0,0 +1,53 @@
package com.loganmagnan.firstjoincommand.utils.command;
import lombok.Getter;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@Getter
public class CommandArguments {
private CommandSender sender;
private Command command;
private String label;
private String[] args;
protected CommandArguments(CommandSender sender, Command command, String label, String[] args, int subCommand) {
String[] modArgs = new String[args.length - subCommand];
for (int i = 0; i < args.length - subCommand; i++) {
modArgs[i] = args[i + subCommand];
}
StringBuffer buffer = new StringBuffer();
buffer.append(label);
for (int x = 0; x < subCommand; x++) {
buffer.append("." + args[x]);
}
String cmdLabel = buffer.toString();
this.sender = sender;
this.command = command;
this.label = cmdLabel;
this.args = modArgs;
}
public String getArgs(int index) {
return args[index];
}
public int length() {
return args.length;
}
public boolean isPlayer() {
return sender instanceof Player;
}
public Player getPlayer() {
if (sender instanceof Player) {
return (Player) sender;
} else {
return null;
}
}
}

View File

@ -0,0 +1,171 @@
package com.loganmagnan.firstjoincommand.utils.command;
import com.loganmagnan.firstjoincommand.FirstJoinCommand;
import com.loganmagnan.firstjoincommand.utils.ColorUtils;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.SimplePluginManager;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class CommandFramework implements CommandExecutor {
private FirstJoinCommand plugin;
private Map<String, Entry<Method, Object>> commandMap = new HashMap<>();
private CommandMap map;
public CommandFramework(FirstJoinCommand plugin) {
this.plugin = plugin;
if (plugin.getServer().getPluginManager() instanceof SimplePluginManager) {
SimplePluginManager manager = (SimplePluginManager) plugin.getServer().getPluginManager();
try {
Field field = SimplePluginManager.class.getDeclaredField("commandMap");
field.setAccessible(true);
map = (CommandMap) field.get(manager);
} catch (IllegalArgumentException | SecurityException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
}
}
@Override
public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
return handleCommand(sender, cmd, label, args);
}
public boolean handleCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
for (int i = args.length; i >= 0; i--) {
StringBuffer buffer = new StringBuffer();
buffer.append(label.toLowerCase());
for (int x = 0; x < i; x++) {
buffer.append("." + args[x].toLowerCase());
}
String cmdLabel = buffer.toString();
if (commandMap.containsKey(cmdLabel)) {
Method method = commandMap.get(cmdLabel).getKey();
Object methodObject = commandMap.get(cmdLabel).getValue();
Command command = method.getAnnotation(Command.class);
if (!command.permission().equals("") && (!sender.hasPermission(command.permission()))) {
sender.sendMessage(ColorUtils.getMessageType("&cYou don't have permissions to perform this."));
return true;
}
if (command.inGameOnly() && !(sender instanceof Player)) {
sender.sendMessage(ColorUtils.getMessageType("&cThis command can only be executed in game."));
return true;
}
try {
method.invoke(methodObject, new CommandArguments(sender, cmd, label, args, cmdLabel.split("\\.").length - 1));
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return true;
}
}
defaultCommand(new CommandArguments(sender, cmd, label, args, 0));
return true;
}
public void registerCommands(Object obj, List<String> aliases) {
for (Method method : obj.getClass().getMethods()) {
if (method.getAnnotation(Command.class) != null) {
Command command = method.getAnnotation(Command.class);
if (method.getParameterTypes().length > 1 || method.getParameterTypes()[0] != CommandArguments.class) {
System.out.println("Unable to register command " + method.getName() + ". Unexpected method arguments");
continue;
}
registerCommand(command, command.name(), method, obj);
for (String alias : command.aliases()) {
registerCommand(command, alias, method, obj);
}
if (aliases != null) {
for (String alias : aliases) {
registerCommand(command, alias, method, obj);
}
}
} else if (method.getAnnotation(Completer.class) != null) {
Completer comp = method.getAnnotation(Completer.class);
if (method.getParameterTypes().length > 1 || method.getParameterTypes().length == 0 || method.getParameterTypes()[0] != CommandArguments.class) {
System.out.println("Unable to register tab completer " + method.getName() + ". Unexpected method arguments");
continue;
}
if (method.getReturnType() != List.class) {
System.out.println("Unable to register tab completer " + method.getName() + ". Unexpected return type");
continue;
}
registerCompleter(comp.name(), method, obj);
for (String alias : comp.aliases()) {
registerCompleter(alias, method, obj);
}
}
}
}
public void registerCommand(Command command, String label, Method m, Object obj) {
commandMap.put(label.toLowerCase(), new AbstractMap.SimpleEntry<>(m, obj));
commandMap.put(this.plugin.getName() + ':' + label.toLowerCase(), new AbstractMap.SimpleEntry<>(m, obj));
String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase();
if (map.getCommand(cmdLabel) == null) {
org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this, plugin);
map.register(plugin.getName(), cmd);
}
if (!command.description().equalsIgnoreCase("") && cmdLabel.equals(label)) {
map.getCommand(cmdLabel).setDescription(command.description());
}
if (!command.usage().equalsIgnoreCase("") && cmdLabel.equals(label)) {
map.getCommand(cmdLabel).setUsage(command.usage());
}
}
public void registerCompleter(String label, Method m, Object obj) {
String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase();
if (map.getCommand(cmdLabel) == null) {
org.bukkit.command.Command command = new BukkitCommand(cmdLabel, this, plugin);
map.register(plugin.getName(), command);
}
if (map.getCommand(cmdLabel) instanceof BukkitCommand) {
BukkitCommand command = (BukkitCommand) map.getCommand(cmdLabel);
if (command.completer == null) {
command.completer = new BukkitCompleter();
}
command.completer.addCompleter(label, m, obj);
} else if (map.getCommand(cmdLabel) instanceof PluginCommand) {
try {
Object command = map.getCommand(cmdLabel);
Field field = command.getClass().getDeclaredField("completer");
field.setAccessible(true);
if (field.get(command) == null) {
BukkitCompleter completer = new BukkitCompleter();
completer.addCompleter(label, m, obj);
field.set(command, completer);
} else if (field.get(command) instanceof BukkitCompleter) {
BukkitCompleter completer = (BukkitCompleter) field.get(command);
completer.addCompleter(label, m, obj);
} else {
System.out.println("Unable to register tab completer " + m.getName() + ". A tab completer is already registered for that command!");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
private void defaultCommand(CommandArguments args) {
args.getSender().sendMessage(args.getLabel() + " is not handled! Oh noes!");
}
}

View File

@ -0,0 +1,15 @@
package com.loganmagnan.firstjoincommand.utils.command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Completer {
String name();
String[] aliases() default {};
}

View File

@ -0,0 +1,88 @@
package com.loganmagnan.firstjoincommand.utils.config;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public class ConfigCursor {
private final FileConfig fileConfig;
private String path;
public ConfigCursor(FileConfig fileConfig, String path) {
this.fileConfig = fileConfig;
this.path = path;
}
public FileConfig getFileConfig() {
return this.fileConfig;
}
public String getPath() {
return this.path;
}
public void setPath(String path) {
this.path = path;
}
public boolean exists() {
return exists(null);
}
public boolean exists(String path) {
return this.fileConfig.getConfig().contains(this.path + ((path == null) ? "" : ("." + path)));
}
public Set<String> getKeys() {
return getKeys(null);
}
public Set<String> getKeys(String path) {
return this.fileConfig.getConfig().getConfigurationSection(this.path + ((path == null) ? "" : ("." + path))).getKeys(false);
}
public boolean getBoolean(String path) {
return this.fileConfig.getConfig().getBoolean(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public int getInt(String path) {
return this.fileConfig.getConfig().getInt(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public long getLong(String path) {
return this.fileConfig.getConfig().getLong(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public String getString(String path) {
return this.fileConfig.getConfig().getString(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public List<String> getStringList(String path) {
return this.fileConfig.getConfig().getStringList(((this.path == null) ? "" : (this.path + ".")) + "." + path);
}
public UUID getUuid(String path) {
return UUID.fromString(this.fileConfig.getConfig().getString(this.path + "." + path));
}
public World getWorld(String path) {
return Bukkit.getWorld(this.fileConfig.getConfig().getString(this.path + "." + path));
}
public void set(Object value) {
set(null, value);
}
public void set(String path, Object value) {
this.fileConfig.getConfig().set(this.path + ((path == null) ? "" : ("." + path)), value);
}
public void save() {
this.fileConfig.save();
}
}

View File

@ -0,0 +1,50 @@
package com.loganmagnan.firstjoincommand.utils.config;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
public class FileConfig {
private File file;
private FileConfiguration config;
public File getFile() {
return this.file;
}
public FileConfiguration getConfig() {
return this.config;
}
public FileConfig(JavaPlugin plugin, String fileName) {
this.file = new File(plugin.getDataFolder(), fileName);
if (!this.file.exists()) {
this.file.getParentFile().mkdirs();
if (plugin.getResource(fileName) == null) {
try {
this.file.createNewFile();
} catch (IOException e) {
plugin.getLogger().severe("Failed to create new file " + fileName);
}
} else {
plugin.saveResource(fileName, false);
}
}
this.config = YamlConfiguration.loadConfiguration(this.file);
}
public void save() {
try {
this.config.save(this.file);
} catch (IOException e) {
Bukkit.getLogger().severe("Could not save config file " + this.file.toString());
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,39 @@
package com.loganmagnan.firstjoincommand.utils.config.file;
import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
@Getter
public class Config {
private final FileConfiguration config;
private final File configFile;
protected boolean wasCreated;
public Config(String name, JavaPlugin plugin) {
this.configFile = new File(plugin.getDataFolder() + "/" + name + ".yml");
if (!this.configFile.exists()) {
try {
this.configFile.getParentFile().mkdirs();
this.configFile.createNewFile();
this.wasCreated = true;
} catch (IOException e) {
e.printStackTrace();
}
}
this.config = YamlConfiguration.loadConfiguration(this.configFile);
}
public void save() {
try {
this.config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,103 @@
package com.loganmagnan.firstjoincommand.utils.config.file;
import lombok.Getter;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ConfigFile {
@Getter private File file;
@Getter private YamlConfiguration configuration;
public ConfigFile(JavaPlugin plugin, String name) {
file = new File(plugin.getDataFolder(), name + ".yml");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdir();
}
plugin.saveResource(name + ".yml", false);
configuration = YamlConfiguration.loadConfiguration(file);
}
public double getDouble(String path) {
if (configuration.contains(path)) {
return configuration.getDouble(path);
}
return 0;
}
public int getInt(String path) {
if (configuration.contains(path)) {
return configuration.getInt(path);
}
return 0;
}
public boolean getBoolean(String path) {
if (configuration.contains(path)) {
return configuration.getBoolean(path);
}
return false;
}
public String getString(String path) {
if (configuration.contains(path)) {
return ChatColor.translateAlternateColorCodes('&', configuration.getString(path));
}
return "ERROR: STRING NOT FOUND";
}
public String getString(String path, String callback, boolean colorize) {
if (configuration.contains(path)) {
if (colorize) {
return ChatColor.translateAlternateColorCodes('&', configuration.getString(path));
} else {
return configuration.getString(path);
}
}
return callback;
}
public List<String> getReversedStringList(String path) {
List<String> list = getStringList(path);
if (list != null) {
int size = list.size();
List<String> toReturn = new ArrayList<>();
for (int i = size - 1; i >= 0; i--) {
toReturn.add(list.get(i));
}
return toReturn;
}
return Arrays.asList("ERROR: STRING LIST NOT FOUND!");
}
public List<String> getStringList(String path) {
if (configuration.contains(path)) {
ArrayList<String> strings = new ArrayList<>();
for (String string : configuration.getStringList(path)) {
strings.add(ChatColor.translateAlternateColorCodes('&', string));
}
return strings;
}
return Arrays.asList("ERROR: STRING LIST NOT FOUND!");
}
public List<String> getStringListOrDefault(String path, List<String> toReturn) {
if (configuration.contains(path)) {
ArrayList<String> strings = new ArrayList<>();
for (String string : configuration.getStringList(path)) {
strings.add(ChatColor.translateAlternateColorCodes('&', string));
}
return strings;
}
return toReturn;
}
}

View File

@ -0,0 +1,42 @@
package com.loganmagnan.firstjoincommand.utils.cuboid;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class Cuboid {
private final int xMin;
private final int xMax;
private final int yMin;
private final int yMax;
private final int zMin;
private final int zMax;
private final World world;
public Cuboid(final Location point1, final Location point2) {
this.xMin = Math.min(point1.getBlockX(), point2.getBlockX());
this.xMax = Math.max(point1.getBlockX(), point2.getBlockX());
this.yMin = Math.min(point1.getBlockY(), point2.getBlockY());
this.yMax = Math.max(point1.getBlockY(), point2.getBlockY());
this.zMin = Math.min(point1.getBlockZ(), point2.getBlockZ());
this.zMax = Math.max(point1.getBlockZ(), point2.getBlockZ());
this.world = point1.getWorld();
}
private boolean contains(World world, int x, int y, int z) {
return world.getName().equals(this.world.getName()) && x >= xMin && x <= xMax && y >= yMin && y <= yMax && z >= zMin && z <= zMax;
}
private boolean contains(Location loc) {
return this.contains(loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
}
public boolean isInside(Player player) {
return this.contains(player.getLocation());
}
}

View File

@ -0,0 +1,97 @@
package com.loganmagnan.firstjoincommand.utils.cuboid;
import org.bukkit.World;
import org.bukkit.block.Block;
import java.util.Iterator;
public class CuboidBlockIterator implements Iterator<Block> {
private World world;
private int baseX;
private int baseY;
private int baseZ;
private int sizeX;
private int sizeY;
private int sizeZ;
private int x;
private int y;
private int z;
CuboidBlockIterator(World world, int x1, int y1, int z1, int x2, int y2, int z2) {
this.world = world;
this.baseX = x1;
this.baseY = y1;
this.baseZ = z1;
this.sizeX = Math.abs(x2 - x1) + 1;
this.sizeY = Math.abs(y2 - y1) + 1;
this.sizeZ = Math.abs(z2 - z1) + 1;
this.z = 0;
this.y = 0;
this.x = 0;
}
@Override
public boolean hasNext() {
return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ;
}
@Override
public Block next() {
Block block = this.world.getBlockAt(this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z);
if (++this.x >= this.sizeX) {
this.x = 0;
if (++this.y >= this.sizeY) {
this.y = 0;
++this.z;
}
}
return block;
}
@Override
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public World getWorld() {
return this.world;
}
public int getBaseX() {
return this.baseX;
}
public int getBaseY() {
return this.baseY;
}
public int getBaseZ() {
return this.baseZ;
}
public int getSizeX() {
return this.sizeX;
}
public int getSizeY() {
return this.sizeY;
}
public int getSizeZ() {
return this.sizeZ;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getZ() {
return this.z;
}
}

View File

@ -0,0 +1,46 @@
package com.loganmagnan.firstjoincommand.utils.cuboid;
public enum CuboidDirection {
NORTH, EAST, SOUTH, WEST,
UP, DOWN, HORIZONTAL, VERTICAL, BOTH,
UNKNOWN;
private CuboidDirection() {
}
public CuboidDirection opposite() {
switch (this) {
case NORTH: {
return SOUTH;
}
case EAST: {
return WEST;
}
case SOUTH: {
return NORTH;
}
case WEST: {
return EAST;
}
case HORIZONTAL: {
return VERTICAL;
}
case VERTICAL: {
return HORIZONTAL;
}
case UP: {
return DOWN;
}
case DOWN: {
return UP;
}
case BOTH: {
return BOTH;
}
}
return UNKNOWN;
}
}

View File

@ -0,0 +1,97 @@
package com.loganmagnan.firstjoincommand.utils.cuboid;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.Iterator;
public class CuboidLocationIterator implements Iterator<Location> {
private World world;
private int baseX;
private int baseY;
private int baseZ;
private int sizeX;
private int sizeY;
private int sizeZ;
private int x;
private int y;
private int z;
CuboidLocationIterator(World world, int x1, int y1, int z1, int x2, int y2, int z2) {
this.world = world;
this.baseX = x1;
this.baseY = y1;
this.baseZ = z1;
this.sizeX = Math.abs(x2 - x1) + 1;
this.sizeY = Math.abs(y2 - y1) + 1;
this.sizeZ = Math.abs(z2 - z1) + 1;
this.z = 0;
this.y = 0;
this.x = 0;
}
@Override
public boolean hasNext() {
return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ;
}
@Override
public Location next() {
Location location = new Location(this.world, this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z);
if (++this.x >= this.sizeX) {
this.x = 0;
if (++this.y >= this.sizeY) {
this.y = 0;
++this.z;
}
}
return location;
}
@Override
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
public World getWorld() {
return this.world;
}
public int getBaseX() {
return this.baseX;
}
public int getBaseY() {
return this.baseY;
}
public int getBaseZ() {
return this.baseZ;
}
public int getSizeX() {
return this.sizeX;
}
public int getSizeY() {
return this.sizeY;
}
public int getSizeZ() {
return this.sizeZ;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getZ() {
return this.z;
}
}

View File

@ -0,0 +1,5 @@
FIRST-JOIN-COMMANDS:
- "say Hello %player%."
- "give %player% stone 100"
DELAY-AMOUNT: 5 # Seconds

View File

@ -0,0 +1,5 @@
name: FirstJoinCommand
version: 1.0
author: Trixkz
api-version: 1.13
main: com.loganmagnan.firstjoincommand.FirstJoinCommand