5 | * Copyright (c) contributors
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | * SOFTWARE.
24 | */
25 | package xyz.theprogramsrc.supercoreapi.global.dependencies.classloader;
26 |
27 | import java.net.URL;
28 | import java.net.URLClassLoader;
29 |
30 | /**
31 | * A classloader "isolated" from the rest of the Minecraft server.
32 | *
33 | * Used to load specific LuckPerms dependencies without causing conflicts
34 | * with other plugins, or libraries provided by the server implementation.
35 | */
36 | public class IsolatedClassLoader extends URLClassLoader {
37 | static {
38 | ClassLoader.registerAsParallelCapable();
39 | }
40 |
41 | public IsolatedClassLoader(URL[] urls) {
42 | /*
43 | * ClassLoader#getSystemClassLoader returns the AppClassLoader
44 | *
45 | * Calling #getParent on this returns the ExtClassLoader (Java 8) or
46 | * the PlatformClassLoader (Java 9). Since we want this classloader to
47 | * be isolated from the Minecraft server (the app), we set the parent
48 | * to be the platform class loader.
49 | */
50 | super(urls, ClassLoader.getSystemClassLoader().getParent());
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/test/java/xyz/theprogramsrc/supercoreapi/global/utils/UtilsTest.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global.utils;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertTrue;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.security.MessageDigest;
9 | import java.security.NoSuchAlgorithmException;
10 |
11 | import org.junit.jupiter.api.Test;
12 |
13 | class UtilsTest {
14 |
15 | @Test
16 | void capitalizeTest() {
17 | String capitalized = Utils.capitalize("abCde");
18 | assertEquals("AbCde", capitalized);
19 | }
20 |
21 | @Test
22 | void toTicksTest() {
23 | long ticks = Utils.toTicks(5);
24 | assertEquals(100, ticks);
25 | }
26 |
27 | @Test
28 | void toMillisTest() {
29 | long millis = Utils.toMillis(5);
30 | assertEquals(5000, millis);
31 | }
32 |
33 | @Test
34 | void isIntegerTest() {
35 | boolean integer = Utils.isInteger("1");
36 | assertTrue(integer);
37 | }
38 |
39 | @Test
40 | void parseHypotenuseTest() {
41 | double hypotenuse = Utils.parseHypotenuse(3,4);
42 | assertEquals(25, hypotenuse);
43 | }
44 |
45 | @Test
46 | void squareRootTest() {
47 | double sqrt = Utils.squareRoot(Utils.parseHypotenuse(3,4));
48 | assertEquals(5, sqrt);
49 | }
50 |
51 | @Test
52 | void checksumGeneratorTest() throws IOException, NoSuchAlgorithmException {
53 | // First we download the sample jar
54 | File tmpFile = new File("4.13.0.pom.xml");
55 | Utils.downloadFile("https://repo.theprogramsrc.xyz/repository/maven-public/xyz/theprogramsrc/SuperCoreAPI/4.13.0/SuperCoreAPI-4.13.0.pom", tmpFile);
56 | String knownHash = "f70c0d83eab4bb30e8794f929299fd9a"; // We Store the known hash
57 | MessageDigest messageDigest = Utils.getDigest("MD5"); // We generate the message digest
58 | String generatedHash = Utils.generateFileChecksum(messageDigest, tmpFile); // Now we generate the hash
59 | assertEquals(knownHash, generatedHash); // Now we check the hash
60 | tmpFile.deleteOnExit();
61 | }
62 |
63 | @Test
64 | void getTimeSecondsFromStringTest(){
65 | long seconds = Utils.getTimeSecondsFromString("1h 30s");
66 | assertEquals(3630l, seconds);
67 | }
68 |
69 | @Test
70 | void getTimeSecondsFromWordTest(){
71 | long seconds = Utils.getTimeSecondsFromWord("1h");
72 | assertEquals(3600l, seconds);
73 | }
74 | }
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/MinecraftServer.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.utils;
2 |
3 | import org.bukkit.Bukkit;
4 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
5 |
6 | public enum MinecraftServer {
7 |
8 | UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE;
9 | private final static MinecraftServer minecraftServer = checkProject();
10 |
11 | private static MinecraftServer checkProject() {
12 | String serverPath = Bukkit.getServer().getClass().getName();
13 | if (serverPath.contains("glowstone")) {
14 | return GLOWSTONE;
15 | }
16 |
17 | // Taco is pretty easy to check. it uses paper stuff, though, so should be checked first
18 | try {
19 | Class.forName("net.techcable.tacospigot.TacoSpigotConfig");
20 | return TACO;
21 | } catch (ClassNotFoundException ignored) { }
22 |
23 | // Paper used to be called "paperclip"
24 | try {
25 | Class.forName("com.destroystokyo.paperclip.Paperclip");
26 | return PAPER;
27 | } catch (ClassNotFoundException ignored) {}
28 |
29 | try {
30 | Class.forName("com.destroystokyo.paper.PaperConfig");
31 | return PAPER;
32 | } catch (ClassNotFoundException ignored) { }
33 |
34 | // Spigot is the fork that pretty much all builds are based on anymore
35 | try {
36 | Class.forName("org.spigotmc.SpigotConfig");
37 | return SPIGOT;
38 | } catch (ClassNotFoundException ignored) { }
39 |
40 | return serverPath.contains("craftbukkit") ? CRAFTBUKKIT : UNKNOWN;
41 | }
42 |
43 | /**
44 | * Gets tge current server software name
45 | * @return the current server software name
46 | */
47 | public static MinecraftServer getServerVersion() {
48 | return minecraftServer;
49 | }
50 |
51 | /**
52 | * Checks if the current server software it's the same as the provided one
53 | * @param version the other version to check
54 | * @return true if booth are the same, false otherwise
55 | */
56 | public static boolean isServer(MinecraftServer version) {
57 | return minecraftServer == version;
58 | }
59 |
60 | /**
61 | * Checks if the current server software it's one of the provided ones
62 | * @param versions the versions to check
63 | * @return true if the current server software it's in the list, false otherwise
64 | */
65 | public static boolean isServer(MinecraftServer... versions) {
66 | return Utils.inArray(versions, minecraftServer);
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '22 12 * * 1'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'java' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37 | # Learn more:
38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39 |
40 | steps:
41 | - name: Checkout repository
42 | uses: actions/checkout@v2
43 |
44 | # Initializes the CodeQL tools for scanning.
45 | - name: Initialize CodeQL
46 | uses: github/codeql-action/init@v1
47 | with:
48 | languages: ${{ matrix.language }}
49 | # If you wish to specify custom queries, you can do so here or in a config file.
50 | # By default, queries listed here will override any specified in a config file.
51 | # Prefix the list here with "+" to use these queries and those in the config file.
52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
53 |
54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55 | # If this step fails, then you should remove it and run the build manually (see below)
56 | - name: Autobuild
57 | uses: github/codeql-action/autobuild@v1
58 |
59 | # ℹ️ Command-line programs to run using the OS shell.
60 | # 📚 https://git.io/JvXDl
61 |
62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63 | # and modify them (or add more) to build your code if your project
64 | # uses a compiled language
65 |
66 | #- run: |
67 | # make bootstrap
68 | # make release
69 |
70 | - name: Perform CodeQL Analysis
71 | uses: github/codeql-action/analyze@v1
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/LogsFilter.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global;
2 |
3 | import org.apache.logging.log4j.Level;
4 | import org.apache.logging.log4j.LogManager;
5 | import org.apache.logging.log4j.Marker;
6 | import org.apache.logging.log4j.core.LogEvent;
7 | import org.apache.logging.log4j.core.Logger;
8 | import org.apache.logging.log4j.core.filter.AbstractFilter;
9 | import org.apache.logging.log4j.message.Message;
10 |
11 | import java.util.Arrays;
12 |
13 | public class LogsFilter extends AbstractFilter{
14 |
15 | private final FilterResult result;
16 | private final String[] filteredStrings;
17 |
18 | /**
19 | * Constructor of a log filter
20 | * @param result the default result for the filtered words
21 | * @param filteredStrings the strings to filter
22 | */
23 | public LogsFilter(FilterResult result, String... filteredStrings){
24 | this.result = result;
25 | this.filteredStrings = filteredStrings;
26 | }
27 |
28 | private Result process(String message){
29 | if(message != null){
30 | String msg = message.toLowerCase();
31 | if(Arrays.stream(this.filteredStrings).anyMatch(s-> msg.contains(s.toLowerCase()) && Arrays.stream(this.getExtraRequirements()).anyMatch(s1-> msg.contains(s1.toLowerCase())))){
32 | return Result.toResult(this.result.name(), Result.NEUTRAL);
33 | }
34 | }
35 |
36 | return Result.NEUTRAL;
37 | }
38 |
39 | public void register(){
40 | Logger consoleLogger = ((Logger) LogManager.getRootLogger());
41 | consoleLogger.addFilter(this);
42 | }
43 |
44 | @Override
45 | public Result filter(LogEvent event) {
46 | return this.process(event.getMessage().getFormattedMessage());
47 | }
48 |
49 | @Override
50 | public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
51 | return this.process(msg.getFormattedMessage());
52 | }
53 |
54 | @Override
55 | public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
56 | return this.process(msg.toString());
57 | }
58 |
59 | @Override
60 | public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
61 | return this.process(msg);
62 | }
63 |
64 | /**
65 | * An array of strings that will be checked if a message contains one of those to filter the message
66 | * @return the strings
67 | */
68 | public String[] getExtraRequirements(){
69 | return new String[0];
70 | }
71 |
72 | public enum FilterResult{
73 | DENY,
74 | NEUTRAL,
75 | NONE
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/bungee/utils/tasks/BungeeTasks.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.bungee.utils.tasks;
2 |
3 | import net.md_5.bungee.api.scheduler.ScheduledTask;
4 | import net.md_5.bungee.api.scheduler.TaskScheduler;
5 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
6 | import xyz.theprogramsrc.supercoreapi.global.objects.RecurringTask;
7 |
8 | import java.util.concurrent.TimeUnit;
9 |
10 | public class BungeeTasks extends BungeeModule {
11 |
12 | private final TaskScheduler scheduler;
13 |
14 | public BungeeTasks() {
15 | this.scheduler = this.getProxy().getScheduler();
16 | }
17 |
18 | /**
19 | * Schedule a task to be executed asynchronously. The task will commence
20 | * running as soon as this method returns.
21 | *
22 | * @param task the task to run
23 | * @return the scheduled task
24 | */
25 | public ScheduledTask runAsync(Runnable task){
26 | return this.scheduler.runAsync(this.bungeePlugin, task);
27 | }
28 |
29 | /**
30 | * Schedules a task to be executed asynchronously after the specified delay
31 | * is up.
32 | *
33 | * @param task the task to run
34 | * @param delay the delay before this task will be executed (in ticks)
35 | * @return the scheduled task
36 | */
37 | public ScheduledTask runAsyncLater(Runnable task, long delay){
38 | return this.scheduler.schedule(this.bungeePlugin, task, delay*50L, TimeUnit.MILLISECONDS);
39 | }
40 |
41 | /**
42 | * Schedules a task to be executed asynchronously after the specified delay
43 | * is up. The scheduled task will continue running at the specified
44 | * interval. The interval will not begin to count down until the last task
45 | * invocation is complete.
46 | *
47 | * @param task the task to run
48 | * @param delay the delay before this task will be executed (in ticks)
49 | * @param period the interval before subsequent executions of this task (in ticks)
50 | * @return the scheduled task
51 | */
52 | public RecurringTask runAsyncTimer(Runnable task, long delay, long period){
53 | ScheduledTask scheduledTask = this.scheduler.schedule(this.bungeePlugin, task, delay*50L, period*50L, TimeUnit.MILLISECONDS);
54 | return new RecurringTask() {
55 | private boolean cancelled;
56 | @Override
57 | public void start() {
58 | if(this.cancelled){
59 | BungeeTasks.this.runAsyncTimer(task, delay, period);
60 | }
61 | }
62 |
63 | @Override
64 | public void stop() {
65 | scheduledTask.cancel();
66 | this.cancelled = true;
67 | }
68 | };
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/precreated/GeneralConfigurationSettingPane.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings.precreated;
2 |
3 | import com.cryptomorin.xseries.XMaterial;
4 |
5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base;
6 | import xyz.theprogramsrc.supercoreapi.spigot.dialog.Dialog;
7 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry;
8 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiRows;
9 | import xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings.SettingPane;
10 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
11 |
12 | public class GeneralConfigurationSettingPane extends SettingPane {
13 |
14 | @Override
15 | public String getDisplayName() {
16 | return Base.GENERAL.toString();
17 | }
18 |
19 | @Override
20 | public GuiRows getRows(){
21 | return GuiRows.THREE;
22 | }
23 |
24 | @Override
25 | public SimpleItem getDisplayItem() {
26 | return new SimpleItem(XMaterial.COMMAND_BLOCK_MINECART)
27 | .setDisplayName("&a" + Base.SETTINGS_GENERAL_NAME)
28 | .setLore(
29 | "&7",
30 | "&7" + Base.SETTINGS_GENERAL_DESCRIPTION
31 | );
32 | }
33 |
34 | @Override
35 | public GuiEntry[] getButtons() {
36 | return new GuiEntry[]{
37 | this.getChangePrefixButton()
38 | };
39 | }
40 |
41 | @Override
42 | public int[] getContainerSlots() {
43 | return new int[]{13};
44 | }
45 |
46 | private GuiEntry getChangePrefixButton(){
47 | SimpleItem item = new SimpleItem(XMaterial.NAME_TAG)
48 | .setDisplayName("&a" + Base.GENERAL_SET_PREFIX_NAME)
49 | .setLore(
50 | "&7",
51 | "&7" + Base.GENERAL_SET_PREFIX_DESCRIPTION
52 | ).addPlaceholder("{Prefix}", "&r" + this.getSettings().getPrefix() + "&r");
53 | return new GuiEntry(item, a-> new Dialog(a.player){
54 | @Override
55 | public String getTitle() {
56 | return "&9" + Base.DIALOG_CHANGE_PREFIX_TITLE;
57 | }
58 |
59 | @Override
60 | public String getSubtitle() {
61 | return "&7" + Base.DIALOG_CHANGE_PREFIX_SUBTITLE;
62 | }
63 |
64 | @Override
65 | public String getActionbar() {
66 | return "&a" + Base.DIALOG_CHANGE_PREFIX_ACTIONBAR;
67 | }
68 |
69 | @Override
70 | public boolean onResult(String playerInput) {
71 | this.getSettings().setPrefix(playerInput);
72 | a.gui.open();
73 | return true;
74 | }
75 | }.addPlaceholder("{Prefix}", "&r"+this.getSettings().getPrefix()+"&r"));
76 | }
77 | }
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/SuperModule.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi;
2 |
3 | import java.io.File;
4 |
5 | /**
6 | * Representation of a Plugin Module
7 | * @param The listener of the plugin
8 | */
9 | public abstract class SuperModule {
10 |
11 | protected SuperPlugin> plugin;
12 |
13 | public SuperModule(SuperPlugin> plugin){
14 | this.plugin = plugin;
15 | }
16 |
17 | /**
18 | * Executed on the module load
19 | */
20 | public void onLoad(){
21 |
22 | }
23 |
24 | /**
25 | * Sends a message with prefix through console
26 | * @param message Message to send
27 | */
28 | protected void log(String message){
29 | this.plugin.log(message);
30 | }
31 |
32 | /**
33 | * Show a debug message if the debug mode is enabled
34 | * @param message the message to show if the debug mode is enabled
35 | */
36 | protected void debug(String message){
37 | this.plugin.debug(message);
38 | }
39 |
40 | /**
41 | * Checks if the debug mode is enabled
42 | * @return if the debug mode is enabled
43 | */
44 | protected boolean isDebugEnabled(){
45 | return this.plugin.isDebugEnabled();
46 | }
47 |
48 | /**
49 | * Registers new listeners
50 | * @param listeners Listeners to register
51 | */
52 | protected abstract void listener(LISTENER... listeners);
53 |
54 | /**
55 | * Gets the server folder
56 | * @return server folder
57 | */
58 | protected File getServerFolder(){
59 | return this.plugin.getServerFolder();
60 | }
61 |
62 | /**
63 | * Gets the plugin file
64 | * @return plugin file
65 | */
66 | protected File getPluginFile(){
67 | return this.plugin.getPluginFile();
68 | }
69 |
70 | /**
71 | * Gets the plugin folder
72 | * @return plugin folder
73 | */
74 | protected File getPluginFolder(){
75 | return this.plugin.getPluginFolder();
76 | }
77 |
78 | /**
79 | * Gets the translation folder
80 | * @return translation folder
81 | */
82 | protected File getTranslationsFolder(){
83 | return this.plugin.getTranslationsFolder();
84 | }
85 |
86 | /**
87 | * Gets the plugin version
88 | * @return plugin version
89 | */
90 | protected String getPluginVersion(){
91 | return this.plugin.getPluginVersion();
92 | }
93 |
94 | /**
95 | * Gets the plugin name
96 | * @return plugin name
97 | */
98 | protected String getPluginName(){
99 | return this.plugin.getPluginName();
100 | }
101 |
102 | /**
103 | * Gets the plugin
104 | * @return plugin
105 | */
106 | public SuperPlugin> getPlugin() {
107 | return plugin;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/classloader/ReflectionClassLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of LuckPerms, licensed under the MIT License.
3 | *
4 | * Copyright (c) lucko (Luck)
5 | * Copyright (c) contributors
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | * SOFTWARE.
24 | */
25 |
26 | package xyz.theprogramsrc.supercoreapi.global.dependencies.classloader;
27 |
28 | import java.lang.reflect.InvocationTargetException;
29 | import java.lang.reflect.Method;
30 | import java.net.MalformedURLException;
31 | import java.net.URL;
32 | import java.net.URLClassLoader;
33 | import java.nio.file.Path;
34 |
35 | public class ReflectionClassLoader implements PluginClassLoader {
36 | private static final Method ADD_URL_METHOD;
37 |
38 | static {
39 | try {
40 | ADD_URL_METHOD = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
41 | ADD_URL_METHOD.setAccessible(true);
42 | } catch (NoSuchMethodException e) {
43 | throw new ExceptionInInitializerError(e);
44 | }
45 | }
46 |
47 | private final URLClassLoader classLoader;
48 |
49 | public ReflectionClassLoader(Object plugin) throws IllegalStateException {
50 | ClassLoader classLoader = plugin.getClass().getClassLoader();
51 | if (classLoader instanceof URLClassLoader) {
52 | this.classLoader = (URLClassLoader) classLoader;
53 | } else {
54 | throw new IllegalStateException("ClassLoader is not instance of URLClassLoader");
55 | }
56 | }
57 |
58 | @Override
59 | public void loadJar(Path file) {
60 | try {
61 | ADD_URL_METHOD.invoke(this.classLoader, file.toUri().toURL());
62 | } catch (IllegalAccessException | InvocationTargetException | MalformedURLException e) {
63 | throw new RuntimeException(e);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/precreated/GeneralConfigurationSettingPane.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings.precreated;
2 |
3 | import java.util.LinkedList;
4 |
5 | import com.cryptomorin.xseries.XMaterial;
6 |
7 | import xyz.theprogramsrc.supercoreapi.global.translations.Base;
8 | import xyz.theprogramsrc.supercoreapi.spigot.dialog.Dialog;
9 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton;
10 | import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows;
11 | import xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings.SettingPane;
12 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
13 |
14 | /**
15 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}.
16 | */
17 | @Deprecated public class GeneralConfigurationSettingPane extends SettingPane {
18 |
19 | @Override
20 | public String getDisplayName() {
21 | return Base.GENERAL.toString();
22 | }
23 |
24 | @Override
25 | public SimpleItem getDisplayItem() {
26 | return new SimpleItem(XMaterial.COMMAND_BLOCK_MINECART)
27 | .setDisplayName("&a" + Base.SETTINGS_GENERAL_NAME)
28 | .setLore(
29 | "&7",
30 | "&7" + Base.SETTINGS_GENERAL_DESCRIPTION
31 | );
32 | }
33 |
34 | @Override
35 | public GUIButton[] getButtons() {
36 | LinkedList buttons = new LinkedList<>();
37 | buttons.add(this.getChangePrefixButton());
38 | return buttons.toArray(new GUIButton[0]);
39 | }
40 |
41 | @Override
42 | public int[] getContainerSlots() {
43 | return new int[]{13};
44 | }
45 |
46 | @Override
47 | public GUIRows getRows() {
48 | return GUIRows.THREE;
49 | }
50 |
51 | private GUIButton getChangePrefixButton(){
52 | SimpleItem item = new SimpleItem(XMaterial.NAME_TAG)
53 | .setDisplayName("&a" + Base.GENERAL_SET_PREFIX_NAME)
54 | .setLore(
55 | "&7",
56 | "&7" + Base.GENERAL_SET_PREFIX_DESCRIPTION
57 | ).addPlaceholder("{Prefix}", "&r" + this.getSettings().getPrefix() + "&r");
58 | return new GUIButton(item, a-> new Dialog(a.getPlayer()){
59 | @Override
60 | public String getTitle() {
61 | return "&9" + Base.DIALOG_CHANGE_PREFIX_TITLE;
62 | }
63 |
64 | @Override
65 | public String getSubtitle() {
66 | return "&7" + Base.DIALOG_CHANGE_PREFIX_SUBTITLE;
67 | }
68 |
69 | @Override
70 | public String getActionbar() {
71 | return "&a" + Base.DIALOG_CHANGE_PREFIX_ACTIONBAR;
72 | }
73 |
74 | @Override
75 | public boolean onResult(String playerInput) {
76 | this.getSettings().setPrefix(playerInput);
77 | a.openGUI();
78 | return true;
79 | }
80 | }.addPlaceholder("{Prefix}", "&r"+this.getSettings().getPrefix()+"&r"));
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/translations/TranslationDownloader.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global.translations;
2 |
3 | import java.io.File;
4 |
5 | import com.google.gson.JsonArray;
6 | import com.google.gson.JsonElement;
7 | import com.google.gson.JsonObject;
8 | import com.google.gson.JsonParser;
9 |
10 | import xyz.theprogramsrc.supercoreapi.SuperPlugin;
11 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
12 | import xyz.theprogramsrc.supercoreapi.global.utils.files.FileUtils;
13 |
14 | public class TranslationDownloader {
15 |
16 | /**
17 | * Used to download all translations from github
18 | * @param core The Plugin
19 | * @param username The GitHub Username
20 | * @param repository The GitHub Repository
21 | * @param folder The folder of the Translations
22 | * @deprecated due to new translation system
23 | */
24 | @Deprecated public static void downloadFromGitHub(final SuperPlugin> core, final String username, final String repository, final String folder){
25 | JsonParser parser = new JsonParser();
26 | try{
27 | String url = "https://api.github.com/repos/{Username}/{Repository}/contents/{Folder}";
28 | url = url.replace("{Username}", username);
29 | url = url.replace("{Repository}", repository);
30 | url = url.replace("{Folder}", folder);
31 | url = url.replace("{PluginName}", core.getPluginName().toLowerCase());
32 | String content = Utils.readWithInputStream(url);
33 | if(content != null){
34 | JsonArray availableFiles = parser.parse(content).getAsJsonArray();
35 | for (JsonElement jsonElement : availableFiles) {
36 | JsonObject json = jsonElement.getAsJsonObject();
37 | String name = json.get("name").getAsString();
38 | if(name.endsWith(".lang") && name.contains("_")){
39 | String download = json.get("download_url").getAsString();
40 | File file = new File(core.getTranslationsFolder(), name);
41 | file.delete();
42 | FileUtils.downloadUsingCommons(download, file);
43 | }
44 | }
45 | }
46 | core.getTranslationManager().loadTranslations();
47 | }catch (Exception ex){
48 | ex.printStackTrace();
49 | }
50 | }
51 |
52 | /**
53 | * Download a specific translation from web
54 | * @param core The Plugin
55 | * @param directUrl The DirectURl (This API doesn't support redirection)
56 | * @param fileName The name of the file to save
57 | * @deprecated due to new translation system
58 | */
59 | @Deprecated public static void downloadTranslation(final SuperPlugin> core, String directUrl, String fileName){
60 | try{
61 | File file = new File(core.getTranslationsFolder(), fileName.endsWith(".lang") ? fileName : (fileName+".lang"));
62 | file.delete();
63 | FileUtils.downloadUsingCommons(directUrl, file);
64 | }catch (Exception ex){
65 | ex.printStackTrace();
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/items/PreloadedItems.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.items;
2 |
3 | import com.cryptomorin.xseries.XMaterial;
4 | import org.bukkit.enchantments.Enchantment;
5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base;
6 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
7 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;
8 |
9 | /**
10 | * Representation of the Pre-Created Items
11 | */
12 | public class PreloadedItems extends SpigotModule {
13 |
14 | /**
15 | * Common item that represent a back button
16 | * @return the item
17 | */
18 | public SimpleItem getBackItem(){
19 | if(Utils.isConnected()){
20 | return new SimpleItem(Skulls.BACK.asSkinTexture()).setDisplayName(Base.ITEM_BACK_NAME.toString()).setLore(Base.ITEM_BACK_DESCRIPTION.toString());
21 | }else{
22 | return new SimpleItem(XMaterial.ARROW).setDisplayName(Base.ITEM_BACK_NAME.toString()).setLore(Base.ITEM_BACK_DESCRIPTION.toString());
23 | }
24 | }
25 |
26 | /**
27 | * Common item that represent a next page button
28 | * @return the item
29 | */
30 | public SimpleItem getNextItem(){
31 | if(Utils.isConnected()){
32 | return new SimpleItem(Skulls.ARROW_RIGHT.asSkinTexture()).setDisplayName(Base.ITEM_NEXT_NAME.toString()).setLore(Base.ITEM_NEXT_DESCRIPTION.toString());
33 | }else{
34 | return new SimpleItem(XMaterial.PAPER).setDisplayName(Base.ITEM_NEXT_NAME.toString()).setLore(Base.ITEM_NEXT_DESCRIPTION.toString());
35 | }
36 | }
37 |
38 | /**
39 | * Common item that represent a previous page button
40 | * @return the item
41 | */
42 | public SimpleItem getPreviousItem(){
43 | if(Utils.isConnected()){
44 | return new SimpleItem(Skulls.ARROW_LEFT.asSkinTexture()).setDisplayName(Base.ITEM_PREVIOUS_NAME.toString()).setLore(Base.ITEM_PREVIOUS_DESCRIPTION.toString());
45 | }else{
46 | return new SimpleItem(XMaterial.PAPER).setDisplayName(Base.ITEM_PREVIOUS_NAME.toString()).setLore(Base.ITEM_PREVIOUS_DESCRIPTION.toString());
47 | }
48 | }
49 |
50 | /**
51 | * Common item that represent a Search button
52 | * @return the item
53 | */
54 | public SimpleItem getSearchItem(){
55 | return new SimpleItem(XMaterial.BOOKSHELF).setDisplayName(Base.ITEM_SEARCH_NAME.toString()).setLore(Base.ITEM_SEARCH_DESCRIPTION.toString());
56 | }
57 |
58 | /**
59 | * Common item that represent a End Search button
60 | * @return the item
61 | */
62 | public SimpleItem getEndSearchItem(){
63 | return new SimpleItem(XMaterial.BOOKSHELF).addEnchantment(Enchantment.DURABILITY).setShowEnchantments(false).setDisplayName(Base.ITEM_END_SEARCH_NAME.toString()).setLore(Base.ITEM_END_SEARCH_DESCRIPTION.toString());
64 | }
65 |
66 | /**
67 | * Common item that represent an empty button
68 | * @return the item
69 | */
70 | public SimpleItem emptyItem(){
71 | return new SimpleItem(XMaterial.WHITE_STAINED_GLASS_PANE).setDisplayName("&7").addEnchantment(Enchantment.DURABILITY).setShowEnchantments(false);
72 | }
73 |
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/utils/skintexture/SkinTextureManager.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.utils.skintexture;
2 |
3 |
4 | import org.bukkit.Bukkit;
5 | import org.bukkit.entity.Player;
6 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
7 | import xyz.theprogramsrc.supercoreapi.spigot.items.Skulls;
8 |
9 | import java.util.HashMap;
10 |
11 | public class SkinTextureManager {
12 |
13 | private final HashMap cache;
14 | private final HashMap urls;
15 | private final HashMap db;
16 | public static SkinTextureManager INSTANCE;
17 |
18 | public SkinTextureManager(){
19 | this.cache = new HashMap<>();
20 | this.urls = new HashMap<>();
21 | this.db = new HashMap<>();
22 | INSTANCE = this;
23 | }
24 |
25 | /**
26 | * Gets a skin from cache
27 | * @param player the player
28 | * @return the skin
29 | */
30 | public SkinTexture getSkin(Player player) {
31 | String key = Utils.encodeBase64(player.getName());
32 | if(!this.cache.containsKey(key)){
33 | SkinTexture skinTexture = Bukkit.getOnlineMode() ? SkinTexture.fromPlayer(player) : SkinTexture.fromMojang(player.getName());
34 | if(skinTexture == null){
35 | return null;
36 | }
37 | this.cache.put(key, skinTexture);
38 | }
39 | return this.cache.get(key);
40 | }
41 |
42 | /**
43 | * Gets a skin from an url
44 | * @param url the url of the skin
45 | * @return the skin
46 | */
47 | public SkinTexture getSkin(String url){
48 | String key = Utils.encodeBase64(url);
49 | if(!this.urls.containsKey(key)){
50 | SkinTexture texture = SkinTexture.fromURL(url);
51 | this.urls.put(key, texture);
52 | }
53 |
54 | return this.urls.get(key);
55 | }
56 |
57 | /**
58 | * Clears the skin cache
59 | */
60 | public void clearCache(){
61 | this.cache.clear();
62 | this.urls.clear();
63 | this.db.clear();
64 | }
65 |
66 | /**
67 | * Gets a SkinTexture from the database
68 | * @param name the key/name of the SkinTexture
69 | * @return null if there is any error, otherwise the skin
70 | */
71 | public SkinTexture fromDataBase(String name){
72 | String key = Utils.encodeBase64(name);
73 | if(!this.db.containsKey(key)){
74 | this.db.put(key, Skulls.fromDataBase(name));
75 | }
76 | return this.db.get(key);
77 | }
78 |
79 | /**
80 | * Gets the cache of the player skulls
81 | * @return the cache of the players skulls
82 | */
83 | public HashMap getPlayersCache() {
84 | return this.cache;
85 | }
86 |
87 | /**
88 | * Gets the cache of the database skulls
89 | * @return the cache of the database skulls
90 | */
91 | public HashMap getDataBaseCache() {
92 | return this.db;
93 | }
94 |
95 | /**
96 | * Gets the cache of the URLs skulls
97 | * @return the cache of the URLs skulls
98 | */
99 | public HashMap getURLsCache() {
100 | return this.urls;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/files/FileUtils.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global.utils.files;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.File;
5 | import java.io.FileOutputStream;
6 | import java.io.IOException;
7 | import java.net.HttpURLConnection;
8 | import java.net.URL;
9 |
10 | public class FileUtils {
11 |
12 | /**
13 | * Used to download a file using CommonsIO
14 | * @param url Url of the file
15 | * @param file Output file
16 | * @throws IOException If occurs any exception
17 | */
18 | public static void downloadUsingCommons(String url, File file) throws IOException {
19 | org.apache.commons.io.FileUtils.copyURLToFile(new URL(url), file);
20 | }
21 |
22 | /**
23 | * Download a File using Stream
24 | * @param urlLocation The url to download
25 | * @param output The output of the file
26 | * @return false if occurs any error, otherwise true
27 | */
28 | public static boolean downloadUsingStream(String urlLocation, File output){
29 | try{
30 | URL url = new URL(followRedirects(urlLocation));
31 | BufferedInputStream bis = new BufferedInputStream(url.openStream());
32 | FileOutputStream fis = new FileOutputStream(output);
33 | byte[] buffer = new byte[1024];
34 | int count;
35 | while((count = bis.read(buffer,0,1024)) != -1) {
36 | fis.write(buffer, 0, count);
37 | }
38 | fis.close();
39 | bis.close();
40 | return true;
41 | }catch (Exception ex){
42 | ex.printStackTrace();
43 | return false;
44 | }
45 | }
46 |
47 | private static String followRedirects(String url) {
48 | URL urlTmp;
49 | String redUrl;
50 | HttpURLConnection connection;
51 | try { urlTmp = new URL(url); } catch (Exception e1) { return url; }
52 | try { connection = (HttpURLConnection) urlTmp.openConnection(); } catch (Exception e) { return url; }
53 | try { connection.getResponseCode(); } catch (Exception e) { return url; }
54 | redUrl = connection.getURL().toString();
55 | connection.disconnect();
56 | if(redUrl.equals(url)) {
57 | try {
58 | URL obj = new URL(url);
59 | HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
60 | conn.setReadTimeout(5000);
61 | conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
62 | conn.addRequestProperty("User-Agent", "Mozilla");
63 | conn.addRequestProperty("Referer", "google.com");
64 | boolean redirect = false;
65 | int status = conn.getResponseCode();
66 | if (status != HttpURLConnection.HTTP_OK) {
67 | if (status == HttpURLConnection.HTTP_MOVED_TEMP
68 | || status == HttpURLConnection.HTTP_MOVED_PERM
69 | || status == HttpURLConnection.HTTP_SEE_OTHER)
70 | redirect = true;
71 | }
72 | if (redirect) {
73 | return conn.getHeaderField("Location");
74 | }
75 | } catch (Exception ignored) {}
76 | } else {
77 | return redUrl;
78 | }
79 | return url;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/items/Skulls.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.items;
2 |
3 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
4 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin;
5 | import xyz.theprogramsrc.supercoreapi.spigot.utils.skintexture.SkinTexture;
6 |
7 | import java.util.LinkedHashMap;
8 | import java.util.LinkedList;
9 | import java.util.List;
10 |
11 | public enum Skulls {
12 |
13 | BACK("https://textures.minecraft.net/texture/9c042597eda9f061794fe11dacf78926d247f9eea8ddef39dfbe6022989b8395"),
14 | ARROW_LEFT("https://textures.minecraft.net/texture/f7aacad193e2226971ed95302dba433438be4644fbab5ebf818054061667fbe2"),
15 | ARROW_RIGHT("https://textures.minecraft.net/texture/a5fb343b2e7822c7de47abac4c3679f6ad1fa12efc5866c033c7584d6848"),
16 |
17 | ;
18 |
19 | private static LinkedHashMap cache = new LinkedHashMap<>();
20 |
21 | private final String url;
22 |
23 | Skulls(String url){
24 | this.url = url;
25 | }
26 |
27 | /**
28 | * Gets the url of the texture
29 | * @return the url of the texture
30 | */
31 | public String asUrl(){
32 | return this.url;
33 | }
34 |
35 | /**
36 | * Gets the SkinTexture of this skull
37 | * @return the texture of this skull
38 | */
39 | public SkinTexture asSkinTexture(){
40 | return SkinTexture.fromURL(this.asUrl());
41 | }
42 |
43 | /**
44 | * Gets a SkinTexture from the GitHub Heads DataBase
45 | * @param key the key/name of the SkinTexture
46 | * @return the texture of the specified key
47 | */
48 | public static SkinTexture fromDataBase(String key){
49 | if(cache == null) cache = new LinkedHashMap<>();
50 | return new SkinTexture(cache.getOrDefault(key, "https://textures.minecraft.net/texture/badc048a7ce78f7dad72a07da27d85c0916881e5522eeed1e3daf217a38c1a"));
51 | }
52 |
53 | /**
54 | * Gets a URL from the GitHub Heads DataBase
55 | * @param key the key/name of the Texture URL
56 | * @return the URL of the texture
57 | */
58 | public static String urlFromDataBase(String key){
59 | if(cache == null) cache = new LinkedHashMap<>();
60 | return cache.getOrDefault(key, "https://textures.minecraft.net/texture/badc048a7ce78f7dad72a07da27d85c0916881e5522eeed1e3daf217a38c1a");
61 | }
62 |
63 | /**
64 | * Gets all the keys/names of the GitHub Heads DataBase
65 | * @return all the keys/names of the GitHub Heads DataBase
66 | */
67 | public static LinkedList getDataBaseKeys(){
68 | if(cache == null) cache = new LinkedHashMap<>();
69 | return new LinkedList<>(cache.keySet());
70 | }
71 |
72 | /**
73 | * Caches the Heads DataBase from GitHub
74 | */
75 | public static void loadFromGitHub(){
76 | if(cache == null) cache = new LinkedHashMap<>();
77 | try {
78 | List content = Utils.readLinesWithInputStream("https://raw.githubusercontent.com/TheProgramSrc/PluginsResources/master/SuperCoreAPI/Heads");
79 | for (String line : content) {
80 | String[] data = line.split(":", 2);
81 | cache.put(data[0], data[1]);
82 | }
83 | SpigotPlugin.i.log("Successfully loaded " + cache.size() + " Heads from the GitHub DataBase");
84 | } catch (Exception e) {
85 | SpigotPlugin.i.log("&cError while loading Heads DataBase from GitHub");
86 | e.printStackTrace();
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/SQLiteDataBase.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global.storage;
2 |
3 | import xyz.theprogramsrc.supercoreapi.SuperPlugin;
4 |
5 | import java.io.File;
6 | import java.io.IOException;
7 | import java.sql.Connection;
8 | import java.sql.DriverManager;
9 | import java.sql.SQLException;
10 |
11 | public class SQLiteDataBase implements DataBase {
12 |
13 | protected Connection connection;
14 | protected SuperPlugin> plugin;
15 | private final File databaseFile;
16 |
17 | public SQLiteDataBase(SuperPlugin> plugin){
18 | this.plugin = plugin;
19 | this.databaseFile = new File(this.plugin.getPluginFolder(), this.plugin.getPluginName().toLowerCase()+".db");
20 | this.createConnection();
21 | }
22 |
23 | public SQLiteDataBase(File databaseFile){
24 | this.databaseFile = databaseFile;
25 | this.createConnection();
26 | }
27 |
28 | private void createConnection() {
29 | if(this.plugin != null) this.plugin.debug("Connecting to SQLite DataBase");
30 | try{
31 | if(!databaseFile.exists()) databaseFile.createNewFile();
32 | Class.forName("org.sqlite.JDBC");
33 | this.connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
34 | }catch (SQLException | ClassNotFoundException | IOException ex){
35 | if(this.plugin != null) this.plugin.addError(ex);
36 | this.log("&cCannot create SQLite Connection:");
37 | ex.printStackTrace();
38 | }
39 | }
40 |
41 | /**
42 | * SQLite is always available
43 | * @return True because SQLite dont require internet
44 | */
45 | @Override
46 | public boolean isLoaded() {
47 | return true;
48 | }
49 |
50 | /**
51 | * Closes the current connection with DataBase
52 | */
53 | @Override
54 | public void closeConnection() {
55 | if(this.plugin != null) this.plugin.debug("Closing connection with SQLite DataBase");
56 | try{
57 | if(this.connection != null){
58 | this.connection.close();
59 | }
60 | }catch (SQLException ex){
61 | if(this.plugin != null) this.plugin.addError(ex);
62 | this.log("&cCannot close SQLite Connection:");
63 | ex.printStackTrace();
64 | }
65 | }
66 |
67 | /**
68 | * Connects to the DataBase and execute the specified call
69 | * @param call ConnectionCall to execute
70 | */
71 | @Override
72 | public void connect(ConnectionCall call) {
73 | try{
74 | if(this.connection == null){
75 | this.createConnection();
76 | }else if(this.connection.isClosed()){
77 | this.createConnection();
78 | }
79 | }catch (SQLException e){
80 | if(this.plugin != null) this.plugin.addError(e);
81 | this.log("&cError while connecting to SQLite:");
82 | e.printStackTrace();
83 | }
84 |
85 | call.onConnect(this.connection);
86 | }
87 |
88 | /**
89 | * This is not needed because SQLite doesn't use credentials
90 | * @return null
91 | */
92 | @Override
93 | public DataBaseSettings getDataBaseSettings() {
94 | return null;
95 | }
96 |
97 | private void log(String msg){
98 | if(this.plugin == null)
99 | System.out.println(msg);
100 | else
101 | this.plugin.log(msg);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SuperCoreAPI
2 | _The best way to create a plugin_
3 | [](https://repo.theprogramsrc.xyz/#browse/browse:maven-releases)
4 | [](https://repo.theprogramsrc.xyz/#browse/browse:maven-snapshots)
5 |
6 | [](https://go.theprogramsrc.xyz/discord)
7 | [](https://go.theprogramsrc.xyz/tos)
8 | [](https://github.com/TheProgramSrc/SuperCoreAPI/wiki)
9 | [](https://go.theprogramsrc.xyz/patreon)
10 |
11 |
12 | ## Available extensions:
13 | This is the list of included extensions in the SuperCoreAPI Package.
14 | ### [Global](https://github.com/TheProgramSrc/SuperCoreAPI/tree/master/src/main/java/xyz/theprogramsrc/supercoreapi/global)
15 | * Songoda / Spigot Update Checker
16 | * Plugin Injection
17 | * Dependency Manager
18 | * Translations
19 | * Metrics
20 | * File Utils
21 | * String Utils
22 | * Server Utils
23 |
24 | ### [BungeeCord](https://github.com/TheProgramSrc/SuperCoreAPI/tree/master/src/main/java/xyz/theprogramsrc/supercoreapi/bungee)
25 | * Custom Command Creator
26 | * Messaging Services (Not tested yet)
27 | * Custom File Storage
28 | * BungeeCord Utils
29 | * BungeeCord Console Utils
30 |
31 | ### [Spigot](https://github.com/TheProgramSrc/SuperCoreAPI/tree/master/src/main/java/xyz/theprogramsrc/supercoreapi/spigot)
32 | * Custom Command Creator
33 | * Dialog Creator
34 | * Custom Events
35 | * Interactive GUI Creator
36 | * Hologram creator
37 | * Item Builder
38 | * Packet Utils
39 | * Reflection Utils
40 | * Plugin Updater
41 | * Custom Head Texture Util
42 | * Storage Utils
43 | * Cross-Version materials
44 | * Task Utils
45 |
46 | ## Included Libraries
47 | * [XSeries](https://github.com/CryptoMorin/XSeries) ([License](https://github.com/CryptoMorin/XSeries/blob/master/LICENSE.txt))
48 | * [slf4j-api, slf4j-nop](https://github.com/qos-ch/slf4j) ([License](http://www.slf4j.org/license.html))
49 | * [commons-codec](https://github.com/apache/commons-codec) ([License](https://www.apache.org/licenses/LICENSE-2.0))
50 | * [commons-io](https://github.com/apache/commons-io) ([License](https://www.apache.org/licenses/LICENSE-2.0))
51 | * [gson](https://github.com/google/gson) ([License](https://github.com/google/gson/blob/master/LICENSE))
52 | * [SimpleYaml](https://github.com/Carleslc/Simple-YAML) ([License](https://github.com/Carleslc/Simple-YAML/blob/master/LICENSE))
53 | * [HikariCP](https://github.com/brettwooldridge/HikariCP/) ([License](https://github.com/brettwooldridge/HikariCP/blob/dev/LICENSE))
54 | * [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc/) ([License](https://github.com/xerial/sqlite-jdbc/blob/master/LICENSE))
55 | * [log4j2](https://github.com/apache/logging-log4j2) ([License](https://github.com/apache/logging-log4j2/blob/master/LICENSE.txt))
56 | * [Zip4J](https://github.com/srikanth-lingala/zip4j) ([License](https://github.com/srikanth-lingala/zip4j/blob/master/LICENSE))
57 | * [PlaceholderAPI](https://github.com/PlaceholderAPI/PlaceholderAPI) ([License](https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/LICENSE))
58 |
59 |
60 | ## Links
61 | * Become a [Patron](https://go.theprogramsrc.xyz/patreon) and support us!
62 | * [Donate](https://go.theprogramsrc.xyz/donate) to support us!
63 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/utils/StringUtils.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global.utils;
2 |
3 | import java.util.HashMap;
4 | import java.util.concurrent.atomic.AtomicReference;
5 |
6 | /**
7 | * A set of utils for strings
8 | */
9 | public class StringUtils {
10 | private String content;
11 |
12 | /**
13 | * String utils constructor
14 | * @param content String to use
15 | */
16 | public StringUtils(String content){
17 | this.content = content;
18 | }
19 |
20 | /**
21 | * Make all the characters lower case
22 | * @return This class
23 | */
24 | public StringUtils lower(){
25 | this.content = this.content.toLowerCase();
26 | return this;
27 | }
28 |
29 | /**
30 | * Make all the characters upper case
31 | * @return This class
32 | */
33 | public StringUtils upper(){
34 | this.content = this.content.toUpperCase();
35 | return this;
36 | }
37 |
38 | /**
39 | * Capitalize the content with Camel Case
40 | * @return This class
41 | */
42 | public StringUtils capitalize(){
43 | this.content = Utils.capitalize(this.content);
44 | return this;
45 | }
46 |
47 | /**
48 | * Replace variables with format ($1,$2,$3...)
49 | * @param vars Placeholders replacement in order
50 | * @return This class
51 | */
52 | public StringUtils vars(String... vars){
53 | return this.variables("$INDEX", vars);
54 | }
55 |
56 | /**
57 | * Replace custom vars
58 | * @param format Format to replace (INDEX will be replaced with the index, See {@link #vars(String...)})
59 | * @param vars The value of every format
60 | * @return This class
61 | */
62 | public StringUtils variables(String format, String... vars){
63 | String r = this.content;
64 | for(int i = 0; i < vars.length; ++i){
65 | String var = vars[i];
66 | String replace = format.replace("INDEX", (i+1)+"");
67 | r = r.replace(replace, var);
68 | }
69 | this.content = r;
70 | return this;
71 | }
72 |
73 | /**
74 | * Inject placeholders to the content
75 | * @param placeholders Placeholders to inject
76 | * @return This class
77 | */
78 | public StringUtils placeholders(HashMap placeholders){
79 | AtomicReference r = new AtomicReference<>(this.content);
80 | placeholders.forEach((k,v)-> r.set(r.get().replace(k,v)));
81 | this.content = r.get();
82 | return this;
83 | }
84 |
85 | /**
86 | * Inject a single placeholder
87 | * @param key Placeholder to replace
88 | * @param value Placeholder replacement
89 | * @return This class
90 | */
91 | public StringUtils placeholder(String key, String value){
92 | this.content = this.content.replace(key, value);
93 | return this;
94 | }
95 |
96 | /**
97 | * Makes the first character uppercase
98 | * @return This class
99 | */
100 | public StringUtils firstUpper(){
101 | this.content = this.content.substring(0, 1).toUpperCase() + this.content.substring(1);
102 | return this;
103 | }
104 |
105 | /**
106 | * Gets the final string
107 | * @return the final string
108 | */
109 | public String get(){
110 | return this.content;
111 | }
112 |
113 | /**
114 | * Gets the final string
115 | * @return the final string
116 | */
117 | public String toString(){
118 | return this.get();
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/objets/GuiModel.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.objets;
2 |
3 | import java.util.LinkedHashMap;
4 |
5 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;
6 |
7 | /**
8 | * Representation of the Gui Model
9 | * @since 5.2.0
10 | */
11 | public class GuiModel extends SpigotModule{
12 |
13 | private GuiTitle title;
14 | private GuiRows rows;
15 | private final LinkedHashMap buttons;
16 |
17 | public GuiModel(GuiTitle title, GuiRows rows) {
18 | this.title = title;
19 | this.rows = rows;
20 | this.buttons = new LinkedHashMap<>();
21 | }
22 |
23 | public GuiTitle getTitle() {
24 | return title;
25 | }
26 |
27 | /**
28 | * Sets the title of the Gui
29 | * @param title The title of the Gui
30 | */
31 | public void setTitle(GuiTitle title) {
32 | this.title = title;
33 | }
34 |
35 | public GuiRows getRows() {
36 | return rows;
37 | }
38 |
39 | /**
40 | * Sets the rows of the Gui
41 | * @param rows The rows of the Gui
42 | */
43 | public void setRows(GuiRows rows) {
44 | this.rows = rows;
45 | }
46 |
47 | public LinkedHashMap getButtons() {
48 | return buttons;
49 | }
50 |
51 | /**
52 | * Clear the buttons from the Gui
53 | */
54 | public void clearButtons(){
55 | this.buttons.clear();
56 | }
57 |
58 | /**
59 | * Sets a new button in the Gui overriding it if it already exists
60 | * @param slot The slot of the button to add
61 | * @param entry The entry of the button to add
62 | */
63 | public void setButton(int slot, GuiEntry entry) {
64 | buttons.put(slot, entry);
65 | }
66 |
67 | /**
68 | * Adds the button to the first empty slot
69 | * @param entry The entry of the button to add
70 | */
71 | public void addButton(GuiEntry entry){
72 | for(int i = 0; i < this.rows.size; i++){
73 | if(!this.buttons.containsKey(i)){
74 | this.buttons.put(i, entry);
75 | break;
76 | }
77 | }
78 | }
79 |
80 | /**
81 | * Fills all the empty slots with the given entry
82 | * @param entry The entry of the button to add to all the empty slots
83 | * @since 5.2.1
84 | */
85 | public void fillEmptySlotsWithEntry(GuiEntry entry){
86 | for(int i = 0; i < this.rows.size; i++){
87 | if(!this.buttons.containsKey(i)){
88 | this.setButton(i, entry);
89 | }
90 | }
91 | }
92 |
93 | /**
94 | * Fills the empty slots with the empty item.
95 | * See {@link xyz.theprogramsrc.supercoreapi.spigot.items.PreloadedItems#emptyItem}
96 | * @since 5.2.1
97 | */
98 | public void fillEmptySlots(){
99 | this.fillEmptySlotsWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()));
100 | }
101 |
102 | /**
103 | * Fills the specified slots with the specified entry.
104 | * @param entry The entry of the button to add to the given slots
105 | * @param slots The slots to fill
106 | * @since 5.2.1
107 | */
108 |
109 | public void fillWithEntry(GuiEntry entry, int[] slots){
110 | for(int slot : slots){
111 | this.setButton(slot, entry);
112 | }
113 | }
114 |
115 | /**
116 | * Fills the specified slots with an empty item.
117 | * @param slots The slots to fill with the empty item
118 | * @since 5.2.1
119 | */
120 | public void fillWithEmptyItem(int[] slots){
121 | this.fillWithEntry(new GuiEntry(this.getPreloadedItems().emptyItem()), slots);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/hologram/Hologram.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.hologram;
2 |
3 | import org.bukkit.Location;
4 | import org.bukkit.entity.ArmorStand;
5 | import org.bukkit.entity.EntityType;
6 | import org.bukkit.event.EventHandler;
7 | import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
8 | import org.bukkit.event.player.PlayerInteractEntityEvent;
9 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
10 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;
11 |
12 | import java.util.LinkedList;
13 |
14 | public class Hologram extends SpigotModule {
15 |
16 | private final LinkedList lines;
17 | private final LinkedList armorStands;
18 | private final Location location;
19 |
20 | /**
21 | * Create a new Hologram
22 | * @param location The location
23 | * @param lines The content of the hologram
24 | */
25 | public Hologram(Location location, LinkedList lines){
26 | String worldName = location.getWorld() == null ? "Unknown World" : location.getWorld().getName();
27 | this.debug("Registering Hologram with " + lines.size() + " lines in the world '" + worldName + "'");
28 | this.location = location;
29 | this.armorStands = new LinkedList<>();
30 | this.lines = lines;
31 | this.loadHologram();
32 | }
33 |
34 | /**
35 | * Loads the hologram
36 | */
37 | public void loadHologram(){
38 | try{
39 | for(double i = 0.0; i < this.lines.size(); ++i){
40 | String line = this.lines.get((int) i);
41 | double y = this.location.getY() - (i / 5);
42 | Location loc = new Location(this.location.getWorld(), this.location.getX(), y, this.location.getZ(), this.location.getYaw(), this.location.getPitch());
43 | ArmorStand armorStand = ((ArmorStand) Utils.requireNonNull(loc.getWorld()).spawnEntity(loc, EntityType.ARMOR_STAND));
44 | armorStand.setGravity(false);
45 | armorStand.setArms(false);
46 | armorStand.setBasePlate(false);
47 | armorStand.setSmall(true);
48 | armorStand.setVisible(false);
49 | armorStand.setCustomName(Utils.ct(line));
50 | armorStand.setCustomNameVisible(true);
51 | this.armorStands.add(armorStand);
52 | }
53 | }catch (Exception ex){
54 | ex.printStackTrace();
55 | }
56 | }
57 |
58 | /**
59 | * Unloads the hologram
60 | */
61 | public void unloadHologram(){
62 | for(ArmorStand armorStand : this.armorStands){
63 | armorStand.remove();
64 | }
65 | }
66 |
67 | /**
68 | * Sets the specified line in the specified index
69 | * @param index the index
70 | * @param text the text to place
71 | */
72 | public void setLine(int index, String text){
73 | this.lines.set(index,text);
74 | this.unloadHologram();
75 | this.loadHologram();
76 | }
77 |
78 | /**
79 | * Adds a line at the bottom of the hologram
80 | * @param text the text to add
81 | */
82 | public void addLine(String text){
83 | this.lines.add(text);
84 | this.unloadHologram();
85 | this.loadHologram();
86 | }
87 |
88 | @EventHandler
89 | public void onInteract(PlayerInteractEntityEvent e){
90 | if(e.getRightClicked() instanceof ArmorStand){
91 | ArmorStand armorStand = ((ArmorStand) e.getRightClicked());
92 | if(!armorStand.isVisible()){
93 | e.setCancelled(true);
94 | }
95 | }
96 | }
97 |
98 | @EventHandler
99 | public void onManipulate(PlayerArmorStandManipulateEvent e){
100 | if(!e.getRightClicked().isVisible()){
101 | e.setCancelled(true);
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/dependencies/Dependency.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of LuckPerms, licensed under the MIT License.
3 | *
4 | * Copyright (c) lucko (Luck)
5 | * Copyright (c) contributors
6 | *
7 | * Permission is hereby granted, free of charge, to any person obtaining a copy
8 | * of this software and associated documentation files (the "Software"), to deal
9 | * in the Software without restriction, including without limitation the rights
10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the Software is
12 | * furnished to do so, subject to the following conditions:
13 | *
14 | * The above copyright notice and this permission notice shall be included in all
15 | * copies or substantial portions of the Software.
16 | *
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 | * SOFTWARE.
24 | */
25 | package xyz.theprogramsrc.supercoreapi.global.dependencies;
26 |
27 | import com.google.common.collect.ImmutableList;
28 | import xyz.theprogramsrc.supercoreapi.global.dependencies.classloader.LoaderType;
29 |
30 | import java.net.URL;
31 | import java.util.Base64;
32 | import java.util.List;
33 |
34 | public class Dependency {
35 |
36 | private static final String MAVEN_FORMAT = "%s/%s/%s/%s-%s.jar";
37 |
38 | private final String name;
39 | private final List urls;
40 | private final String version;
41 | private final byte[] checksum;
42 | private boolean autoLoad;
43 | private LoaderType loaderType;
44 |
45 | public Dependency(String name, String groupId, String artifactId, String version, String checksum, LoaderType loaderType) {
46 | this.name = name;
47 | this.autoLoad = true;
48 | this.loaderType = loaderType;
49 |
50 | String path = String.format(MAVEN_FORMAT,
51 | rewriteEscaping(groupId).replace(".", "/"),
52 | rewriteEscaping(artifactId),
53 | version,
54 | rewriteEscaping(artifactId),
55 | version
56 | );
57 | try {
58 | ImmutableList.Builder b = ImmutableList.builder();
59 | for(Repositories r : Repositories.values()){
60 | b.add(new URL(r.getURL() + path));
61 | }
62 | this.urls = b.build();
63 | } catch (Exception e) {
64 | throw new RuntimeException(e); // propagate
65 | }
66 | this.version = version;
67 | this.checksum = Base64.getDecoder().decode(checksum);
68 | }
69 |
70 | private static String rewriteEscaping(String s) {
71 | return s.replace("{}", ".");
72 | }
73 |
74 | public static String getMavenFormat() {
75 | return MAVEN_FORMAT;
76 | }
77 |
78 | public String getName() {
79 | return name;
80 | }
81 |
82 | public List getUrls() {
83 | return urls;
84 | }
85 |
86 | public String getVersion() {
87 | return version;
88 | }
89 |
90 | public byte[] getChecksum() {
91 | return checksum;
92 | }
93 |
94 | public boolean isAutoLoad() {
95 | return autoLoad;
96 | }
97 |
98 | public LoaderType getLoaderType() {
99 | return loaderType;
100 | }
101 |
102 | public void setAutoLoad(boolean autoLoad) {
103 | this.autoLoad = autoLoad;
104 | }
105 |
106 | public void setLoaderType(LoaderType loaderType) {
107 | this.loaderType = loaderType;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/gui/precreated/settings/SettingsGui.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.gui.precreated.settings;
2 |
3 | import org.bukkit.entity.Player;
4 |
5 | import xyz.theprogramsrc.supercoreapi.global.translations.Base;
6 | import xyz.theprogramsrc.supercoreapi.spigot.gui.Gui;
7 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiAction;
8 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiEntry;
9 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiModel;
10 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiRows;
11 | import xyz.theprogramsrc.supercoreapi.spigot.gui.objets.GuiTitle;
12 |
13 | public abstract class SettingsGui extends Gui{
14 |
15 | private final int[] containerSlots = {
16 | 19, 20, 21, 22, 23, 24, 25,
17 | 28, 29, 30, 31, 32, 33, 34,
18 | 37, 38, 39, 40, 41, 42, 43,
19 | };
20 | private int current;
21 | private SettingPane[] settingPanes;
22 |
23 | public SettingsGui(Player player){
24 | super(player, false);
25 | this.current = -1;
26 | this.settingPanes = this.getSettingPanes();
27 | this.open();
28 | }
29 |
30 | @Override
31 | public void open() {
32 | this.settingPanes = this.getSettingPanes();
33 | if(this.settingPanes == null)
34 | this.settingPanes = new SettingPane[0];
35 | super.open();
36 | }
37 |
38 | @Override
39 | public GuiRows getRows() {
40 | if(this.current == -1){
41 | return GuiRows.SIX;
42 | }
43 |
44 | SettingPane settingPane = this.settingPanes[this.current];
45 | return settingPane.getRows() != null ? settingPane.getRows() : GuiRows.SIX;
46 | }
47 |
48 | @Override
49 | public GuiTitle getTitle() {
50 | String result;
51 | if(this.current != -1){
52 | SettingPane settingPane = this.settingPanes[this.current];
53 | result = "&c" + Base.SETTING_PANE_GUI_TITLE.options().placeholder("{Setting}", settingPane.getDisplayName()).get();
54 | }else{
55 | result = "&c" + Base.SETTINGS_GUI_TITLE;
56 | }
57 |
58 | return GuiTitle.of(result);
59 | }
60 |
61 | @Override
62 | public void onBuild(GuiModel model) {
63 | model.clearButtons();
64 | if(this.current == -1){
65 | model.setButton(0, new GuiEntry(this.getPreloadedItems().getBackItem(), this::onBack));
66 | for(int i = 0; i < this.containerSlots.length; i++){
67 | int slot = this.containerSlots[i];
68 | if(i < this.settingPanes.length){
69 | int newCurrent = i;
70 | model.setButton(slot, new GuiEntry(this.settingPanes[i].getDisplayItem(), a -> {
71 | this.current = newCurrent;
72 | this.open();
73 | }));
74 | }else{
75 | model.setButton(slot, new GuiEntry(this.getPreloadedItems().emptyItem()));
76 | }
77 | }
78 | }else{
79 | SettingPane pane = this.settingPanes[current];
80 | int[] paneContainerSlots = pane.getContainerSlots();
81 | GuiEntry[] paneEntries = pane.getButtons();
82 | for(int i = 0; i < paneContainerSlots.length; i++){
83 | int slot = paneContainerSlots[i];
84 | if(i < paneEntries.length){
85 | model.setButton(slot, paneEntries[i]);
86 | }else{
87 | if(pane.showItemsForEmpty()){
88 | model.setButton(slot, new GuiEntry(this.getPreloadedItems().emptyItem()));
89 | }
90 | }
91 | }
92 |
93 | model.setButton(0, new GuiEntry(this.getPreloadedItems().getBackItem(), a -> {
94 | this.current = -1;
95 | this.open();
96 | }));
97 | }
98 | }
99 |
100 | public abstract SettingPane[] getSettingPanes();
101 |
102 | public abstract void onBack(GuiAction action);
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/bungee/commands/BungeeCommand.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.bungee.commands;
2 |
3 | import net.md_5.bungee.api.CommandSender;
4 | import net.md_5.bungee.api.chat.TextComponent;
5 | import net.md_5.bungee.api.connection.ProxiedPlayer;
6 | import net.md_5.bungee.api.plugin.Command;
7 | import xyz.theprogramsrc.supercoreapi.bungee.BungeeModule;
8 | import xyz.theprogramsrc.supercoreapi.bungee.utils.BungeeConsole;
9 | import xyz.theprogramsrc.supercoreapi.global.translations.Base;
10 |
11 | /**
12 | * BungeeCommand is a representation of a {@link Command Command}
13 | * with ease of control and customization.
14 | */
15 | public abstract class BungeeCommand extends BungeeModule {
16 |
17 | /**
18 | * Create a new {@link BungeeCommand BungeeCommand}
19 | */
20 | public BungeeCommand(){
21 | this.debug("Registering command '" + this.getCommand() + "'");
22 | getProxy().getPluginManager().registerCommand(this.bungeePlugin, new Command(this.getCommand(), this.getPermission(), this.getAliases()) {
23 | @Override
24 | public void execute(CommandSender sender, String[] args) {
25 | CommandResult result;
26 | if(sender instanceof ProxiedPlayer){
27 | ProxiedPlayer player = ((ProxiedPlayer) sender);
28 | result = BungeeCommand.this.onPlayerExecute(player, args);
29 | }else{
30 | result = BungeeCommand.this.onConsoleExecute(new BungeeConsole(), args);
31 | }
32 | BungeeCommand.this.onResult(sender, result);
33 | }
34 | });
35 | }
36 |
37 | private void onResult(CommandSender sender, CommandResult result){
38 | if(result == CommandResult.NO_PERMISSION){
39 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NO_PERMISSION.toString())));
40 | }else if(result == CommandResult.NO_ACCESS){
41 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NO_ACCESS.toString())));
42 | }else if(result == CommandResult.NOT_SUPPORTED){
43 | if(sender instanceof ProxiedPlayer){
44 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.CONSOLE.toString()).toString())));
45 | }else{
46 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.NOT_SUPPORTED.options().vars(Base.PLAYERS.toString()).toString())));
47 | }
48 | }else if(result == CommandResult.INVALID_ARGS){
49 | sender.sendMessage(new TextComponent(this.bungeePlugin.getSuperUtils().color(Base.INVALID_ARGUMENTS.toString())));
50 | }
51 | }
52 |
53 | /**
54 | * Gets the command executed to run the {@link BungeeCommand BungeeCommand}
55 | * @return The command
56 | */
57 | public abstract String getCommand();
58 |
59 | /**
60 | * Gets the permission to use the command
61 | *
62 | * @return The permission to use the command
63 | * @see #getCommand()
64 | */
65 | public String getPermission(){
66 | return null;
67 | }
68 |
69 | /**
70 | * Gets all the available aliases.
71 | * The aliases are more commands to run the {@link BungeeCommand BungeeCommand}
72 | *
73 | * @return The aliases
74 | */
75 | public String[] getAliases(){
76 | return new String[0];
77 | }
78 |
79 | /**
80 | * Executed when a player executes the command
81 | *
82 | * @param player Who execute the command
83 | * @param args The arguments of the command
84 | * @return The {@link CommandResult Result} of the command
85 | */
86 | public abstract CommandResult onPlayerExecute(ProxiedPlayer player, String[] args);
87 |
88 | /**
89 | * Executed when the console executes the command
90 | *
91 | * @param console The console
92 | * @param args The arguments of the command
93 | * @return The {@link CommandResult Result} of the command
94 | */
95 | public abstract CommandResult onConsoleExecute(BungeeConsole console, String[] args);
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/precreated/settings/SettingsGUI.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.settings;
2 |
3 | import java.util.LinkedList;
4 |
5 | import org.bukkit.entity.Player;
6 |
7 | import xyz.theprogramsrc.supercoreapi.global.translations.Base;
8 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUI;
9 | import xyz.theprogramsrc.supercoreapi.spigot.guis.GUIButton;
10 | import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction;
11 | import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows;
12 |
13 | /**
14 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}.
15 | */
16 | @Deprecated public abstract class SettingsGUI extends GUI {
17 |
18 | private final int[] containerSlots = {
19 | 19, 20, 21, 22, 23, 24, 25,
20 | 28, 29, 30, 31, 32, 33, 34,
21 | 37, 38, 39, 40, 41, 42, 43,
22 | };
23 | private int current;
24 | private SettingPane[] settingPanes;
25 |
26 | public SettingsGUI(Player player) {
27 | super(player);
28 | this.current = -1;
29 | this.settingPanes = this.getSettingPanes();
30 | this.open();
31 | }
32 |
33 | @Override
34 | public void open() {
35 | this.settingPanes = this.getSettingPanes();
36 | if(this.settingPanes == null)
37 | this.settingPanes = new SettingPane[0];
38 | super.open();
39 | }
40 |
41 | @Override
42 | protected GUIRows getRows() {
43 | if(this.current == -1){
44 | return GUIRows.SIX;
45 | }
46 |
47 | SettingPane settingPane = this.settingPanes[this.current];
48 | return settingPane.getRows() != null ? settingPane.getRows() : GUIRows.SIX;
49 | }
50 |
51 | @Override
52 | protected String getTitle() {
53 | if(this.current != -1){
54 | SettingPane settingPane = this.settingPanes[this.current];
55 | return "&c" + Base.SETTING_PANE_GUI_TITLE.options().placeholder("{Setting}", settingPane.getDisplayName()).get();
56 | }
57 |
58 | return "&c" + Base.SETTINGS_GUI_TITLE;
59 | }
60 |
61 | public abstract SettingPane[] getSettingPanes();
62 |
63 | @Override
64 | protected GUIButton[] getButtons() {
65 | LinkedList buttons = new LinkedList<>();
66 | this.clearButtons();
67 | if(this.current == -1){
68 | buttons.add(new GUIButton(0, this.getPreloadedItems().getBackItem(), this::onBack));
69 |
70 | for(int i = 0; i < this.containerSlots.length; ++i){
71 | int slot = this.containerSlots[i];
72 | if(i < this.settingPanes.length){
73 | int finalI = i;
74 | buttons.add(new GUIButton(slot, this.settingPanes[i].getDisplayItem(), a-> {
75 | this.current = finalI;
76 | this.open();
77 | }));
78 | }else{
79 | buttons.add(new GUIButton(slot, this.getPreloadedItems().emptyItem()));
80 | }
81 | }
82 | }else{
83 | SettingPane pane = this.settingPanes[current];
84 | int[] _containerSlots = pane.getContainerSlots();
85 | GUIButton[] paneButtons = pane.getButtons();
86 | for(int i = 0; i < _containerSlots.length; ++i){
87 | int slot = _containerSlots[i];
88 | if(i < paneButtons.length){
89 | buttons.add(paneButtons[i].setSlot(slot));
90 | }else{
91 | if(pane.showItemsForEmpty()){
92 | buttons.add(new GUIButton(slot, this.getPreloadedItems().emptyItem()));
93 | }
94 | }
95 | }
96 | buttons.add(new GUIButton(0, this.getPreloadedItems().getBackItem(), a-> {
97 | this.current = -1;
98 | this.open();
99 | }));
100 | }
101 | return buttons.toArray(new GUIButton[0]);
102 | }
103 |
104 | public abstract void onBack(ClickAction clickAction);
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/recipes/RecipeCreator.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.recipes;
2 |
3 | import org.bukkit.event.EventHandler;
4 | import org.bukkit.event.inventory.PrepareItemCraftEvent;
5 | import org.bukkit.inventory.CraftingInventory;
6 | import org.bukkit.inventory.ItemStack;
7 | import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
8 | import xyz.theprogramsrc.supercoreapi.spigot.SpigotModule;
9 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
10 | import xyz.theprogramsrc.supercoreapi.spigot.utils.ItemUtils;
11 |
12 | import java.util.Arrays;
13 | import java.util.HashMap;
14 | import java.util.List;
15 | import java.util.Objects;
16 | import java.util.stream.Collectors;
17 |
18 | public class RecipeCreator extends SpigotModule {
19 |
20 | private final HashMap recipes;
21 |
22 | /**
23 | * Create a new custom recipe!
24 | */
25 | public RecipeCreator(){
26 | this.recipes = new HashMap<>();
27 | }
28 |
29 | public void addRecipe(String id, CustomRecipe recipe){
30 | if(this.recipes.containsKey(id)){
31 | throw new IllegalArgumentException("The identifier '" + id + "' is already in use!");
32 | }else{
33 | this.recipes.put(id, recipe);
34 | }
35 | }
36 |
37 | public void removeRecipe(String id){
38 | this.recipes.remove(id);
39 | }
40 |
41 | public HashMap getRecipes() {
42 | return recipes;
43 | }
44 |
45 | @EventHandler
46 | public void onCraftPrepare(PrepareItemCraftEvent event){
47 | if(!event.isRepair()){
48 | CraftingInventory inv = event.getInventory();
49 | HashMap items = new HashMap<>();
50 | List contents = Arrays.stream(inv.getMatrix()).filter(Utils::nonNull).collect(Collectors.toList());
51 |
52 | for(int i = 1; i <= 9; ++i){
53 | items.put(i, inv.getItem(i));
54 | }
55 |
56 | for (CustomRecipe recipe : this.recipes.values()) {
57 | List unordered = Arrays.stream(recipe.getRecipeItems()).filter(i-> i.getSlot() == -1).map(RecipeItem::getItem).filter(Objects::nonNull).collect(Collectors.toList());
58 | if(!unordered.isEmpty()){
59 | if(contents.containsAll(unordered)){
60 | inv.setResult(recipe.getResult());
61 | }
62 | }else{
63 | HashMap recipes = new HashMap<>();
64 | Arrays.stream(recipe.getRecipeItems()).filter(i-> i.getSlot() != -1).forEach(r-> recipes.put(r.getSlot(), r.getItem()));
65 | int matches = 0;
66 | for(int i = 1; i <= 9; ++i){
67 | ItemStack recipeItem = recipes.get(i);
68 | ItemStack inCraft = items.get(i);
69 | if(inCraft != null && recipeItem != null){
70 | if(check(inCraft, recipeItem)){
71 | matches++;
72 | }
73 | }
74 | }
75 |
76 | if(matches == recipes.size()){
77 | inv.setResult(recipe.getResult());
78 | }
79 | }
80 | }
81 | }
82 | }
83 |
84 | private boolean check(ItemStack i1, ItemStack i2){
85 | SimpleItem s1 = new SimpleItem(i1), s2 = new SimpleItem(i2);
86 | boolean base = ItemUtils.check(i1, i2), lore = ItemUtils.checkLore(i1, i2), name = ItemUtils.checkName(i1, i2, false), type = ItemUtils.checkType(i1, i2);
87 | if(!s1.hasLore() || !s2.hasLore()){
88 | if(!s1.hasDisplayName() || !s2.hasDisplayName()){
89 | return base && type;
90 | }else{
91 | return base && type && name;
92 | }
93 | }else{
94 | if(!s1.hasDisplayName() || !s2.hasDisplayName()){
95 | return base && type && lore;
96 | }else{
97 | return base && type && lore && name;
98 | }
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/global/storage/MySQLDataBase.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.global.storage;
2 |
3 | import java.sql.Connection;
4 |
5 | import com.zaxxer.hikari.HikariConfig;
6 | import com.zaxxer.hikari.HikariDataSource;
7 |
8 | import xyz.theprogramsrc.supercoreapi.SuperPlugin;
9 | import xyz.theprogramsrc.supercoreapi.global.LogsFilter;
10 |
11 | public abstract class MySQLDataBase implements DataBase {
12 |
13 | protected Connection connection;
14 | private HikariDataSource dataSource;
15 | protected SuperPlugin> plugin;
16 | private boolean loaded;
17 |
18 | public MySQLDataBase(SuperPlugin> plugin) {
19 | boolean debug = plugin != null && plugin.isDebugEnabled();
20 | this.plugin = plugin;
21 | this.log("Connecting to '" + getDataBaseSettings().host() + ":" + getDataBaseSettings().port() + "'...");
22 | if (this.hideHikariLogs() && !debug) {
23 | new LogsFilter(LogsFilter.FilterResult.DENY, "com.zaxxer.hikari").register();
24 | }
25 | if (plugin != null) this.plugin.debug("Loading HikariConfig");
26 | HikariConfig cfg = new HikariConfig();
27 | cfg.setJdbcUrl(
28 | getDataBaseSettings().getURL()
29 | .replace("{Host}", getDataBaseSettings().host())
30 | .replace("{Port}", getDataBaseSettings().port())
31 | .replace("{Database}", getDataBaseSettings().database())
32 | .replace("{UseSSL}", Boolean.toString(getDataBaseSettings().useSSL()))
33 | );
34 | cfg.setUsername(getDataBaseSettings().username());
35 | cfg.setPassword(getDataBaseSettings().password());
36 | cfg.setMaximumPoolSize(3);
37 | this.processSettings(cfg);
38 |
39 | if (plugin != null) this.plugin.debug("Loading HikariDataSource");
40 | try {
41 | this.dataSource = new HikariDataSource(cfg);
42 | this.loaded = true;
43 | } catch (Exception ex) {
44 | this.log("&cCannot connect to MySQL DataBase:");
45 | if (plugin != null) this.plugin.addError(ex);
46 | ex.printStackTrace();
47 | }
48 | }
49 |
50 | /**
51 | * Process the Hikari Settings
52 | * @param config the hikari config
53 | */
54 | public void processSettings(HikariConfig config){
55 |
56 | }
57 |
58 | /**
59 | * Used to check if the Connection is loaded
60 | *
61 | * @return if the connection is loaded
62 | */
63 | @Override
64 | public boolean isLoaded() {
65 | return this.loaded;
66 | }
67 |
68 | /**
69 | * Closes the connection between the plugin and the DataBase
70 | */
71 | @Override
72 | public void closeConnection() {
73 | if (this.plugin != null) this.plugin.debug("Closing connection with DataBase");
74 | try {
75 | if (this.dataSource != null) {
76 | this.dataSource.close();
77 | }
78 | } catch (Exception ex) {
79 | this.log("&cCannot close MySQL Connection:");
80 | if (this.plugin != null) this.plugin.addError(ex);
81 | ex.printStackTrace();
82 | }
83 | }
84 |
85 | /**
86 | * Used to connect to the DataBase and execute a {@link xyz.theprogramsrc.supercoreapi.global.storage.DataBase.ConnectionCall ConnectionCall}
87 | *
88 | * @param call ConnectionCall to execute
89 | */
90 | @Override
91 | public void connect(ConnectionCall call) {
92 | try (Connection connection = this.dataSource.getConnection()) {
93 | call.onConnect(connection);
94 | } catch (Exception ex) {
95 | this.log("&cCannot execute MySQL Connection Call:");
96 | if (this.plugin != null) this.plugin.addError(ex);
97 | ex.printStackTrace();
98 | }
99 | }
100 |
101 | /**
102 | * @return true to hide the hikaricp logs, otherwise false
103 | */
104 | public boolean hideHikariLogs() {
105 | return true;
106 | }
107 |
108 | private void log(String msg){
109 | if(this.plugin == null)
110 | System.out.println(msg);
111 | else
112 | this.plugin.log(msg);
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/GUIButton.java:
--------------------------------------------------------------------------------
1 | package xyz.theprogramsrc.supercoreapi.spigot.guis;
2 |
3 | import org.bukkit.inventory.ItemStack;
4 |
5 | import xyz.theprogramsrc.supercoreapi.spigot.guis.action.Action;
6 | import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
7 |
8 | /**
9 | * Representation of a GUI Button
10 | * @deprecated As of version 5.2.0 the GUI system has been replaced with {@link xyz.theprogramsrc.supercoreapi.spigot.gui.Gui}.
11 | */
12 | @Deprecated public class GUIButton {
13 |
14 | private int slot;
15 | private final ItemStack itemStack;
16 | private Action action;
17 |
18 | /**
19 | * Constructor of a GUI Button
20 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png)
21 | * @param itemStack The item to place {@link SimpleItem}
22 | * @param action The action to execute when is clicked
23 | */
24 | public GUIButton(int slot, ItemStack itemStack, Action action){
25 | this.slot = slot;
26 | this.itemStack = itemStack;
27 | this.action = action;
28 | }
29 |
30 | /**
31 | * Constructor of a GUI Button
32 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png)
33 | * @param simpleItem The item to place
34 | * @param action The action to execute when is clicked
35 | */
36 | public GUIButton(int slot, SimpleItem simpleItem, Action action){
37 | this(slot, simpleItem.build(), action);
38 | }
39 |
40 | /**
41 | * Constructor of a GUI Button
42 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png)
43 | * @param itemStack The item to place {@link SimpleItem}
44 | */
45 | public GUIButton(int slot, ItemStack itemStack) {
46 | this(slot, itemStack, null);
47 | }
48 |
49 | /**
50 | * Constructor of a GUI Button
51 | * @param slot The slot where should be placed (See https://i.theprogramsrc.xyz/files/DoubleChest-slots.png)
52 | * @param simpleItem The item to place
53 | */
54 | public GUIButton(int slot, SimpleItem simpleItem){
55 | this(slot, simpleItem.build());
56 | }
57 |
58 | /**
59 | * Constructor of a GUI Button
60 | * @param itemStack The item to place {@link SimpleItem}
61 | */
62 | public GUIButton(ItemStack itemStack, Action action){
63 | this(-1, itemStack, action);
64 | }
65 |
66 | /**
67 | * Constructor of a GUI Button
68 | * @param simpleItem The item to place
69 | */
70 | public GUIButton(SimpleItem simpleItem, Action action){
71 | this(simpleItem.build(), action);
72 | }
73 |
74 | /**
75 | * Constructor of a GUI Button
76 | * @param itemStack The item to place {@link SimpleItem}
77 | */
78 | public GUIButton(ItemStack itemStack){
79 | this(-1, itemStack);
80 | }
81 |
82 | /**
83 | * Constructor of a GUI Button
84 | * @param simpleItem The item to place
85 | */
86 | public GUIButton(SimpleItem simpleItem){
87 | this(simpleItem.build());
88 | }
89 |
90 | /**
91 | * Sets the action to trigger when the button is clicked
92 | * @param action the action
93 | * @return this GUIButton
94 | */
95 | public GUIButton setAction(Action action) {
96 | this.action = action;
97 | return this;
98 | }
99 |
100 | /**
101 | * Sets the slot of this button
102 | * @param slot the slot
103 | * @return this GUIButton
104 | */
105 | public GUIButton setSlot(int slot){
106 | this.slot = slot;
107 | return this;
108 | }
109 |
110 | /**
111 | * Gets the action to trigger when the button is clicked
112 | * @return the action
113 | */
114 | public Action getAction() {
115 | return action;
116 | }
117 |
118 | /**
119 | * Gets the item to place
120 | * @return the item
121 | */
122 | public ItemStack getItemStack() {
123 | return itemStack;
124 | }
125 |
126 | /**
127 | * Gets the slot where should be placed the button
128 | * @return the slot
129 | */
130 | public int getSlot() {
131 | return slot;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------