runescape-client: refactor for 162

This commit is contained in:
Adam
2018-02-01 09:55:01 -05:00
parent e0364f791a
commit 0325150267
6 changed files with 0 additions and 419 deletions

View File

@@ -1,32 +0,0 @@
/*
* Copyright (c) 2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.api.events;
import lombok.Data;
@Data
public class ClanMembersChanged
{
}

View File

@@ -1,103 +0,0 @@
/*
* Copyright (c) 2018, UniquePassive <https://github.com/uniquepassive>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.mixins;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSClanMember;
import net.runelite.rs.api.RSClient;
@Mixin(RSClient.class)
public abstract class PlayerIsClanMemberMixin implements RSClient
{
@Shadow("clanChatCount")
private static int clanChatCount;
@Inject
private static int oldClanChatCount;
@Inject
private static Cache<String, Boolean> cachedClanMembers;
@Inject
@Override
public boolean isClanMember(String name)
{
if (name == null)
{
return false;
}
if (cachedClanMembers == null)
{
cachedClanMembers = CacheBuilder
.newBuilder()
.expireAfterAccess(1, TimeUnit.MINUTES)
.build();
}
if (oldClanChatCount != clanChatCount)
{
cachedClanMembers.invalidateAll();
oldClanChatCount = clanChatCount;
}
Boolean isClanMember = cachedClanMembers.getIfPresent(name);
if (isClanMember == null)
{
isClanMember = false;
final RSClanMember[] clanMembers = getClanMembers();
if (clanMembers == null)
{
return false;
}
for (RSClanMember clanMember : clanMembers)
{
if (clanMember == null)
{
continue;
}
if (name.equals(clanMember.getUsername()))
{
isClanMember = true;
break;
}
}
cachedClanMembers.put(name, isClanMember);
}
return isClanMember;
}
}

View File

@@ -1,98 +0,0 @@
/*
* Copyright (c) 2018, UniquePassive <https://github.com/uniquepassive>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.mixins;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSClient;
@Mixin(RSClient.class)
public abstract class PlayerIsFriendMixin implements RSClient
{
@Shadow("friendCount")
private static int friendCount;
@Inject
private static int oldFriendCount;
@Inject
private static Cache<String, Boolean> cachedFriends;
@Inject
private static Cache<String, Boolean> cachedOnlineFriends;
@Copy("isFriended")
private static boolean rs$isFriended(String name, boolean mustBeLoggedIn)
{
throw new IllegalStateException();
}
@Replace("isFriended")
private static boolean rl$isFriended(String name, boolean mustBeLoggedIn)
{
if (name == null)
{
return false;
}
if (cachedFriends == null)
{
cachedFriends = CacheBuilder
.newBuilder()
.expireAfterAccess(1, TimeUnit.MINUTES)
.build();
cachedOnlineFriends = CacheBuilder
.newBuilder()
.expireAfterAccess(1, TimeUnit.MINUTES)
.build();
}
if (oldFriendCount != friendCount)
{
cachedFriends.invalidateAll();
cachedOnlineFriends.invalidateAll();
oldFriendCount = friendCount;
}
Cache<String, Boolean> cache = mustBeLoggedIn ? cachedOnlineFriends : cachedFriends;
Boolean isFriended = cache.getIfPresent(name);
if (isFriended == null)
{
isFriended = rs$isFriended(name, mustBeLoggedIn);
cache.put(name, isFriended);
}
return isFriended;
}
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (c) 2018, UniquePassive <https://github.com/uniquepassive>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.mixins;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.util.concurrent.TimeUnit;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSClient;
@Mixin(RSClient.class)
public abstract class PlayerIsIgnoredMixin implements RSClient
{
@Shadow("ignoreCount")
private static int ignoreCount;
@Inject
private static int oldIgnoreCount;
@Inject
private static Cache<String, Boolean> cachedIgnored;
@Copy("isIgnored")
private static boolean rs$isIgnored(String name)
{
throw new IllegalStateException();
}
@Replace("isIgnored")
private static boolean rl$isIgnored(String name)
{
if (name == null)
{
return false;
}
if (cachedIgnored == null)
{
cachedIgnored = CacheBuilder
.newBuilder()
.expireAfterAccess(1, TimeUnit.MINUTES)
.build();
}
if (oldIgnoreCount != ignoreCount)
{
cachedIgnored.invalidateAll();
oldIgnoreCount = ignoreCount;
}
Boolean isIgnored = cachedIgnored.getIfPresent(name);
if (isIgnored == null)
{
isIgnored = rs$isIgnored(name);
cachedIgnored.put(name, isIgnored);
}
return isIgnored;
}
}

View File

@@ -1,63 +0,0 @@
/*
* Copyright (c) 2018, UniquePassive <https://github.com/uniquepassive>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.mixins;
import com.google.common.cache.Cache;
import net.runelite.api.mixins.FieldHook;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSFriend;
@Mixin(RSFriend.class)
public abstract class RSFriendMixin implements RSFriend
{
@Shadow("cachedFriends")
private static Cache<String, Boolean> cachedFriends;
@Shadow("cachedOnlineFriends")
private static Cache<String, Boolean> cachedOnlineFriends;
@FieldHook("previousName")
@Inject
public void previousNameChanged(int idx)
{
if (cachedFriends != null)
{
cachedFriends.invalidate(getPreviousName());
cachedOnlineFriends.invalidate(getPreviousName());
}
}
@FieldHook("world")
@Inject
public void worldChanged(int idx)
{
if (cachedFriends != null)
{
cachedOnlineFriends.invalidate(getName());
}
}
}

View File

@@ -1,36 +0,0 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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.rs.api;
import net.runelite.mapping.Import;
public interface RSIgnore
{
@Import("name")
String getName();
@Import("previousName")
String getPreviousName();
}