add new files
This commit is contained in:
parent
5e33753041
commit
ec4d1bf526
113
T2CodeLibNew/.gitignore
vendored
Normal file
113
T2CodeLibNew/.gitignore
vendored
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
144
T2CodeLibNew/pom.xml
Normal file
144
T2CodeLibNew/pom.xml
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<?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>net.t2code</groupId>
|
||||||
|
<artifactId>T2CodeLib</artifactId>
|
||||||
|
<version>13.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>T2CodeLib</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>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype-oss-snapshots1</id>
|
||||||
|
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- Mojang / Spigot -->
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- repo.t2code / T2Code -->
|
||||||
|
<repository>
|
||||||
|
<id>Builders-Paradise</id>
|
||||||
|
<url>https://repo.t2code.net/repository/Builders-Paradise/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>T2Code</id>
|
||||||
|
<url>https://repo.t2code.net/repository/T2Code/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- Vault-->
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
<!-- placeholderapi -->
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- votingplugin -->
|
||||||
|
<repository>
|
||||||
|
<id>BenCodez Repo</id>
|
||||||
|
<url>https://nexus.bencodez.com/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Mojang / Spigot-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.19-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- repo.t2code / T2Code -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.t2code</groupId>
|
||||||
|
<artifactId>bungee</artifactId>
|
||||||
|
<version>1642</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.t2code</groupId>
|
||||||
|
<artifactId>LuckyBox-API</artifactId>
|
||||||
|
<version>4.2.7</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Vault-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- placeholderapi -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- votingplugin -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bencodez</groupId>
|
||||||
|
<artifactId>votingplugin</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!--Kyori MiniMessage-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<version>4.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class T2Ccmd {
|
||||||
|
public static void console(String cmd) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void player(Player player, String cmd) {
|
||||||
|
player.chat("/" + cmd);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class T2Ctab {
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int arg, String[] args, String perm, Boolean onlinePlayer) {
|
||||||
|
if (args.length != arg + 1) return;
|
||||||
|
for (Player player1 : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (passend(player1.getName(), args[arg]) && hasPermission(sender, perm)) {
|
||||||
|
matches.add(player1.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int argEquals, String equalsValue, int arg, String[] args, String perm, Boolean onlinePlayer) {
|
||||||
|
if (args.length != arg + 1) return;
|
||||||
|
if (!args[argEquals].toLowerCase().equals(equalsValue)) return;
|
||||||
|
for (Player player1 : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (passend(player1.getName(), args[arg]) && hasPermission(sender, perm)) {
|
||||||
|
matches.add(player1.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int arg, String[] args, HashMap<String, String> permMap, Boolean onlinePlayer, String permForPlayer) {
|
||||||
|
if (args.length != arg + 1) return;
|
||||||
|
for (String command : permMap.keySet()) {
|
||||||
|
if (hasPermission(sender, permMap.get(command)) && passend(command, args[arg])) {
|
||||||
|
matches.add(command);
|
||||||
|
} else if (onlinePlayer != null && permForPlayer != null) {
|
||||||
|
tab(matches, sender, arg, args, permForPlayer, onlinePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int arg, String[] args, HashMap<String, String> permMap) {
|
||||||
|
tab(matches, sender, arg, args, permMap, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int argEquals, String equalsValue, int arg, String[] args, HashMap<String, String> permMap) {
|
||||||
|
if (args.length != arg + 1) return;
|
||||||
|
if (!args[argEquals].toLowerCase().equals(equalsValue)) return;
|
||||||
|
for (String command : permMap.keySet()) {
|
||||||
|
if (hasPermission(sender, permMap.get(command)) && passend(command, args[arg])) {
|
||||||
|
matches.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> tab(CommandSender sender, int arg, String[] args, String perm, String command) {
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
if (hasPermission(sender, perm) && passend(command, args[arg])) {
|
||||||
|
matches.add(command);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean passend(String command, String arg) {
|
||||||
|
for (int i = 0; i < arg.toUpperCase().length(); i++) {
|
||||||
|
if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPermission(CommandSender sender, String permission) {
|
||||||
|
String[] Permissions = permission.split(";");
|
||||||
|
for (String perm : Permissions) {
|
||||||
|
if (sender.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.eco;
|
||||||
|
|
||||||
|
import com.bencodez.votingplugin.VotingPluginMain;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class T2Ceco {
|
||||||
|
public static boolean moneyRemove(String prefix, Player player, Double price) {
|
||||||
|
if (vault(prefix, player)) {
|
||||||
|
return T2CodeLibMain.getEco().withdrawPlayer(player, price).transactionSuccess();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean moneyAdd(String prefix, Player player, Double price) {
|
||||||
|
if (vault(prefix, player)) {
|
||||||
|
return T2CodeLibMain.getEco().depositPlayer(player, price).transactionSuccess();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean vault(String prefix, Player player) {
|
||||||
|
if (T2CodeLibMain.getEco() == null) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||||
|
T2Csend.console(prefix + " §4\n" + prefix + " §4Vault could not be found! §9Please download it here: " +
|
||||||
|
"§6https://www.spigotmc.org/resources/vault.34315/§4\n" + prefix);
|
||||||
|
}
|
||||||
|
player.sendMessage(prefix + "\n" + SelectLibMsg.vaultNotSetUp + "\n" + prefix);
|
||||||
|
return false;
|
||||||
|
} else return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean itemRemove(Player player, String item, int amount) {
|
||||||
|
ItemStack itemStack = new ItemStack(Material.valueOf(item.toUpperCase()));
|
||||||
|
boolean have = false;
|
||||||
|
int anz = 0;
|
||||||
|
for (int iam = 0; iam < player.getInventory().getSize(); iam++) {
|
||||||
|
ItemStack itm = player.getInventory().getItem(iam);
|
||||||
|
if (itm == null) continue;
|
||||||
|
if (itm.getType() == itemStack.getType()) {
|
||||||
|
anz = anz + itm.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (anz >= amount) {
|
||||||
|
player.getInventory().removeItem(new ItemStack(Material.valueOf(item), amount));
|
||||||
|
have = true;
|
||||||
|
}
|
||||||
|
return have;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean itemAdd(Player player, ItemStack itemStack, int amount) {
|
||||||
|
boolean empty = false;
|
||||||
|
for (int i = 0; i < player.getInventory().getSize() - 5; i++) {
|
||||||
|
if (player.getInventory().getItem(i) == null) {
|
||||||
|
empty = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < amount; i++) {
|
||||||
|
if (empty) {
|
||||||
|
player.getInventory().addItem(itemStack);
|
||||||
|
} else {
|
||||||
|
player.getLocation().getWorld().dropItem(player.getLocation(), itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean votePointsRemove(String prefix, Player player, Integer amount) {
|
||||||
|
if (votePlugin(prefix, player)) {
|
||||||
|
return VotingPluginMain.getPlugin().getVotingPluginUserManager().getVotingPluginUser(player).removePoints(amount);
|
||||||
|
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean votePointsAdd(String prefix, Player player, Integer amount) {
|
||||||
|
if (votePlugin(prefix, player)) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(T2CodeLibMain.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
VotingPluginMain.getPlugin().getVotingPluginUserManager().getVotingPluginUser(player).addPoints(amount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean votePlugin(String prefix, Player player) {
|
||||||
|
if (T2CpluginCheck.votingPlugin()) return true;
|
||||||
|
T2Csend.console(prefix + " §4\n" + prefix + " §4VotingPlugin could not be found! §9Please download it here: " +
|
||||||
|
"§6https://www.spigotmc.org/resources/votingplugin.15358/§4\n" + prefix);
|
||||||
|
player.sendMessage(prefix + "\n" + SelectLibMsg.votingPluginNotSetUp + "\n" + prefix);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.items;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class T2CitemVersion {
|
||||||
|
private static Material Head;
|
||||||
|
private static ItemStack HeadIS;
|
||||||
|
private static ItemStack CRAFTING_TABLE;
|
||||||
|
private static ItemStack YELLOW_WOOL;
|
||||||
|
private static ItemStack ORANGE_WOOL;
|
||||||
|
private static ItemStack GREEN_WOOL;
|
||||||
|
private static ItemStack GRAY_WOOL;
|
||||||
|
private static ItemStack RED_WOOL;
|
||||||
|
private static ItemStack RED_STAINED_GLASS_PANE;
|
||||||
|
|
||||||
|
public void scan() {
|
||||||
|
if (T2CmcVersion.isMc1_8() || T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
|
||||||
|
Head = Material.valueOf("SKULL_ITEM");
|
||||||
|
YELLOW_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 4);
|
||||||
|
ORANGE_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 1);
|
||||||
|
GREEN_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 5);
|
||||||
|
GRAY_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 8);
|
||||||
|
RED_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 14);
|
||||||
|
RED_STAINED_GLASS_PANE = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 14);
|
||||||
|
CRAFTING_TABLE = new ItemStack(Material.valueOf("WORKBENCH"));
|
||||||
|
} else {
|
||||||
|
Head = Material.valueOf("PLAYER_HEAD");
|
||||||
|
CRAFTING_TABLE = new ItemStack(Material.CRAFTING_TABLE);
|
||||||
|
YELLOW_WOOL = new ItemStack(Material.YELLOW_WOOL);
|
||||||
|
ORANGE_WOOL = new ItemStack(Material.ORANGE_WOOL);
|
||||||
|
GREEN_WOOL = new ItemStack(Material.GREEN_WOOL);
|
||||||
|
GRAY_WOOL = new ItemStack(Material.GRAY_WOOL);
|
||||||
|
RED_WOOL = new ItemStack(Material.RED_WOOL);
|
||||||
|
RED_STAINED_GLASS_PANE = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||||
|
}
|
||||||
|
HeadIS = new ItemStack(Head, 1, (byte) 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Material getHead() {
|
||||||
|
return Head;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getHeadIS() {
|
||||||
|
return HeadIS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getCraftingTable() {
|
||||||
|
return CRAFTING_TABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getYellowWool() {
|
||||||
|
return YELLOW_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getOrangeWool() {
|
||||||
|
return ORANGE_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getGreenWool() {
|
||||||
|
return GREEN_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getGrayWool() {
|
||||||
|
return GRAY_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getRedWool() {
|
||||||
|
return RED_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getRedStainedGlassPane() {
|
||||||
|
return RED_STAINED_GLASS_PANE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class T2ChoverModule {
|
||||||
|
|
||||||
|
public static void modulePlayer(String text, String hover, String action, String actionValue, Player player) {
|
||||||
|
modulePlayer((text != null ? text : "null") + "/*/" + (hover != null ? hover : "null") + "/*/" + (action != null ? action : "null")
|
||||||
|
+ "/*/" + (actionValue != null ? actionValue : "null"), player);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void modulePlayer(String msg, Player player) {
|
||||||
|
if (msg.contains("/*/")) {
|
||||||
|
t2cmodule(msg, player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//todo miniMessage(msg,player);
|
||||||
|
}
|
||||||
|
public static void moduleSender(String msg, CommandSender sender) {
|
||||||
|
//todo miniMessage(msg,sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static void t2cmodule(String msg, Player player) {
|
||||||
|
String[] split = msg.split("/\\*/");
|
||||||
|
int i = split.length;
|
||||||
|
String text = null;
|
||||||
|
String hover = null;
|
||||||
|
String action = null;
|
||||||
|
String actionValue = null;
|
||||||
|
if (i > 0) text = split[0];
|
||||||
|
if (i > 1) hover = split[1];
|
||||||
|
if (i > 2) action = split[2];
|
||||||
|
if (i > 3) actionValue = split[3];
|
||||||
|
|
||||||
|
T2CtextBuilder textBuilder = new T2CtextBuilder(text);
|
||||||
|
if (hover != null && !hover.equals("null")) {
|
||||||
|
textBuilder.addHover(hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action != null && actionValue != null && !action.equals("null") && !actionValue.equals("null")) {
|
||||||
|
textBuilder.addClickEvent(ClickEvent.Action.valueOf(action.toUpperCase()), actionValue);
|
||||||
|
}
|
||||||
|
player.spigot().sendMessage(textBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class T2CminiMessage {
|
||||||
|
private static MiniMessage mm = MiniMessage.miniMessage();
|
||||||
|
|
||||||
|
public void sendMiniMessage(String msg, CommandSender sender) {
|
||||||
|
T2CodeLibMain.adventure().sender(sender).sendMessage(replace(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendMiniMessage(String msg) {
|
||||||
|
T2CodeLibMain.adventure().console().sendMessage(replace(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static Component replace(String text){
|
||||||
|
return mm.deserialize(T2Creplace.convertColorCode(text));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,143 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class T2Creplace {
|
||||||
|
|
||||||
|
public static String replace(String prefix, String Text) {
|
||||||
|
|
||||||
|
return replaceLegacyColor(Text).replace("[prefix]", prefix).replace("[ue]", "ü")
|
||||||
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
||||||
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replace(String prefix, Player player, String Text) {
|
||||||
|
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replace(String prefix, List<String> Text) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
for (String input : Text) {
|
||||||
|
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n"));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replace(String prefix, Player player, List<String> Text) {
|
||||||
|
List<String> output = new ArrayList();
|
||||||
|
if (player == null) {
|
||||||
|
return Collections.singletonList("player is null");
|
||||||
|
}
|
||||||
|
if (Text == null) {
|
||||||
|
return Collections.singletonList("Text is null");
|
||||||
|
}
|
||||||
|
for (String input : Text) {
|
||||||
|
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n")));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replacePrice(String prefix, List<String> Text, String price) {
|
||||||
|
List<String> rp = new ArrayList();
|
||||||
|
for (String s : Text) {
|
||||||
|
rp.add(replaceLegacyColor(s).replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n").replace("[price]", String.valueOf(price)));
|
||||||
|
}
|
||||||
|
return rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String removeColorCode(String value) {
|
||||||
|
return value.replace("&0", "").replace("&1", "").replace("&2", "").replace("&3", "")
|
||||||
|
.replace("&4", "").replace("&5", "").replace("&6", "").replace("&7", "")
|
||||||
|
.replace("&8", "").replace("&9", "").replace("&a", "").replace("&b", "")
|
||||||
|
.replace("&c", "").replace("&d", "").replace("&e", "").replace("&f", "")
|
||||||
|
.replace("&k", "").replace("&l", "").replace("&m", "").replace("&n", "")
|
||||||
|
.replace("&o", "").replace("&r", "");
|
||||||
|
// String text = value.replace("&", "§");
|
||||||
|
// while (text.contains("§")) {
|
||||||
|
// int stelle = text.indexOf("§");
|
||||||
|
// if (text.length() >= stelle + 2) {
|
||||||
|
// text = text.substring(0, stelle) + text.substring(stelle + 2);
|
||||||
|
// } else {
|
||||||
|
// text = text.substring(0, stelle) + text.substring(stelle + 1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return (text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replacePrice(String prefix, Player player, List<String> Text, String price) {
|
||||||
|
List<String> rp = new ArrayList();
|
||||||
|
for (String s : Text) {
|
||||||
|
rp.add(replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, s.replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n")
|
||||||
|
.replace("[price]", String.valueOf(price)))));
|
||||||
|
}
|
||||||
|
return rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replacePrice(String prefix, String Text, String price) {
|
||||||
|
return replaceLegacyColor(Text).replace("[prefix]", prefix)
|
||||||
|
.replace("&o", "§o").replace("&r", "§r").replace("[ue]", "ü")
|
||||||
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
||||||
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[price]", String.valueOf(price))
|
||||||
|
.replace("[nl]", "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replacePrice(String prefix, Player player, String Text, String price) {
|
||||||
|
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[price]", String.valueOf(price)).replace("[nl]", "\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceLegacyColor(String text) {
|
||||||
|
return text.replace("&0", "§0").replace("&1", "§1").replace("&2", "§2").replace("&3", "§3")
|
||||||
|
.replace("&4", "§4").replace("&5", "§5").replace("&6", "§6").replace("&7", "§7")
|
||||||
|
.replace("&8", "§8").replace("&9", "§9").replace("&a", "§a").replace("&b", "§b")
|
||||||
|
.replace("&c", "§c").replace("&d", "§d").replace("&e", "§e").replace("&f", "§f")
|
||||||
|
.replace("&k", "§k").replace("&l", "§l").replace("&m", "§m").replace("&n", "§n")
|
||||||
|
.replace("&o", "§o").replace("&r", "§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convertColorCode(String text) {
|
||||||
|
return text.replace("&0", "<black>").replace("§0", "<black>")
|
||||||
|
.replace("&1", "<dark_blue>").replace("§1", "<dark_blue>")
|
||||||
|
.replace("&2", "<dark_green>").replace("§2", "<dark_green>")
|
||||||
|
.replace("&3", "<dark_aqua>").replace("§3", "<dark_aqua>")
|
||||||
|
.replace("&4", "<dark_red>").replace("§4", "<dark_red>")
|
||||||
|
.replace("&5", "<dark_purple>").replace("§5", "<dark_purple>")
|
||||||
|
.replace("&6", "<gold>").replace("§6", "<gold>")
|
||||||
|
.replace("&7", "<gray>").replace("§7", "<gray>")
|
||||||
|
.replace("&8", "<dark_gray>").replace("§8", "<dark_gray>")
|
||||||
|
.replace("&9", "<blue>").replace("§9", "<blue>")
|
||||||
|
.replace("&a", "<green>").replace("§a", "<green>")
|
||||||
|
.replace("&b", "<aqua>").replace("§b", "<aqua>")
|
||||||
|
.replace("&c", "<red>").replace("§c", "<red>")
|
||||||
|
.replace("&d", "<light_purple>").replace("§d", "<light_purple>")
|
||||||
|
.replace("&e", "<yellow>").replace("§e", "<yellow>")
|
||||||
|
.replace("&f", "<white>").replace("§f", "<white>")
|
||||||
|
.replace("&k", "<obfuscated>").replace("§k", "<obfuscated>")
|
||||||
|
.replace("&l", "<bold>").replace("§l", "<bold>")
|
||||||
|
.replace("&m", "<strikethrough>").replace("§m", "<strikethrough>")
|
||||||
|
.replace("&n", "<underlined>").replace("§n", "<underlined>")
|
||||||
|
.replace("&o", "<italic>").replace("§o", "<italic>")
|
||||||
|
.replace("&r", "<reset>").replace("§r", "<reset>");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class T2Csend {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spigot
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void console(String msg) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
Bukkit.getConsoleSender().sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void player(Player player, String msg) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
T2ChoverModule.modulePlayer(msg, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void title(Player player, @Nullable String title, @Nullable String subtitle) {
|
||||||
|
player.sendTitle(title, subtitle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void title(Player player, @Nullable String title, @Nullable String subtitle, int fadeIn, int stay, int fadeOut) {
|
||||||
|
player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sender(CommandSender sender, String msg) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
T2ChoverModule.moduleSender(msg, sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(Plugin plugin, String msg) {
|
||||||
|
debug(plugin, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(Plugin plugin, String msg, Integer stage) {
|
||||||
|
// if (!new File(Main.getPath(), "config.yml").exists()) return;
|
||||||
|
if (stage == null) {
|
||||||
|
if (plugin.getConfig().getBoolean("Plugin.Debug"))
|
||||||
|
Bukkit.getConsoleSender().sendMessage(plugin.getDescription().getPrefix() + " §5DEBUG: §6" + msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plugin.getConfig().getInt("Plugin.Debug") >= stage)
|
||||||
|
Bukkit.getConsoleSender().sendMessage(plugin.getDescription().getPrefix() + " §5DEBUG: §6" + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debugmsg(Plugin plugin, String msg) {
|
||||||
|
warning(plugin,"");
|
||||||
|
Bukkit.getConsoleSender().sendMessage("§e[" + plugin.getDescription().getPrefix() + "] §5DEBUG-MSG: §6" + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.INFO, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class T2Ctemplate {
|
||||||
|
public static Long onLoadHeader(String prefix, List<String> autor, String version, String spigot, String discord) {
|
||||||
|
return onLoadHeader(prefix, autor, version, spigot, discord, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix, List<String> autor, String version, String spigot, String discord, Boolean isPremium) {
|
||||||
|
return onLoadHeader(prefix, autor, version, spigot, discord, isPremium, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix, List<String> autor, String version, String spigot, String discord, Boolean isPremium, Boolean isVerify) {
|
||||||
|
Long long_ = System.currentTimeMillis();
|
||||||
|
// send.console(prefix +" §4===================== " + prefix + " §4=====================");
|
||||||
|
|
||||||
|
|
||||||
|
T2Csend.console("[prefix] <dark_red> _______ </dark_red><gray>___ </gray><dark_red>_____ </dark_red>");
|
||||||
|
T2Csend.console("[prefix] <dark_red> |__ __|</dark_red><gray>__ \\ </gray><dark_red>/ ____|</dark_red>");
|
||||||
|
T2Csend.console("[prefix] <dark_red> | | </dark_red><gray> ) </gray><dark_red>| | </dark_red>");
|
||||||
|
T2Csend.console("[prefix] <dark_red> | | </dark_red><gray> / /</gray><dark_red>| | </dark_red>");
|
||||||
|
T2Csend.console("[prefix] <dark_red> | | </dark_red><gray>/ /_</gray><dark_red>| |____ </dark_red>");
|
||||||
|
T2Csend.console("[prefix] <dark_red> |_| </dark_red><gray>|____|</gray><dark_red>\\_____|</dark_red>");
|
||||||
|
T2Csend.console(prefix + " §4 §e------------------");
|
||||||
|
T2Csend.console(prefix + " §4 §e| §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
|
||||||
|
T2Csend.console(prefix + " §4 §e| §2Version: §6" + version);
|
||||||
|
T2Csend.console(prefix + " §4 §e| §2Spigot: §6" + spigot);
|
||||||
|
T2Csend.console(prefix + " §4 §e| §2Discord: §6" + discord);
|
||||||
|
if (isPremium != null) {
|
||||||
|
if (isPremium) {
|
||||||
|
T2Csend.console(prefix + " §4 §e| §6Premium: §2true");
|
||||||
|
} else T2Csend.console(prefix + " §4 §e| §6Premium: §4false");
|
||||||
|
if (isVerify != null) {
|
||||||
|
if (isVerify) {
|
||||||
|
T2Csend.console(prefix + " §4 §e| §6Verify: §2true");
|
||||||
|
} else T2Csend.console(prefix + " §4 §e| §6Verify: §4false");
|
||||||
|
} else T2Csend.console(prefix + " §4 §e| §6Verify: §4false");
|
||||||
|
}
|
||||||
|
|
||||||
|
T2Csend.console(prefix + " §4 §e-------------------");
|
||||||
|
if (version.toLowerCase().contains("dev") || version.toLowerCase().contains("snapshot") || version.toLowerCase().contains("beta")) {
|
||||||
|
T2Csend.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! Some features may not be working as expected. Please report all" +
|
||||||
|
" bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!");
|
||||||
|
T2Csend.console(prefix + " §4 §e-------------------");
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return long_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix) {
|
||||||
|
Long long_ = System.currentTimeMillis();
|
||||||
|
T2Csend.console(prefix + "§4===================== " + prefix + " §4=====================");
|
||||||
|
return long_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadSeparateStroke(String prefix) {
|
||||||
|
T2Csend.console(prefix + " §8-------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadFooter(String prefix, Long long_, String version) {
|
||||||
|
onLoadSeparateStroke(prefix);
|
||||||
|
T2Csend.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadFooter(String prefix, Long long_) {
|
||||||
|
onLoadSeparateStroke(prefix);
|
||||||
|
T2Csend.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onDisable(String prefix, List<String> autor, String version, String spigot, String discord) {
|
||||||
|
T2Csend.console(prefix + " §2Version: §6" + version);
|
||||||
|
T2Csend.console(prefix + " §4Plugin successfully disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(CommandSender sender, String prefix, int spigotID, String discord, List<String> autor, Boolean isPremium) {
|
||||||
|
//todo
|
||||||
|
//T2Csend.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||||
|
//T2Csend.sender(sender, prefix + " §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
|
||||||
|
//if (sender instanceof Player) {
|
||||||
|
// Player player = (Player) sender;
|
||||||
|
// if (T2CmcVersion.isMc1_8() || T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12() ||
|
||||||
|
// T2CmcVersion.isMc1_13() || T2CmcVersion.isMc1_14() || T2CmcVersion.isMc1_15()) {
|
||||||
|
// T2Csend.sender(sender, prefix + " §2Version: §6" + pluginVersion);
|
||||||
|
// } else {
|
||||||
|
// TextComponent comp2 = new T2CtextBuilder(prefix + " §2Version: §6" + pluginVersion)
|
||||||
|
// .addHover("§8Click to copy").addClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, Replace.removeColorCode(prefix) + " - " + pluginVersion).build();
|
||||||
|
// player.spigot().sendMessage(comp2);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (!publicVersion.equalsIgnoreCase(pluginVersion)) {
|
||||||
|
// UpdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion, (Player) sender);
|
||||||
|
// }
|
||||||
|
// TextComponent comp3 = new TextBuilder(prefix + " §2Spigot: §6" + spigot)
|
||||||
|
// .addHover("§8Open Spigot").addClickEvent(ClickEvent.Action.OPEN_URL, spigot).build();
|
||||||
|
//
|
||||||
|
// player.spigot().sendMessage(comp3);
|
||||||
|
// TextComponent comp4 = new TextBuilder(prefix + " §2Discord: §6" + discord)
|
||||||
|
// .addHover("§8Open Discord").addClickEvent(ClickEvent.Action.OPEN_URL, discord).build();
|
||||||
|
// player.spigot().sendMessage(comp4);
|
||||||
|
//} else {
|
||||||
|
// if (publicVersion.equalsIgnoreCase(pluginVersion)) {
|
||||||
|
// T2Csend.sender(sender, prefix + " §2Version: §6" + pluginVersion);
|
||||||
|
// } else {
|
||||||
|
// UpdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion);
|
||||||
|
// }
|
||||||
|
// T2Csend.sender(sender, prefix + " §2Spigot: §6" + spigot);
|
||||||
|
// T2Csend.sender(sender, prefix + " §2Discord: §6" + discord);
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//if (isPremium != null) {
|
||||||
|
// if (isPremium) {
|
||||||
|
// T2Csend.sender(sender, prefix + " §6Premium: §2true");
|
||||||
|
// } else T2Csend.sender(sender, prefix + " §6Premium: §4false");
|
||||||
|
//}
|
||||||
|
//T2Csend.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(CommandSender sender, String prefix, int spigotID, String discord, List<String> autor) {
|
||||||
|
sendInfo(sender, prefix, spigotID, discord, autor, null);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
public class T2CtextBuilder {
|
||||||
|
|
||||||
|
private final String text;
|
||||||
|
private String hover;
|
||||||
|
private String click;
|
||||||
|
private ClickEvent.Action action;
|
||||||
|
|
||||||
|
public T2CtextBuilder(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T2CtextBuilder addHover(String hover) {
|
||||||
|
this.hover = hover;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T2CtextBuilder addClickEvent(ClickEvent.Action clickEventAction, String value) {
|
||||||
|
this.action = clickEventAction;
|
||||||
|
this.click = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextComponent build() {
|
||||||
|
if (this.text.contains("[empty]")) return null;
|
||||||
|
TextComponent textComponent = new TextComponent();
|
||||||
|
textComponent.setText(this.text);
|
||||||
|
if (this.hover != null) {
|
||||||
|
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(this.hover).create()));
|
||||||
|
}
|
||||||
|
if (this.click != null && (this.action != null)) {
|
||||||
|
textComponent.setClickEvent(new ClickEvent(action, this.click));
|
||||||
|
}
|
||||||
|
return textComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ClickEventType {
|
||||||
|
OPEN_URL, OPEN_FILE, RUN_COMMAND, SUGGEST_COMMAND, CHANGE_PAGE, COPY_TO_CLIPBOARD
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,234 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.minecraftVersion;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class T2CmcVersion {
|
||||||
|
|
||||||
|
public static void onCheck() {
|
||||||
|
mcVersion = Bukkit.getServer().getVersion();
|
||||||
|
bukkitVersion = Bukkit.getServer().getBukkitVersion();
|
||||||
|
nms = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
|
mc1_8 = nms.contains("1_8");
|
||||||
|
mc1_9 = nms.contains("1_9");
|
||||||
|
mc1_10 = nms.contains("1_10");
|
||||||
|
mc1_11 = nms.contains("1_11");
|
||||||
|
mc1_12 = nms.contains("1_12");
|
||||||
|
mc1_13 = nms.contains("1_13");
|
||||||
|
mc1_14 = nms.contains("1_14");
|
||||||
|
mc1_15 = nms.contains("1_15");
|
||||||
|
mc1_16 = nms.contains("1_16");
|
||||||
|
mc1_17 = nms.contains("1_17");
|
||||||
|
mc1_18 = nms.contains("1_18");
|
||||||
|
mc1_19 = nms.contains("1_19");
|
||||||
|
mc1_20 = nms.contains("1_20");
|
||||||
|
|
||||||
|
nms1_8_R1 = nms.contains("1_8_R1");
|
||||||
|
nms1_8_R2 = nms.contains("1_8_R2");
|
||||||
|
nms1_8_R3 = nms.contains("1_8_R3");
|
||||||
|
nms1_9_R1 = nms.contains("1_9_R1");
|
||||||
|
nms1_9_R2 = nms.contains("1_9_R2");
|
||||||
|
nms1_10_R1 = nms.contains("1_10_R1");
|
||||||
|
nms1_11_R1 = nms.contains("1_11_R1");
|
||||||
|
nms1_12_R1 = nms.contains("1_12_R1");
|
||||||
|
nms1_13_R1 = nms.contains("1_13_R1");
|
||||||
|
nms1_13_R2 = nms.contains("1_13_R2");
|
||||||
|
nms1_14_R1 = nms.contains("1_14_R1");
|
||||||
|
nms1_15_R1 = nms.contains("1_15_R1");
|
||||||
|
nms1_16_R1 = nms.contains("1_16_R1");
|
||||||
|
nms1_16_R2 = nms.contains("1_16_R2");
|
||||||
|
nms1_16_R3 = nms.contains("1_16_R3");
|
||||||
|
nms1_17_R1 = nms.contains("1_17_R1");
|
||||||
|
nms1_18_R1 = nms.contains("1_18_R1");
|
||||||
|
nms1_18_R2 = nms.contains("1_18_R2");
|
||||||
|
nms1_19_R1 = nms.contains("1_19_R1");
|
||||||
|
nms1_19_R2 = nms.contains("1_19_R2");
|
||||||
|
nms1_20_R1 = nms.contains("1_20_R1");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String mcVersion;
|
||||||
|
private static String bukkitVersion;
|
||||||
|
private static boolean mc1_8;
|
||||||
|
private static boolean mc1_9;
|
||||||
|
private static boolean mc1_10;
|
||||||
|
private static boolean mc1_11;
|
||||||
|
private static boolean mc1_12;
|
||||||
|
private static boolean mc1_13;
|
||||||
|
private static boolean mc1_14;
|
||||||
|
private static boolean mc1_15;
|
||||||
|
private static boolean mc1_16;
|
||||||
|
private static boolean mc1_17;
|
||||||
|
private static boolean mc1_18;
|
||||||
|
private static boolean mc1_19;
|
||||||
|
private static boolean mc1_20;
|
||||||
|
|
||||||
|
private static String nms;
|
||||||
|
private static boolean nms1_8_R1;
|
||||||
|
private static boolean nms1_8_R2;
|
||||||
|
private static boolean nms1_8_R3;
|
||||||
|
private static boolean nms1_9_R1;
|
||||||
|
private static boolean nms1_9_R2;
|
||||||
|
private static boolean nms1_10_R1;
|
||||||
|
private static boolean nms1_11_R1;
|
||||||
|
private static boolean nms1_12_R1;
|
||||||
|
private static boolean nms1_13_R1;
|
||||||
|
private static boolean nms1_13_R2;
|
||||||
|
private static boolean nms1_14_R1;
|
||||||
|
private static boolean nms1_15_R1;
|
||||||
|
private static boolean nms1_16_R1;
|
||||||
|
private static boolean nms1_16_R2;
|
||||||
|
private static boolean nms1_16_R3;
|
||||||
|
private static boolean nms1_17_R1;
|
||||||
|
private static boolean nms1_18_R1;
|
||||||
|
private static boolean nms1_18_R2;
|
||||||
|
private static boolean nms1_19_R1;
|
||||||
|
private static boolean nms1_19_R2;
|
||||||
|
private static boolean nms1_20_R1;
|
||||||
|
|
||||||
|
public static String getMcVersion() {
|
||||||
|
return mcVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBukkitVersion() {
|
||||||
|
return bukkitVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_8() {
|
||||||
|
return mc1_8;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_9() {
|
||||||
|
return mc1_9;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_10() {
|
||||||
|
return mc1_10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_11() {
|
||||||
|
return mc1_11;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_12() {
|
||||||
|
return mc1_12;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_13() {
|
||||||
|
return mc1_13;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_14() {
|
||||||
|
return mc1_14;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_15() {
|
||||||
|
return mc1_15;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_16() {
|
||||||
|
return mc1_16;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_17() {
|
||||||
|
return mc1_17;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_18() {
|
||||||
|
return mc1_18;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_19() {
|
||||||
|
return mc1_19;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMc1_20() {
|
||||||
|
return mc1_20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getNms() {
|
||||||
|
return nms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_8_R1() {
|
||||||
|
return nms1_8_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_8_R2() {
|
||||||
|
return nms1_8_R2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_8_R3() {
|
||||||
|
return nms1_8_R3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_9_R1() {
|
||||||
|
return nms1_9_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_9_R2() {
|
||||||
|
return nms1_9_R2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_10_R1() {
|
||||||
|
return nms1_10_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_11_R1() {
|
||||||
|
return nms1_11_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_12_R1() {
|
||||||
|
return nms1_12_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_13_R1() {
|
||||||
|
return nms1_13_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_13_R2() {
|
||||||
|
return nms1_13_R2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_14_R1() {
|
||||||
|
return nms1_14_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_15_R1() {
|
||||||
|
return nms1_15_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_16_R1() {
|
||||||
|
return nms1_16_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_16_R2() {
|
||||||
|
return nms1_16_R2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_16_R3() {
|
||||||
|
return nms1_16_R3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_17_R1() {
|
||||||
|
return nms1_17_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_18_R1() {
|
||||||
|
return nms1_18_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_18_R2() {
|
||||||
|
return nms1_18_R2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_19_R1() {
|
||||||
|
return nms1_19_R1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_19_R2() {
|
||||||
|
return nms1_19_R2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNms1_20_R1() {
|
||||||
|
return nms1_20_R1;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,142 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.player;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class T2CnameHistory {
|
||||||
|
public static class NameLookup {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL from Mojang API that provides the JSON String in response.
|
||||||
|
*/
|
||||||
|
private static final String LOOKUP_URL = "https://api.mojang.com/user/profiles/%s/names";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL from Mojang API to resolve the UUID of a player from their name.
|
||||||
|
*/
|
||||||
|
private static final String GET_UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?t=0";
|
||||||
|
private static final Gson JSON_PARSER = new Gson();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread!It blocks while attempting to get a response from Mojang servers!</h1>
|
||||||
|
* @param player The UUID of the player to be looked up.
|
||||||
|
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||||
|
* @throws IOException {@link #getPlayerPreviousNames(String)}
|
||||||
|
*/
|
||||||
|
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(UUID player) throws IOException {
|
||||||
|
return getPlayerPreviousNames(player.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||||
|
* Alternative method accepting an 'OfflinePlayer' (and therefore 'Player') objects as parameter.
|
||||||
|
* @param player The OfflinePlayer object to obtain the UUID from.
|
||||||
|
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||||
|
* @throws IOException {@link #getPlayerPreviousNames(UUID)}
|
||||||
|
*/
|
||||||
|
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(OfflinePlayer player) throws IOException {
|
||||||
|
return getPlayerPreviousNames(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||||
|
* Alternative method accepting an {@link OfflinePlayer} (and therefore {@link Player}) objects as parameter.
|
||||||
|
* @param uuid The UUID String to lookup
|
||||||
|
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(String uuid) throws IOException {
|
||||||
|
if (uuid == null || uuid.isEmpty())
|
||||||
|
return null;
|
||||||
|
String response = getRawJsonResponse(new URL(String.format(LOOKUP_URL, uuid)));
|
||||||
|
PreviousPlayerNameEntry[] names = JSON_PARSER.fromJson(response, PreviousPlayerNameEntry[].class);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you don't have the UUID of a player, this method will resolve it for you.<br>
|
||||||
|
* The output of this method may be used directly with {@link #getPlayerPreviousNames(String)}.<br>
|
||||||
|
* <b>NOTE: as with the rest, this method opens a connection with a remote server, so running it synchronously will block the main thread which will lead to server lag.</b>
|
||||||
|
* @param name The name of the player to lookup.
|
||||||
|
* @return A String which represents the player's UUID. <b>Note: the uuid cannot be parsed to a UUID object directly, as it doesnt contain dashes. This feature will be implemented later</b>
|
||||||
|
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||||
|
*/
|
||||||
|
public static String getPlayerUUID(String name) throws IOException {
|
||||||
|
String response = getRawJsonResponse(new URL(String.format(GET_UUID_URL, name)));
|
||||||
|
JsonObject o = JSON_PARSER.fromJson(response, JsonObject.class);
|
||||||
|
if (o == null)
|
||||||
|
return null;
|
||||||
|
return o.get("id") == null ? null : o.get("id").getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method used to read the response of Mojang's API webservers.
|
||||||
|
* @param u the URL to connect to
|
||||||
|
* @return a String with the data read.
|
||||||
|
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||||
|
*/
|
||||||
|
private static String getRawJsonResponse(URL u) throws IOException {
|
||||||
|
HttpURLConnection con = (HttpURLConnection) u.openConnection();
|
||||||
|
con.setDoInput(true);
|
||||||
|
con.setConnectTimeout(2000);
|
||||||
|
con.setReadTimeout(2000);
|
||||||
|
con.connect();
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
String response = in.readLine();
|
||||||
|
in.close();
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the typical response expected by Mojang servers when requesting the name history of a player.
|
||||||
|
*/
|
||||||
|
public class PreviousPlayerNameEntry {
|
||||||
|
private String name;
|
||||||
|
@SerializedName("changedToAt")
|
||||||
|
private long changeTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player name of this entry.
|
||||||
|
* @return The name of the player.
|
||||||
|
*/
|
||||||
|
public String getPlayerName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time of change of the name.
|
||||||
|
* <br><b>Note: This will return 0 if the name is the original (initial) name of the player! Make sure you check if it is 0 before handling!
|
||||||
|
* <br>Parsing 0 to a Date will result in the date "01/01/1970".</b>
|
||||||
|
* @return a timestamp in miliseconds that you can turn into a date or handle however you want :)
|
||||||
|
*/
|
||||||
|
public long getChangeTime() {
|
||||||
|
return changeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this name is the name used to register the account (the initial/original name)
|
||||||
|
* @return a boolean, true if it is the the very first name of the player, otherwise false.
|
||||||
|
*/
|
||||||
|
public boolean isPlayersInitialName() {
|
||||||
|
return getChangeTime() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Name: " + name + " Date of change: " + new Date(changeTime).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.plugins;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class T2CpluginCheck {
|
||||||
|
public static Boolean pluginCheck(String pluginName){
|
||||||
|
return Bukkit.getPluginManager().getPlugin(pluginName) != null;
|
||||||
|
}
|
||||||
|
public static Plugin pluginInfos(String pluginName){
|
||||||
|
return Bukkit.getPluginManager().getPlugin(pluginName);
|
||||||
|
}
|
||||||
|
public static Boolean papi(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean vault(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("Vault") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plotSquared(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlotSquared") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plugManGUI(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlugManGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean cmi(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("CMI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean votingPlugin(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("VotingPlugin") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* T2Code Plugins
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Boolean cgui(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("CommandGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean functiongui(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-CommandGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plotSquaredGUI(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlotSquaredGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean luckyBox(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-LuckyBox") != null;
|
||||||
|
}
|
||||||
|
public static Boolean autoResponse(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-AutoResponse") != null;
|
||||||
|
}
|
||||||
|
public static Boolean opSec(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("OPSecurity") != null;
|
||||||
|
}
|
||||||
|
public static Boolean papiTest(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PaPiTest") != null;
|
||||||
|
}
|
||||||
|
public static Boolean booster(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("Booster") != null;
|
||||||
|
}
|
||||||
|
public static Boolean antiMapCopy(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("AntiMapCopy") != null;
|
||||||
|
}
|
||||||
|
public static Boolean loreEditor(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("LoreEditor") != null;
|
||||||
|
}
|
||||||
|
public static Boolean t2cAlias(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-Alias") != null;
|
||||||
|
}
|
||||||
|
public static Boolean t2cWarp(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-Warp") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean pluginNotFound(Plugin plugin, String prefix, String pl, Integer spigotID) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(pl) == null) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
|
||||||
|
Bukkit.getConsoleSender().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " +
|
||||||
|
"§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(T2CodeLibMain.getPlugin());
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.plugins;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class T2CpluginManager {
|
||||||
|
|
||||||
|
public static void restart(String plugin) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enable(String plugin) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disable(String plugin) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void restart(Plugin plugin) {
|
||||||
|
if (plugin == null) return;
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(plugin);
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enable(Plugin plugin) {
|
||||||
|
if (plugin == null) return;
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().enablePlugin(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disable(Plugin plugin) {
|
||||||
|
if (plugin == null) return;
|
||||||
|
T2CodeLibMain.getPlugin().getPluginLoader().disablePlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.register;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class T2Cregister {
|
||||||
|
public static void listener(Listener listener, Plugin plugin) {
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, Plugin plugin) {
|
||||||
|
if (plugin.getServer().getPluginManager().getPermission(permission) == null) {
|
||||||
|
plugin.getServer().getPluginManager().addPermission(new Permission(permission));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, PermissionDefault setDefault, Plugin plugin) {
|
||||||
|
permission(permission, plugin);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).setDefault(setDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, String children, Boolean setBoolean, Plugin plugin) {
|
||||||
|
permission(permission, plugin);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).getChildren().put(children, setBoolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, PermissionDefault setDefault, String children, Boolean setBoolean, Plugin plugin) {
|
||||||
|
permission(permission, plugin);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).setDefault(setDefault);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).getChildren().put(children, setBoolean);
|
||||||
|
}
|
||||||
|
public static void permissionDescription(String permission, String description, Plugin plugin) {
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).setDescription(description);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,123 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class T2CupdateAPI {
|
||||||
|
public static HashMap<String, T2CupdateObject> pluginVersions = new HashMap<>();
|
||||||
|
|
||||||
|
public static void join(Plugin plugin, String prefix, String perm, Player player, Integer spigotID, String discord) {
|
||||||
|
if (!SelectLibConfig.getUpdateCheckOnJoin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!player.hasPermission(perm) && !player.isOp()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pluginVersions.get(plugin.getName()) == null) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
join(plugin, prefix, perm, player, spigotID, discord);
|
||||||
|
}
|
||||||
|
}.runTaskLaterAsynchronously(plugin, 20L);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
|
||||||
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
if (pluginVersion.equals(publicVersion)) return;
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendUpdateMsg(prefix, spigotID, discord, plugin, player);
|
||||||
|
}
|
||||||
|
}.runTaskLaterAsynchronously(T2CodeLibMain.getPlugin(), 200L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendUpdateMsg(String prefix, Integer spigotID, String discord, Plugin plugin, Player player) {
|
||||||
|
String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
|
||||||
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
if (publicVersion.equals("§4No public version found!")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String st = "[prefix]<br>" +
|
||||||
|
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <gold>A new</gold> [value]<gold>version was found!</gold></hover></click><br>" +
|
||||||
|
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <red>[plv]</red> <gray>-></gray> <green>[puv]</green></hover></click><br>" +
|
||||||
|
"<click:open_url:'[dc]'><hover:show_text:'<yellow>[dc]</yellow>'>[prefix] <gold>You can find more information on Discord.</gold></hover></click><br>" +
|
||||||
|
"[prefix]";
|
||||||
|
String value = "";
|
||||||
|
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
if (publicVersion.toLowerCase().contains("dev")) {
|
||||||
|
value = "<dark_red>DEV </dark_red>";
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("beta")) {
|
||||||
|
value = "<green>BETA </green>";
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
value = "<yellow>SNAPSHOT </yellow>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
T2Csend.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", "https://www.spigotmc.org/resources/" + spigotID)
|
||||||
|
.replace("[plv]", pluginVersion).replace("[puv]", publicVersion).replace("[dc]", discord));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendUpdateMsg(String prefix, Integer spigot, String discord, Plugin plugin) {
|
||||||
|
String publicVersion = pluginVersions.get(plugin.getName()).publicVersion;
|
||||||
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
T2Csend.console("§4=========== " + prefix + " §4===========");
|
||||||
|
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
if (publicVersion.toLowerCase().contains("dev")) {
|
||||||
|
T2Csend.console("§6A new §4DEV§6 version was found!");
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("beta")) {
|
||||||
|
T2Csend.console("§6A new §2BETA§6 version was found!");
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
T2Csend.console("§6A new §eSNAPSHOT§6 version was found!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
T2Csend.console("§6A new version was found!");
|
||||||
|
}
|
||||||
|
T2Csend.console("§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion);
|
||||||
|
T2Csend.console("§6You can download it here: §ehttps://www.spigotmc.org/resources/" + spigot);
|
||||||
|
T2Csend.console("§6You can find more information on Discord: §e" + discord);
|
||||||
|
T2Csend.console("§4=========== " + prefix + " §4===========");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean load = false;
|
||||||
|
|
||||||
|
public static void onUpdateCheck(Plugin plugin, String prefix, int spigotID, String discord) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
(new T2CupdateChecker((JavaPlugin) plugin, spigotID)).getVersion((update_version) -> {
|
||||||
|
T2CupdateObject update = new T2CupdateObject(
|
||||||
|
plugin.getName(),
|
||||||
|
plugin.getDescription().getVersion(),
|
||||||
|
update_version
|
||||||
|
);
|
||||||
|
pluginVersions.put(plugin.getName(), update);
|
||||||
|
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
|
||||||
|
if (!load) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
load = true;
|
||||||
|
sendUpdateMsg(prefix, spigotID, discord, plugin);
|
||||||
|
}
|
||||||
|
}.runTaskLaterAsynchronously(plugin, 600L);
|
||||||
|
} else sendUpdateMsg(prefix, spigotID, discord, plugin);
|
||||||
|
} else {
|
||||||
|
T2Csend.console(prefix + " §2No update found.");
|
||||||
|
}
|
||||||
|
}, prefix, plugin.getDescription().getVersion());
|
||||||
|
}
|
||||||
|
}.runTaskTimerAsynchronously(plugin, 0L, SelectLibConfig.getUpdateCheckTimeInterval() * 60 * 20L);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class T2CupdateChecker {
|
||||||
|
private JavaPlugin plugin;
|
||||||
|
private int resourceId;
|
||||||
|
|
||||||
|
public T2CupdateChecker(JavaPlugin plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
|
||||||
|
if (!plugin.isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
|
||||||
|
try {
|
||||||
|
Scanner scanner = new Scanner(inputStream);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
consumer.accept(scanner.next());
|
||||||
|
}
|
||||||
|
} catch (Throwable var8) {
|
||||||
|
try {
|
||||||
|
scanner.close();
|
||||||
|
} catch (Throwable var7) {
|
||||||
|
var8.addSuppressed(var7);
|
||||||
|
}
|
||||||
|
throw var8;
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
} catch (Throwable var9) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (Throwable var6) {
|
||||||
|
var9.addSuppressed(var6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw var9;
|
||||||
|
}
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException var10) {
|
||||||
|
T2CupdateObject update = new T2CupdateObject(
|
||||||
|
plugin.getName(),
|
||||||
|
pluginVersion,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
T2CupdateAPI.pluginVersions.put(plugin.getName(), update);
|
||||||
|
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.update;
|
||||||
|
|
||||||
|
public class T2CupdateObject {
|
||||||
|
|
||||||
|
public String pluginName;
|
||||||
|
public String pluginVersion;
|
||||||
|
public String publicVersion;
|
||||||
|
|
||||||
|
public T2CupdateObject(String pluginName,
|
||||||
|
String pluginVersion,
|
||||||
|
String publicVersion ) {
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
this.pluginVersion = pluginVersion;
|
||||||
|
this.publicVersion = publicVersion;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.api.yaml;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class T2Cconfig {
|
||||||
|
public static void set(String path, String value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, YamlConfiguration YamlConfiguration) {
|
||||||
|
YamlConfiguration.set(path, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Double value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, List<String> value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSound(String soundName, String sound1_8, String sound1_9, String sound1_13, YamlConfiguration yamlConfiguration) {
|
||||||
|
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||||
|
String sound;
|
||||||
|
if (T2CmcVersion.isMc1_8()) {
|
||||||
|
sound = sound1_8.toString();
|
||||||
|
} else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
|
||||||
|
sound = sound1_9.toString();
|
||||||
|
} else sound = sound1_13.toString();
|
||||||
|
set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) {
|
||||||
|
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||||
|
String sound;
|
||||||
|
if (T2CmcVersion.isMc1_8()) {
|
||||||
|
sound = sound1_8.toString();
|
||||||
|
} else sound = sound1_13.toString();
|
||||||
|
set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) {
|
||||||
|
set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||||
|
set("Sound." + soundName + ".Sound", sound.toString(), yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean selectSoundEnable(String soundName, YamlConfiguration yamlConfiguration) {
|
||||||
|
return selectBoolean("Sound." + soundName + ".Enable", yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String selectSound(String prefix, String soundName, YamlConfiguration yamlConfiguration) {
|
||||||
|
return select(prefix, "Sound." + soundName + ".Sound", yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sound checkSound(String sound1_8, String sound1_9, String sound1_13, String selectSoundFromConfig, String prefix) {
|
||||||
|
String SOUND;
|
||||||
|
if (T2CmcVersion.isMc1_8()) {
|
||||||
|
SOUND = sound1_8;
|
||||||
|
} else if (T2CmcVersion.isMc1_9() || T2CmcVersion.isMc1_10() || T2CmcVersion.isMc1_11() || T2CmcVersion.isMc1_12()) {
|
||||||
|
SOUND = sound1_9;
|
||||||
|
} else SOUND = sound1_13;
|
||||||
|
|
||||||
|
return checkSound(SOUND, selectSoundFromConfig, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) {
|
||||||
|
String SOUND;
|
||||||
|
if (T2CmcVersion.isMc1_8()) {
|
||||||
|
SOUND = sound1_8;
|
||||||
|
} else SOUND = sound1_13;
|
||||||
|
|
||||||
|
return checkSound(SOUND, selectSoundFromConfig, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sound checkSound(String sound, String selectSoundFromConfig, String prefix) {
|
||||||
|
try {
|
||||||
|
return Sound.valueOf(selectSoundFromConfig);
|
||||||
|
} catch (Exception e) {
|
||||||
|
T2Csend.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", prefix)
|
||||||
|
.replace("[sound]", "§8Buy: §6" + selectSoundFromConfig) + "§4\n§4\n§4\n");
|
||||||
|
return Sound.valueOf(sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String select(String prefix, String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return T2Creplace.replace(prefix, yamlConfiguration.getString(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Integer selectInt(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getInt(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getBoolean(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getDouble(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> selectList(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getStringList(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getItemStack(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<String> selectList(String prefix, String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
List<String> input = yamlConfiguration.getStringList(path);
|
||||||
|
for (String st : input) {
|
||||||
|
output.add(T2Creplace.replace(prefix, st));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void select(String prefix, List<String> value, String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
List<String> input = yamlConfiguration.getStringList(path);
|
||||||
|
for (String st : input) {
|
||||||
|
output.add(T2Creplace.replace(prefix, st));
|
||||||
|
}
|
||||||
|
value = output;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.CreateReportLog;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CmdExecuter implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!sender.hasPermission("t2code.admin")) {
|
||||||
|
T2Csend.sender(sender, "§4No Permission §8t2code.admin");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (args.length == 0) {
|
||||||
|
//todo T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), T2CodeLibMain.getAutor(), T2CodeLibMain.getVersion(), UpdateAPI.PluginVersionen.get(T2CodeMain.getPlugin().getName()).publicVersion);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "info":
|
||||||
|
case "plugin":
|
||||||
|
case "pl":
|
||||||
|
case "version":
|
||||||
|
case "ver":
|
||||||
|
//todo T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), T2CodeLibMain.getAutor(), T2CodeLibMain.getVersion(), UpdateAPI.PluginVersionen.get(T2CodeMain.getPerm().getName()).publicVersion);
|
||||||
|
return false;
|
||||||
|
case "reloadconfig":
|
||||||
|
SelectLibConfig.onSelect();
|
||||||
|
return false;
|
||||||
|
case "debug":
|
||||||
|
if (args.length != 2) {
|
||||||
|
T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ("createreportlog".equals(args[1].toLowerCase())) {
|
||||||
|
CreateReportLog.create(sender);
|
||||||
|
} else T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
||||||
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
T2Csend.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//TabCompleter
|
||||||
|
private static HashMap<String, String> arg1 = new HashMap<String, String>() {{
|
||||||
|
put("debug", "t2code.admin");
|
||||||
|
put("info", "t2code.admin");
|
||||||
|
put("reloadconfig", "t2code.admin");
|
||||||
|
}};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player p = (Player) sender;
|
||||||
|
if (args.length == 1) {
|
||||||
|
for (String command : arg1.keySet()) {
|
||||||
|
if (hasPermission(p, arg1.get(command)) && passend(command, args[0])) {
|
||||||
|
list.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 2 && args[0].equalsIgnoreCase("debug")) {
|
||||||
|
if (sender.hasPermission("t2code.admin")) {
|
||||||
|
if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) {
|
||||||
|
list.add("createReportLog");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean passend(String command, String arg) {
|
||||||
|
for (int i = 0; i < arg.toUpperCase().length(); i++) {
|
||||||
|
if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasPermission(Player player, String permission) {
|
||||||
|
if (player.isOp()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String[] Permissions = permission.split(";");
|
||||||
|
for (String perm : Permissions) {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,186 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system;
|
||||||
|
|
||||||
|
import net.t2code.luckyBox.api.LuckyBoxAPI;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
public class CreateReportLog {
|
||||||
|
protected static void create(CommandSender sender) {
|
||||||
|
T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog is created...");
|
||||||
|
String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime());
|
||||||
|
|
||||||
|
File directory = new File(T2CodeLibMain.getPath() + "/DebugLogs");
|
||||||
|
if (!directory.exists()) {
|
||||||
|
directory.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(T2CodeLibMain.getPath(), "/DebugLogs/T2CodeLog.txt");
|
||||||
|
PrintWriter pWriter = null;
|
||||||
|
try {
|
||||||
|
pWriter = new PrintWriter(new FileWriter(file.getPath()));
|
||||||
|
String timeStamp = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(Calendar.getInstance().getTime());
|
||||||
|
pWriter.println("Created on: " + timeStamp);
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("Server Bukkit version: " + T2CmcVersion.getBukkitVersion());
|
||||||
|
pWriter.println("Server run on: " + T2CmcVersion.getMcVersion());
|
||||||
|
pWriter.println("Server NMS: " + T2CmcVersion.getNms());
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("Online Mode: " + Bukkit.getOnlineMode());
|
||||||
|
pWriter.println("Worlds: " + Bukkit.getWorlds());
|
||||||
|
pWriter.println("OP-Player:");
|
||||||
|
for (OfflinePlayer player : Bukkit.getOperators()) {
|
||||||
|
pWriter.println(" - Player: " + player.getName() + " - " + player.getUniqueId());
|
||||||
|
}
|
||||||
|
pWriter.println();
|
||||||
|
if (Vault.vaultEnable) {
|
||||||
|
pWriter.println("Vault: " + Bukkit.getPluginManager().getPlugin("Vault").getName() + " - " + Bukkit.getPluginManager().getPlugin("Vault")
|
||||||
|
.getDescription().getVersion());
|
||||||
|
} else pWriter.println("Vault: not connected");
|
||||||
|
if (T2CodeLibMain.getEco() != null) {
|
||||||
|
String st = T2CodeLibMain.getEco().getName();
|
||||||
|
if (T2CodeLibMain.getEco().getName().equals("CMIEconomy")) st = "CMI";
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(st) != null) {
|
||||||
|
pWriter.println("Economy: " + T2CodeLibMain.getEco().isEnabled() + " - " + st + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion());
|
||||||
|
} else pWriter.println("Economy: " + T2CodeLibMain.getEco().isEnabled() + " - " + st);
|
||||||
|
} else pWriter.println("Economy: not connected via vault");
|
||||||
|
if (T2CodeLibMain.getPerm() != null) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(T2CodeLibMain.getPerm().getName()) != null) {
|
||||||
|
pWriter.println("Permission: " + T2CodeLibMain.getPerm().isEnabled() + " - " + T2CodeLibMain.getPerm().getName() + " - " + Bukkit.getPluginManager()
|
||||||
|
.getPlugin(T2CodeLibMain.getPerm().getName()).getDescription().getVersion());
|
||||||
|
} else pWriter.println("Permission: " + T2CodeLibMain.getPerm().isEnabled() + " - " + T2CodeLibMain.getPerm().getName());
|
||||||
|
} else pWriter.println("Permission: not connected via vault");
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("Java: " + System.getProperty("java.version"));
|
||||||
|
pWriter.println("System: " + System.getProperty("os.name"));
|
||||||
|
pWriter.println("System: " + System.getProperty("os.version"));
|
||||||
|
pWriter.println("User Home: " + System.getProperty("user.home"));
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("T2CodeLib: " + T2CodeLibMain.getPlugin().getDescription().getVersion());
|
||||||
|
pWriter.println();
|
||||||
|
if (T2CpluginCheck.luckyBox()) {
|
||||||
|
pWriter.println("T2C-PremiumPlugins: ");
|
||||||
|
pWriter.println("T2C-LuckyBox UID: " + LuckyBoxAPI.getUID());
|
||||||
|
pWriter.println("T2C-LuckyBox RID: " + LuckyBoxAPI.getRID());
|
||||||
|
pWriter.println("T2C-LuckyBox DID: " + LuckyBoxAPI.getDID());
|
||||||
|
pWriter.println("T2C-LuckyBox isP: " + LuckyBoxAPI.isP());
|
||||||
|
pWriter.println("T2C-LuckyBox isV: " + LuckyBoxAPI.isV());
|
||||||
|
pWriter.println();
|
||||||
|
}
|
||||||
|
pWriter.println("Plugins: ");
|
||||||
|
for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription()
|
||||||
|
.getAuthors() + " - Website: " + pl.getDescription().getWebsite());
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (pWriter != null) {
|
||||||
|
pWriter.flush();
|
||||||
|
pWriter.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = T2CodeLibMain.getPath() + "/DebugLogs/T2CodeLog.txt";
|
||||||
|
String log = "logs/latest.log";
|
||||||
|
String zipPath = "plugins/T2CodeLib/DebugLogs/T2CLog-" + timeStampFile + ".zip";
|
||||||
|
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath))) {
|
||||||
|
File fileToZip = new File(filePath);
|
||||||
|
zip.putNextEntry(new ZipEntry(fileToZip.getName()));
|
||||||
|
Files.copy(fileToZip.toPath(), zip);
|
||||||
|
|
||||||
|
addFileToZip("", "logs/latest.log", zip, false);
|
||||||
|
|
||||||
|
for (String pl : Util.getT2cPlugins()){
|
||||||
|
pluginToDebug(pl, zip);
|
||||||
|
}
|
||||||
|
zip.closeEntry();
|
||||||
|
zip.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
file.delete();
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
||||||
|
T2Csend.console(Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
||||||
|
} else T2Csend.sender(sender, Util.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void pluginToDebug(String pluginName, ZipOutputStream zip) throws IOException {
|
||||||
|
if (T2CpluginCheck.pluginCheck(pluginName)) {
|
||||||
|
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||||
|
File plConfigs = new File(plugin.getDataFolder().getPath());
|
||||||
|
if (plConfigs.exists()) {
|
||||||
|
addFolderToZip("T2Code-Plugins", plugin.getDataFolder().getPath(), zip);
|
||||||
|
}
|
||||||
|
File f = new File("plugins/");
|
||||||
|
File[] fileArray = f.listFiles();
|
||||||
|
|
||||||
|
for (File config : fileArray) {
|
||||||
|
if (config.getName().contains(pluginName) && config.getName().contains(".jar")) {
|
||||||
|
addFileToZip("T2Code-Plugins", config.getPath(), zip, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
|
||||||
|
File folder = new File(srcFolder);
|
||||||
|
if (folder.list() == null) {
|
||||||
|
addFileToZip(path + "/" + folder.getName(), srcFolder, zip, false);
|
||||||
|
} else if (folder.list().length == 0) {
|
||||||
|
addFileToZip(path, srcFolder, zip, true);
|
||||||
|
} else {
|
||||||
|
for (String fileName : folder.list()) {
|
||||||
|
if (path.equals("")) {
|
||||||
|
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
|
||||||
|
} else {
|
||||||
|
addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException {
|
||||||
|
File folder = new File(srcFile);
|
||||||
|
if (flag) {
|
||||||
|
zip.putNextEntry(new ZipEntry(path + "/" + folder.getName() + "/"));
|
||||||
|
} else {
|
||||||
|
if (folder.isDirectory()) {
|
||||||
|
addFolderToZip(path, srcFile, zip);
|
||||||
|
} else {
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
FileInputStream in = new FileInputStream(srcFile);
|
||||||
|
|
||||||
|
if (path.equals("")) {
|
||||||
|
zip.putNextEntry(new ZipEntry((folder.getName())));
|
||||||
|
} else {
|
||||||
|
zip.putNextEntry(new ZipEntry((path + "/" + folder.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
try {
|
||||||
|
zip.write(buf, 0, len);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
// This claas was created by JaTiTV
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.SPIGOT.system;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
|
||||||
|
public class JoinEvent implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoinEvent(PlayerLoginEvent event) {
|
||||||
|
T2CupdateAPI.join(T2CodeLibMain.getPlugin(), Util.getPrefix(),"t2code.lib.updatemsg",event.getPlayer(),Util.getSpigotID(),Util.getDiscord());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,152 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system;
|
||||||
|
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Ctemplate;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.minecraftVersion.T2CmcVersion;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.update.T2CupdateAPI;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.bstats.Metrics;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.config.ConfigCreate;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.languages.LanguagesCreate;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.languages.SelectLibMsg;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class T2CodeLibMain extends JavaPlugin {
|
||||||
|
private static T2CodeLibMain plugin;
|
||||||
|
private static Economy eco = null;
|
||||||
|
private static Permission perm = null;
|
||||||
|
|
||||||
|
private static List<String> autor;
|
||||||
|
private static String version;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Plugin startup logic
|
||||||
|
plugin = this;
|
||||||
|
autor = plugin.getDescription().getAuthors();
|
||||||
|
version = plugin.getDescription().getVersion();
|
||||||
|
this.adventure = BukkitAudiences.create(this);
|
||||||
|
long long_ = T2Ctemplate.onLoadHeader(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||||
|
String prefix = Util.getPrefix();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Vault.loadVault();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
T2CmcVersion.onCheck();
|
||||||
|
|
||||||
|
if (T2CmcVersion.isMc1_19()) {
|
||||||
|
T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
T2Csend.console(prefix);
|
||||||
|
T2Csend.warning(plugin,"The 1.19.* is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net");
|
||||||
|
T2Csend.console(prefix);
|
||||||
|
T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
T2Csend.console(prefix + " §3Server run on: §6" + T2CmcVersion.getMcVersion() + " / " + T2CmcVersion.getNms());
|
||||||
|
if (eco != null) {
|
||||||
|
String st = eco.getName();
|
||||||
|
if (eco.getName().equals("CMIEconomy")) st = "CMI";
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(st) != null) {
|
||||||
|
T2Csend.console(prefix + " §3Economy: §6" + eco.getName() + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion() + " §7- §e" +
|
||||||
|
(System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else T2Csend.console(prefix + " §3Economy: §6" + eco.getName() + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else T2Csend.console(prefix + " §3Economy: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
|
||||||
|
if (perm != null) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(perm.getName()) != null) {
|
||||||
|
T2Csend.console(prefix + " §3Permission plugin: §6" + perm.getName() + " - " + Bukkit.getPluginManager().getPlugin(perm.getName()).getDescription().getVersion()
|
||||||
|
+ " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else T2Csend.console(prefix + " §3Permission plugin: §6" + perm.getName() + " - §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else T2Csend.console(prefix + " §3Permission plugin: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
|
||||||
|
if (T2CpluginCheck.papi()) {
|
||||||
|
T2Csend.console(prefix + " §3PlaceholderAPI: §6connected" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getCommand("t2code").setExecutor(new CmdExecuter());
|
||||||
|
ConfigCreate.configCreate();
|
||||||
|
LanguagesCreate.langCreate();
|
||||||
|
SelectLibConfig.onSelect();
|
||||||
|
SelectLibMsg.onSelect();
|
||||||
|
|
||||||
|
T2CupdateAPI.onUpdateCheck(plugin, prefix, Util.getSpigotID(), Util.getDiscord());
|
||||||
|
Metrics.Bstats(plugin, Util.getBstatsID());
|
||||||
|
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
|
||||||
|
T2Ctemplate.onLoadFooter(prefix, long_);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
if (SelectLibConfig.getInventoriesCloseByServerStop()) {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(this.adventure != null) {
|
||||||
|
this.adventure.close();
|
||||||
|
this.adventure = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vault.vaultDisable();
|
||||||
|
T2Ctemplate.onDisable(Util.getPrefix(), autor, version, Util.getSpigot(), Util.getDiscord());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getPath() {
|
||||||
|
return plugin.getDataFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setEco(Economy eco) {
|
||||||
|
T2CodeLibMain.eco = eco;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setPerm(Permission perm) {
|
||||||
|
T2CodeLibMain.perm = perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T2CodeLibMain getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Economy getEco() {
|
||||||
|
return eco;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Permission getPerm() {
|
||||||
|
return perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getAutor() {
|
||||||
|
return autor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BukkitAudiences adventure;
|
||||||
|
|
||||||
|
public static BukkitAudiences adventure() {
|
||||||
|
if (adventure == null) {
|
||||||
|
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||||
|
}
|
||||||
|
return adventure;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
public class Vault {
|
||||||
|
|
||||||
|
public static Boolean vaultEnable;
|
||||||
|
public static Boolean connected;
|
||||||
|
|
||||||
|
public static void loadVault() throws InterruptedException {
|
||||||
|
long long_ = System.currentTimeMillis();
|
||||||
|
if (T2CodeLibMain.getPlugin().getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||||
|
vaultEnable = true;
|
||||||
|
RegisteredServiceProvider<Economy> eco = T2CodeLibMain.getPlugin().getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (eco != null) {
|
||||||
|
T2CodeLibMain.setEco(eco.getProvider());
|
||||||
|
if (T2CodeLibMain.getEco() != null) {
|
||||||
|
connected = true;
|
||||||
|
T2Csend.console(Util.getPrefix() + " §2Vault / Economy successfully connected!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else {
|
||||||
|
connected = false;
|
||||||
|
T2Csend.console(Util.getPrefix() + " §4Economy could not be connected / found! [1]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
connected = false;
|
||||||
|
T2Csend.console(Util.getPrefix() + " §4Economy could not be connected / found! [2]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
RegisteredServiceProvider<Permission> perm = T2CodeLibMain.getPlugin().getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
|
if (perm != null) {
|
||||||
|
T2CodeLibMain.setPerm(perm.getProvider());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vaultEnable = false;
|
||||||
|
connected = false;
|
||||||
|
T2Csend.console(Util.getPrefix() + " §4Vault could not be connected! [3]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void vaultDisable() {
|
||||||
|
if (!connected) return;
|
||||||
|
connected = false;
|
||||||
|
T2Csend.console(Util.getPrefix() + " §4Vault / Economy successfully deactivated.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,851 @@
|
|||||||
|
// This claas was created by JaTiTV
|
||||||
|
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.SPIGOT.system.bstats;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
public class Metrics {
|
||||||
|
|
||||||
|
public static void Bstats(Plugin plugin, int bstatsID) {
|
||||||
|
int pluginId = bstatsID; // <-- Replace with the id of your plugin!
|
||||||
|
Metrics metrics = new Metrics((JavaPlugin) plugin, pluginId);
|
||||||
|
metrics.addCustomChart(new SimplePie("updatecheckonjoin", () -> String.valueOf(SelectLibConfig.getUpdateCheckOnJoin())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
private final MetricsBase metricsBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Metrics instance.
|
||||||
|
*
|
||||||
|
* @param plugin Your plugin instance.
|
||||||
|
* @param serviceId The id of the service. It can be found at <a
|
||||||
|
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||||
|
*/
|
||||||
|
public Metrics(JavaPlugin plugin, int serviceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
// Get the config file
|
||||||
|
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||||
|
File configFile = new File(bStatsFolder, "config.yml");
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
if (!config.isSet("serverUuid")) {
|
||||||
|
config.addDefault("enabled", true);
|
||||||
|
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||||
|
config.addDefault("logFailedRequests", false);
|
||||||
|
config.addDefault("logSentData", false);
|
||||||
|
config.addDefault("logResponseStatusText", false);
|
||||||
|
// Inform the server owners about bStats
|
||||||
|
config
|
||||||
|
.options()
|
||||||
|
.header(
|
||||||
|
"bStats (https://bStats.org) collects some basic information for plugin authors, like how\n"
|
||||||
|
+ "many people use their plugin and their total player count. It's recommended to keep bStats\n"
|
||||||
|
+ "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
|
||||||
|
+ "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
|
||||||
|
+ "anonymous.")
|
||||||
|
.copyDefaults(true);
|
||||||
|
try {
|
||||||
|
config.save(configFile);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Load the data
|
||||||
|
boolean enabled = config.getBoolean("enabled", true);
|
||||||
|
String serverUUID = config.getString("serverUuid");
|
||||||
|
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
||||||
|
boolean logSentData = config.getBoolean("logSentData", false);
|
||||||
|
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||||
|
metricsBase =
|
||||||
|
new MetricsBase(
|
||||||
|
"bukkit",
|
||||||
|
serverUUID,
|
||||||
|
serviceId,
|
||||||
|
enabled,
|
||||||
|
this::appendPlatformData,
|
||||||
|
this::appendServiceData,
|
||||||
|
submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||||
|
plugin::isEnabled,
|
||||||
|
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||||
|
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||||
|
logErrors,
|
||||||
|
logSentData,
|
||||||
|
logResponseStatusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom chart.
|
||||||
|
*
|
||||||
|
* @param chart The chart to add.
|
||||||
|
*/
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
metricsBase.addCustomChart(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendPlatformData(JsonObjectBuilder builder) {
|
||||||
|
builder.appendField("playerAmount", getPlayerAmount());
|
||||||
|
builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0);
|
||||||
|
builder.appendField("bukkitVersion", Bukkit.getVersion());
|
||||||
|
builder.appendField("bukkitName", Bukkit.getName());
|
||||||
|
builder.appendField("javaVersion", System.getProperty("java.version"));
|
||||||
|
builder.appendField("osName", System.getProperty("os.name"));
|
||||||
|
builder.appendField("osArch", System.getProperty("os.arch"));
|
||||||
|
builder.appendField("osVersion", System.getProperty("os.version"));
|
||||||
|
builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendServiceData(JsonObjectBuilder builder) {
|
||||||
|
builder.appendField("pluginVersion", plugin.getDescription().getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPlayerAmount() {
|
||||||
|
try {
|
||||||
|
// Around MC 1.8 the return type was changed from an array to a collection,
|
||||||
|
// This fixes java.lang.NoSuchMethodError:
|
||||||
|
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||||
|
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||||
|
return onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||||
|
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||||
|
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Just use the new method if the reflection failed
|
||||||
|
return Bukkit.getOnlinePlayers().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MetricsBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version of the Metrics class.
|
||||||
|
*/
|
||||||
|
public static final String METRICS_VERSION = "2.2.1";
|
||||||
|
|
||||||
|
private static final ScheduledExecutorService scheduler =
|
||||||
|
Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
|
||||||
|
|
||||||
|
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
||||||
|
|
||||||
|
private final String platform;
|
||||||
|
|
||||||
|
private final String serverUuid;
|
||||||
|
|
||||||
|
private final int serviceId;
|
||||||
|
|
||||||
|
private final Consumer<JsonObjectBuilder> appendPlatformDataConsumer;
|
||||||
|
|
||||||
|
private final Consumer<JsonObjectBuilder> appendServiceDataConsumer;
|
||||||
|
|
||||||
|
private final Consumer<Runnable> submitTaskConsumer;
|
||||||
|
|
||||||
|
private final Supplier<Boolean> checkServiceEnabledSupplier;
|
||||||
|
|
||||||
|
private final BiConsumer<String, Throwable> errorLogger;
|
||||||
|
|
||||||
|
private final Consumer<String> infoLogger;
|
||||||
|
|
||||||
|
private final boolean logErrors;
|
||||||
|
|
||||||
|
private final boolean logSentData;
|
||||||
|
|
||||||
|
private final boolean logResponseStatusText;
|
||||||
|
|
||||||
|
private final Set<CustomChart> customCharts = new HashSet<>();
|
||||||
|
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new MetricsBase class instance.
|
||||||
|
*
|
||||||
|
* @param platform The platform of the service.
|
||||||
|
* @param serviceId The id of the service.
|
||||||
|
* @param serverUuid The server uuid.
|
||||||
|
* @param enabled Whether or not data sending is enabled.
|
||||||
|
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||||
|
* appends all platform-specific data.
|
||||||
|
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||||
|
* appends all service-specific data.
|
||||||
|
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
|
||||||
|
* used to delegate the data collection to a another thread to prevent errors caused by
|
||||||
|
* concurrency. Can be {@code null}.
|
||||||
|
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
|
||||||
|
* @param errorLogger A consumer that accepts log message and an error.
|
||||||
|
* @param infoLogger A consumer that accepts info log messages.
|
||||||
|
* @param logErrors Whether or not errors should be logged.
|
||||||
|
* @param logSentData Whether or not the sent data should be logged.
|
||||||
|
* @param logResponseStatusText Whether or not the response status text should be logged.
|
||||||
|
*/
|
||||||
|
public MetricsBase(
|
||||||
|
String platform,
|
||||||
|
String serverUuid,
|
||||||
|
int serviceId,
|
||||||
|
boolean enabled,
|
||||||
|
Consumer<JsonObjectBuilder> appendPlatformDataConsumer,
|
||||||
|
Consumer<JsonObjectBuilder> appendServiceDataConsumer,
|
||||||
|
Consumer<Runnable> submitTaskConsumer,
|
||||||
|
Supplier<Boolean> checkServiceEnabledSupplier,
|
||||||
|
BiConsumer<String, Throwable> errorLogger,
|
||||||
|
Consumer<String> infoLogger,
|
||||||
|
boolean logErrors,
|
||||||
|
boolean logSentData,
|
||||||
|
boolean logResponseStatusText) {
|
||||||
|
this.platform = platform;
|
||||||
|
this.serverUuid = serverUuid;
|
||||||
|
this.serviceId = serviceId;
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.appendPlatformDataConsumer = appendPlatformDataConsumer;
|
||||||
|
this.appendServiceDataConsumer = appendServiceDataConsumer;
|
||||||
|
this.submitTaskConsumer = submitTaskConsumer;
|
||||||
|
this.checkServiceEnabledSupplier = checkServiceEnabledSupplier;
|
||||||
|
this.errorLogger = errorLogger;
|
||||||
|
this.infoLogger = infoLogger;
|
||||||
|
this.logErrors = logErrors;
|
||||||
|
this.logSentData = logSentData;
|
||||||
|
this.logResponseStatusText = logResponseStatusText;
|
||||||
|
checkRelocation();
|
||||||
|
if (enabled) {
|
||||||
|
startSubmitting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
this.customCharts.add(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startSubmitting() {
|
||||||
|
final Runnable submitTask =
|
||||||
|
() -> {
|
||||||
|
if (!enabled || !checkServiceEnabledSupplier.get()) {
|
||||||
|
// Submitting data or service is disabled
|
||||||
|
scheduler.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (submitTaskConsumer != null) {
|
||||||
|
submitTaskConsumer.accept(this::submitData);
|
||||||
|
} else {
|
||||||
|
this.submitData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution
|
||||||
|
// of requests on the
|
||||||
|
// bStats backend. To circumvent this problem, we introduce some randomness into the initial
|
||||||
|
// and second delay.
|
||||||
|
// WARNING: You must not modify and part of this Metrics class, including the submit delay or
|
||||||
|
// frequency!
|
||||||
|
// WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it!
|
||||||
|
long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
|
||||||
|
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
|
||||||
|
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
|
||||||
|
scheduler.scheduleAtFixedRate(
|
||||||
|
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void submitData() {
|
||||||
|
final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder();
|
||||||
|
appendPlatformDataConsumer.accept(baseJsonBuilder);
|
||||||
|
final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder();
|
||||||
|
appendServiceDataConsumer.accept(serviceJsonBuilder);
|
||||||
|
JsonObjectBuilder.JsonObject[] chartData =
|
||||||
|
customCharts.stream()
|
||||||
|
.map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toArray(JsonObjectBuilder.JsonObject[]::new);
|
||||||
|
serviceJsonBuilder.appendField("id", serviceId);
|
||||||
|
serviceJsonBuilder.appendField("customCharts", chartData);
|
||||||
|
baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
|
||||||
|
baseJsonBuilder.appendField("serverUUID", serverUuid);
|
||||||
|
baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);
|
||||||
|
JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();
|
||||||
|
scheduler.execute(
|
||||||
|
() -> {
|
||||||
|
try {
|
||||||
|
// Send the data
|
||||||
|
sendData(data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Something went wrong! :(
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Could not submit bStats metrics data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
|
||||||
|
if (logSentData) {
|
||||||
|
infoLogger.accept("Sent bStats metrics data: " + data.toString());
|
||||||
|
}
|
||||||
|
String url = String.format(REPORT_URL, platform);
|
||||||
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||||
|
// Compress the data to save bandwidth
|
||||||
|
byte[] compressedData = compress(data.toString());
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
|
connection.addRequestProperty("Connection", "close");
|
||||||
|
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||||
|
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setRequestProperty("User-Agent", "Metrics-Service/1");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||||
|
outputStream.write(compressedData);
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
try (BufferedReader bufferedReader =
|
||||||
|
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
builder.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (logResponseStatusText) {
|
||||||
|
infoLogger.accept("Sent data to bStats and received response: " + builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the class was properly relocated.
|
||||||
|
*/
|
||||||
|
private void checkRelocation() {
|
||||||
|
// You can use the property to disable the check in your test environment
|
||||||
|
if (System.getProperty("bstats.relocatecheck") == null
|
||||||
|
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||||
|
// Maven's Relocate is clever and changes strings, too. So we have to use this little
|
||||||
|
// "trick" ... :D
|
||||||
|
final String defaultPackage =
|
||||||
|
new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||||
|
final String examplePackage =
|
||||||
|
new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||||
|
// We want to make sure no one just copy & pastes the example and uses the wrong package
|
||||||
|
// names
|
||||||
|
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)
|
||||||
|
|| MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
|
||||||
|
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gzips the given string.
|
||||||
|
*
|
||||||
|
* @param str The string to gzip.
|
||||||
|
* @return The gzipped string.
|
||||||
|
*/
|
||||||
|
private static byte[] compress(final String str) throws IOException {
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||||
|
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AdvancedBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, int[]>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, int[]> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue().length == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SimpleBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()});
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MultiLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AdvancedPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class CustomChart {
|
||||||
|
|
||||||
|
private final String chartId;
|
||||||
|
|
||||||
|
protected CustomChart(String chartId) {
|
||||||
|
if (chartId == null) {
|
||||||
|
throw new IllegalArgumentException("chartId must not be null");
|
||||||
|
}
|
||||||
|
this.chartId = chartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
||||||
|
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
||||||
|
JsonObjectBuilder builder = new JsonObjectBuilder();
|
||||||
|
builder.appendField("chartId", chartId);
|
||||||
|
try {
|
||||||
|
JsonObjectBuilder.JsonObject data = getChartData();
|
||||||
|
if (data == null) {
|
||||||
|
// If the data is null we don't send the chart.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
builder.appendField("data", data);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SingleLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Integer> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
int value = callable.call();
|
||||||
|
if (value == 0) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("value", value).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SimplePie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<String> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimplePie(String chartId, Callable<String> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
String value = callable.call();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("value", value).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DrilldownPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Map<String, Integer>> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean reallyAllSkipped = true;
|
||||||
|
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||||
|
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||||
|
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
||||||
|
allSkipped = false;
|
||||||
|
}
|
||||||
|
if (!allSkipped) {
|
||||||
|
reallyAllSkipped = false;
|
||||||
|
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reallyAllSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extremely simple JSON builder.
|
||||||
|
*
|
||||||
|
* <p>While this class is neither feature-rich nor the most performant one, it's sufficient enough
|
||||||
|
* for its use-case.
|
||||||
|
*/
|
||||||
|
public static class JsonObjectBuilder {
|
||||||
|
|
||||||
|
private StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
private boolean hasAtLeastOneField = false;
|
||||||
|
|
||||||
|
public JsonObjectBuilder() {
|
||||||
|
builder.append("{");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a null field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendNull(String key) {
|
||||||
|
appendFieldUnescaped(key, "null");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param value The value of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, String value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new IllegalArgumentException("JSON value must not be null");
|
||||||
|
}
|
||||||
|
appendFieldUnescaped(key, "\"" + escape(value) + "\"");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an integer field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param value The value of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, int value) {
|
||||||
|
appendFieldUnescaped(key, String.valueOf(value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an object to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param object The object.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, JsonObject object) {
|
||||||
|
if (object == null) {
|
||||||
|
throw new IllegalArgumentException("JSON object must not be null");
|
||||||
|
}
|
||||||
|
appendFieldUnescaped(key, object.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The string array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, String[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values)
|
||||||
|
.map(value -> "\"" + escape(value) + "\"")
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an integer array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The integer array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, int[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an object array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The integer array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, JsonObject[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a field to the object.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param escapedValue The escaped value of the field.
|
||||||
|
*/
|
||||||
|
private void appendFieldUnescaped(String key, String escapedValue) {
|
||||||
|
if (builder == null) {
|
||||||
|
throw new IllegalStateException("JSON has already been built");
|
||||||
|
}
|
||||||
|
if (key == null) {
|
||||||
|
throw new IllegalArgumentException("JSON key must not be null");
|
||||||
|
}
|
||||||
|
if (hasAtLeastOneField) {
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
|
||||||
|
hasAtLeastOneField = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the JSON string and invalidates this builder.
|
||||||
|
*
|
||||||
|
* @return The built JSON string.
|
||||||
|
*/
|
||||||
|
public JsonObject build() {
|
||||||
|
if (builder == null) {
|
||||||
|
throw new IllegalStateException("JSON has already been built");
|
||||||
|
}
|
||||||
|
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||||
|
builder = null;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||||
|
*
|
||||||
|
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||||
|
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||||
|
*
|
||||||
|
* @param value The value to escape.
|
||||||
|
* @return The escaped value.
|
||||||
|
*/
|
||||||
|
private static String escape(String value) {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < value.length(); i++) {
|
||||||
|
char c = value.charAt(i);
|
||||||
|
if (c == '"') {
|
||||||
|
builder.append("\\\"");
|
||||||
|
} else if (c == '\\') {
|
||||||
|
builder.append("\\\\");
|
||||||
|
} else if (c <= '\u000F') {
|
||||||
|
builder.append("\\u000").append(Integer.toHexString(c));
|
||||||
|
} else if (c <= '\u001F') {
|
||||||
|
builder.append("\\u00").append(Integer.toHexString(c));
|
||||||
|
} else {
|
||||||
|
builder.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A super simple representation of a JSON object.
|
||||||
|
*
|
||||||
|
* <p>This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
|
||||||
|
* allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
|
||||||
|
* JsonObject)}.
|
||||||
|
*/
|
||||||
|
public static class JsonObject {
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
private JsonObject(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system.config.config;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class ConfigCreate {
|
||||||
|
|
||||||
|
public static void configCreate() {
|
||||||
|
long long_ = System.currentTimeMillis();
|
||||||
|
if (new File(T2CodeLibMain.getPath(), "config.yml").exists()){
|
||||||
|
if (T2CodeLibMain.getPlugin().getConfig().getBoolean("Plugin.Debug")) T2Csend.console(Util.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
|
||||||
|
} else T2Csend.console(Util.getPrefix() + " §4config.yml are created...");
|
||||||
|
|
||||||
|
|
||||||
|
File config = new File(T2CodeLibMain.getPath(), "config.yml");
|
||||||
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||||
|
|
||||||
|
T2Cconfig.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration);
|
||||||
|
T2Cconfig.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration);
|
||||||
|
T2Cconfig.set("Plugin.language", "english", yamlConfiguration);
|
||||||
|
|
||||||
|
T2Cconfig.set("BungeeCord.Enable", false, yamlConfiguration);
|
||||||
|
T2Cconfig.set("BungeeCord.ThisServer", "server", yamlConfiguration);
|
||||||
|
T2Cconfig.set("Player.Inventories.CloseByServerStop", true, yamlConfiguration);
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfiguration.save(config);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
T2Csend.console(Util.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system.config.config;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class SelectLibConfig {
|
||||||
|
|
||||||
|
private static Boolean UpdateCheckOnJoin;
|
||||||
|
private static Boolean t2cTestDevelopment;
|
||||||
|
private static Integer UpdateCheckTimeInterval;
|
||||||
|
private static Boolean Debug;
|
||||||
|
private static String language;
|
||||||
|
private static Boolean InventoriesCloseByServerStop;
|
||||||
|
|
||||||
|
public static void onSelect() {
|
||||||
|
File config = new File(T2CodeLibMain.getPath(), "config.yml");
|
||||||
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||||
|
|
||||||
|
UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin");
|
||||||
|
t2cTestDevelopment = yamlConfiguration.getBoolean("t2cTestDevelopment");
|
||||||
|
UpdateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval");
|
||||||
|
Debug = yamlConfiguration.getBoolean("Plugin.Debug");
|
||||||
|
language = yamlConfiguration.getString("Plugin.language");
|
||||||
|
InventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getUpdateCheckOnJoin() {
|
||||||
|
return UpdateCheckOnJoin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getT2cTestDevelopment() {
|
||||||
|
return t2cTestDevelopment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getUpdateCheckTimeInterval() {
|
||||||
|
return UpdateCheckTimeInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getDebug() {
|
||||||
|
return Debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getInventoriesCloseByServerStop() {
|
||||||
|
return InventoriesCloseByServerStop;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system.config.languages;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.yaml.T2Cconfig;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class LanguagesCreate {
|
||||||
|
static Plugin plugin = T2CodeLibMain.getPlugin();
|
||||||
|
|
||||||
|
public static void langCreate() {
|
||||||
|
T2Csend.debug(plugin, "§4Language files are created / updated...");
|
||||||
|
long long_ = System.currentTimeMillis();
|
||||||
|
|
||||||
|
|
||||||
|
setFile("english", MSG.EN_VaultNotSetUp, MSG.EN_VotingPluginNotSetUp, MSG.EN_SoundNotFound);
|
||||||
|
|
||||||
|
setFile("german", MSG.DE_VaultNotSetUp, MSG.DE_VotingPluginNotSetUp, MSG.DE_SoundNotFound);
|
||||||
|
|
||||||
|
setFile("norwegian", MSG.NO_VaultNotSetUp, MSG.NO_VotingPluginNotSetUp, MSG.NO_SoundNotFound);
|
||||||
|
|
||||||
|
T2Csend.console(Util.getPrefix() + " §2Language files were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setFile(String language, String vaultNotSetUp, String votingPluginNotSetUp, String soundNotFound) {
|
||||||
|
File messages = new File(T2CodeLibMain.getPath(), "languages/" + language + ".yml");
|
||||||
|
YamlConfiguration yamlConfigurationNO = YamlConfiguration.loadConfiguration(messages);
|
||||||
|
|
||||||
|
T2Cconfig.set("Plugin.VaultNotSetUp", vaultNotSetUp, yamlConfigurationNO);
|
||||||
|
T2Cconfig.set("Plugin.VotingPluginNotSetUp", votingPluginNotSetUp, yamlConfigurationNO);
|
||||||
|
T2Cconfig.set("Plugin.SoundNotFound", soundNotFound, yamlConfigurationNO);
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfigurationNO.save(messages);
|
||||||
|
} catch (IOException e) {
|
||||||
|
T2Csend.warning(plugin, e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
// This claas was created by JaTiTV
|
||||||
|
|
||||||
|
package net.t2code.t2codelib.SPIGOT.system.config.languages;
|
||||||
|
|
||||||
|
public class MSG {
|
||||||
|
|
||||||
|
// EN
|
||||||
|
public static String EN_VaultNotSetUp = "[prefix] &4Vault / Economy not set up!";
|
||||||
|
public static String EN_VotingPluginNotSetUp = "[prefix] &4VotingPlugin is not present on the server!";
|
||||||
|
public static String EN_SoundNotFound = "[prefix] &4The sound &6[sound] &4was not found! Please check the settings.";
|
||||||
|
|
||||||
|
|
||||||
|
// DE
|
||||||
|
public static String DE_VaultNotSetUp = "[prefix] &4Vault / Economy nicht eingerichtet!";
|
||||||
|
public static String DE_VotingPluginNotSetUp = "[prefix] &4VotingPlugin ist auf dem Server nicht vorhanden!";
|
||||||
|
public static String DE_SoundNotFound = "[prefix] &4Der Sound &6[sound] &4wurde nicht gefunden! Bitte [ue]berpr[ue]fe die Einstellungen.";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// NO
|
||||||
|
public static String NO_VaultNotSetUp = "[prefix] &4Vault / Økonomi har ikke blitt satt opp!";
|
||||||
|
public static String NO_VotingPluginNotSetUp = "[prefix] &4VotingPlugin er ikke til stede på serveren!";
|
||||||
|
public static String NO_SoundNotFound = "[prefix] &4Lyden &6[sound] &4ble ikke bli funnet! Vennligst sjekk innstillingene.";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package net.t2code.t2codelib.SPIGOT.system.config.languages;
|
||||||
|
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Creplace;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.messages.T2Csend;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.system.config.config.SelectLibConfig;
|
||||||
|
import net.t2code.t2codelib.Util;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class SelectLibMsg {
|
||||||
|
private static Plugin plugin = T2CodeLibMain.getPlugin();
|
||||||
|
|
||||||
|
public static String selectMSG;
|
||||||
|
|
||||||
|
public static String vaultNotSetUp;
|
||||||
|
public static String votingPluginNotSetUp;
|
||||||
|
public static String soundNotFound;
|
||||||
|
|
||||||
|
public static void onSelect() {
|
||||||
|
String prefix = Util.getPrefix();
|
||||||
|
|
||||||
|
T2Csend.debug(plugin, "§4Select language...");
|
||||||
|
long long_ = System.currentTimeMillis();
|
||||||
|
|
||||||
|
File msg;
|
||||||
|
|
||||||
|
msg = new File(T2CodeLibMain.getPath(), "languages/" + SelectLibConfig.getLanguage() + "_messages.yml");
|
||||||
|
if (!msg.isFile()) {
|
||||||
|
T2Csend.console(prefix);
|
||||||
|
T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
T2Csend.console(prefix + " §4The selected §c" + SelectLibConfig.getLanguage() + " §4language file was not found.");
|
||||||
|
T2Csend.console(prefix + " §6The default language §eEnglish §6is used!");
|
||||||
|
T2Csend.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
T2Csend.console(prefix);
|
||||||
|
msg = new File(T2CodeLibMain.getPath(), "languages/" + "english_messages.yml");
|
||||||
|
selectMSG = "english";
|
||||||
|
} else selectMSG = SelectLibConfig.getLanguage();
|
||||||
|
YamlConfiguration yamlConfiguration_msg = YamlConfiguration.loadConfiguration(msg);
|
||||||
|
|
||||||
|
vaultNotSetUp = T2Creplace.replace(prefix, yamlConfiguration_msg.getString("Plugin.VaultNotSetUp"));
|
||||||
|
votingPluginNotSetUp = T2Creplace.replace(prefix, yamlConfiguration_msg.getString("Plugin.VotingPluginNotSetUp"));
|
||||||
|
soundNotFound = T2Creplace.replace(prefix, yamlConfiguration_msg.getString("Plugin.SoundNotFound"));
|
||||||
|
|
||||||
|
T2Csend.console(prefix + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
}
|
44
T2CodeLibNew/src/main/java/net/t2code/t2codelib/Util.java
Normal file
44
T2CodeLibNew/src/main/java/net/t2code/t2codelib/Util.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package net.t2code.t2codelib;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
|
||||||
|
public static String getPrefix() {
|
||||||
|
return "§8[§4T2Code§5Lib§8]";
|
||||||
|
}
|
||||||
|
public static Integer getSpigotID() {
|
||||||
|
return 96388;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getBstatsID() {
|
||||||
|
return 12518;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSpigot() {
|
||||||
|
return "https://www.spigotmc.org/resources/" + getSpigotID();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDiscord() {
|
||||||
|
return "http://dc.t2code.net";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getT2cPlugins(){
|
||||||
|
return Arrays.asList(
|
||||||
|
"T2C-LuckyBox",
|
||||||
|
"WonderBagShop",
|
||||||
|
"CommandGUI",
|
||||||
|
"OPSecurity",
|
||||||
|
"PaPiTest",
|
||||||
|
"PlotSquaredGUI",
|
||||||
|
"T2C-Alias",
|
||||||
|
"T2C-AutoResponse",
|
||||||
|
"LoreEditor",
|
||||||
|
"Booster",
|
||||||
|
"AntiMapCopy",
|
||||||
|
"AntiCopy"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
31
T2CodeLibNew/src/main/resources/plugin.yml
Normal file
31
T2CodeLibNew/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
name: T2CodeLib
|
||||||
|
version: '${project.version}'
|
||||||
|
main: net.t2code.t2codelib.SPIGOT.system.T2CodeLibMain
|
||||||
|
api-version: 1.13
|
||||||
|
prefix: T2CodeLib
|
||||||
|
authors: [ JaTiTV, Jkobs ]
|
||||||
|
description: Library from T2Code Plugins
|
||||||
|
website: T2Code.net
|
||||||
|
load: STARTUP
|
||||||
|
|
||||||
|
softdepend:
|
||||||
|
- VotingPlugin
|
||||||
|
- PlaceholderAPI
|
||||||
|
- PlotSquared
|
||||||
|
- CMI
|
||||||
|
- CMILib
|
||||||
|
- Vault
|
||||||
|
- Economy
|
||||||
|
- XConomy
|
||||||
|
|
||||||
|
loadbefore:
|
||||||
|
- T2C-Alias
|
||||||
|
- T2C-CommandGUI
|
||||||
|
|
||||||
|
commands:
|
||||||
|
t2code:
|
||||||
|
aliases: t2c
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
t2code.admin:
|
||||||
|
default: op
|
114
T2CodeLibOld/.gitignore
vendored
Normal file
114
T2CodeLibOld/.gitignore
vendored
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
target\
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
144
T2CodeLibOld/pom.xml
Normal file
144
T2CodeLibOld/pom.xml
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<version>12.7</version>
|
||||||
|
<!-- <classifier>dev-1</classifier> -->
|
||||||
|
|
||||||
|
<groupId>net.t2code</groupId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<artifactId>T2CodeLib</artifactId>
|
||||||
|
|
||||||
|
<name>T2CodeLib</name>
|
||||||
|
|
||||||
|
<description>Library from T2Code Plugins</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>T2Code.net</url>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<!-- Mojang / Spigot -->
|
||||||
|
<repository>
|
||||||
|
<id>spigot-repo</id>
|
||||||
|
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- repo.t2code / T2Code -->
|
||||||
|
<repository>
|
||||||
|
<id>Builders-Paradise</id>
|
||||||
|
<url>https://repo.t2code.net/repository/Builders-Paradise/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>T2Code</id>
|
||||||
|
<url>https://repo.t2code.net/repository/T2Code/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- Vault-->
|
||||||
|
<repository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</repository>
|
||||||
|
<!-- placeholderapi -->
|
||||||
|
<repository>
|
||||||
|
<id>placeholderapi</id>
|
||||||
|
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||||
|
</repository>
|
||||||
|
<!-- votingplugin -->
|
||||||
|
<repository>
|
||||||
|
<id>BenCodez Repo</id>
|
||||||
|
<url>https://nexus.bencodez.com/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- Mojang / Spigot-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spigotmc</groupId>
|
||||||
|
<artifactId>spigot-api</artifactId>
|
||||||
|
<version>1.19-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- repo.t2code / T2Code -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.t2code</groupId>
|
||||||
|
<artifactId>bungee</artifactId>
|
||||||
|
<version>1642</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.t2code</groupId>
|
||||||
|
<artifactId>LuckyBox-API</artifactId>
|
||||||
|
<version>4.2.7</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Vault-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- placeholderapi -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>me.clip</groupId>
|
||||||
|
<artifactId>placeholderapi</artifactId>
|
||||||
|
<version>2.11.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- votingplugin -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.bencodez</groupId>
|
||||||
|
<artifactId>votingplugin</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<!--Kyori MiniMessage-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.11.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<version>4.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
46
T2CodeLibOld/src/main/java/net/t2code/lib/Bungee/BMain.java
Normal file
46
T2CodeLibOld/src/main/java/net/t2code/lib/Bungee/BMain.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package net.t2code.lib.Bungee;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.t2code.lib.Bungee.Lib.messages.Bsend;
|
||||||
|
import net.t2code.lib.Bungee.system.BLoad;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
|
||||||
|
public final class BMain extends Plugin {
|
||||||
|
|
||||||
|
|
||||||
|
public static Plugin plugin;
|
||||||
|
public static String Version;
|
||||||
|
private static String orgVersion;
|
||||||
|
public static String Autor;
|
||||||
|
|
||||||
|
public static String Prefix = Util.getPrefix();
|
||||||
|
public static Integer SpigotID = Util.getSpigotID();
|
||||||
|
public static Integer BstatsID = Util.getBstatsID();
|
||||||
|
public static String Spigot = Util.getSpigot();
|
||||||
|
public static String Discord = Util.getDiscord();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Plugin startup logic
|
||||||
|
plugin = this;
|
||||||
|
orgVersion = plugin.getDescription().getVersion();
|
||||||
|
Autor = plugin.getDescription().getAuthor();
|
||||||
|
BLoad.onLoad(plugin, Prefix, Autor, orgVersion, Spigot, Discord, SpigotID,BstatsID);
|
||||||
|
String[] fv=orgVersion.split("_");
|
||||||
|
plugin.getDescription().setVersion(fv[0]);
|
||||||
|
Version = plugin.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
Bsend.console(Prefix + "§4============================= " + Prefix + " §4=============================");
|
||||||
|
Bsend.console(Prefix + " §2Autor: §6" + String.valueOf(Autor).replace("[", "").replace("]", ""));
|
||||||
|
Bsend.console(Prefix + " §2Version: §6" + Version);
|
||||||
|
Bsend.console(Prefix + " §2Spigot: §6" + Spigot);
|
||||||
|
Bsend.console(Prefix + " §2Discord: §6" + Discord);
|
||||||
|
Bsend.console(Prefix + " §4Plugin successfully disabled.");
|
||||||
|
Bsend.console(Prefix + "§4============================= " + Prefix + " §4=============================");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.commands;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BTab {
|
||||||
|
public static Iterable<String> tab(CommandSender sender, String[] args, String perm,Boolean onlinePlayer){
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
Iterator var6 = ProxyServer.getInstance().getPlayers().iterator();
|
||||||
|
while (var6.hasNext()) {
|
||||||
|
ProxiedPlayer player1 = (ProxiedPlayer) var6.next();
|
||||||
|
if (passend(player1.getName(), args[0]) && hasPermission(sender, perm)){
|
||||||
|
matches.add(player1.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<String> tab(CommandSender sender, String[] args, HashMap<String, String> permMap) {
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
for (String command : permMap.keySet()) {
|
||||||
|
if (hasPermission(sender, permMap.get(command)) && passend(command, args[0])) {
|
||||||
|
matches.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Iterable<String> tab(CommandSender sender, String[] args, String perm, String command) {
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
if (hasPermission(sender, perm) && passend(command, args[0])) {
|
||||||
|
matches.add(command);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean passend(String command, String arg) {
|
||||||
|
for (int i = 0; i < arg.toUpperCase().length(); i++) {
|
||||||
|
if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean hasPermission(CommandSender sender, String permission) {
|
||||||
|
String[] Permissions = permission.split(";");
|
||||||
|
for (String perm : Permissions) {
|
||||||
|
if (sender.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.commands;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
public class Bcmd {
|
||||||
|
public static void Console(String cmd){
|
||||||
|
ProxyServer.getInstance().getPluginManager().dispatchCommand(ProxyServer.getInstance().getConsole(), cmd);
|
||||||
|
}
|
||||||
|
public static void Player(ProxiedPlayer player, String cmd){
|
||||||
|
ProxyServer.getInstance().getPluginManager().dispatchCommand(player, cmd);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.messages;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.t2code.lib.Bungee.Lib.update.BUpdateAPI;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BT2CodeTemplate {
|
||||||
|
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix, String autor, String version, String spigot, String discord) {
|
||||||
|
Long long_ = Long.valueOf(System.currentTimeMillis());
|
||||||
|
Bsend.console(prefix + "§4============================= " + prefix + " §4=============================");
|
||||||
|
Bsend.console(prefix + " §2Autor: §6" + autor.replace("[", "").replace("]", ""));
|
||||||
|
Bsend.console(prefix + " §2Version: §6" + version);
|
||||||
|
Bsend.console(prefix + " §2Spigot: §6" + spigot);
|
||||||
|
Bsend.console(prefix + " §2Discord: §6" + discord);
|
||||||
|
Bsend.console(prefix + " §8-------------------------------");
|
||||||
|
return long_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadSeparateStroke(String prefix) {
|
||||||
|
Bsend.console(prefix + " §8-------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadFooter(String prefix, Long long_) {
|
||||||
|
Bsend.console(prefix + " §8-------------------------------");
|
||||||
|
Bsend.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
|
||||||
|
Bsend.console(prefix + "§4============================= " + prefix + " §4=============================");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onDisable(String prefix, String autor, String version, String spigot, String discord) {
|
||||||
|
Bsend.console(prefix + "§4============================= " + prefix + " §4=============================");
|
||||||
|
Bsend.console(prefix + " §2Autor: §6" + autor.replace("[", "").replace("]", ""));
|
||||||
|
Bsend.console(prefix + " §2Version: §6" + version);
|
||||||
|
Bsend.console(prefix + " §2Spigot: §6" + spigot);
|
||||||
|
Bsend.console(prefix + " §2Discord: §6" + discord);
|
||||||
|
Bsend.console(prefix + " §4Plugin successfully disabled.");
|
||||||
|
Bsend.console(prefix + "§4============================= " + prefix + " §4=============================");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(CommandSender sender, String prefix, String spigot, String discord, String autor, String pluginVersion, String publicVersion) {
|
||||||
|
Bsend.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||||
|
Bsend.sender(sender, prefix + " §2Autor: §6" + autor);
|
||||||
|
if (publicVersion.equalsIgnoreCase(pluginVersion)) {
|
||||||
|
Bsend.sender(sender, prefix + " §2Version: §6" + pluginVersion);
|
||||||
|
} else {
|
||||||
|
BUpdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion, sender);
|
||||||
|
}
|
||||||
|
Bsend.sender(sender, prefix + " §2Spigot: §6" + spigot);
|
||||||
|
Bsend.sender(sender, prefix + " §2Discord: §6" + discord);
|
||||||
|
Bsend.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.messages;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.Title;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class Bsend {
|
||||||
|
public static void console(String msg) {
|
||||||
|
ProxyServer.getInstance().getConsole().sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void player(ProxiedPlayer player, String msg) {
|
||||||
|
player.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void title(ProxiedPlayer player, Title msg) {
|
||||||
|
player.sendTitle(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sender(CommandSender sender, String msg) {
|
||||||
|
sender.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(Plugin plugin, String msg) {
|
||||||
|
debug(plugin, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug(Plugin plugin, String msg, Integer stage) {
|
||||||
|
// if (!new File(Main.getPath(), "config.yml").exists()) return;
|
||||||
|
if (stage == null) {
|
||||||
|
//todo if (plugin.getConfig().getBoolean("Plugin.Debug")){
|
||||||
|
// ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg);
|
||||||
|
// }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// todo if (plugin.getConfig().getInt("Plugin.Debug") >= stage) {
|
||||||
|
// ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG: §6" + msg);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debugmsg(Plugin plugin, String msg) {
|
||||||
|
ProxyServer.getInstance().getConsole().sendMessage(plugin.getDescription().getName() + " §5DEBUG-MSG: §6" + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info(Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.INFO, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error(Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.plugins;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.t2code.lib.Bungee.BMain;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class BPluginCheck {
|
||||||
|
public static Boolean pluginCheck(String pluginName){
|
||||||
|
return (ProxyServer.getInstance().getPluginManager().getPlugin(pluginName) != null);
|
||||||
|
}
|
||||||
|
public static Plugin pluginInfos(String pluginName){
|
||||||
|
return (ProxyServer.getInstance().getPluginManager().getPlugin(pluginName));
|
||||||
|
}
|
||||||
|
public static Boolean papi(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean vault(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("Vault") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plotSquared(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("PlotSquared") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plugManGUI(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("PlugManGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean cmi(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("CMI") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* T2Code Plugins
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Boolean cgui(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("CommandGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plotSquaredGUI(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("PlotSquaredGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean luckyBox(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("T2C-LuckyBox") != null;
|
||||||
|
}
|
||||||
|
public static Boolean opSec(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("OPSecurity") != null;
|
||||||
|
}
|
||||||
|
public static Boolean papiTest(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("PaPiTest") != null;
|
||||||
|
}
|
||||||
|
public static Boolean booster(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("Booster") != null;
|
||||||
|
}
|
||||||
|
public static Boolean antiMapCopy(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("AAntiMapCopy") != null;
|
||||||
|
}
|
||||||
|
public static Boolean loreEditor(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("LoreEditor") != null;
|
||||||
|
}
|
||||||
|
public static Boolean t2cAlias(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("T2C-Alias") != null;
|
||||||
|
}
|
||||||
|
public static Boolean t2cWarp(){
|
||||||
|
return ProxyServer.getInstance().getPluginManager().getPlugin("T2C-Warp") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean pluginNotFound(Plugin plugin, String prefix, String pl, Integer spigotID) {
|
||||||
|
if (ProxyServer.getInstance().getPluginManager().getPlugin(pl) == null) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
|
||||||
|
ProxyServer.getInstance().getConsole().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " +
|
||||||
|
"§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
|
||||||
|
BMain.plugin.getProxy().getPluginManager().getPlugin(plugin.getDescription().getName()).onDisable();
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.replace;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BReplace {
|
||||||
|
|
||||||
|
public static String replace(String prefix, String Text) {
|
||||||
|
return Text.replace("[prefix]", prefix).replace("&", "§").replace("[ue]", "ü")
|
||||||
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
||||||
|
.replace("[ae]", "ä").replace("[AE]", "Ä");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static List<String> replace(String prefix, List<String> Text) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
for (String input : Text) {
|
||||||
|
output.add(input.replace("[prefix]", prefix).replace("&", "§")
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä"));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List replacePrice(String prefix,List<String> Text, String price) {
|
||||||
|
List rp = new ArrayList();
|
||||||
|
for (String s : Text) {
|
||||||
|
rp.add(s.replace("[prefix]", prefix).replace("&", "§")
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[price]", String.valueOf(price)));
|
||||||
|
}
|
||||||
|
return rp;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.update;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.t2code.lib.Bungee.Lib.messages.Bsend;
|
||||||
|
import net.t2code.lib.Spigot.Lib.update.UpdateObject;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class BUpdateAPI {
|
||||||
|
public static HashMap<String, UpdateObject> bungeePluginVersionen = new HashMap<String, UpdateObject>();
|
||||||
|
|
||||||
|
public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version) {
|
||||||
|
Bsend.console("§4=========== " + Prefix + " §4===========");
|
||||||
|
Bsend.console("§6A new version was found!");
|
||||||
|
Bsend.console("§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version);
|
||||||
|
Bsend.console("§6You can download it here: §e" + Spigot);
|
||||||
|
Bsend.console("§6You can find more information on Discord: §e" + Discord);
|
||||||
|
Bsend.console("§4=========== " + Prefix + " §4===========");
|
||||||
|
}
|
||||||
|
public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String foundVersion, String update_version, CommandSender sender) {
|
||||||
|
Bsend.sender(sender,"§4=========== " + Prefix + " §4===========");
|
||||||
|
Bsend.sender(sender,"§6A new version was found!");
|
||||||
|
Bsend.sender(sender,"§6Your version: §c" + foundVersion + " §7- §6Current version: §a" + update_version);
|
||||||
|
Bsend.sender(sender,"§6You can download it here: §e" + Spigot);
|
||||||
|
Bsend.sender(sender,"§6You can find more information on Discord: §e" + Discord);
|
||||||
|
Bsend.sender(sender,"§4=========== " + Prefix + " §4===========");
|
||||||
|
}
|
||||||
|
private static Boolean noUpdate = true;
|
||||||
|
private static String pluginVersion;
|
||||||
|
public static void onUpdateCheckTimer(Plugin plugin, String Prefix, String Spigot, String Discord, Integer SpigotID) {
|
||||||
|
ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
(new BUpdateAPI(plugin, SpigotID)).getVersion((update_version) -> {
|
||||||
|
pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
UpdateObject update = new UpdateObject(
|
||||||
|
plugin.getDescription().getName(),
|
||||||
|
pluginVersion,
|
||||||
|
update_version
|
||||||
|
);
|
||||||
|
bungeePluginVersionen.put(plugin.getDescription().getName(), update);
|
||||||
|
if (!pluginVersion.replace("_Bungee", "").equalsIgnoreCase(update_version)) {
|
||||||
|
sendUpdateMsg(Prefix, Spigot, Discord, pluginVersion, update_version);
|
||||||
|
noUpdate = true;
|
||||||
|
} else {
|
||||||
|
if (noUpdate) {
|
||||||
|
Bsend.console(Prefix + " §2No update found.");
|
||||||
|
noUpdate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},Prefix, pluginVersion);
|
||||||
|
}
|
||||||
|
}, 0, 20 * 60 * 60L, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
private Plugin plugin;
|
||||||
|
private int resourceId;
|
||||||
|
|
||||||
|
public BUpdateAPI(Plugin plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
|
||||||
|
ProxyServer.getInstance().getScheduler().runAsync(this.plugin, () -> {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
|
||||||
|
try {
|
||||||
|
Scanner scanner = new Scanner(inputStream);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
consumer.accept(scanner.next());
|
||||||
|
}
|
||||||
|
} catch (Throwable var8) {
|
||||||
|
try {
|
||||||
|
scanner.close();
|
||||||
|
} catch (Throwable var7) {
|
||||||
|
var8.addSuppressed(var7);
|
||||||
|
}
|
||||||
|
throw var8;
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
} catch (Throwable var9) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (Throwable var6) {
|
||||||
|
var9.addSuppressed(var6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw var9;
|
||||||
|
}
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException var10) {
|
||||||
|
UpdateObject update = new UpdateObject(
|
||||||
|
plugin.getDescription().getName(),
|
||||||
|
pluginVersion,
|
||||||
|
"§4No public version found!"
|
||||||
|
);
|
||||||
|
bungeePluginVersionen.put(plugin.getDescription().getName(), update);
|
||||||
|
this.plugin.getLogger().severe(Prefix + "§4 Cannot look for updates: " + var10.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.update;
|
||||||
|
|
||||||
|
public class BUpdateObject {
|
||||||
|
public String pluginName;
|
||||||
|
public String pluginVersion;
|
||||||
|
public String publicVersion;
|
||||||
|
public BUpdateObject(String pluginName, String pluginVersion, String publicVersion){
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
this.pluginVersion = pluginVersion;
|
||||||
|
this.publicVersion = publicVersion;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package net.t2code.lib.Bungee.Lib.yamlConfiguration;
|
||||||
|
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BConfig {
|
||||||
|
public static void set(String path, String value, Configuration configuration) {
|
||||||
|
if (!configuration.contains(path)) {
|
||||||
|
configuration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Configuration configuration) {
|
||||||
|
configuration.set(path, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Integer value, Configuration configuration) {
|
||||||
|
if (!configuration.contains(path)) {
|
||||||
|
configuration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Double value, Configuration configuration) {
|
||||||
|
if (!configuration.contains(path)) {
|
||||||
|
configuration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Boolean value, Configuration configuration) {
|
||||||
|
if (!configuration.contains(path)) {
|
||||||
|
configuration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, List<String> value, Configuration configuration) {
|
||||||
|
if (!configuration.contains(path)) {
|
||||||
|
configuration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String select(String prefix, String path, Configuration configuration) {
|
||||||
|
return Replace.replace(prefix, configuration.getString(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Integer selectInt(String path, Configuration configuration) {
|
||||||
|
return (configuration.getInt(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean selectBoolean(String path, Configuration configuration) {
|
||||||
|
return (configuration.getBoolean(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double selectDouble(String path, Configuration configuration) {
|
||||||
|
return (configuration.getDouble(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> selectList(String path, Configuration configuration) {
|
||||||
|
return (configuration.getStringList(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static List<String> selectList(String prefix, String path, Configuration configuration) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
List<String> input = configuration.getStringList(path);
|
||||||
|
for (String st : input) {
|
||||||
|
output.add(Replace.replace(prefix, st));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void select(String prefix, List<String> value, String path, Configuration configuration) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
List<String> input = configuration.getStringList(path);
|
||||||
|
for (String st : input) {
|
||||||
|
output.add(Replace.replace(prefix, st));
|
||||||
|
}
|
||||||
|
value = output;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package net.t2code.lib.Bungee.system;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.t2code.lib.Bungee.Lib.messages.Bsend;
|
||||||
|
import net.t2code.lib.Bungee.Lib.update.BUpdateAPI;
|
||||||
|
|
||||||
|
public class BLoad {
|
||||||
|
public static void onLoad(Plugin plugin, String prefix, String autor, String version, String spigot, String discord, Integer spigotID,Integer bstatsID){
|
||||||
|
Long long_ = Long.valueOf(System.currentTimeMillis());
|
||||||
|
Bsend.console(prefix + "§4============================= " + prefix + " §4=============================");
|
||||||
|
Bsend.console(prefix + " §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
|
||||||
|
Bsend.console(prefix + " §2Version: §6" + version);
|
||||||
|
Bsend.console(prefix + " §2Spigot: §6" + spigot);
|
||||||
|
Bsend.console(prefix + " §2Discord: §6" + discord);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BMetrics.Bstats(plugin, bstatsID);
|
||||||
|
|
||||||
|
BUpdateAPI.onUpdateCheckTimer(plugin, prefix, spigot, discord, spigotID);
|
||||||
|
|
||||||
|
Bsend.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
|
||||||
|
Bsend.console(prefix + "§4============================= " + prefix + " §4=============================");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,851 @@
|
|||||||
|
package net.t2code.lib.Bungee.system;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import net.md_5.bungee.config.Configuration;
|
||||||
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
public class BMetrics {
|
||||||
|
|
||||||
|
public static void Bstats(Plugin plugin, int bstatsID) {
|
||||||
|
int pluginId = bstatsID; // <-- Replace with the id of your plugin!
|
||||||
|
BMetrics metrics = new BMetrics(plugin, pluginId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
private final MetricsBase metricsBase;
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
|
||||||
|
private String serverUUID;
|
||||||
|
|
||||||
|
private boolean logErrors = false;
|
||||||
|
|
||||||
|
private boolean logSentData;
|
||||||
|
|
||||||
|
private boolean logResponseStatusText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Metrics instance.
|
||||||
|
*
|
||||||
|
* @param plugin Your plugin instance.
|
||||||
|
* @param serviceId The id of the service. It can be found at <a
|
||||||
|
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||||
|
*/
|
||||||
|
public BMetrics(Plugin plugin, int serviceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
try {
|
||||||
|
loadConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Failed to load configuration
|
||||||
|
plugin.getLogger().log(Level.WARNING, "Failed to load bStats config!", e);
|
||||||
|
metricsBase = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
metricsBase =
|
||||||
|
new MetricsBase(
|
||||||
|
"bungeecord",
|
||||||
|
serverUUID,
|
||||||
|
serviceId,
|
||||||
|
enabled,
|
||||||
|
this::appendPlatformData,
|
||||||
|
this::appendServiceData,
|
||||||
|
null,
|
||||||
|
() -> true,
|
||||||
|
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||||
|
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||||
|
logErrors,
|
||||||
|
logSentData,
|
||||||
|
logResponseStatusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Loads the bStats configuration. */
|
||||||
|
private void loadConfig() throws IOException {
|
||||||
|
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||||
|
bStatsFolder.mkdirs();
|
||||||
|
File configFile = new File(bStatsFolder, "config.yml");
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
writeFile(
|
||||||
|
configFile,
|
||||||
|
"# bStats (https://bStats.org) collects some basic information for plugin authors, like how",
|
||||||
|
"# many people use their plugin and their total player count. It's recommended to keep bStats",
|
||||||
|
"# enabled, but if you're not comfortable with this, you can turn this setting off. There is no",
|
||||||
|
"# performance penalty associated with having metrics enabled, and data sent to bStats is fully",
|
||||||
|
"# anonymous.",
|
||||||
|
"enabled: true",
|
||||||
|
"serverUuid: \"" + UUID.randomUUID() + "\"",
|
||||||
|
"logFailedRequests: false",
|
||||||
|
"logSentData: false",
|
||||||
|
"logResponseStatusText: false");
|
||||||
|
}
|
||||||
|
Configuration configuration =
|
||||||
|
ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||||
|
// Load configuration
|
||||||
|
enabled = configuration.getBoolean("enabled", true);
|
||||||
|
serverUUID = configuration.getString("serverUuid");
|
||||||
|
logErrors = configuration.getBoolean("logFailedRequests", false);
|
||||||
|
logSentData = configuration.getBoolean("logSentData", false);
|
||||||
|
logResponseStatusText = configuration.getBoolean("logResponseStatusText", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeFile(File file, String... lines) throws IOException {
|
||||||
|
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) {
|
||||||
|
for (String line : lines) {
|
||||||
|
bufferedWriter.write(line);
|
||||||
|
bufferedWriter.newLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom chart.
|
||||||
|
*
|
||||||
|
* @param chart The chart to add.
|
||||||
|
*/
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
metricsBase.addCustomChart(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendPlatformData(JsonObjectBuilder builder) {
|
||||||
|
builder.appendField("playerAmount", plugin.getProxy().getOnlineCount());
|
||||||
|
builder.appendField("managedServers", plugin.getProxy().getServers().size());
|
||||||
|
builder.appendField("onlineMode", plugin.getProxy().getConfig().isOnlineMode() ? 1 : 0);
|
||||||
|
builder.appendField("bungeecordVersion", plugin.getProxy().getVersion());
|
||||||
|
builder.appendField("javaVersion", System.getProperty("java.version"));
|
||||||
|
builder.appendField("osName", System.getProperty("os.name"));
|
||||||
|
builder.appendField("osArch", System.getProperty("os.arch"));
|
||||||
|
builder.appendField("osVersion", System.getProperty("os.version"));
|
||||||
|
builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendServiceData(JsonObjectBuilder builder) {
|
||||||
|
builder.appendField("pluginVersion", plugin.getDescription().getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MetricsBase {
|
||||||
|
|
||||||
|
/** The version of the Metrics class. */
|
||||||
|
public static final String METRICS_VERSION = "2.2.1";
|
||||||
|
|
||||||
|
private static final ScheduledExecutorService scheduler =
|
||||||
|
Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
|
||||||
|
|
||||||
|
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
||||||
|
|
||||||
|
private final String platform;
|
||||||
|
|
||||||
|
private final String serverUuid;
|
||||||
|
|
||||||
|
private final int serviceId;
|
||||||
|
|
||||||
|
private final Consumer<JsonObjectBuilder> appendPlatformDataConsumer;
|
||||||
|
|
||||||
|
private final Consumer<JsonObjectBuilder> appendServiceDataConsumer;
|
||||||
|
|
||||||
|
private final Consumer<Runnable> submitTaskConsumer;
|
||||||
|
|
||||||
|
private final Supplier<Boolean> checkServiceEnabledSupplier;
|
||||||
|
|
||||||
|
private final BiConsumer<String, Throwable> errorLogger;
|
||||||
|
|
||||||
|
private final Consumer<String> infoLogger;
|
||||||
|
|
||||||
|
private final boolean logErrors;
|
||||||
|
|
||||||
|
private final boolean logSentData;
|
||||||
|
|
||||||
|
private final boolean logResponseStatusText;
|
||||||
|
|
||||||
|
private final Set<CustomChart> customCharts = new HashSet<>();
|
||||||
|
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new MetricsBase class instance.
|
||||||
|
*
|
||||||
|
* @param platform The platform of the service.
|
||||||
|
* @param serviceId The id of the service.
|
||||||
|
* @param serverUuid The server uuid.
|
||||||
|
* @param enabled Whether or not data sending is enabled.
|
||||||
|
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||||
|
* appends all platform-specific data.
|
||||||
|
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||||
|
* appends all service-specific data.
|
||||||
|
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
|
||||||
|
* used to delegate the data collection to a another thread to prevent errors caused by
|
||||||
|
* concurrency. Can be {@code null}.
|
||||||
|
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
|
||||||
|
* @param errorLogger A consumer that accepts log message and an error.
|
||||||
|
* @param infoLogger A consumer that accepts info log messages.
|
||||||
|
* @param logErrors Whether or not errors should be logged.
|
||||||
|
* @param logSentData Whether or not the sent data should be logged.
|
||||||
|
* @param logResponseStatusText Whether or not the response status text should be logged.
|
||||||
|
*/
|
||||||
|
public MetricsBase(
|
||||||
|
String platform,
|
||||||
|
String serverUuid,
|
||||||
|
int serviceId,
|
||||||
|
boolean enabled,
|
||||||
|
Consumer<JsonObjectBuilder> appendPlatformDataConsumer,
|
||||||
|
Consumer<JsonObjectBuilder> appendServiceDataConsumer,
|
||||||
|
Consumer<Runnable> submitTaskConsumer,
|
||||||
|
Supplier<Boolean> checkServiceEnabledSupplier,
|
||||||
|
BiConsumer<String, Throwable> errorLogger,
|
||||||
|
Consumer<String> infoLogger,
|
||||||
|
boolean logErrors,
|
||||||
|
boolean logSentData,
|
||||||
|
boolean logResponseStatusText) {
|
||||||
|
this.platform = platform;
|
||||||
|
this.serverUuid = serverUuid;
|
||||||
|
this.serviceId = serviceId;
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.appendPlatformDataConsumer = appendPlatformDataConsumer;
|
||||||
|
this.appendServiceDataConsumer = appendServiceDataConsumer;
|
||||||
|
this.submitTaskConsumer = submitTaskConsumer;
|
||||||
|
this.checkServiceEnabledSupplier = checkServiceEnabledSupplier;
|
||||||
|
this.errorLogger = errorLogger;
|
||||||
|
this.infoLogger = infoLogger;
|
||||||
|
this.logErrors = logErrors;
|
||||||
|
this.logSentData = logSentData;
|
||||||
|
this.logResponseStatusText = logResponseStatusText;
|
||||||
|
checkRelocation();
|
||||||
|
if (enabled) {
|
||||||
|
startSubmitting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
this.customCharts.add(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startSubmitting() {
|
||||||
|
final Runnable submitTask =
|
||||||
|
() -> {
|
||||||
|
if (!enabled || !checkServiceEnabledSupplier.get()) {
|
||||||
|
// Submitting data or service is disabled
|
||||||
|
scheduler.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (submitTaskConsumer != null) {
|
||||||
|
submitTaskConsumer.accept(this::submitData);
|
||||||
|
} else {
|
||||||
|
this.submitData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution
|
||||||
|
// of requests on the
|
||||||
|
// bStats backend. To circumvent this problem, we introduce some randomness into the initial
|
||||||
|
// and second delay.
|
||||||
|
// WARNING: You must not modify and part of this Metrics class, including the submit delay or
|
||||||
|
// frequency!
|
||||||
|
// WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it!
|
||||||
|
long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
|
||||||
|
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
|
||||||
|
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
|
||||||
|
scheduler.scheduleAtFixedRate(
|
||||||
|
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void submitData() {
|
||||||
|
final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder();
|
||||||
|
appendPlatformDataConsumer.accept(baseJsonBuilder);
|
||||||
|
final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder();
|
||||||
|
appendServiceDataConsumer.accept(serviceJsonBuilder);
|
||||||
|
JsonObjectBuilder.JsonObject[] chartData =
|
||||||
|
customCharts.stream()
|
||||||
|
.map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toArray(JsonObjectBuilder.JsonObject[]::new);
|
||||||
|
serviceJsonBuilder.appendField("id", serviceId);
|
||||||
|
serviceJsonBuilder.appendField("customCharts", chartData);
|
||||||
|
baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
|
||||||
|
baseJsonBuilder.appendField("serverUUID", serverUuid);
|
||||||
|
baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);
|
||||||
|
JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();
|
||||||
|
scheduler.execute(
|
||||||
|
() -> {
|
||||||
|
try {
|
||||||
|
// Send the data
|
||||||
|
sendData(data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Something went wrong! :(
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Could not submit bStats metrics data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
|
||||||
|
if (logSentData) {
|
||||||
|
infoLogger.accept("Sent bStats metrics data: " + data.toString());
|
||||||
|
}
|
||||||
|
String url = String.format(REPORT_URL, platform);
|
||||||
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||||
|
// Compress the data to save bandwidth
|
||||||
|
byte[] compressedData = compress(data.toString());
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
|
connection.addRequestProperty("Connection", "close");
|
||||||
|
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||||
|
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setRequestProperty("User-Agent", "Metrics-Service/1");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||||
|
outputStream.write(compressedData);
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
try (BufferedReader bufferedReader =
|
||||||
|
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
builder.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (logResponseStatusText) {
|
||||||
|
infoLogger.accept("Sent data to bStats and received response: " + builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Checks that the class was properly relocated. */
|
||||||
|
private void checkRelocation() {
|
||||||
|
// You can use the property to disable the check in your test environment
|
||||||
|
if (System.getProperty("bstats.relocatecheck") == null
|
||||||
|
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||||
|
// Maven's Relocate is clever and changes strings, too. So we have to use this little
|
||||||
|
// "trick" ... :D
|
||||||
|
final String defaultPackage =
|
||||||
|
new String(new byte[] {'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||||
|
final String examplePackage =
|
||||||
|
new String(new byte[] {'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||||
|
// We want to make sure no one just copy & pastes the example and uses the wrong package
|
||||||
|
// names
|
||||||
|
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)
|
||||||
|
|| MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
|
||||||
|
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gzips the given string.
|
||||||
|
*
|
||||||
|
* @param str The string to gzip.
|
||||||
|
* @return The gzipped string.
|
||||||
|
*/
|
||||||
|
private static byte[] compress(final String str) throws IOException {
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||||
|
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AdvancedBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, int[]>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, int[]> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue().length == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SimpleBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
valuesBuilder.appendField(entry.getKey(), new int[] {entry.getValue()});
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MultiLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AdvancedPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class CustomChart {
|
||||||
|
|
||||||
|
private final String chartId;
|
||||||
|
|
||||||
|
protected CustomChart(String chartId) {
|
||||||
|
if (chartId == null) {
|
||||||
|
throw new IllegalArgumentException("chartId must not be null");
|
||||||
|
}
|
||||||
|
this.chartId = chartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
||||||
|
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
||||||
|
JsonObjectBuilder builder = new JsonObjectBuilder();
|
||||||
|
builder.appendField("chartId", chartId);
|
||||||
|
try {
|
||||||
|
JsonObjectBuilder.JsonObject data = getChartData();
|
||||||
|
if (data == null) {
|
||||||
|
// If the data is null we don't send the chart.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
builder.appendField("data", data);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SingleLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Integer> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
int value = callable.call();
|
||||||
|
if (value == 0) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("value", value).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SimplePie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<String> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimplePie(String chartId, Callable<String> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
String value = callable.call();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("value", value).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DrilldownPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Map<String, Integer>> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean reallyAllSkipped = true;
|
||||||
|
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||||
|
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||||
|
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
||||||
|
allSkipped = false;
|
||||||
|
}
|
||||||
|
if (!allSkipped) {
|
||||||
|
reallyAllSkipped = false;
|
||||||
|
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reallyAllSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extremely simple JSON builder.
|
||||||
|
*
|
||||||
|
* <p>While this class is neither feature-rich nor the most performant one, it's sufficient enough
|
||||||
|
* for its use-case.
|
||||||
|
*/
|
||||||
|
public static class JsonObjectBuilder {
|
||||||
|
|
||||||
|
private StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
private boolean hasAtLeastOneField = false;
|
||||||
|
|
||||||
|
public JsonObjectBuilder() {
|
||||||
|
builder.append("{");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a null field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendNull(String key) {
|
||||||
|
appendFieldUnescaped(key, "null");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param value The value of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, String value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new IllegalArgumentException("JSON value must not be null");
|
||||||
|
}
|
||||||
|
appendFieldUnescaped(key, "\"" + escape(value) + "\"");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an integer field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param value The value of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, int value) {
|
||||||
|
appendFieldUnescaped(key, String.valueOf(value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an object to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param object The object.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, JsonObject object) {
|
||||||
|
if (object == null) {
|
||||||
|
throw new IllegalArgumentException("JSON object must not be null");
|
||||||
|
}
|
||||||
|
appendFieldUnescaped(key, object.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The string array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, String[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values)
|
||||||
|
.map(value -> "\"" + escape(value) + "\"")
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an integer array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The integer array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, int[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an object array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The integer array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, JsonObject[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a field to the object.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param escapedValue The escaped value of the field.
|
||||||
|
*/
|
||||||
|
private void appendFieldUnescaped(String key, String escapedValue) {
|
||||||
|
if (builder == null) {
|
||||||
|
throw new IllegalStateException("JSON has already been built");
|
||||||
|
}
|
||||||
|
if (key == null) {
|
||||||
|
throw new IllegalArgumentException("JSON key must not be null");
|
||||||
|
}
|
||||||
|
if (hasAtLeastOneField) {
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
|
||||||
|
hasAtLeastOneField = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the JSON string and invalidates this builder.
|
||||||
|
*
|
||||||
|
* @return The built JSON string.
|
||||||
|
*/
|
||||||
|
public JsonObject build() {
|
||||||
|
if (builder == null) {
|
||||||
|
throw new IllegalStateException("JSON has already been built");
|
||||||
|
}
|
||||||
|
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||||
|
builder = null;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||||
|
*
|
||||||
|
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||||
|
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||||
|
*
|
||||||
|
* @param value The value to escape.
|
||||||
|
* @return The escaped value.
|
||||||
|
*/
|
||||||
|
private static String escape(String value) {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < value.length(); i++) {
|
||||||
|
char c = value.charAt(i);
|
||||||
|
if (c == '"') {
|
||||||
|
builder.append("\\\"");
|
||||||
|
} else if (c == '\\') {
|
||||||
|
builder.append("\\\\");
|
||||||
|
} else if (c <= '\u000F') {
|
||||||
|
builder.append("\\u000").append(Integer.toHexString(c));
|
||||||
|
} else if (c <= '\u001F') {
|
||||||
|
builder.append("\\u00").append(Integer.toHexString(c));
|
||||||
|
} else {
|
||||||
|
builder.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A super simple representation of a JSON object.
|
||||||
|
*
|
||||||
|
* <p>This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
|
||||||
|
* allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
|
||||||
|
* JsonObject)}.
|
||||||
|
*/
|
||||||
|
public static class JsonObject {
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
private JsonObject(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.commands;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class Cmd {
|
||||||
|
public static void console(String cmd) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void player(Player player, String cmd) {
|
||||||
|
player.chat("/" + cmd);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.commands;
|
||||||
|
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Tab {
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int arg, String[] args, String perm, Boolean onlinePlayer) {
|
||||||
|
if (args.length == arg + 1) {
|
||||||
|
Iterator var6 = Bukkit.getOnlinePlayers().iterator();
|
||||||
|
while (var6.hasNext()) {
|
||||||
|
Player player1 = (Player) var6.next();
|
||||||
|
if (passend(player1.getName(), args[arg]) && hasPermission(sender, perm)) {
|
||||||
|
matches.add(player1.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int argEquals, String equalsValue, int arg, String[] args, String perm, Boolean onlinePlayer) {
|
||||||
|
if (args.length == arg + 1) {
|
||||||
|
if (args[argEquals].toLowerCase().equals(equalsValue)) {
|
||||||
|
Iterator var6 = Bukkit.getOnlinePlayers().iterator();
|
||||||
|
while (var6.hasNext()) {
|
||||||
|
Player player1 = (Player) var6.next();
|
||||||
|
if (passend(player1.getName(), args[arg]) && hasPermission(sender, perm)) {
|
||||||
|
matches.add(player1.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int arg, String[] args, HashMap<String, String> permMap, Boolean onlinePlayer, String permForPlayer) {
|
||||||
|
if (args.length == arg + 1) {
|
||||||
|
for (String command : permMap.keySet()) {
|
||||||
|
if (hasPermission(sender, permMap.get(command)) && passend(command, args[arg])) {
|
||||||
|
matches.add(command);
|
||||||
|
} else if (onlinePlayer != null && permForPlayer != null) {
|
||||||
|
tab(matches, sender, arg, args, permForPlayer, onlinePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int arg, String[] args, HashMap<String, String> permMap) {
|
||||||
|
tab(matches, sender, arg, args, permMap, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tab(List<String> matches, CommandSender sender, int argEquals, String equalsValue, int arg, String[] args, HashMap<String, String> permMap) {
|
||||||
|
if (args.length == arg + 1) {
|
||||||
|
if (args[argEquals].toLowerCase().equals(equalsValue)) {
|
||||||
|
for (String command : permMap.keySet()) {
|
||||||
|
if (hasPermission(sender, permMap.get(command)) && passend(command, args[arg])) {
|
||||||
|
matches.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> tab(CommandSender sender, int arg, String[] args, String perm, String command) {
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
if (hasPermission(sender, perm) && passend(command, args[arg])) {
|
||||||
|
matches.add(command);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Boolean passend(String command, String arg) {
|
||||||
|
for (int i = 0; i < arg.toUpperCase().length(); i++) {
|
||||||
|
if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean hasPermission(CommandSender sender, String permission) {
|
||||||
|
String[] Permissions = permission.split(";");
|
||||||
|
for (String perm : Permissions) {
|
||||||
|
if (sender.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.eco;
|
||||||
|
|
||||||
|
import com.bencodez.votingplugin.VotingPluginMain;
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import net.t2code.lib.Spigot.system.languages.SelectLibMsg;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class Eco {
|
||||||
|
|
||||||
|
public static boolean moneyRemove(String prefix, Player player, Double price) {
|
||||||
|
if (vault(prefix, player)) {
|
||||||
|
return T2CodeMain.getEco().withdrawPlayer(player, price).transactionSuccess();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean moneyAdd(String prefix, Player player, Double price) {
|
||||||
|
if (vault(prefix, player)) {
|
||||||
|
return T2CodeMain.getEco().depositPlayer(player, price).transactionSuccess();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean vault(String prefix, Player player) {
|
||||||
|
if (T2CodeMain.getEco() == null) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
|
||||||
|
send.console(prefix + " §4\n" + prefix + " §4Vault could not be found! §9Please download it here: " +
|
||||||
|
"§6https://www.spigotmc.org/resources/vault.34315/§4\n" + prefix);
|
||||||
|
}
|
||||||
|
player.sendMessage(prefix + "\n" + SelectLibMsg.vaultNotSetUp + "\n" + prefix);
|
||||||
|
return false;
|
||||||
|
} else return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean itemRemove(Player player, String item, int amount) {
|
||||||
|
ItemStack itemStack = new ItemStack(Material.valueOf(item.toUpperCase()));
|
||||||
|
boolean have = false;
|
||||||
|
int anz = 0;
|
||||||
|
for (int iam = 0; iam < player.getInventory().getSize(); iam++) {
|
||||||
|
ItemStack itm = player.getInventory().getItem(iam);
|
||||||
|
if (itm == null) continue;
|
||||||
|
if (itm.getType() == itemStack.getType()) {
|
||||||
|
anz = anz + itm.getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (anz >= amount) {
|
||||||
|
player.getInventory().removeItem(new ItemStack(Material.valueOf(item), amount));
|
||||||
|
have = true;
|
||||||
|
}
|
||||||
|
return have;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean itemAdd(Player player, String item, int amount) {
|
||||||
|
ItemStack itemStack = new ItemStack(Material.valueOf(item.toUpperCase()));
|
||||||
|
boolean empty = false;
|
||||||
|
for (int i = 0; i < player.getInventory().getSize() - 5; i++) {
|
||||||
|
if (player.getInventory().getItem(i) == null) {
|
||||||
|
empty = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < amount; i++) {
|
||||||
|
if (empty) {
|
||||||
|
player.getInventory().addItem(itemStack);
|
||||||
|
} else {
|
||||||
|
player.getLocation().getWorld().dropItem(player.getLocation(), itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean votePointsRemove(String prefix, Player player, Integer amount) {
|
||||||
|
if (votePlugin(prefix, player)) {
|
||||||
|
return VotingPluginMain.getPlugin().getVotingPluginUserManager().getVotingPluginUser(player).removePoints(amount);
|
||||||
|
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean votePointsAdd(String prefix, Player player, Integer amount) {
|
||||||
|
if (votePlugin(prefix, player)) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(T2CodeMain.getPlugin(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
VotingPluginMain.getPlugin().getVotingPluginUserManager().getVotingPluginUser(player).addPoints(amount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean votePlugin(String prefix, Player player) {
|
||||||
|
if (PluginCheck.votingPlugin()) return true;
|
||||||
|
send.console(prefix + " §4\n" + prefix + " §4VotingPlugin could not be found! §9Please download it here: " +
|
||||||
|
"§6https://www.spigotmc.org/resources/votingplugin.15358/§4\n" + prefix);
|
||||||
|
player.sendMessage(prefix + "\n" + SelectLibMsg.votingPluginNotSetUp + "\n" + prefix);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.items;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class ItemVersion {
|
||||||
|
private static Material Head;
|
||||||
|
private static ItemStack HeadIS;
|
||||||
|
private static ItemStack CRAFTING_TABLE;
|
||||||
|
private static ItemStack YELLOW_WOOL;
|
||||||
|
private static ItemStack ORANGE_WOOL;
|
||||||
|
private static ItemStack GREEN_WOOL;
|
||||||
|
private static ItemStack GRAY_WOOL;
|
||||||
|
private static ItemStack RED_WOOL;
|
||||||
|
private static ItemStack RED_STAINED_GLASS_PANE;
|
||||||
|
|
||||||
|
public static void scan() {
|
||||||
|
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
||||||
|
Head = Material.valueOf("SKULL_ITEM");
|
||||||
|
YELLOW_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 4);
|
||||||
|
ORANGE_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 1);
|
||||||
|
GREEN_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 5);
|
||||||
|
GRAY_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 8);
|
||||||
|
RED_WOOL = new ItemStack(Material.valueOf("WOOL"), 1, (short) 14);
|
||||||
|
RED_STAINED_GLASS_PANE = new ItemStack(Material.valueOf("STAINED_GLASS_PANE"), 1, (short) 14);
|
||||||
|
CRAFTING_TABLE = new ItemStack(Material.valueOf("WORKBENCH"));
|
||||||
|
} else {
|
||||||
|
Head = Material.valueOf("PLAYER_HEAD");
|
||||||
|
CRAFTING_TABLE = new ItemStack(Material.CRAFTING_TABLE);
|
||||||
|
YELLOW_WOOL = new ItemStack(Material.YELLOW_WOOL);
|
||||||
|
ORANGE_WOOL = new ItemStack(Material.ORANGE_WOOL);
|
||||||
|
GREEN_WOOL = new ItemStack(Material.GREEN_WOOL);
|
||||||
|
GRAY_WOOL = new ItemStack(Material.GRAY_WOOL);
|
||||||
|
RED_WOOL = new ItemStack(Material.RED_WOOL);
|
||||||
|
RED_STAINED_GLASS_PANE = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||||
|
}
|
||||||
|
HeadIS = new ItemStack(Head, 1, (byte) 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Material getHead() {
|
||||||
|
return Head;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getHeadIS() {
|
||||||
|
return HeadIS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getCraftingTable() {
|
||||||
|
return CRAFTING_TABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getYellowWool() {
|
||||||
|
return YELLOW_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getOrangeWool() {
|
||||||
|
return ORANGE_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getGreenWool() {
|
||||||
|
return GREEN_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getGrayWool() {
|
||||||
|
return GRAY_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getRedWool() {
|
||||||
|
return RED_WOOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getRedStainedGlassPane() {
|
||||||
|
return RED_STAINED_GLASS_PANE;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.messages;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class HoverModule {
|
||||||
|
|
||||||
|
public static void modulePlayer(String text, String hover, String action, String actionValue, Player player) {
|
||||||
|
modulePlayer((text != null ? text : "null") + "/*/" + (hover != null ? hover : "null") + "/*/" + (action != null ? action : "null")
|
||||||
|
+ "/*/" + (actionValue != null ? actionValue : "null"), player);
|
||||||
|
}
|
||||||
|
private static final MiniMessage mm = MiniMessage.miniMessage();
|
||||||
|
|
||||||
|
public static void modulePlayer(String msg, Player player) {
|
||||||
|
if (msg.contains("/*/")) {
|
||||||
|
t2cmodule(msg, player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
miniMessage(msg,player);
|
||||||
|
}
|
||||||
|
public static void moduleSender(String msg, CommandSender sender) {
|
||||||
|
miniMessage(msg,sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void miniMessage(String msg, Player player){
|
||||||
|
Component parsed = mm.deserialize(Replace.convertColorCode(msg));
|
||||||
|
T2CodeMain.adventure().player(player).sendMessage(parsed);
|
||||||
|
}
|
||||||
|
public static void miniMessage(String msg, CommandSender sender){
|
||||||
|
Component parsed = mm.deserialize(Replace.convertColorCode(msg));
|
||||||
|
T2CodeMain.adventure().sender(sender).sendMessage(parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void t2cmodule(String msg, Player player) {
|
||||||
|
String[] split = msg.split("/\\*/");
|
||||||
|
int i = split.length;
|
||||||
|
String text = null;
|
||||||
|
String hover = null;
|
||||||
|
String action = null;
|
||||||
|
String actionValue = null;
|
||||||
|
if (i > 0) text = split[0];
|
||||||
|
if (i > 1) hover = split[1];
|
||||||
|
if (i > 2) action = split[2];
|
||||||
|
if (i > 3) actionValue = split[3];
|
||||||
|
|
||||||
|
TextBuilder textBuilder = new TextBuilder(text);
|
||||||
|
if (hover != null && !hover.equals("null")) {
|
||||||
|
textBuilder.addHover(hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action != null && actionValue != null && !action.equals("null") && !actionValue.equals("null")) {
|
||||||
|
textBuilder.addClickEvent(ClickEvent.Action.valueOf(action.toUpperCase()), actionValue);
|
||||||
|
}
|
||||||
|
player.spigot().sendMessage(textBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,146 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.messages;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
||||||
|
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class T2CodeTemplate {
|
||||||
|
public static Long onLoadHeader(String prefix, List<String> autor, String version, String spigot, String discord) {
|
||||||
|
return onLoadHeader(prefix, autor, version, spigot, discord, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix, List<String> autor, String version, String spigot, String discord, Boolean isPremium) {
|
||||||
|
return onLoadHeader(prefix, autor, version, spigot, discord, isPremium, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix, List<String> autor, String version, String spigot, String discord, Boolean isPremium, Boolean isVerify) {
|
||||||
|
Long long_ = System.currentTimeMillis();
|
||||||
|
// send.console(prefix +" §4===================== " + prefix + " §4=====================");
|
||||||
|
send.console(prefix + " §4 _______ §7___ §4_____ ");
|
||||||
|
send.console(prefix + " §4 |__ __|§7__ \\ §4/ ____|");
|
||||||
|
send.console(prefix + " §4 | | §7 ) §4| | ");
|
||||||
|
send.console(prefix + " §4 | | §7 / /§4| | ");
|
||||||
|
send.console(prefix + " §4 | | §7/ /_§4| |____ ");
|
||||||
|
send.console(prefix + " §4 |_| §7|____|§4\\_____|");
|
||||||
|
send.console(prefix + " §4 §e------------------");
|
||||||
|
send.console(prefix + " §4 §e| §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
|
||||||
|
send.console(prefix + " §4 §e| §2Version: §6" + version);
|
||||||
|
send.console(prefix + " §4 §e| §2Spigot: §6" + spigot);
|
||||||
|
send.console(prefix + " §4 §e| §2Discord: §6" + discord);
|
||||||
|
if (isPremium != null) {
|
||||||
|
if (isPremium) {
|
||||||
|
send.console(prefix + " §4 §e| §6Premium: §2true");
|
||||||
|
} else send.console(prefix + " §4 §e| §6Premium: §4false");
|
||||||
|
if (isVerify != null) {
|
||||||
|
if (isVerify) {
|
||||||
|
send.console(prefix + " §4 §e| §6Verify: §2true");
|
||||||
|
} else send.console(prefix + " §4 §e| §6Verify: §4false");
|
||||||
|
} else send.console(prefix + " §4 §e| §6Verify: §4false");
|
||||||
|
}
|
||||||
|
|
||||||
|
send.console(prefix + " §4 §e-------------------");
|
||||||
|
if (!(Util.getSnapshot() && spigot.equals(Util.getSpigot()))){
|
||||||
|
if (version.toLowerCase().contains("dev") || version.toLowerCase().contains("snapshot") || version.toLowerCase().contains("beta")) {
|
||||||
|
send.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! Some features may not be working as expected. Please report all" +
|
||||||
|
" bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!");
|
||||||
|
send.console(prefix + " §4 §e-------------------");
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//onLoadSeparateStroke(prefix);
|
||||||
|
return long_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long onLoadHeader(String prefix) {
|
||||||
|
Long long_ = System.currentTimeMillis();
|
||||||
|
send.console(prefix + "§4===================== " + prefix + " §4=====================");
|
||||||
|
return long_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadSeparateStroke(String prefix) {
|
||||||
|
send.console(prefix + " §8-------------------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadFooter(String prefix, Long long_, String version) {
|
||||||
|
onLoadSeparateStroke(prefix);
|
||||||
|
send.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
// send.console(prefix +" §4===================== " + prefix + "§4=====================");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onLoadFooter(String prefix, Long long_) {
|
||||||
|
onLoadSeparateStroke(prefix);
|
||||||
|
send.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
// send.console(prefix +" §4===================== " + prefix + "§4=====================");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onDisable(String prefix, List<String> autor, String version, String spigot, String discord) {
|
||||||
|
//send.console(prefix + "§4===================== " + prefix + " §7- §6" + version + " §4=====================");
|
||||||
|
//send.console(prefix + " §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
|
||||||
|
//send.console(prefix + " §2Version: §6" + version);
|
||||||
|
//send.console(prefix + " §2Spigot: §6" + spigot);
|
||||||
|
//send.console(prefix + " §2Discord: §6" + discord);
|
||||||
|
//send.console(prefix + " §4Plugin successfully disabled.");
|
||||||
|
//send.console(prefix + "§4===================== " + prefix + " §7- §6" + version + " §4=====================");
|
||||||
|
send.console(prefix + " §2Version: §6" + version);
|
||||||
|
send.console(prefix + " §4Plugin successfully disabled.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(CommandSender sender, String prefix, String spigot, String discord, List<String> autor, String pluginVersion, String publicVersion,
|
||||||
|
Boolean isPremium) {
|
||||||
|
send.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||||
|
send.sender(sender, prefix + " §2Autor: §6" + String.valueOf(autor).replace("[", "").replace("]", ""));
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if (MCVersion.minecraft1_8 || MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12 ||
|
||||||
|
MCVersion.minecraft1_13 || MCVersion.minecraft1_14 || MCVersion.minecraft1_15) {
|
||||||
|
send.sender(sender, prefix + " §2Version: §6" + pluginVersion);
|
||||||
|
} else {
|
||||||
|
TextComponent comp2 = new TextBuilder(prefix + " §2Version: §6" + pluginVersion)
|
||||||
|
.addHover("§8Click to copy").addClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, Replace.removeColorCode(prefix) + " - " + pluginVersion).build();
|
||||||
|
player.spigot().sendMessage(comp2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!publicVersion.equalsIgnoreCase(pluginVersion)) {
|
||||||
|
UpdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion, (Player) sender);
|
||||||
|
}
|
||||||
|
TextComponent comp3 = new TextBuilder(prefix + " §2Spigot: §6" + spigot)
|
||||||
|
.addHover("§8Open Spigot").addClickEvent(ClickEvent.Action.OPEN_URL, spigot).build();
|
||||||
|
|
||||||
|
player.spigot().sendMessage(comp3);
|
||||||
|
TextComponent comp4 = new TextBuilder(prefix + " §2Discord: §6" + discord)
|
||||||
|
.addHover("§8Open Discord").addClickEvent(ClickEvent.Action.OPEN_URL, discord).build();
|
||||||
|
player.spigot().sendMessage(comp4);
|
||||||
|
} else {
|
||||||
|
if (publicVersion.equalsIgnoreCase(pluginVersion)) {
|
||||||
|
send.sender(sender, prefix + " §2Version: §6" + pluginVersion);
|
||||||
|
} else {
|
||||||
|
UpdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion);
|
||||||
|
}
|
||||||
|
send.sender(sender, prefix + " §2Spigot: §6" + spigot);
|
||||||
|
send.sender(sender, prefix + " §2Discord: §6" + discord);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (isPremium != null) {
|
||||||
|
if (isPremium) {
|
||||||
|
send.sender(sender, prefix + " §6Premium: §2true");
|
||||||
|
} else send.sender(sender, prefix + " §6Premium: §4false");
|
||||||
|
}
|
||||||
|
send.sender(sender, prefix + "§4======= " + prefix + " §4=======");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendInfo(CommandSender sender, String prefix, String spigot, String discord, List<String> autor, String pluginVersion, String publicVersion) {
|
||||||
|
sendInfo(sender, prefix, spigot, discord, autor, pluginVersion, publicVersion, null);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.messages;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import net.md_5.bungee.api.chat.HoverEvent;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
|
|
||||||
|
public class TextBuilder {
|
||||||
|
|
||||||
|
private final String text;
|
||||||
|
private String hover;
|
||||||
|
private String click;
|
||||||
|
private ClickEvent.Action action;
|
||||||
|
|
||||||
|
public TextBuilder(String text) {
|
||||||
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder addHover(String hover) {
|
||||||
|
this.hover = hover;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBuilder addClickEvent(ClickEvent.Action clickEventAction, String value) {
|
||||||
|
this.action = clickEventAction;
|
||||||
|
this.click = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextComponent build() {
|
||||||
|
if (this.text.contains("[empty]")) return null;
|
||||||
|
TextComponent textComponent = new TextComponent();
|
||||||
|
textComponent.setText(this.text);
|
||||||
|
if (this.hover != null) {
|
||||||
|
textComponent.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(this.hover).create()));
|
||||||
|
}
|
||||||
|
if (this.click != null && (this.action != null)) {
|
||||||
|
textComponent.setClickEvent(new ClickEvent(action, this.click));
|
||||||
|
}
|
||||||
|
return textComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ClickEventType {
|
||||||
|
OPEN_URL, OPEN_FILE, RUN_COMMAND, SUGGEST_COMMAND, CHANGE_PAGE, COPY_TO_CLIPBOARD
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.messages;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class send {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spigot
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void console(String msg) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
Bukkit.getConsoleSender().sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void player( Player player, String msg) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
HoverModule.modulePlayer(msg, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void title( Player player, String msg, String msg2) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
if (msg2 == null || msg2.contains("[empty]")) return;
|
||||||
|
player.sendTitle(msg, msg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void title( Player player, String msg, String msg2, int i, int i1, int i2) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
if (msg2 == null || msg2.contains("[empty]")) return;
|
||||||
|
player.sendTitle(msg, msg2, i, i1, i2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sender( CommandSender sender, String msg) {
|
||||||
|
if (msg == null || msg.contains("[empty]")) return;
|
||||||
|
HoverModule.moduleSender(msg, sender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug( Plugin plugin, String msg) {
|
||||||
|
debug(plugin, msg, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debug( Plugin plugin, String msg, Integer stage) {
|
||||||
|
// if (!new File(Main.getPath(), "config.yml").exists()) return;
|
||||||
|
if (stage == null) {
|
||||||
|
if (plugin.getConfig().getBoolean("Plugin.Debug"))
|
||||||
|
Bukkit.getConsoleSender().sendMessage(plugin.getDescription().getPrefix() + " §5DEBUG: §6" + msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plugin.getConfig().getInt("Plugin.Debug") >= stage)
|
||||||
|
Bukkit.getConsoleSender().sendMessage(plugin.getDescription().getPrefix() + " §5DEBUG: §6" + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void debugmsg(Plugin plugin, String msg) {
|
||||||
|
warning(plugin, "");
|
||||||
|
Bukkit.getConsoleSender().sendMessage("§e[" + plugin.getDescription().getPrefix() + "] §5DEBUG-MSG: §6" + msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void info( Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.INFO, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning( Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.WARNING, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void error( Plugin plugin, String msg) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, msg);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.minecraftVersion;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class MCVersion {
|
||||||
|
public static String isVersion;
|
||||||
|
public static String isBuckitVersion;
|
||||||
|
public static boolean minecraft1_8;
|
||||||
|
public static boolean minecraft1_9;
|
||||||
|
public static boolean minecraft1_10;
|
||||||
|
public static boolean minecraft1_11;
|
||||||
|
public static boolean minecraft1_12;
|
||||||
|
public static boolean minecraft1_13;
|
||||||
|
public static boolean minecraft1_14;
|
||||||
|
public static boolean minecraft1_15;
|
||||||
|
public static boolean minecraft1_16;
|
||||||
|
public static boolean minecraft1_17;
|
||||||
|
public static boolean minecraft1_18;
|
||||||
|
public static boolean minecraft1_19;
|
||||||
|
public static boolean minecraft1_20;
|
||||||
|
public static void onCheck(){
|
||||||
|
isVersion = Bukkit.getServer().getVersion();
|
||||||
|
isBuckitVersion = Bukkit.getServer().getBukkitVersion();
|
||||||
|
minecraft1_8 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8");
|
||||||
|
minecraft1_9 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9");
|
||||||
|
minecraft1_10 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10");
|
||||||
|
minecraft1_11 = Bukkit.getServer().getClass().getPackage().getName().contains("1_11");
|
||||||
|
minecraft1_12 = Bukkit.getServer().getClass().getPackage().getName().contains("1_12");
|
||||||
|
minecraft1_13 = Bukkit.getServer().getClass().getPackage().getName().contains("1_13");
|
||||||
|
minecraft1_14 = Bukkit.getServer().getClass().getPackage().getName().contains("1_14");
|
||||||
|
minecraft1_15 = Bukkit.getServer().getClass().getPackage().getName().contains("1_15");
|
||||||
|
minecraft1_16 = Bukkit.getServer().getClass().getPackage().getName().contains("1_16");
|
||||||
|
minecraft1_17 = Bukkit.getServer().getClass().getPackage().getName().contains("1_17");
|
||||||
|
minecraft1_18 = Bukkit.getServer().getClass().getPackage().getName().contains("1_18");
|
||||||
|
minecraft1_19 = Bukkit.getServer().getClass().getPackage().getName().contains("1_19");
|
||||||
|
minecraft1_20 = Bukkit.getServer().getClass().getPackage().getName().contains("1_20");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.minecraftVersion;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class NMSVersion {
|
||||||
|
public static String isNMS;
|
||||||
|
public static boolean v1_8_R1;
|
||||||
|
public static boolean v1_8_R2;
|
||||||
|
public static boolean v1_8_R3;
|
||||||
|
public static boolean v1_9_R1;
|
||||||
|
public static boolean v1_9_R2;
|
||||||
|
public static boolean v1_10_R1;
|
||||||
|
public static boolean v1_11_R1;
|
||||||
|
public static boolean v1_12_R1;
|
||||||
|
public static boolean v1_13_R1;
|
||||||
|
public static boolean v1_13_R2;
|
||||||
|
public static boolean v1_14_R1;
|
||||||
|
public static boolean v1_15_R1;
|
||||||
|
public static boolean v1_16_R1;
|
||||||
|
public static boolean v1_16_R2;
|
||||||
|
public static boolean v1_16_R3;
|
||||||
|
public static boolean v1_17_R1;
|
||||||
|
public static boolean v1_18_R1;
|
||||||
|
public static boolean v1_18_R2;
|
||||||
|
public static boolean v1_19_R1;
|
||||||
|
public static boolean v1_19_R2;
|
||||||
|
|
||||||
|
public static void onCheck() {
|
||||||
|
isNMS = Bukkit.getServer().getClass().getPackage().getName();
|
||||||
|
v1_8_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8_R1");
|
||||||
|
v1_8_R2 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8_R2");
|
||||||
|
v1_8_R3 = Bukkit.getServer().getClass().getPackage().getName().contains("1_8_R3");
|
||||||
|
v1_9_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9_R1");
|
||||||
|
v1_9_R2 = Bukkit.getServer().getClass().getPackage().getName().contains("1_9_R2");
|
||||||
|
v1_10_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_10_R1");
|
||||||
|
v1_11_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_11_R1");
|
||||||
|
v1_12_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_12_R1");
|
||||||
|
v1_13_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_13_R1");
|
||||||
|
v1_13_R2 = Bukkit.getServer().getClass().getPackage().getName().contains("1_13_R2");
|
||||||
|
v1_14_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_14_R1");
|
||||||
|
v1_15_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_15_R1");
|
||||||
|
v1_16_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_16_R1");
|
||||||
|
v1_16_R2 = Bukkit.getServer().getClass().getPackage().getName().contains("1_16_R2");
|
||||||
|
v1_16_R3 = Bukkit.getServer().getClass().getPackage().getName().contains("1_16_R3");
|
||||||
|
v1_17_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_17_R1");
|
||||||
|
v1_18_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_18_R1");
|
||||||
|
v1_18_R2 = Bukkit.getServer().getClass().getPackage().getName().contains("1_18_R2");
|
||||||
|
v1_19_R1 = Bukkit.getServer().getClass().getPackage().getName().contains("1_19_R1");
|
||||||
|
v1_19_R2 = Bukkit.getServer().getClass().getPackage().getName().contains("1_19_R2");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,143 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.player;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
|
public class NameHistory {
|
||||||
|
public static class NameLookup {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL from Mojang API that provides the JSON String in response.
|
||||||
|
*/
|
||||||
|
private static final String LOOKUP_URL = "https://api.mojang.com/user/profiles/%s/names";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The URL from Mojang API to resolve the UUID of a player from their name.
|
||||||
|
*/
|
||||||
|
private static final String GET_UUID_URL = "https://api.mojang.com/users/profiles/minecraft/%s?t=0";
|
||||||
|
private static final Gson JSON_PARSER = new Gson();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread!It blocks while attempting to get a response from Mojang servers!</h1>
|
||||||
|
* @param player The UUID of the player to be looked up.
|
||||||
|
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||||
|
* @throws IOException {@link #getPlayerPreviousNames(String)}
|
||||||
|
*/
|
||||||
|
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(UUID player) throws IOException {
|
||||||
|
return getPlayerPreviousNames(player.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||||
|
* Alternative method accepting an 'OfflinePlayer' (and therefore 'Player') objects as parameter.
|
||||||
|
* @param player The OfflinePlayer object to obtain the UUID from.
|
||||||
|
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||||
|
* @throws IOException {@link #getPlayerPreviousNames(UUID)}
|
||||||
|
*/
|
||||||
|
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(OfflinePlayer player) throws IOException {
|
||||||
|
return getPlayerPreviousNames(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h1>NOTE: Avoid running this method <i>Synchronously</i> with the main thread! It blocks while attempting to get a response from Mojang servers!</h1>
|
||||||
|
* Alternative method accepting an {@link OfflinePlayer} (and therefore {@link Player}) objects as parameter.
|
||||||
|
* @param uuid The UUID String to lookup
|
||||||
|
* @return Returns an array of {@link PreviousPlayerNameEntry} objects, or null if the response couldn't be interpreted.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static PreviousPlayerNameEntry[] getPlayerPreviousNames(String uuid) throws IOException {
|
||||||
|
if (uuid == null || uuid.isEmpty())
|
||||||
|
return null;
|
||||||
|
String response = getRawJsonResponse(new URL(String.format(LOOKUP_URL, uuid)));
|
||||||
|
PreviousPlayerNameEntry[] names = JSON_PARSER.fromJson(response, PreviousPlayerNameEntry[].class);
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you don't have the UUID of a player, this method will resolve it for you.<br>
|
||||||
|
* The output of this method may be used directly with {@link #getPlayerPreviousNames(String)}.<br>
|
||||||
|
* <b>NOTE: as with the rest, this method opens a connection with a remote server, so running it synchronously will block the main thread which will lead to server lag.</b>
|
||||||
|
* @param name The name of the player to lookup.
|
||||||
|
* @return A String which represents the player's UUID. <b>Note: the uuid cannot be parsed to a UUID object directly, as it doesnt contain dashes. This feature will be implemented later</b>
|
||||||
|
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||||
|
*/
|
||||||
|
public static String getPlayerUUID(String name) throws IOException {
|
||||||
|
String response = getRawJsonResponse(new URL(String.format(GET_UUID_URL, name)));
|
||||||
|
JsonObject o = JSON_PARSER.fromJson(response, JsonObject.class);
|
||||||
|
if (o == null)
|
||||||
|
return null;
|
||||||
|
return o.get("id") == null ? null : o.get("id").getAsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a helper method used to read the response of Mojang's API webservers.
|
||||||
|
* @param u the URL to connect to
|
||||||
|
* @return a String with the data read.
|
||||||
|
* @throws IOException Inherited by {@link BufferedReader#readLine()}, {@link BufferedReader#close()}, {@link URL}, {@link HttpURLConnection#getInputStream()}
|
||||||
|
*/
|
||||||
|
private static String getRawJsonResponse(URL u) throws IOException {
|
||||||
|
HttpURLConnection con = (HttpURLConnection) u.openConnection();
|
||||||
|
con.setDoInput(true);
|
||||||
|
con.setConnectTimeout(2000);
|
||||||
|
con.setReadTimeout(2000);
|
||||||
|
con.connect();
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
String response = in.readLine();
|
||||||
|
in.close();
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the typical response expected by Mojang servers when requesting the name history of a player.
|
||||||
|
*/
|
||||||
|
public class PreviousPlayerNameEntry {
|
||||||
|
private String name;
|
||||||
|
@SerializedName("changedToAt")
|
||||||
|
private long changeTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the player name of this entry.
|
||||||
|
* @return The name of the player.
|
||||||
|
*/
|
||||||
|
public String getPlayerName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time of change of the name.
|
||||||
|
* <br><b>Note: This will return 0 if the name is the original (initial) name of the player! Make sure you check if it is 0 before handling!
|
||||||
|
* <br>Parsing 0 to a Date will result in the date "01/01/1970".</b>
|
||||||
|
* @return a timestamp in miliseconds that you can turn into a date or handle however you want :)
|
||||||
|
*/
|
||||||
|
public long getChangeTime() {
|
||||||
|
return changeTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this name is the name used to register the account (the initial/original name)
|
||||||
|
* @return a boolean, true if it is the the very first name of the player, otherwise false.
|
||||||
|
*/
|
||||||
|
public boolean isPlayersInitialName() {
|
||||||
|
return getChangeTime() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Name: " + name + " Date of change: " + new Date(changeTime).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.plugins;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class PluginCheck {
|
||||||
|
public static Boolean pluginCheck(String pluginName){
|
||||||
|
return Bukkit.getPluginManager().getPlugin(pluginName) != null;
|
||||||
|
}
|
||||||
|
public static Plugin pluginInfos(String pluginName){
|
||||||
|
return Bukkit.getPluginManager().getPlugin(pluginName);
|
||||||
|
}
|
||||||
|
public static Boolean papi(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean vault(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("Vault") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plotSquared(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlotSquared") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plugManGUI(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlugManGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean cmi(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("CMI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean votingPlugin(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("VotingPlugin") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* T2Code Plugins
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Boolean cgui(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("CommandGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean functiongui(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-CommandGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean plotSquaredGUI(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PlotSquaredGUI") != null;
|
||||||
|
}
|
||||||
|
public static Boolean luckyBox(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-LuckyBox") != null;
|
||||||
|
}
|
||||||
|
public static Boolean autoResponse(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-AutoResponse") != null;
|
||||||
|
}
|
||||||
|
public static Boolean opSec(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("OPSecurity") != null;
|
||||||
|
}
|
||||||
|
public static Boolean papiTest(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("PaPiTest") != null;
|
||||||
|
}
|
||||||
|
public static Boolean booster(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("Booster") != null;
|
||||||
|
}
|
||||||
|
public static Boolean antiMapCopy(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("AntiMapCopy") != null;
|
||||||
|
}
|
||||||
|
public static Boolean loreEditor(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("LoreEditor") != null;
|
||||||
|
}
|
||||||
|
public static Boolean t2cAlias(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-Alias") != null;
|
||||||
|
}
|
||||||
|
public static Boolean t2cWarp(){
|
||||||
|
return Bukkit.getPluginManager().getPlugin("T2C-Warp") != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean pluginNotFound(Plugin plugin, String prefix, String pl, Integer spigotID) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(pl) == null) {
|
||||||
|
plugin.getLogger().log(Level.SEVERE, "Plugin can not be loaded!");
|
||||||
|
Bukkit.getConsoleSender().sendMessage(prefix + " §e" + pl + " §4could not be found. Please download it here: " +
|
||||||
|
"§6https://spigotmc.org/resources/" + pl + "." + spigotID + " §4to be able to use this plugin.");
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().disablePlugin(T2CodeMain.getPlugin());
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.plugins;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class T2CPluginManager {
|
||||||
|
|
||||||
|
public static void restart(String plugin) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().disablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().enablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enable(String plugin) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().enablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disable(String plugin) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(plugin) == null) return;
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().disablePlugin(Objects.requireNonNull(Bukkit.getPluginManager().getPlugin(plugin)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void restart(Plugin plugin) {
|
||||||
|
if (plugin == null) return;
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().disablePlugin(plugin);
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().enablePlugin(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void enable(Plugin plugin) {
|
||||||
|
if (plugin == null) return;
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().enablePlugin(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disable(Plugin plugin) {
|
||||||
|
if (plugin == null) return;
|
||||||
|
T2CodeMain.getPlugin().getPluginLoader().disablePlugin(plugin);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.register;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class Register {
|
||||||
|
public static void listener(Listener listener, Plugin plugin) {
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, Plugin plugin) {
|
||||||
|
if (plugin.getServer().getPluginManager().getPermission(permission) == null) {
|
||||||
|
plugin.getServer().getPluginManager().addPermission(new Permission(permission));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, PermissionDefault setDefault, Plugin plugin) {
|
||||||
|
permission(permission, plugin);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).setDefault(setDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, String children, Boolean setBoolean, Plugin plugin) {
|
||||||
|
permission(permission, plugin);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).getChildren().put(children, setBoolean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permission(String permission, PermissionDefault setDefault, String children, Boolean setBoolean, Plugin plugin) {
|
||||||
|
permission(permission, plugin);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).setDefault(setDefault);
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).getChildren().put(children, setBoolean);
|
||||||
|
}
|
||||||
|
public static void permissionDescription(String permission, String description, Plugin plugin) {
|
||||||
|
plugin.getServer().getPluginManager().getPermission(permission).setDescription(description);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,143 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.replace;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Replace {
|
||||||
|
|
||||||
|
public static String replace(String prefix, String Text) {
|
||||||
|
|
||||||
|
return replaceLegacyColor(Text).replace("[prefix]", prefix).replace("[ue]", "ü")
|
||||||
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
||||||
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replace(String prefix, Player player, String Text) {
|
||||||
|
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replace(String prefix, List<String> Text) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
for (String input : Text) {
|
||||||
|
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n"));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replace(String prefix, Player player, List<String> Text) {
|
||||||
|
List<String> output = new ArrayList();
|
||||||
|
if (player == null) {
|
||||||
|
return Collections.singletonList("player is null");
|
||||||
|
}
|
||||||
|
if (Text == null) {
|
||||||
|
return Collections.singletonList("Text is null");
|
||||||
|
}
|
||||||
|
for (String input : Text) {
|
||||||
|
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n")));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replacePrice(String prefix, List<String> Text, String price) {
|
||||||
|
List<String> rp = new ArrayList();
|
||||||
|
for (String s : Text) {
|
||||||
|
rp.add(replaceLegacyColor(s).replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[nl]", "\n").replace("[price]", String.valueOf(price)));
|
||||||
|
}
|
||||||
|
return rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String removeColorCode(String value) {
|
||||||
|
return value.replace("&0", "").replace("&1", "").replace("&2", "").replace("&3", "")
|
||||||
|
.replace("&4", "").replace("&5", "").replace("&6", "").replace("&7", "")
|
||||||
|
.replace("&8", "").replace("&9", "").replace("&a", "").replace("&b", "")
|
||||||
|
.replace("&c", "").replace("&d", "").replace("&e", "").replace("&f", "")
|
||||||
|
.replace("&k", "").replace("&l", "").replace("&m", "").replace("&n", "")
|
||||||
|
.replace("&o", "").replace("&r", "");
|
||||||
|
// String text = value.replace("&", "§");
|
||||||
|
// while (text.contains("§")) {
|
||||||
|
// int stelle = text.indexOf("§");
|
||||||
|
// if (text.length() >= stelle + 2) {
|
||||||
|
// text = text.substring(0, stelle) + text.substring(stelle + 2);
|
||||||
|
// } else {
|
||||||
|
// text = text.substring(0, stelle) + text.substring(stelle + 1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return (text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> replacePrice(String prefix, Player player, List<String> Text, String price) {
|
||||||
|
List<String> rp = new ArrayList();
|
||||||
|
for (String s : Text) {
|
||||||
|
rp.add(replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, s.replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n")
|
||||||
|
.replace("[price]", String.valueOf(price)))));
|
||||||
|
}
|
||||||
|
return rp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replacePrice(String prefix, String Text, String price) {
|
||||||
|
return replaceLegacyColor(Text).replace("[prefix]", prefix)
|
||||||
|
.replace("&o", "§o").replace("&r", "§r").replace("[ue]", "ü")
|
||||||
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
||||||
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[price]", String.valueOf(price))
|
||||||
|
.replace("[nl]", "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replacePrice(String prefix, Player player, String Text, String price) {
|
||||||
|
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
|
||||||
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
|
.replace("[price]", String.valueOf(price)).replace("[nl]", "\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String replaceLegacyColor(String text) {
|
||||||
|
return text.replace("&0", "§0").replace("&1", "§1").replace("&2", "§2").replace("&3", "§3")
|
||||||
|
.replace("&4", "§4").replace("&5", "§5").replace("&6", "§6").replace("&7", "§7")
|
||||||
|
.replace("&8", "§8").replace("&9", "§9").replace("&a", "§a").replace("&b", "§b")
|
||||||
|
.replace("&c", "§c").replace("&d", "§d").replace("&e", "§e").replace("&f", "§f")
|
||||||
|
.replace("&k", "§k").replace("&l", "§l").replace("&m", "§m").replace("&n", "§n")
|
||||||
|
.replace("&o", "§o").replace("&r", "§r");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convertColorCode(String text) {
|
||||||
|
return text.replace("&0", "<black>").replace("§0", "<black>")
|
||||||
|
.replace("&1", "<dark_blue>").replace("§1", "<dark_blue>")
|
||||||
|
.replace("&2", "<dark_green>").replace("§2", "<dark_green>")
|
||||||
|
.replace("&3", "<dark_aqua>").replace("§3", "<dark_aqua>")
|
||||||
|
.replace("&4", "<dark_red>").replace("§4", "<dark_red>")
|
||||||
|
.replace("&5", "<dark_purple>").replace("§5", "<dark_purple>")
|
||||||
|
.replace("&6", "<gold>").replace("§6", "<gold>")
|
||||||
|
.replace("&7", "<gray>").replace("§7", "<gray>")
|
||||||
|
.replace("&8", "<dark_gray>").replace("§8", "<dark_gray>")
|
||||||
|
.replace("&9", "<blue>").replace("§9", "<blue>")
|
||||||
|
.replace("&a", "<green>").replace("§a", "<green>")
|
||||||
|
.replace("&b", "<aqua>").replace("§b", "<aqua>")
|
||||||
|
.replace("&c", "<red>").replace("§c", "<red>")
|
||||||
|
.replace("&d", "<light_purple>").replace("§d", "<light_purple>")
|
||||||
|
.replace("&e", "<yellow>").replace("§e", "<yellow>")
|
||||||
|
.replace("&f", "<white>").replace("§f", "<white>")
|
||||||
|
.replace("&k", "<obfuscated>").replace("§k", "<obfuscated>")
|
||||||
|
.replace("&l", "<bold>").replace("§l", "<bold>")
|
||||||
|
.replace("&m", "<strikethrough>").replace("§m", "<strikethrough>")
|
||||||
|
.replace("&n", "<underlined>").replace("§n", "<underlined>")
|
||||||
|
.replace("&o", "<italic>").replace("§o", "<italic>")
|
||||||
|
.replace("&r", "<reset>").replace("§r", "<reset>");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,192 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.update;
|
||||||
|
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.HoverModule;
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.system.config.SelectLibConfig;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class UpdateAPI {
|
||||||
|
public static HashMap<String, UpdateObject> PluginVersionen = new HashMap<>();
|
||||||
|
|
||||||
|
public static void join(Plugin plugin, String prefix, String perm, Player player, String spigot, String discord) {
|
||||||
|
if (!SelectLibConfig.getUpdateCheckOnJoin()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String pluginVersion = plugin.getDescription().getVersion();
|
||||||
|
if (!player.hasPermission(perm) && !player.isOp()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (UpdateAPI.PluginVersionen.get(plugin.getName()) == null) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
join(plugin, prefix, perm, player, spigot, discord);
|
||||||
|
}
|
||||||
|
}.runTaskLaterAsynchronously(plugin, 20L);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String publicVersion = UpdateAPI.PluginVersionen.get(plugin.getName()).publicVersion;
|
||||||
|
if (pluginVersion.equals(publicVersion)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
use(plugin, prefix, player, pluginVersion, publicVersion, spigot, discord);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void use(Plugin plugin, String prefix, Player player, String pluginVersion, String publicVersion, String spigot, String discord) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
UpdateAPI.sendUpdateMsg(prefix, spigot, discord, pluginVersion, publicVersion, player);
|
||||||
|
}
|
||||||
|
}.runTaskLaterAsynchronously(plugin, 200L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendUpdateMsg(String Prefix, String Spigot, String Discord, String pluginVersion, String publicVersion) {
|
||||||
|
send.console("§4=========== " + Prefix + " §4===========");
|
||||||
|
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
if (publicVersion.toLowerCase().contains("dev")) {
|
||||||
|
send.console("§6A new §4DEV§6 version was found!");
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("beta")) {
|
||||||
|
send.console("§6A new §2BETA§6 version was found!");
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
send.console("§6A new §eSNAPSHOT§6 version was found!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
send.console("§6A new version was found!");
|
||||||
|
}
|
||||||
|
send.console("§6Your version: §c" + pluginVersion + " §7- §6Current version: §a" + publicVersion);
|
||||||
|
send.console("§6You can download it here: §e" + Spigot);
|
||||||
|
send.console("§6You can find more information on Discord: §e" + Discord);
|
||||||
|
send.console("§4=========== " + Prefix + " §4===========");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendUpdateMsg(String prefix, String Spigot, String Discord, String pluginVersion, String publicVersion, Player player) {
|
||||||
|
if (publicVersion.equals("§4No public version found!")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String st = "[prefix]<br>" +
|
||||||
|
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <gold>A new</gold> [value]<gold>version was found!</gold></hover></click><br>" +
|
||||||
|
"<click:open_url:'[link]'><hover:show_text:'<gold>You can download it here: <yellow>[link]</yellow></gold>'>[prefix] <red>[plv]</red> <gray>-></gray> <green>[puv]</green></hover></click><br>" +
|
||||||
|
"<click:open_url:'[dc]'><hover:show_text:'<yellow>[dc]</yellow>'>[prefix] <gold>You can find more information on Discord.</gold></hover></click><br>" +
|
||||||
|
"[prefix]";
|
||||||
|
String value = "";
|
||||||
|
if (publicVersion.toLowerCase().contains("dev") || publicVersion.toLowerCase().contains("beta") || publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
if (publicVersion.toLowerCase().contains("dev")) {
|
||||||
|
value = "<dark_red>DEV </dark_red>";
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("beta")) {
|
||||||
|
value = "<green>BETA </green>";
|
||||||
|
}
|
||||||
|
if (publicVersion.toLowerCase().contains("snapshot")) {
|
||||||
|
value = "<yellow>SNAPSHOT </yellow>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
send.player(player, st.replace("[prefix]", prefix).replace("[value]", value).replace("[link]", Spigot)
|
||||||
|
.replace("[plv]",pluginVersion).replace("[puv]",publicVersion).replace("[dc]",Discord));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean noUpdate = true;
|
||||||
|
|
||||||
|
public static void onUpdateCheck(Plugin plugin, String Prefix, String Spigot, int SpigotID, String Discord) {
|
||||||
|
onUpdateCheck(plugin, Prefix, Spigot, SpigotID, Discord, 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onUpdateCheck(Plugin plugin, String Prefix, String Spigot, int SpigotID, String Discord, Integer timeInMin) {
|
||||||
|
int taskID = Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
(new UpdateAPI((JavaPlugin) plugin, SpigotID)).getVersion((update_version) -> {
|
||||||
|
UpdateObject update = new UpdateObject(
|
||||||
|
plugin.getName(),
|
||||||
|
plugin.getDescription().getVersion(),
|
||||||
|
update_version
|
||||||
|
);
|
||||||
|
UpdateAPI.PluginVersionen.put(plugin.getName(), update);
|
||||||
|
if (!plugin.getDescription().getVersion().equalsIgnoreCase(update_version)) {
|
||||||
|
noUpdate = true;
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sendUpdateMsg(Prefix, Spigot, Discord, plugin.getDescription().getVersion(), update_version);
|
||||||
|
}
|
||||||
|
}.runTaskLater(plugin, 600L);
|
||||||
|
} else {
|
||||||
|
if (noUpdate) {
|
||||||
|
send.console(Prefix + " §2No update found.");
|
||||||
|
noUpdate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, Prefix, plugin.getDescription().getVersion());
|
||||||
|
}
|
||||||
|
}, 0L, timeInMin * 60 * 20L);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JavaPlugin plugin;
|
||||||
|
private int resourceId;
|
||||||
|
|
||||||
|
public UpdateAPI(JavaPlugin plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getVersion(Consumer<String> consumer, String Prefix, String pluginVersion) {
|
||||||
|
if (!plugin.isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = (new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId)).openStream();
|
||||||
|
try {
|
||||||
|
Scanner scanner = new Scanner(inputStream);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
consumer.accept(scanner.next());
|
||||||
|
}
|
||||||
|
} catch (Throwable var8) {
|
||||||
|
try {
|
||||||
|
scanner.close();
|
||||||
|
} catch (Throwable var7) {
|
||||||
|
var8.addSuppressed(var7);
|
||||||
|
}
|
||||||
|
throw var8;
|
||||||
|
}
|
||||||
|
scanner.close();
|
||||||
|
} catch (Throwable var9) {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (Throwable var6) {
|
||||||
|
var9.addSuppressed(var6);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw var9;
|
||||||
|
}
|
||||||
|
if (inputStream != null) {
|
||||||
|
inputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException var10) {
|
||||||
|
UpdateObject update = new UpdateObject(
|
||||||
|
plugin.getName(),
|
||||||
|
pluginVersion,
|
||||||
|
"§4No public version found!"
|
||||||
|
);
|
||||||
|
UpdateAPI.PluginVersionen.put(plugin.getName(), update);
|
||||||
|
this.plugin.getLogger().severe("§4 Cannot look for updates: " + var10.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.update;
|
||||||
|
|
||||||
|
public class UpdateObject {
|
||||||
|
|
||||||
|
public String pluginName;
|
||||||
|
public String pluginVersion;
|
||||||
|
public String publicVersion;
|
||||||
|
|
||||||
|
public UpdateObject(String pluginName, String pluginVersion, String publicVersion) {
|
||||||
|
this.pluginName = pluginName;
|
||||||
|
this.pluginVersion = pluginVersion;
|
||||||
|
this.publicVersion = publicVersion;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
package net.t2code.lib.Spigot.Lib.yamlConfiguration;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
||||||
|
import net.t2code.lib.Spigot.system.languages.SelectLibMsg;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
public static void set(String path, String value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, YamlConfiguration YamlConfiguration) {
|
||||||
|
YamlConfiguration.set(path, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Integer value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Double value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, Boolean value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, List<String> value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void set(String path, ItemStack value, YamlConfiguration YamlConfiguration) {
|
||||||
|
if (!YamlConfiguration.contains(path)) {
|
||||||
|
YamlConfiguration.set(path, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSound(String soundName, String sound1_8, String sound1_9, String sound1_13, YamlConfiguration yamlConfiguration) {
|
||||||
|
Config.set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||||
|
String sound;
|
||||||
|
if (MCVersion.minecraft1_8) {
|
||||||
|
sound = sound1_8.toString();
|
||||||
|
} else if (MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
||||||
|
sound = sound1_9.toString();
|
||||||
|
} else sound = sound1_13.toString();
|
||||||
|
Config.set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSound(String soundName, String sound1_8, String sound1_13, YamlConfiguration yamlConfiguration) {
|
||||||
|
Config.set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||||
|
String sound;
|
||||||
|
if (MCVersion.minecraft1_8) {
|
||||||
|
sound = sound1_8.toString();
|
||||||
|
} else sound = sound1_13.toString();
|
||||||
|
Config.set("Sound." + soundName + ".Sound", sound, yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSound(String soundName, String sound, YamlConfiguration yamlConfiguration) {
|
||||||
|
Config.set("Sound." + soundName + ".Enable", true, yamlConfiguration);
|
||||||
|
Config.set("Sound." + soundName + ".Sound", sound.toString(), yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean selectSoundEnable(String soundName, YamlConfiguration yamlConfiguration) {
|
||||||
|
return selectBoolean("Sound." + soundName + ".Enable", yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String selectSound(String prefix, String soundName, YamlConfiguration yamlConfiguration) {
|
||||||
|
return select(prefix, "Sound." + soundName + ".Sound", yamlConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sound checkSound(String sound1_8, String sound1_9, String sound1_13, String selectSoundFromConfig, String prefix) {
|
||||||
|
String SOUND;
|
||||||
|
if (MCVersion.minecraft1_8) {
|
||||||
|
SOUND = sound1_8;
|
||||||
|
} else if (MCVersion.minecraft1_9 || MCVersion.minecraft1_10 || MCVersion.minecraft1_11 || MCVersion.minecraft1_12) {
|
||||||
|
SOUND = sound1_9;
|
||||||
|
} else SOUND = sound1_13;
|
||||||
|
|
||||||
|
return checkSound(SOUND, selectSoundFromConfig, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sound checkSound(String sound1_8, String sound1_13, String selectSoundFromConfig, String prefix) {
|
||||||
|
String SOUND;
|
||||||
|
if (MCVersion.minecraft1_8) {
|
||||||
|
SOUND = sound1_8;
|
||||||
|
} else SOUND = sound1_13;
|
||||||
|
|
||||||
|
return checkSound(SOUND, selectSoundFromConfig, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sound checkSound(String sound, String selectSoundFromConfig, String prefix) {
|
||||||
|
try {
|
||||||
|
return Sound.valueOf(selectSoundFromConfig);
|
||||||
|
} catch (Exception e) {
|
||||||
|
send.console("§4\n§4\n§4\n" + SelectLibMsg.soundNotFound.replace("[prefix]", prefix)
|
||||||
|
.replace("[sound]", "§8Buy: §6" + selectSoundFromConfig) + "§4\n§4\n§4\n");
|
||||||
|
return Sound.valueOf(sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String select(String prefix, String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return Replace.replace(prefix, yamlConfiguration.getString(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Integer selectInt(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getInt(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean selectBoolean(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getBoolean(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double selectDouble(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getDouble(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> selectList(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getStringList(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack selectItemStack(String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
return (yamlConfiguration.getItemStack(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<String> selectList(String prefix, String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
List<String> input = yamlConfiguration.getStringList(path);
|
||||||
|
for (String st : input) {
|
||||||
|
output.add(Replace.replace(prefix, st));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void select(String prefix, List<String> value, String path, YamlConfiguration yamlConfiguration) {
|
||||||
|
List<String> output = new ArrayList<>();
|
||||||
|
List<String> input = yamlConfiguration.getStringList(path);
|
||||||
|
for (String st : input) {
|
||||||
|
output.add(Replace.replace(prefix, st));
|
||||||
|
}
|
||||||
|
value = output;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,115 @@
|
|||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||||
|
import net.t2code.lib.Spigot.system.config.SelectLibConfig;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CmdExecuter implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (!sender.hasPermission("t2code.admin")) {
|
||||||
|
send.sender(sender, "§4No Permission §8t2code.admin");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (args.length == 0) {
|
||||||
|
T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), T2CodeMain.getAutor(), T2CodeMain.getVersion(), UpdateAPI.PluginVersionen.get(T2CodeMain.getPlugin().getName()).publicVersion);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "info":
|
||||||
|
case "plugin":
|
||||||
|
case "pl":
|
||||||
|
case "version":
|
||||||
|
case "ver":
|
||||||
|
T2CodeTemplate.sendInfo(sender, Util.getPrefix(), Util.getSpigot(), Util.getDiscord(), T2CodeMain.getAutor(), T2CodeMain.getVersion(), UpdateAPI.PluginVersionen.get(T2CodeMain.getPerm().getName()).publicVersion);
|
||||||
|
return false;
|
||||||
|
case "reloadconfig":
|
||||||
|
SelectLibConfig.onSelect();
|
||||||
|
return false;
|
||||||
|
case "debug":
|
||||||
|
if (args.length != 2) {
|
||||||
|
send.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ("createreportlog".equals(args[1].toLowerCase())) {
|
||||||
|
CreateReportLog.create(sender);
|
||||||
|
} else send.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
||||||
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
send.sender(sender, "§4Use: §7/t2code debug createReportLog");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TabCompleter
|
||||||
|
private static HashMap<String, String> arg1 = new HashMap<String, String>() {{
|
||||||
|
put("debug", "t2code.admin");
|
||||||
|
put("info", "t2code.admin");
|
||||||
|
put("reloadconfig", "t2code.admin");
|
||||||
|
}};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command cmd, String s, String[] args) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
Player p = (Player) sender;
|
||||||
|
if (args.length == 1) {
|
||||||
|
for (String command : arg1.keySet()) {
|
||||||
|
if (hasPermission(p, arg1.get(command)) && passend(command, args[0])) {
|
||||||
|
list.add(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length == 2 && args[0].equalsIgnoreCase("debug")) {
|
||||||
|
if (sender.hasPermission("t2code.admin")) {
|
||||||
|
if (hasPermission(p, arg1.get("debug")) && passend("debug", args[1])) {
|
||||||
|
list.add("createReportLog");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Boolean passend(String command, String arg) {
|
||||||
|
for (int i = 0; i < arg.toUpperCase().length(); i++) {
|
||||||
|
if (arg.toUpperCase().length() >= command.toUpperCase().length()) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (arg.toUpperCase().charAt(i) != command.toUpperCase().charAt(i)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean hasPermission(Player player, String permission) {
|
||||||
|
if (player.isOp()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String[] Permissions = permission.split(";");
|
||||||
|
for (String perm : Permissions) {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,199 @@
|
|||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.NMSVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
import net.t2code.luckyBox.api.LuckyBoxAPI;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
public class CreateReportLog {
|
||||||
|
protected static void create(CommandSender sender) {
|
||||||
|
send.sender(sender, T2CodeMain.getPrefix() + " §6A DebugLog is created...");
|
||||||
|
String timeStampFile = new SimpleDateFormat("HH_mm_ss-dd_MM_yyyy").format(Calendar.getInstance().getTime());
|
||||||
|
|
||||||
|
File directory = new File(T2CodeMain.getPath() + "/DebugLogs");
|
||||||
|
if (!directory.exists()) {
|
||||||
|
directory.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(T2CodeMain.getPath(), "/DebugLogs/T2CodeLog.txt");
|
||||||
|
PrintWriter pWriter = null;
|
||||||
|
try {
|
||||||
|
pWriter = new PrintWriter(new FileWriter(file.getPath()));
|
||||||
|
String timeStamp = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy").format(Calendar.getInstance().getTime());
|
||||||
|
pWriter.println("Created on: " + timeStamp);
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("Server Bukkit version: " + MCVersion.isBuckitVersion);
|
||||||
|
pWriter.println("Server run on: " + MCVersion.isVersion);
|
||||||
|
pWriter.println("Server NMS: " + NMSVersion.isNMS);
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("Online Mode: " + Bukkit.getOnlineMode());
|
||||||
|
pWriter.println("Worlds: " + Bukkit.getWorlds());
|
||||||
|
pWriter.println("OP-Player:");
|
||||||
|
for (OfflinePlayer player : Bukkit.getOperators()) {
|
||||||
|
pWriter.println(" - Player: " + player.getName() + " - " + player.getUniqueId());
|
||||||
|
}
|
||||||
|
pWriter.println();
|
||||||
|
if (Vault.vaultEnable) {
|
||||||
|
pWriter.println("Vault: " + Bukkit.getPluginManager().getPlugin("Vault").getName() + " - " + Bukkit.getPluginManager().getPlugin("Vault").getDescription().getVersion());
|
||||||
|
} else pWriter.println("Vault: not connected");
|
||||||
|
if (T2CodeMain.getEco() != null) {
|
||||||
|
String st = T2CodeMain.getEco().getName();
|
||||||
|
if (T2CodeMain.getEco().getName().equals("CMIEconomy")) st = "CMI";
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(st) != null) {
|
||||||
|
pWriter.println("Economy: " + T2CodeMain.getEco().isEnabled() + " - " + st + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion());
|
||||||
|
} else pWriter.println("Economy: " + T2CodeMain.getEco().isEnabled() + " - " + st);
|
||||||
|
} else pWriter.println("Economy: not connected via vault");
|
||||||
|
if (T2CodeMain.getPerm() != null) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(T2CodeMain.getPerm().getName()) != null) {
|
||||||
|
pWriter.println("Permission: " + T2CodeMain.getPerm().isEnabled() + " - " + T2CodeMain.getPerm().getName() + " - " + Bukkit.getPluginManager().getPlugin(T2CodeMain.getPerm().getName()).getDescription().getVersion());
|
||||||
|
} else pWriter.println("Permission: " + T2CodeMain.getPerm().isEnabled() + " - " + T2CodeMain.getPerm().getName());
|
||||||
|
} else pWriter.println("Permission: not connected via vault");
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("Java: " + System.getProperty("java.version"));
|
||||||
|
pWriter.println("System: " + System.getProperty("os.name"));
|
||||||
|
pWriter.println("System: " + System.getProperty("os.version"));
|
||||||
|
pWriter.println("User Home: " + System.getProperty("user.home"));
|
||||||
|
pWriter.println();
|
||||||
|
pWriter.println("T2CodeLib: " + T2CodeMain.getPlugin().getDescription().getVersion());
|
||||||
|
pWriter.println();
|
||||||
|
if (PluginCheck.luckyBox()) {
|
||||||
|
pWriter.println("T2C-PremiumPlugins: ");
|
||||||
|
pWriter.println("T2C-LuckyBox UID: " + LuckyBoxAPI.getUID());
|
||||||
|
pWriter.println("T2C-LuckyBox RID: " + LuckyBoxAPI.getRID());
|
||||||
|
pWriter.println("T2C-LuckyBox DID: " + LuckyBoxAPI.getDID());
|
||||||
|
pWriter.println("T2C-LuckyBox isP: " + LuckyBoxAPI.isP());
|
||||||
|
pWriter.println("T2C-LuckyBox isV: " + LuckyBoxAPI.isV());
|
||||||
|
pWriter.println();
|
||||||
|
}
|
||||||
|
pWriter.println("Plugins: ");
|
||||||
|
for (Plugin pl : Bukkit.getPluginManager().getPlugins()) {
|
||||||
|
pWriter.println(" - " + pl.getName() + " - " + pl.getDescription().getVersion() + " - Enabled: " + pl.isEnabled() + " - Autors: " + pl.getDescription().getAuthors() + " - Website: " + pl.getDescription().getWebsite());
|
||||||
|
}
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
ioe.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (pWriter != null) {
|
||||||
|
pWriter.flush();
|
||||||
|
pWriter.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String filePath = T2CodeMain.getPath() + "/DebugLogs/T2CodeLog.txt";
|
||||||
|
String log = "logs/latest.log";
|
||||||
|
String zipPath = "plugins/T2CodeLib/DebugLogs/T2CLog-" + timeStampFile + ".zip";
|
||||||
|
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipPath))) {
|
||||||
|
File fileToZip = new File(filePath);
|
||||||
|
zip.putNextEntry(new ZipEntry(fileToZip.getName()));
|
||||||
|
Files.copy(fileToZip.toPath(), zip);
|
||||||
|
|
||||||
|
addFileToZip("", "logs/latest.log", zip, false);
|
||||||
|
|
||||||
|
for (String pl : Util.getT2cPlugins()){
|
||||||
|
pluginToDebug(pl, zip);
|
||||||
|
}
|
||||||
|
|
||||||
|
//pluginToDebug("T2C-LuckyBox", zip);
|
||||||
|
//pluginToDebug("WonderBagShop", zip);
|
||||||
|
//pluginToDebug("CommandGUI", zip);
|
||||||
|
//pluginToDebug("OPSecurity", zip);
|
||||||
|
//pluginToDebug("PaPiTest", zip);
|
||||||
|
//pluginToDebug("PlotSquaredGUI", zip);
|
||||||
|
//pluginToDebug("T2C-Alias", zip);
|
||||||
|
//pluginToDebug("T2C-AutoResponse", zip);
|
||||||
|
//
|
||||||
|
//pluginToDebug("LoreEditor", zip);
|
||||||
|
//pluginToDebug("Booster", zip);
|
||||||
|
//pluginToDebug("AntiMapCopy", zip);
|
||||||
|
//pluginToDebug("AntiCopy", zip);
|
||||||
|
|
||||||
|
zip.closeEntry();
|
||||||
|
zip.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
file.delete();
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
send.sender(sender, T2CodeMain.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
||||||
|
send.console(T2CodeMain.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
||||||
|
} else send.sender(sender, T2CodeMain.getPrefix() + " §6A DebugLog zip has been created. you can find it on in the files on your server under the path: §e" + zipPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void pluginToDebug(String pluginName, ZipOutputStream zip) throws IOException {
|
||||||
|
if (PluginCheck.pluginCheck(pluginName)) {
|
||||||
|
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||||
|
File plConfigs = new File(plugin.getDataFolder().getPath());
|
||||||
|
if (plConfigs.exists()) {
|
||||||
|
addFolderToZip("T2Code-Plugins", plugin.getDataFolder().getPath(), zip);
|
||||||
|
}
|
||||||
|
File f = new File("plugins/");
|
||||||
|
File[] fileArray = f.listFiles();
|
||||||
|
|
||||||
|
for (File config : fileArray) {
|
||||||
|
if (config.getName().contains(pluginName) && config.getName().contains(".jar")) {
|
||||||
|
addFileToZip("T2Code-Plugins", config.getPath(), zip, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFolderToZip(String path, String srcFolder, ZipOutputStream zip) throws IOException {
|
||||||
|
File folder = new File(srcFolder);
|
||||||
|
if (folder.list() == null) {
|
||||||
|
addFileToZip(path + "/" + folder.getName(), srcFolder, zip, false);
|
||||||
|
} else if (folder.list().length == 0) {
|
||||||
|
addFileToZip(path, srcFolder, zip, true);
|
||||||
|
} else {
|
||||||
|
for (String fileName : folder.list()) {
|
||||||
|
if (path.equals("")) {
|
||||||
|
addFileToZip(folder.getName(), srcFolder + "/" + fileName, zip, false);
|
||||||
|
} else {
|
||||||
|
addFileToZip(path + "/" + folder.getName(), srcFolder + "/" + fileName, zip, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean flag) throws IOException {
|
||||||
|
File folder = new File(srcFile);
|
||||||
|
if (flag) {
|
||||||
|
zip.putNextEntry(new ZipEntry(path + "/" + folder.getName() + "/"));
|
||||||
|
} else {
|
||||||
|
if (folder.isDirectory()) {
|
||||||
|
addFolderToZip(path, srcFile, zip);
|
||||||
|
} else {
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
FileInputStream in = new FileInputStream(srcFile);
|
||||||
|
|
||||||
|
if (path.equals("")) {
|
||||||
|
zip.putNextEntry(new ZipEntry((folder.getName())));
|
||||||
|
} else {
|
||||||
|
zip.putNextEntry(new ZipEntry((path + "/" + folder.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
try {
|
||||||
|
zip.write(buf, 0, len);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
// This claas was created by JaTiTV
|
||||||
|
|
||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
|
||||||
|
public class JoinEvent implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoinEvent(PlayerLoginEvent event) {
|
||||||
|
UpdateAPI.join(T2CodeMain.getPlugin(), Util.getPrefix(), "t2code.lib.updatemsg", event.getPlayer(), T2CodeMain.getSpigot(), T2CodeMain.getDiscord());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,851 @@
|
|||||||
|
// This claas was created by JaTiTV
|
||||||
|
|
||||||
|
|
||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.system.config.SelectLibConfig;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.*;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
public class Metrics {
|
||||||
|
|
||||||
|
public static void Bstats(Plugin plugin, int bstatsID) {
|
||||||
|
int pluginId = bstatsID; // <-- Replace with the id of your plugin!
|
||||||
|
Metrics metrics = new Metrics((JavaPlugin) plugin, pluginId);
|
||||||
|
metrics.addCustomChart(new SimplePie("updatecheckonjoin", () -> String.valueOf(SelectLibConfig.getUpdateCheckOnJoin())));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
private final MetricsBase metricsBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Metrics instance.
|
||||||
|
*
|
||||||
|
* @param plugin Your plugin instance.
|
||||||
|
* @param serviceId The id of the service. It can be found at <a
|
||||||
|
* href="https://bstats.org/what-is-my-plugin-id">What is my plugin id?</a>
|
||||||
|
*/
|
||||||
|
public Metrics(JavaPlugin plugin, int serviceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
// Get the config file
|
||||||
|
File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats");
|
||||||
|
File configFile = new File(bStatsFolder, "config.yml");
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
|
if (!config.isSet("serverUuid")) {
|
||||||
|
config.addDefault("enabled", true);
|
||||||
|
config.addDefault("serverUuid", UUID.randomUUID().toString());
|
||||||
|
config.addDefault("logFailedRequests", false);
|
||||||
|
config.addDefault("logSentData", false);
|
||||||
|
config.addDefault("logResponseStatusText", false);
|
||||||
|
// Inform the server owners about bStats
|
||||||
|
config
|
||||||
|
.options()
|
||||||
|
.header(
|
||||||
|
"bStats (https://bStats.org) collects some basic information for plugin authors, like how\n"
|
||||||
|
+ "many people use their plugin and their total player count. It's recommended to keep bStats\n"
|
||||||
|
+ "enabled, but if you're not comfortable with this, you can turn this setting off. There is no\n"
|
||||||
|
+ "performance penalty associated with having metrics enabled, and data sent to bStats is fully\n"
|
||||||
|
+ "anonymous.")
|
||||||
|
.copyDefaults(true);
|
||||||
|
try {
|
||||||
|
config.save(configFile);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Load the data
|
||||||
|
boolean enabled = config.getBoolean("enabled", true);
|
||||||
|
String serverUUID = config.getString("serverUuid");
|
||||||
|
boolean logErrors = config.getBoolean("logFailedRequests", false);
|
||||||
|
boolean logSentData = config.getBoolean("logSentData", false);
|
||||||
|
boolean logResponseStatusText = config.getBoolean("logResponseStatusText", false);
|
||||||
|
metricsBase =
|
||||||
|
new MetricsBase(
|
||||||
|
"bukkit",
|
||||||
|
serverUUID,
|
||||||
|
serviceId,
|
||||||
|
enabled,
|
||||||
|
this::appendPlatformData,
|
||||||
|
this::appendServiceData,
|
||||||
|
submitDataTask -> Bukkit.getScheduler().runTask(plugin, submitDataTask),
|
||||||
|
plugin::isEnabled,
|
||||||
|
(message, error) -> this.plugin.getLogger().log(Level.WARNING, message, error),
|
||||||
|
(message) -> this.plugin.getLogger().log(Level.INFO, message),
|
||||||
|
logErrors,
|
||||||
|
logSentData,
|
||||||
|
logResponseStatusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom chart.
|
||||||
|
*
|
||||||
|
* @param chart The chart to add.
|
||||||
|
*/
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
metricsBase.addCustomChart(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendPlatformData(JsonObjectBuilder builder) {
|
||||||
|
builder.appendField("playerAmount", getPlayerAmount());
|
||||||
|
builder.appendField("onlineMode", Bukkit.getOnlineMode() ? 1 : 0);
|
||||||
|
builder.appendField("bukkitVersion", Bukkit.getVersion());
|
||||||
|
builder.appendField("bukkitName", Bukkit.getName());
|
||||||
|
builder.appendField("javaVersion", System.getProperty("java.version"));
|
||||||
|
builder.appendField("osName", System.getProperty("os.name"));
|
||||||
|
builder.appendField("osArch", System.getProperty("os.arch"));
|
||||||
|
builder.appendField("osVersion", System.getProperty("os.version"));
|
||||||
|
builder.appendField("coreCount", Runtime.getRuntime().availableProcessors());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendServiceData(JsonObjectBuilder builder) {
|
||||||
|
builder.appendField("pluginVersion", plugin.getDescription().getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPlayerAmount() {
|
||||||
|
try {
|
||||||
|
// Around MC 1.8 the return type was changed from an array to a collection,
|
||||||
|
// This fixes java.lang.NoSuchMethodError:
|
||||||
|
// org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection;
|
||||||
|
Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers");
|
||||||
|
return onlinePlayersMethod.getReturnType().equals(Collection.class)
|
||||||
|
? ((Collection<?>) onlinePlayersMethod.invoke(Bukkit.getServer())).size()
|
||||||
|
: ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Just use the new method if the reflection failed
|
||||||
|
return Bukkit.getOnlinePlayers().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MetricsBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version of the Metrics class.
|
||||||
|
*/
|
||||||
|
public static final String METRICS_VERSION = "2.2.1";
|
||||||
|
|
||||||
|
private static final ScheduledExecutorService scheduler =
|
||||||
|
Executors.newScheduledThreadPool(1, task -> new Thread(task, "bStats-Metrics"));
|
||||||
|
|
||||||
|
private static final String REPORT_URL = "https://bStats.org/api/v2/data/%s";
|
||||||
|
|
||||||
|
private final String platform;
|
||||||
|
|
||||||
|
private final String serverUuid;
|
||||||
|
|
||||||
|
private final int serviceId;
|
||||||
|
|
||||||
|
private final Consumer<JsonObjectBuilder> appendPlatformDataConsumer;
|
||||||
|
|
||||||
|
private final Consumer<JsonObjectBuilder> appendServiceDataConsumer;
|
||||||
|
|
||||||
|
private final Consumer<Runnable> submitTaskConsumer;
|
||||||
|
|
||||||
|
private final Supplier<Boolean> checkServiceEnabledSupplier;
|
||||||
|
|
||||||
|
private final BiConsumer<String, Throwable> errorLogger;
|
||||||
|
|
||||||
|
private final Consumer<String> infoLogger;
|
||||||
|
|
||||||
|
private final boolean logErrors;
|
||||||
|
|
||||||
|
private final boolean logSentData;
|
||||||
|
|
||||||
|
private final boolean logResponseStatusText;
|
||||||
|
|
||||||
|
private final Set<CustomChart> customCharts = new HashSet<>();
|
||||||
|
|
||||||
|
private final boolean enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new MetricsBase class instance.
|
||||||
|
*
|
||||||
|
* @param platform The platform of the service.
|
||||||
|
* @param serviceId The id of the service.
|
||||||
|
* @param serverUuid The server uuid.
|
||||||
|
* @param enabled Whether or not data sending is enabled.
|
||||||
|
* @param appendPlatformDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||||
|
* appends all platform-specific data.
|
||||||
|
* @param appendServiceDataConsumer A consumer that receives a {@code JsonObjectBuilder} and
|
||||||
|
* appends all service-specific data.
|
||||||
|
* @param submitTaskConsumer A consumer that takes a runnable with the submit task. This can be
|
||||||
|
* used to delegate the data collection to a another thread to prevent errors caused by
|
||||||
|
* concurrency. Can be {@code null}.
|
||||||
|
* @param checkServiceEnabledSupplier A supplier to check if the service is still enabled.
|
||||||
|
* @param errorLogger A consumer that accepts log message and an error.
|
||||||
|
* @param infoLogger A consumer that accepts info log messages.
|
||||||
|
* @param logErrors Whether or not errors should be logged.
|
||||||
|
* @param logSentData Whether or not the sent data should be logged.
|
||||||
|
* @param logResponseStatusText Whether or not the response status text should be logged.
|
||||||
|
*/
|
||||||
|
public MetricsBase(
|
||||||
|
String platform,
|
||||||
|
String serverUuid,
|
||||||
|
int serviceId,
|
||||||
|
boolean enabled,
|
||||||
|
Consumer<JsonObjectBuilder> appendPlatformDataConsumer,
|
||||||
|
Consumer<JsonObjectBuilder> appendServiceDataConsumer,
|
||||||
|
Consumer<Runnable> submitTaskConsumer,
|
||||||
|
Supplier<Boolean> checkServiceEnabledSupplier,
|
||||||
|
BiConsumer<String, Throwable> errorLogger,
|
||||||
|
Consumer<String> infoLogger,
|
||||||
|
boolean logErrors,
|
||||||
|
boolean logSentData,
|
||||||
|
boolean logResponseStatusText) {
|
||||||
|
this.platform = platform;
|
||||||
|
this.serverUuid = serverUuid;
|
||||||
|
this.serviceId = serviceId;
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.appendPlatformDataConsumer = appendPlatformDataConsumer;
|
||||||
|
this.appendServiceDataConsumer = appendServiceDataConsumer;
|
||||||
|
this.submitTaskConsumer = submitTaskConsumer;
|
||||||
|
this.checkServiceEnabledSupplier = checkServiceEnabledSupplier;
|
||||||
|
this.errorLogger = errorLogger;
|
||||||
|
this.infoLogger = infoLogger;
|
||||||
|
this.logErrors = logErrors;
|
||||||
|
this.logSentData = logSentData;
|
||||||
|
this.logResponseStatusText = logResponseStatusText;
|
||||||
|
checkRelocation();
|
||||||
|
if (enabled) {
|
||||||
|
startSubmitting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCustomChart(CustomChart chart) {
|
||||||
|
this.customCharts.add(chart);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startSubmitting() {
|
||||||
|
final Runnable submitTask =
|
||||||
|
() -> {
|
||||||
|
if (!enabled || !checkServiceEnabledSupplier.get()) {
|
||||||
|
// Submitting data or service is disabled
|
||||||
|
scheduler.shutdown();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (submitTaskConsumer != null) {
|
||||||
|
submitTaskConsumer.accept(this::submitData);
|
||||||
|
} else {
|
||||||
|
this.submitData();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Many servers tend to restart at a fixed time at xx:00 which causes an uneven distribution
|
||||||
|
// of requests on the
|
||||||
|
// bStats backend. To circumvent this problem, we introduce some randomness into the initial
|
||||||
|
// and second delay.
|
||||||
|
// WARNING: You must not modify and part of this Metrics class, including the submit delay or
|
||||||
|
// frequency!
|
||||||
|
// WARNING: Modifying this code will get your plugin banned on bStats. Just don't do it!
|
||||||
|
long initialDelay = (long) (1000 * 60 * (3 + Math.random() * 3));
|
||||||
|
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
|
||||||
|
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
|
||||||
|
scheduler.scheduleAtFixedRate(
|
||||||
|
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void submitData() {
|
||||||
|
final JsonObjectBuilder baseJsonBuilder = new JsonObjectBuilder();
|
||||||
|
appendPlatformDataConsumer.accept(baseJsonBuilder);
|
||||||
|
final JsonObjectBuilder serviceJsonBuilder = new JsonObjectBuilder();
|
||||||
|
appendServiceDataConsumer.accept(serviceJsonBuilder);
|
||||||
|
JsonObjectBuilder.JsonObject[] chartData =
|
||||||
|
customCharts.stream()
|
||||||
|
.map(customChart -> customChart.getRequestJsonObject(errorLogger, logErrors))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toArray(JsonObjectBuilder.JsonObject[]::new);
|
||||||
|
serviceJsonBuilder.appendField("id", serviceId);
|
||||||
|
serviceJsonBuilder.appendField("customCharts", chartData);
|
||||||
|
baseJsonBuilder.appendField("service", serviceJsonBuilder.build());
|
||||||
|
baseJsonBuilder.appendField("serverUUID", serverUuid);
|
||||||
|
baseJsonBuilder.appendField("metricsVersion", METRICS_VERSION);
|
||||||
|
JsonObjectBuilder.JsonObject data = baseJsonBuilder.build();
|
||||||
|
scheduler.execute(
|
||||||
|
() -> {
|
||||||
|
try {
|
||||||
|
// Send the data
|
||||||
|
sendData(data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Something went wrong! :(
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Could not submit bStats metrics data", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendData(JsonObjectBuilder.JsonObject data) throws Exception {
|
||||||
|
if (logSentData) {
|
||||||
|
infoLogger.accept("Sent bStats metrics data: " + data.toString());
|
||||||
|
}
|
||||||
|
String url = String.format(REPORT_URL, platform);
|
||||||
|
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||||
|
// Compress the data to save bandwidth
|
||||||
|
byte[] compressedData = compress(data.toString());
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.addRequestProperty("Accept", "application/json");
|
||||||
|
connection.addRequestProperty("Connection", "close");
|
||||||
|
connection.addRequestProperty("Content-Encoding", "gzip");
|
||||||
|
connection.addRequestProperty("Content-Length", String.valueOf(compressedData.length));
|
||||||
|
connection.setRequestProperty("Content-Type", "application/json");
|
||||||
|
connection.setRequestProperty("User-Agent", "Metrics-Service/1");
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||||
|
outputStream.write(compressedData);
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
try (BufferedReader bufferedReader =
|
||||||
|
new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
while ((line = bufferedReader.readLine()) != null) {
|
||||||
|
builder.append(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (logResponseStatusText) {
|
||||||
|
infoLogger.accept("Sent data to bStats and received response: " + builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that the class was properly relocated.
|
||||||
|
*/
|
||||||
|
private void checkRelocation() {
|
||||||
|
// You can use the property to disable the check in your test environment
|
||||||
|
if (System.getProperty("bstats.relocatecheck") == null
|
||||||
|
|| !System.getProperty("bstats.relocatecheck").equals("false")) {
|
||||||
|
// Maven's Relocate is clever and changes strings, too. So we have to use this little
|
||||||
|
// "trick" ... :D
|
||||||
|
final String defaultPackage =
|
||||||
|
new String(new byte[]{'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's'});
|
||||||
|
final String examplePackage =
|
||||||
|
new String(new byte[]{'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e'});
|
||||||
|
// We want to make sure no one just copy & pastes the example and uses the wrong package
|
||||||
|
// names
|
||||||
|
if (MetricsBase.class.getPackage().getName().startsWith(defaultPackage)
|
||||||
|
|| MetricsBase.class.getPackage().getName().startsWith(examplePackage)) {
|
||||||
|
throw new IllegalStateException("bStats Metrics class has not been relocated correctly!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gzips the given string.
|
||||||
|
*
|
||||||
|
* @param str The string to gzip.
|
||||||
|
* @return The gzipped string.
|
||||||
|
*/
|
||||||
|
private static byte[] compress(final String str) throws IOException {
|
||||||
|
if (str == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) {
|
||||||
|
gzip.write(str.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
return outputStream.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AdvancedBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, int[]>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedBarChart(String chartId, Callable<Map<String, int[]>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, int[]> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, int[]> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue().length == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SimpleBarChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimpleBarChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
valuesBuilder.appendField(entry.getKey(), new int[]{entry.getValue()});
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class MultiLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public MultiLineChart(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class AdvancedPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Integer>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public AdvancedPie(String chartId, Callable<Map<String, Integer>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Integer> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
||||||
|
if (entry.getValue() == 0) {
|
||||||
|
// Skip this invalid
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
allSkipped = false;
|
||||||
|
valuesBuilder.appendField(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
if (allSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class CustomChart {
|
||||||
|
|
||||||
|
private final String chartId;
|
||||||
|
|
||||||
|
protected CustomChart(String chartId) {
|
||||||
|
if (chartId == null) {
|
||||||
|
throw new IllegalArgumentException("chartId must not be null");
|
||||||
|
}
|
||||||
|
this.chartId = chartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonObjectBuilder.JsonObject getRequestJsonObject(
|
||||||
|
BiConsumer<String, Throwable> errorLogger, boolean logErrors) {
|
||||||
|
JsonObjectBuilder builder = new JsonObjectBuilder();
|
||||||
|
builder.appendField("chartId", chartId);
|
||||||
|
try {
|
||||||
|
JsonObjectBuilder.JsonObject data = getChartData();
|
||||||
|
if (data == null) {
|
||||||
|
// If the data is null we don't send the chart.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
builder.appendField("data", data);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (logErrors) {
|
||||||
|
errorLogger.accept("Failed to get data for custom chart with id " + chartId, t);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract JsonObjectBuilder.JsonObject getChartData() throws Exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SingleLineChart extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Integer> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SingleLineChart(String chartId, Callable<Integer> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
int value = callable.call();
|
||||||
|
if (value == 0) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("value", value).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class SimplePie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<String> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public SimplePie(String chartId, Callable<String> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
String value = callable.call();
|
||||||
|
if (value == null || value.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("value", value).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DrilldownPie extends CustomChart {
|
||||||
|
|
||||||
|
private final Callable<Map<String, Map<String, Integer>>> callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param chartId The id of the chart.
|
||||||
|
* @param callable The callable which is used to request the chart data.
|
||||||
|
*/
|
||||||
|
public DrilldownPie(String chartId, Callable<Map<String, Map<String, Integer>>> callable) {
|
||||||
|
super(chartId);
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JsonObjectBuilder.JsonObject getChartData() throws Exception {
|
||||||
|
JsonObjectBuilder valuesBuilder = new JsonObjectBuilder();
|
||||||
|
Map<String, Map<String, Integer>> map = callable.call();
|
||||||
|
if (map == null || map.isEmpty()) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
boolean reallyAllSkipped = true;
|
||||||
|
for (Map.Entry<String, Map<String, Integer>> entryValues : map.entrySet()) {
|
||||||
|
JsonObjectBuilder valueBuilder = new JsonObjectBuilder();
|
||||||
|
boolean allSkipped = true;
|
||||||
|
for (Map.Entry<String, Integer> valueEntry : map.get(entryValues.getKey()).entrySet()) {
|
||||||
|
valueBuilder.appendField(valueEntry.getKey(), valueEntry.getValue());
|
||||||
|
allSkipped = false;
|
||||||
|
}
|
||||||
|
if (!allSkipped) {
|
||||||
|
reallyAllSkipped = false;
|
||||||
|
valuesBuilder.appendField(entryValues.getKey(), valueBuilder.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (reallyAllSkipped) {
|
||||||
|
// Null = skip the chart
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new JsonObjectBuilder().appendField("values", valuesBuilder.build()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An extremely simple JSON builder.
|
||||||
|
*
|
||||||
|
* <p>While this class is neither feature-rich nor the most performant one, it's sufficient enough
|
||||||
|
* for its use-case.
|
||||||
|
*/
|
||||||
|
public static class JsonObjectBuilder {
|
||||||
|
|
||||||
|
private StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
private boolean hasAtLeastOneField = false;
|
||||||
|
|
||||||
|
public JsonObjectBuilder() {
|
||||||
|
builder.append("{");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a null field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendNull(String key) {
|
||||||
|
appendFieldUnescaped(key, "null");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param value The value of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, String value) {
|
||||||
|
if (value == null) {
|
||||||
|
throw new IllegalArgumentException("JSON value must not be null");
|
||||||
|
}
|
||||||
|
appendFieldUnescaped(key, "\"" + escape(value) + "\"");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an integer field to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param value The value of the field.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, int value) {
|
||||||
|
appendFieldUnescaped(key, String.valueOf(value));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an object to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param object The object.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, JsonObject object) {
|
||||||
|
if (object == null) {
|
||||||
|
throw new IllegalArgumentException("JSON object must not be null");
|
||||||
|
}
|
||||||
|
appendFieldUnescaped(key, object.toString());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a string array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The string array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, String[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values)
|
||||||
|
.map(value -> "\"" + escape(value) + "\"")
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an integer array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The integer array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, int[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values).mapToObj(String::valueOf).collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends an object array to the JSON.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param values The integer array.
|
||||||
|
* @return A reference to this object.
|
||||||
|
*/
|
||||||
|
public JsonObjectBuilder appendField(String key, JsonObject[] values) {
|
||||||
|
if (values == null) {
|
||||||
|
throw new IllegalArgumentException("JSON values must not be null");
|
||||||
|
}
|
||||||
|
String escapedValues =
|
||||||
|
Arrays.stream(values).map(JsonObject::toString).collect(Collectors.joining(","));
|
||||||
|
appendFieldUnescaped(key, "[" + escapedValues + "]");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Appends a field to the object.
|
||||||
|
*
|
||||||
|
* @param key The key of the field.
|
||||||
|
* @param escapedValue The escaped value of the field.
|
||||||
|
*/
|
||||||
|
private void appendFieldUnescaped(String key, String escapedValue) {
|
||||||
|
if (builder == null) {
|
||||||
|
throw new IllegalStateException("JSON has already been built");
|
||||||
|
}
|
||||||
|
if (key == null) {
|
||||||
|
throw new IllegalArgumentException("JSON key must not be null");
|
||||||
|
}
|
||||||
|
if (hasAtLeastOneField) {
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
builder.append("\"").append(escape(key)).append("\":").append(escapedValue);
|
||||||
|
hasAtLeastOneField = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the JSON string and invalidates this builder.
|
||||||
|
*
|
||||||
|
* @return The built JSON string.
|
||||||
|
*/
|
||||||
|
public JsonObject build() {
|
||||||
|
if (builder == null) {
|
||||||
|
throw new IllegalStateException("JSON has already been built");
|
||||||
|
}
|
||||||
|
JsonObject object = new JsonObject(builder.append("}").toString());
|
||||||
|
builder = null;
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escapes the given string like stated in https://www.ietf.org/rfc/rfc4627.txt.
|
||||||
|
*
|
||||||
|
* <p>This method escapes only the necessary characters '"', '\'. and '\u0000' - '\u001F'.
|
||||||
|
* Compact escapes are not used (e.g., '\n' is escaped as "\u000a" and not as "\n").
|
||||||
|
*
|
||||||
|
* @param value The value to escape.
|
||||||
|
* @return The escaped value.
|
||||||
|
*/
|
||||||
|
private static String escape(String value) {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < value.length(); i++) {
|
||||||
|
char c = value.charAt(i);
|
||||||
|
if (c == '"') {
|
||||||
|
builder.append("\\\"");
|
||||||
|
} else if (c == '\\') {
|
||||||
|
builder.append("\\\\");
|
||||||
|
} else if (c <= '\u000F') {
|
||||||
|
builder.append("\\u000").append(Integer.toHexString(c));
|
||||||
|
} else if (c <= '\u001F') {
|
||||||
|
builder.append("\\u00").append(Integer.toHexString(c));
|
||||||
|
} else {
|
||||||
|
builder.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A super simple representation of a JSON object.
|
||||||
|
*
|
||||||
|
* <p>This class only exists to make methods of the {@link JsonObjectBuilder} type-safe and not
|
||||||
|
* allow a raw string inputs for methods like {@link JsonObjectBuilder#appendField(String,
|
||||||
|
* JsonObject)}.
|
||||||
|
*/
|
||||||
|
public static class JsonObject {
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
private JsonObject(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,192 @@
|
|||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import net.t2code.lib.Spigot.Lib.items.ItemVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.MCVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.minecraftVersion.NMSVersion;
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.T2CodeTemplate;
|
||||||
|
import net.t2code.lib.Spigot.Lib.plugins.PluginCheck;
|
||||||
|
import net.t2code.lib.Spigot.Lib.update.UpdateAPI;
|
||||||
|
import net.t2code.lib.Spigot.system.config.ConfigCreate;
|
||||||
|
import net.t2code.lib.Spigot.system.languages.LanguagesCreate;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
import net.t2code.lib.Spigot.system.config.SelectLibConfig;
|
||||||
|
import net.t2code.lib.Spigot.system.languages.SelectLibMsg;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class T2CodeMain extends JavaPlugin {
|
||||||
|
|
||||||
|
public static File getPath() {
|
||||||
|
return plugin.getDataFolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BukkitAudiences adventure;
|
||||||
|
public static BukkitAudiences adventure() {
|
||||||
|
if(adventure == null) {
|
||||||
|
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||||
|
}
|
||||||
|
return adventure;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static T2CodeMain plugin;
|
||||||
|
private static Economy eco = null;
|
||||||
|
private static Permission perm = null;
|
||||||
|
|
||||||
|
private static List<String> autor;
|
||||||
|
private static String version;
|
||||||
|
|
||||||
|
private static String prefix = Util.getPrefix();
|
||||||
|
private static Integer spigotID = Util.getSpigotID();
|
||||||
|
private static Integer bstatsID = Util.getBstatsID();
|
||||||
|
private static String spigot = Util.getSpigot();
|
||||||
|
private static String discord = Util.getDiscord();
|
||||||
|
|
||||||
|
private static Boolean load = false;
|
||||||
|
|
||||||
|
public static String getDiscord() {
|
||||||
|
return discord;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T2CodeMain getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Economy getEco() {
|
||||||
|
return eco;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setEco(Economy eco) {
|
||||||
|
T2CodeMain.eco = eco;
|
||||||
|
}
|
||||||
|
public static Permission getPerm() {
|
||||||
|
return perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getAutor() {
|
||||||
|
return autor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPrefix() {
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getSpigotID() {
|
||||||
|
return spigotID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getBstatsID() {
|
||||||
|
return bstatsID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSpigot() {
|
||||||
|
return spigot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getLoad() {
|
||||||
|
return load;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setPerm(Permission perm) {
|
||||||
|
T2CodeMain.perm = perm;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
// Plugin startup logic
|
||||||
|
plugin = this;
|
||||||
|
autor = plugin.getDescription().getAuthors();
|
||||||
|
version = plugin.getDescription().getVersion();
|
||||||
|
this.adventure = BukkitAudiences.create(this);
|
||||||
|
long long_;
|
||||||
|
long_ = T2CodeTemplate.onLoadHeader(prefix, autor, version, spigot, discord);
|
||||||
|
if (Util.getSnapshot()) {
|
||||||
|
send.console(prefix + " §eYou are running §4" + version + " §eof " + prefix + "§e! §4This is a trial version! §eSome features may not be working as expected." +
|
||||||
|
" Please report all bugs here: http://dc.t2code.net §4UpdateChecker & bStats may be disabled!");
|
||||||
|
send.console(prefix + " §4 §e-------------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Vault.loadVault();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
NMSVersion.onCheck();
|
||||||
|
MCVersion.onCheck();
|
||||||
|
if (MCVersion.minecraft1_19) {
|
||||||
|
send.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
send.console(prefix );
|
||||||
|
send.warning(this, "The 1.19.* is a very fresh / new version. If there are any bugs in our plugins, please report them to us via our Discord: http://dc.t2code.net");
|
||||||
|
send.console(prefix);
|
||||||
|
send.console(prefix + " §4!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ItemVersion.scan();
|
||||||
|
send.console(T2CodeMain.prefix + " §3Server run on: §6" + MCVersion.isVersion + " / " + NMSVersion.isNMS);
|
||||||
|
if (eco != null) {
|
||||||
|
String st = eco.getName();
|
||||||
|
if (eco.getName().equals("CMIEconomy")) st = "CMI";
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(st) != null) {
|
||||||
|
send.console(T2CodeMain.prefix + " §3Economy: §6" + eco.getName() + " - " + Bukkit.getPluginManager().getPlugin(st).getDescription().getVersion() + " §7- §e" +
|
||||||
|
(System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else send.console(T2CodeMain.prefix + " §3Economy: §6" + eco.getName() + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else send.console(T2CodeMain.prefix + " §3Economy: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
|
||||||
|
if (perm != null) {
|
||||||
|
if (Bukkit.getPluginManager().getPlugin(perm.getName()) != null) {
|
||||||
|
send.console(T2CodeMain.prefix + " §3Permission plugin: §6" + perm.getName() + " - " + Bukkit.getPluginManager().getPlugin(perm.getName()).getDescription().getVersion()
|
||||||
|
+ " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else send.console(T2CodeMain.prefix + " §3Permission plugin: §6" + perm.getName() + " - §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else send.console(T2CodeMain.prefix + " §3Permission plugin: §4not connected via vault!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
|
||||||
|
if (PluginCheck.papi()) {
|
||||||
|
send.console(T2CodeMain.prefix + " §3PlaceholderAPI: §6connected" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
T2CodeMain.plugin.getCommand("t2code").setExecutor(new CmdExecuter());
|
||||||
|
ConfigCreate.configCreate();
|
||||||
|
LanguagesCreate.langCreate();
|
||||||
|
SelectLibConfig.onSelect();
|
||||||
|
SelectLibMsg.onSelect(prefix);
|
||||||
|
if (!Util.getSnapshot() || version.toLowerCase().contains("dev")) {
|
||||||
|
UpdateAPI.onUpdateCheck(plugin, prefix, spigot, spigotID, discord);
|
||||||
|
Metrics.Bstats(plugin, bstatsID);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bukkit.getServer().getPluginManager().registerEvents(new JoinEvent(), plugin);
|
||||||
|
T2CodeTemplate.onLoadFooter(prefix, long_);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
// Plugin shutdown logic
|
||||||
|
if (SelectLibConfig.getInventoriesCloseByServerStop()) {
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(this.adventure != null) {
|
||||||
|
this.adventure.close();
|
||||||
|
this.adventure = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vault.vaultDisable();
|
||||||
|
T2CodeTemplate.onDisable(prefix, autor, version, spigot, discord);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class UpdateChecker {
|
||||||
|
private final JavaPlugin plugin;
|
||||||
|
private final int resourceId;
|
||||||
|
|
||||||
|
public UpdateChecker(JavaPlugin plugin, int resourceId) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getVersion(final Consumer<String> consumer) {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
|
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
|
||||||
|
if (scanner.hasNext()) {
|
||||||
|
consumer.accept(scanner.next());
|
||||||
|
}
|
||||||
|
} catch (IOException exception) {
|
||||||
|
plugin.getLogger().info("Unable to check for updates: " + exception.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package net.t2code.lib.Spigot.system;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Util;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
public class Vault {
|
||||||
|
|
||||||
|
public static Boolean vaultEnable;
|
||||||
|
public static Boolean connected;
|
||||||
|
|
||||||
|
public static void loadVault() throws InterruptedException {
|
||||||
|
long long_ = System.currentTimeMillis();
|
||||||
|
if (T2CodeMain.getPlugin().getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||||
|
vaultEnable = true;
|
||||||
|
RegisteredServiceProvider<Economy> eco = T2CodeMain.getPlugin().getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (eco != null) {
|
||||||
|
T2CodeMain.setEco(eco.getProvider());
|
||||||
|
if (T2CodeMain.getEco() != null) {
|
||||||
|
connected = true;
|
||||||
|
send.console(Util.getPrefix() + " §2Vault / Economy successfully connected!" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
} else {
|
||||||
|
connected = false;
|
||||||
|
send.console(Util.getPrefix() + " §4Economy could not be connected / found! [1]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
connected = false;
|
||||||
|
send.console(Util.getPrefix() + " §4Economy could not be connected / found! [2]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
RegisteredServiceProvider<Permission> perm = T2CodeMain.getPlugin().getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
|
if (perm != null) {
|
||||||
|
T2CodeMain.setPerm(perm.getProvider());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vaultEnable = false;
|
||||||
|
connected = false;
|
||||||
|
send.console(Util.getPrefix() + " §4Vault could not be connected! [3]" + " §7- §e" + (System.currentTimeMillis() - long_) + "ms");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void vaultDisable() {
|
||||||
|
if (!connected) return;
|
||||||
|
connected = false;
|
||||||
|
send.console(Util.getPrefix() + " §4Vault / Economy successfully deactivated.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package net.t2code.lib.Spigot.system.config;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class ConfigCreate {
|
||||||
|
|
||||||
|
public static void configCreate() {
|
||||||
|
Long long_ = Long.valueOf(System.currentTimeMillis());
|
||||||
|
if (new File(T2CodeMain.getPath(), "config.yml").exists()){
|
||||||
|
if (T2CodeMain.getPlugin().getConfig().getBoolean("Plugin.Debug")) send.console(T2CodeMain.getPrefix() + " §5DEBUG: §6" + " §4config.yml are created / updated...");
|
||||||
|
} else send.console(T2CodeMain.getPrefix() + " §4config.yml are created...");
|
||||||
|
|
||||||
|
|
||||||
|
File config = new File(T2CodeMain.getPath(), "config.yml");
|
||||||
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||||
|
|
||||||
|
Config.set("Plugin.UpdateCheck.OnJoin", true, yamlConfiguration);
|
||||||
|
Config.set("Plugin.UpdateCheck.TimeInterval", 60, yamlConfiguration);
|
||||||
|
Config.set("Plugin.language", "english", yamlConfiguration);
|
||||||
|
|
||||||
|
Config.set("BungeeCord.Enable", false, yamlConfiguration);
|
||||||
|
Config.set("BungeeCord.ThisServer", "server", yamlConfiguration);
|
||||||
|
Config.set("Player.Inventories.CloseByServerStop", true, yamlConfiguration);
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfiguration.save(config);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
send.console(T2CodeMain.getPrefix() + " §2config.yml were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package net.t2code.lib.Spigot.system.config;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class SelectLibConfig {
|
||||||
|
|
||||||
|
|
||||||
|
private static Boolean UpdateCheckOnJoin;
|
||||||
|
private static Boolean t2cTestDevelopment;
|
||||||
|
private static Integer UpdateCheckTimeInterval;
|
||||||
|
private static Boolean Debug;
|
||||||
|
private static String language;
|
||||||
|
private static Boolean InventoriesCloseByServerStop;
|
||||||
|
|
||||||
|
public static void onSelect() {
|
||||||
|
File config = new File(T2CodeMain.getPath(), "config.yml");
|
||||||
|
YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(config);
|
||||||
|
|
||||||
|
UpdateCheckOnJoin = yamlConfiguration.getBoolean("Plugin.UpdateCheck.OnJoin");
|
||||||
|
t2cTestDevelopment = yamlConfiguration.getBoolean("t2cTestDevelopment");
|
||||||
|
UpdateCheckTimeInterval = yamlConfiguration.getInt("Plugin.UpdateCheck.TimeInterval");
|
||||||
|
Debug = yamlConfiguration.getBoolean("Plugin.Debug");
|
||||||
|
language = yamlConfiguration.getString("Plugin.language");
|
||||||
|
InventoriesCloseByServerStop = yamlConfiguration.getBoolean("Player.Inventories.CloseByServerStop");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getUpdateCheckOnJoin() {
|
||||||
|
return UpdateCheckOnJoin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getT2cTestDevelopment() {
|
||||||
|
return t2cTestDevelopment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getUpdateCheckTimeInterval() {
|
||||||
|
return UpdateCheckTimeInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getDebug() {
|
||||||
|
return Debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getInventoriesCloseByServerStop() {
|
||||||
|
return InventoriesCloseByServerStop;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package net.t2code.lib.Spigot.system.languages;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import net.t2code.lib.Spigot.Lib.yamlConfiguration.Config;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class LanguagesCreate {
|
||||||
|
static Plugin plugin = T2CodeMain.getPlugin();
|
||||||
|
|
||||||
|
public static void langCreate() {
|
||||||
|
send.debug(plugin, "§4Language files are created / updated...");
|
||||||
|
Long long_ = Long.valueOf(System.currentTimeMillis());
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ENGLISH
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
File messagesEN = new File(T2CodeMain.getPath(), "languages/english_messages.yml");
|
||||||
|
YamlConfiguration yamlConfigurationEN = YamlConfiguration.loadConfiguration(messagesEN);
|
||||||
|
|
||||||
|
Config.set("Plugin.VaultNotSetUp", MSG.EN_VaultNotSetUp, yamlConfigurationEN);
|
||||||
|
Config.set("Plugin.VotingPluginNotSetUp", MSG.EN_VotingPluginNotSetUp, yamlConfigurationEN);
|
||||||
|
Config.set("Plugin.SoundNotFound", MSG.EN_SoundNotFound, yamlConfigurationEN);
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfigurationEN.save(messagesEN);
|
||||||
|
} catch (IOException e) {
|
||||||
|
send.warning(T2CodeMain.getPlugin(), e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* GERMAN
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
File messagesDE = new File(T2CodeMain.getPath(), "languages/german_messages.yml");
|
||||||
|
YamlConfiguration yamlConfigurationDE = YamlConfiguration.loadConfiguration(messagesDE);
|
||||||
|
|
||||||
|
Config.set("Plugin.VaultNotSetUp", MSG.DE_VotingPluginNotSetUp, yamlConfigurationDE);
|
||||||
|
Config.set("Plugin.VotingPluginNotSetUp", MSG.DE_VotingPluginNotSetUp, yamlConfigurationDE);
|
||||||
|
Config.set("Plugin.SoundNotFound", MSG.DE_SoundNotFound, yamlConfigurationDE);
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfigurationDE.save(messagesDE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
send.warning(T2CodeMain.getPlugin(), e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* norwegian
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
File messagesNO = new File(T2CodeMain.getPath(), "languages/norwegian_messages.yml");
|
||||||
|
YamlConfiguration yamlConfigurationNO = YamlConfiguration.loadConfiguration(messagesNO);
|
||||||
|
|
||||||
|
Config.set("Plugin.VaultNotSetUp", MSG.NO_VaultNotSetUp, yamlConfigurationNO);
|
||||||
|
Config.set("Plugin.VotingPluginNotSetUp", MSG.NO_VotingPluginNotSetUp, yamlConfigurationNO);
|
||||||
|
Config.set("Plugin.SoundNotFound", MSG.NO_SoundNotFound, yamlConfigurationNO);
|
||||||
|
|
||||||
|
try {
|
||||||
|
yamlConfigurationNO.save(messagesNO);
|
||||||
|
} catch (IOException e) {
|
||||||
|
send.warning(T2CodeMain.getPlugin(), e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
send.console(T2CodeMain.getPrefix() + " §2Language files were successfully created / updated." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
// This claas was created by JaTiTV
|
||||||
|
|
||||||
|
package net.t2code.lib.Spigot.system.languages;
|
||||||
|
|
||||||
|
public class MSG {
|
||||||
|
|
||||||
|
// EN
|
||||||
|
public static String EN_VaultNotSetUp = "[prefix] &4Vault / Economy not set up!";
|
||||||
|
public static String EN_VotingPluginNotSetUp = "[prefix] &4VotingPlugin is not present on the server!";
|
||||||
|
public static String EN_SoundNotFound = "[prefix] &4The sound &6[sound] &4was not found! Please check the settings.";
|
||||||
|
|
||||||
|
|
||||||
|
// DE
|
||||||
|
public static String DE_VaultPluginNotSetUp = "[prefix] &4Vault / Economy nicht eingerichtet!";
|
||||||
|
public static String DE_VotingPluginNotSetUp = "[prefix] &4VotingPlugin ist auf dem Server nicht vorhanden!";
|
||||||
|
public static String DE_SoundNotFound = "[prefix] &4Der Sound &6[sound] &4wurde nicht gefunden! Bitte [ue]berpr[ue]fe die Einstellungen.";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// NO
|
||||||
|
public static String NO_VaultNotSetUp = "[prefix] &4Vault / Økonomi har ikke blitt satt opp!";
|
||||||
|
public static String NO_VotingPluginNotSetUp = "[prefix] &4VotingPlugin er ikke til stede på serveren!";
|
||||||
|
public static String NO_SoundNotFound = "[prefix] &4Lyden &6[sound] &4ble ikke bli funnet! Vennligst sjekk innstillingene.";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package net.t2code.lib.Spigot.system.languages;
|
||||||
|
|
||||||
|
import net.t2code.lib.Spigot.Lib.messages.send;
|
||||||
|
import net.t2code.lib.Spigot.Lib.replace.Replace;
|
||||||
|
import net.t2code.lib.Spigot.system.T2CodeMain;
|
||||||
|
import net.t2code.lib.Spigot.system.config.SelectLibConfig;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class SelectLibMsg {
|
||||||
|
private static Plugin plugin = T2CodeMain.getPlugin();
|
||||||
|
private static String prefix = T2CodeMain.getPrefix();
|
||||||
|
|
||||||
|
public static String selectMSG;
|
||||||
|
|
||||||
|
public static String vaultNotSetUp;
|
||||||
|
public static String votingPluginNotSetUp;
|
||||||
|
public static String soundNotFound;
|
||||||
|
|
||||||
|
public static void onSelect(String Prefix) {
|
||||||
|
|
||||||
|
send.debug(plugin, "§4Select language...");
|
||||||
|
Long long_ = Long.valueOf(System.currentTimeMillis());
|
||||||
|
|
||||||
|
File msg;
|
||||||
|
|
||||||
|
msg = new File(T2CodeMain.getPath(), "languages/" + SelectLibConfig.getLanguage() + "_messages.yml");
|
||||||
|
if (!msg.isFile()) {
|
||||||
|
send.console(Prefix);
|
||||||
|
send.console(Prefix + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
send.console(Prefix + " §4The selected §c" + SelectLibConfig.getLanguage() + " §4language file was not found.");
|
||||||
|
send.console(Prefix + " §6The default language §eEnglish §6is used!");
|
||||||
|
send.console(Prefix + " §4!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
|
send.console(Prefix);
|
||||||
|
msg = new File(T2CodeMain.getPath(), "languages/" + "english_messages.yml");
|
||||||
|
selectMSG = "english";
|
||||||
|
} else selectMSG = SelectLibConfig.getLanguage();
|
||||||
|
YamlConfiguration yamlConfiguration_msg = YamlConfiguration.loadConfiguration(msg);
|
||||||
|
|
||||||
|
vaultNotSetUp = Replace.replace(prefix, yamlConfiguration_msg.getString("Plugin.VaultNotSetUp"));
|
||||||
|
votingPluginNotSetUp = Replace.replace(prefix, yamlConfiguration_msg.getString("Plugin.VotingPluginNotSetUp"));
|
||||||
|
soundNotFound = Replace.replace(prefix, yamlConfiguration_msg.getString("Plugin.SoundNotFound"));
|
||||||
|
|
||||||
|
send.console(Prefix + " §2Language successfully selected to: §6" + selectMSG + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
|
||||||
|
}
|
||||||
|
}
|
58
T2CodeLibOld/src/main/java/net/t2code/lib/Util.java
Normal file
58
T2CodeLibOld/src/main/java/net/t2code/lib/Util.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package net.t2code.lib;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
private static Boolean Snapshot = false;
|
||||||
|
|
||||||
|
private static String Prefix = "§8[§4T2Code§5Lib§8]";
|
||||||
|
private static Integer SpigotID = 96388;
|
||||||
|
private static Integer BstatsID = 12518;
|
||||||
|
private static String Spigot = "https://www.spigotmc.org/resources/" + SpigotID;
|
||||||
|
private static String Discord = "http://dc.t2code.net";
|
||||||
|
|
||||||
|
public static String getPrefix() {
|
||||||
|
return Prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getSpigotID() {
|
||||||
|
return SpigotID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getBstatsID() {
|
||||||
|
return BstatsID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSpigot() {
|
||||||
|
return Spigot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDiscord() {
|
||||||
|
return Discord;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getSnapshot(){
|
||||||
|
return Snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getT2cPlugins() {
|
||||||
|
return t2cPlugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> t2cPlugins =
|
||||||
|
Arrays.asList(
|
||||||
|
"T2C-LuckyBox",
|
||||||
|
"WonderBagShop",
|
||||||
|
"CommandGUI",
|
||||||
|
"OPSecurity",
|
||||||
|
"PaPiTest",
|
||||||
|
"PlotSquaredGUI",
|
||||||
|
"T2C-Alias",
|
||||||
|
"T2C-AutoResponse",
|
||||||
|
"LoreEditor",
|
||||||
|
"Booster",
|
||||||
|
"AntiMapCopy",
|
||||||
|
"AntiCopy"
|
||||||
|
);
|
||||||
|
}
|
5
T2CodeLibOld/src/main/resources/bungee.yml
Normal file
5
T2CodeLibOld/src/main/resources/bungee.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: T2CodeLib
|
||||||
|
version: ${project.version}
|
||||||
|
main: net.t2code.lib.Bungee.BMain
|
||||||
|
author: JaTiTV, Jkobs
|
||||||
|
description: Library from T2Code Plugins
|
30
T2CodeLibOld/src/main/resources/plugin.yml
Normal file
30
T2CodeLibOld/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
name: T2CodeLib
|
||||||
|
version: ${project.version}
|
||||||
|
main: net.t2code.lib.Spigot.system.T2CodeMain
|
||||||
|
api-version: 1.13
|
||||||
|
prefix: T2CodeLib
|
||||||
|
authors: [ JaTiTV, Jkobs ]
|
||||||
|
description: Library from T2Code Plugins
|
||||||
|
website: T2Code.net
|
||||||
|
load: STARTUP
|
||||||
|
softdepend:
|
||||||
|
- VotingPlugin
|
||||||
|
- PlaceholderAPI
|
||||||
|
- PlotSquared
|
||||||
|
- CMI
|
||||||
|
- CMILib
|
||||||
|
- Vault
|
||||||
|
- Economy
|
||||||
|
- XConomy
|
||||||
|
|
||||||
|
loadbefore:
|
||||||
|
- T2C-Alias
|
||||||
|
- CommandGUI
|
||||||
|
|
||||||
|
commands:
|
||||||
|
t2code:
|
||||||
|
aliases: t2c
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
t2code.admin:
|
||||||
|
default: op
|
Loading…
Reference in New Issue
Block a user