Skip to content

Commit

Permalink
Add an ability to disable notifications that are send about unlocking…
Browse files Browse the repository at this point in the history
… new generators.
  • Loading branch information
BONNe committed Dec 4, 2020
1 parent c19ee5e commit d06eed4
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,29 @@ public void setBorderBlockName(String borderBlockName)
this.borderBlockName = borderBlockName;
}


/**
* Is notify unlocked generators boolean.
*
* @return the boolean
*/
public boolean isNotifyUnlockedGenerators()
{
return notifyUnlockedGenerators;
}


/**
* Sets notify unlocked generators.
*
* @param notifyUnlockedGenerators the notify unlocked generators
*/
public void setNotifyUnlockedGenerators(boolean notifyUnlockedGenerators)
{
this.notifyUnlockedGenerators = notifyUnlockedGenerators;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -357,6 +380,15 @@ public void setBorderBlockName(String borderBlockName)
@ConfigEntry(path = "default-active-generators")
private int defaultActiveGeneratorCount = 3;

@ConfigComment("")
@ConfigComment("Send a notification message when player unlocks a new generator.")
@ConfigComment("3 messages that will be showed:")
@ConfigComment("stone-generator.conversations.click-text-to-purchase - if generator is unlocked but is not purchased.")
@ConfigComment("stone-generator.conversations.click-text-to-activate-vault - if generator is unlocked but requires activation cost.")
@ConfigComment("stone-generator.conversations.click-text-to-activate - if generator is unlocked and can be activated.")
@ConfigEntry(path = "notify-on-unlock")
private boolean notifyUnlockedGenerators = true;

@ConfigComment("")
@ConfigComment("This list stores GameModes in which the addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,18 +983,34 @@ public void unlockGenerator(@NotNull GeneratorDataObject dataObject,
// save data.
this.saveGeneratorData(dataObject);

if (!this.addon.getSettings().isNotifyUnlockedGenerators())
{
// Not necessary to notify users.
return;
}

// Send message to user
if (this.addon.isVaultProvided() && generator.getGeneratorTierCost() > 0)
{
// Send message that generator is available for purchase.

island.getMemberSet().forEach(uuid -> Utils.sendUnlockMessage(uuid, island, generator, this.addon.isVaultProvided(), false));
island.getMemberSet().forEach(uuid ->
Utils.sendUnlockMessage(uuid,
island,
generator,
this.addon,
false));
}
else
{
// Send message that generator is available for activation.

island.getMemberSet().forEach(uuid -> Utils.sendUnlockMessage(uuid, island, generator, this.addon.isVaultProvided(), true));
island.getMemberSet().forEach(uuid ->
Utils.sendUnlockMessage(uuid,
island,
generator,
this.addon,
true));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ public void build()
panelBuilder.item(11, this.createButton(Action.WORKING_RANGE));
panelBuilder.item(20, this.createButton(Action.ACTIVE_GENERATORS));

panelBuilder.item(13, this.createButton(Action.USE_PHYSIC));
panelBuilder.item(12, this.createButton(Action.USE_PHYSIC));

panelBuilder.item(15, this.createButton(Action.SHOW_FILTERS));
panelBuilder.item(24, this.createButton(Action.BORDER_BLOCK));
panelBuilder.item(25, this.createButton(Action.BORDER_BLOCK_NAME));
panelBuilder.item(14, this.createButton(Action.SHOW_FILTERS));
panelBuilder.item(23, this.createButton(Action.BORDER_BLOCK));
panelBuilder.item(24, this.createButton(Action.BORDER_BLOCK_NAME));

panelBuilder.item(16, this.createButton(Action.UNLOCK_NOTIFY));

panelBuilder.item(35, this.createButton(Action.RETURN));
panelBuilder.build();
Expand Down Expand Up @@ -331,6 +333,35 @@ private PanelItem createButton(Action button)
// Not implemented in current GUI.
break;
}
case UNLOCK_NOTIFY:
{
clickHandler = (panel, user, clickType, i) -> {
this.settings.setNotifyUnlockedGenerators(!this.settings.isNotifyUnlockedGenerators());
this.saveSettings();
// Update button in panel
this.build();

return true;
};

glow = this.settings.isNotifyUnlockedGenerators();

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"));

material = Material.OAK_SIGN;

break;
}
case RETURN:
{
description.add("");
Expand Down Expand Up @@ -421,6 +452,10 @@ private enum Action
* Process border block action.
*/
BORDER_BLOCK_NAME,
/**
* Process unlock notification action.
*/
UNLOCK_NOTIFY,
/**
* Process Return Action.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.magiccobblestonegenerator.StoneGeneratorAddon;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorTierObject;


Expand Down Expand Up @@ -489,31 +490,37 @@ public static void sendMessage(User user, String message)
* @param uuid the uuid
* @param island the island
* @param generator the generator
* @param hasVault Indicates that vault addon is provided.
* @param addon instance of stone generator addon.
* @param available the available
*/
public static void sendUnlockMessage(UUID uuid, Island island, GeneratorTierObject generator, boolean hasVault, boolean available)
public static void sendUnlockMessage(UUID uuid, Island island, GeneratorTierObject generator, StoneGeneratorAddon addon, boolean available)
{
User user = User.getInstance(uuid);

WorldSettings settings = BentoBox.getInstance().getIWM().getWorldSettings(island.getWorld());
WorldSettings settings = addon.getPlugin().getIWM().getWorldSettings(island.getWorld());

if (settings != null && user != null && user.isOnline())
{
TextComponent component;

String command = "/" + settings.getPlayerCommandAliases().split(" ")[0];
StringBuilder commandBuilder = new StringBuilder();
commandBuilder.append("/");
commandBuilder.append(settings.getPlayerCommandAliases().split(" ")[0]);
commandBuilder.append(" ");
commandBuilder.append(addon.getSettings().getPlayerMainCommand().split(" ")[0]);
commandBuilder.append(" ");

if (!available)
{
component = new TextComponent(user.getTranslation(Constants.CONVERSATIONS + "click-text-to-purchase",
Constants.GENERATOR, generator.getFriendlyName(),
Constants.NUMBER, String.valueOf(generator.getGeneratorTierCost())));
command += " generator buy ";

commandBuilder.append(addon.getSettings().getPlayerBuyCommand().split(" ")[0]);
}
else
{
if (hasVault && generator.getActivationCost() > 0)
if (addon.isVaultProvided() && generator.getActivationCost() > 0)
{
component = new TextComponent(user.getTranslation(Constants.CONVERSATIONS + "click-text-to-activate-vault",
Constants.GENERATOR, generator.getFriendlyName(),
Expand All @@ -525,10 +532,13 @@ public static void sendUnlockMessage(UUID uuid, Island island, GeneratorTierObje
Constants.GENERATOR, generator.getFriendlyName()));
}

command += " generator activate ";
commandBuilder.append(addon.getSettings().getPlayerActivateCommand().split(" ")[0]);
}

component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command + generator.getUniqueId()));
commandBuilder.append(" ");
commandBuilder.append(generator.getUniqueId());

component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, commandBuilder.toString()));

user.getPlayer().spigot().sendMessage(component);
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ working-range: 0
# Can be changed with a permission `[gamemode].stone-generator.active-generators.[number]`.
default-active-generators: 3
#
# Send a notification message when player unlocks a new generator.
# 3 messages that will be showed:
# stone-generator.conversations.click-text-to-purchase - if generator is unlocked but is not purchased.
# stone-generator.conversations.click-text-to-activate-vault - if generator is unlocked but requires activation cost.
# stone-generator.conversations.click-text-to-activate - if generator is unlocked and can be activated.
notify-on-unlock: true
#
# This list stores GameModes in which the addon should not work.
# To disable addon it is necessary to write its name in new line that starts with -. Example:
# disabled-gamemodes:
Expand Down
16 changes: 13 additions & 3 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,16 @@ stone-generator:
&7 To set it as 1 empty space,
&7 write "empty".
value: "&b Name: `&r[name]&r&b`"
unlock_notify:
name: "&f&l Notify On Unlock"
description: |-
&7 A message will be send
&7 to a user when he unlocks
&7 a new generator.
enabled: |-
&b Notify on unlock is &a enabled &b .
disabled: |-
&b Notify on unlock is &c disabled &b .
# Buttons in Library GUI
library:
name: "&f&l [name]"
Expand Down Expand Up @@ -876,9 +886,9 @@ stone-generator:
# Message that appears after successful data importing
new-generators-imported: "&a Success, new generators for [gamemode] are imported."
# Message that appears after unlocking a new generator.
click-text-to-purchase: "&e You have unlocked &r [generator] &r&e. Click here to buy it now for [number]."
click-text-to-activate-vault: "&e You have unlocked &r [generator] &r&e. Click here to activate it now for [number]."
click-text-to-activate: "&e You have unlocked &r [generator] &r&e. Click here to activate it now."
click-text-to-purchase: "&e You have unlocked &r [generator]&r&e. Click here to buy it now for [number]."
click-text-to-activate-vault: "&e You have unlocked &r [generator]&r&e. Click here to activate it now for [number]."
click-text-to-activate: "&e You have unlocked &r [generator]&r&e. Click here to activate it now."
# Showcase for manual material translation
materials:
# Names should be lowercase.
Expand Down

0 comments on commit d06eed4

Please sign in to comment.