diff --git a/build.gradle b/build.gradle
index 53fd9d5..e682854 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,12 +19,18 @@ apply plugin: 'groovy'
apply plugin: 'forge'
apply plugin: 'maven'
-version = "1.7.10-0.5.66"
+allprojects {
+ apply plugin: 'java'
+ sourceCompatibility = 1.7
+ targetCompatibility = 1.7
+}
+
+version = "1.7.10-0.5.67"
group= "eu.usrv" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "YAMCore"
minecraft {
- version = "1.7.10-10.13.2.1291"
+ version = "10.13.4.1558-1.7.10"
runDir = "eclipse"
replaceIn "src/main/java/eu/usrv/yamcore/YAMCore.java"
diff --git a/codeformat/copyright.txt b/codeformat/copyright.txt
new file mode 100644
index 0000000..3beacc9
--- /dev/null
+++ b/codeformat/copyright.txt
@@ -0,0 +1,14 @@
+ Copyright 2016 Stefan 'Namikon' Thomanek
+
+ 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 .
\ No newline at end of file
diff --git a/codeformat/eclipse-code-format.xml b/codeformat/eclipse-code-format.xml
new file mode 100644
index 0000000..ca27f30
--- /dev/null
+++ b/codeformat/eclipse-code-format.xml
@@ -0,0 +1,291 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/codeformat/eclipse.importorder b/codeformat/eclipse.importorder
new file mode 100644
index 0000000..115b117
--- /dev/null
+++ b/codeformat/eclipse.importorder
@@ -0,0 +1,10 @@
+#Organize Import Order
+8=eu
+7=
+6=cpw
+5=net
+4=io
+3=org
+2=com
+1=javax
+0=java
diff --git a/src/main/java/eu/usrv/yamcore/YAMCore.java b/src/main/java/eu/usrv/yamcore/YAMCore.java
index 8ca6f70..d7df29e 100644
--- a/src/main/java/eu/usrv/yamcore/YAMCore.java
+++ b/src/main/java/eu/usrv/yamcore/YAMCore.java
@@ -12,7 +12,9 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.event.FMLServerStartingEvent;
import eu.usrv.yamcore.auxiliary.LogHelper;
+import eu.usrv.yamcore.command.YAMCommand;
import eu.usrv.yamcore.events.BucketHandler;
import eu.usrv.yamcore.proxy.CommonProxy;
@@ -24,6 +26,14 @@ import eu.usrv.yamcore.proxy.CommonProxy;
@Mod( modid = "YAMCore", name = "YAMCore", version = "GRADLETOKEN_VERSION" )
public class YAMCore
{
+ private static String tVersion = "GRADLETOKEN_VERSION";
+ private static boolean tDebugFilePresent = false;
+
+ public static boolean isDebug()
+ {
+ return ( tVersion.length() == 19 ) || tDebugFilePresent;
+ }
+
private LogHelper _mLogger = new LogHelper( "Yamcl" );
public LogHelper getLogger()
@@ -35,18 +45,15 @@ public class YAMCore
public static CommonProxy proxy;
@Instance( "YAMCore" )
- public static YAMCore instance = new YAMCore();
-
- private boolean DebugTagFileFound( FMLPreInitializationEvent event )
- {
- File tFile = new File( event.getModConfigurationDirectory() + "/YAMCoreDebug" );
- return tFile.exists();
- }
+ public static YAMCore instance = new YAMCore();
@EventHandler
public void preInit( FMLPreInitializationEvent event )
{
- if( DebugTagFileFound( event ) )
+ File tFile = new File( event.getModConfigurationDirectory() + "/YAMCoreDebug" );
+ tDebugFilePresent = tFile.exists();
+
+ if( isDebug() )
{
_mLogger.info( "YAMCore debug information ENABLED" );
_mLogger.setDebugOutput( true );
@@ -65,4 +72,11 @@ public class YAMCore
{
}
+
+ @EventHandler
+ public void serverLoad( FMLServerStartingEvent pEvent )
+ {
+ if( isDebug() )
+ pEvent.registerServerCommand( new YAMCommand() );
+ }
}
diff --git a/src/main/java/eu/usrv/yamcore/auxiliary/ItemDescriptor.java b/src/main/java/eu/usrv/yamcore/auxiliary/ItemDescriptor.java
index 9c2846c..d3ef825 100644
--- a/src/main/java/eu/usrv/yamcore/auxiliary/ItemDescriptor.java
+++ b/src/main/java/eu/usrv/yamcore/auxiliary/ItemDescriptor.java
@@ -20,9 +20,9 @@ import eu.usrv.yamcore.auxiliary.enums.ItemEqualsCompareMethodEnum;
public class ItemDescriptor
{
private static LogHelper _mLog = YAMCore.instance.getLogger();
- private final String mModID;
- private final String mItemName;
- private final int mMetaID;
+ private final String mModID;
+ private final String mItemName;
+ private final int mMetaID;
public String getModID()
{
@@ -254,24 +254,46 @@ public class ItemDescriptor
* @return An itemstack with attached NBTTag, or null if the tag was invalid, or the itemdescriptor
* couldn't be turned into a valid itemstack
*/
- public ItemStack getItemStackwNBT( int pAmount, String pTag )
+ public ItemStack getItemStackwNBT( int pAmount, NBTTagCompound pTag )
{
ItemStack tRet = null;
+ tRet = getItemStack( pAmount );
+ if( pTag != null )
+ tRet.setTagCompound( pTag );
+
+ return tRet;
+ }
+
+ /**
+ * Get an ItemStack instance with given amount of items and NBT Tag pTag is
+ * optional, and this function will return an ItemStack without NBT if pTag
+ * is empty
+ *
+ * @param pAmount
+ * @param pTag
+ * @return An itemstack with attached NBTTag, or null if the tag was invalid, or the itemdescriptor
+ * couldn't be turned into a valid itemstack
+ */
+ public ItemStack getItemStackwNBT( int pAmount, String pTag )
+ {
+ NBTTagCompound tNBT = null;
+ boolean tDamagedNBT = false;
+
try
{
- tRet = getItemStack( pAmount );
- if( tRet != null && !pTag.isEmpty() )
- {
- NBTTagCompound tNBT = (NBTTagCompound) JsonToNBT.func_150315_a( pTag );
- tRet.setTagCompound( tNBT );
- }
+ if( !pTag.isEmpty() )
+ tNBT = (NBTTagCompound) JsonToNBT.func_150315_a( pTag );
}
catch( Exception e )
{
_mLog.error( String.format( "Found invalid NBT Tag: %s", pTag ) );
- tRet = null;
+ tDamagedNBT = true;
}
- return tRet;
+
+ if( !tDamagedNBT )
+ return getItemStackwNBT( pAmount, tNBT );
+ else
+ return null;
}
/**
diff --git a/src/main/java/eu/usrv/yamcore/auxiliary/PlayerChatHelper.java b/src/main/java/eu/usrv/yamcore/auxiliary/PlayerChatHelper.java
index 1503616..c36c2c3 100644
--- a/src/main/java/eu/usrv/yamcore/auxiliary/PlayerChatHelper.java
+++ b/src/main/java/eu/usrv/yamcore/auxiliary/PlayerChatHelper.java
@@ -2,8 +2,16 @@
package eu.usrv.yamcore.auxiliary;
+import java.util.ArrayList;
+import java.util.Formatter;
+
+import eu.usrv.yamcore.YAMCore;
+import eu.usrv.yamcore.auxiliary.classes.JSONChatText;
+
+import net.minecraft.command.ICommandManager;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
@@ -27,17 +35,49 @@ public class PlayerChatHelper
pCommandSender.addChatMessage( new ChatComponentText( pMessage ) );
}
+ /**
+ * Just plain white text without any format or color
+ * Just pass your args. No need for String.format()
+ *
+ * @param pCommandSender
+ * @param pMessage
+ * @param pArgs
+ */
+ public static void SendPlain( ICommandSender pCommandSender, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendPlain( pCommandSender, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
/**
* Just plain white text without any format or color
*
* @param pPlayer
* @param pMessage
*/
+
public static void SendPlain( EntityPlayer pPlayer, String pMessage )
{
pPlayer.addChatMessage( new ChatComponentText( pMessage ) );
}
+ /**
+ * Just plain white text without any format or color
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+ public static void SendPlain( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendPlain( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
/**
* Meant for notifications that are being send to an admin/op
* Color will be GREEN
@@ -45,11 +85,28 @@ public class PlayerChatHelper
* @param pCommandSender
* @param pMessage
*/
+
public static void SendInfo( ICommandSender pCommandSender, String pMessage )
{
pCommandSender.addChatMessage( new ChatComponentText( EnumChatFormatting.GREEN + pMessage ) );
}
+ /**
+ * Meant for notifications that are being send to an admin/op
+ * Color will be GREEN
+ * Just pass your args. No need for String.format()
+ *
+ * @param pCommandSender
+ * @param pMessage
+ */
+ public static void SendInfo( ICommandSender pCommandSender, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendInfo( pCommandSender, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
/**
* Meant for notifications that are being send to an admin/op
* Color will be RED
@@ -57,6 +114,7 @@ public class PlayerChatHelper
* @param pCommandSender
* @param pMessage
*/
+
public static void SendError( ICommandSender pCommandSender, String pMessage )
{
pCommandSender.addChatMessage( new ChatComponentText( EnumChatFormatting.RED + pMessage ) );
@@ -69,11 +127,44 @@ public class PlayerChatHelper
* @param pCommandSender
* @param pMessage
*/
+
public static void SendWarn( ICommandSender pCommandSender, String pMessage )
{
pCommandSender.addChatMessage( new ChatComponentText( EnumChatFormatting.YELLOW + pMessage ) );
}
+ /**
+ * Meant for notifications that are being send to an admin/op
+ * Color will be RED
+ * Just pass your args. No need for String.format()
+ *
+ * @param pCommandSender
+ * @param pMessage
+ */
+ public static void SendError( ICommandSender pCommandSender, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendError( pCommandSender, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
+ /**
+ * Meant for notifications that are being send to an admin/op
+ * Color will be YELLOW
+ * Just pass your args. No need for String.format()
+ *
+ * @param pCommandSender
+ * @param pMessage
+ */
+ public static void SendWarn( ICommandSender pCommandSender, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendWarn( pCommandSender, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
/**
* Meant for notifications that are being send to an admin/op
* Color will be GREEN
@@ -81,6 +172,7 @@ public class PlayerChatHelper
* @param pPlayer
* @param pMessage
*/
+
public static void SendInfo( EntityPlayer pPlayer, String pMessage )
{
pPlayer.addChatMessage( new ChatComponentText( EnumChatFormatting.GREEN + pMessage ) );
@@ -93,6 +185,7 @@ public class PlayerChatHelper
* @param pPlayer
* @param pMessage
*/
+
public static void SendError( EntityPlayer pPlayer, String pMessage )
{
pPlayer.addChatMessage( new ChatComponentText( EnumChatFormatting.RED + pMessage ) );
@@ -105,11 +198,63 @@ public class PlayerChatHelper
* @param pPlayer
* @param pMessage
*/
+
public static void SendWarn( EntityPlayer pPlayer, String pMessage )
{
pPlayer.addChatMessage( new ChatComponentText( EnumChatFormatting.YELLOW + pMessage ) );
}
+ /**
+ * Meant for notifications that are being send to an admin/op
+ * Color will be GREEN
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+
+ public static void SendInfo( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendInfo( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
+ /**
+ * Meant for notifications that are being send to an admin/op
+ * Color will be RED
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+
+ public static void SendError( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendError( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
+ /**
+ * Meant for notifications that are being send to an admin/op
+ * Color will be YELLOW
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+
+ public static void SendWarn( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendWarn( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
/**
* Meant for ingame notifications that are being send to a player, not an admin/op
* Color will be DARK_GREEN
@@ -117,6 +262,7 @@ public class PlayerChatHelper
* @param pPlayer
* @param pMessage
*/
+
public static void SendNotifyPositive( EntityPlayer pPlayer, String pMessage )
{
pPlayer.addChatMessage( new ChatComponentText( EnumChatFormatting.DARK_GREEN + pMessage ) );
@@ -146,4 +292,195 @@ public class PlayerChatHelper
pPlayer.addChatMessage( new ChatComponentText( EnumChatFormatting.DARK_PURPLE + pMessage ) );
}
+ /**
+ * Meant for ingame notifications that are being send to a player, not an admin/op
+ * Color will be DARK_GREEN
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+ public static void SendNotifyPositive( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendNotifyPositive( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
+ /**
+ * Meant for ingame notifications that are being send to a player, not an admin/op
+ * Color will be AQUA
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+ public static void SendNotifyNormal( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendNotifyNormal( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
+ /**
+ * Meant for ingame notifications that are being send to a player, not an admin/op
+ * Color will be DARK_PURPLE
+ * Just pass your args. No need for String.format()
+ *
+ * @param pPlayer
+ * @param pMessage
+ */
+ public static void SendNotifyWarning( EntityPlayer pPlayer, String pMessage, Object... pArgs )
+ {
+ try( Formatter f = new Formatter() )
+ {
+ SendNotifyWarning( pPlayer, f.format( pMessage, pArgs ).toString() );
+ }
+ }
+
+ /**
+ * Send any combination of links, colors, Tooltips like you would with String.format().
+ * Use the following tokens to fill in the json chat objects:
+ * "This is a {0} sample message that will {1} display elements based on {0} their index value {2}"
+ * {0} refers to the first given object, {1} to the second, etc.
+ * If you want to use { and } in your text, escape them like any other special char: \{
+ *
+ * @param pPlayer The player to send this message to
+ * @param pMessage The message template with tokens
+ * @param pChatObjects
+ * @throws Exception
+ */
+ public static void SendJsonFormatted( EntityPlayer pPlayer, String pMessage, JSONChatText... pChatObjects ) throws Exception
+ {
+ char[] tMessageArray = pMessage.toCharArray();
+ ArrayList tMessageParts = new ArrayList();
+ int tokenLastEnd = 0;
+ int tokenStart = -1;
+ int tokenEnd = -1;
+
+ // Start: 13
+ // End : 15
+ // i : 15
+ // {samplestring {0} blablablehstri aiaa nakna {2} djaj {3}
+ for( int i = 0; i < tMessageArray.length; i++ )
+ {
+ if( tMessageArray[i] == '{' ) // Token found
+ {
+ if( i > 0 ) // Can we check for -1?
+ {
+ if( tMessageArray[i - 1] != '\\' ) // Is this token escaped?
+ {
+ // Token not escaped. Let's see if we already have a start-token
+ if( tokenStart > -1 )
+ throw new Exception( String.format( "Unescaped token-start symbol found at position %d", i ) ); // Crash
+ else
+ tokenStart = i; // we don't have a start-token yet. Store it
+ }
+ // Else: Skip this token. it is escaped and part of the original message
+ }
+ else
+ // We can't check. It's the first char, so it is definitely a token to be checked
+ tokenStart = i;
+ }
+
+ if( tMessageArray[i] == '}' )
+ {
+ if( i > 0 ) // Can we check for -1?
+ {
+ if( tMessageArray[i - 1] != '\\' ) // Is this token escaped?
+ {
+ // Token not escaped. Let's see if we already have a start-token that this close one relates to
+ if( tokenStart > -1 )
+ tokenEnd = i; // we do have a start-token
+ else
+ // We don't have one
+ throw new Exception( String.format( "Unescaped token-start symbol found at position %d", i ) ); // Crash
+ }
+ // Else: Skip this token. it is escaped and part of the original message
+ }
+ else
+ // We can't check. It's the first char. And thus fails, there can't be a start token
+ throw new Exception( String.format( "Unescaped token-start symbol found at position %d", i ) ); // Crash
+ }
+
+ // Both start&end is set. Analyse it
+ if( tokenStart > -1 && tokenEnd > -1 )
+ {
+ // Create an empty json body with the text and add it to the collection
+ tMessageParts.add( extractSubStringToJSON(pMessage, tokenLastEnd, tokenStart) );
+
+ // Extract the Arg-Nr. that is supposed to fill the gap
+ String tArgNr = pMessage.substring( tokenStart + 1, tokenEnd - tokenStart - 1 );
+ if( !IntHelper.tryParse( tArgNr ) )
+ throw new IllegalArgumentException( String.format( "Token-Element at pos %d is not an integer", tokenStart + 1 ) );
+
+ int tArg = Integer.parseInt( tArgNr );
+
+ if( pChatObjects.length < tArg )
+ throw new IndexOutOfBoundsException( String.format( "Token-ID %d requested, but only given %d !", tArg, pChatObjects.length ) );
+
+ // Add the messagepart from given ChatObjects
+ tMessageParts.add( pChatObjects[tArg] );
+
+ // Store last known end-token in var, reset start & end and continue loop
+ tokenLastEnd = tokenEnd + 1;
+ tokenStart = -1;
+ tokenEnd = -1;
+ }
+ }
+
+ // If there is more text after the last close-tag, copy that now
+ if (tokenLastEnd < tMessageArray.length)
+ tMessageParts.add( extractSubStringToJSON(pMessage, tokenLastEnd, tMessageArray.length - tokenLastEnd) );
+
+ // Send assembled message
+ JSONChatText[] tJsonMessages = new JSONChatText[tMessageParts.size()];
+ tJsonMessages = tMessageParts.toArray( tJsonMessages );
+ SendJsonRaw( pPlayer, tJsonMessages );
+ }
+
+ private static JSONChatText extractSubStringToJSON( String pMessage, int pStart, int pLen )
+ {
+ // Exctact the text between the last known end-token and the new start one
+ String tMessagePart = pMessage.substring( pStart, pLen );
+
+ // Get rid of the escape-chars
+ tMessagePart = tMessagePart.replace( "\\{", "{" );
+ tMessagePart = tMessagePart.replace( "\\}", "}" );
+
+ // Create an empty json body with the text and add it to the collection
+ return JSONChatText.simpleMessage( tMessagePart );
+ }
+
+ public static void SendJsonRaw( EntityPlayer pPlayer, JSONChatText... pChatObjects )
+ {
+ MinecraftServer tMCServer = MinecraftServer.getServer();
+ ICommandManager tCmdMngr = tMCServer.getCommandManager();
+
+ if( tMCServer != null )
+ {
+ String tConstructedJSON = "";
+ if( pChatObjects.length > 1 )
+ {
+ boolean tFirst = true;
+ tConstructedJSON = "[";
+ for( JSONChatText pChatObject : pChatObjects )
+ {
+ if( tFirst )
+ tFirst = false;
+ else
+ tConstructedJSON += ", ";
+
+ tConstructedJSON += pChatObject.getConstructed();
+ }
+ tConstructedJSON += "]";
+ }
+ else
+ tConstructedJSON = pChatObjects[0].getConstructed();
+
+ tCmdMngr.executeCommand( tMCServer, "tellraw " + pPlayer.getCommandSenderName() + " " + tConstructedJSON );
+ }
+ }
}
diff --git a/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONChatText.java b/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONChatText.java
new file mode 100644
index 0000000..5714690
--- /dev/null
+++ b/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONChatText.java
@@ -0,0 +1,100 @@
+
+package eu.usrv.yamcore.auxiliary.classes;
+
+
+import java.util.ArrayList;
+
+import net.minecraft.util.EnumChatFormatting;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+
+
+/**
+ * Convenient class to construct Chat-messages that include Hover and/or Click-events
+ */
+public class JSONChatText
+{
+ public boolean Bold;
+ public boolean Italic;
+ public boolean Underlined;
+ public boolean Strikethrough;
+ public boolean Obfuscated;
+ public EnumChatFormatting Color;
+ public JSONHoverEvent HoverEvent;
+ public JSONClickEvent ClickEvent;
+
+ public static JSONChatText simpleMessage( String pMessage )
+ {
+ JSONChatText tJ = new JSONChatText();
+ tJ.Message = pMessage;
+ return tJ;
+ }
+
+ /**
+ * The Message to be sent. This is just plain Text
+ */
+ public String Message;
+
+ /**
+ * Display text from the localized language. e.g. item.stone for the localized name for stone.
+ * This string may also contain one or multiple placeholder (%s). For each placeholder,
+ * you must create an entry in TranslateArray. The first %s is TranslateArray[0], the second [1],...
+ */
+ public String Translate;
+ public ArrayList TranslateArray;
+
+ public JSONChatText()
+ {
+ Color = null;
+ HoverEvent = null;
+ ClickEvent = null;
+ Message = "";
+ Translate = "";
+ TranslateArray = null;
+ }
+
+ public String toString()
+ {
+ return getConstructed();
+ }
+
+ /**
+ * Construct the chat object into an useable JSON string for sending
+ *
+ * @return
+ */
+ public String getConstructed()
+ {
+ JsonObject tResultObject = new JsonObject();
+
+ if( Message != "" )
+ tResultObject.addProperty( "text", Message );
+ if( Translate != "" )
+ tResultObject.addProperty( "translate", Translate );
+
+ if( TranslateArray != null )
+ tResultObject.add( "with", new Gson().toJsonTree( TranslateArray ) );
+
+ if( Bold != false )
+ tResultObject.addProperty( "bold", true );
+ if( Italic != false )
+ tResultObject.addProperty( "italic", true );
+ if( Underlined != false )
+ tResultObject.addProperty( "underlined", true );
+ if( Strikethrough != false )
+ tResultObject.addProperty( "strikethrough", true );
+ if( Obfuscated != false )
+ tResultObject.addProperty( "obfuscated", true );
+ if( Color != null )
+ tResultObject.addProperty( "color", Color.getFriendlyName() );
+
+ if( HoverEvent != null )
+ tResultObject.add( "hoverEvent", HoverEvent.getJson() );
+
+ if( ClickEvent != null )
+ tResultObject.add( "clickEvent", ClickEvent.getJson() );
+
+ return tResultObject.toString();
+ }
+}
diff --git a/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONClickEvent.java b/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONClickEvent.java
new file mode 100644
index 0000000..1ad2961
--- /dev/null
+++ b/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONClickEvent.java
@@ -0,0 +1,73 @@
+
+package eu.usrv.yamcore.auxiliary.classes;
+
+
+import com.google.gson.JsonObject;
+
+
+public class JSONClickEvent
+{
+ public enum EventTypeEnum
+ {
+ RUN_COMMAND,
+ SUGGEST_COMMAND,
+ OPEN_URL,
+ }
+
+ public EventTypeEnum EventType;
+ public String Text;
+
+ /**
+ * Makes the user run any specific command without asking further questions
+ *
+ * @param pCommand
+ * @return
+ */
+ public static JSONClickEvent runCommand( String pCommand )
+ {
+ return new JSONClickEvent( EventTypeEnum.RUN_COMMAND, pCommand );
+ }
+
+ /**
+ * Will suggest a command. This will open chat, place your command but it will wait for the
+ * player to hit return to send it
+ *
+ * @param pCommand
+ * @return
+ */
+ public static JSONClickEvent suggestCommand( String pCommand )
+ {
+ return new JSONClickEvent( EventTypeEnum.SUGGEST_COMMAND, pCommand );
+ }
+
+ /**
+ * Will open the provided URL. use this to create short links
+ * The player has to accept to open the URL via a popup, just like clicking a regular link
+ *
+ * @param pURL The URL to open
+ * @return
+ */
+ public static JSONClickEvent openURL( String pURL )
+ {
+ return new JSONClickEvent( EventTypeEnum.OPEN_URL, pURL );
+ }
+
+ private JSONClickEvent( EventTypeEnum pEventType, String pText )
+ {
+ EventType = pEventType;
+ Text = pText;
+ }
+
+ /**
+ * Return the constructed JSON Element. Use it in your own chat-handler, or pass it to JSONChatText class
+ *
+ * @return
+ */
+ public JsonObject getJson()
+ {
+ JsonObject tJO = new JsonObject();
+ tJO.addProperty( "action", EventType.toString().toLowerCase() );
+ tJO.addProperty( "value", Text );
+ return tJO;
+ }
+}
diff --git a/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONHoverEvent.java b/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONHoverEvent.java
new file mode 100644
index 0000000..9c87d35
--- /dev/null
+++ b/src/main/java/eu/usrv/yamcore/auxiliary/classes/JSONHoverEvent.java
@@ -0,0 +1,91 @@
+
+package eu.usrv.yamcore.auxiliary.classes;
+
+
+import net.minecraft.nbt.NBTTagCompound;
+
+import com.google.gson.JsonObject;
+
+import eu.usrv.yamcore.auxiliary.ItemDescriptor;
+
+
+public class JSONHoverEvent
+{
+ public enum EventTypeEnum
+ {
+ SHOW_TEXT,
+ SHOW_ITEM,
+ SHOW_ACHIEVEMENT,
+ SHOW_ENTITY
+ }
+
+ public EventTypeEnum EventType;
+ public String Text;
+
+ /**
+ * Generate a Hover-Event that will display regular text.
+ *
+ * @param pMessage The message to be displayed as tooltip
+ * @return
+ */
+ public static JSONHoverEvent SimpleText( String pMessage )
+ {
+ return new JSONHoverEvent( EventTypeEnum.SHOW_TEXT, pMessage, null );
+ }
+
+ /**
+ * Generate a Hover-Event that will display an Item tooltip.
+ * This will also show any lore this item contains
+ *
+ * @param pItem The itemdescriptor of that item
+ * @return
+ */
+ public static JSONHoverEvent Item( ItemDescriptor pItem )
+ {
+ return new JSONHoverEvent( EventTypeEnum.SHOW_ITEM, "", pItem );
+ }
+
+ /**
+ * Generate a Hover-Event that will show an achievement. Take the full name from your
+ * own mod or check /stats/uuid.json for the achievement you want to display
+ *
+ * @param pStatIdentifier
+ * @return
+ */
+ public static JSONHoverEvent Achievement( String pStatIdentifier )
+ {
+ return new JSONHoverEvent( EventTypeEnum.SHOW_ACHIEVEMENT, pStatIdentifier, null );
+ }
+
+ // public static JSONHoverEvent Entity( String pMessage )
+ // {
+ // return new JSONHoverEvent( EventTypeEnum.SHOW_ENTITY, pMessage, null );
+ // }
+
+ private JSONHoverEvent( EventTypeEnum pEventType, String pText, ItemDescriptor pDescriptor )
+ {
+ EventType = pEventType;
+ if( EventType == EventTypeEnum.SHOW_ITEM )
+ {
+ NBTTagCompound tItem = new NBTTagCompound();
+ pDescriptor.getItemStack( 1 ).writeToNBT( tItem );
+ Text = tItem.toString();
+ }
+ else
+ Text = pText;
+
+ }
+
+ /**
+ * Return the constructed JSON Element. Use it in your own chat-handler, or pass it to JSONChatText class
+ *
+ * @return
+ */
+ public JsonObject getJson()
+ {
+ JsonObject tJO = new JsonObject();
+ tJO.addProperty( "action", EventType.toString().toLowerCase() );
+ tJO.addProperty( "value", Text );
+ return tJO;
+ }
+}
diff --git a/src/main/java/eu/usrv/yamcore/command/YAMCommand.java b/src/main/java/eu/usrv/yamcore/command/YAMCommand.java
new file mode 100644
index 0000000..5a607c2
--- /dev/null
+++ b/src/main/java/eu/usrv/yamcore/command/YAMCommand.java
@@ -0,0 +1,200 @@
+
+package eu.usrv.yamcore.command;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.minecraft.command.ICommand;
+import net.minecraft.command.ICommandManager;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.util.ChunkCoordinates;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.IChatComponent;
+import net.minecraft.world.World;
+import eu.usrv.yamcore.YAMCore;
+import eu.usrv.yamcore.auxiliary.IntHelper;
+import eu.usrv.yamcore.auxiliary.ItemDescriptor;
+import eu.usrv.yamcore.auxiliary.PlayerChatHelper;
+import eu.usrv.yamcore.auxiliary.classes.JSONChatText;
+import eu.usrv.yamcore.auxiliary.classes.JSONClickEvent;
+import eu.usrv.yamcore.auxiliary.classes.JSONHoverEvent;
+
+
+public class YAMCommand implements ICommand, ICommandSender
+{
+ private List aliases;
+
+ public YAMCommand()
+ {
+ this.aliases = new ArrayList();
+ }
+
+ @Override
+ public int compareTo( Object arg0 )
+ {
+ return 0;
+ }
+
+ @Override
+ public String getCommandName()
+ {
+ return "yamcore";
+ }
+
+ @Override
+ public String getCommandUsage( ICommandSender p_71518_1_ )
+ {
+ return "derp";
+ }
+
+ @Override
+ public List getCommandAliases()
+ {
+
+ return this.aliases;
+ }
+
+ @Override
+ public void processCommand( ICommandSender pCmdSender, String[] pArgs )
+ {
+ int tFunc = 1;
+ if( IntHelper.tryParse( pArgs[0] ) )
+ tFunc = Integer.parseInt( pArgs[0] );
+
+ JSONChatText jct = new JSONChatText();
+ JSONChatText jct2 = new JSONChatText();
+ JSONChatText jct3 = new JSONChatText();
+ JSONChatText jct4 = new JSONChatText();
+
+ jct.Message = "#1";
+ jct2.Message = "#2";
+ jct2.Color = EnumChatFormatting.GOLD;
+ jct3.Message = "#3";
+ jct3.HoverEvent = JSONHoverEvent.SimpleText( "Hover #3" );
+ jct4.Message = "#4";
+ jct4.HoverEvent = JSONHoverEvent.SimpleText( "Hover #4" );
+ jct4.Color = EnumChatFormatting.AQUA;
+ jct4.Italic = true;
+ jct4.ClickEvent = JSONClickEvent.suggestCommand( "Command #4" );
+
+ if( tFunc == 1 )
+ {
+ jct.Message = "Simple message";
+ }
+ else if( tFunc == 2 )
+ {
+ jct.Message = "Message with tooltip;";
+ jct.HoverEvent = JSONHoverEvent.SimpleText( "A simple text" );
+ }
+ else if( tFunc == 3 )
+ {
+ jct.Message = "[Stone]";
+ jct.HoverEvent = JSONHoverEvent.Item( ItemDescriptor.fromString( "minecraft:stone" ) );
+ }
+ else if( tFunc == 4 )
+ {
+ jct.Message = "Suggest command";
+ jct.ClickEvent = JSONClickEvent.suggestCommand( "/suicide" );
+ }
+ else if( tFunc == 5 )
+ {
+ jct.Message = "Seed";
+ jct.ClickEvent = JSONClickEvent.runCommand( "/suicide" );
+ }
+ else if( tFunc == 6 )
+ {
+ jct.Message = "Woo, golden!";
+ jct.Color = EnumChatFormatting.GOLD;
+ }
+ else if( tFunc == 7 )
+ {
+ PlayerChatHelper.SendJsonRaw( (EntityPlayer) pCmdSender, jct, jct2, jct3, jct4 );
+ return;
+ }
+ else if( tFunc == 8 )
+ {
+ try
+ {
+ PlayerChatHelper.SendJsonFormatted( (EntityPlayer) pCmdSender, "Json1: [%s], Json2: [%s], Json3: [%s], Json4: [%s]", jct, jct2, jct3, jct4 );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+ else if( tFunc == 9 )
+ {
+ }
+ else if( tFunc == 10 )
+ {
+ }
+
+ MinecraftServer minecraftserver = MinecraftServer.getServer();
+
+ if( minecraftserver != null )
+ {
+ ICommandManager icommandmanager = minecraftserver.getCommandManager();
+ String tJson = jct.getConstructed();
+ YAMCore.instance.getLogger().info( tJson );
+ icommandmanager.executeCommand( this, "tellraw " + pCmdSender.getCommandSenderName() + " " + jct.getConstructed() );
+ }
+ }
+
+ @Override
+ public boolean canCommandSenderUseCommand( ICommandSender pCommandSender )
+ {
+ return true;
+ }
+
+ @Override
+ public List addTabCompletionOptions( ICommandSender p_71516_1_,
+ String[] p_71516_2_ )
+ {
+ return null;
+ }
+
+ @Override
+ public boolean isUsernameIndex( String[] p_82358_1_, int p_82358_2_ )
+ {
+ return false;
+ }
+
+ @Override
+ public String getCommandSenderName()
+ {
+ return "YAMCoreDebug";
+ }
+
+ @Override
+ public IChatComponent func_145748_c_()
+ {
+ return null;
+ }
+
+ @Override
+ public void addChatMessage( IChatComponent p_145747_1_ )
+ {
+ }
+
+ @Override
+ public boolean canCommandSenderUseCommand( int p_70003_1_, String p_70003_2_ )
+ {
+ return true;
+ }
+
+ @Override
+ public ChunkCoordinates getPlayerCoordinates()
+ {
+ return null;
+ }
+
+ @Override
+ public World getEntityWorld()
+ {
+ return null;
+ }
+
+}