mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-31 03:41:24 +01:00
Added suport for permission based max size for Stackable
add the permission fabledskyblock.stackable.MATERIAL.maxsize.MAXSIZE this is a one of the defaults fabledskyblock.stackable.diamond_block.maxsize.5000
This commit is contained in:
parent
d6cdb061ba
commit
a77095d4d1
@ -47,6 +47,9 @@ import com.songoda.skyblock.utils.version.Materials;
|
||||
import com.songoda.skyblock.utils.version.NMSUtil;
|
||||
import com.songoda.skyblock.utils.version.Sounds;
|
||||
import com.songoda.skyblock.world.WorldManager;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
public class Interact implements Listener {
|
||||
|
||||
@ -173,16 +176,24 @@ public class Interact implements Listener {
|
||||
Location location = event.getClickedBlock().getLocation();
|
||||
Stackable stackable = stackableManager.getStack(location, blockType);
|
||||
int itemAmount = event.getItem().getAmount();
|
||||
Materials material = Materials.getMaterials(block.getType(), block.getData());
|
||||
int maxSize = getStackLimit(player, material) + 1;
|
||||
|
||||
if (stackable == null) {
|
||||
stackableManager.addStack(stackable = new Stackable(location, blockType));
|
||||
stackableManager.addStack(stackable = new Stackable(location, blockType, maxSize));
|
||||
stackable.setSize(itemAmount + 1);
|
||||
} else {
|
||||
stackable.setSize(stackable.getSize() + itemAmount);
|
||||
stackable.setMaxSize(maxSize);
|
||||
if (stackable.getSize() + itemAmount <= stackable.getMaxSize()) {
|
||||
stackable.setSize(stackable.getSize() + itemAmount);
|
||||
}
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
InventoryUtil.takeItem(player, itemAmount);
|
||||
|
||||
if (stackable.getSize() + itemAmount <= stackable.getMaxSize()) {
|
||||
InventoryUtil.takeItem(player, itemAmount);
|
||||
}
|
||||
|
||||
FileManager.Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
@ -588,6 +599,21 @@ public class Interact implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private int getStackLimit(Player player, Materials materials) {
|
||||
String maxSizePermission = "fabledskyblock.stackable." + materials.name().toLowerCase() + ".maxsize.";
|
||||
System.out.println(maxSizePermission);
|
||||
|
||||
for (PermissionAttachmentInfo attachmentInfo : player.getEffectivePermissions()) {
|
||||
if (attachmentInfo.getPermission().startsWith(maxSizePermission)) {
|
||||
String permission = attachmentInfo.getPermission();
|
||||
int i = Integer.parseInt(permission.substring(permission.lastIndexOf(".") + 1));
|
||||
System.out.println(i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 5000;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractStructure(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -27,6 +27,7 @@ public class Stackable {
|
||||
private Materials material;
|
||||
private int size = 2;
|
||||
private ArmorStand display;
|
||||
private int maxSize;
|
||||
|
||||
public Stackable(Location location, Materials material) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
@ -37,6 +38,16 @@ public class Stackable {
|
||||
this.save();
|
||||
}
|
||||
|
||||
public Stackable(Location location, Materials material, int maxSize) {
|
||||
this.uuid = UUID.randomUUID();
|
||||
this.location = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
this.material = material;
|
||||
this.maxSize = maxSize;
|
||||
this.updateDisplay();
|
||||
SkyBlock.getInstance().getSoundManager().playSound(location, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public Stackable(UUID uuid, Location location, Materials material, int size) {
|
||||
this.uuid = uuid;
|
||||
this.location = new Location(location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
@ -76,6 +87,14 @@ public class Stackable {
|
||||
this.save();
|
||||
}
|
||||
|
||||
public int getMaxSize() {
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
|
||||
public void addOne() {
|
||||
this.size++;
|
||||
this.updateDisplay();
|
||||
|
Loading…
Reference in New Issue
Block a user