mirror of
				https://e.coding.net/circlecloud/TeleportRandom.git
				synced 2025-11-03 18:16:02 +00:00 
			
		
		
		
	@@ -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;
 | 
				
			||||||
@@ -22,7 +22,7 @@ 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) {
 | 
				
			||||||
@@ -88,12 +88,17 @@ 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())) {
 | 
				
			||||||
 | 
					                    p.sendMessage(getPrefix() + config.getMessage("Message.CDs").replace("{0}", String.format("%0.2f", (t - cd.get(p.getName())) / 1000.00)));
 | 
				
			||||||
                    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 +113,51 @@ 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 Material rbm = getBlock(point).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);
 | 
					                getBlock(point).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);
 | 
					                        getBlock(point).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 +170,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, point.world.getHighestBlockYAt(point.x, point.z) + 3, point.z);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    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 +193,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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user