Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I love packets
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/net/aufdemrand/denizen/utilities/packets/SignEditor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.aufdemrand.denizen.utilities.packets; | ||
|
||
import net.aufdemrand.denizen.utilities.debugging.dB; | ||
import net.minecraft.server.v1_8_R1.BlockPosition; | ||
import net.minecraft.server.v1_8_R1.PacketPlayOutOpenSignEditor; | ||
import net.minecraft.server.v1_8_R1.TileEntity; | ||
import net.minecraft.server.v1_8_R1.TileEntitySign; | ||
import org.bukkit.Location; | ||
import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
public class SignEditor { | ||
|
||
private static final Field sign_location; | ||
|
||
static { | ||
Map<String, Field> fields = PacketHelper.registerFields(PacketPlayOutOpenSignEditor.class); | ||
sign_location = fields.get("a"); | ||
} | ||
|
||
public static PacketPlayOutOpenSignEditor getSignEditorPacket(Location location) { | ||
PacketPlayOutOpenSignEditor signEditorPacket = new PacketPlayOutOpenSignEditor(); | ||
try { | ||
sign_location.set(signEditorPacket, new BlockPosition(location.getX(), location.getY(), location.getZ())); | ||
} catch (Exception e) { | ||
dB.echoError(e); | ||
} | ||
return signEditorPacket; | ||
} | ||
|
||
public static void editSign(Player player, Location location) { | ||
PacketPlayOutOpenSignEditor signEditorPacket = getSignEditorPacket(location); | ||
TileEntity sign = ((CraftWorld) location.getWorld()).getTileEntityAt(location.getBlockX(), | ||
location.getBlockY(), location.getBlockZ()); | ||
if (sign instanceof TileEntitySign) { | ||
((TileEntitySign) sign).isEditable = true; | ||
PacketHelper.sendPacket(player, signEditorPacket); | ||
} | ||
else { | ||
dB.echoError("Can't edit non-sign materials!"); | ||
} | ||
} | ||
|
||
} |