
Break Denyer
This mod provides Minecraft server administrators with an effective tool to protect the game environment from unwanted interference by regular players. The main function is to block the ability to destroy and place blocks for all participants who do not have operator rights.
Key Features
This solution is ideal for servers operating in survival or adventure modes, where administrators want to keep certain structures and landscapes intact. At the same time, players retain the ability to fight mobs, create items, use weapons, and interact with other game mechanics not related to block modification.
Technical Implementation
The mod works on the server side and automatically cancels block break and place events if the player does not have operator status. Rights verification is performed through Minecraft's system mechanisms.
package thut.breakdeny;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.management.UserListOpsEntry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import net.minecraftforge.event.world.BlockEvent.PlaceEvent;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
@Mod(modid = BreakDeny.MODID, name = "Break Denyer", version = BreakDeny.VERSION, acceptableRemoteVersions = "*")
public class BreakDeny
{
public static final String MODID = "break_denyer";
public static final String VERSION = "1.0.0";
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
if (event.getSide() == Side.SERVER) MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void denyBreak(BreakEvent event)
{
EntityPlayer player = event.getPlayer();
if (!isOp(player)) event.setCanceled(true);
}
@SubscribeEvent
public void denyPlace(PlaceEvent event)
{
EntityPlayer player = event.player;
if (!isOp(player)) event.setCanceled(true);
}
private boolean isOp(EntityPlayer player)
{
if (player != null && !player.worldObj.isRemote)
{
UserListOpsEntry userentry = (UserListOpsEntry) ((EntityPlayerMP) player).mcServer.getConfigurationManager()
.getOppedPlayers().getEntry(player.getGameProfile());
if (userentry != null
|| !FMLCommonHandler.instance().getMinecraftServerInstance().isDedicatedServer()) { return true; }
}
return false;
}
}