1
0
mirror of https://e.coding.net/circlecloud/TeleportRandom.git synced 2024-11-01 07:38:47 +00:00

feat: 添加命令CD

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-07-20 10:12:31 +08:00
parent 6e28bf73a4
commit 8b5b8a593b
4 changed files with 54 additions and 16 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>pw.yumc</groupId>
<artifactId>TeleportRandom</artifactId>
<version>1.3.2</version>
<version>1.4</version>
<name>TeleportRandom</name>
<build>
<finalName>${project.name}</finalName>
@ -59,6 +59,7 @@
<properties>
<update.description>&amp;a代码重构版本</update.description>
<update.changes>
&amp;b1.4 - &amp;a添加命令CD...;
&amp;b1.3.2 - &amp;c修复上个版本的空指针错误...;
&amp;b1.3.1 - &amp;c修复上个版本一个逻辑错误...;
&amp;b1.3 - &amp;c修复传送世界限制(区分大小写)...;

View File

@ -1,6 +1,8 @@
package pw.yumc.TeleportRandom;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -20,20 +22,27 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
public final static Random rr = new Random();
public static FileConfig config;
private final Set<String> cd = new HashSet<>();
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String string, final String[] args) {
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
if (args[0].equalsIgnoreCase("reload")) {
config.reload();
sender.sendMessage(getPrefix() + config.getMessage("Message.Reload"));
return true;
}
if (args[0].equalsIgnoreCase("help")) {
sender.sendMessage("玩家: /tpr [范围] [世界]");
sender.sendMessage("控制台: /tpr <玩家> [范围] [世界]");
return true;
}
try {
if (sender instanceof Player) {
final Player p = (Player) sender;
if (!p.hasPermission("tpr.use")) {
sender.sendMessage(getPrefix() + config.getMessage("Message.NoPerm"));
return true;
}
try {
switch (args.length) {
case 0:
randomTP(0, p.getWorld(), p);
@ -45,13 +54,24 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
randomTP(Integer.parseInt(args[0]), Bukkit.getWorld(args[1]), p);
break;
}
} catch (final IllegalArgumentException e) {
sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!");
return true;
} else if (args.length > 1) {
final Player p = Bukkit.getPlayer(args[0]);
switch (args.length) {
case 2:
randomTP(Integer.parseInt(args[1]), p.getWorld(), p);
break;
case 3:
randomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), p);
break;
default:
break;
}
}
return true;
} else if (args.length > 2) {
randomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), Bukkit.getPlayer(args[0]));
return true;
} catch (final IllegalArgumentException e) {
sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!");
}
return false;
}
@ -71,6 +91,9 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
if (world == null || p == null) {
throw new IllegalArgumentException();
}
if (!p.hasPermission("tpr.nocd") && cd.contains(p.getName())) {
p.sendMessage(getPrefix() + config.getMessage("Message.CD"));
}
if (!config.getStringList("AllowWorld").contains(world.getName())) {
p.sendMessage(getPrefix() + config.getMessage("Message.NoPermWorld"));
}
@ -89,6 +112,13 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
final Point point = new Point(lr, world);
checkBlock(point, p);
point.tp(p);
cd.add(p.getName());
getServer().getScheduler().runTaskLater(this, new Runnable() {
@Override
public void run() {
cd.remove(p.getName());
}
}, config.getLong("CD"));
}
private void checkBlock(final Point point, final Player p) {

View File

@ -1,5 +1,5 @@
#本文件为随机传送插件的主配置文件
version: 1.0
version: 1.1
#服务器名称
servername: ''
#插件名称
@ -24,6 +24,8 @@ Message:
NoPerm: '&c当前没有使用随机传送的权限'
#当前世界不允许传送
NoPermWorld: '&c当前世界不允许使用随机传送'
#当前世界不允许传送
CD: '&c随机传送冷却中'
#允许传送的世界(区分大小写)
AllowWorld:
- world
@ -31,9 +33,11 @@ AllowWorld:
- world_the_end
#默认传送距离
default: 10000
default: 1000
#最大传送距离
Limit: 10000
#命令CD时间(单位Tick 1秒=20Tick)
CD: 60
#传送保护列表(不区分大小写)
ProtectBlock:

View File

@ -18,6 +18,9 @@ permissions:
tpr.use:
description: 允许使用随机传送!
default: true
tpr.nocd:
description: 允许无CD传送!
default: op
tpr.reload:
description: 允许重载随机传送!
default: op