Initial commit

This commit is contained in:
Laura
2026-01-18 15:06:50 +01:00
commit a88b64c678
35 changed files with 1649 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
+80
View File
@@ -0,0 +1,80 @@
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Maven.gitlab-ci.yml
# Build JAVA applications using Apache Maven (http://maven.apache.org)
# For docker image tags see https://hub.docker.com/_/maven/
#
# For general lifecycle information see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
# This template will build and test your projects
# * Caches downloaded dependencies and plugins between invocation.
# * Verify but don't deploy merge requests.
# * Deploy built artifacts from master branch only.
variables:
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: >-
-Dhttps.protocols=TLSv1.2
-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
-Dorg.slf4j.simpleLogger.showDateTime=true
-Djava.awt.headless=true
# As of Maven 3.3.0 instead of this you MAY define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# As of Maven 3.6.1, the use of `--no-tranfer-progress` (or `-ntp`) suppresses download and upload messages. The use
# of the `Slf4jMavenTransferListener` is no longer necessary.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
MAVEN_CLI_OPTS: >-
--batch-mode
--errors
--fail-at-end
--show-version
--no-transfer-progress
-DinstallAtEnd=true
-DdeployAtEnd=true
# This template uses the latest Maven 3 release, e.g., 3.8.6, and OpenJDK 8 (LTS)
# for verifying and deploying images
# Maven 3.8.x REQUIRES HTTPS repositories.
# See https://maven.apache.org/docs/3.8.1/release-notes.html#how-to-fix-when-i-get-a-http-repository-blocked for more.
image: maven:3-openjdk-20
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
# Be aware that `mvn deploy` will install the built jar into this repository. If you notice your cache size
# increasing, consider adding `-Dmaven.install.skip=true` to `MAVEN_OPTS` or in `.mvn/maven.config`
cache:
paths:
- .m2/repository
# For merge requests do not `deploy` but only run `verify`.
# See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
.verify:
stage: test
script:
- 'mvn $MAVEN_CLI_OPTS verify'
except:
variables:
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Verify merge requests using JDK8
verify:jdk20:
extends:
- .verify
# To deploy packages from CI, create a `ci_settings.xml` file
# For deploying packages to GitLab's Maven Repository: See https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#create-maven-packages-with-gitlab-cicd for more details.
# Please note: The GitLab Maven Repository is currently only available in GitLab Premium / Ultimate.
# For `master` or `main` branch run `mvn deploy` automatically.
deploy:jdk20:
stage: deploy
script:
- if [ ! -f ci_settings.xml ]; then
echo "CI settings missing\! If deploying to GitLab Maven Repository, please see https://docs.gitlab.com/ee/user/packages/maven_repository/index.html#create-maven-packages-with-gitlab-cicd for instructions.";
fi
- 'mvn $MAVEN_CLI_OPTS deploy --settings ci_settings.xml'
only:
variables:
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+3
View File
@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="ASK" />
<option name="description" value="" />
<option name="theme" value="material" />
<option name="button1Title" value="" />
<option name="button1Url" value="" />
<option name="button2Title" value="" />
<option name="button2Url" value="" />
</component>
</project>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
+20
View File
@@ -0,0 +1,20 @@
<?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>
<option name="workspaceImportForciblyTurnedOn" value="true" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="corretto-18" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+124
View 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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.svg" 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>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+30
View File
@@ -0,0 +1,30 @@
# GameAPI
## Description
open Source network development API for making minigames
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
just take a look at [Usage of the API](usage.md)
## Support
just text me on Discord: zLavra
## Contributing
comming in the Future
## Authors and acknowledgment
Laura/Softwarerat
## License
For open source projects, say how it is licensed.
## Project status
in Continous development
+15
View File
@@ -0,0 +1,15 @@
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
+56
View File
@@ -0,0 +1,56 @@
<?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>com.softwarerat</groupId>
<artifactId>GameAPI</artifactId>
<version>1.6.4-SNAPSHOT</version>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.softwarerat.com/api/v4/projects/16/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.softwarerat.com/api/v4/projects/16/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>papermc-repo</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
+15
View File
@@ -0,0 +1,15 @@
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
@@ -0,0 +1,50 @@
package com.softwarerat.API.builder;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
public class ItemBuilder {
// Basic ItemBuilder
private final ItemMeta itemMeta;
private final ItemStack itemStack;
public ItemBuilder(Material mat){
itemStack = new ItemStack(mat);
itemMeta = itemStack.getItemMeta();
}
public ItemBuilder setDisplayname(String s){
itemMeta.setDisplayName(s);
return this;
}
public ItemBuilder setLocalizedName(String s){
itemMeta.setLocalizedName(s);
return this;
}
public ItemBuilder setLore(String... s){
itemMeta.setLore(Arrays.asList(s));
return this;
}
public ItemBuilder setUnbreakable(boolean s){
itemMeta.setUnbreakable(s);
return this;
}
public ItemBuilder addItemFlags(ItemFlag... s){
itemMeta.addItemFlags(s);
return this;
}
@Override
public String toString() {
return "ItemBuilder{" +
"itemMeta=" + itemMeta +
", itemStack=" + itemStack +
'}';
}
public ItemStack build(){
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}
@@ -0,0 +1,267 @@
package com.softwarerat.API.builder;
import com.softwarerat.GameAPI;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nonnull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
// Inventory Builder
public final class SpigotInventory implements Listener{
private final PlayerInventory playerInventory;
private final Map<ItemStack, Consumer<PlayerInteractEvent>> clickActions;
private GameAPI gameAPI;
public SpigotInventory(Player player, JavaPlugin javaPlugin) {
this.clickActions = new HashMap<>();
this.playerInventory = player.getInventory();
Bukkit.getPluginManager().registerEvents(this,javaPlugin );
}
public SpigotInventory addItem(ItemStack... items) {
this.playerInventory.addItem(items);
return this;
}
public SpigotInventory setHelmet(ItemStack item) {
this.playerInventory.setHelmet(item);
return this;
}
public SpigotInventory setChestplate(ItemStack item) {
this.playerInventory.setChestplate(item);
return this;
}
public SpigotInventory setLeggings(ItemStack item) {
this.playerInventory.setLeggings(item);
return this;
}
public SpigotInventory setBoots(ItemStack item) {
this.playerInventory.setBoots(item);
return this;
}
@Deprecated public SpigotInventory setItemInHand(ItemStack item) {
this.playerInventory.setItemInHand(item);
return this;
}
public SpigotInventory setItemInHand(ItemStack item, Hand hand) {
hand.setItem(this.playerInventory, item);
return this;
}
public SpigotInventory setItemInMainHand(ItemStack item) {
this.playerInventory.setItemInMainHand(item);
return this;
}
public SpigotInventory setItemInOffHand(ItemStack item) {
this.playerInventory.setItemInOffHand(item);
return this;
}
public SpigotInventory setArmorContents(ItemStack[] item) {
this.playerInventory.setArmorContents(item);
return this;
}
public SpigotInventory setSlot(@Nonnull ItemStack item, int slot, @Nonnull Consumer<PlayerInteractEvent> clickAction) {
this.setSlot(item, slot);
this.clickActions.put(item, clickAction);
return this;
}
public SpigotInventory setSlot(ItemStack item, int slot) {
this.playerInventory.setItem(slot, item);
return this;
}
public SpigotInventory setSlot(ItemStack item, int... slots) {
for (byte b = 0; b <= (byte) slots.length; b++) { this.playerInventory.setItem(slots[b], item); }
return this;
}
public SpigotInventory setSlot(ItemStack item, List<Integer> slots) {
slots.forEach(slot -> this.playerInventory.setItem(slot, item));
return this;
}
public SpigotInventory forEach(Consumer<? super ItemStack> action) {
this.playerInventory.forEach(action);
return this;
}
public SpigotInventory clear() {
this.playerInventory.clear();
return this;
}
public SpigotInventory clear(int slot) {
this.playerInventory.clear(slot);
return this;
}
public SpigotInventory clear(int... slots) {
for (int slot : slots) { this.playerInventory.clear(slot); }
return this;
}
public SpigotInventory clear(@Nonnull List<Integer> slots) {
slots.stream().forEach(slot -> this.playerInventory.clear(slot));
return this;
}
public int getSlot(@Nonnull Material material) {
for (int slot = 0; slot < this.playerInventory.getSize(); slot++) {
if(this.getItem(slot) == null) continue;
if (this.getItem(slot).getType() != material) continue;
return slot;
}
return -1;
}
public ItemStack getItem(@Nonnull Material material) {
for (ItemStack itemStack : this.playerInventory.getContents()) {
if(itemStack == null) continue;
if(itemStack.getType() != material) continue;
return itemStack;
}
return null;
}
public ItemStack getItem(@Nonnull ItemStack item) {
for (ItemStack itemStack : this.playerInventory.getContents()) {
if(itemStack == null) continue;
if(itemStack.getType() != item.getType()) continue;
return itemStack;
}
return null;
}
public ItemStack getItem(@Nonnull Material material, int amaunt) {
for (ItemStack itemStack : this.playerInventory.getContents()) {
if(itemStack == null) continue;
if(itemStack.getType() != material) continue;
if(itemStack.getAmount() < amaunt) continue;
return itemStack;
}
return null;
}
public ItemStack getItem(@Nonnull ItemStack item, int amaunt) {
for (ItemStack itemStack : this.playerInventory.getContents()) {
if(itemStack == null) continue;
if(itemStack.getType() != item.getType()) continue;
if(itemStack.getAmount() < amaunt) continue;
return itemStack;
}
return null;
}
public int getAmount(@Nonnull ItemStack item) {
var amount = 0;
for (ItemStack itemStack : this.playerInventory.getContents()) {
if(itemStack == null) continue;
if(itemStack.getType() != item.getType()) continue;
amount += itemStack.getAmount();
}
return amount;
}
public int getAmount(@Nonnull Material material) {
var amount = 0;
for (ItemStack itemStack : this.playerInventory.getContents()) {
if(itemStack == null) continue;
if(itemStack.getType() != material) continue;
amount += itemStack.getAmount();
}
return amount;
}
public SpigotInventory removeItems(ItemStack item, int amount) {
if (amount <= 0) return this;
int size = this.playerInventory.getSize();
for (int slot = 0; slot < size; slot++) {
ItemStack invItem = this.getItem(slot);
if (invItem == null) continue;
if (!invItem.isSimilar(item)) continue;
int newAmount = invItem.getAmount() - amount;
if (newAmount > 0) {
invItem.setAmount(newAmount);
break;
}
this.playerInventory.clear(slot);
amount = -newAmount;
if (amount == 0) break;
}
return this;
}
public ItemStack[] getArmorContents() { return this.playerInventory.getArmorContents(); }
public ItemStack getChestplate() { return this.playerInventory.getChestplate(); }
public ItemStack getLeggings() { return this.playerInventory.getLeggings(); }
public ItemStack getBoots() { return this.playerInventory.getBoots(); }
public ItemStack getHelmet() { return this.playerInventory.getHelmet(); }
public HumanEntity getHolder() { return this.playerInventory.getHolder(); }
public ItemStack[] getContents() { return this.playerInventory.getContents(); }
public int getHeldItemSlot() { return this.playerInventory.getHeldItemSlot(); }
public ItemStack getItem(int slot) { return this.playerInventory.getItem(slot); }
public ItemStack getItemInMainHand() { return this.playerInventory.getItemInMainHand(); }
public ItemStack getItemInOffHand() { return this.playerInventory.getItemInOffHand(); }
public int getMaxStackSize() { return this.playerInventory.getMaxStackSize(); }
public ItemStack[] getExtraContents() { return this.playerInventory.getExtraContents(); }
public int getSize() { return this.playerInventory.getSize(); }
public Location getLocation() { return this.playerInventory.getLocation(); }
public ItemStack[] getStorageContents() { return this.playerInventory.getStorageContents(); }
public InventoryType getType() { return this.playerInventory.getType(); }
public List<HumanEntity> getViewers() { return this.playerInventory.getViewers(); }
public boolean isEmpty() { return this.playerInventory.isEmpty(); }
public ItemStack getItem(EquipmentSlot slot) { return this.playerInventory.getItem(slot); }
@Deprecated public ItemStack getItemInHand() { return this.playerInventory.getItemInHand(); }
public ItemStack getItemInHand(Hand hand) { return hand.getItem(this.playerInventory); }
public enum Hand {
MAIN {
@Override public ItemStack getItem(PlayerInventory inventory) { return inventory.getItemInMainHand(); }
@Override public void setItem(PlayerInventory inventory, ItemStack item) { inventory.setItemInMainHand(item); }
},
OFF {
@Override public ItemStack getItem(PlayerInventory inventory) { return inventory.getItemInOffHand(); }
@Override public void setItem(PlayerInventory inventory, ItemStack item) { inventory.setItemInOffHand(item); }
};
public abstract ItemStack getItem(PlayerInventory inventory);
public abstract void setItem(PlayerInventory inventory, ItemStack item);
}
@EventHandler public void onInteract(PlayerInteractEvent interactEvent) {
var item = interactEvent.getItem();
if(item == null) return;
if(!this.clickActions.containsKey(item)) return;
this.clickActions.get(item).accept(interactEvent);
}
}
@@ -0,0 +1,227 @@
package com.softwarerat.API.builder;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkEffectMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.bukkit.inventory.meta.SkullMeta;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
// Another Item Builder
public class SpigotItem {
private ItemStack itemStack;
private String textures;
private String colorCode(@Nonnull String message) { return ChatColor.translateAlternateColorCodes('&', message); }
public SpigotItem(@Nonnull Material material, @Nonnull int amount) {
this.itemStack = new ItemStack(material, amount);
}
public SpigotItem(@Nonnull Material material) { this(material, 1); }
public SpigotItem(@Nonnull ItemStack itemStack) { this(itemStack.getType()); }
public SpigotItem setAmount(int amount) {
this.itemStack.setAmount(amount);
return this;
}
public SpigotItem setName(@Nonnull String name) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
itemMeta.setDisplayName(colorCode(name));
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem setLore(@Nonnull String lore) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
itemMeta.setLore(Arrays.asList(colorCode(lore)));
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem setLore(@Nonnull String... lores) {
List<String> colored = new ArrayList<>();
ItemMeta itemMeta = this.itemStack.getItemMeta();
for (String lore : lores) { colored.add(this.colorCode(lore)); }
itemMeta.setLore(colored);
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem setLore(@Nonnull List<String> lore) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
List<String> colored = lore.stream().filter(Objects::nonNull).map(this::colorCode).collect(Collectors.toList());
itemMeta.setLore(colored);
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem removeLoreLine(@Nonnull String line) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
List<String> lore = new ArrayList<>(itemMeta.getLore());
if (!lore.contains(line)) return this;
lore.remove(colorCode(line));
itemMeta.setLore(lore);
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem removeLoreLine(int index) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
List<String> lore = new ArrayList<>(itemMeta.getLore());
if (index < 0 || index > lore.size()) return this;
lore.remove(index);
itemMeta.setLore(lore);
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem addLoreLine(@Nonnull String line) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
List<String> lore = new ArrayList<>();
if (itemMeta.hasLore()) lore = new ArrayList<>(itemMeta.getLore());
lore.add(colorCode(line));
itemMeta.setLore(lore);
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem addLoreLine(@Nonnull String line, int pos) {
ItemMeta itemMeta = this.itemStack.getItemMeta();
List<String> lore = new ArrayList<>(itemMeta.getLore());
lore.set(pos, colorCode(line));
itemMeta.setLore(lore);
this.itemStack.setItemMeta(itemMeta);
return this;
}
public SpigotItem addEnchant(@Nonnull Enchantment ench, int level) {
this.itemStack.addEnchantment(ench, level);
return this;
}
public SpigotItem addUnsafeEnchantment(@Nonnull Enchantment ench, int level) {
this.itemStack.addUnsafeEnchantment(ench, level);
return this;
}
public SpigotItem addEnchantments(@Nonnull Map<Enchantment, Integer> ench) {
this.itemStack.addEnchantments(ench);
return this;
}
public SpigotItem removeEnchant(@Nonnull Enchantment ench) {
this.itemStack.removeEnchantment(ench);
return this;
}
@Deprecated
public SpigotItem setOwner(@Nonnull String owner) {
if (Material.LEGACY_SKULL_ITEM.equals(this.itemStack.getType())) {
if (this.itemStack.getDurability() != 3) this.itemStack.setDurability((short)3);
SkullMeta skullMeta = (SkullMeta) this.itemStack.getItemMeta();
skullMeta.setOwner(owner);
this.itemStack.setItemMeta(skullMeta);
}
return this;
}
@Deprecated
public SpigotItem setColor(@Nonnull DyeColor color) {
this.itemStack.setDurability(color.getDyeData());
return this;
}
public SpigotItem setFireworkColor(@Nonnull Color... color) {
if (this.itemStack.getType() == Material.FIREWORK_STAR) {
FireworkEffectMeta meta = (FireworkEffectMeta) this.itemStack.getItemMeta();
meta.setEffect(FireworkEffect.builder().withColor(color).build());
this.itemStack.setItemMeta(meta);
}
return this;
}
public SpigotItem setItemFlag(@Nonnull ItemFlag... flags) {
ItemMeta meta = this.itemStack.getItemMeta();
meta.addItemFlags(flags);
this.itemStack.setItemMeta(meta);
return this;
}
public SpigotItem setAllItemFlag() {
ItemMeta meta = this.itemStack.getItemMeta();
meta.addItemFlags(ItemFlag.values());
this.itemStack.setItemMeta(meta);
return this;
}
public SpigotItem setUnbreakable(boolean unbreakable) {
this.itemStack.getItemMeta().setUnbreakable(unbreakable);
return this;
}
public SpigotItem setGlowing() {
this.itemStack.addUnsafeEnchantment(Enchantment.LUCK, 1);
ItemMeta meta = this.itemStack.getItemMeta();
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
this.itemStack.setItemMeta(meta);
return this;
}
public SpigotItem unGlowing() {
this.itemStack.removeEnchantment(Enchantment.LUCK);
return this;
}
public SpigotItem setArmorColor(@Nonnull Color color) {
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) this.itemStack.getItemMeta();
leatherArmorMeta.setColor(color);
this.itemStack.setItemMeta(leatherArmorMeta);
return this;
}
public SpigotItem setMeta(@Nonnull ItemMeta meta) {
this.itemStack.setItemMeta(meta);
return this;
}
public List<String> getLore() { return this.itemStack.getItemMeta().getLore(); }
public Set<ItemFlag> getItemFlags() { return this.itemStack.getItemMeta().getItemFlags(); }
public String getName() { return this.itemStack.getItemMeta().getDisplayName(); }
public boolean hasItemFlag(@Nonnull ItemFlag flag) { return this.itemStack.getItemMeta().hasItemFlag(flag); }
public boolean hasDisplay() { return this.itemStack.getItemMeta().hasDisplayName(); }
public boolean hasLore() { return this.itemStack.getItemMeta().hasLore(); }
public boolean isUnbreakable() { return this.itemStack.getItemMeta().isUnbreakable(); }
// public boolean isSimilar() { return this.itemStack.isSimilar(this.itemStack); }
public boolean isSimilar(@Nonnull ItemStack item) { return this.itemStack.isSimilar(item); }
@Deprecated public short getDurability() { return this.itemStack.getDurability(); }
public int getStackSize() { return this.itemStack.getMaxStackSize(); }
public int getAmount() { return this.itemStack.getAmount(); }
public String getTextures() { return this.textures; }
public Map<Enchantment, Integer> getEnchants() { return this.itemStack.getEnchantments(); }
public boolean hasEnchant(@Nonnull Enchantment ench) { return this.itemStack.getItemMeta().hasEnchant(ench); }
public boolean hasEnchants() { return this.itemStack.getItemMeta().hasEnchants(); }
public int getEnchantmentLevel(@Nonnull Enchantment ench) { return this.itemStack.getEnchantmentLevel(ench); }
public ItemMeta getMeta() { return this.itemStack.getItemMeta(); }
public Material getType() { return this.itemStack.getType(); }
public ItemStack build() { return this.itemStack; }
}
@@ -0,0 +1,255 @@
package com.softwarerat.API.builder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import com.softwarerat.GameAPI;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
// UI Builder
public final class SpigotUI implements Listener {
private static Map<Player, Boolean> openList = new HashMap<>();
private final Inventory inventory;
private final Map<Integer, Consumer<InventoryClickEvent>> clickActions;
private Runnable callback;
private final List<Integer> freeSlots;
private Player player;
private int rows;
private String title;
public SpigotUI(InventoryHolder holder, int rows, JavaPlugin javaPlugin) {
if (rows >= 7) rows = 6;
this.inventory = Bukkit.createInventory(holder, rows * 9);
this.rows = rows;
if (holder != null) this.player = (Player)holder;
this.freeSlots = new ArrayList<>();
this.clickActions = new HashMap<>();
openList.put(player, false);
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
}
public SpigotUI(InventoryHolder holder, @Nonnull InventoryType type,JavaPlugin javaPlugin) {
this.inventory = Bukkit.createInventory(holder, type);
this.rows = -1;
if (holder != null) this.player = (Player)holder;
if (type == InventoryType.CHEST) this.rows = 3;
this.freeSlots = new ArrayList<>();
this.clickActions = new HashMap<>();
openList.put(player, false);
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
}
public SpigotUI(InventoryHolder holder, int rows, @Nonnull String title,JavaPlugin javaPlugin) {
if (rows >= 7) rows = 6;
this.inventory = Bukkit.createInventory(holder, rows * 9, title);
this.title = title;
this.rows = rows;
if (holder != null) this.player = (Player)holder;
this.freeSlots = new ArrayList<>();
this.clickActions = new HashMap<>();
openList.put(player, false);
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
}
public SpigotUI(InventoryHolder holder, @Nonnull InventoryType type, @Nonnull String title,JavaPlugin javaPlugin) {
this.inventory = Bukkit.createInventory(holder, type, title);
this.rows = -1;
if (holder != null) this.player = (Player)holder;
if (type == InventoryType.CHEST) this.rows = 3;
this.freeSlots = new ArrayList<>();
this.clickActions = new HashMap<>();
openList.put(player, false);
Bukkit.getPluginManager().registerEvents(this, javaPlugin);
}
public SpigotUI setFreeClickedSlots(int... slots) {
for (int slot = 0; slot < slots.length; slot++) { this.freeSlots.add(slot); }
return this;
}
public SpigotUI setSlot(@Nonnull ItemStack item, int slot) {
this.inventory.setItem(slot, item);
return this;
}
public SpigotUI setSlot(@Nonnull ItemStack item, int row, int slot) {
this.inventory.setItem(getSlots(row).get(slot), item);
return this;
}
public SpigotUI setSlot(@Nonnull ItemStack item, int slot, @Nonnull Consumer<InventoryClickEvent> clickAction) {
this.inventory.setItem(slot, item);
this.clickActions.put(slot, clickAction);
return this;
}
public SpigotUI setSlot(@Nonnull ItemStack item, int row, int slot, @Nonnull Consumer<InventoryClickEvent> clickAction) {
int slots = getSlots(row).get(slot);
this.inventory.setItem(slots, item);
this.clickActions.put(slots, clickAction);
return this;
}
public SpigotUI setSlot(@Nonnull ItemStack item, int... slots) {
for (int slot = 0; slot < slots.length; slot++) { this.inventory.setItem(slot, item); }
return this;
}
public SpigotUI all(@Nonnull ItemStack item) {
this.inventory.all(item);
return this;
}
public SpigotUI all(@Nonnull Material material) {
this.inventory.all(material);
return this;
}
public SpigotUI addItem(@Nonnull ItemStack... items) {
this.inventory.addItem(items);
return this;
}
public SpigotUI clear() {
this.inventory.clear();
return this;
}
public SpigotUI clear(int slot) {
this.inventory.clear(slot);
return this;
}
public SpigotUI clear(int... slots) {
for (int slot : slots) { this.inventory.clear(slot); }
return this;
}
public SpigotUI clear(@Nonnull List<Integer> slots) {
slots.stream().forEach(slot -> this.inventory.clear(slot));
return this;
}
public SpigotUI placeHolder(@Nonnull ItemStack item, boolean replaceItem) {
for (int i = 0; i < this.inventory.getSize(); i++) {
if (this.inventory.getItem(i) == null && !replaceItem) setSlot(item, i);
if (replaceItem) setSlot(item, i);
}
return this;
}
public void openInventory() {
this.player.openInventory(this.inventory);
openList.put(player, true);
}
public void updateInventory() {
this.player.updateInventory();
}
public void closeInventory() {
openList.put(player, false);
this.player.closeInventory();
}
public void openInventory(@Nonnull Player player) {
player.openInventory(this.inventory);
openList.put(player, true);
}
public void updateInventory(@Nonnull Player player) { player.updateInventory(); }
public void closeInventory(@Nonnull Player player) {
player.closeInventory();
openList.put(player, false);
}
public boolean containsAsFor(@Nonnull ItemStack item) {
for (int slot = 0; slot < this.inventory.getSize(); slot++) { if (this.inventory.getItem(slot) == item) return true; }
return false;
}
public int getSlot(@Nonnull ItemStack item) {
for (int slot = 0; slot < this.inventory.getSize(); slot++) { if (this.inventory.getItem(slot) == item) return slot; }
return -1;
}
public List<Integer> getSlots(int row) {
if (row > getRows()) row = getRows();
List<Integer> slots = new ArrayList<>();
for (int slot = 9 * (row - 1); slot < row * 9; slot++) slots.add(slot);
return slots;
}
public SpigotUI setRunOnClose(Runnable callback) {
this.callback = callback;
return this;
}
public boolean contains(@Nonnull ItemStack item, int slot) { return this.inventory.contains(item, slot); }
public boolean contains(@Nonnull ItemStack item) { return this.inventory.contains(item); }
public boolean contains(@Nonnull Material material, int slot) { return this.inventory.contains(material, slot); }
public boolean contains(@Nonnull Material material) { return this.inventory.contains(material); }
public boolean containsAtLeast(@Nonnull ItemStack item, int slot) { return this.inventory.containsAtLeast(item, slot); }
public ItemStack getItem(int slot) { return this.inventory.getItem(slot); }
public int getSize() { return this.inventory.getSize(); }
public int getSlot() { return this.inventory.getSize() - 1; }
public int getRows() { return this.rows; }
public InventoryType getType() { return this.inventory.getType(); }
public InventoryHolder getHolder() { return this.inventory.getHolder(); }
public ItemStack[] getContents() { return this.inventory.getContents(); }
public int getMaxStackSize() { return this.inventory.getMaxStackSize(); }
public List<HumanEntity> getViewers() { return this.inventory.getViewers(); }
public ItemStack[] getStorageContents() { return this.inventory.getStorageContents(); }
public int firstEmpty() { return this.inventory.firstEmpty(); }
public boolean isOpen() { return openList.get(this.player) != null && openList.get(this.player); }
public boolean isOpen(@Nonnull Player player) { return openList.get(player) != null && openList.get(player); }
@EventHandler
public void openInventory(InventoryOpenEvent openEvent) {
Inventory openInventory = openEvent.getInventory();
if (Boolean.TRUE.equals(openList.get(openEvent.getPlayer()))) return;
if (openInventory.getType() != InventoryType.CHEST) return;
if (!openInventory.getType().equals(this.inventory.getType())) return;
openList.put(player, true);
}
@EventHandler
public void closeInventory(InventoryCloseEvent closeEvent) {
Inventory closeInventory = closeEvent.getInventory();
if (Boolean.FALSE.equals(openList.get(closeEvent.getPlayer()))) return;
if (closeInventory.getType() != InventoryType.CHEST) return;
if (!closeInventory.getType().equals(this.inventory.getType())) return;
openList.put(player, false);
if (this.callback != null) this.callback.run();
}
@EventHandler
public void executeActions(InventoryClickEvent clickEvent) {
Inventory clickedInventory = clickEvent.getClickedInventory();
if (clickedInventory == null) return;
if (clickedInventory.getType() != InventoryType.CHEST) return;
if (Boolean.FALSE.equals(openList.get(clickEvent.getWhoClicked()))) return;
if (!clickedInventory.getType().equals(this.inventory.getType())) return;
if (clickedInventory.getHolder() != this.player) return;
if (!clickEvent.getView().getTitle().equals(this.title)) return;
if (!this.freeSlots.contains(clickEvent.getSlot())) clickEvent.setCancelled(true);
if (this.clickActions.containsKey(clickEvent.getSlot())) this.clickActions.get(clickEvent.getSlot()).accept(clickEvent);
}
}
@@ -0,0 +1,60 @@
package com.softwarerat.API.commands;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.softwarerat.API.builder.SpigotInventory;
import com.softwarerat.API.builder.SpigotItem;
import com.softwarerat.API.builder.SpigotUI;
import com.softwarerat.GameAPI;
import lombok.AllArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
//Default Navigator
public class Navigator implements CommandExecutor {
JavaPlugin javaPlugin;
public Navigator(JavaPlugin javaPlugin) {
this.javaPlugin = javaPlugin;
}
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
Player player = Bukkit.getPlayer(commandSender.getName());
SpigotInventory playerInventory = new SpigotInventory(player,javaPlugin);
playerInventory.setSlot(new SpigotItem(Material.COMPASS).setName("Navigator").build(), 4, (click) -> openServerCreatorMenu(click.getPlayer()));
player.sendMessage("give ITem");
return false;
}
public void sendPlayer(Player player){
if (player.hasPermission("group.Content")) {
// player.sendMessage("hasperm");
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF("build-1");
player.sendPluginMessage(javaPlugin, "BungeeCord", out.toByteArray());
// player.sendMessage("sucess");
}
}
public void openServerCreatorMenu(Player player) {
int rows = 6;
SpigotUI gui = new SpigotUI(player, rows, "Server Auswählen",javaPlugin);
gui.openInventory(player);
gui.setSlot(new SpigotItem( Material.GRASS_BLOCK).setName("Bauserver").build(),10, (click) -> sendPlayer(player));
// gui.setRunOnClose(() -> {});
}
}
@@ -0,0 +1,50 @@
package com.softwarerat.API.data;
import com.softwarerat.API.gameState.GameState;
import com.softwarerat.API.gameType.GameType;
import com.softwarerat.API.location.PlayerSpawnLocation;
import com.softwarerat.GameAPI;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.List;
// Server related Data
// made possible with Lombok
@Getter
@Setter
public class GameData {
List<PlayerSpawnLocation> spawnLocations;
PlayerSpawnLocation defaultSpawnLocation;
GameAPI gameapi;
GameState currentGameState;
Location mapLocation;
String primaryKit;
String secondaryKit;
String helper;
GameType gameType;
List<Player> alivePlayers;
List<Player> spectators;
Scoreboard scoreboard;
public GameData(GameAPI gameapi) {
this.gameapi = gameapi;
}
public String getGameHost(JavaPlugin javaPlugin){
String sn = javaPlugin.getName();
int indexOfUnderscore = sn.indexOf("_");
int indexOfHyphen = sn.indexOf("-");
if (indexOfUnderscore != -1 && indexOfHyphen != -1) {
return sn.substring(indexOfUnderscore + 1, indexOfHyphen);
}else return "zLavra";
}
public void setPrimaryKit(String kitData){
primaryKit = kitData;
}
}
@@ -0,0 +1,7 @@
package com.softwarerat.API.gameState;
public enum GameState {
GAME_STATE_LOBBY,
GAME_STATE_INGAME;
}
@@ -0,0 +1,8 @@
package com.softwarerat.API.gameState;
public interface IGameState {
public void Start();
public void Stop();
}
@@ -0,0 +1,7 @@
package com.softwarerat.API.gameType;
public enum GameType {
GAME_TYPE_MINIGAME,
GAME_TYPE_ONE_VERSUS_ONE,
GAME_TYPE_TYPELESS;
}
@@ -0,0 +1,21 @@
package com.softwarerat.API.listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
// Listener for checking if a Player is Building / Breaking any Blocks
public class BuildBreakListener implements Listener {
@EventHandler
public void onEvent(BlockBreakEvent event) {
event.setCancelled(true);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
event.setCancelled(true);
}
}
@@ -0,0 +1,7 @@
package com.softwarerat.API.listener;
// Chat Listener
public class ChatListener {
}
@@ -0,0 +1,6 @@
package com.softwarerat.API.listener;
// Join Listener
public class JoinListener {
}
@@ -0,0 +1,15 @@
package com.softwarerat.API.listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
// Inventory Click listener for Lobbies
public class LobbyInventoryClickListener implements Listener {
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
event.setCancelled(true);
}
}
@@ -0,0 +1,54 @@
package com.softwarerat.API.listener;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.softwarerat.API.builder.SpigotInventory;
import com.softwarerat.API.builder.SpigotItem;
import com.softwarerat.API.builder.SpigotUI;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.ChatColor;
// Lobby join magic including the navigator
public class LobbyJoinListener implements Listener{
JavaPlugin javaPlugin;
public LobbyJoinListener(JavaPlugin javaPlugin) {
this.javaPlugin = javaPlugin;
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
event.getPlayer().getInventory().clear();
SpigotInventory playerInventory = new SpigotInventory(player,javaPlugin);
playerInventory.setSlot(new SpigotItem(Material.COMPASS).setName(ChatColor.BLUE.toString() + ChatColor.BOLD +"Navigator "+ ChatColor.RESET + ChatColor.GRAY+"(Click)" ).build(), 4, (click) -> openServerCreatorMenu(event.getPlayer()));
player.sendMessage("give ITem");
}
public void sendPlayer(Player player){
if (player.hasPermission("group.Content")) {
// player.sendMessage("hasperm");
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF("build-1");
player.sendPluginMessage(javaPlugin, "BungeeCord", out.toByteArray());
// player.sendMessage("sucess");
}
}
public void openServerCreatorMenu(Player player) {
int rows = 6;
SpigotUI gui = new SpigotUI(player, rows, "Server Auswählen",javaPlugin);
gui.openInventory(player);
gui.setSlot(new SpigotItem( Material.GRASS_BLOCK).setName("Bauserver").build(),10, inventoryClickEvent -> sendPlayer(player));
// gui.setRunOnClose(() -> {});
}
}
@@ -0,0 +1,4 @@
package com.softwarerat.API.listener;
public class QuitListener {
}
@@ -0,0 +1,30 @@
package com.softwarerat.API.location;
import com.softwarerat.API.data.GameData;
import lombok.AllArgsConstructor;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
// Game related Location building
@AllArgsConstructor
public class LocationAPI {
GameData gameData;
public void setDefaultSpawnLocation(String world,int x,int y,int z){
Location l = new Location(Bukkit.getWorld(world),x,y,z);
PlayerSpawnLocation location = new PlayerSpawnLocation();
location.setLocation(l);
gameData.setDefaultSpawnLocation(location);
}
public void addSpawnLocationForPlayer(@NotNull Player p, String world, int x, int y, int z){
Location l = new Location(Bukkit.getWorld(world),x,y,z);
PlayerSpawnLocation location = new PlayerSpawnLocation();
location.setLocation(l);
location.setAssociatedPlayer(p.getUniqueId());
gameData.getSpawnLocations().add(location);
}
}
@@ -0,0 +1,19 @@
package com.softwarerat.API.location;
import com.softwarerat.API.gameType.GameType;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Location;
import java.util.UUID;
// Game related Player spawn Location
@Getter
@Setter
public class PlayerSpawnLocation {
GameType gameType;
Location location;
UUID associatedPlayer;
}
@@ -0,0 +1,20 @@
package com.softwarerat.API.player;
import com.softwarerat.API.data.GameData;
import com.softwarerat.GameAPI;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
// Game related PlayerAPI for checking if a player is the GameHost
public class PlayerAPI {
GameAPI gameAPI;
GameData gameData;
JavaPlugin javaPlugin = gameAPI.getJavaPlugin();
public boolean isHosting(Player p){
String s = gameData.getGameHost(javaPlugin);
return p.getName().equals(s);
}
}
@@ -0,0 +1,57 @@
package com.softwarerat.API.prefix;
import com.softwarerat.API.data.GameData;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import java.util.List;
public class PrefixAPI {
/* PrefixSystem of the whole Network
* this will be the future way to add Tablist Prefixes, and will depend on GameData Settings like wich GameType and
*
*
* */
Scoreboard scoreboard;
public PrefixAPI(Scoreboard scoreboard) {
this.scoreboard = scoreboard;
}
public void createPrefix(String prefixName, int priority, String prefix) {
Team t = scoreboard.registerNewTeam(priority+prefixName);
t.setPrefix(prefix);
}
public void addPlayerToTeam(String prefixName, int priority,Player player) {
if (scoreboard.getTeam(priority+prefixName) != null){
scoreboard.getTeam(priority+prefixName).addPlayer(player);
}
}
public boolean playerIsPermissible(Player player, String prefixName){
return player.hasPermission("prefixAPI."+prefixName);
}
public void addPermissiblePlayerToTeam(Player player, String prefixName,int priority){
Team t = getTeam(prefixName,priority);
if (this.playerIsPermissible(player,prefixName)) t.addPlayer(player);
}
public void removePlayerFromTeam(String prefixName, int priority,Player player){
if (scoreboard.getTeam(priority+prefixName) != null){
scoreboard.getTeam(priority+prefixName).removePlayer(player);
}
}
public Team getTeam(String prefixName, int priority){
if (scoreboard.getTeam(priority+prefixName) != null){
return scoreboard.getTeam(priority+prefixName);
}
return null;
}
}
@@ -0,0 +1,19 @@
package com.softwarerat.API.scoreboard;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*;
public class ScoreAPI {
public ScoreAPI(String minigameName, String mapName,Player player,String localName){
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getNewScoreboard();
Objective objective = board.registerNewObjective(localName, "dummy");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
objective.setDisplayName(minigameName);
player.setScoreboard(board);
}
}
@@ -0,0 +1,20 @@
package com.softwarerat.API.world;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
public class WorldAPI {
public void unloadWorld(String WorldName){
Bukkit.unloadWorld(WorldName,true);
}
public void loadWorld(String WorldName){
new WorldCreator(WorldName).environment(World.Environment.NORMAL).createWorld();
}
public void teleportOnlinePlayersToWorld(String worldName){
Location L = new Location(Bukkit.getWorld(worldName),0,10,0);
Bukkit.getOnlinePlayers().forEach(p ->{p.teleportAsync(L);});
}
}
@@ -0,0 +1,40 @@
package com.softwarerat;
import com.softwarerat.API.commands.Navigator;
import com.softwarerat.API.data.GameData;
import com.softwarerat.API.location.LocationAPI;
import com.softwarerat.API.prefix.PrefixAPI;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.softwarerat.API.world.WorldAPI;
@Getter
@Setter
public class GameAPI {
JavaPlugin javaPlugin;
GameData gameData;
WorldAPI worldAPI;
LocationAPI locationAPI;
PrefixAPI prefixAPI;
public void enableAPI(JavaPlugin jPlugin){
javaPlugin = jPlugin;
worldAPI = new WorldAPI();
System.out.println("Enabled GameAPI");
PluginManager pluginManager = Bukkit.getPluginManager();
locationAPI = new LocationAPI(gameData);
//javaPlugin.getCommand("getNavigator").setExecutor(new Navigator(this));
//if (gameData.getGameType().equals(GameType.GAME_TYPE_TYPELESS) || gameData.getCurrentGameState().equals(GameState.GAME_STATE_LOBBY)){
// pluginManager.registerEvents(new BuildBreakListener(),jPlugin);
// pluginManager.registerEvents(new LobbyJoinListener(),jPlugin);
//}
}
}
View File