Skip to content

Commit

Permalink
Fix AdminPanel.
Browse files Browse the repository at this point in the history
Remove unused buttons and implement missing ones.
Add BlockSelector which allows changing default island icon.
  • Loading branch information
BONNe committed Feb 3, 2022
1 parent c45209d commit 3c01559
Show file tree
Hide file tree
Showing 5 changed files with 719 additions and 343 deletions.
251 changes: 126 additions & 125 deletions src/main/java/world/bentobox/visit/panels/admin/AdminPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand All @@ -24,6 +25,7 @@
import world.bentobox.visit.configs.Settings;
import world.bentobox.visit.panels.ConversationUtils;
import world.bentobox.visit.panels.player.ConfigurePanel;
import world.bentobox.visit.panels.util.SingleBlockSelector;
import world.bentobox.visit.utils.Constants;
import world.bentobox.visit.utils.Utils;

Expand Down Expand Up @@ -63,23 +65,31 @@ private void build()
PanelUtils.fillBorder(panelBuilder, 5, Material.MAGENTA_STAINED_GLASS_PANE);

panelBuilder.item(10, this.createButton(Button.MANAGE));
panelBuilder.item(28, this.createButton(Button.RESET));
panelBuilder.item(11, this.createButton(Button.ICON));
panelBuilder.item(19, this.createButton(Button.RESET));

if (this.addon.getVaultHook() != null && this.addon.getVaultHook().hook())
{
panelBuilder.item(29, this.createButton(Button.ENABLE_ECONOMY));
}
panelBuilder.item(28, this.createButton(Button.ENABLE_ECONOMY));

if (!this.addon.getSettings().isDisableEconomy())
{
if (this.addon.getBankHook() != null)
{
panelBuilder.item(29, this.createButton(Button.USE_BANK));
}

panelBuilder.item(11, this.createButton(Button.TAX));
panelBuilder.item(31, this.createButton(Button.TAX));
panelBuilder.item(32, this.createButton(Button.MAX_VALUE));
panelBuilder.item(34, this.createButton(Button.DEFAULT_PAYMENT));
}
}

panelBuilder.item(13, this.createButton(Button.AT_TOP));
panelBuilder.item(22, this.createButton(Button.TOGGLE_FILTERS));
panelBuilder.item(31, this.createButton(Button.TOGGLE_SEARCH));
panelBuilder.item(14, this.createButton(Button.FILTER));
panelBuilder.item(15, this.createButton(Button.FILTER));
panelBuilder.item(24, this.createButton(Button.ENABLE_CONFIRMATION));

panelBuilder.item(16, this.createButton(Button.DEFAULT_ENABLED));
panelBuilder.item(25, this.createButton(Button.DEFAULT_OFFLINE));
panelBuilder.item(34, this.createButton(Button.DEFAULT_PAYMENT));

