Cleaned up interaction and fixed the last dupe

This commit is contained in:
Hexeption 2020-02-17 03:52:21 +00:00 committed by Brianna
parent 0a6c5e5a5b
commit 46928058bb
2 changed files with 34 additions and 29 deletions

View File

@ -190,18 +190,32 @@ public class Interact implements Listener {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (configLoad.getBoolean("Island.Stackable.Limit.Enable")) { if (configLoad.getBoolean("Island.Stackable.Limit.Enable")) {
// Add block to stackable
Materials material = Materials.getMaterials(block.getType(), block.getData()); Materials material = Materials.getMaterials(block.getType(), block.getData());
int maxSize = getStackLimit(player, material) + 1; int maxStackSize = getStackLimit(player, material);
if (stackable == null) { if (stackable == null) {
stackableManager.addStack(stackable = new Stackable(location, blockType, maxSize)); stackableManager.addStack(stackable = new Stackable(location, blockType, maxStackSize));
stackable.setSize(itemAmount + 1); stackable.setSize(itemAmount + 1);
if(stackable.isMaxSize()){
stackable.setSize(stackable.getMaxSize());
event.setCancelled(true);
return;
}
} else { } else {
stackable.setMaxSize(maxSize); stackable.setMaxSize(maxStackSize);
if (stackable.getSize() + itemAmount <= stackable.getMaxSize()) { stackable.setSize(stackable.getSize() + itemAmount);
stackable.setSize(stackable.getSize() + itemAmount); if(stackable.isMaxSize()){
System.out.println(stackable.getMaxSize() + ":" + stackable.getSize());
stackable.setSize(stackable.getMaxSize());
event.setCancelled(true);
return;
} }
} }
// Disables interaction
event.setCancelled(true);
} else { } else {
if (stackable == null) { if (stackable == null) {
stackableManager.addStack(stackable = new Stackable(location, blockType)); stackableManager.addStack(stackable = new Stackable(location, blockType));
@ -209,44 +223,31 @@ public class Interact implements Listener {
} else { } else {
stackable.setSize(stackable.getSize() + itemAmount); stackable.setSize(stackable.getSize() + itemAmount);
} }
event.setCancelled(true);
} }
event.setCancelled(true); InventoryUtil.takeItem(player, itemAmount);
if (configLoad.getBoolean("Island.Stackable.Limit.Enable")) {
if (stackable.getSize() + itemAmount <= stackable.getMaxSize()) {
InventoryUtil.takeItem(player, itemAmount);
}
} else {
InventoryUtil.takeItem(player, itemAmount);
}
if (!configLoad.getBoolean("Island.Block.Level.Enable")) { if (!configLoad.getBoolean("Island.Block.Level.Enable")) {
return; return;
} }
Materials materials = Materials.getMaterials(block.getType(), block.getData()); long materialAmmount = 0;
IslandLevel level = island.getLevel();
Materials material = Materials.getMaterials(block.getType(), block.getData());
if (materials == null) { if (material == null) {
return; return;
} }
long materialAmount = 0;
IslandLevel level = island.getLevel();
if (level.hasMaterial(materials.name())) { if (level.hasMaterial(material.name())) {
materialAmount = level.getMaterialAmount(materials.name()); materialAmmount = level.getMaterialAmount(material.name());
} }
if (configLoad.getBoolean("Island.Stackable.Limit.Enable")) { level.setMaterialAmount(material.name(), materialAmmount + itemAmount);
if (stackable.getSize() + itemAmount <= stackable.getMaxSize()) {
level.setMaterialAmount(materials.name(), materialAmount + itemAmount);
}else {
return;
}
} else {
level.setMaterialAmount(materials.name(), materialAmount + itemAmount);
}
return; return;
} }
// Check if the clicked block is outside of the border. // Check if the clicked block is outside of the border.

View File

@ -109,6 +109,10 @@ public class Stackable {
this.save(); this.save();
} }
public boolean isMaxSize(){
return size > maxSize;
}
private void updateDisplay() { private void updateDisplay() {
// The chunk needs to be loaded otherwise the getNearbyEntities() in // The chunk needs to be loaded otherwise the getNearbyEntities() in
// removeDisplay() won't find anything // removeDisplay() won't find anything