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
106a83af06
commit
d650e763f0
12
pom.xml
12
pom.xml
@ -1,9 +1,9 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>TeleportRandom</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>1.3</version>
|
||||
<name>TeleportRandom</name>
|
||||
<build>
|
||||
<finalName>${project.name}</finalName>
|
||||
@ -57,8 +57,10 @@
|
||||
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
|
||||
</ciManagement>
|
||||
<properties>
|
||||
<update.description>&e添加后台传送功能...</update.description>
|
||||
<update.changes></update.changes>
|
||||
<update.description>&a代码重构版本</update.description>
|
||||
<update.changes>
|
||||
&b1.3 - &c修复传送世界限制(区分大小写);
|
||||
</update.changes>
|
||||
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
@ -80,7 +82,7 @@
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<type>jar</type>
|
||||
<version>1.9-R0.1-SNAPSHOT</version>
|
||||
<version>1.10.2-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.citycraft</groupId>
|
||||
|
@ -1,135 +0,0 @@
|
||||
package cn.citycraft.TeleportRandom;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
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 cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
|
||||
public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
public FileConfig config;
|
||||
public String pluginname;
|
||||
public String servername;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String string, final String[] args) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
this.onLoad();
|
||||
sender.sendMessage(servername + pluginname + config.getMessage("Message.Reload"));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
final Player p = (Player) sender;
|
||||
if (!p.hasPermission("tpr.use")) {
|
||||
sender.sendMessage(servername + pluginname + config.getMessage("Message.NoPerm"));
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
RandomTP(0, p);
|
||||
break;
|
||||
case 1:
|
||||
RandomTP(Integer.parseInt(args[0]), p);
|
||||
break;
|
||||
case 2:
|
||||
RandomTP(Integer.parseInt(args[0]), Bukkit.getWorld(args[1]), p);
|
||||
break;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
sender.sendMessage(pluginname + "§c非法的参数或不存在的世界!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length > 0) {
|
||||
try {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
RandomTP(0, Bukkit.getPlayer(args[0]));
|
||||
break;
|
||||
case 2:
|
||||
RandomTP(Integer.parseInt(args[1]), Bukkit.getPlayer(args[0]));
|
||||
break;
|
||||
case 3:
|
||||
RandomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), Bukkit.getPlayer(args[0]));
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
} catch (final Exception e) {
|
||||
sender.sendMessage(pluginname + "§c非法的参数或不存在的世界!");
|
||||
}
|
||||
}
|
||||
sender.sendMessage(pluginname + "§c非法的参数!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig(this);
|
||||
servername = config.getMessage("servername");
|
||||
pluginname = config.getMessage("pluginname");
|
||||
}
|
||||
|
||||
public void RandomTP(final int limit, final Player p) {
|
||||
RandomTP(limit, p.getWorld(), p);
|
||||
}
|
||||
|
||||
public void RandomTP(final int limit, final World world, final Player p) {
|
||||
final Random rr = new Random();
|
||||
int lr = config.getInt("default");
|
||||
if (limit == 0) {
|
||||
p.sendMessage(pluginname + config.getMessage("Message.default1"));
|
||||
p.sendMessage(pluginname + config.getMessage("Message.default2"));
|
||||
} else {
|
||||
lr = limit;
|
||||
final int lrLimit = config.getInt("Limit");
|
||||
if (lr > lrLimit) {
|
||||
lr = lrLimit;
|
||||
p.sendMessage(String.format(pluginname + config.getMessage("Message.Wran"), lrLimit));
|
||||
}
|
||||
}
|
||||
int x = rr.nextInt(lr);
|
||||
int z = rr.nextInt(lr);
|
||||
final int xf = rr.nextInt(x);
|
||||
final int yf = rr.nextInt(z);
|
||||
if (xf % 2 != 0) {
|
||||
x = -x;
|
||||
}
|
||||
if (yf % 2 != 0) {
|
||||
z = -z;
|
||||
}
|
||||
final int y = world.getHighestBlockYAt(x, z);
|
||||
final Location trl = new Location(world, x, y - 1, z);
|
||||
final Material rbm = trl.getBlock().getType();
|
||||
final String blockname = rbm.name();
|
||||
for (final String protectblock : config.getStringList("ProtectBlock")) {
|
||||
if (protectblock.equalsIgnoreCase(blockname)) {
|
||||
trl.getBlock().setType(Material.GLASS);
|
||||
p.sendMessage(pluginname + config.getMessage("Message.Protect"));
|
||||
this.getServer().getScheduler().runTaskLater(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
trl.getBlock().setType(rbm);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
final Location nrl = new Location(world, x, y + 3, z);
|
||||
p.teleport(nrl);
|
||||
p.sendMessage(String.format(pluginname + config.getMessage("Message.Tip"), world.getName(), x, y, z));
|
||||
}
|
||||
}
|
160
src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java
Normal file
160
src/main/java/pw/yumc/TeleportRandom/TeleportRandom.java
Normal file
@ -0,0 +1,160 @@
|
||||
package pw.yumc.TeleportRandom;
|
||||
|
||||
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;
|
||||
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 cn.citycraft.PluginHelper.utils.VersionChecker;
|
||||
|
||||
public class TeleportRandom extends JavaPlugin implements CommandExecutor {
|
||||
public final static Random rr = new Random();
|
||||
public static FileConfig config;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String string, final String[] args) {
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("reload")) {
|
||||
config.reload();
|
||||
sender.sendMessage(getPrefix() + config.getMessage("Message.Reload"));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof Player) {
|
||||
final Player p = (Player) sender;
|
||||
if (!p.hasPermission("tpr.use")) {
|
||||
sender.sendMessage(getPrefix() + config.getMessage("Message.NoPerm"));
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
switch (args.length) {
|
||||
case 0:
|
||||
randomTP(0, p.getWorld(), p);
|
||||
break;
|
||||
case 1:
|
||||
randomTP(Integer.parseInt(args[0]), p.getWorld(), p);
|
||||
break;
|
||||
case 2:
|
||||
randomTP(Integer.parseInt(args[0]), Bukkit.getWorld(args[1]), p);
|
||||
break;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
sender.sendMessage(getPrefix() + "§c非法的参数或不存在的世界!");
|
||||
}
|
||||
return true;
|
||||
} else if (args.length > 2) {
|
||||
randomTP(Integer.parseInt(args[1]), Bukkit.getWorld(args[2]), Bukkit.getPlayer(args[0]));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new VersionChecker(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
config = new FileConfig(this);
|
||||
}
|
||||
|
||||
public void randomTP(final int limit, final World world, final Player p) {
|
||||
if (world == null || p == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
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(limit, world);
|
||||
checkBlock(point, p);
|
||||
point.tp(p);
|
||||
}
|
||||
|
||||
private void checkBlock(final Point point, final Player p) {
|
||||
final Material rbm = point.getBlock().getType();
|
||||
final String blockname = rbm.name();
|
||||
for (final String protectblock : config.getStringList("ProtectBlock")) {
|
||||
if (protectblock.equalsIgnoreCase(blockname)) {
|
||||
point.getBlock().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);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getPluginname() {
|
||||
return config.getMessage("pluginname");
|
||||
}
|
||||
|
||||
private String getPrefix() {
|
||||
return getServername() + getPluginname();
|
||||
}
|
||||
|
||||
private String getServername() {
|
||||
return config.getMessage("servername");
|
||||
}
|
||||
|
||||
class Point {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public int limit;
|
||||
public World world;
|
||||
|
||||
public Point(final int limit, final World world) {
|
||||
this.limit = limit;
|
||||
x = rr.nextInt(limit);
|
||||
z = rr.nextInt(limit);
|
||||
final int xf = rr.nextInt(x);
|
||||
final int yf = rr.nextInt(z);
|
||||
if (xf % 2 != 0) {
|
||||
x = -x;
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -22,10 +22,13 @@ Message:
|
||||
Protect: '&3传送保护 下方有&c危险&3 已自动生成玻璃(10秒后消失) !'
|
||||
#没有传送的权限
|
||||
NoPerm: '&c当前没有使用随机传送的权限!'
|
||||
|
||||
#允许传送的世界(不区分大小写)
|
||||
#当前世界不允许传送
|
||||
NoPermWorld: '&c当前世界不允许使用随机传送!'
|
||||
#允许传送的世界(区分大小写)
|
||||
AllowWorld:
|
||||
- World
|
||||
- world
|
||||
- world_nether
|
||||
- world_the_end
|
||||
|
||||
#默认传送距离
|
||||
default: 10000
|
||||
|
Loading…
Reference in New Issue
Block a user