Merge branch 'development' into 'master'

2.0.3

See merge request Songoda/songodaupdater!6
This commit is contained in:
Jacob Scott 2019-09-03 20:40:15 +00:00
commit 5aa06c72e8
5 changed files with 39 additions and 19 deletions

View File

@ -4,7 +4,7 @@ stages:
variables: variables:
name: "SongodaCore" name: "SongodaCore"
path: "/builds/$CI_PROJECT_PATH" path: "/builds/$CI_PROJECT_PATH"
version: "2.0.2" version: "2.0.3"
build: build:
stage: build stage: build

View File

@ -129,16 +129,19 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId> <artifactId>UltimateStacker</artifactId>
<version>1.9.6</version> <version>1.9.6</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.bgsoftware</groupId> <groupId>com.bgsoftware</groupId>
<artifactId>WildStacker</artifactId> <artifactId>WildStacker</artifactId>
<version>2-9-0</version> <version>2-9-0</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>uk.antiperson</groupId> <groupId>uk.antiperson</groupId>
<artifactId>stackmob</artifactId> <artifactId>stackmob</artifactId>
<version>4-0-2</version> <version>4-0-2</version>
<scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1158,6 +1158,19 @@ public enum LegacyMaterials {
return name == null ? null : lookupMap.get(name.toUpperCase()); return name == null ? null : lookupMap.get(name.toUpperCase());
} }
/**
* Lookup a Legacy Material by its modern id name. <br />
* This also can grab materials by their legacy, but only if there is no
* modern material by that name.
*
* @param name item to lookup
* @param def default item if this is not a valid material
* @return LegacyMaterial or null if none found
*/
public static LegacyMaterials getMaterial(String name, LegacyMaterials def) {
return name == null ? def : lookupMap.getOrDefault(name.toUpperCase(), def);
}
/** /**
* Lookup a Legacy Material by bukkit material. * Lookup a Legacy Material by bukkit material.
* *
@ -1299,7 +1312,7 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isBlock() { public boolean isBlock() {
return material == null && material.isBlock(); return material != null && material.isBlock();
} }
/** /**
@ -1308,7 +1321,7 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isEdible() { public boolean isEdible() {
return material == null && material.isEdible(); return material != null && material.isEdible();
} }
/** /**
@ -1317,7 +1330,7 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isSolid() { public boolean isSolid() {
return material == null && material.isSolid(); return material != null && material.isSolid();
} }
/** /**
@ -1326,7 +1339,7 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isTransparent() { public boolean isTransparent() {
return material == null && material.isTransparent(); return material != null && material.isTransparent();
} }
/** /**
@ -1335,7 +1348,7 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isFlammable() { public boolean isFlammable() {
return material == null && material.isFlammable(); return material != null && material.isFlammable();
} }
/** /**
@ -1344,7 +1357,7 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isBurnable() { public boolean isBurnable() {
return material == null && material.isBurnable(); return material != null && material.isBurnable();
} }
/** /**
@ -1544,14 +1557,14 @@ public enum LegacyMaterials {
* @return * @return
*/ */
public boolean isOccluding() { public boolean isOccluding() {
return material == null && material.isOccluding(); return material != null && material.isOccluding();
} }
/** /**
* @return True if this material is affected by gravity. * @return True if this material is affected by gravity.
*/ */
public boolean hasGravity() { public boolean hasGravity() {
return material == null && material.hasGravity(); return material != null && material.hasGravity();
} }
/** /**

View File

@ -243,7 +243,7 @@ public class Gui {
public Gui setItem(int cell, ItemStack item) { public Gui setItem(int cell, ItemStack item) {
cellItems.put(cell, item); cellItems.put(cell, item);
if (open && cell >= 0 && cell < inventory.getSize()) { if (inventory != null && cell >= 0 && cell < inventory.getSize()) {
inventory.setItem(cell, item); inventory.setItem(cell, item);
} }
return this; return this;
@ -252,7 +252,7 @@ public class Gui {
public Gui setItem(int row, int col, ItemStack item) { public Gui setItem(int row, int col, ItemStack item) {
final int cell = col + row * 9; final int cell = col + row * 9;
cellItems.put(cell, item); cellItems.put(cell, item);
if (open && cell >= 0 && cell < inventory.getSize()) { if (inventory != null && cell >= 0 && cell < inventory.getSize()) {
inventory.setItem(cell, item); inventory.setItem(cell, item);
} }
return this; return this;

View File

@ -4,6 +4,7 @@ import com.songoda.core.compatibility.LegacyMaterials;
import static com.songoda.core.gui.Gui.trimTitle; import static com.songoda.core.gui.Gui.trimTitle;
import com.songoda.core.gui.events.GuiClickEvent; import com.songoda.core.gui.events.GuiClickEvent;
import com.songoda.core.gui.methods.Clickable; import com.songoda.core.gui.methods.Clickable;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -169,13 +170,12 @@ public class SimplePagedGui extends Gui {
pages = (int) Math.ceil(maxRows / rowsPerPage); pages = (int) Math.ceil(maxRows / rowsPerPage);
// create a new inventory if needed // create a new inventory if needed
final int cells = rows * 9; List<Player> toUpdate = null;
boolean isNew = false; if (Math.min(54, (maxRows + (useHeader ? 1 : 0)) * 9) != inventory.getSize()) {
if (cells != inventory.getSize()) { toUpdate = getPlayers();
this.setRows(maxRows + (useHeader ? 2 : 1)); this.setRows(maxRows + (useHeader ? 1 : 0));
inventory = Bukkit.getServer().createInventory(inventory.getHolder(), cells, inventory = Bukkit.getServer().createInventory(inventory.getHolder(), rows * 9,
title == null ? "" : trimTitle(ChatColor.translateAlternateColorCodes('&', title))); title == null ? "" : trimTitle(ChatColor.translateAlternateColorCodes('&', title)));
isNew = true;
} }
// populate header // populate header
@ -185,17 +185,21 @@ public class SimplePagedGui extends Gui {
inventory.setItem(i, item != null ? item : (headerBackItem != null ? headerBackItem : blankItem)); inventory.setItem(i, item != null ? item : (headerBackItem != null ? headerBackItem : blankItem));
} }
} }
// last row is dedicated to pagation // last row is dedicated to pagation
final int cells = rows * 9;
for (int i = cells - 9; i < cells; ++i) { for (int i = cells - 9; i < cells; ++i) {
inventory.setItem(i, footerBackItem != null ? footerBackItem : blankItem); inventory.setItem(i, footerBackItem != null ? footerBackItem : blankItem);
} }
// fill out the rest of the page // fill out the rest of the page
showPage(); showPage();
if(isNew) { // did we need to change the display window size?
if(toUpdate != null) {
// whoopsie! // whoopsie!
exit(); exit();
getPlayers().forEach(player -> ((GuiHolder) inventory.getHolder()).manager.showGUI(player, this)); toUpdate.forEach(player -> ((GuiHolder) inventory.getHolder()).manager.showGUI(player, this));
} }
} }