mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-23 00:21:30 +01:00
Fix cycle click nullables
This commit is contained in:
parent
6cdde8ca5f
commit
468ad4e83d
@ -4,7 +4,6 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
@ -72,25 +71,26 @@ public class CycleClick implements PanelItem.ClickHandler {
|
|||||||
if (island != null && user.getUniqueId().equals(island.getOwner())) {
|
if (island != null && user.getUniqueId().equals(island.getOwner())) {
|
||||||
changeOccurred = true;
|
changeOccurred = true;
|
||||||
RanksManager rm = plugin.getRanksManager();
|
RanksManager rm = plugin.getRanksManager();
|
||||||
Flag flag = plugin.getFlagsManager().getFlag(id).orElse(null);
|
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
|
||||||
int currentRank = island.getFlag(flag);
|
int currentRank = island.getFlag(flag);
|
||||||
if (click.equals(ClickType.LEFT)) {
|
if (click.equals(ClickType.LEFT)) {
|
||||||
if (currentRank >= maxRank) {
|
if (currentRank >= maxRank) {
|
||||||
island.setFlag(flag, minRank);
|
island.setFlag(flag, minRank);
|
||||||
} else {
|
} else {
|
||||||
island.setFlag(flag, rm.getRankUpValue(currentRank));
|
island.setFlag(flag, rm.getRankUpValue(currentRank));
|
||||||
|
}
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
|
} else if (click.equals(ClickType.RIGHT)) {
|
||||||
|
if (currentRank <= minRank) {
|
||||||
|
island.setFlag(flag, maxRank);
|
||||||
|
} else {
|
||||||
|
island.setFlag(flag, rm.getRankDownValue(currentRank));
|
||||||
|
}
|
||||||
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
}
|
}
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
// Apply change to panel
|
||||||
} else if (click.equals(ClickType.RIGHT)) {
|
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
||||||
if (currentRank <= minRank) {
|
});
|
||||||
island.setFlag(flag, maxRank);
|
|
||||||
} else {
|
|
||||||
island.setFlag(flag, rm.getRankDownValue(currentRank));
|
|
||||||
}
|
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
|
||||||
}
|
|
||||||
// Apply change to panel
|
|
||||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
|
||||||
} else {
|
} else {
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
@ -45,12 +44,13 @@ public class IslandToggleClick implements ClickHandler {
|
|||||||
// Get the user's island
|
// Get the user's island
|
||||||
Island island = plugin.getIslands().getIsland(user.getWorld(), user);
|
Island island = plugin.getIslands().getIsland(user.getWorld(), user);
|
||||||
if (island != null && user.getUniqueId().equals(island.getOwner())) {
|
if (island != null && user.getUniqueId().equals(island.getOwner())) {
|
||||||
Flag flag = plugin.getFlagsManager().getFlag(id).orElse(null);
|
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
|
||||||
// Toggle flag
|
// Toggle flag
|
||||||
island.toggleFlag(flag);
|
island.toggleFlag(flag);
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.flags.Flag;
|
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
import world.bentobox.bentobox.api.panels.Panel;
|
import world.bentobox.bentobox.api.panels.Panel;
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
|
||||||
@ -42,12 +41,13 @@ public class WorldToggleClick implements ClickHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Get flag
|
// Get flag
|
||||||
Flag flag = plugin.getFlagsManager().getFlag(id).orElse(null);
|
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
|
||||||
// Toggle flag
|
// Toggle flag
|
||||||
flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld()));
|
flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld()));
|
||||||
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F);
|
||||||
// Apply change to panel
|
// Apply change to panel
|
||||||
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem());
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user