mirror of
https://e.coding.net/circlecloud/TeleportRandom.git
synced 2024-12-26 16:38: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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>pw.yumc</groupId>
|
<groupId>pw.yumc</groupId>
|
||||||
<artifactId>TeleportRandom</artifactId>
|
<artifactId>TeleportRandom</artifactId>
|
||||||
<version>1.4.3</version>
|
<version>1.5</version>
|
||||||
<name>TeleportRandom</name>
|
<name>TeleportRandom</name>
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
@ -62,11 +62,8 @@
|
|||||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
<properties>
|
<properties>
|
||||||
<update.description>&a代码重构版本</update.description>
|
<update.description></update.description>
|
||||||
<update.changes>
|
<update.changes></update.changes>
|
||||||
&b1.4.3 - &c修复世界限制无效 添加CD剩余时间...;
|
|
||||||
&b1.4.2 - &c修复CD只提示无限制的BUG...;
|
|
||||||
</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>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
package pw.yumc.TeleportRandom;
|
package pw.yumc.TeleportRandom;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -14,13 +9,19 @@ import org.bukkit.command.CommandExecutor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import pw.yumc.YumCore.config.FileConfig;
|
||||||
import cn.citycraft.PluginHelper.config.FileConfig;
|
|
||||||
import pw.yumc.YumCore.statistic.Statistics;
|
import pw.yumc.YumCore.statistic.Statistics;
|
||||||
import pw.yumc.YumCore.update.SubscribeTask;
|
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 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;
|
public static FileConfig config;
|
||||||
|
|
||||||
private final Map<String, Long> cd = new HashMap<>();
|
private final Map<String, Long> cd = new HashMap<>();
|
||||||
@ -85,13 +86,11 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
config = new FileConfig(this);
|
config = new FileConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void randomTP(final int limit, final World world, final Player p) {
|
public void randomTP(final int limit, final World world, final Player p) {
|
||||||
if (world == null || p == null) {
|
if (world == null || p == null) { throw new IllegalArgumentException(); }
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
getServer().getScheduler().runTaskAsynchronously(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -121,7 +120,9 @@ public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
|||||||
getServer().getScheduler().runTask(TeleportRandom.this, new Runnable() {
|
getServer().getScheduler().runTask(TeleportRandom.this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
checkBlock(point, p);
|
while (config.getStringList("ProtectBlock").contains(getBlock(point).getType().name())) {
|
||||||
|
point.random();
|
||||||
|
}
|
||||||
tp(point, p);
|
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()));
|
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) {
|
private Block getBlock(final Point point) {
|
||||||
return new Location(point.world, point.x, point.world.getHighestBlockYAt(point.x, point.z) - 1, point.z).getBlock();
|
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) {
|
public Point(final int limit, final World world) {
|
||||||
this.limit = limit;
|
this.limit = limit;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
x = rr.nextInt(limit);
|
random();
|
||||||
z = rr.nextInt(limit);
|
}
|
||||||
final int xf = rr.nextInt(x);
|
|
||||||
final int yf = rr.nextInt(z);
|
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) {
|
if (xf % 2 != 0) {
|
||||||
x = -x;
|
x = -x;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user