Preliminary work on help desk integration with Customer Support server.

Updated DisguiseSheep with values from craftbukkit.jar
This commit is contained in:
Jonathan Williams 2014-08-22 13:32:22 -05:00
parent 83b3e49151
commit 13b90e1142
11 changed files with 516 additions and 5 deletions

View File

@ -14,7 +14,7 @@ public class DisguiseSheep extends DisguiseAnimal
public boolean isSheared() public boolean isSheared()
{ {
return (DataWatcher.getByte(16) & 0x10) != 0; return (DataWatcher.getByte(16) & 16) != 0;
} }
public void setSheared(boolean sheared) public void setSheared(boolean sheared)
@ -22,14 +22,14 @@ public class DisguiseSheep extends DisguiseAnimal
byte b0 = DataWatcher.getByte(16); byte b0 = DataWatcher.getByte(16);
if (sheared) if (sheared)
DataWatcher.watch(16, Byte.valueOf((byte)(b0 | 0x10))); DataWatcher.watch(16, Byte.valueOf((byte)(b0 | 16)));
else else
DataWatcher.watch(16, Byte.valueOf((byte)(b0 & 0xFFFFFFEF))); DataWatcher.watch(16, Byte.valueOf((byte)(b0 & -17)));
} }
public int getColor() public int getColor()
{ {
return DataWatcher.getByte(16) & 0xF; return DataWatcher.getByte(16) & 15;
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -37,6 +37,6 @@ public class DisguiseSheep extends DisguiseAnimal
{ {
byte b0 = DataWatcher.getByte(16); byte b0 = DataWatcher.getByte(16);
DataWatcher.watch(16, Byte.valueOf((byte)(b0 & 0xF0 | color.getWoolData() & 0xF))); DataWatcher.watch(16, Byte.valueOf((byte)(b0 & 240 | color.getWoolData() & 15)));
} }
} }

View File

@ -8,5 +8,9 @@
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/jedis-2.4.2.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/jedis-2.4.2.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/> <classpathentry combineaccessrules="false" kind="src" path="/Mineplex.ServerData"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/> <classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpcore-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -0,0 +1,16 @@
package mineplex.staffServer.helpdesk;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.staffServer.helpdesk.repository.ApiGetCall;
public class HelpDeskManager extends MiniPlugin
{
public HelpDeskManager(JavaPlugin plugin)
{
super("Help Desk", plugin);
new ApiGetCall("https://mineplex.jitbit.com/helpdesk/api", "Tickets");
}
}

View File

@ -0,0 +1,29 @@
package mineplex.staffServer.helpdesk;
public class ListTicketToken
{
public int IssueID;
public int Priority;
public int StatusID;
public String IssueDate;
public String Subject;
public String Status;
public boolean UpdatedByUser;
public boolean UpdatedByPerformer;
public int CategoryID;
public String UserName;
public String Technician;
public String FirstName;
public String LastName;
public String DueDate;
public String TechFirstName;
public String TechLastName;
public String LastUpdated;
public boolean UpdatedForTechView;
public int UserID;
public int CompanyID;
public String CompanyName;
public int SectionID;
public int AssignedToUserID;
public String Category;
}

View File

@ -0,0 +1,22 @@
package mineplex.staffServer.helpdesk;
public class TicketToken
{
public int TicketID;
public int UserID;
public int AssignedToUserID;
public String IssueDate;
public String Subject;
public String Body;
public int Priority;
public int StatusID;
public int CategoryID;
public String DueDate;
public String ResolvedDate;
public String StartDate;
public int TimeSpentInSeconds;
public boolean IsCurrentUserTechInThisCategory;
public boolean IsCurrentCategoryForTechsOnly;
public boolean SubmittedByCurrentUser;
public boolean IsInKb;
}

View File

@ -0,0 +1,19 @@
package mineplex.staffServer.helpdesk.repository;
import org.apache.http.client.methods.HttpDelete;
public class ApiDeleteCall extends HelpDeskApiCallBase
{
public ApiDeleteCall(String apiUrl, int domainId, String category)
{
super(apiUrl, domainId, category);
}
public void Execute()
{
HttpDelete request = new HttpDelete(ApiUrl + DomainId + Category);
System.out.println(request.getURI().toString());
System.out.println(execute(request));
}
}

View File

