diff --git a/src/main/java/codechicken/chunkloader/BlockChunkLoader.java b/src/main/java/codechicken/chunkloader/BlockChunkLoader.java index 6c43c0b..3d29f27 100644 --- a/src/main/java/codechicken/chunkloader/BlockChunkLoader.java +++ b/src/main/java/codechicken/chunkloader/BlockChunkLoader.java @@ -93,7 +93,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p if (!world.isRemote) { TileChunkLoader tile = (TileChunkLoader) world.getTileEntity(x, y, z); - if (tile.owner == null || tile.owner.equals(player.getCommandSenderName()) + if (tile.owner == null || (ChunkLoaderManager.userInteract() && tile.owner.equals(player.getCommandSenderName())) || ChunkLoaderManager.opInteract() && ServerUtils.isPlayerOP(player.getCommandSenderName())) { PacketCustom packet = new PacketCustom(ChunkLoaderSPH.channel, 12); packet.writeCoord(x, y, z); diff --git a/src/main/java/codechicken/chunkloader/ChunkLoaderCPH.java b/src/main/java/codechicken/chunkloader/ChunkLoaderCPH.java index ad8751c..d7c037c 100644 --- a/src/main/java/codechicken/chunkloader/ChunkLoaderCPH.java +++ b/src/main/java/codechicken/chunkloader/ChunkLoaderCPH.java @@ -82,4 +82,11 @@ public static void sendShapeChange(TileChunkLoader tile, ChunkLoaderShape shape, packet.writeByte(radius); packet.sendToServer(); } + + public static void sendOwnerChange(TileChunkLoader tile, String owner) { + PacketCustom packet = new PacketCustom(channel, 3); + packet.writeCoord(tile.xCoord, tile.yCoord, tile.zCoord); + packet.writeString(owner); + packet.sendToServer(); + } } diff --git a/src/main/java/codechicken/chunkloader/ChunkLoaderManager.java b/src/main/java/codechicken/chunkloader/ChunkLoaderManager.java index 6ae1e85..a2532b2 100644 --- a/src/main/java/codechicken/chunkloader/ChunkLoaderManager.java +++ b/src/main/java/codechicken/chunkloader/ChunkLoaderManager.java @@ -427,6 +427,8 @@ public static void load() { private static boolean reloadDimensions = false; private static boolean opInteract = false; + private static boolean userInteract = true; + private static boolean allowOwnerChange = false; private static int cleanupTicks; private static int maxChunks; private static int awayTimeout; @@ -587,6 +589,12 @@ public static void initConfig(ConfigFile config) { opInteract = config.getTag("op-interact").setComment( "Enabling this lets OPs alter other player's chunkloaders. WARNING: If you change a chunkloader, you have no idea what may break/explode by not being chunkloaded.") .getBooleanValue(false); + userInteract = config.getTag("user-interact").setComment( + "Disabling this lets normal non-OP player's never open any chunkloader, also not their own. WARNING: Only to be used if 'op-interact' is true to ensure only admins can control chunk loaders.") + .getBooleanValue(true); + allowOwnerChange = config.getTag("allow-owner-change").setComment( + "Enabling this enables the option to change the owner of a Chunkloader. By default only the owner can change it. In case of 'user-interact' is false, only OPs can edit them. WARNING: If you change a owner of a chunkloader, you have no idea what may break/explode.") + .getBooleanValue(false); maxChunks = config.getTag("maxchunks").setComment("The maximum number of chunks per chunkloader") .getIntValue(400); awayTimeout = config.getTag("awayTimeout").setComment( @@ -783,6 +791,14 @@ public static boolean opInteract() { return opInteract; } + public static boolean userInteract() { + return userInteract; + } + + public static boolean allowOwnerChange() { + return allowOwnerChange; + } + public static void unloadWorld(World world) { int dim = CommonUtils.getDimension(world); for (TicketManager mgr : playerOrganisers.values()) mgr.unloadDimension(dim); diff --git a/src/main/java/codechicken/chunkloader/ChunkLoaderSPH.java b/src/main/java/codechicken/chunkloader/ChunkLoaderSPH.java index 1037be0..df27c18 100644 --- a/src/main/java/codechicken/chunkloader/ChunkLoaderSPH.java +++ b/src/main/java/codechicken/chunkloader/ChunkLoaderSPH.java @@ -21,7 +21,9 @@ public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandler case 2: handleChunkLoaderChangePacket(sender.worldObj, packet); break; - + case 3: + handleChunkLoaderOwnerPackage(sender.worldObj, packet); + break; } } @@ -32,4 +34,12 @@ private void handleChunkLoaderChangePacket(World world, PacketCustom packet) { ctile.setShapeAndRadius(ChunkLoaderShape.values()[packet.readUByte()], packet.readUByte()); } } + + private void handleChunkLoaderOwnerPackage(World world, PacketCustom packet) { + TileEntity tile = world.getTileEntity(packet.readInt(), packet.readInt(), packet.readInt()); + if (tile instanceof TileChunkLoader) { + TileChunkLoader ctile = (TileChunkLoader) tile; + ctile.setOwner(packet.readString()); + } + } } diff --git a/src/main/java/codechicken/chunkloader/GuiChunkLoader.java b/src/main/java/codechicken/chunkloader/GuiChunkLoader.java index b20111d..b66ef3b 100644 --- a/src/main/java/codechicken/chunkloader/GuiChunkLoader.java +++ b/src/main/java/codechicken/chunkloader/GuiChunkLoader.java @@ -2,9 +2,11 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; import org.lwjgl.opengl.GL11; +import codechicken.core.ServerUtils; import codechicken.lib.render.CCRenderState; import codechicken.lib.util.LangProxy; @@ -14,6 +16,7 @@ public class GuiChunkLoader extends GuiScreen { public GuiButton laserButton; public GuiButton shapeButton; + public GuiTextField ownerText; public TileChunkLoader tile; public GuiChunkLoader(TileChunkLoader tile) { @@ -27,6 +30,13 @@ public void initGui() { buttonList.add(new GuiButton(2, width / 2 - 80, height / 2 - 45, 20, 20, "-")); buttonList.add(laserButton = new GuiButton(3, width / 2 + 7, height / 2 - 60, 75, 20, "-")); buttonList.add(shapeButton = new GuiButton(4, width / 2 + 7, height / 2 - 37, 75, 20, "-")); + + if (enableOwner()) + buttonList.add(new GuiButton(5, width / 2 + 7, height / 2 - 8, 75, 20, lang.translate("setowner"))); + + ownerText = new GuiTextField(fontRendererObj, width / 2 - 80, height / 2 - 7, 80, 18); + ownerText.setText(tile.getOwner()); + updateNames(); super.initGui(); @@ -46,12 +56,16 @@ public void updateScreen() { } updateNames(); super.updateScreen(); + ownerText.updateCursorCounter(); } public void drawScreen(int i, int j, float f) { drawDefaultBackground(); drawContainerBackground(); + if (enableOwner()) + ownerText.drawTextBox(); + super.drawScreen(i, j, f);// buttons GL11.glDisable(GL11.GL_LIGHTING); @@ -85,6 +99,13 @@ protected void mouseClicked(int par1, int par2, int par3) { button = par3; if (par3 == 1) par3 = 0; super.mouseClicked(par1, par2, par3); + ownerText.mouseClicked(par1, par2, par3); + } + + @Override + protected void keyTyped(char par1, int par2) { + super.keyTyped(par1, par2); + ownerText.textboxKeyTyped(par1, par2); } protected void actionPerformed(GuiButton guibutton) { @@ -93,14 +114,21 @@ protected void actionPerformed(GuiButton guibutton) { if (guibutton.id == 3) tile.renderInfo.showLasers = !tile.renderInfo.showLasers; if (guibutton.id == 4) ChunkLoaderCPH.sendShapeChange(tile, button == 1 ? tile.shape.prev() : tile.shape.next(), tile.radius); + if (guibutton.id == 5) + ChunkLoaderCPH.sendOwnerChange(tile, ownerText.getText()); } private void drawContainerBackground() { + boolean isOpInteract = enableOwner(); GL11.glColor4f(1, 1, 1, 1); - CCRenderState.changeTexture("chickenchunks:textures/gui/guiSmall.png"); + CCRenderState.changeTexture("chickenchunks:textures/gui/" + (isOpInteract ? "guiSmall2" : "guiSmall") + ".png"); int posx = width / 2 - 88; int posy = height / 2 - 83; - drawTexturedModalRect(posx, posy, 0, 0, 176, 166); + drawTexturedModalRect(posx, posy, 0, 0, 176, isOpInteract ? 192 : 166); + } + + private boolean enableOwner() { + return ChunkLoaderManager.allowOwnerChange() && (!ChunkLoaderManager.userInteract() || (ChunkLoaderManager.opInteract() && ServerUtils.isPlayerOP(this.tile.owner))); } public boolean doesGuiPauseGame() { diff --git a/src/main/java/codechicken/chunkloader/TileChunkLoader.java b/src/main/java/codechicken/chunkloader/TileChunkLoader.java index 2e6a42d..9764571 100644 --- a/src/main/java/codechicken/chunkloader/TileChunkLoader.java +++ b/src/main/java/codechicken/chunkloader/TileChunkLoader.java @@ -8,7 +8,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; - +import net.minecraft.world.chunk.storage.ChunkLoader; import codechicken.lib.packet.PacketCustom; public class TileChunkLoader extends TileChunkLoaderBase { @@ -29,6 +29,20 @@ public static void handleDescriptionPacket(PacketCustom packet, World world) { } } + public boolean setOwner(String newOwner) { + // If remote, we just remember the new owner. + if (worldObj.isRemote) { + owner = newOwner; + return true; + } + + // Disable for the old owner, then set the new owner and enable again. + deactivate(); + owner = newOwner; + activate(); + return true; + } + public boolean setShapeAndRadius(ChunkLoaderShape newShape, int newRadius) { if (worldObj.isRemote) { radius = newRadius; diff --git a/src/main/resources/assets/chickenchunks/lang/en_US.lang b/src/main/resources/assets/chickenchunks/lang/en_US.lang index 5552d05..bec302e 100644 --- a/src/main/resources/assets/chickenchunks/lang/en_US.lang +++ b/src/main/resources/assets/chickenchunks/lang/en_US.lang @@ -7,6 +7,7 @@ chickenchunks.gui.hidelasers=Hide Lasers chickenchunks.gui.chunk=%d Chunk chickenchunks.gui.chunks=%d Chunks chickenchunks.gui.radius=Radius +chickenchunks.gui.setowner=Set Owner chickenchunks.shape.square=Square chickenchunks.shape.circle=Circle diff --git a/src/main/resources/assets/chickenchunks/textures/gui/guiSmall2.png b/src/main/resources/assets/chickenchunks/textures/gui/guiSmall2.png new file mode 100644 index 0000000..99e0272 Binary files /dev/null and b/src/main/resources/assets/chickenchunks/textures/gui/guiSmall2.png differ