├── .gitignore ├── .settings ├── org.eclipse.jdt.apt.core.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── checkstyle-suppressions.xml ├── .editorconfig ├── src └── main │ └── java │ └── me │ └── blackness │ └── black │ ├── Target.java │ ├── req │ ├── DragReq.java │ ├── ClickReq.java │ ├── PlayerReq.java │ ├── OrReq.java │ ├── ClickedItemReq.java │ ├── HotbarButtonReq.java │ ├── AddedItemReq.java │ ├── ClickedCursorItemReq.java │ ├── ClickedElementReq.java │ ├── DragTypeReq.java │ ├── AddedElementReq.java │ ├── ClickedCursorElementReq.java │ ├── ClickTypeReq.java │ ├── DraggedItemReq.java │ ├── DraggedElementReq.java │ └── SlotReq.java │ ├── Requirement.java │ ├── ElementEvent.java │ ├── listener │ ├── InventoryCloseListener.java │ ├── PluginListener.java │ ├── InventoryDragListener.java │ └── InventoryClickListener.java │ ├── event │ ├── ElementBasicEvent.java │ ├── ElementDragEvent.java │ └── ElementClickEvent.java │ ├── target │ ├── BasicTarget.java │ ├── DragTarget.java │ └── ClickTarget.java │ ├── element │ ├── TSafeElement.java │ ├── LiveElement.java │ └── BasicElement.java │ ├── Element.java │ ├── Page.java │ ├── page │ ├── TSafePage.java │ ├── CloseInformerPage.java │ └── ChestPage.java │ ├── Blackness.java │ ├── pane │ ├── TSafePane.java │ ├── LivePane.java │ └── BasicPane.java │ └── Pane.java ├── .github └── ISSUE_TEMPLATE │ ├── Feature_request.md │ └── Bug_report.md ├── .project ├── .classpath ├── pom.xml ├── checkstyle.xml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=false 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding/=UTF-8 4 | -------------------------------------------------------------------------------- /checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | indent_size = 2 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | max_line_length = 80 11 | 12 | [*.java] 13 | indent_size = 4 14 | max_line_length = 100 15 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/Target.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import org.bukkit.event.inventory.InventoryInteractEvent; 4 | 5 | /** 6 | * target is the type of all the event handlers. 7 | * 8 | * @author personinblack 9 | * @since 4.0.0-alpha 10 | */ 11 | public interface Target { 12 | /** 13 | * let the target handle this event. 14 | * 15 | * @param event the event to handle 16 | */ 17 | void handle(InventoryInteractEvent event); 18 | } 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: feature request 3 | about: contribute to black by requesting features 4 | 5 | --- 6 | 7 | **what is this feature you want to see on black** 8 | a clear explanation of the feature you would like to see. 9 | 10 | **why do you want to see this feature on black?** 11 | the purpose of this feature. 12 | 13 | **anything you want to add** 14 | any other stuff you would like to write about this feature request. you can also add images here. 15 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 3 | org.eclipse.jdt.core.compiler.compliance=1.8 4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 7 | org.eclipse.jdt.core.compiler.processAnnotations=disabled 8 | org.eclipse.jdt.core.compiler.release=disabled 9 | org.eclipse.jdt.core.compiler.source=1.8 10 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/DragReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import org.bukkit.event.inventory.InventoryDragEvent; 4 | import org.bukkit.event.inventory.InventoryInteractEvent; 5 | 6 | import me.blackness.black.Requirement; 7 | 8 | /** 9 | * a requirement which requires a drag. 10 | * 11 | * @author personinblack 12 | * @see Requirement 13 | * @since 4.0.0-alpha 14 | */ 15 | public final class DragReq implements Requirement { 16 | @Override 17 | public boolean control(final InventoryInteractEvent event) { 18 | return event instanceof InventoryDragEvent; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/ClickReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import org.bukkit.event.inventory.InventoryClickEvent; 4 | import org.bukkit.event.inventory.InventoryInteractEvent; 5 | 6 | import me.blackness.black.Requirement; 7 | 8 | /** 9 | * a requirement which requires a drag. 10 | * 11 | * @author personinblack 12 | * @see Requirement 13 | * @since 4.0.0-alpha 14 | */ 15 | public final class ClickReq implements Requirement { 16 | @Override 17 | public boolean control(final InventoryInteractEvent event) { 18 | return event instanceof InventoryClickEvent; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/Requirement.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import org.bukkit.event.inventory.InventoryInteractEvent; 4 | 5 | /** 6 | * requirement is the type of all the event conditions. 7 | * 8 | * @author personinblack 9 | * @since 4.0.0-alpha 10 | */ 11 | public interface Requirement { 12 | /** 13 | * make the requirement control this event to see if it passes and return the result. 14 | * 15 | * @param event event to control 16 | * @return {@code true} if the event passes this requirement or {@code false} otherwise. 17 | * @see InventoryInteractEvent 18 | */ 19 | boolean control(InventoryInteractEvent event); 20 | } 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: bug report 3 | about: send bug reports to help us improve black 4 | 5 | --- 6 | 7 | **describe the bug** 8 | a clear description of what the bug is. 9 | 10 | **to reproduce** 11 | steps to reproduce the behavior: 12 | 13 | 1. write '...' 14 | 2. do '...' 15 | 3. get the error '...' 16 | 17 | **expected behavior** 18 | a clear description of what you expected to happen. 19 | 20 | **screenshots** 21 | if applicable, add screenshots to help explain your problem. 22 | 23 | **console logs** 24 | if applicable, add console logs to help explain your problem. 25 | 26 | **environment:** 27 | 28 | - version of black [e.g. 3.1.0] 29 | - version of server [e.g. 1.12.2] 30 | - operating system of server: [e.g. ubuntu] 31 | 32 | **additional context** 33 | anything you want to add. 34 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/ElementEvent.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | /** 6 | * represents an element event. 7 | * 8 | * @author personinblack 9 | * @see Element 10 | * @since 4.0.0-alpha 11 | */ 12 | public interface ElementEvent { 13 | /** 14 | * the player involved in this event. 15 | * 16 | * @return the player who triggered this event 17 | * @see Player 18 | */ 19 | Player player(); 20 | 21 | /** 22 | * cancels the action the player has done. 23 | */ 24 | void cancel(); 25 | 26 | /** 27 | * closes all the open inventories the player has at the moment. 28 | * (i don't know why i wrote this like a player can have multiple inventories open 29 | * at the same time but whatever...) 30 | */ 31 | void closeView(); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/listener/InventoryCloseListener.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.listener; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.inventory.InventoryCloseEvent; 6 | 7 | import me.blackness.black.Page; 8 | 9 | /** 10 | * a listener that listen for players closing inventories. 11 | * 12 | * @author personinblack 13 | * @since 2.0.0 14 | */ 15 | public final class InventoryCloseListener implements Listener { 16 | /** 17 | * the listener that listens for inventory closes and informs the pages associated with them. 18 | * 19 | * @param event the event that happened 20 | */ 21 | @EventHandler 22 | public void closeListener(final InventoryCloseEvent event) { 23 | if (event.getInventory().getHolder() instanceof Page) { 24 | ((Page) event.getInventory().getHolder()).handleClose(event); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/PlayerReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | 8 | import me.blackness.black.Requirement; 9 | 10 | /** 11 | * a requirement which requires a player. 12 | * 13 | * @author personinblack 14 | * @see Requirement 15 | * @see Player 16 | * @since 4.0.0-alpha 17 | */ 18 | public final class PlayerReq implements Requirement { 19 | private final Player player; 20 | 21 | /** 22 | * ctor. 23 | * 24 | * @param player the required player 25 | */ 26 | public PlayerReq(final Player player) { 27 | this.player = Objects.requireNonNull(player); 28 | } 29 | 30 | @Override 31 | public boolean control(final InventoryInteractEvent event) { 32 | return event.getWhoClicked().getUniqueId().equals(player.getUniqueId()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | black 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | 25 | 1647098625535 26 | 27 | 30 28 | 29 | org.eclipse.core.resources.regexFilterMatcher 30 | node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/OrReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryInteractEvent; 6 | 7 | import me.blackness.black.Requirement; 8 | 9 | /** 10 | * a requirement which takes multiple other requirements and matches either one of them. 11 | * 12 | * @author personinblack 13 | * @see Requirement 14 | * @since 4.0.0-alpha 15 | */ 16 | public final class OrReq implements Requirement { 17 | private final Requirement[] reqs; 18 | 19 | /** 20 | * ctor. 21 | * 22 | * @param reqs requirements to do the *or* check 23 | */ 24 | public OrReq(final Requirement... reqs) { 25 | this.reqs = Objects.requireNonNull(reqs.clone()); 26 | } 27 | 28 | @Override 29 | public boolean control(final InventoryInteractEvent event) { 30 | for (final Requirement req : reqs) { 31 | if (req.control(event)) { 32 | return true; 33 | } 34 | } 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/listener/PluginListener.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.listener; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.server.PluginDisableEvent; 6 | 7 | import me.blackness.black.Blackness; 8 | 9 | /** 10 | * a listener that listen for plugins getting disabled. 11 | * 12 | * @author personinblack 13 | * @version 2.0.0 14 | */ 15 | public final class PluginListener implements Listener { 16 | private final Blackness blackness; 17 | 18 | /** 19 | * ctor. 20 | * 21 | * @param blackness blackness to inform 22 | */ 23 | public PluginListener(final Blackness blackness) { 24 | this.blackness = blackness; 25 | } 26 | 27 | /** 28 | * the listener that listens for plugin disables and informs blackness. 29 | * 30 | * @param event the event that happened 31 | */ 32 | @EventHandler 33 | public void listener(final PluginDisableEvent event) { 34 | blackness.processPluginDisable(event); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/listener/InventoryDragListener.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.listener; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.inventory.InventoryDragEvent; 6 | import org.bukkit.inventory.PlayerInventory; 7 | 8 | import me.blackness.black.Page; 9 | 10 | /** 11 | * a listener that listen for drags happening on inventories. 12 | * 13 | * @author personinblack 14 | * @since 4.0.0-alpha 15 | */ 16 | public final class InventoryDragListener implements Listener { 17 | /** 18 | * the listener that listens for inventory drags and informs the pages associated with them. 19 | * 20 | * @param event the event that happened 21 | * @see InventoryDragEvent 22 | */ 23 | @EventHandler 24 | public void listener(final InventoryDragEvent event) { 25 | if (event.getInventory().getHolder() instanceof Page && 26 | !(event.getInventory() instanceof PlayerInventory)) { 27 | 28 | ((Page) event.getInventory().getHolder()).accept(event); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/listener/InventoryClickListener.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.listener; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.inventory.PlayerInventory; 7 | 8 | import me.blackness.black.Page; 9 | 10 | /** 11 | * a listener that listen for clicks happening on inventories. 12 | * 13 | * @author personinblack 14 | * @since 2.0.0 15 | */ 16 | public final class InventoryClickListener implements Listener { 17 | /** 18 | * the listener that listens for inventory clicks and informs the pages associated with them. 19 | * 20 | * @param event the event that happened 21 | * @see InventoryClickEvent 22 | */ 23 | @EventHandler 24 | public void listener(final InventoryClickEvent event) { 25 | if (event.getInventory().getHolder() instanceof Page && 26 | !(event.getClickedInventory() instanceof PlayerInventory)) { 27 | 28 | ((Page) event.getInventory().getHolder()).accept(event); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/ClickedItemReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires a certain item to be clicked on. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @see ItemStack 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class ClickedItemReq implements Requirement { 20 | private final ItemStack item; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param item itemstack to be clicked on 26 | */ 27 | public ClickedItemReq(final ItemStack item) { 28 | this.item = Objects.requireNonNull(item); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryClickEvent) { 34 | return ((InventoryClickEvent) event).getCurrentItem().equals(item); 35 | } else { 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/HotbarButtonReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | 8 | import me.blackness.black.Requirement; 9 | 10 | /** 11 | * a requirement which requires a certain keyboard button to be pressed. 12 | * returns {@code false} for a non click event. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @since 4.0.0-alpha 17 | */ 18 | public final class HotbarButtonReq implements Requirement { 19 | private final int button; 20 | 21 | /** 22 | * ctor. 23 | * 24 | * @param button the button which expected to be pressed 25 | */ 26 | public HotbarButtonReq(final int button) { 27 | this.button = Objects.requireNonNull(button); 28 | } 29 | 30 | @Override 31 | public boolean control(final InventoryInteractEvent event) { 32 | if (event instanceof InventoryClickEvent) { 33 | return ((InventoryClickEvent) event).getHotbarButton() == button; 34 | } else { 35 | return false; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/AddedItemReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryDragEvent; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires an item to be added by dragging. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @see ItemStack 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class AddedItemReq implements Requirement { 20 | private final ItemStack item; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param item the item that needs to be added 26 | */ 27 | public AddedItemReq(final ItemStack item) { 28 | this.item = Objects.requireNonNull(item); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryDragEvent) { 34 | return ((InventoryDragEvent) event).getNewItems().values() 35 | .stream().anyMatch(this.item::equals); 36 | } 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/ClickedCursorItemReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import me.blackness.black.Requirement; 4 | import org.bukkit.event.inventory.InventoryClickEvent; 5 | import org.bukkit.event.inventory.InventoryInteractEvent; 6 | import org.bukkit.inventory.ItemStack; 7 | 8 | import java.util.Objects; 9 | 10 | /** 11 | * a requirement which requires holding a certain item on cursor. 12 | * 13 | * @author Draww 14 | * @see Requirement 15 | * @see ItemStack 16 | * @since 4.1.0-alpha 17 | */ 18 | public final class ClickedCursorItemReq implements Requirement { 19 | private final ItemStack item; 20 | 21 | /** 22 | * ctor. 23 | * 24 | * @param item the itemstack which has to be on player's cursor 25 | */ 26 | public ClickedCursorItemReq(final ItemStack item) { 27 | this.item = Objects.requireNonNull(item); 28 | } 29 | 30 | @Override 31 | public boolean control(final InventoryInteractEvent event) { 32 | if (event instanceof InventoryClickEvent) { 33 | return ((InventoryClickEvent) event).getCursor().equals(item); 34 | } else { 35 | return false; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/ClickedElementReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | 8 | import me.blackness.black.Element; 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires a certain element to be clicked. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @see Element 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class ClickedElementReq implements Requirement { 20 | private final Element element; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param element the element that needs to be clicked 26 | */ 27 | public ClickedElementReq(final Element element) { 28 | this.element = Objects.requireNonNull(element); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryClickEvent) { 34 | return element.is(((InventoryClickEvent) event).getCurrentItem()); 35 | } else { 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/DragTypeReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.DragType; 6 | import org.bukkit.event.inventory.InventoryDragEvent; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires a certain drag type. returns {@code false} for a non drag event. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @see DragType 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class DragTypeReq implements Requirement { 20 | private final DragType dragType; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param dragType the required drag type 26 | */ 27 | public DragTypeReq(final DragType dragType) { 28 | this.dragType = Objects.requireNonNull(dragType); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryDragEvent) { 34 | return ((InventoryDragEvent) event).getType() == dragType; 35 | } else { 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/AddedElementReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryDragEvent; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | 8 | import me.blackness.black.Element; 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires an element to be added by dragging. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @see Element 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class AddedElementReq implements Requirement { 20 | private final Element element; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param element the element that needs to be added 26 | */ 27 | public AddedElementReq(final Element element) { 28 | this.element = Objects.requireNonNull(element); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryDragEvent) { 34 | return ((InventoryDragEvent) event).getNewItems().values() 35 | .stream().anyMatch(element::is); 36 | } 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/ClickedCursorElementReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import me.blackness.black.Element; 4 | import me.blackness.black.Requirement; 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | 8 | import java.util.Objects; 9 | 10 | /** 11 | * a requirement which requires holding a certain element on cursor. 12 | * 13 | * @author Draww 14 | * @see Requirement 15 | * @see Element 16 | * @since 4.1.0-alpha 17 | */ 18 | public final class ClickedCursorElementReq implements Requirement { 19 | private final Element element; 20 | 21 | /** 22 | * ctor. 23 | * 24 | * @param element the element which has to be on player's cursor 25 | */ 26 | public ClickedCursorElementReq(final Element element) { 27 | this.element = Objects.requireNonNull(element); 28 | } 29 | 30 | @Override 31 | public boolean control(final InventoryInteractEvent event) { 32 | if (event instanceof InventoryClickEvent) { 33 | return element.is(((InventoryClickEvent) event).getCursor()); 34 | } else { 35 | return false; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/ClickTypeReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.ClickType; 6 | import org.bukkit.event.inventory.InventoryClickEvent; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires a certain click type. returns {@code false} for a non click event. 13 | * 14 | * @author personinblack 15 | * @see Requirement 16 | * @see ClickType 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class ClickTypeReq implements Requirement { 20 | private final ClickType clickType; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param clickType required click type 26 | */ 27 | public ClickTypeReq(final ClickType clickType) { 28 | this.clickType = Objects.requireNonNull(clickType); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryClickEvent) { 34 | return ((InventoryClickEvent) event).getClick() == clickType; 35 | } else { 36 | return false; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/DraggedItemReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryDragEvent; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import me.blackness.black.Requirement; 11 | 12 | /** 13 | * a requirement which requires a certain item to be dragged. 14 | * 15 | * @author personinblack 16 | * @see Requirement 17 | * @see ItemStack 18 | * @since 4.0.0-alpha 19 | */ 20 | public final class DraggedItemReq implements Requirement { 21 | private final ItemStack item; 22 | 23 | /** 24 | * ctor. 25 | * 26 | * @param item itemstack to be dragged 27 | */ 28 | public DraggedItemReq(final ItemStack item) { 29 | this.item = Objects.requireNonNull(item); 30 | } 31 | 32 | @Override 33 | public boolean control(final InventoryInteractEvent event) { 34 | if (event instanceof InventoryClickEvent) { 35 | return false; 36 | } else { 37 | return ((InventoryDragEvent) event).getOldCursor().equals(item); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/DraggedElementReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryDragEvent; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | 9 | import me.blackness.black.Element; 10 | import me.blackness.black.Requirement; 11 | 12 | /** 13 | * a requirement which requires a certain element to be dragged. 14 | * 15 | * @author personinblack 16 | * @see Requirement 17 | * @see Element 18 | * @since 4.0.0-alpha 19 | */ 20 | public final class DraggedElementReq implements Requirement { 21 | private final Element element; 22 | 23 | /** 24 | * ctor. 25 | * 26 | * @param element the element that needs to be dragged 27 | */ 28 | public DraggedElementReq(final Element element) { 29 | this.element = Objects.requireNonNull(element); 30 | } 31 | 32 | @Override 33 | public boolean control(final InventoryInteractEvent event) { 34 | if (event instanceof InventoryClickEvent) { 35 | return false; 36 | } else { 37 | return element.is(((InventoryDragEvent) event).getCursor()); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/req/SlotReq.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.req; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryClickEvent; 6 | import org.bukkit.event.inventory.InventoryDragEvent; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | 9 | import me.blackness.black.Requirement; 10 | 11 | /** 12 | * a requirement which requires a specific slot to be pressed. 13 | * for drag events, this will check all the affected slots. 14 | * 15 | * @author personinblack 16 | * @see Requirement 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class SlotReq implements Requirement { 20 | private final int slot; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param slot the slot which required to be pressed 26 | */ 27 | public SlotReq(final int slot) { 28 | this.slot = Objects.requireNonNull(slot); 29 | } 30 | 31 | @Override 32 | public boolean control(final InventoryInteractEvent event) { 33 | if (event instanceof InventoryClickEvent) { 34 | return ((InventoryClickEvent) event).getSlot() == slot; 35 | } else { 36 | return ((InventoryDragEvent) event).getInventorySlots().contains(slot); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/event/ElementBasicEvent.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.event; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | 9 | import me.blackness.black.ElementEvent; 10 | 11 | /** 12 | * an event which contains the implementation of the methods of {@link ElementEvent}. 13 | * 14 | * @author personinblack 15 | * @since 4.0.0-alpha 16 | */ 17 | public final class ElementBasicEvent implements ElementEvent { 18 | private final InventoryInteractEvent baseEvent; 19 | 20 | /** 21 | * ctor. 22 | * 23 | * @param baseEvent the base event 24 | */ 25 | public ElementBasicEvent(final InventoryInteractEvent baseEvent) { 26 | this.baseEvent = Objects.requireNonNull(baseEvent); 27 | } 28 | 29 | @Override 30 | public Player player() { 31 | return (Player) baseEvent.getWhoClicked(); 32 | } 33 | 34 | @Override 35 | public void cancel() { 36 | baseEvent.setCancelled(true); 37 | } 38 | 39 | @Override 40 | public void closeView() { 41 | Bukkit.getScheduler().runTask( 42 | baseEvent.getHandlers().getRegisteredListeners()[0].getPlugin(), 43 | () -> { 44 | baseEvent.getWhoClicked().closeInventory(); 45 | } 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/target/BasicTarget.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.target; 2 | 3 | import java.util.Objects; 4 | import java.util.function.Consumer; 5 | 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | 8 | import me.blackness.black.Requirement; 9 | import me.blackness.black.Target; 10 | import me.blackness.black.event.ElementBasicEvent; 11 | 12 | /** 13 | * the most basic click target which can handle all the interact events. 14 | * 15 | * @author personinblack 16 | * @see Target 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class BasicTarget implements Target { 20 | private final Consumer handler; 21 | private final Requirement[] reqs; 22 | 23 | /** 24 | * ctor. 25 | * 26 | * @param handler handler of this target 27 | * @param reqs requirements of this target 28 | * @see Consumer 29 | * @see Requirement 30 | */ 31 | public BasicTarget(final Consumer handler, final Requirement... reqs) { 32 | this.handler = Objects.requireNonNull(handler); 33 | this.reqs = Objects.requireNonNull(reqs.clone()); 34 | } 35 | 36 | @Override 37 | public void handle(final InventoryInteractEvent event) { 38 | for (final Requirement req : reqs) { 39 | if (!req.control(event)) { 40 | return; 41 | } 42 | } 43 | handler.accept(new ElementBasicEvent(event)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/target/DragTarget.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.target; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | import java.util.function.Consumer; 6 | 7 | import org.bukkit.event.inventory.InventoryDragEvent; 8 | import org.bukkit.event.inventory.InventoryInteractEvent; 9 | 10 | import me.blackness.black.Requirement; 11 | import me.blackness.black.Target; 12 | import me.blackness.black.event.ElementDragEvent; 13 | 14 | /** 15 | * the most basic drag target. 16 | * 17 | * @author personinblack 18 | * @see Target 19 | * @since 4.0.0-alpha 20 | */ 21 | public final class DragTarget implements Target { 22 | private final Consumer handler; 23 | private final Requirement[] reqs; 24 | 25 | /** 26 | * ctor. 27 | * 28 | * @param handler handler of this target 29 | * @param reqs requirements of this target 30 | * @see Consumer 31 | * @see Requirement 32 | */ 33 | public DragTarget(final Consumer handler, final Requirement... reqs) { 34 | this.handler = Objects.requireNonNull(handler); 35 | this.reqs = Objects.requireNonNull(reqs.clone()); 36 | } 37 | 38 | @Override 39 | public void handle(final InventoryInteractEvent event) { 40 | if (event instanceof InventoryDragEvent && 41 | Arrays.stream(reqs).allMatch(req -> req.control(event))) { 42 | 43 | handler.accept(new ElementDragEvent((InventoryDragEvent) event)); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/target/ClickTarget.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.target; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | import java.util.function.Consumer; 6 | 7 | import org.bukkit.event.inventory.InventoryClickEvent; 8 | import org.bukkit.event.inventory.InventoryInteractEvent; 9 | 10 | import me.blackness.black.Requirement; 11 | import me.blackness.black.Target; 12 | import me.blackness.black.event.ElementClickEvent; 13 | 14 | /** 15 | * the most basic click target. 16 | * 17 | * @author personinblack 18 | * @see Target 19 | * @since 4.0.0-alpha 20 | */ 21 | public final class ClickTarget implements Target { 22 | private final Consumer handler; 23 | private final Requirement[] reqs; 24 | 25 | /** 26 | * ctor. 27 | * 28 | * @param handler handler of this target 29 | * @param reqs requirements of this target 30 | * @see Consumer 31 | * @see Requirement 32 | */ 33 | public ClickTarget(final Consumer handler, final Requirement... reqs) { 34 | this.handler = Objects.requireNonNull(handler); 35 | this.reqs = Objects.requireNonNull(reqs.clone()); 36 | } 37 | 38 | @Override 39 | public void handle(final InventoryInteractEvent event) { 40 | if (event instanceof InventoryClickEvent && 41 | Arrays.stream(reqs).allMatch(req -> req.control(event))) { 42 | 43 | handler.accept(new ElementClickEvent((InventoryClickEvent) event)); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/element/TSafeElement.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.element; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryInteractEvent; 6 | import org.bukkit.inventory.Inventory; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | import me.blackness.black.Element; 10 | 11 | /** 12 | * thread-safe decorator for any element. 13 | * 14 | * @author personinblack 15 | * @see Element 16 | * @since 3.1.0 17 | */ 18 | public final class TSafeElement implements Element { 19 | private final Element baseElement; 20 | 21 | /** 22 | * ctor. 23 | * 24 | * @param baseElement the element to make thread-safe 25 | */ 26 | public TSafeElement(final Element baseElement) { 27 | this.baseElement = Objects.requireNonNull(baseElement); 28 | } 29 | 30 | @Override 31 | public void displayOn(final Inventory inventory, final int locX, final int locY) { 32 | synchronized (baseElement) { 33 | baseElement.displayOn(inventory, locX, locY); 34 | } 35 | } 36 | 37 | @Override 38 | public void accept(final InventoryInteractEvent event) { 39 | baseElement.accept(event); 40 | } 41 | 42 | @Override 43 | public boolean is(final ItemStack icon) { 44 | return baseElement.is(icon); 45 | } 46 | 47 | @Override 48 | public boolean is(final Element element) { 49 | if (baseElement instanceof TSafeElement) { 50 | return this.baseElement.is(((TSafeElement) element).baseElement); 51 | } else { 52 | return baseElement.is(element); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/Element.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import org.bukkit.event.inventory.InventoryInteractEvent; 4 | import org.bukkit.inventory.Inventory; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | /** 8 | * element is the type of all the buttons inside a pane which does stuff when you click on it. 9 | * 10 | * @author personinblack 11 | * @see Pane 12 | * @since 1.0.0 13 | */ 14 | public interface Element { 15 | /** 16 | * display the element on an inventory. this method is being used by the pane 17 | * which contains this element. 18 | * 19 | * @param inventory inventory to display the element on 20 | * @param locX x location of the slot 21 | * @param locY y location of the slot 22 | * @see Pane 23 | * @see Inventory 24 | */ 25 | void displayOn(Inventory inventory, int locX, int locY); 26 | 27 | /** 28 | * accept the element click event and pass it to the framework user's handler. 29 | * 30 | * @param event event to pass 31 | * @see InventoryInteractEvent 32 | */ 33 | void accept(InventoryInteractEvent event); 34 | 35 | /** 36 | * compares the specified element with this one. 37 | * 38 | * @param element the element to compare 39 | * @return {@code true} if they are the same or {@code false} if they are not 40 | */ 41 | boolean is(Element element); 42 | 43 | /** 44 | * compares the specified itemstack with this element's icon. 45 | * 46 | * @param icon the itemstack to compare 47 | * @return {@code true} if they are the same or {@code false} if they are not 48 | * @see ItemStack 49 | */ 50 | boolean is(ItemStack icon); 51 | } 52 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/event/ElementDragEvent.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.event; 2 | 3 | import java.util.Map; 4 | import java.util.Objects; 5 | 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.inventory.InventoryDragEvent; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import me.blackness.black.ElementEvent; 11 | 12 | /** 13 | * an event which represents an inventory drag. 14 | * 15 | * @author personinblack 16 | * @see ElementEvent 17 | * @since 4.0.0-alpha 18 | */ 19 | public final class ElementDragEvent implements ElementEvent { 20 | private final InventoryDragEvent baseEvent; 21 | private final ElementBasicEvent baseElementEvent; 22 | 23 | /** 24 | * ctor. 25 | * 26 | * @param baseEvent the base event 27 | */ 28 | public ElementDragEvent(final InventoryDragEvent baseEvent) { 29 | this.baseEvent = Objects.requireNonNull(baseEvent); 30 | this.baseElementEvent = new ElementBasicEvent(baseEvent); 31 | } 32 | 33 | /** 34 | * the cursor before the drag is done. 35 | * 36 | * @return cursor before the drag 37 | * @see ItemStack 38 | * @see Player#getItemOnCursor() for the cursor *after* the drag is done 39 | */ 40 | public ItemStack oldCursor() { 41 | return baseEvent.getOldCursor(); 42 | } 43 | 44 | /** 45 | * items being changed in this event. 46 | * 47 | * @return a map of slots and itemstack changes associated with them 48 | * @see Map 49 | * @see ItemStack 50 | */ 51 | public Map items() { 52 | return baseEvent.getNewItems(); 53 | } 54 | 55 | @Override 56 | public Player player() { 57 | return baseElementEvent.player(); 58 | } 59 | 60 | @Override 61 | public void cancel() { 62 | baseElementEvent.cancel(); 63 | } 64 | 65 | @Override 66 | public void closeView() { 67 | baseElementEvent.closeView(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/event/ElementClickEvent.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.event; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.inventory.InventoryClickEvent; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | import me.blackness.black.ElementEvent; 10 | 11 | /** 12 | * an event which represents an inventory click. 13 | * 14 | * @author personinblack 15 | * @see ElementEvent 16 | * @since 4.0.0-alpha 17 | */ 18 | public final class ElementClickEvent implements ElementEvent { 19 | private final InventoryClickEvent baseEvent; 20 | private final ElementBasicEvent baseElementEvent; 21 | 22 | /** 23 | * ctor. 24 | * 25 | * @param baseEvent the base event 26 | */ 27 | public ElementClickEvent(final InventoryClickEvent baseEvent) { 28 | this.baseEvent = Objects.requireNonNull(baseEvent); 29 | this.baseElementEvent = new ElementBasicEvent(baseEvent); 30 | } 31 | 32 | /** 33 | * the itemstack the player has clicked on. 34 | * 35 | * @return the itemstack that the player has clicked on 36 | * @see ItemStack 37 | * @see Player 38 | */ 39 | public ItemStack currentItem() { 40 | return baseEvent.getCurrentItem().clone(); 41 | } 42 | 43 | /** 44 | * x location of the clicked slot. 45 | * 46 | * @return x 47 | */ 48 | public int clickedX() { 49 | return baseEvent.getSlot() % 9; 50 | } 51 | 52 | /** 53 | * y location of the clicked slot. 54 | * 55 | * @return y 56 | */ 57 | public int clickedY() { 58 | return baseEvent.getSlot() / 9; 59 | } 60 | 61 | @Override 62 | public Player player() { 63 | return baseElementEvent.player(); 64 | } 65 | 66 | @Override 67 | public void cancel() { 68 | baseElementEvent.cancel(); 69 | } 70 | 71 | @Override 72 | public void closeView() { 73 | baseElementEvent.closeView(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/Page.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.inventory.InventoryCloseEvent; 5 | import org.bukkit.event.inventory.InventoryInteractEvent; 6 | import org.bukkit.inventory.InventoryHolder; 7 | 8 | import me.blackness.observer.Target; 9 | 10 | /** 11 | * page is the type of all the inventory pages which made from panes and 12 | * can be displayed to players. 13 | * 14 | * @author personinblack 15 | * @see Pane 16 | * @see Player 17 | * @since 1.0.0 18 | */ 19 | public interface Page extends InventoryHolder, Target { 20 | 21 | /** 22 | * adds a new pane to the page. 23 | * 24 | * @param pane pane to add 25 | * @param position the position of the new pane 26 | */ 27 | void add(Pane pane, int position); 28 | 29 | /** 30 | * removes the pane at the specified position. 31 | * 32 | * @param position position 33 | */ 34 | void remove(int position); 35 | 36 | /** 37 | * rearranges the panes from top to bottom. this will shift the panes towards bottom 38 | * when they are about to overlap each other. 39 | * 40 | * @param paneIndex index of the pane which will be rearranged 41 | * @param position the new desired position of the pane 42 | */ 43 | void rearrange(int paneIndex, int position); 44 | 45 | /** 46 | * defines a new holder for the page. specifically to be used by page decorators. 47 | * 48 | * @param holder new holder 49 | */ 50 | void defineHolder(Page holder); 51 | 52 | /** 53 | * shows this page. 54 | * 55 | * @param player player to show the page to 56 | * @see Player 57 | */ 58 | void showTo(Player player); 59 | 60 | /** 61 | * this method is being triggered by the inventory close event in order to make this page 62 | * do not update the player who closed this page anymore. 63 | * 64 | * @param event event to handle 65 | * @see InventoryCloseEvent 66 | */ 67 | void handleClose(InventoryCloseEvent event); 68 | 69 | /** 70 | * this method is being triggered by the inventory click event and passes the event to 71 | * the panes of it. 72 | * 73 | * @param event event to pass 74 | * @see InventoryInteractEvent 75 | */ 76 | void accept(InventoryInteractEvent event); 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/page/TSafePage.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.page; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.inventory.InventoryCloseEvent; 7 | import org.bukkit.event.inventory.InventoryInteractEvent; 8 | import org.bukkit.inventory.Inventory; 9 | 10 | import me.blackness.black.Page; 11 | import me.blackness.black.Pane; 12 | 13 | /** 14 | * thread-safe decorator for any page. 15 | * 16 | * @author personinblack 17 | * @see Page 18 | * @since 3.1.0 19 | */ 20 | public final class TSafePage implements Page { 21 | private final Page basePage; 22 | 23 | /** 24 | * ctor. 25 | * 26 | * @param basePage the page to make thread-safe 27 | */ 28 | public TSafePage(final Page basePage) { 29 | this.basePage = Objects.requireNonNull(basePage); 30 | } 31 | 32 | @Override 33 | public void add(final Pane pane, final int position) { 34 | synchronized (basePage) { 35 | basePage.add(pane, position); 36 | } 37 | } 38 | 39 | @Override 40 | public void remove(final int position) { 41 | synchronized (basePage) { 42 | basePage.remove(position); 43 | } 44 | } 45 | 46 | @Override 47 | public void rearrange(final int paneIndex, final int position) { 48 | synchronized (basePage) { 49 | basePage.rearrange(paneIndex, position); 50 | } 51 | } 52 | 53 | @Override 54 | public void defineHolder(final Page holder) { 55 | basePage.defineHolder(holder); 56 | } 57 | 58 | @Override 59 | public void showTo(final Player player) { 60 | synchronized (basePage) { 61 | basePage.showTo(player); 62 | } 63 | } 64 | 65 | @Override 66 | public void handleClose(final InventoryCloseEvent event) { 67 | synchronized (basePage) { 68 | basePage.handleClose(event); 69 | } 70 | } 71 | 72 | @Override 73 | public void update(final Object argument) { 74 | synchronized (basePage) { 75 | basePage.update(argument); 76 | } 77 | } 78 | 79 | /** 80 | * {@inheritDoc} 81 | * @deprecated because this is against oop and we don't have a single universal inventory. 82 | */ 83 | @Override @Deprecated 84 | public Inventory getInventory() { 85 | return basePage.getInventory(); 86 | } 87 | 88 | @Override 89 | public void accept(final InventoryInteractEvent event) { 90 | synchronized (basePage) { 91 | basePage.accept(event); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/page/CloseInformerPage.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.page; 2 | 3 | import java.util.Objects; 4 | import java.util.function.Consumer; 5 | 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.inventory.InventoryCloseEvent; 8 | import org.bukkit.event.inventory.InventoryInteractEvent; 9 | import org.bukkit.inventory.Inventory; 10 | 11 | import me.blackness.black.Page; 12 | import me.blackness.black.Pane; 13 | 14 | /** 15 | * a page decorator which calls a consumer when a player closes the page. 16 | * 17 | * @author personinblack 18 | * @see Page 19 | * @see InventoryCloseEvent 20 | * @since 4.3.0 21 | */ 22 | public final class CloseInformerPage implements Page { 23 | private final Page basePage; 24 | private final Consumer consumer; 25 | 26 | /** 27 | * ctor. 28 | * 29 | * @param basePage the page which will have its close events listened 30 | * @param consumer the consumer to call when a close event gets handled 31 | */ 32 | public CloseInformerPage(final Page basePage, final Consumer consumer) { 33 | this.basePage = Objects.requireNonNull(basePage); 34 | this.consumer = Objects.requireNonNull(consumer); 35 | defineHolder(this); 36 | } 37 | 38 | @Override 39 | public void add(final Pane pane, final int position) { 40 | this.basePage.add(pane, position); 41 | } 42 | 43 | @Override 44 | public void remove(final int position) { 45 | this.basePage.remove(position); 46 | } 47 | 48 | @Override 49 | public void rearrange(final int paneIndex, final int position) { 50 | this.basePage.rearrange(paneIndex, position); 51 | } 52 | 53 | @Override 54 | public void defineHolder(final Page holder) { 55 | basePage.defineHolder(holder); 56 | } 57 | 58 | @Override 59 | public void showTo(final Player player) { 60 | this.basePage.showTo(player); 61 | } 62 | 63 | @Override 64 | public void handleClose(final InventoryCloseEvent event) { 65 | this.basePage.handleClose(event); 66 | consumer.accept((Player) event.getPlayer()); 67 | } 68 | 69 | @Override 70 | public void update(final Object argument) { 71 | basePage.update(argument); 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | * @deprecated because this is against oop and we don't have a single universal inventory. 77 | */ 78 | @Override @Deprecated 79 | public Inventory getInventory() { 80 | return basePage.getInventory(); 81 | } 82 | 83 | @Override 84 | public void accept(final InventoryInteractEvent event) { 85 | basePage.accept(event); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/Blackness.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | import java.util.Queue; 6 | import java.util.concurrent.ConcurrentLinkedQueue; 7 | 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.event.Listener; 10 | import org.bukkit.event.server.PluginDisableEvent; 11 | import org.bukkit.plugin.Plugin; 12 | 13 | import me.blackness.black.listener.InventoryClickListener; 14 | import me.blackness.black.listener.InventoryCloseListener; 15 | import me.blackness.black.listener.InventoryDragListener; 16 | import me.blackness.black.listener.PluginListener; 17 | 18 | /** 19 | * object that controls the blackness. 20 | * 21 | * @author personinblack 22 | * @since 2.0.0 23 | */ 24 | public final class Blackness { 25 | private static final Listener[] LISTENERS = { 26 | new PluginListener(new Blackness()), 27 | new InventoryClickListener(), 28 | new InventoryDragListener(), 29 | new InventoryCloseListener(), 30 | }; 31 | 32 | private static final Queue PLUGINQUEUE = new ConcurrentLinkedQueue<>(); 33 | 34 | /** 35 | * prepares the blackness for the specified plugin or adds it to the {@link #PLUGINQUEUE}. 36 | * 37 | * @param plugin plugin that needs blackness prepared 38 | * @see Plugin 39 | */ 40 | public void prepareFor(final Plugin plugin) { 41 | Objects.requireNonNull(plugin); 42 | if (PLUGINQUEUE.isEmpty()) { 43 | registerListeners(plugin); 44 | } 45 | 46 | synchronized (this) { 47 | PLUGINQUEUE.add(plugin); 48 | } 49 | } 50 | 51 | /** 52 | * this method handles every plugin disable event. 53 | * 54 | * @param event event to handle 55 | */ 56 | public void processPluginDisable(final PluginDisableEvent event) { 57 | if (!PLUGINQUEUE.peek().equals(event.getPlugin())) { 58 | synchronized (this) { 59 | PLUGINQUEUE.remove(event.getPlugin()); 60 | return; 61 | } 62 | } 63 | 64 | synchronized (this) { 65 | PLUGINQUEUE.poll(); 66 | } 67 | 68 | final Plugin nextPlugin = PLUGINQUEUE.peek(); 69 | if (nextPlugin != null && nextPlugin.isEnabled()) { 70 | registerListeners(nextPlugin); 71 | } 72 | } 73 | 74 | /** 75 | * registers all the listeners in the name of the plugin. 76 | * 77 | * @param plugin plugin 78 | * @see Plugin 79 | */ 80 | private void registerListeners(final Plugin plugin) { 81 | synchronized (this) { 82 | Arrays.stream(LISTENERS).forEach(listener -> 83 | Bukkit.getPluginManager().registerEvents(listener, plugin)); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/pane/TSafePane.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.pane; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.event.inventory.InventoryInteractEvent; 6 | import org.bukkit.inventory.Inventory; 7 | import org.bukkit.inventory.ItemStack; 8 | 9 | import me.blackness.black.Element; 10 | import me.blackness.black.Pane; 11 | import me.blackness.observer.Target; 12 | 13 | /** 14 | * thread-safe decorator for any pane. 15 | * 16 | * @author personinblack 17 | * @see Pane 18 | * @since 3.1.0 19 | */ 20 | public final class TSafePane implements Pane { 21 | private final Pane basePane; 22 | 23 | /** 24 | * ctor. 25 | * 26 | * @param basePane the pane to make thread-safe 27 | */ 28 | public TSafePane(final Pane basePane) { 29 | this.basePane = Objects.requireNonNull(basePane); 30 | } 31 | 32 | @Override 33 | public void fill(final Element element) { 34 | synchronized (basePane) { 35 | basePane.fill(element); 36 | } 37 | } 38 | 39 | @Override 40 | public void fill(final Element... elements) { 41 | synchronized (basePane) { 42 | basePane.fill(elements); 43 | } 44 | } 45 | 46 | @Override 47 | public void clear() { 48 | synchronized (basePane) { 49 | basePane.clear(); 50 | } 51 | } 52 | 53 | @Override 54 | public boolean add(final Element element) { 55 | synchronized (basePane) { 56 | return basePane.add(element); 57 | } 58 | } 59 | 60 | @Override 61 | public Element[] add(final Element... elements) { 62 | synchronized (basePane) { 63 | return basePane.add(elements); 64 | } 65 | } 66 | 67 | @Override 68 | public void insert(final Element element, final int locX, final int locY, final boolean shift) 69 | throws IllegalArgumentException { 70 | 71 | synchronized (basePane) { 72 | basePane.insert(element, locX, locY, shift); 73 | } 74 | } 75 | 76 | @Override 77 | public void replaceAll(final Element... elements) { 78 | synchronized (basePane) { 79 | basePane.replaceAll(elements); 80 | } 81 | } 82 | 83 | @Override 84 | public void remove(final int locX, final int locY) throws IllegalArgumentException { 85 | synchronized (basePane) { 86 | basePane.remove(locX, locY); 87 | } 88 | } 89 | 90 | @Override 91 | public void subscribe(final Target target) { 92 | synchronized (basePane) { 93 | basePane.subscribe(target); 94 | } 95 | } 96 | 97 | @Override 98 | public boolean contains(final ItemStack icon) { 99 | return basePane.contains(icon); 100 | } 101 | 102 | @Override 103 | public void accept(final InventoryInteractEvent event) { 104 | basePane.accept(event); 105 | } 106 | 107 | @Override 108 | public void displayOn(final Inventory inventory) { 109 | basePane.displayOn(inventory); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/element/LiveElement.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.element; 2 | 3 | import java.util.Objects; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | import org.bukkit.inventory.Inventory; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.bukkit.plugin.Plugin; 10 | import org.bukkit.scheduler.BukkitRunnable; 11 | 12 | import me.blackness.black.Element; 13 | 14 | /** 15 | * an element which takes some other elements and makes an animation out of them. 16 | * 17 | * @author personinblack 18 | * @see Element 19 | * @see BasicElement 20 | * @since 1.0.0 21 | */ 22 | public final class LiveElement implements Element { 23 | private final Plugin plugin; 24 | private final int period; 25 | private final Element[] frames; 26 | 27 | /** 28 | * ctor. 29 | * 30 | * @param plugin plugin for being used on registering bukkit tasks 31 | * @param period delay between every frame 32 | * @param frames frames to display in order 33 | */ 34 | public LiveElement(final Plugin plugin, final int period, final Element... frames) { 35 | this.plugin = Objects.requireNonNull(plugin); 36 | this.period = Objects.requireNonNull(period); 37 | this.frames = Objects.requireNonNull(frames.clone()); 38 | } 39 | 40 | private Element nullElement() { 41 | return new BasicElement(new ItemStack(Material.PAPER), "nullElement"); 42 | } 43 | 44 | private Element findFrame(final ItemStack icon) { 45 | for (final Element frame : frames) { 46 | if (frame.is(icon)) { 47 | return frame; 48 | } 49 | } 50 | 51 | return nullElement(); 52 | } 53 | 54 | private boolean contains(final Element element) { 55 | for (final Element frame : frames) { 56 | if (frame.is(element)) { 57 | return true; 58 | } 59 | } 60 | 61 | return false; 62 | } 63 | 64 | @Override 65 | public void accept(final InventoryInteractEvent event) { 66 | for (final Element frame : frames) { 67 | frame.accept(event); 68 | } 69 | } 70 | 71 | @Override 72 | public void displayOn(final Inventory inventory, final int locX, final int locY) { 73 | frames[0].displayOn(inventory, locX, locY); 74 | new BukkitRunnable() { 75 | private int iterator; 76 | 77 | @Override 78 | public void run() { 79 | if (inventory.getViewers().isEmpty()) { 80 | this.cancel(); 81 | } else { 82 | nextFrame().displayOn(inventory, locX, locY); 83 | } 84 | } 85 | 86 | private Element nextFrame() { 87 | iterator = iterator + 1 < frames.length 88 | ? iterator + 1 89 | : 0; 90 | 91 | return frames[iterator]; 92 | } 93 | }.runTaskTimer(plugin, 1, period); 94 | } 95 | 96 | @Override 97 | public boolean is(final ItemStack icon) { 98 | return findFrame(icon).is(icon); 99 | } 100 | 101 | @Override 102 | public boolean is(final Element element) { 103 | return contains(element); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | me.blackness 6 | black 7 | black 8 | 0.0.0 9 | 10 | 11 | UTF-8 12 | 1.8 13 | 1.8 14 | 8 15 | 16 | 17 | 18 | ${project.name}-${project.version} 19 | src/main/java 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-shade-plugin 24 | 3.2.4 25 | 26 | 27 | package 28 | 29 | shade 30 | 31 | 32 | 33 | 34 | true 35 | false 36 | 37 | 38 | *:* 39 | 40 | META-INF/MANIFEST.MF 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.apache.maven.plugins 48 | maven-checkstyle-plugin 49 | 3.1.2 50 | 51 | checkstyle.xml 52 | UTF-8 53 | true 54 | true 55 | false 56 | 57 | checkstyle-suppressions.xml 58 | 59 | 60 | checkstyle.suppressions.file 61 | 62 | 63 | 64 | 65 | com.puppycrawl.tools 66 | checkstyle 67 | 8.42 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | spigot-repo 77 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/ 78 | 79 | 80 | jitpack 81 | https://jitpack.io/ 82 | 83 | 84 | 85 | 86 | 87 | com.github.Personinblack 88 | observer 89 | bfb66b7c69 90 | compile 91 | 92 | 93 | org.spigotmc 94 | spigot-api 95 | 1.8.8-R0.1-SNAPSHOT 96 | provided 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/page/ChestPage.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.page; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Objects; 7 | 8 | import org.bukkit.Bukkit; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.inventory.InventoryCloseEvent; 11 | import org.bukkit.event.inventory.InventoryInteractEvent; 12 | import org.bukkit.event.inventory.InventoryType; 13 | import org.bukkit.inventory.Inventory; 14 | 15 | import me.blackness.black.Page; 16 | import me.blackness.black.Pane; 17 | 18 | /** 19 | * a page that uses an inventory of {@link InventoryType#CHEST}. 20 | * 21 | * @author personinblack 22 | * @since 1.0.0 23 | */ 24 | public final class ChestPage implements Page { 25 | private final String title; 26 | private final int size; 27 | private final List panes; 28 | private final List viewers; 29 | private Page holder; 30 | 31 | /** 32 | * ctor. 33 | * 34 | * @param title title of the page 35 | * @param size size of the page which has to be multiple of 9 36 | * @param panes panes of this page to display 37 | */ 38 | public ChestPage(final String title, final int size, final Pane... panes) { 39 | this.title = Objects.requireNonNull(title); 40 | this.size = size < 9 ? 9 : size; 41 | this.panes = new ArrayList<>(Arrays.asList(Objects.requireNonNull(panes))); 42 | this.viewers = new ArrayList<>(); 43 | this.holder = this; 44 | 45 | Arrays.stream(panes).forEach(pane -> pane.subscribe(this)); 46 | } 47 | 48 | @Override 49 | public void add(final Pane pane, final int position) { 50 | panes.add( 51 | position > panes.size() 52 | ? panes.size() 53 | : Objects.requireNonNull(position), 54 | Objects.requireNonNull(pane) 55 | ); 56 | update(new Object()); 57 | } 58 | 59 | @Override 60 | public void remove(final int position) { 61 | panes.remove(position); 62 | update(new Object()); 63 | } 64 | 65 | @Override 66 | public void rearrange(final int paneIndex, final int position) { 67 | final Pane pane = panes.get(paneIndex); 68 | panes.remove(paneIndex); 69 | panes.add( 70 | position > panes.size() ? panes.size() : position, 71 | pane 72 | ); 73 | update(new Object()); 74 | } 75 | 76 | @Override 77 | public void defineHolder(final Page holder) { 78 | this.holder = Objects.requireNonNull(holder); 79 | } 80 | 81 | @Override 82 | public void showTo(final Player player) { 83 | final Inventory inventory = Bukkit.createInventory(holder, size, title); 84 | for (final Pane pane : panes) { 85 | pane.displayOn(inventory); 86 | } 87 | player.openInventory(inventory); 88 | if (!viewers.contains(player)) { 89 | viewers.add(player); 90 | } 91 | } 92 | 93 | @Override 94 | public void handleClose(final InventoryCloseEvent event) { 95 | viewers.remove((Player) event.getPlayer()); 96 | } 97 | 98 | @Override 99 | public void update(final Object argument) { 100 | Bukkit.getScheduler().runTask( 101 | Bukkit.getPluginManager().getPlugins()[0], () -> { 102 | viewers.forEach(viewer -> { 103 | final Inventory inventory = viewer.getOpenInventory().getTopInventory(); 104 | inventory.clear(); 105 | panes.forEach(pane -> { 106 | pane.displayOn(inventory); 107 | }); 108 | }); 109 | } 110 | ); 111 | } 112 | 113 | /** 114 | * {@inheritDoc} 115 | * @deprecated because this is against oop and we don't have a single universal inventory. 116 | */ 117 | @Override @Deprecated 118 | public Inventory getInventory() { 119 | return Bukkit.createInventory(null, 9); 120 | } 121 | 122 | @Override 123 | public void accept(final InventoryInteractEvent event) { 124 | new ArrayList<>(panes).forEach(pane -> pane.accept(event)); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/Pane.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black; 2 | 3 | import org.bukkit.event.inventory.InventoryInteractEvent; 4 | import org.bukkit.inventory.Inventory; 5 | import org.bukkit.inventory.ItemStack; 6 | 7 | import me.blackness.observer.Target; 8 | 9 | /** 10 | * pane is the type of all the sections of a page which can contain elements and 11 | * display those elements on a page. 12 | * 13 | * @author personinblack 14 | * @see Page 15 | * @see Element 16 | * @since 1.0.0 17 | */ 18 | public interface Pane { 19 | /** 20 | * fills the pane with specified elements. 21 | * 22 | * @param element the element to fill the pane with 23 | * @see Element 24 | */ 25 | void fill(Element element); 26 | 27 | /** 28 | * fills the pane with specified elements. this method will reuse the elements, 29 | * if amount of elements given is not enough to fill the pane. 30 | * 31 | * @param elements the elements to fill the pane with 32 | * @see Element 33 | */ 34 | void fill(Element... elements); 35 | 36 | /** 37 | * clears the pane. 38 | */ 39 | void clear(); 40 | 41 | /** 42 | * adds a new element to the pane. 43 | * 44 | * @param element the element to add 45 | * @return {@code true} if the element has been added or 46 | * {@code false} if there was no space for it 47 | * @see Element 48 | */ 49 | boolean add(Element element); 50 | 51 | /** 52 | * adds new elements to the pane. 53 | * 54 | * @param elements the elements to add 55 | * @return an array that contains the elements which couldn't be added because of fullness or 56 | * an empty array if all the elements were added 57 | * @see Element 58 | */ 59 | Element[] add(Element... elements); 60 | 61 | /** 62 | * inserts an element to the specified slot. 63 | * 64 | * @param element the element to add 65 | * @param locX x location of the slot 66 | * @param locY y location of the slot 67 | * @param shift either shift the element that already exist at the specified location or 68 | * replace it with this one 69 | * @throws IllegalArgumentException if the specified slot is not in the range of the pane 70 | * @see Element 71 | */ 72 | void insert(Element element, int locX, int locY, boolean shift) throws IllegalArgumentException; 73 | 74 | /** 75 | * replaces all the elements of the pane with the given ones. this method will reuse 76 | * the elements, if the amount of elements given is smaller then the amount of existing ones. 77 | * 78 | * @param elements elements to fill the pane with 79 | * @see Element 80 | */ 81 | void replaceAll(Element... elements); 82 | 83 | /** 84 | * removes the element at the specified slot. 85 | * 86 | * @param locX x location of the slot 87 | * @param locY y location of the slot 88 | * @throws IllegalArgumentException if the specified slot is not in the range of the pane 89 | */ 90 | void remove(int locX, int locY) throws IllegalArgumentException; 91 | 92 | /** 93 | * subscribe to the pane to get updated when it is updated. 94 | * 95 | * @param target the target that wants to subscribe 96 | * @see Target 97 | */ 98 | void subscribe(Target target); 99 | 100 | /** 101 | * compares specified icon with icons of this pane's elements'. 102 | * 103 | * @param icon the itemstack to compare 104 | * @return {@code true} if this pane contains an element with specified icon or 105 | * {@code false} otherwise 106 | */ 107 | boolean contains(ItemStack icon); 108 | 109 | /** 110 | * this method is being triggered by the page which contains this pane then 111 | * the pane passes this event to its elements. 112 | * 113 | * @param event event to pass 114 | * @see InventoryInteractEvent 115 | */ 116 | void accept(InventoryInteractEvent event); 117 | 118 | /** 119 | * display this pane on the specified inventory. this method is being triggered by the page 120 | * which contains this pane and being passed to the underlying elements of this pane. 121 | * 122 | * @param inventory inventory to display this pane on 123 | * @see Inventory 124 | */ 125 | void displayOn(Inventory inventory); 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/element/BasicElement.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.element; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Objects; 6 | import java.util.UUID; 7 | 8 | import org.bukkit.ChatColor; 9 | import org.bukkit.Material; 10 | import org.bukkit.event.inventory.InventoryInteractEvent; 11 | import org.bukkit.inventory.Inventory; 12 | import org.bukkit.inventory.ItemStack; 13 | import org.bukkit.inventory.meta.ItemMeta; 14 | 15 | import me.blackness.black.Element; 16 | import me.blackness.black.Requirement; 17 | import me.blackness.black.Target; 18 | import me.blackness.black.req.AddedElementReq; 19 | import me.blackness.black.req.ClickedElementReq; 20 | import me.blackness.black.req.DragReq; 21 | import me.blackness.black.req.OrReq; 22 | 23 | /** 24 | * an element that has all the basic stuff. 25 | * 26 | * @author personinblack 27 | * @see Element 28 | * @since 1.0.0 29 | */ 30 | public final class BasicElement implements Element { 31 | private final String id; 32 | private final ItemStack icon; 33 | private final Target[] targets; 34 | private final Requirement elementReq; 35 | 36 | /** 37 | * ctor. 38 | * 39 | * @param icon an icon to represent this element 40 | * @param id id of this element. should be unique 41 | * @param targets targets of this element 42 | */ 43 | public BasicElement(final ItemStack icon, final String id, final Target... targets) { 44 | this.icon = encrypted(Objects.requireNonNull(icon), Objects.requireNonNull(id)); 45 | this.id = id; 46 | this.targets = Objects.requireNonNull(targets.clone()); 47 | elementReq = new OrReq( 48 | new ClickedElementReq(this), 49 | icon.getType() == Material.AIR 50 | ? new DragReq() 51 | : new AddedElementReq(this) 52 | ); 53 | } 54 | 55 | /** 56 | * ctor. 57 | * 58 | * @param icon an icon to represent this element 59 | * @param targets targets of this element 60 | */ 61 | public BasicElement(final ItemStack icon, final Target... targets) { 62 | this(icon, UUID.randomUUID().toString() + System.currentTimeMillis(), targets); 63 | } 64 | 65 | /** 66 | * ctor. 67 | * 68 | * @param icon an icon to represent this element 69 | * @param id id of this element. should be unique 70 | */ 71 | public BasicElement(final ItemStack icon, final String id) { 72 | this(icon, id, new Target[0]); 73 | } 74 | 75 | /** 76 | * ctor. 77 | * 78 | * @param icon an icon to represent this element 79 | */ 80 | public BasicElement(final ItemStack icon) { 81 | this(icon, new Target[0]); 82 | } 83 | 84 | private ItemStack encrypted(final ItemStack itemStack, final String textToEncrypt) { 85 | if (itemStack.getType() == Material.AIR) { 86 | return itemStack; 87 | } 88 | 89 | final ItemMeta itemMeta = itemStack.getItemMeta(); 90 | final List lore = itemMeta.getLore() == null 91 | ? new ArrayList<>() 92 | : itemMeta.getLore(); 93 | lore.add(encrypted(textToEncrypt)); 94 | itemMeta.setLore(lore); 95 | 96 | final ItemStack encryptedItem = itemStack.clone(); 97 | encryptedItem.setItemMeta(itemMeta); 98 | return encryptedItem; 99 | } 100 | 101 | private String encrypted(final String textToEncrypt) { 102 | final StringBuilder encryptedText = new StringBuilder(); 103 | for (final char ch : textToEncrypt.toCharArray()) { 104 | encryptedText.append(ChatColor.COLOR_CHAR).append(ch); 105 | } 106 | return encryptedText.toString(); 107 | } 108 | 109 | private String decrypted(final ItemStack itemStack) throws IllegalArgumentException { 110 | if (itemStack.getType() == Material.AIR) { 111 | return ""; 112 | } else if (itemStack.hasItemMeta() && itemStack.getItemMeta().hasLore()) { 113 | final List lore = itemStack.getItemMeta().getLore(); 114 | return lore.get(lore.size() - 1).replace(String.valueOf(ChatColor.COLOR_CHAR), ""); 115 | } else { 116 | throw new IllegalArgumentException( 117 | "The itemStack couldn't be decrypted because it has no lore\n" + 118 | itemStack 119 | ); 120 | } 121 | } 122 | 123 | @Override 124 | public void displayOn(final Inventory inventory, final int locX, final int locY) { 125 | inventory.setItem(locX + locY * 9, icon.clone()); 126 | } 127 | 128 | @Override 129 | public void accept(final InventoryInteractEvent event) { 130 | if (elementReq.control(event)) { 131 | for (final Target target : targets) { 132 | target.handle(event); 133 | } 134 | } 135 | } 136 | 137 | @Override 138 | public boolean is(final ItemStack itemStack) { 139 | if (itemStack.getType() == Material.AIR && icon.getType() == Material.AIR) { 140 | return true; 141 | } 142 | 143 | try { 144 | return decrypted(itemStack).equals(id); 145 | } catch (IllegalArgumentException ex) { 146 | return false; 147 | } 148 | } 149 | 150 | @Override 151 | public boolean is(final Element element) { 152 | if (element instanceof BasicElement) { 153 | return is(((BasicElement) element).icon); 154 | } else { 155 | return false; 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/pane/LivePane.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.pane; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | 6 | import org.bukkit.event.inventory.InventoryInteractEvent; 7 | import org.bukkit.inventory.Inventory; 8 | import org.bukkit.inventory.ItemStack; 9 | import org.bukkit.plugin.Plugin; 10 | import org.bukkit.scheduler.BukkitRunnable; 11 | 12 | import me.blackness.black.Element; 13 | import me.blackness.black.Pane; 14 | import me.blackness.observer.Target; 15 | 16 | /** 17 | * a pane which takes some other panes and makes an animation out of them. 18 | * 19 | * @author personinblack 20 | * @see Pane 21 | * @see BasicPane 22 | * @since 1.0.3 23 | */ 24 | public final class LivePane implements Pane { 25 | private final Plugin plugin; 26 | private final int period; 27 | private final Pane[] frames; 28 | 29 | /** 30 | * ctor. 31 | * 32 | * @param plugin plugin for being used on registering bukkit tasks 33 | * @param period delay between every frame 34 | * @param frames frames to display in order 35 | */ 36 | public LivePane(final Plugin plugin, final int period, final Pane... frames) { 37 | this.plugin = Objects.requireNonNull(plugin); 38 | this.period = Objects.requireNonNull(period); 39 | this.frames = Objects.requireNonNull(frames.clone()); 40 | } 41 | 42 | /** 43 | * {@inheritDoc} 44 | * 45 | * @see #fill(int, Element) 46 | */ 47 | @Override 48 | public void fill(final Element element) { 49 | for (final Pane frame : frames) { 50 | frame.fill(element); 51 | } 52 | } 53 | 54 | /** 55 | * fills the specified pane with specified elements. 56 | * 57 | * @param frame the frame number of the pane to fill 58 | * @param element the element to fill the pane with 59 | * @see Element 60 | */ 61 | public void fill(final int frame, final Element element) { 62 | frames[frame].fill(element); 63 | } 64 | 65 | /** 66 | * {@inheritDoc} 67 | * 68 | * @see #fill(int, Element...) 69 | */ 70 | @Override 71 | public void fill(final Element... elements) { 72 | for (final Pane frame : frames) { 73 | frame.fill(elements); 74 | } 75 | } 76 | 77 | /** 78 | * fills the specified pane with specified elements. this method will reuse the elements, 79 | * if amount of elements given is not enough to fill the pane. 80 | * 81 | * @param frame the frame number of the pane to fill 82 | * @param elements the elements to fill the pane with 83 | * @see Element 84 | */ 85 | public void fill(final int frame, final Element... elements) { 86 | frames[frame].fill(elements); 87 | } 88 | 89 | @Override 90 | public void clear() { 91 | for (final Pane frame : frames) { 92 | frame.clear(); 93 | } 94 | } 95 | 96 | @Override 97 | public boolean add(final Element element) { 98 | for (final Pane frame : frames) { 99 | if (frame.add(element)) { 100 | return true; 101 | } 102 | } 103 | 104 | return false; 105 | } 106 | 107 | @Override 108 | public Element[] add(final Element... elements) { 109 | Element[] leftOvers = elements; 110 | for (final Pane frame : frames) { 111 | leftOvers = frame.add(leftOvers); 112 | if (leftOvers.length == 0) { 113 | break; 114 | } 115 | } 116 | 117 | return leftOvers; 118 | } 119 | 120 | /** 121 | * {@inheritDoc} 122 | * 123 | * @deprecated because you have to specify which frame 124 | * @see #insert(int, Element, int, int, boolean) 125 | */ 126 | @Override @Deprecated 127 | public void insert(final Element element, final int locX, final int locY, 128 | final boolean shift) throws IllegalArgumentException { 129 | 130 | // this method is useless because you have to specify the frame to insert an element 131 | } 132 | 133 | /** 134 | * inserts an element to the specified slot of the specified frame. 135 | * 136 | * @param frame the frame which will get the specified element 137 | * @param element the element to add 138 | * @param locX x location of the slot 139 | * @param locY y location of the slot 140 | * @param shift either shift the element that already exist at the specified location or 141 | * replace it with this one 142 | * @throws IllegalArgumentException if the specified slot is not in the range of the pane 143 | * @see Element 144 | */ 145 | public void insert(final int frame, final Element element, final int locX, final int locY, 146 | final boolean shift) throws IllegalArgumentException { 147 | 148 | frames[frame].insert(element, locX, locY, shift); 149 | } 150 | 151 | /** 152 | * {@inheritDoc} 153 | * 154 | * @see #replaceAll(int, Element...) 155 | */ 156 | @Override 157 | public void replaceAll(final Element... elements) { 158 | for (final Pane frame : frames) { 159 | frame.replaceAll(elements); 160 | } 161 | } 162 | 163 | /** 164 | * replaces all the elements of the said frame with the given ones. this method will reuse 165 | * the elements, if the amount of elements given is smaller then the amount of existing ones. 166 | * 167 | * @param frame the frame number of the pane to replace all 168 | * @param elements elements to fill the pane with 169 | * @see Element 170 | */ 171 | public void replaceAll(final int frame, final Element... elements) { 172 | frames[frame].replaceAll(elements); 173 | } 174 | 175 | /** 176 | * {@inheritDoc} 177 | * 178 | * @deprecated because you have to specify which frame 179 | * @see #remove(int, int, int) 180 | */ 181 | @Override @Deprecated 182 | public void remove(final int locX, final int locY) throws IllegalArgumentException { 183 | // this method is useless because you have to specify the frame to remove an element 184 | } 185 | 186 | /** 187 | * removes the element at the specified slot from the specified frame. 188 | * 189 | * @param frame the frame which will get the specified slot of it cleared 190 | * @param locX x location of the slot 191 | * @param locY y location of the slot 192 | * @throws IllegalArgumentException if the specified slot is not in the range of the pane 193 | */ 194 | public void remove(final int frame, final int locX, final int locY) 195 | throws IllegalArgumentException { 196 | 197 | frames[frame].remove(locX, locY); 198 | } 199 | 200 | @Override 201 | public void subscribe(final Target target) { 202 | Arrays.stream(frames).forEach(frame -> frame.subscribe(target)); 203 | } 204 | 205 | @Override 206 | public boolean contains(final ItemStack icon) { 207 | for (final Pane frame : frames) { 208 | if (frame.contains(icon)) { 209 | return true; 210 | } 211 | } 212 | 213 | return false; 214 | } 215 | 216 | @Override 217 | public void accept(final InventoryInteractEvent event) { 218 | for (final Pane frame : frames) { 219 | frame.accept(event); 220 | } 221 | } 222 | 223 | @Override 224 | public void displayOn(final Inventory inventory) { 225 | frames[0].displayOn(inventory); 226 | 227 | new BukkitRunnable() { 228 | private int iterator; 229 | 230 | @Override 231 | public void run() { 232 | if (inventory.getViewers().isEmpty()) { 233 | this.cancel(); 234 | } else { 235 | nextFrame().displayOn(inventory); 236 | } 237 | } 238 | 239 | private Pane nextFrame() { 240 | iterator = iterator + 1 < frames.length 241 | ? iterator + 1 242 | : 0; 243 | 244 | return frames[iterator]; 245 | } 246 | }.runTaskTimer(plugin, 1, period); 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /src/main/java/me/blackness/black/pane/BasicPane.java: -------------------------------------------------------------------------------- 1 | package me.blackness.black.pane; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.LinkedList; 6 | import java.util.Objects; 7 | import java.util.Queue; 8 | import java.util.function.BiConsumer; 9 | import java.util.function.BiFunction; 10 | 11 | import org.bukkit.Bukkit; 12 | import org.bukkit.Material; 13 | import org.bukkit.event.inventory.InventoryInteractEvent; 14 | import org.bukkit.inventory.Inventory; 15 | import org.bukkit.inventory.ItemStack; 16 | 17 | import me.blackness.black.Element; 18 | import me.blackness.black.Pane; 19 | import me.blackness.black.element.BasicElement; 20 | import me.blackness.black.req.SlotReq; 21 | import me.blackness.observer.Source; 22 | import me.blackness.observer.Target; 23 | import me.blackness.observer.source.BasicSource; 24 | 25 | /** 26 | * a pane that has all the basic stuff. 27 | * 28 | * @author personinblack 29 | * @see Pane 30 | * @since 1.0.0 31 | */ 32 | public final class BasicPane implements Pane { 33 | private static final String LOC_OUT = 34 | "The specified location [%s][%s] is out of bounds"; 35 | 36 | private final Source source; 37 | 38 | private final Element[][] paneElements; 39 | private final int locX; 40 | private final int locY; 41 | 42 | /** 43 | * ctor. 44 | * 45 | * @param locX the x location of the top left corner of this pane 46 | * @param locY the y location of the top left corner of this pane 47 | * @param height height of this pane 48 | * @param length length of this pane 49 | */ 50 | public BasicPane(final int locX, final int locY, final int height, final int length) { 51 | source = new BasicSource<>(); 52 | this.locX = locX; 53 | this.locY = locY; 54 | paneElements = new Element[height][length]; 55 | clear(); 56 | } 57 | 58 | /** 59 | * ctor. 60 | * 61 | * @param locX the x location of the top left corner of this pane 62 | * @param locY the y location of the top left corner of this pane 63 | * @param height height of this pane 64 | * @param length length of this pane 65 | * @param element element to fill the pane with 66 | * 67 | * @see #replaceAll(Element...) 68 | */ 69 | public BasicPane(final int locX, final int locY, final int height, final int length, 70 | final Element element) { 71 | 72 | this(locX, locY, height, length); 73 | replaceAll(Objects.requireNonNull(element)); 74 | } 75 | 76 | /** 77 | * ctor. 78 | * 79 | * @param locX the x location of the top left corner of this pane 80 | * @param locY the y location of the top left corner of this pane 81 | * @param height height of this pane 82 | * @param length length of this pane 83 | * @param elements elements to be added to the pane 84 | * 85 | * @see #add(Element...) 86 | */ 87 | public BasicPane(final int locX, final int locY, final int height, final int length, 88 | final Element... elements) { 89 | 90 | this(locX, locY, height, length); 91 | add(elements); 92 | } 93 | 94 | private int length() { 95 | return paneElements[0].length; 96 | } 97 | 98 | private int height() { 99 | return paneElements.length; 100 | } 101 | 102 | private Element emptyElement() { 103 | return new BasicElement( 104 | new ItemStack(Material.TNT), "emptyElement" 105 | ); 106 | } 107 | 108 | private void validate(final int inventorySize) throws IllegalArgumentException { 109 | final boolean locXFaulty = locX < 0; 110 | final boolean locYFaulty = locY < 0; 111 | final boolean heightFaulty = locY + height() > inventorySize / 9 || height() <= 0; 112 | final boolean lengthFaulty = locX + length() > 9 || length() <= 0; 113 | if (locXFaulty || locYFaulty || heightFaulty || lengthFaulty) { 114 | throw new IllegalArgumentException( 115 | String.format( 116 | "Validation for the newest created Pane failed.%n" + 117 | "locX (%s) is faulty: %s, locY (%s) is faulty: %s, " + 118 | "height (%s) is faulty: %s, length (%s) is faulty: %s", 119 | locX, locXFaulty, locY, locYFaulty, height(), heightFaulty, length(), 120 | lengthFaulty 121 | ) 122 | ); 123 | } 124 | } 125 | 126 | private boolean isWithinBounds(final int xToCheck, final int yToCheck) { 127 | return xToCheck < length() && yToCheck < height() && xToCheck >= 0 && yToCheck >= 0; 128 | } 129 | 130 | private void shiftElementAt(final int xToShift, final int yToShift) { 131 | for (int y = height() - 1; y >= 0; y--) { 132 | for (int x = length() - 1; x >= 0; x--) { 133 | if (y < yToShift || y == yToShift && x < xToShift) { 134 | continue; 135 | } else if (x + 1 < length()) { 136 | paneElements[y][x + 1] = paneElements[y][x]; 137 | } else if (y + 1 < height()) { 138 | paneElements[y + 1][0] = paneElements[y][x]; 139 | } 140 | } 141 | } 142 | 143 | paneElements[yToShift][xToShift] = emptyElement(); 144 | } 145 | 146 | private boolean forEachSlot(final BiFunction action) { 147 | for (int y = 0; isWithinBounds(0, y); y++) { 148 | for (int x = 0; isWithinBounds(x, y); x++) { 149 | if (action.apply(y, x)) { 150 | return true; 151 | } 152 | } 153 | } 154 | return false; 155 | } 156 | 157 | private void forEachSlot(final BiConsumer action) { 158 | forEachSlot((y, x) -> { 159 | action.accept(y, x); 160 | return false; 161 | }); 162 | } 163 | 164 | @Override 165 | public void fill(final Element element) { 166 | fill(new Element[]{Objects.requireNonNull(element)}); 167 | this.source.notifyTargets(new Object()); 168 | } 169 | 170 | @Override 171 | public void fill(final Element... elements) { 172 | final Queue queue = new LinkedList<>( 173 | Arrays.asList(Objects.requireNonNull(elements)) 174 | ); 175 | forEachSlot((y, x) -> { 176 | if (queue.isEmpty()) { 177 | queue.addAll(Arrays.asList(elements)); 178 | } 179 | if (paneElements[y][x].is(emptyElement())) { 180 | paneElements[y][x] = queue.poll(); 181 | } 182 | }); 183 | this.source.notifyTargets(new Object()); 184 | } 185 | 186 | @Override 187 | public void clear() { 188 | replaceAll(emptyElement()); 189 | } 190 | 191 | @Override 192 | public boolean add(final Element element) { 193 | return forEachSlot((y, x) -> { 194 | if (paneElements[y][x].is(emptyElement())) { 195 | paneElements[y][x] = Objects.requireNonNull(element); 196 | this.source.notifyTargets(new Object()); 197 | return true; 198 | } else { 199 | return false; 200 | } 201 | }); 202 | } 203 | 204 | @Override 205 | public Element[] add(final Element... elements) { 206 | final ArrayList remainings = new ArrayList<>(); 207 | for (final Element element : Objects.requireNonNull(elements)) { 208 | if (!add(element)) { 209 | remainings.add(element); 210 | } 211 | } 212 | return remainings.toArray(new Element[0]); 213 | } 214 | 215 | @Override 216 | public void insert(final Element element, final int locX, final int locY, 217 | final boolean shift) throws IllegalArgumentException { 218 | 219 | if (isWithinBounds(locX, locY)) { 220 | if (shift && !paneElements[locY][locX].is(emptyElement())) { 221 | shiftElementAt(locX, locY); 222 | } 223 | paneElements[locY][locX] = Objects.requireNonNull(element); 224 | } else { 225 | throw new IllegalArgumentException( 226 | String.format( 227 | LOC_OUT, 228 | locX, locY 229 | ) 230 | ); 231 | } 232 | this.source.notifyTargets(new Object()); 233 | } 234 | 235 | @Override 236 | public void replaceAll(final Element... elements) { 237 | final Queue queue = new LinkedList<>( 238 | Arrays.asList(Objects.requireNonNull(elements)) 239 | ); 240 | forEachSlot((y, x) -> { 241 | if (queue.isEmpty()) { 242 | queue.addAll(Arrays.asList(elements)); 243 | } 244 | paneElements[y][x] = queue.poll(); 245 | }); 246 | this.source.notifyTargets(new Object()); 247 | } 248 | 249 | @Override 250 | public void remove(final int locX, final int locY) throws IllegalArgumentException { 251 | if (isWithinBounds(locX, locY)) { 252 | paneElements[locY][locX] = emptyElement(); 253 | this.source.notifyTargets(new Object()); 254 | } else { 255 | throw new IllegalArgumentException( 256 | String.format( 257 | LOC_OUT, 258 | locX, locY 259 | ) 260 | ); 261 | } 262 | } 263 | 264 | @Override 265 | public void subscribe(final Target target) { 266 | source.subscribe(Objects.requireNonNull(target)); 267 | } 268 | 269 | @Override 270 | public boolean contains(final ItemStack icon) { 271 | return forEachSlot((y, x) -> { 272 | return paneElements[y][x].is(icon); 273 | }); 274 | } 275 | 276 | @Override 277 | public void accept(final InventoryInteractEvent event) { 278 | forEachSlot((y, x) -> { 279 | if (new SlotReq(locX + x + (locY + y) * 9).control(event)) { 280 | paneElements[y][x].accept(event); 281 | } 282 | }); 283 | } 284 | 285 | @Override 286 | public void displayOn(final Inventory inventory) { 287 | try { 288 | validate(inventory.getSize()); 289 | } catch (IllegalArgumentException ex) { 290 | Bukkit.getLogger().severe(ex.toString()); 291 | return; 292 | } 293 | forEachSlot((y, x) -> { 294 | final Element element = paneElements[y][x]; 295 | if (!element.is(emptyElement())) { 296 | element.displayOn(inventory, locX + x, locY + y); 297 | } 298 | }); 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # black 2 | 3 | [![jitpack](https://jitpack.io/v/Personinblack/black.svg)](https://jitpack.io/#Personinblack/black) 4 | 5 | black is an extensive and object-oriented inventory framework designed for spigot. 6 | 7 | [a live demonstration of how black works (outdated atm)](https://my.mixtape.moe/vemebo.webm) 8 | 9 | with black you can: 10 | 11 | - create infinite amount of pages 12 | - link those pages 13 | - have panes inside pages for dividing your pages into sections 14 | - layer those panes however you like (for like having a background pane below other panes) 15 | - create animated elements with changing actions and icons 16 | 17 | black does not contain: 18 | 19 | - `static` but not `private` variables 20 | - getters and setters 21 | - `static` methods 22 | - `null` references 23 | - `extends` keyword on anything other than interfaces 24 | - mutable objects 25 | - any object without a purpose to live (data objects for example) 26 | - any method that has more than one purpose 27 | - any not `final` but `public` method without `@Override` annotation 28 | 29 | in black, elements creates panes and panes creates pages. 30 | later on those pages can be showed to players. 31 | 32 | --- 33 | 34 | ## how can i use this 35 | 36 | before anything else, you have to prepare the blackness. you can do that by saying 37 | `new Blackness().prepareFor(yourPluginInstance);` inside your onEnable method. 38 | 39 | this is required because black needs to register events for your inventories. 40 | 41 | also check out the *working with build tools* section. 42 | 43 | ### now lets create some elements 44 | 45 | an element is an object that can be placed inside a pane. you can think of elements as buttons but they 46 | are not just handling clicks; they can be used for decorating your inventories too. they determine 47 | how your inventories look and how they behave. 48 | 49 | black comes with two element objects, `BasicElement` and `LiveElement`. 50 | 51 | basic element is the simplest element. it asks for an icon (`ItemStack`) and 52 | some targets (`Target`). 53 | 54 | you should already know what an `ItemStack` is but what you may don't know is the `Target`. 55 | `Target`s are your event handlers; they take events, run them through their `Requirement`s and 56 | do stuff according to the `Requirement`s' output. 57 | 58 | take a look at this example: 59 | 60 | ```java 61 | final Element myFirstElement = new BasicElement( 62 | new ItemStack(Material.APPLE), // this is the icon 63 | // this is a target which requires you to click on the apple with your keyboard button 1. 64 | new ClickTarget(event -> { 65 | event.player().sendMessage("you have clicked on the apple using the hotbar button 1"); 66 | }, new HotbarButtonReq(1)), 67 | // and this is a target which only requires a drag event to be happened. 68 | new DragTarget(event -> { 69 | event.player().sendMessage("you have dragged more apples to the apple and apple sucks"); 70 | }), 71 | // finally this is just a basic target, which can handle both clicks and drags. 72 | new BasicTarget(event -> { 73 | // let's just cancel all of them. 74 | event.cancel(); 75 | }) 76 | ); 77 | ``` 78 | 79 | live element is a group of elements (you can use your custom elements or basic elements). 80 | what it does is it loops through every element you gave to it and displays them in the order 81 | you gave with the amount of period you specified in between. 82 | 83 | here is an example live element: 84 | 85 | ```java 86 | // this is the element we created earlier. 87 | final Element myFirstElement = theElementWeCreatedEarlier(); 88 | 89 | // another basic element. 90 | final Element mySecondElement = new BasicElement( 91 | new ItemStack(Material.AIR), 92 | new BasicTarget(ElementBasicEvent::cancel) // canceling all the events in a compact way. 93 | ); 94 | 95 | // this is your plugin instance. 96 | final Plugin myPlugin = 97 | Bukkit.getPluginManager().getPlugin("myPluginsName"); 98 | 99 | // live element inside live element??!!? 100 | final Element myThirdElement = new LiveElement( 101 | myPlugin, 102 | 5, 103 | myFirstElement, mySecondElement 104 | ); 105 | 106 | /* 107 | myPlugin is your plugin instance, 108 | 20 is the delay between each animation frame and 109 | elements are the frames in order. 110 | */ 111 | final Element mySecondLiveElement = new LiveElement( 112 | myPlugin, 113 | 20, 114 | myFirstElement, mySecondElement, myThirdElement 115 | ); 116 | ``` 117 | 118 | ***you can't and you shouldn't***: 119 | 120 | - edit any element after its creation. you can always create a new one and update your panes with it. 121 | - get any information from an element. (like its icon's display name) 122 | 123 | if you are asking the question `but why the f***??!!?`, check out `encapsulation`. 124 | 125 | ### then create some panes 126 | 127 | a pane is a group of elements that has a size (height and length) 128 | and a position (x and y locations). panes can be stacked on top of each other 129 | like layers, inside pages. 130 | 131 | there are two pane objects that comes with black. those are `BasicPane` and `LivePane`. 132 | 133 | basic pane is the simplest pane. it asks for a x location (`int`), a y location (`int`), 134 | a height (`int`) and a length (`int`). 135 | 136 | need an example? here it comes... 137 | 138 | ```java 139 | final Element backgroundElement = new BasicElement( 140 | new ItemStack(Material.STAINED_GLASS_PANE), 141 | new BasicTarget(ElementBasicEvent::cancel) 142 | ); 143 | 144 | // this is just a list, nothing fancy or 145 | // relevant to the topic. 146 | final List playerHeads = 147 | new PlayerHeads(PlayerType.STAFF); 148 | 149 | final Element exitButton = new BasicElement( 150 | new ItemStack(Material.BARRIER), 151 | new BasicTarget(event -> { 152 | event.cancel(); 153 | event.closeView(); 154 | }) 155 | ); 156 | 157 | /* 158 | first two integers are x and y locations, 159 | second two integers are height and length 160 | and the last parameter is the element to 161 | fill the pane with. 162 | 163 | if you insert multiple elements, they will 164 | be added to the pane just like when you call 165 | the add method. 166 | */ 167 | final Pane myFirstPane = new BasicPane( 168 | 0, 0, // x and y locations 169 | 1, 1, // height and length 170 | backgroundElement // an element to fill the pane with 171 | ); 172 | 173 | final Pane mySecondPane = new BasicPane( 174 | 0, 0, 175 | 6, 9 176 | ); 177 | 178 | // looping through every player head in the list above 179 | // and adding them to the second pane one by one. 180 | playerHeads.forEach(mySecondPane::add); 181 | 182 | /* 183 | 4 is the x location (center), 184 | 5 is the y location (bottom) 185 | true is for shifting any other element that could be 186 | at that location. if there is an element at the end 187 | it will be vanished. 188 | */ 189 | mySecondPane.insert( 190 | exitButton, 191 | 4, 5 192 | true 193 | ); 194 | ``` 195 | 196 | live pane is the animated version of the basic pane you can create out of basic panes. 197 | its using the same concept as the live element so i am not going to write an example for it. 198 | 199 | ### and finally the page 200 | 201 | a page is combination of panes or just one pane in a way that can be displayed on an inventory. 202 | you can build one with a title (`String`), a size (`int`) and the panes to be displayed. 203 | 204 | black only has one page object and that is the chest page but you can create 205 | your own custom pages later. 206 | 207 | here is an example chest page in case you need one: 208 | 209 | ```java 210 | // panes from the previous example 211 | final Pane myFirstPane = 212 | retriveTheFirstPane(); 213 | final Pane mySecondPane = 214 | retriveTheSecondPane(); 215 | 216 | /* 217 | we inserted the first pane before the 218 | second pane because, first pane is the 219 | background pane and has to appear before 220 | the second pane so second pane can be 221 | on top of it. 222 | */ 223 | final Page thePage = new ChestPage( 224 | "Staff List", 54, 225 | myFirstPane, mySecondPane 226 | ); 227 | 228 | thePage.showTo( 229 | Bukkit.getPlayerExact("Personinblack") 230 | ); 231 | ``` 232 | 233 | --- 234 | 235 | ## what is this decorator pattern thingy 236 | 237 | decorator pattern is one of the best design patterns for object-oriented 238 | programming i have ever seen. it replaces the bad keyword called "extends", makes 239 | your code composable and much more flexible than before. 240 | 241 | wanna know how it works? well, do you remember the `LiveElement` stuff and how we have bunch of `BasicElement`s inside it? that is the decorator pattern. in this example we are decorating the 242 | `BasicElement`s and making them live: 243 | 244 | ```java 245 | final ItemStack frame1 = new ItemStack(Material.STONE); 246 | final ItemStack frame2 = new ItemStack(Material.SPONGE); 247 | 248 | final Element liveElement = new LiveElement(this, 20, 249 | new BasicElement(frame1, new BasicTarget(event -> { 250 | event.cancel(); 251 | event.player().sendMessage("this is frame 1"); 252 | })), 253 | new BasicElement(frame2, new BasicTarget(event -> { 254 | event.cancel(); 255 | event.player().sendMessage("and this is frame 2"); 256 | })) 257 | ); 258 | ``` 259 | 260 | so, the `LiveElement` asks for two `Element`s to work with. you can insert another `LiveElement` 261 | but this `LiveElement` will also ask you for an `Element`. this makes sure that you will always 262 | end up with a `BasicElement` (or your own `BasicElement` clone). `LiveElement` itself does not 263 | reimplement the methods that already exists in `BasicElement` but it extends them. for example 264 | the `displayOn` method of the `LiveElement` is calling `displayOn` methods of every frame 265 | one by one. 266 | 267 | you should now have the basic knowledge about how decorator pattern works. and you may want to 268 | extend `BasicElement` or `LiveElement`'s usage by yourself too. let's see how you can do that: 269 | 270 | ```java 271 | final class CustomElement implements Element { 272 | private final Element baseElement; 273 | 274 | public CustomElement(final Element baseElement) { 275 | this.baseElement = Objects.requireNonNull(baseElement); 276 | } 277 | 278 | @Override 279 | public void displayOn(final Inventory inventory, final int locX, final int locY) { 280 | baseElement.displayOn(inventory, locX, locY); 281 | } 282 | 283 | @Override 284 | public void accept(final InventoryInteractEvent event) { 285 | baseElement.accept(event); 286 | } 287 | 288 | @Override 289 | public boolean is(final ItemStack icon) { 290 | return baseElement.is(Objects.requireNonNull(icon)); 291 | } 292 | 293 | @Override 294 | public boolean is(final Element element) { 295 | return baseElement.is(Objects.requireNonNull(element)); 296 | } 297 | } 298 | ``` 299 | 300 | first things first, we have an `Element` as a parameter thats called `baseElement`. this element 301 | is what we are decorating. we are calling its methods inside our `CustomElement`'s methods. 302 | this is important, we are not recoding the methods of `baseElement`, we are just extending them. 303 | 304 | but hey! there is nothing custom here at the moment. so if you do something like this: 305 | 306 | ```java 307 | final Element liveElement = new LiveElement(/*the parameters*/); 308 | final Element customElement = new CustomElement(liveElement); 309 | ``` 310 | 311 | the `customElement` will act just like the `liveElement`. 312 | 313 | so you have to customize this `CustomElement` and make it yours! compare `LiveElement` and 314 | `BasicElement` to see how you can customize your `CustomElement`. 315 | 316 | --- 317 | 318 | ## working with build tools 319 | 320 | you probably will want to use black with a build tool to shade it into your projects. 321 | since i'm only familiar with `gradle` i will give an example for it. if any of you reading this 322 | have knowledge about any other build tools, you can create a pull request and submit an example. 323 | 324 | ### gradle 325 | 326 | so you want to use black with gradle and don't know where to start huh? 327 | don't worry i got you covered. 328 | 329 | first of all we need the gradle plugin called `shadow`. it can shade in any dependencies you have 330 | into your jar files. we can set it up like this: 331 | 332 | build.gradle 333 | 334 | ```groovy 335 | plugins { id "com.github.johnrengelman.shadow" version "2.0.3" } 336 | 337 | shadowJar { 338 | baseName = '' 339 | classifier = null 340 | } 341 | 342 | build.dependsOn shadowJar 343 | ``` 344 | 345 | so what do we have here? we have the `build` task depending on the `shadowJar` task. by having that, 346 | when we run the `build` task it will automatically run the `shadowJar` task. thats great! 347 | we also have a `shadowJar` scope to configure the task. inside the scope we are giving a name to 348 | our jar file and removing the `classifier`. you can also modify the `version` too if you want or 349 | set it to *null* just like the `classifier`. 350 | 351 | the plugins scope we have in the example, won't work if you are under gradle version 2.1. 352 | so you have to do this: 353 | 354 | build.gradle 355 | 356 | ```groovy 357 | buildscript { 358 | repositories { 359 | jcenter() 360 | } 361 | dependencies { 362 | classpath 'com.github.jengelman.gradle.plugins:shadow:' 363 | } 364 | } 365 | 366 | apply plugin: 'com.github.johnrengelman.shadow' 367 | ``` 368 | 369 | it just adds the `shadow` plugin to your project. 370 | 371 | we are done with the `shadow` and we can now add the `jitpack` repository to the project. 372 | this is pretty easy, just do this: 373 | 374 | build.gradle 375 | 376 | ```groovy 377 | repositories { 378 | // there probably will be bunch of other repositories too like spigot. 379 | maven { url 'https://jitpack.io' } 380 | } 381 | ``` 382 | 383 | last step! adding and configuring dependencies... 384 | 385 | build.gradle 386 | 387 | ```groovy 388 | compileOnly group: 'org.spigotmc', name: 'spigot-api', version: '' 389 | compile group: 'com.github.Personinblack', name: 'black', version: '' 390 | ``` 391 | 392 | i included the `spigot-api` dependency in here for a reason. did you notice the difference between 393 | the two dependencies? yes, the `spigot-api` does have `compileOnly`. but what does it mean? well, 394 | it means that we don't want to shade `spigot-api` into our jar file because our server already 395 | have it. `shadow` will see that and ignore the `spigot-api` dependency. you can do that with any 396 | dependencies you don't want inside your jar file. 397 | 398 | aaaannnd done! you can just run the `build` task by saying `gradle build` inside your project 399 | folder where you have the `build.gradle` file. this will generate a jar file with `black` inside it. 400 | you can check the jar file by opening it with an archive manager to see if `black` is in it. 401 | 402 | --- 403 | 404 | please do feel free to ask any of your questions, share your ideas through issues tab above. 405 | 406 | you can find me on [spigot](https://spigotmc.org/) as "Menfie" and on [discord](https://discordapp.com/) 407 | as "Personinblack#6059" 408 | 409 | --- 410 | 411 | stay black! 412 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------