Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from 602723113/dev
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
602723113 authored Sep 8, 2018
2 parents 5ed33f8 + 664e701 commit 03c81e8
Show file tree
Hide file tree
Showing 101 changed files with 3,085 additions and 3,725 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: java
sudo: false
jdk: oraclejdk8
install: mvn clean install package
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
# MayCore
一个基于BukkitAPI开发的类库
# May Common Library (MCLib) [![Build status](https://ci.appveyor.com/api/projects/status/fi528yanx76w25qe?svg=true)](https://ci.appveyor.com/project/602723113/may-common-library) [![Build Status](https://travis-ci.org/602723113/May-Common-Library.svg?branch=dev)](https://travis-ci.org/602723113/May-Common-Library) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/e8b69ada84954b13a415981844a7e376)](https://www.codacy.com/app/602723113/May-Common-Library?utm_source=github.com&utm_medium=referral&utm_content=602723113/May-Common-Library&utm_campaign=Badge_Grade)
> A library based on BukkitAPI development, and give developer some useful feature
## 它能为你做些什么?
##### 在MayCore中你可以享受以下内容
- 简易的构造Title
- 简易的构造ActionBar
- 简易的构造Tellraw
- 简易的构造Book
- [API]简易的使用1.12的新特性Advancement
- 已封装好的BungeeCordAPI
- 封装了许许多多的Util
[Wiki](https://github.com/602723113/May-Common-Library/wiki)
### README Languages
- English
- [Chinese | 中文](https://github.com/602723113/May-Common-Library/blob/dev/README_zh_CN.md)

## 编译
本项目使用 maven 进行管理
构建请使用
'''
### Feature
> In _MCLib_ you can enjoy the following features
- Easy to use NMS
- Easy to use NBT
- Easy to use Tellraw
- Easy to use ServerPing
- Easy to use Book
- Easy to use 1.12 new features **Advancement**
- Easy to use Pager
- Easy to use Reflection
- A lot of Utils
- ...

### License
- This project follows the MIT protocol

### Compile
This project uses Maven for management
Construction please use command
```
mvn clean install package
'''
```

**Like this project? Why not put it a star**
28 changes: 28 additions & 0 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# May Common Library (MCLib) [![Build status](https://ci.appveyor.com/api/projects/status/fi528yanx76w25qe?svg=true)](https://ci.appveyor.com/project/602723113/may-common-library) [![Build Status](https://travis-ci.org/602723113/May-Common-Library.svg?branch=dev)](https://travis-ci.org/602723113/May-Common-Library) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/e8b69ada84954b13a415981844a7e376)](https://www.codacy.com/app/602723113/May-Common-Library?utm_source=github.com&utm_medium=referral&utm_content=602723113/May-Common-Library&utm_campaign=Badge_Grade)
> 一个基于BukkitAPI开发的类库
[Wiki](https://github.com/602723113/May-Common-Library/wiki)
### 特性
> _MCLib_ 中你可以享受以下功能
- 简易使用NMS
- 简易使用NBT
- 简易的使用Tellraw
- 简易的使用ServerPing
- 简易的使用Book
- 简易的使用1.12的新特性Advancement
- 简易的使用分页(Pager)
- 简易的使用反射工具类
- 封装了许许多多的Util
- ...

### 协议
- 本项目遵循 MIT 协议

### 编译
本项目使用 maven 进行管理
构建请使用
```
mvn clean install package
```

**喜欢这个项目?不妨给它留个star?**
16 changes: 16 additions & 0 deletions advancement/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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">
<parent>
<artifactId>May-Common-Library</artifactId>
<groupId>cc.zoyn.core</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>advancement</artifactId>
<packaging>jar</packaging>


</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package cc.zoyn.core.builder;
package cc.zoyn.core.advancement;

import cc.zoyn.core.advancement.FrameEnum;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import cc.zoyn.core.advancement.BackgroundEnum;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Bukkit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum BackgroundEnum {

private String name;

private BackgroundEnum(String name) {
BackgroundEnum(String name) {
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.zoyn.core.builder;
package cc.zoyn.core.advancement;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cc.zoyn.core.builder;
package cc.zoyn.core.advancement;

import com.google.common.collect.Lists;
import com.google.gson.JsonObject;
import cc.zoyn.core.advancement.TriggerEnum;

import java.util.List;

Expand Down
22 changes: 22 additions & 0 deletions advancement/src/main/java/cc/zoyn/core/advancement/FrameEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cc.zoyn.core.advancement;

/**
* 图标边框枚举
*
* @author Zoyn
*/
public enum FrameEnum {
/**
* TASK(默认)
*/
TASK(),
/**
* GOAL为更圆的边框标题,其用于完整信标进度
*/
GOAL(),
/**
* CHALLENGE,其用于杀死所有种类生物的进度
*/
CHALLENGE()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Wrapper 1.12 version advancement operation
*
* @author Zoyn
* @since 2017-12-09
*/
package cc.zoyn.core.advancement;
24 changes: 24 additions & 0 deletions book/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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">
<parent>
<artifactId>May-Common-Library</artifactId>
<groupId>cc.zoyn.core</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>book</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>cc.zoyn.core</groupId>
<artifactId>common</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
36 changes: 36 additions & 0 deletions book/src/main/java/cc/zoyn/core/book/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cc.zoyn.core.book;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;

import java.util.List;

/**
* Book - 数据模型
*
* @author Zoyn
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Book {

private String author = "Zoyn";
private String title = "HelloWorld";
private List<Page> pages = Lists.newArrayList();

public ItemStack getItem() {
ItemStack book = new ItemStack(Material.WRITTEN_BOOK);
BookMeta meta = (BookMeta) book.getItemMeta();
meta.setTitle(title);
meta.setAuthor(author);
BookUtils.setPagesAsPage(meta, pages);
book.setItemMeta(meta);
return book;
}
}
138 changes: 138 additions & 0 deletions book/src/main/java/cc/zoyn/core/book/BookUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package cc.zoyn.core.book;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;

import java.lang.reflect.Method;
import java.util.List;
import java.util.stream.Collectors;

import static cc.zoyn.core.util.NMSUtils.*;
import static cc.zoyn.core.util.reflect.ReflectionUtils.getFieldByFieldName;
import static cc.zoyn.core.util.reflect.ReflectionUtils.getMethod;

/**
* 书本 - 工具类
* <p>
* 简易的打开一个带有特定json的书
* <p>
* Easy to open a book with the specified json
*
* @author Zoyn
* @since 2017/?/?
*/
public final class BookUtils {

private static boolean initialised = false;
private static Method getHandle;
private static Method openBook;

static {
try {
getHandle = getMethod(getOBCClass("CraftPlayer"), "getHandle");
openBook = getMethod(getNMSClass("EntityPlayer"), "a", getNMSClass("ItemStack"), getNMSClass("EnumHand"));

initialised = true;
} catch (ReflectiveOperationException e) {
e.printStackTrace();
Bukkit.getServer().getLogger().warning("Cannot force open book!");
initialised = false;
}
}

// Prevent accidental construction
private BookUtils() {
}

public static boolean isInitialised() {
return initialised;
}

/**
* 打开一个虚拟的书
* <p>
* open a virtual book
*
* @param item 给定的书
* @param player 给定的玩家
* @return return true if open book successfully
*/
public static boolean openBook(Player player, ItemStack item) {
if (!initialised) {
return false;
}
ItemStack held = player.getInventory().getItemInMainHand();
try {
player.getInventory().setItemInMainHand(item);
sendPacket(item, player);
} catch (ReflectiveOperationException e) {
e.printStackTrace();
initialised = false;
}
player.getInventory().setItemInMainHand(held);
return initialised;
}

/**
* 打开一个虚拟的书
* <p>
* open a virtual book
*
* @param player the player
* @param book a {@link Book} object
* @return return true if open book successfully
*/
public static boolean openBook(Player player, Book book) {
return openBook(player, book.getItem());
}

/**
* 以JSON格式来设置书的页面
* <p>
* use json to set the book pages
*
* @param metadata book's meta
* @param pages JSON lists
*/
@SuppressWarnings("unchecked")
public static void setBookPagesAsJson(BookMeta metadata, List<String> pages) {
List<Object> p;
Object page;
try {
p = (List<Object>) getFieldByFieldName(getOBCClass("CraftMetaBook"), "pages").get(metadata);
for (String text : pages) {
page = stringToIChatBaseComponent(text);
p.add(page);
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 用{@link Page}来设置书的页面
* <p>
* use {@link Page} to set the book page
*
* @param metadata book's meta
* @param pages {@link Page} lists
*/
@SuppressWarnings("unchecked")
public static void setPagesAsPage(BookMeta metadata, List<Page> pages) {
setBookPagesAsJson(metadata, pages.stream()
.map(Page::toJsonString)
.collect(Collectors.toList()));
}

private static void sendPacket(ItemStack itemStack, Player p) throws ReflectiveOperationException {
Object entityplayer = getHandle.invoke(p);
Class<?> enumHand = getNMSClass("EnumHand");
Object[] enumArray = new Object[0];
if (enumHand != null) {
enumArray = enumHand.getEnumConstants();
}
openBook.invoke(entityplayer, getNMSItem(itemStack), enumArray[0]);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cc.zoyn.core.minecraft;
package cc.zoyn.core.book;

import cc.zoyn.core.util.JsonBuilderUtils;

Expand Down
Loading

0 comments on commit 03c81e8

Please sign in to comment.