Deprecate Menu and it's surrounding classes and change /prefs to use ShopBase

This commit is contained in:
Sam 2018-01-31 13:02:43 +00:00 committed by Alexander Meech
parent f5e0a91414
commit 2bdf00d36f
20 changed files with 206 additions and 370 deletions

View File

@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
/**
* An abstract class for managing buttons inside of menus
*/
@Deprecated
public abstract class Button<T extends MiniPlugin>
{

View File

@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack;
* Representation of a purely cosmetic icon
* IE: When clicked, this button does not execute any action
*/
@Deprecated
public class IconButton extends Button
{

View File

@ -16,7 +16,10 @@ import java.util.UUID;
/**
* A class to manage dynamic creation of GUI's
*
* @deprecated Allows abuse of the F6 Minecraft 1.8 streaming bug, use {@link mineplex.core.shop.page.ShopPageBase} instead.
*/
@Deprecated
public abstract class Menu<T extends MiniPlugin>
{

View File

@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
/**
* Listener for the Menu system
*/
@Deprecated
public class MenuListener implements Listener
{

View File

@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
/**
*
*/
@Deprecated
public class MenuManager extends MiniPlugin
{

View File

@ -1,28 +0,0 @@
package mineplex.core.menu.builtin;
import java.util.function.Supplier;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import mineplex.core.MiniPlugin;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
public abstract class ButtonOpenAnvilInput<T extends MiniPlugin> extends Button<T>
{
private final Supplier<Menu<T>> _menuSupplier;
public ButtonOpenAnvilInput(T plugin, ItemStack item, Supplier<Menu<T>> menu)
{
super(item, plugin);
_menuSupplier = menu;
}
@Override
public void onClick(Player player, ClickType clickType)
{
_menuSupplier.get().open(player);
}
}

View File

@ -10,6 +10,7 @@ import mineplex.core.MiniPlugin;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
@Deprecated
public class ButtonOpenInventory<T extends MiniPlugin> extends Button<T>
{
private final Supplier<Menu<T>> _menuSupplier;

View File

@ -32,10 +32,11 @@ import mineplex.core.account.permissions.PermissionGroup;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.donation.DonationManager;
import mineplex.core.incognito.IncognitoManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.preferences.command.PreferencesCommand;
import mineplex.core.preferences.ui.PreferenceMainMenu;
import mineplex.core.preferences.ui.PreferencesShop;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.utils.UtilGameProfile;
@ -50,7 +51,9 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
private final PreferencesRepository _repository;
private final CoreClientManager _clientManager;
private final DonationManager _donationManager;
private final IncognitoManager _incognitoManager;
private final PreferencesShop _shop;
private final Set<UserPreferences> _saveBuffer = Sets.newHashSet();
private final Map<Integer, UserPreferences> _preferences = Maps.newHashMap();
@ -63,9 +66,10 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
_repository = new PreferencesRepository(this);
_clientManager = clientManager;
_donationManager = require(DonationManager.class);
_incognitoManager = incognito;
_clientManager.addStoredProcedureLoginProcessor(this);
_shop = new PreferencesShop(this);
addCommand(new PreferencesCommand(this));
@ -196,9 +200,14 @@ public class PreferencesManager extends MiniPlugin implements ILoginProcessor
return _clientManager;
}
public DonationManager getDonationManager()
{
return _donationManager;
}
public void openMenu(Player player)
{
new PreferenceMainMenu(this).open(player);
_shop.attemptShopOpen(player);
}
public void handlePlayerJoin(Player player, boolean force)

View File

@ -1,55 +0,0 @@
package mineplex.core.preferences.ui;
import java.util.List;
import org.bukkit.entity.Player;
import com.google.common.collect.Lists;
import mineplex.core.common.util.UtilUI;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
import mineplex.core.preferences.PreferenceCategory;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.ui.buttons.CategoryButton;
/**
*
*/
public class PreferenceMainMenu extends Menu<PreferencesManager>
{
private static final int INV_SIZE_MAX = 54;
private static final int INV_SIZE_MIN = 45;
public PreferenceMainMenu(PreferencesManager plugin)
{
super("My Preferences", plugin);
}
@Override
protected Button<?>[] setUp(Player player)
{
boolean exclusive = getPlugin().getClientManager().Get(player).hasPermission(PreferencesManager.Perm.VIEW_EXCLUSIVE_MENU);
Button<?>[] buttons = new Button[exclusive ? INV_SIZE_MAX : INV_SIZE_MIN];
List<PreferenceCategory> list = Lists.newArrayList(PreferenceCategory.values());
if (!exclusive)
{
list.remove(PreferenceCategory.EXCLUSIVE);
}
int[] slots = UtilUI.getIndicesFor(list.size(), 2, 4, 0);
int size = list.size();
for (int i = 0; i < size; i++)
{
int slot = slots[i];
PreferenceCategory category = list.get(i);
buttons[slot] = new CategoryButton(category, getPlugin());
}
return pane(buttons);
}
}

View File

@ -0,0 +1,56 @@
package mineplex.core.preferences.ui;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilUI;
import mineplex.core.preferences.PreferenceCategory;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.PreferencesManager.Perm;
import mineplex.core.shop.page.ShopPageBase;
public class PreferencesMainPage extends ShopPageBase<PreferencesManager, PreferencesShop>
{
private static final int INV_SIZE_MAX = 54;
private static final int INV_SIZE_MIN = 45;
public PreferencesMainPage(PreferencesManager plugin, PreferencesShop shop, Player player)
{
super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), plugin.getName(), player, plugin.getClientManager().Get(player).hasPermission(Perm.VIEW_EXCLUSIVE_MENU) ? INV_SIZE_MAX : INV_SIZE_MIN);
buildPage();
}
@Override
protected void buildPage()
{
boolean exclusive = getSize() > INV_SIZE_MIN;
List<PreferenceCategory> categories;
if (exclusive)
{
categories = Arrays.asList(PreferenceCategory.values());
}
else
{
categories = Arrays.stream(PreferenceCategory.values())
.filter(category -> category != PreferenceCategory.EXCLUSIVE)
.collect(Collectors.toList());
}
int size = categories.size();
int[] slots = UtilUI.getIndicesFor(size, 2, 4, 0);
for (int i = 0; i < size; i++)
{
int slot = slots[i];
PreferenceCategory category = categories.get(i);
addButton(slot, category.getItem(), (player, clickType) -> getShop().openPageForPlayer(player, new PreferencesPage(getPlugin(), getShop(), player, this, category)));
}
}
}

View File

@ -0,0 +1,104 @@
package mineplex.core.preferences.ui;
import java.util.List;
import java.util.stream.Collectors;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilUI;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferenceCategory;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.UserPreferences;
import mineplex.core.shop.page.ShopPageBase;
public class PreferencesPage extends ShopPageBase<PreferencesManager, PreferencesShop>
{
private static final ItemStack GO_BACK = new ItemBuilder(Material.BED)
.setTitle(C.cGreen + "Go Back")
.build();
private final PreferencesMainPage _previous;
private final PreferenceCategory _category;
PreferencesPage(PreferencesManager plugin, PreferencesShop shop, Player player, PreferencesMainPage previous, PreferenceCategory category)
{
super(plugin, shop, plugin.getClientManager(), plugin.getDonationManager(), category.getName(), player);
_previous = previous;
_category = category;
buildPage();
}
@Override
protected void buildPage()
{
List<Preference> preferences = Preference.getByCategory(_category).stream()
.filter(preference -> getPlugin().getClientManager().Get(getPlayer()).hasPermission(preference))
.collect(Collectors.toList());
UserPreferences user = getPlugin().get(getPlayer());
int[] slots = UtilUI.getIndicesFor(preferences.size(), 1, 4, 1);
for (int i = 0; i < preferences.size(); i++)
{
int slot = slots[i];
Preference preference = preferences.get(i);
boolean active = user.isActive(preference);
ItemBuilder builder = new ItemBuilder(preference.getIcon())
.setTitle(C.cRed + preference.getName())
.setData(preference.getIcon() == Material.SKULL_ITEM ? (byte) 3 : 0);
addToggleLore(builder, active);
builder.addLore(preference.getLore());
addButton(slot, builder.build(), (player, clickType) ->
{
playAcceptSound(player);
user.toggle(preference);
refresh();
});
builder.setType(Material.INK_SACK);
builder.setData(active ? DyeColor.LIME.getDyeData() : DyeColor.GRAY.getDyeData());
builder.getLore().clear();
addToggleLore(builder, active);
addButton(slot + 9, builder.build(), (player, clickType) ->
{
playAcceptSound(player);
user.toggle(preference);
refresh();
});
}
addButton(4, GO_BACK, (player, clickType) -> getShop().openPageForPlayer(player, _previous));
}
private void addToggleLore(ItemBuilder builder, boolean active)
{
if (active)
{
builder.addLore(C.cGreen + "Enabled", "", C.cYellow + "Click to Disable");
}
else
{
builder.addLore(C.cRed + "Disabled", "", C.cYellow + "Click to Enable");
}
}
@Override
public void playerClosed()
{
getPlugin().save(getPlugin().get(getPlayer()));
super.playerClosed();
}
}

View File

@ -0,0 +1,22 @@
package mineplex.core.preferences.ui;
import org.bukkit.entity.Player;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
public class PreferencesShop extends ShopBase<PreferencesManager>
{
public PreferencesShop(PreferencesManager plugin)
{
super(plugin, plugin.getClientManager(), plugin.getDonationManager(), "Preferences");
}
@Override
protected ShopPageBase<PreferencesManager, ? extends ShopBase<PreferencesManager>> buildPagesFor(Player player)
{
return new PreferencesMainPage(getPlugin(), this, player);
}
}

View File

@ -1,40 +0,0 @@
package mineplex.core.preferences.ui.buttons;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
import mineplex.core.preferences.PreferencesManager;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
/**
*
*/
public class BackButton extends Button<PreferencesManager>
{
private static ItemStack ITEM = new ItemBuilder(Material.BED)
.setTitle(ChatColor.GRAY + "\u21FD Go Back")
.build();
public BackButton(PreferencesManager plugin)
{
super(ITEM, plugin);
}
@Override
public void onClick(Player player, ClickType clickType)
{
Menu.get(player.getUniqueId()).setUseClose(false);
player.closeInventory();
getPlugin().openMenu(player);
getPlugin().save(getPlugin().get(player));
Menu.get(player.getUniqueId()).setUseClose(true);
}
}

View File

@ -1,28 +0,0 @@
package mineplex.core.preferences.ui.buttons;
import mineplex.core.menu.Button;
import mineplex.core.preferences.PreferenceCategory;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.ui.menus.PreferenceMenu;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
/**
*
*/
public class CategoryButton extends Button<PreferencesManager>
{
private PreferenceCategory _category;
public CategoryButton(PreferenceCategory category, PreferencesManager plugin)
{
super(category.getItem(), plugin);
_category = category;
}
@Override
public void onClick(Player player, ClickType clickType)
{
new PreferenceMenu(_category, getPlugin()).open(player);
}
}

View File

@ -1,76 +0,0 @@
package mineplex.core.preferences.ui.buttons;
import com.google.common.collect.Lists;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.UserPreferences;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
*
*/
public class PreferenceButton extends Button<PreferencesManager>
{
protected final Preference _preference;
protected final UserPreferences _user;
private final ItemStack _disabled;
private final ItemStack _enabled;
public PreferenceButton(UserPreferences user, Preference preference, PreferencesManager plugin)
{
super(null, plugin);
_preference = preference;
_user = user;
Material icon = preference.getIcon();
boolean head = icon == Material.SKULL_ITEM;
List<String> lore = Lists.newArrayList();
if(preference.getLore() != null)
{
lore.add(" ");
for(String s : preference.getLore())
{
lore.add(C.cGray + s);
}
}
_disabled = new ItemBuilder(preference.getIcon())
.setTitle(C.cRed + preference.getName())
.addLore(C.cRed + "Disabled", " " , C.cWhite + "Click to Enable")
.addLores(lore)
.setData(head ? (short) 3 : 0)
.build();
_enabled = new ItemBuilder(preference.getIcon())
.setTitle(C.cGreen + preference.getName())
.addLore(C.cGreen + "Enabled", " " , C.cWhite + "Click to Disable")
.addLores(lore)
.setData(head ? (short) 3 : 0)
.build();
}
@Override
public void onClick(Player player, ClickType clickType)
{
_user.toggle(_preference);
Menu.get(player.getUniqueId()).resetAndUpdate();
}
@Override
public ItemStack getItemStack()
{
return _user.isActive(_preference) ? _enabled : _disabled;
}
}

View File

@ -1,42 +0,0 @@
package mineplex.core.preferences.ui.buttons;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.UserPreferences;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
/**
*
*/
public class PreferenceDyeButton extends PreferenceButton
{
private final ItemStack _disabledDye;
private final ItemStack _enabledDye;
public PreferenceDyeButton(UserPreferences user, Preference preference, PreferencesManager plugin)
{
super(user, preference, plugin);
_disabledDye = new ItemBuilder(Material.INK_SACK)
.setData(DyeColor.GRAY.getDyeData())
.setTitle(C.cRed + preference.getName())
.setLore(C.cRed + "Disabled", " " , C.cWhite + "Click to Enable")
.build();
_enabledDye = new ItemBuilder(Material.INK_SACK)
.setData(DyeColor.LIME.getDyeData())
.setTitle(C.cGreen + preference.getName())
.setLore(C.cGreen + "Enabled", " " , C.cWhite + "Click to Disable")
.build();
}
@Override
public ItemStack getItemStack()
{
return _user.isActive(_preference) ? _enabledDye : _disabledDye;
}
}

View File

@ -1,67 +0,0 @@
package mineplex.core.preferences.ui.menus;
import java.util.List;
import org.bukkit.entity.Player;
import com.google.common.collect.Lists;
import mineplex.core.common.util.UtilUI;
import mineplex.core.menu.Button;
import mineplex.core.menu.Menu;
import mineplex.core.preferences.Preference;
import mineplex.core.preferences.PreferenceCategory;
import mineplex.core.preferences.PreferencesManager;
import mineplex.core.preferences.UserPreferences;
import mineplex.core.preferences.ui.buttons.BackButton;
import mineplex.core.preferences.ui.buttons.PreferenceButton;
import mineplex.core.preferences.ui.buttons.PreferenceDyeButton;
/**
*
*/
public class PreferenceMenu extends Menu<PreferencesManager>
{
private final int INV_SIZE = 54;
private final PreferenceCategory _category;
public PreferenceMenu(PreferenceCategory category, PreferencesManager plugin)
{
super(category.getName(), plugin);
_category = category;
setUseClose(true);
}
@Override
protected Button<?>[] setUp(Player player)
{
Button<?>[] buttons = new Button[INV_SIZE];
List<Preference> preferences = Lists.newArrayList(Preference.getByCategory(_category));
UserPreferences user = getPlugin().get(player);
preferences.removeIf(pref -> !getPlugin().getClientManager().Get(player).hasPermission(pref));
int[] slots = UtilUI.getIndicesFor(preferences.size(), 1, 4, 1);
for(int i = 0; i < preferences.size(); i++)
{
int slot = slots[i];
Preference preference = preferences.get(i);
buttons[slot] = new PreferenceButton(user, preference, getPlugin());
buttons[slot + 9] = new PreferenceDyeButton(user, preference, getPlugin());
}
buttons[0] = new BackButton(getPlugin());
return pane(buttons);
}
@Override
public void onClose(Player player)
{
remove(player.getUniqueId());
getPlugin().save(getPlugin().get(player));
}
}

View File

@ -7,6 +7,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.server.v1_8_R3.EntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -126,13 +128,13 @@ import mineplex.minecraft.game.core.condition.ConditionManager;
import mineplex.minecraft.game.core.damage.DamageManager;
import mineplex.minecraft.game.core.fire.Fire;
import mineplex.serverdata.Region;
import nautilus.game.arcade.addons.SoupAddon;
import nautilus.game.arcade.booster.GameBoosterManager;
import nautilus.game.arcade.command.CancelNextGameCommand;
import nautilus.game.arcade.command.GameCommand;
import nautilus.game.arcade.command.GoToNextGameCommand;
import nautilus.game.arcade.command.KitUnlockCommand;
import nautilus.game.arcade.command.OpenGameMechPrefsCommand;
import nautilus.game.arcade.command.TauntCommand;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
@ -142,7 +144,6 @@ import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.games.event.EventModule;
import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague;
import nautilus.game.arcade.game.modules.winstreak.WinStreakModule;
import nautilus.game.arcade.managers.GameAchievementManager;
import nautilus.game.arcade.managers.GameCreationManager;
import nautilus.game.arcade.managers.GameFlagManager;
@ -155,7 +156,6 @@ import nautilus.game.arcade.managers.GameSpectatorManager;
import nautilus.game.arcade.managers.GameStatManager;
import nautilus.game.arcade.managers.GameTournamentManager;
import nautilus.game.arcade.managers.GameWorldManager;
import nautilus.game.arcade.managers.HolidayManager;
import nautilus.game.arcade.managers.IdleManager;
import nautilus.game.arcade.managers.MiscManager;
import nautilus.game.arcade.managers.NextBestGameManager;
@ -167,7 +167,6 @@ import nautilus.game.arcade.managers.lobby.current.NewGameLobbyManager;
import nautilus.game.arcade.managers.lobby.legacy.LegacyGameLobbyManager;
import nautilus.game.arcade.player.ArcadePlayer;
import nautilus.game.arcade.shop.ArcadeShop;
import net.minecraft.server.v1_8_R3.EntityLiving;
public class ArcadeManager extends MiniPlugin implements IRelation
{
@ -407,7 +406,6 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_nextBestGameManager = new NextBestGameManager(serverConfig.ServerGroup, region, _partyManager);
addCommand(new GoToNextGameCommand(this));
addCommand(new OpenGameMechPrefsCommand(this));
addCommand(new CancelNextGameCommand(this));
addCommand(new TauntCommand(this));

View File

@ -1,25 +0,0 @@
package nautilus.game.arcade.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.preferences.PreferenceCategory;
import mineplex.core.preferences.ui.menus.PreferenceMenu;
import nautilus.game.arcade.ArcadeManager;
/**
*
*/
public class OpenGameMechPrefsCommand extends CommandBase<ArcadeManager>
{
public OpenGameMechPrefsCommand(ArcadeManager plugin)
{
super(plugin, ArcadeManager.Perm.NEXT_BEST_GAME, "opengamemechanicpreferences");
}
@Override
public void Execute(Player caller, String[] args)
{
new PreferenceMenu(PreferenceCategory.GAME_PLAY, Plugin.getPreferences()).open(caller);
}
}

View File

@ -158,7 +158,7 @@ public class NextBestGameManager implements Listener
private static final TextComponent YOU_HAVE = new TextComponent("You have ");
private static final TextComponent AUTO_JOIN_PREF = new TextComponent("Auto-Join ");
private static final TextComponent ON_PLUS_EXTRA = new TextComponent("on! If you don't want to be sent to another game automatically, ");
private static final String COMMAND_PREFS = "/opengamemechanicpreferences";
private static final String COMMAND_PREFS = "/prefs";
private static final TextComponent CLICK_PREFS = new TextComponent("click here ");
private static final TextComponent TO_CHANGE = new TextComponent("to disable it in your preferences.");