Implement communities GUI system with several pages for community management
This commit is contained in:
parent
f6362676ff
commit
d44a3774db
@ -0,0 +1,27 @@
|
||||
package mineplex.core.communities.gui;
|
||||
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.Callback;
|
||||
|
||||
public class ActionButton extends CommunitiesGUIButton
|
||||
{
|
||||
private Callback<ClickType> _onClick;
|
||||
|
||||
public ActionButton(ItemStack icon, Callback<ClickType> onClick)
|
||||
{
|
||||
super(icon);
|
||||
|
||||
_onClick = onClick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
_onClick.run(type);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package mineplex.core.communities.gui;
|
||||
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.communities.CommunityManager;
|
||||
|
||||
public abstract class CommunitiesGUIButton
|
||||
{
|
||||
public ItemStack Button = null;
|
||||
|
||||
public CommunitiesGUIButton(ItemStack button)
|
||||
{
|
||||
Button = button;
|
||||
}
|
||||
|
||||
public static CommunityManager getCommunityManager()
|
||||
{
|
||||
return Managers.get(CommunityManager.class);
|
||||
}
|
||||
|
||||
public abstract void update();
|
||||
|
||||
public abstract void handleClick(ClickType type);
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package mineplex.core.communities.gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.communities.CommunityManager;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public abstract class CommunitiesGUIPage implements Listener
|
||||
{
|
||||
protected Player Viewer;
|
||||
protected Inventory Inv;
|
||||
protected Map<Integer, CommunitiesGUIButton> Buttons = new HashMap<>();
|
||||
|
||||
public CommunitiesGUIPage(String name, int rows, Player viewer)
|
||||
{
|
||||
Viewer = viewer;
|
||||
Inv = Bukkit.createInventory(viewer, 9 * rows, name);
|
||||
}
|
||||
|
||||
private void disable()
|
||||
{
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
public static CommunityManager getCommunityManager()
|
||||
{
|
||||
return Managers.get(CommunityManager.class);
|
||||
}
|
||||
|
||||
public void open()
|
||||
{
|
||||
Viewer.openInventory(Inv);
|
||||
UtilServer.RegisterEvents(this);
|
||||
}
|
||||
|
||||
public void updateButtons(boolean callUpdate)
|
||||
{
|
||||
Inv.clear();
|
||||
Buttons.entrySet().stream().forEach(entry ->
|
||||
{
|
||||
if (callUpdate)
|
||||
{
|
||||
entry.getValue().update();
|
||||
}
|
||||
Inv.setItem(entry.getKey(), entry.getValue().Button);
|
||||
});
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onUpdate(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() == UpdateType.TICK)
|
||||
{
|
||||
if (Viewer.getOpenInventory() == null || Viewer.getOpenInventory().getTopInventory() == null || !Viewer.getOpenInventory().getTopInventory().getTitle().equals(Inv.getTitle()))
|
||||
{
|
||||
disable();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.getType() == UpdateType.SEC_05)
|
||||
{
|
||||
Buttons.entrySet().forEach(entry ->
|
||||
{
|
||||
entry.getValue().update();
|
||||
Inv.setItem(entry.getKey(), entry.getValue().Button);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void handleClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null || !event.getClickedInventory().getTitle().equals(Inv.getTitle()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!Viewer.getName().equals(event.getWhoClicked().getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
if (!Recharge.Instance.use(Viewer, "Communities Button Click", 500, false, false))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Integer slot = event.getSlot();
|
||||
if (!Buttons.containsKey(slot))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Buttons.get(slot).handleClick(event.getClick());
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package mineplex.core.communities.gui.browser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.CommunityBrowserUpdateEvent;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.community.CommunityButton;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityBrowserPage extends CommunitiesGUIPage
|
||||
{
|
||||
private static final int COMMUNITIES_PER_PAGE = 27;
|
||||
|
||||
private int _page = 1;
|
||||
|
||||
private List<Integer> _displaying = new ArrayList<>();
|
||||
|
||||
//protected PrivacySetting PrivacyFilter = null;
|
||||
//protected GameDisplay GameFilter = null;
|
||||
|
||||
public CommunityBrowserPage(Player viewer)
|
||||
{
|
||||
super("Community Browser", 9 * 5, viewer);
|
||||
|
||||
setup(1, true);
|
||||
open();
|
||||
}
|
||||
|
||||
private void setup(int page, boolean initial)
|
||||
{
|
||||
if (initial)
|
||||
{
|
||||
Buttons.clear();
|
||||
Inv.clear();
|
||||
}
|
||||
{
|
||||
ActionButton back = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cRed + "Previous Page").build(), clickType ->
|
||||
{
|
||||
setup(_page - 1, false);
|
||||
});
|
||||
ActionButton next = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cGreen + "Next Page").build(), clickType ->
|
||||
{
|
||||
setup(_page + 1, false);
|
||||
});
|
||||
Buttons.put(27, back);
|
||||
Inv.setItem(27, back.Button);
|
||||
Buttons.put(35, next);
|
||||
Inv.setItem(35, next.Button);
|
||||
}
|
||||
|
||||
int slot = 0;
|
||||
boolean cleared = false;
|
||||
_displaying.clear();
|
||||
for (int i = (page - 1) * COMMUNITIES_PER_PAGE; i < (page - 1) * COMMUNITIES_PER_PAGE + COMMUNITIES_PER_PAGE && i < getCommunityManager().BrowserIds.size(); i++)
|
||||
{
|
||||
if (!cleared && !initial)
|
||||
{
|
||||
cleared = true;
|
||||
_page = page;
|
||||
for (int clear = 0; clear < 27; clear++)
|
||||
{
|
||||
Buttons.remove(clear);
|
||||
Inv.setItem(clear, null);
|
||||
}
|
||||
}
|
||||
CommunityButton button = new CommunityButton(Viewer, getCommunityManager().getLoadedCommunity(getCommunityManager().BrowserIds.get(i)));
|
||||
_displaying.add(getCommunityManager().BrowserIds.get(i));
|
||||
Buttons.put(slot, button);
|
||||
Inv.setItem(slot, button.Button);
|
||||
|
||||
slot++;
|
||||
}
|
||||
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBrowserUpdate(CommunityBrowserUpdateEvent event)
|
||||
{
|
||||
setup(1, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommunityDisband(CommunityDisbandEvent event)
|
||||
{
|
||||
if (_displaying.contains(event.getCommunity().getId()))
|
||||
{
|
||||
setup(1, false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package mineplex.core.communities.gui.browser;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
import mineplex.core.communities.gui.community.CommunityMembersPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityButton extends CommunitiesGUIButton
|
||||
{
|
||||
private Player _viewer;
|
||||
private Community _community;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public CommunityButton(Player viewer, Community community)
|
||||
{
|
||||
super(new ItemBuilder(new ItemStack(community.getFavoriteGame().getMaterial(), 1, community.getFavoriteGame().getMaterialData(), null)).setTitle(C.cGreen + community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cGold + "Members: " + C.cGray + community.getMembers().size(), C.cGold + "Privacy: " + C.cGray + community.getPrivacySetting().getDisplayText(), C.cGold + "Favorite Game: " + C.cGray + community.getFavoriteGame().getName(), C.cGold + "Description: " + C.cGray + community.getDescription()}, LineFormat.LORE)).build());
|
||||
|
||||
_viewer = viewer;
|
||||
_community = community;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
Button = new ItemBuilder(new ItemStack(_community.getFavoriteGame().getMaterial(), 1, _community.getFavoriteGame().getMaterialData(), null)).setTitle(C.cGreen + _community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cGold + "Members: " + C.cGray + _community.getMembers().size(), C.cGold + "Privacy: " + C.cGray + _community.getPrivacySetting().getDisplayText(), C.cGold + "Favorite Game: " + C.cGray + _community.getFavoriteGame().getName(), C.cGold + "Description: " + C.cGray + _community.getDescription()}, LineFormat.LORE)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
if (type == ClickType.SHIFT_LEFT)
|
||||
{
|
||||
new CommunityMembersPage(_viewer, _community).open();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityButton extends CommunitiesGUIButton
|
||||
{
|
||||
private Player _viewer;
|
||||
private Community _community;
|
||||
|
||||
public CommunityButton(Player viewer, Community community)
|
||||
{
|
||||
super(community.getMembers().containsKey(viewer.getUniqueId()) ?
|
||||
new ItemBuilder(Material.EMERALD_BLOCK).setTitle(C.cGold + community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed + "Description: " + C.cGray + community.getDescription(), C.cRed + "Members: " + C.cGray + community.getMembers().size(), C.cRed, C.cDRed + "Shift Left Click to Leave"}, LineFormat.LORE)).build()
|
||||
: (!community.getJoinRequests().containsKey(viewer.getUniqueId()) ?
|
||||
new ItemBuilder(Material.REDSTONE_BLOCK).setTitle(C.cGold + community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed + "Description: " + C.cGray + community.getDescription(), C.cRed + "Members: " + C.cGray + community.getMembers().size(), C.cRed, C.cDRed + "Shift Left Click to Request to Join"}, LineFormat.LORE)).build() :
|
||||
new ItemBuilder(Material.REDSTONE_BLOCK).setTitle(C.cGold + community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed + "Description: " + C.cGray + community.getDescription(), C.cRed + "Members: " + C.cGray + community.getMembers().size(), C.cRed, C.cDRed + "Join Request Pending"}, LineFormat.LORE)).build()));
|
||||
|
||||
_viewer = viewer;
|
||||
_community = community;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (_community.getMembers().containsKey(_viewer.getUniqueId()))
|
||||
{
|
||||
Button = new ItemBuilder(Material.EMERALD_BLOCK).setTitle(C.cGold + _community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed + "Description: " + C.cGray + _community.getDescription(), C.cRed + "Members: " + C.cGray + _community.getMembers().size(), C.cRed, C.cDRed + "Shift Left Click to Leave"}, LineFormat.LORE)).build();
|
||||
}
|
||||
if (!_community.getJoinRequests().containsKey(_viewer.getUniqueId()))
|
||||
{
|
||||
Button = new ItemBuilder(Material.REDSTONE_BLOCK).setTitle(C.cGold + _community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed + "Description: " + C.cGray + _community.getDescription(), C.cRed + "Members: " + C.cGray + _community.getMembers().size(), C.cRed, C.cDRed + "Shift Left Click to Request to Join"}, LineFormat.LORE)).build();
|
||||
}
|
||||
else
|
||||
{
|
||||
Button = new ItemBuilder(Material.REDSTONE_BLOCK).setTitle(C.cGold + _community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed + "Description: " + C.cGray + _community.getDescription(), C.cRed + "Members: " + C.cGray + _community.getMembers().size(), C.cRed, C.cDRed + "Join Request Pending"}, LineFormat.LORE)).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
if (type == ClickType.SHIFT_LEFT)
|
||||
{
|
||||
if (_community.getMembers().containsKey(_viewer.getUniqueId()))
|
||||
{
|
||||
getCommunityManager().handleLeave(_viewer, _community, _community.getMembers().get(_viewer.getUniqueId()));
|
||||
}
|
||||
else if (!_community.getJoinRequests().containsKey(_viewer.getUniqueId()))
|
||||
{
|
||||
getCommunityManager().handleJoinRequest(_viewer, _community);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityJoinRequestInfo;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
|
||||
public class CommunityJoinRequestButton extends CommunitiesGUIButton
|
||||
{
|
||||
private Player _viewer;
|
||||
private Community _community;
|
||||
private CommunityJoinRequestInfo _info;
|
||||
|
||||
public CommunityJoinRequestButton(Player viewer, Community community, CommunityJoinRequestInfo info)
|
||||
{
|
||||
super(info.getRepresentation());
|
||||
|
||||
_viewer = viewer;
|
||||
_community = community;
|
||||
_info = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
Button = _info.getRepresentation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
if (type == ClickType.LEFT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
getCommunityManager().handleInvite(_viewer, _community, _info.Name);
|
||||
}
|
||||
}
|
||||
if (type == ClickType.RIGHT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
getCommunityManager().handleCloseJoinRequest(_viewer, _community, _info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityJoinRequestInfo;
|
||||
import mineplex.core.communities.CommunityJoinRequestsUpdateEvent;
|
||||
import mineplex.core.communities.CommunityMembershipUpdateEvent;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.overview.CommunityOverviewPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityJoinRequestsPage extends CommunitiesGUIPage
|
||||
{
|
||||
private static final int REQUESTS_PER_PAGE = 27;
|
||||
|
||||
private Community _community;
|
||||
private int _page = 1;
|
||||
|
||||
public CommunityJoinRequestsPage(Player viewer, Community community)
|
||||
{
|
||||
super(C.cGold + community.getName() + C.cBlack, 6, viewer);
|
||||
_community = community;
|
||||
|
||||
setup(1, true);
|
||||
open();
|
||||
}
|
||||
|
||||
private void setup(int page, boolean initial)
|
||||
{
|
||||
if (initial)
|
||||
{
|
||||
Buttons.clear();
|
||||
Inv.clear();
|
||||
}
|
||||
{
|
||||
//0
|
||||
ActionButton membersButton = new ActionButton(new ItemBuilder(Material.SKULL_ITEM).setData((short)3).setTitle(C.cGold + "Members").build(), clickType ->
|
||||
{
|
||||
new CommunityMembersPage(Viewer, _community).open();
|
||||
});
|
||||
Buttons.put(0, membersButton);
|
||||
Inv.setItem(0, membersButton.Button);
|
||||
//4
|
||||
CommunityButton communityButton = new CommunityButton(Viewer, _community);
|
||||
Buttons.put(4, communityButton);
|
||||
Inv.setItem(4, communityButton.Button);
|
||||
//8
|
||||
ActionButton returnButton = new ActionButton(new ItemBuilder(Material.BED).setTitle(C.cGold + "Return to your Menu").build(), clickType ->
|
||||
{
|
||||
new CommunityOverviewPage(Viewer).open();
|
||||
});
|
||||
Buttons.put(8, returnButton);
|
||||
Inv.setItem(8, returnButton.Button);
|
||||
//CoLeader+
|
||||
if (_community.getMembers().containsKey(Viewer.getUniqueId()) && _community.getMembers().get(Viewer.getUniqueId()).Role.ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
ActionButton requestsButton = new ActionButton(new ItemBuilder(Material.ANVIL).setTitle(C.cGold + "Manage Join Requests").build(), clickType -> {});
|
||||
Buttons.put(2, requestsButton);
|
||||
Inv.setItem(2, requestsButton.Button);
|
||||
ActionButton settingsButton = new ActionButton(new ItemBuilder(Material.REDSTONE_COMPARATOR).setTitle(C.cGold + "Community Settings").build(), clickType ->
|
||||
{
|
||||
new CommunitySettingsPage(Viewer, _community);
|
||||
});
|
||||
Buttons.put(6, settingsButton);
|
||||
Inv.setItem(6, settingsButton.Button);
|
||||
}
|
||||
}
|
||||
{
|
||||
ActionButton back = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cRed + "Previous Page").build(), clickType ->
|
||||
{
|
||||
setup(_page - 1, false);
|
||||
});
|
||||
ActionButton next = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cGreen + "Next Page").build(), clickType ->
|
||||
{
|
||||
setup(_page + 1, false);
|
||||
});
|
||||
Buttons.put(45, back);
|
||||
Inv.setItem(45, back.Button);
|
||||
Buttons.put(53, next);
|
||||
Inv.setItem(53, next.Button);
|
||||
}
|
||||
List<CommunityJoinRequestInfo> requests = new LinkedList<>();
|
||||
for (CommunityJoinRequestInfo info : _community.getJoinRequests().values())
|
||||
{
|
||||
requests.add(info);
|
||||
}
|
||||
requests.sort((info1, info2) ->
|
||||
{
|
||||
return info1.Name.compareToIgnoreCase(info2.Name);
|
||||
});
|
||||
|
||||
int slot = 18;
|
||||
boolean cleared = false;
|
||||
for (int i = (page - 1) * REQUESTS_PER_PAGE; i < (page - 1) * REQUESTS_PER_PAGE + REQUESTS_PER_PAGE && i < requests.size(); i++)
|
||||
{
|
||||
if (!cleared && !initial)
|
||||
{
|
||||
cleared = true;
|
||||
_page = page;
|
||||
for (int clear = 18; clear < 45; clear++)
|
||||
{
|
||||
Buttons.remove(clear);
|
||||
Inv.setItem(clear, null);
|
||||
}
|
||||
}
|
||||
CommunityJoinRequestButton button = new CommunityJoinRequestButton(Viewer, _community, requests.get(i));
|
||||
Buttons.put(slot, button);
|
||||
Inv.setItem(slot, button.Button);
|
||||
|
||||
slot++;
|
||||
}
|
||||
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMembershipUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId() != _community.getId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_community.getMembers().containsKey(Viewer.getUniqueId()) && _community.getMembers().get(Viewer.getUniqueId()).Role.ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
setup(1, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
new CommunityMembersPage(Viewer, _community).open();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRequestsUpdate(CommunityJoinRequestsUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId() != _community.getId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
setup(1, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommunityDisband(CommunityDisbandEvent event)
|
||||
{
|
||||
if (_community.getId() == event.getCommunity().getId())
|
||||
{
|
||||
Viewer.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityMemberInfo;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
|
||||
public class CommunityMemberButton extends CommunitiesGUIButton
|
||||
{
|
||||
private Player _viewer;
|
||||
private Community _community;
|
||||
private CommunityMemberInfo _info;
|
||||
|
||||
public CommunityMemberButton(Player viewer, Community community, CommunityMemberInfo info)
|
||||
{
|
||||
super(info.getRepresentation(getCommunityManager().Get(viewer).getRoleIn(community)));
|
||||
|
||||
_viewer = viewer;
|
||||
_community = community;
|
||||
_info = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
Button = _info.getRepresentation(getCommunityManager().Get(_viewer).getRoleIn(_community));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
if (type == ClickType.SHIFT_RIGHT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() < _info.Role.ordinal())
|
||||
{
|
||||
getCommunityManager().handleKick(_viewer, _community, _info);
|
||||
}
|
||||
}
|
||||
if (type == ClickType.LEFT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community) == CommunityRole.LEADER && _info.Role != CommunityRole.LEADER)
|
||||
{
|
||||
if (_info.Role == CommunityRole.MEMBER)
|
||||
{
|
||||
getCommunityManager().handleRoleUpdate(_viewer, _community, _info, CommunityRole.COLEADER);
|
||||
}
|
||||
if (_info.Role == CommunityRole.COLEADER)
|
||||
{
|
||||
if (!Rank.valueOf(Managers.get(CoreClientManager.class).loadOfflineClient(_info.UUID).Rank).has(Rank.ETERNAL))
|
||||
{
|
||||
UtilPlayer.message(_viewer, F.main(getCommunityManager().getName(), "Only Eternal rank and above can own a community!"));
|
||||
return;
|
||||
}
|
||||
getCommunityManager().handleRoleUpdate(_viewer, _community, _info, CommunityRole.LEADER);
|
||||
getCommunityManager().handleRoleUpdate(_viewer, _community, _community.getMembers().get(_viewer.getUniqueId()), CommunityRole.COLEADER);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type == ClickType.RIGHT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community) == CommunityRole.LEADER && _info.Role == CommunityRole.COLEADER)
|
||||
{
|
||||
getCommunityManager().handleRoleUpdate(_viewer, _community, _info, CommunityRole.MEMBER);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,153 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityMemberInfo;
|
||||
import mineplex.core.communities.CommunityMembershipUpdateEvent;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.overview.CommunityOverviewPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityMembersPage extends CommunitiesGUIPage
|
||||
{
|
||||
private static final int MEMBERS_PER_PAGE = 27;
|
||||
|
||||
private Community _community;
|
||||
private int _page = 1;
|
||||
|
||||
public CommunityMembersPage(Player viewer, Community community)
|
||||
{
|
||||
super(C.cGold + community.getName() + C.cAqua, 6, viewer);
|
||||
_community = community;
|
||||
|
||||
setup(1, true);
|
||||
open();
|
||||
}
|
||||
|
||||
private void setup(int page, boolean initial)
|
||||
{
|
||||
if (initial)
|
||||
{
|
||||
Buttons.clear();
|
||||
Inv.clear();
|
||||
}
|
||||
{
|
||||
//0
|
||||
ActionButton membersButton = new ActionButton(new ItemBuilder(Material.SKULL_ITEM).setData((short)3).setTitle(C.cGold + "Members").build(), clickType -> {});
|
||||
Buttons.put(0, membersButton);
|
||||
Inv.setItem(0, membersButton.Button);
|
||||
//4
|
||||
CommunityButton communityButton = new CommunityButton(Viewer, _community);
|
||||
Buttons.put(4, communityButton);
|
||||
Inv.setItem(4, communityButton.Button);
|
||||
//8
|
||||
ActionButton returnButton = new ActionButton(new ItemBuilder(Material.BED).setTitle(C.cGold + "Return to your Menu").build(), clickType ->
|
||||
{
|
||||
new CommunityOverviewPage(Viewer).open();
|
||||
});
|
||||
Buttons.put(8, returnButton);
|
||||
Inv.setItem(8, returnButton.Button);
|
||||
//CoLeader+
|
||||
if (_community.getMembers().containsKey(Viewer.getUniqueId()) && _community.getMembers().get(Viewer.getUniqueId()).Role.ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
ActionButton requestsButton = new ActionButton(new ItemBuilder(Material.ANVIL).setTitle(C.cGold + "Manage Join Requests").build(), clickType ->
|
||||
{
|
||||
new CommunityJoinRequestsPage(Viewer, _community).open();
|
||||
});
|
||||
Buttons.put(2, requestsButton);
|
||||
Inv.setItem(2, requestsButton.Button);
|
||||
ActionButton settingsButton = new ActionButton(new ItemBuilder(Material.REDSTONE_COMPARATOR).setTitle(C.cGold + "Community Settings").build(), clickType ->
|
||||
{
|
||||
new CommunitySettingsPage(Viewer, _community);
|
||||
});
|
||||
Buttons.put(6, settingsButton);
|
||||
Inv.setItem(6, settingsButton.Button);
|
||||
}
|
||||
}
|
||||
{
|
||||
ActionButton back = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cRed + "Previous Page").build(), clickType ->
|
||||
{
|
||||
setup(_page - 1, false);
|
||||
});
|
||||
ActionButton next = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cGreen + "Next Page").build(), clickType ->
|
||||
{
|
||||
setup(_page + 1, false);
|
||||
});
|
||||
Buttons.put(45, back);
|
||||
Inv.setItem(45, back.Button);
|
||||
Buttons.put(53, next);
|
||||
Inv.setItem(53, next.Button);
|
||||
}
|
||||
List<CommunityMemberInfo> members = new LinkedList<>();
|
||||
for (CommunityMemberInfo info : _community.getMembers().values())
|
||||
{
|
||||
members.add(info);
|
||||
}
|
||||
members.sort((info1, info2) ->
|
||||
{
|
||||
if (info1.isOnline() == info2.isOnline())
|
||||
{
|
||||
return info1.Name.compareToIgnoreCase(info2.Name);
|
||||
}
|
||||
|
||||
if (info1.isOnline())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
|
||||
int slot = 18;
|
||||
boolean cleared = false;
|
||||
for (int i = (page - 1) * MEMBERS_PER_PAGE; i < (page - 1) * MEMBERS_PER_PAGE + MEMBERS_PER_PAGE && i < members.size(); i++)
|
||||
{
|
||||
if (!cleared && !initial)
|
||||
{
|
||||
cleared = true;
|
||||
_page = page;
|
||||
for (int clear = 18; clear < 45; clear++)
|
||||
{
|
||||
Buttons.remove(clear);
|
||||
Inv.setItem(clear, null);
|
||||
}
|
||||
}
|
||||
CommunityMemberButton button = new CommunityMemberButton(Viewer, _community, members.get(i));
|
||||
Buttons.put(slot, button);
|
||||
Inv.setItem(slot, button.Button);
|
||||
|
||||
slot++;
|
||||
}
|
||||
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMembershipUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId() != _community.getId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setup(1, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommunityDisband(CommunityDisbandEvent event)
|
||||
{
|
||||
if (_community.getId() == event.getCommunity().getId())
|
||||
{
|
||||
Viewer.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,252 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.Community.PrivacySetting;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.CommunitySetting;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
import mineplex.core.game.GameDisplay;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunitySettingButton extends CommunitiesGUIButton
|
||||
{
|
||||
@SuppressWarnings("serial")
|
||||
private static final Map<ChatColor, DyeColor> COLOR_MAP = new HashMap<ChatColor, DyeColor>()
|
||||
{
|
||||
{
|
||||
put(ChatColor.AQUA, DyeColor.CYAN);
|
||||
put(ChatColor.BLACK, DyeColor.BLACK);
|
||||
put(ChatColor.BLUE, DyeColor.LIGHT_BLUE);
|
||||
put(ChatColor.DARK_AQUA, DyeColor.CYAN);
|
||||
put(ChatColor.DARK_BLUE, DyeColor.BLUE);
|
||||
put(ChatColor.DARK_GRAY, DyeColor.GRAY);
|
||||
put(ChatColor.DARK_GREEN, DyeColor.GREEN);
|
||||
put(ChatColor.DARK_PURPLE, DyeColor.PURPLE);
|
||||
put(ChatColor.DARK_RED, DyeColor.RED);
|
||||
put(ChatColor.GOLD, DyeColor.YELLOW);
|
||||
put(ChatColor.GRAY, DyeColor.SILVER);
|
||||
put(ChatColor.GREEN, DyeColor.LIME);
|
||||
put(ChatColor.LIGHT_PURPLE, DyeColor.PINK);
|
||||
put(ChatColor.RED, DyeColor.RED);
|
||||
put(ChatColor.WHITE, DyeColor.WHITE);
|
||||
put(ChatColor.YELLOW, DyeColor.YELLOW);
|
||||
}
|
||||
};
|
||||
@SuppressWarnings("serial")
|
||||
private static final Map<ChatColor, String> COLOR_NAME_MAP = new HashMap<ChatColor, String>()
|
||||
{
|
||||
{
|
||||
put(ChatColor.AQUA, "Aqua");
|
||||
put(ChatColor.BLACK, "Black");
|
||||
put(ChatColor.BLUE, "Blue");
|
||||
put(ChatColor.DARK_AQUA, "Cyan");
|
||||
put(ChatColor.DARK_BLUE, "Dark Blue");
|
||||
put(ChatColor.DARK_GRAY, "Dark Gray");
|
||||
put(ChatColor.DARK_GREEN, "Dark Green");
|
||||
put(ChatColor.DARK_PURPLE, "Purple");
|
||||
put(ChatColor.DARK_RED, "Dark Red");
|
||||
put(ChatColor.GOLD, "Gold");
|
||||
put(ChatColor.GRAY, "Gray");
|
||||
put(ChatColor.GREEN, "Green");
|
||||
put(ChatColor.LIGHT_PURPLE, "Pink");
|
||||
put(ChatColor.RED, "Red");
|
||||
put(ChatColor.WHITE, "White");
|
||||
put(ChatColor.YELLOW, "Yellow");
|
||||
}
|
||||
};
|
||||
|
||||
private Player _viewer;
|
||||
private Community _community;
|
||||
private CommunitySetting _setting;
|
||||
|
||||
public CommunitySettingButton(Player viewer, Community community, CommunitySetting setting)
|
||||
{
|
||||
super(new ItemBuilder(Material.BARRIER).build());
|
||||
|
||||
_viewer = viewer;
|
||||
_community = community;
|
||||
_setting = setting;
|
||||
update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
if (_setting == CommunitySetting.FAVORITE_GAME)
|
||||
{
|
||||
Button = new ItemBuilder(Material.SKULL_ITEM).setData((short)4).setTitle(C.cGreen + "Favorite Game").addLore(C.cGold + "Currently: " + C.cGray + _community.getFavoriteGame().getName()).build();
|
||||
}
|
||||
else if (_setting == CommunitySetting.PRIVACY)
|
||||
{
|
||||
Button = new ItemBuilder(Material.DARK_OAK_DOOR_ITEM).setTitle(C.cGreen + "Privacy").addLore(C.cGold + "Currently: " + C.cGray + _community.getPrivacySetting().getDisplayText()).build();
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_DELAY)
|
||||
{
|
||||
Button = new ItemBuilder(Material.PAPER).setTitle(C.cGreen + "Chat Delay").addLore(C.cGold + "Currently: " + C.cGray + (_community.getChatDelay() == 0 ? "No Delay" : _community.getChatDelay() / 1000 + " Second(s)")).build();
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_NAME_COLOR)
|
||||
{
|
||||
Button = new ItemBuilder(Material.WOOL).setColor(COLOR_MAP.get(_community.getChatFormatting()[0]).getColor()).setTitle(C.cGreen + "Chat Community Color").addLore(C.cGold + "Currently: " + C.cGray + COLOR_NAME_MAP.get(_community.getChatFormatting()[0])).build();
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_PLAYER_COLOR)
|
||||
{
|
||||
Button = new ItemBuilder(Material.WOOL).setColor(COLOR_MAP.get(_community.getChatFormatting()[1]).getColor()).setTitle(C.cGreen + "Chat Player Color").addLore(C.cGold + "Currently: " + C.cGray + COLOR_NAME_MAP.get(_community.getChatFormatting()[1])).build();
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_MESSAGE_COLOR)
|
||||
{
|
||||
Button = new ItemBuilder(Material.WOOL).setColor(COLOR_MAP.get(_community.getChatFormatting()[2]).getColor()).setTitle(C.cGreen + "Chat Message Color").addLore(C.cGold + "Currently: " + C.cGray + COLOR_NAME_MAP.get(_community.getChatFormatting()[2])).build();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
if (type == ClickType.LEFT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
String[] valueArray = new String[] {};
|
||||
int index = 0;
|
||||
|
||||
if (_setting == CommunitySetting.FAVORITE_GAME)
|
||||
{
|
||||
GameDisplay[] games = Arrays.asList(GameDisplay.values()).stream().filter(display -> display.isCommunityFavoriteOption()).toArray(size -> new GameDisplay[size]);
|
||||
valueArray = new String[games.length];
|
||||
for (int i = 0; i < games.length; i++)
|
||||
{
|
||||
valueArray[i] = games[i].getName();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getFavoriteGame().getName());
|
||||
}
|
||||
else if (_setting == CommunitySetting.PRIVACY)
|
||||
{
|
||||
valueArray = new String[] {PrivacySetting.OPEN.toString(), PrivacySetting.RECRUITING.toString(), PrivacySetting.PRIVATE.toString()};
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getPrivacySetting().toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_DELAY)
|
||||
{
|
||||
valueArray = new String[] {1000L + "", 3000L + "", 5000L + ""};
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatDelay().toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_NAME_COLOR)
|
||||
{
|
||||
ChatColor[] colors = COLOR_MAP.keySet().toArray(new ChatColor[COLOR_MAP.size()]);
|
||||
valueArray = new String[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
valueArray[i] = colors[i].toString();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatFormatting()[0].toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_PLAYER_COLOR)
|
||||
{
|
||||
ChatColor[] colors = COLOR_MAP.keySet().toArray(new ChatColor[COLOR_MAP.size()]);
|
||||
valueArray = new String[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
valueArray[i] = colors[i].toString();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatFormatting()[1].toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_MESSAGE_COLOR)
|
||||
{
|
||||
ChatColor[] colors = COLOR_MAP.keySet().toArray(new ChatColor[COLOR_MAP.size()]);
|
||||
valueArray = new String[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
valueArray[i] = colors[i].toString();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatFormatting()[2].toString());
|
||||
}
|
||||
|
||||
int newIndex = (index + 1 >= valueArray.length) ? 0 : (index + 1);
|
||||
getCommunityManager().handleSettingUpdate(_viewer, _community, _setting, valueArray[newIndex]);
|
||||
}
|
||||
}
|
||||
if (type == ClickType.RIGHT)
|
||||
{
|
||||
if (getCommunityManager().Get(_viewer).getRoleIn(_community) != null && getCommunityManager().Get(_viewer).getRoleIn(_community).ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
String[] valueArray = new String[] {};
|
||||
int index = 0;
|
||||
|
||||
if (_setting == CommunitySetting.FAVORITE_GAME)
|
||||
{
|
||||
GameDisplay[] games = Arrays.asList(GameDisplay.values()).stream().filter(display -> display.isCommunityFavoriteOption()).toArray(size -> new GameDisplay[size]);
|
||||
valueArray = new String[games.length];
|
||||
for (int i = 0; i < games.length; i++)
|
||||
{
|
||||
valueArray[i] = games[i].getName();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getFavoriteGame().getName());
|
||||
}
|
||||
else if (_setting == CommunitySetting.PRIVACY)
|
||||
{
|
||||
valueArray = new String[] {PrivacySetting.OPEN.toString(), PrivacySetting.RECRUITING.toString(), PrivacySetting.PRIVATE.toString()};
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getPrivacySetting().toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_DELAY)
|
||||
{
|
||||
valueArray = new String[] {1000L + "", 3000L + "", 5000L + ""};
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatDelay().toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_NAME_COLOR)
|
||||
{
|
||||
ChatColor[] colors = COLOR_MAP.keySet().toArray(new ChatColor[COLOR_MAP.size()]);
|
||||
valueArray = new String[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
valueArray[i] = colors[i].toString();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatFormatting()[0].toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_PLAYER_COLOR)
|
||||
{
|
||||
ChatColor[] colors = COLOR_MAP.keySet().toArray(new ChatColor[COLOR_MAP.size()]);
|
||||
valueArray = new String[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
valueArray[i] = colors[i].toString();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatFormatting()[1].toString());
|
||||
}
|
||||
else if (_setting == CommunitySetting.CHAT_MESSAGE_COLOR)
|
||||
{
|
||||
ChatColor[] colors = COLOR_MAP.keySet().toArray(new ChatColor[COLOR_MAP.size()]);
|
||||
valueArray = new String[colors.length];
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
{
|
||||
valueArray[i] = colors[i].toString();
|
||||
}
|
||||
|
||||
index = Arrays.asList(valueArray).indexOf(_community.getChatFormatting()[2].toString());
|
||||
}
|
||||
|
||||
int newIndex = (index - 1 < 0) ? (valueArray.length - 1) : (index - 1);
|
||||
getCommunityManager().handleSettingUpdate(_viewer, _community, _setting, valueArray[newIndex]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
package mineplex.core.communities.gui.community;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityMembershipUpdateEvent;
|
||||
import mineplex.core.communities.CommunityRole;
|
||||
import mineplex.core.communities.CommunitySetting;
|
||||
import mineplex.core.communities.CommunitySettingUpdateEvent;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.overview.CommunityOverviewPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunitySettingsPage extends CommunitiesGUIPage
|
||||
{
|
||||
private Community _community;
|
||||
|
||||
public CommunitySettingsPage(Player viewer, Community community)
|
||||
{
|
||||
super(C.cGold + community.getName() + C.cBlue, 6, viewer);
|
||||
_community = community;
|
||||
|
||||
setup();
|
||||
open();
|
||||
}
|
||||
|
||||
private void setup()
|
||||
{
|
||||
{
|
||||
//0
|
||||
ActionButton membersButton = new ActionButton(new ItemBuilder(Material.SKULL_ITEM).setData((short)3).setTitle(C.cGold + "Members").build(), clickType ->
|
||||
{
|
||||
new CommunityMembersPage(Viewer, _community).open();
|
||||
});
|
||||
Buttons.put(0, membersButton);
|
||||
Inv.setItem(0, membersButton.Button);
|
||||
//4
|
||||
CommunityButton communityButton = new CommunityButton(Viewer, _community);
|
||||
Buttons.put(4, communityButton);
|
||||
Inv.setItem(4, communityButton.Button);
|
||||
//8
|
||||
ActionButton returnButton = new ActionButton(new ItemBuilder(Material.BED).setTitle(C.cGold + "Return to your Menu").build(), clickType ->
|
||||
{
|
||||
new CommunityOverviewPage(Viewer).open();
|
||||
});
|
||||
Buttons.put(8, returnButton);
|
||||
Inv.setItem(8, returnButton.Button);
|
||||
//CoLeader+
|
||||
if (_community.getMembers().containsKey(Viewer.getUniqueId()) && _community.getMembers().get(Viewer.getUniqueId()).Role.ordinal() <= CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
ActionButton requestsButton = new ActionButton(new ItemBuilder(Material.ANVIL).setTitle(C.cGold + "Manage Join Requests").build(), clickType ->
|
||||
{
|
||||
new CommunityJoinRequestsPage(Viewer, _community).open();
|
||||
});
|
||||
Buttons.put(2, requestsButton);
|
||||
Inv.setItem(2, requestsButton.Button);
|
||||
ActionButton settingsButton = new ActionButton(new ItemBuilder(Material.REDSTONE_COMPARATOR).setTitle(C.cGold + "Community Settings").build(), clickType -> {});
|
||||
Buttons.put(6, settingsButton);
|
||||
Inv.setItem(6, settingsButton.Button);
|
||||
}
|
||||
}
|
||||
{
|
||||
CommunitySettingButton gameButton = new CommunitySettingButton(Viewer, _community, CommunitySetting.FAVORITE_GAME);
|
||||
Buttons.put(21, gameButton);
|
||||
Inv.setItem(21, gameButton.Button);
|
||||
|
||||
CommunitySettingButton privacyButton = new CommunitySettingButton(Viewer, _community, CommunitySetting.PRIVACY);
|
||||
Buttons.put(23, privacyButton);
|
||||
Inv.setItem(23, privacyButton.Button);
|
||||
|
||||
CommunitySettingButton delayButton = new CommunitySettingButton(Viewer, _community, CommunitySetting.CHAT_DELAY);
|
||||
Buttons.put(38, delayButton);
|
||||
Inv.setItem(38, delayButton.Button);
|
||||
|
||||
CommunitySettingButton communityColorButton = new CommunitySettingButton(Viewer, _community, CommunitySetting.CHAT_NAME_COLOR);
|
||||
Buttons.put(40, communityColorButton);
|
||||
Inv.setItem(40, communityColorButton.Button);
|
||||
|
||||
CommunitySettingButton playerColorButton = new CommunitySettingButton(Viewer, _community, CommunitySetting.CHAT_PLAYER_COLOR);
|
||||
Buttons.put(41, playerColorButton);
|
||||
Inv.setItem(41, playerColorButton.Button);
|
||||
|
||||
CommunitySettingButton messageColorButton = new CommunitySettingButton(Viewer, _community, CommunitySetting.CHAT_MESSAGE_COLOR);
|
||||
Buttons.put(42, messageColorButton);
|
||||
Inv.setItem(42, messageColorButton.Button);
|
||||
}
|
||||
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMembershipUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId() != _community.getId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_community.getMembers().containsKey(Viewer.getUniqueId()) || _community.getMembers().get(Viewer.getUniqueId()).Role.ordinal() > CommunityRole.COLEADER.ordinal())
|
||||
{
|
||||
new CommunityMembersPage(Viewer, _community).open();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onSettingsUpdate(CommunitySettingUpdateEvent event)
|
||||
{
|
||||
if (event.getCommunity().getId() != _community.getId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
setup();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommunityDisband(CommunityDisbandEvent event)
|
||||
{
|
||||
if (_community.getId() == event.getCommunity().getId())
|
||||
{
|
||||
Viewer.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package mineplex.core.communities.gui.overview;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.LineFormat;
|
||||
import mineplex.core.common.util.UtilText;
|
||||
import mineplex.core.communities.Community;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIButton;
|
||||
import mineplex.core.communities.gui.community.CommunityMembersPage;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityButton extends CommunitiesGUIButton
|
||||
{
|
||||
private Player _viewer;
|
||||
private Community _community;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public CommunityButton(Player viewer, Community community)
|
||||
{
|
||||
super(new ItemBuilder(new ItemStack(community.getFavoriteGame().getMaterial(), 1, community.getFavoriteGame().getMaterialData(), null)).setTitle(C.cGreen + community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cGold + "Members: " + C.cGray + community.getMembers().size(), C.cGold + "Privacy: " + C.cGray + community.getPrivacySetting().getDisplayText(), C.cGold + "Favorite Game: " + C.cGray + community.getFavoriteGame().getName(), C.cGold + "Description: " + C.cGray + community.getDescription()}, LineFormat.LORE)).build());
|
||||
|
||||
_viewer = viewer;
|
||||
_community = community;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
Button = new ItemBuilder(new ItemStack(_community.getFavoriteGame().getMaterial(), 1, _community.getFavoriteGame().getMaterialData(), null)).setTitle(C.cGreen + _community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cGold + "Members: " + C.cGray + _community.getMembers().size(), C.cGold + "Favorite Game: " + C.cGray + _community.getFavoriteGame().getName(), C.cGold + "Description: " + C.cGray + _community.getDescription()}, LineFormat.LORE)).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(ClickType type)
|
||||
{
|
||||
if (type == ClickType.SHIFT_LEFT)
|
||||
{
|
||||
new CommunityMembersPage(_viewer, _community).open();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package mineplex.core.communities.gui.overview;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityMemberDataUpdateEvent;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.browser.CommunityBrowserPage;
|
||||
import mineplex.core.communities.gui.community.CommunityButton;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityInvitesPage extends CommunitiesGUIPage
|
||||
{
|
||||
private static final int COMMUNITIES_PER_PAGE = 27;
|
||||
|
||||
private int _page = 1;
|
||||
|
||||
public CommunityInvitesPage(Player viewer)
|
||||
{
|
||||
super(C.cGold + "Your Community Invites", 6, viewer);
|
||||
|
||||
setup(1, true);
|
||||
open();
|
||||
}
|
||||
|
||||
private void setup(int page, boolean initial)
|
||||
{
|
||||
if (initial)
|
||||
{
|
||||
Buttons.clear();
|
||||
Inv.clear();
|
||||
}
|
||||
{
|
||||
//1
|
||||
ActionButton communitiesButton = new ActionButton(new ItemBuilder(Material.EMERALD).setTitle(C.cGold + "Your Communities").build(), clickType ->
|
||||
{
|
||||
new CommunityOverviewPage(Viewer).open();
|
||||
});
|
||||
Buttons.put(1, communitiesButton);
|
||||
Inv.setItem(1, communitiesButton.Button);
|
||||
//4
|
||||
ActionButton browserButton = new ActionButton(new ItemBuilder(Material.COMPASS).setTitle(C.cGold + "Browse Communities").build(), clickType ->
|
||||
{
|
||||
new CommunityBrowserPage(Viewer).open();
|
||||
});
|
||||
Buttons.put(4, browserButton);
|
||||
Inv.setItem(4, browserButton.Button);
|
||||
//7
|
||||
ActionButton invitesButton = new ActionButton(new ItemBuilder(Material.BED).setTitle(C.cGold + "Your Community Invites").build(), clickType -> {});
|
||||
Buttons.put(7, invitesButton);
|
||||
Inv.setItem(7, invitesButton.Button);
|
||||
}
|
||||
{
|
||||
ActionButton back = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cRed + "Previous Page").build(), clickType ->
|
||||
{
|
||||
setup(_page - 1, false);
|
||||
});
|
||||
ActionButton next = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cGreen + "Next Page").build(), clickType ->
|
||||
{
|
||||
setup(_page + 1, false);
|
||||
});
|
||||
Buttons.put(45, back);
|
||||
Inv.setItem(45, back.Button);
|
||||
Buttons.put(53, next);
|
||||
Inv.setItem(53, next.Button);
|
||||
}
|
||||
|
||||
int slot = 18;
|
||||
boolean cleared = false;
|
||||
for (int i = (page - 1) * COMMUNITIES_PER_PAGE; i < (page - 1) * COMMUNITIES_PER_PAGE + COMMUNITIES_PER_PAGE && i < getCommunityManager().Get(Viewer).getTotalCommunities(); i++)
|
||||
{
|
||||
if (!cleared && !initial)
|
||||
{
|
||||
cleared = true;
|
||||
_page = page;
|
||||
for (int clear = 18; clear < 45; clear++)
|
||||
{
|
||||
Buttons.remove(clear);
|
||||
Inv.setItem(clear, null);
|
||||
}
|
||||
}
|
||||
CommunityButton button = new CommunityButton(Viewer, getCommunityManager().Get(Viewer).getCommunities()[i]);
|
||||
Buttons.put(slot, button);
|
||||
Inv.setItem(slot, button.Button);
|
||||
|
||||
slot++;
|
||||
}
|
||||
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMemberDataUpdateEvent event)
|
||||
{
|
||||
if (!event.getPlayer().getUniqueId().toString().equalsIgnoreCase(Viewer.getUniqueId().toString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setup(1, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommunityDisband(CommunityDisbandEvent event)
|
||||
{
|
||||
if (getCommunityManager().Get(Viewer).Invites.contains(event.getCommunity().getId()))
|
||||
{
|
||||
setup(1, false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package mineplex.core.communities.gui.overview;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.communities.CommunityDisbandEvent;
|
||||
import mineplex.core.communities.CommunityMemberDataUpdateEvent;
|
||||
import mineplex.core.communities.gui.ActionButton;
|
||||
import mineplex.core.communities.gui.CommunitiesGUIPage;
|
||||
import mineplex.core.communities.gui.browser.CommunityBrowserPage;
|
||||
import mineplex.core.communities.gui.community.CommunityButton;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
|
||||
public class CommunityOverviewPage extends CommunitiesGUIPage
|
||||
{
|
||||
private static final int COMMUNITIES_PER_PAGE = 27;
|
||||
|
||||
private int _page = 1;
|
||||
|
||||
public CommunityOverviewPage(Player viewer)
|
||||
{
|
||||
super(C.cGold + "Your Communities", 6, viewer);
|
||||
|
||||
setup(1, true);
|
||||
open();
|
||||
}
|
||||
|
||||
private void setup(int page, boolean initial)
|
||||
{
|
||||
if (initial)
|
||||
{
|
||||
Buttons.clear();
|
||||
Inv.clear();
|
||||
}
|
||||
{
|
||||
//1
|
||||
ActionButton communitiesButton = new ActionButton(new ItemBuilder(Material.EMERALD).setTitle(C.cGold + "Your Communities").build(), clickType -> {});
|
||||
Buttons.put(1, communitiesButton);
|
||||
Inv.setItem(1, communitiesButton.Button);
|
||||
//4
|
||||
ActionButton browserButton = new ActionButton(new ItemBuilder(Material.COMPASS).setTitle(C.cGold + "Browse Communities").build(), clickType ->
|
||||
{
|
||||
new CommunityBrowserPage(Viewer).open();
|
||||
});
|
||||
Buttons.put(4, browserButton);
|
||||
Inv.setItem(4, browserButton.Button);
|
||||
//7
|
||||
ActionButton invitesButton = new ActionButton(new ItemBuilder(Material.BED).setTitle(C.cGold + "Your Community Invites").build(), clickType ->
|
||||
{
|
||||
new CommunityInvitesPage(Viewer);
|
||||
});
|
||||
Buttons.put(7, invitesButton);
|
||||
Inv.setItem(7, invitesButton.Button);
|
||||
}
|
||||
{
|
||||
ActionButton back = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cRed + "Previous Page").build(), clickType ->
|
||||
{
|
||||
setup(_page - 1, false);
|
||||
});
|
||||
ActionButton next = new ActionButton(new ItemBuilder(Material.ARROW).setTitle(C.cGreen + "Next Page").build(), clickType ->
|
||||
{
|
||||
setup(_page + 1, false);
|
||||
});
|
||||
Buttons.put(45, back);
|
||||
Inv.setItem(45, back.Button);
|
||||
Buttons.put(53, next);
|
||||
Inv.setItem(53, next.Button);
|
||||
}
|
||||
|
||||
int slot = 18;
|
||||
boolean cleared = false;
|
||||
for (int i = (page - 1) * COMMUNITIES_PER_PAGE; i < (page - 1) * COMMUNITIES_PER_PAGE + COMMUNITIES_PER_PAGE && i < getCommunityManager().Get(Viewer).getTotalCommunities(); i++)
|
||||
{
|
||||
if (!cleared && !initial)
|
||||
{
|
||||
cleared = true;
|
||||
_page = page;
|
||||
for (int clear = 18; clear < 45; clear++)
|
||||
{
|
||||
Buttons.remove(clear);
|
||||
Inv.setItem(clear, null);
|
||||
}
|
||||
}
|
||||
CommunityButton button = new CommunityButton(Viewer, getCommunityManager().Get(Viewer).getCommunities()[i]);
|
||||
Buttons.put(slot, button);
|
||||
Inv.setItem(slot, button.Button);
|
||||
|
||||
slot++;
|
||||
}
|
||||
|
||||
Viewer.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onMembershipUpdate(CommunityMemberDataUpdateEvent event)
|
||||
{
|
||||
if (!event.getPlayer().getUniqueId().toString().equalsIgnoreCase(Viewer.getUniqueId().toString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
setup(1, false);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommunityDisband(CommunityDisbandEvent event)
|
||||
{
|
||||
if (getCommunityManager().Get(Viewer).Invites.contains(event.getCommunity().getId()))
|
||||
{
|
||||
setup(1, false);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user