Skip to content

Commit 0af88ce

Browse files
committed
feat: reloadmappings Command.
1 parent 3332528 commit 0af88ce

File tree

7 files changed

+145
-1
lines changed

7 files changed

+145
-1
lines changed

core/src/main/java/org/geysermc/geyser/command/CommandRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.geysermc.geyser.command.defaults.PingCommand;
5555
import org.geysermc.geyser.command.defaults.QuickActionsCommand;
5656
import org.geysermc.geyser.command.defaults.ReloadCommand;
57+
import org.geysermc.geyser.command.defaults.ReloadMappingsCommand;
5758
import org.geysermc.geyser.command.defaults.SettingsCommand;
5859
import org.geysermc.geyser.command.defaults.StatisticsCommand;
5960
import org.geysermc.geyser.command.defaults.StopCommand;
@@ -159,6 +160,7 @@ public CommandRegistry(GeyserImpl geyser, CommandManager<GeyserCommandSource> cl
159160

160161
registerBuiltInCommand(new ListCommand(geyser, "list", "geyser.commands.list.desc", "geyser.command.list"));
161162
registerBuiltInCommand(new ReloadCommand(geyser, "reload", "geyser.commands.reload.desc", "geyser.command.reload"));
163+
registerBuiltInCommand(new ReloadMappingsCommand(geyser, "reloadmappings", "geyser.commands.reloadmappings.desc", "geyser.command.reloadmappings"));
162164
registerBuiltInCommand(new OffhandCommand("offhand", "geyser.commands.offhand.desc", "geyser.command.offhand"));
163165
registerBuiltInCommand(new DumpCommand(geyser, "dump", "geyser.commands.dump.desc", "geyser.command.dump"));
164166
registerBuiltInCommand(new VersionCommand(geyser, "version", "geyser.commands.version.desc", "geyser.command.version"));
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.command.defaults;
27+
28+
import org.geysermc.geyser.GeyserImpl;
29+
import org.geysermc.geyser.api.util.TriState;
30+
import org.geysermc.geyser.command.GeyserCommand;
31+
import org.geysermc.geyser.command.GeyserCommandSource;
32+
import org.geysermc.geyser.pack.SkullResourcePackManager;
33+
import org.geysermc.geyser.registry.BlockRegistries;
34+
import org.geysermc.geyser.registry.Registries;
35+
import org.geysermc.geyser.registry.populator.BlockRegistryPopulator;
36+
import org.geysermc.geyser.registry.populator.CustomBlockRegistryPopulator;
37+
import org.geysermc.geyser.registry.populator.CustomSkullRegistryPopulator;
38+
import org.geysermc.geyser.registry.populator.ItemRegistryPopulator;
39+
import org.geysermc.geyser.registry.populator.TagRegistryPopulator;
40+
import org.geysermc.geyser.text.GeyserLocale;
41+
import org.incendo.cloud.context.CommandContext;
42+
43+
import java.util.concurrent.TimeUnit;
44+
45+
public class ReloadMappingsCommand extends GeyserCommand {
46+
47+
private final GeyserImpl geyser;
48+
49+
public ReloadMappingsCommand(GeyserImpl geyser, String name, String description, String permission) {
50+
super(name, description, permission, TriState.NOT_SET);
51+
this.geyser = geyser;
52+
}
53+
54+
@Override
55+
public void execute(CommandContext<GeyserCommandSource> context) {
56+
GeyserCommandSource source = context.sender();
57+
source.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.reloadmappings.message", source.locale()));
58+
59+
geyser.getSessionManager().disconnectAll("geyser.commands.reloadmappings.kick");
60+
61+
geyser.getScheduledThread().schedule(() -> {
62+
reloadMappings();
63+
source.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.reloadmappings.success", source.locale()));
64+
}, 10, TimeUnit.MILLISECONDS);
65+
}
66+
67+
static void reloadMappings() {
68+
BlockRegistries.BLOCKS.clear();
69+
BlockRegistries.JAVA_BLOCK_STATE_IDENTIFIER_TO_ID.clear();
70+
BlockRegistries.NON_VANILLA_BLOCK_IDS.clear();
71+
BlockRegistries.WATERLOGGED.clear();
72+
BlockRegistries.INTERACTIVE.clear();
73+
BlockRegistries.INTERACTIVE_MAY_BUILD.clear();
74+
BlockRegistries.CUSTOM_BLOCKS.clear();
75+
BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.clear();
76+
BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.clear();
77+
BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.clear();
78+
BlockRegistries.EXTENDED_COLLISION_BOXES.clear();
79+
BlockRegistries.CUSTOM_SKULLS.clear();
80+
81+
Registries.ITEMS.clear();
82+
Registries.TAGS.clear();
83+
84+
SkullResourcePackManager.SKULL_SKINS.clear();
85+
86+
CustomSkullRegistryPopulator.populate();
87+
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.PRE_INIT);
88+
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.DEFINITION);
89+
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_JAVA);
90+
BlockRegistries.COLLISIONS.load();
91+
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.NON_VANILLA_REGISTRATION);
92+
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.VANILLA_REGISTRATION);
93+
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.CUSTOM_REGISTRATION);
94+
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_BEDROCK);
95+
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.POST_INIT);
96+
ItemRegistryPopulator.populate();
97+
TagRegistryPopulator.populate();
98+
99+
Registries.POTION_MIXES.load();
100+
}
101+
}

core/src/main/java/org/geysermc/geyser/registry/ArrayRegistry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.checkerframework.checker.nullness.qual.Nullable;
2929
import org.geysermc.geyser.registry.loader.RegistryLoader;
3030

31+
import java.util.Arrays;
3132
import java.util.function.Supplier;
3233

3334
/**
@@ -148,4 +149,9 @@ public static <I, M> ArrayRegistry<M> create(RegistryLoader<I, M[]> registryLoad
148149
public static <I, M> ArrayRegistry<M> create(I input, RegistryLoader<I, M[]> registryLoader) {
149150
return new ArrayRegistry<>(input, registryLoader);
150151
}
152+
153+
@Override
154+
public void clear() {
155+
Arrays.fill(this.mappings, null);
156+
}
151157
}

core/src/main/java/org/geysermc/geyser/registry/DeferredRegistry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ public boolean loaded() {
123123
return this.loaded;
124124
}
125125

126+
@Override
127+
public void clear() {
128+
if (!this.loaded) {
129+
return;
130+
}
131+
this.backingRegistry.clear();
132+
}
133+
126134
/**
127135
* A registry initializer.
128136
*

core/src/main/java/org/geysermc/geyser/registry/IRegistry.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,12 @@ interface IRegistry<M> {
5757
* @param consumer the consumer
5858
*/
5959
void register(Consumer<M> consumer);
60+
61+
/**
62+
* Clears The Underlying Mappings.
63+
* Throws {@link UnsupportedOperationException} When The Registry Doesn't Support It.
64+
*/
65+
default void clear() {
66+
throw new UnsupportedOperationException("Registry does not support clear.");
67+
}
6068
}

core/src/main/java/org/geysermc/geyser/registry/Registry.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
package org.geysermc.geyser.registry;
2727

28+
import java.util.BitSet;
29+
import java.util.Collection;
30+
import java.util.Map;
2831
import java.util.function.Consumer;
2932
import org.geysermc.geyser.registry.loader.RegistryLoader;
3033

@@ -110,4 +113,20 @@ public void set(M mappings) {
110113
public void register(Consumer<M> consumer) {
111114
consumer.accept(this.mappings);
112115
}
116+
117+
/**
118+
* Clears The Mappings.
119+
*/
120+
@Override
121+
public void clear() {
122+
if (this.mappings instanceof Collection) {
123+
((Collection<?>) this.mappings).clear();
124+
} else if (this.mappings instanceof Map) {
125+
((Map<?, ?>) this.mappings).clear();
126+
} else if (this.mappings instanceof BitSet) {
127+
((BitSet) this.mappings).clear();
128+
} else {
129+
throw new UnsupportedOperationException("Cannot clear registry of type " + (this.mappings == null ? "null" : this.mappings.getClass().getName()));
130+
}
131+
}
113132
}

core/src/main/resources/languages

0 commit comments

Comments
 (0)