Moved to maven

This commit is contained in:
stijnb1234 2020-11-16 18:52:42 +01:00
parent 833b55d6ca
commit 78c68f4f32
32 changed files with 382 additions and 2739 deletions

View file

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: me.mctp.Main

View file

@ -6,7 +6,6 @@ import me.mctp.listener.WGListener;
import me.mctp.managers.WGManager;
import me.mctp.radio.Playlist;
import me.mctp.socket.Client;
import nl.iobyte.menuapi.MenuAPI;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.Listener;
@ -39,7 +38,7 @@ public class Main extends JavaPlugin implements Listener {
pl = this;
client = new Client("ws://bots.d-group.nl:8166");
client = new Client("ws://173.249.31.58:8166");
client.connect();
getCommand("audio").setExecutor(new MCTPAudioCMD());
@ -50,8 +49,6 @@ public class Main extends JavaPlugin implements Listener {
playlist = new Playlist();
MenuAPI.register(this);
Bukkit.getLogger().info(prefix + " __ __ ____ _____ ____ _ _ _ ");
Bukkit.getLogger().info(prefix + " | \\/ |/ ___|_ _| _ \\ / \\ _ _ __| (_) ___ ");
Bukkit.getLogger().info(prefix + " | |\\/| | | | | | |_) / _ \\| | | |/ _` | |/ _ \\ ");

View file

@ -72,6 +72,8 @@ public class WGListener implements Listener {
/** Hue detection */
@EventHandler
public void onRegionEnter(RegionsEnteredEvent e) {
if (e.getPlayer() == null) return;
Set<String> list2 = Main.getPlugin().getConfig().getConfigurationSection("HueRegions").getKeys(false);
if (!Collections.disjoint(list2, e.getRegionsNames())) {
@ -91,7 +93,7 @@ public class WGListener implements Listener {
Integer brightness = null;
if (configDataSplit.length == 5) brightness = Integer.parseInt(configDataSplit[4]);
if (!PinManager.hasPin(Objects.requireNonNull(e.getPlayer()).getUniqueId())) return;
if (!PinManager.hasPin(e.getPlayer().getUniqueId())) return;
JSONObject data = new JSONObject();
data.put("task", "HUE");

View file

@ -5,7 +5,7 @@ import java.util.UUID;
import java.util.WeakHashMap;
public class PinManager {
private static WeakHashMap<UUID, String> pins = new WeakHashMap<>();
private static final WeakHashMap<UUID, String> pins = new WeakHashMap<>();
/**
* Get the pin of a player

View file

@ -13,7 +13,7 @@ import org.json.simple.JSONObject;
import java.io.IOException;
public class Playlist {
private me.mctp.api.maps.Playlist<String> songList = new me.mctp.api.maps.Playlist<>();
private final me.mctp.api.maps.Playlist<String> songList = new me.mctp.api.maps.Playlist<>();
private boolean running = false;
private BukkitTask currentTimer;
@ -66,6 +66,8 @@ public class Playlist {
public void nextSong() {
if (currentTimer != null) return;
if (songList.isEmpty()) return;
//Get song
String nextURL = songList.getRandom();
if (nextURL == null) return;

View file

@ -3,7 +3,7 @@ package me.mctp.utils;
import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.UnsupportedTagException;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.io.FileOutputStream;
@ -26,7 +26,7 @@ public class HeadUtil {
}
}
return result.toString().replaceAll(".", "");
return result.toString().replaceAll("\\.", "");
}
private static String downloadFromUrl(URL url, String localFilename) throws IOException {

View file

@ -16,7 +16,7 @@ import java.util.stream.Collectors;
public class SpigotPlayerSelector {
private String selector;
private final String selector;
public SpigotPlayerSelector(String selector) {
this.selector = selector;
@ -150,7 +150,7 @@ public class SpigotPlayerSelector {
}
}
return result.toString().replaceAll(".", "");
return result.toString().replaceAll("\\.", "");
}
}

View file

@ -1,10 +1,10 @@
main: me.mctp.Main
name: MCTPAudio
version: 1.2
api-version: 1.14
author: MaybeFromNL_SBDeveloper
version: ${project.version}
main: me.mctp.Main
api-version: 1.16
authors: [ SBDeveloper ]
depend: [ WorldGuard ]
description: Copyright MaybeFromNL & SBDeveloper
depend: ['WorldGuard']
commands:
mctpaudio:

View file

@ -1,57 +0,0 @@
package me.mctp.utils;
import me.mctp.xutils.SkullUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MultiPageGUI {
private List<Inventory> inventories = new ArrayList<>();
public MultiPageGUI(String title, int itemsPerPage, List<ItemStack> items) {
if (!title.contains("%page%")) {
throw new IllegalArgumentException("Title must contain %page% for the page.");
}
int invSize = itemsPerPage + 9;
if (itemsPerPage%9 != 0) {
throw new IllegalArgumentException("ItemsPerPage must be divisible by 9.");
}
int neededInvs = ((int) Math.ceil(items.size() / invSize));
for (int i = 0; i < neededInvs; i++) {
//Create inv
Inventory inv = Bukkit.createInventory(null, invSize - 1, title.replace("%page%", String.valueOf(i + 1)));
inventories.add(inv);
//Add navigation
ItemStack previous = SkullUtils.getSkull(UUID.fromString("a68f0b64-8d14-4000-a95f-4b9ba14f8df9"));
ItemMeta previousMeta = previous.getItemMeta();
previousMeta.setDisplayName(ChatColor.GOLD + "<< Vorige Pagina");
previous.setItemMeta(previousMeta);
ItemStack close = new ItemStack(Material.BARRIER, 1);
ItemMeta closeMeta = close.getItemMeta();
closeMeta.setDisplayName(ChatColor.RED + "Sluit Menu");
close.setItemMeta(closeMeta);
ItemStack next = SkullUtils.getSkull(UUID.fromString("50c8510b-5ea0-4d60-be9a-7d542d6cd156"));
ItemMeta nextMeta = next.getItemMeta();
nextMeta.setDisplayName(ChatColor.GOLD + "Volgende Pagina >>");
next.setItemMeta(nextMeta);
inv.setItem(itemsPerPage, previous);
inv.setItem(itemsPerPage + 4, close);
inv.setItem(itemsPerPage + 8, next);
}
}
}

View file

@ -1,144 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Crypto Morin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.mctp.xutils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.concurrent.CompletableFuture;
/**
* <b>ReflectionUtils</b> - Reflection handler for NMS and CraftBukkit.<br>
* Caches the packet related methods and is asynchronous.
* <p>
* This class does not handle null checks as most of the requests are from the
* other utility classes that already handle null checks.
* <p>
* <a href="https://wiki.vg/Protocol">Clientbound Packets</a> are considered fake
* updates to the client without changing the actual data. Since all the data is handled
* by the server.
*
* @author Crypto Morin
* @version 1.0.2
*/
public class ReflectionUtils {
/**
* We use reflection mainly to avoid writing a new class for version barrier.
* The version barrier is for NMS that uses the Minecraft version as the main package name.
* <p>
* E.g. EntityPlayer in 1.15 is in the class {@code net.minecraft.server.v1_15_R1}
* but in 1.14 it's in {@code net.minecraft.server.v1_14_R1}
* In order to maintain cross-version compatibility we cannot import these classes.
*/
public static final String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
public static final String CRAFTBUKKIT = "org.bukkit.craftbukkit." + VERSION + '.';
public static final String NMS = "net.minecraft.server." + VERSION + '.';
private static final MethodHandle PLAYER_CONNECTION;
private static final MethodHandle GET_HANDLE;
private static final MethodHandle SEND_PACKET;
static {
Class<?> entityPlayer = getNMSClass("EntityPlayer");
Class<?> craftPlayer = getCraftClass("entity.CraftPlayer");
Class<?> playerConnection = getNMSClass("PlayerConnection");
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandle sendPacket = null;
MethodHandle getHandle = null;
MethodHandle connection = null;
try {
connection = lookup.findGetter(entityPlayer, "playerConnection", playerConnection);
getHandle = lookup.findVirtual(craftPlayer, "getHandle", MethodType.methodType(entityPlayer));
sendPacket = lookup.findVirtual(playerConnection, "sendPacket", MethodType.methodType(void.class, getNMSClass("Packet")));
} catch (NoSuchMethodException | NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
PLAYER_CONNECTION = connection;
SEND_PACKET = sendPacket;
GET_HANDLE = getHandle;
}
/**
* Get a NMS (net.minecraft.server) class.
*
* @param name the name of the class.
* @return the class.
* @since 1.0.0
*/
@Nullable
public static Class<?> getNMSClass(@Nonnull String name) {
try {
return Class.forName(NMS + name);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
return null;
}
}
/**
* Sends a packet to the player asynchronously.
* Packets are thread-safe.
*
* @param player the player to send the packet to.
* @param packets the packets to send.
* @return the async thread handling the packet.
* @since 1.0.0
*/
@Nonnull
public static CompletableFuture<Void> sendPacket(@Nonnull Player player, @Nonnull Object... packets) {
return CompletableFuture.runAsync(() -> {
try {
Object handle = GET_HANDLE.invoke(player);
Object connection = PLAYER_CONNECTION.invoke(handle);
if (player.isOnline()) {
for (Object packet : packets) SEND_PACKET.invoke(connection, packet);
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
});
}
/**
* Get a CraftBukkit class.
*
* @param name the name of the class.
* @return a class.
* @since 1.0.0
*/
@Nullable
public static Class<?> getCraftClass(@Nonnull String name) {
try {
return Class.forName(CRAFTBUKKIT + name);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
return null;
}
}
}

View file

@ -1,123 +0,0 @@
package me.mctp.xutils;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.authlib.GameProfile;
import org.apache.commons.lang.Validate;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
/**
* This class is currently unused until I find a solution.
*/
@SuppressWarnings("unused")
final class SkullCacheListener {
protected static final Map<UUID, String> CACHE = new HashMap<>();
private static final String SESSION = "https://sessionserver.mojang.com/session/minecraft/profile/";
/**
* https://api.mojang.com/users/profiles/minecraft/Username gives the ID
* https://api.mojang.com/user/profiles/ID without dashes/names gives the names used for the unique ID.
* https://sessionserver.mojang.com/session/minecraft/profile/ID example data:
* <p>
* <pre>
* {
* "id": "Without dashes -",
* "name": "",
* "properties": [
* {
* "name": "textures",
* "value": ""
* }
* ]
* }
* </pre>
*/
@Nullable
public static String getSkinValue(@Nonnull String id) {
Objects.requireNonNull(id, "Player UUID cannot be null");
try {
JsonParser parser = new JsonParser();
URL properties = new URL(SESSION + id); // + "?unsigned=false"
try (InputStreamReader readProperties = new InputStreamReader(properties.openStream())) {
JsonObject jObjectP = parser.parse(readProperties).getAsJsonObject();
if (mojangError(jObjectP)) return null;
JsonObject textureProperty = jObjectP.get("properties").getAsJsonArray().get(0).getAsJsonObject();
//String signature = textureProperty.get("signature").getAsString();
return textureProperty.get("value").getAsString();
}
} catch (IOException | IllegalStateException e) {
System.err.println("Could not get skin data from session servers! " + e.getMessage());
e.printStackTrace();
return null;
}
}
@Nullable
public static String getIdFromUsername(@Nonnull String username) {
Validate.notEmpty(username, "Cannot get UUID of a null or empty username");
int len = username.length();
if (len < 3 || len > 16) throw new IllegalArgumentException("Username cannot be less than 3 and longer than 16 characters: " + username);
try {
URL convertName = new URL("https://api.mojang.com/users/profiles/minecraft/" + username);
JsonParser parser = new JsonParser();
try (InputStreamReader idReader = new InputStreamReader(convertName.openStream())) {
JsonElement jElement = parser.parse(idReader);
if (!jElement.isJsonObject()) return null;
JsonObject jObject = jElement.getAsJsonObject();
if (mojangError(jObject)) return null;
return jObject.get("id").getAsString();
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
private static boolean mojangError(@Nonnull JsonObject jsonObject) {
if (!jsonObject.has("error")) return false;
String err = jsonObject.get("error").getAsString();
String msg = jsonObject.get("errorMessage").getAsString();
System.err.println("Mojang Error " + err + ": " + msg);
return true;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
GameProfile profile = new GameProfile(player.getUniqueId(), player.getName());
ItemStack head = XMaterial.PLAYER_HEAD.parseItem();
SkullMeta meta = (SkullMeta) head.getItemMeta();
try {
SkullUtils.GAME_PROFILE.invoke(meta, profile);
} catch (Throwable ex) {
ex.printStackTrace();
}
head.setItemMeta(meta);
// If you don't add it to the players inventory, it won't be cached. That's the problem.
// Or is the inventory cached? I tested this with multiple inventories and other inventories load immediately after an inventory with
// the skull in it is opened once.
player.getInventory().addItem(head);
}
}

View file

@ -1,191 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Crypto Morin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package me.mctp.xutils;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.util.Base64;
import java.util.Objects;
import java.util.UUID;
import java.util.regex.Pattern;
/**
* <b>SkullUtils</b> - Apply skull texture from different sources.<br>
* Skull Meta: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/meta/SkullMeta.html
* Mojang API: https://wiki.vg/Mojang_API
*
* @author Crypto Morin
* @version 3.0.1
* @see XMaterial
*/
public class SkullUtils {
protected static final MethodHandle GAME_PROFILE;
private static final String VALUE_PROPERTY = "{\"textures\":{\"SKIN\":{\"url\":\"";
private static final boolean SUPPORTS_UUID = XMaterial.supports(12);
private static final String TEXTURES = "https://textures.minecraft.net/texture/";
private static final Pattern BASE64 = Pattern.compile("(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?");
static {
MethodHandles.Lookup lookup = MethodHandles.lookup();
MethodHandle gameProfile = null;
try {
Class<?> craftSkull = ReflectionUtils.getCraftClass("inventory.CraftMetaSkull");
Field profileField = craftSkull.getDeclaredField("profile");
profileField.setAccessible(true);
gameProfile = lookup.unreflectSetter(profileField);
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
GAME_PROFILE = gameProfile;
}
@SuppressWarnings("deprecation")
@Nonnull
public static ItemStack getSkull(@Nonnull UUID id) {
ItemStack head = XMaterial.PLAYER_HEAD.parseItem();
SkullMeta meta = (SkullMeta) head.getItemMeta();
if (SUPPORTS_UUID) meta.setOwningPlayer(Bukkit.getOfflinePlayer(id));
else meta.setOwner(id.toString());
head.setItemMeta(meta);
return head;
}
@Nonnull
public static SkullMeta applyCachedSkin(@Nonnull ItemMeta head, @Nonnull UUID identifier) {
String base64 = SkullCacheListener.CACHE.get(identifier);
SkullMeta meta = (SkullMeta) head;
return getSkullByValue(meta, base64);
}
@SuppressWarnings("deprecation")
@Nonnull
public static SkullMeta applySkin(@Nonnull ItemMeta head, @Nonnull OfflinePlayer identifier) {
SkullMeta meta = (SkullMeta) head;
if (SUPPORTS_UUID) {
meta.setOwningPlayer(identifier);
} else {
meta.setOwner(identifier.getName());
}
return meta;
}
@Nonnull
public static SkullMeta applySkin(@Nonnull ItemMeta head, @Nonnull UUID identifier) {
return applySkin(head, Bukkit.getOfflinePlayer(identifier));
}
@SuppressWarnings("deprecation")
@Nonnull
public static SkullMeta applySkin(@Nonnull ItemMeta head, @Nonnull String identifier) {
SkullMeta meta = (SkullMeta) head;
if (isUsername(identifier)) return applySkin(head, Bukkit.getOfflinePlayer(identifier));
if (identifier.contains("textures.minecraft.net")) return getValueFromTextures(meta, identifier);
if (identifier.length() > 100 && isBase64(identifier)) return getSkullByValue(meta, identifier);
return getTexturesFromUrlValue(meta, identifier);
}
@Nonnull
private static SkullMeta getSkullByValue(@Nonnull SkullMeta head, @Nonnull String value) {
Validate.notEmpty(value, "Skull value cannot be null or empty");
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", value));
try {
GAME_PROFILE.invoke(head, profile);
} catch (Throwable ex) {
ex.printStackTrace();
}
return head;
}
@Nonnull
private static SkullMeta getValueFromTextures(@Nonnull SkullMeta head, @Nonnull String url) {
return getSkullByValue(head, encodeBase64(VALUE_PROPERTY + url + "\"}}}"));
}
@Nonnull
private static SkullMeta getTexturesFromUrlValue(@Nonnull SkullMeta head, @Nonnull String urlValue) {
return getValueFromTextures(head, TEXTURES + urlValue);
}
@Nonnull
private static String encodeBase64(@Nonnull String str) {
return Base64.getEncoder().encodeToString(str.getBytes());
}
private static boolean isBase64(@Nonnull String base64) {
return BASE64.matcher(base64).matches();
}
@Nullable
public static String getSkinValue(@Nonnull ItemStack skull) {
Objects.requireNonNull(skull, "Skull ItemStack cannot be null");
SkullMeta meta = (SkullMeta) skull.getItemMeta();
GameProfile profile = null;
try {
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profile = (GameProfile) profileField.get(meta);
} catch (SecurityException | NoSuchFieldException | IllegalAccessException ex) {
ex.printStackTrace();
}
if (profile != null && !profile.getProperties().get("textures").isEmpty())
for (Property property : profile.getProperties().get("textures"))
if (!property.getValue().isEmpty())
return property.getValue();
return null;
}
private static boolean isUsername(@Nullable String name) {
if (Strings.isNullOrEmpty(name)) return false;
int len = name.length();
if (len < 3 || len > 16) return false;
// For some reasons Apache's Lists.charactersOf is faster than character indexing for small strings.
for (char ch : Lists.charactersOf(name)) {
if (ch != '_' && !(ch >= 'A' && ch <= 'Z') && !(ch >= 'a' && ch <= 'z') && !(ch >= '0' && ch <= '9')) return false;
}
return true;
}
}

File diff suppressed because it is too large Load diff