mirror of
https://e.coding.net/circlecloud/TeleportRandom.git
synced 2024-12-25 16:28:49 +00:00
feat: 添加剩余传送时间
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
a25c7e4501
commit
85e530a127
19
pom.xml
19
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>TeleportRandom</artifactId>
|
||||
<version>1.4.2</version>
|
||||
<version>1.4.3</version>
|
||||
<name>TeleportRandom</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
@ -31,10 +31,15 @@
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>pw.yumc:YumCore</include>
|
||||
<include>cn.citycraft:PluginHelper</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>pw.yumc.YumCore</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
@ -59,12 +64,8 @@
|
||||
<properties>
|
||||
<update.description>&a代码重构版本</update.description>
|
||||
<update.changes>
|
||||
&b1.4.3 - &c修复世界限制无效 添加CD剩余时间...;
|
||||
&b1.4.2 - &c修复CD只提示无限制的BUG...;
|
||||
&b1.4.1 - &c修复AIOOBE错误...;
|
||||
&b1.4 - &a添加命令CD...;
|
||||
&b1.3.2 - &c修复上个版本的空指针错误...;
|
||||
&b1.3.1 - &c修复上个版本一个逻辑错误...;
|
||||
&b1.3 - &c修复传送世界限制(区分大小写)...;
|
||||
</update.changes>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -95,5 +96,11 @@
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>YumCore</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,8 +1,8 @@
|
||||
package pw.yumc.TeleportRandom;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -16,13 +16,14 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
import pw.yumc.YumCore.statistic.Statistics;
|
||||
import pw.yumc.YumCore.update.SubscribeTask;
|
||||
|
||||
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<>();
|
||||
private final Map<String, Long> cd = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String string, final String[] args) {
|
||||
@ -47,6 +48,8 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
} else if (args.length > 1) {
|
||||
final Player p = Bukkit.getPlayer(args[0]);
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
throw new IllegalArgumentException();
|
||||
case 2:
|
||||
randomTP(Integer.parseInt(args[1]), p.getWorld(), p);
|
||||
return true;
|
||||
@ -56,27 +59,28 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
}
|
||||
}
|
||||
} catch (final IllegalArgumentException e) {
|
||||
if (args.length > 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!");
|
||||
}
|
||||
if (args.length > 0) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getCommand("tpr").setExecutor(this);
|
||||
new VersionChecker(this);
|
||||
new Statistics();
|
||||
new SubscribeTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,54 +92,78 @@ 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"));
|
||||
return;
|
||||
}
|
||||
if (!config.getStringList("AllowWorld").contains(world.getName())) {
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.NoPermWorld"));
|
||||
}
|
||||
int lr = config.getInt("default");
|
||||
if (limit == 0) {
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.default1"));
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.default2"));
|
||||
} else {
|
||||
lr = limit;
|
||||
final int lrLimit = config.getInt("Limit");
|
||||
if (lr > lrLimit) {
|
||||
lr = lrLimit;
|
||||
p.sendMessage(String.format(getPrefix() + config.getMessage("Message.Wran"), lrLimit));
|
||||
}
|
||||
}
|
||||
final Point point = new Point(lr, world);
|
||||
checkBlock(point, p);
|
||||
point.tp(p);
|
||||
cd.add(p.getName());
|
||||
getServer().getScheduler().runTaskLater(this, new Runnable() {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cd.remove(p.getName());
|
||||
final long t = System.currentTimeMillis();
|
||||
if (!p.hasPermission("tpr.nocd") && cd.keySet().contains(p.getName())) {
|
||||
final long leftTime = config.getLong("CD") / 20 - (t - cd.get(p.getName())) / 1000;
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.CDs").replace("{0}", String.format("%s", leftTime)));
|
||||
return;
|
||||
}
|
||||
if (!config.getStringList("AllowWorld").contains(world.getName())) {
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.NoPermWorld"));
|
||||
return;
|
||||
}
|
||||
int lr = config.getInt("default");
|
||||
if (limit == 0) {
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.default1"));
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.default2"));
|
||||
} else {
|
||||
lr = limit;
|
||||
final int lrLimit = config.getInt("Limit");
|
||||
if (lr > lrLimit) {
|
||||
lr = lrLimit;
|
||||
p.sendMessage(String.format(getPrefix() + config.getMessage("Message.Wran"), lrLimit));
|
||||
}
|
||||
}
|
||||
final Point point = new Point(lr, world);
|
||||
getServer().getScheduler().runTask(TeleportRandom.this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkBlock(point, p);
|
||||
tp(point, p);
|
||||
}
|
||||
});
|
||||
cd.put(p.getName(), t);
|
||||
getServer().getScheduler().runTaskLater(TeleportRandom.this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cd.remove(p.getName());
|
||||
}
|
||||
}, config.getLong("CD"));
|
||||
}
|
||||
}, config.getLong("CD"));
|
||||
});
|
||||
}
|
||||
|
||||
public void tp(final Point point, final Player p) {
|
||||
final Location loc = getTpLocation(point);
|
||||
p.teleport(loc);
|
||||
p.sendMessage(String.format(getPluginname() + config.getMessage("Message.Tip"), loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
|
||||
}
|
||||
|
||||
private void checkBlock(final Point point, final Player p) {
|
||||
final Material rbm = point.getBlock().getType();
|
||||
final Block bk = getBlock(point);
|
||||
final Material rbm = bk.getType();
|
||||
final String blockname = rbm.name();
|
||||
for (final String protectblock : config.getStringList("ProtectBlock")) {
|
||||
if (protectblock.equalsIgnoreCase(blockname)) {
|
||||
point.getBlock().setType(Material.GLASS);
|
||||
bk.setType(Material.GLASS);
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.Protect"));
|
||||
this.getServer().getScheduler().runTaskLater(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
point.getBlock().setType(rbm);
|
||||
bk.setType(rbm);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Block getBlock(final Point point) {
|
||||
return new Location(point.world, point.x, point.world.getHighestBlockYAt(point.x, point.z) - 1, point.z).getBlock();
|
||||
}
|
||||
|
||||
private String getPluginname() {
|
||||
return config.getMessage("pluginname");
|
||||
}
|
||||
@ -148,9 +176,12 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
return config.getMessage("servername");
|
||||
}
|
||||
|
||||
private Location getTpLocation(final Point point) {
|
||||
return new Location(point.world, point.x + 0.5, point.world.getHighestBlockYAt(point.x, point.z) + 3, point.z + 0.5);
|
||||
}
|
||||
|
||||
class Point {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public int limit;
|
||||
public World world;
|
||||
@ -168,23 +199,6 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
if (yf % 2 != 0) {
|
||||
z = -z;
|
||||
}
|
||||
y = world.getHighestBlockYAt(x, z);
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return new Location(world, x, y - 1, z).getBlock();
|
||||
}
|
||||
|
||||
public Location getTpLocation() {
|
||||
return new Location(world, x, y + 3, z);
|
||||
}
|
||||
|
||||
public void sendMessage(final Player p) {
|
||||
p.sendMessage(String.format(getPluginname() + config.getMessage("Message.Tip"), world.getName(), x, y, z));
|
||||
}
|
||||
|
||||
public void tp(final Player p) {
|
||||
p.teleport(getTpLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#本文件为随机传送插件的主配置文件
|
||||
Version: 1.4
|
||||
Version: 1.5
|
||||
#服务器名称
|
||||
servername: ''
|
||||
#插件名称
|
||||
@ -25,7 +25,7 @@ Message:
|
||||
#当前世界不允许传送
|
||||
NoPermWorld: '&c当前世界不允许使用随机传送!'
|
||||
#当前世界不允许传送
|
||||
CD: '&c随机传送冷却中!'
|
||||
CDs: '&c随机传送冷却中 剩余 {0} 秒!'
|
||||
#允许传送的世界(区分大小写)
|
||||
AllowWorld:
|
||||
- world
|
||||
|
Loading…
Reference in New Issue
Block a user