Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/ch/njol/skript/ModernSkriptBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.skriptlang.skript.util.Registry;

import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -75,6 +76,11 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
return unmodifiableSkript.registry(registryClass, putIfAbsent);
}

@Override
public Collection<Registry<?>> registries() {
return unmodifiableSkript.registries();
}

@Override
public SyntaxRegistry syntaxRegistry() {
return unmodifiableSkript.syntaxRegistry();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ch/njol/skript/SkriptAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -154,6 +155,11 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
return addon.registry(registryClass, putIfAbsent);
}

@Override
public Collection<Registry<?>> registries() {
return addon.registries();
}

@Override
public SyntaxRegistry syntaxRegistry() {
return addon.syntaxRegistry();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/skriptlang/skript/SkriptImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
Expand Down Expand Up @@ -65,6 +66,11 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
return (R) registries.computeIfAbsent(registryClass, key -> putIfAbsent.get());
}

@Override
public Collection<Registry<?>> registries() {
return List.copyOf(registries.values());
}

/*
* SkriptAddon Management
*/
Expand Down Expand Up @@ -181,6 +187,11 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
return skript.registry(registryClass, putIfAbsent);
}

@Override
public Collection<Registry<?>> registries() {
return skript.registries();
}

@Override
public SyntaxRegistry syntaxRegistry() {
return registry(SyntaxRegistry.class);
Expand Down Expand Up @@ -256,6 +267,11 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
return unmodifiableAddon.registry(registryClass, putIfAbsent);
}

@Override
public Collection<Registry<?>> registries() {
return unmodifiableAddon.registries();
}

@Override
public SyntaxRegistry syntaxRegistry() {
return unmodifiableAddon.syntaxRegistry();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/skriptlang/skript/addon/SkriptAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.skriptlang.skript.util.ViewProvider;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;

Expand Down Expand Up @@ -72,6 +73,11 @@ public interface SkriptAddon extends ViewProvider<SkriptAddon> {
*/
<R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> putIfAbsent);

/**
* @return A collection of all registries accessible through this addon.
*/
Collection<Registry<?>> registries();

/**
* @return A syntax registry for this addon's syntax.
*/
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/org/skriptlang/skript/addon/SkriptAddonImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.skriptlang.skript.util.Registry;
import org.skriptlang.skript.util.ViewProvider;

import java.util.Collection;
import java.util.function.Supplier;

class SkriptAddonImpl {
Expand Down Expand Up @@ -47,9 +48,9 @@ public boolean hasRegistry(Class<? extends Registry<?>> registryClass) {
@Override
public <R extends Registry<?>> R registry(Class<R> registryClass) {
R registry = addon.registry(registryClass);
if (registry instanceof ViewProvider) {
if (registry instanceof ViewProvider<?> viewProvider) {
//noinspection unchecked
registry = ((ViewProvider<R>) registry).unmodifiableView();
registry = (R) viewProvider.unmodifiableView();
}
return registry;
}
Expand All @@ -59,6 +60,18 @@ public <R extends Registry<?>> R registry(Class<R> registryClass, Supplier<R> pu
throw new UnsupportedOperationException("Cannot store registries on an unmodifiable addon");
}

@Override
public Collection<Registry<?>> registries() {
return addon.registries().stream()
.map(registry -> {
if (registry instanceof ViewProvider<?> viewProvider) {
return (Registry<?>) viewProvider.unmodifiableView();
}
return registry;
})
.toList();
}

@Override
public SyntaxRegistry syntaxRegistry() {
return addon.syntaxRegistry().unmodifiableView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void testRegistry() {
assertEquals(registry, unmodifiable.registry(MockRegistry.class));
assertTrue(addon.hasRegistry(MockRegistry.class));
assertTrue(unmodifiable.hasRegistry(MockRegistry.class));

// access all registries
assertTrue(addon.registries().contains(registry));
assertTrue(unmodifiable.registries().contains(registry));
}

@Test
Expand All @@ -91,6 +95,10 @@ public void testSyntaxRegistry() {
assertNotNull(unmodifiable.syntaxRegistry());
// unmodifiable's syntax registry should be unmodifiable (different)
assertNotEquals(addon.syntaxRegistry(), unmodifiable.syntaxRegistry());
assertNotEquals(addon.syntaxRegistry(), unmodifiable.registries().stream()
.filter(registry -> registry instanceof SyntaxRegistry)
.findFirst()
.orElseThrow());
}

@Test
Expand Down
Loading