Skip to content

Instantly share code, notes, and snippets.

@plumbusfactory
Last active July 20, 2019 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plumbusfactory/255270773610eb48aa1b to your computer and use it in GitHub Desktop.
Save plumbusfactory/255270773610eb48aa1b to your computer and use it in GitHub Desktop.
package API;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
/**
* Created by Mr.Whalerus on 11/16/2015.
*
*
*/
public class GUIBuilder {
@Getter @Setter private Material icon;
@Getter @Setter private int size;
@Getter @Setter private String Title;
@Getter @Setter private Player invHolder;
@Getter @Setter private Collection<ItemStack> items;
@Getter private Inventory inv;
GUIBuilder(Material icon, int size, String Title,Player invHolder, Collection<ItemStack> items, Inventory inv){
this.icon = icon;
this.size = (size > 54) ? size : 54;
this.Title = Title;
this.invHolder = invHolder;
this.items = items;
this.inv = inv;
}
public Inventory getInventory(){
return inv;
}
public static GUIFactory builder(){
return new GUIFactory();
}
public static class GUIFactory {
private Material icon;
private int size;
private String Title;
private Player invHolder;
private boolean parse = false;
private Collection<ItemStack> items;
GUIFactory(){
}
public GUIFactory icon(Material icon){
this.icon = icon;
return this;
}
public GUIFactory size(int size){
this.size = size;
return this;
}
public GUIFactory title(String title){
this.Title = title;
return this;
}
public GUIFactory holder(Player holder){
this.invHolder = holder;
return this;
}
public GUIFactory setContents(Collection<ItemStack> items) throws Exception {
if (items.size() > 54){
throw new TooLargeException("items Collection contained more then 54 items which is greater the the 54 aloud by minecraft!");
} else {
this.items = items;
return this;
}
}
public GUIFactory addItem(ItemStack i){
items.add(i);
return this;
}
public GUIFactory parseColor(char c ,boolean b){
if (b){
String oldtitle = Title;
this.Title = ChatColor.translateAlternateColorCodes(c, oldtitle);
return this;
} else {
return this;
}
}
public GUIBuilder build(){
Inventory inv = Bukkit.createInventory(null, size, Title);
return new GUIBuilder(icon,size,Title,invHolder,items,inv);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment