Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into development
- Loading branch information
Showing
13 changed files
with
187 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# v0.3.1 | ||
> Release date: 05.03.2021 | ||
**Independent Widgets**: | ||
* Widgets _can_ now independent from players (#44) | ||
* Added an additional KelpPlayer parameter to the following methods: | ||
- `KelpInventory.render(KelpPlayer)` | ||
- `GroupedWidget.render(KelpPlayer)` | ||
* To summarize and cleanup all `Widget` implementations, the abstract class `AbstractWidget<W extends AbstractWidget<?>>` was added. It's responsible for player-specific actions like adding a `ClickListener` to a certain item. | ||
* Add `/sweetinv` command to testing module demonstrating the new feature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/main/java/de/pxav/kelp/core/inventory/widget/AbstractWidget.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package de.pxav.kelp.core.inventory.widget; | ||
|
||
import de.pxav.kelp.core.inventory.item.KelpItem; | ||
import de.pxav.kelp.core.inventory.listener.ClickListener; | ||
import de.pxav.kelp.core.player.KelpPlayer; | ||
|
||
/** | ||
* An abstract implementation of the Widget class, | ||
* which is responsible for player-dependent actions. | ||
* | ||
* @author Etrayed | ||
*/ | ||
public abstract class AbstractWidget<W extends AbstractWidget<?>> implements Widget { | ||
|
||
protected KelpPlayer player; | ||
|
||
/** | ||
* Sets the player to whom the current widget is currently dedicated. | ||
* | ||
* @param player The player you want to choose. | ||
* @return The current instance of the widget. | ||
*/ | ||
@Override | ||
public final W player(KelpPlayer player) { | ||
this.player = player; | ||
|
||
return (W) this; | ||
} | ||
|
||
/** | ||
* Gets the player to whom the current widget is dedicated. | ||
* | ||
* @return The {@code KelpPlayer} - "owner" of the widget. | ||
*/ | ||
@Override | ||
public final KelpPlayer getPlayer() { | ||
return this.player; | ||
} | ||
|
||
/** | ||
* Adds a listener to the omitted item. If {@link #player the player} | ||
* is {@code null}, a {@link KelpItem#addGlobalListener(ClickListener) global listener} will be added. | ||
* | ||
* @param item The item to listen to. | ||
* @param listener The listener. | ||
*/ | ||
protected void addClickListener(KelpItem item, ClickListener listener) { | ||
if(player == null) { | ||
item.addGlobalListener(listener); | ||
} else { | ||
item.addListener(player, listener); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.