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

View File

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

View File

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

View File

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