Add qp to chat service
This commit is contained in:
@@ -33,7 +33,7 @@ import okhttp3.Response;
|
|||||||
|
|
||||||
public class ChatClient
|
public class ChatClient
|
||||||
{
|
{
|
||||||
public boolean submit(String username, String boss, int kc) throws IOException
|
public boolean submitKc(String username, String boss, int kc) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
@@ -54,7 +54,7 @@ public class ChatClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int get(String username, String boss) throws IOException
|
public int getKc(String username, String boss) throws IOException
|
||||||
{
|
{
|
||||||
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
.addPathSegment("chat")
|
.addPathSegment("chat")
|
||||||
@@ -76,4 +76,46 @@ public class ChatClient
|
|||||||
return Integer.parseInt(response.body().string());
|
return Integer.parseInt(response.body().string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean submitQp(String username, int qp) throws IOException
|
||||||
|
{
|
||||||
|
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
|
.addPathSegment("chat")
|
||||||
|
.addPathSegment("qp")
|
||||||
|
.addQueryParameter("name", username)
|
||||||
|
.addQueryParameter("qp", Integer.toString(qp))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.post(RequestBody.create(null, new byte[0]))
|
||||||
|
.url(url)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
|
{
|
||||||
|
return response.isSuccessful();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQp(String username) throws IOException
|
||||||
|
{
|
||||||
|
HttpUrl url = RuneLiteAPI.getApiBase().newBuilder()
|
||||||
|
.addPathSegment("chat")
|
||||||
|
.addPathSegment("qp")
|
||||||
|
.addQueryParameter("name", username)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(url)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (Response response = RuneLiteAPI.CLIENT.newCall(request).execute())
|
||||||
|
{
|
||||||
|
if (!response.isSuccessful())
|
||||||
|
{
|
||||||
|
throw new IOException("Unable to look up quest points!");
|
||||||
|
}
|
||||||
|
return Integer.parseInt(response.body().string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class ChatController
|
|||||||
private ChatService chatService;
|
private ChatService chatService;
|
||||||
|
|
||||||
@PostMapping("/kc")
|
@PostMapping("/kc")
|
||||||
public void submit(@RequestParam String name, @RequestParam String boss, @RequestParam int kc)
|
public void submitKc(@RequestParam String name, @RequestParam String boss, @RequestParam int kc)
|
||||||
{
|
{
|
||||||
if (kc <= 0)
|
if (kc <= 0)
|
||||||
{
|
{
|
||||||
@@ -60,7 +60,7 @@ public class ChatController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/kc")
|
@GetMapping("/kc")
|
||||||
public int get(@RequestParam String name, @RequestParam String boss)
|
public int getKc(@RequestParam String name, @RequestParam String boss)
|
||||||
{
|
{
|
||||||
Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss));
|
Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss));
|
||||||
if (kc == null)
|
if (kc == null)
|
||||||
@@ -78,4 +78,26 @@ public class ChatController
|
|||||||
}
|
}
|
||||||
return kc;
|
return kc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/qp")
|
||||||
|
public void submitQp(@RequestParam String name, @RequestParam int qp)
|
||||||
|
{
|
||||||
|
if (qp < 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chatService.setQp(name, qp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/qp")
|
||||||
|
public int getKc(@RequestParam String name)
|
||||||
|
{
|
||||||
|
Integer kc = chatService.getQp(name);
|
||||||
|
if (kc == null)
|
||||||
|
{
|
||||||
|
throw new NotFoundException();
|
||||||
|
}
|
||||||
|
return kc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,4 +60,22 @@ public class ChatService
|
|||||||
jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc));
|
jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getQp(String name)
|
||||||
|
{
|
||||||
|
String value;
|
||||||
|
try (Jedis jedis = jedisPool.getResource())
|
||||||
|
{
|
||||||
|
value = jedis.get("qp." + name);
|
||||||
|
}
|
||||||
|
return value == null ? null : Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQp(String name, int qp)
|
||||||
|
{
|
||||||
|
try (Jedis jedis = jedisPool.getResource())
|
||||||
|
{
|
||||||
|
jedis.setex("qp." + name, (int) EXPIRE.getSeconds(), Integer.toString(qp));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
chatClient.submit(playerName, boss, kc);
|
chatClient.submitKc(playerName, boss, kc);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -325,7 +325,7 @@ public class ChatCommandsPlugin extends Plugin
|
|||||||
final int kc;
|
final int kc;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
kc = chatClient.get(player, search);
|
kc = chatClient.getKc(player, search);
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user