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

Make Slimefun blocks unable to be replaced #93

Merged
merged 2 commits into from
Jul 20, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public class SensibleToolboxPlugin extends JavaPlugin implements ConfigurationLi
private MinecraftVersion minecraftVersion = MinecraftVersion.UNKNOWN;

private ConfigurationManager configManager;
private boolean slimefunEnabled = false;
private boolean protocolLibEnabled = false;
private SoundMufflerListener soundMufflerListener;
private boolean enabled = false;
Expand Down Expand Up @@ -258,6 +259,7 @@ public void onEnable() {
scheduleEnergyNetTicker();

if (getServer().getPluginManager().isPluginEnabled("Slimefun")) {
slimefunEnabled = true;
new SlimefunBridge(this);
}

Expand Down Expand Up @@ -485,6 +487,10 @@ private void setupProtocolLib() {
}
}

public boolean isSlimefunEnabled() {
return slimefunEnabled;
}

public boolean isProtocolLibEnabled() {
return protocolLibEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;

import me.mrCookieSlime.Slimefun.api.BlockStorage;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.sensibletoolbox.SensibleToolboxPlugin;
import io.github.thebusybiscuit.sensibletoolbox.api.SensibleToolbox;
import io.github.thebusybiscuit.sensibletoolbox.api.energy.Chargeable;
import io.github.thebusybiscuit.sensibletoolbox.api.items.BaseSTBItem;
Expand Down Expand Up @@ -253,14 +255,21 @@ private int howMuchDoesPlayerHave(Player p, Material mat) {
}

protected boolean canReplace(Player player, Block b) {
// we won't replace any block which can hold items, or any STB block, or any unbreakable block
// Check for non-replaceable block types.
// STB Blocks
if (SensibleToolbox.getBlockAt(b.getLocation(), true) != null) {
return false;
// Vanilla inventories
} else if (VanillaInventoryUtils.isVanillaInventory(b)) {
return false;
// Slimefun Blocks
} else if (SensibleToolboxPlugin.getInstance().isSlimefunEnabled() && BlockStorage.hasBlockInfo(b)) {
return false;
// Unbreakable Blocks
} else if (b.getType().getHardness() >= 3600000) {
return false;
} else {
// Block is replaceable, return permission to break
return SensibleToolbox.getProtectionManager().hasPermission(player, b, ProtectableAction.BREAK_BLOCK);
}
}
Expand Down