Skip to content

Commit

Permalink
Updated to upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubix327 committed Oct 7, 2022
2 parents 920c785 + 8037e70 commit 95a3e38
Show file tree
Hide file tree
Showing 51 changed files with 2,923 additions and 1,825 deletions.
4 changes: 2 additions & 2 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
before_install:
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
- source ./install-jdk.sh --feature 18
- source ./install-jdk.sh --feature 19
jdk:
- openjdk18
- openjdk19
39 changes: 28 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<!-- (c) All rights reserved. Do not share, copy, reproduce
<!-- (c) All rights reserved. Do not share, copy, reproduce
or sell any part of this library unless you have written permission from
MineAcademy.org. All infringements will be prosecuted. If you are the personal
owner of the MineAcademy.org End User License then you may use it for your
own use in plugins but not for any other purpose. -->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.mineacademy</groupId>
<artifactId>Foundation</artifactId>
<version>6.1.0</version>
<version>6.2.1</version>
<packaging>jar</packaging>

<name>Foundation</name>
Expand All @@ -33,6 +31,7 @@
</repositories>

<dependencies>

<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
Expand All @@ -49,13 +48,13 @@
<scope>provided</scope>
</dependency>

<!-- The Spigot API -->
<!-- The core Spigot-API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.19.2-R0.1-SNAPSHOT</version>
</dependency>

<!-- MineAcademy guaranteed availability repos for plugins -->
<dependency>
<groupId>org.mineacademy.plugin</groupId>
Expand All @@ -66,11 +65,11 @@
<groupId>org.mineacademy.plugin</groupId>
<artifactId>BentoBox</artifactId>
<version>1.20.1</version>
</dependency>
</dependency>
<dependency>
<groupId>org.mineacademy.plugin</groupId>
<artifactId>CitizensAPI</artifactId>
<version>2.0.29-b839</version>
<version>2.0.30-b879</version>
</dependency>
<dependency>
<groupId>org.mineacademy.plugin</groupId>
Expand Down Expand Up @@ -155,12 +154,12 @@
<dependency>
<groupId>org.mineacademy.plugin</groupId>
<artifactId>WorldEdit</artifactId>
<version>7.2.10</version>
<version>7.2.12</version>
</dependency>
<dependency>
<groupId>org.mineacademy.plugin</groupId>
<artifactId>WorldGuard</artifactId>
<version>7.0.7</version>
<version>7.0.5</version>
</dependency>
</dependencies>
<build>
Expand All @@ -179,6 +178,24 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.20.0</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<outputDirectory>${delombok.output}</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
</configuration>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
57 changes: 21 additions & 36 deletions src/main/java/org/mineacademy/fo/BungeeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import org.mineacademy.fo.plugin.SimplePlugin;
import org.mineacademy.fo.remain.Remain;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.UUID;

/**
Expand Down Expand Up @@ -73,9 +71,10 @@ public static <T> void sendPluginMessage(String channel, BungeeMessageType actio
*
* OBS! The data written always start with:
*
* 1. The recipient UUID
* 2. {@link Remain#getServerName()}
* 3. The action parameter
* 1. The channel name (to avoid "Unknown custom packed identifier: plugin:chcred" console spam we use "BungeeCord")
* 2. The recipient UUID
* 3. {@link Remain#getServerName()}
* 4. The action parameter
*
*
* @param <T>
Expand Down Expand Up @@ -104,6 +103,7 @@ public static <T> void sendPluginMessage(Player sender, String channel, BungeeMe

final ByteArrayDataOutput out = ByteStreams.newDataOutput();

out.writeUTF(channel);
out.writeUTF(sender.getUniqueId().toString());
out.writeUTF(Remain.getServerName());
out.writeUTF(action.toString());
Expand Down Expand Up @@ -197,7 +197,7 @@ public static <T> void sendPluginMessage(Player sender, String channel, BungeeMe
final byte[] byteArray = out.toByteArray();

try {
sender.sendPluginMessage(SimplePlugin.getInstance(), channel, byteArray);
sender.sendPluginMessage(SimplePlugin.getInstance(), "BungeeCord", byteArray);

} catch (final ChannelNotRegisteredException ex) {
Common.log("Cannot send Bungee '" + action + "' message because channel '" + channel + "' is not registered. "
Expand All @@ -210,6 +210,18 @@ public static <T> void sendPluginMessage(Player sender, String channel, BungeeMe
actionHead = 0;
}

/**
* Sends a plugin message that will re-connect the player to another server on Bungee
*
* @param player the living non-dead player
* @param serverName the server name as you have in config.yml of your BungeeCord
*/
public static void connect(@NonNull Player player, @NonNull String serverName) {
sendBungeeMessage(player,
"Connect",
serverName);
}

