use of com.bergerkiller.generated.net.minecraft.world.inventory.ContainerAnvilHandle in project BKCommonLib by bergerhealer.
the class MapWidgetAnvil method setWindowOpen.
private void setWindowOpen(boolean enabled) {
if (this._isWindowOpen == enabled) {
return;
}
this._isWindowOpen = enabled;
// Close all old views first (to be sure), both when enabling and disabling
for (InventoryView view : this._openInventories) {
view.close();
}
this._openInventories.clear();
if (enabled) {
// Start listening
JavaPlugin plugin = this.getDisplay().getPlugin();
Bukkit.getPluginManager().registerEvents(this._listener, plugin);
// Reset text
this._text = "";
// Open windows for all viewing players
for (Player player : (_openFor.isEmpty() ? this.display.getViewers() : _openFor)) {
if (_openFor.isEmpty() && !this.display.isControlling(player)) {
continue;
}
final InventoryView view = EntityPlayerHandle.fromBukkit(player).openAnvilWindow(null);
// Required for handling text changes < MC 1.9
if (!CommonCapabilities.HAS_PREPARE_ANVIL_EVENT) {
ContainerAnvilHandle container = ContainerAnvilHandle.fromBukkit(view);
LegacyContainerAnvilHook hook = ClassHook.get(container.getRaw(), LegacyContainerAnvilHook.class);
hook.textChangeCallback = () -> handleTextChange(view);
}
this._openInventories.add(view);
this.refreshButtons(view);
}
// If it couldn't be opened for anyone, close itself
if (this._openInventories.isEmpty()) {
setWindowOpen(false);
}
} else {
// Unregister event listener
CommonUtil.unregisterListener(this._listener);
// Deactivate the widget (to be sure)
deactivate();
// Event
onClose();
}
}
Aggregations