mirror of
https://e.coding.net/circlecloud/TeleportRandom.git
synced 2024-12-26 16:38: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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>TeleportRandom</artifactId>
|
<artifactId>TeleportRandom</artifactId>
|
||||||
<version>1.4.2</version>
|
<version>1.4.3</version>
|
||||||
<name>TeleportRandom</name>
|
<name>TeleportRandom</name>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
@ -31,10 +31,15 @@
|
|||||||
<minimizeJar>true</minimizeJar>
|
<minimizeJar>true</minimizeJar>
|
||||||
<artifactSet>
|
<artifactSet>
|
||||||
<includes>
|
<includes>
|
||||||
|
<include>pw.yumc:YumCore</include>
|
||||||
<include>cn.citycraft:PluginHelper</include>
|
<include>cn.citycraft:PluginHelper</include>
|
||||||
</includes>
|
</includes>
|
||||||
</artifactSet>
|
</artifactSet>
|
||||||
<relocations>
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>pw.yumc.YumCore</pattern>
|
||||||
|
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||||
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||||
@ -59,12 +64,8 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<update.description>&a代码重构版本</update.description>
|
<update.description>&a代码重构版本</update.description>
|
||||||
<update.changes>
|
<update.changes>
|
||||||
|
&b1.4.3 - &c修复世界限制无效 添加CD剩余时间...;
|
||||||
&b1.4.2 - &c修复CD只提示无限制的BUG...;
|
&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>
|
</update.changes>
|
||||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
@ -95,5 +96,11 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>pw.yumc</groupId>
|
||||||
|
<artifactId>YumCore</artifactId>
|
||||||
|
<type>jar</type>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,8 +1,8 @@
|
|||||||
package pw.yumc.TeleportRandom;
|
package pw.yumc.TeleportRandom;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
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;
|
||||||
@ -16,13 +16,14 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
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 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<>();
|
private final Map<String, Long> cd = new HashMap<>();
|
||||||
|
|
||||||
@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) {
|
||||||
@ -47,6 +48,8 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
} else if (args.length > 1) {
|
} else if (args.length > 1) {
|
||||||
final Player p = Bukkit.getPlayer(args[0]);
|
final Player p = Bukkit.getPlayer(args[0]);
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
|
case 1:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
case 2:
|
case 2:
|
||||||
randomTP(Integer.parseInt(args[1]), p.getWorld(), p);
|
randomTP(Integer.parseInt(args[1]), p.getWorld(), p);
|
||||||
return true;
|
return true;
|
||||||
@ -56,8 +59,6 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!");
|
|
||||||
}
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
if (args[0].equalsIgnoreCase("reload")) {
|
||||||
config.reload();
|
config.reload();
|
||||||
@ -70,13 +71,16 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getCommand("tpr").setExecutor(this);
|
getCommand("tpr").setExecutor(this);
|
||||||
new VersionChecker(this);
|
new Statistics();
|
||||||
|
new SubscribeTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -88,12 +92,18 @@ 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())) {
|
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||||
p.sendMessage(getPrefix() + config.getMessage("Message.CD"));
|
@Override
|
||||||
|
public void run() {
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
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"));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
int lr = config.getInt("default");
|
int lr = config.getInt("default");
|
||||||
if (limit == 0) {
|
if (limit == 0) {
|
||||||
@ -108,34 +118,52 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final Point point = new Point(lr, world);
|
final Point point = new Point(lr, world);
|
||||||
|
getServer().getScheduler().runTask(TeleportRandom.this, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
checkBlock(point, p);
|
checkBlock(point, p);
|
||||||
point.tp(p);
|
tp(point, p);
|
||||||
cd.add(p.getName());
|
}
|
||||||
getServer().getScheduler().runTaskLater(this, new Runnable() {
|
});
|
||||||
|
cd.put(p.getName(), t);
|
||||||
|
getServer().getScheduler().runTaskLater(TeleportRandom.this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
cd.remove(p.getName());
|
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) {
|
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();
|
final String blockname = rbm.name();
|
||||||
for (final String protectblock : config.getStringList("ProtectBlock")) {
|
for (final String protectblock : config.getStringList("ProtectBlock")) {
|
||||||
if (protectblock.equalsIgnoreCase(blockname)) {
|
if (protectblock.equalsIgnoreCase(blockname)) {
|
||||||
point.getBlock().setType(Material.GLASS);
|
bk.setType(Material.GLASS);
|
||||||
p.sendMessage(getPrefix() + config.getMessage("Message.Protect"));
|
p.sendMessage(getPrefix() + config.getMessage("Message.Protect"));
|
||||||
this.getServer().getScheduler().runTaskLater(this, new Runnable() {
|
this.getServer().getScheduler().runTaskLater(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
point.getBlock().setType(rbm);
|
bk.setType(rbm);
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 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() {
|
private String getPluginname() {
|
||||||
return config.getMessage("pluginname");
|
return config.getMessage("pluginname");
|
||||||
}
|
}
|
||||||
@ -148,9 +176,12 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
return config.getMessage("servername");
|
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 {
|
class Point {
|
||||||
public int x;
|
public int x;
|
||||||
public int y;
|
|
||||||
public int z;
|
public int z;
|
||||||
public int limit;
|
public int limit;
|
||||||
public World world;
|
public World world;
|
||||||
@ -168,23 +199,6 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
if (yf % 2 != 0) {
|
if (yf % 2 != 0) {
|
||||||
z = -z;
|
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: ''
|
servername: ''
|
||||||
#插件名称
|
#插件名称
|
||||||
@ -25,7 +25,7 @@ Message:
|
|||||||
#当前世界不允许传送
|
#当前世界不允许传送
|
||||||
NoPermWorld: '&c当前世界不允许使用随机传送!'
|
NoPermWorld: '&c当前世界不允许使用随机传送!'
|
||||||
#当前世界不允许传送
|
#当前世界不允许传送
|
||||||
CD: '&c随机传送冷却中!'
|
CDs: '&c随机传送冷却中 剩余 {0} 秒!'
|
||||||
#允许传送的世界(区分大小写)
|
#允许传送的世界(区分大小写)
|
||||||
AllowWorld:
|
AllowWorld:
|
||||||
- world
|
- world
|
||||||
|
Loading…
Reference in New Issue
Block a user