Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixed] Players were able to steal items from Island while Previewing… #54

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.craftaro</groupId>
<artifactId>FabledSkyBlock</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>

<name>FabledSkyBlock</name>
<description>Bring your server's SkyBlock experience to the next level with the ability to fine-tune island settings, create custom islands, view leaderboards, and much more</description>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>com.craftaro</groupId>
<artifactId>CraftaroCore</artifactId>
<version>3.6.0-SNAPSHOT</version>
<version>3.7.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void onCommandByPlayer(Player player, String[] args) {
}

soundManager.playSound(player, XSound.ENTITY_VILLAGER_NO);

return;
}
// Do not preview if user has an island
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.hooks.LogManager;
import com.craftaro.skyblock.playerdata.PlayerData;
import com.craftaro.third_party.com.cryptomorin.xseries.XBlock;
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
import com.craftaro.third_party.com.cryptomorin.xseries.XSound;
Expand Down Expand Up @@ -170,6 +171,14 @@ public void onPlayerInteract(PlayerInteractEvent event) {
return;
}

// Check if the player is previewing an island and cancel interactions.
PlayerData data = this.plugin.getPlayerDataManager().getPlayerData(player);
if (data != null && data.isPreview()) {
// Cancel the interaction
event.setCancelled(true);
this.plugin.getMessageManager().sendMessage(player, "You cannot interact with blocks while previewing an island.");
}

// Check permissions.
if (!this.plugin.getPermissionManager().processPermission(event, player, island)) {
return;
Expand Down Expand Up @@ -231,24 +240,37 @@ public void onPlayerInteract(PlayerInteractEvent event) {
// Add block to stackable
int maxStackSize = getStackLimit(player, material.get());

//Fixing Dupe that was found when stack hits the limit and player gets whole (applied stack) back.
if (stackable == null) {
stackableManager.addStack(stackable = new Stackable(location, blockType.get(), maxStackSize));
stackable.setSize(itemAmount + 1);
if (stackable.isMaxSize()) {
stackable = new Stackable(location, blockType.get(), maxStackSize);
stackableManager.addStack(stackable);

int spaceAvailable = stackable.getMaxSize() - stackable.getSize();
if (itemAmount <= spaceAvailable) {
stackable.setSize(stackable.getSize() + itemAmount);
} else {
stackable.setSize(stackable.getMaxSize());
int excessAmount = itemAmount - spaceAvailable;
// Return the excess items to the player
player.getInventory().addItem(new ItemStack(blockType.get().parseMaterial(), excessAmount));
event.setCancelled(true);
return;
}
} else {
stackable.setMaxSize(maxStackSize);
stackable.setSize(stackable.getSize() + itemAmount);
if (stackable.isMaxSize()) {

int spaceAvailable = stackable.getMaxSize() - stackable.getSize();
if (itemAmount <= spaceAvailable) {
stackable.setSize(stackable.getSize() + itemAmount);
} else {
stackable.setSize(stackable.getMaxSize());
int excessAmount = itemAmount - spaceAvailable;
// Return the excess items to the player
player.getInventory().addItem(new ItemStack(blockType.get().parseMaterial(), excessAmount));
event.setCancelled(true);
return;
}
}


// Disables interaction
event.setCancelled(true);

Expand Down Expand Up @@ -291,7 +313,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {

}

// Check if the clicked block is outside of the border.
// Check if the clicked block is outside the border.
WorldManager worldManager = this.plugin.getWorldManager();
org.bukkit.block.Block clickedBlock = event.getClickedBlock();
IslandWorld world = worldManager.getIslandWorld(clickedBlock.getWorld());
Expand Down
Loading