mirror of
https://e.coding.net/circlecloud/TeleportRandom.git
synced 2024-12-25 16:28:49 +00:00
feat: 直接过滤危险地点
This commit is contained in:
parent
13ccb1a96b
commit
5403a1275a
9
pom.xml
9
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>TeleportRandom</artifactId>
|
||||
<version>1.4.3</version>
|
||||
<version>1.5</version>
|
||||
<name>TeleportRandom</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
@ -62,11 +62,8 @@
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<update.description>&a代码重构版本</update.description>
|
||||
<update.changes>
|
||||
&b1.4.3 - &c修复世界限制无效 添加CD剩余时间...;
|
||||
&b1.4.2 - &c修复CD只提示无限制的BUG...;
|
||||
</update.changes>
|
||||
<update.description></update.description>
|
||||
<update.changes></update.changes>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
@ -1,12 +1,7 @@
|
||||
package pw.yumc.TeleportRandom;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.Command;
|
||||
@ -14,13 +9,19 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
||||
import pw.yumc.YumCore.config.FileConfig;
|
||||
import pw.yumc.YumCore.statistic.Statistics;
|
||||
import pw.yumc.YumCore.update.SubscribeTask;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
public final static Random rr = new Random();
|
||||
public final static Random r1 = new SecureRandom();
|
||||
public final static Random r2 = new SecureRandom();
|
||||
|
||||
public static FileConfig config;
|
||||
|
||||
private final Map<String, Long> cd = new HashMap<>();
|
||||
@ -85,13 +86,11 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig(this);
|
||||
config = new FileConfig();
|
||||
}
|
||||
|
||||
public void randomTP(final int limit, final World world, final Player p) {
|
||||
if (world == null || p == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (world == null || p == null) { throw new IllegalArgumentException(); }
|
||||
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -121,7 +120,9 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
getServer().getScheduler().runTask(TeleportRandom.this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkBlock(point, p);
|
||||
while (config.getStringList("ProtectBlock").contains(getBlock(point).getType().name())) {
|
||||
point.random();
|
||||
}
|
||||
tp(point, p);
|
||||
}
|
||||
});
|
||||
@ -142,24 +143,6 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
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 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)) {
|
||||
bk.setType(Material.GLASS);
|
||||
p.sendMessage(getPrefix() + config.getMessage("Message.Protect"));
|
||||
this.getServer().getScheduler().runTaskLater(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
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();
|
||||
}
|
||||
@ -189,10 +172,14 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
public Point(final int limit, final World world) {
|
||||
this.limit = limit;
|
||||
this.world = world;
|
||||
x = rr.nextInt(limit);
|
||||
z = rr.nextInt(limit);
|
||||
final int xf = rr.nextInt(x);
|
||||
final int yf = rr.nextInt(z);
|
||||
random();
|
||||
}
|
||||
|
||||
public void random() {
|
||||
x = r1.nextInt(limit);
|
||||
z = r1.nextInt(limit);
|
||||
final int xf = r2.nextInt(x);
|
||||
final int yf = r2.nextInt(z);
|
||||
if (xf % 2 != 0) {
|
||||
x = -x;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user