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

“ChatControl Pro/WIKI/JavaScript变量”的版本间的差异

来自Minecraft插件百科
跳转至: 导航搜索
 
第1行: 第1行:
 
{{模板:Ccpbox}}
 
{{模板:Ccpbox}}
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.
+
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编程知识,不会的话你也可以百度一下.
  
 
== 运算符 ==
 
== 运算符 ==
第58行: 第58行:
 
   }
 
   }
  
== Accessing NMS easily ==
+
== 轻易地访问NMS ==
 
define {ping}
 
define {ping}
  
第69行: 第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 编程向导 ==
 
== Javascript/Java 编程向导 ==

2019年1月29日 (二) 15: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 编程向导

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