Initial commit
This commit is contained in:
8
Plugins/PrincepDE/LobbySystem/.idea/.gitignore
generated
vendored
Normal file
8
Plugins/PrincepDE/LobbySystem/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
12
Plugins/PrincepDE/LobbySystem/.idea/LobbySystem.iml
generated
Normal file
12
Plugins/PrincepDE/LobbySystem/.idea/LobbySystem.iml
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
14
Plugins/PrincepDE/LobbySystem/.idea/compiler.xml
generated
Normal file
14
Plugins/PrincepDE/LobbySystem/.idea/compiler.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="lobbysystem" />
|
||||
<module name="LobbySystem" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
7
Plugins/PrincepDE/LobbySystem/.idea/discord.xml
generated
Normal file
7
Plugins/PrincepDE/LobbySystem/.idea/discord.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
||||
30
Plugins/PrincepDE/LobbySystem/.idea/jarRepositories.xml
generated
Normal file
30
Plugins/PrincepDE/LobbySystem/.idea/jarRepositories.xml
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spigotmc-repo" />
|
||||
<option name="name" value="spigotmc-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
11
Plugins/PrincepDE/LobbySystem/.idea/libraries/spigot_1_8_8.xml
generated
Normal file
11
Plugins/PrincepDE/LobbySystem/.idea/libraries/spigot_1_8_8.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="spigot 1.8.8">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../../Old/Spigot Versions/spigot 1.8.8.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
<root url="jar://$PROJECT_DIR$/../../Old/Spigot Versions/spigot 1.8.8.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
19
Plugins/PrincepDE/LobbySystem/.idea/misc.xml
generated
Normal file
19
Plugins/PrincepDE/LobbySystem/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<list size="1">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||
</list>
|
||||
</component>
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
124
Plugins/PrincepDE/LobbySystem/.idea/uiDesigner.xml
generated
Normal file
124
Plugins/PrincepDE/LobbySystem/.idea/uiDesigner.xml
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
||||
6
Plugins/PrincepDE/LobbySystem/.idea/vcs.xml
generated
Normal file
6
Plugins/PrincepDE/LobbySystem/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
12
Plugins/PrincepDE/LobbySystem/LobbySystem.iml
Normal file
12
Plugins/PrincepDE/LobbySystem/LobbySystem.iml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
</module>
|
||||
72
Plugins/PrincepDE/LobbySystem/pom.xml
Normal file
72
Plugins/PrincepDE/LobbySystem/pom.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?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>de.princep</groupId>
|
||||
<artifactId>LobbySystem</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<java.version>8</java.version>
|
||||
</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>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<version>LATEST</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,53 @@
|
||||
package de.princep.lobbysystem;
|
||||
|
||||
import de.princep.lobbysystem.annotations.AnnotationManager;
|
||||
import de.princep.lobbysystem.apis.HiderAPI;
|
||||
import de.princep.lobbysystem.apis.MySQL;
|
||||
import de.princep.lobbysystem.apis.CoinAPI;
|
||||
import de.princep.lobbysystem.apis.WingAPI;
|
||||
import de.princep.lobbysystem.join.JoinListener;
|
||||
import de.princep.lobbysystem.utils.LocationManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LobbySystem extends JavaPlugin {
|
||||
|
||||
public static LocationManager locationManager;
|
||||
|
||||
//Config
|
||||
public static File file;
|
||||
public static FileConfiguration cfg;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
locationManager = new LocationManager();
|
||||
|
||||
//Config
|
||||
saveDefaultConfig();
|
||||
LobbySystem.file = new File("plugins/Hub", "config.yml");
|
||||
LobbySystem.cfg = YamlConfiguration.loadConfiguration(LobbySystem.file);
|
||||
|
||||
AnnotationManager am = new AnnotationManager();
|
||||
am.addApiObject(new CoinAPI());
|
||||
am.addApiObject(new MySQL("localhost", 3306, "princep", "princep", "Fs427SX9TrAWFFx"));
|
||||
am.addApiObject(new HiderAPI());
|
||||
am.addApiObject(new WingAPI());
|
||||
|
||||
PluginManager pm = Bukkit.getPluginManager();
|
||||
pm.registerEvents(am.addObject(new JoinListener()), this);
|
||||
|
||||
am.initialiseFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package de.princep.lobbysystem.annotations;
|
||||
|
||||
public interface AnnotationAPI {
|
||||
void initialise();
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.princep.lobbysystem.annotations;
|
||||
|
||||
import io.github.classgraph.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AnnotationManager {
|
||||
|
||||
private final Map<Class<?>, Object> objects = new HashMap<>();
|
||||
private final Map<Class<? extends AnnotationAPI>, AnnotationAPI> apiObjects = new HashMap<>();
|
||||
|
||||
public void addApiObject(AnnotationAPI o) {
|
||||
apiObjects.put(o.getClass(), o);
|
||||
objects.put(o.getClass(), o);
|
||||
}
|
||||
|
||||
public AnnotationAPI getApiObject(Class<?> clazz) {
|
||||
return apiObjects.get(clazz);
|
||||
}
|
||||
|
||||
public <T> T addObject(T o) {
|
||||
objects.put(o.getClass(), o);
|
||||
return o;
|
||||
}
|
||||
|
||||
public Object getObject(Class<?> clazz) {
|
||||
return objects.get(clazz);
|
||||
}
|
||||
|
||||
public void initialiseFields() {
|
||||
try (ScanResult result = new ClassGraph()
|
||||
.enableAllInfo()
|
||||
.acceptPackages("de.princep.lobbysystem")
|
||||
.scan()) {
|
||||
ClassInfoList classInfos = result.getAllClasses();
|
||||
for (ClassInfo classInfo : classInfos) {
|
||||
FieldInfoList fieldInfos = classInfo.getFieldInfo();
|
||||
for (FieldInfo fieldInfo : fieldInfos) {
|
||||
if (fieldInfo.hasAnnotation(GetAPI.class.getName())) {
|
||||
Field field = fieldInfo.loadClassAndGetField();
|
||||
AnnotationAPI apiInstance = getApiObject(field.getType());
|
||||
boolean isStatic = Modifier.isStatic(field.getModifiers());
|
||||
field.set(isStatic ? null : getObject(field.getDeclaringClass()), apiInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
for (AnnotationAPI api : apiObjects.values()) {
|
||||
api.initialise();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.princep.lobbysystem.annotations;
|
||||
|
||||
public @interface GetAPI {
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.princep.lobbysystem.apis;
|
||||
|
||||
import de.princep.lobbysystem.annotations.AnnotationAPI;
|
||||
import de.princep.lobbysystem.annotations.GetAPI;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.*;
|
||||
|
||||
public class CoinAPI implements AnnotationAPI {
|
||||
@GetAPI
|
||||
public MySQL sql;
|
||||
private int startCoins = 0;
|
||||
|
||||
public void initialise() {
|
||||
sql.insert("CREATE TABLE IF NOT EXISTS Coins (UUID VARCHAR(20), Coins INT(20))");
|
||||
}
|
||||
|
||||
public void loadUser(UUID user) {
|
||||
if (getCoins(user) == -1) setCoins(user, startCoins);
|
||||
}
|
||||
|
||||
public void setStartCoins(int startCoins) { this.startCoins = startCoins; }
|
||||
|
||||
public void setCoins(UUID user, int coins) {
|
||||
sql.insert("DELETE FROM Coins WHERE UUID = \"" + user + "\"");
|
||||
if (coins < 0) coins *= -1;
|
||||
sql.insert("INSERT INTO Coins VALUES (\"" + user + "\", " + coins + ")");
|
||||
}
|
||||
|
||||
public int getCoins(UUID user) {
|
||||
try {
|
||||
ResultSet rs = sql.getData("SELECT Coins FROM Coins WHERE UUID = \"" + user + "\"");
|
||||
if (rs.next()) {
|
||||
return rs.getInt("Coins");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void addCoins(UUID user, int coins) {
|
||||
if (coins < 0) coins *= -1;
|
||||
setCoins(user, getCoins(user) + coins);
|
||||
}
|
||||
|
||||
public void removeCoins(UUID user, int coins) {
|
||||
if (coins > 0) coins *= -1;
|
||||
coins = getCoins(user) - coins;
|
||||
if (coins < 0) coins = 0;
|
||||
setCoins(user, coins);
|
||||
}
|
||||
|
||||
public boolean compare(UUID user, int coins) {
|
||||
return getCoins(user) >= coins;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package de.princep.lobbysystem.apis;
|
||||
|
||||
import de.princep.lobbysystem.annotations.AnnotationAPI;
|
||||
import de.princep.lobbysystem.annotations.GetAPI;
|
||||
import de.princep.lobbysystem.utils.Promissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HiderAPI implements AnnotationAPI {
|
||||
@GetAPI
|
||||
public MySQL sql;
|
||||
|
||||
@Override
|
||||
public void initialise() {
|
||||
sql.insert("CREATE TABLE IF NOT EXISTS Hider (UUID VARCHAR(100), ID INT(10))");
|
||||
}
|
||||
|
||||
private interface Executable { void execute(Player p, Player all); }
|
||||
|
||||
public enum State {
|
||||
HIDE_ALL(0, Material.SULPHUR, "§cKein Spieler sichtbar §7(Rechtsklick)", Player::hidePlayer),
|
||||
ONLY_VIP(1, Material.REDSTONE, "§5Nur VIPs §7(Rechtsklick)", (p, all) -> { if (all.hasPermission(Promissions.VIP)) p.showPlayer(all); else p.hidePlayer(all); }),
|
||||
SHOW_ALL(2, Material.GLOWSTONE_DUST, "§aAlle Spieler sichtbar §7(Rechtsklick)", Player::showPlayer);
|
||||
|
||||
private final int id;
|
||||
private final Material material;
|
||||
private final String name;
|
||||
private final Executable exe;
|
||||
|
||||
State(int id, Material material, String name, Executable exe) {
|
||||
this.material = material;
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.exe = exe;
|
||||
}
|
||||
|
||||
public int getID() { return id; }
|
||||
public ItemStack getItem() {
|
||||
ItemStack item = new ItemStack(material);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
public void manageHiding(Player p) { for (Player all : Bukkit.getOnlinePlayers()) exe.execute(p, all); }
|
||||
|
||||
public static State getByID(int id) {
|
||||
for (State state : values())
|
||||
if (state.getID() == id) return state;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public State getState(Player p) {
|
||||
try {
|
||||
ResultSet rs = sql.getData("SELECT ID FROM Hider WHERE UUID = \"" + p.getUniqueId() + "\"");
|
||||
if (rs == null || !rs.next()) {
|
||||
setState(p, State.SHOW_ALL);
|
||||
return State.SHOW_ALL;
|
||||
}
|
||||
int id = rs.getInt("ID");
|
||||
return State.getByID(id);
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return State.SHOW_ALL;
|
||||
}
|
||||
|
||||
public void setState(Player p, State state) {
|
||||
sql.insert("DELETE FROM Hider WHERE UUID = \"" + p.getUniqueId() + "\"");
|
||||
sql.insert("INSERT INTO Hider (UUID, ID) VALUES (\"" + p.getUniqueId() + "\", " + state.getID() + ")");
|
||||
}
|
||||
|
||||
private final HashMap<Player, Long> cooldowns = new HashMap<>();
|
||||
private final long cooldownInMilliseconds = 3000;
|
||||
public boolean checkCooldown(Player p) {
|
||||
if (!cooldowns.containsKey(p)) return true;
|
||||
long lastTime = cooldowns.get(p);
|
||||
long difference = System.currentTimeMillis() - lastTime;
|
||||
return difference >= cooldownInMilliseconds;
|
||||
}
|
||||
public void updateCooldown(Player p) {
|
||||
cooldowns.remove(p);
|
||||
cooldowns.put(p, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package de.princep.lobbysystem.apis;
|
||||
|
||||
import de.princep.lobbysystem.annotations.AnnotationAPI;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public class MySQL implements AnnotationAPI {
|
||||
protected String server;
|
||||
protected int port;
|
||||
protected String database;
|
||||
protected String username;
|
||||
protected String password;
|
||||
protected Connection con;
|
||||
|
||||
public MySQL(String server, int port, String database, String username, String password) {
|
||||
this.server = server;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public MySQL(String server, String database, String username, String password) { this(server, 3306, database, username, password); }
|
||||
|
||||
public void connect() {
|
||||
if (isConnected()) return;
|
||||
try {
|
||||
con = DriverManager.getConnection("jdbc:mysql://" + server + ":" + port + "/" + database, username, password);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (!isConnected()) return;
|
||||
try {
|
||||
con.close();
|
||||
con = null;
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public boolean isConnected() { return con != null; }
|
||||
|
||||
public void insert(String qry) {
|
||||
if (!isConnected()) throw new NullPointerException("MySQL not connected");
|
||||
try {
|
||||
con.prepareStatement(qry).executeUpdate();
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public ResultSet getData(String qry) {
|
||||
if (!isConnected()) throw new NullPointerException("MySQL not connected");
|
||||
try {
|
||||
return con.prepareStatement(qry).executeQuery();
|
||||
}catch (Exception e) { e.printStackTrace(); }
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialise() { connect(); }
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
package de.princep.lobbysystem.apis;
|
||||
|
||||
import de.princep.lobbysystem.annotations.AnnotationAPI;
|
||||
import de.princep.lobbysystem.annotations.GetAPI;
|
||||
import de.princep.lobbysystem.particlesystem.Particle;
|
||||
import de.princep.lobbysystem.particlesystem.ParticleEffect;
|
||||
import de.princep.lobbysystem.particlesystem.WingPattern;
|
||||
import de.princep.lobbysystem.utils.Promissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class WingAPI implements AnnotationAPI {
|
||||
public enum Wings {
|
||||
|
||||
NORMAL(0, WingPattern.NORMAL, WingPattern.NORMAL_DISTANCE, ParticleEffect.REDSTONE, ParticleEffect.FLAME, WingPattern.NORMAL_OFFSET),
|
||||
ADVANCED(1, WingPattern.ADVANCED, WingPattern.ADVANCED_DISTANCE, ParticleEffect.REDSTONE, ParticleEffect.FLAME, WingPattern.ADVANCED_OFFSET);
|
||||
|
||||
private final String[] pattern;
|
||||
private final float space;
|
||||
private final ParticleEffect smallPar;
|
||||
private final ParticleEffect largePar;
|
||||
private final float yOffset;
|
||||
private final int id;
|
||||
|
||||
Wings(int id, String[] pattern, float space, ParticleEffect smallPar, ParticleEffect largePar, float yOffset) {
|
||||
this.id = id;
|
||||
this.pattern = pattern;
|
||||
this.space = space;
|
||||
this.smallPar = smallPar;
|
||||
this.largePar = largePar;
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public String[] getPattern() { return pattern; }
|
||||
public float getSpace() { return space; }
|
||||
public ParticleEffect getSmallPar() { return smallPar; }
|
||||
public ParticleEffect getLargePar() { return largePar; }
|
||||
public float getYOffset() { return yOffset; }
|
||||
public int getId() { return id; }
|
||||
|
||||
public static Wings getById(int id) { return id == 0 ? NORMAL : ADVANCED; }
|
||||
}
|
||||
private enum WingSite {
|
||||
LEFT(0, 0.5f),
|
||||
RIGHT(180, 0.5f);
|
||||
|
||||
private final int rot;
|
||||
private final float xOffset;
|
||||
WingSite(int rot, float xOffset) { this.rot = rot; this.xOffset = xOffset; }
|
||||
public int getRot() { return rot; }
|
||||
public float getXOffset() { return xOffset; }
|
||||
}
|
||||
|
||||
@GetAPI
|
||||
public HiderAPI hider;
|
||||
@GetAPI
|
||||
public MySQL sql;
|
||||
|
||||
@Override
|
||||
public void initialise() {
|
||||
sql.insert("CREATE TABLE IF NOT EXISTS Wings (UUID VARCHAR(50), id INT(1))");
|
||||
}
|
||||
|
||||
private final HashMap<Player, Wings> activatedPlayerWings = new HashMap<>();
|
||||
|
||||
private Location getParticleLoc(Location orig, float x, float y, WingSite side, int animationState) {
|
||||
Location particleLoc = orig.clone();
|
||||
float yaw = particleLoc.getYaw();
|
||||
|
||||
int state = side.getRot() + animationState;
|
||||
|
||||
if (side == WingSite.LEFT)
|
||||
yaw -= state;
|
||||
else
|
||||
yaw += state;
|
||||
|
||||
double yawRad = Math.toRadians(yaw);
|
||||
Vector vector = new Vector(Math.cos(yawRad) * x, y, Math.sin(yawRad) * x);
|
||||
particleLoc.add(vector);
|
||||
particleLoc.setYaw(yaw);
|
||||
return particleLoc;
|
||||
}
|
||||
|
||||
private Particle[][] getParticlePositions(String[] pattern, float space, Location orig, ParticleEffect bigParticle, ParticleEffect smallParticle, WingSite site, float yOffset) {
|
||||
orig.setY(orig.getY() + yOffset);
|
||||
Particle[][] particles = new Particle[pattern.length][pattern[0].length()];
|
||||
|
||||
if (pattern == WingPattern.NORMAL) {
|
||||
for (int x = pattern.length - 1; x >= 0; x--)
|
||||
for (int y = 0; y < pattern[x].length(); y++) {
|
||||
float xp = space * (pattern[x].length() - x);
|
||||
float yp = space * (pattern[x].length() - y);
|
||||
Location parLoc = getParticleLoc(orig, xp + site.getXOffset(), yp, site, 20);
|
||||
char c = pattern[x].toCharArray()[y];
|
||||
if (c == '-') continue;
|
||||
if (c == '+')
|
||||
particles[x][y] = new Particle(parLoc, smallParticle);
|
||||
if (c == 'x')
|
||||
particles[x][y] = new Particle(parLoc, bigParticle);
|
||||
}
|
||||
return particles;
|
||||
}
|
||||
|
||||
for (int x = 0; x < pattern.length; x++)
|
||||
for (int y = 0; y < pattern[x].length(); y++) {
|
||||
float xp = space * (pattern[x].length() - x);
|
||||
float yp = space * (pattern[x].length() - y);
|
||||
Location parLoc = getParticleLoc(orig, xp + site.getXOffset(), yp, site, 20);
|
||||
char c = pattern[x].toCharArray()[y];
|
||||
if (c == '-') continue;
|
||||
if (c == '+')
|
||||
particles[x][y] = new Particle(parLoc, smallParticle);
|
||||
if (c == 'x')
|
||||
particles[x][y] = new Particle(parLoc, bigParticle);
|
||||
}
|
||||
return particles;
|
||||
}
|
||||
private void spawnParticles(Player[] players, Particle[][] particles) {
|
||||
for (Particle[] parX : particles)
|
||||
for (Particle particle : parX) {
|
||||
if (particle == null) continue;
|
||||
particle.effect.display(0, 0, 0, 0, 1, particle.location, players);
|
||||
}
|
||||
}
|
||||
private void showWings(Wings wings, Player p) {
|
||||
ArrayList<Player> players = new ArrayList<>();
|
||||
players.add(p);
|
||||
for (Player all : Bukkit.getOnlinePlayers()) {
|
||||
if (all == p) continue;
|
||||
if (!all.canSee(p)) continue;
|
||||
HiderAPI.State state = hider.getState(all);
|
||||
if (state == HiderAPI.State.SHOW_ALL || (p.hasPermission(Promissions.VIP) && state == HiderAPI.State.ONLY_VIP))
|
||||
players.add(all);
|
||||
}
|
||||
Particle[][] left = getParticlePositions(wings.getPattern(), wings.getSpace(), p.getLocation().clone(), wings.getLargePar(), wings.getSmallPar(), WingSite.LEFT, wings.getYOffset());
|
||||
Particle[][] right = getParticlePositions(wings.getPattern(), wings.getSpace(), p.getLocation().clone(), wings.getLargePar(), wings.getSmallPar(), WingSite.RIGHT, wings.getYOffset());
|
||||
spawnParticles(players.toArray(new Player[0]), left);
|
||||
spawnParticles(players.toArray(new Player[0]), right);
|
||||
}
|
||||
|
||||
public void activateWings(Player p, Wings wings) {
|
||||
deactivateWings(p); activatedPlayerWings.put(p, wings);
|
||||
}
|
||||
public void deactivateWings(Player p) { activatedPlayerWings.remove(p); }
|
||||
public Map<Player, Wings> getActivatedPlayerWings() { return activatedPlayerWings; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package de.princep.lobbysystem.gui;
|
||||
|
||||
import de.princep.lobbysystem.utils.ItemBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PlayerInvGUI implements Listener {
|
||||
|
||||
public static void addPlayerInv(Player player) {
|
||||
player.getInventory().clear();
|
||||
Inventory inventory = player.getInventory();
|
||||
|
||||
inventory.setItem(0, new ItemBuilder(Material.CHEST).setName("§6Inventar").build());
|
||||
inventory.setItem(1, new ItemBuilder(Material.NETHER_STAR).setName("§eShop").build());
|
||||
inventory.setItem(4, new ItemBuilder(Material.COMPASS).setName("§c§lNavigator").build());
|
||||
|
||||
//inventory.setItem(7, Hider.getState(player).getItem());
|
||||
|
||||
inventory.setItem(8, new ItemBuilder(player).setName("§b§l" + player.getName()).build());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction().equals(Action.RIGHT_CLICK_AIR) || event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
Player player = event.getPlayer();
|
||||
//if (Main.buildMode.contains(player)) return;
|
||||
event.setCancelled(true);
|
||||
|
||||
if (event.getItem() == null) return;
|
||||
switch (event.getItem().getType()) {
|
||||
case CHEST:
|
||||
//InventoryGUI.openInventory(player);
|
||||
break;
|
||||
|
||||
case NETHER_STAR:
|
||||
//ShopGUI
|
||||
break;
|
||||
|
||||
case COMPASS:
|
||||
//NavigationGUI.openNav(player);
|
||||
//TempNavGUI.openTemNav(player);
|
||||
break;
|
||||
|
||||
case SKULL_ITEM:
|
||||
//FRIENDGUI
|
||||
break;
|
||||
}
|
||||
/*if (event.getItem().getType() == Hider.getState(player).getItem().getType()) {
|
||||
if (!Hider.checkCooldown(player)) {
|
||||
//Send message
|
||||
Title.sendActionBar(player, Title.prefix + "§cRUHIG BRUDER! §7wir haben ja Zeit");
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
int id = Hider.getState(player).getID() + 1;
|
||||
if (id > Hider.State.values().length - 1) id = 0;
|
||||
Hider.setState(player, Objects.requireNonNull(Hider.State.getByID(id)));
|
||||
player.getInventory().setItem(7, Objects.requireNonNull(Hider.State.getByID(id)).getItem());
|
||||
Objects.requireNonNull(Hider.State.getByID(id)).manageHiding(player);
|
||||
Hider.updateCooldown(player);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.princep.lobbysystem.join;
|
||||
|
||||
import de.princep.lobbysystem.LobbySystem;
|
||||
import de.princep.lobbysystem.annotations.GetAPI;
|
||||
import de.princep.lobbysystem.apis.CoinAPI;
|
||||
import de.princep.lobbysystem.gui.PlayerInvGUI;
|
||||
import de.princep.lobbysystem.utils.Title;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class JoinListener implements Listener {
|
||||
@GetAPI
|
||||
public CoinAPI coinAPI;
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
coinAPI.loadUser(event.getPlayer().getUniqueId());
|
||||
System.out.println(coinAPI.getCoins(event.getPlayer().getUniqueId()));
|
||||
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//Msg
|
||||
event.setJoinMessage(null);
|
||||
|
||||
//Gamemode
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
//XP
|
||||
player.setLevel(2021);
|
||||
|
||||
//Inv
|
||||
PlayerInvGUI.addPlayerInv(player);
|
||||
|
||||
//spawn loc
|
||||
Location l = null;
|
||||
try {
|
||||
l = LobbySystem.locationManager.getLocation();
|
||||
} catch (Exception ignored) { }
|
||||
if (!(l == null)) {
|
||||
player.teleport(LobbySystem.locationManager.getLocation());
|
||||
player.playSound(player.getLocation(), Sound.LEVEL_UP, 1, 2);
|
||||
} else {
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 1, 1);
|
||||
player.sendMessage("§8»");
|
||||
player.sendMessage(Title.prefix + "§7Der Spawn wurde noch nicht gesetzt.");
|
||||
player.sendMessage(Title.prefix + "§7Bitte wende dich an einen Serveradministrator.");
|
||||
player.sendMessage("§8»");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.princep.lobbysystem.particlesystem;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Particle {
|
||||
public Location location;
|
||||
public ParticleEffect effect;
|
||||
|
||||
public Particle(Location loc, ParticleEffect e) { location = loc; effect = e; }
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,602 @@
|
||||
package de.princep.lobbysystem.particlesystem;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* <b>ReflectionUtils</b>
|
||||
* <p>
|
||||
* This class provides useful methods which makes dealing with reflection much easier, especially when working with Bukkit
|
||||
* <p>
|
||||
* You are welcome to use it, modify it and redistribute it under the following conditions:
|
||||
* <ul>
|
||||
* <li>Don't claim this class as your own
|
||||
* <li>Don't remove this disclaimer
|
||||
* </ul>
|
||||
* <p>
|
||||
* <i>It would be nice if you provide credit to me if you use this class in a published project</i>
|
||||
*
|
||||
* @author DarkBlade12
|
||||
* @version 1.1
|
||||
*/
|
||||
public final class ReflectionUtils {
|
||||
// Prevent accidental construction
|
||||
private ReflectionUtils() {}
|
||||
|
||||
/**
|
||||
* Returns the constructor of a given class with the given parameter types
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param parameterTypes Parameter types of the desired constructor
|
||||
* @return The constructor of the target class with the specified parameter types
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
|
||||
* @see DataType
|
||||
* @see DataType#getPrimitive(Class[])
|
||||
* @see DataType#compare(Class[], Class[])
|
||||
*/
|
||||
public static Constructor<?> getConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes);
|
||||
for (Constructor<?> constructor : clazz.getConstructors()) {
|
||||
if (!DataType.compare(DataType.getPrimitive(constructor.getParameterTypes()), primitiveTypes)) {
|
||||
continue;
|
||||
}
|
||||
return constructor;
|
||||
}
|
||||
throw new NoSuchMethodException("There is no such constructor in this class with the specified parameter types");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructor of a desired class with the given parameter types
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param parameterTypes Parameter types of the desired constructor
|
||||
* @return The constructor of the desired target class with the specified parameter types
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified parameter types cannot be found
|
||||
* @throws ClassNotFoundException ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getConstructor(Class, Class...)
|
||||
*/
|
||||
public static Constructor<?> getConstructor(String className, PackageType packageType, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
|
||||
return getConstructor(packageType.getClass(className), parameterTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a class with the given arguments
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param arguments Arguments which are used to construct an object of the target class
|
||||
* @return The instance of the target class with the specified arguments
|
||||
* @throws InstantiationException If you cannot create an instance of the target class due to certain circumstances
|
||||
* @throws IllegalAccessException If the desired constructor cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the constructor (this should not occur since it searches for a constructor with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired constructor cannot be invoked
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
|
||||
*/
|
||||
public static Object instantiateObject(Class<?> clazz, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
|
||||
return getConstructor(clazz, DataType.getPrimitive(arguments)).newInstance(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of a desired class with the given arguments
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param arguments Arguments which are used to construct an object of the desired target class
|
||||
* @return The instance of the desired target class with the specified arguments
|
||||
* @throws InstantiationException If you cannot create an instance of the desired target class due to certain circumstances
|
||||
* @throws IllegalAccessException If the desired constructor cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the constructor (this should not occur since it searches for a constructor with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired constructor cannot be invoked
|
||||
* @throws NoSuchMethodException If the desired constructor with the specified arguments cannot be found
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #instantiateObject(Class, Object...)
|
||||
*/
|
||||
public static Object instantiateObject(String className, PackageType packageType, Object... arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||
return instantiateObject(packageType.getClass(className), arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a method of a class with the given parameter types
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param methodName Name of the desired method
|
||||
* @param parameterTypes Parameter types of the desired method
|
||||
* @return The method of the target class with the specified name and parameter types
|
||||
* @throws NoSuchMethodException If the desired method of the target class with the specified name and parameter types cannot be found
|
||||
* @see DataType#getPrimitive(Class[])
|
||||
* @see DataType#compare(Class[], Class[])
|
||||
*/
|
||||
public static Method getMethod(Class<?> clazz, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
Class<?>[] primitiveTypes = DataType.getPrimitive(parameterTypes);
|
||||
for (Method method : clazz.getMethods()) {
|
||||
if (!method.getName().equals(methodName) || !DataType.compare(DataType.getPrimitive(method.getParameterTypes()), primitiveTypes)) {
|
||||
continue;
|
||||
}
|
||||
return method;
|
||||
}
|
||||
throw new NoSuchMethodException("There is no such method in this class with the specified name and parameter types");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a method of a desired class with the given parameter types
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param methodName Name of the desired method
|
||||
* @param parameterTypes Parameter types of the desired method
|
||||
* @return The method of the desired target class with the specified name and parameter types
|
||||
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and parameter types cannot be found
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getMethod(Class, String, Class...)
|
||||
*/
|
||||
public static Method getMethod(String className, PackageType packageType, String methodName, Class<?>... parameterTypes) throws NoSuchMethodException, ClassNotFoundException {
|
||||
return getMethod(packageType.getClass(className), methodName, parameterTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method on an object with the given arguments
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param methodName Name of the desired method
|
||||
* @param arguments Arguments which are used to invoke the desired method
|
||||
* @return The result of invoking the desired method on the target object
|
||||
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
|
||||
* @throws NoSuchMethodException If the desired method of the class of the target object with the specified name and arguments cannot be found
|
||||
* @see #getMethod(Class, String, Class...)
|
||||
* @see DataType#getPrimitive(Object[])
|
||||
*/
|
||||
public static Object invokeMethod(Object instance, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
|
||||
return getMethod(instance.getClass(), methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method of the target class on an object with the given arguments
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param clazz Target class
|
||||
* @param methodName Name of the desired method
|
||||
* @param arguments Arguments which are used to invoke the desired method
|
||||
* @return The result of invoking the desired method on the target object
|
||||
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
|
||||
* @throws NoSuchMethodException If the desired method of the target class with the specified name and arguments cannot be found
|
||||
* @see #getMethod(Class, String, Class...)
|
||||
* @see DataType#getPrimitive(Object[])
|
||||
*/
|
||||
public static Object invokeMethod(Object instance, Class<?> clazz, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
|
||||
return getMethod(clazz, methodName, DataType.getPrimitive(arguments)).invoke(instance, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a method of a desired class on an object with the given arguments
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param methodName Name of the desired method
|
||||
* @param arguments Arguments which are used to invoke the desired method
|
||||
* @return The result of invoking the desired method on the target object
|
||||
* @throws IllegalAccessException If the desired method cannot be accessed due to certain circumstances
|
||||
* @throws IllegalArgumentException If the types of the arguments do not match the parameter types of the method (this should not occur since it searches for a method with the types of the arguments)
|
||||
* @throws InvocationTargetException If the desired method cannot be invoked on the target object
|
||||
* @throws NoSuchMethodException If the desired method of the desired target class with the specified name and arguments cannot be found
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #invokeMethod(Object, Class, String, Object...)
|
||||
*/
|
||||
public static Object invokeMethod(Object instance, String className, PackageType packageType, String methodName, Object... arguments) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException {
|
||||
return invokeMethod(instance, packageType.getClass(className), methodName, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a field of the target class with the given name
|
||||
*
|
||||
* @param clazz Target class
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The field of the target class with the specified name
|
||||
* @throws NoSuchFieldException If the desired field of the given class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
*/
|
||||
public static Field getField(Class<?> clazz, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException {
|
||||
Field field = declared ? clazz.getDeclaredField(fieldName) : clazz.getField(fieldName);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a field of a desired class with the given name
|
||||
*
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The field of the desired target class with the specified name
|
||||
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getField(Class, boolean, String)
|
||||
*/
|
||||
public static Field getField(String className, PackageType packageType, boolean declared, String fieldName) throws NoSuchFieldException, SecurityException, ClassNotFoundException {
|
||||
return getField(packageType.getClass(className), declared, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a field of the given class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param clazz Target class
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The value of field of the target object
|
||||
* @throws IllegalArgumentException If the target object does not feature the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #getField(Class, boolean, String)
|
||||
*/
|
||||
public static Object getValue(Object instance, Class<?> clazz, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
return getField(clazz, declared, fieldName).get(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a field of a desired class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The value of field of the target object
|
||||
* @throws IllegalArgumentException If the target object does not feature the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #getValue(Object, Class, boolean, String)
|
||||
*/
|
||||
public static Object getValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
|
||||
return getValue(instance, packageType.getClass(className), declared, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a field with the given name of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @return The value of field of the target object
|
||||
* @throws IllegalArgumentException If the target object does not feature the desired field (should not occur since it searches for a field with the given name in the class of the object)
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target object cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #getValue(Object, Class, boolean, String)
|
||||
*/
|
||||
public static Object getValue(Object instance, boolean declared, String fieldName) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
return getValue(instance, instance.getClass(), declared, fieldName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a field of the given class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param clazz Target class
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @param value New value
|
||||
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #getField(Class, boolean, String)
|
||||
*/
|
||||
public static void setValue(Object instance, Class<?> clazz, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
getField(clazz, declared, fieldName).set(instance, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a field of a desired class of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param className Name of the desired target class
|
||||
* @param packageType Package where the desired target class is located
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @param value New value
|
||||
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the desired class cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @throws ClassNotFoundException If the desired target class with the specified name and package cannot be found
|
||||
* @see #setValue(Object, Class, boolean, String, Object)
|
||||
*/
|
||||
public static void setValue(Object instance, String className, PackageType packageType, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException, ClassNotFoundException {
|
||||
setValue(instance, packageType.getClass(className), declared, fieldName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a field with the given name of an object
|
||||
*
|
||||
* @param instance Target object
|
||||
* @param declared Whether the desired field is declared or not
|
||||
* @param fieldName Name of the desired field
|
||||
* @param value New value
|
||||
* @throws IllegalArgumentException If the type of the value does not match the type of the desired field
|
||||
* @throws IllegalAccessException If the desired field cannot be accessed
|
||||
* @throws NoSuchFieldException If the desired field of the target object cannot be found
|
||||
* @throws SecurityException If the desired field cannot be made accessible
|
||||
* @see #setValue(Object, Class, boolean, String, Object)
|
||||
*/
|
||||
public static void setValue(Object instance, boolean declared, String fieldName, Object value) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
setValue(instance, instance.getClass(), declared, fieldName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an enumeration of dynamic packages of NMS and CraftBukkit
|
||||
* <p>
|
||||
* This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
|
||||
*
|
||||
* @author DarkBlade12
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum PackageType {
|
||||
MINECRAFT_SERVER("net.minecraft.server." + getServerVersion()),
|
||||
CRAFTBUKKIT("org.bukkit.craftbukkit." + getServerVersion()),
|
||||
CRAFTBUKKIT_BLOCK(CRAFTBUKKIT, "block"),
|
||||
CRAFTBUKKIT_CHUNKIO(CRAFTBUKKIT, "chunkio"),
|
||||
CRAFTBUKKIT_COMMAND(CRAFTBUKKIT, "command"),
|
||||
CRAFTBUKKIT_CONVERSATIONS(CRAFTBUKKIT, "conversations"),
|
||||
CRAFTBUKKIT_ENCHANTMENS(CRAFTBUKKIT, "enchantments"),
|
||||
CRAFTBUKKIT_ENTITY(CRAFTBUKKIT, "entity"),
|
||||
CRAFTBUKKIT_EVENT(CRAFTBUKKIT, "event"),
|
||||
CRAFTBUKKIT_GENERATOR(CRAFTBUKKIT, "generator"),
|
||||
CRAFTBUKKIT_HELP(CRAFTBUKKIT, "help"),
|
||||
CRAFTBUKKIT_INVENTORY(CRAFTBUKKIT, "inventory"),
|
||||
CRAFTBUKKIT_MAP(CRAFTBUKKIT, "map"),
|
||||
CRAFTBUKKIT_METADATA(CRAFTBUKKIT, "metadata"),
|
||||
CRAFTBUKKIT_POTION(CRAFTBUKKIT, "potion"),
|
||||
CRAFTBUKKIT_PROJECTILES(CRAFTBUKKIT, "projectiles"),
|
||||
CRAFTBUKKIT_SCHEDULER(CRAFTBUKKIT, "scheduler"),
|
||||
CRAFTBUKKIT_SCOREBOARD(CRAFTBUKKIT, "scoreboard"),
|
||||
CRAFTBUKKIT_UPDATER(CRAFTBUKKIT, "updater"),
|
||||
CRAFTBUKKIT_UTIL(CRAFTBUKKIT, "util");
|
||||
|
||||
private final String path;
|
||||
|
||||
/**
|
||||
* Construct a new package type
|
||||
*
|
||||
* @param path Path of the package
|
||||
*/
|
||||
private PackageType(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new package type
|
||||
*
|
||||
* @param parent Parent package of the package
|
||||
* @param path Path of the package
|
||||
*/
|
||||
private PackageType(PackageType parent, String path) {
|
||||
this(parent + "." + path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of this package type
|
||||
*
|
||||
* @return The path
|
||||
*/
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class with the given name
|
||||
*
|
||||
* @param className Name of the desired class
|
||||
* @return The class with the specified name
|
||||
* @throws ClassNotFoundException If the desired class with the specified name and package cannot be found
|
||||
*/
|
||||
public Class<?> getClass(String className) throws ClassNotFoundException {
|
||||
return Class.forName(this + "." + className);
|
||||
}
|
||||
|
||||
// Override for convenience
|
||||
@Override
|
||||
public String toString() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of your server
|
||||
*
|
||||
* @return The server version
|
||||
*/
|
||||
public static String getServerVersion() {
|
||||
return Bukkit.getServer().getClass().getPackage().getName().substring(23);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an enumeration of Java data types with corresponding classes
|
||||
* <p>
|
||||
* This class is part of the <b>ReflectionUtils</b> and follows the same usage conditions
|
||||
*
|
||||
* @author DarkBlade12
|
||||
* @since 1.0
|
||||
*/
|
||||
public enum DataType {
|
||||
BYTE(byte.class, Byte.class),
|
||||
SHORT(short.class, Short.class),
|
||||
INTEGER(int.class, Integer.class),
|
||||
LONG(long.class, Long.class),
|
||||
CHARACTER(char.class, Character.class),
|
||||
FLOAT(float.class, Float.class),
|
||||
DOUBLE(double.class, Double.class),
|
||||
BOOLEAN(boolean.class, Boolean.class);
|
||||
|
||||
private static final Map<Class<?>, DataType> CLASS_MAP = new HashMap<Class<?>, DataType>();
|
||||
private final Class<?> primitive;
|
||||
private final Class<?> reference;
|
||||
|
||||
// Initialize map for quick class lookup
|
||||
static {
|
||||
for (DataType type : values()) {
|
||||
CLASS_MAP.put(type.primitive, type);
|
||||
CLASS_MAP.put(type.reference, type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new data type
|
||||
*
|
||||
* @param primitive Primitive class of this data type
|
||||
* @param reference Reference class of this data type
|
||||
*/
|
||||
private DataType(Class<?> primitive, Class<?> reference) {
|
||||
this.primitive = primitive;
|
||||
this.reference = reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class of this data type
|
||||
*
|
||||
* @return The primitive class
|
||||
*/
|
||||
public Class<?> getPrimitive() {
|
||||
return primitive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class of this data type
|
||||
*
|
||||
* @return The reference class
|
||||
*/
|
||||
public Class<?> getReference() {
|
||||
return reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data type with the given primitive/reference class
|
||||
*
|
||||
* @param clazz Primitive/Reference class of the data type
|
||||
* @return The data type
|
||||
*/
|
||||
public static DataType fromClass(Class<?> clazz) {
|
||||
return CLASS_MAP.get(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class of the data type with the given reference class
|
||||
*
|
||||
* @param clazz Reference class of the data type
|
||||
* @return The primitive class
|
||||
*/
|
||||
public static Class<?> getPrimitive(Class<?> clazz) {
|
||||
DataType type = fromClass(clazz);
|
||||
return type == null ? clazz : type.getPrimitive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class of the data type with the given primitive class
|
||||
*
|
||||
* @param clazz Primitive class of the data type
|
||||
* @return The reference class
|
||||
*/
|
||||
public static Class<?> getReference(Class<?> clazz) {
|
||||
DataType type = fromClass(clazz);
|
||||
return type == null ? clazz : type.getReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class array of the given class array
|
||||
*
|
||||
* @param classes Given class array
|
||||
* @return The primitive class array
|
||||
*/
|
||||
public static Class<?>[] getPrimitive(Class<?>[] classes) {
|
||||
int length = classes == null ? 0 : classes.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getPrimitive(classes[index]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class array of the given class array
|
||||
*
|
||||
* @param classes Given class array
|
||||
* @return The reference class array
|
||||
*/
|
||||
public static Class<?>[] getReference(Class<?>[] classes) {
|
||||
int length = classes == null ? 0 : classes.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getReference(classes[index]);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the primitive class array of the given object array
|
||||
*
|
||||
* @param objects Given object array
|
||||
* @return The primitive class array
|
||||
*/
|
||||
public static Class<?>[] getPrimitive(Object[] objects) {
|
||||
int length = objects == null ? 0 : objects.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getPrimitive(objects[index].getClass());
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reference class array of the given object array
|
||||
*
|
||||
* @param objects Given object array
|
||||
* @return The reference class array
|
||||
*/
|
||||
public static Class<?>[] getReference(Object[] objects) {
|
||||
int length = objects == null ? 0 : objects.length;
|
||||
Class<?>[] types = new Class<?>[length];
|
||||
for (int index = 0; index < length; index++) {
|
||||
types[index] = getReference(objects[index].getClass());
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two class arrays on equivalence
|
||||
*
|
||||
* @param primary Primary class array
|
||||
* @param secondary Class array which is compared to the primary array
|
||||
* @return Whether these arrays are equal or not
|
||||
*/
|
||||
public static boolean compare(Class<?>[] primary, Class<?>[] secondary) {
|
||||
if (primary == null || secondary == null || primary.length != secondary.length) {
|
||||
return false;
|
||||
}
|
||||
for (int index = 0; index < primary.length; index++) {
|
||||
Class<?> primaryClass = primary[index];
|
||||
Class<?> secondaryClass = secondary[index];
|
||||
if (primaryClass.equals(secondaryClass) || primaryClass.isAssignableFrom(secondaryClass)) {
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package de.princep.lobbysystem.particlesystem;
|
||||
|
||||
public final class WingPattern {
|
||||
private WingPattern() {}
|
||||
|
||||
public static final String[] NORMAL = new String[] {
|
||||
"----xxx---",
|
||||
"---xxxxx--",
|
||||
"--xxxxxxx-",
|
||||
"-xxxxxxxx-",
|
||||
"xxxxxxxxxx",
|
||||
"xxxxxxxxxx",
|
||||
"xxxxxxxxxx",
|
||||
"xxxxxxxxxx",
|
||||
"--xxxxxxxx",
|
||||
"---xxxxxxx",
|
||||
"---xxxxxxx",
|
||||
"----xxxxxx",
|
||||
"----xxxxxx",
|
||||
"-----xxxx-",
|
||||
"-----xxxx-",
|
||||
"------xxx-",
|
||||
"------xxx-",
|
||||
"-------xx-",
|
||||
"--------x-"
|
||||
};
|
||||
|
||||
public static final String[] ADVANCED = new String[] {
|
||||
"-------------------x+",
|
||||
"------------------x+-",
|
||||
"-----------------x+--",
|
||||
"---------------xxx---",
|
||||
"--------------xxx+---",
|
||||
"-------------xxx+----",
|
||||
"-----------xxxx+-----",
|
||||
"----------xxx+----x+-",
|
||||
"---------xxx+---xx+--",
|
||||
"-------xxx+----xx+---",
|
||||
"------xx+----xx+-----",
|
||||
"----xxx+---xxx+------",
|
||||
"---xx+---xxx+--------",
|
||||
"--xxx--xxx+-----x+---",
|
||||
"---xxxxx+----xxx+----",
|
||||
"----xxx+--xxxx+------",
|
||||
"----xxx--xxx+--------",
|
||||
"-----xxxxx+----x+----",
|
||||
"-----xxx+---xxx+-----",
|
||||
"----xxx+---xx+-------",
|
||||
"----xxx--xx+---------",
|
||||
"---xxxxxxx+----------",
|
||||
"xxxxxxxx-------------",
|
||||
"-xx---xx-------------",
|
||||
"--xx---xx------------",
|
||||
"---xx---xx-----------",
|
||||
"----xx---------------"
|
||||
};
|
||||
|
||||
public static final float NORMAL_DISTANCE = 0.1f;
|
||||
public static final float ADVANCED_DISTANCE = 0.125f;
|
||||
|
||||
public static final float NORMAL_OFFSET = 0.5f;
|
||||
public static final float ADVANCED_OFFSET = -1;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package de.princep.lobbysystem.utils;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
public Material material;
|
||||
public String name;
|
||||
public int amount = 1;
|
||||
public short damage = 0;
|
||||
public HashMap<Enchantment, Integer> enchantments = new HashMap<>();
|
||||
public ArrayList<String> lore = new ArrayList<>();
|
||||
public boolean showEnchantments = true;
|
||||
public boolean isSkull = false;
|
||||
public OfflinePlayer player;
|
||||
|
||||
public ItemBuilder(Material mat){
|
||||
material = mat;
|
||||
}
|
||||
|
||||
public ItemBuilder(Material mat, int amount){
|
||||
material = mat;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public ItemBuilder(Material mat, int amount, int damage){
|
||||
material = mat;
|
||||
this.amount = amount;
|
||||
this.damage = (short) damage;
|
||||
}
|
||||
|
||||
public ItemBuilder(OfflinePlayer player) {
|
||||
this.player = player;
|
||||
isSkull = true;
|
||||
}
|
||||
|
||||
public ItemBuilder(OfflinePlayer player, int amount) {
|
||||
this.player = player;
|
||||
this.amount = amount;
|
||||
isSkull = true;
|
||||
}
|
||||
|
||||
public ItemBuilder setName(String name){
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder addEnchantment(Enchantment e, int level){
|
||||
enchantments.put(e, level);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder showEnchantments(boolean value) {
|
||||
showEnchantments = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setLore(String... lore){
|
||||
this.lore.addAll(Arrays.asList(lore));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setGlowing(boolean value) {
|
||||
if (value) {
|
||||
enchantments.put(Enchantment.DURABILITY, 1);
|
||||
showEnchantments = false;
|
||||
}else {
|
||||
enchantments.clear();
|
||||
showEnchantments = true;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemBuilder setAmount(int amount) { this.amount = amount; return this; }
|
||||
|
||||
public ItemStack build(){
|
||||
ItemStack item;
|
||||
if (!isSkull) {
|
||||
item = new ItemStack(material, amount, damage);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
for (Enchantment e : enchantments.keySet()){
|
||||
meta.addEnchant(e, enchantments.get(e), true);
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(name);
|
||||
if (!showEnchantments) meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
item.setItemMeta(meta);
|
||||
}else {
|
||||
item = new ItemStack(Material.SKULL_ITEM, amount, (short) 3);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwner(player.getName());
|
||||
for (Enchantment e : enchantments.keySet()){
|
||||
meta.addEnchant(e, enchantments.get(e), true);
|
||||
}
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(name);
|
||||
if (!showEnchantments) meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package de.princep.lobbysystem.utils;
|
||||
|
||||
import de.princep.lobbysystem.LobbySystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class LocationManager {
|
||||
|
||||
public void save() {
|
||||
try {
|
||||
LobbySystem.cfg.save(LobbySystem.file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLocation(Location location) {
|
||||
LobbySystem.cfg.set("Location.Spawn.world", location.getWorld().getName());
|
||||
LobbySystem.cfg.set("Location.Spawn.x", location.getX());
|
||||
LobbySystem.cfg.set("Location.Spawn.y", location.getY());
|
||||
LobbySystem.cfg.set("Location.Spawn.z", location.getZ());
|
||||
LobbySystem.cfg.set("Location.Spawn.yaw", location.getYaw());
|
||||
LobbySystem.cfg.set("Location.Spawn.pitch", location.getPitch());
|
||||
save();
|
||||
}
|
||||
|
||||
public void setDeathBoarder(Player player) {
|
||||
LobbySystem.cfg.set("Location.Death.border", player.getLocation().getY());
|
||||
save();
|
||||
}
|
||||
|
||||
public Double getDeathBoarder() {
|
||||
return LobbySystem.cfg.getDouble("Location.Death.border");
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
Location location;
|
||||
World w = Bukkit.getWorld(LobbySystem.cfg.getString("Location.Spawn.world"));
|
||||
double x = LobbySystem.cfg.getDouble("Location.Spawn.x");
|
||||
double y = LobbySystem.cfg.getDouble("Location.Spawn.y");
|
||||
double z = LobbySystem.cfg.getDouble("Location.Spawn.z");
|
||||
location = new Location(w, x, y, z);
|
||||
location.setYaw(LobbySystem.cfg.getInt("Location.Spawn.yaw"));
|
||||
location.setPitch(LobbySystem.cfg.getInt("Location.Spawn.pitch"));
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setWarp(String name, Location location) {
|
||||
LobbySystem.cfg.set("Warp." + name + ".world", location.getWorld().getName());
|
||||
LobbySystem.cfg.set("Warp." + name + ".x", location.getX());
|
||||
LobbySystem.cfg.set("Warp." + name + ".y", location.getY());
|
||||
LobbySystem.cfg.set("Warp." + name + ".z", location.getZ());
|
||||
LobbySystem.cfg.set("Warp." + name + ".yaw", location.getYaw());
|
||||
LobbySystem.cfg.set("Warp." + name + ".pitch", location.getPitch());
|
||||
save();
|
||||
}
|
||||
|
||||
public void delWarp(String name) {
|
||||
LobbySystem.cfg.set("Warp." + name + ".world", null);
|
||||
LobbySystem.cfg.set("Warp." + name + ".x", null);
|
||||
LobbySystem.cfg.set("Warp." + name + ".y", null);
|
||||
LobbySystem.cfg.set("Warp." + name + ".z", null);
|
||||
LobbySystem.cfg.set("Warp." + name + ".yaw", null);
|
||||
LobbySystem.cfg.set("Warp." + name + ".pitch", null);
|
||||
save();
|
||||
}
|
||||
|
||||
public Location getWarp(String name) {
|
||||
Location location;
|
||||
World w = Bukkit.getWorld(LobbySystem.cfg.getString("Warp." + name + ".world"));
|
||||
double x = LobbySystem.cfg.getDouble("Warp." + name + ".x");
|
||||
double y = LobbySystem.cfg.getDouble("Warp." + name + ".y");
|
||||
double z = LobbySystem.cfg.getDouble("Warp." + name + ".z");
|
||||
location = new Location(w, x, y, z);
|
||||
location.setYaw(LobbySystem.cfg.getInt("Warp." + name + ".yaw"));
|
||||
location.setPitch(LobbySystem.cfg.getInt("Warp." + name + ".pitch"));
|
||||
return location;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.princep.lobbysystem.utils;
|
||||
|
||||
public final class Promissions {
|
||||
|
||||
public static final String VIP = "princep.vip";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package de.princep.lobbysystem.utils;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
|
||||
|
||||
public class Title {
|
||||
|
||||
public static String prefix = "§c§lPrincepDE §r§8» §r";
|
||||
|
||||
public static String noPerm = prefix + "§7Diesen Befehl gibt es nicht.";
|
||||
|
||||
|
||||
public static void sendActionBar(Player p, String msg) {
|
||||
IChatBaseComponent base = IChatBaseComponent.ChatSerializer.a("{\"text\": \"\"}").a(msg);
|
||||
PacketPlayOutChat chat = new PacketPlayOutChat(base, (byte) 2);
|
||||
|
||||
CraftPlayer cp = (CraftPlayer)p;
|
||||
cp.getHandle().playerConnection.sendPacket(chat);
|
||||
}
|
||||
|
||||
public static void locTP(Player player, Location location) {
|
||||
Location l = null;
|
||||
try {
|
||||
l = location;
|
||||
} catch (Exception ignored) { }
|
||||
if (!(l == null)) {
|
||||
player.teleport(location);
|
||||
} else {
|
||||
player.playSound(player.getLocation(), Sound.ANVIL_BREAK, 1, 1);
|
||||
player.sendMessage("§8»");
|
||||
player.sendMessage(Title.prefix + "§7Der Punkt wurde noch nicht gesetzt.");
|
||||
player.sendMessage(Title.prefix + "§7Bitte wende dich an einen Serveradministrator.");
|
||||
player.sendMessage("§8»");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
16
Plugins/PrincepDE/LobbySystem/src/main/resources/config.yml
Normal file
16
Plugins/PrincepDE/LobbySystem/src/main/resources/config.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
# ----------------------------------------------------------
|
||||
# Config.yml
|
||||
# ----------------------------------------------------------
|
||||
# made by marc
|
||||
#
|
||||
# warps: citybuild, freebuild
|
||||
|
||||
Location:
|
||||
Spawn:
|
||||
world:
|
||||
x:
|
||||
y:
|
||||
z:
|
||||
yaw:
|
||||
pitch:
|
||||
Deathborder:
|
||||
@@ -0,0 +1,4 @@
|
||||
name: LobbyPlugin
|
||||
author: PrincepDE
|
||||
version: 1.0
|
||||
main: de.princep.lobbysystem.LobbySystem
|
||||
BIN
Plugins/PrincepDE/LobbySystem/target/LobbySystem-1.0-shaded.jar
Normal file
BIN
Plugins/PrincepDE/LobbySystem/target/LobbySystem-1.0-shaded.jar
Normal file
Binary file not shown.
BIN
Plugins/PrincepDE/LobbySystem/target/LobbySystem-1.0.jar
Normal file
BIN
Plugins/PrincepDE/LobbySystem/target/LobbySystem-1.0.jar
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
Plugins/PrincepDE/LobbySystem/target/classes/plugin.yml
Normal file
4
Plugins/PrincepDE/LobbySystem/target/classes/plugin.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
name: LobbyPlugin
|
||||
author: PrincepDE
|
||||
version: 1.0
|
||||
main: de.princep.lobbysystem.LobbySystem
|
||||
@@ -0,0 +1,5 @@
|
||||
#Generated by Maven
|
||||
#Fri Nov 05 16:42:10 CET 2021
|
||||
version=1.0
|
||||
groupId=de.princep
|
||||
artifactId=LobbySystem
|
||||
@@ -0,0 +1,7 @@
|
||||
de\princep\lobbysystem\annotations\AnnotationManager.class
|
||||
de\princep\lobbysystem\annotations\GetAPI.class
|
||||
de\princep\lobbysystem\apis\MySQL.class
|
||||
de\princep\lobbysystem\LobbySystem.class
|
||||
de\princep\lobbysystem\join\JoinListener.class
|
||||
de\princep\lobbysystem\apis\CoinAPI.class
|
||||
de\princep\lobbysystem\annotations\AnnotationAPI.class
|
||||
@@ -0,0 +1,6 @@
|
||||
D:\Programmierstuff\Plugins\PrincepDE\LobbySystem\src\main\java\de\princep\lobbysystem\join\JoinListener.java
|
||||
D:\Programmierstuff\Plugins\PrincepDE\LobbySystem\src\main\java\de\princep\lobbysystem\coins\GetCoinAPI.java
|
||||
D:\Programmierstuff\Plugins\PrincepDE\LobbySystem\src\main\java\de\princep\lobbysystem\coins\ICoinAPI.java
|
||||
D:\Programmierstuff\Plugins\PrincepDE\LobbySystem\src\main\java\de\princep\lobbysystem\LobbySystem.java
|
||||
D:\Programmierstuff\Plugins\PrincepDE\LobbySystem\src\main\java\de\princep\lobbysystem\coins\logic\CoinAPI.java
|
||||
D:\Programmierstuff\Plugins\PrincepDE\LobbySystem\src\main\java\de\princep\lobbysystem\MySQL.java
|
||||
Binary file not shown.
Reference in New Issue
Block a user