Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KorshunK authored Mar 20, 2024
1 parent 1389e4d commit a958a9a
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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>ru.squarecircle</groupId>
<artifactId>MinecraftMenuFramework</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>MinecraftMenuFramework</name>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<repositories>
<repository>
<id>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>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.squarecircle.minecraftmenuframework;

import org.bukkit.plugin.java.JavaPlugin;

public final class MinecraftMenuAPI extends JavaPlugin {

@Override
public void onEnable() {
getLogger().info("Framework enabled!");
}

@Override
public void onDisable() {
getLogger().info("Framework disabled!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.squarecircle.minecraftmenuframework.core;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public abstract class AbstractMenu {
protected static void create(int size, String title) {
createMenu(title, size);
}
protected static void create(Player owner, int size, String title) {
createMenu(owner, size, title);
}
private static void createMenu(String title, int size) {
Bukkit.createInventory(null, size, title);
}
private static void createMenu(Player owner, int size, String title) {
Bukkit.createInventory(owner, size, title);
}
}
102 changes: 102 additions & 0 deletions src/main/java/ru/squarecircle/minecraftmenuframework/core/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package ru.squarecircle.minecraftmenuframework.core;

import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;

import java.util.List;


public class Menu extends AbstractMenu {
private Player owner = null;
private int size;
private String title = "Menu created with MinecraftMenuFramework";
public Menu(Player owner, int size, String title) {
this.owner = owner;
this.size = size;
this.title = title;
create(owner, size, title);
}
public Menu(int size, String title) {
this.size = size;
this.title = title;
create(size, title);
}
public Menu(int size) {
this.size = size;
create(size, "Menu created with MinecraftMenuFramework");
}

public Player getOwner() {
return owner;
}

public void setOwner(Player owner) {
this.owner = owner;
}

public int getSize() {
return size;
}

public void setSize(int size) {
this.size = size;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public void clear() {
this.get().clear();
}
public boolean isEmpty() {
return this.get().getContents() == null;
}

public void addItem(ItemStack itemStack) {
this.get().addItem(itemStack);
}

public void setItem(int slot, ItemStack itemStack) {
this.get().setItem(slot, itemStack);
}

public void removeItem(ItemStack itemStack) {
this.get().remove(itemStack);
}

public void removeItem(int i) {
this.get().remove(i);
}

public ItemStack getItem(int i) {
return this.get().getItem(i);
}

public ItemStack[] getContents() {
return this.get().getContents();
}

public ItemStack[] getArmorContents() {
return this.getArmorContents();
}

public List<HumanEntity> getViewers() {
return this.get().getViewers();
}



public Inventory get() {
return Bukkit.createInventory(owner, size, title);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ru.squarecircle.minecraftmenuframework.core;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public class MenuManager {
private static List<Menu> allMenus = new ArrayList<>();
public static Menu create(int size, String title) {
return createMenu(size, title);
}
public static Menu create(Player owner, int size, String title) {
return createMenu(owner, size, title);
}
private static Menu createMenu(int size, String title) {
Menu menu = new Menu(size, title);
allMenus.add(menu);
return menu;
}
private static Menu createMenu(Player owner, int size, String title) {
Menu menu = new Menu(owner, size, title);
allMenus.add(menu);
return menu;
}
public static Menu castToMenu(Inventory inventory) {
return new Menu(inventory.getSize(), inventory.getTitle());
}

public static Inventory castToInventory(Menu menu) {
return Bukkit.createInventory(menu.getOwner(), menu.getSize(), menu.getTitle());
}
public static List<Menu> getAllMenus() {
return allMenus;
}
public static void allMenusForEach(Consumer<? super Menu> action) {
getAllMenus().forEach(action);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.squarecircle.minecraftmenuframework.core;

import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class PlayerMenu {
public static void openFor(Player player, Menu menu) {
player.openInventory(menu.get());
}
public static void closeViewFor(Player player) {
player.getOpenInventory().close();
}
public static void updateViewFor(Player player) {
player.updateInventory();
}
}
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: MinecraftMenuFramework
version: '${project.version}'
main: ru.squarecircle.minecraftmenuframework.MinecraftMenuFramework
prefix: MinecraftMenuFramework

0 comments on commit a958a9a

Please sign in to comment.