This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from 602723113/dev
Release 1.0.0
- Loading branch information
Showing
101 changed files
with
3,085 additions
and
3,725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
# MayCore | ||
一个基于BukkitAPI开发的类库 | ||
# May Common Library (MCLib) [](https://ci.appveyor.com/project/602723113/may-common-library) [](https://travis-ci.org/602723113/May-Common-Library) [](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** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# May Common Library (MCLib) [](https://ci.appveyor.com/project/602723113/may-common-library) [](https://travis-ci.org/602723113/May-Common-Library) [](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?** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
4 changes: 1 addition & 3 deletions
4
...zoyn/core/builder/AdvancementBuilder.java → .../core/advancement/AdvancementBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...c/zoyn/core/builder/ConditionBuilder.java → ...yn/core/advancement/ConditionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...cc/zoyn/core/builder/CriteriaBuilder.java → ...oyn/core/advancement/CriteriaBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
advancement/src/main/java/cc/zoyn/core/advancement/FrameEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
} |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
advancement/src/main/java/cc/zoyn/core/advancement/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...java/cc/zoyn/core/minecraft/JsonImpl.java → ...main/java/cc/zoyn/core/book/JsonImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
Oops, something went wrong.