diff --git a/http-api/src/main/java/net/runelite/http/api/kc/KillCountClient.java b/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java similarity index 95% rename from http-api/src/main/java/net/runelite/http/api/kc/KillCountClient.java rename to http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java index 5cc3cfca42..75ae64b932 100644 --- a/http-api/src/main/java/net/runelite/http/api/kc/KillCountClient.java +++ b/http-api/src/main/java/net/runelite/http/api/chat/ChatClient.java @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.http.api.kc; +package net.runelite.http.api.chat; import java.io.IOException; import net.runelite.http.api.RuneLiteAPI; @@ -31,11 +31,12 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -public class KillCountClient +public class ChatClient { public boolean submit(String username, String boss, int kc) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") .addPathSegment("kc") .addQueryParameter("name", username) .addQueryParameter("boss", boss) @@ -56,6 +57,7 @@ public class KillCountClient public int get(String username, String boss) throws IOException { HttpUrl url = RuneLiteAPI.getApiBase().newBuilder() + .addPathSegment("chat") .addPathSegment("kc") .addQueryParameter("name", username) .addQueryParameter("boss", boss) diff --git a/http-service/src/main/java/net/runelite/http/service/kc/KillCountController.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java similarity index 82% rename from http-service/src/main/java/net/runelite/http/service/kc/KillCountController.java rename to http-service/src/main/java/net/runelite/http/service/chat/ChatController.java index bd843de347..ed608bf7d0 100644 --- a/http-service/src/main/java/net/runelite/http/service/kc/KillCountController.java +++ b/http-service/src/main/java/net/runelite/http/service/chat/ChatController.java @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.http.service.kc; +package net.runelite.http.service.chat; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; @@ -36,18 +36,18 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController -@RequestMapping("/kc") -public class KillCountController +@RequestMapping("/chat") +public class ChatController { - private final Cache cache = CacheBuilder.newBuilder() + private final Cache killCountCache = CacheBuilder.newBuilder() .expireAfterWrite(2, TimeUnit.MINUTES) .maximumSize(128L) .build(); @Autowired - private KillCountService killCountService; + private ChatService chatService; - @PostMapping + @PostMapping("/kc") public void submit(@RequestParam String name, @RequestParam String boss, @RequestParam int kc) { if (kc <= 0) @@ -55,20 +55,20 @@ public class KillCountController return; } - killCountService.setKc(name, boss, kc); - cache.put(new KillCountKey(name, boss), kc); + chatService.setKc(name, boss, kc); + killCountCache.put(new KillCountKey(name, boss), kc); } - @GetMapping + @GetMapping("/kc") public int get(@RequestParam String name, @RequestParam String boss) { - Integer kc = cache.getIfPresent(new KillCountKey(name, boss)); + Integer kc = killCountCache.getIfPresent(new KillCountKey(name, boss)); if (kc == null) { - kc = killCountService.getKc(name, boss); + kc = chatService.getKc(name, boss); if (kc != null) { - cache.put(new KillCountKey(name, boss), kc); + killCountCache.put(new KillCountKey(name, boss), kc); } } diff --git a/http-service/src/main/java/net/runelite/http/service/kc/KillCountService.java b/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java similarity index 88% rename from http-service/src/main/java/net/runelite/http/service/kc/KillCountService.java rename to http-service/src/main/java/net/runelite/http/service/chat/ChatService.java index 045a5c548a..7824218e61 100644 --- a/http-service/src/main/java/net/runelite/http/service/kc/KillCountService.java +++ b/http-service/src/main/java/net/runelite/http/service/chat/ChatService.java @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.http.service.kc; +package net.runelite.http.service.chat; import java.time.Duration; import org.springframework.beans.factory.annotation.Autowired; @@ -31,14 +31,14 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; @Service -public class KillCountService +public class ChatService { - private static final Duration KC_EXPIRE = Duration.ofMinutes(2); + private static final Duration EXPIRE = Duration.ofMinutes(2); private final JedisPool jedisPool; @Autowired - public KillCountService(JedisPool jedisPool) + public ChatService(JedisPool jedisPool) { this.jedisPool = jedisPool; } @@ -57,7 +57,7 @@ public class KillCountService { try (Jedis jedis = jedisPool.getResource()) { - jedis.setex("kc." + name + "." + boss, (int) KC_EXPIRE.getSeconds(), Integer.toString(kc)); + jedis.setex("kc." + name + "." + boss, (int) EXPIRE.getSeconds(), Integer.toString(kc)); } } } diff --git a/http-service/src/main/java/net/runelite/http/service/kc/KillCountKey.java b/http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java similarity index 97% rename from http-service/src/main/java/net/runelite/http/service/kc/KillCountKey.java rename to http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java index 976a228ba2..07ca775dad 100644 --- a/http-service/src/main/java/net/runelite/http/service/kc/KillCountKey.java +++ b/http-service/src/main/java/net/runelite/http/service/chat/KillCountKey.java @@ -22,7 +22,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package net.runelite.http.service.kc; +package net.runelite.http.service.chat; import lombok.Value; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 513007c774..9cc2eeab88 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -61,6 +61,7 @@ import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.util.StackFormatter; +import net.runelite.http.api.chat.ChatClient; import net.runelite.http.api.hiscore.HiscoreClient; import net.runelite.http.api.hiscore.HiscoreEndpoint; import net.runelite.http.api.hiscore.HiscoreResult; @@ -68,7 +69,6 @@ import net.runelite.http.api.hiscore.HiscoreSkill; import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; import net.runelite.http.api.hiscore.Skill; import net.runelite.http.api.item.ItemPrice; -import net.runelite.http.api.kc.KillCountClient; @PluginDescriptor( name = "Chat Commands", @@ -91,7 +91,7 @@ public class ChatCommandsPlugin extends Plugin private static final String CMB_COMMAND_STRING = "!cmb"; private final HiscoreClient hiscoreClient = new HiscoreClient(); - private final KillCountClient killCountClient = new KillCountClient(); + private final ChatClient chatClient = new ChatClient(); private boolean logKills; private HiscoreEndpoint hiscoreEndpoint; // hiscore endpoint for current player @@ -285,7 +285,7 @@ public class ChatCommandsPlugin extends Plugin { try { - killCountClient.submit(playerName, boss, kc); + chatClient.submit(playerName, boss, kc); } catch (Exception ex) { @@ -325,7 +325,7 @@ public class ChatCommandsPlugin extends Plugin final int kc; try { - kc = killCountClient.get(player, search); + kc = chatClient.get(player, search); } catch (IOException ex) {