Initial Pass at Minecraft 1.12 support

This commit is contained in:
Olof Larsson 2017-06-11 19:02:26 +02:00
parent 22180b7b3d
commit 5503ba44f0
8 changed files with 134 additions and 30 deletions

View File

@ -35,6 +35,7 @@ import com.massivecraft.massivecore.item.WriterItemStack;
import com.massivecraft.massivecore.mixin.MixinEvent; import com.massivecraft.massivecore.mixin.MixinEvent;
import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.mson.MsonEvent; import com.massivecraft.massivecore.mson.MsonEvent;
import com.massivecraft.massivecore.nms.NmsBasics;
import com.massivecraft.massivecore.nms.NmsItemStackCreate17R4P; import com.massivecraft.massivecore.nms.NmsItemStackCreate17R4P;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSAdapter; import com.massivecraft.massivecore.ps.PSAdapter;
@ -262,6 +263,17 @@ public class MassiveCore extends MassivePlugin
return ret; return ret;
} }
@Override
public List<Class<?>> getClassesActiveNms()
{
List<Class<?>> ret = super.getClassesActiveNms();
ret.remove(NmsBasics.class);
ret.add(0, NmsBasics.class);
return ret;
}
@Override @Override
public List<Class<?>> getClassesActiveMixins() public List<Class<?>> getClassesActiveMixins()
{ {

View File

@ -14,6 +14,7 @@ public class NmsChat extends Mixin
// -------------------------------------------- // // -------------------------------------------- //
private static NmsChat d = new NmsChat().setAlternatives( private static NmsChat d = new NmsChat().setAlternatives(
NmsChat112R1P.class,
NmsChat18R2P.class, NmsChat18R2P.class,
NmsChat18R1.class, NmsChat18R1.class,
NmsChatFallback.class NmsChatFallback.class

View File

@ -0,0 +1,54 @@
package com.massivecraft.massivecore.nms;
import com.massivecraft.massivecore.particleeffect.ReflectionUtils.PackageType;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.ReflectionUtil;
import org.bukkit.entity.Player;
public class NmsChat112R1P extends NmsChatAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static NmsChat112R1P i = new NmsChat112R1P();
public static NmsChat112R1P get() { return i; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
protected Class<?> classChatMessageType;
protected Object instanceChatMessageTypeGameInfo;
// -------------------------------------------- //
// SETUP
// -------------------------------------------- //
@Override
public void setup() throws Throwable
{
this.classChatSerializer = PackageType.MINECRAFT_SERVER.getClass("IChatBaseComponent$ChatSerializer");
this.methodChatSerializer = ReflectionUtil.getMethod(this.classChatSerializer, "a", String.class);
this.classEnumTitleAction = PackageType.MINECRAFT_SERVER.getClass("PacketPlayOutTitle$EnumTitleAction");
setupCommon();
this.classChatMessageType = PackageType.MINECRAFT_SERVER.getClass("ChatMessageType");
this.instanceChatMessageTypeGameInfo = this.classChatMessageType.getEnumConstants()[2];
// CHAT(0),
// SYSTEM(1),
// GAME_INFO(2);
this.constructorPacketPlayOutChatType = ReflectionUtil.getConstructor(this.classPacketPlayOutChat, this.classIChatBaseComponent, this.classChatMessageType);
}
// -------------------------------------------- //
// ACTIONBAR
// -------------------------------------------- //
@Override
public <T> T constructActionBarPacket(Object component) {
return ReflectionUtil.invokeConstructor(this.constructorPacketPlayOutChatType, component, this.instanceChatMessageTypeGameInfo);
}
}

View File

@ -13,16 +13,19 @@ public class NmsChat18R1 extends NmsChatAbstract
public static NmsChat18R1 get() { return i; } public static NmsChat18R1 get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// SETUP SPECIFIC // SETUP
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setupSpecific() throws Throwable public void setup() throws Throwable
{ {
this.classChatSerializer = PackageType.MINECRAFT_SERVER.getClass("ChatSerializer"); this.classChatSerializer = PackageType.MINECRAFT_SERVER.getClass("ChatSerializer");
this.methodChatSerializer = ReflectionUtil.getMethod(this.classChatSerializer, "a", String.class); this.methodChatSerializer = ReflectionUtil.getMethod(this.classChatSerializer, "a", String.class);
this.classEnumTitleAction = PackageType.MINECRAFT_SERVER.getClass("EnumTitleAction"); this.classEnumTitleAction = PackageType.MINECRAFT_SERVER.getClass("EnumTitleAction");
setupCommon();
this.constructorPacketPlayOutChatType = ReflectionUtil.getConstructor(this.classPacketPlayOutChat, this.classIChatBaseComponent, Byte.TYPE);
} }
} }

View File

@ -13,16 +13,18 @@ public class NmsChat18R2P extends NmsChatAbstract
public static NmsChat18R2P get() { return i; } public static NmsChat18R2P get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// SETUP SPECIFIC // SETUP
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setupSpecific() throws Throwable public void setup() throws Throwable
{ {
this.classChatSerializer = PackageType.MINECRAFT_SERVER.getClass("IChatBaseComponent$ChatSerializer"); this.classChatSerializer = PackageType.MINECRAFT_SERVER.getClass("IChatBaseComponent$ChatSerializer");
this.methodChatSerializer = ReflectionUtil.getMethod(this.classChatSerializer, "a", String.class); this.methodChatSerializer = ReflectionUtil.getMethod(this.classChatSerializer, "a", String.class);
this.classEnumTitleAction = PackageType.MINECRAFT_SERVER.getClass("PacketPlayOutTitle$EnumTitleAction"); this.classEnumTitleAction = PackageType.MINECRAFT_SERVER.getClass("PacketPlayOutTitle$EnumTitleAction");
}
setupCommon();
this.constructorPacketPlayOutChatType = ReflectionUtil.getConstructor(this.classPacketPlayOutChat, this.classIChatBaseComponent, Byte.TYPE);
}
} }

