Skip to content

Commit

Permalink
Fix #340 Allow creative-mode players to cheat in items
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Jul 6, 2016
1 parent fbf7d4a commit 62c77cd
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/main/java/mezz/jei/network/packets/PacketGiveItemStack.java
Expand Up @@ -6,7 +6,6 @@

import mezz.jei.network.IPacketId;
import mezz.jei.network.PacketIdServer;
import net.minecraft.command.CommandGive;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandManager;
import net.minecraft.entity.item.EntityItem;
Expand All @@ -17,10 +16,11 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.UserListOps;
import net.minecraft.server.management.UserListOpsEntry;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.fml.server.FMLServerHandler;

public class PacketGiveItemStack extends PacketJEI {
private ItemStack itemStack;
Expand Down Expand Up @@ -48,11 +48,7 @@ public void readPacketData(PacketBuffer buf, EntityPlayer player) throws IOExcep
if (player instanceof EntityPlayerMP) {
EntityPlayerMP sender = (EntityPlayerMP) player;

MinecraftServer minecraftServer = sender.mcServer;
ICommandManager commandManager = minecraftServer.getCommandManager();
Map<String, ICommand> commands = commandManager.getCommands();
ICommand giveCommand = commands.get("give");
if (giveCommand != null && giveCommand.checkPermission(minecraftServer, sender)) {
if (hasPermission(sender)) {
NBTTagCompound itemStackSerialized = buf.readNBTTagCompoundFromBuffer();
if (itemStackSerialized != null) {
ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemStackSerialized);
Expand All @@ -68,7 +64,25 @@ public void readPacketData(PacketBuffer buf, EntityPlayer player) throws IOExcep
}
}

public void executeGive(EntityPlayer entityplayer, ItemStack itemStack) {
private static boolean hasPermission(EntityPlayerMP sender) {
if (sender.isCreative()) {
return true;
}

MinecraftServer minecraftServer = sender.mcServer;
ICommandManager commandManager = minecraftServer.getCommandManager();
Map<String, ICommand> commands = commandManager.getCommands();
ICommand giveCommand = commands.get("give");
if (giveCommand != null && giveCommand.checkPermission(minecraftServer, sender)) {
return true;
} else {
UserListOps oppedPlayers = minecraftServer.getPlayerList().getOppedPlayers();
UserListOpsEntry userlistopsentry = oppedPlayers.getEntry(sender.getGameProfile());
return userlistopsentry != null && userlistopsentry.getPermissionLevel() >= minecraftServer.getOpPermissionLevel();
}
}

private static void executeGive(EntityPlayer entityplayer, ItemStack itemStack) {
boolean addedToInventory = entityplayer.inventory.addItemStackToInventory(itemStack);

if (addedToInventory) {
Expand Down

0 comments on commit 62c77cd

Please sign in to comment.