-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ItemGUI class that will be used to change all required and rew…
…ard item stacks.
- Loading branch information
Showing
1 changed file
with
129 additions
and
0 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
src/main/java/world/bentobox/challenges/panel/util/ItemGUI.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,129 @@ | ||
package world.bentobox.challenges.panel.util; | ||
|
||
|
||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.event.inventory.InventoryCloseEvent; | ||
import org.bukkit.inventory.ItemStack; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import world.bentobox.bentobox.api.panels.PanelItem; | ||
import world.bentobox.bentobox.api.panels.PanelListener; | ||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder; | ||
import world.bentobox.bentobox.api.user.User; | ||
|
||
|
||
/** | ||
* This class allows to change Input ItemStacks to different ItemStacks. | ||
*/ | ||
public class ItemGUI | ||
{ | ||
public ItemGUI(User user, List<ItemStack> itemStacks) | ||
{ | ||
this.user = user; | ||
this.itemStacks = itemStacks; | ||
this.build(); | ||
} | ||
|
||
|
||
/** | ||
* This method builds panel that allows to change given number value. | ||
*/ | ||
private void build() | ||
{ | ||
PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); | ||
panelBuilder.listener(new CustomPanelListener()); | ||
|
||
for (ItemStack itemStack : this.itemStacks) | ||
{ | ||
panelBuilder.item(new CustomPanelItem(itemStack)); | ||
} | ||
|
||
panelBuilder.build().open(this.user); | ||
} | ||
|
||
|
||
// --------------------------------------------------------------------- | ||
// Section: Private classes | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
/** | ||
* This CustomPanelItem does no lose Item original MetaData. After PanelItem has been | ||
* created it restores original meta data. It also does not allow to change anything that | ||
* could destroy meta data. | ||
*/ | ||
private class CustomPanelItem extends PanelItem | ||
{ | ||
CustomPanelItem(ItemStack item) | ||
{ | ||
super(item.clone(), "", Collections.emptyList(), false, null, false); | ||
this.getItem().setItemMeta(item.getItemMeta()); | ||
} | ||
|
||
|
||
@Override | ||
public void setGlow(boolean glow) | ||
{ | ||
} | ||
|
||
|
||
@Override | ||
public void setDescription(List<String> description) | ||
{ | ||
} | ||
|
||
|
||
@Override | ||
public void setName(String name) | ||
{ | ||
} | ||
|
||
|
||
@Override | ||
public void setHead(ItemStack itemStack) | ||
{ | ||
} | ||
} | ||
|
||
|
||
/** | ||
* This CustomPanelListener allows to move items in current panel. | ||
*/ | ||
private class CustomPanelListener implements PanelListener | ||
{ | ||
@Override | ||
public void setup() | ||
{ | ||
} | ||
|
||
|
||
@Override | ||
public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) | ||
{ | ||
} | ||
|
||
|
||
@Override | ||
public void onInventoryClick(User user, InventoryClickEvent event) | ||
{ | ||
event.setCancelled(false); | ||
} | ||
} | ||
|
||
|
||
// --------------------------------------------------------------------- | ||
// Section: Variables | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
/** | ||
* User who opens current gui. | ||
*/ | ||
private User user; | ||
|
||
/** | ||
* List with original items. | ||
*/ | ||
private List<ItemStack> itemStacks; | ||
} |