// At the end we just call build method that creates and opens panel.
panelBuilder.build();
Expand Down Expand Up @@ -121,9 +131,9 @@ private PanelItem createButton(Button button)
sorted((o1, o2) ->
{
String o1Name = o1.getName() != null ? o1.getName() :
Objects.requireNonNull(User.getInstance(o1.getOwner())).getName();
User.getInstance(Objects.requireNonNull(o1.getOwner())).getName();
String o2Name = o2.getName() != null ? o2.getName() :
Objects.requireNonNull(User.getInstance(o2.getOwner())).getName();
User.getInstance(Objects.requireNonNull(o2.getOwner())).getName();

return o1Name.compareToIgnoreCase(o2Name);
}).
Expand Down Expand Up @@ -154,7 +164,7 @@ private PanelItem createButton(Button button)
{
this.addon.getIslands().getIslands(this.world).forEach(island ->
{
if (island.getMetaData() != null)
if (island.getMetaData().isPresent())
{
island.removeMetaData(Constants.METADATA_OFFLINE);
island.removeMetaData(Constants.METADATA_PAYMENT);
Expand Down Expand Up @@ -306,78 +316,13 @@ private PanelItem createButton(Button button)

break;
}
case AT_TOP:
{
material = Material.GLASS;

glow = this.addon.getSettings().isFiltersTopLine();

if (glow)
{
description.add(this.user.getTranslation(reference + ".enabled"));
}
else
{
description.add(this.user.getTranslation(reference + ".disabled"));
}
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle"));

clickHandler = (panel, user, clickType, slot) ->
{
this.addon.getSettings().setFiltersTopLine(
!this.addon.getSettings().isFiltersTopLine());
this.addon.saveSettings();
this.build();

return true;
};

break;
}
case TOGGLE_FILTERS:
{
material = Material.HOPPER;

glow = this.addon.getSettings().isFiltersEnabled();

if (glow)
{
description.add(this.user.getTranslation(reference + ".enabled"));
}
else
{
description.add(this.user.getTranslation(reference + ".disabled"));
}
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle"));

clickHandler = (panel, user, clickType, slot) ->
{
this.addon.getSettings().setFiltersEnabled(
!this.addon.getSettings().isFiltersEnabled());
this.addon.saveSettings();
this.build();

return true;
};

break;
}
case FILTER:
{
switch (this.addon.getSettings().getDefaultFilter())
{
case ONLINE_ISLANDS:
material = Material.SANDSTONE_STAIRS;
break;
case CAN_VISIT:
material = Material.SANDSTONE_STAIRS;
break;
default:
material = Material.SMOOTH_SANDSTONE;
break;
}
material = switch (this.addon.getSettings().getDefaultFilter()) {
case ONLINE_ISLANDS -> Material.SANDSTONE_STAIRS;
case CAN_VISIT -> Material.SANDSTONE_STAIRS;
default -> Material.SMOOTH_SANDSTONE;
};

description.add(this.user.getTranslation(reference + "." +
this.addon.getSettings().getDefaultFilter().name().toLowerCase()));
Expand Down Expand Up @@ -408,11 +353,35 @@ private PanelItem createButton(Button button)

break;
}
case TOGGLE_SEARCH:
case ICON:
{
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-change"));

material = this.addon.getSettings().getIslandIcon();
clickHandler = (panel, user, clickType, slot) ->
{
SingleBlockSelector.open(this.user,
SingleBlockSelector.Mode.ANY,
(status, block) -> {
if (status)
{
this.addon.getSettings().setIslandIcon(block);
this.addon.saveSettings();
}

this.build();
});

return true;
};
break;
}
case USE_BANK:
{
material = Material.PAPER;
material = Material.DIAMOND;

glow = this.addon.getSettings().isSearchEnabled();
glow = this.addon.getSettings().isUseIslandBank();

if (glow)
{
Expand All @@ -422,13 +391,14 @@ private PanelItem createButton(Button button)
{
description.add(this.user.getTranslation(reference + ".disabled"));
}

description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle"));

clickHandler = (panel, user, clickType, slot) ->
{
this.addon.getSettings().setSearchEnabled(
!this.addon.getSettings().isSearchEnabled());
this.addon.getSettings().setUseIslandBank(
!this.addon.getSettings().isUseIslandBank());
this.addon.saveSettings();
this.build();

Expand All @@ -437,18 +407,6 @@ private PanelItem createButton(Button button)

break;
}
case DEFAULT_RANK:
// TODO: need Implementing
return PanelItem.empty();
case ICON:
// TODO: need Implementing
return PanelItem.empty();
case BORDER_BLOCK:
// TODO: need Implementing
return PanelItem.empty();
case BORDER_BLOCK_NAME:
// TODO: need Implementing
return PanelItem.empty();
case ENABLE_ECONOMY:
{
material = Material.EMERALD;
Expand Down Expand Up @@ -479,8 +437,67 @@ private PanelItem createButton(Button button)
break;
}
case ENABLE_CONFIRMATION:
// TODO: need Implementing
return PanelItem.empty();
{
material = Material.REDSTONE_TORCH;

glow = this.addon.getSettings().isPaymentConfirmation();

if (glow)
{
description.add(this.user.getTranslation(reference + ".enabled"));
}
else
{
description.add(this.user.getTranslation(reference + ".disabled"));
}
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle"));

clickHandler = (panel, user, clickType, slot) ->
{
this.addon.getSettings().setPaymentConfirmation(
!this.addon.getSettings().isPaymentConfirmation());
this.addon.saveSettings();
this.build();

return true;
};

break;
}
case MAX_VALUE:
{
material = Material.GOLD_BLOCK;
description.add(this.user.getTranslation(reference + ".value",
Constants.PARAMETER_NUMBER, String.valueOf(this.addon.getSettings().getMaxAmount())));
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-edit"));

clickHandler = (panel, user, clickType, slot) ->
{
Consumer<Number> numberConsumer = number ->
{
if (number != null)
{
this.addon.getSettings().setMaxAmount(number.doubleValue());
this.addon.saveSettings();
}

// reopen panel
this.build();
};

ConversationUtils.createNumericInput(numberConsumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "input-number"),
0,
Double.MAX_VALUE);

return true;
};

break;
}
default:
return PanelItem.empty();
}
Expand Down Expand Up @@ -539,38 +556,14 @@ private enum Button
* Allows to change default visiting enable mode.
*/
DEFAULT_ENABLED,
/**
* Allows to switch filters from top to bottom.
*/
AT_TOP,
/**
* Allows to toggle filters
*/
TOGGLE_FILTERS,
/**
* Allows to change default active filter
*/
FILTER,
/**
* Allows to toggle search button
*/
TOGGLE_SEARCH,
/**
* Allows to change default rank for changing config.
*/
DEFAULT_RANK,
/**
* Allows to switch default island icon.
*/
ICON,
/**
* Allows to change border block material.
*/
BORDER_BLOCK,
/**
* Allows to change border block name.
*/
BORDER_BLOCK_NAME,
/**
* Allows to disable economy part of the addon.
*/
Expand All @@ -579,6 +572,14 @@ private enum Button
* Allows to enable confirmation requirement before teleportation if cost is set.
*/
ENABLE_CONFIRMATION,
/**
* Allows toggle if money should be taken from bank addon.
*/
USE_BANK,
/**
* Allows to set max value for payment.
*/
MAX_VALUE
}


Expand Down

0 comments on commit 3c01559

Please sign in to comment.