From 8e2befa2a41f7450c3024674fca3592c10bb0a78 Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Fri, 4 Oct 2019 11:35:24 -0500 Subject: [PATCH] update doubleGui functions --- .../java/com/songoda/core/SongodaPlugin.java | 1 - .../java/com/songoda/core/gui/DoubleGui.java | 37 +++++++++++++++++++ .../main/java/com/songoda/core/gui/Gui.java | 17 +++++++++ .../java/com/songoda/core/locale/Message.java | 2 +- 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/songoda/core/SongodaPlugin.java b/Core/src/main/java/com/songoda/core/SongodaPlugin.java index 9c2595fc..15e38515 100644 --- a/Core/src/main/java/com/songoda/core/SongodaPlugin.java +++ b/Core/src/main/java/com/songoda/core/SongodaPlugin.java @@ -1,7 +1,6 @@ package com.songoda.core; import com.songoda.core.configuration.Config; -import com.songoda.core.configuration.ConfigFileConfigurationAdapter; import com.songoda.core.locale.Locale; import com.songoda.core.utils.Metrics; import java.util.List; diff --git a/Core/src/main/java/com/songoda/core/gui/DoubleGui.java b/Core/src/main/java/com/songoda/core/gui/DoubleGui.java index 1dfadfc2..856f2c89 100644 --- a/Core/src/main/java/com/songoda/core/gui/DoubleGui.java +++ b/Core/src/main/java/com/songoda/core/gui/DoubleGui.java @@ -47,6 +47,11 @@ public class DoubleGui extends Gui { allowDropItems = false; } + public DoubleGui(Gui parent) { + super(parent); + allowDropItems = false; + } + public int getPlayerRows() { return playerRows; } @@ -85,6 +90,38 @@ public class DoubleGui extends Gui { return this; } + public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) { + final int last = invOffset(cellLast); + for (int cell = invOffset(cellFirst); cell <= last; ++cell) { + unlockedCells.put(cell, true); + } + return this; + } + + public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast, boolean open) { + final int last = invOffset(cellLast); + for (int cell = invOffset(cellFirst); cell <= last; ++cell) { + unlockedCells.put(cell, open); + } + return this; + } + + public DoubleGui setPlayerUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) { + final int last = invOffset(cellColLast + cellRowLast * 9); + for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) { + unlockedCells.put(cell, true); + } + return this; + } + + public DoubleGui setPlayerUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) { + final int last = invOffset(cellColLast + cellRowLast * 9); + for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) { + unlockedCells.put(cell, open); + } + return this; + } + public DoubleGui setPlayerItem(int cell, ItemStack item) { cellItems.put(invOffset(cell), item); if (open && cell >= 0 && cell < 36) { diff --git a/Core/src/main/java/com/songoda/core/gui/Gui.java b/Core/src/main/java/com/songoda/core/gui/Gui.java index 82da0cae..2797b1f5 100644 --- a/Core/src/main/java/com/songoda/core/gui/Gui.java +++ b/Core/src/main/java/com/songoda/core/gui/Gui.java @@ -181,6 +181,14 @@ public class Gui { return this; } + @NotNull + public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) { + for (int cell = cellFirst; cell <= cellLast; ++cell) { + unlockedCells.put(cell, open); + } + return this; + } + @NotNull public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) { final int last = cellColLast + cellRowLast * 9; @@ -190,6 +198,15 @@ public class Gui { return this; } + @NotNull + public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) { + final int last = cellColLast + cellRowLast * 9; + for (int cell = cellColFirst + cellRowFirst * 9; cell <= last; ++cell) { + unlockedCells.put(cell, open); + } + return this; + } + @NotNull public Gui setUnlocked(int cell, boolean open) { unlockedCells.put(cell, open); diff --git a/Core/src/main/java/com/songoda/core/locale/Message.java b/Core/src/main/java/com/songoda/core/locale/Message.java index e30c586f..a19256cb 100644 --- a/Core/src/main/java/com/songoda/core/locale/Message.java +++ b/Core/src/main/java/com/songoda/core/locale/Message.java @@ -119,7 +119,7 @@ public class Message { */ public Message processPlaceholder(String placeholder, Object replacement) { final String place = Matcher.quoteReplacement(placeholder); - this.message = message.replaceAll("%" + place + "%|\\{" + place +"\\}", Matcher.quoteReplacement(replacement.toString())); + this.message = message.replaceAll("%" + place + "%|\\{" + place +"\\}", replacement == null ? "" : Matcher.quoteReplacement(replacement.toString())); return this; }