svdragster

Listener

Jul 31st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.62 KB | None | 0 0
  1. package de.svdragster.supersign;
  2.  
  3. import net.canarymod.Canary;
  4. import net.canarymod.api.world.blocks.Block;
  5. import net.canarymod.api.world.blocks.BlockType;
  6. import net.canarymod.api.world.blocks.ComplexBlock;
  7. import net.canarymod.api.world.blocks.Sign;
  8. import net.canarymod.chat.Colors;
  9. import net.canarymod.hook.HookHandler;
  10. import net.canarymod.hook.player.BlockLeftClickHook;
  11. import net.canarymod.hook.player.BlockRightClickHook;
  12. import net.canarymod.hook.player.SignChangeHook;
  13. import net.canarymod.plugin.PluginListener;
  14.  
  15. public class SuperSignListener implements PluginListener {
  16.     public static String FirstLine = "";
  17.     public static String SecondLine = "";
  18.     public static String ThirdLine = "";
  19.     public static String FourthLine = "";
  20.     public static final String PERMISSION_COPY = "supersign.copy";
  21.     public static final String PERMISSION_RESTORE = "supersign.restore";
  22.     public static final String PERMISSION_COLOR = "supersign.color";
  23.     public static final String STRING_RESTORE = "%restore";
  24.     public static boolean copysign = false;
  25.     public static String[] copiedsign = {};
  26.    
  27.     public boolean CopySign() {
  28.         if (copysign == false) {
  29.             copysign = true;
  30.             return true;
  31.         } else if (copysign == true) {
  32.             copysign = false;
  33.             return false;
  34.         } else {
  35.             return false;
  36.         }
  37.     }
  38.    
  39.     public void SaveSign(Sign sign) {
  40.         FirstLine = sign.getTextOnLine(0);
  41.         SecondLine = sign.getTextOnLine(1);
  42.         ThirdLine = sign.getTextOnLine(2);
  43.         FourthLine = sign.getTextOnLine(3);
  44.     }
  45.    
  46.     public void SaveCopy(Sign sign) {
  47.         copiedsign = sign.getText();
  48.     }
  49.    
  50.     public String[] RestoreCopy() {
  51.         if (copiedsign.length >= 1) {
  52.             return copiedsign;
  53.         } else {
  54.             String[] NoData = {"No Data"};
  55.             return NoData;
  56.         }
  57.     }
  58.    
  59.     public String[] RestoreSign() {
  60.         String[] str = {FirstLine, SecondLine, ThirdLine, FourthLine};
  61.         return str;
  62.     }
  63.    
  64.     @HookHandler
  65.     public void onSignChange(SignChangeHook hook) {
  66.         if (hook.getPlayer().hasPermission(PERMISSION_COPY)) {
  67.             if (copysign) {
  68.                 Sign MySign = hook.getSign();
  69.                 MySign.setText(RestoreCopy());
  70.                 MySign.update();
  71.                 hook.getPlayer().message(Colors.GREEN + "Copied sign!");
  72.             }
  73.         }
  74.         if (hook.getPlayer().hasPermission(PERMISSION_RESTORE)) {
  75.             Sign MySign = hook.getSign();
  76.             if (MySign.getTextOnLine(0).equalsIgnoreCase(STRING_RESTORE)) {
  77.                 MySign.setText(RestoreSign());
  78.                 MySign.update();
  79.             }
  80.         }
  81.         if (hook.getPlayer().hasPermission(PERMISSION_COLOR)) {
  82.             String[] TheText = hook.getSign().getText();
  83.             Sign MySign = hook.getSign();
  84.             for (int i=0; i<TheText.length; i++) {
  85.                 String ReplacedText = TheText[i].replace("&", Colors.MARKER); // Make Color codes for each line of the sign.
  86.                 MySign.setTextOnLine(ReplacedText, i);
  87.             }
  88.             MySign.update();
  89.         }
  90.     }
  91.    
  92.     @HookHandler
  93.     public void onBlockRightClick(BlockRightClickHook hook) {
  94.         if (hook.getPlayer().hasPermission(PERMISSION_COPY)) {
  95.             if (hook.getBlockClicked().getTypeId() == 63 || hook.getBlockClicked().getTypeId() == 68) {
  96.                 if (copysign) {
  97.                     Block MyBlock = hook.getBlockClicked();
  98.                     ComplexBlock MyComplexBlock = Canary.getServer().getDefaultWorld().getComplexBlock(MyBlock);
  99.                     SaveCopy( (Sign) MyComplexBlock);
  100.                     hook.getPlayer().message(Colors.GREEN + "Saved sign!");
  101.                 }
  102.             }
  103.         }
  104.     }
  105.    
  106.     @HookHandler
  107.     public void onBlockLeftClick(BlockLeftClickHook hook) {
  108.         Block MyBlock = hook.getBlock();
  109.         if (MyBlock.getType().equals(BlockType.WallSign) || MyBlock.getType().equals(BlockType.SignPost)) {
  110.             ComplexBlock MyComplexBlock = Canary.getServer().getDefaultWorld().getComplexBlock(MyBlock);
  111.             Sign MySign = (Sign) MyComplexBlock;
  112.             SaveSign(MySign);
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment