|
| 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 | +} |
0 commit comments