• 欢迎来到Minecraft插件百科!
  • 对百科编辑一脸懵逼?帮助:快速入门带您快速熟悉百科编辑!
  • 因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289

ChatControl Pro/WIKI/JavaScript变量:修订间差异

来自Minecraft插件百科
跳转到导航 跳转到搜索
(创建页面,内容为“ChatControl Pro supports dynamic, high performance variables you create! They can be used across the plugin, in for example chat formatter or death messages. Current…”)
 
无编辑摘要
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
ChatControl Pro supports dynamic, high performance variables you create! They can be used across the plugin, in for example chat formatter or death messages. Currently, the file javascript.txt in variables folder stores all custom variables.
{{模板:Ccpbox}}
ChatControl Pro 支持你创建的动态高性能变量! 变量可以用于很多地方, 如聊天格式和死亡消息. 目前javascript.txt存储了所有的自定义变量.


Those can not only be used to display information, but because you can write your own full code in Javascript to display them, they can also do whatever you would wish for your players/server.
变量不仅可以用于显示信息,还可以在你写的JavaScript代码内使用.


To use Javascript variables, set Variables.Custom_Enabled to true in your settings.yml.
想要使用Javascript变量,需先启用 Variables.Custom_Enabled.


Notice: As the variables need to be recompiled (and scrips re-run) on every new message (to see if the value has changed), adding too many of them might negatively affect server's performance.
提醒: 变量在每条新消息上需要重编译,添加太多可能会影响服务器性能.


== Requirements ==
== 需求 ==
It is recommended you know a little bit of Java, knowing how to access methods in Bukkit, and have some basic knowledge of Javascript itself, or at least know how to use Google properly and adjust and debug others' Javascript code to your needs.
你需要有一定的Java编程知识,不会的话你也可以百度一下.


== 运算符 ==
== 运算符 ==
第23行: 第24行:
使用这个运算符来些脚本 (JavaScript)来获取变量.脚本从新一行开始写.
使用这个运算符来些脚本 (JavaScript)来获取变量.脚本从新一行开始写.


Scripts accept following variables directly from the game:
脚本接受以下来自以下的变量:


* 'player' for getting the player instance, if available
* 'player' 获取可用玩家名
* 'event' for getting the event, if available
* 'event' 获取可用事件名


  // Example of a variable that returns Watch out! message
  // 返回Watch out 的变量示例!对玩家发送消息和
  // 播放音效:
  // and plays a sound to the player:
  define {sound_and_message}
  define {sound_and_message}
 
script:
script:
  // define local pl variable, 只在该脚本内可用
 
  var pl = event.getPlayer();
   // define local pl variable, only available within this script
  // define local sound variable
 
  var sound = Java.type("org.bukkit.Sound").ANVIL_LAND;
   var pl = event.getPlayer();
  // 播放音效
 
  pl.playSound(pl.getLocation(), sound, 1F, 1F);
   // define local sound variable
  // 返回 "Watch out!"消息 as the placeholder  
 
  “Watch out!”;
   var sound = Java.type("org.bukkit.Sound").ANVIL_LAND;
 
   // actually plays sound to the player
 
   pl.playSound(pl.getLocation(), sound, 1F, 1F);
 
   // return "Watch out!" message as the placeholder  
 
   “Watch out!”;
<br />
<br />


== Using variables from PlaceholderAPI in your custom variable ==
== 使用来自 PlaceholderAPI的变量并用于你的变量 ==
Here is an example on how you can combine other plugins' variables to mix up your own variable depending on another variable's output!
以下示例告诉你如何结合其他插件的变量到你的变量内.


define {test}
define {test}
 
script:
script:
  getTagOrPrefix(); // call the function below that returns the tag or prefix
 
   getTagOrPrefix(); // call the function below that returns the tag or prefix
  function getTagOrPrefix() {
 
      // replace with the tag
 
      var tag = "{deluxetags_identifier}";
   function getTagOrPrefix() {
     
 
      // if the tag is empty, return prefix, else return tag with [] around it.
       // replace with the tag
      return tag == "" ? "{pl_prefix}" : "[" + tag + "]";
 
  }
       var tag = "{deluxetags_identifier}";
 
     
 
       // if the tag is empty, return prefix, else return tag with [] around it.
 
<nowiki>       return tag == "" ? "{pl_prefix}" : "[" + tag + "]";</nowiki>
 
   }


