Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.svdragster.supersign;
- import net.canarymod.Canary;
- import net.canarymod.api.world.blocks.Block;
- import net.canarymod.api.world.blocks.BlockType;
- import net.canarymod.api.world.blocks.ComplexBlock;
- import net.canarymod.api.world.blocks.Sign;
- import net.canarymod.chat.Colors;
- import net.canarymod.hook.HookHandler;
- import net.canarymod.hook.player.BlockLeftClickHook;
- import net.canarymod.hook.player.BlockRightClickHook;
- import net.canarymod.hook.player.SignChangeHook;
- import net.canarymod.plugin.PluginListener;
- public class SuperSignListener implements PluginListener {
- public static String FirstLine = "";
- public static String SecondLine = "";
- public static String ThirdLine = "";
- public static String FourthLine = "";
- public static final String PERMISSION_COPY = "supersign.copy";
- public static final String PERMISSION_RESTORE = "supersign.restore";
- public static final String PERMISSION_COLOR = "supersign.color";
- public static final String STRING_RESTORE = "%restore";
- public static boolean copysign = false;
- public static String[] copiedsign = {};
- public boolean CopySign() {
- if (copysign == false) {
- copysign = true;
- return true;
- } else if (copysign == true) {
- copysign = false;
- return false;
- } else {
- return false;
- }
- }
- public void SaveSign(Sign sign) {
- FirstLine = sign.getTextOnLine(0);
- SecondLine = sign.getTextOnLine(1);
- ThirdLine = sign.getTextOnLine(2);
- FourthLine = sign.getTextOnLine(3);
- }
- public void SaveCopy(Sign sign) {
- copiedsign = sign.getText();
- }
- public String[] RestoreCopy() {
- if (copiedsign.length >= 1) {
- return copiedsign;
- } else {
- String[] NoData = {"No Data"};
- return NoData;
- }
- }
- public String[] RestoreSign() {
- String[] str = {FirstLine, SecondLine, ThirdLine, FourthLine};
- return str;
- }
- @HookHandler
- public void onSignChange(SignChangeHook hook) {
- if (hook.getPlayer().hasPermission(PERMISSION_COPY)) {
- if (copysign) {
- Sign MySign = hook.getSign();
- MySign.setText(RestoreCopy());
- MySign.update();
- hook.getPlayer().message(Colors.GREEN + "Copied sign!");
- }
- }
- if (hook.getPlayer().hasPermission(PERMISSION_RESTORE)) {
- Sign MySign = hook.getSign();
- if (MySign.getTextOnLine(0).equalsIgnoreCase(STRING_RESTORE)) {
- MySign.setText(RestoreSign());
- MySign.update();
- }
- }
- if (hook.getPlayer().hasPermission(PERMISSION_COLOR)) {
- String[] TheText = hook.getSign().getText();
- Sign MySign = hook.getSign();
- for (int i=0; i<TheText.length; i++) {
- String ReplacedText = TheText[i].replace("&", Colors.MARKER); // Make Color codes for each line of the sign.
- MySign.setTextOnLine(ReplacedText, i);
- }
- MySign.update();
- }
- }
- @HookHandler
- public void onBlockRightClick(BlockRightClickHook hook) {
- if (hook.getPlayer().hasPermission(PERMISSION_COPY)) {
- if (hook.getBlockClicked().getTypeId() == 63 || hook.getBlockClicked().getTypeId() == 68) {
- if (copysign) {
- Block MyBlock = hook.getBlockClicked();
- ComplexBlock MyComplexBlock = Canary.getServer().getDefaultWorld().getComplexBlock(MyBlock);
- SaveCopy( (Sign) MyComplexBlock);
- hook.getPlayer().message(Colors.GREEN + "Saved sign!");
- }
- }
- }
- }
- @HookHandler
- public void onBlockLeftClick(BlockLeftClickHook hook) {
- Block MyBlock = hook.getBlock();
- if (MyBlock.getType().equals(BlockType.WallSign) || MyBlock.getType().equals(BlockType.SignPost)) {
- ComplexBlock MyComplexBlock = Canary.getServer().getDefaultWorld().getComplexBlock(MyBlock);
- Sign MySign = (Sign) MyComplexBlock;
- SaveSign(MySign);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment