Skip to content

Commit

Permalink
Merge pull request #176 from balugaq/master
Browse files Browse the repository at this point in the history
fix security, fix boom, fix dupe
  • Loading branch information
balugaq authored Nov 14, 2024
2 parents c3d5103 + 42ee8c8 commit 76db30a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ytdd9527.networksexpansion</groupId>
<artifactId>NetworksExpansion</artifactId>
<version>2.1-Alpha-7</version>
<version>2.1-Alpha-8</version>

<distributionManagement>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public String color(@Nonnull String str) {
}
}
if (!found) {
Networks.getInstance().getLogger().warning("Unknown color code: " + colorCode);
break;
}
matcher = this.pattern.matcher(str);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.attributes.DistinctiveItem;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction;
import io.ncbpfluffybear.fluffymachines.items.Barrel;
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenu;
import org.bukkit.Location;
Expand All @@ -46,6 +48,10 @@

@SuppressWarnings("unused")
public class ItemMover extends SpecialSlimefunItem implements DistinctiveItem {
@Nonnull
public static final Interaction[] CHECK_INTERACTIONS = new Interaction[] {
Interaction.PLACE_BLOCK, Interaction.BREAK_BLOCK, Interaction.INTERACT_BLOCK
};
@Nonnull
public static final List<String> DEFAULT_LORE = ExpansionItemStacks.ITEM_MOVER.getItemMeta() == null ? new ArrayList<>() : (ExpansionItemStacks.ITEM_MOVER.getItemMeta().hasLore() && ExpansionItemStacks.ITEM_MOVER.getItemMeta().getLore() != null ? ExpansionItemStacks.ITEM_MOVER.getItemMeta().getLore() : new ArrayList<>());

Expand All @@ -70,12 +76,14 @@ public ItemMover(@Nonnull ItemGroup itemGroup, @Nonnull SlimefunItemStack item,
return;
}
final Location location = optional.get().getLocation();
if (!player.isSneaking()) {
// Right-click
tryDepositIntoMover(player, itemStack, location);
} else {
// Shift+Right-click
tryWithdrawFromMover(player, itemStack, location);
if (hasPermission(player, location)) {
if (!player.isSneaking()) {
// Right-click
tryDepositIntoMover(player, itemStack, location);
} else {
// Shift+Right-click
tryWithdrawFromMover(player, itemStack, location);
}
}
}
e.cancel();
Expand Down Expand Up @@ -366,6 +374,9 @@ public static NetworkStorage getNetworkStorage(@Nonnull Location location) {
}

private static void tryDepositIntoMover(Player player, ItemStack mover, Location clickedLocation) {
if (!hasPermission(player, clickedLocation)) {
return;
}
int storedAmount = getStoredAmount(mover);
ItemStack storedItemStack = getStoredItemStack(mover);
BarrelIdentity barrel = getBarrel(player, clickedLocation);
Expand Down Expand Up @@ -404,6 +415,9 @@ private static void tryDepositIntoMover(Player player, ItemStack mover, Location
}

private static void tryWithdrawFromMover(Player player, ItemStack mover, Location clickedLocation) {
if (!hasPermission(player, clickedLocation)) {
return;
}
int storedAmount = getStoredAmount(mover);
ItemStack storedItemStack = getStoredItemStack(mover);
BarrelIdentity barrel = getBarrel(player, clickedLocation);
Expand Down Expand Up @@ -442,4 +456,19 @@ private static List<String> cloneDefaultLore() {
public boolean canStack(@Nonnull ItemMeta itemMeta, @Nonnull ItemMeta itemMeta1) {
return itemMeta.getPersistentDataContainer().equals(itemMeta1.getPersistentDataContainer());
}

public static boolean hasPermission(Player player, Location location) {
for (Interaction interaction : CHECK_INTERACTIONS) {
if (!Slimefun.getProtectionManager().hasPermission(player, location, interaction)) {
return false;
}
}

SlimefunItem sfitem = StorageCacheUtils.getSfItem(location);
if (!Slimefun.getPermissionsService().hasPermission(player, sfitem)) {
return false;
}

return true;
}
}

0 comments on commit 76db30a

Please sign in to comment.