Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat/minestom
Browse files Browse the repository at this point in the history
# Conflicts:
#	settings.gradle
  • Loading branch information
LooFifteen committed Jan 24, 2025
2 parents 9dd08da + 1bf0deb commit 6b9cc1e
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;

import java.time.Duration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.lucko.luckperms.common.messaging;

import com.google.gson.JsonObject;
import me.lucko.luckperms.common.actionlog.ActionJsonSerializer;
import me.lucko.luckperms.common.actionlog.LoggedAction;
import me.lucko.luckperms.common.messaging.message.ActionLogMessageImpl;
import me.lucko.luckperms.common.messaging.message.CustomMessageImpl;
import me.lucko.luckperms.common.messaging.message.UpdateMessageImpl;
import me.lucko.luckperms.common.messaging.message.UserUpdateMessageImpl;
import me.lucko.luckperms.common.util.gson.JObject;
import net.luckperms.api.actionlog.Action;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MessageImplTest {

@Test
public void testUpdateMessage() {
UUID uuid = UUID.fromString("22f9e168-8815-44f1-83c8-b642ebfbcef2");

// encode
UpdateMessageImpl msg = new UpdateMessageImpl(uuid);
assertEquals("{\"id\":\"22f9e168-8815-44f1-83c8-b642ebfbcef2\",\"type\":\"update\"}", msg.asEncodedString());

// decode
msg = UpdateMessageImpl.decode(new JsonObject(), uuid);
assertEquals(uuid, msg.getId());
}

@Test
public void testUserUpdateMessage() {
UUID uuid = UUID.fromString("22f9e168-8815-44f1-83c8-b642ebfbcef2");
UUID userUuid = UUID.fromString("4c087cd9-f444-4c52-8438-e03e57ba2e8e");

// encode
UserUpdateMessageImpl msg = new UserUpdateMessageImpl(uuid, userUuid);
// {"id":"22f9e168-8815-44f1-83c8-b642ebfbcef2","type":"userupdate","content":{"userUuid":"4c087cd9-f444-4c52-8438-e03e57ba2e8e"}}
assertEquals("{\"id\":\"22f9e168-8815-44f1-83c8-b642ebfbcef2\",\"type\":\"userupdate\",\"content\":{\"userUuid\":\"4c087cd9-f444-4c52-8438-e03e57ba2e8e\"}}", msg.asEncodedString());

// decode
msg = UserUpdateMessageImpl.decode(new JObject().add("userUuid", userUuid.toString()).toJson(), uuid);
assertEquals(uuid, msg.getId());
assertEquals(userUuid, msg.getUserUniqueId());
}

@Test
public void testActionLogMessage() {
UUID uuid = UUID.fromString("22f9e168-8815-44f1-83c8-b642ebfbcef2");
LoggedAction action = LoggedAction.build()
.source(UUID.fromString("d3500320-564c-436e-87a0-026d7f2c92f6"))
.sourceName("Test")
.targetType(Action.Target.Type.GROUP)
.targetName("test")
.description("test")
.timestamp(Instant.ofEpochSecond(1))
.build();

// encode
ActionLogMessageImpl msg = new ActionLogMessageImpl(uuid, action);
// {"id":"22f9e168-8815-44f1-83c8-b642ebfbcef2","type":"log","content":{"timestamp":1,"source":{"uniqueId":"d3500320-564c-436e-87a0-026d7f2c92f6","name":"Test"},"target":{"type":"GROUP","name":"test"},"description":"test"}}
assertEquals("{\"id\":\"22f9e168-8815-44f1-83c8-b642ebfbcef2\",\"type\":\"log\",\"content\":{\"timestamp\":1,\"source\":{\"uniqueId\":\"d3500320-564c-436e-87a0-026d7f2c92f6\",\"name\":\"Test\"},\"target\":{\"type\":\"GROUP\",\"name\":\"test\"},\"description\":\"test\"}}", msg.asEncodedString());

// decode
msg = ActionLogMessageImpl.decode(ActionJsonSerializer.serialize(action), uuid);
assertEquals(uuid, msg.getId());
assertEquals(action, msg.getAction());
}

@Test
public void testCustomMessage() {
UUID uuid = UUID.fromString("22f9e168-8815-44f1-83c8-b642ebfbcef2");
String channelId = "test";
String payload = "test";

// encode
CustomMessageImpl msg = new CustomMessageImpl(uuid, channelId, payload);
// {"id":"22f9e168-8815-44f1-83c8-b642ebfbcef2","type":"custom","content":{"channelId":"test","payload":"test"}}
assertEquals("{\"id\":\"22f9e168-8815-44f1-83c8-b642ebfbcef2\",\"type\":\"custom\",\"content\":{\"channelId\":\"test\",\"payload\":\"test\"}}", msg.asEncodedString());

// decode
msg = CustomMessageImpl.decode(new JObject().add("channelId", channelId).add("payload", payload).toJson(), uuid);
assertEquals(uuid, msg.getId());
assertEquals(channelId, msg.getChannelId());
assertEquals(payload, msg.getPayload());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.lucko.luckperms.common.sender;

import me.lucko.luckperms.common.locale.Message;
import net.kyori.adventure.text.Component;
import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AbstractSenderTest {

@Test
public void testSplitNewlines() {
Component component = Message.joinNewline(
Component.text("hello"),
Component.text("world"),
Message.joinNewline(
Component.text("foo"),
Component.text("bar")
)
);

List<Component> components = ImmutableList.copyOf(AbstractSender.splitNewlines(component));
assertEquals(4, components.size());
assertEquals(Component.text("hello"), components.get(0));
assertEquals(Component.text("world"), components.get(1));
assertEquals(Component.text("foo"), components.get(2));
assertEquals(Component.text("bar"), components.get(3));
}

}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ include (
// 'sponge',
// 'sponge:loader',
// 'sponge:sponge-service',
// 'sponge:sponge-service-api8',
// 'sponge:sponge-service-proxy',
// 'velocity',
// 'standalone',
// 'standalone:loader',
Expand Down
8 changes: 6 additions & 2 deletions sponge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ plugins {
alias(libs.plugins.shadow)
}

sourceCompatibility = 17
targetCompatibility = 21

repositories {
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
}

dependencies {
implementation project(':common')
implementation project(':sponge:sponge-service')
implementation project(':sponge:sponge-service-api8')
implementation project(':sponge:sponge-service-proxy')
compileOnly project(':common:loader-utils')

compileOnly('org.spongepowered:spongeapi:8.0.0') {
compileOnly('org.spongepowered:spongeapi:12.0.0') {
exclude(module: 'configurate-core')
exclude(module: 'configurate-hocon')
exclude(module: 'configurate-gson')
exclude(module: 'configurate-yaml')
}
compileOnly 'com.google.guava:guava:33.3.1-jre'
}

processResources {
Expand Down
5 changes: 4 additions & 1 deletion sponge/loader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ plugins {
alias(libs.plugins.shadow)
}

sourceCompatibility = 17
targetCompatibility = 21

repositories {
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
}

dependencies {
compileOnly 'org.spongepowered:spongeapi:8.0.0'
compileOnly 'org.spongepowered:spongeapi:12.0.0'

implementation project(':api')
implementation project(':common:loader-utils')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": [
{
"id": "spongeapi",
"version": "8.0.0"
"version": "12.0.0"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ repositories {
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
}

sourceCompatibility = 17
targetCompatibility = 21

dependencies {
implementation project(':common')
implementation project(':sponge:sponge-service')

compileOnly('org.spongepowered:spongeapi:8.0.0') {
compileOnly('org.spongepowered:spongeapi:12.0.0') {
exclude(module: 'configurate-core')
exclude(module: 'configurate-hocon')
exclude(module: 'configurate-gson')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.sponge.service.proxy.api8;
package me.lucko.luckperms.sponge.service.proxy;

import me.lucko.luckperms.common.context.ImmutableContextSetImpl;
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.sponge.service.proxy.api8;
package me.lucko.luckperms.sponge.service.proxy;

import me.lucko.luckperms.common.util.ImmutableCollectors;
import me.lucko.luckperms.sponge.service.model.LPPermissionDescription;
Expand Down Expand Up @@ -130,6 +130,6 @@ public int hashCode() {

@Override
public String toString() {
return "luckperms.api8.PermissionDescriptionProxy(handle=" + this.handle + ")";
return "luckperms.PermissionDescriptionProxy(handle=" + this.handle + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.sponge.service.proxy.api8;
package me.lucko.luckperms.sponge.service.proxy;

import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.util.ImmutableCollectors;
Expand Down Expand Up @@ -169,6 +169,6 @@ public int hashCode() {

@Override
public String toString() {
return "luckperms.api8.PermissionServiceProxy(handle=" + this.handle + ")";
return "luckperms.PermissionServiceProxy(handle=" + this.handle + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* SOFTWARE.
*/

package me.lucko.luckperms.sponge.service.proxy.api8;
package me.lucko.luckperms.sponge.service.proxy;

import me.lucko.luckperms.common.util.ImmutableCollectors;
import me.lucko.luckperms.sponge.service.model.LPProxiedServiceObject;
Expand All @@ -43,7 +43,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;

@SuppressWarnings("unchecked")
public final class SubjectCollectionProxy implements SubjectCollection, LPProxiedServiceObject {
private final LPSubjectCollection handle;

Expand Down Expand Up @@ -86,7 +85,7 @@ public SubjectCollectionProxy(LPSubjectCollection handle) {
return this.handle.getLoadedSubjects().stream().map(LPSubject::sponge).collect(ImmutableCollectors.toSet());
}

@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public @NonNull CompletableFuture<Set<String>> allIdentifiers() {
return (CompletableFuture) this.handle.getAllIdentifiers();
Expand All @@ -102,13 +101,13 @@ public SubjectCollectionProxy(LPSubjectCollection handle) {
return this.handle.getService().getReferenceFactory().obtain(identifier(), subjectIdentifier);
}

@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public @NonNull CompletableFuture<Map<SubjectReference, Boolean>> allWithPermission(@NonNull String s) {
return (CompletableFuture) this.handle.getAllWithPermission(s);
}

@SuppressWarnings("rawtypes")
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public @NonNull CompletableFuture<Map<SubjectReference, Boolean>> allWithPermission(@NonNull String s, @NonNull Cause cause) {
return (CompletableFuture) this.handle.getAllWithPermission(this.handle.getService().getContextsForCause(cause), s);
Expand Down Expand Up @@ -154,7 +153,7 @@ public int hashCode() {

@Override
public String toString() {
return "luckperms.api8.SubjectCollectionProxy(handle=" + this.handle + ")";
return "luckperms.SubjectCollectionProxy(handle=" + this.handle + ")";
}

}
Loading

0 comments on commit 6b9cc1e

Please sign in to comment.