/**
* Sends message via a channel to the bungee network (upstreams). You need an
* implementation in bungee to handle it, otherwise nothing will happen.
Expand All @@ -220,7 +232,7 @@ public static <T> void sendPluginMessage(Player sender, String channel, BungeeMe
* @param sender the player to send the message as
* @param data the data
*/
public static void sendMessage(@NonNull Player sender, Object... data) {
public static void sendBungeeMessage(@NonNull Player sender, Object... data) {
Valid.checkBoolean(data != null && data.length >= 1, "");

final ByteArrayDataOutput out = ByteStreams.newDataOutput();
Expand All @@ -247,47 +259,20 @@ else if (datum instanceof String)
sender.sendPluginMessage(SimplePlugin.getInstance(), "BungeeCord", out.toByteArray());
}

/**
* Sends a plugin message that will re-connect the player to another server on Bungee
*
* @param player the living non-dead player
* @param serverName the server name as you have in config.yml of your BungeeCord
*/
public static void connect(@NonNull Player player, @NonNull String serverName) {
final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(byteArray);

try {
out.writeUTF("Connect");
out.writeUTF(serverName);

} catch (final Throwable t) {
Common.error(t,
"Unable to connect " + player.getName() + " to server " + serverName,
"Error: %error");
}

player.sendPluginMessage(SimplePlugin.getInstance(), "BungeeCord", byteArray.toByteArray());
}

/**
/*
* Return either the first online player or the server itself
* through which we send the bungee message as
*
* @return
*/
private static Player findFirstPlayer() {
return Remain.getOnlinePlayers().isEmpty() ? null : Remain.getOnlinePlayers().iterator().next();
}

/**
/*
* Ensures we are reading in the correct order as the given {@link BungeeMessageType}
* specifies in its {@link BungeeMessageType#getContent()} getter.
* <p>
* This also ensures we are reading the correct data type (both primitives and wrappers
* are supported).
*
* @param typeOf
*/
private static void moveHead(int actionHead, BungeeMessageType action, Class<?> typeOf, Object[] data) throws Throwable {
Valid.checkNotNull(action, "Action not set!");
Expand Down
98 changes: 70 additions & 28 deletions src/main/java/org/mineacademy/fo/Common.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
package org.mineacademy.fo;

import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand All @@ -34,6 +17,8 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
Expand All @@ -44,6 +29,7 @@
import org.mineacademy.fo.collection.SerializedMap;
import org.mineacademy.fo.collection.StrictList;
import org.mineacademy.fo.collection.StrictMap;
import org.mineacademy.fo.constants.FoConstants;
import org.mineacademy.fo.debug.Debugger;
import org.mineacademy.fo.exception.FoException;
import org.mineacademy.fo.exception.RegexTimeoutException;
Expand All @@ -52,16 +38,23 @@
import org.mineacademy.fo.model.Replacer;
import org.mineacademy.fo.plugin.SimplePlugin;
import org.mineacademy.fo.remain.CompChatColor;
import org.mineacademy.fo.remain.CompMaterial;
import org.mineacademy.fo.remain.Remain;
import org.mineacademy.fo.remain.nbt.NBTItem;
import org.mineacademy.fo.settings.ConfigSection;
import org.mineacademy.fo.settings.SimpleLocalization;
import org.mineacademy.fo.settings.SimpleSettings;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import net.md_5.bungee.api.chat.TextComponent;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
* Our main utility class hosting a large variety of different convenience functions
Expand Down Expand Up @@ -948,7 +941,11 @@ private static String getException(final long count, final String ofWhat) {
"datum", "data",
"index", "indices",
"entry", "entries",
"boss", "bosses");
"boss", "bosses",
"iron", "iron",
"Iron", "Iron",
"gold", "gold",
"Gold", "Gold");

return exceptions.containsKey(ofWhat) ? count + " " + (count == 0 || count > 1 ? exceptions.getString(ofWhat) : ofWhat) : null;
}
Expand Down Expand Up @@ -999,13 +996,58 @@ public static String fancyBar(final int min, final char minChar, final int max,
/**
* Formats the vector location to one digit decimal points
*
* DO NOT USE FOR SAVING, ONLY INTENDED FOR DEBUGGING
*
* @param vec
* @return
*/
public static String shortLocation(final Vector vec) {
return " [" + MathUtil.formatOneDigit(vec.getX()) + ", " + MathUtil.formatOneDigit(vec.getY()) + ", " + MathUtil.formatOneDigit(vec.getZ()) + "]";
}

/**
* Formats the item stack into a readable useful console log
* printing only its name, lore and nbt tags
*
* DO NOT USE FOR SAVING, ONLY INTENDED FOR DEBUGGING
*
* @param item
* @return
*/
public static String shortItemStack(ItemStack item) {
if (item == null)
return "null";

if (CompMaterial.isAir(item.getType()))
return "Air";

String name = ItemUtil.bountifyCapitalized(item.getType());

if (Remain.hasItemMeta() && item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();

name += "{";

if (meta.hasDisplayName())
name += "name='" + Common.stripColors(meta.getDisplayName()) + "', ";

if (meta.hasLore())
name += "lore=[" + Common.stripColors(String.join(", ", meta.getLore())) + "], ";

final NBTItem nbt = new NBTItem(item);

if (nbt.hasTag(FoConstants.NBT.TAG))
name += "tags=" + nbt.getCompound(FoConstants.NBT.TAG) + ", ";

if (name.endsWith(", "))
name = name.substring(0, name.length() - 2);

name += "}";
}

return name;
}

/**
* Formats the given location to block points without decimals
*
Expand Down
Loading

0 comments on commit 95a3e38

Please sign in to comment.