Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. public static final String wieGehtEsDir = "Schmied: \"Möchtest du ein Schwert kaufen?\"";
  2. public final List<String> substrings = new ArrayList<>( wieGehtEsDir.length() );
  3. public final Map<UUID, Integer> wieGehtEsDirIndices = new HashMap<>();
  4. private TextComponent auswahl;
  5. private int eins;
  6.  
  7. @Override
  8. public void onEnable() {
  9.  
  10. // System.out.println( Bukkit.getPluginManager().getPlugin( "ClickableText" ) );
  11. // System.out.println( Bukkit.getPluginManager().getPlugin( "ClickableText" ) instanceof ClickableTextExample.Main );
  12.  
  13. for ( int i = 10; i <= wieGehtEsDir.length(); i++ ) {
  14. substrings.add( wieGehtEsDir.substring( 0, i ) );
  15. }
  16.  
  17. // TextComponent frage = new TextComponent( "Wie geht es dir?" );
  18. // frage.setColor( ChatColor.YELLOW );
  19. // frage.setBold( true );
  20. // frage.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "This; is a Firestorm!!" ).create() ) );
  21.  
  22. auswahl = new TextComponent( "[Ja]" );
  23. auswahl.setColor( ChatColor.GREEN );
  24. auswahl.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/kaufen" ) );
  25. auswahl.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Kaufe für XY Gold ein Schwert" ).create() ) );
  26.  
  27. TextComponent nein = new TextComponent( " [Nein]" );
  28. nein.setColor( ChatColor.RED );
  29. nein.setClickEvent( new ClickEvent( ClickEvent.Action.RUN_COMMAND, "/nichtkaufen" ) );
  30. nein.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT, new ComponentBuilder( "Lehne den Kauf ab und verärgere den Schmied" ).create() ) );
  31.  
  32. auswahl.addExtra( nein );
  33.  
  34. // System.out.println( "tostring(): " + frage.toString() );
  35. // System.out.println( "getText(): " + frage.getText() );
  36. // System.out.println( "toLegacyText(): " + frage.toLegacyText() );
  37. // System.out.println( "toPlainText(): " + frage.toPlainText() );
  38.  
  39. // for ( Player p : Bukkit.getOnlinePlayers() ) {
  40. // sendWieGehtEsDir( p );
  41. // p.spigot().sendMessage( auswahl );
  42. // }
  43.  
  44. }
  45.  
  46. public void sendWieGehtEsDir( final Player p ) {
  47. int substringsSize = substrings.size();
  48. byte ticksPerString = 3;
  49. eins = 1;
  50.  
  51. for ( int ticks = 0; ticks < substringsSize * ticksPerString; ticks += ticksPerString )
  52. Bukkit.getScheduler().scheduleSyncDelayedTask( this, new Runnable() {
  53.  
  54. @Override
  55. public void run() {
  56.  
  57. // for ( String s : substrings ) {
  58. // for ( int i = 0; i < 10; i++ )
  59. // p.sendMessage( "" );
  60. // p.sendMessage( s );
  61. // }
  62.  
  63. Integer index = wieGehtEsDirIndices.get( p.getUniqueId() );
  64. if ( index == null )
  65. index = 0;
  66.  
  67. for ( int i = 0; i < 10; i++ )
  68. p.sendMessage( "" );
  69. p.sendMessage( substrings.get( index ) );
  70. System.out.println( "sending message: " + substrings.get( index ) );
  71. wieGehtEsDirIndices.put( p.getUniqueId(), index + 1 );
  72. if ( eins == substrings.size() ) {
  73. p.spigot().sendMessage( auswahl );
  74. wieGehtEsDirIndices.put( p.getUniqueId(), 0 );
  75. eins = 0;
  76. }
  77. else {
  78. eins++;
  79. }
  80. }
  81. }, ticks );
  82. }
  83.  
  84. public boolean onCommand( CommandSender s, Command cmd, String cl, String[] args ) {
  85. Player p = (Player) s;
  86. if ( cmd.getName().equalsIgnoreCase( "kaufen" ) ) {
  87. p.sendMessage( "Das freut mich" );
  88. return true;
  89. }
  90. if ( cmd.getName().equalsIgnoreCase( "nichtkaufen" ) ) {
  91. p.sendMessage( "Hier darfst du nie mehr was kaufen!" );
  92. return true;
  93. }
  94. return false;
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement