Skip to content

Commit

Permalink
update to 1.0.3-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
myunco committed Feb 10, 2022
1 parent b951474 commit b425587
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
23 changes: 13 additions & 10 deletions src/items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
lore-exact: true

#匹配物品类型 可选 没有此项则不限物品类型 (虽然name,lore,type都是可选的,但至少要提供一个)
#如果你不知道某个物品的类型是什么 可以使用/ic add type命令将物品添加到物品配置文件 即可看到类型
type: 'PAPER'

#使用物品需要满足的条件 一行一个条件 可选 支持变量 格式为 类型:表达式,不满足条件时显示的消息(不想显示消息的话 只写,即可)
Expand Down Expand Up @@ -49,36 +50,38 @@
- 'right'

#物品使用后执行的动作 一行一个动作 支持变量 可选 没有此项则不执行任何动作
#可选的动作有: cmd, op, console, tell, chat, sound, broadcast, give-money, give-points,
#可选的动作有: cmd, op, console, tell, chat, sound, sound-all, broadcast, give-money, give-points,
# title, title-all, action-bar, action-bar-all, server 不指定默认为cmd
#格式为 动作: 值 (动作后面需要紧跟一个英文冒号 否则无法识别出正确动作会默认为整行都是cmd动作的值)
action:
#cmd = 让使用物品的玩家执行的命令 命令不需要加 /
#cmd = 让使用物品的玩家执行命令 命令不需要加 /
- 'cmd: help'
#op = 让使用物品的玩家以op身份执行的命令 同样不需要加 /
#op = 让使用物品的玩家以op身份执行命令 同样不需要加 /
- 'op: list'
#console = 让控制台执行的命令
#console = 让控制台执行命令
- 'console: say hi {player}'
#tell = 给使用物品的玩家发送消息
- 'tell: hi {player}'
#chat = 让使用物品的玩家发送聊天消息
- 'chat: 我使用了example'
#sound = 给使用物品的玩家播放的音效
- 'chat: 我使用了§6示例物品'
#sound = 给使用物品的玩家播放指定音效
- 'sound: ENTITY_EXPERIENCE_ORB_PICKUP'
#broadcast = 给全服玩家发送的消息(公告)
- 'broadcast: {player}使用了example'
#sound-all = 给全服玩家播放指定音效
- 'sound-all: ENTITY_EXPERIENCE_ORB_PICKUP'
#broadcast = 给全服玩家发送消息(公告)
- 'broadcast: {player}使用了§6示例物品'
#give-money = 给予使用物品的玩家指定数量的钱 只能为正整数 使用此功能需要安装Vault以及支持Vault的经济插件
- 'give-money: 10'
#give-points = 给予使用物品的玩家指定数量的点券 只能为正整数 使用此功能需要安装PlayerPoints插件
- 'give-points: 10'
#title = 给使用物品的玩家发送Title消息 格式 标题,副标题,显示时间(秒) 注意 逗号为英文逗号 1.10及以下版本会无视显示时间 1.8以下版本不支持此动作
- 'title: HiHiHi,没人看得到我 因为会被覆盖,10'
#title-all = 给全服玩家发送Title消息 格式同上 注意 新的Title会覆盖没显示完的Title 所以这条Title会覆盖掉上面那一条
- 'title-all: Hi,{player},10'
- 'title-all: Hi,{player}使用了§6示例物品,10'
#action-bar = 给使用物品的玩家发送ActionBar消息 1.8及以下版本不支持此动作 并且使用此动作需要使用Spigot或其衍生服务端 如Paper
- 'action-bar: hi 没人看得到我'
#action-bar-all = 给全服玩家发送ActionBar消息 注意 新的ActionBar会覆盖没显示完的ActionBar 所以这条ActionBar会覆盖掉上面那一条
- 'action-bar-all: hi {player}'
- 'action-bar-all: {player}使用了§6示例物品'
#server = 让使用物品的玩家切换到指定的BC子服 如果你不知道这是什么 那么你不需要此功能
- 'server: login'

Expand Down
5 changes: 3 additions & 2 deletions src/ml/mcos/itemcommand/action/ActionBarAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ public void execute(Player player) {
plugin.logMessage(Language.actionExecuteErrorActionBarNotSupport);
return;
}
String msg = plugin.replacePlaceholders(player, value);
try {
if (all) {
for (Player p : plugin.getServer().getOnlinePlayers()) {
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(plugin.replacePlaceholders(p, value)));
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg));
}
} else {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(plugin.replacePlaceholders(player, value)));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(msg));
}
} catch (Throwable t) {
plugin.logMessage(Language.actionExecuteErrorActionBarNotSupport);
Expand Down
31 changes: 30 additions & 1 deletion src/ml/mcos/itemcommand/action/SoundAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,47 @@
import org.bukkit.Sound;
import org.bukkit.entity.Player;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

public class SoundAction extends Action {
private final boolean all;

public SoundAction(String value) {
this(value, false);
}

public SoundAction(String value, boolean all) {
super(value);
this.all = all;
}

@Override
public void execute(Player player) {
try {
player.playSound(player.getLocation(), Sound.valueOf(value), 1F, 1F);
if (all) {
for (Player p : getOnlinePlayers()) {
p.playSound(p.getLocation(), Sound.valueOf(value), 1F, 1F);
}
} else {
player.playSound(player.getLocation(), Sound.valueOf(value), 1F, 1F);
}
} catch (IllegalArgumentException e) {
plugin.logMessage(Language.replaceArgs(Language.actionExecuteErrorSound, value));
}
}

public Collection<? extends Player> getOnlinePlayers() {
if (plugin.getMcVersion() > 7 || (plugin.getMcVersion() == 7 && plugin.getMcVersionPatch() == 10)) {
return plugin.getServer().getOnlinePlayers();
}
try {
return Arrays.asList((Player[]) Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers").invoke(plugin.getServer()));
} catch (Exception e) {
e.printStackTrace();
return Collections.emptyList();
}
}

}
7 changes: 5 additions & 2 deletions src/ml/mcos/itemcommand/action/TitleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ public void execute(Player player) {
plugin.logMessage(Language.actionExecuteErrorTitleArgsError);
return;
}
String title = plugin.replacePlaceholders(player, args[0]);
String subtitle = plugin.replacePlaceholders(player, args[1]);
int time = Utils.parseInt(plugin.replacePlaceholders(player, args[2]));
if (all) {
for (Player p : plugin.getServer().getOnlinePlayers()) {
if (!sendTitle(p, plugin.replacePlaceholders(p, args[0]), plugin.replacePlaceholders(p, args[1]), Utils.parseInt(plugin.replacePlaceholders(p, args[2])))) {
if (!sendTitle(p, title, subtitle, time)) {
return;
}
}
} else {
sendTitle(player, plugin.replacePlaceholders(player, args[0]), plugin.replacePlaceholders(player, args[1]), Utils.parseInt(plugin.replacePlaceholders(player, args[2])));
sendTitle(player, title, subtitle, time);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/ml/mcos/itemcommand/config/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ private static Item loadItem(ItemCommand plugin, String id) {
case "sound":
action[i] = new SoundAction(actionValue);
break;
case "sound-all":
action[i] = new SoundAction(actionValue, true);
break;
case "broadcast":
action[i] = new BroadcastAction(actionValue);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: ItemCommand
main: ml.mcos.itemcommand.ItemCommand
version: 1.0.2
version: 1.0.3-SNAPSHOT
api-version: 1.13
author: myunco
softdepend:
Expand Down

0 comments on commit b425587

Please sign in to comment.