diff --git a/pom.xml b/pom.xml index e482706..a46a2b1 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc TeleportRandom - 1.4.3 + 1.5 TeleportRandom ${project.name} @@ -62,11 +62,8 @@ http://ci.yumc.pw/job/${project.artifactId}/ - &a代码重构版本 - - &b1.4.3 - &c修复世界限制无效 添加CD剩余时间...; - &b1.4.2 - &c修复CD只提示无限制的BUG...; - + + DEBUG UTF-8 diff --git a/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java b/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java index 0f093f4..d9d42dc 100644 --- a/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java +++ b/src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java @@ -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 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; }