From 863522afa91ee772dbb2605775c5a9aced5c4707 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 May 2018 10:27:03 -0400 Subject: [PATCH 1/6] runelite-api: expose Friend --- .../java/net/runelite/api/ChatPlayer.java | 29 +++++++++++ .../main/java/net/runelite/api/Friend.java | 32 ++++++++++++ .../main/java/net/runelite/api/Nameable.java | 29 +++++++++++ .../runelite/mixins/RSClanMemberMixin.java | 2 +- .../net/runelite/mixins/RSFriendMixin.java | 49 +++++++++++++++++++ .../net/runelite/rs/api/RSChatPlayer.java | 3 +- .../java/net/runelite/rs/api/RSFriend.java | 4 +- .../main/java/net/runelite/rs/api/RSName.java | 2 +- .../java/net/runelite/rs/api/RSNameable.java | 8 ++- 9 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/ChatPlayer.java create mode 100644 runelite-api/src/main/java/net/runelite/api/Friend.java create mode 100644 runelite-api/src/main/java/net/runelite/api/Nameable.java create mode 100644 runelite-mixins/src/main/java/net/runelite/mixins/RSFriendMixin.java diff --git a/runelite-api/src/main/java/net/runelite/api/ChatPlayer.java b/runelite-api/src/main/java/net/runelite/api/ChatPlayer.java new file mode 100644 index 0000000000..b4c07bb170 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/ChatPlayer.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018, Adam + * 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; + +public interface ChatPlayer extends Nameable +{ +} diff --git a/runelite-api/src/main/java/net/runelite/api/Friend.java b/runelite-api/src/main/java/net/runelite/api/Friend.java new file mode 100644 index 0000000000..9320c9135d --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/Friend.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018, Adam + * 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; + +public interface Friend extends ChatPlayer +{ + String getName(); + + String getPrevName(); +} diff --git a/runelite-api/src/main/java/net/runelite/api/Nameable.java b/runelite-api/src/main/java/net/runelite/api/Nameable.java new file mode 100644 index 0000000000..dded3671b3 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/Nameable.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018, Adam + * 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; + +public interface Nameable extends Comparable +{ +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSClanMemberMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSClanMemberMixin.java index 873c324e70..a35a267bce 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSClanMemberMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSClanMemberMixin.java @@ -36,7 +36,7 @@ public abstract class RSClanMemberMixin implements RSClanMember @Inject public String getUsername() { - return getName().getName(); + return getRsName().getName(); } @Override diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSFriendMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSFriendMixin.java new file mode 100644 index 0000000000..db47e095a1 --- /dev/null +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSFriendMixin.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018, Adam + * 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 net.runelite.api.mixins.Inject; +import net.runelite.api.mixins.Mixin; +import net.runelite.rs.api.RSFriend; +import net.runelite.rs.api.RSName; + +@Mixin(RSFriend.class) +public abstract class RSFriendMixin implements RSFriend +{ + @Override + @Inject + public String getName() + { + return getRsName().getName(); + } + + @Override + @Inject + public String getPrevName() + { + RSName prevName = getRsPrevName(); + return prevName == null ? null : prevName.getName(); + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSChatPlayer.java b/runescape-api/src/main/java/net/runelite/rs/api/RSChatPlayer.java index 4d70862b10..37853eea14 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSChatPlayer.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSChatPlayer.java @@ -24,9 +24,10 @@ */ package net.runelite.rs.api; +import net.runelite.api.ChatPlayer; import net.runelite.mapping.Import; -public interface RSChatPlayer extends RSNameable +public interface RSChatPlayer extends ChatPlayer, RSNameable { @Import("world") int getWorld(); diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSFriend.java b/runescape-api/src/main/java/net/runelite/rs/api/RSFriend.java index ee30442c02..0948c5fc85 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSFriend.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSFriend.java @@ -24,6 +24,8 @@ */ package net.runelite.rs.api; -public interface RSFriend extends RSChatPlayer +import net.runelite.api.Friend; + +public interface RSFriend extends Friend, RSChatPlayer { } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSName.java b/runescape-api/src/main/java/net/runelite/rs/api/RSName.java index bbd4f9abfd..4b2c83abfe 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSName.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSName.java @@ -26,7 +26,7 @@ package net.runelite.rs.api; import net.runelite.mapping.Import; -public interface RSName +public interface RSName extends Comparable { @Import("name") String getName(); diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSNameable.java b/runescape-api/src/main/java/net/runelite/rs/api/RSNameable.java index 50c92b2226..6b7feef4ab 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSNameable.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSNameable.java @@ -24,10 +24,14 @@ */ package net.runelite.rs.api; +import net.runelite.api.Nameable; import net.runelite.mapping.Import; -public interface RSNameable +public interface RSNameable extends Nameable, Comparable { @Import("name") - RSName getName(); + RSName getRsName(); + + @Import("prevName") + RSName getRsPrevName(); } From 8106d99f83147522df088f03da4343aab84b1f0c Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 May 2018 10:27:20 -0400 Subject: [PATCH 2/6] runelite-api: add nameable name change event --- .../api/events/NameableNameChanged.java | 37 ++++++++++++++++ .../net/runelite/mixins/RSNameableMixin.java | 44 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/NameableNameChanged.java create mode 100644 runelite-mixins/src/main/java/net/runelite/mixins/RSNameableMixin.java diff --git a/runelite-api/src/main/java/net/runelite/api/events/NameableNameChanged.java b/runelite-api/src/main/java/net/runelite/api/events/NameableNameChanged.java new file mode 100644 index 0000000000..33fefa8904 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/NameableNameChanged.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, Adam + * 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.Value; +import net.runelite.api.Nameable; + +/** + * Event called when a nameable name changes + */ +@Value +public class NameableNameChanged +{ + private final Nameable nameable; +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSNameableMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSNameableMixin.java new file mode 100644 index 0000000000..5032129952 --- /dev/null +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSNameableMixin.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, Adam + * 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 net.runelite.api.events.NameableNameChanged; +import net.runelite.api.mixins.FieldHook; +import net.runelite.api.mixins.Inject; +import net.runelite.api.mixins.Mixin; +import static net.runelite.client.callback.Hooks.eventBus; +import net.runelite.rs.api.RSNameable; + +@Mixin(RSNameable.class) +public abstract class RSNameableMixin implements RSNameable +{ + @FieldHook("prevName") + @Inject + public void onPrevNameChanged(int idx) + { + NameableNameChanged nameableNameChanged = new NameableNameChanged(this); + eventBus.post(nameableNameChanged); + } +} From 4037ba9c009880eb3ac6ffe0744ed8dd586c2c0f Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 May 2018 12:20:15 -0400 Subject: [PATCH 3/6] injector: add method hooks --- .../net/runelite/api/mixins/FieldHook.java | 2 +- .../net/runelite/api/mixins/MethodHook.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 runelite-mixins/src/main/java/net/runelite/api/mixins/MethodHook.java diff --git a/runelite-mixins/src/main/java/net/runelite/api/mixins/FieldHook.java b/runelite-mixins/src/main/java/net/runelite/api/mixins/FieldHook.java index 77efdc2703..af4a814895 100644 --- a/runelite-mixins/src/main/java/net/runelite/api/mixins/FieldHook.java +++ b/runelite-mixins/src/main/java/net/runelite/api/mixins/FieldHook.java @@ -31,7 +31,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.FIELD}) +@Target(ElementType.METHOD) @Documented public @interface FieldHook { diff --git a/runelite-mixins/src/main/java/net/runelite/api/mixins/MethodHook.java b/runelite-mixins/src/main/java/net/runelite/api/mixins/MethodHook.java new file mode 100644 index 0000000000..5caeca8336 --- /dev/null +++ b/runelite-mixins/src/main/java/net/runelite/api/mixins/MethodHook.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, Adam + * 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.mixins; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +@Documented +public @interface MethodHook +{ + String value(); + + boolean end() default false; +} From e74dfcf13dca74c04ec3e3fcc30109bb7e2ff649 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 May 2018 12:21:06 -0400 Subject: [PATCH 4/6] Add removed friend event --- .../java/net/runelite/api/FriendManager.java | 29 ++++++++++++ .../runelite/api/events/RemovedFriend.java | 36 +++++++++++++++ .../runelite/mixins/RSFriendManagerMixin.java | 45 +++++++++++++++++++ .../net/runelite/rs/api/RSFriendManager.java | 3 +- 4 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/FriendManager.java create mode 100644 runelite-api/src/main/java/net/runelite/api/events/RemovedFriend.java create mode 100644 runelite-mixins/src/main/java/net/runelite/mixins/RSFriendManagerMixin.java diff --git a/runelite-api/src/main/java/net/runelite/api/FriendManager.java b/runelite-api/src/main/java/net/runelite/api/FriendManager.java new file mode 100644 index 0000000000..49345043a7 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/FriendManager.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2018, Adam + * 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; + +public interface FriendManager +{ +} diff --git a/runelite-api/src/main/java/net/runelite/api/events/RemovedFriend.java b/runelite-api/src/main/java/net/runelite/api/events/RemovedFriend.java new file mode 100644 index 0000000000..612bb3be87 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/RemovedFriend.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Adam + * 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.Value; + +/** + * Called when a request to remove a friend is sent to the server + */ +@Value +public class RemovedFriend +{ + private final String name; +} diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSFriendManagerMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSFriendManagerMixin.java new file mode 100644 index 0000000000..9e568096be --- /dev/null +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSFriendManagerMixin.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018, Adam + * 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 net.runelite.api.events.RemovedFriend; +import net.runelite.api.mixins.Inject; +import net.runelite.api.mixins.MethodHook; +import net.runelite.api.mixins.Mixin; +import static net.runelite.client.callback.Hooks.eventBus; +import net.runelite.rs.api.RSFriend; +import net.runelite.rs.api.RSFriendManager; + +@Mixin(RSFriendManager.class) +public abstract class RSFriendManagerMixin implements RSFriend +{ + @MethodHook("removeFriend") + @Inject + public void rl$removeFriend(String friendName) + { + RemovedFriend removedFriend = new RemovedFriend(friendName); + eventBus.post(removedFriend); + } +} diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSFriendManager.java b/runescape-api/src/main/java/net/runelite/rs/api/RSFriendManager.java index 99de577be1..2538d02d10 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSFriendManager.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSFriendManager.java @@ -24,9 +24,10 @@ */ package net.runelite.rs.api; +import net.runelite.api.FriendManager; import net.runelite.mapping.Import; -public interface RSFriendManager +public interface RSFriendManager extends FriendManager { @Import("isFriended") boolean isFriended(RSName var1, boolean var2); From e60d9ec2c1eae8ea095852aaa9397f9e8e30b719 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 7 May 2018 12:55:40 -0400 Subject: [PATCH 5/6] chatbox input manager: add support for character limit --- .../net/runelite/client/game/ChatboxInputManager.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/game/ChatboxInputManager.java b/runelite-client/src/main/java/net/runelite/client/game/ChatboxInputManager.java index 8b84748be2..bb907e1cbf 100644 --- a/runelite-client/src/main/java/net/runelite/client/game/ChatboxInputManager.java +++ b/runelite-client/src/main/java/net/runelite/client/game/ChatboxInputManager.java @@ -39,10 +39,12 @@ import net.runelite.client.callback.ClientThread; @Slf4j public class ChatboxInputManager { + private static final int NO_LIMIT = Integer.MAX_VALUE; private final Client client; private final ClientThread clientThread; private Consumer done; + private int characterLimit = NO_LIMIT; @Inject public ChatboxInputManager(Client client, ClientThread clientThread, EventBus eventBus) @@ -60,8 +62,14 @@ public class ChatboxInputManager * @param done Callback when the text box has been exited, called with "" on esc */ public void openInputWindow(String text, String defaul, Consumer done) + { + openInputWindow(text, defaul, NO_LIMIT, done); + } + + public void openInputWindow(String text, String defaul, int characterLimit, Consumer done) { this.done = done; + this.characterLimit = characterLimit; clientThread.invokeLater(() -> client.runScript( ScriptID.RUNELITE_CHATBOX_INPUT_INIT, text, @@ -97,7 +105,7 @@ public class ChatboxInputManager } default: // If we wanted to do numbers only, we could add a limit here - if (typedKey >= 32) + if (typedKey >= 32 && (str.length() < characterLimit)) { str += Character.toString((char) typedKey); } From d2bf775e3bcd8e5f499d0d18c814bde5177fe1d6 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 May 2018 12:21:35 -0400 Subject: [PATCH 6/6] Add friend notes plugin --- .../friendnotes/FriendNoteOverlay.java | 71 ++++++ .../friendnotes/FriendNotesPlugin.java | 219 ++++++++++++++++++ .../plugins/friendnotes/HoveredFriend.java | 36 +++ 3 files changed, 326 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNoteOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/HoveredFriend.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNoteOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNoteOverlay.java new file mode 100644 index 0000000000..eaa8a35c4d --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNoteOverlay.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018, Rheon + * Copyright (c) 2018, Adam + * 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 HOLDER 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.client.plugins.friendnotes; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.tooltip.Tooltip; +import net.runelite.client.ui.overlay.tooltip.TooltipManager; + +class FriendNoteOverlay extends Overlay +{ + private final Client client; + private final FriendNotesPlugin plugin; + private final TooltipManager tooltipManager; + + @Inject + private FriendNoteOverlay(Client client, FriendNotesPlugin plugin, TooltipManager tooltipManager) + { + this.client = client; + this.plugin = plugin; + this.tooltipManager = tooltipManager; + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (client.isMenuOpen()) + { + return null; + } + + final HoveredFriend hovered = plugin.getHoveredFriend(); + if (hovered == null) + { + return null; + } + + final String content = hovered.getNote(); + tooltipManager.add(new Tooltip(content)); + + return null; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java new file mode 100644 index 0000000000..2bdc768f8c --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2018, Rheon + * Copyright (c) 2018, Adam + * 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 HOLDER 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.client.plugins.friendnotes; + +import com.google.common.base.Strings; +import com.google.common.eventbus.Subscribe; +import java.util.Arrays; +import javax.inject.Inject; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import net.runelite.api.Client; +import net.runelite.api.Friend; +import net.runelite.api.MenuAction; +import net.runelite.api.MenuEntry; +import net.runelite.api.Nameable; +import net.runelite.api.events.MenuEntryAdded; +import net.runelite.api.events.MenuOptionClicked; +import net.runelite.api.events.NameableNameChanged; +import net.runelite.api.events.RemovedFriend; +import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.game.ChatboxInputManager; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.util.Text; + +@Slf4j +@PluginDescriptor(name = "Friend Notes") +public class FriendNotesPlugin extends Plugin +{ + private static final String CONFIG_GROUP = "friendNotes"; + + private static final int CHARACTER_LIMIT = 128; + + private static final String ADD_NOTE = "Add Note"; + private static final String EDIT_NOTE = "Edit Note"; + private static final String NOTE_PROMPT_FORMAT = "%s's Notes
" + + "(Limit %s Characters)"; + + @Inject + private Client client; + + @Inject + private ConfigManager configManager; + + @Inject + private FriendNoteOverlay overlay; + + @Inject + private ChatboxInputManager chatboxInputManager; + + @Getter + private HoveredFriend hoveredFriend = null; + + @Override + public Overlay getOverlay() + { + return overlay; + } + + private void setFriendNote(String friend, String note) + { + if (!Strings.isNullOrEmpty(note)) + { + configManager.setConfiguration(CONFIG_GROUP, "note_" + friend, note); + } + else + { + configManager.unsetConfiguration(CONFIG_GROUP, "note_" + friend); + } + } + + private String getFriendNote(String friend) + { + return configManager.getConfiguration(CONFIG_GROUP, "note_" + friend); + } + + private void checkNameChange(String currentDisplayName, String previousDisplayName) + { + String currentNote = getFriendNote(currentDisplayName); + if (currentNote == null) + { + String prevNote = getFriendNote(previousDisplayName); + if (prevNote != null) + { + setFriendNote(previousDisplayName, null); + setFriendNote(currentDisplayName, prevNote); + log.debug("Updating friends username: '{}' '{}'", currentDisplayName, previousDisplayName); + } + } + } + + private void setCurrentFriend(String target) + { + hoveredFriend = null; + + if (!Strings.isNullOrEmpty(target)) + { + target = Text.removeTags(target); + String targetNote = getFriendNote(target); + if (targetNote != null) + { + hoveredFriend = new HoveredFriend(target, targetNote); + } + } + } + + @Subscribe + public void onMenuEntryAdded(MenuEntryAdded event) + { + final int groupId = WidgetInfo.TO_GROUP(event.getActionParam1()); + + if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId()) + { + setCurrentFriend(event.getTarget()); + + final MenuEntry addNote = new MenuEntry(); + addNote.setOption(hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE); + addNote.setType(MenuAction.RUNELITE.getId()); + addNote.setTarget(event.getTarget()); + addNote.setParam0(event.getActionParam0()); + addNote.setParam1(event.getActionParam1()); + + MenuEntry[] menuEntries = client.getMenuEntries(); + menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); + + menuEntries[menuEntries.length - 1] = addNote; + + client.setMenuEntries(menuEntries); + } + else if (hoveredFriend != null) + { + hoveredFriend = null; + } + } + + @Subscribe + public void onMenuOptionClicked(MenuOptionClicked event) + { + if (WidgetInfo.TO_GROUP(event.getWidgetId()) == WidgetInfo.FRIENDS_LIST.getGroupId()) + { + if (Strings.isNullOrEmpty(event.getMenuTarget())) + { + return; + } + + final String sanitizedTarget = Text.removeTags(event.getMenuTarget()); + + if (event.getMenuOption().equals(ADD_NOTE) || event.getMenuOption().equals(EDIT_NOTE)) + { + event.consume(); + + String note = getFriendNote(sanitizedTarget); + + chatboxInputManager.openInputWindow(String.format(NOTE_PROMPT_FORMAT, sanitizedTarget, + CHARACTER_LIMIT), Strings.nullToEmpty(note), CHARACTER_LIMIT, (content) -> + { + if (content == null) + { + return; + } + + content = Text.removeTags(content).trim(); + log.debug("Set note for '{}': '{}'", sanitizedTarget, content); + setFriendNote(sanitizedTarget, content); + }); + } + } + + } + + @Subscribe + public void onNameableNameChange(NameableNameChanged nameableNameChanged) + { + Nameable nameable = nameableNameChanged.getNameable(); + + if (nameable instanceof Friend) + { + Friend friend = (Friend) nameable; + String name = friend.getName(); + String prevName = friend.getPrevName(); + checkNameChange(name, prevName); + } + } + + @Subscribe + public void onRemoveFriend(RemovedFriend removedFriend) + { + String name = removedFriend.getName(); + log.debug("Removed friend: '{}'", name); + setFriendNote(name, null); + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/HoveredFriend.java b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/HoveredFriend.java new file mode 100644 index 0000000000..9a049ec58e --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/HoveredFriend.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018, Rheon + * 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 HOLDER 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.client.plugins.friendnotes; + +import lombok.Value; + +@Value +class HoveredFriend +{ + private String friendName; + private String note; +}