Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player GUI API #1189

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,8 @@
*/
package org.spongepowered.api.entity.living.player;

import static com.google.common.base.Preconditions.checkNotNull;

import org.spongepowered.api.Server;
import org.spongepowered.api.block.tileentity.EnderChest;
import org.spongepowered.api.command.source.RemoteSource;
Expand All @@ -38,6 +40,7 @@
import org.spongepowered.api.entity.living.player.gamemode.GameMode;
import org.spongepowered.api.entity.living.player.tab.TabList;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.gui.window.Window;
import org.spongepowered.api.item.inventory.Container;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.network.PlayerConnection;
Expand Down Expand Up @@ -102,6 +105,37 @@ default boolean isViewingInventory() {
*/
boolean closeInventory(Cause cause) throws IllegalArgumentException;

/**
* Gets the active {@link Window} displayed to the player, or
* {@link Optional#empty} if no window is shown or otherwise detected from
* the server.
*
* @return The active window, if available
*/
Optional<Window> getActiveWindow();

/**
* Closes the active window.
*
* @return True if the window was closed
*/
default void closeActiveWindow() {
Optional<Window> active = getActiveWindow();
if (active.isPresent()) {
active.get().close(this);
}
}

/**
* Shows the window to the player if possible.
*
* @param window The window to show
* @return Whether it was shown to the player
*/
default boolean showWindow(Window window) {
return !getActiveWindow().isPresent() && checkNotNull(window, "window").show(this);
}

/**
* Gets the view distance setting of the player. This value represents the
* radius (around the player) in unit chunks.
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/spongepowered/api/gui/window/AnvilWindow.java
@@ -0,0 +1,38 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.Sponge;

public interface AnvilWindow extends ContainerWindow, LocationBackedWindow {

static Builder builder() {
return Sponge.getRegistry().createBuilder(Builder.class);
}

interface Builder extends Window.Builder<AnvilWindow, Builder> {
}

}
58 changes: 58 additions & 0 deletions src/main/java/org/spongepowered/api/gui/window/BeaconWindow.java
@@ -0,0 +1,58 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.carrier.Beacon;
import org.spongepowered.api.data.manipulator.mutable.tileentity.BeaconData;

import javax.annotation.Nullable;

public interface BeaconWindow extends ContainerWindow, TileBackedWindow<Beacon> {

/**
* Sets the beacon data for use only if this window is not bound to a
* location.
*
* @param beaconData The beacon data, or null to clear
*/
void setVirtualBeaconData(@Nullable BeaconData beaconData);

/**
* Sets the completed levels for a virtual window.
*
* @param levels
* @see Beacon#getCompletedLevels
*/
void setVirtualLevels(int levels);

static Builder builder() {
return Sponge.getRegistry().createBuilder(Builder.class);
}

interface Builder extends Window.Builder<BeaconWindow, Builder> {
}

}
59 changes: 59 additions & 0 deletions src/main/java/org/spongepowered/api/gui/window/BookWindow.java
@@ -0,0 +1,59 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.text.BookView;

import javax.annotation.Nullable;

/**
* Note that this doesn't work for editing books. Only signed books will work.
*/
public interface BookWindow extends Window {

/**
* Gets the book view. If no book has been explicitly set, an empty view is
* returned.
*
* @return Current book view
*/
BookView getBookView();

/**
* Sets the book view.
*
* @param view The book view
*/
void setBookView(@Nullable BookView view);

static Builder builder() {
return Sponge.getRegistry().createBuilder(Builder.class);
}

interface Builder extends Window.Builder<BookWindow, Builder> {
}

}
@@ -0,0 +1,41 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.carrier.BrewingStand;

public interface BrewingStandWindow extends ContainerWindow, TileBackedWindow<BrewingStand> {

void setVirtualRemainingTime(int time);

static Builder builder() {
return Sponge.getRegistry().createBuilder(Builder.class);
}

interface Builder extends Window.Builder<BrewingStandWindow, Builder> {
}

}
39 changes: 39 additions & 0 deletions src/main/java/org/spongepowered/api/gui/window/ChestWindow.java
@@ -0,0 +1,39 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.tileentity.carrier.Chest;

public interface ChestWindow extends ContainerWindow, TileBackedWindow<Chest> {

static Builder builder() {
return Sponge.getRegistry().createBuilder(Builder.class);
}

interface Builder extends Window.Builder<ChestWindow, Builder> {
}

}
@@ -0,0 +1,40 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.Sponge;

public interface CommandBlockWindow extends Window {
// TODO Can't open from server side but may be able to observe data sent
// from client when closing etc

static Builder builder() {
return Sponge.getRegistry().createBuilder(Builder.class);
}

interface Builder extends Window.Builder<CommandBlockWindow, Builder> {
}

}
@@ -0,0 +1,45 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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 org.spongepowered.api.gui.window;

import org.spongepowered.api.event.item.inventory.ClickInventoryEvent;
import org.spongepowered.api.item.inventory.Container;

import java.util.Optional;

/**
* Note: To listen for slot clicks, listen to {@link ClickInventoryEvent} and
* test if the container is equal to {@link #getContainer}.
*/
public interface ContainerWindow extends Window {

/**
* Gets the open container, if this window is being displayed to a player.
*
* @return The container, if available
*/
Optional<Container> getContainer();

}