== Accessing NMS easily ==
== 轻易地访问NMS ==
define {ping}
define {ping}


第88行: 第69行:




Let's analyze this code really quickly:
代码分析:


# The <code>define</code> operator makes up and registers the variable <code>{ping}</code>, so you can use it in the plugin.
# <code>define</code> 运算符定义变量 <code>{ping}</code>.
# The <code>script:</code> begins the declaration of the Javascript code itself. Write your code below this line. It can have unlimited size - ChatControl will stop reading it when it reaches the end of the file or another define operator.
# <code>script:</code> 开始编译Javascript代码. 在下面输入你的代码. 代码无大小限制 - ChatControl会在代码结束后或是定义另一个运算符时停止读取.
# The code itself - contains predefined "player" variable you can use (if present) to get the player instance. This instance represents CraftPlayer in Bukkit in Java, so you can easily access NMS internals without even specifying those pesky 1_12_R0 numbers every time!
# code itself - 你可以使用包含预定义的 "player" 变量 (如果存在的话)来获取玩家名. 这个的实例代表了Bukkit在Java中的CraftPlayer,因此您可以很容易地访问NMS内部.


== Javascript/Java Coding Guide ==
== Javascript/Java 编程向导 ==
There is an extensive guide on how to code Javascript for Java on these locations:
插件作者提供了一些如何编程的教程网站:


* Unofficial Nashorn Tutorial
* [http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/ 非官方Nashorn教程]
* Official Nashorn Tutorial
* [http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html 官方Nashorn教程]

2019年1月29日 (二) 07:49的最新版本

子页面

常见疑问

权限

指令

频道

JSON

分组

格式

Discord

获取帮助

变量

处理器

JavaScript变量

多世界聊天格式

自定义指令缩写

自定义服务器名

监听优先度

聊天忽略

本地化

ChatControl Pro 支持你创建的动态高性能变量! 变量可以用于很多地方, 如聊天格式和死亡消息. 目前javascript.txt存储了所有的自定义变量.

变量不仅可以用于显示信息,还可以在你写的JavaScript代码内使用.

想要使用Javascript变量,需先启用 Variables.Custom_Enabled.

提醒: 变量在每条新消息上需要重编译,添加太多可能会影响服务器性能.

需求

你需要有一定的Java编程知识,不会的话你也可以百度一下.

运算符

定义

开始声明变量. 把变量名放到运算符后.

// 定义{player_name}变量:

define {player_name}


脚本

使用这个运算符来些脚本 (JavaScript)来获取变量.脚本从新一行开始写.

脚本接受以下来自以下的变量:

  • 'player' 获取可用玩家名
  • 'event' 获取可用事件名
// 返回Watch out 的变量示例!对玩家发送消息和 
// 播放音效:
define {sound_and_message}
script:
  // define local pl variable, 只在该脚本内可用
  var pl = event.getPlayer();
  // define local sound variable
  var sound = Java.type("org.bukkit.Sound").ANVIL_LAND;
  // 播放音效
  pl.playSound(pl.getLocation(), sound, 1F, 1F);
  // 返回 "Watch out!"消息 as the placeholder 
  “Watch out!”;


使用来自 PlaceholderAPI的变量并用于你的变量

以下示例告诉你如何结合其他插件的变量到你的变量内.

define {test}
script:
  getTagOrPrefix(); // call the function below that returns the tag or prefix

  function getTagOrPrefix() {
      // replace with the tag
      var tag = "{deluxetags_identifier}";
     
      // if the tag is empty, return prefix, else return tag with [] around it.
      return tag == "" ? "{pl_prefix}" : "[" + tag + "]";
  }

轻易地访问NMS

define {ping}

script:

   // acts if as you were inside of CraftPlayer class, so NMS is directly available

   player.getHandle().ping  


代码分析:

  1. define 运算符定义变量 {ping}.
  2. script: 开始编译Javascript代码. 在下面输入你的代码. 代码无大小限制 - ChatControl会在代码结束后或是定义另一个运算符时停止读取.
  3. code itself - 你可以使用包含预定义的 "player" 变量 (如果存在的话)来获取玩家名. 这个的实例代表了Bukkit在Java中的CraftPlayer,因此您可以很容易地访问NMS内部.

Javascript/Java 编程向导

插件作者提供了一些如何编程的教程网站: