Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #29 from McMoonLakeDev/v1.9-alpha
Browse files Browse the repository at this point in the history
v1.9 a3
  • Loading branch information
MoonLake authored Feb 24, 2017
2 parents 9ced0b3 + c8d4f22 commit d32053e
Show file tree
Hide file tree
Showing 94 changed files with 6,779 additions and 463 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MoonLake [![GitHub version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=gh&type=6&v=1.9-a2.2&x2=0)](https://github.com/u2g/MoonLake) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://github.com/u2g/MoonLake) [![Open Source Love](https://badges.frapsoft.com/os/gpl/gpl.svg?v=102)](https://github.com/u2g/MoonLake)
# MoonLake [![GitHub version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=gh&type=6&v=1.9-a3&x2=0)](https://github.com/u2g/MoonLake) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://github.com/u2g/MoonLake) [![Open Source Love](https://badges.frapsoft.com/os/gpl/gpl.svg?v=102)](https://github.com/u2g/MoonLake)

Minecraft MoonLake Core API Plugin
By Month_Light Ver: 1.9-a2.2
By Month_Light Ver: 1.9-a3

## 简介
这个插件提供了大量的 API 功能,实现了一些 Bukkit 无法做到的 NMS 功能<br />
Expand All @@ -14,11 +14,11 @@ By Month_Light Ver: 1.9-a2.2
* `Cauldron | KCauldron [模组服务端]` <span style="color: red">✘</span> 完全不支持

## 目前已经实现的功能
* 玩家支持库: [点我](/src/main/java/com/minecraft/moonlake/api/player "Player Library")
* 月色之湖玩家: [点我](/src/main/java/com/minecraft/moonlake/api/player/MoonLakePlayer.java "Player Library")
* 物品栈支持库: [点我](/src/main/java/com/minecraft/moonlake/api/item "Item Library")
* 数据库支持库: [点我](/src/main/java/com/minecraft/moonlake/mysql "MySQL Library")
* 花式消息支持库: [点我](/src/main/java/com/minecraft/moonlake/api/fancy "FancyMessage")
* NMS 数据包发送: [点我](/src/main/java/com/minecraft/moonlake/nms/packet "NMS Packet")
* NMS 数据包发送: [点我](/src/main/java/com/minecraft/moonlake/api/packet "NMS Packet")
* NBT 操作支持库: [点我](/src/main/java/com/minecraft/moonlake/api/nbt "NBT Library")
* 插件注解支持库: [点我](/src/main/java/com/minecraft/moonlake/api/annotation/plugin "Plugin Annotation")
* 数据包通道监听器: [点我](/src/main/java/com/minecraft/moonlake/api/packet/listener "Packet Channel Listener")
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.minecraft.moonlake</groupId>
<artifactId>MoonLake</artifactId>
<packaging>jar</packaging>
<version>1.9-a2.2</version>
<version>1.9-a3</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/com/minecraft/moonlake/MoonLakeAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import com.minecraft.moonlake.api.nbt.NBTFactory;
import com.minecraft.moonlake.api.nbt.NBTLibrary;
import com.minecraft.moonlake.api.nbt.NBTList;
import com.minecraft.moonlake.api.packet.PacketPlayOutBukkit;
import com.minecraft.moonlake.api.packet.PacketPlayOutBungee;
import com.minecraft.moonlake.api.packet.exception.PacketException;
import com.minecraft.moonlake.api.player.MoonLakePlayer;
import com.minecraft.moonlake.api.player.PlayerLibrary;
import com.minecraft.moonlake.api.player.PlayerLibraryFactorys;
Expand All @@ -54,7 +56,6 @@
import com.minecraft.moonlake.nbt.exception.NBTException;
import com.minecraft.moonlake.nms.packet.Packet;
import com.minecraft.moonlake.nms.packet.PacketFactory;
import com.minecraft.moonlake.nms.packet.exception.PacketException;
import com.minecraft.moonlake.particle.ParticleEffect;
import com.minecraft.moonlake.particle.ParticleException;
import com.minecraft.moonlake.reflect.Reflect;
Expand Down Expand Up @@ -435,7 +436,9 @@ public static FireworkBuilder newFireworkBuilder() {
* 获取 PlayerLibrary 对象
*
* @return PlayerLibrary
* @deprecated 已过时, 将于 v2.0 删除.
*/
@Deprecated
public static PlayerLibrary getPlayerLibrary() {

return PlayerLibraryFactorys.player();
Expand Down Expand Up @@ -775,7 +778,7 @@ public static MySQLConnection newMySQLConnection(String host, int port, @Nullabl
* @param <T> Packet
* @return Packet 实例对象
* @throws PacketException 如果获取错误则抛出异常
* @deprecated 已过时, 建议使用参数获取实例对象
* @deprecated 已过时, 将于 v2.0 删除. 请使用 {@link #newPacketPlayOutBukkit(Class)}
* @see #newPacket(Class, Object...)
*/
@Deprecated
Expand All @@ -793,12 +796,35 @@ public static <T extends Packet> T newPacket(Class<T> packet) throws PacketExcep
* @param <T> Packet
* @return Packet 实例对象
* @throws PacketException 如果获取错误则抛出异常
* @deprecated 已过时, 将于 v2.0 删除. 请使用 {@link #newPacketPlayOutBukkit(Class)}
*/
@Deprecated
@SuppressWarnings("deprecation")
public static <T extends Packet> T newPacket(Class<T> packet, Object... args) throws PacketException {

return PacketFactory.get().instance(packet, args);
}

/**
* 获取指定 PacketPlayOutBukkit 的实例对象
*
* @param packet 数据包
* @param <T> 数据包类
* @return 数据包实例对象
* @throws PacketException 如果获取错误则抛出异常
*/
public static <T extends PacketPlayOutBukkit> T newPacketPlayOutBukkit(Class<T> packet) throws PacketException {

try {

return packet.newInstance();

} catch (Exception e) {

throw new PacketException(e.getMessage(), e);
}
}

/**
* 调用任务帮助器运行任务
*
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/com/minecraft/moonlake/MoonLakePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
package com.minecraft.moonlake;

import com.minecraft.moonlake.api.MoonLake;
import com.minecraft.moonlake.api.packet.listener.PacketListenerFactory;
import com.minecraft.moonlake.api.player.PlayerLibraryFactorys;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

Expand All @@ -32,7 +30,7 @@
* <hr />
* <div>
* <h1>Minecraft MoonLake Core API Plugin</h1>
* <p>By Month_Light Ver: 1.9-a2.2</p>
* <p>By Month_Light Ver: 1.9-a3</p>
* <p>Website: <a href="http://www.mcyszh.com" target="_blank" style="text-decoration: none;">MoonLake Website</a></p>
* <p>QQ Group: 377607025 -> <a href="http://jq.qq.com/?_wv=1027&k=2IfPFrH" target="_blank">Jump</a></p>
* <hr />
Expand All @@ -50,11 +48,11 @@
* <div>
* <h1>目前已经实现的功能有:</h1>
* <ul>
* <li>玩家支持库 {@link com.minecraft.moonlake.api.player.PlayerLibrary}</li>
* <li>月色之湖玩家 {@link com.minecraft.moonlake.api.player.MoonLakePlayer}</li>
* <li>物品栈支持库 {@link com.minecraft.moonlake.api.item.ItemLibrary}</li>
* <li>数据库支持库 {@link com.minecraft.moonlake.mysql.MySQLConnection}</li>
* <li>花式消息支持库 {@link com.minecraft.moonlake.api.fancy.FancyMessage}</li>
* <li>NMS 数据包发送 {@link com.minecraft.moonlake.nms.packet.Packet}</li>
* <li>NMS 数据包发送 {@link com.minecraft.moonlake.api.packet.Packet}</li>
* <li>NBT 操作支持库 {@link com.minecraft.moonlake.api.nbt.NBTLibrary}</li>
* <li>插件注解支持库 {@link com.minecraft.moonlake.api.annotation.plugin.PluginAnnotation}</li>
* <li>数据包通道监听器 {@link com.minecraft.moonlake.api.packet.listener.PacketListener}</li>
Expand All @@ -67,7 +65,7 @@
* <h1>修改操作请您遵守 <a href="https://github.com/u2g/MoonLake/blob/master/LICENSE" target="_blank">GPLv3</a> 协议,您必须公开修改过的所有代码!</h1>
* </div>
*
* @version 1.9-a2.2
* @version 1.9-a3
* @author Month_Light
*/
public class MoonLakePlugin extends JavaPlugin implements MoonLake {
Expand Down Expand Up @@ -105,13 +103,18 @@ public void onEnable() {
private void loadLibraryClass() {
// load class
try {
// load PlayerLibraryFactorys class to register listener
Class.forName(PlayerLibraryFactorys.class.getName());
// load depend player class to register listener
Class.forName("com.minecraft.moonlake.api.player.DependPlayerPluginListener");
}
catch (Exception e) {

this.getLogger().log(Level.WARNING, "The load depend player plugin listener exception.", e);
}
try {

if(getConfiguration().isPacketChannelListener()) {
// load PacketListenerFactory class
Class.forName(PacketListenerFactory.class.getName());
this.getLogger().info("月色之湖数据包通道监听器(PCL)成功加载.");
Class.forName("com.minecraft.moonlake.api.packet.listener.PacketListenerFactory");
}
}
catch (Exception e) {
Expand Down
97 changes: 97 additions & 0 deletions src/main/java/com/minecraft/moonlake/api/chat/ChatSerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright (C) 2017 The MoonLake Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


package com.minecraft.moonlake.api.chat;

import com.minecraft.moonlake.api.nms.exception.NMSException;
import com.minecraft.moonlake.validate.Validate;

import java.lang.reflect.Method;

import static com.minecraft.moonlake.reflect.Reflect.*;

/**
* <h1>ChatSerializer</h1>
* 聊天序列化 (临时)
*
* @version 1.0
* @author Month_Light
*/
public class ChatSerializer {

private final static Class<?> CLASS_ICHATBASECOMPONENT;
private final static Class<?> CLASS_CHARSERIALIZER;
private final static Method METHOD_JSONTOICBC;

static {

try {
CLASS_ICHATBASECOMPONENT = PackageType.MINECRAFT_SERVER.getClass("IChatBaseComponent");
CLASS_CHARSERIALIZER = PackageType.MINECRAFT_SERVER.getClass(getServerVersion().equals("v1_8_R1") ? "ChatSerializer" : "IChatBaseComponent$ChatSerializer");

Method JSONTOICBC_TEMP = null;

try {
// 先直接获取 ChatSerializer 类的 a 函数, 这个函数也就是将 json 转换为 ICBC 对象
JSONTOICBC_TEMP = getMethod(CLASS_CHARSERIALIZER, "a", String.class);
} catch (Exception e) {
}
if(JSONTOICBC_TEMP == null) {
// 判断一下如果上面的获取异常, 那么在使用这个方式
// 这个方式就是遍历 ChatSerializer 类的所有公开函数
// 然后对比返回值和函数的需要参数, 符合则获取对应函数对象
try {
Class<?>[] parameArray = { String.class };
Method[] methods = CLASS_CHARSERIALIZER.getMethods();
for(Method method : methods)
if(CLASS_ICHATBASECOMPONENT.isAssignableFrom(method.getReturnType()) && DataType.compare(method.getParameterTypes(), parameArray)) {
JSONTOICBC_TEMP = method;
break;
}
} catch (Exception e) {
}
}
METHOD_JSONTOICBC = JSONTOICBC_TEMP;
}
catch (Exception e) {

throw new NMSException("The chat serializer reflect raw initialize exception.", e);
}
}

private ChatSerializer() {
}

/**
* 将指定 Json 文本内容转换到 IChatBaseComponent 对象实例
*
* @param json Json 文本
* @return IChatBaseComponent | null
*/
public static Object fromJson(String json) {

Validate.notNull(json, "The json object is null.");

try {
return METHOD_JSONTOICBC.invoke(null, json);
}
catch (Exception e) {
}
return null;
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/minecraft/moonlake/api/event/Cancellable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2017 The MoonLake Authors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


package com.minecraft.moonlake.api.event;

public interface Cancellable extends org.bukkit.event.Cancellable, Cloneable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
* @author Month_Light
* @see MoonLakePacketEvent
* @see Packet
* @deprecated 已过时, 将于 v2.0 删除. 请使用 {@link MoonLakePacketOutEvent}
*/
@Deprecated
public class MoonLakePacketDispatchEvent extends MoonLakePacketEvent implements Cancellable {

private final static HandlerList handlerList = new HandlerList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.minecraft.moonlake.api.event.core;

import com.minecraft.moonlake.api.event.MoonLakeEvent;
import com.minecraft.moonlake.nms.packet.Packet;
import com.minecraft.moonlake.api.packet.Packet;
import com.minecraft.moonlake.validate.Validate;

/**
Expand All @@ -33,15 +33,15 @@
*/
public abstract class MoonLakePacketEvent extends MoonLakeEvent {

private final Packet<?> packet;
private final Packet packet;

/**
* 月色之湖数据包事件类构造函数
*
* @param packet 数据包对象
* @throws IllegalArgumentException 如果数据包对象为 {@code null} 则抛出异常
*/
public MoonLakePacketEvent(Packet<?> packet) throws IllegalArgumentException {
public MoonLakePacketEvent(Packet packet) throws IllegalArgumentException {

Validate.notNull(packet, "The moonlake packet object is null.");

Expand All @@ -54,7 +54,7 @@ public MoonLakePacketEvent(Packet<?> packet) throws IllegalArgumentException {
* @return Packet
* @see Packet
*/
public final Packet<?> getPacket() {
public Packet getPacket() {

return packet;
}
Expand Down
Loading

0 comments on commit d32053e

Please sign in to comment.