@ -0,0 +1,128 @@
package mineplex.staffServer.helpdesk.repository;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
public class ApiGetCall
{
protected String ApiUrl = "https://mineplex.jitbit.com/helpdesk/api";
protected String SecretKey = "?sharedSecret={WzG49S3L6spqt4}";
private String _action;
public ApiGetCall(String apiUrl, String action)
{
ApiUrl = apiUrl;
_action = action;
}
protected String execute()
{
HttpGet request = new HttpGet(ApiUrl + SecretKey + "&" + _action);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", 80, PlainSocketFactory.getSocketFactory()));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
connectionManager.setMaxTotal(200);
connectionManager.setDefaultMaxPerRoute(20);
HttpClient httpClient = new DefaultHttpClient(connectionManager);
InputStream in = null;
String response = "";
try
{
HttpResponse httpResponse = httpClient.execute(request);
if (httpResponse != null)
{
in = httpResponse.getEntity().getContent();
response = convertStreamToString(in);
}
}
catch (Exception ex)
{
System.out.println("HelpDeskApiCall Error:\n" + ex.getMessage());
for (StackTraceElement trace : ex.getStackTrace())
{
System.out.println(trace);
}
}
finally
{
httpClient.getConnectionManager().shutdown();
if (in != null)
{
try
{
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
return response;
}
protected String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try
{
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}
public void Execute()
{
}
/*
public <T> T Execute(Type returnType)
{
HttpGet request = new HttpGet(ApiUrl + DomainId + Category + _action);
String response = execute(request);
System.out.println(response);
return new Gson().fromJson(response, returnType);
}
*/
}

View File

@ -0,0 +1,79 @@
package mineplex.staffServer.helpdesk.repository;
import java.lang.reflect.Type;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import com.google.gson.Gson;
public class ApiPostCall extends HelpDeskApiCallBase
{
private String _action;
public ApiPostCall(String apiUrl, int domainId, String category, String action)
{
super(apiUrl, domainId, category);
_action = action;
}
public void Execute(Object argument)
{
Gson gson = new Gson();
HttpPost request = new HttpPost(ApiUrl + DomainId + Category + _action);
System.out.println(request.getURI().toString());
try
{
StringEntity params = new StringEntity(gson.toJson(argument));
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
request.setEntity(params);
}
catch (Exception exception)
{
System.out.println("Error executing ApiPostCall(Object): \n" + exception.getMessage());
for (StackTraceElement trace : exception.getStackTrace())
{
System.out.println(trace);
}
}
System.out.println(execute(request));
}
public <T> T Execute(Class<T> returnClass)
{
return Execute(returnClass, (Object)null);
}
public <T> T Execute(Type returnType, Object argument)
{
Gson gson = new Gson();
HttpPost request = new HttpPost(ApiUrl + DomainId + Category + _action);
System.out.println(request.getURI().toString());
try
{
StringEntity params = new StringEntity(gson.toJson(argument));
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
request.setEntity(params);
}
catch (Exception exception)
{
System.out.println("Error executing ApiPostCall(Type, Object): \n" + exception.getMessage());
for (StackTraceElement trace : exception.getStackTrace())
{
System.out.println(trace);
}
}
String response = execute(request);
System.out.println(response);
return new Gson().fromJson(response, returnType);
}
}

View File

@ -0,0 +1,80 @@
package mineplex.staffServer.helpdesk.repository;
import java.lang.reflect.Type;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import com.google.gson.Gson;
public class ApiPutCall extends HelpDeskApiCallBase
{
private String _action;
public ApiPutCall(String apiUrl, int domainId, String category, String action)
{
super(apiUrl, domainId, category);
_action = action;
}
public void Execute(Object argument)
{
Gson gson = new Gson();
HttpPut request = new HttpPut(ApiUrl + DomainId + Category + _action);
System.out.println(request.getURI().toString());
try
{
StringEntity params = new StringEntity(gson.toJson(argument));
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
request.setEntity(params);
}
catch (Exception exception)
{
System.out.println("Error executing ApiPutCall(Object): \n" + exception.getMessage());
for (StackTraceElement trace : exception.getStackTrace())
{
System.out.println(trace);
}
}
System.out.println(execute(request));
}
public <T> T Execute(Class<T> returnClass)
{
return Execute(returnClass, (Object)null);
}
public <T> T Execute(Type returnType, Object argument)
{
Gson gson = new Gson();
HttpPut request = new HttpPut(ApiUrl + DomainId + Category + _action);
System.out.println(request.getURI().toString());
try
{
StringEntity params = new StringEntity(gson.toJson(argument));
params.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
request.setEntity(params);
}
catch (Exception exception)
{
System.out.println("Error executing ApiPutCall(Type, Object): \n" + exception.getMessage());
for (StackTraceElement trace : exception.getStackTrace())
{
System.out.println(trace);
}
}
String response = execute(request);
System.out.println(response);
return new Gson().fromJson(response, returnType);
}
}

View File

@ -0,0 +1,128 @@
package mineplex.staffServer.helpdesk.repository;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
public abstract class HelpDeskApiCallBase
{
protected String ApiUrl = "https://mineplex.jitbit.com/helpdesk/api";
protected int DomainId = 962728;
protected String Category = "";
public HelpDeskApiCallBase(String apiUrl, int domainId, String category)
{
ApiUrl = apiUrl;
DomainId = domainId;
Category = category;
}
protected String execute(HttpRequestBase request)
{
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", 80, PlainSocketFactory.getSocketFactory()));
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
connectionManager.setMaxTotal(200);
connectionManager.setDefaultMaxPerRoute(20);
HttpClient httpClient = new DefaultHttpClient(connectionManager);
InputStream in = null;
String response = "";
try
{
HttpResponse httpResponse = httpClient.execute(request);
if (httpResponse != null)
{
in = httpResponse.getEntity().getContent();
response = convertStreamToString(in);
}
}
catch (Exception ex)
{
System.out.println("HelpDeskApiCall Error:\n" + ex.getMessage());
for (StackTraceElement trace : ex.getStackTrace())
{
System.out.println(trace);
}
}
finally
{
httpClient.getConnectionManager().shutdown();
if (in != null)
{
try
{
in.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
return response;
}
protected String getServerTime()
{
Calendar calendar = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return dateFormat.format(calendar.getTime());
}
protected String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try
{
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
is.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return sb.toString();
}
}

View File

@ -0,0 +1,6 @@
package mineplex.staffServer.helpdesk.repository;
public class HelpDeskRepository
{
}