Skip to content

Commit

Permalink
Remove Craftbukkit dependency and shade GSON separately.
Browse files Browse the repository at this point in the history
  • Loading branch information
drtshock committed Dec 4, 2014
1 parent f168221 commit 423ae7c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
38 changes: 33 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>mkremins</groupId>
<artifactId>fanciful</artifactId>
<version>0.2.0-SNAPSHOT</version>
<version>0.2.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -27,10 +27,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.7.9-R0.1</version>
<scope>provided</scope>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.1</version>
</dependency>
</dependencies>

Expand Down Expand Up @@ -68,6 +67,35 @@
</execution>
</executions>
</plugin>

<!-- Shade GSON because it's no longer in Craftbukkit. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<artifactSet>
<includes>
<include>com.google.code.gson:gson</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.gson</pattern>
<shadedPattern>mkremins.fanciful.shaded.gson</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
18 changes: 10 additions & 8 deletions src/main/java/mkremins/fanciful/FancyMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
import java.util.Map;
import java.util.logging.Level;
import static mkremins.fanciful.TextualComponent.rawText;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonWriter;
import net.amoebaman.util.ArrayWrapper;
import net.amoebaman.util.Reflection;
import org.bukkit.Achievement;
Expand All @@ -25,11 +31,6 @@
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.craftbukkit.libs.com.google.gson.JsonArray;
import org.bukkit.craftbukkit.libs.com.google.gson.JsonElement;
import org.bukkit.craftbukkit.libs.com.google.gson.JsonObject;
import org.bukkit.craftbukkit.libs.com.google.gson.JsonParser;
import org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -495,6 +496,7 @@ public FancyMessage then() {
return this;
}

@Override
public void writeJson(JsonWriter writer) throws IOException{
if (messageParts.size() == 1) {
latest().writeJson(writer);
Expand Down Expand Up @@ -559,16 +561,16 @@ private void send(CommandSender sender, String jsonString){
}

// The ChatSerializer's instance of Gson
private static net.minecraft.util.com.google.gson.Gson nmsChatSerializerGsonInstance;
private static com.google.gson.Gson nmsChatSerializerGsonInstance;

private Object createChatPacket(String json) throws IllegalArgumentException, IllegalAccessException, InstantiationException, InvocationTargetException{
if(nmsChatSerializerGsonInstance == null){
// Find the field and its value, completely bypassing obfuscation
for(Field declaredField : Reflection.getNMSClass("ChatSerializer").getDeclaredFields()){
if(Modifier.isFinal(declaredField.getModifiers()) && Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType() == net.minecraft.util.com.google.gson.Gson.class){
if(Modifier.isFinal(declaredField.getModifiers()) && Modifier.isStatic(declaredField.getModifiers()) && declaredField.getType() == com.google.gson.Gson.class){
// We've found our field
declaredField.setAccessible(true);
nmsChatSerializerGsonInstance = (net.minecraft.util.com.google.gson.Gson)declaredField.get(null);
nmsChatSerializerGsonInstance = (com.google.gson.Gson)declaredField.get(null);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mkremins/fanciful/JsonRepresentedObject.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package mkremins.fanciful;

import java.io.IOException;
import com.google.gson.stream.JsonWriter;

import org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter;
import java.io.IOException;

/**
* Represents an object that can be serialized to a JSON writer instance.
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mkremins/fanciful/JsonString.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import javax.annotation.concurrent.Immutable;

import com.google.gson.stream.JsonWriter;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter;

/**
* Represents a JSON string value.
Expand All @@ -22,7 +22,8 @@ final class JsonString implements JsonRepresentedObject, ConfigurationSerializab
public JsonString(String value){
_value = value;
}


@Override
public void writeJson(JsonWriter writer) throws IOException {
writer.value(getValue());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mkremins/fanciful/MessagePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.HashMap;
import java.util.Map;

import com.google.gson.stream.JsonWriter;
import org.bukkit.ChatColor;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter;

import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableBiMap;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mkremins/fanciful/TextualComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.HashMap;
import java.util.Map;

import com.google.gson.stream.JsonWriter;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.craftbukkit.libs.com.google.gson.stream.JsonWriter;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
Expand Down

0 comments on commit 423ae7c

Please sign in to comment.