View File

@ -61,8 +61,14 @@ public abstract class NmsChatAbstract extends NmsChat
@Override @Override
public void setup() throws Throwable public void setup() throws Throwable
{ {
this.setupSpecific(); throw notImplemented();
}
// -------------------------------------------- //
// SETUP COMMON
// -------------------------------------------- //
protected void setupCommon() throws Throwable {
for (Object object : this.classEnumTitleAction.getEnumConstants()) for (Object object : this.classEnumTitleAction.getEnumConstants())
{ {
Enum<?> e = (Enum<?>) object; Enum<?> e = (Enum<?>) object;
@ -82,15 +88,8 @@ public abstract class NmsChatAbstract extends NmsChat
// Get Chat packet and it's constructor // Get Chat packet and it's constructor
this.classPacketPlayOutChat = PackageType.MINECRAFT_SERVER.getClass("PacketPlayOutChat"); this.classPacketPlayOutChat = PackageType.MINECRAFT_SERVER.getClass("PacketPlayOutChat");
this.constructorPacketPlayOutChat = ReflectionUtil.getConstructor(this.classPacketPlayOutChat, this.classIChatBaseComponent); this.constructorPacketPlayOutChat = ReflectionUtil.getConstructor(this.classPacketPlayOutChat, this.classIChatBaseComponent);
this.constructorPacketPlayOutChatType = ReflectionUtil.getConstructor(this.classPacketPlayOutChat, this.classIChatBaseComponent, Byte.TYPE);
} }
// -------------------------------------------- //
// SETUP SPECIFIC
// -------------------------------------------- //
public abstract void setupSpecific() throws Throwable;
// -------------------------------------------- // // -------------------------------------------- //
// TO COMPONENT // TO COMPONENT
// -------------------------------------------- // // -------------------------------------------- //
@ -173,8 +172,12 @@ public abstract class NmsChatAbstract extends NmsChat
if (player == null) return; if (player == null) return;
Object component = toComponent(raw); Object component = toComponent(raw);
Object packet = ReflectionUtil.invokeConstructor(this.constructorPacketPlayOutChatType, component, (byte)2); Object packet = this.constructActionBarPacket(component);
NmsBasics.get().sendPacket(player, packet); NmsBasics.get().sendPacket(player, packet);
} }
public <T> T constructActionBarPacket(Object component) {
return ReflectionUtil.invokeConstructor(this.constructorPacketPlayOutChatType, component, (byte)2);
}
} }

View File

@ -7,7 +7,7 @@ import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissibleBase; import org.bukkit.permissions.PermissibleBase;
public class BasicCommandSender extends PermissibleBase implements CommandSender public abstract class BasicCommandSender extends PermissibleBase implements CommandSender
{ {
public final String name; public final String name;
@ -39,12 +39,6 @@ public class BasicCommandSender extends PermissibleBase implements CommandSender
return Bukkit.getServer(); return Bukkit.getServer();
} }
@Override
public void sendMessage(String message)
{
// Nothing per default
}
@Override @Override
public void sendMessage(String[] messages) public void sendMessage(String[] messages)
{ {

View File

@ -1,16 +1,51 @@
package com.massivecraft.massivecore.util; package com.massivecraft.massivecore.util;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.predicate.Predicate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapelessRecipe; import org.bukkit.inventory.ShapelessRecipe;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionType; import org.bukkit.potion.PotionType;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
// NOTE: This utility targets 1.9 and will crash on older servers. // NOTE: This utility targets 1.9 and will crash on older servers.
public class RecipeUtil public class RecipeUtil
{ {
// ------------------------------------------- //
// REMOVE
// -------------------------------------------- //
public static void remove(Predicate<Recipe> removePredicate)
{
Objects.requireNonNull(removePredicate);
List<Recipe> recipesToRemove = new MassiveList<>();
List<Recipe> recipesToKeep = new MassiveList<>();
Iterator<Recipe> iterator = Bukkit.recipeIterator();
while (iterator.hasNext())
{
Recipe recipe = iterator.next();
List<Recipe> recipes = removePredicate.apply(recipe) ? recipesToRemove : recipesToKeep;
recipes.add(recipe);
}
if (recipesToRemove.isEmpty()) return;
Bukkit.clearRecipes();
for (Recipe recipe : recipesToKeep) {
Bukkit.addRecipe(recipe);
}
}
// ------------------------------------------- // // ------------------------------------------- //
// POTION // POTION
// -------------------------------------------- // // -------------------------------------------- //