Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasEi committed Mar 15, 2018
0 parents commit c53b346
Show file tree
Hide file tree
Showing 23 changed files with 1,975 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*.class

\# Mobile Tools for Java (J2ME)
.mtj.tmp/

\# Package Files \#
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# ignore the output
out/
target/

**/dependency-reduced-pom.xml

.idea/
*.iml

.settings/
.project
.classpath
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# NMS Utilities

Version dependent utilities. Currently supports all versions from 1.8 to 1.12.

### Maven
```xml
<repositories>
<repository>
<id>nikl-repo</id>
<url>http://repo.nikl.me/artifactory/repositories</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>me.nikl.nmsutilities</groupId>
<artifactId>nmsutilities</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
```
37 changes: 37 additions & 0 deletions nmsutilities-nms/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

<parent>
<groupId>me.nikl.nmsutilities</groupId>
<artifactId>nmsutilities-parent</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>nmsutilities-nms</artifactId>

<repositories>
<repository>
<id>bukkit-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package me.nikl.nmsutilities;

import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.Collection;

/**
* Created by niklas on 10/17/16.
*
* interface for nms utils
*/
public interface NmsUtility {

void updateInventoryTitle(Player player, String newTitle);

void sendJSON(Player player, String json);

void sendJSON(Player player, Collection<String> json);

void sendJSON(Collection<Player> players, String json);

void sendJSON(Collection<Player> players, Collection<String> json);

void sendTitle(Player player, String title, String subTitle);

void sendActionbar(Player player, String message);

void sendListHeader(Player player, String header);

void sendListFooter(Player player, String footer);

ItemStack removeGlow(ItemStack item);

ItemStack addGlow(ItemStack item);
}
41 changes: 41 additions & 0 deletions nmsutilities-v1_10_R1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

<parent>
<groupId>me.nikl.nmsutilities</groupId>
<artifactId>nmsutilities-parent</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>nmsutilities-v1_10_R1</artifactId>

<repositories>
<repository>
<id>bukkit-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.10.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.nikl.nmsutilities</groupId>
<artifactId>nmsutilities-nms</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package me.nikl.nmsutilities;

import com.google.gson.stream.JsonReader;
import net.minecraft.server.v1_10_R1.ChatMessage;
import net.minecraft.server.v1_10_R1.EntityPlayer;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.ItemStack;
import net.minecraft.server.v1_10_R1.NBTTagCompound;
import net.minecraft.server.v1_10_R1.NBTTagList;
import net.minecraft.server.v1_10_R1.PacketPlayOutChat;
import net.minecraft.server.v1_10_R1.PacketPlayOutOpenWindow;
import net.minecraft.server.v1_10_R1.PacketPlayOutPlayerListHeaderFooter;
import net.minecraft.server.v1_10_R1.PacketPlayOutTitle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;

import java.io.StringReader;
import java.lang.reflect.Field;
import java.util.Collection;

/**
* Created by niklas on 10/17/16.
*
* nms utility for 1.10.R1
*/
public class NmsUtility_1_10_R1 implements NmsUtility {
@Override
public void updateInventoryTitle(Player player, String newTitle) {
EntityPlayer ep = ((CraftPlayer) player).getHandle();
PacketPlayOutOpenWindow packet = new PacketPlayOutOpenWindow(ep.activeContainer.windowId, "minecraft:chest", new ChatMessage(ChatColor.translateAlternateColorCodes('&', newTitle)), player.getOpenInventory().getTopInventory().getSize());
ep.playerConnection.sendPacket(packet);
ep.updateInventory(ep.activeContainer);
}

@Override
public void sendJSON(Player player, String json) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 0);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}

@Override
public void sendJSON(Player player, Collection<String> json) {
for (String message : json) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(message);
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 0);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

@Override
public void sendJSON(Collection<Player> players, String json) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(json);
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 0);
for (Player player : players) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}

@Override
public void sendJSON(Collection<Player> players, Collection<String> json) {
for (String message : json) {
IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(message);
PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 0);
for (Player player : players) {
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}
}
}

@Override
public void sendTitle(Player player, String title, String subTitle) {
if (title != null) {
IChatBaseComponent chatTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', title + "\"}"));
PacketPlayOutTitle pTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, chatTitle);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(pTitle);
}
if (subTitle != null) {
IChatBaseComponent chatSubTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', subTitle + "\"}"));
PacketPlayOutTitle pSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, chatSubTitle);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(pSubTitle);
}
PacketPlayOutTitle length = new PacketPlayOutTitle(5, 20, 5);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(length);
}

@Override
public void sendActionbar(Player player, String message) {
IChatBaseComponent icbc = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', message + "\"}"));
PacketPlayOutChat bar = new PacketPlayOutChat(icbc, (byte) 2);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(bar);
}

@Override
public void sendListFooter(Player player, String footer) {
IChatBaseComponent bottom = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
try {
Field footerField = packet.getClass().getDeclaredField("b");
footerField.setAccessible(true);
footerField.set(packet, bottom);
footerField.setAccessible(false);
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}

@Override
public void sendListHeader(Player player, String header) {
JsonReader reader = new JsonReader(new StringReader("{'text': '" + header + "'}"));
IChatBaseComponent bottom = IChatBaseComponent.ChatSerializer.a((reader.toString()));
PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
try {
Field footerField = packet.getClass().getDeclaredField("a");
footerField.setAccessible(true);
footerField.set(packet, bottom);
footerField.setAccessible(false);
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
}

@Override
public org.bukkit.inventory.ItemStack removeGlow(org.bukkit.inventory.ItemStack item) {
ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag = null;
if (nmsStack.hasTag()) {
tag = nmsStack.getTag();
tag.remove("ench");
nmsStack.setTag(tag);
return CraftItemStack.asCraftMirror(nmsStack);
}
return item;
}

@Override
public org.bukkit.inventory.ItemStack addGlow(org.bukkit.inventory.ItemStack item) {
ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
NBTTagCompound tag = null;
if (!nmsStack.hasTag()) {
tag = new NBTTagCompound();
nmsStack.setTag(tag);
}
if (tag == null) tag = nmsStack.getTag();
NBTTagList ench = new NBTTagList();
tag.set("ench", ench);
nmsStack.setTag(tag);
return CraftItemStack.asCraftMirror(nmsStack);
}
}
41 changes: 41 additions & 0 deletions nmsutilities-v1_11_R1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>

<parent>
<groupId>me.nikl.nmsutilities</groupId>
<artifactId>nmsutilities-parent</artifactId>
<version>1.0.0</version>
</parent>

<artifactId>nmsutilities-v1_11_R1</artifactId>

<repositories>
<repository>
<id>bukkit-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.11.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.nikl.nmsutilities</groupId>
<artifactId>nmsutilities-nms</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Loading

0 comments on commit c53b346

Please sign in to comment.